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

handle edge case model no_leap, data gregorian #192

Merged
merged 4 commits into from
Oct 3, 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
72 changes: 36 additions & 36 deletions streams/dshr_strdata_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,6 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc)

sdat%ymd = ymd
sdat%tod = tod

if (nstreams > 0) then
allocate(newData(nstreams))
allocate(ymdmod(nstreams))
Expand All @@ -909,6 +908,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc)
ymdmod(ns) = ymd
todmod = tod
calendar = trim(sdat%stream(ns)%calendar)
call shr_cal_date2ymd (ymd,year,month,day)
if (trim(sdat%model_calendar) /= trim(sdat%stream(ns)%calendar)) then
if (( trim(sdat%model_calendar) == trim(shr_cal_gregorian)) .and. &
(trim(sdat%stream(ns)%calendar) == trim(shr_cal_noleap))) then
Expand All @@ -918,42 +918,8 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc)
call shr_cal_ymd2date(year,2,28,ymdmod(ns))
endif
calendar = shr_cal_noleap
else if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. &
(trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then
! case (2), feb 29 input data will be skipped automatically
else
! case (3), abort
write(logunit,*) trim(subname),' ERROR: mismatch calendar ', &
trim(sdat%model_calendar),':',trim(sdat%stream(ns)%calendar)
call shr_sys_abort(trim(subname)//' ERROR: mismatch calendar ')
endif
else ! calendars are the same
if(trim(sdat%model_calendar) == trim(shr_cal_gregorian)) then
! Both are in gregorian - but it's possible that there is a mismatch
! such that the model is in leapyear but the data is not
call shr_cal_date2ymd (ymd,year,month,day)
call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday)

if(month == 2 .and. day==29) then
if(.not. shr_cal_leapyear(datayear)) then
! model is in leap year but data is not
calendar = shr_cal_noleap
endif
else if(datamonth == 2) then
if(.not. shr_cal_leapyear(year)) then
if(debug>0 .and. sdat%mainproc) then
write(logunit, *) subname,' dataday = ', dataday
endif
calendar = shr_cal_noleap
endif
else
calendar = sdat%model_calendar
endif
else
calendar = sdat%model_calendar
endif
endif

! ---------------------------------------------------------
! Determine if new data is read in - if so then copy
! fldbun_stream_ub to fldbun_stream_lb and read in new fldbun_stream_ub data
Expand Down Expand Up @@ -983,6 +949,40 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc)
! ---------------------------------------------------------

if (newData(ns)) then
if (trim(sdat%model_calendar) /= trim(sdat%stream(ns)%calendar)) then
if ((trim(sdat%model_calendar) == trim(shr_cal_noleap)) .and. &
(trim(sdat%stream(ns)%calendar) == trim(shr_cal_gregorian))) then
call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday)
if(datamonth==3 .and. dataday==1 .and. month==2 .and. day==28) then
calendar = shr_cal_noleap
endif
! case (2), feb 29 input data will be skipped automatically
else if (.not. ( trim(sdat%model_calendar) == trim(shr_cal_gregorian)) .and. &
(trim(sdat%stream(ns)%calendar) == trim(shr_cal_noleap))) then
! case (3), abort
write(logunit,*) trim(subname),' ERROR: mismatch calendar ', &
trim(sdat%model_calendar),':',trim(sdat%stream(ns)%calendar)
call shr_sys_abort(trim(subname)//' ERROR: mismatch calendar ')
endif
else ! calendars are the same
if(trim(sdat%model_calendar) == trim(shr_cal_gregorian)) then
! Both are in gregorian - but it's possible that there is a mismatch
! such that the model is in leapyear but the data is not
call shr_cal_date2ymd (ymd,year,month,day)
call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday)
if(month == 2 .and. day >= 28) then
if(shr_cal_leapyear(year) .and. .not. shr_cal_leapyear(datayear)) then
! model is in leap year but data is not
calendar = shr_cal_noleap
endif
else
calendar = sdat%model_calendar
endif
else
calendar = sdat%model_calendar
endif
endif

! Reset time bounds if newdata read in
call shr_cal_timeSet(timeLB,sdat%pstrm(ns)%ymdLB,0,calendar,rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand All @@ -1006,7 +1006,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc)
write(sdat%stream(1)%logunit,*) trim(subName),' ERROR: ymdLB, todLB, ymdUB, todUB = ', &
sdat%pstrm(ns)%ymdLB, sdat%pstrm(ns)%todLB, sdat%pstrm(ns)%ymdUB, sdat%pstrm(ns)%todUB
end if
write(6,*) trim(subname),' ERROR: for stream ',ns
write(6,*) trim(subname),' ERROR: for stream ',ns, ' and calendar ',trim(calendar)
write(6,*) trim(subName),' ERROR: dtime, dtmax, dtmin, dtlimit = ',&
dtime, sdat%pstrm(ns)%dtmax, sdat%pstrm(ns)%dtmin, sdat%stream(ns)%dtlimit
write(6,*) trim(subName),' ERROR: ymdLB, todLB, ymdUB, todUB = ', &
Expand Down