-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsproc.f90
18298 lines (16458 loc) · 593 KB
/
tsproc.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
! Last change: JD 26 Aug 2003 1:42 pm
MODULE DEFN
! -- File DEFN.F90 contains definitions for defined types and global variables.
!****************************************************************************
! defined types
!****************************************************************************
type modelgrid
integer :: nrow,ncol
double precision :: east_corner,north_corner,rotation
real :: cosang,sinang
real, dimension(:), pointer :: delr,delc
integer :: specunit,specline
character (len=80) :: specfile
end type modelgrid
!****************************************************************************
!global variables
!****************************************************************************
!variables for reading a file ------->
integer, parameter :: NUM_WORD_DIM=1000
integer, dimension(NUM_WORD_DIM) :: left_word,right_word
character (len=3000) :: cline
!variables for writing a message ------->
integer :: imessage=0
character (len=500) :: amessage= ' '
character (len=200) :: initial_message=' '
!escape variables ------->
integer :: escset=0
character (len=5) :: eschar = 'E ~e '
!variables in bore data manipulation ------->
integer :: num_bore_coord, num_bore_list
character (len=120) :: bore_coord_file, bore_list_file
integer, dimension(:), pointer :: bore_coord_layer
double precision, dimension(:), pointer :: bore_coord_east, &
bore_coord_north
character (len=10), dimension(:), pointer :: bore_coord_id, &
bore_list_id
!variables recording data settings ------->
integer :: datespec
END MODULE DEFN
! Last change: JD 24 Aug 2001 2:49 pm
MODULE INTER
! -- Contains interface blocks for all subprograms.
!******************************************************************************
! generic subprograms
!******************************************************************************
interface char2num
subroutine a2i(ifail,string,num)
integer, intent(out) :: ifail
character (len=*), intent(in) :: string
integer, intent(out) :: num
end subroutine a2i
subroutine a2r(ifail,string,num)
integer, intent(out) :: ifail
character (len=*), intent(in) :: string
real, intent(out) :: num
end subroutine a2r
subroutine a2d(ifail,string,num)
integer, intent(out) :: ifail
character (len=*), intent(in) :: string
double precision, intent(out) :: num
end subroutine a2d
end interface
interface num2char
subroutine i2a(value,string,nchar)
integer, intent(in) :: value
character (len=*), intent(out):: string
integer, intent(in), optional :: nchar
end subroutine i2a
subroutine r2a(value,string,nchar)
real, intent(in) :: value
character (len=*), intent(out):: string
integer, intent(in), optional :: nchar
end subroutine r2a
subroutine d2a(value,string,nchar)
double precision, intent(in) :: value
character (len=*), intent(out):: string
integer, intent(in), optional :: nchar
end subroutine d2a
end interface
interface pos_test
integer function pos_i_test(value,string)
integer, intent(in) :: value
character (len=*), intent(in) :: string
end function pos_i_test
integer function pos_r_test(value,string)
real, intent(in) :: value
character (len=*), intent(in) :: string
end function pos_r_test
integer function pos_d_test(value,string)
double precision, intent(in) :: value
character (len=*), intent(in) :: string
end function pos_d_test
end interface
interface nneg_test
integer function nneg_i_test(value,string)
integer, intent(in) :: value
character (len=*), intent(in) :: string
end function nneg_i_test
integer function nneg_r_test(value,string)
real, intent(in) :: value
character (len=*), intent(in) :: string
end function nneg_r_test
integer function nneg_d_test(value,string)
double precision, intent(in) :: value
character (len=*), intent(in) :: string
end function nneg_d_test
end interface
interface key_read
integer function int_key_read(value)
integer,intent(out) :: value
end function int_key_read
integer function real_key_read(value)
real,intent(out) :: value
end function real_key_read
integer function double_key_read(value)
double precision,intent(out) :: value
end function double_key_read
end interface
interface equals
logical function equals_int(r1,r2)
integer, intent(in) :: r1
integer, intent(in) :: r2
end function equals_int
logical function equals_real(r1,r2)
real, intent(in) :: r1
real, intent(in) :: r2
end function equals_real
logical function equals_dbl(r1,r2)
real (kind (1.0d0)), intent(in) :: r1
real (kind (1.0d0)), intent(in) :: r2
end function equals_dbl
end interface
interface swr
subroutine read_swr_binary_mul(ifail,jseries,irchgrpnum,ifiletype,idataidx, &
jjseries,afile,aname,yy,mm,dd,hh,nn,ss, &
begdays,begsecs)
integer, intent(out) :: ifail
integer, intent(in) :: jseries
integer, intent(in),dimension(jseries) :: irchgrpnum
integer, intent(in) :: ifiletype
integer, intent(in) :: idataidx
integer, intent(in) :: yy,mm,dd,hh,nn,ss,begdays,begsecs
integer, intent(in),dimension(jseries) :: jjseries
character (len=120),intent(in) :: afile
character (len=10), intent(in), dimension(:) :: aname
end subroutine read_swr_binary_mul
end interface
!******************************************************************************
! other subprograms
!******************************************************************************
! utility subprograms ------->
interface
subroutine casetrans(string,hi_or_lo)
character (len=*), intent(inout) :: string
character (len=*), intent(in) :: hi_or_lo
end subroutine casetrans
subroutine sub_error(subname)
character (len=*) ::subname
end subroutine sub_error
integer function nextunit()
end function nextunit
subroutine close_files
end subroutine close_files
subroutine open_input_file(ifail,aprompt,infile,inunit,file_format)
integer, intent(out) :: ifail
character (len=*), intent(in) :: aprompt
character (len=*), intent(out) :: infile
integer, intent(out) :: inunit
character (len=*), intent(in), optional :: file_format
end subroutine open_input_file
subroutine open_named_input_file(ifail,aprompt,infile,inunit)
integer, intent(out) :: ifail
character (len=*), intent(in) :: aprompt
character (len=*), intent(inout) :: infile
integer, intent(out) :: inunit
end subroutine open_named_input_file
subroutine open_output_file(ifail,aprompt,outfile,outunit)
integer, intent(out) :: ifail
character (len=*) :: aprompt,outfile
integer, intent(out) :: outunit
end subroutine open_output_file
subroutine readfig(specfile,coordfile,sampfile,pumpfile,pilotfile)
character (len=*), intent(out) :: specfile
character (len=*), intent(out), optional :: coordfile,sampfile,&
pumpfile,pilotfile
end subroutine readfig
subroutine read_settings(ifail,idate)
integer, intent(out) :: ifail,idate
end subroutine read_settings
subroutine char_add(astring,achar)
character (len=*), intent(inout) :: astring
character (len=*), intent(in) :: achar
end subroutine char_add
subroutine int2alph(inum,alph,nsig)
integer, intent(in) :: inum
character (len=*), intent(out) :: alph
integer, optional, intent(in) :: nsig
end subroutine int2alph
logical function isspace(astring)
character (len=*), intent(in) :: astring
end function isspace
subroutine repchar(astring,substring,replacement)
character (len=*), intent(inout) :: astring
character (len=*), intent(in) :: substring
character (len=*), intent(in) :: replacement
end subroutine
end interface
! reading-a-file subprograms ------->
interface
subroutine linesplit(ifail,num)
integer, intent(out) :: ifail
integer, intent(in) :: num
end subroutine linesplit
integer function char2int(ifail,num)
integer, intent(in) :: num
integer, intent(out) :: ifail
end function char2int
real function char2real(ifail,num)
integer, intent(in) :: num
integer, intent(out) :: ifail
end function char2real
double precision function char2double(ifail,num)
integer, intent(in) :: num
integer, intent(out) :: ifail
end function char2double
subroutine getfile(ifail,cline,filename,ibeg,iend)
integer, intent(out) :: ifail
integer, intent(in) :: ibeg
integer, intent(inout) :: iend
character (len=*), intent(in) :: cline
character (len=*), intent(out) :: filename
end subroutine getfile
subroutine addquote(afile,aqfile)
character (len=*), intent(in) :: afile
character (len=*), intent(out) :: aqfile
end subroutine addquote
end interface
! message subprograms ------->
interface
subroutine write_initial_message(leadspace,endspace)
character (len=*), intent(in), optional :: leadspace,endspace
end subroutine write_initial_message
subroutine write_message(increment,iunit,error,leadspace,endspace)
integer, intent(in), optional ::increment,iunit
character (len=*), intent(in), optional ::error,leadspace,endspace
end subroutine write_message
end interface
! site data manipulation subprograms ------->
interface
subroutine read_rest_of_sample_line(ifail,cols,ndays,nsecs,value, &
iline,sampfile)
integer, intent(out) :: ifail
integer, intent(in) :: cols
integer, intent(out) :: ndays,nsecs
double precision, intent(out) :: value
integer, intent(in) :: iline
character (len=*), intent(in) :: sampfile
end subroutine read_rest_of_sample_line
subroutine time_interp(ifail,nbore,ndays,nsecs,value,intday, &
intsec,rnear,rconst,valinterp,extrap,direction,startindex)
integer, intent(out) :: ifail
integer, intent(in) :: nbore
integer, intent(in), dimension(nbore) :: ndays,nsecs
double precision, intent(in), dimension(nbore) :: value
integer, intent(in) :: intday,intsec
real, intent(in) :: rnear,rconst
double precision, intent(out) :: valinterp
character (len=*), intent(in),optional :: extrap
character (len=*), intent(in),optional :: direction
integer, intent(inout), optional :: startindex
end subroutine time_interp
subroutine get_num_ids(ifail,iunit,afile,numid,maxsamp,ignore_x)
integer, intent(out) :: ifail
integer, intent(in) :: iunit
character (len=*), intent(in) :: afile
integer, intent(out) :: numid,maxsamp
character (len=*), intent(in), optional :: ignore_x
end subroutine get_num_ids
subroutine get_ids_and_interval(ifail,iunit,afile,nid,aid,ndays1, &
nsecs1,ndays2,nsecs2, ignore_x)
integer, intent(out) :: ifail
integer, intent(in) :: iunit
character (len=*), intent(in) :: afile
integer, intent(in) :: nid
character (len=*), intent(out) :: aid(nid)
integer, intent(out) :: ndays1(nid),nsecs1(nid), &
ndays2(nid),nsecs2(nid)
character (len=*), intent(in), optional :: ignore_x
end subroutine get_ids_and_interval
subroutine volume_interp(ifail,num,days,secs,flows,bdays,bsecs, &
fdays,fsecs,vol,fac)
integer, intent(out) :: ifail
integer, intent(in) :: num
integer, intent(in) :: days(num),secs(num)
double precision, intent(in) :: flows(num)
integer, intent(in) :: bdays,bsecs,fdays,fsecs
double precision, intent(out) :: vol
double precision, intent(in) :: fac
end subroutine volume_interp
end interface
! date manipulation subprograms ------->
interface
subroutine char2date(ifail,adate,dd,mm,yy)
integer, intent(out) :: ifail
character (len=*), intent(in) :: adate
integer, intent(out) :: dd,mm,yy
end subroutine char2date
subroutine datestring(dd,mm,yy,hhh,mmm,sss,time,at,adate,atime)
integer, intent(in) :: dd,mm,yy,hhh,mmm,sss
real, intent(in) :: time
character (len=1), intent(in) :: at
character (len=*), intent(out) :: adate, atime
end subroutine datestring
logical function leap(year)
integer, intent(in) :: year
end function leap
integer function numdays(dr,mr,yr,d,m,y)
integer, intent(in) :: dr,mr,yr,d,m,y
end function numdays
integer function numsecs(h1,m1,s1,h2,m2,s2)
integer, intent(in) :: h1,m1,s1,h2,m2,s2
end function numsecs
subroutine char2time(ifail,adate,hh,mm,ss,ignore_24)
integer, intent(out) :: ifail
character (len=*), intent(in) :: adate
integer, intent(out) :: hh,mm,ss
integer, optional,intent(in) :: ignore_24
end subroutine char2time
subroutine time2char(ifail,hh,mm,ss,atime)
integer, intent(out) :: ifail
integer, intent(in) :: hh,mm,ss
character (len=*), intent(out) :: atime
end subroutine time2char
subroutine elapsdate(eltime,dayfactor,day1,mon1,year1,hour1,min1,sec1,&
day2,mon2,year2,hour2,min2,sec2)
real, intent(in) :: eltime,dayfactor
integer, intent(in) :: day1,mon1,year1,hour1,min1,sec1
integer, intent(out) :: day2,mon2,year2,hour2,min2,sec2
end subroutine elapsdate
subroutine newdate(ndays,day1,mon1,year1,day2,mon2,year2)
integer, intent(in) :: ndays,day1,mon1,year1
integer, intent(out) :: day2,mon2,year2
end subroutine newdate
subroutine sectime(nsecs,sec,min,hour)
integer, intent(in) :: nsecs
integer, intent(out) :: sec,min,hour
end subroutine sectime
end interface
END MODULE INTER
! Last change: J 9 Sep 2004 5:38 pm
module tspvar
integer, parameter :: MAXSERIES=100000
integer, parameter :: MAXSERIESREAD=50
integer, parameter :: MAXSTABLE=300
integer, parameter :: MAXCTABLE=500
integer, parameter :: MAXCONTEXT=5
integer, parameter :: MAXVTABLE=500
integer, parameter :: MAXDTABLE=100
integer, parameter :: MAXTEMPDURFLOW=300
integer, parameter :: MAXTEMPFILE=200
integer, parameter :: MAXPAR=50000
integer, parameter :: MAXCONST=5000
! character, parameter :: OBSCHAR='#'
character, parameter :: OBSCHAR='_'
type time_series
logical active
integer nterm
character*2 type
character*10 name
integer, dimension(:), pointer :: days
integer, dimension(:), pointer :: secs
real, dimension(:), pointer :: val
end type time_series
type s_table
logical active
character*10 name
character*10 series_name
real maximum
real minimum
real range
real mean
real stddev
real total
real minmean
real maxmean
real rec_power
integer rec_icount
integer rec_itrans
integer rec_begdays
integer rec_begsecs
integer rec_enddays
integer rec_endsecs
integer avetime
end type s_table
type c_table
logical active
character*10 name
character*10 series_name_obs
character*10 series_name_sim
real bias
real se
real rbias
real rse
real ns
real ce
real ia
integer rec_icount
integer rec_begdays
integer rec_begsecs
integer rec_enddays
integer rec_endsecs
end type c_table
type v_table
logical active
character*10 name
character*10 series_name
integer nterm
integer, dimension(:), pointer :: days1
integer, dimension(:), pointer :: secs1
integer, dimension(:), pointer :: days2
integer, dimension(:), pointer :: secs2
real, dimension(:), pointer :: vol
end type v_table
type d_table
logical active
character*10 name
character*10 series_name
character*7 time_units
integer under_over
integer nterm
real total_time
real, dimension(:), pointer :: flow
real, dimension(:), pointer :: tdelay
real, dimension(:), pointer :: time
end type d_table
type constants
character*25 name
logical active
real value
end type constants
type (time_series) tempseries
type (time_series) series(MAXSERIES)
type (s_table) stable(MAXSTABLE)
type (c_table) ctable(MAXCTABLE)
type (v_table) vtable(MAXVTABLE)
type (d_table) tempdtable
type (d_table) dtable(MAXDTABLE)
type (constants) const(MAXCONST)
integer inunit,recunit,outunit
integer NumProcBlock,ILine,IProcSetting
character*25 Context
character*40 CurrentBlock
character*120 infile,recfile,outfile,astring
! -- The following variables are global because they are used to exchange information
! between the LIST_OUTPUT block and the WRITE_PEST_FILES block.
integer imseries
integer imstable
integer imctable
integer imvtable
integer imdtable
integer outseries(MAXSERIES),outstable(MAXSTABLE),outvtable(MAXVTABLE), &
outdtable(MAXDTABLE),outctable(MAXCTABLE)
character*10 series_format
character*120 list_output_file
! -- Following are some parameter definitions related to equations.
! -- Maximum terms in any mathematical expression:-
integer MAXTERM
parameter(MAXTERM=200)
! -- Maximum number of function types:-
integer NFUNCT
parameter(NFUNCT=16)
! -- Maximum number of operators:-
integer NOPER
parameter(NOPER=7)
! -- Maximum number of series names in a series equation:-
integer MAXEQNSER
parameter (MAXEQNSER=25)
integer iorder(MAXTERM)
character*1 operat(7)
character*6 funct(NFUNCT)
character*28 aterm(MAXTERM),bterm(MAXTERM),cterm(MAXTERM)
double precision rterm(MAXTERM), qterm(MAXTERM)
data funct /'abs ','acos ','asin ','atan ','cos ','cosh ', &
'exp ','log ','log10 ','sin ','sinh ','sqrt ','tan ', &
'tanh ','neg ','pos '/
data operat /'^','/','*','-','+','(',')'/
! -- The following pertain to WDM files.
integer MAXWDOPN
parameter (MAXWDOPN=10) ! Number of WDM files that can be open.
integer iwdopn
integer wdmun(MAXWDOPN)
character*120 wdmfil(MAXWDOPN)
end module
! Last change: J 9 Sep 2004 10:05 pm
program tsproc
! -- Program TSPROC is a general time-series processor. It can also be used for
! PEST input file preparation.
use defn
use inter
use tspvar
implicit none
integer ifail,idate,ierr,nbb,iBlock,i,lastblock
character*120 afile
!open(unit=*,carriagecontrol='list')
open(unit=11,carriagecontrol='list')
! -- Initialisation
write(amessage,5)
5 format(' Program TSPROC is a general time-series processor. It can ', &
'also be used for PEST input file preparation where time series data, ', &
'or processed time series data, comprises at least part of the observation ',&
'dataset.')
call write_message(leadspace='yes',endspace='yes')
! call read_settings(ifail,idate)
! if(ifail.eq.1) then
! write(amessage,7)
!7 format(' A settings file (settings.fig) was not found in the ', &
! 'current directory.')
! go to 9890
! else if(ifail.eq.2) then
! write(amessage,8)
!8 format(' Error encountered while reading settings file settings.fig')
! go to 9890
! endif
! if((idate.ne.0).or.(datespec.eq.0)) then
! write(amessage,9)
!9 format(' Cannot read date format from settings file ', &
! 'settings.fig')
! go to 9890
! end if
! -- Some variables are initialised
series%active=.false. !series is an array
stable%active=.false. !stable is an array
vtable%active=.false. !vtable is an array
dtable%active=.false. !dtable is an array
ctable%active=.false. !ctable is an array
tempseries%active=.false.
const%active=.false.
tempdtable%active=.true.
allocate(tempdtable%flow(MAXTEMPDURFLOW), &
tempdtable%time(MAXTEMPDURFLOW), &
tempdtable%tdelay(MAXTEMPDURFLOW),stat=ierr)
if(ierr.ne.0)then
write(amessage,16)
16 format(' Cannot allocate sufficient memory to store temporary E_TABLE.')
go to 9890
end if
4 imessage=0
6 if(imessage.eq.5) go to 9900
11 write(6,15,advance='no')
15 format(' Enter name of TSPROC input file: ')
read(5,'(a)') infile
!infile = 'tsproc.dat'
if(infile.eq.' ') go to 11
infile=adjustl(infile)
if(index(eschar,infile(1:2)).ne.0) go to 9900
nbb=len_trim(infile)
call getfile(ifail,infile,afile,1,nbb)
if(ifail.ne.0) go to 11
infile=afile
! call casetrans(infile,'hi')
inunit=nextunit()
open(unit=inunit,file=infile,status='old',iostat=ierr)
if(ierr.ne.0) then
call addquote(infile,astring)
write(amessage,20) trim(astring)
20 format(' Cannot open file ',a,' - try again.')
call write_message(increment=1)
go to 6
end if
imessage=0
100 call open_output_file(ifail, &
' Enter name for TSPROC run record file: ',recfile,recunit)
if(ifail.ne.0) go to 9900
if(escset.ne.0)then
escset=0
close(unit=inunit)
write(*,*)
go to 4
end if
! -- More variables are initialised.
imessage=0
NumProcBlock=0
ILine=0
IProcSetting=0
Context=' '
tempseries%nterm=0
call addquote(infile,astring)
write(*,110) trim(astring)
write(recunit,110) trim(astring)
110 format(/,' Processing information contained in TSPROC input file ',a,'....')
! -- The TSPROC input file is now read, looking for Blocks.
120 continue
call GetNextBlock(ifail,iblock)
if(ifail.ne.0) go to 9900
if(iblock.eq.0) then ! settings
call process_settings(ifail)
else if(iblock.eq.101)then ! get series from WDM file
call get_wdm_series(ifail)
else if(iblock.eq.102)then ! get series from site sample file
call get_ssf_series(ifail)
else if(iblock.eq.103)then ! get series from PLOTGEN file
call get_plt_series(ifail)
else if(iblock.eq.104)then ! get series from TETRAD output file
call get_mul_series_tetrad(ifail)
else if(iblock.eq.105)then ! get multiple series from site sample file
call get_mul_series_ssf(ifail)
else if(iblock.eq.106)then ! get series from UFORE-HYDRO file
call get_ufore_series(ifail)
else if(iblock.eq.107)then ! get multiple series from a GSFLOW gage file
call get_mul_series_gsflow_gage(ifail)
else if(iblock.eq.108)then ! get multiple series from a MMS/GSFLOW STATVAR file
call get_mul_series_statvar(ifail)
else if(iblock.eq.120)then ! get series from SWR1 binary output
call get_swr_series(ifail)
else if (iblock.eq.121)then ! get a list of constants from an external file
call get_constants(ifail)
else if (iblock.eq.122)then ! get multiple series(reachgroups) from SWR1 binary file
call get_mul_swr_series(ifail)
else if(iblock.eq.201)then ! write list output file
call write_list_output(ifail)
else if(iblock.eq.301)then ! erase entity from memory
call erase_entity(ifail)
else if(iblock.eq.302)then ! reduce time_span of series
call reduce_span(ifail)
else if(iblock.eq.303)then ! calculate series statistics
call statistics(ifail)
else if(iblock.eq.304)then ! series comparison statistics
call compare_series(ifail)
else if(iblock.eq.305)then ! change time_base
call time_base(ifail)
else if(iblock.eq.306)then ! volume calculation
call volume(ifail)
else if(iblock.eq.308)then ! exceedence time
call time_duration(ifail)
else if(iblock.eq.310)then ! series equation
call equation(ifail)
else if(iblock.eq.311)then ! series displace
call displace(ifail)
else if(iblock.eq.312)then ! series clean
call series_clean(ifail)
else if(iblock.eq.313)then ! digital filter
call bfilter(ifail)
else if(iblock.eq.314)then ! series base level
call series_base_level(ifail)
else if(iblock.eq.315)then ! volume to series
call vol_to_series(ifail)
else if(iblock.eq.316)then ! moving minimum
call moving_window(ifail)
else if(iblock.eq.317)then ! new uniform series
call new_series_uniform(ifail)
else if(iblock.eq.318)then ! series difference
call series_difference(ifail)
else if(iblock.eq.319)then ! series block drawdown
call series_block_drawdown(ifail)
else if(iblock.eq.320)then ! series time average
call series_time_average(ifail)
else if(iblock.eq.321)then
call displace_constant(ifail)
else if(iblock.eq.401)then ! write pest files
call pest_files(ifail,lastblock)
end if
if(ifail.ne.0) go to 9900
lastblock=iblock
go to 120
9890 call write_message(leadspace='yes')
9900 call close_files
do i=1,MAXSERIES
if(series(i)%active)then
deallocate(series(i)%days,series(i)%secs,series(i)%val,stat=ierr)
if(associated(series(i)%days)) nullify(series(i)%days)
if(associated(series(i)%secs)) nullify(series(i)%secs)
if(associated(series(i)%val)) nullify(series(i)%val)
end if
end do
if(tempseries%active)then
deallocate(tempseries%days,tempseries%secs,tempseries%val,stat=ierr)
if(associated(tempseries%days)) nullify(tempseries%days)
if(associated(tempseries%secs)) nullify(tempseries%secs)
if(associated(tempseries%val)) nullify(tempseries%val)
end if
do i=1,MAXVTABLE
if(vtable(i)%active)then
deallocate(vtable(i)%days1,vtable(i)%days2,vtable(i)%secs1, &
vtable(i)%secs2,vtable(i)%vol,stat=ierr)
if(associated(vtable(i)%days1)) nullify(vtable(i)%days1)
if(associated(vtable(i)%days2)) nullify(vtable(i)%days2)
if(associated(vtable(i)%secs1)) nullify(vtable(i)%secs1)
if(associated(vtable(i)%secs2)) nullify(vtable(i)%secs2)
if(associated(vtable(i)%vol)) nullify(vtable(i)%vol)
end if
end do
do i=1,MAXDTABLE
if(dtable(i)%active)then
deallocate(dtable(i)%time,dtable(i)%flow, &
dtable(i)%tdelay,stat=ierr)
if(associated(dtable(i)%time)) nullify(dtable(i)%time)
if(associated(dtable(i)%flow)) nullify(dtable(i)%flow)
if(associated(dtable(i)%tdelay)) nullify(dtable(i)%tdelay)
end if
end do
deallocate(tempdtable%time,tempdtable%flow,tempdtable%tdelay,stat=ierr)
nullify (tempdtable%time,tempdtable%flow,tempdtable%tdelay)
end program tsproc
subroutine GetNextBlock(ifail,iblock)
! -- Subroutine GetNextBlock obtains the header to the next section of
! the TSPROC input file.
use tspvar
use defn
use inter
implicit none
integer, intent(out) :: ifail,iblock
integer ierr
character*15 aline
character*30 ablock
ifail=0
call addquote(infile,astring)
do
iline=iline+1
read(inunit,'(a)',err=9000,end=500) cline
if(cline.eq.' ') cycle
if(cline(1:1).eq.'#')cycle
cline=adjustl(cline)
call linesplit(ierr,2)
if(ierr.ne.0)then
call num2char(iline,aline)
write(amessage,5) trim(aline),trim(astring)
5 format('two entries expected on line ',a,' of file ',a)
go to 9800
end if
ablock=cline(left_word(1):right_word(1))
call casetrans(ablock,'hi')
if(ablock.ne.'START')then
call num2char(iline,aline)
write(amessage,7) trim(aline),trim(astring)
7 format('first item on line ',a,' of file ',a,' expected to be START.')
go to 9800
end if
ablock=cline(left_word(2):right_word(2))
call casetrans(ablock,'hi')
if(ablock.eq.'SETTINGS')then
iBlock=0
else if(ablock.eq.'GET_SERIES_WDM')then
iBlock=101
else if(ablock.eq.'GET_SERIES_SSF')then
iBlock=102
else if(ablock.eq.'GET_SERIES_PLOTGEN')then
iBlock=103
else if(ablock.eq.'GET_SERIES_TETRAD')then
iBlock=104
else if(ablock.eq.'GET_MUL_SERIES_SSF')then
iBlock=105
else if(ablock.eq.'GET_SERIES_UFORE_HYDRO')then
iBlock=106
else if(ablock.eq.'GET_MUL_SERIES_GSFLOW_GAGE')then
iBlock=107
else if(ablock.eq.'GET_MUL_SERIES_STATVAR')then
iBlock=108
else if(ablock.eq.'GET_SERIES_SWR')then
iBlock=120
else if(ablock.eq.'GET_MUL_SERIES_SWR')then
iBlock=122
else if (ablock.eq.'GET_CONSTANTS')then
iBlock=121
else if(ablock.eq.'LIST_OUTPUT')then
iBlock=201
else if(ablock.eq.'ERASE_ENTITY')then
iblock=301
else if(ablock.eq.'REDUCE_TIME_SPAN')then
iblock=302
else if(ablock.eq.'SERIES_STATISTICS')then
iblock=303
else if(ablock.eq.'SERIES_COMPARE')then
iblock=304
else if(ablock.eq.'NEW_TIME_BASE')then
iblock=305
else if(ablock.eq.'VOLUME_CALCULATION')then
iblock=306
else if(ablock.eq.'EXCEEDENCE_TIME')then
iblock=308
else if(ablock.eq.'SERIES_EQUATION')then
iblock=310
else if(ablock.eq.'SERIES_DISPLACE')then
iblock=311
else if(ablock.eq.'SERIES_CLEAN')then
iblock=312
else if(ablock.eq.'DIGITAL_FILTER')then
iblock=313
else if(ablock.eq.'SERIES_BASE_LEVEL')then
iblock=314
else if(ablock.eq.'V_TABLE_TO_SERIES')then
iblock=315
else if(ablock.eq.'MOVING_MINIMUM')then
iblock=316
else if(ablock.eq.'NEW_SERIES_UNIFORM')then
iblock=317
else if(ablock.eq.'SERIES_DIFFERENCE')then
iblock=318
else if(ablock.eq.'SERIES_BLOCK_DRAWDOWN')then
iblock=319
else if(ablock.eq.'SERIES_TIME_AVERAGE')then
iblock=320
else if(ablock.eq.'SERIES_DISPLACE_CONSTANT')then
iblock=321
else if(ablock.eq.'WRITE_PEST_FILES')then
iblock=401
else
call num2char(iline,aline)
write(amessage,10) trim(ablock),trim(aline),trim(astring)
10 format(' Unrecognised block title "',a,'" at line ',a, &
' of TSPROC input file ',a)
call write_message(leadspace='yes')
call write_message(iunit=recunit,leadspace='yes')
ifail=1
return
end if
go to 400
end do
400 continue
numprocBlock=numprocBlock+1
if(iBlock.eq.0)then
if(IProcSetting.ne.0)then
write(amessage,525) trim(astring)
525 format('file ',a,' contains two SETTINGS blocks.')
go to 9800
else if(numprocBlock.ne.1)then
write(amessage,520)
520 format('SETTINGS block must be the first block in a TSPROC input file.')
go to 9800