-
Notifications
You must be signed in to change notification settings - Fork 62
/
base_routines.f90
1581 lines (1347 loc) · 62 KB
/
base_routines.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!> \file
!> \author Chris Bradley
!> \brief This module contains all the low-level base routines e.g., all debug, control, and low-level communication routines.
!>
!> \section LICENSE
!>
!> Version: MPL 1.1/GPL 2.0/LGPL 2.1
!>
!> The contents of this file are subject to the Mozilla Public License
!> Version 1.1 (the "License"); you may not use this file except in
!> compliance with the License. You may obtain a copy of the License at
!> http://www.mozilla.org/MPL/
!>
!> Software distributed under the License is distributed on an "AS IS"
!> basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
!> License for the specific language governing rights and limitations
!> under the License.
!>
!> The Original Code is OpenCMISS
!>
!> The Initial Developer of the Original Code is University of Auckland,
!> Auckland, New Zealand, the University of Oxford, Oxford, United
!> Kingdom and King's College, London, United Kingdom. Portions created
!> by the University of Auckland, the University of Oxford and King's
!> College, London are Copyright (C) 2007-2010 by the University of
!> Auckland, the University of Oxford and King's College, London.
!> All Rights Reserved.
!>
!> Contributor(s):
!>
!> Alternatively, the contents of this file may be used under the terms of
!> either the GNU General Public License Version 2 or later (the "GPL"), or
!> the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
!> in which case the provisions of the GPL or the LGPL are applicable instead
!> of those above. If you wish to allow use of your version of this file only
!> under the terms of either the GPL or the LGPL, and not to allow others to
!> use your version of this file under the terms of the MPL, indicate your
!> decision by deleting the provisions above and replace them with the notice
!> and other provisions required by the GPL or the LGPL. If you do not delete
!> the provisions above, a recipient may use your version of this file under
!> the terms of any one of the MPL, the GPL or the LGPL.
!>
!> This module contains all the low-level base routines e.g., all debug, control, and low-level communication routines.
MODULE BaseRoutines
USE Constants
USE Kinds
USE ISO_C_BINDING
USE ISO_VARYING_STRING
USE MACHINE_CONSTANTS
IMPLICIT NONE
PRIVATE
!Module parameters
INTEGER(INTG), PARAMETER :: MAX_OUTPUT_LINES=500 !<Maximum number of lines that can be output \see BaseRoutines::WriteStr
INTEGER(INTG), PARAMETER :: MAX_OUTPUT_WIDTH=132 !<Maximum width of output line \see BaseRoutines::WriteStr
!> \addtogroup BaseRoutines_OutputType BaseRoutines::OutputType
!> \brief Output type parameter
!> \see BaseRoutines
!>@{
INTEGER(INTG), PARAMETER :: GENERAL_OUTPUT_TYPE=1 !<General output type \see BaseRoutines_OutputType,BaseRoutines
INTEGER(INTG), PARAMETER :: DIAGNOSTIC_OUTPUT_TYPE=2 !<Diagnostic output type \see BaseRoutines_OutputType,BaseRoutines
INTEGER(INTG), PARAMETER :: TIMING_OUTPUT_TYPE=3 !<Timing output type \see BaseRoutines_OutputType,BaseRoutines
INTEGER(INTG), PARAMETER :: ERROR_OUTPUT_TYPE=4 !<Error output type \see BaseRoutines_OutputType,BaseRoutines
INTEGER(INTG), PARAMETER :: WARNING_OUTPUT_TYPE=5 !<Warning output type \see BaseRoutines_OutputType,BaseRoutines
INTEGER(INTG), PARAMETER :: HELP_OUTPUT_TYPE=6 !<Help output type \see BaseRoutines_OutputType,BaseRoutines
!>@}
!> \addtogroup BaseRoutines_FileUnits BaseRoutines::FileUnits
!> \brief File unit parameters
!> \see BaseRoutines
!>@{
INTEGER(INTG), PARAMETER :: ECHO_FILE_UNIT=10 !<File unit for echo files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: DIAGNOSTICS_FILE_UNIT=11 !<File unit for diagnostic files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: TIMING_FILE_UNIT=12 !<File unit for timing files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: LEARN_FILE_UNIT=13 !<File unit for learn files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: IO1_FILE_UNIT=21 !<File unit for general IO 1 files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: IO2_FILE_UNIT=22 !<File unit for general IO 2 files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: IO3_FILE_UNIT=23 !<File unit for general IO 3 files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: IO4_FILE_UNIT=24 !<File unit for general IO 4 files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: IO5_FILE_UNIT=25 !<File unit for general IO 5 files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: TEMPORARY_FILE_UNIT=80 !<File unit for temporary files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: OPEN_COMFILE_UNIT=90 !<File unit for open command files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: START_READ_COMFILE_UNIT=90 !<First file unit for read command files \see BaseRoutines_FileUnits,BaseRoutines
INTEGER(INTG), PARAMETER :: STOP_READ_COMFILE_UNIT=99 !<Last file unit for read command files \see BaseRoutines_FileUnits,BaseRoutines
!>@}
!> \addtogroup BaseRoutines_DiagnosticTypes BaseRoutines::DiagnosticTypes
!> \brief Diganostic type parameters
!> \see BaseRoutines,OpenCMISS_DiagnosticTypes
!>@{
INTEGER(INTG), PARAMETER :: ALL_DIAG_TYPE=1 !<Type for setting diagnostic output in all routines \see BaseRoutines_DiagnosticTypes,BaseRoutines
INTEGER(INTG), PARAMETER :: IN_DIAG_TYPE=2 !<Type for setting diagnostic output in one routine \see BaseRoutines_DiagnosticTypes,BaseRoutines
INTEGER(INTG), PARAMETER :: FROM_DIAG_TYPE=3 !<Type for setting diagnostic output from one routine downwards \see BaseRoutines_DiagnosticTypes,BaseRoutines
!>@}
!> \addtogroup BaseRoutines_TimingTypes BaseRoutines::TimingTypes
!> \brief Timing type parameters
!> \see BaseRoutines,OpenCMISS_TimingTypes
!>@{
INTEGER(INTG), PARAMETER :: ALL_TIMING_TYPE=1 !<Type for setting timing output in all routines \see BaseRoutines_TimingTypes,BaseRoutines
INTEGER(INTG), PARAMETER :: IN_TIMING_TYPE=2 !<Type for setting timing output in one routine \see BaseRoutines_TimingTypes,BaseRoutines
INTEGER(INTG), PARAMETER :: FROM_TIMING_TYPE=3 !<Type for setting timing output from one routine downwards \see BaseRoutines_TimingTypes,BaseRoutines
!>@}
!Module types
!>Contains information for an item in the routine list for diagnostics or timing
TYPE RoutineListItemType
CHARACTER(LEN=63) :: name !<Name of the routine
INTEGER(INTG) :: numberOfInvocations !<Number of times the routine has been invocted
REAL(SP) :: totalInclusiveCPUTime !<Total User CPU time spent in the routine inclusive of calls
REAL(SP) :: totalInclusiveSystemTime !<Total System CPU time spent in the routine inclusive of calls
REAL(SP) :: totalExclusiveCPUTime !<Total User CPU time spent in the routine exclusive of calls
REAL(SP) :: totalExclusiveSystemTime !<Total System CPU time spent in the routine exclusive of calls
TYPE(RoutineListItemType), POINTER :: nextRoutine !<Pointer to the next routine item in the routine list
END TYPE RoutineListItemType
!>Contains information for the routine list for diagnostics or timing
TYPE RoutineListType
TYPE(RoutineListItemType), POINTER :: head !<A pointer to the head of the routine list.
END TYPE RoutineListType
!>Contains information for an item in the routine invocation stack
TYPE RoutineStackItemType
CHARACTER(LEN=63) :: name !<Name of the routine
REAL(SP) :: inclusiveCPUTime !<User CPU time spent in the routine inclusive of calls
REAL(SP) :: inclusiveSystemTime !<System CPU time spent in the routine inclusive of calls
REAL(SP) :: exclusiveCPUTime !<User CPU time spent in the routine exclusive of calls
REAL(SP) :: exclusiveSystemTime !<System CPU time spent in the routine exclusive of calls
LOGICAL :: diagnostics !<.TRUE. if diagnostics are active in the routine
LOGICAL :: timing !<.TRUE. if timing is active in the routine
TYPE(RoutineListItemType), POINTER :: routineListItem !<Pointer to the routine list item for diagnostics or timing
TYPE(RoutineStackItemType), POINTER :: previousRoutine !<Pointer to the previous routine in the routine stack
END TYPE RoutineStackItemType
!>Contains information for the routine invocation stack
TYPE RoutineStackType
TYPE(RoutineStackItemType), POINTER :: stackPointer !<Pointer to the top of the stack
END TYPE RoutineStackType
!Module variables
INTEGER(INTG), SAVE :: myComputationalNodeNumber !<The computational rank for this node
INTEGER(INTG), SAVE :: numberOfComputationalNodes !<The number of computational nodes
INTEGER(INTG), ALLOCATABLE :: cmissRandomSeeds(:) !<The current error handling seeds for OpenCMISS
LOGICAL, SAVE :: diagnostics !<.TRUE. if diagnostic output is required in any routines.
LOGICAL, SAVE :: diagnostics1 !<.TRUE. if level 1 diagnostic output is active in the current routine
LOGICAL, SAVE :: diagnostics2 !<.TRUE. if level 2 diagnostic output is active in the current routine
LOGICAL, SAVE :: diagnostics3 !<.TRUE. if level 3 diagnostic output is active in the current routine
LOGICAL, SAVE :: diagnostics4 !<.TRUE. if level 4 diagnostic output is active in the current routine
LOGICAL, SAVE :: diagnostics5 !<.TRUE. if level 5 diagnostic output is active in the current routine
LOGICAL, SAVE :: diagnosticsLevel1 !<.TRUE. if the user has requested level 1 diagnostic output to be active
LOGICAL, SAVE :: diagnosticsLevel2 !<.TRUE. if the user has requested level 2 diagnostic output to be active
LOGICAL, SAVE :: diagnosticsLevel3 !<.TRUE. if the user has requested level 3 diagnostic output to be active
LOGICAL, SAVE :: diagnosticsLevel4 !<.TRUE. if the user has requested level 4 diagnostic output to be active
LOGICAL, SAVE :: diagnosticsLevel5 !<.TRUE. if the user has requested level 5 diagnostic output to be active
LOGICAL, SAVE :: diagAllSubroutines !<.TRUE. if diagnostic output is required in all routines
LOGICAL, SAVE :: diagFromSubroutine !<.TRUE. if diagnostic output is required from a particular routine
LOGICAL, SAVE :: diagFileOpen !<.TRUE. if the diagnostic output file is open
LOGICAL, SAVE :: diagOrTiming !<.TRUE. if diagnostics or time is .TRUE.
LOGICAL, SAVE :: echoOutput !<.TRUE. if all output is to be echoed to the echo file
LOGICAL, SAVE :: timing !<.TRUE. if timing output is required in any routines.
LOGICAL, SAVE :: timingSummary !<.TRUE. if timing output will be summary form via a TimingSummaryOutput call otherwise timing will be output for routines when the routine exits \see BaseRoutines::TimingSummaryOutput
LOGICAL, SAVE :: timingAllSubroutines !<.TRUE. if timing output is required in all routines
LOGICAL, SAVE :: timingFromSubroutine !<.TRUE. if timing output is required from a particular routine
LOGICAL, SAVE :: timingFileOpen !<.TRUE. if the timing output file is open
CHARACTER(LEN=MAXSTRLEN), SAVE :: outputString(MAX_OUTPUT_LINES) !<The array of lines to output
TYPE(RoutineListType), SAVE :: diagRoutineList !<The list of routines for which diagnostic output is required
TYPE(RoutineListType), SAVE :: timingRoutineList !<The list of routines for which timing output is required
TYPE(RoutineStackType), SAVE :: routineStack !<The routime invocation stack
!Interfaces
INTERFACE
!!!!NOTE: This module needs to call the c cputime function directly in order to avoid a circular module loop when timer uses
!!!! base_routines.
SUBROUTINE CPUTimer(returnTime, timeType, err, cError) BIND(C,NAME="CPUTimer")
USE ISO_C_BINDING
REAL(C_DOUBLE), INTENT(OUT) :: returnTime
INTEGER(C_INT), INTENT(IN) :: timeType
INTEGER(C_INT), INTENT(OUT) :: err
CHARACTER(C_CHAR), INTENT(OUT) :: cError(*)
END SUBROUTINE CPUTimer
END INTERFACE
!>Extracts the error message part of an error string
INTERFACE ExtractErrorMessage
MODULE PROCEDURE ExtractErrorMessageC
MODULE PROCEDURE ExtractErrorMessageVS
END INTERFACE ExtractErrorMessage
!>Extracts the error stack part of the error string
INTERFACE ExtractErrorStack
MODULE PROCEDURE ExtractErrorStackC
MODULE PROCEDURE ExtractErrorStackVS
END INTERFACE ExtractErrorStack
!>Flags an error condition
INTERFACE FLAG_ERROR
MODULE PROCEDURE FlagErrorC
MODULE PROCEDURE FlagErrorVS
END INTERFACE FLAG_ERROR
!>Flags an error condition
INTERFACE FlagError
MODULE PROCEDURE FlagErrorC
MODULE PROCEDURE FlagErrorVS
END INTERFACE FlagError
!>Flags a warning to the user
INTERFACE FLAG_WARNING
MODULE PROCEDURE FlagWarningC
MODULE PROCEDURE FlagWarningVS
END INTERFACE FLAG_WARNING
!>Flags a warning to the user
INTERFACE FlagWarning
MODULE PROCEDURE FlagWarningC
MODULE PROCEDURE FlagWarningVS
END INTERFACE FlagWarning
PUBLIC GENERAL_OUTPUT_TYPE,DIAGNOSTIC_OUTPUT_TYPE,TIMING_OUTPUT_TYPE,ERROR_OUTPUT_TYPE,HELP_OUTPUT_TYPE
PUBLIC ALL_DIAG_TYPE,IN_DIAG_TYPE,FROM_DIAG_TYPE
PUBLIC OPEN_COMFILE_UNIT,START_READ_COMFILE_UNIT,STOP_READ_COMFILE_UNIT,TEMPORARY_FILE_UNIT
PUBLIC ALL_TIMING_TYPE,IN_TIMING_TYPE,FROM_TIMING_TYPE
PUBLIC LEARN_FILE_UNIT,IO1_FILE_UNIT,IO2_FILE_UNIT,IO3_FILE_UNIT,IO4_FILE_UNIT,IO5_FILE_UNIT
PUBLIC diagnostics1,diagnostics2,diagnostics3,diagnostics4,diagnostics5
PUBLIC cmissRandomSeeds
PUBLIC outputString
PUBLIC BaseRoutines_Finalise,BaseRoutines_Initialise
PUBLIC ComputationalNodeNumbersSet
PUBLIC DiagnosticsSetOn,DiagnosticsSetOff
PUBLIC Enters,Errors,Exits
PUBLIC ExtractErrorMessage
PUBLIC ExtractErrorStack
PUBLIC FLAG_ERROR,FLAG_WARNING
PUBLIC FlagError,FlagWarning
PUBLIC OutputSetOff,OutputSetOn
PUBLIC RandomSeedsGet,RandomSeedsSizeGet,RandomSeedsSet
PUBLIC TimingSetOn,TimingSetOff
PUBLIC TimingSummaryOutput
PUBLIC WriteError
PUBLIC WriteStr
CONTAINS
!
!================================================================================================================================
!
!>Records the entry into the named procedure and initialises the error code \see BaseRoutines::EXITS
SUBROUTINE Enters(name,err,error,*)
!Argument variables
CHARACTER(LEN=*), INTENT(IN) :: name !<The name of the routine being entered
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
CHARACTER(C_CHAR) :: cError(MAXSTRLEN)
REAL(DP) :: entersCPUTime,entersSystemTime
LOGICAL :: finished
TYPE(RoutineListItemType), POINTER :: listRoutinePtr
TYPE(RoutineStackItemType), POINTER :: newRoutinePtr,routinePtr
IF(diagOrTiming) THEN
!$OMP CRITICAL(ENTERS_1)
ALLOCATE(newRoutinePtr,STAT=err)
IF(err/=0) CALL FlagError("Could not allocate new routine stack item.",err,error,*999)
newRoutinePtr%diagnostics=.FALSE.
newRoutinePtr%timing=.FALSE.
newRoutinePtr%name=name(1:LEN_TRIM(name))
IF(ASSOCIATED(routineStack%stackPointer)) THEN
newRoutinePtr%previousRoutine=>routineStack%stackPointer
routineStack%stackPointer=>newRoutinePtr
ELSE
NULLIFY(newRoutinePtr%previousRoutine)
routineStack%stackPointer=>newRoutinePtr
ENDIF
routinePtr=>routineStack%stackPointer
NULLIFY(routinePtr%routineListItem)
IF(diagnostics) THEN
IF(diagAllSubroutines) THEN !turn diagnostics on in all subroutines
routinePtr%diagnostics=.TRUE.
ELSE !diagnostics on in selected subroutines
finished=.FALSE.
listRoutinePtr=>diagRoutineList%head
DO WHILE(ASSOCIATED(listRoutinePtr).AND..NOT.finished)
IF(listRoutinePtr%name(1:LEN_TRIM(listRoutinePtr%name))==routinePtr%name(1:LEN_TRIM(routinePtr%name))) THEN
routinePtr%diagnostics=.TRUE.
routinePtr%routineListItem=>listRoutinePtr
finished=.TRUE.
ELSE
listRoutinePtr=>listRoutinePtr%nextRoutine
ENDIF
ENDDO
IF(diagFromSubroutine) THEN
IF(ASSOCIATED(routinePtr%previousRoutine)) THEN
IF(routinePtr%previousRoutine%diagnostics) routinePtr%diagnostics=.TRUE.
ENDIF
ENDIF
ENDIF
IF(routinePtr%diagnostics) THEN
diagnostics1=diagnosticsLevel1
diagnostics2=diagnosticsLevel2
diagnostics3=diagnosticsLevel3
diagnostics4=diagnosticsLevel4
diagnostics5=diagnosticsLevel5
ELSE
diagnostics1=.FALSE.
diagnostics2=.FALSE.
diagnostics3=.FALSE.
diagnostics4=.FALSE.
diagnostics5=.FALSE.
ENDIF
IF(routinePtr%diagnostics) THEN
WRITE(outputString,'("*** Enters: ",A)') name(1:LEN_TRIM(name))
CALL WriteStr(DIAGNOSTIC_OUTPUT_TYPE,err,error,*999)
ELSE IF(ASSOCIATED(routinePtr%previousRoutine)) THEN
!CPB 16/05/2007 Only show the calls if we have level 3 diagnostics or higher
IF(diagnostics3) THEN
IF(routinePtr%previousRoutine%diagnostics) THEN
WRITE(outputString,'("*** Calls : ",A)') name(1:LEN_TRIM(name))
CALL WriteStr(DIAGNOSTIC_OUTPUT_TYPE,err,error,*999)
ENDIF
ENDIF
ENDIF
ENDIF
IF(timing) THEN
CALL CPUTimer(entersCPUTime,1,ERR,cError)
CALL CPUTimer(entersSystemTime,2,ERR,cError)
routinePtr%inclusiveCPUTime=REAL(entersCPUTime,SP)
routinePtr%inclusiveSystemTime=REAL(entersSystemTime,SP)
routinePtr%exclusiveCPUTime=0.0_SP
routinePtr%exclusiveSystemTime=0.0_SP
IF(timingAllSubroutines) THEN
routinePtr%timing=.TRUE.
ELSE
finished=.FALSE.
listRoutinePtr=>timingRoutineList%head
DO WHILE(ASSOCIATED(listRoutinePtr).AND..NOT.finished)
IF(listRoutinePtr%name(1:LEN_TRIM(listRoutinePtr%name))==routinePtr%name(1:LEN_TRIM(routinePtr%name))) THEN
routinePtr%timing=.TRUE.
routinePtr%routineListItem=>listRoutinePtr
finished=.TRUE.
ELSE
listRoutinePtr=>listRoutinePtr%nextRoutine
ENDIF
ENDDO
IF(timingFromSubroutine) THEN
IF(ASSOCIATED(routinePtr%previousRoutine)) THEN
IF(routinePtr%previousRoutine%timing) routinePtr%timing=.TRUE.
ENDIF
ENDIF
ENDIF
ENDIF
!$OMP END CRITICAL(ENTERS_1)
ENDIF
RETURN
999 RETURN 1
END SUBROUTINE Enters
!
!================================================================================================================================
!
!>Records the exiting error of the subroutine
SUBROUTINE Errors(name,err,error)
!Argument variables
CHARACTER(LEN=*), INTENT(IN) :: name !<The name of the routine with an error condition
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(INOUT) :: error !<The error string
!Local variables
TYPE(VARYING_STRING) :: localError
IF(err==0) err=1
!CPB 20/02/07 aix compiler does not like varying strings so split the concatenate statement up into two statements
localError=error//ERROR_SEPARATOR_CONSTANT
error=localError//name(1:LEN_TRIM(name))
RETURN
END SUBROUTINE Errors
!
!================================================================================================================================
!
!>Records the exit out of the named procedure \see BaseRoutines::ENTERS
SUBROUTINE Exits(name)
!Argument variables
CHARACTER(LEN=*), INTENT(IN) :: name !<The name of the routine exiting
!Local variables
CHARACTER(C_CHAR) :: cError(MAXSTRLEN)
INTEGER(INTG) :: err
REAL(DP) :: exitsCPUTime,exitsSystemTime
TYPE(VARYING_STRING) :: error
TYPE(RoutineStackItemType), POINTER :: previousRoutinePtr,routinePtr
IF(diagOrTiming) THEN
!$OMP CRITICAL(EXITS_1)
routinePtr=>routineStack%stackPointer
IF(ASSOCIATED(routinePtr)) THEN
previousRoutinePtr=>routinePtr%previousRoutine
IF(diagnostics) THEN
IF(routinePtr%diagnostics) THEN
WRITE(outputString,'("*** Exits : ",A)') name(1:LEN_TRIM(name))
CALL WriteStr(DIAGNOSTIC_OUTPUT_TYPE,err,error,*999)
ENDIF
IF(ASSOCIATED(previousRoutinePtr)) THEN
IF(previousRoutinePtr%diagnostics) THEN
diagnostics1=diagnosticsLevel1
diagnostics2=diagnosticsLevel2
diagnostics3=diagnosticsLevel3
diagnostics4=diagnosticsLevel4
diagnostics5=diagnosticsLevel5
ELSE
diagnostics1=.FALSE.
diagnostics2=.FALSE.
diagnostics3=.FALSE.
diagnostics4=.FALSE.
diagnostics5=.FALSE.
ENDIF
ENDIF
ENDIF
IF(timing) THEN
CALL CPUTimer(exitsCPUTime,1,ERR,cError)
CALL CPUTimer(exitsSystemTime,2,ERR,cError)
routinePtr%inclusiveCPUTime=ABS(REAL(exitsCPUTime,SP)-routinePtr%inclusiveCPUTime)
routinePtr%inclusiveSystemTime=ABS(REAL(exitsSystemTime,SP)-routinePtr%inclusiveSystemTime)
IF(ASSOCIATED(previousRoutinePtr)) THEN
previousRoutinePtr%exclusiveCPUTime=previousRoutinePtr%exclusiveCPUTime+routinePtr%inclusiveCPUTime
previousRoutinePtr%exclusiveSystemTime=previousRoutinePtr%exclusiveSystemTime+routinePtr%inclusiveSystemTime
ENDIF
IF(ASSOCIATED(routinePtr%routineListItem)) THEN
routinePtr%routineListItem%numberOfInvocations=routinePtr%routineListItem%numberOfInvocations+1
routinePtr%routineListItem%totalInclusiveCPUTime=routinePtr%routineListItem%totalInclusiveCPUTime+ &
& routinePtr%inclusiveCPUTime
routinePtr%routineListItem%totalInclusiveSystemTime=routinePtr%routineListItem%totalInclusiveSystemTime+ &
& routinePtr%inclusiveSystemTime
IF(ASSOCIATED(previousRoutinePtr)) THEN
IF(ASSOCIATED(previousRoutinePtr%routineListItem)) THEN
previousRoutinePtr%routineListItem%totalExclusiveCPUTime=previousRoutinePtr%routineListItem% &
& totalExclusiveCPUTime+previousRoutinePtr%exclusiveCPUTime
previousRoutinePtr%routineListItem%totalExclusiveSystemTime=previousRoutinePtr%routineListItem% &
& totalExclusiveSystemTime+previousRoutinePtr%exclusiveSystemTime
ENDIF
ENDIF
ENDIF
IF(routinePtr%timing) THEN
IF(.NOT.timingSummary) THEN
WRITE(outputString,'("*** Timing : ",A)') name(1:LEN_TRIM(name))
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
IF(ASSOCIATED(routinePtr%routineListItem)) THEN
WRITE(outputString,'("*** Number of invocations: ",I10)') routinePtr%routineListItem%numberOfInvocations
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
WRITE(outputString, &
& '("*** Routine times: Call Inclusive Call Exclusive Total Inclusive Average Inclusive")')
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
WRITE(outputString,'("*** CPU (s): ",E14.6," ",E14.6," ",E15.6," ",E17.6)') &
& routinePtr%inclusiveCPUTime,routinePtr%inclusiveCPUTime-routinePtr%exclusiveCPUTime, &
& routinePtr%routineListItem%totalInclusiveCPUTime,routinePtr%routineListItem% &
& totalInclusiveCPUTime/REAL(routinePtr%routineListItem%numberOfInvocations,SP)
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
WRITE(outputString,'("*** System (s): ",E14.6," ",E14.6," ",E15.6," ",E17.6)') &
& routinePtr%inclusiveSystemTime,routinePtr%inclusiveSystemTime-routinePtr%exclusiveSystemTime, &
& routinePtr%routineListItem%totalInclusiveSystemTime,routinePtr%routineListItem% &
& totalInclusiveSystemTime/REAL(routinePtr%routineListItem%numberOfInvocations,SP)
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
ELSE
WRITE(outputString,'("*** Routine times: Call Inclusive Call Exclusive")')
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
WRITE(outputString,'("*** CPU (s): ",E14.6," ",E14.6)') &
& routinePtr%inclusiveCPUTime,routinePtr%inclusiveCPUTime-routinePtr%exclusiveCPUTime
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
WRITE(outputString,'("*** System (s): ",E14.6," ",E14.6)') &
& routinePtr%inclusiveSystemTime,routinePtr%inclusiveSystemTime-routinePtr%exclusiveSystemTime
CALL WriteStr(TIMING_OUTPUT_TYPE,err,error,*999)
ENDIF
ENDIF
ENDIF
ENDIF
IF(ASSOCIATED(previousRoutinePtr)) THEN
routineStack%stackPointer=>previousRoutinePtr
ELSE
NULLIFY(routineStack%stackPointer)
ENDIF
!Delete the routine pointer
DEALLOCATE(routinePtr)
!ELSE ERROR????
ENDIF
!$OMP END CRITICAL(EXITS_1)
ENDIF
999 RETURN
END SUBROUTINE Exits
!
!================================================================================================================================
!
#include "macros.h"
!>Set the computational node numbers. Note: this is done as a subroutine as ComputationalEnvironment depends on BaseRoutines.
SUBROUTINE ComputationalNodeNumbersSet(myNodeNumber,numberOfNodes,err,error,*)
!Argument variables
INTEGER(INTG), INTENT(IN) :: myNodeNumber !<The node number for this rank.
INTEGER(INTG), INTENT(IN) :: numberOfNodes !<The number of computational nodes.
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
ENTERS("ComputationalNodeNumbersSet",err,error,*999)
IF(numberOfNodes>0) THEN
IF(myNodeNumber>=0.AND.myNodeNumber<=numberOfNodes-1) THEN
myComputationalNodeNumber=myNodeNumber
numberOfComputationalNodes=numberOfNodes
ELSE
CALL FlagError("Invalid node number.",err,error,*999)
ENDIF
ELSE
CALL FlagError("Invalid number of nodes.",err,error,*999)
ENDIF
EXITS("ComputationalNodeNumbersSet")
RETURN
999 ERRORSEXITS("ComputationalNodeNumbersSet",err,error)
RETURN 1
END SUBROUTINE ComputationalNodeNumbersSet
!
!================================================================================================================================
!
!>Extracts the error message from a CMISS error string and returns it as a varying string
SUBROUTINE ExtractErrorMessageVS(errorMessage,err,error,*)
!Argument variables
TYPE(VARYING_STRING), INTENT(OUT) :: errorMessage !<The extracted error message
INTEGER(INTG), INTENT(IN) :: err !<The error code
TYPE(VARYING_STRING), INTENT(IN) :: error !<The error string
!Local Variables
INTEGER(INTG) :: position
position=INDEX(error,ERROR_SEPARATOR_CONSTANT)
errorMessage=EXTRACT(error,1,position-1)
RETURN
END SUBROUTINE ExtractErrorMessageVS
!
!================================================================================================================================
!
!>Extracts the error message from a CMISS error string and returns it as a character array
SUBROUTINE ExtractErrorMessageC(errorMessage,err,error,*)
!Argument variables
CHARACTER(LEN=*), INTENT(OUT) :: errorMessage !<The extracted error message
INTEGER(INTG), INTENT(IN) :: err !<The error code
TYPE(VARYING_STRING), INTENT(IN) :: error !<The error string
!Local Variables
INTEGER(INTG) :: position
position=INDEX(error,ERROR_SEPARATOR_CONSTANT)
errorMessage=EXTRACT(error,1,position-1)
RETURN
END SUBROUTINE ExtractErrorMessageC
!
!================================================================================================================================
!
!>Extracts the error stack from a CMISS error string and returns it as a varying string
SUBROUTINE ExtractErrorStackVS(errorStack,err,error,*)
!Argument variables
TYPE(VARYING_STRING), INTENT(OUT) :: errorStack !<The extracted error stack
INTEGER(INTG), INTENT(IN) :: err !<The error code
TYPE(VARYING_STRING), INTENT(IN) :: error !<The error string
!Local Variables
INTEGER(INTG) :: position
position=INDEX(error,ERROR_SEPARATOR_CONSTANT)
errorStack=EXTRACT(error,position+1,LEN_TRIM(error))
RETURN
END SUBROUTINE ExtractErrorStackVS
!
!================================================================================================================================
!
!>Extracts the error stack from a CMISS error string and returns it as a character array
SUBROUTINE ExtractErrorStackC(errorStack,err,error,*)
!Argument variables
CHARACTER(LEN=*), INTENT(OUT) :: errorStack !<The extracted error stack
INTEGER(INTG), INTENT(IN) :: err !<The error code
TYPE(VARYING_STRING), INTENT(IN) :: error !<The error string
!Local Variables
INTEGER(INTG) :: position
position=INDEX(error,ERROR_SEPARATOR_CONSTANT)
errorStack=EXTRACT(error,position+1,LEN_TRIM(error))
RETURN
END SUBROUTINE ExtractErrorStackC
!
!================================================================================================================================
!
!>Sets the error string specified by a character string and flags an error
SUBROUTINE FlagErrorC(string,err,error,*)
!Argument variables
CHARACTER(LEN=*), INTENT(IN) :: string !<The error condition string
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
INTEGER(INTG) :: stringLength
IF(err==0) err=1
stringLength=LEN_TRIM(string)
ERROR=string(1:stringLength)
RETURN 1
END SUBROUTINE FlagErrorC
!
!================================================================================================================================
!
!>Sets the error string specified by a varying string and flags an error.
SUBROUTINE FlagErrorVS(string,err,error,*)
!Argument variables
TYPE(VARYING_STRING), INTENT(IN) :: string !<The error condition string
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
IF(err==0) err=1
error=string
RETURN 1
END SUBROUTINE FlagErrorVS
!
!================================================================================================================================
!
!>Writes a warning message specified by a character string to the user.
SUBROUTINE FlagWarningC(string,err,error,*)
!Argument variables
CHARACTER(LEN=*), INTENT(IN) :: string !<The warning string
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
IF(numberOfComputationalNodes>1) THEN
WRITE(outputString,'(">>WARNING (",I0,"): ",A)') myComputationalNodeNumber,string
ELSE
WRITE(outputString,'(">>WARNING: ",A)') string
ENDIF
CALL WriteStr(WARNING_OUTPUT_TYPE,err,error,*999)
RETURN
999 ERRORS("FlagWarningC",err,error)
RETURN 1
END SUBROUTINE FlagWarningC
!
!================================================================================================================================
!
!>Writes a warning message specified by a varying string to the user.
SUBROUTINE FlagWarningVS(string,err,error,*)
!Argument variables
TYPE(VARYING_STRING), INTENT(IN) :: string !<The warning string
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
IF(numberOfComputationalNodes>1) THEN
WRITE(outputString,'(">>WARNING (",I0,"): ",A)') myComputationalNodeNumber,CHAR(string)
ELSE
WRITE(outputString,'(">>WARNING: ",A)') CHAR(string)
ENDIF
CALL WriteStr(WARNING_OUTPUT_TYPE,err,error,*999)
RETURN
999 ERRORS("FlagWarningVS",err,error)
RETURN 1
END SUBROUTINE FlagWarningVS
!
!================================================================================================================================
!
!>Finalises the base_routines module and deallocates all memory. \todo Finish this routine and deallocate memory.
SUBROUTINE BaseRoutines_Finalise(err,error,*)
!Argument variables
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
err=0
error=""
!Deallocate the random seeds
IF(ALLOCATED(cmissRandomSeeds)) DEALLOCATE(cmissRandomSeeds)
RETURN
999 RETURN 1
END SUBROUTINE BaseRoutines_Finalise
!
!================================================================================================================================
!
!>Initialises the variables required for the base_routines module.
SUBROUTINE BaseRoutines_Initialise(err,error,*)
!Argument variables
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
INTEGER(INTG) :: i,j,randomSeedsSize,time(8)
err=0
error=""
myComputationalNodeNumber=0
numberOfComputationalNodes=1
diagnostics=.FALSE.
diagnostics1=.FALSE.
diagnostics2=.FALSE.
diagnostics3=.FALSE.
diagnostics4=.FALSE.
diagnostics5=.FALSE.
diagnosticsLevel1=.FALSE.
diagnosticsLevel2=.FALSE.
diagnosticsLevel3=.FALSE.
diagnosticsLevel4=.FALSE.
diagnosticsLevel5=.FALSE.
diagAllSubroutines=.TRUE.
diagFromSubroutine=.FALSE.
diagFileOpen=.FALSE.
diagOrTiming=.FALSE.
echoOutput=.FALSE.
timing=.FALSE.
timingSummary=.FALSE.
timingAllSubroutines=.TRUE.
timingFromSubroutine=.FALSE.
timingFileOpen=.FALSE.
!Initialise loose tolerance here rather than in constants.f90
LOOSE_TOLERANCE=SQRT(EPSILON(1.0_DP))
LOOSE_TOLERANCE_SP=SQRT(EPSILON(1.0_SP))
!Setup the random seeds based on the time
CALL RANDOM_SEED(SIZE=randomSeedsSize)
ALLOCATE(cmissRandomSeeds(randomSeedsSize),STAT=err)
IF(err/=0) CALL FlagError("Could not allocate random seeds.",err,error,*999)
cmissRandomSeeds(1:randomSeedsSize)=[(i,i=1,randomSeedsSize)]
CALL DATE_AND_TIME(VALUES=time)
cmissRandomSeeds(1)=3600000*time(5)+60000*time(6)+1000*time(7)+time(8)
CALL RANDOM_SEED(PUT=cmissRandomSeeds)
!Initialise outputString
SELECT CASE(MACHINE_OS)
CASE(VMS_OS)
DO i=1,MAX_OUTPUT_LINES
outputString(i)(1:1)=CHAR(0)
ENDDO !i
CASE(IRIX_OS,LINUX_OS,AIX_OS)
DO i=1,MAX_OUTPUT_LINES
DO j=1,MAXSTRLEN
outputString(i)(j:j)=' '
ENDDO !j
ENDDO !i
CASE(WINDOWS_OS)
DO i=1,MAX_OUTPUT_LINES
outputString(i)(1:1)=CHAR(0)
ENDDO !i
CASE DEFAULT
CALL FlagError("Operating system not implemented.",err,error,*999)
END SELECT
!Initialise diagnostics and tracing
NULLIFY(routineStack%stackPointer)
NULLIFY(diagRoutineList%head)
NULLIFY(timingRoutineList%head)
RETURN
999 RETURN 1
END SUBROUTINE BaseRoutines_Initialise
!
!================================================================================================================================
!
!>Sets diagnositics off. \see BaseRoutines::DiagnosticsSetOn,OpenCMISS::Iron::DiagnosticsSetOn
SUBROUTINE DiagnosticsSetOff(err,error,*)
!Argument variables
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
TYPE(RoutineListItemType), POINTER :: nextRoutine,routine
ENTERS("DiagnosticsSetOff",err,error,*999)
IF(diagnostics) THEN
IF(diagFileOpen) THEN
diagFileOpen=.FALSE.
CLOSE(UNIT=DIAGNOSTICS_FILE_UNIT)
ENDIF
IF(diagAllSubroutines) THEN
diagAllSubroutines=.FALSE.
ELSE
routine=>diagRoutineList%head
DO WHILE(ASSOCIATED(routine))
nextRoutine=>routine%nextRoutine
DEALLOCATE(routine)
routine=>nextRoutine
ENDDO
NULLIFY(diagRoutineList%head)
diagFromSubroutine=.FALSE.
ENDIF
diagnosticsLevel1=.FALSE.
diagnosticsLevel2=.FALSE.
diagnosticsLevel3=.FALSE.
diagnosticsLevel4=.FALSE.
diagnosticsLevel5=.FALSE.
diagnostics1=.FALSE.
diagnostics2=.FALSE.
diagnostics3=.FALSE.
diagnostics4=.FALSE.
diagnostics5=.FALSE.
diagnostics=.FALSE.
diagOrTiming=timing
ELSE
CALL FlagError("Diagnositics is not on.",err,error,*999)
ENDIF
EXITS("DiagnosticsSetOff")
RETURN
999 ERRORSEXITS("DiagnosticsSetOff",err,error)
RETURN 1
END SUBROUTINE DiagnosticsSetOff
!
!================================================================================================================================
!
!>Sets diagnositics on. \see BaseRoutines::DiagnosticsSetOff,OpenCMISS::Iron::DiagnosticsSetOff
SUBROUTINE DiagnosticsSetOn(diagType,levelList,diagFilename,routineList,err,error,*)
!Argument variables
INTEGER(INTG), INTENT(IN) :: diagType !<The type of diagnostics to set on \see BaseRoutines_DiagnosticTypes
INTEGER(INTG), INTENT(IN) :: levelList(:) !<The list of diagnostic levels to set on
CHARACTER(LEN=*), INTENT(IN) :: diagFilename !<If present the name of the file to output diagnostic information to. If omitted the diagnostic output is sent to the screen
CHARACTER(LEN=*), INTENT(IN) :: routineList(:) !<The list of routines to set diagnostics on in.
INTEGER(INTG), INTENT(OUT) :: err !<The error code
TYPE(VARYING_STRING), INTENT(OUT) :: error !<The error string
!Local variables
INTEGER(INTG) :: i,level
CHARACTER(LEN=MAXSTRLEN) :: filename
TYPE(RoutineListItemType), POINTER :: nextRoutine,previousRoutine,routine
NULLIFY(routine)
ENTERS("DiagnosticsSetOn",err,error,*999)
IF(LEN_TRIM(diagFilename)>=1) THEN
IF(diagFileOpen) CLOSE(UNIT=DIAGNOSTICS_FILE_UNIT)
IF(numberOfComputationalNodes>1) THEN
WRITE(filename,'(A,".diag.",I0)') diagFilename(1:LEN_TRIM(diagFilename)),myComputationalNodeNumber
ELSE
filename=diagFilename(1:LEN_TRIM(diagFilename))//".diag"
ENDIF
OPEN(UNIT=DIAGNOSTICS_FILE_UNIT,FILE=filename(1:LEN_TRIM(filename)),STATUS="UNKNOWN",IOSTAT=err)
IF(err/=0) CALL FlagError("Could not open diagnostics file.",err,error,*999)
diagFileOpen=.TRUE.
ENDIF
SELECT CASE(diagType)
CASE(ALL_DIAG_TYPE)
diagAllSubroutines=.TRUE.
CASE(IN_DIAG_TYPE,FROM_DIAG_TYPE)
diagAllSubroutines=.FALSE.
diagFromSubroutine=diagType==FROM_DIAG_TYPE
IF(ASSOCIATED(diagRoutineList%head)) THEN
routine=>diagRoutineList%head
DO WHILE(ASSOCIATED(routine))
nextRoutine=>routine%nextRoutine
DEALLOCATE(routine)
routine=>nextRoutine
ENDDO
NULLIFY(diagRoutineList%head)
ENDIF
ALLOCATE(routine,STAT=err)
IF(err/=0) CALL FlagError("Could not allocate routine list item.",err,error,*999)
routine%name=routineList(1)
previousRoutine=>routine
NULLIFY(routine%nextRoutine)
diagRoutineList%head=>routine
DO i=2,SIZE(routineList,1)
ALLOCATE(routine,STAT=err)
IF(err/=0) CALL FlagError("Could not allocate routine list item.",err,error,*999)
routine%name=routineList(i)
NULLIFY(routine%nextRoutine)
previousRoutine%nextRoutine=>routine
previousRoutine=>routine
ENDDO !i
CASE DEFAULT
CALL FlagError("Invalid diagnostic type.",err,error,*999)
END SELECT
DO i=1,SIZE(levelList,1)
level=levelList(i)
SELECT CASE(level)
CASE(1)
diagnosticsLevel1=.TRUE.
CASE(2)
diagnosticsLevel2=.TRUE.
CASE(3)
diagnosticsLevel3=.TRUE.
CASE(4)
diagnosticsLevel4=.TRUE.
CASE(5)
diagnosticsLevel5=.TRUE.
CASE DEFAULT
CALL FlagError("Invalid diagnostic level.",err,error,*999)
END SELECT
ENDDO !i
diagnostics=.TRUE.
diagOrTiming=.TRUE.
EXITS("DiagnosticsSetOn")
RETURN
999 IF(diagFileOpen) THEN
CLOSE(UNIT=DIAGNOSTICS_FILE_UNIT)
diagFileOpen=.FALSE.
ENDIF
routine=>diagRoutineList%head
DO WHILE(ASSOCIATED(routine))
nextRoutine=>routine%nextRoutine