Skip to content

Commit

Permalink
changed to reading seperate files instead of constructing it with dir…
Browse files Browse the repository at this point in the history
…s for restart

also, grid_info neaded the specification for mHM or mRM before. This is
not neccessary anymore.
  • Loading branch information
makaluza committed Mar 30, 2020
1 parent 187527b commit faba884
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 38 deletions.
11 changes: 4 additions & 7 deletions src/common/mo_common_restart.f90
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ end subroutine write_grid_info

! INTENT(IN)
!> \param[in] "integer(i4) :: iDomain" number of domain
!> \param[in] "character(256) :: InPath" Input Path including trailing slash
!> \param[in] "character(256) :: InFile" Input Path including trailing slash
!> \param[in] "character(*) :: level_name" level_name (id)
!> \param[in] "character(*) :: fname_part" filename part (either "mHM" or "mRM")

Expand All @@ -160,7 +160,7 @@ end subroutine write_grid_info
! Robert Schweppe Jun 2018 - refactoring and reformatting
! Stephan Thober May 2019 - added allocation check for mask and cellArea because cellArea needs to be read by mRM, but mask is created before by mHM

subroutine read_grid_info(domainID, InPath, level_name, fname_part, new_grid)
subroutine read_grid_info(domainID, InFile, level_name, new_grid)

use mo_common_variables, only : Grid
use mo_kind, only : dp, i4
Expand All @@ -174,14 +174,11 @@ subroutine read_grid_info(domainID, InPath, level_name, fname_part, new_grid)
integer(i4), intent(in) :: domainID

! Input Path including trailing slash
character(256), intent(in) :: InPath
character(256), intent(in) :: InFile

! level_name (id)
character(*), intent(in) :: level_name

! filename part (either "mHM" or "mRM")
character(*), intent(in) :: fname_part

! grid to save information to
type(Grid), intent(inout) :: new_grid

Expand All @@ -201,7 +198,7 @@ subroutine read_grid_info(domainID, InPath, level_name, fname_part, new_grid)


! read config
fname = trim(InPath) // trim(fname_part) // '_restart_' // trim(num2str(domainID, '(i3.3)')) // '.nc' ! '_restart.nc'
fname = trim(InFile)
call message(' Reading config from ', trim(adjustl(Fname)), ' ...')

nc = NcDataset(fname, "r")
Expand Down
14 changes: 9 additions & 5 deletions src/common_mHM_mRM/mo_common_mHM_mRM_read_config.f90
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ MODULE mo_common_mHM_mRM_read_config
subroutine common_mHM_mRM_read_config(file_namelist, unamelist)

use mo_common_constants, only : maxNoDomains
use mo_common_mHM_mRM_variables, only : LCyearId, dds_r, dirRestartIn, evalPer, mcmc_error_params, mcmc_opti, nIterations, &
use mo_common_mHM_mRM_variables, only : LCyearId, dds_r, mhmFileRestartIn, mrmFileRestartIn, evalPer,&
mcmc_error_params, mcmc_opti, nIterations, &
nTStepDay, opti_function, opti_method, optimize, optimize_restart, &
read_restart, mrm_read_river_network, resolutionRouting, sa_temp, &
sce_ngs, sce_npg, sce_nps, seed, &
Expand Down Expand Up @@ -77,13 +78,14 @@ subroutine common_mHM_mRM_read_config(file_namelist, unamelist)

real(dp), dimension(maxNoDomains) :: resolution_Routing

character(256), dimension(maxNoDomains) :: dir_RestartIn
character(256), dimension(maxNoDomains) :: mhm_file_RestartIn
character(256), dimension(maxNoDomains) :: mrm_file_RestartIn


! namelist spatial & temporal resolution, otmization information
namelist /mainconfig_mhm_mrm/ timestep, resolution_Routing, optimize, &
optimize_restart, opti_method, opti_function, &
read_restart, mrm_read_river_network, dir_RestartIn
read_restart, mrm_read_river_network, mhm_file_RestartIn, mrm_file_RestartIn
! namelist for optimization settings
namelist /Optimization/ nIterations, seed, dds_r, sa_temp, sce_ngs, &
sce_npg, sce_nps, mcmc_opti, mcmc_error_params
Expand Down Expand Up @@ -112,10 +114,12 @@ subroutine common_mHM_mRM_read_config(file_namelist, unamelist)
end if

