[ncl-talk] Time string with 1 minute interval

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Fri Jul 12 19:06:57 MDT 2019


You have time origin of 1800-01-01, and you need a resolution of 1 minute
in year 2017.  This requires a precision of at least 33 bits.  However, you
made time coordinates with NCL single precision type "float".  This has a
precision of only 24 bits.

Another problem is that the cd_string function has a known bug where
sometimes 60 seconds is printed instead of zero, and the rest of the date
and time is one minute too low.

There is more than one way to fix this.  I recommend the following.  (1)
and (2) for sure, (3) is optional in this case.

(1) Convert all of your time coordinate calculations to type double.  Make
sure to includes all of the floating point constants, by adding suffix "d".
(2) Use function ut_string rather than cd_string.
(3) Use a time origin that is much closer to your model dates, such as
2000-1-1 or even 2017-1-1.  This will reduce the full number of bits of
precision needed for small time steps.

To more clearly see what is going on with high precision problems, print
the actual numeric coordinate values, not just the final strings.  Also
temporarily show the seconds in time of day, by changing part of your
format string to %H%M%S.

--Dave


On Fri, Jul 12, 2019 at 12:52 PM Sakib Ahmed via ncl-talk <ncl-talk at ucar.edu>
wrote:

> Hello NCL Community,
>
> I'm stuck with a simple problem of creating time string with an interval
> of 1 minute. I'm working with a wind model and the output file doesn't have
> any time coordinates attached. I'm using the cd_inv_calendar and cd_string
> functions for creating time string.  In my model output, I have outputs
> saved in each minute and in total, I have 900 minutes (15 hours) of data
> stored in the output file. This is what I tried:
>
> ---------------------------------------------------------------------------
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"
>
> ; model start time 2017-09-10 12Z
>
> syyyy = 2017
> smm = 09
> sdd = 10
> shh = 12
>
> ; model end time 2017-09-11 03Z
>
>
> eyyyy = 2017
> emm = 09
> edd = 11
> ehh = 03
>
> timeUnits = "hours since 1800-01-01 00:00:00"
>
> sdate = cd_inv_calendar(syyyy,smm,sdd,shh,00,00,timeUnits,0)
> edate = cd_inv_calendar(eyyyy,emm,edd,ehh,00,00,timeUnits,0)
>
> ntimes = toint((edate-sdate)/.01666666667) +1 ; model has 900 steps, each
> step is 1 minute
>
> times = new( (/ntimes/), "float")
>
> times at units = timeUnits
>
> do n=0,ntimes-1
>    times(n) = tofloat(sdate + (.01666666667*n)) ;multiplying n by 1 makes
> time interval as 1 hour. Multiplying n by 0.25 makes time interval 15
> minutes. But multiplying by 0.01666666667 doesn't create 1 minute interval.
>  end do
>
>  time_str = cd_string(times,"%H%M UTC %d %c %Y")
>
> print(time_str)
>
> ------------------------------------------
> Variable: time_str
> Type: string
> Total Size: 7200 bytes
>             900 values
> Number of Dimensions: 1
> Dimensions and sizes:   [900]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue :  missing
> (0)     1200 UTC 10 Sep 2017
> (1)     1200 UTC 10 Sep 2017
> (2)     1200 UTC 10 Sep 2017
> (3)     1200 UTC 10 Sep 2017
> (4)     1207 UTC 10 Sep 2017
> (5)     1207 UTC 10 Sep 2017
> (6)     1207 UTC 10 Sep 2017
> (7)     1207 UTC 10 Sep 2017
> (8)     1207 UTC 10 Sep 2017
> (9)     1207 UTC 10 Sep 2017
> (10)    1207 UTC 10 Sep 2017
> (11)    1207 UTC 10 Sep 2017
> (12)    1215 UTC 10 Sep 2017
> (13)    1215 UTC 10 Sep 2017
> .
> .
> .
> (891)   0252 UTC 11 Sep 2017
> (892)   0252 UTC 11 Sep 2017
> (893)   0252 UTC 11 Sep 2017
> (894)   0252 UTC 11 Sep 2017
> (895)   0252 UTC 11 Sep 2017
> (896)   0252 UTC 11 Sep 2017
> (897)   0300 UTC 11 Sep 2017
> (898)   0300 UTC 11 Sep 2017
> (899)   0300 UTC 11 Sep 2017
>
> --
> Thank you,
> Sakib Ahmed
> Connecticut College
> Environmental Studies Major,
> New London, CT 06320
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20190712/9d4d8ef6/attachment.html>


More information about the ncl-talk mailing list