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
473 use mo_string_utils, only : num2str
474
475 implicit none
476
477 class(meteo_handler_type), intent(inout) :: self
478 !> grid information at level-0
479 type(grid), dimension(:), intent(in) :: level0
480 !> grid information at level-1 if all meteo data is coupled
481 type(grid), dimension(:), intent(in) :: level1
482
483 ! header info
484 integer(i4) :: nrows2, ncols2
485 real(dp) :: xllcorner2, yllcorner2
486 real(dp) :: cellsize2, nodata_dummy
487 ! file name
488 character(256) :: fName
489 ! looping variable
490 integer(i4) :: iDomain
491
492 ! create level-2 info
493 allocate(self%level2(self%nDomains))
494
495 ! we don't need level 2 if all meteo data comes from the coupler
496 if (self%couple_all) then
497 self%level2(:) = level1(:)
498 return
499 end if
500
501 do idomain = 1, self%nDomains
502 ! read header
503 fname = trim(adjustl(self%dir_meteo_header(idomain))) // trim(adjustl(self%file_meteo_header))
504 call read_header_ascii(trim(fname), self%umeteo_header, &
505 nrows2, ncols2, xllcorner2, yllcorner2, cellsize2, nodata_dummy)
506
507 ! check grid compatibility
508 call init_lowres_level(level0(self%L0DataFrom(idomain)), cellsize2, self%level2(idomain))
509 call check_header(ncols2, nrows2, xllcorner2, yllcorner2, cellsize2, &
510 self%level2(idomain)%ncols, self%level2(idomain)%nrows, &
511 self%level2(idomain)%xllcorner, self%level2(idomain)%yllcorner, self%level2(idomain)%cellsize, &
512 context = '***ERROR: subroutine L2_variable_init: size mismatch in grid file for level2 in domain ' // &
513 trim(adjustl(num2str(idomain))) // '! ')
514 end do
515
516 ! set indices
517 call set_domain_indices(self%level2)
518
519 end subroutine init_level2
520
521 !> \brief update the current time-step of the \ref meteo_handler_type class
522 subroutine update_timestep(self, tt, time, iDomain, level1, simPer)
523
524 implicit none
525
526 class(meteo_handler_type), intent(inout) :: self
527 integer(i4), intent(in) :: tt !< current time step
528 real(dp), intent(in) :: time !< current decimal Julian day
529 integer(i4), intent(in) :: iDomain !< current domain
530 !> grid information at hydrologic level
531 type(grid), dimension(:), intent(in) :: level1
532 !> warmPer + evalPer
533 type(period), dimension(:), intent(in) :: simPer
534
535 ! store current indizes and time
536 ! only needed for the "get_<var>" methods
537 self%s1 = level1(idomain)%iStart
538 self%e1 = level1(idomain)%iEnd
539 self%time = time
540
541 ! time increment is done right after call to mrm (and initially before looping)
542 if (self%single_read(idomain) .or. self%couple_all) then
543 ! whole meteorology is already read or all meteo is coupled
544
545 ! set start and end of meteo position
546 self%s_meteo = level1(idomain)%iStart
547 self%e_meteo = level1(idomain)%iEnd
548
549 ! time step for meteorological variable (daily values)
550 ! iMeteoTS = ceiling(real(tt, dp) / real(nTstepDay, dp))
551 if (self%couple_all) then
552 self%iMeteoTS = 1_i4
553 else
554 self%iMeteoTS = ceiling(real(tt, dp) / real(nint( 24._dp / real(self%nTstepForcingDay, dp)), dp))
555 end if
556 else
557 ! read chunk of meteorological forcings data (reading, upscaling/downscaling)
558 call self%prepare_data(tt, idomain, level1, simper)
559 ! set start and end of meteo position
560 self%s_meteo = 1
561 self%e_meteo = level1(idomain)%iEnd - level1(idomain)%iStart + 1
562 ! time step for meteorological variable (daily values)
563 self%iMeteoTS = ceiling(real(tt, dp) / real(nint( 24._dp / real(self%nTstepForcingDay, dp)), dp)) &
564 - (self%readPer%julStart - simper(idomain)%julStart)
565 end if
566
567 end subroutine update_timestep
568
569 !> \brief Prepare meteorological forcings data for a given variable
570 !> \details Prepare meteorological forcings data for a given variable.
571 !! Internally this subroutine calls another routine meteo_wrapper
572 !! for different meterological variables
573 !> \changelog
574 !! - Matthias Zink, Jun 2013
575 !! - addded NetCDf reader
576 !! - Rohini Kumar, Aug 2013
577 !! - name changed "inputFormat" to inputFormat_meteo_forcings
578 !! - Matthias Zink, Feb 2014
579 !! - added read in for different PET processes (process 5)
580 !! - Stephan Thober, Jun 2014
581 !! - add chunk_config for chunk read, copied L2 initialization to mo_startup
582 !! - Stephan Thober, Nov 2016
583 !! - moved processMatrix to common variables
584 !! - Stephan Thober, Jan 2017
585 !! - added subroutine for meteo_weights
586 !! - Robert Schweppe Jun 2018
587 !! - refactoring and reformatting
588 !! - Sebastian Müller Mar 2023
589 !! - converted routine to meteo-handler method
590 !> \authors Rohini Kumar
591 !> \date Jan 2013
592 subroutine prepare_data(self, tt, iDomain, level1, simPer)
593
594 use mo_string_utils, only : num2str
595 use mo_timer, only : timer_get, timer_start, timer_stop
597
598 implicit none
599
600 class(meteo_handler_type), intent(inout) :: self
601 integer(i4), intent(in) :: tt !< current timestep
602 integer(i4), intent(in) :: iDomain !< Domain number
603 !> grid information at hydrologic level
604 type(grid), dimension(:), intent(in) :: level1
605 !> warmPer + evalPer
606 type(period), dimension(:), intent(in) :: simPer
607
608 ! indicate whether data should be read
609 logical :: read_flag
610 integer(i4) :: domainID ! current domain ID
611
612 ! allocate arrays only once if they are coupled
613 if (self%couple_pre .and. .not. allocated(self%L1_pre)) allocate(self%L1_pre(level1(idomain)%nCells, 1))
614 if (self%couple_temp .and. .not. allocated(self%L1_temp)) allocate(self%L1_temp(level1(idomain)%nCells, 1))
615 if (self%couple_pet .and. .not. allocated(self%L1_pet)) allocate(self%L1_pet(level1(idomain)%nCells, 1))
616 if (self%couple_tmin .and. .not. allocated(self%L1_tmin)) allocate(self%L1_tmin(level1(idomain)%nCells, 1))
617 if (self%couple_tmax .and. .not. allocated(self%L1_tmax)) allocate(self%L1_tmax(level1(idomain)%nCells, 1))
618 if (self%couple_netrad .and. .not. allocated(self%L1_netrad)) allocate(self%L1_netrad(level1(idomain)%nCells, 1))
619 if (self%couple_absvappress .and. .not. allocated(self%L1_absvappress)) allocate(self%L1_absvappress(level1(idomain)%nCells, 1))
620 if (self%couple_windspeed .and. .not. allocated(self%L1_windspeed)) allocate(self%L1_windspeed(level1(idomain)%nCells, 1))
621 if (self%couple_ssrd .and. .not. allocated(self%L1_ssrd)) allocate(self%L1_ssrd(level1(idomain)%nCells, 1))
622 if (self%couple_strd .and. .not. allocated(self%L1_strd)) allocate(self%L1_strd(level1(idomain)%nCells, 1))
623 if (self%couple_tann .and. .not. allocated(self%L1_tann)) allocate(self%L1_tann(level1(idomain)%nCells, 1))
624
625 domainid = self%indices(idomain)
626
627 ! configuration of chunk_read
628 call chunk_config(idomain, tt, self%nTstepDay, simper, self%timestep, self%timeStep_model_inputs, read_flag, self%readPer)
629
630 ! only read, if read_flag is true
631 if (read_flag) then
632
633 ! read weights for hourly disaggregation
634 if (tt .eq. 1) then
635 ! TODO-RIV-TEMP: No NC files for weights for radiation at the moment
636 if (self%single_read(idomain)) call message(' read meteo weights for tavg ...')
637 call meteo_weights_wrapper(idomain, self%read_meteo_weights, self%dirTemperature(idomain), &
638 self%L1_temp_weights, level1=level1, level2=self%level2, ncvarname = 'tavg_weight')
639
640 if (self%single_read(idomain)) call message(' read meteo weights for pet ...')
641 call meteo_weights_wrapper(idomain, self%read_meteo_weights, self%dirReferenceET(idomain), &
642 self%L1_pet_weights, level1=level1, level2=self%level2, ncvarname = 'pet_weight')
643
644 if (self%single_read(idomain)) call message(' read meteo weights for pre ...')
645 call meteo_weights_wrapper(idomain, self%read_meteo_weights, self%dirPrecipitation(idomain), &
646 self%L1_pre_weights, level1=level1, level2=self%level2, ncvarname = 'pre_weight')
647 end if
648
649 ! free L1 variables if chunk read is activated
650 if (self%timeStep_model_inputs(idomain) .ne. 0) then
651 if (.not. self%couple_pre .and. allocated(self%L1_pre)) deallocate(self%L1_pre)
652 if (.not. self%couple_temp .and. allocated(self%L1_temp)) deallocate(self%L1_temp)
653 if (.not. self%couple_pet .and. allocated(self%L1_pet)) deallocate(self%L1_pet)
654 if (.not. self%couple_tmin .and. allocated(self%L1_tmin)) deallocate(self%L1_tmin)
655 if (.not. self%couple_tmax .and. allocated(self%L1_tmax)) deallocate(self%L1_tmax)
656 if (.not. self%couple_netrad .and. allocated(self%L1_netrad)) deallocate(self%L1_netrad)
657 if (.not. self%couple_absvappress .and. allocated(self%L1_absvappress)) deallocate(self%L1_absvappress)
658 if (.not. self%couple_windspeed .and. allocated(self%L1_windspeed)) deallocate(self%L1_windspeed)
659 end if
660
661 ! Domain characteristics and read meteo header
662 if (self%single_read(idomain)) then
663 call message(' Reading meteorological forcings for Domain: ', trim(adjustl(num2str(domainid))), ' ...')
664 call timer_start(1)
665 end if
666
667 ! precipitation
668 if (.not. self%couple_pre) then
669 if (self%single_read(idomain)) call message(' read precipitation ...')
670 ! upper bound: 1825 mm/d in La Réunion 7-8 Jan 1966
671 call meteo_forcings_wrapper(idomain, self%dirPrecipitation(idomain), self%inputFormat_meteo_forcings, &
672 dataout1=self%L1_pre, &
673 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
674 lower = 0.0_dp, upper = 2000._dp, ncvarname = 'pre', bound_error=self%bound_error)
675 end if
676
677 ! temperature
678 if (.not. self%couple_temp) then
679 if (self%single_read(idomain)) call message(' read temperature ...')
680 call meteo_forcings_wrapper(idomain, self%dirTemperature(idomain), self%inputFormat_meteo_forcings, &
681 dataout1=self%L1_temp, &
682 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
683 lower = -100._dp, upper = 100._dp, ncvarname = 'tavg', bound_error=self%bound_error)
684 end if
685
686 ! read input for PET (process 5) depending on specified option
687 ! 0 - input, 1 - Hargreaves-Samani, 2 - Priestley-Taylor, 3 - Penman-Monteith
688 select case (self%pet_case)
689 case(-1 : 0) ! pet is input
690 if (.not. self%couple_pet) then
691 if (self%single_read(idomain)) call message(' read pet ...')
692 call meteo_forcings_wrapper(idomain, self%dirReferenceET(idomain), self%inputFormat_meteo_forcings, &
693 dataout1=self%L1_pet, &
694 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
695 lower = 0.0_dp, upper = 1000._dp, ncvarname = 'pet', bound_error=self%bound_error)
696 end if
697 ! allocate PET and dummies for mhm_call
698 if ((idomain.eq.self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
699 allocate(self%L1_tmin(1, 1))
700 allocate(self%L1_tmax(1, 1))
701 allocate(self%L1_netrad(1, 1))
702 allocate(self%L1_absvappress(1, 1))
703 allocate(self%L1_windspeed(1, 1))
704 end if
705
706 case(1) ! Hargreaves-Samani formulation (input: minimum and maximum Temperature)
707 if (.not. self%couple_tmin) then
708 if (self%single_read(idomain)) call message(' read min. temperature ...')
709 call meteo_forcings_wrapper(idomain, self%dirMinTemperature(idomain), self%inputFormat_meteo_forcings, &
710 dataout1=self%L1_tmin, &
711 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
712 lower = -100.0_dp, upper = 100._dp, ncvarname = 'tmin', bound_error=self%bound_error)
713 end if
714 if (.not. self%couple_tmax) then
715 if (self%single_read(idomain)) call message(' read max. temperature ...')
716 call meteo_forcings_wrapper(idomain, self%dirMaxTemperature(idomain), self%inputFormat_meteo_forcings, &
717 dataout1=self%L1_tmax, &
718 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
719 lower = -100.0_dp, upper = 100._dp, ncvarname = 'tmax', bound_error=self%bound_error)
720 end if
721 ! allocate PET and dummies for mhm_call
722 if ((idomain .eq. self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
723 allocate(self%L1_pet (size(self%L1_tmax, dim = 1), size(self%L1_tmax, dim = 2)))
724 allocate(self%L1_netrad(1, 1))
725 allocate(self%L1_absvappress(1, 1))
726 allocate(self%L1_windspeed(1, 1))
727 end if
728
729 case(2) ! Priestley-Taylor formulation (input: net radiation)
730 if (.not. self%couple_netrad) then
731 if (self%single_read(idomain)) call message(' read net radiation ...')
732 call meteo_forcings_wrapper(idomain, self%dirNetRadiation(idomain), self%inputFormat_meteo_forcings, &
733 dataout1=self%L1_netrad, &
734 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
735 lower = -500.0_dp, upper = 1500._dp, ncvarname = 'net_rad', bound_error=self%bound_error)
736 end if
737 ! allocate PET and dummies for mhm_call
738 if ((idomain .eq. self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
739 allocate(self%L1_pet (size(self%L1_netrad, dim = 1), size(self%L1_netrad, dim = 2)))
740 allocate(self%L1_tmin(1, 1))
741 allocate(self%L1_tmax(1, 1))
742 allocate(self%L1_absvappress(1, 1))
743 allocate(self%L1_windspeed(1, 1))
744 end if
745
746 case(3) ! Penman-Monteith formulation (input: net radiationm absulute vapour pressure, windspeed)
747 if (.not. self%couple_netrad) then
748 if (self%single_read(idomain)) call message(' read net radiation ...')
749 call meteo_forcings_wrapper(idomain, self%dirNetRadiation(idomain), self%inputFormat_meteo_forcings, &
750 dataout1=self%L1_netrad, &
751 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
752 lower = -500.0_dp, upper = 1500._dp, ncvarname = 'net_rad', bound_error=self%bound_error)
753 end if
754 if (.not. self%couple_absvappress) then
755 if (self%single_read(idomain)) call message(' read absolute vapour pressure ...')
756 call meteo_forcings_wrapper(idomain, self%dirabsVapPressure(idomain), self%inputFormat_meteo_forcings, &
757 dataout1=self%L1_absvappress, &
758 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
759 lower = 0.0_dp, upper = 15000.0_dp, ncvarname = 'eabs', bound_error=self%bound_error)
760 end if
761 if (.not. self%couple_windspeed) then
762 if (self%single_read(idomain)) call message(' read windspeed ...')
763 call meteo_forcings_wrapper(idomain, self%dirwindspeed(idomain), self%inputFormat_meteo_forcings, &
764 dataout1=self%L1_windspeed, &
765 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
766 lower = 0.0_dp, upper = 250.0_dp, ncvarname = 'windspeed', bound_error=self%bound_error)
767 end if
768 ! allocate PET and dummies for mhm_call
769 if ((idomain.eq.self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0)) then
770 allocate(self%L1_pet (size(self%L1_absvappress, dim = 1), size(self%L1_absvappress, dim = 2)))
771 allocate(self%L1_tmin(1, 1))
772 allocate(self%L1_tmax(1, 1))
773 end if
774 end select
775
776 ! long/short-wave radiation and annual mean temperature for river-temperature routing
777 if ( self%riv_temp_case .ne. 0 ) then
778 ! free L1 variables if chunk read is activated
779 if (self%timeStep_model_inputs(idomain) .ne. 0) then
780 if (.not. self%couple_ssrd .and. allocated(self%L1_ssrd)) deallocate(self%L1_ssrd)
781 if (.not. self%couple_strd .and. allocated(self%L1_strd)) deallocate(self%L1_strd)
782 if (.not. self%couple_tann .and. allocated(self%L1_tann)) deallocate(self%L1_tann)
783 end if
784 if (.not. self%couple_ssrd) then
785 if (self%single_read(idomain)) call message(' read short-wave radiation ...')
787 idomain, self%dirRadiation(idomain), self%inputFormat_meteo_forcings, &
788 dataout1=self%L1_ssrd, &
789 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
790 lower = 0.0_dp, upper = 1500._dp, ncvarname = 'ssrd', bound_error=self%bound_error)
791 end if
792 if (.not. self%couple_strd) then
793 if (self%single_read(idomain)) call message(' read long-wave radiation ...')
795 idomain, self%dirRadiation(idomain), self%inputFormat_meteo_forcings, &
796 dataout1=self%L1_strd, &
797 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
798 lower = 0.0_dp, upper = 1500._dp, ncvarname = 'strd', bound_error=self%bound_error)
799 end if
800 if (.not. self%couple_tann) then
801 if (self%single_read(idomain)) call message(' read annual mean temperature ...')
803 idomain, self%dirTemperature(idomain), self%inputFormat_meteo_forcings, &
804 dataout1=self%L1_tann, &
805 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
806 lower = -100.0_dp, upper = 100._dp, ncvarname = 'tann', bound_error=self%bound_error)
807 end if
808 end if
809
810 if (self%single_read(idomain)) then
811 call timer_stop(1)
812 call message(' in ', trim(num2str(timer_get(1), '(F9.3)')), ' seconds.')
813 end if
814 end if
815
816 if (tt .eq. 1) then
817 ! set hourly flags (once at begining)
818 if (self%couple_all) then
819 self%nTstepForcingDay = int(one_day() / self%couple_step_delta, i4)
820 self%is_hourly_forcing = self%couple_is_hourly
821 else
822 self%is_hourly_forcing = (self%nTstepForcingDay .eq. 24_i4)
823 end if
824
825 ! check hourly data for PET (once at begining)
826 select case (self%pet_case)
827 case(1) ! Hargreaves-Samani formulation
828 if (self%couple_temp .and. self%couple_tmin .and. self%couple_tmax) then
829 if (self%couple_is_hourly) call error_message("Coupling: PET - Hargreaves-Samani needs daily data. Got hourly.")
830 else if (self%couple_temp .or. self%couple_tmin .or. self%couple_tmax) then
831 if (self%couple_is_hourly) call error_message("Coupling: PET - Hargreaves-Samani needs daily data. Got hourly.")
832 if (self%is_hourly_forcing) call error_message("Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
833 else
834 if (self%is_hourly_forcing) call error_message("Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
835 end if
836
837 case(2) ! Priestley-Taylor formulation
838 if (self%couple_temp .and. self%couple_netrad) then
839 if (self%couple_is_hourly) call error_message("Coupling: PET - Priestley-Taylor needs daily data. Got hourly.")
840 else if (self%couple_temp .or. self%couple_netrad) then
841 if (self%couple_is_hourly) call error_message("Coupling: PET - Priestley-Taylor needs daily data. Got hourly.")
842 if (self%is_hourly_forcing) call error_message("Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
843 else
844 if (self%is_hourly_forcing) call error_message("Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
845 end if
846
847 case(3) ! Penman-Monteith formulation
848 if (self%couple_temp .and. self%couple_netrad .and. self%couple_absvappress .and. self%couple_windspeed) then
849 if (self%couple_is_hourly) call error_message("Coupling: PET - Penman-Monteith needs daily data. Got hourly.")
850 else if (self%couple_temp .or. self%couple_netrad .or. self%couple_absvappress .or. self%couple_windspeed) then
851 if (self%couple_is_hourly) call error_message("Coupling: PET - Penman-Monteith needs daily data. Got hourly.")
852 if (self%is_hourly_forcing) call error_message("Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
853 else
854 if (self%is_hourly_forcing) call error_message("Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
855 end if
856 end select
857 end if
858
859 end subroutine prepare_data
860
861 !> \brief get corrected PET for the current timestep and domain
862 subroutine get_corrected_pet(self, pet_calc, &
863 petLAIcorFactorL1, fAsp, HarSamCoeff, latitude, PrieTayAlpha, aeroResist, surfResist)
864
865 use mo_mhm_constants, only : harsamconst
866 use mo_julian, only : date2dec, dec2date
868 use mo_string_utils, only : num2str
870
871 implicit none
872
873 class(meteo_handler_type), intent(inout) :: self
874 !> [mm TS-1] estimated PET (if PET is input = corrected values (fAsp*PET))
875 real(dp), dimension(:), intent(inout) :: pet_calc
876 !> PET correction factor based on LAI at level 1
877 real(dp), dimension(:), intent(in) :: petLAIcorFactorL1
878 !> [1] PET correction for Aspect at level 1
879 real(dp), dimension(:), intent(in) :: fAsp
880 !> [1] PET Hargreaves Samani coefficient at level 1
881 real(dp), dimension(:), intent(in) :: HarSamCoeff
882 !> latitude on level 1
883 real(dp), dimension(:), intent(in) :: latitude
884 !> [1] PET Priestley Taylor coefficient at level 1
885 real(dp), dimension(:), intent(in) :: PrieTayAlpha
886 !> [s m-1] PET aerodynamical resitance at level 1
887 real(dp), dimension(:), intent(in) :: aeroResist
888 !> [s m-1] PET bulk surface resitance at level 1
889 real(dp), dimension(:), intent(in) :: surfResist
890
891 ! pet in [mm d-1]
892 real(dp) :: pet
893 logical :: isday, is_hourly
894 integer(i4) :: year, month, day, hour
895 type(datetime) :: curr_dt
896 type(timedelta) :: meteo_time_delta
897
898 ! doy of the year [1-365 or 1-366]
899 integer(i4) :: doy
900
901 ! number of L1 cells
902 integer(i4) :: nCells1
903 ! cell index
904 integer(i4) :: k, i, s1
905 ! individual meteo time-steps for all variables due to possible coupling
906 integer(i4) :: mTS_pet, mTS_temp, mTS_tmin, mTS_tmax, mTS_rn, mTS_avp, mTS_ws
907
908 ! date and month of this timestep
909 call dec2date(self%time, yy = year, mm = month, dd = day, hh = hour)
910 curr_dt = datetime(year, month, day, hour)
911 doy = curr_dt%doy()
912
913 ncells1 = self%e1 - self%s1 + 1
914 s1 = self%s1
915
916 if (self%couple_pet) then
917 meteo_time_delta = curr_dt - self%couple_pet_time
918 ! check that the PET from the interface has the correct time-stamp
919 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
920 call error_message("meteo_handler: PET was expected from coupler, but has a wrong time-stamp.")
921 mts_pet = 1_i4
922 is_hourly = self%couple_is_hourly
923 else
924 mts_pet = self%iMeteoTS
925 is_hourly = self%is_hourly_forcing ! not needed to set with other variables
926 end if
927
928 if (self%couple_temp) then
929 meteo_time_delta = curr_dt - self%couple_temp_time
930 ! check that the temperature from the interface has the correct time-stamp
931 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
932 call error_message("meteo_handler: temperature was expected from coupler, but has a wrong time-stamp.")
933 mts_temp = 1_i4
934 is_hourly = .false.
935 else
936 mts_temp = self%iMeteoTS
937 end if
938
939 if (self%couple_tmin) then
940 meteo_time_delta = curr_dt - self%couple_tmin_time
941 ! check that the tmin from the interface has the correct time-stamp
942 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
943 call error_message("meteo_handler: minimum temperature was expected from coupler, but has a wrong time-stamp.")
944 mts_tmin = 1_i4
945 is_hourly = .false.
946 else
947 mts_tmin = self%iMeteoTS
948 end if
949
950 if (self%couple_tmax) then
951 meteo_time_delta = curr_dt - self%couple_tmax_time
952 ! check that the tmax from the interface has the correct time-stamp
953 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
954 call error_message("meteo_handler: maximum temperature was expected from coupler, but has a wrong time-stamp.")
955 mts_tmax = 1_i4
956 is_hourly = .false.
957 else
958 mts_tmax = self%iMeteoTS
959 end if
960
961 if (self%couple_netrad) then
962 meteo_time_delta = curr_dt - self%couple_netrad_time
963 ! check that the netrad from the interface has the correct time-stamp
964 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
965 call error_message("meteo_handler: net-radiation was expected from coupler, but has a wrong time-stamp.")
966 mts_rn = 1_i4
967 is_hourly = .false.
968 else
969 mts_rn = self%iMeteoTS
970 end if
971
972 if (self%couple_absvappress) then
973 meteo_time_delta = curr_dt - self%couple_absvappress_time
974 ! check that the absvappress from the interface has the correct time-stamp
975 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
976 call error_message("meteo_handler: Abs. vapour pressure was expected from coupler, but has a wrong time-stamp.")
977 mts_avp = 1_i4
978 is_hourly = .false.
979 else
980 mts_avp = self%iMeteoTS
981 end if
982
983 if (self%couple_windspeed) then
984 meteo_time_delta = curr_dt - self%couple_windspeed_time
985 ! check that the windspeed from the interface has the correct time-stamp
986 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
987 call error_message("meteo_handler: windspeed was expected from coupler, but has a wrong time-stamp.")
988 mts_ws = 1_i4
989 is_hourly = .false.
990 else
991 mts_ws = self%iMeteoTS
992 end if
993
994 ! flag for day or night depending on hours of the day
995 isday = (hour .gt. 6) .AND. (hour .le. 18)
996
997 !$OMP parallel default(shared) &
998 !$OMP private(k, pet, i)
999 !$OMP do SCHEDULE(STATIC)
1000 do k = 1, ncells1
1001
1002 ! correct index on concatenated arrays
1003 i = self%s_meteo - 1 + k
1004
1005 ! PET calculation
1006 select case (self%pet_case)
1007 case(-1) ! PET is input ! correct pet for every day only once at the first time step
1008 pet = petlaicorfactorl1(k) * self%L1_pet(i, mts_pet)
1009
1010 case(0) ! PET is input ! correct pet for every day only once at the first time step
1011 pet = fasp(k) * self%L1_pet(i, mts_pet)
1012
1013 case(1) ! Hargreaves-Samani
1014 ! estimate day of the year (doy) for approximation of the extraterrestrial radiation
1015 if (self%L1_tmax(i, mts_tmax) .lt. self%L1_tmin(i, mts_tmin)) &
1016 call message('WARNING: tmax smaller than tmin at doy ', &
1017 num2str(doy), ' in year ', num2str(year), ' at cell', num2str(k), '!')
1018 pet = fasp(k) * pet_hargreaves( &
1019 harsamcoeff=harsamcoeff(k), &
1021 tavg=self%L1_temp(i, mts_temp), &
1022 tmax=self%L1_tmax(i, mts_tmax), &
1023 tmin=self%L1_tmin(i, mts_tmin), &
1024 latitude=latitude(k), &
1025 doy=doy)
1026
1027 case(2) ! Priestley-Taylor
1028 ! Priestley Taylor is not defined for values netrad < 0.0_dp
1029 pet = pet_priestly( &
1030 prietayparam=prietayalpha(k), &
1031 rn=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1032 tavg=self%L1_temp(i, mts_temp))
1033
1034 case(3) ! Penman-Monteith
1035 pet = pet_penman( &
1036 net_rad=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1037 tavg=self%L1_temp(i, mts_temp), &
1038 act_vap_pressure=self%L1_absvappress(i, mts_avp) / 1000.0_dp, &
1039 aerodyn_resistance=aeroresist(k) / self%L1_windspeed(i, mts_ws), &
1040 bulksurface_resistance=surfresist(k), &
1041 a_s=1.0_dp, &
1042 a_sh=1.0_dp)
1043 end select
1044
1045 ! temporal disaggreagtion of forcing variables
1046 if (self%is_hourly_forcing) then
1047 pet_calc(k) = pet
1048 else
1049 if (self%read_meteo_weights) then
1050 ! all meteo forcings are disaggregated with given weights
1052 meteo_val_day=pet, &
1053 meteo_val_weights=self%L1_pet_weights(s1 - 1 + k, month, hour + 1), &
1054 meteo_val=pet_calc(k))
1055 else
1056 ! all meteo forcings are disaggregated with day-night correction values
1058 isday=isday, &
1059 ntimesteps_day=self%nTstepDay_dp, &
1060 meteo_val_day=pet, &
1061 fday_meteo_val=self%fday_pet(month), &
1062 fnight_meteo_val=self%fnight_pet(month), &
1063 meteo_val=pet_calc(k))
1064 end if
1065 end if
1066 end do
1067 !$OMP end do
1068 !$OMP end parallel
1069
1070 end subroutine get_corrected_pet
1071
1072 !> \brief get surface temperature for the current timestep and domain
1073 subroutine get_temp(self, temp_calc)
1074
1075 use mo_julian, only : dec2date
1077 use mo_constants, only : t0_dp ! 273.15 - Celcius <-> Kelvin [K]
1078
1079 implicit none
1080
1081 class(meteo_handler_type), intent(inout) :: self
1082 !> [degC] temperature for current time step
1083 real(dp), dimension(:), intent(inout) :: temp_calc
1084
1085 logical :: isday, is_hourly
1086 integer(i4) :: year, month, day, hour
1087 type(datetime) :: curr_dt
1088 type(timedelta) :: meteo_time_delta
1089
1090 ! number of L1 cells
1091 integer(i4) :: nCells1
1092 ! cell index
1093 integer(i4) :: k, i, s1, mTS
1094
1095 ! date and month of this timestep
1096 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1097
1098 ncells1 = self%e1 - self%s1 + 1
1099 s1 = self%s1
1100 if (self%couple_temp) then
1101 curr_dt = datetime(year, month, day, hour)
1102 meteo_time_delta = curr_dt - self%couple_temp_time
1103 ! check that the temperature from the interface has the correct time-stamp
1104 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1105 call error_message("meteo_handler: temperature was expected from coupler, but has a wrong time-stamp.")
1106 mts = 1_i4
1107 is_hourly = self%couple_is_hourly
1108 else
1109 mts = self%iMeteoTS
1110 is_hourly = self%is_hourly_forcing
1111 end if
1112
1113 ! shortcut hourly data
1114 if (is_hourly) then
1115 temp_calc(:) = self%L1_temp(self%s_meteo : self%e_meteo, mts)
1116 return
1117 end if
1118
1119 ! flag for day or night depending on hours of the day
1120 isday = (hour .gt. 6) .AND. (hour .le. 18)
1121
1122 !$OMP parallel default(shared) &
1123 !$OMP private(k, i)
1124 !$OMP do SCHEDULE(STATIC)
1125 do k = 1, ncells1
1126
1127 ! correct index on concatenated arrays
1128 i = self%s_meteo - 1 + k
1129
1130 if (self%read_meteo_weights) then
1131 ! all meteo forcings are disaggregated with given weights
1133 meteo_val_day=self%L1_temp(i, mts), &
1134 meteo_val_weights=self%L1_temp_weights(s1 - 1 + k, month, hour + 1), &
1135 meteo_val=temp_calc(k), &
1136 weights_correction=t0_dp)
1137 else
1138 ! all meteo forcings are disaggregated with day-night correction values
1140 isday=isday, &
1141 ntimesteps_day=self%nTstepDay_dp, &
1142 meteo_val_day=self%L1_temp(i, mts), &
1143 fday_meteo_val=self%fday_temp(month), &
1144 fnight_meteo_val=self%fnight_temp(month), &
1145 meteo_val=temp_calc(k), &
1146 add_correction=.true.)
1147 end if
1148 end do
1149 !$OMP end do
1150 !$OMP end parallel
1151
1152 end subroutine get_temp
1153
1154 !> \brief get precipitation for the current timestep and domain
1155 subroutine get_prec(self, prec_calc)
1156
1157 use mo_julian, only : dec2date
1159
1160 implicit none
1161
1162 class(meteo_handler_type), intent(inout) :: self
1163 !> [mm TS-1] precipitation for current time step
1164 real(dp), dimension(:), intent(inout) :: prec_calc
1165
1166 logical :: isday, is_hourly
1167 integer(i4) :: year, month, day, hour
1168 type(datetime) :: curr_dt
1169 type(timedelta) :: meteo_time_delta
1170
1171 ! number of L1 cells
1172 integer(i4) :: nCells1
1173 ! cell index
1174 integer(i4) :: k, i, s1, mTS
1175
1176 ! date and month of this timestep
1177 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1178
1179 ncells1 = self%e1 - self%s1 + 1
1180 s1 = self%s1
1181 if (self%couple_pre) then
1182 curr_dt = datetime(year, month, day, hour)
1183 meteo_time_delta = curr_dt - self%couple_pre_time
1184 ! check that the precipitation from the interface has the correct time-stamp
1185 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1186 call error_message("meteo_handler: precipitation was expected from coupler, but has a wrong time-stamp.")
1187 mts = 1_i4
1188 is_hourly = self%couple_is_hourly
1189 else
1190 mts = self%iMeteoTS
1191 is_hourly = self%is_hourly_forcing
1192 end if
1193
1194 ! shortcut hourly data
1195 if (is_hourly) then
1196 prec_calc(:) = self%L1_pre(self%s_meteo : self%e_meteo, mts)
1197 return
1198 end if
1199
1200 ! flag for day or night depending on hours of the day
1201 isday = (hour .gt. 6) .AND. (hour .le. 18)
1202
1203 !$OMP parallel default(shared) &
1204 !$OMP private(k, i)
1205 !$OMP do SCHEDULE(STATIC)
1206 do k = 1, ncells1
1207
1208 ! correct index on concatenated arrays
1209 i = self%s_meteo - 1 + k
1210
1211 ! temporal disaggreagtion of forcing variables
1212 if (self%read_meteo_weights) then
1213 ! all meteo forcings are disaggregated with given weights
1215 meteo_val_day=self%L1_pre(i, mts), &
1216 meteo_val_weights=self%L1_pre_weights(s1 - 1 + k, month, hour + 1), &
1217 meteo_val=prec_calc(k))
1218 else
1219 ! all meteo forcings are disaggregated with day-night correction values
1221 isday=isday, &
1222 ntimesteps_day=self%nTstepDay_dp, &
1223 meteo_val_day=self%L1_pre(i, mts), &
1224 fday_meteo_val=self%fday_prec(month), &
1225 fnight_meteo_val=self%fnight_prec(month), &
1226 meteo_val=prec_calc(k))
1227 end if
1228 end do
1229 !$OMP end do
1230 !$OMP end parallel
1231
1232 end subroutine get_prec
1233
1234 !> \brief get surface short-wave (solar) radiation downwards for the current timestep and domain
1235 subroutine get_ssrd(self, ssrd_calc)
1236
1237 use mo_julian, only : dec2date
1239
1240 implicit none
1241
1242 class(meteo_handler_type), intent(inout) :: self
1243 !> [W m2] surface short-wave (solar) radiation downwards for current time step
1244 real(dp), dimension(:), intent(inout) :: ssrd_calc
1245
1246 logical :: isday, is_hourly
1247 integer(i4) :: year, month, day, hour
1248 type(datetime) :: curr_dt
1249 type(timedelta) :: meteo_time_delta
1250
1251 ! number of L1 cells
1252 integer(i4) :: nCells1
1253 ! cell index
1254 integer(i4) :: k, i, s1, mTS
1255
1256 ! date and month of this timestep
1257 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1258
1259 ncells1 = self%e1 - self%s1 + 1
1260 s1 = self%s1
1261 if (self%couple_ssrd) then
1262 curr_dt = datetime(year, month, day, hour)
1263 meteo_time_delta = curr_dt - self%couple_ssrd_time
1264 ! check that the ssrd from the interface has the correct time-stamp
1265 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1266 call error_message("meteo_handler: ssrd was expected from coupler, but has a wrong time-stamp.")
1267 mts = 1_i4
1268 is_hourly = self%couple_is_hourly
1269 else
1270 mts = self%iMeteoTS
1271 is_hourly = self%is_hourly_forcing
1272 end if
1273
1274 ! shortcut hourly data
1275 if (is_hourly) then
1276 ssrd_calc(:) = self%L1_ssrd(self%s_meteo : self%e_meteo, mts)
1277 return
1278 end if
1279
1280 ! flag for day or night depending on hours of the day
1281 isday = (hour .gt. 6) .AND. (hour .le. 18)
1282
1283 !$OMP parallel default(shared) &
1284 !$OMP private(k, i)
1285 !$OMP do SCHEDULE(STATIC)
1286 do k = 1, ncells1
1287 ! correct index on concatenated arrays
1288 i = self%s_meteo - 1 + k
1289 ! TODO-RIV-TEMP: add weights for ssrd
1290 ! temporal disaggreagtion of forcing variables
1292 isday=isday, &
1293 ntimesteps_day=self%nTstepDay_dp, &
1294 meteo_val_day=self%L1_ssrd(i, mts), &
1295 fday_meteo_val=self%fday_ssrd(month), &
1296 fnight_meteo_val=self%fnight_ssrd(month), &
1297 meteo_val=ssrd_calc(k) &
1298 )
1299 end do
1300 !$OMP end do
1301 !$OMP end parallel
1302
1303 end subroutine get_ssrd
1304
1305 !> \brief get surface long-wave (thermal) radiation downwards for the current timestep and domain
1306 subroutine get_strd(self, strd_calc)
1307
1308 use mo_julian, only : dec2date
1310
1311 implicit none
1312
1313 class(meteo_handler_type), intent(inout) :: self
1314 !> [W m2] surface long-wave (thermal) radiation downwards for current time step
1315 real(dp), dimension(:), intent(inout) :: strd_calc
1316
1317 logical :: isday, is_hourly
1318 integer(i4) :: year, month, day, hour
1319 type(datetime) :: curr_dt
1320 type(timedelta) :: meteo_time_delta
1321
1322 ! number of L1 cells
1323 integer(i4) :: nCells1
1324 ! cell index
1325 integer(i4) :: k, i, s1, mTS
1326
1327 ! date and month of this timestep
1328 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1329
1330 ncells1 = self%e1 - self%s1 + 1
1331 s1 = self%s1
1332 if (self%couple_strd) then
1333 curr_dt = datetime(year, month, day, hour)
1334 meteo_time_delta = curr_dt - self%couple_strd_time
1335 ! check that the strd from the interface has the correct time-stamp
1336 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1337 call error_message("meteo_handler: strd was expected from coupler, but has a wrong time-stamp.")
1338 mts = 1_i4
1339 is_hourly = self%couple_is_hourly
1340 else
1341 mts = self%iMeteoTS
1342 is_hourly = self%is_hourly_forcing
1343 end if
1344
1345 ! shortcut hourly data
1346 if (is_hourly) then
1347 strd_calc(:) = self%L1_strd(self%s_meteo : self%e_meteo, mts)
1348 return
1349 end if
1350
1351 ! flag for day or night depending on hours of the day
1352 isday = (hour .gt. 6) .AND. (hour .le. 18)
1353
1354 !$OMP parallel default(shared) &
1355 !$OMP private(k, i)
1356 !$OMP do SCHEDULE(STATIC)
1357 do k = 1, ncells1
1358 ! correct index on concatenated arrays
1359 i = self%s_meteo - 1 + k
1360 ! TODO-RIV-TEMP: add weights for strd
1361 ! temporal disaggreagtion of forcing variables
1363 isday=isday, &
1364 ntimesteps_day=self%nTstepDay_dp, &
1365 meteo_val_day=self%L1_strd(i, mts), &
1366 fday_meteo_val=self%fday_strd(month), &
1367 fnight_meteo_val=self%fnight_strd(month), &
1368 meteo_val=strd_calc(k) &
1369 )
1370 end do
1371 !$OMP end do
1372 !$OMP end parallel
1373
1374 end subroutine get_strd
1375
1376 !> \brief get annual mean surface temperature for the current timestep and domain
1377 subroutine get_tann(self, tann_calc)
1378 use mo_julian, only : dec2date
1379
1380 implicit none
1381
1382 class(meteo_handler_type), intent(inout) :: self
1383 !> [degC] annual mean air temperature
1384 real(dp), dimension(:), intent(inout) :: tann_calc
1385
1386 type(datetime) :: curr_dt
1387 type(timedelta) :: meteo_time_delta
1388 integer(i4) :: year, month, day, hour, mTS
1389
1390 if (self%couple_tann) then
1391 ! date and month of this timestep
1392 call dec2date(self%time, yy=year, mm=month, dd=day, hh=hour)
1393 curr_dt = datetime(year, month, day, hour)
1394 meteo_time_delta = curr_dt - self%couple_tann_time
1395 ! check that the tann from the interface has the correct time-stamp
1396 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1397 call error_message("meteo_handler: tann was expected from coupler, but has a wrong time-stamp.")
1398 mts = 1_i4
1399 else
1400 mts = self%iMeteoTS
1401 end if
1402
1403 ! annual temperature is not disaggregated
1404 tann_calc(:) = self%L1_tann(self%s_meteo : self%e_meteo, mts)
1405
1406 end subroutine get_tann
1407
1408 !> \brief set meteo_data from coupling
1409 subroutine set_meteo(self, &
1410 year, month, day, hour, &
1411 pre, &
1412 temp, &
1413 pet, &
1414 tmin, &
1415 tmax, &
1416 netrad, &
1417 absvappress, &
1418 windspeed, &
1419 ssrd, &
1420 strd, &
1421 tann)
1422 implicit none
1423 class(meteo_handler_type), intent(inout) :: self
1424 integer(i4), intent(in) :: year
1425 integer(i4), intent(in) :: month
1426 integer(i4), intent(in) :: day
1427 integer(i4), intent(in), optional :: hour
1428 real(dp), dimension(:), optional, intent(in) :: pre
1429 real(dp), dimension(:), optional, intent(in) :: temp
1430 real(dp), dimension(:), optional, intent(in) :: pet
1431 real(dp), dimension(:), optional, intent(in) :: tmin
1432 real(dp), dimension(:), optional, intent(in) :: tmax
1433 real(dp), dimension(:), optional, intent(in) :: netrad
1434 real(dp), dimension(:), optional, intent(in) :: absvappress
1435 real(dp), dimension(:), optional, intent(in) :: windspeed
1436 real(dp), dimension(:), optional, intent(in) :: ssrd
1437 real(dp), dimension(:), optional, intent(in) :: strd
1438 real(dp), dimension(:), optional, intent(in) :: tann
1439
1440 integer(i4) :: hour_
1441 type(datetime) :: input_time
1442
1443 if (.not. self%couple_cfg%active()) &
1444 call error_message("meteo_handler%set_meteo: coupling was not activated.")
1445
1446 ! determine input time
1447 hour_ = -1_i4
1448 if (present(hour)) then
1449 hour_ = hour
1450 else if (self%couple_cfg%meteo_timestep == 24_i4) then
1451 hour_ = 0_i4
1452 end if
1453 if (hour_ == -1_i4) &
1454 call error_message("meteo_handler%set_meteo: hour for the meteo date needs to be given if the timestep is not daily.")
1455 input_time = datetime(year, month, day, hour_)
1456
1457 ! fix input time, if reference point is at the end of the time interval
1458 if (self%couple_cfg%meteo_time_ref_endpoint) input_time = input_time - self%couple_step_delta
1459
1460 ! check if input time matches the required time step
1461 if (mod(input_time%hour, self%couple_cfg%meteo_timestep) /= 0) &
1462 call error_message("meteo_handler%set_meteo: given time doesn't match couple timestep: ", input_time%str())
1463
1464 ! precipitation
1465 if (present(pre)) then
1466 if (.not. self%couple_pre) &
1467 call error_message("meteo_handler%set_meteo: precipitation was not set to be coupled.")
1468 self%couple_pre_time = input_time
1469 self%L1_pre(:, 1_i4) = pre(:)
1470 end if
1471
1472 ! temperature
1473 if (present(temp)) then
1474 if (.not. self%couple_temp) &
1475 call error_message("meteo_handler%set_meteo: avg. temperature was not set to be coupled.")
1476 self%couple_temp_time = input_time
1477 self%L1_temp(:, 1_i4) = temp(:)
1478 end if
1479
1480 ! PET
1481 if (present(pet)) then
1482 if (.not. self%couple_pet) &
1483 call error_message("meteo_handler%set_meteo: PET was not set to be coupled.")
1484 self%couple_pet_time = input_time
1485 self%L1_pet(:, 1_i4) = pet(:)
1486 end if
1487
1488 ! tmin
1489 if (present(tmin)) then
1490 if (.not. self%couple_tmin) &
1491 call error_message("meteo_handler%set_meteo: tmin was not set to be coupled.")
1492 self%couple_tmin_time = input_time
1493 self%L1_tmin(:, 1_i4) = tmin(:)
1494 end if
1495
1496 ! tmax
1497 if (present(tmax)) then
1498 if (.not. self%couple_tmax) &
1499 call error_message("meteo_handler%set_meteo: tmax was not set to be coupled.")
1500 self%couple_tmax_time = input_time
1501 self%L1_tmax(:, 1_i4) = tmax(:)
1502 end if
1503
1504 ! netrad
1505 if (present(netrad)) then
1506 if (.not. self%couple_netrad) &
1507 call error_message("meteo_handler%set_meteo: netrad was not set to be coupled.")
1508 self%couple_netrad_time = input_time
1509 self%L1_netrad(:, 1_i4) = netrad(:)
1510 end if
1511
1512 ! absvappress
1513 if (present(absvappress)) then
1514 if (.not. self%couple_absvappress) &
1515 call error_message("meteo_handler%set_meteo: absvappress was not set to be coupled.")
1516 self%couple_absvappress_time = input_time
1517 self%L1_absvappress(:, 1_i4) = absvappress(:)
1518 end if
1519
1520 ! windspeed
1521 if (present(windspeed)) then
1522 if (.not. self%couple_windspeed) &
1523 call error_message("meteo_handler%set_meteo: windspeed was not set to be coupled.")
1524 self%couple_windspeed_time = input_time
1525 self%L1_windspeed(:, 1_i4) = windspeed(:)
1526 end if
1527
1528 ! ssrd
1529 if (present(ssrd)) then
1530 if (.not. self%couple_ssrd) &
1531 call error_message("meteo_handler%set_meteo: ssrd was not set to be coupled.")
1532 self%couple_ssrd_time = input_time
1533 self%L1_ssrd(:, 1_i4) = ssrd(:)
1534 end if
1535
1536 ! strd
1537 if (present(strd)) then
1538 if (.not. self%couple_strd) &
1539 call error_message("meteo_handler%set_meteo: strd was not set to be coupled.")
1540 self%couple_strd_time = input_time
1541 self%L1_strd(:, 1_i4) = strd(:)
1542 end if
1543
1544 ! tann
1545 if (present(tann)) then
1546 if (.not. self%couple_tann) &
1547 call error_message("meteo_handler%set_meteo: tann was not set to be coupled.")
1548 self%couple_tann_time = input_time
1549 self%L1_tann(:, 1_i4) = tann(:)
1550 end if
1551
1552 end subroutine set_meteo
1553
1554end 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 check_header(ncols, nrows, xllcorner, yllcorner, cellsize, ref_ncols, ref_nrows, ref_xllcorner, ref_yllcorner, ref_cellsize, tolerance, context)
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.