allocate(resolutionRouting(domainMeta%nDomains))
allocate(dirRestartIn(domainMeta%nDomains))
allocate(mhmFileRestartIn(domainMeta%nDomains))
allocate(mrmFileRestartIn(domainMeta%nDomains))
do iDomain = 1, domainMeta%nDomains
domainID = domainMeta%indices(iDomain)
dirRestartIn(iDomain) = dir_RestartIn(domainID)
mhmFileRestartIn(iDomain) = mhm_file_RestartIn(domainID)
mrmFileRestartIn(iDomain) = mrm_file_RestartIn(domainID)
resolutionRouting(iDomain) = resolution_Routing(domainID)
end do

Expand Down
3 changes: 2 additions & 1 deletion src/common_mHM_mRM/mo_common_mHM_mRM_variables.f90
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ module mo_common_mHM_mRM_variables
! DIRECTORIES
! ------------------------------------------------------------------
! has the dimension of nDomains
character(256), dimension(:), allocatable, public :: dirRestartIn! Directory where input of restart is read from
character(256), dimension(:), allocatable, public :: mhmFileRestartIn! Directory where input of restart is read from
character(256), dimension(:), allocatable, public :: mrmFileRestartIn! Directory where input of restart is read from

! -------------------------------------------------------------------
! OPTIMIZATION
Expand Down
7 changes: 4 additions & 3 deletions src/mHM/mo_mhm_eval.f90
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ SUBROUTINE mhm_eval(parameterset, opti_domain_indices, runoff, smOptiSim, neutro

use mo_common_constants, only : nodata_dp
use mo_optimization_types, only : optidata_sim
use mo_common_mHM_mRM_variables, only : LCyearId, dirRestartIn, nTstepDay, optimize, readPer, read_restart, simPer, timeStep, &
use mo_common_mHM_mRM_variables, only : LCyearId, mhmFileRestartIn, mrmFileRestartIn, nTstepDay,&
optimize, readPer, read_restart, simPer, timeStep, &
warmingDays, c2TSTu
use mo_common_variables, only : level1, domainMeta, processMatrix
use mo_global_variables, only : L1_Throughfall, L1_aETCanopy, L1_aETSealed, L1_aETSoil, &
Expand Down Expand Up @@ -303,7 +304,7 @@ SUBROUTINE mhm_eval(parameterset, opti_domain_indices, runoff, smOptiSim, neutro
end if
domainID = domainMeta%indices(iDomain)
! this reads the eff. parameters and optionally the states and fluxes
call read_restart_states(iDomain, domainID, dirRestartIn(iDomain))
call read_restart_states(iDomain, domainID, mhmFileRestartIn(iDomain))
end do
end if

Expand Down Expand Up @@ -364,7 +365,7 @@ SUBROUTINE mhm_eval(parameterset, opti_domain_indices, runoff, smOptiSim, neutro
#ifdef MRM2MHM
if (domainMeta%doRouting(iDomain)) then
! read states from restart
if (read_restart) call mrm_read_restart_states(iDomain, domainID, dirRestartIn(iDomain))
if (read_restart) call mrm_read_restart_states(iDomain, domainID, mrmFileRestartIn(iDomain))
!
! get Domain information at L11 and L110 if routing is activated
s11 = level11(iDomain)%iStart
Expand Down
8 changes: 4 additions & 4 deletions src/mHM/mo_restart.f90
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ end subroutine write_restart_files

! INTENT(IN)
!> \param[in] "integer(i4) :: iDomain" number of domains
!> \param[in] "character(256) :: InPath" Input Path including trailing slash
!> \param[in] "character(256) :: InFile" Input Path including trailing slash

! HISTORY
!> \authors Stephan Thober
Expand All @@ -341,7 +341,7 @@ end subroutine write_restart_files
! Stephan Thober Nov 2016 - moved processMatrix to common variables
! Robert Schweppe Jun 2018 - refactoring and reformatting

subroutine read_restart_states(iDomain, domainID, InPath)
subroutine read_restart_states(iDomain, domainID, InFile)

use mo_common_variables, only : LC_year_end, LC_year_start, level1, nLCoverScene, processMatrix
use mo_global_variables, only : L1_Inter, L1_Throughfall, L1_aETCanopy, &
Expand All @@ -368,7 +368,7 @@ subroutine read_restart_states(iDomain, domainID, InPath)
integer(i4), intent(in) :: domainID

! Input Path including trailing slash
character(256), intent(in) :: InPath
character(256), intent(in) :: InFile

character(256) :: Fname

Expand Down Expand Up @@ -404,7 +404,7 @@ subroutine read_restart_states(iDomain, domainID, InPath)
LAIBoundaries_temp


Fname = trim(InPath) // 'mHM_restart_' // trim(num2str(domainID, '(i3.3)')) // '.nc'
Fname = trim(InFile)
! call message(' Reading states from ', trim(adjustl(Fname)),' ...')

! get domain information at level 1
Expand Down
4 changes: 2 additions & 2 deletions src/mHM/mo_startup.f90
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ MODULE mo_startup

subroutine mhm_initialize

use mo_common_mHM_mRM_variables, only : dirRestartIn, read_restart
use mo_common_mHM_mRM_variables, only : mhmFileRestartIn, read_restart
use mo_common_restart, only : read_grid_info
use mo_common_variables, only : level0, level1, domainMeta
use mo_global_variables, only : level2
Expand Down Expand Up @@ -98,7 +98,7 @@ subroutine mhm_initialize

if (read_restart) then
! this reads only the domain properties
call read_grid_info(domainID, dirRestartIn(iDomain), "1", "mHM", level1(iDomain))
call read_grid_info(domainID, mhmFileRestartIn(iDomain), "1", level1(iDomain))
! Parameter fields have to be allocated in any case
call init_eff_params(level1(iDomain)%nCells)
end if
Expand Down
5 changes: 3 additions & 2 deletions src/mRM/mo_mrm_eval.f90
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ subroutine mrm_eval(parameterset, opti_domain_indices, runoff, smOptiSim, neutro

use mo_optimization_types, only : optidata_sim
use mo_common_constants, only : HourSecs
use mo_common_mHM_mRM_variables, only : LCYearId, dirRestartIn, nTStepDay, optimize, read_restart, resolutionRouting, simPer, &
use mo_common_mHM_mRM_variables, only : LCYearId, mrmFileRestartIn, nTStepDay, optimize,&
read_restart, resolutionRouting, simPer, &
timestep, warmingDays
use mo_common_variables, only : level1, domainMeta, processMatrix, resolutionHydrology
use mo_julian, only : caldat, julday
Expand Down Expand Up @@ -188,7 +189,7 @@ subroutine mrm_eval(parameterset, opti_domain_indices, runoff, smOptiSim, neutro
end if
domainID = domainMeta%indices(iDomain)
! read states from restart
if (read_restart) call mrm_read_restart_states(iDomain, domainID, dirRestartIn(iDomain))
if (read_restart) call mrm_read_restart_states(iDomain, domainID, mrmFileRestartIn(iDomain))
!
! get domain information at L11 and L1 if routing is activated
s1 = level1(iDomain)%iStart
Expand Down
12 changes: 6 additions & 6 deletions src/mRM/mo_mrm_init.f90
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ end subroutine mrm_configuration
subroutine mrm_init(file_namelist, unamelist, file_namelist_param, unamelist_param, ReadLatLon)

use mo_common_constants, only : nodata_dp, nodata_i4
use mo_common_mHM_mRM_variables, only : dirRestartIn, mrm_coupling_mode, mrm_read_river_network, &
use mo_common_mHM_mRM_variables, only : mrmFileRestartIn, mrm_coupling_mode, mrm_read_river_network, &
resolutionRouting
use mo_common_restart, only : read_grid_info
use mo_common_variables, only : domainMeta, global_parameters, l0_l1_remap, level0, level1, domainMeta, &
Expand Down Expand Up @@ -163,13 +163,13 @@ subroutine mrm_init(file_namelist, unamelist, file_namelist_param, unamelist_par
! this reads the domain properties
if (.not. allocated(level0)) allocate(level0(domainMeta%nDomains))
! ToDo: L0_Domain, parallel
call read_grid_info(domainMeta%indices(domainMeta%L0DataFrom(iDomain)), dirRestartIn(iDomain), &
"0", "mRM", level0(domainMeta%L0DataFrom(iDomain)))
call read_grid_info(domainMeta%indices(domainMeta%L0DataFrom(iDomain)), mrmFileRestartIn(iDomain), &
"0", level0(domainMeta%L0DataFrom(iDomain)))
if (mrm_coupling_mode .eq. 0_i4) then
call read_grid_info(domainID, dirRestartIn(iDomain), "1", "mRM", level1(iDomain))
call read_grid_info(domainID, mrmFileRestartIn(iDomain), "1", level1(iDomain))
end if
call read_grid_info(domainID, dirRestartIn(iDomain), "11", "mRM", level11(iDomain))
call mrm_read_restart_config(iDomain, domainID, dirRestartIn(iDomain))
call read_grid_info(domainID, mrmFileRestartIn(iDomain), "11", level11(iDomain))
call mrm_read_restart_config(iDomain, domainID, mrmFileRestartIn(iDomain))
else
if (iDomain .eq. 1) then
call L0_check_input_routing(domainMeta%L0DataFrom(iDomain))
Expand Down
16 changes: 8 additions & 8 deletions src/mRM/mo_mrm_restart.f90
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ end subroutine mrm_write_restart

! INTENT(IN)
!> \param[in] "integer(i4) :: iDomain" number of domains
!> \param[in] "character(256) :: InPath" Input Path including trailing slash
!> \param[in] "character(256) :: InFile" Input Path including trailing slash

! HISTORY
!> \authors Stephan Thober
Expand All @@ -457,7 +457,7 @@ end subroutine mrm_write_restart
! Stephan Thober May 2016 - split L0_OutletCoord into L0_rowOutlet & L0_colOutlet because multiple outlets could exist
! Robert Schweppe Jun 2018 - refactoring and reformatting

subroutine mrm_read_restart_states(iDomain, domainID, InPath)
subroutine mrm_read_restart_states(iDomain, domainID, InFile)

use mo_common_variables, only : nLCoverScene
use mo_mrm_constants, only : nRoutingStates
Expand All @@ -474,7 +474,7 @@ subroutine mrm_read_restart_states(iDomain, domainID, InPath)
integer(i4), intent(in) :: domainID

! Input Path including trailing slash
character(256), intent(in) :: InPath
character(256), intent(in) :: InFile

integer(i4) :: ii

Expand All @@ -501,7 +501,7 @@ subroutine mrm_read_restart_states(iDomain, domainID, InPath)


! set file name
fname = trim(InPath) // 'mRM_restart_' // trim(num2str(domainID, '(i3.3)')) // '.nc'
fname = trim(InFile)

! get Domain info at L11 including ncells, start, end, and mask
s11 = level11(iDomain)%iStart
Expand Down Expand Up @@ -582,7 +582,7 @@ end subroutine mrm_read_restart_states

! INTENT(IN)
!> \param[in] "integer(i4) :: iDomain" number of Domain
!> \param[in] "character(256) :: InPath" Input Path including trailing slash
!> \param[in] "character(256) :: InFile" Input Path including trailing slash

! HISTORY
!> \authors Stephan Thober
Expand All @@ -599,7 +599,7 @@ end subroutine mrm_read_restart_states
! Robert Schweppe Jun 2018 - refactoring and reformatting
! Stephan Thober May 2019 - added L0 info required for Process 3

subroutine mrm_read_restart_config(iDomain, domainID, InPath)
subroutine mrm_read_restart_config(iDomain, domainID, InFile)

use mo_append, only : append
use mo_common_constants, only : nodata_dp
Expand All @@ -624,7 +624,7 @@ subroutine mrm_read_restart_config(iDomain, domainID, InPath)
integer(i4), intent(in) :: domainID

! Input Path including trailing slash
character(256), intent(in) :: InPath
character(256), intent(in) :: InFile

character(256) :: fname

Expand Down Expand Up @@ -653,7 +653,7 @@ subroutine mrm_read_restart_config(iDomain, domainID, InPath)


! set file name
fname = trim(InPath) // 'mRM_restart_' // trim(num2str(domainID, '(i3.3)')) // '.nc'
fname = trim(InFile)
call message(' Reading mRM restart file: ', trim(adjustl(Fname)), ' ...')

! get Domain info at L11 mask
Expand Down

0 comments on commit faba884

Please sign in to comment.