LCOV - code coverage report
Current view: top level - meteo - mo_meteo_temporal_tools.f90 (source / functions) Hit Total Coverage
Test: mHM coverage Lines: 17 25 68.0 %
Date: 2024-04-30 08:53:32 Functions: 2 3 66.7 %

          Line data    Source code
       1             : !> \file mo_meteo_temporal_tools.f90
       2             : !> \brief \copybrief mo_meteo_temporal_tools
       3             : !> \details \copydetails mo_meteo_temporal_tools
       4             : 
       5             : !> \brief Temporal disaggregation of daily input values
       6             : !> \details Calculate actual values for precipitation, PET and temperature from daily mean inputs
       7             : !> \note There is not PET correction for aspect in this routine. Use pet * fasp before or after the routine.
       8             : !> \authors Matthias Cuntz
       9             : !> \date Dec 2012
      10             : !> \copyright Copyright 2005-\today, the mHM Developers, Luis Samaniego, Sabine Attinger: All rights reserved.
      11             : !! mHM is released under the LGPLv3+ license \license_note
      12             : !> \ingroup f_meteo
      13             : MODULE mo_meteo_temporal_tools
      14             : 
      15             :   USE mo_kind, ONLY : dp
      16             : 
      17             :   IMPLICIT NONE
      18             : 
      19             :   PRIVATE
      20             : 
      21             :   PUBLIC :: temporal_disagg_meteo_weights ! Temporally distribute meteo value by weights correction
      22             :   PUBLIC :: temporal_disagg_flux_daynight ! Temporally distribute meteo flux by day/night correction
      23             :   PUBLIC :: temporal_disagg_state_daynight ! Temporally distribute meteo state variable by day/night correction
      24             : 
      25             : CONTAINS
      26             : 
      27             :   !> \brief Temporally distribute daily mean forcings onto time step
      28             :   !> \details Calculates actual meteo forcings from daily mean inputs.
      29             :   !! They are distributed with predefined weights onto the day.
      30             :   !> \authors Sebastian Mueller
      31             :   !> \date Jun 2020
      32           0 :   elemental subroutine temporal_disagg_meteo_weights( &
      33             :     meteo_val_day, &
      34             :     meteo_val_weights, &
      35             :     meteo_val, &
      36             :     weights_correction &
      37             :   )
      38             :     implicit none
      39             : 
      40             :     !> Daily meteo_val
      41             :     real(dp), intent(in) :: meteo_val_day
      42             :     !> weights for meteo_val
      43             :     real(dp), intent(in) :: meteo_val_weights
      44             :     !> Actual meteo_val
      45             :     real(dp), intent(out) :: meteo_val
      46             :     !> Additive correction before applying weights (e.g. for temperature conversion)
      47             :     real(dp), intent(in), optional :: weights_correction
      48             : 
      49             :     real(dp) :: weights_correction_
      50             : 
      51             :     ! default values (can't be initialized directly in a pure function)
      52           0 :     weights_correction_ = 0.0_dp
      53             :     ! set potential given optional values
      54           0 :     if ( present(weights_correction) ) weights_correction_ = weights_correction
      55             : 
      56             :     ! use weights to distribute meteo values
      57           0 :     meteo_val = (meteo_val_day + weights_correction_) * meteo_val_weights - weights_correction_
      58             : 
      59           0 :   end subroutine temporal_disagg_meteo_weights
      60             : 
      61             :   !> \brief Temporally distribute daily mean forcings onto time step
      62             :   !> \details Calculates actual meteo forcings from daily mean inputs.
      63             :   !! They are distributed with predefined factors/summands for day and night.
      64             :   !> \authors Sebastian Mueller
      65             :   !> \date Jun 2020
      66   153294096 :   elemental subroutine temporal_disagg_flux_daynight( &
      67             :     isday, &
      68             :     ntimesteps_day, &
      69             :     meteo_val_day, &
      70             :     fday_meteo_val, &
      71             :     fnight_meteo_val, &
      72             :     meteo_val &
      73             :   )
      74             :     implicit none
      75             : 
      76             :     !> is day (False for night)
      77             :     logical, intent(in) :: isday
      78             :     !> number of time steps per day
      79             :     real(dp), intent(in) :: ntimesteps_day
      80             :     !> Daily meteo_val
      81             :     real(dp), intent(in) :: meteo_val_day
      82             :     !> Daytime fraction of meteo_val
      83             :     real(dp), intent(in) :: fday_meteo_val
      84             :     !> Nighttime fraction of meteo_val
      85             :     real(dp), intent(in) :: fnight_meteo_val
      86             :     !> Actual meteo_val
      87             :     real(dp), intent(out) :: meteo_val
      88             : 
      89             :     ! Distribute into time steps night/day
      90   153294096 :     if(ntimesteps_day .gt. 1.0_dp) then
      91   153294096 :       if ( isday ) then ! DAY-TIME
      92    76647048 :         meteo_val = 2.0_dp * meteo_val_day * fday_meteo_val / ntimesteps_day
      93             :       else            ! NIGHT-TIME
      94    76647048 :         meteo_val = 2.0_dp * meteo_val_day * fnight_meteo_val / ntimesteps_day
      95             :       end if
      96             :     else
      97             :       ! default vaule used if ntimesteps_day = 1 (i.e., e.g. daily values)
      98           0 :       meteo_val = meteo_val_day
      99             :     end if
     100             : 
     101           0 :   end subroutine temporal_disagg_flux_daynight
     102             : 
     103             :   !> \brief Temporally distribute daily mean state forcings onto time step
     104             :   !> \details Calculates meteo forcings from daily mean inputs of a state variable.
     105             :   !> They are distributed with predefined factors/summands for day and night.
     106             :   !> \authors Sebastian Mueller
     107             :   !> \date Jun 2020
     108    77538120 :   elemental subroutine temporal_disagg_state_daynight( &
     109             :     isday, &
     110             :     ntimesteps_day, &
     111             :     meteo_val_day, &
     112             :     fday_meteo_val, &
     113             :     fnight_meteo_val, &
     114             :     meteo_val, &
     115             :     add_correction &
     116             :   )
     117             :     implicit none
     118             : 
     119             :     !> is day (False for night)
     120             :     logical, intent(in) :: isday
     121             :     !> number of time steps per day
     122             :     real(dp), intent(in) :: ntimesteps_day
     123             :     !> Daily meteo_val
     124             :     real(dp), intent(in) :: meteo_val_day
     125             :     !> Daytime fraction of meteo_val
     126             :     real(dp), intent(in) :: fday_meteo_val
     127             :     !> Nighttime fraction of meteo_val
     128             :     real(dp), intent(in) :: fnight_meteo_val
     129             :     !> Actual meteo_val
     130             :     real(dp), intent(out) :: meteo_val
     131             :     !> if True, correcting values will be added (e.g. for temperature), otherwise used as percentage
     132             :     logical, intent(in), optional :: add_correction
     133             : 
     134             :     logical :: add_correction_
     135             : 
     136             :     ! default values (can't be initialized directly in a pure function)
     137    77538120 :     add_correction_ = .False.
     138             :     ! set potential given optional values
     139    77538120 :     if ( present(add_correction) ) add_correction_ = add_correction
     140             : 
     141             :     ! Distribute into time steps night/day
     142    77538120 :     if(ntimesteps_day .gt. 1.0_dp) then
     143    77538120 :       if ( add_correction_ ) then  ! for e.g. temperature
     144    76647048 :         if ( isday ) then ! DAY-TIME
     145    38323524 :           meteo_val = meteo_val_day + fday_meteo_val
     146             :         else            ! NIGHT-TIME
     147    38323524 :           meteo_val = meteo_val_day + fnight_meteo_val
     148             :         end if
     149             :       else
     150      891072 :         if ( isday ) then ! DAY-TIME
     151      445536 :           meteo_val = 2.0_dp * meteo_val_day * fday_meteo_val
     152             :         else            ! NIGHT-TIME
     153      445536 :           meteo_val = 2.0_dp * meteo_val_day * fnight_meteo_val
     154             :         end if
     155             :       end if
     156             :     else
     157             :       ! default vaule used if ntimesteps_day = 1 (i.e., e.g. daily values)
     158           0 :       meteo_val = meteo_val_day
     159             :     end if
     160             : 
     161   153294096 :   end subroutine temporal_disagg_state_daynight
     162             : 
     163             : END MODULE mo_meteo_temporal_tools

Generated by: LCOV version 1.16