13 use mo_kind,
only : i4, dp
14 use mo_message,
only : message, error_message
73 use mo_netcdf,
only : ncdataset, ncdimension, ncvariable
74 use mo_string_utils,
only : num2str
79 integer(i4),
intent(in) :: idomain
82 integer(i4),
intent(in) :: domainid
85 character(256),
dimension(:),
intent(in) :: outfile
87 character(256) :: fname
92 integer(i4) :: noutlet
101 logical,
dimension(:, :),
allocatable :: mask0
110 logical,
dimension(:, :),
allocatable :: mask1
119 integer(i4) :: ncols11
122 integer(i4) :: nrows11
125 integer(i4),
allocatable :: dummy(:)
128 logical,
dimension(:, :),
allocatable :: mask11
131 real(dp),
dimension(:, :, :),
allocatable :: dummy_d3
132 real(dp),
dimension(:),
allocatable :: dummy_d1
134 type(ncdataset) :: nc
136 type(ncdimension) :: rows0, cols0, rows1, cols1, rows11, cols11, it11, lcscenes, nout
138 type(ncdimension) :: links, nts, nproc
140 type(ncvariable) :: var
148 s1 =
level1(idomain)%iStart
150 mask1 =
level1(idomain)%mask
154 ncols11 =
level11(idomain)%ncols
155 nrows11 =
level11(idomain)%nrows
159 fname = trim(outfile(idomain))
161 call message(
' Writing mRM restart file to ' // trim(fname) //
' ...')
163 nc = ncdataset(fname,
"w")
169 nout = nc%setDimension(
"Noutlet", noutlet)
170 rows0 = nc%getDimension(
"nrows0")
171 cols0 = nc%getDimension(
"ncols0")
172 rows1 = nc%getDimension(
"nrows1")
173 cols1 = nc%getDimension(
"ncols1")
174 rows11 = nc%getDimension(
"nrows11")
175 cols11 = nc%getDimension(
"ncols11")
178 links = nc%setDimension(
"nLinks",
size(
l11_length(s11 : e11)))
179 nts = nc%setDimension(
"TS", 1)
180 nproc = nc%setDimension(
"Nprocesses",
size(
processmatrix, dim = 1))
192 var = nc%setVariable(
"ProcessMatrix",
"i32", (/nproc/))
195 call var%setAttribute(
"long_name",
"Process Matrix")
200 var = nc%setVariable(
"L0_fDir",
"i32", (/rows0, cols0/))
203 call var%setAttribute(
"long_name",
"flow direction at level 0")
205 var = nc%setVariable(
"L0_fAcc",
"i32", (/rows0, cols0/))
208 call var%setAttribute(
"long_name",
"flow accumulation at level 0")
210 var = nc%setVariable(
"L0_slope",
"f64", (/rows0, cols0/))
213 call var%setAttribute(
"long_name",
"slope at level 0")
215 var = nc%setVariable(
"L0_streamnet",
"i32", (/rows0, cols0/))
218 call var%setAttribute(
"long_name",
"streamnet at level 0")
221 var = nc%setVariable(
"L1_Id",
"i32", (/rows1, cols1/))
223 call var%setData(unpack(
level1(idomain)%Id(1:e1-s1+1), mask1,
nodata_i4))
224 call var%setAttribute(
"long_name",
"cell IDs at level 1")
226 var = nc%setVariable(
"L1_L11_Id",
"i32", (/rows1, cols1/))
229 call var%setAttribute(
"long_name",
"Mapping of L1 Id on L11")
231 var = nc%setVariable(
"L11_Qmod",
"f64", (/rows11, cols11/))
234 call var%setAttribute(
"long_name",
"simulated discharge at each node at level 11")
236 var = nc%setVariable(
"L11_qOUT",
"f64", (/rows11, cols11/))
239 call var%setAttribute(
"long_name",
"Total outflow from cells L11 at time tt at level 11")
241 do ii = 1,
size(dummy_d3, 3)
244 var = nc%setVariable(
"L11_qTIN",
"f64", (/rows11, cols11, it11/))
246 call var%setData(dummy_d3)
247 call var%setAttribute(
"long_name",
"Total discharge inputs at t-1 and t at level 11")
249 do ii = 1,
size(dummy_d3, 3)
252 var = nc%setVariable(
"L11_qTR",
"f64", (/rows11, cols11, it11/))
254 call var%setData(dummy_d3)
255 call var%setAttribute(
"long_name",
"Routed outflow leaving a node at level 11")
257 var = nc%setVariable(
"L11_K",
"f64", (/rows11, cols11/))
260 call var%setAttribute(
"long_name",
"kappa: Muskingum travel time parameter at level 11")
262 var = nc%setVariable(
"L11_xi",
"f64", (/rows11, cols11/))
265 call var%setAttribute(
"long_name",
"xi: Muskingum diffusion parameter at level 11")
267 var = nc%setVariable(
"L11_C1",
"f64", (/rows11, cols11/))
270 call var%setAttribute(
"long_name",
"Routing parameter C1=f(K,xi, DT) (Chow, 25-41) at level 11")
272 var = nc%setVariable(
"L11_C2",
"f64", (/rows11, cols11/))
275 call var%setAttribute(
"long_name",
"Routing parameter C2=f(K,xi, DT) (Chow, 25-41) at level 11")
279 do ii = 1,
size(dummy_d3, 3)
282 var = nc%setVariable(
"L11_nLinkFracFPimp",
"f64", (/rows11, cols11, lcscenes/))
284 call var%setData(dummy_d3)
285 call var%setAttribute(
"long_name",
"Fraction of the flood plain with impervious cover at level 11")
290 var = nc%setVariable(
"L11_domain_Mask",
"i32", (/rows11, cols11/))
292 call var%setData(merge(1_i4, 0_i4, mask11))
293 call var%setAttribute(
"long_name",
"Mask at Level 11")
295 var = nc%setVariable(
"L11_TSrout",
"i32", (/nts/))
298 call var%setAttribute(
"long_name",
"routing resolution at Level 11")
299 call var%setAttribute(
"units",
"s")
301 var = nc%setVariable(
"L11_Id",
"i32", (/rows11, cols11/))
303 call var%setData(unpack(
level11(idomain)%Id(1:e11-s11+1), mask11,
nodata_i4))
304 call var%setAttribute(
"long_name",
"cell Ids at Level 11")
306 var = nc%setVariable(
"L11_fDir",
"i32", (/rows11, cols11/))
309 call var%setAttribute(
"long_name",
"flow Direction at Level 11")
311 var = nc%setVariable(
"L11_fAcc",
"f64", (/rows11, cols11/))
314 call var%setAttribute(
"long_name",
"flow accumulation at Level 11")
316 var = nc%setVariable(
"L11_rowOut",
"i32", (/rows11, cols11/))
319 call var%setAttribute(
"long_name",
"Grid vertical location of the Outlet at Level 11")
321 var = nc%setVariable(
"L11_colOut",
"i32", (/rows11, cols11/))
324 call var%setAttribute(
"long_name",
"Grid horizontal location of the Outlet at Level 11")
326 var = nc%setVariable(
"L11_fromN",
"i32", (/links/))
329 call var%setAttribute(
"long_name",
"From Node")
331 var = nc%setVariable(
"L11_toN",
"i32", (/links/))
333 call var%setData(
l11_ton(s11 : e11))
334 call var%setAttribute(
"long_name",
"To Node")
336 var = nc%setVariable(
"L11_rOrder",
"i32", (/links/))
339 call var%setAttribute(
"long_name",
"Network routing order at Level 11")
341 var = nc%setVariable(
"L11_label",
"i32", (/links/))
344 call var%setAttribute(
"long_name",
"Label Id [0='', 1=HeadWater, 2=Sink] at Level 11")
346 var = nc%setVariable(
"L11_sink",
"i32", (/links/))
348 allocate(dummy(e11 - s11 + 1))
354 call var%setData(dummy)
356 call var%setAttribute(
"long_name",
".true. if sink node reached at Level 11")
358 var = nc%setVariable(
"L11_netPerm",
"i32", (/links/))
361 call var%setAttribute(
"long_name",
"Routing sequence (permutation of L11_rOrder) at Level 11")
363 var = nc%setVariable(
"L11_fRow",
"i32", (/links/))
365 call var%setData(
l11_frow(s11 : e11))
366 call var%setAttribute(
"long_name",
"From row in L0 grid at Level 11")
368 var = nc%setVariable(
"L11_fCol",
"i32", (/links/))
370 call var%setData(
l11_fcol(s11 : e11))
371 call var%setAttribute(
"long_name",
"From col in L0 grid at Level 11")
373 var = nc%setVariable(
"L11_tRow",
"i32", (/links/))
375 call var%setData(
l11_trow(s11 : e11))
376 call var%setAttribute(
"long_name",
"To row in L0 grid at Level 11")
378 var = nc%setVariable(
"L11_tCol",
"i32", (/links/))
380 call var%setData(
l11_tcol(s11 : e11))
381 call var%setAttribute(
"long_name",
"To Col in L0 grid at Level 11")
383 var = nc%setVariable(
"L11_length",
"f64", (/links/))
386 call var%setAttribute(
"long_name",
"Total length of river link [m]")
388 var = nc%setVariable(
"L11_aFloodPlain",
"f64", (/links/))
391 call var%setAttribute(
"long_name",
"Area of the flood plain [m2]")
393 var = nc%setVariable(
"L11_slope",
"f64", (/links/))
396 call var%setAttribute(
"long_name",
"Average slope of river link")
398 var = nc%setVariable(
"L11_L1_Id",
"i32", (/rows11, cols11/))
401 call var%setAttribute(
"long_name",
"Mapping of L1 Id on L11")
403 var = nc%setVariable(
"gaugeNodeList",
"i32", &
404 (/nc%setDimension(
"Ngauges",
size(
domain_mrm(idomain)%gaugeNodeList(:)))/) &
407 call var%setData(
domain_mrm(idomain)%gaugeNodeList(:))
408 call var%setAttribute(
"long_name",
"cell ID of gauges")
410 var = nc%setVariable(
"InflowGaugeNodeList",
"i32", &
411 (/nc%setDimension(
"nInflowGauges",
size(
domain_mrm(idomain)%InflowGaugeNodeList(:)))/) &
414 call var%setData(
domain_mrm(idomain)%InflowGaugeNodeList(:))
415 call var%setAttribute(
"long_name",
"cell ID of gauges")
418 var = nc%setVariable(
"L11_celerity",
"f64", (/links/))
421 call var%setAttribute(
"long_name",
"celerity at Level 11")
465 use mo_netcdf,
only : ncdataset, ncvariable
466 use mo_string_utils,
only : num2str
471 integer(i4),
intent(in) :: idomain
473 integer(i4),
intent(in) :: domainid
476 character(256),
intent(in) :: infile
487 logical,
dimension(:, :),
allocatable :: mask11
490 real(dp),
dimension(:, :),
allocatable :: dummyd2
493 real(dp),
dimension(:, :, :),
allocatable :: dummyd3
495 character(256) :: fname
497 type(ncdataset) :: nc
499 type(ncvariable) :: var
511 nc = ncdataset(fname,
"r")
514 var = nc%getVariable(
"L11_Qmod")
515 call var%getData(dummyd2)
516 l11_qmod(s11 : e11) = pack(dummyd2, mask11)
519 var = nc%getVariable(
"L11_qOUT")
520 call var%getData(dummyd2)
521 l11_qout(s11 : e11) = pack(dummyd2, mask11)
524 var = nc%getVariable(
"L11_qTIN")
525 call var%getData(dummyd3)
527 l11_qtin(s11 : e11, ii) = pack(dummyd3(:, :, ii), mask11)
531 var = nc%getVariable(
"L11_qTR")
532 call var%getData(dummyd3)
534 l11_qtr(s11 : e11, ii) = pack(dummyd3(:, :, ii), mask11)
538 var = nc%getVariable(
"L11_K")
539 call var%getData(dummyd2)
540 l11_k(s11 : e11) = pack(dummyd2, mask11)
543 var = nc%getVariable(
"L11_xi")
544 call var%getData(dummyd2)
545 l11_xi(s11 : e11) = pack(dummyd2, mask11)
548 var = nc%getVariable(
"L11_C1")
549 call var%getData(dummyd2)
550 l11_c1(s11 : e11) = pack(dummyd2, mask11)
553 var = nc%getVariable(
"L11_C2")
554 call var%getData(dummyd2)
555 l11_c2(s11 : e11) = pack(dummyd2, mask11)
558 var = nc%getVariable(
"L11_nLinkFracFPimp")
560 call var%getData(dummyd3)
566 deallocate(dummyd2, dummyd3)
604 use mo_append,
only : append
607 use mo_kind,
only : dp, i4
614 use mo_netcdf,
only : ncdataset, ncvariable
615 use mo_string_utils,
only : num2str
620 integer(i4),
intent(in) :: idomain
623 integer(i4),
intent(in) :: domainid
626 character(256),
intent(in) :: infile
628 character(256) :: fname
631 logical,
allocatable,
dimension(:, :) :: mask0
634 logical,
allocatable,
dimension(:, :) :: mask1
637 logical,
allocatable,
dimension(:, :) :: mask11
640 integer(i4),
allocatable,
dimension(:) :: dummyi1
643 integer(i4),
allocatable,
dimension(:, :) :: dummyi2
646 real(dp),
allocatable,
dimension(:) :: dummyd1
647 real(dp),
allocatable,
dimension(:, :) :: dummyd2
648 real(dp),
allocatable :: dummyd0
650 type(ncdataset) :: nc
652 type(ncvariable) :: var
657 call message(
' Reading mRM restart file: ', trim(adjustl(fname)),
' ...')
661 mask1 =
level1(idomain)%mask
664 nc = ncdataset(fname,
"r")
669 var = nc%getVariable(
"ProcessMatrix")
671 call var%getData(dummyi1)
673 call error_message(
'***ERROR: process description for routing', raise=.false.)
674 call error_message(
'***ERROR: given in restart file does not match', raise=.false.)
675 call error_message(
'***ERROR: that in namelist', raise=.false.)
676 call error_message(
'***ERROR: restart file value:. ' // num2str(dummyi1(8),
'(i2)'), raise=.false.)
677 call error_message(
'***ERROR: namelist value:..... ' // num2str(
processmatrix(8, 1),
'(i2)'), raise=.false.)
678 call error_message(
'ERROR: mrm_read_restart_config')
687 var = nc%getVariable(
"L0_fDir")
688 call var%getData(dummyi2)
689 call append(
l0_fdir, pack(dummyi2, mask0))
691 var = nc%getVariable(
"L0_fAcc")
692 call var%getData(dummyi2)
693 call append(
l0_facc, pack(dummyi2, mask0))
695 var = nc%getVariable(
"L0_slope")
696 call var%getData(dummyd2)
697 call append(
l0_slope, pack(dummyd2, mask0))
699 var = nc%getVariable(
"L0_streamnet")
700 call var%getData(dummyi2)
707 var = nc%getVariable(
"L1_L11_Id")
708 call var%getData(dummyi2)
709 call append(
l1_l11_id, pack(dummyi2, mask1))
715 if (idomain .eq. 1)
then
719 var = nc%getVariable(
"L11_TSrout")
720 call var%getData(dummyd0)
725 var = nc%getVariable(
"L11_L1_Id")
726 call var%getData(dummyi2)
727 call append(
l11_l1_id, pack(dummyi2, mask11))
730 var = nc%getVariable(
"L11_fDir")
731 call var%getData(dummyi2)
732 call append(
l11_fdir, pack(dummyi2, mask11))
737 var = nc%getVariable(
"L11_fAcc")
738 call var%getData(dummyd2)
739 call append(
l11_facc, pack(dummyd2, mask11))
742 var = nc%getVariable(
"L11_rowOut")
743 call var%getData(dummyi2)
744 call append(
l11_rowout, pack(dummyi2, mask11))
747 var = nc%getVariable(
"L11_colOut")
748 call var%getData(dummyi2)
749 call append(
l11_colout, pack(dummyi2, mask11))
753 var = nc%getVariable(
"L11_fromN")
754 call var%getData(dummyi1)
758 var = nc%getVariable(
"L11_toN")
759 call var%getData(dummyi1)
764 var = nc%getVariable(
"L11_rOrder")
765 call var%getData(dummyi1)
769 var = nc%getVariable(
"L11_label")
770 call var%getData(dummyi1)
774 var = nc%getVariable(
"L11_sink")
775 call var%getData(dummyi1)
776 call append(
l11_sink, (dummyi1 .eq. 1_i4))
779 var = nc%getVariable(
"L11_netPerm")
780 call var%getData(dummyi1)
785 var = nc%getVariable(
"L11_fRow")
786 call var%getData(dummyi1)
790 var = nc%getVariable(
"L11_fCol")
791 call var%getData(dummyi1)
795 var = nc%getVariable(
"L11_tRow")
796 call var%getData(dummyi1)
800 var = nc%getVariable(
"L11_tCol")
801 call var%getData(dummyi1)
807 var = nc%getVariable(
"gaugeNodeList")
808 call var%getData(dummyi1)
809 domain_mrm(idomain)%gaugeNodeList(:) = dummyi1
812 if (
domain_mrm(idomain)%nInflowGauges > 0)
then
813 var = nc%getVariable(
"InflowGaugeNodeList")
814 call var%getData(dummyi1)
815 domain_mrm(idomain)%InflowgaugeNodeList(:) = dummyi1
821 var = nc%getVariable(
"L11_length")
822 call var%getData(dummyd1)
826 var = nc%getVariable(
"L11_aFloodPlain")
827 call var%getData(dummyd1)
831 var = nc%getVariable(
"L11_slope")
832 call var%getData(dummyd1)
Provides constants commonly used by mHM, mRM and MPR.
character(64), parameter, public landcoverperiodsvarname
real(dp), parameter, public nodata_dp
integer(i4), parameter, public nodata_i4
subroutine, public write_grid_info(grid_in, level_name, nc)
write restart files for each domain
Provides structures needed by mHM, mRM and/or mpr.
type(domain_meta), public domainmeta
integer(i4), public nlcoverscene
integer(i4), dimension(:), allocatable, public lc_year_end
integer(i4), dimension(nprocesses, 3), public processmatrix
type(grid), dimension(:), allocatable, target, public level1
type(grid), dimension(:), allocatable, target, public level0
integer(i4), dimension(:), allocatable, public lc_year_start
Global variables for mpr only.
real(dp), dimension(:), allocatable, public l0_slope
Provides mRM specific constants.
integer(i4), parameter, public nroutingstates
Global variables for mRM only.
real(dp), dimension(:, :), allocatable, public l11_qtin
real(dp), dimension(:), allocatable, public l11_facc
integer(i4), dimension(:), allocatable, public l11_netperm
real(dp), dimension(:), allocatable, public l11_qout
real(dp), dimension(:, :), allocatable, public l11_nlinkfracfpimp
integer(i4), dimension(:), allocatable, public l11_l1_id
integer(i4), dimension(:), allocatable, public l1_l11_id
real(dp), dimension(:), allocatable, target, public l11_afloodplain
integer(i4), dimension(:), allocatable, public l0_fdir
integer(i4), dimension(:), allocatable, public l11_fcol
real(dp), dimension(:), allocatable, public l11_xi
integer(i4), dimension(:), allocatable, public l11_label
integer(i4), dimension(:), allocatable, public l0_streamnet
integer(i4), dimension(:), allocatable, public l11_fromn
real(dp), dimension(:), allocatable, public l11_length
integer(i4), dimension(:), allocatable, public l11_rowout
real(dp), dimension(:), allocatable, public l11_qmod
integer(i4), dimension(:), allocatable, public l11_ton
type(domaininfo_mrm), dimension(:), allocatable, target, public domain_mrm
integer(i4), dimension(:), allocatable, public l11_trow
type(grid), dimension(:), allocatable, target, public level11
integer(i4), dimension(:), allocatable, public l11_fdir
integer(i4), dimension(:), allocatable, public l0_facc
real(dp), dimension(:), allocatable, public l11_c1
integer(i4), dimension(:), allocatable, public l11_tcol
integer(i4), dimension(:), allocatable, public l11_frow
real(dp), dimension(:), allocatable, public l11_slope
logical, dimension(:), allocatable, public l11_sink
real(dp), dimension(:), allocatable, public l11_celerity
integer(i4), dimension(:), allocatable, public l11_noutlets
real(dp), dimension(:), allocatable, public l11_k
integer(i4), dimension(:), allocatable, public l11_rorder
real(dp), dimension(:), allocatable, public l11_tsrout
integer(i4), dimension(:), allocatable, public l11_colout
real(dp), dimension(:, :), allocatable, public l11_qtr
real(dp), dimension(:), allocatable, public l11_c2
subroutine, public mrm_read_restart_states(idomain, domainid, infile)
read routing states
subroutine, public mrm_write_restart(idomain, domainid, outfile)
write routing states and configuration
subroutine, public mrm_read_restart_config(idomain, domainid, infile)
reads Level 11 configuration from a restart directory