[ncl-talk] Bug in cd_string

Kyle Griffin ksgriffin2 at wisc.edu
Mon Oct 13 23:07:45 MDT 2014


I remember some discussion on this topic on the list a couple years ago.
Although I didn't find that particular thread, a similar one came to light
from 2008 highlighting the problem at hand.

https://www.ncl.ucar.edu/Support/talk_archives/2008/0946.html

If I remember from the last time, the fact that most time values must be
doubles costs some precision when it comes to seconds (I didn't think
minutes were affected, although it appears they are indirectly) and the
dates are also not accurate in very early years, although for a different
reason (prior to the last major shift in the Gregorian calendar, I believe,
late 1600s?).

With increasingly high-resolution datasets (e.g. the "new" HRRR from NCEP -
data every 15 minutes, http://www.nco.ncep.noaa.gov/pmb/products/hrrr/),
both spatially and temporally, the minutes portion of this bug might be
worth tackling as the potential issues now might be more frequent than they
may have been in the past.


Kyle

----------------------------------------
Kyle S. Griffin
Department of Atmospheric and Oceanic Sciences
University of Wisconsin - Madison
Room 1421
1225 W Dayton St, Madison, WI 53706
Email: ksgriffin2 at wisc.edu

On Mon, Oct 13, 2014 at 11:48 PM, Mary Haley <haley at ucar.edu> wrote:

> Jared,
>
> I will try to look into this, but I don't know how soon I can get to it.
> Does ut_string give you the same problem?
>
> I think we may already have a ticket on this issue, NCL-1829, so I will
> add your nice test script to this ticket.
>
>
> --Mary
>
> On Fri, Oct 10, 2014 at 9:43 AM, Jared Lee <jaredlee at ucar.edu> wrote:
>
>> Hi, I believe I've found a bug in the cd_string function in NCL v6.2.0
>> (I'm running on NCAR's Yellowstone supercomputer).  It seems like it's
>> possibly a rounding error.  Here's sample code to demonstrate the bug:
>>
>> =====
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/contrib/cd_string.ncl"
>>
>> begin
>> do testMin = 0, 60, 1
>>    testMin at units = "minutes since 2014-01-01 00:00:00"
>>    print("testMin = "+testMin+" -> "+cd_string(testMin, "%N/%D/%Y,
>> %H:%M:%S"))
>> end do
>> do testSec = 0, 3600, 60
>>    testSec at units = "seconds since 1970-01-01 00:00:00"
>>    print("testSec = "+testSec+" -> "+cd_string(testSec, "%N/%D/%Y,
>> %H:%M:%S"))
>> end do
>> end
>> =====
>>
>> This script gives the following output.  Notice that the seconds field
>> sometimes returns a value of "00", and sometimes returns a value of "60".
>> This means that sometimes the minutes value is not correct, which is
>> problematic for my applications, where I'm trying to match a string
>> returned from cd_string with an observation time in a data file (and those,
>> of course, never have 60 in the seconds field).  Note also that this is a
>> problem that occurs with different time units.  Here is the output:
>>
>> =====
>> (0)    testMin = 0 -> 01/01/2014, 00:00:00
>> (0)    testMin = 1 -> 01/01/2014, 00:00:60
>> (0)    testMin = 2 -> 01/01/2014, 00:01:60
>> (0)    testMin = 3 -> 01/01/2014, 00:02:60
>> (0)    testMin = 4 -> 01/01/2014, 00:03:60
>> (0)    testMin = 5 -> 01/01/2014, 00:04:60
>> (0)    testMin = 6 -> 01/01/2014, 00:05:60
>> (0)    testMin = 7 -> 01/01/2014, 00:06:60
>> (0)    testMin = 8 -> 01/01/2014, 00:08:00
>> (0)    testMin = 9 -> 01/01/2014, 00:09:00
>> (0)    testMin = 10 -> 01/01/2014, 00:10:00
>> (0)    testMin = 11 -> 01/01/2014, 00:11:00
>> (0)    testMin = 12 -> 01/01/2014, 00:12:00
>> (0)    testMin = 13 -> 01/01/2014, 00:13:00
>> (0)    testMin = 14 -> 01/01/2014, 00:14:00
>> (0)    testMin = 15 -> 01/01/2014, 00:15:00
>> (0)    testMin = 16 -> 01/01/2014, 00:15:60
>> (0)    testMin = 17 -> 01/01/2014, 00:16:60
>> (0)    testMin = 18 -> 01/01/2014, 00:17:60
>> (0)    testMin = 19 -> 01/01/2014, 00:18:60
>> (0)    testMin = 20 -> 01/01/2014, 00:19:60
>> (0)    testMin = 21 -> 01/01/2014, 00:20:60
>> (0)    testMin = 22 -> 01/01/2014, 00:21:60
>> (0)    testMin = 23 -> 01/01/2014, 00:23:00
>> (0)    testMin = 24 -> 01/01/2014, 00:24:00
>> (0)    testMin = 25 -> 01/01/2014, 00:25:00
>> (0)    testMin = 26 -> 01/01/2014, 00:26:00
>> (0)    testMin = 27 -> 01/01/2014, 00:27:00
>> (0)    testMin = 28 -> 01/01/2014, 00:28:00
>> (0)    testMin = 29 -> 01/01/2014, 00:29:00
>> (0)    testMin = 30 -> 01/01/2014, 00:30:00
>> (0)    testMin = 31 -> 01/01/2014, 00:30:60
>> (0)    testMin = 32 -> 01/01/2014, 00:31:60
>> (0)    testMin = 33 -> 01/01/2014, 00:32:60
>> (0)    testMin = 34 -> 01/01/2014, 00:33:60
>> (0)    testMin = 35 -> 01/01/2014, 00:34:60
>> (0)    testMin = 36 -> 01/01/2014, 00:35:60
>> (0)    testMin = 37 -> 01/01/2014, 00:36:60
>> (0)    testMin = 38 -> 01/01/2014, 00:38:00
>> (0)    testMin = 39 -> 01/01/2014, 00:39:00
>> (0)    testMin = 40 -> 01/01/2014, 00:40:00
>> (0)    testMin = 41 -> 01/01/2014, 00:41:00
>> (0)    testMin = 42 -> 01/01/2014, 00:42:00
>> (0)    testMin = 43 -> 01/01/2014, 00:43:00
>> (0)    testMin = 44 -> 01/01/2014, 00:44:00
>> (0)    testMin = 45 -> 01/01/2014, 00:45:00
>> (0)    testMin = 46 -> 01/01/2014, 00:45:60
>> (0)    testMin = 47 -> 01/01/2014, 00:46:60
>> (0)    testMin = 48 -> 01/01/2014, 00:47:60
>> (0)    testMin = 49 -> 01/01/2014, 00:48:60
>> (0)    testMin = 50 -> 01/01/2014, 00:49:60
>> (0)    testMin = 51 -> 01/01/2014, 00:50:60
>> (0)    testMin = 52 -> 01/01/2014, 00:51:60
>> (0)    testMin = 53 -> 01/01/2014, 00:53:00
>> (0)    testMin = 54 -> 01/01/2014, 00:54:00
>> (0)    testMin = 55 -> 01/01/2014, 00:55:00
>> (0)    testMin = 56 -> 01/01/2014, 00:56:00
>> (0)    testMin = 57 -> 01/01/2014, 00:57:00
>> (0)    testMin = 58 -> 01/01/2014, 00:58:00
>> (0)    testMin = 59 -> 01/01/2014, 00:59:00
>> (0)    testMin = 60 -> 01/01/2014, 01:00:00
>> (0)    testSec = 0 -> 01/01/1970, 00:00:00
>> (0)    testSec = 60 -> 01/01/1970, 00:00:60
>> (0)    testSec = 120 -> 01/01/1970, 00:02:00
>> (0)    testSec = 180 -> 01/01/1970, 00:03:00
>> (0)    testSec = 240 -> 01/01/1970, 00:03:60
>> (0)    testSec = 300 -> 01/01/1970, 00:04:60
>> (0)    testSec = 360 -> 01/01/1970, 00:06:00
>> (0)    testSec = 420 -> 01/01/1970, 00:07:00
>> (0)    testSec = 480 -> 01/01/1970, 00:07:60
>> (0)    testSec = 540 -> 01/01/1970, 00:08:60
>> (0)    testSec = 600 -> 01/01/1970, 00:10:00
>> (0)    testSec = 660 -> 01/01/1970, 00:11:00
>> (0)    testSec = 720 -> 01/01/1970, 00:11:60
>> (0)    testSec = 780 -> 01/01/1970, 00:12:60
>> (0)    testSec = 840 -> 01/01/1970, 00:14:00
>> (0)    testSec = 900 -> 01/01/1970, 00:15:00
>> (0)    testSec = 960 -> 01/01/1970, 00:15:60
>> (0)    testSec = 1020 -> 01/01/1970, 00:17:00
>> (0)    testSec = 1080 -> 01/01/1970, 00:18:00
>> (0)    testSec = 1140 -> 01/01/1970, 00:18:60
>> (0)    testSec = 1200 -> 01/01/1970, 00:19:60
>> (0)    testSec = 1260 -> 01/01/1970, 00:21:00
>> (0)    testSec = 1320 -> 01/01/1970, 00:22:00
>> (0)    testSec = 1380 -> 01/01/1970, 00:22:60
>> (0)    testSec = 1440 -> 01/01/1970, 00:23:60
>> (0)    testSec = 1500 -> 01/01/1970, 00:25:00
>> (0)    testSec = 1560 -> 01/01/1970, 00:26:00
>> (0)    testSec = 1620 -> 01/01/1970, 00:26:60
>> (0)    testSec = 1680 -> 01/01/1970, 00:27:60
>> (0)    testSec = 1740 -> 01/01/1970, 00:29:00
>> (0)    testSec = 1800 -> 01/01/1970, 00:30:00
>> (0)    testSec = 1860 -> 01/01/1970, 00:30:60
>> (0)    testSec = 1920 -> 01/01/1970, 00:32:00
>> (0)    testSec = 1980 -> 01/01/1970, 00:33:00
>> (0)    testSec = 2040 -> 01/01/1970, 00:33:60
>> (0)    testSec = 2100 -> 01/01/1970, 00:34:60
>> (0)    testSec = 2160 -> 01/01/1970, 00:36:00
>> (0)    testSec = 2220 -> 01/01/1970, 00:37:00
>> (0)    testSec = 2280 -> 01/01/1970, 00:37:60
>> (0)    testSec = 2340 -> 01/01/1970, 00:38:60
>> (0)    testSec = 2400 -> 01/01/1970, 00:40:00
>> (0)    testSec = 2460 -> 01/01/1970, 00:41:00
>> (0)    testSec = 2520 -> 01/01/1970, 00:41:60
>> (0)    testSec = 2580 -> 01/01/1970, 00:42:60
>> (0)    testSec = 2640 -> 01/01/1970, 00:44:00
>> (0)    testSec = 2700 -> 01/01/1970, 00:45:00
>> (0)    testSec = 2760 -> 01/01/1970, 00:45:60
>> (0)    testSec = 2820 -> 01/01/1970, 00:47:00
>> (0)    testSec = 2880 -> 01/01/1970, 00:48:00
>> (0)    testSec = 2940 -> 01/01/1970, 00:48:60
>> (0)    testSec = 3000 -> 01/01/1970, 00:49:60
>> (0)    testSec = 3060 -> 01/01/1970, 00:51:00
>> (0)    testSec = 3120 -> 01/01/1970, 00:52:00
>> (0)    testSec = 3180 -> 01/01/1970, 00:52:60
>> (0)    testSec = 3240 -> 01/01/1970, 00:53:60
>> (0)    testSec = 3300 -> 01/01/1970, 00:55:00
>> (0)    testSec = 3360 -> 01/01/1970, 00:56:00
>> (0)    testSec = 3420 -> 01/01/1970, 00:56:60
>> (0)    testSec = 3480 -> 01/01/1970, 00:57:60
>> (0)    testSec = 3540 -> 01/01/1970, 00:59:00
>> (0)    testSec = 3600 -> 01/01/1970, 01:00:00
>> =====
>>
>> Is there an easy fix to this bug?
>>
>> Jared
>>
>> --
>> ===============================
>> Jared A. Lee, Ph.D.
>> Project Scientist I
>> Research Applications Laboratory
>> National Center for Atmospheric Research
>> Boulder, Colorado, USA
>>
>> Email: jaredlee at ucar.edu (w)
>> Phone: 303.497.8485 (w)
>> Web: https://staff.ucar.edu/users/jaredlee
>> ===============================
>>
>> _______________________________________________
>> ncl-talk mailing list
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20141014/e53ea7ab/attachment.html 


More information about the ncl-talk mailing list