14 use mo_kind,
only : i4, dp
15 use mo_message,
only: message, error_message
62 use mo_netcdf,
only : ncdataset, ncdimension, ncvariable
67 type(
grid),
intent(in) :: grid_in
70 character(*),
intent(in) :: level_name
73 type(ncdataset),
intent(inout) :: nc
76 integer(i4),
allocatable :: dummy(:, :)
78 type(ncdimension) :: rows, cols
80 type(ncvariable) :: var
83 rows = nc%setDimension(
"nrows" // trim(level_name), grid_in%nrows)
84 cols = nc%setDimension(
"ncols" // trim(level_name), grid_in%ncols)
87 var = nc%setVariable(
"L" // trim(level_name) //
"_domain_mask",
"i32", (/rows, cols/))
91 allocate(dummy(
size(grid_in%mask, 1),
size(grid_in%mask, 2)))
93 where(grid_in%mask) dummy = 1_i4
94 call var%setData(dummy)
96 call var%setAttribute(
"long_name",
"Mask at level " // trim(level_name))
98 var = nc%setVariable(
"L" // trim(level_name) //
"_domain_lat",
"f64", (/rows, cols/))
100 call var%setData(grid_in%y)
101 call var%setAttribute(
"long_name",
"Latitude at level " // trim(level_name))
103 var = nc%setVariable(
"L" // trim(level_name) //
"_domain_lon",
"f64", (/rows, cols/))
105 call var%setData(grid_in%x)
106 call var%setAttribute(
"long_name",
"Longitude at level " // trim(level_name))
108 var = nc%setVariable(
"L" // trim(level_name) //
"_domain_cellarea",
"f64", (/rows, cols/))
110 call var%setData(unpack(grid_in%CellArea * 1.0e-6_dp, grid_in%mask,
nodata_dp))
111 call var%setAttribute(
"long_name",
"Cell area at level " // trim(level_name))
113 call nc%setAttribute(
"xllcorner_L" // trim(level_name), grid_in%xllcorner)
114 call nc%setAttribute(
"yllcorner_L" // trim(level_name), grid_in%yllcorner)
115 call nc%setAttribute(
"cellsize_L" // trim(level_name), grid_in%cellsize)
116 call nc%setAttribute(
"nrows_L" // trim(level_name), grid_in%nrows)
117 call nc%setAttribute(
"ncols_L" // trim(level_name), grid_in%ncols)
118 call nc%setAttribute(
"nCells_L" // trim(level_name), grid_in%nCells)
144 use mo_netcdf,
only : ncdataset, ncvariable
149 character(256),
intent(in) :: infile
152 character(*),
intent(in) :: level_name
155 type(
grid),
intent(inout) :: new_grid
158 integer(i4),
dimension(:, :),
allocatable :: dummyi2
161 real(dp),
dimension(:, :),
allocatable :: dummyd2
163 character(256) :: fname
165 type(ncdataset) :: nc
167 type(ncvariable) :: var
174 call message(
' Reading config from ', trim(adjustl(fname)),
' ...')
176 nc = ncdataset(fname,
"r")
182 call nc%getAttribute(
"xllcorner_L" // trim(level_name), new_grid%xllcorner)
183 call nc%getAttribute(
"yllcorner_L" // trim(level_name), new_grid%yllcorner)
184 call nc%getAttribute(
"nrows_L" // trim(level_name), new_grid%nrows)
185 call nc%getAttribute(
"ncols_L" // trim(level_name), new_grid%ncols)
186 call nc%getAttribute(
"cellsize_L" // trim(level_name), new_grid%cellsize)
187 call nc%getAttribute(
"nCells_L" // trim(level_name), new_grid%nCells)
189 if (.not.
allocated(new_grid%mask))
allocate(new_grid%mask(new_grid%nrows, new_grid%ncols))
190 if (.not.
allocated(new_grid%x))
allocate(new_grid%x(new_grid%nrows, new_grid%ncols))
191 if (.not.
allocated(new_grid%y))
allocate(new_grid%y(new_grid%nrows, new_grid%ncols))
193 var = nc%getVariable(
"L" // trim(level_name) //
"_domain_mask")
195 call var%getData(dummyi2)
197 new_grid%mask = (dummyi2 .eq. 1_i4)
199 var = nc%getVariable(
"L" // trim(level_name) //
"_domain_lat")
200 call var%getData(new_grid%y)
202 var = nc%getVariable(
"L" // trim(level_name) //
"_domain_lon")
203 call var%getData(new_grid%x)
205 var = nc%getVariable(
"L" // trim(level_name) //
"_domain_cellarea")
206 call var%getData(dummyd2)
207 if (.not.
allocated(new_grid%CellArea)) new_grid%CellArea = pack(dummyd2 / 1.0e-6_dp, new_grid%mask)
212 new_grid%Id = (/ (k, k = 1, new_grid%nCells) /)
225 use mo_netcdf,
only : ncdataset, ncvariable, ncdimension
232 integer(i4),
intent(in) :: idomain
234 character(256),
intent(in) :: infile
236 character(256) :: fname
237 type(ncdataset) :: nc
238 type(ncvariable) :: var
239 type(ncdimension) :: nc_dim
241 integer(i4) :: nsoilhorizons_temp, nlais_temp, nlandcoverperiods_temp
242 real(dp),
dimension(:),
allocatable :: landcoverperiodboundaries_temp, soilhorizonboundaries_temp, &
246 real(dp),
dimension(:, :),
allocatable :: dummyd2, dummyd2_tmp
252 call message(
' Reading and checking LAI, land-cover and soil-horizons from ', trim(adjustl(fname)),
' ...')
254 nc = ncdataset(fname,
"r")
258 call var%getData(dummyd2_tmp)
259 if (
allocated(dummyd2))
deallocate(dummyd2)
261 allocate(dummyd2(
size(dummyd2_tmp,2),
size(dummyd2_tmp,1)))
262 dummyd2 = transpose(dummyd2_tmp)
264 allocate(dummyd2(
size(dummyd2_tmp,1),
size(dummyd2_tmp,2)))
265 dummyd2 = dummyd2_tmp
267 deallocate(dummyd2_tmp)
268 nsoilhorizons_temp =
size(dummyd2, 2)
269 allocate(soilhorizonboundaries_temp(nsoilhorizons_temp+1))
270 soilhorizonboundaries_temp(1:nsoilhorizons_temp) = dummyd2(1, :)
271 soilhorizonboundaries_temp(nsoilhorizons_temp+1) = dummyd2(2, nsoilhorizons_temp)
275 call var%getData(dummyd2_tmp)
276 if (
allocated(dummyd2))
deallocate(dummyd2)
278 allocate(dummyd2(
size(dummyd2_tmp,2),
size(dummyd2_tmp,1)))
279 dummyd2 = transpose(dummyd2_tmp)
281 allocate(dummyd2(
size(dummyd2_tmp,1),
size(dummyd2_tmp,2)))
282 dummyd2 = dummyd2_tmp
284 deallocate(dummyd2_tmp)
285 nlandcoverperiods_temp =
size(dummyd2, 2)
286 allocate(landcoverperiodboundaries_temp(nlandcoverperiods_temp+1))
287 landcoverperiodboundaries_temp(1:nlandcoverperiods_temp) = dummyd2(1, :)
288 landcoverperiodboundaries_temp(nlandcoverperiods_temp+1) = dummyd2(2, nlandcoverperiods_temp)
291 if (nc%hasVariable(trim(
laivarname)//
'_bnds'))
then
292 var = nc%getVariable(trim(
laivarname)//
'_bnds')
293 call var%getData(dummyd2_tmp)
294 if (
allocated(dummyd2))
deallocate(dummyd2)
296 allocate(dummyd2(
size(dummyd2_tmp,2),
size(dummyd2_tmp,1)))
297 dummyd2 = transpose(dummyd2_tmp)
299 allocate(dummyd2(
size(dummyd2_tmp,1),
size(dummyd2_tmp,2)))
300 dummyd2 = dummyd2_tmp
302 deallocate(dummyd2_tmp)
303 nlais_temp =
size(dummyd2, 2)
304 allocate(laiboundaries_temp(nlais_temp+1))
305 laiboundaries_temp(1:nlais_temp) = dummyd2(1, :)
306 laiboundaries_temp(nlais_temp+1) = dummyd2(2, nlais_temp)
307 else if (nc%hasDimension(
'L1_LAITimesteps'))
then
308 nc_dim = nc%getDimension(
'L1_LAITimesteps')
309 nlais_temp = nc_dim%getLength()
310 allocate(laiboundaries_temp(nlais_temp+1))
311 laiboundaries_temp = [(ii, ii=1, nlais_temp+1)]
313 call error_message(
'***ERROR: no LAI information in restart file for reading')
317 if (
nlai == -1_i4)
then
324 nlais_temp, laiboundaries_temp, nlandcoverperiods_temp, landcoverperiodboundaries_temp)
334 nLAIs_temp, LAIBoundaries_temp, nLandCoverPeriods_temp, landCoverPeriodBoundaries_temp)
338 use mo_string_utils,
only: compress, num2str
340 integer(i4),
intent(in) :: iDomain
342 integer(i4),
intent(in) :: nSoilHorizons_temp, nLAIs_temp, nLandCoverPeriods_temp
343 real(dp),
dimension(:),
intent(inout) :: landCoverPeriodBoundaries_temp, soilHorizonBoundaries_temp, &
345 character(256) :: errorString
356 errorstring = compress(trim(num2str(k)))//
'th land cover boundary'
359 errorstring =
'last land cover boundary (with 1 year added due to real/int conversion) '
361 landcoverperiodboundaries_temp(
nlcoverscene+1), errorstring, idomain)
366 errorstring = compress(trim(num2str(k)))//
'th soil horizon boundary'
371 errorstring = compress(trim(num2str(k)))//
'th LAI period boundary'
379 use mo_utils,
only: ne
380 use mo_string_utils,
only: compress, num2str
382 real(dp),
intent(in) :: item1, item2
383 character(*),
intent(in) :: name
384 integer(i4),
intent(in) :: iDomain
386 if (ne(item1, item2))
then
387 call error_message( &
389 ' as set in the configuration file (', &
390 compress(trim(num2str(item1))), &
391 ') does not conform with domain ', &
392 compress(trim(num2str(idomain))),
' (', compress(trim(num2str(item2))),
').')
398 use mo_string_utils,
only: compress, num2str
400 integer(i4),
intent(in) :: item1, item2
401 character(*),
intent(in) :: name
402 integer(i4),
intent(in) :: iDomain
404 if (item1 /= item2)
then
405 call error_message( &
407 ' as set in the configuration file (', &
408 compress(trim(num2str(item1))), &
409 ') does not conform with domain ', &
410 compress(trim(num2str(idomain))),
' (', compress(trim(num2str(item2))),
').')
check consistency of two given items
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
integer(i4), parameter, public nodata_i4
Provides structures needed by mHM, mRM and/or mpr.
logical, public read_old_style_restart_bounds
subroutine, public read_grid_info(infile, level_name, new_grid)
reads configuration apart from Level 11 configuration from a restart directory
subroutine, public write_grid_info(grid_in, level_name, nc)
write restart files for each domain
subroutine check_consistency_element_i4(item1, item2, name, idomain)
check consistency of two given items
subroutine, public read_nlai_and_check_dims(idomain, infile)
read nubmer of LAI time steps and check dimension configurations read from restart file
subroutine check_consistency_element_dp(item1, item2, name, idomain)
check consistency of two given items
subroutine check_dimension_consistency(idomain, nsoilhorizons_temp, soilhorizonboundaries_temp, nlais_temp, laiboundaries_temp, nlandcoverperiods_temp, landcoverperiodboundaries_temp)
checks dimension configurations read from restart file
Provides common types needed by mHM, mRM and/or mpr.
Provides structures needed by mHM, mRM and/or mpr.
integer(i4), public nlcoverscene
integer(i4), dimension(:), allocatable, public lc_year_end
integer(i4), dimension(:), allocatable, public lc_year_start
Global variables for mpr only.
integer(i4), public nsoilhorizons_mhm
real(dp), dimension(:), allocatable, public laiboundaries
real(dp), dimension(:), allocatable, public horizondepth_mhm