14 USE mo_kind,
ONLY : i4, dp
15 use mo_message,
only: error_message
47 use mo_nml,
only : close_nml, open_nml, position_nml
48 use mo_string_utils,
only : num2str
53 character(*),
intent(in) :: file_namelist
56 integer,
intent(in) :: unamelist
59 integer(i4),
dimension(nProcesses) :: processcase
61 character(256),
dimension(maxNoDomains) :: dir_morpho
63 character(256),
dimension(maxNoDomains) :: mhm_file_restartout
65 character(256),
dimension(maxNoDomains) :: mrm_file_restartout
67 character(256),
dimension(maxNoDomains) :: dir_lcover
69 character(256),
dimension(maxNoDomains) :: dir_out
71 character(256),
dimension(maxNoDomains) :: file_latlon
73 real(dp),
dimension(maxNoDomains) :: resolution_hydrology
75 integer(i4),
dimension(maxNoDomains) :: l0domain
77 integer(i4),
dimension(maxNoDomains) :: read_opt_domain_data
80 integer(i4),
dimension(maxNLCovers) :: lcoveryearstart
83 integer(i4),
dimension(maxNLCovers) :: lcoveryearend
86 character(256),
dimension(maxNLCovers) :: lcoverfname
88 integer(i4) :: i, newdomainid, domainid, idomain, ndomains
99 dir_morpho, dir_lcover, &
100 dir_out, mhm_file_restartout, mrm_file_restartout, &
106 namelist /processselection/ processcase
109 namelist/lcover/
nlcoverscene, lcoveryearstart, lcoveryearend, lcoverfname
114 call open_nml(file_namelist, unamelist, quiet = .true.)
119 call position_nml(
'project_description', unamelist)
120 read(unamelist, nml = project_description)
125 call position_nml(
'mainconfig', unamelist)
126 read(unamelist, nml = mainconfig)
131 call error_message(
'***ERROR: Number of domains is resticted to ', trim(num2str(
maxnodomains)),
'!')
154 newdomainid = l0domain(domainid)
158 do i = 1, idomain - 1
159 if (newdomainid ==
domainmeta%indices(i))
then
169 call error_message(
'***ERROR: coordinate system for the model run should be 0 or 1')
175 call position_nml(
'LCover', unamelist)
176 read(unamelist, nml = lcover)
190 call position_nml(
'directories_general', unamelist)
191 read(unamelist, nml = directories_general)
195 domainmeta%optidata(idomain) = read_opt_domain_data(domainid)
196 dirmorpho(idomain) = dir_morpho(domainid)
199 dirlcover(idomain) = dir_lcover(domainid)
200 dirout(idomain) = dir_out(domainid)
214 call position_nml(
'processselection', unamelist)
215 read(unamelist, nml = processselection)
225 call close_nml(unamelist)
241 use mo_string_utils,
only : num2str
245 type(
period),
dimension(:),
intent(in) :: sim_per
246 integer(i4),
dimension(:, :),
allocatable,
intent(inout) :: lcyear_id
248 integer(i4) :: ii, idomain
253 call error_message(
'***ERROR: Land cover for warming period is missing!', raise=.false.)
254 call error_message(
' SimStart : ', trim(num2str(minval(sim_per(1 :
domainmeta%nDomains)%yStart))), raise=.false.)
255 call error_message(
' LCoverStart: ', trim(num2str(
lc_year_start(1))))
258 call error_message(
'***ERROR: Land cover period shorter than modelling period!', raise=.false.)
259 call error_message(
' SimEnd : ', trim(num2str(maxval(sim_per(1 :
domainmeta%nDomains)%yEnd))), raise=.false.)
263 allocate(lcyear_id(minval(sim_per(1 :
domainmeta%nDomains)%yStart) : maxval(sim_per(1 :
domainmeta%nDomains)%yEnd), &
269 if ((
lc_year_end(ii) .LT. sim_per(idomain)%yStart) .OR. &
273 else if ((
lc_year_start(ii) .LE. sim_per(idomain)%yStart) .AND. &
275 lcyear_id(sim_per(idomain)%yStart : sim_per(idomain)%yEnd, idomain) = ii
278 else if ((
lc_year_start(ii) .LE. sim_per(idomain)%yStart) .AND. &
280 lcyear_id(sim_per(idomain)%yStart :
lc_year_end(ii), idomain) = ii
282 else if ((
lc_year_start(ii) .GT. sim_per(idomain)%yStart) .AND. &
284 lcyear_id(
lc_year_start(ii) : sim_per(idomain)%yEnd, idomain) = ii
326 integer(i4),
intent(in) :: nDomains
327 integer(i4),
dimension(:),
intent(in) :: optiData
333 integer(i4) :: iDomain
334 integer(i4) :: colDomain, colMasters
336 domainmeta%overallNumberOfDomains = ndomains
339 call mpi_comm_size(comm, nproc, ierror)
341 call mpi_comm_rank(comm, rank, ierror)
343 call error_message(
'at least 2 processes are required')
346 if (nproc > domainmeta%overallNumberOfDomains + 1)
then
347 domainmeta%nDomains = 0
350 call init_domain_variable_for_master(domainmeta, colmasters, coldomain)
356 call distribute_processes_to_domains_according_to_role(optidata, rank, &
357 domainmeta, colmasters, coldomain)
365 call mpi_comm_split(comm, colmasters, rank, domainmeta%comMaster, ierror)
366 call mpi_comm_split(comm, coldomain, rank, domainmeta%comLocal, ierror)
367 call mpi_comm_size(domainmeta%comMaster, nproc, ierror)
371 call mpi_comm_dup(comm, domainmeta%comMaster, ierror)
372 domainmeta%isMasterInComLocal = .true.
373 domainmeta%nDomains = 0
376 domainmeta%nDomains = domainmeta%overallNumberOfDomains
377 allocate(domainmeta%indices(domainmeta%nDomains))
378 do idomain = 1, domainmeta%nDomains
379 domainmeta%indices(idomain) = idomain
383 call distributedomainsroundrobin(nproc, rank, domainmeta)
387 domainmeta%nDomains = ndomains
388 allocate(domainmeta%indices(domainmeta%nDomains))
389 do idomain = 1, domainmeta%nDomains
390 domainmeta%indices(idomain) = idomain
397 subroutine init_domain_variable_for_master(domainMeta, colMasters, colDomain)
400 integer(i4),
intent(out) :: colMasters
401 integer(i4),
intent(out) :: colDomain
403 integer(i4) :: iDomain
405 domainmeta%nDomains = domainmeta%overallNumberOfDomains
406 allocate(domainmeta%indices(domainmeta%nDomains))
407 do idomain = 1, domainmeta%nDomains
408 domainmeta%indices(idomain) = idomain
412 domainmeta%isMasterInComLocal = .true.
414 end subroutine init_domain_variable_for_master
416 subroutine distributedomainsroundrobin(nproc, rank, domainMeta)
418 integer(i4),
intent(in) :: nproc
419 integer(i4),
intent(in) :: rank
422 integer(i4) :: iDomain, iProcDomain
424 do idomain = 1 , domainmeta%overallNumberOfDomains
425 if (rank == (modulo(idomain + nproc - 2, (nproc - 1)) + 1))
then
426 domainmeta%nDomains = domainmeta%nDomains + 1
429 allocate(domainmeta%indices(domainmeta%nDomains))
431 do idomain = 1 , domainmeta%overallNumberOfDomains
432 if (rank == (modulo(idomain + nproc - 2, (nproc - 1)) + 1))
then
433 iprocdomain = iprocdomain + 1
434 domainmeta%indices(iprocdomain) = idomain
437 end subroutine distributedomainsroundrobin
439 subroutine distribute_processes_to_domains_according_to_role(optiData, rank, &
440 domainMeta, colMasters, colDomain)
442 integer(i4),
dimension(:),
intent(in) :: optiData
443 integer(i4),
intent(in) :: rank
445 integer(i4),
intent(out) :: colMasters
446 integer(i4),
intent(out) :: colDomain
449 integer(i4) :: nDomainsAll, nTreeDomains, i, iDomain
450 integer(i4),
dimension(:),
allocatable :: treeDomainList
452 ndomainsall = domainmeta%overallNumberOfDomains
454 do idomain = 1, ndomainsall
456 if (optidata(idomain) == 1)
then
457 ntreedomains = ntreedomains + 1
460 allocate(treedomainlist(ntreedomains))
462 do idomain = 1, ndomainsall
463 if (optidata(idomain) == 1)
then
465 treedomainlist(i) = idomain
468 if (rank < ndomainsall + 1)
then
471 domainmeta%isMasterInComLocal = .true.
472 domainmeta%nDomains = 1
473 allocate(domainmeta%indices(domainmeta%nDomains))
474 domainmeta%indices(1) = rank
477 if (ntreedomains > 0)
then
478 coldomain = treedomainlist(mod(rank, ntreedomains) + 1)
482 domainmeta%isMasterInComLocal = .false.
483 domainmeta%nDomains = 1
484 allocate(domainmeta%indices(domainmeta%nDomains))
487 domainmeta%indices(1) = 1
489 deallocate(treedomainlist)
498 use mo_string_utils,
only : num2str
500 integer(i4),
dimension(maxNoDomains),
intent(in) ::L0Domain
501 integer(i4),
intent(in) :: nDomains
506 if (l0domain(i) < 0)
call error_message( &
507 "L0Domain values need to be positive: ", &
508 "L0Domain(", trim(adjustl(num2str(i))),
") = ", trim(adjustl(num2str(l0domain(i)))))
509 if (l0domain(i) > i)
call error_message( &
510 "L0Domain values need to be less or equal to the domain index: ", &
511 "L0Domain(", trim(adjustl(num2str(i))),
") = ", trim(adjustl(num2str(l0domain(i)))))
514 if (l0domain(i) < l0domain(i-1))
call error_message( &
515 "L0Domain values need to be increasing: ", &
516 "L0Domain(", trim(adjustl(num2str(i-1))),
") = ", trim(adjustl(num2str(l0domain(i-1)))), &
517 ", L0Domain(", trim(adjustl(num2str(i))),
") = ", trim(adjustl(num2str(l0domain(i)))))
520 if (l0domain(i) < i)
then
521 if (l0domain(l0domain(i)) /= l0domain(i))
call error_message( &
522 "L0Domain values should be taken from a domain with its own L0 data: ", &
523 "L0Domain(", trim(adjustl(num2str(i))),
") = ", trim(adjustl(num2str(l0domain(i)))), &
524 ", L0Domain(", trim(adjustl(num2str(l0domain(i)))),
") = ", trim(adjustl(num2str(l0domain(l0domain(i))))))
Provides constants commonly used by mHM, mRM and MPR.
integer(i4), parameter, public maxnodomains
integer(i4), parameter, public maxnlcovers
integer(i4), parameter, public nodata_i4
Reading of main model configurations.
subroutine check_l0domain(l0domain, ndomains)
subroutine, public set_land_cover_scenes_id(sim_per, lcyear_id)
Set land cover scenes IDs.
subroutine init_domain_variable(ndomains, optidata, domainmeta)
Initialization of the domain variables.
subroutine, public common_read_config(file_namelist, unamelist)
Read main configurations commonly used by mHM, mRM and MPR.
Provides common types needed by mHM, mRM and/or mpr.
Provides structures needed by mHM, mRM and/or mpr.
integer(i4), parameter, public nprocesses
character(256), dimension(:), allocatable, public filelatlon
character(256), dimension(:), allocatable, public mhmfilerestartout
character(1024), public history
character(1024), public setup_description
real(dp), dimension(:), allocatable, public resolutionhydrology
logical, public write_restart
character(256), dimension(:), allocatable, public lcfilename
type(domain_meta), public domainmeta
character(1024), public project_details
character(1024), public contact
character(256), public dirconfigout
character(256), public conventions
character(1024), public simulation_type
integer(i4), public nuniquel0domains
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), public dircommonfiles
character(256), dimension(:), allocatable, public dirmorpho
integer(i4), public iflag_cordinate_sys
integer(i4), dimension(nprocesses, 3), public processmatrix
character(256), dimension(:), allocatable, public mrmfilerestartout
character(1024), public mhm_details
integer(i4), dimension(:), allocatable, public lc_year_start
DOMAIN general description.