5.13.3-dev0
mHM
The mesoscale Hydrological Model
Loading...
Searching...
No Matches
mo_meteo_handler.f90
Go to the documentation of this file.
1!> \dir meteo
2!> \brief \copybrief f_meteo
3!> \details \copydetails f_meteo
4
5!> \defgroup f_meteo Meteo - Fortran modules
6!> \brief Core modules to deal with meteorological forcings.
7!> \details These modules provide the meteo handler, the spatial and temporal remapping algorithms and helper routines.
8
9!> \file mo_meteo_handler.f90
10!> \brief \copybrief mo_meteo_handler
11!> \details \copydetails mo_meteo_handler
12
13!> \brief Class for the meteo handler
14!> \details Handler for meteorological forcings in mHM.
15!! Is independent of global variables and provides 3 methods to access forcings:
16!! - get_corrected_pet : get the modified pet for mHM for the current timestep
17!! - get_temp : get the temporal disaggregated temperature for the current timestep
18!! - get_prec : get the temporal disaggregated percipitation for the current timestep
19!!
20!> \version 0.1
21!> \authors Sebastian Mueller
22!> \date Mar 2023
23!> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
24!! mHM is released under the LGPLv3+ license \license_note
25!> \ingroup f_meteo
27
28 USE mo_kind, ONLY : i4, dp
29 USE mo_constants, ONLY : yearmonths
30 use mo_common_types, only: grid, period
31 use mo_message, only : message, error_message
33 use mo_sentinel, only : set_sentinel, check_sentinel
34 use mo_datetime, only : datetime, timedelta, zero_delta, one_hour, one_day
35
36 implicit none
37
38 private
39
40 !> \class meteo_handler_type
41 !> \brief This is a handler for the meteorological forcings
42 !> \details This class provides all procedures to handle meteorological forcings from file or interfaces.
43 type, public :: meteo_handler_type
44 ! config settings
45 character(256) :: dir_nml_name = 'directories_mHM' !< namelist name in mhm namelist
46 character(256) :: weight_nml_name = 'nightDayRatio' !< namelist name in mhm namelist
47 !> Input nCols and nRows of binary meteo and LAI files are in header file
48 CHARACTER(256) :: file_meteo_header = 'header.txt'
49 !> Unit for meteo header file
50 INTEGER :: umeteo_header = 50
51 !> .FALSE. to only warn about bound (lower, upper) violations in meteo files, default = .TRUE. - raise an error
52 logical :: bound_error
53 integer(i4) :: pet_case !< process case for PET (processCase(5))
54 integer(i4) :: riv_temp_case !< process case for river temperature (processCase(11))
55 type(period), public :: readper !< start and end dates of read period
56 integer(i4), public :: ntstepforcingday !< Number of forcing intervals per day
57 !> flag wether forcings are given at hourly timestep
58 logical, public :: is_hourly_forcing
59 integer(i4), public :: timestep !< [h] simulation time step (= TS) in [h]
60 integer(i4), public :: ntstepday !< Number of time intervals per day
61 real(dp), public :: ntstepday_dp !< Number of time intervals per day as real
62 ! -------------------------------------------------------------------
63 ! level 2 description
64 ! -------------------------------------------------------------------
65 type(grid), dimension(:), allocatable, public :: level2 !< Reference of the metereological variables
66 ! -------------------------------------------------------------------
67 ! INPUT variables for configuration of mHM
68 ! -------------------------------------------------------------------
69 integer(i4), dimension(:), allocatable, public :: timestep_model_inputs !< frequency for reading meteo input
70 logical, public :: read_meteo_weights !< read weights for tavg and pet
71 character(256), public :: inputformat_meteo_forcings !< format of meteo input data (nc)
72 ! ------------------------------------------------------------------
73 ! DIRECTORIES
74 ! ------------------------------------------------------------------
75 ! has the dimension of nDomains
76 character(256), dimension(:), allocatable, public :: dir_meteo_header !< Directory where the meteo header file is located
77 character(256), dimension(:), allocatable, public :: dirprecipitation !< Directory where precipitation files are located
78 character(256), dimension(:), allocatable, public :: dirtemperature !< Directory where temperature files are located
79 character(256), dimension(:), allocatable, public :: dirmintemperature !< Directory where minimum temp. files are located
80 character(256), dimension(:), allocatable, public :: dirmaxtemperature !< Directory where maximum temp. files are located
81 character(256), dimension(:), allocatable, public :: dirnetradiation !< Directory where abs. vap. pressure files are located
82 character(256), dimension(:), allocatable, public :: dirabsvappressure !< Directory where abs. vap. pressure files are located
83 character(256), dimension(:), allocatable, public :: dirwindspeed !< Directory where windspeed files are located
84 character(256), dimension(:), allocatable, public :: dirreferenceet !< Directory where reference-ET files are located
85 ! riv-temp releated
86 character(256), dimension(:), allocatable, public :: dirradiation !< Directory where short/long-wave rad. files are located
87 ! -------------------------------------------------------------------
88 ! L1 DOMAIN description
89 ! -------------------------------------------------------------------
90 ! Forcings
91 ! dim1 = number grid cells L1
92 ! dim2 = number of meteorological time steps
93 ! dim2 = month of year
94 real(dp), public, dimension(:, :, :), allocatable :: l1_temp_weights !< hourly temperature weights for daily values
95 real(dp), public, dimension(:, :, :), allocatable :: l1_pet_weights !< hourly pet weights for daily values
96 real(dp), public, dimension(:, :, :), allocatable :: l1_pre_weights !< hourly pre weights for daily values
97 real(dp), public, dimension(:, :), allocatable :: l1_pre !< [mm] Precipitation
98 real(dp), public, dimension(:, :), allocatable :: l1_temp !< [degC] Air temperature
99 real(dp), public, dimension(:, :), allocatable :: l1_pet !< [mm TS-1] Potential evapotranspiration
100 real(dp), public, dimension(:, :), allocatable :: l1_tmin !< [degC] minimum daily air temperature
101 real(dp), public, dimension(:, :), allocatable :: l1_tmax !< [degC] maximum daily air temperature
102 real(dp), public, dimension(:, :), allocatable :: l1_netrad !< [W m2] net radiation
103 real(dp), public, dimension(:, :), allocatable :: l1_absvappress !< [Pa] absolute vapour pressure
104 real(dp), public, dimension(:, :), allocatable :: l1_windspeed !< [m s-1] windspeed
105 ! riv-temp related
106 real(dp), public, dimension(:, :), allocatable :: l1_ssrd !< [W m2] short wave radiation
107 real(dp), public, dimension(:, :), allocatable :: l1_strd !< [W m2] long wave radiation
108 real(dp), public, dimension(:, :), allocatable :: l1_tann !< [degC] annual mean air temperature
109 ! -------------------------------------------------------------------
110 ! Monthly day/night variation of Meteorological variables
111 ! for temporal disaggregation
112 ! -------------------------------------------------------------------
113 ! dim1 = number of months in a year
114 real(dp), public, dimension(int(YearMonths, i4)) :: fday_prec !< [-] Day ratio precipitation < 1
115 real(dp), public, dimension(int(YearMonths, i4)) :: fnight_prec !< [-] Night ratio precipitation < 1
116 real(dp), public, dimension(int(YearMonths, i4)) :: fday_pet !< [-] Day ratio PET < 1
117 real(dp), public, dimension(int(YearMonths, i4)) :: fnight_pet !< [-] Night ratio PET < 1
118 real(dp), public, dimension(int(YearMonths, i4)) :: fday_temp !< [-] Day factor mean temp
119 real(dp), public, dimension(int(YearMonths, i4)) :: fnight_temp !< [-] Night factor mean temp
120 real(dp), public, dimension(int(YearMonths, i4)) :: fday_ssrd !< [-] Day factor short-wave rad.
121 real(dp), public, dimension(int(YearMonths, i4)) :: fnight_ssrd !< [-] Night factor short-wave rad.
122 real(dp), public, dimension(int(YearMonths, i4)) :: fday_strd !< [-] Day factor long-wave rad.
123 real(dp), public, dimension(int(YearMonths, i4)) :: fnight_strd !< [-] Night factor long-wave rad.
124
125 ! -------------------------------------------------------------------
126 ! current mHM array indizes
127 ! -------------------------------------------------------------------
128 !> start index of meteo variables
129 integer(i4) :: s_meteo
130 !> end index of meteo variables
131 integer(i4) :: e_meteo
132 !> index of meteo time-step
133 integer(i4) :: imeteots
134 !> start index of level-1 variables
135 integer(i4) :: s1
136 !> end index of level-1 variables
137 integer(i4) :: e1
138 !> number of domains
139 integer(i4) :: ndomains
140 integer(i4), dimension(:), allocatable :: indices !< indices
141 integer(i4), dimension(:), allocatable :: l0datafrom !< index of associated level-0 domain
142 !> current julian time
143 real(dp) :: time
144
145 ! -------------------------------------------------------------------
146 ! coupling settings
147 ! -------------------------------------------------------------------
148 type(couple_cfg_type), public :: couple_cfg !< coupling configuration class
149 type(timedelta) :: couple_step_delta !< timedelta for the coupling meteo time-step
150 type(datetime) :: couple_pre_time !< current time from coupling for pre
151 type(datetime) :: couple_temp_time !< current time from coupling for temp
152 type(datetime) :: couple_pet_time !< current time from coupling for pet
153 type(datetime) :: couple_tmin_time !< current time from coupling for tmin
154 type(datetime) :: couple_tmax_time !< current time from coupling for tmax
155 type(datetime) :: couple_netrad_time !< current time from coupling for netrad
156 type(datetime) :: couple_absvappress_time !< current time from coupling for absvappress
157 type(datetime) :: couple_windspeed_time !< current time from coupling for windspeed
158 type(datetime) :: couple_ssrd_time !< current time from coupling for ssrd
159 type(datetime) :: couple_strd_time !< current time from coupling for strd
160 type(datetime) :: couple_tann_time !< current time from coupling for tann
161 logical, public :: couple_pre !< coupling config for pre
162 logical, public :: couple_temp !< coupling config for temp
163 logical, public :: couple_pet !< coupling config for pet
164 logical, public :: couple_tmin !< coupling config for tmin
165 logical, public :: couple_tmax !< coupling config for tmax
166 logical, public :: couple_netrad !< coupling config for netrad
167 logical, public :: couple_absvappress !< coupling config for absvappress
168 logical, public :: couple_windspeed !< coupling config for windspeed
169 logical, public :: couple_ssrd !< coupling config for ssrd
170 logical, public :: couple_strd !< coupling config for strd
171 logical, public :: couple_tann !< coupling config for tann
172 logical, public :: couple_all !< flag to indicated that all meteo-data is coming from the coupler
173 logical, public :: couple_is_hourly !< flag to indicated hourly data from coupler
174 contains
175 !> \copydoc mo_meteo_handler::clean_up
176 procedure :: clean_up !< \see mo_meteo_handler::clean_up
177 !> \copydoc mo_meteo_handler::config
178 procedure :: config !< \see mo_meteo_handler::config
179 !> \copydoc mo_meteo_handler::single_read
180 procedure :: single_read !< \see mo_meteo_handler::single_read
181 !> \copydoc mo_meteo_handler::init_level2
182 procedure :: init_level2 !< \see mo_meteo_handler::init_level2
183 !> \copydoc mo_meteo_handler::prepare_data
184 procedure :: prepare_data !< \see mo_meteo_handler::prepare_data
185 !> \copydoc mo_meteo_handler::update_timestep
186 procedure :: update_timestep !< \see mo_meteo_handler::update_timestep
187 !> \copydoc mo_meteo_handler::get_corrected_pet
188 procedure :: get_corrected_pet !< \see mo_meteo_handler::get_corrected_pet
189 !> \copydoc mo_meteo_handler::get_temp
190 procedure :: get_temp !< \see mo_meteo_handler::get_temp
191 !> \copydoc mo_meteo_handler::get_prec
192 procedure :: get_prec !< \see mo_meteo_handler::get_prec
193 !> \copydoc mo_meteo_handler::get_ssrd
194 procedure :: get_ssrd !< \see mo_meteo_handler::get_ssrd
195 !> \copydoc mo_meteo_handler::get_strd
196 procedure :: get_strd !< \see mo_meteo_handler::get_strd
197 !> \copydoc mo_meteo_handler::get_tann
198 procedure :: get_tann !< \see mo_meteo_handler::get_tann
199 !> \copydoc mo_meteo_handler::set_meteo
200 procedure :: set_meteo !< \see mo_meteo_handler::set_meteo
201 end type meteo_handler_type
202
203contains
204
205 !> \brief clean up
206 subroutine clean_up(self)
207 implicit none
208
209 class(meteo_handler_type), intent(inout) :: self
210
211 if ( allocated(self%indices) ) deallocate(self%indices)
212 if ( allocated(self%L0DataFrom) ) deallocate(self%L0DataFrom)
213 if ( allocated(self%timeStep_model_inputs) ) deallocate(self%timeStep_model_inputs)
214 if ( allocated(self%dir_meteo_header) ) deallocate(self%dir_meteo_header)
215 if ( allocated(self%dirPrecipitation) ) deallocate(self%dirPrecipitation)
216 if ( allocated(self%dirTemperature) ) deallocate(self%dirTemperature)
217 if ( allocated(self%dirMinTemperature) ) deallocate(self%dirMinTemperature)
218 if ( allocated(self%dirMaxTemperature) ) deallocate(self%dirMaxTemperature)
219 if ( allocated(self%dirNetRadiation) ) deallocate(self%dirNetRadiation)
220 if ( allocated(self%dirabsVapPressure) ) deallocate(self%dirabsVapPressure)
221 if ( allocated(self%dirwindspeed) ) deallocate(self%dirwindspeed)
222 if ( allocated(self%dirReferenceET) ) deallocate(self%dirReferenceET)
223 if ( allocated(self%dirRadiation) ) deallocate(self%dirRadiation)
224 if ( allocated(self%level2) ) deallocate(self%level2)
225 if ( allocated(self%L1_temp_weights) ) deallocate(self%L1_temp_weights)
226 if ( allocated(self%L1_pet_weights) ) deallocate(self%L1_pet_weights)
227 if ( allocated(self%L1_pre_weights) ) deallocate(self%L1_pre_weights)
228 if ( allocated(self%L1_pre) ) deallocate(self%L1_pre)
229 if ( allocated(self%L1_temp) ) deallocate(self%L1_temp)
230 if ( allocated(self%L1_pet) ) deallocate(self%L1_pet)
231 if ( allocated(self%L1_tmin) ) deallocate(self%L1_tmin)
232 if ( allocated(self%L1_tmax) ) deallocate(self%L1_tmax)
233 if ( allocated(self%L1_netrad) ) deallocate(self%L1_netrad)
234 if ( allocated(self%L1_absvappress) ) deallocate(self%L1_absvappress)
235 if ( allocated(self%L1_windspeed) ) deallocate(self%L1_windspeed)
236 if ( allocated(self%L1_ssrd) ) deallocate(self%L1_ssrd)
237 if ( allocated(self%L1_strd) ) deallocate(self%L1_strd)
238 if ( allocated(self%L1_tann) ) deallocate(self%L1_tann)
239
240 end subroutine clean_up
241
242 !> \brief configure the \ref meteo_handler_type class from the mhm namelist
243 subroutine config(self, file_namelist, optimize, domainMeta, processMatrix, timeStep, couple_cfg)
244
246 use mo_common_types, only : domain_meta
249
250 implicit none
251
252 class(meteo_handler_type), intent(inout) :: self
253 character(*), intent(in) :: file_namelist !< mhm namelist file
254 logical, intent(in) :: optimize !< Optimization flag
255 type(domain_meta), intent(in) :: domainMeta !< domain general description
256 integer(i4), dimension(nProcesses, 3), intent(in) :: processMatrix !< Info about which process runs in which option
257 integer(i4), intent(in) :: timeStep !< [h] simulation time step (= TS) in [h]
258 type(couple_cfg_type), intent(in) :: couple_cfg !< coupling configuration class
259
260 integer(i4), dimension(maxNoDomains) :: time_step_model_inputs
261 character(256), dimension(maxNoDomains) :: dir_meteo_header
262 character(256), dimension(maxNoDomains) :: dir_Precipitation
263 character(256), dimension(maxNoDomains) :: dir_Temperature
264 character(256), dimension(maxNoDomains) :: dir_MinTemperature
265 character(256), dimension(maxNoDomains) :: dir_MaxTemperature
266 character(256), dimension(maxNoDomains) :: dir_NetRadiation
267 character(256), dimension(maxNoDomains) :: dir_windspeed
268 character(256), dimension(maxNoDomains) :: dir_absVapPressure
269 character(256), dimension(maxNoDomains) :: dir_ReferenceET
270 character(256), dimension(maxNoDomains) :: dir_Radiation ! riv-temp related
271
272 integer(i4) :: domainID, iDomain
273
274 ! store coupling config
275 self%couple_cfg = couple_cfg
276
277 ! store needed domain meta infos
278 self%nDomains = domainmeta%nDomains
279 allocate(self%indices(self%nDomains))
280 allocate(self%L0DataFrom(self%nDomains))
281 self%indices(:) = domainmeta%indices(:)
282 self%L0DataFrom(:) = domainmeta%L0DataFrom(:)
283
284 ! # init of number of forcing timesteps, will be set when reading forcings
285 self%nTStepForcingDay = nodata_i4
286
287 ! store important process cases
288 self%pet_case = processmatrix(5,1)
289 self%riv_temp_case = processmatrix(11,1)
290 ! store time-stepping info
291 self%timeStep = timestep
292 self%nTStepDay = 24_i4 / timestep ! # of time steps per day
293 self%nTstepDay_dp = real(self%nTStepDay, dp)
294
295 ! allocate variables
296 allocate(self%dir_meteo_header(self%nDomains))
297 allocate(self%dirPrecipitation(self%nDomains))
298 allocate(self%dirTemperature(self%nDomains))
299 allocate(self%dirwindspeed(self%nDomains))
300 allocate(self%dirabsVapPressure(self%nDomains))
301 allocate(self%dirReferenceET(self%nDomains))
302 allocate(self%dirMinTemperature(self%nDomains))
303 allocate(self%dirMaxTemperature(self%nDomains))
304 allocate(self%dirNetRadiation(self%nDomains))
305 allocate(self%dirRadiation(self%nDomains))
306 ! allocate time periods
307 allocate(self%timestep_model_inputs(self%nDomains))
308
309 !===============================================================
310 ! Read namelist main directories
311 !===============================================================
312
313 call nml_directories_mhm%read(file_namelist)
314 self%bound_error = nml_directories_mhm%bound_error
315 self%inputFormat_meteo_forcings = nml_directories_mhm%inputFormat_meteo_forcings
316 dir_meteo_header = nml_directories_mhm%dir_meteo_header
317 dir_precipitation = nml_directories_mhm%dir_Precipitation
318 dir_temperature = nml_directories_mhm%dir_Temperature
319 dir_referenceet = nml_directories_mhm%dir_ReferenceET
320 dir_mintemperature = nml_directories_mhm%dir_MinTemperature
321 dir_maxtemperature = nml_directories_mhm%dir_MaxTemperature
322 dir_absvappressure = nml_directories_mhm%dir_absVapPressure
323 dir_windspeed = nml_directories_mhm%dir_windspeed
324 dir_netradiation = nml_directories_mhm%dir_NetRadiation
325 dir_radiation = nml_directories_mhm%dir_Radiation
326 time_step_model_inputs = nml_directories_mhm%time_step_model_inputs
327
328 do idomain = 1, self%nDomains
329 domainid = self%indices(idomain)
330 self%timestep_model_inputs(idomain) = time_step_model_inputs(domainid)
331 self%dirPrecipitation(idomain) = dir_precipitation(domainid)
332 self%dirTemperature(idomain) = dir_temperature(domainid)
333 self%dirReferenceET(idomain) = dir_referenceet(domainid)
334 self%dirMinTemperature(idomain) = dir_mintemperature(domainid)
335 self%dirMaxTemperature(idomain) = dir_maxtemperature(domainid)
336 self%dirNetRadiation(idomain) = dir_netradiation(domainid)
337 self%dirwindspeed(idomain) = dir_windspeed(domainid)
338 self%dirabsVapPressure(idomain) = dir_absvappressure(domainid)
339 ! riv-temp related
340 self%dirRadiation(idomain) = dir_radiation(domainid)
341 ! meteo header directory (if not given, use precipitation dir)
342 if (check_sentinel(dir_meteo_header(domainid))) then
343 self%dir_meteo_header(idomain) = self%dirPrecipitation(idomain)
344 else
345 self%dir_meteo_header(idomain) = dir_meteo_header(domainid)
346 end if
347 end do
348
349 ! consistency check for timestep_model_inputs
350 if (any(self%timestep_model_inputs .ne. 0) .and. .not. all(self%timestep_model_inputs .ne. 0)) then
351 call error_message('***ERROR: timestep_model_inputs either have to be all zero or all non-zero')
352 end if
353 ! check for optimzation and timestep_model_inputs options
354 if (optimize .and. (any(self%timestep_model_inputs .ne. 0))) then
355 call error_message('***ERROR: optimize and chunk read is switched on! (set timestep_model_inputs to zero)')
356 end if
357
358 !===============================================================
359 ! Read night-day ratios and pan evaporation
360 !===============================================================
361
362 call nml_nightdayratio%read(file_namelist)
363 self%read_meteo_weights = nml_nightdayratio%read_meteo_weights
364 self%fnight_prec = nml_nightdayratio%fnight_prec
365 self%fnight_pet = nml_nightdayratio%fnight_pet
366 self%fnight_temp = nml_nightdayratio%fnight_temp
367 self%fnight_ssrd = nml_nightdayratio%fnight_ssrd
368 self%fnight_strd = nml_nightdayratio%fnight_strd
369 self%fday_prec = 1.0_dp - self%fnight_prec
370 self%fday_pet = 1.0_dp - self%fnight_pet
371 self%fday_temp = -1.0_dp * self%fnight_temp
372 self%fday_ssrd = 1.0_dp - self%fnight_ssrd
373 self%fday_strd = 1.0_dp - self%fnight_strd
374
375 ! TODO-RIV-TEMP: add short- and long-wave raidiation weights (nc files)
376
377 ! check coupling configuration matching process cases
378 self%couple_is_hourly = .false.
379 self%couple_all = .false.
380 self%couple_pre = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_pre
381 self%couple_temp = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_temp
382 self%couple_pet = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_pet
383 self%couple_tmin = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_tmin
384 self%couple_tmax = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_tmax
385 self%couple_netrad = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_netrad
386 self%couple_absvappress = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_absvappress
387 self%couple_windspeed = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_windspeed
388 self%couple_ssrd = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_ssrd
389 self%couple_strd = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_strd
390 self%couple_tann = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_tann
391 if (self%couple_cfg%active()) then
392 self%couple_step_delta = timedelta(hours=self%couple_cfg%meteo_timestep)
393 self%couple_is_hourly = self%couple_step_delta == one_hour()
394 ! default init values for coupling times: 0001-01-01
395 if (self%couple_cfg%meteo_expect_pre) self%couple_pre_time = datetime()
396 if (self%couple_cfg%meteo_expect_temp) self%couple_temp_time = datetime()
397 ! PET releated
398 if (self%couple_cfg%meteo_expect_pet) self%couple_pet_time = datetime()
399 if (self%couple_cfg%meteo_expect_tmin) self%couple_tmin_time = datetime()
400 if (self%couple_cfg%meteo_expect_tmax) self%couple_tmax_time = datetime()
401 if (self%couple_cfg%meteo_expect_netrad) self%couple_netrad_time = datetime()
402 if (self%couple_cfg%meteo_expect_absvappress) self%couple_absvappress_time = datetime()
403 if (self%couple_cfg%meteo_expect_windspeed) self%couple_windspeed_time = datetime()
404 ! RIV-TEMP releated
405 if (self%couple_cfg%meteo_expect_ssrd) self%couple_ssrd_time = datetime()
406 if (self%couple_cfg%meteo_expect_strd) self%couple_strd_time = datetime()
407 if (self%couple_cfg%meteo_expect_tann) self%couple_tann_time = datetime()
408 ! PET related meteo
409 self%couple_all = self%couple_cfg%meteo_expect_pre .and. self%couple_cfg%meteo_expect_temp
410 select case (self%pet_case)
411 case(-1 : 0) ! pet is input
412 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_pet
413 if (self%couple_cfg%meteo_expect_tmin) call error_message("Coupling: tmin expected but not needed for PET.")
414 if (self%couple_cfg%meteo_expect_tmax) call error_message("Coupling: tmax expected but not needed for PET.")
415 if (self%couple_cfg%meteo_expect_netrad) call error_message("Coupling: netrad expected but not needed for PET.")
416 if (self%couple_cfg%meteo_expect_absvappress) call error_message("Coupling: absvappress expected but not needed for PET.")
417 if (self%couple_cfg%meteo_expect_windspeed) call error_message("Coupling: windspeed expected but not needed for PET.")
418
419 case(1) ! Hargreaves-Samani formulation (input: minimum and maximum Temperature)
420 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_tmin
421 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_tmax
422 if (self%couple_cfg%meteo_expect_pet) call error_message("Coupling: pet expected but not needed for PET.")
423 if (self%couple_cfg%meteo_expect_netrad) call error_message("Coupling: netrad expected but not needed for PET.")
424 if (self%couple_cfg%meteo_expect_absvappress) call error_message("Coupling: absvappress expected but not needed for PET.")
425 if (self%couple_cfg%meteo_expect_windspeed) call error_message("Coupling: windspeed expected but not needed for PET.")
426
427 case(2) ! Priestley-Taylor formulation (input: net radiation)
428 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_netrad
429 if (self%couple_cfg%meteo_expect_pet) call error_message("Coupling: pet expected but not needed for PET.")
430 if (self%couple_cfg%meteo_expect_tmin) call error_message("Coupling: tmin expected but not needed for PET.")
431 if (self%couple_cfg%meteo_expect_tmax) call error_message("Coupling: tmax expected but not needed for PET.")
432 if (self%couple_cfg%meteo_expect_absvappress) call error_message("Coupling: absvappress expected but not needed for PET.")
433 if (self%couple_cfg%meteo_expect_windspeed) call error_message("Coupling: windspeed expected but not needed for PET.")
434
435 case(3) ! Penman-Monteith formulation (input: net radiationm absulute vapour pressure, windspeed)
436 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_netrad
437 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_absvappress
438 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_windspeed
439 if (self%couple_cfg%meteo_expect_pet) call error_message("Coupling: pet expected but not needed for PET.")
440 if (self%couple_cfg%meteo_expect_tmin) call error_message("Coupling: tmin expected but not needed for PET.")
441 if (self%couple_cfg%meteo_expect_tmax) call error_message("Coupling: tmax expected but not needed for PET.")
442 end select
443 ! river temperature related meteo
444 if ( self%riv_temp_case == 0 ) then
445 if (self%couple_cfg%meteo_expect_ssrd) call error_message("Coupling: ssrd expected but river temperature not activated.")
446 if (self%couple_cfg%meteo_expect_strd) call error_message("Coupling: strd expected but river temperature not activated.")
447 if (self%couple_cfg%meteo_expect_tann) call error_message("Coupling: tann expected but river temperature not activated.")
448 else
449 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_ssrd
450 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_strd
451 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_tann
452 end if
453 end if
454 end subroutine config
455
456 !> \brief whether meteo data should be read completely at the begining
457 !> \return True if meteo data is retrieved with a single read
458 logical function single_read(self, iDomain)
459 implicit none
460 class(meteo_handler_type), intent(in) :: self
461 integer(i4), intent(in) :: idomain !< current domain
462 single_read = self%timeStep_model_inputs(idomain) == 0_i4
463 end function single_read
464
465 !> \brief Initialize meteo data and level-2 grid
466 subroutine init_level2(self, level0, level1)
467
469 use mo_common_types, only : grid
472 use mo_string_utils, only : num2str
473
474 implicit none
475
476 class(meteo_handler_type), intent(inout) :: self
477 !> grid information at level-0
478 type(grid), dimension(:), intent(in) :: level0
479 !> grid information at level-1 if all meteo data is coupled
480 type(grid), dimension(:), intent(in) :: level1
481
482 ! header info
483 integer(i4) :: nrows2, ncols2
484 real(dp) :: xllcorner2, yllcorner2
485 real(dp) :: cellsize2, nodata_dummy
486 ! file name
487 character(256) :: fName
488 ! looping variable
489 integer(i4) :: iDomain
490
491 ! create level-2 info
492 allocate(self%level2(self%nDomains))
493
494 ! we don't need level 2 if all meteo data comes from the coupler
495 if (self%couple_all) then
496 self%level2(:) = level1(:)
497 return
498 end if
499
500 do idomain = 1, self%nDomains
501 ! read header
502 fname = trim(adjustl(self%dir_meteo_header(idomain))) // trim(adjustl(self%file_meteo_header))
503 call read_header_ascii(trim(fname), self%umeteo_header, &
504 nrows2, ncols2, xllcorner2, yllcorner2, cellsize2, nodata_dummy)
505 ! check grid compatibility
506 call init_lowres_level(level0(self%L0DataFrom(idomain)), cellsize2, self%level2(idomain))
507 ! check
508 if ((ncols2 .ne. self%level2(idomain)%ncols) .or. &
509 (nrows2 .ne. self%level2(idomain)%nrows) .or. &
510 (abs(xllcorner2 - self%level2(idomain)%xllcorner) .gt. tiny(1.0_dp)) .or. &
511 (abs(yllcorner2 - self%level2(idomain)%yllcorner) .gt. tiny(1.0_dp)) .or. &
512 (abs(cellsize2 - self%level2(idomain)%cellsize) .gt. tiny(1.0_dp))) then
513 call error_message(' ***ERROR: subroutine L2_variable_init: size mismatch in grid file for level2 in domain ', &
514 trim(adjustl(num2str(idomain))), '!', raise=.false.)
515 call error_message(' Expected to have following properties (based on L0):', raise=.false.)
516 call error_message('... rows: ', trim(adjustl(num2str(self%level2(idomain)%nrows))), ', ', raise=.false.)
517 call error_message('... cols: ', trim(adjustl(num2str(self%level2(idomain)%ncols))), ', ', raise=.false.)
518 call error_message('... cellsize: ', trim(adjustl(num2str(self%level2(idomain)%cellsize))), ', ', raise=.false.)
519 call error_message('... xllcorner:', trim(adjustl(num2str(self%level2(idomain)%xllcorner))), ', ', raise=.false.)
520 call error_message('... yllcorner:', trim(adjustl(num2str(self%level2(idomain)%yllcorner))), ', ', raise=.false.)
521 call error_message(' Provided (in precipitation file):', raise=.false.)
522 call error_message('... rows: ', trim(adjustl(num2str(nrows2))), ', ', raise=.false.)
523 call error_message('... cols: ', trim(adjustl(num2str(ncols2))), ', ', raise=.false.)
524 call error_message('... cellsize: ', trim(adjustl(num2str(cellsize2))), ', ', raise=.false.)
525 call error_message('... xllcorner:', trim(adjustl(num2str(xllcorner2))), ', ', raise=.false.)
526 call error_message('... yllcorner:', trim(adjustl(num2str(yllcorner2))), ', ')
527 end if
528 end do
529
530 ! set indices
531 call set_domain_indices(self%level2)
532
533 end subroutine init_level2
534
535 !> \brief update the current time-step of the \ref meteo_handler_type class
536 subroutine update_timestep(self, tt, time, iDomain, level1, simPer)
537
538 implicit none
539
540 class(meteo_handler_type), intent(inout) :: self
541 integer(i4), intent(in) :: tt !< current time step
542 real(dp), intent(in) :: time !< current decimal Julian day
543 integer(i4), intent(in) :: iDomain !< current domain
544 !> grid information at hydrologic level
545 type(grid), dimension(:), intent(in) :: level1
546 !> warmPer + evalPer
547 type(period), dimension(:), intent(in) :: simPer
548
549 ! store current indizes and time
550 ! only needed for the "get_<var>" methods
551 self%s1 = level1(idomain)%iStart
552 self%e1 = level1(idomain)%iEnd
553 self%time = time
554
555 ! time increment is done right after call to mrm (and initially before looping)
556 if (self%single_read(idomain) .or. self%couple_all) then
557 ! whole meteorology is already read or all meteo is coupled
558
559 ! set start and end of meteo position
560 self%s_meteo = level1(idomain)%iStart
561 self%e_meteo = level1(idomain)%iEnd
562
563 ! time step for meteorological variable (daily values)
564 ! iMeteoTS = ceiling(real(tt, dp) / real(nTstepDay, dp))
565 if (self%couple_all) then
566 self%iMeteoTS = 1_i4
567 else
568 self%iMeteoTS = ceiling(real(tt, dp) / real(nint( 24._dp / real(self%nTstepForcingDay, dp)), dp))
569 end if
570 else
571 ! read chunk of meteorological forcings data (reading, upscaling/downscaling)
572 call self%prepare_data(tt, idomain, level1, simper)
573 ! set start and end of meteo position
574 self%s_meteo = 1
575 self%e_meteo = level1(idomain)%iEnd - level1(idomain)%iStart + 1
576 ! time step for meteorological variable (daily values)
577 self%iMeteoTS = ceiling(real(tt, dp) / real(nint( 24._dp / real(self%nTstepForcingDay, dp)), dp)) &
578 - (self%readPer%julStart - simper(idomain)%julStart)
579 end if
580
581 end subroutine update_timestep
582
583 !> \brief Prepare meteorological forcings data for a given variable
584 !> \details Prepare meteorological forcings data for a given variable.
585 !! Internally this subroutine calls another routine meteo_wrapper
586 !! for different meterological variables
587 !> \changelog
588 !! - Matthias Zink, Jun 2013
589 !! - addded NetCDf reader
590 !! - Rohini Kumar, Aug 2013
591 !! - name changed "inputFormat" to inputFormat_meteo_forcings
592 !! - Matthias Zink, Feb 2014
593 !! - added read in for different PET processes (process 5)
594 !! - Stephan Thober, Jun 2014
595 !! - add chunk_config for chunk read, copied L2 initialization to mo_startup
596 !! - Stephan Thober, Nov 2016
597 !! - moved processMatrix to common variables
598 !! - Stephan Thober, Jan 2017
599 !! - added subroutine for meteo_weights
600 !! - Robert Schweppe Jun 2018
601 !! - refactoring and reformatting
602 !! - Sebastian Müller Mar 2023
603 !! - converted routine to meteo-handler method
604 !> \authors Rohini Kumar
605 !> \date Jan 2013
606 subroutine prepare_data(self, tt, iDomain, level1, simPer)
607
608 use mo_string_utils, only : num2str
609 use mo_timer, only : timer_get, timer_start, timer_stop
611
612 implicit none
613
614 class(meteo_handler_type), intent(inout) :: self
615 integer(i4), intent(in) :: tt !< current timestep
616 integer(i4), intent(in) :: iDomain !< Domain number
617 !> grid information at hydrologic level
618 type(grid), dimension(:), intent(in) :: level1
619 !> warmPer + evalPer
620 type(period), dimension(:), intent(in) :: simPer
621
622 ! indicate whether data should be read
623 logical :: read_flag
624 integer(i4) :: domainID ! current domain ID
625
626 ! allocate arrays only once if they are coupled
627 if (self%couple_pre .and. .not. allocated(self%L1_pre)) allocate(self%L1_pre(level1(idomain)%nCells, 1))
628 if (self%couple_temp .and. .not. allocated(self%L1_temp)) allocate(self%L1_temp(level1(idomain)%nCells, 1))
629 if (self%couple_pet .and. .not. allocated(self%L1_pet)) allocate(self%L1_pet(level1(idomain)%nCells, 1))
630 if (self%couple_tmin .and. .not. allocated(self%L1_tmin)) allocate(self%L1_tmin(level1(idomain)%nCells, 1))
631 if (self%couple_tmax .and. .not. allocated(self%L1_tmax)) allocate(self%L1_tmax(level1(idomain)%nCells, 1))
632 if (self%couple_netrad .and. .not. allocated(self%L1_netrad)) allocate(self%L1_netrad(level1(idomain)%nCells, 1))
633 if (self%couple_absvappress .and. .not. allocated(self%L1_absvappress)) allocate(self%L1_absvappress(level1(idomain)%nCells, 1))
634 if (self%couple_windspeed .and. .not. allocated(self%L1_windspeed)) allocate(self%L1_windspeed(level1(idomain)%nCells, 1))
635 if (self%couple_ssrd .and. .not. allocated(self%L1_ssrd)) allocate(self%L1_ssrd(level1(idomain)%nCells, 1))
636 if (self%couple_strd .and. .not. allocated(self%L1_strd)) allocate(self%L1_strd(level1(idomain)%nCells, 1))
637 if (self%couple_tann .and. .not. allocated(self%L1_tann)) allocate(self%L1_tann(level1(idomain)%nCells, 1))
638
639 domainid = self%indices(idomain)
640
641 ! configuration of chunk_read
642 call chunk_config(idomain, tt, self%nTstepDay, simper, self%timestep, self%timeStep_model_inputs, read_flag, self%readPer)
643
644 ! only read, if read_flag is true
645 if (read_flag) then
646
647 ! read weights for hourly disaggregation
648 if (tt .eq. 1) then
649 ! TODO-RIV-TEMP: No NC files for weights for radiation at the moment
650 if (self%single_read(idomain)) call message(' read meteo weights for tavg ...')
651 call meteo_weights_wrapper(idomain, self%read_meteo_weights, self%dirTemperature(idomain), &
652 self%L1_temp_weights, level1=level1, level2=self%level2, ncvarname = 'tavg_weight')
653
654 if (self%single_read(idomain)) call message(' read meteo weights for pet ...')
655 call meteo_weights_wrapper(idomain, self%read_meteo_weights, self%dirReferenceET(idomain), &
656 self%L1_pet_weights, level1=level1, level2=self%level2, ncvarname = 'pet_weight')
657
658 if (self%single_read(idomain)) call message(' read meteo weights for pre ...')
659 call meteo_weights_wrapper(idomain, self%read_meteo_weights, self%dirPrecipitation(idomain), &
660 self%L1_pre_weights, level1=level1, level2=self%level2, ncvarname = 'pre_weight')
661 end if
662
663 ! free L1 variables if chunk read is activated
664 if (self%timeStep_model_inputs(idomain) .ne. 0) then
665 if (.not. self%couple_pre .and. allocated(self%L1_pre)) deallocate(self%L1_pre)
666 if (.not. self%couple_temp .and. allocated(self%L1_temp)) deallocate(self%L1_temp)
667 if (.not. self%couple_pet .and. allocated(self%L1_pet)) deallocate(self%L1_pet)
668 if (.not. self%couple_tmin .and. allocated(self%L1_tmin)) deallocate(self%L1_tmin)
669 if (.not. self%couple_tmax .and. allocated(self%L1_tmax)) deallocate(self%L1_tmax)
670 if (.not. self%couple_netrad .and. allocated(self%L1_netrad)) deallocate(self%L1_netrad)
671 if (.not. self%couple_absvappress .and. allocated(self%L1_absvappress)) deallocate(self%L1_absvappress)
672 if (.not. self%couple_windspeed .and. allocated(self%L1_windspeed)) deallocate(self%L1_windspeed)
673 end if
674
675 ! Domain characteristics and read meteo header
676 if (self%single_read(idomain)) then
677 call message(' Reading meteorological forcings for Domain: ', trim(adjustl(num2str(domainid))), ' ...')
678 call timer_start(1)
679 end if
680
681 ! precipitation
682 if (.not. self%couple_pre) then
683 if (self%single_read(idomain)) call message(' read precipitation ...')
684 ! upper bound: 1825 mm/d in La Réunion 7-8 Jan 1966
685 call meteo_forcings_wrapper(idomain, self%dirPrecipitation(idomain), self%inputFormat_meteo_forcings, &
686 dataout1=self%L1_pre, &
687 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
688 lower = 0.0_dp, upper = 2000._dp, ncvarname = 'pre', bound_error=self%bound_error)
689 end if
690
691 ! temperature
692 if (.not. self%couple_temp) then
693 if (self%single_read(idomain)) call message(' read temperature ...')
694 call meteo_forcings_wrapper(idomain, self%dirTemperature(idomain), self%inputFormat_meteo_forcings, &
695 dataout1=self%L1_temp, &
696 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
697 lower = -100._dp, upper = 100._dp, ncvarname = 'tavg', bound_error=self%bound_error)
698 end if
699
700 ! read input for PET (process 5) depending on specified option
701 ! 0 - input, 1 - Hargreaves-Samani, 2 - Priestley-Taylor, 3 - Penman-Monteith
702 select case (self%pet_case)
703 case(-1 : 0) ! pet is input
704 if (.not. self%couple_pet) then
705 if (self%single_read(idomain)) call message(' read pet ...')
706 call meteo_forcings_wrapper(idomain, self%dirReferenceET(idomain), self%inputFormat_meteo_forcings, &
707 dataout1=self%L1_pet, &
708 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
709 lower = 0.0_dp, upper = 1000._dp, ncvarname = 'pet', bound_error=self%bound_error)
710 end if
711 ! allocate PET and dummies for mhm_call
712 if ((idomain.eq.self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
713 allocate(self%L1_tmin(1, 1))
714 allocate(self%L1_tmax(1, 1))
715 allocate(self%L1_netrad(1, 1))
716 allocate(self%L1_absvappress(1, 1))
717 allocate(self%L1_windspeed(1, 1))
718 end if
719
720 case(1) ! Hargreaves-Samani formulation (input: minimum and maximum Temperature)
721 if (.not. self%couple_tmin) then
722 if (self%single_read(idomain)) call message(' read min. temperature ...')
723 call meteo_forcings_wrapper(idomain, self%dirMinTemperature(idomain), self%inputFormat_meteo_forcings, &
724 dataout1=self%L1_tmin, &
725 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
726 lower = -100.0_dp, upper = 100._dp, ncvarname = 'tmin', bound_error=self%bound_error)
727 end if
728 if (.not. self%couple_tmax) then
729 if (self%single_read(idomain)) call message(' read max. temperature ...')
730 call meteo_forcings_wrapper(idomain, self%dirMaxTemperature(idomain), self%inputFormat_meteo_forcings, &
731 dataout1=self%L1_tmax, &
732 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
733 lower = -100.0_dp, upper = 100._dp, ncvarname = 'tmax', bound_error=self%bound_error)
734 end if
735 ! allocate PET and dummies for mhm_call
736 if ((idomain .eq. self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
737 allocate(self%L1_pet (size(self%L1_tmax, dim = 1), size(self%L1_tmax, dim = 2)))
738 allocate(self%L1_netrad(1, 1))
739 allocate(self%L1_absvappress(1, 1))
740 allocate(self%L1_windspeed(1, 1))
741 end if
742
743 case(2) ! Priestley-Taylor formulation (input: net radiation)
744 if (.not. self%couple_netrad) then
745 if (self%single_read(idomain)) call message(' read net radiation ...')
746 call meteo_forcings_wrapper(idomain, self%dirNetRadiation(idomain), self%inputFormat_meteo_forcings, &
747 dataout1=self%L1_netrad, &
748 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
749 lower = -500.0_dp, upper = 1500._dp, ncvarname = 'net_rad', bound_error=self%bound_error)
750 end if
751 ! allocate PET and dummies for mhm_call
752 if ((idomain .eq. self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
753 allocate(self%L1_pet (size(self%L1_netrad, dim = 1), size(self%L1_netrad, dim = 2)))
754 allocate(self%L1_tmin(1, 1))
755 allocate(self%L1_tmax(1, 1))
756 allocate(self%L1_absvappress(1, 1))
757 allocate(self%L1_windspeed(1, 1))
758 end if
759
760 case(3) ! Penman-Monteith formulation (input: net radiationm absulute vapour pressure, windspeed)
761 if (.not. self%couple_netrad) then
762 if (self%single_read(idomain)) call message(' read net radiation ...')
763 call meteo_forcings_wrapper(idomain, self%dirNetRadiation(idomain), self%inputFormat_meteo_forcings, &
764 dataout1=self%L1_netrad, &
765 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
766 lower = -500.0_dp, upper = 1500._dp, ncvarname = 'net_rad', bound_error=self%bound_error)
767 end if
768 if (.not. self%couple_absvappress) then
769 if (self%single_read(idomain)) call message(' read absolute vapour pressure ...')
770 call meteo_forcings_wrapper(idomain, self%dirabsVapPressure(idomain), self%inputFormat_meteo_forcings, &
771 dataout1=self%L1_absvappress, &
772 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
773 lower = 0.0_dp, upper = 15000.0_dp, ncvarname = 'eabs', bound_error=self%bound_error)
774 end if
775 if (.not. self%couple_windspeed) then
776 if (self%single_read(idomain)) call message(' read windspeed ...')
777 call meteo_forcings_wrapper(idomain, self%dirwindspeed(idomain), self%inputFormat_meteo_forcings, &
778 dataout1=self%L1_windspeed, &
779 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
780 lower = 0.0_dp, upper = 250.0_dp, ncvarname = 'windspeed', bound_error=self%bound_error)
781 end if
782 ! allocate PET and dummies for mhm_call
783 if ((idomain.eq.self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
784 allocate(self%L1_pet (size(self%L1_absvappress, dim = 1), size(self%L1_absvappress, dim = 2)))
785 allocate(self%L1_tmin(1, 1))
786 allocate(self%L1_tmax(1, 1))
787 end if
788 end select
789
790 ! long/short-wave radiation and annual mean temperature for river-temperature routing
791 if ( self%riv_temp_case .ne. 0 ) then
792 ! free L1 variables if chunk read is activated
793 if (self%timeStep_model_inputs(idomain) .ne. 0) then
794 if (.not. self%couple_ssrd .and. allocated(self%L1_ssrd)) deallocate(self%L1_ssrd)
795 if (.not. self%couple_strd .and. allocated(self%L1_strd)) deallocate(self%L1_strd)
796 if (.not. self%couple_tann .and. allocated(self%L1_tann)) deallocate(self%L1_tann)
797 end if
798 if (.not. self%couple_ssrd) then
799 if (self%single_read(idomain)) call message(' read short-wave radiation ...')
801 idomain, self%dirRadiation(idomain), self%inputFormat_meteo_forcings, &
802 dataout1=self%L1_ssrd, &
803 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
804 lower = 0.0_dp, upper = 1500._dp, ncvarname = 'ssrd', bound_error=self%bound_error)
805 end if
806 if (.not. self%couple_strd) then
807 if (self%single_read(idomain)) call message(' read long-wave radiation ...')
809 idomain, self%dirRadiation(idomain), self%inputFormat_meteo_forcings, &
810 dataout1=self%L1_strd, &
811 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
812 lower = 0.0_dp, upper = 1500._dp, ncvarname = 'strd', bound_error=self%bound_error)
813 end if
814 if (.not. self%couple_tann) then
815 if (self%single_read(idomain)) call message(' read annual mean temperature ...')
817 idomain, self%dirTemperature(idomain), self%inputFormat_meteo_forcings, &
818 dataout1=self%L1_tann, &
819 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
820 lower = -100.0_dp, upper = 100._dp, ncvarname = 'tann', bound_error=self%bound_error)
821 end if
822 end if
823
824 if (self%single_read(idomain)) then
825 call timer_stop(1)
826 call message(' in ', trim(num2str(timer_get(1), '(F9.3)')), ' seconds.')
827 end if
828 end if
829
830 if (tt .eq. 1) then
831 ! set hourly flags (once at begining)
832 if (self%couple_all) then
833 self%nTstepForcingDay = int(one_day() / self%couple_step_delta, i4)
834 self%is_hourly_forcing = self%couple_is_hourly
835 else
836 self%is_hourly_forcing = (self%nTstepForcingDay .eq. 24_i4)
837 end if
838
839 ! check hourly data for PET (once at begining)
840 select case (self%pet_case)
841 case(1) ! Hargreaves-Samani formulation
842 if (self%couple_temp .and. self%couple_tmin .and. self%couple_tmax) then
843 if (self%couple_is_hourly) call error_message("Coupling: PET - Hargreaves-Samani needs daily data. Got hourly.")
844 else if (self%couple_temp .or. self%couple_tmin .or. self%couple_tmax) then
845 if (self%couple_is_hourly) call error_message("Coupling: PET - Hargreaves-Samani needs daily data. Got hourly.")
846 if (self%is_hourly_forcing) call error_message("Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
847 else
848 if (self%is_hourly_forcing) call error_message("Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
849 end if
850
851 case(2) ! Priestley-Taylor formulation
852 if (self%couple_temp .and. self%couple_netrad) then
853 if (self%couple_is_hourly) call error_message("Coupling: PET - Priestley-Taylor needs daily data. Got hourly.")
854 else if (self%couple_temp .or. self%couple_netrad) then
855 if (self%couple_is_hourly) call error_message("Coupling: PET - Priestley-Taylor needs daily data. Got hourly.")
856 if (self%is_hourly_forcing) call error_message("Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
857 else
858 if (self%is_hourly_forcing) call error_message("Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
859 end if
860
861 case(3) ! Penman-Monteith formulation
862 if (self%couple_temp .and. self%couple_netrad .and. self%couple_absvappress .and. self%couple_windspeed) then
863 if (self%couple_is_hourly) call error_message("Coupling: PET - Penman-Monteith needs daily data. Got hourly.")
864 else if (self%couple_temp .or. self%couple_netrad .or. self%couple_absvappress .or. self%couple_windspeed) then
865 if (self%couple_is_hourly) call error_message("Coupling: PET - Penman-Monteith needs daily data. Got hourly.")
866 if (self%is_hourly_forcing) call error_message("Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
867 else
868 if (self%is_hourly_forcing) call error_message("Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
869 end if
870 end select
871 end if
872
873 end subroutine prepare_data
874
875 !> \brief get corrected PET for the current timestep and domain
876 subroutine get_corrected_pet(self, pet_calc, &
877 petLAIcorFactorL1, fAsp, HarSamCoeff, latitude, PrieTayAlpha, aeroResist, surfResist)
878
879 use mo_mhm_constants, only : harsamconst
880 use mo_julian, only : date2dec, dec2date
882 use mo_string_utils, only : num2str
884
885 implicit none
886
887 class(meteo_handler_type), intent(inout) :: self
888 !> [mm TS-1] estimated PET (if PET is input = corrected values (fAsp*PET))
889 real(dp), dimension(:), intent(inout) :: pet_calc
890 !> PET correction factor based on LAI at level 1
891 real(dp), dimension(:), intent(in) :: petLAIcorFactorL1
892 !> [1] PET correction for Aspect at level 1
893 real(dp), dimension(:), intent(in) :: fAsp
894 !> [1] PET Hargreaves Samani coefficient at level 1
895 real(dp), dimension(:), intent(in) :: HarSamCoeff
896 !> latitude on level 1
897 real(dp), dimension(:), intent(in) :: latitude
898 !> [1] PET Priestley Taylor coefficient at level 1
899 real(dp), dimension(:), intent(in) :: PrieTayAlpha
900 !> [s m-1] PET aerodynamical resitance at level 1
901 real(dp), dimension(:), intent(in) :: aeroResist
902 !> [s m-1] PET bulk surface resitance at level 1
903 real(dp), dimension(:), intent(in) :: surfResist
904
905 ! pet in [mm d-1]
906 real(dp) :: pet
907 logical :: isday, is_hourly
908 integer(i4) :: year, month, day, hour
909 type(datetime) :: curr_dt
910 type(timedelta) :: meteo_time_delta
911
912 ! doy of the year [1-365 or 1-366]
913 integer(i4) :: doy
914
915 ! number of L1 cells
916 integer(i4) :: nCells1
917 ! cell index
918 integer(i4) :: k, i, s1
919 ! individual meteo time-steps for all variables due to possible coupling
920 integer(i4) :: mTS_pet, mTS_temp, mTS_tmin, mTS_tmax, mTS_rn, mTS_avp, mTS_ws
921
922 ! date and month of this timestep
923 call dec2date(self%time, yy = year, mm = month, dd = day, hh = hour)
924 curr_dt = datetime(year, month, day, hour)
925 doy = curr_dt%doy()
926
927 ncells1 = self%e1 - self%s1 + 1
928 s1 = self%s1
929
930 if (self%couple_pet) then
931 meteo_time_delta = curr_dt - self%couple_pet_time
932 ! check that the PET from the interface has the correct time-stamp
933 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
934 call error_message("meteo_handler: PET was expected from coupler, but has a wrong time-stamp.")
935 mts_pet = 1_i4
936 is_hourly = self%couple_is_hourly
937 else
938 mts_pet = self%iMeteoTS
939 is_hourly = self%is_hourly_forcing ! not needed to set with other variables
940 end if
941
942 if (self%couple_temp) then
943 meteo_time_delta = curr_dt - self%couple_temp_time
944 ! check that the temperature from the interface has the correct time-stamp
945 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
946 call error_message("meteo_handler: temperature was expected from coupler, but has a wrong time-stamp.")
947 mts_temp = 1_i4
948 is_hourly = .false.
949 else
950 mts_temp = self%iMeteoTS
951 end if
952
953 if (self%couple_tmin) then
954 meteo_time_delta = curr_dt - self%couple_tmin_time
955 ! check that the tmin from the interface has the correct time-stamp
956 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
957 call error_message("meteo_handler: minimum temperature was expected from coupler, but has a wrong time-stamp.")
958 mts_tmin = 1_i4
959 is_hourly = .false.
960 else
961 mts_tmin = self%iMeteoTS
962 end if
963
964 if (self%couple_tmax) then
965 meteo_time_delta = curr_dt - self%couple_tmax_time
966 ! check that the tmax from the interface has the correct time-stamp
967 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
968 call error_message("meteo_handler: maximum temperature was expected from coupler, but has a wrong time-stamp.")
969 mts_tmax = 1_i4
970 is_hourly = .false.
971 else
972 mts_tmax = self%iMeteoTS
973 end if
974
975 if (self%couple_netrad) then
976 meteo_time_delta = curr_dt - self%couple_netrad_time
977 ! check that the netrad from the interface has the correct time-stamp
978 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
979 call error_message("meteo_handler: net-radiation was expected from coupler, but has a wrong time-stamp.")
980 mts_rn = 1_i4
981 is_hourly = .false.
982 else
983 mts_rn = self%iMeteoTS
984 end if
985
986 if (self%couple_absvappress) then
987 meteo_time_delta = curr_dt - self%couple_absvappress_time
988 ! check that the absvappress from the interface has the correct time-stamp
989 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
990 call error_message("meteo_handler: Abs. vapour pressure was expected from coupler, but has a wrong time-stamp.")
991 mts_avp = 1_i4
992 is_hourly = .false.
993 else
994 mts_avp = self%iMeteoTS
995 end if
996
997 if (self%couple_windspeed) then
998 meteo_time_delta = curr_dt - self%couple_windspeed_time
999 ! check that the windspeed from the interface has the correct time-stamp
1000 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1001 call error_message("meteo_handler: windspeed was expected from coupler, but has a wrong time-stamp.")
1002 mts_ws = 1_i4
1003 is_hourly = .false.
1004 else
1005 mts_ws = self%iMeteoTS
1006 end if
1007
1008 ! flag for day or night depending on hours of the day
1009 isday = (hour .gt. 6) .AND. (hour .le. 18)
1010
1011 !$OMP parallel default(shared) &
1012 !$OMP private(k, pet, i)
1013 !$OMP do SCHEDULE(STATIC)
1014 do k = 1, ncells1
1015
1016 ! correct index on concatenated arrays
1017 i = self%s_meteo - 1 + k
1018
1019 ! PET calculation
1020 select case (self%pet_case)
1021 case(-1) ! PET is input ! correct pet for every day only once at the first time step
1022 pet = petlaicorfactorl1(k) * self%L1_pet(i, mts_pet)
1023
1024 case(0) ! PET is input ! correct pet for every day only once at the first time step
1025 pet = fasp(k) * self%L1_pet(i, mts_pet)
1026
1027 case(1) ! Hargreaves-Samani
1028 ! estimate day of the year (doy) for approximation of the extraterrestrial radiation
1029 if (self%L1_tmax(i, mts_tmax) .lt. self%L1_tmin(i, mts_tmin)) &
1030 call message('WARNING: tmax smaller than tmin at doy ', &
1031 num2str(doy), ' in year ', num2str(year), ' at cell', num2str(k), '!')
1032 pet = fasp(k) * pet_hargreaves( &
1033 harsamcoeff=harsamcoeff(k), &
1035 tavg=self%L1_temp(i, mts_temp), &
1036 tmax=self%L1_tmax(i, mts_tmax), &
1037 tmin=self%L1_tmin(i, mts_tmin), &
1038 latitude=latitude(k), &
1039 doy=doy)
1040
1041 case(2) ! Priestley-Taylor
1042 ! Priestley Taylor is not defined for values netrad < 0.0_dp
1043 pet = pet_priestly( &
1044 prietayparam=prietayalpha(k), &
1045 rn=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1046 tavg=self%L1_temp(i, mts_temp))
1047
1048 case(3) ! Penman-Monteith
1049 pet = pet_penman( &
1050 net_rad=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1051 tavg=self%L1_temp(i, mts_temp), &
1052 act_vap_pressure=self%L1_absvappress(i, mts_avp) / 1000.0_dp, &
1053 aerodyn_resistance=aeroresist(k) / self%L1_windspeed(i, mts_ws), &
1054 bulksurface_resistance=surfresist(k), &
1055 a_s=1.0_dp, &
1056 a_sh=1.0_dp)
1057 end select
1058
1059 ! temporal disaggreagtion of forcing variables
1060 if (self%is_hourly_forcing) then
1061 pet_calc(k) = pet
1062 else
1063 if (self%read_meteo_weights) then
1064 ! all meteo forcings are disaggregated with given weights
1066 meteo_val_day=pet, &
1067 meteo_val_weights=self%L1_pet_weights(s1 - 1 + k, month, hour + 1), &
1068 meteo_val=pet_calc(k))
1069 else
1070 ! all meteo forcings are disaggregated with day-night correction values
1072 isday=isday, &
1073 ntimesteps_day=self%nTstepDay_dp, &
1074 meteo_val_day=pet, &
1075 fday_meteo_val=self%fday_pet(month), &
1076 fnight_meteo_val=self%fnight_pet(month), &
1077 meteo_val=pet_calc(k))
1078 end if
1079 end if
1080 end do
1081 !$OMP end do
1082 !$OMP end parallel
1083
1084 end subroutine get_corrected_pet
1085
1086 !> \brief get surface temperature for the current timestep and domain
1087 subroutine get_temp(self, temp_calc)
1088
1089 use mo_julian, only : dec2date
1091 use mo_constants, only : t0_dp ! 273.15 - Celcius <-> Kelvin [K]
1092
1093 implicit none
1094
1095 class(meteo_handler_type), intent(inout) :: self
1096 !> [degC] temperature for current time step
1097 real(dp), dimension(:), intent(inout) :: temp_calc
1098
1099 logical :: isday, is_hourly
1100 integer(i4) :: year, month, day, hour
1101 type(datetime) :: curr_dt
1102 type(timedelta) :: meteo_time_delta
1103
1104 ! number of L1 cells
1105 integer(i4) :: nCells1
1106 ! cell index
1107 integer(i4) :: k, i, s1, mTS
1108
1109 ! date and month of this timestep
1110 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1111
1112 ncells1 = self%e1 - self%s1 + 1
1113 s1 = self%s1
1114 if (self%couple_temp) then
1115 curr_dt = datetime(year, month, day, hour)
1116 meteo_time_delta = curr_dt - self%couple_temp_time
1117 ! check that the temperature from the interface has the correct time-stamp
1118 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1119 call error_message("meteo_handler: temperature was expected from coupler, but has a wrong time-stamp.")
1120 mts = 1_i4
1121 is_hourly = self%couple_is_hourly
1122 else
1123 mts = self%iMeteoTS
1124 is_hourly = self%is_hourly_forcing
1125 end if
1126
1127 ! shortcut hourly data
1128 if (is_hourly) then
1129 temp_calc(:) = self%L1_temp(self%s_meteo : self%e_meteo, mts)
1130 return
1131 end if
1132
1133 ! flag for day or night depending on hours of the day
1134 isday = (hour .gt. 6) .AND. (hour .le. 18)
1135
1136 !$OMP parallel default(shared) &
1137 !$OMP private(k, i)
1138 !$OMP do SCHEDULE(STATIC)
1139 do k = 1, ncells1
1140
1141 ! correct index on concatenated arrays
1142 i = self%s_meteo - 1 + k
1143
1144 if (self%read_meteo_weights) then
1145 ! all meteo forcings are disaggregated with given weights
1147 meteo_val_day=self%L1_temp(i, mts), &
1148 meteo_val_weights=self%L1_temp_weights(s1 - 1 + k, month, hour + 1), &
1149 meteo_val=temp_calc(k), &
1150 weights_correction=t0_dp)
1151 else
1152 ! all meteo forcings are disaggregated with day-night correction values
1154 isday=isday, &
1155 ntimesteps_day=self%nTstepDay_dp, &
1156 meteo_val_day=self%L1_temp(i, mts), &
1157 fday_meteo_val=self%fday_temp(month), &
1158 fnight_meteo_val=self%fnight_temp(month), &
1159 meteo_val=temp_calc(k), &
1160 add_correction=.true.)
1161 end if
1162 end do
1163 !$OMP end do
1164 !$OMP end parallel
1165
1166 end subroutine get_temp
1167
1168 !> \brief get precipitation for the current timestep and domain
1169 subroutine get_prec(self, prec_calc)
1170
1171 use mo_julian, only : dec2date
1173
1174 implicit none
1175
1176 class(meteo_handler_type), intent(inout) :: self
1177 !> [mm TS-1] precipitation for current time step
1178 real(dp), dimension(:), intent(inout) :: prec_calc
1179
1180 logical :: isday, is_hourly
1181 integer(i4) :: year, month, day, hour
1182 type(datetime) :: curr_dt
1183 type(timedelta) :: meteo_time_delta
1184
1185 ! number of L1 cells
1186 integer(i4) :: nCells1
1187 ! cell index
1188 integer(i4) :: k, i, s1, mTS
1189
1190 ! date and month of this timestep
1191 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1192
1193 ncells1 = self%e1 - self%s1 + 1
1194 s1 = self%s1
1195 if (self%couple_pre) then
1196 curr_dt = datetime(year, month, day, hour)
1197 meteo_time_delta = curr_dt - self%couple_pre_time
1198 ! check that the precipitation from the interface has the correct time-stamp
1199 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1200 call error_message("meteo_handler: precipitation was expected from coupler, but has a wrong time-stamp.")
1201 mts = 1_i4
1202 is_hourly = self%couple_is_hourly
1203 else
1204 mts = self%iMeteoTS
1205 is_hourly = self%is_hourly_forcing
1206 end if
1207
1208 ! shortcut hourly data
1209 if (is_hourly) then
1210 prec_calc(:) = self%L1_pre(self%s_meteo : self%e_meteo, mts)
1211 return
1212 end if
1213
1214 ! flag for day or night depending on hours of the day
1215 isday = (hour .gt. 6) .AND. (hour .le. 18)
1216
1217 !$OMP parallel default(shared) &
1218 !$OMP private(k, i)
1219 !$OMP do SCHEDULE(STATIC)
1220 do k = 1, ncells1
1221
1222 ! correct index on concatenated arrays
1223 i = self%s_meteo - 1 + k
1224
1225 ! temporal disaggreagtion of forcing variables
1226 if (self%read_meteo_weights) then
1227 ! all meteo forcings are disaggregated with given weights
1229 meteo_val_day=self%L1_pre(i, mts), &
1230 meteo_val_weights=self%L1_pre_weights(s1 - 1 + k, month, hour + 1), &
1231 meteo_val=prec_calc(k))
1232 else
1233 ! all meteo forcings are disaggregated with day-night correction values
1235 isday=isday, &
1236 ntimesteps_day=self%nTstepDay_dp, &
1237 meteo_val_day=self%L1_pre(i, mts), &
1238 fday_meteo_val=self%fday_prec(month), &
1239 fnight_meteo_val=self%fnight_prec(month), &
1240 meteo_val=prec_calc(k))
1241 end if
1242 end do
1243 !$OMP end do
1244 !$OMP end parallel
1245
1246 end subroutine get_prec
1247
1248 !> \brief get surface short-wave (solar) radiation downwards for the current timestep and domain
1249 subroutine get_ssrd(self, ssrd_calc)
1250
1251 use mo_julian, only : dec2date
1253
1254 implicit none
1255
1256 class(meteo_handler_type), intent(inout) :: self
1257 !> [W m2] surface short-wave (solar) radiation downwards for current time step
1258 real(dp), dimension(:), intent(inout) :: ssrd_calc
1259
1260 logical :: isday, is_hourly
1261 integer(i4) :: year, month, day, hour
1262 type(datetime) :: curr_dt
1263 type(timedelta) :: meteo_time_delta
1264
1265 ! number of L1 cells
1266 integer(i4) :: nCells1
1267 ! cell index
1268 integer(i4) :: k, i, s1, mTS
1269
1270 ! date and month of this timestep
1271 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1272
1273 ncells1 = self%e1 - self%s1 + 1
1274 s1 = self%s1
1275 if (self%couple_ssrd) then
1276 curr_dt = datetime(year, month, day, hour)
1277 meteo_time_delta = curr_dt - self%couple_ssrd_time
1278 ! check that the ssrd from the interface has the correct time-stamp
1279 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1280 call error_message("meteo_handler: ssrd was expected from coupler, but has a wrong time-stamp.")
1281 mts = 1_i4
1282 is_hourly = self%couple_is_hourly
1283 else
1284 mts = self%iMeteoTS
1285 is_hourly = self%is_hourly_forcing
1286 end if
1287
1288 ! shortcut hourly data
1289 if (is_hourly) then
1290 ssrd_calc(:) = self%L1_ssrd(self%s_meteo : self%e_meteo, mts)
1291 return
1292 end if
1293
1294 ! flag for day or night depending on hours of the day
1295 isday = (hour .gt. 6) .AND. (hour .le. 18)
1296
1297 !$OMP parallel default(shared) &
1298 !$OMP private(k, i)
1299 !$OMP do SCHEDULE(STATIC)
1300 do k = 1, ncells1
1301 ! correct index on concatenated arrays
1302 i = self%s_meteo - 1 + k
1303 ! TODO-RIV-TEMP: add weights for ssrd
1304 ! temporal disaggreagtion of forcing variables
1306 isday=isday, &
1307 ntimesteps_day=self%nTstepDay_dp, &
1308 meteo_val_day=self%L1_ssrd(i, mts), &
1309 fday_meteo_val=self%fday_ssrd(month), &
1310 fnight_meteo_val=self%fnight_ssrd(month), &
1311 meteo_val=ssrd_calc(k) &
1312 )
1313 end do
1314 !$OMP end do
1315 !$OMP end parallel
1316
1317 end subroutine get_ssrd
1318
1319 !> \brief get surface long-wave (thermal) radiation downwards for the current timestep and domain
1320 subroutine get_strd(self, strd_calc)
1321
1322 use mo_julian, only : dec2date
1324
1325 implicit none
1326
1327 class(meteo_handler_type), intent(inout) :: self
1328 !> [W m2] surface long-wave (thermal) radiation downwards for current time step
1329 real(dp), dimension(:), intent(inout) :: strd_calc
1330
1331 logical :: isday, is_hourly
1332 integer(i4) :: year, month, day, hour
1333 type(datetime) :: curr_dt
1334 type(timedelta) :: meteo_time_delta
1335
1336 ! number of L1 cells
1337 integer(i4) :: nCells1
1338 ! cell index
1339 integer(i4) :: k, i, s1, mTS
1340
1341 ! date and month of this timestep
1342 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1343
1344 ncells1 = self%e1 - self%s1 + 1
1345 s1 = self%s1
1346 if (self%couple_strd) then
1347 curr_dt = datetime(year, month, day, hour)
1348 meteo_time_delta = curr_dt - self%couple_strd_time
1349 ! check that the strd from the interface has the correct time-stamp
1350 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1351 call error_message("meteo_handler: strd was expected from coupler, but has a wrong time-stamp.")
1352 mts = 1_i4
1353 is_hourly = self%couple_is_hourly
1354 else
1355 mts = self%iMeteoTS
1356 is_hourly = self%is_hourly_forcing
1357 end if
1358
1359 ! shortcut hourly data
1360 if (is_hourly) then
1361 strd_calc(:) = self%L1_strd(self%s_meteo : self%e_meteo, mts)
1362 return
1363 end if
1364
1365 ! flag for day or night depending on hours of the day
1366 isday = (hour .gt. 6) .AND. (hour .le. 18)
1367
1368 !$OMP parallel default(shared) &
1369 !$OMP private(k, i)
1370 !$OMP do SCHEDULE(STATIC)
1371 do k = 1, ncells1
1372 ! correct index on concatenated arrays
1373 i = self%s_meteo - 1 + k
1374 ! TODO-RIV-TEMP: add weights for strd
1375 ! temporal disaggreagtion of forcing variables
1377 isday=isday, &
1378 ntimesteps_day=self%nTstepDay_dp, &
1379 meteo_val_day=self%L1_strd(i, mts), &
1380 fday_meteo_val=self%fday_strd(month), &
1381 fnight_meteo_val=self%fnight_strd(month), &
1382 meteo_val=strd_calc(k) &
1383 )
1384 end do
1385 !$OMP end do
1386 !$OMP end parallel
1387
1388 end subroutine get_strd
1389
1390 !> \brief get annual mean surface temperature for the current timestep and domain
1391 subroutine get_tann(self, tann_calc)
1392 use mo_julian, only : dec2date
1393
1394 implicit none
1395
1396 class(meteo_handler_type), intent(inout) :: self
1397 !> [degC] annual mean air temperature
1398 real(dp), dimension(:), intent(inout) :: tann_calc
1399
1400 type(datetime) :: curr_dt
1401 type(timedelta) :: meteo_time_delta
1402 integer(i4) :: year, month, day, hour, mTS
1403
1404 if (self%couple_tann) then
1405 ! date and month of this timestep
1406 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1407 curr_dt = datetime(year, month, day, hour)
1408 meteo_time_delta = curr_dt - self%couple_tann_time
1409 ! check that the tann from the interface has the correct time-stamp
1410 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1411 call error_message("meteo_handler: tann was expected from coupler, but has a wrong time-stamp.")
1412 mts = 1_i4
1413 else
1414 mts = self%iMeteoTS
1415 end if
1416
1417 ! annual temperature is not disaggregated
1418 tann_calc(:) = self%L1_tann(self%s_meteo : self%e_meteo, mts)
1419
1420 end subroutine get_tann
1421
1422 !> \brief set meteo_data from coupling
1423 subroutine set_meteo(self, &
1424 year, month, day, hour, &
1425 pre, &
1426 temp, &
1427 pet, &
1428 tmin, &
1429 tmax, &
1430 netrad, &
1431 absvappress, &
1432 windspeed, &
1433 ssrd, &
1434 strd, &
1435 tann)
1436 implicit none
1437 class(meteo_handler_type), intent(inout) :: self
1438 integer(i4), intent(in) :: year
1439 integer(i4), intent(in) :: month
1440 integer(i4), intent(in) :: day
1441 integer(i4), intent(in), optional :: hour
1442 real(dp), dimension(:), optional, intent(in) :: pre
1443 real(dp), dimension(:), optional, intent(in) :: temp
1444 real(dp), dimension(:), optional, intent(in) :: pet
1445 real(dp), dimension(:), optional, intent(in) :: tmin
1446 real(dp), dimension(:), optional, intent(in) :: tmax
1447 real(dp), dimension(:), optional, intent(in) :: netrad
1448 real(dp), dimension(:), optional, intent(in) :: absvappress
1449 real(dp), dimension(:), optional, intent(in) :: windspeed
1450 real(dp), dimension(:), optional, intent(in) :: ssrd
1451 real(dp), dimension(:), optional, intent(in) :: strd
1452 real(dp), dimension(:), optional, intent(in) :: tann
1453
1454 integer(i4) :: hour_
1455 type(datetime) :: input_time
1456
1457 if (.not. self%couple_cfg%active()) &
1458 call error_message("meteo_handler%set_meteo: coupling was not activated.")
1459
1460 ! determine input time
1461 hour_ = -1_i4
1462 if (present(hour)) then
1463 hour_ = hour
1464 else if (self%couple_cfg%meteo_timestep == 24_i4) then
1465 hour_ = 0_i4
1466 end if
1467 if (hour_ == -1_i4) &
1468 call error_message("meteo_handler%set_meteo: hour for the meteo date needs to be given if the timestep is not daily.")
1469 input_time = datetime(year, month, day, hour_)
1470
1471 ! fix input time, if reference point is at the end of the time interval
1472 if (self%couple_cfg%meteo_time_ref_endpoint) input_time = input_time - self%couple_step_delta
1473
1474 ! check if input time matches the required time step
1475 if (mod(input_time%hour, self%couple_cfg%meteo_timestep) /= 0) &
1476 call error_message("meteo_handler%set_meteo: given time doesn't match couple timestep: ", input_time%str())
1477
1478 ! precipitation
1479 if (present(pre)) then
1480 if (.not. self%couple_pre) &
1481 call error_message("meteo_handler%set_meteo: precipitation was not set to be coupled.")
1482 self%couple_pre_time = input_time
1483 self%L1_pre(:, 1_i4) = pre(:)
1484 end if
1485
1486 ! temperature
1487 if (present(temp)) then
1488 if (.not. self%couple_temp) &
1489 call error_message("meteo_handler%set_meteo: avg. temperature was not set to be coupled.")
1490 self%couple_temp_time = input_time
1491 self%L1_temp(:, 1_i4) = temp(:)
1492 end if
1493
1494 ! PET
1495 if (present(pet)) then
1496 if (.not. self%couple_pet) &
1497 call error_message("meteo_handler%set_meteo: PET was not set to be coupled.")
1498 self%couple_pet_time = input_time
1499 self%L1_pet(:, 1_i4) = pet(:)
1500 end if
1501
1502 ! tmin
1503 if (present(tmin)) then
1504 if (.not. self%couple_tmin) &
1505 call error_message("meteo_handler%set_meteo: tmin was not set to be coupled.")
1506 self%couple_tmin_time = input_time
1507 self%L1_tmin(:, 1_i4) = tmin(:)
1508 end if
1509
1510 ! tmax
1511 if (present(tmax)) then
1512 if (.not. self%couple_tmax) &
1513 call error_message("meteo_handler%set_meteo: tmax was not set to be coupled.")
1514 self%couple_tmax_time = input_time
1515 self%L1_tmax(:, 1_i4) = tmax(:)
1516 end if
1517
1518 ! netrad
1519 if (present(netrad)) then
1520 if (.not. self%couple_netrad) &
1521 call error_message("meteo_handler%set_meteo: netrad was not set to be coupled.")
1522 self%couple_netrad_time = input_time
1523 self%L1_netrad(:, 1_i4) = netrad(:)
1524 end if
1525
1526 ! absvappress
1527 if (present(absvappress)) then
1528 if (.not. self%couple_absvappress) &
1529 call error_message("meteo_handler%set_meteo: absvappress was not set to be coupled.")
1530 self%couple_absvappress_time = input_time
1531 self%L1_absvappress(:, 1_i4) = absvappress(:)
1532 end if
1533
1534 ! windspeed
1535 if (present(windspeed)) then
1536 if (.not. self%couple_windspeed) &
1537 call error_message("meteo_handler%set_meteo: windspeed was not set to be coupled.")
1538 self%couple_windspeed_time = input_time
1539 self%L1_windspeed(:, 1_i4) = windspeed(:)
1540 end if
1541
1542 ! ssrd
1543 if (present(ssrd)) then
1544 if (.not. self%couple_ssrd) &
1545 call error_message("meteo_handler%set_meteo: ssrd was not set to be coupled.")
1546 self%couple_ssrd_time = input_time
1547 self%L1_ssrd(:, 1_i4) = ssrd(:)
1548 end if
1549
1550 ! strd
1551 if (present(strd)) then
1552 if (.not. self%couple_strd) &
1553 call error_message("meteo_handler%set_meteo: strd was not set to be coupled.")
1554 self%couple_strd_time = input_time
1555 self%L1_strd(:, 1_i4) = strd(:)
1556 end if
1557
1558 ! tann
1559 if (present(tann)) then
1560 if (.not. self%couple_tann) &
1561 call error_message("meteo_handler%set_meteo: tann was not set to be coupled.")
1562 self%couple_tann_time = input_time
1563 self%L1_tann(:, 1_i4) = tann(:)
1564 end if
1565
1566 end subroutine set_meteo
1567
1568end module mo_meteo_handler
Provides constants commonly used by mHM, mRM and MPR.
integer(i4), parameter, public maxnodomains
integer(i4), parameter, public nodata_i4
gridding tools
subroutine, public init_lowres_level(highres, target_resolution, lowres, highres_lowres_remap)
Level-1 variable initialization.
subroutine, public set_domain_indices(grids, indices)
TODO: add description.
Provides common types needed by mHM, mRM and/or mpr.
Provides structures needed by mHM, mRM and/or mpr.
integer(i4), parameter, public nprocesses
Types to specify the coupling configuration of mHM.
subroutine clean_up(self)
clean up
Class for the meteo handler.
subroutine set_meteo(self, year, month, day, hour, pre, temp, pet, tmin, tmax, netrad, absvappress, windspeed, ssrd, strd, tann)
set meteo_data from coupling
subroutine get_temp(self, temp_calc)
get surface temperature for the current timestep and domain
subroutine update_timestep(self, tt, time, idomain, level1, simper)
update the current time-step of the meteo_handler_type class
subroutine config(self, file_namelist, optimize, domainmeta, processmatrix, timestep, couple_cfg)
configure the meteo_handler_type class from the mhm namelist
subroutine get_ssrd(self, ssrd_calc)
get surface short-wave (solar) radiation downwards for the current timestep and domain
subroutine get_corrected_pet(self, pet_calc, petlaicorfactorl1, fasp, harsamcoeff, latitude, prietayalpha, aeroresist, surfresist)
get corrected PET for the current timestep and domain
subroutine get_tann(self, tann_calc)
get annual mean surface temperature for the current timestep and domain
subroutine get_prec(self, prec_calc)
get precipitation for the current timestep and domain
subroutine init_level2(self, level0, level1)
Initialize meteo data and level-2 grid.
logical function single_read(self, idomain)
whether meteo data should be read completely at the begining
subroutine prepare_data(self, tt, idomain, level1, simper)
Prepare meteorological forcings data for a given variable.
subroutine get_strd(self, strd_calc)
get surface long-wave (thermal) radiation downwards for the current timestep and domain
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
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.
Temporal disaggregation of daily input values.
elemental subroutine, public temporal_disagg_state_daynight(isday, ntimesteps_day, meteo_val_day, fday_meteo_val, fnight_meteo_val, meteo_val, add_correction)
Temporally distribute daily mean state forcings onto time step.
elemental subroutine, public temporal_disagg_meteo_weights(meteo_val_day, meteo_val_weights, meteo_val, weights_correction)
Temporally distribute daily mean forcings onto time step.
elemental subroutine, public temporal_disagg_flux_daynight(isday, ntimesteps_day, meteo_val_day, fday_meteo_val, fnight_meteo_val, meteo_val)
Temporally distribute daily mean forcings onto time step.
Provides mHM specific constants.
real(dp), parameter, public harsamconst
Hargreaves-Samani ref.
Module containing all namelists representations.
type(nml_nightdayratio_t), public nml_nightdayratio
'nightdayratio' namelist content
type(nml_directories_mhm_t), public nml_directories_mhm
'directories_mhm' namelist content
Module for calculating reference/potential evapotranspiration [mm d-1].
Definition mo_pet.f90:15
elemental pure real(dp) function, public pet_penman(net_rad, tavg, act_vap_pressure, aerodyn_resistance, bulksurface_resistance, a_s, a_sh)
Reference Evapotranspiration after Penman-Monteith.
Definition mo_pet.f90:237
elemental pure real(dp) function, public pet_hargreaves(harsamcoeff, harsamconst, tavg, tmax, tmin, latitude, doy)
Reference Evapotranspiration after Hargreaves.
Definition mo_pet.f90:74
elemental pure real(dp) function, public pet_priestly(prietayparam, rn, tavg)
Reference Evapotranspiration after Priestly-Taylor.
Definition mo_pet.f90:150
Reads spatial input data.
subroutine, public read_header_ascii(filename, fileunit, header_ncols, header_nrows, header_xllcorner, header_yllcorner, header_cellsize, header_nodata)
Reads header lines of ASCII files.
DOMAIN general description.
This is a container to hold all coupling configurations for mHM.
This is a handler for the meteorological forcings.