[ncl-talk] problem of cd_calendar

Dave Allured - NOAA Affiliate dave.allured at noaa.gov
Wed Aug 7 08:39:01 MDT 2024


Lzl lai, the first argument to the cd_calendar function must be one of the
NCL basic "numeric" data types.  See the function documentation.  Your
"time" variable is type int64, which is "extra-numeric", not "numeric".
Please see the NCL reference manual under "Basic numeric types".  The
cd_calendar function needs to be updated, but NCL is not receiving
maintenance right now.

The easy fix is to convert your "time" variable to type "double" before
input to cd_calendar.  This will probably work fine for units = "seconds
since 1970-01-01".

However, there is a risk of loss of precision if some of your int64 time
values are outside the range of exact integer representation for type
double.  You can check for exact conversion like this (untested):

time2 = todouble (time)
time3 = toint64 (time2)
if (any (time3 .ne. time)) then
   print ("Warning, loss of precision when converting time coordinates.")
   max_dif = max (abs (time3 - time))
   print ("Maximum precision loss = " + max_dif + " seconds.")
end if


On Wed, Aug 7, 2024 at 2:10 AM lzl lai via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Hi,
> I have a problem using cd_calendar to convert time variable to a
> UT-referenced date.
> my data is ECMWF( monthly reanalysis), their valid_time type is int64
> when I use cd_calendar, it shows fatal message:
> --------
> Variable: time
> Type: int64
> Total Size: 8120 bytes
>             1015 values
> Number of Dimensions: 1
> Dimensions and sizes:   [valid_time | 1015]
> Coordinates:
>             valid_time: [-946771200..1719792000]
> Number Of Attributes: 4
>   long_name :   time
>   standard_name :       time
>   units :       seconds since 1970-01-01
>   calendar :    proleptic_gregorian
> fatal:Argument type mismatch on argument (0) of (cd_calendar) can not
> coerce
> --------------------
>
> Can anyone help me to deal with  this problem? Thank you very much
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20240807/716ccd75/attachment.htm>


More information about the ncl-talk mailing list