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
115 if (modulo(tpd_sim, tpd_obs) .eq. 0)
then
116 factor = tpd_sim / tpd_obs
118 call error_message(
' Error: Number of modelled datapoints is no multiple of measured datapoints per day')
149 d_qmod(iday,
domain_mrm(idomain)%gaugeIndexList(gg)) = &
167 d_qobs(iday,
domain_mrm(idomain)%gaugeIndexList(gg)) = &
190 isubday = isubday + 1
194 subd_qmod(isubday,
domain_mrm(idomain)%gaugeIndexList(gg)) = &
223 deallocate(d_qmod, d_qobs, subd_qmod, subd_qobs)
259 use mo_kind,
only : dp, i4
264 use mo_string_utils,
only : num2str
265 use mo_utils,
only : ge
266 use mo_os,
only : check_path_isdir
270 character(256) :: fName
272 integer(i4) :: i, iDomain, domainID, j
279 call message(
' Log-file written to ', trim(fname))
281 call check_path_isdir(trim(adjustl(
dirconfigout)), raise=.true.)
282 open(
uconfig, file = fname, status =
'unknown', action =
'write', iostat = err)
284 call error_message(
' Problems while creating File. Error-Code ', num2str(err))
288 write(
uconfig, 100)
'S. Thober, L. Samaniego & R. Kumar, UFZ'
291 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 '
298 write(
uconfig, 103)
'Total No. of nodes ',
level11(idomain)%nCells
300 write(
uconfig, 103)
'No. of cells L1 ',
level1(idomain)%nCells
320 write(
uconfig, 115)
' Model Run Periods for domain ', num2str(domainid)
323 ' Day Month Year Day Month Year'
325 'Warming Period (1) ', &
329 'Evaluation Period (2) ', &
333 'Simulation Period (1)+(2) ', &
344 write(
uconfig, 118)
' Land Cover Observations for domain ', num2str(domainid)
345 write(
uconfig, 119)
' Start Year',
' End Year',
' Land cover scene',
'Land Cover File'
355 write(
uconfig, 121)
' Initial Transfer Function Parameter Ranges (gammas) '
359 ' i',
' min',
' max',
' current', &
367 write(
uconfig, 202)
' domain Runoff Data '
368 write(
uconfig, 107)
' Gauge No.',
' domain Id',
' Qmax[m3/s]',
' Qmin[m3/s]'
379 write(
uconfig, 202)
' domain Inflow Data '
380 write(
uconfig, 107)
' Gauge No.',
' domain Id',
' Qmax[m3/s]',
' Qmin[m3/s]'
391 write(
uconfig, 218)
'domain-wise Configuration'
394 write(
uconfig, 103)
'domain No. ', domainid, &
397 write(
uconfig, 222)
'Directory list'
401 write(
uconfig, 224)
'Directory to gauging station input ',
dirgauges(idomain)
405 write(
uconfig, 224)
'Directory to write output by default ',
dirout(idomain)
408 write(
uconfig, 102)
'River Network (Routing level)'
409 write(
uconfig, 100)
'Label 0 = intermediate draining cell '
410 write(
uconfig, 100)
'Label 1 = headwater cell '
411 write(
uconfig, 100)
'Label 2 = sink cell '
414 write(
uconfig, 104)
' Overall', &
444 write(
uconfig, 134)
' Overall', &
467 write(
uconfig, 109)
' Overall',
' domain', &
468 ' Cell',
' Routing', &
475 write(
uconfig, 111)
' Modeling',
' Routing',
' Effective', &
476 ' Cell',
' Cell Id',
' Area', &
477 ' Id',
' [-]',
' [km2]'
481 level1(idomain)%CellArea(i) * 1.e-6_dp
489 write(
uconfig, 114)
' Total[km2]', sum(
level1(idomain)%CellArea) * 1.e-6_dp
497 102
format (/ 30(
'-') / a30 / 30(
'-'))
498 103
format (a20, 10x, i10)
499 104
format (/ 75(
'-') / 5a10, 5x, 2a10 / 5a10, 5x, 2a10)
500 105
format (5a10, 5x, 2a10 / 75(
'-'))
501 106
format (5i10, 5x, 2f10.3)
502 107
format (2a10, 2a15)
503 108
format (2i10, 2f15.3)
505 109
format (/ 20(
'-') / 2a10 / 2a10 / 2a10 / 20(
'-'))
508 111
format (/ 30(
'-') / 3a10 / 3a10 / 3a10 / 30(
'-'))
509 113
format ( 2i10, 1f10.3 )
510 114
format (30(
'-') / a15, 5x, 1f10.3 /)
512 115
format (/61(
'-')/ a50, a10 /61(
'-'))
513 116
format (39x, a22 / 25x, a36)
514 117
format (3(a25, 6(i6)))
516 118
format (/50(
'-')/ a40, a10 /50(
'-'))
517 119
format (a10, a10, a20, a20/)
518 120
format (i10, i10, 10x, i10, a20)
520 121
format (/55(
'-')/ a55 /55(
'-'))
521 122
format (a10, 3a15, a35)
522 123
format (i10, 3f15.3, a35)
524 126
format (a30, 9x, l1)
526 134
format (/ 50(
'-') / 5a10 / 5a10)
527 135
format (5a10 / 50(
'-'))
532 202
format (/50(
'-')/ a50 /50(
'-'))
534 218
format (/ 80(
'-')/ 26x, a24, 26x, /80(
'-'))
535 222
format (/80(
'-')/ 26x, a21 /80(
'-'))
536 224
format (a40, 5x, a256)
538 301
format (a7, i2, a32, f15.0)
573 use mo_errormeasures,
only : kge, nse
574 use mo_julian,
only : dec2date
577 use mo_string_utils,
only : num2str
578 use mo_utils,
only : ge
579 use mo_netcdf,
only : ncdataset, ncdimension, ncvariable
584 real(dp),
dimension(:, :),
intent(in) :: Qobs
587 real(dp),
dimension(:, :),
intent(in) :: Qsim
589 character(256) :: fName, formHeader, formData, dummy
591 integer(i4) :: domainID, iDomain, gg, tt, err
593 integer(i4) :: igauge_start, igauge_end
595 integer(i4) :: day, month, year
597 integer(i4) :: tlength
600 integer(i4),
allocatable,
dimension(:) :: taxis
605 type(ncdataset) :: nc_out
606 type(ncdimension) :: dim, dim_bnd
607 type(ncvariable) :: var
618 igauge_end = igauge_start +
domain_mrm(idomain)%nGauges - 1
622 open(
udaily_discharge, file = trim(fname), status =
'unknown', action =
'write', iostat = err)
624 call error_message(
' IOError while openening "', trim(fname),
'". Error-Code ', num2str(err))
628 write(formheader, *)
'( 4a8, ',
domain_mrm(idomain)%nGauges,
'(2X, a5, i10.10, 2X, a5, i10.10) )'
630 (
'Qobs_',
gauge%gaugeId(gg), &
631 'Qsim_',
gauge%gaugeId(gg), gg = igauge_start, igauge_end)
634 write(formdata, *)
'( 4I8, ',
domain_mrm(idomain)%nGauges,
'(2X, f15.7 , 2X, f15.7 ) )'
637 newtime = real(
evalper(idomain)%julStart, dp) - 0.5_dp
639 do tt = 1, (
evalper(idomain)%julEnd -
evalper(idomain)%julStart + 1)
640 call dec2date(newtime, yy = year, mm = month, dd = day)
641 write(
udaily_discharge, formdata) tt, day, month, year, (qobs(tt, gg), qsim(tt, gg), gg = igauge_start, igauge_end)
642 newtime = newtime + 1.0_dp
652 nc_out = ncdataset(trim(fname),
"w")
655 allocate(taxis(tlength))
660 forall(tt = 1 : tlength) taxis(tt) = (tt-1) * 24
662 forall(tt = 1 : tlength) taxis(tt) = tt * 24 - 12
664 forall(tt = 1 : tlength) taxis(tt) = tt * 24
667 call dec2date(real(
evalper(idomain)%julStart, dp) - 0.5_dp, yy = year, mm = month, dd = day)
668 dim = nc_out%setDimension(
"time", tlength)
669 var = nc_out%setVariable(
"time",
"i32", [dim])
670 call var%setData(taxis)
671 call var%setAttribute( &
673 'hours since '//trim(num2str(year))//
'-'//trim(num2str(month,
'(i2.2)'))//
'-'//trim(num2str(day,
'(i2.2)'))//
' 00:00:00' &
675 call var%setAttribute(
"long_name",
"time in hours")
676 call var%setAttribute(
"bounds",
"time_bnds")
677 call var%setAttribute(
"axis",
"T")
678 dim_bnd = nc_out%setDimension(
"bnds", 2)
679 var = nc_out%setVariable(
"time_bnds",
"i32", [dim_bnd, dim])
681 call var%setData((tt - 1) * 24, (/1, tt/))
682 call var%setData(tt * 24, (/2, tt/))
686 do gg = igauge_start, igauge_end
687 var = nc_out%setVariable(
'Qsim_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
689 call var%setData(qsim(1 : tlength, gg))
690 call var%setAttribute(
"units",
"m3 s-1")
691 call var%setAttribute(
"long_name",
'simulated discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
692 call var%setAttribute(
"missing_value",
nodata_dp)
694 var = nc_out%setVariable(
'Qobs_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
696 call var%setData(qobs(1 : tlength, gg))
697 call var%setAttribute(
"units",
"m3 s-1")
698 call var%setAttribute(
"long_name",
'observed discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
699 call var%setAttribute(
"missing_value",
nodata_dp)
710 write(dummy,
'(I3)') domainid
711 call message(
' OUTPUT: saved daily discharge file for domain ', trim(adjustl(dummy)))
712 call message(
' to ', trim(fname))
713 do gg = igauge_start, igauge_end
714 if (count(ge(qobs(:, gg), 0.0_dp)) > 1)
then
715 call message(
' KGE of daily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
716 trim(adjustl(num2str(kge(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
717 call message(
' NSE of daily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
718 trim(adjustl(num2str(nse(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
725 igauge_start = igauge_end + 1
766 use mo_errormeasures,
only : kge, nse
767 use mo_julian,
only : dec2date
771 use mo_string_utils,
only : num2str
772 use mo_utils,
only : ge
773 use mo_netcdf,
only : ncdataset, ncdimension, ncvariable
778 real(dp),
dimension(:, :),
intent(in) :: Qobs
781 real(dp),
dimension(:, :),
intent(in) :: Qsim
784 integer(i4),
intent(in) :: factor
786 character(256) :: fName, formHeader, formData, dummy
788 integer(i4) :: domainID, iDomain, gg, tt, err
790 integer(i4) :: igauge_start, igauge_end
792 integer(i4) :: hour, day, month, year
794 integer(i4) :: tlength
797 integer(i4),
allocatable,
dimension(:) :: taxis
802 type(ncdataset) :: nc_out
803 type(ncdimension) :: dim, dim_bnd
804 type(ncvariable) :: var
807 logical :: use_minutes
808 integer(i4) :: time_unit_factor
819 igauge_end = igauge_start +
domain_mrm(idomain)%nGauges - 1
828 open(
usubdaily_discharge, file = trim(fname), status =
'unknown', action =
'write', iostat = err)
830 call error_message(
' IOError while openening "', trim(fname),
'". Error-Code ', num2str(err))
834 write(formheader, *)
'( 5a8, ',
domain_mrm(idomain)%nGauges,
'(2X, a5, i10.10, 2X, a5, i10.10) )'
836 (
'Qobs_',
gauge%gaugeId(gg), &
837 'Qsim_',
gauge%gaugeId(gg), gg = igauge_start, igauge_end)
840 write(formdata, *)
'( 5I8, ',
domain_mrm(idomain)%nGauges,
'(2X, f15.7 , 2X, f15.7 ) )'
843 newtime = real(
evalper(idomain)%julStart, dp) - 0.5_dp
846 call dec2date(newtime, yy = year, mm = month, dd = day, hh = hour)
847 write(
usubdaily_discharge, formdata) tt, hour, day, month, year, (qobs(tt, gg), qsim(tt, gg), gg = igauge_start, igauge_end)
858 nc_out = ncdataset(trim(fname),
"w")
861 allocate(taxis(tlength))
863 use_minutes = .false.
865 if ( mod(factor, 2) == 1 )
then
867 time_unit_factor = 60
873 forall(tt = 1 : tlength) taxis(tt) = (tt-1) * factor * time_unit_factor
875 forall(tt = 1 : tlength) taxis(tt) = tt * factor - factor * time_unit_factor / 2
877 forall(tt = 1 : tlength) taxis(tt) = tt * factor * time_unit_factor
880 call dec2date(real(
evalper(idomain)%julStart, dp) - 0.5_dp, yy = year, mm = month, dd = day, hh = hour)
881 dim = nc_out%setDimension(
"time", tlength)
882 var = nc_out%setVariable(
"time",
"i32", [dim])
883 call var%setData(taxis)
884 if (use_minutes)
then
885 call var%setAttribute( &
887 'minutes since '//trim(num2str(year))//
'-'//trim(num2str(month,
'(i2.2)'))//
'-'//trim(num2str(day,
'(i2.2)'))//
' '// &
888 trim(num2str(hour,
'(i2.2)'))//
':00:00' &
890 call var%setAttribute(
"long_name",
"time in minutes")
892 call var%setAttribute( &
894 'hours since '//trim(num2str(year))//
'-'//trim(num2str(month,
'(i2.2)'))//
'-'//trim(num2str(day,
'(i2.2)'))//
' '// &
895 trim(num2str(hour,
'(i2.2)'))//
':00:00' &
897 call var%setAttribute(
"long_name",
"time in hours")
899 call var%setAttribute(
"bounds",
"time_bnds")
900 call var%setAttribute(
"axis",
"T")
901 dim_bnd = nc_out%setDimension(
"bnds", 2)
902 var = nc_out%setVariable(
"time_bnds",
"i32", [dim_bnd, dim])
904 call var%setData((tt - 1) * factor * time_unit_factor, (/1, tt/))
905 call var%setData(tt * factor * time_unit_factor, (/2, tt/))
909 do gg = igauge_start, igauge_end
910 var = nc_out%setVariable(
'Qsim_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
912 call var%setData(qsim(1 : tlength, gg))
913 call var%setAttribute(
"units",
"m3 s-1")
914 call var%setAttribute(
"long_name",
'simulated discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
915 call var%setAttribute(
"missing_value",
nodata_dp)
917 var = nc_out%setVariable(
'Qobs_' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')),
"f64", [dim])
919 call var%setData(qobs(1 : tlength, gg))
920 call var%setAttribute(
"units",
"m3 s-1")
921 call var%setAttribute(
"long_name",
'observed discharge at gauge ' // trim(num2str(
gauge%gaugeID(gg),
'(i10.10)')))
922 call var%setAttribute(
"missing_value",
nodata_dp)
930 write(dummy,
'(I3)') domainid
931 call message(
' OUTPUT: saved subdaily discharge file for domain ', trim(adjustl(dummy)))
932 call message(
' to ', trim(fname))
933 do gg = igauge_start, igauge_end
934 if (count(ge(qobs(:, gg), 0.0_dp)) > 1)
then
935 call message(
' KGE of subdaily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
936 trim(adjustl(num2str(kge(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
937 call message(
' NSE of subdaily discharge (gauge #', trim(adjustl(num2str(gg))),
'): ', &
938 trim(adjustl(num2str(nse(qobs(:, gg), qsim(:, gg), mask = (ge(qobs(:, gg), 0.0_dp)))))))
943 igauge_start = igauge_end + 1
982 use mo_string_utils,
only : num2str
987 real(dp),
intent(in) :: best_of
990 real(dp),
dimension(:),
intent(in) :: best_paramset
992 character(len = *),
dimension(:),
intent(in) :: param_names
994 character(256) :: fname, formheader, formparams
996 integer(i4) :: ii, err, n_params
1000 n_params =
size(best_paramset)
1004 open(
uopti, file = fname, status =
'unknown', action =
'write', iostat = err, recl = (n_params + 1) * 40)
1006 call error_message(
' IOError while openening "', trim(fname),
'" Error-Code ', num2str(err))
1010 write(formheader, *)
'(a40,', n_params,
'a40)'
1013 write(
uopti, formheader)
'OF', (trim(adjustl(param_names(ii)(1 : 39))), ii = 1, n_params)
1016 write(formparams, *)
'( es40.14, ', n_params,
'(es40.14) )'
1017 write(
uopti, formparams) best_of, (best_paramset(ii), ii = 1, n_params)
1024 call message(
' Optimized parameters written to ', trim(fname))
1058 use mo_string_utils,
only : num2str
1063 real(dp),
dimension(:, :),
intent(in) :: parameters
1066 logical,
dimension(size(parameters, 1)),
intent(in) :: maskpara
1069 character(len = *),
dimension(size(parameters, 1)),
intent(in) :: parameters_name
1071 character(256) :: fname
1073 character(3) :: flag
1082 open(
uopti_nml, file = fname, status =
'unknown', action =
'write', iostat = err)
1084 call message (
' IOError while openening "', trim(fname),
'" Error-Code ', num2str(err))
1087 write(
uopti_nml, *)
'!global_parameters'
1088 write(
uopti_nml, *)
'!PARAMETER lower_bound upper_bound value FLAG SCALING'
1090 write(
uopti_nml, *)
'! ', trim(adjustl(
'routing'))
1096 do ipar = 1,
size(parameters, 1)
1097 if (maskpara(ipar))
then
1102 write(
uopti_nml, *) trim(adjustl(parameters_name(ipar))),
' = ', &
1103 parameters(ipar, 1),
' , ', &
1104 parameters(ipar, 2),
' , ', &
1105 parameters(ipar, 3),
' , ', &
1117 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.