-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathrdtrt.f90
More file actions
2343 lines (2301 loc) · 76.2 KB
/
rdtrt.f90
File metadata and controls
2343 lines (2301 loc) · 76.2 KB
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 m_rdtrt
!----- GPL ---------------------------------------------------------------------
!
! Copyright (C) Stichting Deltares, 2011-2026.
!
! This program is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation version 3.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program. If not, see <http://www.gnu.org/licenses/>.
!
! contact: delft3d.support@deltares.nl
! Stichting Deltares
! P.O. Box 177
! 2600 MH Delft, The Netherlands
!
! All indications and logos of, and references to, "Delft3D" and "Deltares"
! are registered trademarks of Stichting Deltares, and remain the property of
! Stichting Deltares. All rights reserved.
!
!-------------------------------------------------------------------------------
!
!
!!--description-----------------------------------------------------------------
use precision
!
! functions and subroutines
!
public rdtrt
public rdttar
public expblk
public dimtrt
public dittar
contains
subroutine rdtrt(lundia ,error ,lftrto ,dt , &
& kmax ,itimtt ,gdtrachy , &
& griddim ,dryflc ,mdfile_ptr,waqol , &
& ddbval ,d3d_tunit)
!
! Reads the dimensions ntrt, nttaru, nttarv
! Initializes nroupa
!
!!--pseudo code and references--------------------------------------------------
! NONE
!!--declarations----------------------------------------------------------------
use properties
use trachytopes_data_module
use grid_dimens_module, only: griddimtype
use dfparall
use system_utils, only: exifil
use MessageHandling
!
implicit none
!
! type(trachy_type),target :: gdtrachy
!
! The following list of pointer parameters is used to point inside the gdp structure
!
real(fp) , pointer :: alf_area_ser
real(fp) , pointer :: trtminh
real(fp) , pointer :: dttrt
integer , pointer :: iarea_avg
integer , pointer :: nodir
integer , pointer :: nroupa
integer , pointer :: nttaru
integer , pointer :: ntrt
integer , pointer :: max_cl
integer , pointer :: ntrtnrm
integer , pointer :: ntrtcrs
integer , pointer :: ntrtobs
integer , pointer :: n_q
integer , pointer :: n_zs
integer , pointer :: mfg
integer , pointer :: nfg
integer , pointer :: nlb
integer , pointer :: nub
integer , pointer :: nmlb
integer , pointer :: nmub
integer , pointer :: mlb
integer , pointer :: mub
integer , pointer :: mmax
integer , pointer :: nmax
integer , dimension(:,:) , pointer :: ittaru
integer , dimension(:) , pointer :: itrt_list
integer , dimension(:,:) , pointer :: ittdef
integer , dimension(:,:) , pointer :: ittlin
real(fp), dimension(:) , pointer :: fraccu_list
real(fp), dimension(:) , pointer :: rgcalu
real(fp), dimension(:) , pointer :: rttaru
real(fp), dimension(:,:) , pointer :: rttxyz
! real(fp), dimension(:) , pointer :: rttarv
real(fp), dimension(:,:) , pointer :: rttdef
real(fp), dimension(:,:) , pointer :: rttfu
! real(fp), dimension(:,:) , pointer :: rttfv
real(fp), dimension(:) , pointer :: rttacLin
real(fp), dimension(:) , pointer :: vegh2d
real(fp), dimension(:) , pointer :: vden2d
character(256) , pointer :: md_ttdfile ! Name of trachytopes definition file.
character(256) , pointer :: md_arlfile ! Name of trachytopes area definition file
type(trachy_type) , target :: gdtrachy
type (griddimtype), target , intent(in) :: griddim
real(fp) , intent(in) :: dryflc
type (tree_data) , pointer, intent(in) :: mdfile_ptr
logical , intent(in) :: waqol
real(fp) , intent(in) :: d3d_tunit ! d3d_tunit available for compatitibility with Delft3D
!
! Local parameters
!
integer, parameter :: IROUGH = 300
!
! Global variables
!
integer :: itimtt
integer :: itrtcrs
integer :: itrtobs
integer :: lundia
integer :: kmax
integer :: nmaxus
integer :: nmmax
integer :: ddbval
integer :: prev_trt_no ! previous trt_no for discharge/waterlevel dependent trachytopes
integer :: prev_trt_type ! previous type of discharge/waterlevel dependent trachytopes
logical :: error
logical :: lftrto
real(fp) :: dt
!
! Local variables
!
integer :: i
integer :: ibeg
integer :: icx
integer :: iend
integer :: iocond
integer :: istat
integer :: istr
integer :: it
integer :: itttmp
integer :: j
integer :: jdir
integer :: lfile
integer :: luntmp
integer :: m
integer :: m1
integer :: mll
integer :: mcurec
integer :: mtrt
integer :: mtrtnrm
integer :: mtrtcrs
integer :: mtrtobs
integer :: m_q
integer :: m_zs
integer :: n
integer :: n1
integer :: nll
integer :: nm
integer :: nrflds
integer, dimension(IROUGH) :: nropar
integer, dimension(MAXFLD) :: ifield
integer, dimension(MAXFLD) :: itype
integer, dimension(MAXFLD) :: lenchr
integer :: nmaxddb
logical :: lokay
logical :: lrcode
real(fp) :: rtimtt
real(fp), dimension(MAXFLD) :: rfield
character(30), dimension(MAXFLD) :: cfield
character(11) :: fmttmp
character(132) :: rec132
character(20) :: chulp
character(256) :: filtmp
character(256) :: msgtmp
character(6) :: keyw
character(20) :: txtput1
!
!! executable statements -------------------------------------------------------
!
alf_area_ser => gdtrachy%gen%alf_area_ser
trtminh => gdtrachy%gen%trtminh
iarea_avg => gdtrachy%gen%iarea_avg
nroupa => gdtrachy%gen%nroupa
ntrt => gdtrachy%gen%ntrt
ntrtnrm => gdtrachy%gen%ntrtnrm
ntrtcrs => gdtrachy%gen%ntrtcrs
ntrtobs => gdtrachy%gen%ntrtobs
max_cl => gdtrachy%gen%max_cl
n_q => gdtrachy%gen%n_q
n_zs => gdtrachy%gen%n_zs
nodir => gdtrachy%gen%nodir
md_ttdfile => gdtrachy%gen%md_ttdfile
dttrt => gdtrachy%gen%dttrt
itrt_list => gdtrachy%gen%itrt_list
fraccu_list => gdtrachy%gen%fraccu_list
!
nlb => griddim%nlb !WO - was gdp%d%nlb previously
nub => griddim%nub !
mlb => griddim%mlb !
mub => griddim%mub !
nmlb => griddim%nmlb !
nmub => griddim%nmub !
mfg => griddim%mfg !
nfg => griddim%nfg !
nmax => griddim%nmax
mmax => griddim%mmax
if (mod(nmax,2) == 1) then
nmaxus = nmax - 1
else
nmaxus = nmax
end if
nmaxddb = nmax + 2*ddbval
nmmax = nmaxddb*(mmax + 2*ddbval)
!nm = n + nmaxddb * (m - 1 + ddbval ) + ddbval
!(see call n_and_m_to_nm.f90 WO)
!
! n_m_to_nm => griddim%n_m_to_nm
!
!
! Allocate trachytope arrays that are used in main routines
!
if (.not. associated(gdtrachy%dir(1)%rttfu)) then
!
istat = 0
if (waqol) then
if (istat==0) allocate(gdtrachy%gen%vegh2d(nmlb:nmub), stat = istat)
if (istat==0) allocate(gdtrachy%gen%vden2d(nmlb:nmub), stat = istat)
vegh2d => gdtrachy%gen%vegh2d
vden2d => gdtrachy%gen%vden2d
vegh2d = 0.0_fp
vden2d = 0.0_fp
endif
!
do jdir = 1,nodir
if (istat==0) allocate(gdtrachy%dir(jdir)%rttfu(nmlb:nmub,kmax), stat = istat)
!
if (istat/=0) then
call SetMessage(LEVEL_ERROR, 'RDTRT: memory alloc error')
error = .true.
return
endif
!
! update local pointers
!
rttfu => gdtrachy%dir(jdir)%rttfu
md_arlfile => gdtrachy%dir(jdir)%md_arlfile
!
! initialize arrays
!
rttfu(nmlb:nmub,1:kmax) = 0.0_fp
!
end do
endif
!
! Initialize scalars
!
lftrto = .false.
itimtt = 1
iarea_avg = 1
alf_area_ser = 0.6_fp
!
! Read value of Trtrou, default NO
!
chulp = 'N'
call prop_get(mdfile_ptr, '*','Trtrou',chulp)
!
! set LFTRTO to TRUE if CHULP = Y/y
!
call small(chulp ,1 )
if (chulp=='y') lftrto = .true.
!
! if Trtrou turned out to be NO, don't look any further.
!
if (.not.lftrto) goto 9999
!
! Allocate trachytope arrays that are only used locally
!
istat = 0
if (.not. associated(gdtrachy%dir(1)%ittaru)) then
do jdir = 1,nodir
nttaru => gdtrachy%dir(jdir)%nttaru
allocate(gdtrachy%dir(jdir)%ittaru(nttaru,4) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%rgcalu(nmlb:nmub) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%rttaru(nttaru) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%rttxyz(nttaru,3) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%lin(2,nmlb:nmub) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%acLin(nmlb:nmub) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%blu_trt(nmlb:nmub) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%kcu_trt(nmlb:nmub) , stat = istat)
if (istat==0) allocate(gdtrachy%dir(jdir)%zsu_prev(nmlb:nmub) , stat = istat)
end do
! general
if (istat==0) allocate(gdtrachy%gen%ittdef(ntrt,2) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%rttdef(ntrt,nroupa) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%crs(ntrtcrs) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%obs(ntrtobs) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%table_zs(n_zs) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%table_q(n_q) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%rttdef_zs(n_zs,nroupa) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%rttdef_zs_slope(n_zs,nroupa) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%rttdef_zs_cross(n_zs,nroupa) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%ittdef_zs(n_zs) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%rttdef_q(n_q,nroupa) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%rttdef_q_slope(n_q,nroupa) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%rttdef_q_cross(n_q,nroupa) , stat = istat)
if (istat==0) allocate(gdtrachy%gen%ittdef_q(n_q) , stat = istat)
!
if (istat/=0) then
call SetMessage(LEVEL_ERROR, 'RDTRT: memory alloc error')
error = .true.
return
endif
!
! update local pointers
!
! general
md_ttdfile => gdtrachy%gen%md_ttdfile
ittdef => gdtrachy%gen%ittdef
rttdef => gdtrachy%gen%rttdef
!
do jdir = 1,nodir
!
ittlin => gdtrachy%dir(jdir)%lin
rttacLin => gdtrachy%dir(jdir)%acLin
! md_arlfile => gdtrachy%dir(jdir)%md_arlfile
if (jdir == 1) then
icx = nmaxddb ! nmax
else
icx = 1
end if
do m = 1,mmax
do n = 1,nmax
nm = n + nmaxddb * (m - 1 + ddbval ) + ddbval
ittlin(1,nm) = nm
ittlin(2,nm) = nm+icx
rttacLin(nm) = 0.5_fp
enddo
enddo
enddo
endif
!
call SetMessage(LEVEL_INFO, 'Start of trachytopes input')
!
! locate 'DtTrt' record for update time step
!
rtimtt = dt
call prop_get(mdfile_ptr, '*', 'DtTrt', rtimtt)
dttrt = rtimtt
!
! Check on multiple
itimtt = nint(rtimtt/dt)
if (abs(real(itimtt,fp)*dt-rtimtt) > (0.1_fp*dt)) then ! previously : if (dtn(itimtt, rtimtt, dt)) which is approximate - updates are preformed within 0.1 of dtmax, cf. Delft3D, WO)
call SetMessage(LEVEL_ERROR, 'RDTRT: Trachytope update time is not a multiple of the user time step' )
error = .true.
goto 9999
endif
if (abs(real(itimtt,fp)*dt) < (0.1_fp*dt)) then
call SetMessage(LEVEL_ERROR, 'RDTRT: Trachytope update time is smaller than the user time step' )
error = .true.
goto 9999
endif
!
txtput1 = 'DtTrt'
write (msgtmp, '(a,a,f7.3,a)') txtput1,': ',rtimtt*d3d_tunit,' seconds'
call SetMessage(LEVEL_INFO, msgtmp)
!
! Trtdef: trachytope definition file (must exist, no default)
!
filtmp = ' '
keyw = 'Trtdef'
call prop_get(mdfile_ptr, '*',keyw,filtmp)
md_ttdfile = filtmp
!
txtput1 = keyw
write (msgtmp, '(a,a,a)') txtput1,': ',trim(filtmp)
call SetMessage(LEVEL_INFO, msgtmp)
!
! keyword not found ?
!
if (filtmp == ' ') then
call SetMessage(LEVEL_ERROR, 'Missing value (or the keyword): '// keyw //' in file')
error = .true.
goto 9999
endif
!
! test file existence
!
lfile = index(filtmp, ' ')
if (lfile==0) lfile = 13
lfile = lfile - 1
if (.not.exifil(trim(filtmp), lundia)) then
!
! file does not exist !!
!
call SetMessage(LEVEL_ERROR, 'The specified file '// trim(filtmp) //' does not exist')
error = .true.
goto 9999
endif
!
! open trachytope definition file
!
open (newunit=luntmp, file = trim(filtmp), form = 'formatted', iostat = iocond, &
& status = 'old')
if (iocond/=0) then
call SetMessage(LEVEL_ERROR, 'Error while opening file '// trim(filtmp))
error = .true.
goto 9999
endif
!
! freeformatted file
! read records till end of file
!
mtrt = 0
mcurec = 0
mtrtnrm = 0
mtrtcrs = 0
mtrtobs = 0
m_q = 0
m_zs = 0
prev_trt_no = TRACHY_UNDEFINED
prev_trt_type = TRACHY_UNDEFINED
!
! Create list with possible roughnes descriptions.
! NROPAR the number of parameters for the codes
!
nropar = -1
!
! 1-49: Special treatment
!
! Water free terrain
nropar(1) = 0
!
! Combinations of area roughnesses
nropar(2) = 4
!
! 51-99: Standard roughness coefficients
!
! Constant White-Colebrook / Nikuradse value
nropar(51) = 1
!
! Constant Chezy value
nropar(52) = 1
!
! Constant Manning value
nropar(53) = 1
!
! Constant z0 value
nropar(54) = 1
!
! Ebb-flood constant White-Colebrook / Nikuradse value
nropar(61) = 2
!
! Ebb-flood constant Chezy value
nropar(62) = 2
!
! Ebb-flood constant Manning value
nropar(63) = 2
!
! Ebb-flood constant z0 value
nropar(64) = 2
!
! ! 101-149: Alluvial roughness predictors
!
! Waqua description (Simple v. Rijn)
nropar(101) = 2
!
! power law
nropar(102) = 2
!
! Van Rijn
nropar(103) = 0
!
! Struiksma
nropar(104) = 5
!
! Quadratic combination of bedform roughness heights
! used to be 7, use keywords: BdfRpC, BdfRpR, BdfMrC, BdfMrR, BdfDnC, BdfDnR, BdfD50
nropar(105) = 0
!
! Linear superposition of bedform roughness heights
nropar(106) = 0
!
! 151-199: Vegetation roughness predictors (areas)
!
! Waqua vegetation formulation 1
nropar(151) = 2
!
! Waqua vegetation formulation 2
nropar(152) = 4
!
! Baptist vegetation formulation
nropar(153) = 4
nropar(154) = 4
! Vaestilae & Jaervelae (2017) and Jarvela (2004) vegetation formulations
nropar(155) = 10
nropar(156) = 6
nropar(158) = 10
nropar(159) = 6
nropar(160) = 11
nropar(161) = 7
!
! 201-249: Vegetation roughness predictors (linear)
!
! Waqua lineair elements formulation 1
nropar(201) = 2
!
! Waqua lineair elements formulation 2
nropar(202) = 4
!
! 251-299: Vegetation roughness predictors (point)
!
! Waqua tree elements formulation 1
nropar(251) = 2
!
! -->
!
! read line
!
110 continue
read (luntmp, '(a)', iostat = iocond) rec132
if (iocond/=0) then
!
! End-of-file ?
!
if (iocond<0) goto 199
!
! Reading error
!
call SetMessage(LEVEL_ERROR, 'Read error from file: '// trim(filtmp))
error = .true.
goto 199
else
mcurec = mcurec + 1
endif
!
! Interpret line ...
!
!
! Comment line
!
if ((rec132(1:1)=='*') .or. (rec132(1:1)=='#')) goto 110
!
! Scan the record.
!
ibeg = 1
iend = 132
!
! Comment at end of line
!
! loop over rec132 and find #
!
comment_at_end_of_line_loop: &
do istr = ibeg, iend
if (rec132(istr:istr) == '#') then
iend = istr
exit comment_at_end_of_line_loop
end if
end do &
comment_at_end_of_line_loop
!
call scannr(rec132 ,ibeg ,iend ,nrflds ,itype , &
& ifield ,rfield ,cfield ,lenchr ,MAXFLD , &
& .true. ,.true. ,.true. )
!
! When no sub-fields are found, record appears to be empty
!
if (nrflds==0) goto 110
!
if (nrflds<0) then
!
! Cannot interpret line
!
rec132 = ' '
write (rec132, '(i12)') mcurec
call SetMessage(LEVEL_ERROR, 'Read error from file: '// &
& trim(filtmp) // ', Record: ' // trim(rec132))
error = .true.
goto 199
endif
!
! Check the contents
!
if (itype(1)==1 .and. itype(2)==1 .and. ifield(1) /= prev_trt_no) then
!
! Determine roughness description (i)
!
lrcode = .false.
if (ifield(2)<=IROUGH) then
i = ifield(2)
if (nropar(i)>=0) then
lrcode = .true.
endif
endif
if (lrcode) then
!
! Check required parameters
!
if (nrflds/=nropar(i) + 2) then
rec132 = ' '
write (rec132, '(i12)') mcurec
call SetMessage(LEVEL_ERROR, 'Trachytopes: Wrong number of parameters defined, File: ' &
& // trim(filtmp) // ', Record: ' // trim(rec132))
error = .true.
goto 199
endif
!
! Check the parameters
!
lokay = .true.
do j = 1, nropar(i)
if (itype(j + 2)/=2 .and. itype(j + 2)/=1) then
lokay = .false.
endif
enddo
!
! Cannot interpret line
!
if (.not.lokay) then
rec132 = ' '
write (rec132, '(i12)') mcurec
call SetMessage(LEVEL_FATAL, 'Read error from file: '// &
& trim(filtmp) // ', Record: ' // trim(rec132))
error = .true.
goto 199
endif
!
! Everything seems to be OK.
!
! Increment MTRT for checking array size.
!
mtrt = mtrt + 1
mtrtnrm = mtrtnrm + 1
prev_trt_no = TRACHY_UNDEFINED
prev_trt_type = TRACHY_UNDEFINED
!
if (mtrt>ntrt) then
call SetMessage(LEVEL_ERROR, 'Trachytopes: Number of trachytope definitions in file > array size.')
error = .true.
goto 199
endif
if (mtrtnrm>ntrtnrm) then
call SetMessage(LEVEL_ERROR, 'Trachytopes: Number of standard trachytope definitions in file > array size.')
error = .true.
goto 199
endif
!
! Store the trachytope number and roughness description in arrays
!
ittdef(mtrt, 1) = ifield(1)
ittdef(mtrt, 2) = ifield(2)
!
! Store parameters data in array
!
do j = 1, nropar(i)
if (itype(j + 2)==2) then
rttdef(mtrt, j) = rfield(j + 2)
else
rttdef(mtrt, j) = real(ifield(j + 2),fp)
endif
enddo
else
!
! Unknown rougness code
!
rec132 = ' '
write (rec132, '(i12)') mcurec
call SetMessage(LEVEL_ERROR, 'Trachytopes: Unknown roughness code in file ' &
& // trim(filtmp) // ', Record: ' // trim(rec132))
error = .true.
goto 199
endif
elseif (itype(1)==1 .and. itype(2)==3) then
! Reading is done in trachytopes module
! Checking of valid cross-section/observation-station name is done later in FM or Delft3D
!
if (cfield(2)(1:9) == 'DISCHARGE') then ! TO DO: use strcmpi?
! DISCHARGE -> cross-section name
mtrtcrs = mtrtcrs + 1
mtrt = mtrt + 1
prev_trt_no = ifield(1)
prev_trt_type = TRACHY_DISCHARGE_TYPE
!
gdtrachy%gen%crs(mtrtcrs)%name = cfield(3)
gdtrachy%gen%crs(mtrtcrs)%id = TRACHY_UNDEFINED
gdtrachy%gen%crs(mtrtcrs)%rec132 = rec132
gdtrachy%gen%crs(mtrtcrs)%itrt = mtrt
gdtrachy%gen%crs(mtrtcrs)%idx_start = m_q + 1
gdtrachy%gen%crs(mtrtcrs)%idx_end = m_q ! gets updated when first dependent row is read
!
if (mtrtcrs>ntrtcrs) then
call SetMessage(LEVEL_ERROR, &
& 'Trachytopes: Number of discharge-dependent trachytope definitions in file > array size.')
error = .true.
goto 199
endif
if (mtrt>ntrt) then
call SetMessage(LEVEL_ERROR, &
& 'Trachytopes: Number of trachytope definitions in file > array size (check in discharge).')
error = .true.
goto 199
endif
!
goto 110
elseif (cfield(2)(1:10) == 'WATERLEVEL') then ! TO DO: use strcmpi?
! WATERLEVEL -> observation-station name
mtrtobs = mtrtobs + 1
mtrt = mtrt + 1
prev_trt_no = ifield(1)
prev_trt_type = TRACHY_WATERLEVEL_TYPE
!
gdtrachy%gen%obs(mtrtobs)%name = cfield(3)
gdtrachy%gen%obs(mtrtobs)%id = TRACHY_UNDEFINED
gdtrachy%gen%obs(mtrtobs)%rec132 = rec132
gdtrachy%gen%obs(mtrtobs)%itrt = mtrt
gdtrachy%gen%obs(mtrtobs)%idx_start = m_zs + 1
gdtrachy%gen%obs(mtrtobs)%idx_end = m_zs ! gets updated when first dependent row is read
!
if (mtrtobs>ntrtobs) then
call SetMessage(LEVEL_ERROR, 'Trachytopes: Number of waterlevel-dependent trachytope definitions in file > array size.')
error = .true.
goto 199
endif
if (mtrt>ntrt) then
call SetMessage(LEVEL_ERROR, 'Trachytopes: Number of trachytope definitions in file > array size (check in waterlevel).')
error = .true.
goto 199
endif
!
goto 110
else
call SetMessage(LEVEL_ERROR, 'Trachytopes: Unknown roughness code in file ' // trim(filtmp) // ', Record: ' // trim(rec132))
error = .true.
goto 199
end if
elseif (itype(1)==1 .and. itype(2)/=3 .and. itype(3)==1) then
if (ifield(1) == prev_trt_no) then
! add to table for discharge/water level depdendent data
if (prev_trt_type == TRACHY_WATERLEVEL_TYPE) then
! add values to table for waterlevel dependent trachytopes
m_zs = m_zs + 1
ittdef(mtrt, 1) = ifield(1)
ittdef(mtrt, 2) = ifield(3)
gdtrachy%gen%obs(mtrtobs)%nropars = nropar(ifield(3))
gdtrachy%gen%ittdef_zs(m_zs) = ifield(3)
!
! Store parameters data in array temporarily (will be overwritten later)
!
lrcode = .false.
if (ifield(3)<=IROUGH) then
i = ifield(3)
if (nropar(i)>=0) then
lrcode = .true.
end if
end if
if (lrcode) then
gdtrachy%gen%table_zs(m_zs) = rfield(2)
gdtrachy%gen%obs(mtrtobs)%idx_end = m_zs ! check later: idx_end >= idx_start + 1
do j = 1, nropar(i)
rttdef(mtrt, j) = rfield(j + 3)
gdtrachy%gen%rttdef_zs(m_zs, j) = rfield(j + 3)
end do
else
call SetMessage(LEVEL_ERROR, 'Trachytopes: Unknown roughness code for waterlevel dependence in file ' &
& // trim(filtmp) // ', Record: ' // trim(rec132))
error = .true.
goto 199
end if
!
elseif (prev_trt_type == TRACHY_DISCHARGE_TYPE) then
! add values to table for discharge dependent trachytopes
m_q = m_q + 1
ittdef(mtrt, 1) = ifield(1)
ittdef(mtrt, 2) = ifield(3)
gdtrachy%gen%crs(mtrtcrs)%nropars = nropar(ifield(3))
gdtrachy%gen%ittdef_q(m_q) = ifield(3)
!
! Store parameters data in array temporarily (will be overwritten later)
!
lrcode = .false.
if (ifield(3)<=IROUGH) then
i = ifield(3)
if (nropar(i)>=0) then
lrcode = .true.
end if
end if
if (lrcode) then
gdtrachy%gen%table_q(m_q) = rfield(2)
gdtrachy%gen%crs(mtrtcrs)%idx_end = m_q ! check later: idx_end >= idx_start + 1
do j = 1, nropar(i)
rttdef(mtrt, j) = rfield(j + 3)
gdtrachy%gen%rttdef_q(m_q, j) = rfield(j + 3)
end do
else
call SetMessage(LEVEL_ERROR, 'Trachytopes: Unknown roughness code for discharge dependence in file ' &
& // trim(filtmp) // ', Record: ' // trim(rec132))
error = .true.
goto 199
end if
else
call SetMessage(LEVEL_ERROR, 'Unknown read error #3 in rdtrt.f90')
error = .true.
end if
else
call SetMessage(LEVEL_ERROR, 'Unknown read error #4 in rdtrt.f90')
error = .true.
end if
else
!
! Cannot interpret line
!
rec132 = ' '
write (rec132, '(i12)') mcurec
call SetMessage(LEVEL_ERROR, 'Read error from file: '// trim(filtmp) // &
& ', Record: ' // trim(rec132))
error = .true.
goto 199
endif
!
! Go to the next record.
!
goto 110
! <--
!
! close file
!
199 continue
close (luntmp)
!
! Check that tables have entries [ idx_start > idx_end]
!
do itrtcrs = 1, ntrtcrs
if (gdtrachy%gen%crs(itrtcrs)%idx_start + 1 > gdtrachy%gen%crs(itrtcrs)%idx_end) then
call SetMessage(LEVEL_ERROR, 'Error reading trachytopes: Expected 2 '// &
& 'or more TRTDEF DISCHARGE TRT_EQ PARAMS after -> "'//trim(gdtrachy%gen%md_ttdfile)// &
& '": '//trim(gdtrachy%gen%crs(itrtcrs)%rec132))
error = .true.
end if
itttmp = gdtrachy%gen%ittdef_q(gdtrachy%gen%crs(itrtcrs)%idx_start)
do m_q = gdtrachy%gen%crs(itrtcrs)%idx_start, gdtrachy%gen%crs(itrtcrs)%idx_end
if (gdtrachy%gen%ittdef_q(m_q) /= itttmp) then
call SetMessage(LEVEL_ERROR, 'Error reading trachytopes: Trt function '//&
& 'type should be the same for all discharges in "'//&
& trim(gdtrachy%gen%md_ttdfile)//'": '//trim(gdtrachy%gen%crs(itrtcrs)%rec132))
error = .true.
end if
end do
do m_q = gdtrachy%gen%crs(itrtcrs)%idx_start+1, gdtrachy%gen%crs(itrtcrs)%idx_end
! check if discharges are monotonically increasing
if (gdtrachy%gen%table_q(m_q)>gdtrachy%gen%table_q(m_q-1)) then
do j = 1,gdtrachy%gen%crs(itrtcrs)%nropars
! compute slope
gdtrachy%gen%rttdef_q_slope(m_q-1,j) = (gdtrachy%gen%rttdef_q(m_q, j) - &
& gdtrachy%gen%rttdef_q(m_q-1, j))/(gdtrachy%gen%table_q(m_q)-gdtrachy%gen%table_q(m_q-1))
! compute crossing
gdtrachy%gen%rttdef_q_cross(m_q-1,j) = gdtrachy%gen%rttdef_q(m_q-1, j) - &
& gdtrachy%gen%rttdef_q_slope(m_q-1,j) * gdtrachy%gen%table_q(m_q-1)
end do
else
call SetMessage(LEVEL_ERROR, 'Trachytopes: Discharges should be monotonically' &
& //'increasing for discharge dependence in file ' // trim(gdtrachy%gen%md_ttdfile) &
& // ', Record: ' // trim(gdtrachy%gen%crs(itrtcrs)%rec132))
error = .true.
end if
end do
end do
!
do itrtobs = 1, ntrtobs
if (gdtrachy%gen%obs(itrtobs)%idx_start + 1 > gdtrachy%gen%obs(itrtobs)%idx_end) then
call SetMessage(LEVEL_ERROR, 'Error reading trachytopes: Expected 2 '&
& //'or more TRTDEF WATERLEVEL TRT_EQ PARAMS after -> "'//trim(gdtrachy%gen%md_ttdfile) &
& //'": '//trim(gdtrachy%gen%obs(itrtobs)%rec132))
error = .true.
end if
itttmp = gdtrachy%gen%ittdef_zs(gdtrachy%gen%obs(itrtobs)%idx_start)
do m_zs = gdtrachy%gen%obs(itrtobs)%idx_start, gdtrachy%gen%obs(itrtobs)%idx_end
if (gdtrachy%gen%ittdef_zs(m_zs) /= itttmp) then
call SetMessage(LEVEL_ERROR, 'Error reading trachytopes: Trt '&
&//'function type should be the same for all waterlevels in "'&
&//trim(gdtrachy%gen%md_ttdfile)//'": '//trim(gdtrachy%gen%obs(itrtobs)%rec132))
error = .true.
end if
end do
do m_zs = gdtrachy%gen%obs(itrtobs)%idx_start+1, gdtrachy%gen%obs(itrtobs)%idx_end
! check if waterlevels are monotonically increasing
if (gdtrachy%gen%table_zs(m_zs)>gdtrachy%gen%table_zs(m_zs-1)) then
do j = 1,gdtrachy%gen%obs(itrtobs)%nropars
! compute slope
gdtrachy%gen%rttdef_zs_slope(m_zs-1,j) = (gdtrachy%gen%rttdef_zs(m_zs, j)-gdtrachy%gen%rttdef_zs(m_zs-1, j))/(gdtrachy%gen%table_zs(m_zs)-gdtrachy%gen%table_zs(m_zs-1))
! compute crossing
gdtrachy%gen%rttdef_zs_cross(m_zs-1,j) = gdtrachy%gen%rttdef_zs(m_zs-1, j) - gdtrachy%gen%rttdef_zs_slope(m_zs-1,j) * gdtrachy%gen%table_zs(m_zs-1)
end do
else
call SetMessage(LEVEL_ERROR, 'Trachytopes: Water levels should '&
&//'be monotonically increasing for waterlevel dependence in file '&
&// trim(gdtrachy%gen%md_ttdfile) // ', Record: ' // trim(gdtrachy%gen%obs(itrtobs)%rec132))
error = .true.
end if
end do
end do
!
if (error) goto 9999
do jdir = 1, nodir
!
! Trtu/Trtv : trachytope area file for U/V-direction
! (must exist, no default)
!
nttaru => gdtrachy%dir(jdir)%nttaru
ittaru => gdtrachy%dir(jdir)%ittaru
rttaru => gdtrachy%dir(jdir)%rttaru
rttxyz => gdtrachy%dir(jdir)%rttxyz
md_arlfile => gdtrachy%dir(jdir)%md_arlfile
!
filtmp = ' '
if (nodir .eq. 1) then
keyw = 'Trtl'
else
keyw = 'Trt'//char(116+jdir) ! 'Trtu' or 'Trtv'
end if
call prop_get(mdfile_ptr, '*',keyw,filtmp)
!
txtput1 = keyw
write (msgtmp, '(a,a,a)') txtput1,': ',trim(filtmp)
call SetMessage(LEVEL_INFO, msgtmp)
md_arlfile = trim(filtmp)
!
! keyword not found ?
!
if (filtmp == ' ' .and. ntrt /= 1) then
call SetMessage(LEVEL_ERROR, 'Missing value (or the keyword): '// keyw // ' in file')
error = .true.
goto 9999
endif
!
! read file
!
if (filtmp == ' ') then
i = 0
do m = 1,mmax
do n = 1,nmax
i = i+1
ittaru(i,1) = n
ittaru(i,2) = m
ittaru(i,3) = ittdef(1,1)
ittaru(i,4) = ittaru(i,1)+nmaxddb*(ittaru(i,2)-1 + ddbval) + ddbval
rttaru(i) = 1.0_fp
enddo
enddo
else
call rdttar(filtmp ,lundia ,error ,nttaru ,ittaru , &
& rttaru ,rttxyz ,nmax ,ddbval)
if (error) goto 9999
endif
end do
!
do jdir = 1, nodir
!
! TrtClu/TrTClv : Calibration trachytopes in U-direction
! If not found fill array with 1.0
!
rgcalu => gdtrachy%dir(jdir)%rgcalu
!
filtmp = ' '
if (nodir .eq. 1) then
keyw = 'TrtCll'
else
keyw = 'TrtCl'//char(116+jdir) ! 'TrtClu' or 'TrtClv'
end if
call prop_get(mdfile_ptr, '*',keyw,filtmp)
!
txtput1 = keyw
write (msgtmp, '(a,a,a)') txtput1,': ',trim(filtmp)
call SetMessage(LEVEL_INFO, msgtmp)
!
! keyword not found ?
!
if (filtmp /= ' ') then
!
! test file existence
!
lfile = index(filtmp, ' ')
if (lfile==0) lfile = 13
lfile = lfile - 1
if (.not.exifil(filtmp, lundia)) then