-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNWTC_IO.f90
executable file
·3639 lines (2167 loc) · 135 KB
/
NWTC_IO.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
MODULE NWTC_IO
! This module contains I/O-related variables and routines with non-system-specific logic.
! It contains the following routines:
! SUBROUTINE AdjRealStr ( NumStr ) ! Removes leading spaces and trailing zeros from strings created by real numbers.
! SUBROUTINE AllocAry ( ) ! Generic interface for the All*Ary* routines.
! SUBROUTINE AllCAry1 ( Ary, AryDim, Descr, ErrStat ) ! Allocate a 1-D CHARACTER array.
! SUBROUTINE AllCAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat ) ! Allocate a 2-D CHARACTER array.
! SUBROUTINE AllCAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat ) ! Allocate a 3-D CHARACTER array.
! SUBROUTINE AllIAry1 ( Ary, AryDim, Descr, ErrStat ) ! Allocate a 1-D INTEGER array.
! SUBROUTINE AllIAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat ) ! Allocate a 2-D INTEGER array.
! SUBROUTINE AllIAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat ) ! Allocate a 3-D INTEGER array.
! SUBROUTINE AllLAry1 ( Ary, AryDim, Descr, ErrStat ) ! Allocate a 1-D LOGICAL array.
! SUBROUTINE AllLAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat ) ! Allocate a 2-D LOGICAL array.
! SUBROUTINE AllLAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat ) ! Allocate a 3-D LOGICAL array.
! SUBROUTINE AllRAry1 ( Ary, AryDim, Descr, ErrStat ) ! Allocate a 1-D REAL array.
! SUBROUTINE AllRAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat ) ! Allocate a 2-D REAL array.
! SUBROUTINE AllRAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat ) ! Allocate a 3-D REAL array.
! SUBROUTINE AllRAry4 ( Ary, AryDim1, AryDim2, AryDim3, AryDim4, Descr, ErrStat ) ! Allocate a 4-D REAL array.
! SUBROUTINE CheckArgs ( InputFile [, ErrStat] )
! SUBROUTINE CheckIOS ( IOS, Fil, Variable, VarType [, TrapErrors] )
! SUBROUTINE ChkRealFmtStr ( RealFmt, RealFmtVar, ErrStat, ErrMsg ) ! Test to see if a specified string is a valid format for real numbers.
! SUBROUTINE CloseEcho ( )
! SUBROUTINE Conv2UC ( Str )
! FUNCTION CountWords ( Line )
! FUNCTION CurDate ( )
! FUNCTION CurTime ( )
! SUBROUTINE DispNVD ( ) ! Generic interface for DispNVD0, DispNVD1, DispNVD2.
! SUBROUTINE DispNVD0 ( ) ! Used when DispNVD() has no agruments.
! SUBROUTINE DispNVD1 ( ProgInfo ) ! Used when DispNVD() is called with an argument of ProgDesc type.
! SUBROUTINE DispNVD2 ( Name, Ver ) ! Used when DispNVD() is called with name and version.
! FUNCTION Flt2LStr ( FltNum )
! SUBROUTINE GetNewUnit ( UnIn )
! FUNCTION GetNVD ( ProgDesc )
! SUBROUTINE GetPath ( GivenFil, PathName )
! SUBROUTINE GetRoot ( GivenFil, RootName )
! SUBROUTINE GetTokens ( Line, NumTok, Tokens, Error )
! SUBROUTINE GetWords ( Line, Words, NumWords )
! FUNCTION Int2LStr ( Intgr )
! SUBROUTINE NameOFile ( InArg, OutExten, OutFile )
! SUBROUTINE NormStop ( )
! FUNCTION Num2LStr ( Num ) ! Generic interface for Int2LStr, R2LStr4, R2LStr8, R2LStr16
! SUBROUTINE OpenBin ( Un, OutFile, RecLen [, ErrStat] )
! SUBROUTINE OpenBInpFile ( Un, InFile [, ErrStat] )
! SUBROUTINE OpenEcho ( Un, InFile [, ErrStat] )
! SUBROUTINE OpenFInpFile ( Un, InFile [, ErrStat] )
! SUBROUTINE OpenFOutFile ( Un, OutFile [, ErrStat] )
! SUBROUTINE OpenFUnkFile ( Un, OutFile, FailAbt, Failed, Exists [, ErrStat] )
! SUBROUTINE OpenUInBEFile ( Un, InFile, RecLen [, ErrStat] )
! SUBROUTINE OpenUInfile ( Un, InFile [, ErrStat] )
! SUBROUTINE OpenUOutfile ( Un, OutFile [, ErrStat] )
! FUNCTION PathIsRelative( GivenFil )
! SUBROUTINE PremEOF ( Fil , Variable [, TrapErrors] )
! SUBROUTINE ProgAbort ( Message [, TrapErrors] )
! SUBROUTINE ProgPause ! Pause output so the user has to hit <Enter> to continue.
! SUBROUTINE ProgWarn ( Message )
! FUNCTION R2LStr4 ( FltNum ) ! Convert 4-byte REALs to left-justified strings.
! FUNCTION R2LStr8 ( FltNum ) ! Convert 8-byte REALs to left-justified strings.
! FUNCTION R2LStr16 ( FltNum ) ! Convert 16-byte REALs to left-justified strings.
! SUBROUTINE ReadAry ( UnIn, Fil, Ary, AryLen, AryName, AryDescr [, ErrStat] ) ! Generic interface for ReadCAry, ReadIAry, ReadLAry, and ReadRAry.
! SUBROUTINE ReadAryLines ( UnIn, Fil, Ary, AryLen, AryName, AryDescr [, ErrStat] ) ! Generic interface for ReadCAryLines, ReadRAryLines4, ReadRAryLines8, and ReadRAryLines16.
! SUBROUTINE ReadCAry ( UnIn, Fil, CharAry, AryLen, AryName, AryDescr [, ErrStat] )
! SUBROUTINE ReadCAryLines ( UnIn, Fil, CharAry, AryLen, AryName, AryDescr [, ErrStat] )
! SUBROUTINE ReadCom ( UnIn, Fil, ComName [, ErrStat] )
! SUBROUTINE ReadCVar ( UnIn, Fil, CharVar, VarName, VarDescr [, ErrStat] )
! SUBROUTINE ReadFASTbin ( UnIn, FASTdata [, ErrLev, ErrMsg] ) ! Read a FAST binary output file.
! SUBROUTINE ReadIAry ( UnIn, Fil, IntAry, AryLen, AryName, AryDescr [, ErrStat] )
! SUBROUTINE ReadIVar ( UnIn, Fil, IntVar, VarName, VarDescr [, ErrStat] )
! SUBROUTINE ReadLAry ( UnIn, Fil, LogAry, AryLen, AryName, AryDescr [, ErrStat] )
! SUBROUTINE ReadLVar ( UnIn, Fil, LogVar, VarName, VarDescr [, ErrStat] )
! SUBROUTINE ReadNum ( UnIn, Fil, Word, VarName, ErrStat )
! SUBROUTINE ReadOutputList( UnIn, Fil, CharAry, AryLenRead, AryName, AryDescr, ErrStat )
! SUBROUTINE ReadRAry ( UnIn, Fil, RealAry, AryLen, AryName, AryDescr [, ErrStat] )
! SUBROUTINE ReadRAryLines ( UnIn, Fil, RealAry, AryLen, AryName, AryDescr [, ErrStat] )
! SUBROUTINE ReadRVar ( UnIn, Fil, RealVar, VarName, VarDescr [, ErrStat] )
! SUBROUTINE ReadStr ( UnIn, Fil, CharVar, VarName, VarDescr [, ErrStat] )
! SUBROUTINE ReadVar ( UnIn, Fil, Var, VarName, VarDescr [, ErrStat] ) ! Generic interface for ReadCVar, ReadIVar, ReadLVar, and ReadRVar.
! SUBROUTINE WaitTime ( WaitSecs )
! SUBROUTINE WrFileNR ( Unit, Str )
! SUBROUTINE WrML ( Str )
! SUBROUTINE WrPr ( Str )
! SUBROUTINE WrScr1 ( Str )
USE SysSubs
IMPLICIT NONE
!=======================================================================
TYPE, PUBLIC :: ProgDesc
CHARACTER(24) :: Name
CHARACTER(99) :: Ver
CHARACTER(24) :: Date
END TYPE ProgDesc
TYPE, PUBLIC :: FASTdataType ! The derived type for holding FAST binary output data.
CHARACTER(1024) :: File ! The name of the binary input file containing FAST output.
CHARACTER(1024) :: Descr ! The file descriptor stored in the FAST binary output file.
INTEGER(B4Ki) :: NumChans ! The number of channels of FAST output data (including time).
INTEGER(B4Ki) :: NumRecs ! The number of records of FAST output data.
REAL(R8Ki) :: TimeStep ! The time step.
CHARACTER(20), ALLOCATABLE :: ChanNames(:) ! The channel names.
CHARACTER(20), ALLOCATABLE :: ChanUnits(:) ! The channel units.
REAL(ReKi) , ALLOCATABLE :: Data(:,:) ! The channel data. Time is stored in the first column.
END TYPE FASTdataType
INTEGER(IntKi), PARAMETER :: ErrID_None = 0
INTEGER(IntKi), PARAMETER :: ErrID_Info = 1
INTEGER(IntKi), PARAMETER :: ErrID_Warn = 2
INTEGER(IntKi), PARAMETER :: ErrID_Severe = 3
INTEGER(IntKi), PARAMETER :: ErrID_Fatal = 4
INTEGER(IntKi) :: AbortErrLev = ErrID_Fatal
! Global I/O-related variables.
INTEGER(IntKi), PARAMETER :: FlgType = 1 ! Switch for telling if a variable is a flag.
INTEGER(IntKi), PARAMETER :: NumType = 2 ! Switch for telling if a variable is a number.
INTEGER(IntKi), PARAMETER :: StrType = 3 ! Switch for telling if a variable is a string.
INTEGER :: UnEc = 19 ! I/O unit number for the echo file.
LOGICAL :: Beep = .TRUE. ! Flag that specifies whether or not to beep for error messages and program terminations.
LOGICAL :: Echo = .FALSE. ! Flag that specifies whether or not to produce an echo file.
TYPE(ProgDesc), PARAMETER :: NWTC_Ver = ProgDesc( 'NWTC Subroutine Library', 'v1.07.00b-mlb', '10-Jan-2013') ! The name, version, and date of the NWTC Subroutine Library.
CHARACTER(20) :: ProgName = ' ' ! The name of the calling program.
CHARACTER(99) :: ProgVer ! The version (including date) of the calling program.
CHARACTER(1), PARAMETER :: Tab = CHAR( 9 ) ! The tab character.
!=======================================================================
! Create interface for a generic AllocAry that actually uses specific routines.
INTERFACE AllocAry
MODULE PROCEDURE AllCAry1
MODULE PROCEDURE AllCAry2
MODULE PROCEDURE AllCAry3
! MODULE PROCEDURE AllCAry4 Not yet coded.
MODULE PROCEDURE AllIAry1
MODULE PROCEDURE AllIAry2
MODULE PROCEDURE AllIAry3
! MODULE PROCEDURE AllIAry4 Not yet coded.
MODULE PROCEDURE AllLAry1
MODULE PROCEDURE AllLAry2
MODULE PROCEDURE AllLAry3
! MODULE PROCEDURE AllLAry4 Not yet coded.
MODULE PROCEDURE AllRAry1
MODULE PROCEDURE AllRAry2
MODULE PROCEDURE AllRAry3
MODULE PROCEDURE AllRAry4
END INTERFACE
! Create interface for a generic ReadVar that actually uses specific routines.
INTERFACE ReadVar
MODULE PROCEDURE ReadCVar
MODULE PROCEDURE ReadIVar
MODULE PROCEDURE ReadLVar
MODULE PROCEDURE ReadR4Var ! 4-byte real
MODULE PROCEDURE ReadR8Var ! 8-byte real
MODULE PROCEDURE ReadR16Var ! 16-byte real
END INTERFACE
! Create interface for a generic ReadAry that actually uses specific routines.
INTERFACE ReadAry
MODULE PROCEDURE ReadCAry
MODULE PROCEDURE ReadIAry
MODULE PROCEDURE ReadLAry
MODULE PROCEDURE ReadRAry ! replace with routines for 4-, 8-, and 16-byte reals
END INTERFACE
INTERFACE ReadAryLines
MODULE PROCEDURE ReadCAryLines
MODULE PROCEDURE ReadRAryLines4
MODULE PROCEDURE ReadRAryLines8
MODULE PROCEDURE ReadRAryLines16
! MODULE PROCEDURE ReadIAryLines ! Not coded yet
! MODULE PROCEDURE ReadLAryLines ! Not coded yet
END INTERFACE
! Create interface for a generic Num2LStr that actually uses specific routines.
INTERFACE Num2LStr
MODULE PROCEDURE Int2LStr ! default integers
MODULE PROCEDURE R2LStr4 ! 4-byte reals
MODULE PROCEDURE R2LStr8 ! 8-byte reals
MODULE PROCEDURE R2LStr16 ! 16-byte reals
END INTERFACE
! Create interface for DispNVD so that we can pass in the name of the program
INTERFACE DispNVD
MODULE PROCEDURE DispNVD0 ! No arguments.
MODULE PROCEDURE DispNVD1 ! Single argument of TYPE ProgDesc
MODULE PROCEDURE DispNVD2 ! Two arguments of TYPE character
END INTERFACE
CONTAINS
!=======================================================================
SUBROUTINE AdjRealStr( NumStr )
! This routine adjusts strings created from real numbers (4, 8, or 16-byte)
! It removes leading spaces and trailing zeros. It is intended to be called
! from routines R2LStr4, R2LStr8, and R2LStr16.
CHARACTER(*), INTENT(INOUT) :: NumStr ! String representing a real number (e.g., from R2LStr4)
! Local declarations.
INTEGER :: IC ! Character index.
NumStr = ADJUSTL( NumStr )
! Replace trailing zeros and possibly the decimal point with blanks.
! Stop trimming once we find the decimal point or a nonzero.
! Don't remove (important!) trailing zeros if they are in the exponent:
IF (INDEX( NumStr, "E" ) > 0 ) RETURN
IF (INDEX( NumStr, "e" ) > 0 ) RETURN
! These are not in the exponent
DO IC=LEN_TRIM( NumStr ),1,-1
IF ( NumStr(IC:IC) == '.' ) THEN
NumStr(IC:IC) = ' '
RETURN
ELSE IF ( NumStr(IC:IC) /= '0' ) THEN
RETURN
END IF
NumStr(IC:IC) = ' '
END DO ! IC
END SUBROUTINE AdjRealStr
!=======================================================================
SUBROUTINE AllCAry1 ( Ary, AryDim, Descr, ErrStat )
! This routine allocates a 1-D CHARACTER array.
! Argument declarations.
INTEGER, INTENT(IN) :: AryDim ! The size of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), ALLOCATABLE :: Ary (:) ! Array to be allocated
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllCAry1 ! ( Ary, AryDim, Descr )
!=======================================================================
SUBROUTINE AllCAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat )
! This routine allocates a 2-D CHARACTER array.
! Argument declarations.
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), ALLOCATABLE :: Ary (:,:) ! Array to be allocated
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllCAry2 ! ( Ary, AryDim1, AryDim2, Descr )
!=======================================================================
SUBROUTINE AllCAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat )
! This routine allocates a 3-D CHARACTER array.
! Argument declarations.
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(IN) :: AryDim3 ! The size of the third dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), ALLOCATABLE :: Ary (:,:,:) ! Array to be allocated
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2,AryDim3) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllCAry3 ! ( Ary, AryDim1, AryDim2, AryDim3, Descr )
!=======================================================================
SUBROUTINE AllIAry1 ( Ary, AryDim, Descr, ErrStat )
! This routine allocates a 1-D INTEGER array.
! Argument declarations.
INTEGER, ALLOCATABLE :: Ary (:) ! Array to be allocated
INTEGER, INTENT(IN) :: AryDim ! The size of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllIAry1 ! ( Ary, AryDim, Descr )
!=======================================================================
SUBROUTINE AllIAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat )
! This routine allocates a 2-D INTEGER array.
! Argument declarations.
INTEGER, ALLOCATABLE :: Ary (:,:) ! Array to be allocated
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllIAry2 ! ( Ary, AryDim1, AryDim2, Descr )
!=======================================================================
SUBROUTINE AllIAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat )
! This routine allocates a 3-D INTEGER array.
! Argument declarations.
INTEGER, ALLOCATABLE :: Ary (:,:,:) ! Array to be allocated
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(IN) :: AryDim3 ! The size of the third dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2,AryDim3) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllIAry3 ! ( Ary, AryDim1, AryDim2, AryDim3, Descr )
!=======================================================================
SUBROUTINE AllLAry1 ( Ary, AryDim, Descr, ErrStat )
! This routine allocates a 1-D LOGICAL array.
! Argument declarations.
INTEGER, INTENT(IN) :: AryDim ! The size of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
LOGICAL, ALLOCATABLE :: Ary (:) ! Array to be allocated
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllLAry1 ! ( Ary, AryDim, Descr )
!=======================================================================
SUBROUTINE AllLAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat )
! This routine allocates a 2-D LOGICAL array.
! Argument declarations.
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
LOGICAL, ALLOCATABLE :: Ary (:,:) ! Array to be allocated
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllLAry2 ! ( Ary, AryDim1, AryDim2, Descr )
!=======================================================================
SUBROUTINE AllLAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat )
! This routine allocates a 3-D LOGICAL array.
! Argument declarations.
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(IN) :: AryDim3 ! The size of the third dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
LOGICAL, ALLOCATABLE :: Ary (:,:,:) ! Array to be allocated
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2,AryDim3) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllLAry3 ! ( Ary, AryDim1, AryDim2, AryDim3, Descr )
!=======================================================================
SUBROUTINE AllRAry1 ( Ary, AryDim, Descr, ErrStat )
! This routine allocates a 1-D REAL array.
! Argument declarations.
REAL(ReKi), ALLOCATABLE :: Ary (:) ! Array to be allocated
INTEGER, INTENT(IN) :: AryDim ! The size of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllRAry1 ! ( Ary, AryDim, Descr )
!=======================================================================
SUBROUTINE AllRAry2 ( Ary, AryDim1, AryDim2, Descr, ErrStat )
! This routine allocates a 2-D REAL array.
! Argument declarations.
REAL(ReKi), ALLOCATABLE :: Ary (:,:) ! Array to be allocated
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllRAry2 ! ( Ary, AryDim1, AryDim2, Descr )
!=======================================================================
SUBROUTINE AllRAry3 ( Ary, AryDim1, AryDim2, AryDim3, Descr, ErrStat )
! This routine allocates a 3-D REAL array.
! Argument declarations.
REAL(ReKi), ALLOCATABLE :: Ary (:,:,:) ! Array to be allocated
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(IN) :: AryDim3 ! The size of the third dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2,AryDim3) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllRAry3 ! ( Ary, AryDim1, AryDim2, AryDim3, Descr )
!=======================================================================
SUBROUTINE AllRAry4 ( Ary, AryDim1, AryDim2, AryDim3, AryDim4, Descr, ErrStat )
! This routine allocates a 4-D REAL array.
! Argument declarations.
REAL(ReKi), ALLOCATABLE :: Ary (:,:,:,:) ! Array to be allocated
INTEGER, INTENT(IN) :: AryDim1 ! The size of the first dimension of the array.
INTEGER, INTENT(IN) :: AryDim2 ! The size of the second dimension of the array.
INTEGER, INTENT(IN) :: AryDim3 ! The size of the third dimension of the array.
INTEGER, INTENT(IN) :: AryDim4 ! The size of the fourth dimension of the array.
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
CHARACTER(*), INTENT(IN) :: Descr ! Brief array description.
! Local declarations.
INTEGER :: Sttus ! Status of allocation attempt.
ALLOCATE ( Ary(AryDim1,AryDim2,AryDim3,AryDim4) , STAT=Sttus )
IF ( Sttus /= 0 ) THEN
CALL ProgAbort ( ' Error allocating memory for the '//TRIM( Descr )//' array.', PRESENT(ErrStat) )
END IF
IF ( PRESENT(ErrStat) ) ErrStat = Sttus
RETURN
END SUBROUTINE AllRAry4 ! ( Ary, AryDim1, AryDim2, AryDim3, AryDim4, Descr )
!=======================================================================
SUBROUTINE CheckArgs ( InputFile, ErrStat )
! This subroutine is used to check for command-line arguments.
! Argument declarations:
INTEGER, INTENT(OUT),OPTIONAL:: ErrStat ! Error status; if present, program does not abort on error
!bjj: I made this INOUT instead of OUT so that a default input name can be used
!bjj: MLB requests no default InputFile names be allowed; generate error when there is InputFile listed
!Thus, change to
! CALL WrScr1 ( ' '//TRIM( ProgName )//' ['//SwChar//'h] <InputFile>' )
! and add error when NumArg == 0
CHARACTER(*), INTENT(INOUT) :: InputFile ! The name of the input file specified on the command line.
! Local declarations:
INTEGER :: IArg ! The argument number.
INTEGER :: NumArg ! The number of arguments on the command line.
LOGICAL :: Error ! Flag indicating if there was an error getting an argument.
CHARACTER(LEN(InputFile)) :: Arg ! A command-line argument.
! Find out how many arguments were entered on the command line.
CALL Get_Arg_Num ( NumArg )
! Parse them.
IF ( NumArg .GT. 0 ) THEN
DO IArg=1,NumArg
CALL Get_Arg ( IArg , Arg , Error )
IF ( Error ) THEN
CALL ProgAbort ( ' Error getting command-line argument #'//TRIM( Int2LStr( IArg ) )//'.', PRESENT(ErrStat) )
IF ( PRESENT(ErrStat) ) THEN
ErrStat = 1
RETURN
END IF
END IF
IF ( Arg(1:1) == SwChar ) THEN
CALL WrScr1 ( ' Syntax is:' )
IF ( LEN_TRIM( InputFile ) == 0 ) THEN
CALL WrScr1 ( ' '//TRIM( ProgName )//' ['//SwChar//'h] <InputFile>' )
CALL WrScr1 ( ' where:' )
CALL WrScr1 ( ' '//SwChar//'h generates this help message.' )
CALL WrScr ( ' <InputFile> is the name of the required primary input file.' )
ELSE
CALL WrScr1 ( ' '//TRIM( ProgName )//' ['//SwChar//'h] [<InputFile>]' )
CALL WrScr1 ( ' where:' )
CALL WrScr1 ( ' '//SwChar//'h generates this help message.' )
CALL WrScr ( ' <InputFile> is the name of the primary input file. If omitted, the default file is "' &
//TRIM( InputFile )//'".' )
END IF
CALL WrScr ( ' ')
IF ( INDEX( 'Hh?', Arg(2:2) ) > 0 ) THEN
IF ( PRESENT(ErrStat) ) THEN
ErrStat = -1
RETURN
ELSE
CALL ProgExit ( 1 )
END IF
ELSE
CALL ProgAbort ( ' Invalid command-line switch "'//SwChar//TRIM( Arg(2:) )//'".', PRESENT(ErrStat) )
IF ( PRESENT(ErrStat) ) THEN
ErrStat = 1
RETURN
END IF
END IF ! ( INDEX( 'Hh?', Arg(2:2) ) > 0 )
ELSE
InputFile = Arg
END IF ! ( Arg(1:1) == SwChar )
END DO ! IArg
END IF ! ( NumArg .GT. 0 )
IF ( PRESENT( ErrStat ) ) ErrStat = 0
RETURN
END SUBROUTINE CheckArgs
!=======================================================================
SUBROUTINE ChkRealFmtStr ( RealFmt, RealFmtVar, FmtWidth, ErrStat, ErrMsg )
! Test to make sure we have a valid format string for real numbers.
! Argument declarations.
INTEGER(IntKi), INTENT(OUT) :: ErrStat ! An error level to be returned to the calling routine.
INTEGER(IntKi), INTENT(OUT) :: FmtWidth ! The number of characters that will result from writes.
CHARACTER(*), INTENT(OUT) :: ErrMsg ! An error message to be returned to the calling routine.
CHARACTER(*), INTENT(IN) :: RealFmt ! The proposed format string.
CHARACTER(*), INTENT(IN) :: RealFmtVar ! The name of the variable storing the format string.
! Local delarations.
REAL, PARAMETER :: TestVal = -1.0 ! The value to test the format specifier with.
INTEGER :: IOS ! An integer to store the I/O status of the attempted internal write.
INTEGER, PARAMETER :: TestStrLen = 20 ! A parameter for specifying the length of RealStr.
CHARACTER(TestStrLen) :: RealStr ! A string to test writing a real number to.
! Try writing TestVal to RealStr using RealFmt as the format.
! Determine the format width.
WRITE (RealStr,'('//RealFmt//')',IOSTAT=IOS) TestVal
FmtWidth = Len_Trim( RealStr )
! Check to see if the format is invalid or if it did not have even a reasonable width.
IF ( IOS /= 0 ) THEN
ErrStat = ErrID_Fatal
ErrMsg = ' The real-format specifier, '//TRIM(RealFmtVar)//', is invalid. You set it to "'//TRIM( RealFmt )//'".'
FmtWidth = 0
ELSEIF ( INDEX( RealStr, '*' ) > 0 ) THEN
ErrStat = ErrID_Severe
ErrMsg = ' The real-format specifier, '//TRIM(RealFmtVar)//', is too narrow to print even '//TRIM(Num2LStr(TestVal)) &
//'. You set it to "'//TRIM( RealFmt )//'".'
ELSE
ErrStat = ErrID_None
ErrMsg = ' I put this in here just to be silly. Will it still be here in 100 years? - MLB, 07-January-2013'
ENDIF
RETURN
END SUBROUTINE ChkRealFmtStr ! ( RealFmt, TrapErrors )
!=======================================================================
SUBROUTINE CheckIOS ( IOS, Fil, Variable, VarType, TrapErrors )
! This routine checks the I/O status and prints either an end-of-file or
! an invalid-input message, and then aborts the program.
! Argument declarations.
INTEGER, INTENT(IN) :: IOS ! I/O status.
INTEGER, INTENT(IN) :: VarType ! Type of variable.
LOGICAL, INTENT(IN), OPTIONAL:: TrapErrors ! Determines if the program should abort or return to calling function
LOGICAL :: TrapThisError ! The local version of TrapErrors
CHARACTER(*), INTENT(IN) :: Fil ! Name of input file.
CHARACTER(*), INTENT(IN) :: Variable ! Variable name.
IF ( PRESENT( TrapErrors ) ) THEN
TrapThisError = TrapErrors
ELSE
TrapThisError = .FALSE.
END IF
IF ( IOS < 0 ) THEN
CALL PremEOF ( TRIM( Fil ), Variable, TrapThisError )
ELSE IF ( IOS > 0 ) THEN
SELECTCASE ( VarType )
CASE ( NumType )
CALL WrScr1 ( ' Invalid numerical input for file "'//TRIM( Fil )//'".' )
CASE ( FlgType )
CALL WrScr1 ( ' Invalid logical input for file "'//TRIM( Fil )//'".' )
CASE ( StrType )
CALL WrScr1 ( ' Invalid character input for file "'//TRIM( Fil )//'".' )
ENDSELECT
CALL ProgAbort ( ' The error occurred while trying to read '//TRIM( Variable )//'.', TrapThisError )
END IF
RETURN
END SUBROUTINE CheckIOS ! ( IOS, Fil, Variable, VarType )
!=======================================================================
SUBROUTINE CloseEcho( )
! This subroutine closes the echo file and sets Echo to false
CLOSE ( UnEc )
Echo = .FALSE.
END SUBROUTINE CloseEcho
!=======================================================================
SUBROUTINE Conv2UC ( Str )
! This routine converts all the text in a string to upper case.
! Argument declarations.
CHARACTER(*), INTENT(INOUT) :: Str ! The string to be converted to UC.
! Local declarations.
INTEGER :: IC ! Character index
DO IC=1,LEN_TRIM( Str )
IF ( ( Str(IC:IC) >= 'a' ).AND.( Str(IC:IC) <= 'z' ) ) THEN
Str(IC:IC) = CHAR( ICHAR( Str(IC:IC) ) - 32 )
ELSE
Str(IC:IC) = Str(IC:IC)
END IF
END DO ! IC
RETURN
END SUBROUTINE Conv2UC ! ( Str )
!=======================================================================
FUNCTION CountWords ( Line )
! This subroutine is used to count the number of "words" in a line of text.
! It uses spaces, tabs, commas, semicolons, single quotes, and double quotes ("whitespace")
! as word separators.
! Function declaration.
INTEGER :: CountWords ! This function.
! Argument declarations.
CHARACTER(*), INTENT(IN) :: Line ! Count the words in this text string.
! Local declarations.
INTEGER :: Ch ! Character position.
INTEGER :: NextWhite ! Position of the next white space.
! Let's initialize the number of columns and the character pointer.
CountWords = 0
! Let's make sure we have text on this line.
IF ( LEN_TRIM( Line ) == 0 ) RETURN
! Count words separated by any combination of spaces, tabs, commas,
! semicolons, single quotes, and double quotes ("whitespace").
Ch = 0
DO
NextWhite = SCAN( Line(Ch+1:) , ' ,;''"'//Tab )
Ch = Ch + NextWhite
IF ( NextWhite > 1 ) THEN
CountWords = CountWords + 1
ELSE IF ( NextWhite == 1 ) THEN
CYCLE
ELSE
EXIT
END IF
END DO