14 use mo_kind,
only : i4, dp
17 use mo_message,
only : message, error_message
62 integer(i4) :: domainid, idomain
64 integer(i4) :: iday, isubday, is, ie
66 integer(i4) :: maxdailytimesteps, maxmeastimesteps
72 integer(i4) :: ntimesteps
74 real(dp),
dimension(:, :),
allocatable :: d_qmod, subd_qmod
75 real(dp),
dimension(:, :),
allocatable :: d_qobs, subd_qobs
81 integer(i4) :: tpd_sim
84 integer(i4) :: tpd_obs
116 if (modulo(tpd_sim, tpd_obs) .eq. 0)
then
117 factor = tpd_sim / tpd_obs
119 call error_message(
' Error: Number of modelled datapoints is no multiple of measured datapoints per day')
150 d_qmod(iday,
domain_mrm(idomain)%gaugeIndexList(gg)) = &
168 d_qobs(iday,
domain_mrm(idomain)%gaugeIndexList(gg)) = &
191 isubday = isubday + 1
195 subd_qmod(isubday,
domain_mrm(idomain)%gaugeIndexList(gg)) = &
224 deallocate(d_qmod, d_qobs, subd_qmod, subd_qobs)
261 use mo_kind,
only : dp, i4
266 use mo_string_utils,
only : num2str
267 use mo_utils,
only : ge
268 use mo_os,
only : check_path_isdir
272 character(256) :: fName
274 integer(i4) :: i, iDomain, domainID, j
281 call message(
' Log-file written to ', trim(fname))
283 call check_path_isdir(trim(adjustl(
dirconfigout)), raise=.true.)
284 open(
uconfig, file = fname, status =
'unknown', action =
'write', iostat = err)
286 call error_message(
' Problems while creating File. Error-Code ', num2str(err))
290 write(
uconfig, 100)
'S. Thober, L. Samaniego & R. Kumar, UFZ'
293 write(
uconfig, 201)
' M A I N mRM C O N F I G U R A T I O N I N F O R M A T I O N '
300 write(
uconfig, 103)
'Total No. of nodes ',
level11(idomain)%nCells
302 write(
uconfig, 103)
'No. of cells L1 ',
level1(idomain)%nCells
322 write(
uconfig, 115)
' Model Run Periods for domain ', num2str(domainid)
325 ' Day Month Year Day Month Year'
327 'Warming Period (1) ', &
331 'Evaluation Period (2) ', &
335 'Simulation Period (1)+(2) ', &
346 write(
uconfig, 118)
' Land Cover Observations for domain ', num2str(domainid)
347 write(
uconfig, 119)
' Start Year',
' End Year',
' Land cover scene',
'Land Cover File'
357 write(
uconfig, 121)
' Initial Transfer Function Parameter Ranges (gammas) '
361 ' i',
' min',
' max',
' current', &
369 write(
uconfig, 202)
' domain Runoff Data '
370 write(
uconfig, 107)
' Gauge No.',
' domain Id',
' Qmax[m3/s]',
' Qmin[m3/s]'
381 write(
uconfig, 202)
' domain Inflow Data '
382 write(
uconfig, 107)
' Gauge No.',
' domain Id',
' Qmax[m3/s]',
' Qmin[m3/s]'
393 write(
uconfig, 218)
'domain-wise Configuration'
396 write(
uconfig, 103)
'domain No. ', domainid, &
399 write(
uconfig, 222)
'Directory list'
403 write(
uconfig, 224)
'Directory to gauging station input ',
dirgauges(idomain)
407 write(
uconfig, 224)
'Directory to write output by default ',
dirout(idomain)
410 write(
uconfig, 102)
'River Network (Routing level)'
411 write(
uconfig, 100)
'Label 0 = intermediate draining cell '
412 write(
uconfig, 100)
'Label 1 = headwater cell '
413 write(
uconfig, 100)
'Label 2 = sink cell '
416 write(
uconfig, 104)
' Overall', &
446 write(
uconfig, 134)
' Overall', &
469 write(
uconfig, 109)
' Overall',
' domain', &
470 ' Cell',
' Routing', &
477 write(
uconfig, 111)
' Modeling',
' Routing',
' Effective', &
478 ' Cell',
' Cell Id',
' Area', &
479 ' Id',
' [-]',
' [km2]'
483 level1(idomain)%CellArea(i) * 1.e-6_dp
491 write(
uconfig, 114)
' Total[km2]', sum(
level1(idomain)%CellArea) * 1.e-6_dp
499 102
format (/ 30(
'-') / a30 / 30(
'-'))
500 103
format (a20, 10x, i10)
501 104
format (/ 75(
'-') / 5a10, 5x, 2a10 / 5a10, 5x, 2a10)
502 105
format (5a10, 5x, 2a10 / 75(
'-'))
503 106
format (5i10, 5x, 2f10.3)
504 107
format (2a10, 2a15)
505 108
format (2i10, 2f15.3)
507 109
format (/ 20(
'-') / 2a10 / 2a10 / 2a10 / 20(
'-'))
510 111
format (/ 30(
'-') / 3a10 / 3a10 / 3a10 / 30(
'-'))
511 113
format ( 2i10, 1f10.3 )
512 114
format (30(
'-') / a15, 5x, 1f10.3 /)
514 115
format (/61(
'-')/ a50, a10 /61(
'-'))
515 116
format (39x, a22 / 25x, a36)
516 117
format (3(a25, 6(i6)))
518 118
format (/50(
'-')/ a40, a10 /50(
'-'))
519 119
format (a10, a10, a20, a20/)
520 120
format (i10, i10, 10x, i10, a20)
522 121
format (/55(
'-')/ a55 /55(
'-'))
523 122
format (a10, 3a15, a35)
524 123
format (i10, 3f15.3, a35)
526 126
format (a30, 9x, l1)
528 134
format (/ 50(
'-') / 5a10 / 5a10)
529 135
format (5a10 / 50(
'-'))
534 202
format (/50(
'-')/ a50 /50(
'-'))
536 218
format (/ 80(
'-')/ 26x, a24, 26x, /80(
'-'))
537 222
format (/80(
'-')/ 26x, a21 /80(
'-'))
538 224
format (a40, 5x, a256)
540 301
format (a7, i2, a32, f15.0)
575 use mo_errormeasures,
only : kge, nse
576 use mo_julian,
only : dec2date
579 use mo_string_utils,
only : num2str
580 use mo_utils,
only : ge
581 use mo_netcdf,
only : ncdataset, ncdimension, ncvariable
586 real(dp),
dimension(:, :),
intent(in) :: Qobs
589 real(dp),
dimension(:, :),
intent(in) :: Qsim
591 character(256) :: fName, formHeader, formData, dummy
593 integer(i4) :: domainID, iDomain, gg, tt, err
595 integer(i4) :: igauge_start, igauge_end
597 integer(i4) :: day, month, year
599 integer(i4) :: tlength
602 integer(i4),
allocatable,
dimension(:) :: taxis
607 type(ncdataset) :: nc_out
608 type(ncdimension) :: dim, dim_bnd
609 type(ncvariable) :: var
620 igauge_end = igauge_start +
domain_mrm(idomain)%nGauges - 1
624 open(
udaily_discharge, file = trim(fname), status =
'unknown', action =
'write', iostat = err)
626 call error_message(
' IOError while openening "', trim(fname),
'". Error-Code ', num2str(err))
630 write(formheader, *)
'( 4a8, ',
domain_mrm(idomain)%nGauges,
'(2X, a5, i10.10, 2X, a5, i10.10) )'
632 (
'Qobs_',
gauge%gaugeId(gg), &
633 'Qsim_',
gauge%gaugeId(gg), gg = igauge_start, igauge_end)
636 write(formdata, *)
'( 4I8, ',
domain_mrm(idomain)%nGauges,
'(2X, f15.7 , 2X, f15.7 ) )'
639 newtime = real(
evalper(idomain)%julStart, dp) - 0.5_dp
641 do tt = 1, (
evalper(idomain)%julEnd -
evalper(idomain)%julStart + 1)
642 call dec2date(newtime, yy = year, mm = month, dd = day)
643 write(
udaily_discharge, formdata) tt, day, month, year, (qobs(tt, gg), qsim(tt, gg), gg = igauge_start, igauge_end)
644 newtime = newtime + 1.0_dp
654 nc_out = ncdataset(trim(fname),
"w")
657 allocate(taxis(tlength))
662 forall(tt = 1 : tlength) taxis(tt) = (tt-1) * 24
664 forall(tt = 1 : tlength) taxis(tt) = tt * 24 - 12
666 forall(tt = 1 : tlength) taxis(tt) = tt * 24
669 call dec2date(real(
evalper(idomain)%julStart, dp) - 0.5_dp, yy = year, mm = month, dd = day)
670 dim = nc_out%setDimension(
"time", tlength)
671 var = nc_out%setVariable(
"time",
"i32", [dim])
672 call var%setData(taxis)
673 call var%setAttribute( &
675 'hours since '//trim(num2str(year))//
'-'//trim(num2str(month,
'(i2.2)'))//
'-'//trim(num2str(day,
'(i2.2)'))//
' 00:00:00' &
677 call var%setAttribute(
"long_name",
"time in hours")
678 call var%setAttribute(
"bounds",
"time_bnds")
679 call var%setAttribute(
"axis",
"T")
680 dim_bnd = nc_out%setDimension(
"bnds", 2)
681 var = nc_out%setVariable(
"time_bnds",
"i32", [dim_bnd, dim])
683 call var%setData((tt - 1) * 24, (/1, tt/))
684 call var%setData(tt * 24, (/2, tt/))
688 do gg = igauge_start, igauge_end
689 var = nc_out%setVariable(
'Qsim_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
691 call var%setData(qsim(1 : tlength, gg))
692 call var%setAttribute(
"units",
"m3 s-1")
693 call var%setAttribute(
"long_name",
'simulated discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
694 call var%setAttribute(
"missing_value",
nodata_dp)
696 var = nc_out%setVariable(
'Qobs_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
698 call var%setData(qobs(1 : tlength, gg))
699 call var%setAttribute(
"units",
"m3 s-1")
700 call var%setAttribute(
"long_name",
'observed discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
701 call var%setAttribute(
"missing_value",
nodata_dp)
712 write(dummy,
'(I3)') domainid
713 call message(
' OUTPUT: saved daily discharge file for domain ', trim(adjustl(dummy)))
714 call message(
' to ', trim(fname))
715 do gg = igauge_start, igauge_end
716 if (count(ge(qobs(:, gg), 0.0_dp)) > 1)
then
717 call message(
' KGE of daily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
718 trim(adjustl(num2str(kge(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
719 call message(
' NSE of daily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
720 trim(adjustl(num2str(nse(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
727 igauge_start = igauge_end + 1
768 use mo_errormeasures,
only : kge, nse
769 use mo_julian,
only : dec2date
773 use mo_string_utils,
only : num2str
774 use mo_utils,
only : ge
775 use mo_netcdf,
only : ncdataset, ncdimension, ncvariable
780 real(dp),
dimension(:, :),
intent(in) :: Qobs
783 real(dp),
dimension(:, :),
intent(in) :: Qsim
786 integer(i4),
intent(in) :: factor
788 character(256) :: fName, formHeader, formData, dummy
790 integer(i4) :: domainID, iDomain, gg, tt, err
792 integer(i4) :: igauge_start, igauge_end
794 integer(i4) :: hour, day, month, year
796 integer(i4) :: tlength
799 integer(i4),
allocatable,
dimension(:) :: taxis
804 type(ncdataset) :: nc_out
805 type(ncdimension) :: dim, dim_bnd
806 type(ncvariable) :: var
809 logical :: use_minutes
810 integer(i4) :: time_unit_factor
821 igauge_end = igauge_start +
domain_mrm(idomain)%nGauges - 1
830 open(
usubdaily_discharge, file = trim(fname), status =
'unknown', action =
'write', iostat = err)
832 call error_message(
' IOError while openening "', trim(fname),
'". Error-Code ', num2str(err))
836 write(formheader, *)
'( 5a8, ',
domain_mrm(idomain)%nGauges,
'(2X, a5, i10.10, 2X, a5, i10.10) )'
838 (
'Qobs_',
gauge%gaugeId(gg), &
839 'Qsim_',
gauge%gaugeId(gg), gg = igauge_start, igauge_end)
842 write(formdata, *)
'( 5I8, ',
domain_mrm(idomain)%nGauges,
'(2X, f15.7 , 2X, f15.7 ) )'
845 newtime = real(
evalper(idomain)%julStart, dp) - 0.5_dp
848 call dec2date(newtime, yy = year, mm = month, dd = day, hh = hour)
849 write(
usubdaily_discharge, formdata) tt, hour, day, month, year, (qobs(tt, gg), qsim(tt, gg), gg = igauge_start, igauge_end)
860 nc_out = ncdataset(trim(fname),
"w")
863 allocate(taxis(tlength))
865 use_minutes = .false.
867 if ( mod(factor, 2) == 1 )
then
869 time_unit_factor = 60
875 forall(tt = 1 : tlength) taxis(tt) = (tt-1) * factor * time_unit_factor
877 forall(tt = 1 : tlength) taxis(tt) = tt * factor - factor * time_unit_factor / 2
879 forall(tt = 1 : tlength) taxis(tt) = tt * factor * time_unit_factor
882 call dec2date(real(
evalper(idomain)%julStart, dp) - 0.5_dp, yy = year, mm = month, dd = day, hh = hour)
883 dim = nc_out%setDimension(
"time", tlength)
884 var = nc_out%setVariable(
"time",
"i32", [dim])
885 call var%setData(taxis)
886 if (use_minutes)
then
887 call var%setAttribute( &
889 'minutes since '//trim(num2str(year))//
'-'//trim(num2str(month,
'(i2.2)'))//
'-'//trim(num2str(day,
'(i2.2)'))//
' '// &
890 trim(num2str(hour,
'(i2.2)'))//
':00:00' &
892 call var%setAttribute(
"long_name",
"time in minutes")
894 call var%setAttribute( &
896 'hours since '//trim(num2str(year))//
'-'//trim(num2str(month,
'(i2.2)'))//
'-'//trim(num2str(day,
'(i2.2)'))//
' '// &
897 trim(num2str(hour,
'(i2.2)'))//
':00:00' &
899 call var%setAttribute(
"long_name",
"time in hours")
901 call var%setAttribute(
"bounds",
"time_bnds")
902 call var%setAttribute(
"axis",
"T")
903 dim_bnd = nc_out%setDimension(
"bnds", 2)
904 var = nc_out%setVariable(
"time_bnds",
"i32", [dim_bnd, dim])
906 call var%setData((tt - 1) * factor * time_unit_factor, (/1, tt/))
907 call var%setData(tt * factor * time_unit_factor, (/2, tt/))
911 do gg = igauge_start, igauge_end
912 var = nc_out%setVariable(
'Qsim_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
914 call var%setData(qsim(1 : tlength, gg))
915 call var%setAttribute(
"units",
"m3 s-1")
916 call var%setAttribute(
"long_name",
'simulated discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
917 call var%setAttribute(
"missing_value",
nodata_dp)
919 var = nc_out%setVariable(
'Qobs_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
921 call var%setData(qobs(1 : tlength, gg))
922 call var%setAttribute(
"units",
"m3 s-1")
923 call var%setAttribute(
"long_name",
'observed discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
924 call var%setAttribute(
"missing_value",
nodata_dp)
932 write(dummy,
'(I3)') domainid
933 call message(
' OUTPUT: saved subdaily discharge file for domain ', trim(adjustl(dummy)))
934 call message(
' to ', trim(fname))
935 do gg = igauge_start, igauge_end
936 if (count(ge(qobs(:, gg), 0.0_dp)) > 1)
then
937 call message(
' KGE of subdaily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
938 trim(adjustl(num2str(kge(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
939 call message(
' NSE of subdaily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
940 trim(adjustl(num2str(nse(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
945 igauge_start = igauge_end + 1
984 use mo_string_utils,
only : num2str
989 real(dp),
intent(in) :: best_of
992 real(dp),
dimension(:),
intent(in) :: best_paramset
994 character(len = *),
dimension(:),
intent(in) :: param_names
996 character(256) :: fname, formheader, formparams
998 integer(i4) :: ii, err, n_params
1002 n_params =
size(best_paramset)
1006 open(
uopti, file = fname, status =
'unknown', action =
'write', iostat = err, recl = (n_params + 1) * 40)
1008 call error_message(
' IOError while openening "', trim(fname),
'" Error-Code ', num2str(err))
1012 write(formheader, *)
'(a40,', n_params,
'a40)'
1015 write(
uopti, formheader)
'OF', (trim(adjustl(param_names(ii)(1 : 39))), ii = 1, n_params)
1018 write(formparams, *)
'( es40.14, ', n_params,
'(es40.14) )'
1019 write(
uopti, formparams) best_of, (best_paramset(ii), ii = 1, n_params)
1026 call message(
' Optimized parameters written to ', trim(fname))
1060 use mo_string_utils,
only : num2str
1065 real(dp),
dimension(:, :),
intent(in) :: parameters
1068 logical,
dimension(size(parameters, 1)),
intent(in) :: maskpara
1071 character(len = *),
dimension(size(parameters, 1)),
intent(in) :: parameters_name
1073 character(256) :: fname
1075 character(3) :: flag
1084 open(
uopti_nml, file = fname, status =
'unknown', action =
'write', iostat = err)
1086 call message (
' IOError while openening "', trim(fname),
'" Error-Code ', num2str(err))
1089 write(
uopti_nml, *)
'!global_parameters'
1090 write(
uopti_nml, *)
'!PARAMETER lower_bound upper_bound value FLAG SCALING'
1092 write(
uopti_nml, *)
'! ', trim(adjustl(
'routing'))
1098 do ipar = 1,
size(parameters, 1)
1099 if (maskpara(ipar))
then
1104 write(
uopti_nml, *) trim(adjustl(parameters_name(ipar))),
' = ', &
1105 parameters(ipar, 1),
' , ', &
1106 parameters(ipar, 2),
' , ', &
1107 parameters(ipar, 3),
' , ', &
1119 call message(
' Optimized parameters written in namelist format to ', trim(fname))
Provides constants commonly used by mHM, mRM and MPR.
real(dp), parameter, public nodata_dp
Provides file names and units for mRM.
integer, parameter uconfig
Unit for file defining mHM's outputs.
character(len= *), parameter file_config
file defining mHM's outputs
Provides file names and units for mHM.
integer, parameter uopti
Unit for file optimization outputs (objective and parameter set)
character(len=*), parameter file_opti
file defining optimization outputs (objective and parameter set)
character(len=*), parameter file_opti_nml
file defining optimization outputs in a namelist format (parameter set)
integer, parameter uopti_nml
Unit for file optimization outputs in a namelist format (parameter set)
Provides structures needed by mHM, mRM and/or mpr.
type(period), dimension(:), allocatable, public warmper
real(dp), dimension(:), allocatable, public resolutionrouting
integer(i4) mrm_coupling_mode
integer(i4), public ntstepday
integer(i4), dimension(:), allocatable, public warmingdays
integer(i4), dimension(:, :), allocatable, public lcyearid
type(period), dimension(:), allocatable, public simper
integer(i4), public timestep
logical, public read_restart
type(period), dimension(:), allocatable, public evalper
Provides structures needed by mHM, mRM and/or mpr.
real(dp), dimension(:), allocatable, public resolutionhydrology
logical, public write_restart
real(dp), dimension(:, :), allocatable, target, public global_parameters
character(256), dimension(:), allocatable, public lcfilename
character(256), dimension(:), allocatable, public global_parameters_name
type(domain_meta), public domainmeta
character(256), public dirconfigout
integer(i4), public nlcoverscene
character(256), dimension(:), allocatable, public dirlcover
integer(i4), dimension(:), allocatable, public lc_year_end
character(256), dimension(:), allocatable, public dirout
character(256), dimension(:), allocatable, public dirmorpho
integer(i4), dimension(nprocesses, 3), public processmatrix
character(256), dimension(:), allocatable, public mrmfilerestartout
type(grid), dimension(:), allocatable, target, public level1
type(grid), dimension(:), allocatable, target, public level0
integer(i4), dimension(:), allocatable, public lc_year_start
Provides file names and units for mRM.
integer, parameter udaily_discharge
Unit for file optimazation outputs.
integer, parameter usubdaily_discharge
Unit for file optimazation outputs.
character(len=*), parameter version
Current mHM model version.
character(len=*), parameter ncfile_subdaily_discharge
file containing simulated discharge at observat time step
character(len=*), parameter file_daily_discharge
file defining optimazation outputs
character(len=*), parameter file_subdaily_discharge
file defining optimazation outputs
character(len=*), parameter ncfile_discharge
file defining optimazation outputs
Global variables for mRM only.
type(gaugingstation), public inflowgauge
integer(i4), dimension(:), allocatable, public l11_netperm
integer(i4), dimension(:), allocatable, public l11_l1_id
integer(i4), dimension(:), allocatable, public l1_l11_id
integer(i4), dimension(:), allocatable, public l11_label
real(dp), dimension(:, :), allocatable, public mrm_runoff
character(256), dimension(:), allocatable, public dirgauges
integer(i4) output_time_reference_mrm
time reference point location in output nc files
type(gaugingstation), public gauge
integer(i4), dimension(:), allocatable, public l11_fromn
real(dp), dimension(:), allocatable, public l11_length
integer(i4), dimension(:), allocatable, public l11_ton
type(domaininfo_mrm), dimension(:), allocatable, target, public domain_mrm
type(grid), dimension(:), allocatable, target, public level11
real(dp), dimension(:), allocatable, public l11_slope
character(256), dimension(:), allocatable, public dirtotalrunoff
integer(i4), public ninflowgaugestotal
integer(i4), dimension(:), allocatable, public l11_rorder
integer(i4), public nmeasperday
integer(i4), public ngaugestotal
subroutine, public mrm_write_restart(idomain, domainid, outfile)
write routing states and configuration
Creates NetCDF output for different fluxes and state variables of mHM.
write of discharge and restart files
subroutine write_daily_obs_sim_discharge(qobs, qsim)
Write a file for the daily observed and simulated discharge timeseries during the evaluation period f...
subroutine, public mrm_write_optifile(best_of, best_paramset, param_names)
Write briefly final optimization results.
subroutine, public mrm_write_optinamelist(parameters, maskpara, parameters_name)
Write final, optimized parameter set in a namelist format.
subroutine write_subdaily_obs_sim_discharge(qobs, qsim, factor)
Write a file for the simulated discharge timeseries during the evaluation period for each gauging sta...
subroutine, public mrm_write
write discharge and restart files
subroutine write_configfile
This modules writes the results of the configuration into an ASCII-file.