@@ -12,6 +12,7 @@ MODULE histVars_data
12
12
USE public_var, ONLY: kinematicWave ! KW routing ID = 3
13
13
USE public_var, ONLY: muskingumCunge ! MC routing ID = 4
14
14
USE public_var, ONLY: diffusiveWave ! DW routing ID = 5
15
+ USE public_var, ONLY: outputInflow ! logical for outputting upstream inflow in history file
15
16
USE globalData, ONLY: nRoutes
16
17
USE globalData, ONLY: routeMethods
17
18
USE globalData, ONLY: meta_rflx, meta_hflx
@@ -54,6 +55,7 @@ MODULE histVars_data
54
55
real (dp), allocatable :: instRunoff(:) ! instantaneous lateral inflow into each river/lake [m3/s] [nRch]
55
56
real (dp), allocatable :: dlayRunoff(:) ! lateral inflow into river or lake [m3/s] for each reach [nRch]
56
57
real (dp), allocatable :: discharge(:,:) ! river/lake discharge [m3/s] for each reach/lake and routing method [nRch,nMethod]
58
+ real (dp), allocatable :: inflow(:,:) ! inflow from upstream rivers/lakes [m3/s] for each reach/lake and routing method [nRch,nMethod]
57
59
real (dp), allocatable :: elev(:,:) ! river/lake surface water elevation [m] for each reach/lake and routing method [nRch,nMethod]
58
60
real (dp), allocatable :: volume(:,:) ! river/lake volume [m3] for each reach/lake and routing method [nRch,nMethod]
59
61
@@ -95,31 +97,31 @@ FUNCTION constructor(nHru_local, nRch_local, ierr, message) RESULT(instHistVar)
95
97
instHistVar% nRch = nRch_local
96
98
97
99
if (meta_hflx(ixHFLX% basRunoff)% varFile) then
98
- allocate (instHistVar% basRunoff(nHRU_local), stat= ierr, errmsg= cmessage)
100
+ allocate (instHistVar% basRunoff(nHRU_local), source = 0._dp , stat= ierr, errmsg= cmessage)
99
101
if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [instHistVar%basRunoff]' ; return ; endif
100
- instHistVar% basRunoff(1 :nHRU_local) = 0._dp
101
102
end if
102
103
103
104
if (meta_rflx(ixRFLX% instRunoff)% varFile) then
104
- allocate (instHistVar% instRunoff(nRch_local), stat= ierr, errmsg= cmessage)
105
+ allocate (instHistVar% instRunoff(nRch_local), source = 0._dp , stat= ierr, errmsg= cmessage)
105
106
if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [instHistVar%instRunoff]' ; return ; endif
106
- instHistVar% instRunoff(1 :nRch_local) = 0._dp
107
107
end if
108
108
109
109
if (meta_rflx(ixRFLX% dlayRunoff)% varFile) then
110
- allocate (instHistVar% dlayRunoff(nRch_local), stat= ierr, errmsg= cmessage)
110
+ allocate (instHistVar% dlayRunoff(nRch_local), source = 0._dp , stat= ierr, errmsg= cmessage)
111
111
if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [instHistVar%instRunoff]' ; return ; endif
112
- instHistVar% dlayRunoff(1 :nRch_local) = 0._dp
113
112
end if
114
113
115
114
if (nRoutes> 0 ) then ! this should be number of methods that ouput
116
- allocate (instHistVar% discharge(nRch_local, nRoutes), stat= ierr, errmsg= cmessage)
115
+ allocate (instHistVar% discharge(nRch_local, nRoutes), source = 0._dp , stat= ierr, errmsg= cmessage)
117
116
if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [instHistVar%discharge]' ; return ; endif
118
- instHistVar% discharge(1 :nRch_local, 1 :nRoutes) = 0._dp
119
117
120
- allocate (instHistVar% volume(nRch_local, nRoutes), stat= ierr, errmsg= cmessage)
118
+ allocate (instHistVar% volume(nRch_local, nRoutes), source = 0._dp , stat= ierr, errmsg= cmessage)
121
119
if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [instHistVar%volume]' ; return ; endif
122
- instHistVar% volume(1 :nRch_local, 1 :nRoutes) = 0._dp
120
+
121
+ if (outputInflow) then
122
+ allocate (instHistVar% inflow(nRch_local, nRoutes), source= 0._dp , stat= ierr, errmsg= cmessage)
123
+ if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [instHistVar%inflow]' ; return ; endif
124
+ end if
123
125
end if
124
126
125
127
END FUNCTION constructor
@@ -205,6 +207,9 @@ SUBROUTINE aggregate(this, & ! inout:
205
207
do ix= 1 ,this% nRch
206
208
this% discharge(ix,iRoute) = this% discharge(ix,iRoute) + RCHFLX_local(1 ,ix)% ROUTE(idxMethod)% REACH_Q
207
209
this% volume(ix,iRoute) = this% volume(ix,iRoute) + RCHFLX_local(1 ,ix)% ROUTE(idxMethod)% REACH_VOL(1 )
210
+ if (outputInflow) then
211
+ this% inflow(ix,iRoute) = this% inflow(ix,iRoute) + RCHFLX_local(1 ,ix)% ROUTE(idxMethod)% REACH_INFLOW
212
+ end if
208
213
end do
209
214
end do
210
215
@@ -245,6 +250,11 @@ SUBROUTINE finalize(this)
245
250
this% volume = this% volume/ real (this% nt, kind= dp)
246
251
end if
247
252
253
+ ! 6. inflow
254
+ if (allocated (this% inflow)) then
255
+ this% inflow = this% inflow/ real (this% nt, kind= dp)
256
+ end if
257
+
248
258
END SUBROUTINE finalize
249
259
250
260
! ---------------------------------------------------------------
@@ -263,6 +273,7 @@ SUBROUTINE refresh(this)
263
273
if (allocated (this% dlayRunoff)) this% dlayRunoff = 0._dp
264
274
if (allocated (this% discharge)) this% discharge = 0._dp
265
275
if (allocated (this% volume)) this% volume = 0._dp
276
+ if (allocated (this% inflow)) this% inflow = 0._dp
266
277
267
278
END SUBROUTINE refresh
268
279
@@ -280,6 +291,7 @@ SUBROUTINE clean(this)
280
291
if (allocated (this% dlayRunoff)) deallocate (this% dlayRunoff)
281
292
if (allocated (this% discharge)) deallocate (this% discharge)
282
293
if (allocated (this% volume)) deallocate (this% volume)
294
+ if (allocated (this% inflow)) deallocate (this% inflow)
283
295
284
296
END SUBROUTINE clean
285
297
@@ -299,6 +311,7 @@ SUBROUTINE read_restart(this, restart_name, ierr, message)
299
311
real (dp), allocatable :: array_tmp(:) ! temp array
300
312
integer (i4b) :: ixRoute ! loop index
301
313
integer (i4b) :: ixFlow, ixVol ! temporal method index
314
+ integer (i4b) :: ixInflow ! temporal method index
302
315
logical (lgt) :: FileStatus ! file open or close
303
316
type (file_desc_t) :: pioFileDesc ! pio file handle
304
317
@@ -369,30 +382,40 @@ SUBROUTINE read_restart(this, restart_name, ierr, message)
369
382
allocate (this% discharge(this% nRch, nRoutes), stat= ierr, errmsg= cmessage)
370
383
if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [hVars%discharge]' ; return ; endif
371
384
allocate (this% volume(this% nRch, nRoutes), stat= ierr, errmsg= cmessage)
372
- if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [hVars%discharge ]' ; return ; endif
385
+ if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [hVars%volume ]' ; return ; endif
373
386
374
387
this% discharge = 0._dp
375
388
this% volume = 0._dp
376
389
390
+ if (outputInflow) then
391
+ allocate (this% inflow(this% nRch, nRoutes), source= 0.0_dp , stat= ierr, errmsg= cmessage)
392
+ if (ierr/= 0 )then ; message= trim (message)// trim (cmessage)// ' [hVars%volume]' ; return ; endif
393
+ end if
394
+
377
395
do ixRoute= 1 ,nRoutes
378
396
select case (routeMethods(ixRoute))
379
397
case (accumRunoff)
380
398
ixFlow= ixRFLX% sumUpstreamRunoff
381
399
case (impulseResponseFunc)
382
400
ixFlow= ixRFLX% IRFroutedRunoff
383
401
ixVol= ixRFLX% IRFvolume
402
+ ixInflow= ixRFLX% IRFinflow
384
403
case (kinematicWaveTracking)
385
404
ixFlow= ixRFLX% KWTroutedRunoff
386
405
ixVol= ixRFLX% KWTvolume
406
+ ixInflow= ixRFLX% KWTinflow
387
407
case (kinematicWave)
388
408
ixFlow= ixRFLX% KWroutedRunoff
389
409
ixVol= ixRFLX% KWvolume
410
+ ixInflow= ixRFLX% KWinflow
390
411
case (muskingumCunge)
391
412
ixFlow= ixRFLX% MCroutedRunoff
392
413
ixVol= ixRFLX% MCvolume
414
+ ixInflow= ixRFLX% MCinflow
393
415
case (diffusiveWave)
394
416
ixFlow= ixRFLX% DWroutedRunoff
395
417
ixVol= ixRFLX% DWvolume
418
+ ixInflow= ixRFLX% DWinflow
396
419
case default
397
420
write (message,' (2A,1X,G0,1X,A)' ) trim (message), ' routing method index:' ,routeMethods(ixRoute), ' must be 0-5'
398
421
ierr= 81 ; return
@@ -418,13 +441,25 @@ SUBROUTINE read_restart(this, restart_name, ierr, message)
418
441
! need to shift tributary part in main core to after halo reaches (nTribOutlet)
419
442
if (masterproc) then
420
443
this% volume(1 :nRch_mainstem, ixRoute) = array_tmp(1 :nRch_mainstem)
421
- this% volume(nRch_mainstem+ nTribOutlet+1 :this% nRch,ixRoute) = this % volume (nRch_mainstem+1 :nRch_mainstem+ nRch_trib,ixRoute )
444
+ this% volume(nRch_mainstem+ nTribOutlet+1 :this% nRch, ixRoute) = array_tmp (nRch_mainstem+1 :nRch_mainstem+ nRch_trib)
422
445
else
423
446
this% volume(:,ixRoute) = array_tmp
424
447
end if
425
448
end if
426
- end do
427
- end if
449
+
450
+ if (meta_rflx(ixInflow)% varFile) then
451
+ call read_dist_array(pioFileDesc, meta_rflx(ixInflow)% varName, array_tmp, ioDesc_hist_rch_double, ierr, cmessage)
452
+ if (ierr/= 0 )then ; message= trim (message)// trim (cmessage); return ; endif
453
+ ! need to shift tributary part in main core to after halo reaches (nTribOutlet)
454
+ if (masterproc) then
455
+ this% inflow(1 :nRch_mainstem, ixRoute) = array_tmp(1 :nRch_mainstem)
456
+ this% inflow(nRch_mainstem+ nTribOutlet+1 :this% nRch, ixRoute) = array_tmp(nRch_mainstem+1 :nRch_mainstem+ nRch_trib)
457
+ else
458
+ this% inflow(:,ixRoute) = array_tmp
459
+ end if
460
+ end if
461
+ end do ! end of ixRoute loop
462
+ end if ! end of nRoute>0 if-statement
428
463
429
464
call closeFile(pioFileDesc, FileStatus)
430
465
0 commit comments