5.13.2-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_restart.f90
Go to the documentation of this file.
1!> \file mo_restart.f90
2!> \brief \copybrief mo_restart
3!> \details \copydetails mo_restart
4
5!> \brief reading and writing states, fluxes and configuration for restart of mHM.
6!> \details routines are seperated for reading and writing variables for:
7!! - states and fluxes, and
8!! - configuration.
9!!
10!! Reading of L11 configuration is also seperated from the rest,
11!! since it is only required when routing is activated.
12!> \authors Stephan Thober
13!> \date Jul 2013
14!> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
15!! mHM is released under the LGPLv3+ license \license_note
16!> \ingroup f_mhm
18
20
21 IMPLICIT NONE
22
23 PRIVATE
24
25 PUBLIC :: read_restart_states ! read restart files for state variables from a given path
26 PUBLIC :: write_restart_files ! write restart files for configuration to a given path
27
28CONTAINS
29
30 !> \brief write restart files for each domain
31 !> \details write restart files for each domain. For each domain
32 !! three restart files are written. These are xxx_states.nc,
33 !! xxx_L11_config.nc, and xxx_config.nc (xxx being the three digit
34 !! domain index). If a variable is added here, it should also be added
35 !! in the read restart routines below.
36 !> \changelog
37 !! - Stephan Thober Aug 2015
38 !! - moved write of routing states to mRM
39 !! - David Schaefer Nov 2015
40 !! - mo_netcdf
41 !! - Stephan Thober Nov 2016
42 !! - moved processMatrix to common variables
43 !! - Zink M. Demirel C. Mar 2017
44 !! - Added Jarvis soil water stress function at SM process(3)
45 !! - Robert Schweppe Feb 2018
46 !! - Removed all L0 references
47 !! - Robert Schweppe Jun 2018
48 !! - refactoring and reformatting
49 !! - Stephan Thober Dec 2022
50 !! - added grid info for level0
51 !> \authors Stephan Thober
52 !> \date Jun 2014
53 subroutine write_restart_files(OutFile)
54
62
63 use mo_kind, only : dp, i4
64 use mo_message, only : message
67 use mo_netcdf, only : ncdataset, ncdimension, ncvariable
68 use mo_string_utils, only : num2str
69
70 implicit none
71
72 character(256) :: fname
73
74 ! Output Path for each domain
75 character(256), dimension(:), intent(in) :: outfile
76
77 integer(i4) :: idomain, domainid
78
79 integer(i4) :: ii
80
81 ! start index at level 1
82 integer(i4) :: s1
83
84 ! end index at level 1
85 integer(i4) :: e1
86
87 ! mask at level 1
88 logical, dimension(:, :), allocatable :: mask1
89
90 ! dummy variable
91 real(dp), dimension(:, :, :), allocatable :: dummy_3d
92 real(dp), dimension(:), allocatable :: dummy_1d
93
94 integer(i4) :: max_extent
95
96 type(ncdataset) :: nc
97
98 type(ncdimension) :: rows1, cols1, soil1, lcscenes, lais
99
100 type(ncvariable) :: var
101
102
103 ! get maximum extent of one dimension 2 or 3
104 max_extent = max(nsoilhorizons_mhm, nlcoverscene, nlai)
105
106 domain_loop : do idomain = 1, domainmeta%nDomains
107 domainid = domainmeta%indices(idomain)
108
109 ! write restart file for iDomain
110 fname = trim(outfile(idomain))
111 ! print a message
112 call message(" Writing Restart-file: ", trim(adjustl(fname)), " ...")
113
114 nc = ncdataset(fname, "w")
115
116 call write_grid_info(level1(idomain), "1", nc)
117 call write_grid_info(level0(domainmeta%L0DataFrom(idomain)), "0", nc)
118
119 rows1 = nc%getDimension("nrows1")
120 cols1 = nc%getDimension("ncols1")
121
122 ! write the dimension to the file and also save bounds
123 allocate(dummy_1d(nsoilhorizons_mhm+1))
124 dummy_1d(1) = 0.0_dp
125 dummy_1d(2:nsoilhorizons_mhm+1) = horizondepth_mhm(:)
126 soil1 = nc%setCoordinate(trim(soilhorizonsvarname), nsoilhorizons_mhm, dummy_1d, 2_i4)
127 deallocate(dummy_1d)
128 allocate(dummy_1d(nlcoverscene+1))
129 dummy_1d(1:nlcoverscene) = lc_year_start(:)
130 ! this is done because bounds are always stored as real so e.g.
131 ! 1981-1990,1991-2000 is thus saved as 1981.0-1991.0,1991.0-2001.0
132 ! it is translated back into ints correctly during reading
133 dummy_1d(nlcoverscene+1) = lc_year_end(nlcoverscene) + 1
134 lcscenes = nc%setCoordinate(trim(landcoverperiodsvarname), nlcoverscene, dummy_1d, 0_i4)
135 deallocate(dummy_1d)
136 ! write the dimension to the file
137 lais = nc%setCoordinate(trim(laivarname), nlai, laiboundaries, 0_i4)
138
139 ! for appending and intialization
140 allocate(dummy_3d(rows1%getLength(), cols1%getLength(), max_extent))
141 allocate(mask1(rows1%getLength(), cols1%getLength()))
142 s1 = level1(idomain)%iStart
143 e1 = level1(idomain)%iEnd
144 mask1 = level1(idomain)%mask
145
146 var = nc%setVariable("L1_Inter", "f64", (/rows1, cols1/))
147 call var%setFillValue(nodata_dp)
148 call var%setData(unpack(l1_inter(s1 : e1), mask1, nodata_dp))
149 call var%setAttribute("long_name", "Interception storage at level 1")
150
151 var = nc%setVariable("L1_snowPack", "f64", (/rows1, cols1/))
152 call var%setFillValue(nodata_dp)
153 call var%setData(unpack(l1_snowpack(s1 : e1), mask1, nodata_dp))
154 call var%setAttribute("long_name", "Snowpack at level 1")
155
156 var = nc%setVariable("L1_sealSTW", "f64", (/rows1, cols1/))
157 call var%setFillValue(nodata_dp)
158 call var%setData(unpack(l1_sealstw(s1 : e1), mask1, nodata_dp))
159 call var%setAttribute("long_name", "Retention storage of impervious areas at level 1")
160
161 do ii = 1, nsoilhorizons_mhm
162 dummy_3d(:, :, ii) = unpack(l1_soilmoist(s1 : e1, ii), mask1, nodata_dp)
163 end do
164
165 var = nc%setVariable("L1_soilMoist", "f64", (/rows1, cols1, soil1/))
166 call var%setFillValue(nodata_dp)
167 call var%setData(dummy_3d(:, :, 1 : nsoilhorizons_mhm))
168 call var%setAttribute("long_name", "soil moisture at level 1")
169
170 var = nc%setVariable("L1_unsatSTW", "f64", (/rows1, cols1/))
171 call var%setFillValue(nodata_dp)
172 call var%setData(unpack(l1_unsatstw(s1 : e1), mask1, nodata_dp))
173 call var%setAttribute("long_name", "upper soil storage at level 1")
174
175 var = nc%setVariable("L1_satSTW", "f64", (/rows1, cols1/))
176 call var%setFillValue(nodata_dp)
177 call var%setData(unpack(l1_satstw(s1 : e1), mask1, nodata_dp))
178 call var%setAttribute("long_name", "groundwater storage at level 1")
179
180 do ii = 1, nsoilhorizons_mhm
181 dummy_3d(:, :, ii) = unpack(l1_aetsoil(s1 : e1, ii), mask1, nodata_dp)
182 end do
183
184 var = nc%setVariable("L1_aETSoil", "f64", (/rows1, cols1, soil1/))
185 call var%setFillValue(nodata_dp)
186 call var%setData(dummy_3d(:, :, 1 : nsoilhorizons_mhm))
187 call var%setAttribute("long_name", "soil actual ET at level 1")
188
189 var = nc%setVariable("L1_aETCanopy", "f64", (/rows1, cols1/))
190 call var%setFillValue(nodata_dp)
191 call var%setData(unpack(l1_aetcanopy(s1 : e1), mask1, nodata_dp))
192 call var%setAttribute("long_name", "canopy actual ET at level 1")
193
194 var = nc%setVariable("L1_aETSealed", "f64", (/rows1, cols1/))
195 call var%setFillValue(nodata_dp)
196 call var%setData(unpack(l1_aetsealed(s1 : e1), mask1, nodata_dp))
197 call var%setAttribute("long_name", "sealed actual ET at level 1")
198
199 var = nc%setVariable("L1_baseflow", "f64", (/rows1, cols1/))
200 call var%setFillValue(nodata_dp)
201 call var%setData(unpack(l1_baseflow(s1 : e1), mask1, nodata_dp))
202 call var%setAttribute("long_name", "baseflow at level 1")
203
204 do ii = 1, nsoilhorizons_mhm
205 dummy_3d(:, :, ii) = unpack(l1_infilsoil(s1 : e1, ii), mask1, nodata_dp)
206 end do
207
208 var = nc%setVariable("L1_infilSoil", "f64", (/rows1, cols1, soil1/))
209 call var%setFillValue(nodata_dp)
210 call var%setData(dummy_3d(:, :, 1 : nsoilhorizons_mhm))
211 call var%setAttribute("long_name", "soil in-exfiltration at level 1")
212
213 var = nc%setVariable("L1_fastRunoff", "f64", (/rows1, cols1/))
214 call var%setFillValue(nodata_dp)
215 call var%setData(unpack(l1_fastrunoff(s1 : e1), mask1, nodata_dp))
216 call var%setAttribute("long_name", "fast runoff")
217
218 var = nc%setVariable("L1_percol", "f64", (/rows1, cols1/))
219 call var%setFillValue(nodata_dp)
220 call var%setData(unpack(l1_percol(s1 : e1), mask1, nodata_dp))
221 call var%setAttribute("long_name", "percolation at level 1")
222
223 var = nc%setVariable("L1_melt", "f64", (/rows1, cols1/))
224 call var%setFillValue(nodata_dp)
225 call var%setData(unpack(l1_melt(s1 : e1), mask1, nodata_dp))
226 call var%setAttribute("long_name", "snow melt at level 1")
227
228 var = nc%setVariable("L1_preEffect", "f64", (/rows1, cols1/))
229 call var%setFillValue(nodata_dp)
230 call var%setData(unpack(l1_preeffect(s1 : e1), mask1, nodata_dp))
231 call var%setAttribute("long_name", "effective precip. depth (snow melt + rain) at level 1")
232
233 var = nc%setVariable("L1_rain", "f64", (/rows1, cols1/))
234 call var%setFillValue(nodata_dp)
235 call var%setData(unpack(l1_rain(s1 : e1), mask1, nodata_dp))
236 call var%setAttribute("long_name", "rain (liquid water) at level 1")
237
238 var = nc%setVariable("L1_runoffSeal", "f64", (/rows1, cols1/))
239 call var%setFillValue(nodata_dp)
240 call var%setData(unpack(l1_runoffseal(s1 : e1), mask1, nodata_dp))
241 call var%setAttribute("long_name", "runoff from impervious area at level 1")
242
243 var = nc%setVariable("L1_slowRunoff", "f64", (/rows1, cols1/))
244 call var%setFillValue(nodata_dp)
245 call var%setData(unpack(l1_slowrunoff(s1 : e1), mask1, nodata_dp))
246 call var%setAttribute("long_name", "slow runoff at level 1")
247
248 var = nc%setVariable("L1_snow", "f64", (/rows1, cols1/))
249 call var%setFillValue(nodata_dp)
250 call var%setData(unpack(l1_snow(s1 : e1), mask1, nodata_dp))
251 call var%setAttribute("long_name", "snow (solid water) at level 1")
252
253 var = nc%setVariable("L1_Throughfall", "f64", (/rows1, cols1/))
254 call var%setFillValue(nodata_dp)
255 call var%setData(unpack(l1_throughfall(s1 : e1), mask1, nodata_dp))
256 call var%setAttribute("long_name", "throughfall at level 1")
257
258 var = nc%setVariable("L1_total_runoff", "f64", (/rows1, cols1/))
259 call var%setFillValue(nodata_dp)
260 call var%setData(unpack(l1_total_runoff(s1 : e1), mask1, nodata_dp))
261 call var%setAttribute("long_name", "total runoff at level 1")
262
263 call write_eff_params(mask1, s1, e1, rows1, cols1, soil1, lcscenes, lais, nc)
264
265 call nc%close()
266
267 deallocate(dummy_3d, mask1)
268 end do domain_loop
269
270 end subroutine write_restart_files
271
272
273 !> \brief reads fluxes and state variables from file
274 !> \details read fluxes and state variables from given
275 !! restart directory and initialises all state variables
276 !! that are initialized in the subroutine initialise,
277 !! contained in module mo_startup.
278 !> \changelog
279 !! - Stephan Thober Aug 2015
280 !! - moved read of routing states to mRM
281 !! - David Schaefer Nov 2015
282 !! - mo_netcdf
283 !! - Stephan Thober Nov 2016
284 !! - moved processMatrix to common variables
285 !! - Robert Schweppe Jun 2018
286 !! - refactoring and reformatting
287 !! - Sebastian Müller Mar 2023
288 !! - compatibility layer for 2D/3D data
289 !! - move reading of nLAI to mo_startup (needed beforehand)
290 !> \authors Stephan Thober
291 !> \date Apr 2013
292 subroutine read_restart_states(iDomain, domainID, InFile)
293
299 use mo_kind, only : dp, i4
307 ! neutron count
309
310 use mo_netcdf, only : ncdataset, ncdimension, ncvariable
311 use mo_string_utils, only : num2str
312 use mo_message, only: message, error_message
313
314 implicit none
315
316 !> number of domain
317 integer(i4), intent(in) :: idomain
318 !> ID of domain
319 integer(i4), intent(in) :: domainid
320 !> Input Path including trailing slash
321 character(256), intent(in) :: infile
322
323 character(256) :: fname
324 ! variable rank
325 integer(i4) :: var_rank
326 ! loop index
327 integer(i4) :: ii, jj
328 ! start index at level 1
329 integer(i4) :: s1
330 ! end index at level 1
331 integer(i4) :: e1
332 ! mask at level 1
333 logical, dimension(:, :), allocatable :: mask1
334 ! dummy, 2 dimension
335 real(dp), dimension(:, :), allocatable :: dummyd2
336 ! dummy, 3 dimension
337 real(dp), dimension(:, :, :), allocatable :: dummyd3
338 ! dummy, 4 dimension
339 real(dp), dimension(:, :, :, :), allocatable :: dummyd4
340
341 type(ncdataset) :: nc
342 type(ncvariable) :: var
343
344
345 fname = trim(infile)
346 call message(' Reading states from ', trim(adjustl(fname)),' ...')
347
348 ! get domain information at level 1
349 allocate(mask1(level1(idomain)%nrows, level1(idomain)%ncols))
350 mask1 = level1(idomain)%mask
351 s1 = level1(idomain)%iStart
352 e1 = level1(idomain)%iEnd
353
354 nc = ncdataset(fname, "r")
355
356 if (nc%hasVariable('L1_Inter')) then
357 !-------------------------------------------
358 ! STATE VARIABLES (optionally)
359 !-------------------------------------------
360
361 ! Interception
362 var = nc%getVariable("L1_Inter")
363 call var%getData(dummyd2)
364 l1_inter(s1 : e1) = pack(dummyd2, mask1)
365
366 ! Snowpack
367 var = nc%getVariable("L1_snowPack")
368 call var%getData(dummyd2)
369 l1_snowpack(s1 : e1) = pack(dummyd2, mask1)
370
371 ! Retention storage of impervious areas
372 var = nc%getVariable("L1_sealSTW")
373 call var%getData(dummyd2)
374 l1_sealstw(s1 : e1) = pack(dummyd2, mask1)
375
376 ! upper soil storage
377 var = nc%getVariable("L1_unsatSTW")
378 call var%getData(dummyd2)
379 l1_unsatstw(s1 : e1) = pack(dummyd2, mask1)
380
381 ! groundwater storage
382 var = nc%getVariable("L1_satSTW")
383 call var%getData(dummyd2)
384 l1_satstw(s1 : e1) = pack(dummyd2, mask1)
385
386 ! Soil moisture of each horizon
387 var = nc%getVariable("L1_soilMoist")
388 call var%getData(dummyd3)
389 do ii = 1, nsoilhorizons_mhm
390 l1_soilmoist(s1 : e1, ii) = pack(dummyd3(:, :, ii), mask1)
391 end do
392
393 !-------------------------------------------
394 ! FLUXES (optionally)
395 !-------------------------------------------
396
397 ! soil actual ET
398 var = nc%getVariable("L1_aETSoil")
399 call var%getData(dummyd3)
400 do ii = 1, nsoilhorizons_mhm
401 l1_aetsoil(s1 : e1, ii) = pack(dummyd3(:, :, ii), mask1)
402 end do
403
404 ! canopy actual ET
405 var = nc%getVariable("L1_aETCanopy")
406 call var%getData(dummyd2)
407 l1_aetcanopy(s1 : e1) = pack(dummyd2, mask1)
408
409 ! sealed area actual ET
410 var = nc%getVariable("L1_aETSealed")
411 call var%getData(dummyd2)
412 l1_aetsealed(s1 : e1) = pack(dummyd2, mask1)
413
414 ! baseflow
415 var = nc%getVariable("L1_baseflow")
416 call var%getData(dummyd2)
417 l1_baseflow(s1 : e1) = pack(dummyd2, mask1)
418
419 ! soil in-exfiltration
420 var = nc%getVariable("L1_infilSoil")
421 call var%getData(dummyd3)
422 do ii = 1, nsoilhorizons_mhm
423 l1_infilsoil(s1 : e1, ii) = pack(dummyd3(:, :, ii), mask1)
424 end do
425
426 ! fast runoff
427 var = nc%getVariable("L1_fastRunoff")
428 call var%getData(dummyd2)
429 l1_fastrunoff(s1 : e1) = pack(dummyd2, mask1)
430
431 ! snow melt
432 var = nc%getVariable("L1_melt")
433 call var%getData(dummyd2)
434 l1_melt(s1 : e1) = pack(dummyd2, mask1)
435
436 ! percolation
437 var = nc%getVariable("L1_percol")
438 call var%getData(dummyd2)
439 l1_percol(s1 : e1) = pack(dummyd2, mask1)
440
441 ! effective precip. depth (snow melt + rain)
442 var = nc%getVariable("L1_preEffect")
443 call var%getData(dummyd2)
444 l1_preeffect(s1 : e1) = pack(dummyd2, mask1)
445
446 ! rain (liquid water)
447 var = nc%getVariable("L1_rain")
448 call var%getData(dummyd2)
449 l1_rain(s1 : e1) = pack(dummyd2, mask1)
450
451 ! runoff from impervious area
452 var = nc%getVariable("L1_runoffSeal")
453 call var%getData(dummyd2)
454 l1_runoffseal(s1 : e1) = pack(dummyd2, mask1)
455
456 ! slow runoff
457 var = nc%getVariable("L1_slowRunoff")
458 call var%getData(dummyd2)
459 l1_slowrunoff(s1 : e1) = pack(dummyd2, mask1)
460
461 ! snow (solid water)
462 var = nc%getVariable("L1_snow")
463 call var%getData(dummyd2)
464 l1_snow(s1 : e1) = pack(dummyd2, mask1)
465
466 ! throughfall
467 var = nc%getVariable("L1_Throughfall")
468 call var%getData(dummyd2)
469 l1_throughfall(s1 : e1) = pack(dummyd2, mask1)
470
471 ! total runoff
472 var = nc%getVariable("L1_total_runoff")
473 call var%getData(dummyd2)
474 l1_total_runoff(s1 : e1) = pack(dummyd2, mask1)
475 end if
476
477 !-------------------------------------------
478 ! EFFECTIVE PARAMETERS
479 !-------------------------------------------
480 var = nc%getVariable("L1_fSealed")
481 call var%getData(dummyd3)
482 do ii = 1, nlcoverscene
483 l1_fsealed(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
484 end do
485
486 ! exponent for the upper reservoir
487 var = nc%getVariable("L1_alpha")
488 var_rank = var%getrank()
489 select case(var_rank)
490 case(2)
491 ! distribute over all land cover scenes
492 call var%getData(dummyd2)
493 do ii = 1, nlcoverscene
494 l1_alpha(s1 : e1, 1, ii) = pack(dummyd2, mask1)
495 end do
496 case(3)
497 call var%getData(dummyd3)
498 do ii = 1, nlcoverscene
499 l1_alpha(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
500 end do
501 case default
502 call error_message("Restart: L1_alpha rank needs to be 2 or 3")
503 end select
504
505 ! increase of the Degree-day factor per mm of increase in precipitation
506 var = nc%getVariable("L1_degDayInc")
507 call var%getData(dummyd3)
508 do ii = 1, nlcoverscene
509 l1_degdayinc(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
510 end do
511
512 ! maximum degree-day factor
513 var = nc%getVariable("L1_degDayMax")
514 call var%getData(dummyd3)
515 do ii = 1, nlcoverscene
516 l1_degdaymax(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
517 end do
518
519 ! degree-day factor with no precipitation
520 var = nc%getVariable("L1_degDayNoPre")
521 call var%getData(dummyd3)
522 do ii = 1, nlcoverscene
523 l1_degdaynopre(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
524 end do
525
526 ! degree-day factor
527 var = nc%getVariable("L1_degDay")
528 var_rank = var%getrank()
529 select case(var_rank)
530 case(2)
531 ! distribute over all land cover scenes
532 call var%getData(dummyd2)
533 do ii = 1, nlcoverscene
534 l1_degday(s1 : e1, 1, ii) = pack(dummyd2, mask1)
535 end do
536 case(3)
537 call var%getData(dummyd3)
538 do ii = 1, nlcoverscene
539 l1_degday(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
540 end do
541 case default
542 call error_message("Restart: L1_degDay rank needs to be 2 or 3")
543 end select
544
545 ! Karstic percolation loss
546 var = nc%getVariable("L1_karstLoss")
547 call var%getData(dummyd2)
548 l1_karstloss(s1 : e1, 1, 1) = pack(dummyd2, mask1)
549
550 ! Fraction of roots in soil horizons
551 var = nc%getVariable("L1_fRoots")
552 call var%getData(dummyd4)
553 do jj = 1, nlcoverscene
554 do ii = 1, nsoilhorizons_mhm
555 l1_froots(s1 : e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
556 end do
557 end do
558
559 ! Maximum interception
560 var = nc%getVariable("L1_maxInter")
561 call var%getData(dummyd3)
562 do ii = 1, nlai
563 l1_maxinter(s1 : e1, ii, 1) = pack(dummyd3(:, :, ii), mask1)
564 end do
565
566 ! fast interflow recession coefficient ("L1_kFastFlow" or "L1_kfastFlow")
567 if (nc%hasvariable("L1_kFastFlow")) then
568 var = nc%getVariable("L1_kFastFlow")
569 else
570 var = nc%getVariable("L1_kfastFlow")
571 end if
572 call var%getData(dummyd3)
573 do ii = 1, nlcoverscene
574 l1_kfastflow(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
575 end do
576
577 ! slow interflow recession coefficient
578 var = nc%getVariable("L1_kSlowFlow")
579 var_rank = var%getrank()
580 select case(var_rank)
581 case(2)
582 ! distribute over all land cover scenes
583 call var%getData(dummyd2)
584 do ii = 1, nlcoverscene
585 l1_kslowflow(s1 : e1, 1, ii) = pack(dummyd2, mask1)
586 end do
587 case(3)
588 call var%getData(dummyd3)
589 do ii = 1, nlcoverscene
590 l1_kslowflow(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
591 end do
592 case default
593 call error_message("Restart: L1_kSlowFlow rank needs to be 2 or 3")
594 end select
595
596 ! baseflow recession coefficient
597 var = nc%getVariable("L1_kBaseFlow")
598 var_rank = var%getrank()
599 select case(var_rank)
600 case(2)
601 ! distribute over all land cover scenes
602 call var%getData(dummyd2)
603 do ii = 1, nlcoverscene
604 l1_kbaseflow(s1 : e1, 1, ii) = pack(dummyd2, mask1)
605 end do
606 case(3)
607 call var%getData(dummyd3)
608 do ii = 1, nlcoverscene
609 l1_kbaseflow(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
610 end do
611 case default
612 call error_message("Restart: L1_kBaseFlow rank needs to be 2 or 3")
613 end select
614
615 ! percolation coefficient
616 var = nc%getVariable("L1_kPerco")
617 var_rank = var%getrank()
618 select case(var_rank)
619 case(2)
620 ! distribute over all land cover scenes
621 call var%getData(dummyd2)
622 do ii = 1, nlcoverscene
623 l1_kperco(s1 : e1, 1, ii) = pack(dummyd2, mask1)
624 end do
625 case(3)
626 call var%getData(dummyd3)
627 do ii = 1, nlcoverscene
628 l1_kperco(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
629 end do
630 case default
631 call error_message("Restart: L1_kPerco rank needs to be 2 or 3")
632 end select
633
634 ! Soil moisture below which actual ET is reduced linearly till PWP
635 ! for processCase(3) = 1
636 var = nc%getVariable("L1_soilMoistFC")
637 call var%getData(dummyd4)
638 do jj = 1, nlcoverscene
639 do ii = 1, nsoilhorizons_mhm
640 l1_soilmoistfc(s1 : e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
641 end do
642 end do
643
644 ! Saturation soil moisture for each horizon [mm]
645 var = nc%getVariable("L1_soilMoistSat")
646 call var%getData(dummyd4)
647 do jj = 1, nlcoverscene
648 do ii = 1, nsoilhorizons_mhm
649 l1_soilmoistsat(s1 : e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
650 end do
651 end do
652
653 ! Exponential parameter to how non-linear is the soil water retention
654 var = nc%getVariable("L1_soilMoistExp")
655 call var%getData(dummyd4)
656 do jj = 1, nlcoverscene
657 do ii = 1, nsoilhorizons_mhm
658 l1_soilmoistexp(s1 : e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
659 end do
660 end do
661
662 if (any(processmatrix(3, 1) == (/2, 3/))) then
663 ! jarvis critical value for normalized soil water content
664 var = nc%getVariable("L1_jarvis_thresh_c1")
665 call var%getData(dummyd2)
666 l1_jarvis_thresh_c1(s1 : e1, 1, 1) = pack(dummyd2, mask1)
667 end if
668
669 ! Threshold temperature for snow/rain
670 var = nc%getVariable("L1_tempThresh")
671 call var%getData(dummyd3)
672 do ii = 1, nlcoverscene
673 l1_tempthresh(s1 : e1, 1, ii) = pack(dummyd3(:, :, ii), mask1)
674 end do
675
676 ! Threshold water depth controlling fast interflow
677 var = nc%getVariable("L1_unsatThresh")
678 call var%getData(dummyd2)
679 l1_unsatthresh(s1 : e1, 1, 1) = pack(dummyd2, mask1)
680
681 ! Threshold water depth for surface runoff in sealed surfaces
682 var = nc%getVariable("L1_sealedThresh")
683 call var%getData(dummyd2)
684 l1_sealedthresh(s1 : e1, 1, 1) = pack(dummyd2, mask1)
685
686 ! Permanent wilting point
687 var = nc%getVariable("L1_wiltingPoint")
688 call var%getData(dummyd4)
689 do jj = 1, nlcoverscene
690 do ii = 1, nsoilhorizons_mhm
691 l1_wiltingpoint(s1 : e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
692 end do
693 end do
694
695 ! different parameters dependent on PET formulation
696 select case (processmatrix(5, 1))
697 case(-1) ! PET is input
698
699 ! PET correction factor due to LAI
700 var = nc%getVariable("L1_petLAIcorFactor")
701 call var%getData(dummyd4)
702 do jj = 1, nlcoverscene
703 do ii = 1, nlai
704 l1_petlaicorfactor(s1 : e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
705 end do
706 end do
707
708 case(0) ! PET is input
709
710 ! PET correction factor due to terrain aspect
711 var = nc%getVariable("L1_fAsp")
712 call var%getData(dummyd2)
713 l1_fasp(s1 : e1, 1, 1) = pack(dummyd2, mask1)
714
715 case(1) ! Hargreaves-Samani
716
717 ! PET correction factor due to terrain aspect
718 var = nc%getVariable("L1_fAsp")
719 call var%getData(dummyd2)
720 l1_fasp(s1 : e1, 1, 1) = pack(dummyd2, mask1)
721
722 ! Hargreaves Samani coeffiecient
723 var = nc%getVariable("L1_HarSamCoeff")
724 call var%getData(dummyd2)
725 l1_harsamcoeff(s1 : e1, 1, 1) = pack(dummyd2, mask1)
726
727 case(2) ! Priestely-Taylor
728
729 ! Priestley Taylor coeffiecient (alpha)
730 var = nc%getVariable("L1_PrieTayAlpha")
731 call var%getData(dummyd3)
732 do ii = 1, nlai
733 l1_prietayalpha(s1 : e1, ii, 1) = pack(dummyd3(:, :, ii), mask1)
734 end do
735
736 case(3) ! Penman-Monteith
737
738 ! aerodynamical resitance
739 var = nc%getVariable("L1_aeroResist")
740 call var%getData(dummyd4)
741 do jj = 1, nlcoverscene
742 do ii = 1, nlai
743 l1_aeroresist(s1 : e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
744 end do
745 end do
746
747 ! bulk surface resitance
748 var = nc%getVariable("L1_surfResist")
749 call var%getData(dummyd3)
750 do ii = 1, nlai
751 l1_surfresist(s1 : e1, ii, 1) = pack(dummyd3(:, :, ii), mask1)
752 end do
753
754 end select
755
756
757 ! neutron count
758 select case (processmatrix(10, 1))
759 case(1) ! deslet
760 ! N0 count
761 var = nc%getVariable("L1_No_Count")
762 call var%getData(dummyd2)
763 l1_no_count(s1:e1, 1, 1) = pack(dummyd2, mask1)
764
765 ! Bulk density
766 var = nc%getVariable("L1_bulkDens")
767 call var%getData(dummyd4)
768 do jj = 1, nlcoverscene
769 do ii = 1, nsoilhorizons_mhm
770 l1_bulkdens(s1:e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
771 end do
772 end do
773
774 ! Lattice water
775 var = nc%getVariable("L1_latticeWater")
776 call var%getData(dummyd4)
777 do jj = 1, nlcoverscene
778 do ii = 1, nsoilhorizons_mhm
779 l1_latticewater(s1:e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
780 end do
781 end do
782
783 case(2) ! COSMIC
784 ! N0 count
785 var = nc%getVariable("L1_No_Count")
786 call var%getData(dummyd2)
787 l1_no_count(s1 : e1, 1, 1) = pack(dummyd2, mask1)
788
789 ! Bulk density
790 var = nc%getVariable("L1_bulkDens")
791 call var%getData(dummyd4)
792 do jj = 1, nlcoverscene
793 do ii = 1, nsoilhorizons_mhm
794 l1_bulkdens(s1:e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
795 end do
796 end do
797
798 ! Lattice water
799 var = nc%getVariable("L1_latticeWater")
800 call var%getData(dummyd4)
801 do jj = 1, nlcoverscene
802 do ii = 1, nsoilhorizons_mhm
803 l1_latticewater(s1: e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
804 end do
805 end do
806
807 ! COSMIC L3 parameter
808 var = nc%getVariable("L1_COSMICL3")
809 call var%getData(dummyd4)
810 do jj = 1, nlcoverscene
811 do ii = 1, nsoilhorizons_mhm
812 l1_cosmicl3(s1:e1, ii, jj) = pack(dummyd4(:, :, ii, jj), mask1)
813 end do
814 end do
815
816 end select
817
818 ! close file
819 call nc%close()
820
821 end subroutine read_restart_states
822
823END MODULE mo_restart
Provides constants commonly used by mHM, mRM and MPR.
character(64), parameter, public soilhorizonsvarname
character(64), parameter, public landcoverperiodsvarname
character(64), parameter, public laivarname
real(dp), parameter, public nodata_dp
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
Main global variables for mHM.
real(dp), dimension(:), allocatable, public l1_slowrunoff
[mm TS-1] Slow runoff component
real(dp), dimension(:, :), allocatable, public l1_aetsoil
[mm TS-1] Actual ET from soil layers
real(dp), dimension(:), allocatable, public l1_rain
[mm TS-1] Rain precipitation depth
real(dp), dimension(:), allocatable, public l1_aetsealed
[mm TS-1] Real evap.
real(dp), dimension(:), allocatable, public l1_satstw
[mm] groundwater storage
real(dp), dimension(:), allocatable, public l1_aetcanopy
[mm TS-1] Real evaporation intensity from canopy
real(dp), dimension(:), allocatable, public l1_snow
[mm TS-1] Snow precipitation depth
real(dp), dimension(:), allocatable, public l1_preeffect
[mm TS-1] Effective precip.
real(dp), dimension(:), allocatable, public l1_inter
[mm] Interception
real(dp), dimension(:), allocatable, public l1_sealstw
[mm] Retention storage of impervious areas
real(dp), dimension(:), allocatable, public l1_percol
[mm TS-1] Percolation.
real(dp), dimension(:, :), allocatable, public l1_soilmoist
[mm] Soil moisture of each horizon
real(dp), dimension(:), allocatable, public l1_unsatstw
[mm] upper soil storage
real(dp), dimension(:), allocatable, public l1_melt
[mm TS-1] Melting snow depth.
real(dp), dimension(:), allocatable, public l1_fastrunoff
[mm TS-1] Fast runoff component
real(dp), dimension(:), allocatable, public l1_snowpack
[mm] Snowpack
real(dp), dimension(:), allocatable, public l1_runoffseal
[mm TS-1] Direct runoff from impervious areas
real(dp), dimension(:, :), allocatable, public l1_infilsoil
[mm TS-1] Infiltration intensity each soil horizon
real(dp), dimension(:), allocatable, public l1_baseflow
[mm TS-1] Baseflow
real(dp), dimension(:), allocatable, public l1_throughfall
[mm TS-1] Throughfall.
real(dp), dimension(:), allocatable, public l1_total_runoff
[m3 TS-1] Generated runoff
Global variables for mpr only.
real(dp), dimension(:, :, :), allocatable, public l1_degday
real(dp), dimension(:, :, :), allocatable, public l1_degdaymax
real(dp), dimension(:, :, :), allocatable, public l1_soilmoistexp
real(dp), dimension(:, :, :), allocatable, public l1_harsamcoeff
real(dp), dimension(:, :, :), allocatable, public l1_karstloss
real(dp), dimension(:, :, :), allocatable, public l1_unsatthresh
real(dp), dimension(:, :, :), allocatable, public l1_kperco
real(dp), dimension(:, :, :), allocatable, public l1_alpha
real(dp), dimension(:, :, :), allocatable, public l1_surfresist
real(dp), dimension(:,:,:), allocatable, public l1_cosmicl3
real(dp), dimension(:, :, :), allocatable, public l1_degdayinc
real(dp), dimension(:, :, :), allocatable, public l1_petlaicorfactor
real(dp), dimension(:, :, :), allocatable, public l1_fasp
real(dp), dimension(:, :, :), allocatable, public l1_kbaseflow
real(dp), dimension(:, :, :), allocatable, public l1_soilmoistfc
integer(i4), public nsoilhorizons_mhm
real(dp), dimension(:, :, :), allocatable, public l1_maxinter
real(dp), dimension(:,:,:), allocatable, public l1_bulkdens
real(dp), dimension(:, :, :), allocatable, public l1_degdaynopre
real(dp), dimension(:, :, :), allocatable, public l1_wiltingpoint
real(dp), dimension(:, :, :), allocatable, public l1_prietayalpha
real(dp), dimension(:, :, :), allocatable, public l1_fsealed
real(dp), dimension(:), allocatable, public laiboundaries
real(dp), dimension(:, :, :), allocatable, public l1_froots
real(dp), dimension(:, :, :), allocatable, public l1_jarvis_thresh_c1
real(dp), dimension(:, :, :), allocatable, public l1_tempthresh
real(dp), dimension(:), allocatable, public horizondepth_mhm
real(dp), dimension(:,:,:), allocatable, public l1_no_count
real(dp), dimension(:, :, :), allocatable, public l1_kfastflow
real(dp), dimension(:, :, :), allocatable, public l1_kslowflow
real(dp), dimension(:, :, :), allocatable, public l1_aeroresist
real(dp), dimension(:, :, :), allocatable, public l1_sealedthresh
real(dp), dimension(:, :, :), allocatable, public l1_soilmoistsat
real(dp), dimension(:,:,:), allocatable, public l1_latticewater
reading and writing states, fluxes and configuration for restart of mHM.
subroutine, public write_eff_params(mask1, s1, e1, rows1, cols1, soil1, lcscenes, lais, nc)
write effective parameter fields to given restart file
reading and writing states, fluxes and configuration for restart of mHM.
subroutine, public read_restart_states(idomain, domainid, infile)
reads fluxes and state variables from file
subroutine, public write_restart_files(outfile)
write restart files for each domain