Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a logical function to determine if year is leap year #35

Merged
merged 3 commits into from
Sep 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/shr_cal_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module shr_cal_mod
public :: shr_cal_ymdtod2string ! translate ymdtod to string for filenames
public :: shr_cal_datetod2string ! translate date to string for filenames
public :: shr_cal_ymds2rday_offset ! translate yr,month,day,sec offset to a fractional day offset

public :: shr_cal_leapyear ! logical function: is this a gregorian leap year?
! !PUBLIC DATA MEMBERS:

! none
Expand Down Expand Up @@ -244,7 +244,7 @@ subroutine shr_cal_timeSet_int(etime,ymd,sec,calendar, rc)
type(ESMF_CALKIND_FLAG) :: calkind
character(len=shr_cal_calMaxLen) :: lcalendar
integer :: lrc
character(*),parameter :: subName = "(shr_cal_timeSet)"
character(*),parameter :: subName = "(shr_cal_timeSet_int)"

!-------------------------------------------------------------------------------
!
Expand All @@ -253,9 +253,10 @@ subroutine shr_cal_timeSet_int(etime,ymd,sec,calendar, rc)

lcalendar = shr_cal_calendarName(calendar)

calkind = ESMF_CALKIND_NOLEAP
if (trim(lcalendar) == trim(shr_cal_gregorian)) then
calkind = ESMF_CALKIND_GREGORIAN
else
calkind = ESMF_CALKIND_NOLEAP
endif

call shr_cal_date2ymd(ymd,year,month,day)
Expand Down Expand Up @@ -293,9 +294,10 @@ subroutine shr_cal_timeSet_long(etime,ymd,sec,calendar, rc)

lcalendar = shr_cal_calendarName(calendar)

calkind = ESMF_CALKIND_NOLEAP
if (trim(lcalendar) == trim(shr_cal_gregorian)) then
calkind = ESMF_CALKIND_GREGORIAN
else
calkind = ESMF_CALKIND_NOLEAP
endif

call shr_cal_date2ymd(ymd,year,month,day)
Expand Down Expand Up @@ -1410,5 +1412,20 @@ subroutine shr_cal_ymds2rday_offset(etime, rdays_offset, &
if(rc /= ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
end subroutine shr_cal_ymds2rday_offset

logical function shr_cal_leapyear(yr)
integer, intent(in) :: yr
shr_cal_leapyear = .false.
if (modulo(yr, 4) == 0) then
if (modulo(yr, 100) == 0) then
if(modulo(yr, 400) == 0) then
shr_cal_leapyear = .true.
endif
else
shr_cal_leapyear = .true.
endif
endif

end function shr_cal_leapyear

!===============================================================================
end module shr_cal_mod