243 subroutine config(self, file_namelist, unamelist, optimize, domainMeta, processMatrix, timeStep, couple_cfg)
247 use mo_nml,
only : close_nml, open_nml, position_nml
253 character(*),
intent(in) :: file_namelist
254 integer,
intent(in) :: unamelist
255 logical,
intent(in) :: optimize
257 integer(i4),
dimension(nProcesses, 3),
intent(in) :: processMatrix
258 integer(i4),
intent(in) :: timeStep
261 integer(i4),
dimension(maxNoDomains) :: time_step_model_inputs
262 character(256),
dimension(maxNoDomains) :: dir_meteo_header
263 character(256),
dimension(maxNoDomains) :: dir_Precipitation
264 character(256),
dimension(maxNoDomains) :: dir_Temperature
265 character(256),
dimension(maxNoDomains) :: dir_MinTemperature
266 character(256),
dimension(maxNoDomains) :: dir_MaxTemperature
267 character(256),
dimension(maxNoDomains) :: dir_NetRadiation
268 character(256),
dimension(maxNoDomains) :: dir_windspeed
269 character(256),
dimension(maxNoDomains) :: dir_absVapPressure
270 character(256),
dimension(maxNoDomains) :: dir_ReferenceET
271 character(256),
dimension(maxNoDomains) :: dir_Radiation
272 character(256) :: inputFormat_meteo_forcings
274 logical :: read_meteo_weights, bound_error
275 real(dp),
dimension(int(YearMonths, i4)) :: fnight_prec
276 real(dp),
dimension(int(YearMonths, i4)) :: fnight_pet
277 real(dp),
dimension(int(YearMonths, i4)) :: fnight_temp
278 real(dp),
dimension(int(YearMonths, i4)) :: fnight_ssrd
279 real(dp),
dimension(int(YearMonths, i4)) :: fnight_strd
281 integer(i4) :: domainID, iDomain
284 namelist /directories_mhm/ &
285 inputformat_meteo_forcings, &
291 dir_mintemperature, &
292 dir_maxtemperature, &
293 dir_absvappressure, &
297 time_step_model_inputs
300 namelist /nightdayratio/ &
301 read_meteo_weights, &
309 self%couple_cfg = couple_cfg
312 self%nDomains = domainmeta%nDomains
313 allocate(self%indices(self%nDomains))
314 allocate(self%L0DataFrom(self%nDomains))
315 self%indices(:) = domainmeta%indices(:)
316 self%L0DataFrom(:) = domainmeta%L0DataFrom(:)
322 self%pet_case = processmatrix(5,1)
323 self%riv_temp_case = processmatrix(11,1)
325 self%timeStep = timestep
326 self%nTStepDay = 24_i4 / timestep
327 self%nTstepDay_dp = real(self%nTStepDay, dp)
330 allocate(self%dir_meteo_header(self%nDomains))
331 allocate(self%dirPrecipitation(self%nDomains))
332 allocate(self%dirTemperature(self%nDomains))
333 allocate(self%dirwindspeed(self%nDomains))
334 allocate(self%dirabsVapPressure(self%nDomains))
335 allocate(self%dirReferenceET(self%nDomains))
336 allocate(self%dirMinTemperature(self%nDomains))
337 allocate(self%dirMaxTemperature(self%nDomains))
338 allocate(self%dirNetRadiation(self%nDomains))
339 allocate(self%dirRadiation(self%nDomains))
341 allocate(self%timestep_model_inputs(self%nDomains))
344 call open_nml(file_namelist, unamelist, quiet=.true.)
349 call set_sentinel(dir_meteo_header)
350 inputformat_meteo_forcings =
"nc"
352 call position_nml(self%dir_nml_name, unamelist)
353 read(unamelist, nml = directories_mhm)
355 self%bound_error = bound_error
356 self%inputFormat_meteo_forcings = inputformat_meteo_forcings
358 do idomain = 1, self%nDomains
359 domainid = self%indices(idomain)
360 self%timestep_model_inputs(idomain) = time_step_model_inputs(domainid)
361 self%dirPrecipitation(idomain) = dir_precipitation(domainid)
362 self%dirTemperature(idomain) = dir_temperature(domainid)
363 self%dirReferenceET(idomain) = dir_referenceet(domainid)
364 self%dirMinTemperature(idomain) = dir_mintemperature(domainid)
365 self%dirMaxTemperature(idomain) = dir_maxtemperature(domainid)
366 self%dirNetRadiation(idomain) = dir_netradiation(domainid)
367 self%dirwindspeed(idomain) = dir_windspeed(domainid)
368 self%dirabsVapPressure(idomain) = dir_absvappressure(domainid)
370 self%dirRadiation(idomain) = dir_radiation(domainid)
372 if (check_sentinel(dir_meteo_header(domainid)))
then
373 self%dir_meteo_header(idomain) = self%dirPrecipitation(idomain)
375 self%dir_meteo_header(idomain) = dir_meteo_header(domainid)
380 if (any(self%timestep_model_inputs .ne. 0) .and. .not. all(self%timestep_model_inputs .ne. 0))
then
381 call error_message(
'***ERROR: timestep_model_inputs either have to be all zero or all non-zero')
384 if (optimize .and. (any(self%timestep_model_inputs .ne. 0)))
then
385 call error_message(
'***ERROR: optimize and chunk read is switched on! (set timestep_model_inputs to zero)')
393 fnight_strd = 0.45_dp
396 call position_nml(self%weight_nml_name, unamelist)
397 read(unamelist, nml = nightdayratio)
398 self%read_meteo_weights = read_meteo_weights
399 self%fnight_prec = fnight_prec
400 self%fnight_pet = fnight_pet
401 self%fnight_temp = fnight_temp
402 self%fnight_ssrd = fnight_ssrd
403 self%fnight_strd = fnight_strd
404 self%fday_prec = 1.0_dp - self%fnight_prec
405 self%fday_pet = 1.0_dp - self%fnight_pet
406 self%fday_temp = -1.0_dp * self%fnight_temp
407 self%fday_ssrd = 1.0_dp - self%fnight_ssrd
408 self%fday_strd = 1.0_dp - self%fnight_strd
414 call close_nml(unamelist)
417 self%couple_is_hourly = .false.
418 self%couple_all = .false.
419 self%couple_pre = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_pre
420 self%couple_temp = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_temp
421 self%couple_pet = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_pet
422 self%couple_tmin = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_tmin
423 self%couple_tmax = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_tmax
424 self%couple_netrad = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_netrad
425 self%couple_absvappress = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_absvappress
426 self%couple_windspeed = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_windspeed
427 self%couple_ssrd = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_ssrd
428 self%couple_strd = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_strd
429 self%couple_tann = self%couple_cfg%active() .and. self%couple_cfg%meteo_expect_tann
430 if (self%couple_cfg%active())
then
431 self%couple_step_delta = timedelta(hours=self%couple_cfg%meteo_timestep)
432 self%couple_is_hourly = self%couple_step_delta == one_hour()
434 if (self%couple_cfg%meteo_expect_pre) self%couple_pre_time = datetime()
435 if (self%couple_cfg%meteo_expect_temp) self%couple_temp_time = datetime()
437 if (self%couple_cfg%meteo_expect_pet) self%couple_pet_time = datetime()
438 if (self%couple_cfg%meteo_expect_tmin) self%couple_tmin_time = datetime()
439 if (self%couple_cfg%meteo_expect_tmax) self%couple_tmax_time = datetime()
440 if (self%couple_cfg%meteo_expect_netrad) self%couple_netrad_time = datetime()
441 if (self%couple_cfg%meteo_expect_absvappress) self%couple_absvappress_time = datetime()
442 if (self%couple_cfg%meteo_expect_windspeed) self%couple_windspeed_time = datetime()
444 if (self%couple_cfg%meteo_expect_ssrd) self%couple_ssrd_time = datetime()
445 if (self%couple_cfg%meteo_expect_strd) self%couple_strd_time = datetime()
446 if (self%couple_cfg%meteo_expect_tann) self%couple_tann_time = datetime()
448 self%couple_all = self%couple_cfg%meteo_expect_pre .and. self%couple_cfg%meteo_expect_temp
449 select case (self%pet_case)
451 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_pet
452 if (self%couple_cfg%meteo_expect_tmin)
call error_message(
"Coupling: tmin expected but not needed for PET.")
453 if (self%couple_cfg%meteo_expect_tmax)
call error_message(
"Coupling: tmax expected but not needed for PET.")
454 if (self%couple_cfg%meteo_expect_netrad)
call error_message(
"Coupling: netrad expected but not needed for PET.")
455 if (self%couple_cfg%meteo_expect_absvappress)
call error_message(
"Coupling: absvappress expected but not needed for PET.")
456 if (self%couple_cfg%meteo_expect_windspeed)
call error_message(
"Coupling: windspeed expected but not needed for PET.")
459 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_tmin
460 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_tmax
461 if (self%couple_cfg%meteo_expect_pet)
call error_message(
"Coupling: pet expected but not needed for PET.")
462 if (self%couple_cfg%meteo_expect_netrad)
call error_message(
"Coupling: netrad expected but not needed for PET.")
463 if (self%couple_cfg%meteo_expect_absvappress)
call error_message(
"Coupling: absvappress expected but not needed for PET.")
464 if (self%couple_cfg%meteo_expect_windspeed)
call error_message(
"Coupling: windspeed expected but not needed for PET.")
467 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_netrad
468 if (self%couple_cfg%meteo_expect_pet)
call error_message(
"Coupling: pet expected but not needed for PET.")
469 if (self%couple_cfg%meteo_expect_tmin)
call error_message(
"Coupling: tmin expected but not needed for PET.")
470 if (self%couple_cfg%meteo_expect_tmax)
call error_message(
"Coupling: tmax expected but not needed for PET.")
471 if (self%couple_cfg%meteo_expect_absvappress)
call error_message(
"Coupling: absvappress expected but not needed for PET.")
472 if (self%couple_cfg%meteo_expect_windspeed)
call error_message(
"Coupling: windspeed expected but not needed for PET.")
475 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_netrad
476 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_absvappress
477 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_windspeed
478 if (self%couple_cfg%meteo_expect_pet)
call error_message(
"Coupling: pet expected but not needed for PET.")
479 if (self%couple_cfg%meteo_expect_tmin)
call error_message(
"Coupling: tmin expected but not needed for PET.")
480 if (self%couple_cfg%meteo_expect_tmax)
call error_message(
"Coupling: tmax expected but not needed for PET.")
483 if ( self%riv_temp_case == 0 )
then
484 if (self%couple_cfg%meteo_expect_ssrd)
call error_message(
"Coupling: ssrd expected but river temperature not activated.")
485 if (self%couple_cfg%meteo_expect_strd)
call error_message(
"Coupling: strd expected but river temperature not activated.")
486 if (self%couple_cfg%meteo_expect_tann)
call error_message(
"Coupling: tann expected but river temperature not activated.")
488 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_ssrd
489 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_strd
490 self%couple_all = self%couple_all .and. self%couple_cfg%meteo_expect_tann
647 use mo_string_utils,
only : num2str
648 use mo_timer,
only : timer_get, timer_start, timer_stop
654 integer(i4),
intent(in) :: tt
655 integer(i4),
intent(in) :: iDomain
657 type(grid),
dimension(:),
intent(in) :: level1
659 type(period),
dimension(:),
intent(in) :: simPer
663 integer(i4) :: domainID
666 if (self%couple_pre .and. .not.
allocated(self%L1_pre))
allocate(self%L1_pre(level1(idomain)%nCells, 1))
667 if (self%couple_temp .and. .not.
allocated(self%L1_temp))
allocate(self%L1_temp(level1(idomain)%nCells, 1))
668 if (self%couple_pet .and. .not.
allocated(self%L1_pet))
allocate(self%L1_pet(level1(idomain)%nCells, 1))
669 if (self%couple_tmin .and. .not.
allocated(self%L1_tmin))
allocate(self%L1_tmin(level1(idomain)%nCells, 1))
670 if (self%couple_tmax .and. .not.
allocated(self%L1_tmax))
allocate(self%L1_tmax(level1(idomain)%nCells, 1))
671 if (self%couple_netrad .and. .not.
allocated(self%L1_netrad))
allocate(self%L1_netrad(level1(idomain)%nCells, 1))
672 if (self%couple_absvappress .and. .not.
allocated(self%L1_absvappress))
allocate(self%L1_absvappress(level1(idomain)%nCells, 1))
673 if (self%couple_windspeed .and. .not.
allocated(self%L1_windspeed))
allocate(self%L1_windspeed(level1(idomain)%nCells, 1))
674 if (self%couple_ssrd .and. .not.
allocated(self%L1_ssrd))
allocate(self%L1_ssrd(level1(idomain)%nCells, 1))
675 if (self%couple_strd .and. .not.
allocated(self%L1_strd))
allocate(self%L1_strd(level1(idomain)%nCells, 1))
676 if (self%couple_tann .and. .not.
allocated(self%L1_tann))
allocate(self%L1_tann(level1(idomain)%nCells, 1))
678 domainid = self%indices(idomain)
681 call chunk_config(idomain, tt, self%nTstepDay, simper, self%timestep, self%timeStep_model_inputs, read_flag, self%readPer)
689 if (self%single_read(idomain))
call message(
' read meteo weights for tavg ...')
691 self%L1_temp_weights, level1=level1, level2=self%level2, ncvarname =
'tavg_weight')
693 if (self%single_read(idomain))
call message(
' read meteo weights for pet ...')
695 self%L1_pet_weights, level1=level1, level2=self%level2, ncvarname =
'pet_weight')
697 if (self%single_read(idomain))
call message(
' read meteo weights for pre ...')
699 self%L1_pre_weights, level1=level1, level2=self%level2, ncvarname =
'pre_weight')
703 if (self%timeStep_model_inputs(idomain) .ne. 0)
then
704 if (.not. self%couple_pre .and.
allocated(self%L1_pre))
deallocate(self%L1_pre)
705 if (.not. self%couple_temp .and.
allocated(self%L1_temp))
deallocate(self%L1_temp)
706 if (.not. self%couple_pet .and.
allocated(self%L1_pet))
deallocate(self%L1_pet)
707 if (.not. self%couple_tmin .and.
allocated(self%L1_tmin))
deallocate(self%L1_tmin)
708 if (.not. self%couple_tmax .and.
allocated(self%L1_tmax))
deallocate(self%L1_tmax)
709 if (.not. self%couple_netrad .and.
allocated(self%L1_netrad))
deallocate(self%L1_netrad)
710 if (.not. self%couple_absvappress .and.
allocated(self%L1_absvappress))
deallocate(self%L1_absvappress)
711 if (.not. self%couple_windspeed .and.
allocated(self%L1_windspeed))
deallocate(self%L1_windspeed)
715 if (self%single_read(idomain))
then
716 call message(
' Reading meteorological forcings for Domain: ', trim(adjustl(num2str(domainid))),
' ...')
721 if (.not. self%couple_pre)
then
722 if (self%single_read(idomain))
call message(
' read precipitation ...')
725 dataout1=self%L1_pre, &
726 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
727 lower = 0.0_dp, upper = 2000._dp, ncvarname =
'pre', bound_error=self%bound_error)
731 if (.not. self%couple_temp)
then
732 if (self%single_read(idomain))
call message(
' read temperature ...')
734 dataout1=self%L1_temp, &
735 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
736 lower = -100._dp, upper = 100._dp, ncvarname =
'tavg', bound_error=self%bound_error)
741 select case (self%pet_case)
743 if (.not. self%couple_pet)
then
744 if (self%single_read(idomain))
call message(
' read pet ...')
746 dataout1=self%L1_pet, &
747 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
748 lower = 0.0_dp, upper = 1000._dp, ncvarname =
'pet', bound_error=self%bound_error)
751 if ((idomain.eq.self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0))
then
752 allocate(self%L1_tmin(1, 1))
753 allocate(self%L1_tmax(1, 1))
754 allocate(self%L1_netrad(1, 1))
755 allocate(self%L1_absvappress(1, 1))
756 allocate(self%L1_windspeed(1, 1))
760 if (.not. self%couple_tmin)
then
761 if (self%single_read(idomain))
call message(
' read min. temperature ...')
763 dataout1=self%L1_tmin, &
764 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
765 lower = -100.0_dp, upper = 100._dp, ncvarname =
'tmin', bound_error=self%bound_error)
767 if (.not. self%couple_tmax)
then
768 if (self%single_read(idomain))
call message(
' read max. temperature ...')
770 dataout1=self%L1_tmax, &
771 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
772 lower = -100.0_dp, upper = 100._dp, ncvarname =
'tmax', bound_error=self%bound_error)
775 if ((idomain .eq. self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0))
then
776 allocate(self%L1_pet (
size(self%L1_tmax, dim = 1),
size(self%L1_tmax, dim = 2)))
777 allocate(self%L1_netrad(1, 1))
778 allocate(self%L1_absvappress(1, 1))
779 allocate(self%L1_windspeed(1, 1))
783 if (.not. self%couple_netrad)
then
784 if (self%single_read(idomain))
call message(
' read net radiation ...')
786 dataout1=self%L1_netrad, &
787 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
788 lower = -500.0_dp, upper = 1500._dp, ncvarname =
'net_rad', bound_error=self%bound_error)
791 if ((idomain .eq. self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0))
then
792 allocate(self%L1_pet (
size(self%L1_netrad, dim = 1),
size(self%L1_netrad, dim = 2)))
793 allocate(self%L1_tmin(1, 1))
794 allocate(self%L1_tmax(1, 1))
795 allocate(self%L1_absvappress(1, 1))
796 allocate(self%L1_windspeed(1, 1))
800 if (.not. self%couple_netrad)
then
801 if (self%single_read(idomain))
call message(
' read net radiation ...')
803 dataout1=self%L1_netrad, &
804 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
805 lower = -500.0_dp, upper = 1500._dp, ncvarname =
'net_rad', bound_error=self%bound_error)
807 if (.not. self%couple_absvappress)
then
808 if (self%single_read(idomain))
call message(
' read absolute vapour pressure ...')
810 dataout1=self%L1_absvappress, &
811 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
812 lower = 0.0_dp, upper = 15000.0_dp, ncvarname =
'eabs', bound_error=self%bound_error)
814 if (.not. self%couple_windspeed)
then
815 if (self%single_read(idomain))
call message(
' read windspeed ...')
817 dataout1=self%L1_windspeed, &
818 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
819 lower = 0.0_dp, upper = 250.0_dp, ncvarname =
'windspeed', bound_error=self%bound_error)
822 if ((idomain.eq.self%nDomains) .OR. (self%timeStep_model_inputs(idomain) .NE. 0))
then
823 allocate(self%L1_pet (
size(self%L1_absvappress, dim = 1),
size(self%L1_absvappress, dim = 2)))
824 allocate(self%L1_tmin(1, 1))
825 allocate(self%L1_tmax(1, 1))
830 if ( self%riv_temp_case .ne. 0 )
then
832 if (self%timeStep_model_inputs(idomain) .ne. 0)
then
833 if (.not. self%couple_ssrd .and.
allocated(self%L1_ssrd))
deallocate(self%L1_ssrd)
834 if (.not. self%couple_strd .and.
allocated(self%L1_strd))
deallocate(self%L1_strd)
835 if (.not. self%couple_tann .and.
allocated(self%L1_tann))
deallocate(self%L1_tann)
837 if (.not. self%couple_ssrd)
then
838 if (self%single_read(idomain))
call message(
' read short-wave radiation ...')
840 idomain, self%dirRadiation(idomain), self%inputFormat_meteo_forcings, &
841 dataout1=self%L1_ssrd, &
842 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
843 lower = 0.0_dp, upper = 1500._dp, ncvarname =
'ssrd', bound_error=self%bound_error)
845 if (.not. self%couple_strd)
then
846 if (self%single_read(idomain))
call message(
' read long-wave radiation ...')
848 idomain, self%dirRadiation(idomain), self%inputFormat_meteo_forcings, &
849 dataout1=self%L1_strd, &
850 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
851 lower = 0.0_dp, upper = 1500._dp, ncvarname =
'strd', bound_error=self%bound_error)
853 if (.not. self%couple_tann)
then
854 if (self%single_read(idomain))
call message(
' read annual mean temperature ...')
856 idomain, self%dirTemperature(idomain), self%inputFormat_meteo_forcings, &
857 dataout1=self%L1_tann, &
858 readper=self%readPer, ntstepforcingday=self%nTstepForcingDay, level1=level1, level2=self%level2, &
859 lower = -100.0_dp, upper = 100._dp, ncvarname =
'tann', bound_error=self%bound_error)
863 if (self%single_read(idomain))
then
865 call message(
' in ', trim(num2str(timer_get(1),
'(F9.3)')),
' seconds.')
871 if (self%couple_all)
then
872 self%nTstepForcingDay = int(one_day() / self%couple_step_delta, i4)
873 self%is_hourly_forcing = self%couple_is_hourly
875 self%is_hourly_forcing = (self%nTstepForcingDay .eq. 24_i4)
879 select case (self%pet_case)
881 if (self%couple_temp .and. self%couple_tmin .and. self%couple_tmax)
then
882 if (self%couple_is_hourly)
call error_message(
"Coupling: PET - Hargreaves-Samani needs daily data. Got hourly.")
883 else if (self%couple_temp .or. self%couple_tmin .or. self%couple_tmax)
then
884 if (self%couple_is_hourly)
call error_message(
"Coupling: PET - Hargreaves-Samani needs daily data. Got hourly.")
885 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
887 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Hargreaves-Samani needs daily data. Got hourly.")
891 if (self%couple_temp .and. self%couple_netrad)
then
892 if (self%couple_is_hourly)
call error_message(
"Coupling: PET - Priestley-Taylor needs daily data. Got hourly.")
893 else if (self%couple_temp .or. self%couple_netrad)
then
894 if (self%couple_is_hourly)
call error_message(
"Coupling: PET - Priestley-Taylor needs daily data. Got hourly.")
895 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
897 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Priestley-Taylor needs daily data. Got hourly.")
901 if (self%couple_temp .and. self%couple_netrad .and. self%couple_absvappress .and. self%couple_windspeed)
then
902 if (self%couple_is_hourly)
call error_message(
"Coupling: PET - Penman-Monteith needs daily data. Got hourly.")
903 else if (self%couple_temp .or. self%couple_netrad .or. self%couple_absvappress .or. self%couple_windspeed)
then
904 if (self%couple_is_hourly)
call error_message(
"Coupling: PET - Penman-Monteith needs daily data. Got hourly.")
905 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
907 if (self%is_hourly_forcing)
call error_message(
"Meteo: PET - Penman-Monteith needs daily data. Got hourly.")
916 petLAIcorFactorL1, fAsp, HarSamCoeff, latitude, PrieTayAlpha, aeroResist, surfResist)
919 use mo_julian,
only : date2dec, dec2date
921 use mo_string_utils,
only : num2str
928 real(dp),
dimension(:),
intent(inout) :: pet_calc
930 real(dp),
dimension(:),
intent(in) :: petLAIcorFactorL1
932 real(dp),
dimension(:),
intent(in) :: fAsp
934 real(dp),
dimension(:),
intent(in) :: HarSamCoeff
936 real(dp),
dimension(:),
intent(in) :: latitude
938 real(dp),
dimension(:),
intent(in) :: PrieTayAlpha
940 real(dp),
dimension(:),
intent(in) :: aeroResist
942 real(dp),
dimension(:),
intent(in) :: surfResist
946 logical :: isday, is_hourly
947 integer(i4) :: year, month, day, hour
948 type(datetime) :: curr_dt
949 type(timedelta) :: meteo_time_delta
955 integer(i4) :: nCells1
957 integer(i4) :: k, i, s1
959 integer(i4) :: mTS_pet, mTS_temp, mTS_tmin, mTS_tmax, mTS_rn, mTS_avp, mTS_ws
962 call dec2date(self%time, yy = year, mm = month, dd = day, hh = hour)
963 curr_dt = datetime(year, month, day, hour)
966 ncells1 = self%e1 - self%s1 + 1
969 if (self%couple_pet)
then
970 meteo_time_delta = curr_dt - self%couple_pet_time
972 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
973 call error_message(
"meteo_handler: PET was expected from coupler, but has a wrong time-stamp.")
975 is_hourly = self%couple_is_hourly
977 mts_pet = self%iMeteoTS
978 is_hourly = self%is_hourly_forcing
981 if (self%couple_temp)
then
982 meteo_time_delta = curr_dt - self%couple_temp_time
984 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
985 call error_message(
"meteo_handler: temperature was expected from coupler, but has a wrong time-stamp.")
989 mts_temp = self%iMeteoTS
992 if (self%couple_tmin)
then
993 meteo_time_delta = curr_dt - self%couple_tmin_time
995 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
996 call error_message(
"meteo_handler: minimum temperature was expected from coupler, but has a wrong time-stamp.")
1000 mts_tmin = self%iMeteoTS
1003 if (self%couple_tmax)
then
1004 meteo_time_delta = curr_dt - self%couple_tmax_time
1006 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1007 call error_message(
"meteo_handler: maximum temperature was expected from coupler, but has a wrong time-stamp.")
1011 mts_tmax = self%iMeteoTS
1014 if (self%couple_netrad)
then
1015 meteo_time_delta = curr_dt - self%couple_netrad_time
1017 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1018 call error_message(
"meteo_handler: net-radiation was expected from coupler, but has a wrong time-stamp.")
1022 mts_rn = self%iMeteoTS
1025 if (self%couple_absvappress)
then
1026 meteo_time_delta = curr_dt - self%couple_absvappress_time
1028 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1029 call error_message(
"meteo_handler: Abs. vapour pressure was expected from coupler, but has a wrong time-stamp.")
1033 mts_avp = self%iMeteoTS
1036 if (self%couple_windspeed)
then
1037 meteo_time_delta = curr_dt - self%couple_windspeed_time
1039 if (meteo_time_delta < zero_delta() .or. meteo_time_delta >= self%couple_step_delta) &
1040 call error_message(
"meteo_handler: windspeed was expected from coupler, but has a wrong time-stamp.")
1044 mts_ws = self%iMeteoTS
1048 isday = (hour .gt. 6) .AND. (hour .le. 18)
1056 i = self%s_meteo - 1 + k
1059 select case (self%pet_case)
1061 pet = petlaicorfactorl1(k) * self%L1_pet(i, mts_pet)
1064 pet = fasp(k) * self%L1_pet(i, mts_pet)
1068 if (self%L1_tmax(i, mts_tmax) .lt. self%L1_tmin(i, mts_tmin)) &
1069 call message(
'WARNING: tmax smaller than tmin at doy ', &
1070 num2str(doy),
' in year ', num2str(year),
' at cell', num2str(k),
'!')
1072 harsamcoeff=harsamcoeff(k), &
1074 tavg=self%L1_temp(i, mts_temp), &
1075 tmax=self%L1_tmax(i, mts_tmax), &
1076 tmin=self%L1_tmin(i, mts_tmin), &
1077 latitude=latitude(k), &
1083 prietayparam=prietayalpha(k), &
1084 rn=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1085 tavg=self%L1_temp(i, mts_temp))
1089 net_rad=max(self%L1_netrad(i, mts_rn), 0.0_dp), &
1090 tavg=self%L1_temp(i, mts_temp), &
1091 act_vap_pressure=self%L1_absvappress(i, mts_avp) / 1000.0_dp, &
1092 aerodyn_resistance=aeroresist(k) / self%L1_windspeed(i, mts_ws), &
1093 bulksurface_resistance=surfresist(k), &
1099 if (self%is_hourly_forcing)
then
1102 if (self%read_meteo_weights)
then
1105 meteo_val_day=pet, &
1106 meteo_val_weights=self%L1_pet_weights(s1 - 1 + k, month, hour + 1), &
1107 meteo_val=pet_calc(k))
1112 ntimesteps_day=self%nTstepDay_dp, &
1113 meteo_val_day=pet, &
1114 fday_meteo_val=self%fday_pet(month), &
1115 fnight_meteo_val=self%fnight_pet(month), &
1116 meteo_val=pet_calc(k))
1463 year, month, day, hour, &
1477 integer(i4),
intent(in) :: year
1478 integer(i4),
intent(in) :: month
1479 integer(i4),
intent(in) :: day
1480 integer(i4),
intent(in),
optional :: hour
1481 real(dp),
dimension(:),
optional,
intent(in) :: pre
1482 real(dp),
dimension(:),
optional,
intent(in) :: temp
1483 real(dp),
dimension(:),
optional,
intent(in) :: pet
1484 real(dp),
dimension(:),
optional,
intent(in) :: tmin
1485 real(dp),
dimension(:),
optional,
intent(in) :: tmax
1486 real(dp),
dimension(:),
optional,
intent(in) :: netrad
1487 real(dp),
dimension(:),
optional,
intent(in) :: absvappress
1488 real(dp),
dimension(:),
optional,
intent(in) :: windspeed
1489 real(dp),
dimension(:),
optional,
intent(in) :: ssrd
1490 real(dp),
dimension(:),
optional,
intent(in) :: strd
1491 real(dp),
dimension(:),
optional,
intent(in) :: tann
1493 integer(i4) :: hour_
1494 type(datetime) :: input_time
1496 if (.not. self%couple_cfg%active()) &
1497 call error_message(
"meteo_handler%set_meteo: coupling was not activated.")
1501 if (
present(hour))
then
1503 else if (self%couple_cfg%meteo_timestep == 24_i4)
then
1506 if (hour_ == -1_i4) &
1507 call error_message(
"meteo_handler%set_meteo: hour for the meteo date needs to be given if the timestep is not daily.")
1508 input_time = datetime(year, month, day, hour_)
1511 if (self%couple_cfg%meteo_time_ref_endpoint) input_time = input_time - self%couple_step_delta
1514 if (mod(input_time%hour, self%couple_cfg%meteo_timestep) /= 0) &
1515 call error_message(
"meteo_handler%set_meteo: given time doesn't match couple timestep: ", input_time%str())
1518 if (
present(pre))
then
1519 if (.not. self%couple_pre) &
1520 call error_message(
"meteo_handler%set_meteo: precipitation was not set to be coupled.")
1521 self%couple_pre_time = input_time
1522 self%L1_pre(:, 1_i4) = pre(:)
1526 if (
present(temp))
then
1527 if (.not. self%couple_temp) &
1528 call error_message(
"meteo_handler%set_meteo: avg. temperature was not set to be coupled.")
1529 self%couple_temp_time = input_time
1530 self%L1_temp(:, 1_i4) = temp(:)
1534 if (
present(pet))
then
1535 if (.not. self%couple_pet) &
1536 call error_message(
"meteo_handler%set_meteo: PET was not set to be coupled.")
1537 self%couple_pet_time = input_time
1538 self%L1_pet(:, 1_i4) = pet(:)
1542 if (
present(tmin))
then
1543 if (.not. self%couple_tmin) &
1544 call error_message(
"meteo_handler%set_meteo: tmin was not set to be coupled.")
1545 self%couple_tmin_time = input_time
1546 self%L1_tmin(:, 1_i4) = tmin(:)
1550 if (
present(tmax))
then
1551 if (.not. self%couple_tmax) &
1552 call error_message(
"meteo_handler%set_meteo: tmax was not set to be coupled.")
1553 self%couple_tmax_time = input_time
1554 self%L1_tmax(:, 1_i4) = tmax(:)
1558 if (
present(netrad))
then
1559 if (.not. self%couple_netrad) &
1560 call error_message(
"meteo_handler%set_meteo: netrad was not set to be coupled.")
1561 self%couple_netrad_time = input_time
1562 self%L1_netrad(:, 1_i4) = netrad(:)
1566 if (
present(absvappress))
then
1567 if (.not. self%couple_absvappress) &
1568 call error_message(
"meteo_handler%set_meteo: absvappress was not set to be coupled.")
1569 self%couple_absvappress_time = input_time
1570 self%L1_absvappress(:, 1_i4) = absvappress(:)
1574 if (
present(windspeed))
then
1575 if (.not. self%couple_windspeed) &
1576 call error_message(
"meteo_handler%set_meteo: windspeed was not set to be coupled.")
1577 self%couple_windspeed_time = input_time
1578 self%L1_windspeed(:, 1_i4) = windspeed(:)
1582 if (
present(ssrd))
then
1583 if (.not. self%couple_ssrd) &
1584 call error_message(
"meteo_handler%set_meteo: ssrd was not set to be coupled.")
1585 self%couple_ssrd_time = input_time
1586 self%L1_ssrd(:, 1_i4) = ssrd(:)
1590 if (
present(strd))
then
1591 if (.not. self%couple_strd) &
1592 call error_message(
"meteo_handler%set_meteo: strd was not set to be coupled.")
1593 self%couple_strd_time = input_time
1594 self%L1_strd(:, 1_i4) = strd(:)
1598 if (
present(tann))
then
1599 if (.not. self%couple_tann) &
1600 call error_message(
"meteo_handler%set_meteo: tann was not set to be coupled.")
1601 self%couple_tann_time = input_time
1602 self%L1_tann(:, 1_i4) = tann(:)