From 50439d3d47aacc6b6eb0206c430a761795c338e3 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 30 Sep 2022 08:24:32 -0600 Subject: [PATCH 1/4] handle edge case model no_leap, data gregorian --- streams/dshr_strdata_mod.F90 | 1 + 1 file changed, 1 insertion(+) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 53e68d808..0ed4eb62a 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -920,6 +920,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) 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 + calendar = shr_cal_noleap ! case (2), feb 29 input data will be skipped automatically else ! case (3), abort From fe1bcce0e5b640e0062607784f04bd69f81495d7 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 30 Sep 2022 14:45:50 -0600 Subject: [PATCH 2/4] correct edge case again, optimize code by moving part of if block --- streams/dshr_strdata_mod.F90 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 0ed4eb62a..10d56cb92 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -920,7 +920,10 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) 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 - calendar = shr_cal_noleap + call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) + if(.not. shr_cal_leapyear(datayear)) then + calendar = shr_cal_noleap + endif ! case (2), feb 29 input data will be skipped automatically else ! case (3), abort From f5c4a51358491ee21a2ab97ccf7b398b79c153d4 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 30 Sep 2022 17:07:57 -0600 Subject: [PATCH 3/4] not fully working when both calendars are GREGORIAN and model is out of sync with data --- streams/dshr_strdata_mod.F90 | 74 +++++++++++++++++------------------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index 10d56cb92..adc9abd8d 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -918,46 +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 - call shr_cal_date2ymd(sdat%pstrm(ns)%ymdUB, datayear, datamonth, dataday) - if(.not. shr_cal_leapyear(datayear)) then - calendar = shr_cal_noleap - endif - ! 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 @@ -987,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(.not. shr_cal_leapyear(datayear)) 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 @@ -1010,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 = ', & From ae777199cae47ffe6eb6259af00a1e2a012bdaa4 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Sat, 1 Oct 2022 10:02:28 -0600 Subject: [PATCH 4/4] yet another calendar patch --- streams/dshr_strdata_mod.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streams/dshr_strdata_mod.F90 b/streams/dshr_strdata_mod.F90 index adc9abd8d..19dee6043 100644 --- a/streams/dshr_strdata_mod.F90 +++ b/streams/dshr_strdata_mod.F90 @@ -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)) @@ -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 @@ -953,7 +953,7 @@ subroutine shr_strdata_advance(sdat, ymd, tod, logunit, istr, timers, rc) 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(.not. shr_cal_leapyear(datayear)) then + 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