<div dir="ltr"><div dir="ltr">Correction.  Only 27 bits of precision are required in this problem.  My bad.  That is log base 2 of number of minutes elapsed since 1800-1-1.  33 bits was for elapsed seconds.  You still need to calculate in double precision.</div><div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 12, 2019 at 7:06 PM Dave Allured - NOAA Affiliate <<a href="mailto:dave.allured@noaa.gov">dave.allured@noaa.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>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.</div><div><br></div><div>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.</div><div><br></div><div>There is more than one way to fix this.  I recommend the following.  (1) and (2) for sure, (3) is optional in this case.</div><div><br></div><div>(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".</div><div>(2) Use function ut_string rather than cd_string.</div><div>(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.</div><div><br></div><div>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.</div><div><br></div><div>--Dave</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 12, 2019 at 12:52 PM Sakib Ahmed via ncl-talk <<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello NCL Community,<div><br></div><div>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:</div><div><br></div><div>---------------------------------------------------------------------------</div><div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"<br>load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"<br><br></div><div>; model start time 2017-09-10 12Z<br><br>syyyy = 2017<br>smm = 09<br>sdd = 10<br>shh = 12<br><br>; model end time 2017-09-11 03Z<br><br><br>eyyyy = 2017<br>emm = 09<br>edd = 11<br>ehh = 03<br><br>timeUnits = "hours since 1800-01-01 00:00:00"<br><br></div><div>sdate = cd_inv_calendar(syyyy,smm,sdd,shh,00,00,timeUnits,0)<br>edate = cd_inv_calendar(eyyyy,emm,edd,ehh,00,00,timeUnits,0)<br><br>ntimes = toint((edate-sdate)/.01666666667) +1 ; model has 900 steps, each step is 1 minute<br><br>times = new( (/ntimes/), "float")<br><br>times@units = timeUnits<br><br>do n=0,ntimes-1<br></div><div>   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.<br> end do<br><br> time_str = cd_string(times,"%H%M UTC %d %c %Y")<br><br>print(time_str)<br></div><div><br></div><div>------------------------------------------</div><div>Variable: time_str<br>Type: string<br>Total Size: 7200 bytes<br>            900 values<br>Number of Dimensions: 1<br>Dimensions and sizes:   [900]<br>Coordinates:<br>Number Of Attributes: 1<br>  _FillValue :  missing<br>(0)     1200 UTC 10 Sep 2017<br>(1)     1200 UTC 10 Sep 2017<br>(2)     1200 UTC 10 Sep 2017<br>(3)     1200 UTC 10 Sep 2017<br>(4)     1207 UTC 10 Sep 2017<br>(5)     1207 UTC 10 Sep 2017<br>(6)     1207 UTC 10 Sep 2017<br>(7)     1207 UTC 10 Sep 2017<br>(8)     1207 UTC 10 Sep 2017<br>(9)     1207 UTC 10 Sep 2017<br>(10)    1207 UTC 10 Sep 2017<br>(11)    1207 UTC 10 Sep 2017<br>(12)    1215 UTC 10 Sep 2017<br>(13)    1215 UTC 10 Sep 2017<br></div><div>.</div><div>.</div><div>.</div><div>(891)   0252 UTC 11 Sep 2017<br>(892)   0252 UTC 11 Sep 2017<br>(893)   0252 UTC 11 Sep 2017<br>(894)   0252 UTC 11 Sep 2017<br>(895)   0252 UTC 11 Sep 2017<br>(896)   0252 UTC 11 Sep 2017<br>(897)   0300 UTC 11 Sep 2017<br>(898)   0300 UTC 11 Sep 2017<br>(899)   0300 UTC 11 Sep 2017</div><div><br></div><div>--</div><div>Thank you, </div><div>Sakib Ahmed</div><div>Connecticut College<br></div><div>Environmental Studies Major,<br></div><div>New London, CT 06320</div></div></blockquote></div></div></div></div></div>
</blockquote></div></div>