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
594 use mo_string_utils,
only : num2str
595 use mo_timer,
only : timer_get, timer_start, timer_stop
601 integer(i4),
intent(in) :: tt
602 integer(i4),
intent(in) :: iDomain
604 type(grid),
dimension(:),
intent(in) :: level1
606 type(period),
dimension(:),
intent(in) :: simPer
610 integer(i4) :: domainID
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))
625 domainid = self%indices(idomain)
628 call chunk_config(idomain, tt, self%nTstepDay, simper, self%timestep, self%timeStep_model_inputs, read_flag, self%readPer)
636 if (self%single_read(idomain))
call message(
' read meteo weights for tavg ...')
638 self%L1_temp_weights, level1=level1, level2=self%level2, ncvarname =
'tavg_weight')
640 if (self%single_read(idomain))
call message(
' read meteo weights for pet ...')
642 self%L1_pet_weights, level1=level1, level2=self%level2, ncvarname =
'pet_weight')
644 if (self%single_read(idomain))
call message(
' read meteo weights for pre ...')
646 self%L1_pre_weights, level1=level1, level2=self%level2, ncvarname =
'pre_weight')
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)
662 if (self%single_read(idomain))
then
663 call message(
' Reading meteorological forcings for Domain: ', trim(adjustl(num2str(domainid))),
' ...')
668 if (.not. self%couple_pre)
then
669 if (self%single_read(idomain))
call message(
' read precipitation ...')
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)
678 if (.not. self%couple_temp)
then
679 if (self%single_read(idomain))
call message(
' read temperature ...')
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)
688 select case (self%pet_case)
690 if (.not. self%couple_pet)
then
691 if (self%single_read(idomain))
call message(
' read pet ...')
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)
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))
707 if (.not. self%couple_tmin)
then
708 if (self%single_read(idomain))
call message(
' read min. temperature ...')
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)
714 if (.not. self%couple_tmax)
then
715 if (self%single_read(idomain))
call message(
' read max. temperature ...')
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)
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))
730 if (.not. self%couple_netrad)
then
731 if (self%single_read(idomain))
call message(
' read net radiation ...')
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)
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))
747 if (.not. self%couple_netrad)
then
748 if (self%single_read(idomain))
call message(
' read net radiation ...')
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)
754 if (.not. self%couple_absvappress)
then
755 if (self%single_read(idomain))
call message(
' read absolute vapour pressure ...')
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)
761 if (.not. self%couple_windspeed)
then
762 if (self%single_read(idomain))
call message(
' read windspeed ...')
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)
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))
777 if ( self%riv_temp_case .ne. 0 )
then
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)
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)
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)
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)
810 if (self%single_read(idomain))
then
812 call message(
' in ', trim(num2str(timer_get(1),
'(F9.3)')),
' seconds.')
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
822 self%is_hourly_forcing = (self%nTstepForcingDay .eq. 24_i4)
826 select case (self%pet_case)
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.")
834 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
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.")
844 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
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.")
854 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
863 petLAIcorFactorL1, fAsp, HarSamCoeff, latitude, PrieTayAlpha, aeroResist, surfResist)
866 use mo_julian,
only : date2dec, dec2date
868 use mo_string_utils,
only : num2str
875 real(dp),
dimension(:),
intent(inout) :: pet_calc
877 real(dp),
dimension(:),
intent(in) :: petLAIcorFactorL1
879 real(dp),
dimension(:),
intent(in) :: fAsp
881 real(dp),
dimension(:),
intent(in) :: HarSamCoeff
883 real(dp),
dimension(:),
intent(in) :: latitude
885 real(dp),
dimension(:),
intent(in) :: PrieTayAlpha
887 real(dp),
dimension(:),
intent(in) :: aeroResist
889 real(dp),
dimension(:),
intent(in) :: surfResist
893 logical :: isday, is_hourly
894 integer(i4) :: year, month, day, hour
895 type(datetime) :: curr_dt
896 type(timedelta) :: meteo_time_delta
902 integer(i4) :: nCells1
904 integer(i4) :: k, i, s1
906 integer(i4) :: mTS_pet, mTS_temp, mTS_tmin, mTS_tmax, mTS_rn, mTS_avp, mTS_ws
909 call dec2date(self%time, yy = year, mm = month, dd = day, hh = hour)
910 curr_dt = datetime(year, month, day, hour)
913 ncells1 = self%e1 - self%s1 + 1
916 if (self%couple_pet)
then
917 meteo_time_delta = curr_dt - self%couple_pet_time
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.")
922 is_hourly = self%couple_is_hourly
924 mts_pet = self%iMeteoTS
925 is_hourly = self%is_hourly_forcing
928 if (self%couple_temp)
then
929 meteo_time_delta = curr_dt - self%couple_temp_time
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.")
936 mts_temp = self%iMeteoTS
939 if (self%couple_tmin)
then
940 meteo_time_delta = curr_dt - self%couple_tmin_time
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.")
947 mts_tmin = self%iMeteoTS
950 if (self%couple_tmax)
then
951 meteo_time_delta = curr_dt - self%couple_tmax_time
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.")
958 mts_tmax = self%iMeteoTS
961 if (self%couple_netrad)
then
962 meteo_time_delta = curr_dt - self%couple_netrad_time
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.")
969 mts_rn = self%iMeteoTS
972 if (self%couple_absvappress)
then
973 meteo_time_delta = curr_dt - self%couple_absvappress_time
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.")
980 mts_avp = self%iMeteoTS
983 if (self%couple_windspeed)
then
984 meteo_time_delta = curr_dt - self%couple_windspeed_time
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.")
991 mts_ws = self%iMeteoTS
995 isday = (hour .gt. 6) .AND. (hour .le. 18)
1003 i = self%s_meteo - 1 + k
1006 select case (self%pet_case)
1008 pet = petlaicorfactorl1(k) * self%L1_pet(i, mts_pet)
1011 pet = fasp(k) * self%L1_pet(i, mts_pet)
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),
'!')
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), &
1030 prietayparam=prietayalpha(k), &
1031 rn=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1032 tavg=self%L1_temp(i, mts_temp))
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), &
1046 if (self%is_hourly_forcing)
then
1049 if (self%read_meteo_weights)
then
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))
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))
1410 year, month, day, hour, &
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
1440 integer(i4) :: hour_
1441 type(datetime) :: input_time
1443 if (.not. self%couple_cfg%active()) &
1444 call error_message(
"meteo_handler%set_meteo: coupling was not activated.")
1448 if (
present(hour))
then
1450 else if (self%couple_cfg%meteo_timestep == 24_i4)
then
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_)
1458 if (self%couple_cfg%meteo_time_ref_endpoint) input_time = input_time - self%couple_step_delta
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())
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)
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(:)