Skip to content

Commit

Permalink
Remove get_calday hack for Gregorian calendar
Browse files Browse the repository at this point in the history
The hack was documented as being needed for shr_orb_decl, but get_calday
isn't used for this purpose. Removing this hack makes this function work
correctly for leap years.
  • Loading branch information
billsacks committed Jan 6, 2022
1 parent 168212b commit c432b6d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/utils/clm_time_manager.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,10 @@ function get_calday(ymd, tod)
! Return calendar day corresponding to specified time instant.
! Calendar day 1.0 = 0Z on Jan 1.

! If the current run is using a Gregorian calendar, then the year is important, in
! that it determines whether or not we're in a leap year for the sake of determining
! the calendar day.

! Arguments
integer, intent(in) :: &
ymd, &! date in yearmmdd format
Expand All @@ -1157,19 +1161,8 @@ function get_calday(ymd, tod)
date = TimeSetymd( ymd, tod, "get_calday" )
call ESMF_TimeGet( date, dayOfYear_r8=get_calday, rc=rc )
call chkrc(rc, sub//': error return from ESMF_TimeGet')
!----------------------------------------------------------------------------------------!
!!!!!!!!!!!!!! WARNING HACK TO ENABLE Gregorian CALENDAR WITH SHR_ORB !!!!!!!!!!!!!!!!!!!!
!!!! The following hack fakes day 366 by reusing day 365. This is just because the !!!!!!
!!!! current shr_orb_decl calculation can't handle days > 366. !!!!!!
!!!! Dani Bundy-Coleman and Erik Kluzek Aug/2008 !!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if ( (get_calday > 366.0) .and. (get_calday <= 367.0) .and. &
(trim(calendar) == GREGORIAN_C) )then
get_calday = get_calday - 1.0_r8
end if
!!!!!!!!!!!!!! END HACK TO ENABLE Gregorian CALENDAR WITH SHR_ORB !!!!!!!!!!!!!!!!!!!!!!!!
!----------------------------------------------------------------------------------------!
if ( (get_calday < 1.0) .or. (get_calday > 366.0) )then

if ( (get_calday < 1.0) .or. (get_calday > 367.0) )then
write(iulog,*) sub, ' = ', get_calday
call shr_sys_abort( sub//': error calday out of range' )
end if
Expand Down
24 changes: 24 additions & 0 deletions src/utils/test/clm_time_manager_test/test_clm_time_manager.pf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,30 @@ contains
@assertEqual(dtime, step_size)
end subroutine getStepSize_returnsCorrectValue

@Test
subroutine getCalday_jan1_returns1(this)
class(TestTimeManager), intent(inout) :: this
real(r8) :: calday

call unittest_timemgr_setup(dtime=dtime)

calday = get_calday(101, 0)

@assertEqual(1._r8, calday)
end subroutine getCalday_jan1_returns1

@Test
subroutine getCalday_leapYearDec31_returnsCorrectValue(this)
class(TestTimeManager), intent(inout) :: this
real(r8) :: calday

call unittest_timemgr_setup(dtime=dtime, use_gregorian_calendar=.true.)

calday = get_calday(41231, 43200)

@assertEqual(366.5_r8, calday)
end subroutine getCalday_leapYearDec31_returnsCorrectValue

@Test
subroutine getCurrYearfrac_atYearBoundary_returns0(this)
class(TestTimeManager), intent(inout) :: this
Expand Down

0 comments on commit c432b6d

Please sign in to comment.