ESCOMP / WW3

The latest CESM fork of WaveWatch III
Other
0 stars 6 forks source link

time:units set inconsistently in the nuopc interface #17

Open anton-seaice opened 10 months ago

anton-seaice commented 10 months ago

Describe the bug In the netcdf output, when using a restart file, then time:units attribute is set in a way that is inconsistent with the time variable.

For an initial run of one day long, in the netcdf output:

time:units = "seconds since 1900-01-01 00:00:00" ; 
time = 86400 ;

Which is correct

If another day is run, the time variable in netcdf output is:

time:units = "seconds since 1900-01-02 00:00:00" ;
time = 172800 ;

This is inconsistent, as both the time and the time origin have stepped forward one day.

Interestingly the file name has the correct date (i.e. the end of the time period): GMOM_JRA_WD.ww3.hi.1900-01-03-00000.nc

To Reproduce Start the model from a restart file, with netcdf output turned on.

Expected behavior Time:units should be set from the model start time, not the restart time.

Additional context

The time_origin is set based on the 'Current Time' before the model is time stepped:

https://github.com/ESCOMP/WW3/blob/97740a1abb36b7ba6e52a7d6f7a37dd06f915633/model/src/wav_comp_nuopc.F90#L613

   call ESMF_ClockGet( clock, currTime=esmfTime, rc=rc )
      if (ChkErr(rc,__LINE__,u_FILE_u)) return
    endif
    ! Determine time attributes for history output
    call ESMF_TimeGet( esmfTime, timeString=time_origin, calendar=calendar, rc=rc )
    if (ChkErr(rc,__LINE__,u_FILE_u)) return
    time_origin = 'seconds since '//time_origin(1:10)//' '//time_origin(12:19)

But then the 'elapsed_secs' is set from the 'Start Time'

https://github.com/ESCOMP/WW3/blob/97740a1abb36b7ba6e52a7d6f7a37dd06f915633/model/src/wav_comp_nuopc.F90#L1062

elapsedTime = nextTime - startTime
    call ESMF_TimeIntervalGet(elapsedTime, s_i8=elapsed_secs,rc=rc)

I think setting time_origin based on Start Time would make sense.

DeniseWorthen commented 3 months ago

@anton-seaice I have made this fix in some work I'm doing in WW3 for the Coastal application in UFS. I'll be making a PR which will include this fix in the coming weeks.

index c7bb14ef..f2d4a4f8 100644
--- a/model/src/wav_comp_nuopc.F90
+++ b/model/src/wav_comp_nuopc.F90
@@ -623,7 +623,7 @@ contains
       if (ChkErr(rc,__LINE__,u_FILE_u)) return
     endif
     ! Determine time attributes for history output
-    call ESMF_TimeGet( esmfTime, timeString=time_origin, calendar=calendar, rc=rc )
+    call ESMF_TimeGet( startTime, timeString=time_origin, calendar=calendar, rc=rc )
     if (ChkErr(rc,__LINE__,u_FILE_u)) return
     time_origin = 'seconds since '//time_origin(1:10)//' '//time_origin(12:19)
     !call ESMF_ClockGet(clock, calendar=calendar)
anton-seaice commented 3 months ago

Thankyou!