243 subroutine config(self, file_namelist, optimize, domainMeta, processMatrix, timeStep, couple_cfg)
253 character(*),
intent(in) :: file_namelist
254 logical,
intent(in) :: optimize
256 integer(i4),
dimension(nProcesses, 3),
intent(in) :: processMatrix
257 integer(i4),
intent(in) :: timeStep
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
272 integer(i4) :: domainID, iDomain
275 self%couple_cfg = couple_cfg
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(:)
288 self%pet_case = processmatrix(5,1)
289 self%riv_temp_case = processmatrix(11,1)
291 self%timeStep = timestep
292 self%nTStepDay = 24_i4 / timestep
293 self%nTstepDay_dp = real(self%nTStepDay, dp)
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))
307 allocate(self%timestep_model_inputs(self%nDomains))
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)
340 self%dirRadiation(idomain) = dir_radiation(domainid)
342 if (check_sentinel(dir_meteo_header(domainid)))
then
343 self%dir_meteo_header(idomain) = self%dirPrecipitation(idomain)
345 self%dir_meteo_header(idomain) = dir_meteo_header(domainid)
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')
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)')
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
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()
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()
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()
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()
409 self%couple_all = self%couple_cfg%meteo_expect_pre .and. self%couple_cfg%meteo_expect_temp
410 select case (self%pet_case)
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.")
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.")
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.")
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.")
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.")
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
608 use mo_string_utils,
only : num2str
609 use mo_timer,
only : timer_get, timer_start, timer_stop
615 integer(i4),
intent(in) :: tt
616 integer(i4),
intent(in) :: iDomain
618 type(grid),
dimension(:),
intent(in) :: level1
620 type(period),
dimension(:),
intent(in) :: simPer
624 integer(i4) :: domainID
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))
639 domainid = self%indices(idomain)
642 call chunk_config(idomain, tt, self%nTstepDay, simper, self%timestep, self%timeStep_model_inputs, read_flag, self%readPer)
650 if (self%single_read(idomain))
call message(
' read meteo weights for tavg ...')
652 self%L1_temp_weights, level1=level1, level2=self%level2, ncvarname =
'tavg_weight')
654 if (self%single_read(idomain))
call message(
' read meteo weights for pet ...')
656 self%L1_pet_weights, level1=level1, level2=self%level2, ncvarname =
'pet_weight')
658 if (self%single_read(idomain))
call message(
' read meteo weights for pre ...')
660 self%L1_pre_weights, level1=level1, level2=self%level2, ncvarname =
'pre_weight')
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)
676 if (self%single_read(idomain))
then
677 call message(
' Reading meteorological forcings for Domain: ', trim(adjustl(num2str(domainid))),
' ...')
682 if (.not. self%couple_pre)
then
683 if (self%single_read(idomain))
call message(
' read precipitation ...')
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)
692 if (.not. self%couple_temp)
then
693 if (self%single_read(idomain))
call message(
' read temperature ...')
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)
702 select case (self%pet_case)
704 if (.not. self%couple_pet)
then
705 if (self%single_read(idomain))
call message(
' read pet ...')
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)
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))
721 if (.not. self%couple_tmin)
then
722 if (self%single_read(idomain))
call message(
' read min. temperature ...')
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)
728 if (.not. self%couple_tmax)
then
729 if (self%single_read(idomain))
call message(
' read max. temperature ...')
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)
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))
744 if (.not. self%couple_netrad)
then
745 if (self%single_read(idomain))
call message(
' read net radiation ...')
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)
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))
761 if (.not. self%couple_netrad)
then
762 if (self%single_read(idomain))
call message(
' read net radiation ...')
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)
768 if (.not. self%couple_absvappress)
then
769 if (self%single_read(idomain))
call message(
' read absolute vapour pressure ...')
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)
775 if (.not. self%couple_windspeed)
then
776 if (self%single_read(idomain))
call message(
' read windspeed ...')
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)
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))
791 if ( self%riv_temp_case .ne. 0 )
then
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)
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)
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)
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)
824 if (self%single_read(idomain))
then
826 call message(
' in ', trim(num2str(timer_get(1),
'(F9.3)')),
' seconds.')
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
836 self%is_hourly_forcing = (self%nTstepForcingDay .eq. 24_i4)
840 select case (self%pet_case)
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.")
848 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
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.")
858 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
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.")
868 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
877 petLAIcorFactorL1, fAsp, HarSamCoeff, latitude, PrieTayAlpha, aeroResist, surfResist)
880 use mo_julian,
only : date2dec, dec2date
882 use mo_string_utils,
only : num2str
889 real(dp),
dimension(:),
intent(inout) :: pet_calc
891 real(dp),
dimension(:),
intent(in) :: petLAIcorFactorL1
893 real(dp),
dimension(:),
intent(in) :: fAsp
895 real(dp),
dimension(:),
intent(in) :: HarSamCoeff
897 real(dp),
dimension(:),
intent(in) :: latitude
899 real(dp),
dimension(:),
intent(in) :: PrieTayAlpha
901 real(dp),
dimension(:),
intent(in) :: aeroResist
903 real(dp),
dimension(:),
intent(in) :: surfResist
907 logical :: isday, is_hourly
908 integer(i4) :: year, month, day, hour
909 type(datetime) :: curr_dt
910 type(timedelta) :: meteo_time_delta
916 integer(i4) :: nCells1
918 integer(i4) :: k, i, s1
920 integer(i4) :: mTS_pet, mTS_temp, mTS_tmin, mTS_tmax, mTS_rn, mTS_avp, mTS_ws
923 call dec2date(self%time, yy = year, mm = month, dd = day, hh = hour)
924 curr_dt = datetime(year, month, day, hour)
927 ncells1 = self%e1 - self%s1 + 1
930 if (self%couple_pet)
then
931 meteo_time_delta = curr_dt - self%couple_pet_time
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.")
936 is_hourly = self%couple_is_hourly
938 mts_pet = self%iMeteoTS
939 is_hourly = self%is_hourly_forcing
942 if (self%couple_temp)
then
943 meteo_time_delta = curr_dt - self%couple_temp_time
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.")
950 mts_temp = self%iMeteoTS
953 if (self%couple_tmin)
then
954 meteo_time_delta = curr_dt - self%couple_tmin_time
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.")
961 mts_tmin = self%iMeteoTS
964 if (self%couple_tmax)
then
965 meteo_time_delta = curr_dt - self%couple_tmax_time
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.")
972 mts_tmax = self%iMeteoTS
975 if (self%couple_netrad)
then
976 meteo_time_delta = curr_dt - self%couple_netrad_time
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.")
983 mts_rn = self%iMeteoTS
986 if (self%couple_absvappress)
then
987 meteo_time_delta = curr_dt - self%couple_absvappress_time
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.")
994 mts_avp = self%iMeteoTS
997 if (self%couple_windspeed)
then
998 meteo_time_delta = curr_dt - self%couple_windspeed_time
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.")
1005 mts_ws = self%iMeteoTS
1009 isday = (hour .gt. 6) .AND. (hour .le. 18)
1017 i = self%s_meteo - 1 + k
1020 select case (self%pet_case)
1022 pet = petlaicorfactorl1(k) * self%L1_pet(i, mts_pet)
1025 pet = fasp(k) * self%L1_pet(i, mts_pet)
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),
'!')
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), &
1044 prietayparam=prietayalpha(k), &
1045 rn=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1046 tavg=self%L1_temp(i, mts_temp))
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), &
1060 if (self%is_hourly_forcing)
then
1063 if (self%read_meteo_weights)
then
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))
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))
1424 year, month, day, hour, &
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
1454 integer(i4) :: hour_
1455 type(datetime) :: input_time
1457 if (.not. self%couple_cfg%active()) &
1458 call error_message(
"meteo_handler%set_meteo: coupling was not activated.")
1462 if (
present(hour))
then
1464 else if (self%couple_cfg%meteo_timestep == 24_i4)
then
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_)
1472 if (self%couple_cfg%meteo_time_ref_endpoint) input_time = input_time - self%couple_step_delta
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())
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)