5.13.2-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_mrm_restart.f90
Go to the documentation of this file.
1!> \file mo_mrm_restart.f90
2!> \brief \copybrief mo_mrm_restart
3!> \details \copydetails mo_mrm_restart
4
5!> \brief Restart routines
6!> \details This module contains the subroutines for reading and writing routing related variables to file.
7!> \authors Stephan Thober
8!> \date Aug 2015
9!> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
10!! mHM is released under the LGPLv3+ license \license_note
11!> \ingroup f_mrm
13 use mo_kind, only : i4, dp
14 use mo_message, only : message, error_message
15
16 implicit none
17
18 public :: mrm_write_restart
21contains
22
23 ! ------------------------------------------------------------------
24
25 ! NAME
26 ! mrm_write_restart
27
28 ! PURPOSE
29 !> \brief write routing states and configuration
30
31 !> \details write configuration and state variables to a given restart
32 !> directory.
33
34 ! INTENT(IN)
35 !> \param[in] "integer(i4) :: iDomain" number of domain
36 !> \param[in] "character(256), dimension(:) :: OutFile" list of Output paths per Domain
37
38 ! HISTORY
39 !> \authors Stephan Thober
40
41 !> \date Aug 2015
42
43 ! Modifications:
44 ! Stephan Thober Sep 2015 - added all write restart commands in this subroutine
45 ! Stephan Thober Sep 2015 - added L11_areaCell L1_ID and L1_L11_Id for routing
46 ! resolution higher than hydrology resolution
47 ! David Schaefer Nov 2015 - mo_netcdf
48 ! Stephan Thober May 2016 - split L0_OutletCoord into L0_rowOutlet & L0_colOutlet
49 ! because multiple outlets could exist
50 ! Stephan Thober Nov 2016 - added L11_TSrout, ProcessMatrix
51 ! Matthias Kelbling Aug 2017 - added L11_fAcc, L0_slope, L0_celerity, L11_celerity, L11_meandering
52 ! Robert Schweppe Jun 2018 - refactoring and reformatting
53 ! Stephan Thober Jun 2018 - including varying celerity functionality
54 ! Stephan Thober May 2019 - added L0 info required for Process 3
55
56 subroutine mrm_write_restart(iDomain, domainID, OutFile)
57
66 l1_l11_id, &
73 use mo_netcdf, only : ncdataset, ncdimension, ncvariable
74 use mo_string_utils, only : num2str
75
76 implicit none
77
78 ! number of domain
79 integer(i4), intent(in) :: idomain
80
81 ! domain
82 integer(i4), intent(in) :: domainid
83
84 ! list of Output paths per Domain
85 character(256), dimension(:), intent(in) :: outfile
86
87 character(256) :: fname
88
89 integer(i4) :: ii
90
91 ! number of outlets at Level 0
92 integer(i4) :: noutlet
93
94 ! start index at level 0
95 integer(i4) :: s0
96
97 ! end index at level 0
98 integer(i4) :: e0
99
100 ! mask at level 0
101 logical, dimension(:, :), allocatable :: mask0
102
103 ! start index at level 1
104 integer(i4) :: s1
105
106 ! end index at level 1
107 integer(i4) :: e1
108
109 ! mask at level 1
110 logical, dimension(:, :), allocatable :: mask1
111
112 ! start index at level 11
113 integer(i4) :: s11
114
115 ! end index at level 11
116 integer(i4) :: e11
117
118 ! number of colums at level 11
119 integer(i4) :: ncols11
120
121 ! number of rows at level 11
122 integer(i4) :: nrows11
123
124 ! dummy variable for writing L11_sink
125 integer(i4), allocatable :: dummy(:)
126
127 ! mask at level 11
128 logical, dimension(:, :), allocatable :: mask11
129
130 ! dummy variable
131 real(dp), dimension(:, :, :), allocatable :: dummy_d3
132 real(dp), dimension(:), allocatable :: dummy_d1
133
134 type(ncdataset) :: nc
135
136 type(ncdimension) :: rows0, cols0, rows1, cols1, rows11, cols11, it11, lcscenes, nout
137
138 type(ncdimension) :: links, nts, nproc
139
140 type(ncvariable) :: var
141
142
143 ! get Level1 and Level11 information about the Domain
144 noutlet = domain_mrm(domainmeta%L0DataFrom(idomain))%L0_noutlet
145 s0 = level0(domainmeta%L0DataFrom(idomain))%iStart
146 e0 = level0(domainmeta%L0DataFrom(idomain))%iEnd
147 mask0 = level0(domainmeta%L0DataFrom(idomain))%mask
148 s1 = level1(idomain)%iStart
149 e1 = level1(idomain)%iEnd
150 mask1 = level1(idomain)%mask
151 s11 = level11(idomain)%iStart
152 e11 = level11(idomain)%iEnd
153 mask11 = level11(idomain)%mask
154 ncols11 = level11(idomain)%ncols
155 nrows11 = level11(idomain)%nrows
156 allocate(dummy_d3(nrows11, ncols11, nroutingstates))
157
158 ! set restart file name
159 fname = trim(outfile(idomain))
160
161 call message(' Writing mRM restart file to ' // trim(fname) // ' ...')
162
163 nc = ncdataset(fname, "w")
164
165 call write_grid_info(level0(domainmeta%L0DataFrom(idomain)), "0", nc)
166 call write_grid_info(level1(idomain), "1", nc)
167 call write_grid_info(level11(idomain), "11", nc)
168
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")
176
177 it11 = nc%setDimension("nIT", nroutingstates)
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))
181 allocate(dummy_d1(nlcoverscene+1))
182 dummy_d1(1:nlcoverscene) = lc_year_start(:)
183 ! this is done because bounds are always stored as real so e.g.
184 ! 1981-1990,1991-2000 is thus saved as 1981.0-1991.0,1991.0-2001.0
185 ! it is translated back into ints correctly during reading
186 dummy_d1(nlcoverscene+1) = lc_year_end(nlcoverscene) + 1
187 lcscenes = nc%setCoordinate(trim(landcoverperiodsvarname), nlcoverscene, dummy_d1, 0_i4)
188 deallocate(dummy_d1)
189
190
191 ! add processMatrix
192 var = nc%setVariable("ProcessMatrix", "i32", (/nproc/))
193 call var%setFillValue(nodata_i4)
194 call var%setData(processmatrix(:, 1))
195 call var%setAttribute("long_name", "Process Matrix")
196
197 ! add L0 variables if processmatrix is equal to 3
198 if (processmatrix(8, 1) .eq. 3_i4) then
199 ! add L0_fdir, L0_fAcc, L0_slope, L0_streamnet
200 var = nc%setVariable("L0_fDir", "i32", (/rows0, cols0/))
201 call var%setFillValue(nodata_i4)
202 call var%setData(unpack(l0_fdir(s0:e0), mask0, nodata_i4))
203 call var%setAttribute("long_name", "flow direction at level 0")
204
205 var = nc%setVariable("L0_fAcc", "i32", (/rows0, cols0/))
206 call var%setFillValue(nodata_i4)
207 call var%setData(unpack(l0_facc(s0:e0), mask0, nodata_i4))
208 call var%setAttribute("long_name", "flow accumulation at level 0")
209
210 var = nc%setVariable("L0_slope", "f64", (/rows0, cols0/))
211 call var%setFillValue(nodata_dp)
212 call var%setData(unpack(l0_slope(s0:e0), mask0, nodata_dp))
213 call var%setAttribute("long_name", "slope at level 0")
214
215 var = nc%setVariable("L0_streamnet", "i32", (/rows0, cols0/))
216 call var%setFillValue(nodata_i4)
217 call var%setData(unpack(l0_streamnet(s0:e0), mask0, nodata_i4))
218 call var%setAttribute("long_name", "streamnet at level 0")
219 end if
220
221 var = nc%setVariable("L1_Id", "i32", (/rows1, cols1/))
222 call var%setFillValue(nodata_i4)
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")
225
226 var = nc%setVariable("L1_L11_Id", "i32", (/rows1, cols1/))
227 call var%setFillValue(nodata_i4)
228 call var%setData(unpack(l1_l11_id(s1 : e1), mask1, nodata_i4))
229 call var%setAttribute("long_name", "Mapping of L1 Id on L11")
230
231 var = nc%setVariable("L11_Qmod", "f64", (/rows11, cols11/))
232 call var%setFillValue(nodata_dp)
233 call var%setData(unpack(l11_qmod(s11 : e11), mask11, nodata_dp))
234 call var%setAttribute("long_name", "simulated discharge at each node at level 11")
235
236 var = nc%setVariable("L11_qOUT", "f64", (/rows11, cols11/))
237 call var%setFillValue(nodata_dp)
238 call var%setData(unpack(l11_qout(s11 : e11), mask11, nodata_dp))
239 call var%setAttribute("long_name", "Total outflow from cells L11 at time tt at level 11")
240
241 do ii = 1, size(dummy_d3, 3)
242 dummy_d3(:, :, ii) = unpack(l11_qtin(s11 : e11, ii), mask11, nodata_dp)
243 end do
244 var = nc%setVariable("L11_qTIN", "f64", (/rows11, cols11, it11/))
245 call var%setFillValue(nodata_dp)
246 call var%setData(dummy_d3)
247 call var%setAttribute("long_name", "Total discharge inputs at t-1 and t at level 11")
248
249 do ii = 1, size(dummy_d3, 3)
250 dummy_d3(:, :, ii) = unpack(l11_qtr(s11 : e11, ii), mask11, nodata_dp)
251 end do
252 var = nc%setVariable("L11_qTR", "f64", (/rows11, cols11, it11/))
253 call var%setFillValue(nodata_dp)
254 call var%setData(dummy_d3)
255 call var%setAttribute("long_name", "Routed outflow leaving a node at level 11")
256
257 var = nc%setVariable("L11_K", "f64", (/rows11, cols11/))
258 call var%setFillValue(nodata_dp)
259 call var%setData(unpack(l11_k(s11 : e11), mask11, nodata_dp))
260 call var%setAttribute("long_name", "kappa: Muskingum travel time parameter at level 11")
261
262 var = nc%setVariable("L11_xi", "f64", (/rows11, cols11/))
263 call var%setFillValue(nodata_dp)
264 call var%setData(unpack(l11_xi(s11 : e11), mask11, nodata_dp))
265 call var%setAttribute("long_name", "xi: Muskingum diffusion parameter at level 11")
266
267 var = nc%setVariable("L11_C1", "f64", (/rows11, cols11/))
268 call var%setFillValue(nodata_dp)
269 call var%setData(unpack(l11_c1(s11 : e11), mask11, nodata_dp))
270 call var%setAttribute("long_name", "Routing parameter C1=f(K,xi, DT) (Chow, 25-41) at level 11")
271
272 var = nc%setVariable("L11_C2", "f64", (/rows11, cols11/))
273 call var%setFillValue(nodata_dp)
274 call var%setData(unpack(l11_c2(s11 : e11), mask11, nodata_dp))
275 call var%setAttribute("long_name", "Routing parameter C2=f(K,xi, DT) (Chow, 25-41) at level 11")
276
277 deallocate(dummy_d3)
278 allocate(dummy_d3(nrows11, ncols11, nlcoverscene))
279 do ii = 1, size(dummy_d3, 3)
280 dummy_d3(:, :, ii) = unpack(l11_nlinkfracfpimp(s11 : e11, ii), mask11, nodata_dp)
281 end do
282 var = nc%setVariable("L11_nLinkFracFPimp", "f64", (/rows11, cols11, lcscenes/))
283 call var%setFillValue(nodata_dp)
284 call var%setData(dummy_d3)
285 call var%setAttribute("long_name", "Fraction of the flood plain with impervious cover at level 11")
286
287 ! ----------------------------------------------------------
288 ! L11 config set
289 ! ----------------------------------------------------------
290 var = nc%setVariable("L11_domain_Mask", "i32", (/rows11, cols11/))
291 call var%setFillValue(nodata_i4)
292 call var%setData(merge(1_i4, 0_i4, mask11))
293 call var%setAttribute("long_name", "Mask at Level 11")
294
295 var = nc%setVariable("L11_TSrout", "i32", (/nts/))
296 call var%setFillValue(nodata_i4)
297 call var%setData(l11_tsrout(idomain))
298 call var%setAttribute("long_name", "routing resolution at Level 11")
299 call var%setAttribute("units", "s")
300
301 var = nc%setVariable("L11_Id", "i32", (/rows11, cols11/))
302 call var%setFillValue(nodata_i4)
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")
305
306 var = nc%setVariable("L11_fDir", "i32", (/rows11, cols11/))
307 call var%setFillValue(nodata_i4)
308 call var%setData(unpack(l11_fdir(s11 : e11), mask11, nodata_i4))
309 call var%setAttribute("long_name", "flow Direction at Level 11")
310
311 var = nc%setVariable("L11_fAcc", "f64", (/rows11, cols11/))
312 call var%setFillValue(nodata_dp)
313 call var%setData(unpack(l11_facc(s11:e11), mask11, nodata_dp))
314 call var%setAttribute("long_name", "flow accumulation at Level 11")
315
316 var = nc%setVariable("L11_rowOut", "i32", (/rows11, cols11/))
317 call var%setFillValue(nodata_i4)
318 call var%setData(unpack(l11_rowout(s11 : e11), mask11, nodata_i4))
319 call var%setAttribute("long_name", "Grid vertical location of the Outlet at Level 11")
320
321 var = nc%setVariable("L11_colOut", "i32", (/rows11, cols11/))
322 call var%setFillValue(nodata_i4)
323 call var%setData(unpack(l11_colout(s11 : e11), mask11, nodata_i4))
324 call var%setAttribute("long_name", "Grid horizontal location of the Outlet at Level 11")
325
326 var = nc%setVariable("L11_fromN", "i32", (/links/))
327 call var%setFillValue(nodata_i4)
328 call var%setData(l11_fromn(s11 : e11))
329 call var%setAttribute("long_name", "From Node")
330
331 var = nc%setVariable("L11_toN", "i32", (/links/))
332 call var%setFillValue(nodata_i4)
333 call var%setData(l11_ton(s11 : e11))
334 call var%setAttribute("long_name", "To Node")
335
336 var = nc%setVariable("L11_rOrder", "i32", (/links/))
337 call var%setFillValue(nodata_i4)
338 call var%setData(l11_rorder(s11 : e11))
339 call var%setAttribute("long_name", "Network routing order at Level 11")
340
341 var = nc%setVariable("L11_label", "i32", (/links/))
342 call var%setFillValue(nodata_i4)
343 call var%setData(l11_label(s11 : e11))
344 call var%setAttribute("long_name", "Label Id [0='', 1=HeadWater, 2=Sink] at Level 11")
345
346 var = nc%setVariable("L11_sink", "i32", (/links/))
347 call var%setFillValue(nodata_i4)
348 allocate(dummy(e11 - s11 + 1))
349 dummy = 0_i4
350 where(l11_sink(s11 : e11))
351 dummy = 1_i4
352 end where
353 ! call var%setData(merge(1_i4, 0_i4, L11_sink(s11 : e11)))
354 call var%setData(dummy)
355 deallocate(dummy)
356 call var%setAttribute("long_name", ".true. if sink node reached at Level 11")
357
358 var = nc%setVariable("L11_netPerm", "i32", (/links/))
359 call var%setFillValue(nodata_i4)
360 call var%setData(l11_netperm(s11 : e11))
361 call var%setAttribute("long_name", "Routing sequence (permutation of L11_rOrder) at Level 11")
362
363 var = nc%setVariable("L11_fRow", "i32", (/links/))
364 call var%setFillValue(nodata_i4)
365 call var%setData(l11_frow(s11 : e11))
366 call var%setAttribute("long_name", "From row in L0 grid at Level 11")
367
368 var = nc%setVariable("L11_fCol", "i32", (/links/))
369 call var%setFillValue(nodata_i4)
370 call var%setData(l11_fcol(s11 : e11))
371 call var%setAttribute("long_name", "From col in L0 grid at Level 11")
372
373 var = nc%setVariable("L11_tRow", "i32", (/links/))
374 call var%setFillValue(nodata_i4)
375 call var%setData(l11_trow(s11 : e11))
376 call var%setAttribute("long_name", "To row in L0 grid at Level 11")
377
378 var = nc%setVariable("L11_tCol", "i32", (/links/))
379 call var%setFillValue(nodata_i4)
380 call var%setData(l11_tcol(s11 : e11))
381 call var%setAttribute("long_name", "To Col in L0 grid at Level 11")
382
383 var = nc%setVariable("L11_length", "f64", (/links/))
384 call var%setFillValue(nodata_dp)
385 call var%setData(l11_length(s11 : e11))
386 call var%setAttribute("long_name", "Total length of river link [m]")
387
388 var = nc%setVariable("L11_aFloodPlain", "f64", (/links/))
389 call var%setFillValue(nodata_dp)
390 call var%setData(l11_afloodplain(s11 : e11))
391 call var%setAttribute("long_name", "Area of the flood plain [m2]")
392
393 var = nc%setVariable("L11_slope", "f64", (/links/))
394 call var%setFillValue(nodata_dp)
395 call var%setData(l11_slope(s11 : e11))
396 call var%setAttribute("long_name", "Average slope of river link")
397
398 var = nc%setVariable("L11_L1_Id", "i32", (/rows11, cols11/))
399 call var%setFillValue(nodata_i4)
400 call var%setData(unpack(l11_l1_id(s11 : e11), mask11, nodata_i4))
401 call var%setAttribute("long_name", "Mapping of L1 Id on L11")
402
403 var = nc%setVariable("gaugeNodeList", "i32", &
404 (/nc%setDimension("Ngauges", size(domain_mrm(idomain)%gaugeNodeList(:)))/) &
405 )
406 call var%setFillValue(nodata_i4)
407 call var%setData(domain_mrm(idomain)%gaugeNodeList(:))
408 call var%setAttribute("long_name", "cell ID of gauges")
409
410 var = nc%setVariable("InflowGaugeNodeList", "i32", &
411 (/nc%setDimension("nInflowGauges", size(domain_mrm(idomain)%InflowGaugeNodeList(:)))/) &
412 )
413 call var%setFillValue(nodata_i4)
414 call var%setData(domain_mrm(idomain)%InflowGaugeNodeList(:))
415 call var%setAttribute("long_name", "cell ID of gauges")
416
417 if (processmatrix(8, 1) .eq. 3) then
418 var = nc%setVariable("L11_celerity", "f64", (/links/)) ! celerity
419 call var%setFillValue(nodata_dp)
420 call var%setData(l11_celerity(s11:e11))
421 call var%setAttribute("long_name", "celerity at Level 11")
422 end if
423
424 ! free dummy variables
425 deallocate(dummy_d3)
426 call nc%close()
427
428 end subroutine mrm_write_restart
429
430 ! ------------------------------------------------------------------
431
432 ! NAME
433 ! mrm_read_restart_states
434
435 ! PURPOSE
436 !> \brief read routing states
437
438 !> \details This subroutine reads the routing states from
439 !> mRM_states_<domain_id>.nc that has to be in the given
440 !> path directory. This subroutine has to be called directly
441 !> each time the mHM_eval or mRM_eval is called such that the
442 !> the states are always the same at the first simulation time
443 !> step, crucial for optimization.
444
445 ! INTENT(IN)
446 !> \param[in] "integer(i4) :: iDomain" number of domains
447 !> \param[in] "character(256) :: InFile" Input Path including trailing slash
448
449 ! HISTORY
450 !> \authors Stephan Thober
451
452 !> \date Sep 2015
453
454 ! Modifications:
455 ! David Schaefer Mar 2016 - mo_netcdf
456 ! Stephan Thober May 2016 - split L0_OutletCoord into L0_rowOutlet & L0_colOutlet because multiple outlets could exist
457 ! Robert Schweppe Jun 2018 - refactoring and reformatting
458
459 subroutine mrm_read_restart_states(iDomain, domainID, InFile)
460
465 use mo_netcdf, only : ncdataset, ncvariable
466 use mo_string_utils, only : num2str
467
468 implicit none
469
470 ! number of Domain
471 integer(i4), intent(in) :: idomain
472
473 integer(i4), intent(in) :: domainid
474
475 ! Input Path including trailing slash
476 character(256), intent(in) :: infile
477
478 integer(i4) :: ii
479
480 ! start index at level 11
481 integer(i4) :: s11
482
483 ! end index at level 11
484 integer(i4) :: e11
485
486 ! mask at level 11
487 logical, dimension(:, :), allocatable :: mask11
488
489 ! dummy, 2 dimension
490 real(dp), dimension(:, :), allocatable :: dummyd2
491
492 ! dummy, 3 dimension
493 real(dp), dimension(:, :, :), allocatable :: dummyd3
494
495 character(256) :: fname
496
497 type(ncdataset) :: nc
498
499 type(ncvariable) :: var
500
501 !TODO-RIV-TEMP: read/write restart for riv-temp process
502
503 ! set file name
504 fname = trim(infile)
505
506 ! get Domain info at L11 including ncells, start, end, and mask
507 s11 = level11(idomain)%iStart
508 e11 = level11(idomain)%iEnd
509 mask11 = level11(idomain)%mask
510
511 nc = ncdataset(fname, "r")
512
513 ! simulated discharge at each node
514 var = nc%getVariable("L11_Qmod")
515 call var%getData(dummyd2)
516 l11_qmod(s11 : e11) = pack(dummyd2, mask11)
517
518 ! Total outflow from cells L11 at time tt
519 var = nc%getVariable("L11_qOUT")
520 call var%getData(dummyd2)
521 l11_qout(s11 : e11) = pack(dummyd2, mask11)
522
523 ! Total discharge inputs at t-1 and t
524 var = nc%getVariable("L11_qTIN")
525 call var%getData(dummyd3)
526 do ii = 1, nroutingstates
527 l11_qtin(s11 : e11, ii) = pack(dummyd3(:, :, ii), mask11)
528 end do
529
530 ! Routed outflow leaving a node
531 var = nc%getVariable("L11_qTR")
532 call var%getData(dummyd3)
533 do ii = 1, nroutingstates
534 l11_qtr(s11 : e11, ii) = pack(dummyd3(:, :, ii), mask11)
535 end do
536
537 ! kappa: Muskingum travel time parameter.
538 var = nc%getVariable("L11_K")
539 call var%getData(dummyd2)
540 l11_k(s11 : e11) = pack(dummyd2, mask11)
541
542 ! xi: Muskingum diffusion parameter
543 var = nc%getVariable("L11_xi")
544 call var%getData(dummyd2)
545 l11_xi(s11 : e11) = pack(dummyd2, mask11)
546
547 ! Routing parameter C1=f(K,xi, DT) (Chow, 25-41)
548 var = nc%getVariable("L11_C1")
549 call var%getData(dummyd2)
550 l11_c1(s11 : e11) = pack(dummyd2, mask11)
551
552 ! Routing parameter C2 =f(K,xi, DT) (Chow, 25-41)
553 var = nc%getVariable("L11_C2")
554 call var%getData(dummyd2)
555 l11_c2(s11 : e11) = pack(dummyd2, mask11)
556
557 ! Fraction of the flood plain with impervious cover
558 var = nc%getVariable("L11_nLinkFracFPimp")
559 deallocate(dummyd3)
560 call var%getData(dummyd3)
561 do ii = 1, nlcoverscene
562 l11_nlinkfracfpimp(s11 : e11, ii) = pack(dummyd3(:, :, ii), mask11)
563 end do
564
565 ! free memory
566 deallocate(dummyd2, dummyd3)
567
568 end subroutine mrm_read_restart_states
569
570 ! ------------------------------------------------------------------
571
572 ! NAME
573 ! mrm_read_restart_config
574
575 ! PURPOSE
576 !> \brief reads Level 11 configuration from a restart directory
577
578 !> \details read Level 11 configuration variables from a given restart
579 !> directory and initializes all Level 11 configuration variables,
580 !> that are initialized in L11_variable_init,
581 !> contained in module mo_startup.
582
583 ! INTENT(IN)
584 !> \param[in] "integer(i4) :: iDomain" number of Domain
585 !> \param[in] "character(256) :: InFile" Input Path including trailing slash
586
587 ! HISTORY
588 !> \authors Stephan Thober
589
590 !> \date Apr 2013
591
592 ! Modifications:
593 ! Matthias Zink Apr 2014 - added inflow gauge
594 ! Stephan Thober Aug 2015 - adapted for mRM
595 ! Stephan Thober Sep 2015 - added all read restart commands in this subroutine
596 ! Stephan Thober Sep 2015 - added L11_areaCell, L1_ID and L1_L11_Id for routing resolution higher than hydrology resolution
597 ! David Schaefer Mar 2016 - mo_netcdf
598 ! Stephan Thober Nov 2016 - added L11_TSrout, ProcessMatrix
599 ! Robert Schweppe Jun 2018 - refactoring and reformatting
600 ! Stephan Thober May 2019 - added L0 info required for Process 3
601
602 subroutine mrm_read_restart_config(iDomain, domainID, InFile)
603
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
616
617 implicit none
618
619 ! number of Domain
620 integer(i4), intent(in) :: idomain
621
622 ! domain
623 integer(i4), intent(in) :: domainid
624
625 ! Input Path including trailing slash
626 character(256), intent(in) :: infile
627
628 character(256) :: fname
629
630 ! Mask at Level 0
631 logical, allocatable, dimension(:, :) :: mask0
632
633 ! Mask at Level 1
634 logical, allocatable, dimension(:, :) :: mask1
635
636 ! Mask at Level 11
637 logical, allocatable, dimension(:, :) :: mask11
638
639 ! dummy, 1 dimension I4
640 integer(i4), allocatable, dimension(:) :: dummyi1
641
642 ! dummy, 2 dimension I4
643 integer(i4), allocatable, dimension(:, :) :: dummyi2
644
645 ! dummy, DP
646 real(dp), allocatable, dimension(:) :: dummyd1
647 real(dp), allocatable, dimension(:, :) :: dummyd2
648 real(dp), allocatable :: dummyd0
649
650 type(ncdataset) :: nc
651
652 type(ncvariable) :: var
653
654
655 ! set file name
656 fname = trim(infile)
657 call message(' Reading mRM restart file: ', trim(adjustl(fname)), ' ...')
658
659 ! get Domain info at L11 mask
660 mask0 = level0(domainmeta%L0DataFrom(idomain))%mask
661 mask1 = level1(idomain)%mask
662 mask11 = level11(idomain)%mask
663
664 nc = ncdataset(fname, "r")
665
666 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
667 ! Read Process Matrix for check <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
668 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
669 var = nc%getVariable("ProcessMatrix")
670 allocate(dummyi1(size(processmatrix, dim = 1)))
671 call var%getData(dummyi1)
672 if (dummyi1(8) .ne. processmatrix(8, 1)) then
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')
679 end if
680 deallocate(dummyi1)
681
682 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
683 ! Read L0 variables <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
684 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
685 if (processmatrix(8, 1) .eq. 3_i4) then
686 ! add L0_fdir, L0_fAcc, L0_slope, L0_streamnet
687 var = nc%getVariable("L0_fDir")
688 call var%getData(dummyi2)
689 call append(l0_fdir, pack(dummyi2, mask0))
690
691 var = nc%getVariable("L0_fAcc")
692 call var%getData(dummyi2)
693 call append(l0_facc, pack(dummyi2, mask0))
694
695 var = nc%getVariable("L0_slope")
696 call var%getData(dummyd2)
697 call append(l0_slope, pack(dummyd2, mask0))
698
699 var = nc%getVariable("L0_streamnet")
700 call var%getData(dummyi2)
701 call append(l0_streamnet, pack(dummyi2, mask0))
702 end if
703
704 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
705 ! Read L1 variables <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
706 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
707 var = nc%getVariable("L1_L11_Id")
708 call var%getData(dummyi2)
709 call append(l1_l11_id, pack(dummyi2, mask1))
710
711 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
712 ! Read L11 variables <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
713 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
714 ! read L11_TSrout
715 if (idomain .eq. 1) then
716 allocate(l11_tsrout(domainmeta%nDomains))
718 end if
719 var = nc%getVariable("L11_TSrout")
720 call var%getData(dummyd0)
721 l11_tsrout(idomain) = dummyd0
722
723 ! L11 data sets
724 ! Mapping of L1 Ids on L1
725 var = nc%getVariable("L11_L1_Id")
726 call var%getData(dummyi2)
727 call append(l11_l1_id, pack(dummyi2, mask11))
728
729 ! Flow direction (standard notation)
730 var = nc%getVariable("L11_fDir")
731 call var%getData(dummyi2)
732 call append(l11_fdir, pack(dummyi2, mask11))
733 ! append Number of Outlets at Level 11 (where facc == 0 )
734 call append(l11_noutlets, count((dummyi2 .eq. 0_i4)))
735
736 ! Flow accumulation
737 var = nc%getVariable("L11_fAcc")
738 call var%getData(dummyd2)
739 call append(l11_facc, pack(dummyd2, mask11))
740
741 ! Grid vertical location of the Outlet
742 var = nc%getVariable("L11_rowOut")
743 call var%getData(dummyi2)
744 call append(l11_rowout, pack(dummyi2, mask11))
745
746 ! Grid horizontal location of the Outlet
747 var = nc%getVariable("L11_colOut")
748 call var%getData(dummyi2)
749 call append(l11_colout, pack(dummyi2, mask11))
750
751 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
752 ! From Node
753 var = nc%getVariable("L11_fromN")
754 call var%getData(dummyi1)
755 call append(l11_fromn, dummyi1)
756
757 ! To Node
758 var = nc%getVariable("L11_toN")
759 call var%getData(dummyi1)
760 call append(l11_ton, dummyi1)
761
762 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
763 ! Network routing order
764 var = nc%getVariable("L11_rOrder")
765 call var%getData(dummyi1)
766 call append(l11_rorder, dummyi1)
767
768 ! Label Id [0='', 1=HeadWater, 2=Sink]
769 var = nc%getVariable("L11_label")
770 call var%getData(dummyi1)
771 call append(l11_label, dummyi1)
772
773 ! .true. if sink node reached
774 var = nc%getVariable("L11_sink")
775 call var%getData(dummyi1)
776 call append(l11_sink, (dummyi1 .eq. 1_i4))
777
778 ! Routing sequence (permutation of L11_rOrder)
779 var = nc%getVariable("L11_netPerm")
780 call var%getData(dummyi1)
781 call append(l11_netperm, dummyi1)
782
783 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
784 ! From row in L0 grid
785 var = nc%getVariable("L11_fRow")
786 call var%getData(dummyi1)
787 call append(l11_frow, dummyi1)
788
789 ! From col in L0 grid
790 var = nc%getVariable("L11_fCol")
791 call var%getData(dummyi1)
792 call append(l11_fcol, dummyi1)
793
794 ! To row in L0 grid
795 var = nc%getVariable("L11_tRow")
796 call var%getData(dummyi1)
797 call append(l11_trow, dummyi1)
798
799 ! To col in L0 grid
800 var = nc%getVariable("L11_tCol")
801 call var%getData(dummyi1)
802 call append(l11_tcol, dummyi1)
803
804
805 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
806 ! read gaugenodelist
807 var = nc%getVariable("gaugeNodeList")
808 call var%getData(dummyi1)
809 domain_mrm(idomain)%gaugeNodeList(:) = dummyi1
810
811 ! read InflowGaugeNodelist
812 if (domain_mrm(idomain)%nInflowGauges > 0) then
813 var = nc%getVariable("InflowGaugeNodeList")
814 call var%getData(dummyi1)
815 domain_mrm(idomain)%InflowgaugeNodeList(:) = dummyi1
816 end if
817
818 ! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
819 ! L11 network data sets
820 ! [m] Total length of river link
821 var = nc%getVariable("L11_length")
822 call var%getData(dummyd1)
823 call append(l11_length, dummyd1)
824
825 ! [m2] Area of the flood plain
826 var = nc%getVariable("L11_aFloodPlain")
827 call var%getData(dummyd1)
828 call append(l11_afloodplain, dummyd1)
829
830 ! Average slope of river link
831 var = nc%getVariable("L11_slope")
832 call var%getData(dummyd1)
833 call append(l11_slope, dummyd1)
834
835 end subroutine mrm_read_restart_config
836
837end module mo_mrm_restart
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
common restart tools
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
Restart routines.
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