Skip to content

Commit

Permalink
Merge branch 'bt_validate_fix' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
oehmke committed Apr 12, 2024
2 parents d896bc8 + 2ea3940 commit e29a971
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/Infrastructure/TimeMgr/include/ESMCI_BaseTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure/TimeMgr/src/ESMCI_Time.C
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion src/Infrastructure/TimeMgr/tests/ESMF_TimeUTest.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 ?

Expand Down

0 comments on commit e29a971

Please sign in to comment.