diff --git a/src/Infrastructure/TimeMgr/include/ESMCI_BaseTime.h b/src/Infrastructure/TimeMgr/include/ESMCI_BaseTime.h index 9f42c88604..41b3581832 100644 --- a/src/Infrastructure/TimeMgr/include/ESMCI_BaseTime.h +++ b/src/Infrastructure/TimeMgr/include/ESMCI_BaseTime.h @@ -180,6 +180,17 @@ class BaseTime : public Fraction { // it is a fraction ! // internal validation int validate(const char *options=0) const; + // Check if BaseTime hasn't been initialized yet. + // This was added to avoid going through validate and dumping the error message into the logs for an unset basetime + // in TimeSet(). + // Right now this mimics validate() in that it checks for a 0 denominator in the fraction. This works because + // the entire structure is init to 0 on the F90 level via ESMF_TimeType.F90 and setting a 0 denominator in Time after that + // will result in an error due to the validate() that occurs after the BaseTime set in TimeSet. + // + bool uninit() { + return (getd() == 0); + } + // for testing/debugging int print(const char *options=0) const; diff --git a/src/Infrastructure/TimeMgr/src/ESMCI_Time.C b/src/Infrastructure/TimeMgr/src/ESMCI_Time.C index e74047deaf..8214c0c17d 100644 --- a/src/Infrastructure/TimeMgr/src/ESMCI_Time.C +++ b/src/Infrastructure/TimeMgr/src/ESMCI_Time.C @@ -141,8 +141,8 @@ namespace ESMCI{ timeZone != ESMC_NULL_POINTER) { // only calendar and/or timezone specified, do not re-initialize basetime - // initialize basetime only if not done previously - if (BaseTime::validate() != ESMF_SUCCESS) { + // Initialize basetime only if not done previously + if (BaseTime::uninit()) { Fraction::set(0,0,1); // set seconds = 0 // set fractional seconds numerator = 0 // set fractional seconds denominator = 1 diff --git a/src/Infrastructure/TimeMgr/tests/ESMF_TimeUTest.F90 b/src/Infrastructure/TimeMgr/tests/ESMF_TimeUTest.F90 index db9ef6a895..d1a7cb0ca3 100644 --- a/src/Infrastructure/TimeMgr/tests/ESMF_TimeUTest.F90 +++ b/src/Infrastructure/TimeMgr/tests/ESMF_TimeUTest.F90 @@ -73,7 +73,7 @@ program ESMF_TimeUTest ! instantitate some general times and timeintervals type(ESMF_Time) :: time1, time2, time3, time4, time5, time6, time7, & - midMonth, startTime2 + midMonth, startTime2, time8 type(ESMF_TimeInterval) :: timeInterval2, timeInterval3, timeInterval4, & timeInterval5, timeInterval6, timeInterval7 @@ -1136,6 +1136,18 @@ program ESMF_TimeUTest ! ---------------------------------------------------------------------------- + ! ---------------------------------------------------------------------------- + !EX_UTest + ! Setting just a calendar in an uninit time + write(failMsg, *) " Did not return ESMF_SUCCESS" + write(name, *) "Setting just a calendar in an uninitialized Time object." + call ESMF_TimeSet(time8, calendar=julianCalendar, rc=rc) + call ESMF_Test((rc.eq.ESMF_SUCCESS).and.(.not.bool), & + name, failMsg, result, ESMF_SRCLINE) + + ! ---------------------------------------------------------------------------- + + ! return number of failures to environment; 0 = success (all pass) ! return result ! TODO: no way to do this in F90 ?