19 USE mo_kind,
ONLY : i4, dp
20 use mo_message,
only: message, error_message
51 iDomain, dataPath, inputFormat, dataOut1, readPer, nTstepForcingDay, level1, level2, lower, upper, ncvarName, bound_error)
53 use mo_append,
only : append
62 integer(i4),
intent(in) :: idomain
64 character(len = *),
intent(in) :: datapath
66 character(len = *),
intent(in) :: inputformat
68 real(dp),
dimension(:, :),
allocatable,
intent(inout) :: dataout1
70 type(
period),
intent(in) :: readper
72 integer(i4),
intent(inout) :: ntstepforcingday
74 type(
grid),
dimension(:),
intent(in) :: level1
76 type(
grid),
dimension(:),
intent(in) :: level2
78 real(dp),
optional,
intent(in) :: lower
80 real(dp),
optional,
intent(in) :: upper
82 character(len = *),
optional,
intent(in) :: ncvarname
84 logical,
optional,
intent(in) :: bound_error
86 logical,
dimension(:, :),
allocatable :: mask1
87 integer(i4) :: ncells1
88 integer(i4) :: nrows2, ncols2
89 logical,
dimension(:, :),
allocatable :: mask2
91 real(dp),
dimension(:, :, :),
allocatable :: l2_data
93 real(dp),
dimension(:, :, :),
allocatable :: l1_data
95 real(dp),
dimension(:, :),
allocatable :: l1_data_packed
96 integer(i4) :: ntimesteps
98 real(dp) :: cellfactorhbym
102 ncells1 = level1(idomain)%nCells
103 mask1 = level1(idomain)%mask
106 nrows2 = level2(idomain)%nrows
107 ncols2 = level2(idomain)%ncols
108 mask2 = level2(idomain)%mask
111 select case (trim(inputformat))
114 CALL read_nc(datapath, nrows2, ncols2, ncvarname, mask2, l2_data, target_period=readper, &
115 lower=lower, upper=upper, is_meteo=.true., bound_error=bound_error, ntstepforcingday=ntstepforcingday)
117 call error_message(
'***ERROR: meteo_forcings_wrapper: Not recognized input format')
120 cellfactorhbym = level1(idomain)%cellsize / level2(idomain)%cellsize
123 if(cellfactorhbym .gt. 1.0_dp)
then
124 call spatial_aggregation(l2_data, level2(idomain)%cellsize, level1(idomain)%cellsize, mask1, mask2, l1_data)
126 elseif(cellfactorhbym .lt. 1.0_dp)
then
127 call spatial_disaggregation(l2_data, level2(idomain)%cellsize, level1(idomain)%cellsize, mask1, mask2, l1_data)
130 allocate(l1_data(
size(l2_data, 1),
size(l2_data, 2),
size(l2_data, 3)))
131 l1_data(:, :, :) = l2_data(:, :, :)
137 ntimesteps =
size(l1_data, 3)
138 allocate(l1_data_packed(ncells1, ntimesteps))
141 l1_data_packed(:, t) = pack(l1_data(:, :, t), mask = mask1(:, :))
149 call append(dataout1, l1_data_packed(:, :),
nodata_dp)
152 deallocate(l1_data_packed)
175 subroutine meteo_weights_wrapper(iDomain, read_meteo_weights, dataPath, dataOut1, level1, level2, lower, upper, ncvarName)
177 use mo_append,
only : append
186 integer(i4),
intent(in) :: idomain
188 logical,
intent(in) :: read_meteo_weights
190 character(len = *),
intent(in) :: datapath
192 real(dp),
dimension(:, :, :),
allocatable,
intent(inout) :: dataout1
194 type(
grid),
dimension(:),
intent(in) :: level1
196 type(
grid),
dimension(:),
intent(in) :: level2
198 real(dp),
optional,
intent(in) :: lower
200 real(dp),
optional,
intent(in) :: upper
202 character(len = *),
optional,
intent(in) :: ncvarname
204 logical,
dimension(:, :),
allocatable :: mask1
205 integer(i4) :: ncells1
206 integer(i4) :: nrows2, ncols2
207 logical,
dimension(:, :),
allocatable :: mask2
209 real(dp),
dimension(:, :, :, :),
allocatable :: l2_data
211 real(dp),
dimension(:, :, :, :),
allocatable :: l1_data
213 real(dp),
dimension(:, :, :),
allocatable :: l1_data_packed
214 integer(i4) :: nmonths, nhours
216 real(dp) :: cellfactorhbym
220 ncells1 = level1(idomain)%nCells
221 mask1 = level1(idomain)%mask
224 nrows2 = level2(idomain)%nrows
225 ncols2 = level2(idomain)%ncols
226 mask2 = level2(idomain)%mask
228 if (read_meteo_weights)
then
229 call message(
' read_meteo_weights = .TRUE. ... Reading meteo weights ... ')
230 CALL read_weights_nc(datapath, nrows2, ncols2, ncvarname, l2_data, mask2, lower=lower, upper=upper)
233 cellfactorhbym = level1(idomain)%cellsize / level2(idomain)%cellsize
236 if(cellfactorhbym .gt. 1.0_dp)
then
237 call spatial_aggregation(l2_data, level2(idomain)%cellsize, level1(idomain)%cellsize, mask1, mask2, l1_data)
239 elseif(cellfactorhbym .lt. 1.0_dp)
then
240 call spatial_disaggregation(l2_data, level2(idomain)%cellsize, level1(idomain)%cellsize, mask1, mask2, l1_data)
249 nmonths =
size(l1_data, dim = 3)
250 nhours =
size(l1_data, dim = 4)
251 allocate(l1_data_packed(ncells1, nmonths, nhours))
254 l1_data_packed(:, t, j) = pack(l1_data(:, :, t, j), mask = mask1(:, :))
261 allocate(l1_data_packed(ncells1, 12, 24))
266 call append(dataout1, l1_data_packed)
269 deallocate(l1_data_packed)
283 subroutine chunk_config(iDomain, tt, nTstepDay, simPer, timestep, timeStep_model_inputs, read_flag, readPer)
291 integer(i4),
intent(in) :: idomain
293 integer(i4),
intent(in) :: tt
295 integer(i4),
intent(in) :: ntstepday
297 type(
period),
dimension(:),
intent(in) :: simper
299 integer(i4),
intent(in) :: timestep
301 integer(i4),
dimension(:),
intent(in) :: timestep_model_inputs
303 logical,
intent(out) :: read_flag
305 type(
period),
intent(out) :: readper
309 if (tt .eq. 1_i4)
then
322 read_flag =
is_read(idomain, tt, ntstepday, simper, timestep, timestep_model_inputs)
325 if (read_flag)
call chunk_size(idomain, tt, ntstepday, simper, timestep_model_inputs, readper)
339 function is_read(iDomain, tt, nTstepDay, simPer, timestep, timeStep_model_inputs)
342 use mo_julian,
only : caldat
347 integer(i4),
intent(in) :: idomain
349 integer(i4),
intent(in) :: tt
351 integer(i4),
intent(in) :: ntstepday
353 type(
period),
dimension(:),
intent(in) :: simper
355 integer(i4),
intent(in) :: timestep
357 integer(i4),
dimension(:),
intent(in) :: timestep_model_inputs
370 integer(i4) :: ndays_before
372 integer(i4) :: day_before
374 integer(i4) :: month_before
376 integer(i4) :: year_before
382 if (tt .eq. 1_i4)
then
387 ndays = ceiling((real(tt, dp)) / real(ntstepday, dp))
388 ndays_before = ceiling((real(tt, dp) - 1.0_dp) / real(ntstepday, dp))
391 select case(timestep_model_inputs(idomain))
393 if (tt .eq. 1_i4)
is_read = .true.
395 if (mod((tt - 1) * timestep, timestep_model_inputs(idomain) * 24) .eq. 0_i4)
is_read = .true.
397 if (ndays .ne. ndays_before)
is_read = .true.
399 if (ndays .ne. ndays_before)
then
401 call caldat(simper(idomain)%julStart + ndays - 1, dd = day, mm = month, yy = year)
402 call caldat(simper(idomain)%julStart + ndays_before - 1, dd = day_before, mm = month_before, yy = year_before)
403 if (month .ne. month_before)
is_read = .true.
406 if (ndays .ne. ndays_before)
then
408 call caldat(simper(idomain)%julStart + ndays - 1, dd = day, mm = month, yy = year)
409 call caldat(simper(idomain)%julStart + ndays_before - 1, dd = day_before, mm = month_before, yy = year_before)
410 if (year .ne. year_before)
is_read = .true.
413 call error_message(
'ERROR*** mo_meteo_helper: function is_read: timStep_model_inputs not specified correctly!')
431 subroutine chunk_size(iDomain, tt, nTstepDay, simPer, timeStep_model_inputs, readPer)
434 use mo_julian,
only : caldat, julday
439 integer(i4),
intent(in) :: iDomain
441 integer(i4),
intent(in) :: tt
443 integer(i4),
intent(in) :: nTstepDay
445 type(
period),
dimension(:),
intent(in) :: simPer
447 integer(i4),
dimension(:),
intent(in) :: timeStep_model_inputs
449 type(
period),
intent(out) :: readPer
461 ndays = ceiling(real(tt, dp) / real(ntstepday, dp))
464 readper%julStart = simper(idomain)%julStart + ndays - 1
467 select case (timestep_model_inputs(idomain))
469 readper%julEnd = simper(idomain)%julEnd
471 readper%julEnd = readper%julStart + timestep_model_inputs(idomain) - 1
473 readper%julEnd = readper%julStart
476 call caldat(simper(idomain)%julStart + ndays, dd = day, mm = month, yy = year)
478 if (month .eq. 12)
then
484 readper%julEnd = julday(dd = 1, mm = month, yy = year) - 1
487 call caldat(simper(idomain)%julStart + ndays, dd = day, mm = month, yy = year)
488 readper%julEnd = julday(dd = 31, mm = 12, yy = year)
490 call error_message(
'ERROR*** mo_meteo_helper: chunk_size: timStep_model_inputs not specified correctly!')
494 readper%julEnd = min(readper%julEnd, simper(idomain)%julEnd)
497 call caldat(readper%julStart, dd = readper%dstart, mm = readper%mstart, yy = readper%ystart)
498 call caldat(readper%julEnd, dd = readper%dEnd, mm = readper%mend, yy = readper%yend)
499 readper%Nobs = readper%julEnd - readper%julstart + 1
Provides constants commonly used by mHM, mRM and MPR.
real(dp), parameter, public nodata_dp
Provides common types needed by mHM, mRM and/or mpr.
Prepare meteorological forcings data for mHM.
subroutine, public chunk_config(idomain, tt, ntstepday, simper, timestep, timestep_model_inputs, read_flag, readper)
determines the start date, end date, and read_flag given Domain id and current timestep
logical function is_read(idomain, tt, ntstepday, simper, timestep, timestep_model_inputs)
evaluate whether new chunk should be read at this timestep
subroutine chunk_size(idomain, tt, ntstepday, simper, timestep_model_inputs, readper)
calculate beginning and end of read Period, i.e.
subroutine, public meteo_weights_wrapper(idomain, read_meteo_weights, datapath, dataout1, level1, level2, lower, upper, ncvarname)
Prepare weights for meteorological forcings data for mHM at Level-1.
subroutine, public meteo_forcings_wrapper(idomain, datapath, inputformat, dataout1, readper, ntstepforcingday, level1, level2, lower, upper, ncvarname, bound_error)
Prepare meteorological forcings data for mHM at Level-1.
Reads forcing input data.
subroutine, public read_weights_nc(folder, nrows, ncols, varname, data, mask, lower, upper, nocheck, maskout, filename, bound_error)
Reads weights for meteo forcings input in NetCDF file format.
subroutine, public read_nc(folder, nrows, ncols, varname, mask, data, target_period, lower, upper, nctimestep, filename, nocheck, maskout, is_meteo, bound_error, ntstepforcingday)
Reads forcing input in NetCDF file format.