Skip to content

Commit

Permalink
fix assert
Browse files Browse the repository at this point in the history
  • Loading branch information
adrifoster committed May 7, 2024
1 parent f1778be commit 8875fba
Showing 1 changed file with 59 additions and 62 deletions.
121 changes: 59 additions & 62 deletions src/biogeophys/DiurnalOzoneType.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module DiurnalOzoneType
! ozone anomaly file
!
! !USES:
#include "shr_assert.h"
#include "shr_assert.h"
use shr_kind_mod , only : r8 => shr_kind_r8
use decompMod , only : bounds_type
use clm_varcon , only : spval
Expand Down Expand Up @@ -36,7 +36,6 @@ module DiurnalOzoneType
character(len=*), parameter, private :: sourcefile = &
__FILE__


contains

! ========================================================================
Expand Down Expand Up @@ -64,7 +63,6 @@ subroutine Init(this, bounds, n)

end subroutine Init


!-----------------------------------------------------------------------
subroutine InitAllocate(this, bounds)
!
Expand All @@ -87,72 +85,71 @@ subroutine InitAllocate(this, bounds)
allocate(this%o3_anomaly_grc(begg:endg,1:this%ntimes)); this%o3_anomaly_grc(:,:) = nan
allocate(this%time_arr(1:this%ntimes)); this%time_arr(:) = nan

end subroutine InitAllocate

!-----------------------------------------------------------------------
end subroutine InitAllocate

!-----------------------------------------------------------------------
subroutine Interp(this, bounds, forc_o3, forc_o3_down)
!
! !DESCRIPTION:
! Downscale/interpolate multi-day ozone data to subdaily
!
! !USES:
use clm_time_manager , only : get_curr_date
use clm_varcon , only : secspday
!
! !ARGUMENTS:
class(diurnal_ozone_anom_type), intent(in) :: this
type(bounds_type), intent(in) :: bounds ! bounds type
real(r8), intent(in) :: forc_o3(:) ! ozone partial pressure (mol/mol)
real(r8), intent(out) :: forc_o3_down(:) ! ozone partial pressure, downscaled (mol/mol)

!
! LOCAL VARIABLES:
integer :: t ! looping index
integer :: yr ! year
integer :: mon ! month
integer :: day ! day of month
integer :: tod ! time of day (seconds past 0Z)
integer :: begg, endg ! bounds
integer :: t_prev ! previous time index
real(r8) :: tdiff_end
real(r8) :: tdiff_start
real(r8) :: tdiff
!-----------------------------------------------------------------------
subroutine Interp(this, bounds, forc_o3, forc_o3_down)
!
! !DESCRIPTION:
! Downscale/interpolate multi-day ozone data to subdaily
!
! !USES:
use clm_time_manager , only : get_curr_date
use clm_varcon , only : secspday
!
! !ARGUMENTS:
class(diurnal_ozone_anom_type), intent(in) :: this
type(bounds_type), intent(in) :: bounds ! bounds type
real(r8), intent(in) :: forc_o3(:) ! ozone partial pressure (mol/mol)
real(r8), intent(out) :: forc_o3_down(:) ! ozone partial pressure, downscaled (mol/mol)

begg = bounds%begg; endg = bounds%endg
!
! LOCAL VARIABLES:
integer :: t ! looping index
integer :: yr ! year
integer :: mon ! month
integer :: day ! day of month
integer :: tod ! time of day (seconds past 0Z)
integer :: begg, endg ! bounds
integer :: t_prev ! previous time index
real(r8) :: tdiff_end
real(r8) :: tdiff_start
real(r8) :: tdiff
!-----------------------------------------------------------------------

! Get current date/time - we really only need seconds
call get_curr_date(yr, mon, day, tod)
begg = bounds%begg; endg = bounds%endg

! find the time interval we are in
do t = 1, this%ntimes
if (real(tod) <= this%time_arr(t)) then
exit
! Get current date/time - we really only need seconds
call get_curr_date(yr, mon, day, tod)

! find the time interval we are in
do t = 1, this%ntimes
if (real(tod) <= this%time_arr(t)) then
exit
end if
end do

! interpolate, checking for edge cases
if (t == 1) then
! wrap around back
t_prev = this%ntimes
tdiff_end = secspday - this%time_arr(t_prev) + real(tod)
tdiff = this%time_arr(t) + secspday - this%time_arr(t_prev)
else
t_prev = t - 1
tdiff_end = real(tod) - this%time_arr(t_prev)
tdiff = this%time_arr(t) - this%time_arr(t_prev)
end if
end do

! interpolate, checking for edge cases
if (t == 1) then
! wrap around back
t_prev = this%ntimes
tdiff_end = secspday - this%time_arr(t_prev) + real(tod)
tdiff = this%time_arr(t) + secspday - this%time_arr(t_prev)
else
t_prev = t - 1
tdiff_end = real(tod) - this%time_arr(t_prev)
tdiff = this%time_arr(t) - this%time_arr(t_prev)
end if

tdiff_start = this%time_arr(t) - real(tod)

! interpolate
forc_o3_down(begg:endg) = forc_o3(begg:endg)* &
((this%o3_anomaly_grc(begg:endg, t_prev)*tdiff_start + &
this%o3_anomaly_grc(begg:endg, t_prev)*tdiff_end)/tdiff)

end subroutine Interp

tdiff_start = this%time_arr(t) - real(tod)

! interpolate
forc_o3_down(begg:endg) = forc_o3(begg:endg)* &
((this%o3_anomaly_grc(begg:endg, t_prev)*tdiff_start + &
this%o3_anomaly_grc(begg:endg, t_prev)*tdiff_end)/tdiff)

end subroutine Interp

!-----------------------------------------------------------------------

Expand Down

0 comments on commit 8875fba

Please sign in to comment.