Re: time conversion

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Mon Jul 18 2011 - 07:46:59 MDT

I speculate that the ut_calendar function printed a message
saying that it encountered an invalid input string and that
all values were being set to missing)_FillValue).

ut_calendar (5.2.1) expects dates that are udunits-2 conformant.
The documentation notes:

=====
     Must have a units attribute in one of the formats
     recognized by the UDUNITS-2 library

     Caveats of UDUNITS-2:

     Year 0 is treated as year 1, because year 0 does not exist
     in the real world calendar.

     Udunits doesn't like uppercase values in the "units" string.
     For example, "HOURS since 1-1-1 00:00:0.0" is not a valid string,
     but "hours since 1-1-1 00:00:0.0" is.
========================================================

The following is *not* udunits conformant:

units : Days since Jan-1-0000 (MATLAB datenum format)
=========================================================
Try:

  f = addfile("mldinfo_consDT.nc", "r")
  date = f->date(:,0) ; (579611)

  date = date - 1 ; ??? Matlab vs udunits convention

  date@units = "days since 1-1-1 00:00:0.0" ; udunits conformant
or
  date@units = "days since 0000-1-1 00:00:0.0"

  ymdhms = ut_calendar(date,0)
  print(ymdhms)

On 7/18/11 1:58 AM, shinn wong wrote:
> Dear all,
> I still cannot figure out what´s wrong with my dataset that will lead to
> missing value after using ut_calendar. The dataset I used is
> mldinfo_varDT.nc downloaded from http://mixedlayer.ucsd.edu/. Could
> anyone help me with that? Thanks in advance for any help and suggestion.
> Shinn
>
> 2011/7/15 Dennis Shea <shea@ucar.edu <mailto:shea@ucar.edu>>
>
> Prior to using cd_calendar you should use a print
>
> print(time)
>
> date = ut_calendar(time,0)
>
> It is possible that time does not contain some valis values
>
>
>
> On 07/15/2011 10:33 AM, shinn wong wrote:
>
> Dear Dennis,
> Thank you for your help. I am using version 5.5.1. But when I
> used date
> = ut_calendar(time,0), missing value was returned. The dataset
> is too
> large to be sent. I would be much appreciated for any help and
> suggestion.
> Shinn
>
> 2011/7/11 Dennis Shea <shea@ucar.edu <mailto:shea@ucar.edu>
> <mailto:shea@ucar.edu <mailto:shea@ucar.edu>>>
>
>
> I don't use Matlab but maybe ...
>
> time = (/730848.5, 730848.9/)
> time@units = "days since Jan-1-0000 00:00:00"
>
> date = cd_calendar(time,0) ; year,month,day,hour,minute,sec
> print(date)
>
> Due to the way 'cd_calendar' defines the initial day, you may
> need to subtract 1 day
>
> So ...
>
> time = (/730848.5, 730848.9/) - 1 ; ?? adjust for
> different start day
> date = cd_calendar(time,0)
> print(date)
>
> =====
> The inverse is true also
>
> t = cd_inv_calendar(2001,5,19,0,0,____0,units,0) - 1 ;
> Matlab datenum
> print(t)
> ========
> cd_calendar is in v6.0.0
>
> if you have an older version of NCL use
>
> date = ut_calendar(time,0)
>
> BUT in ut_calendar year 0 is treated like year 1 ...
> so test to get the correct day
>
> # Year 0 is not treated as year 1, like it is with the
> ut_calendar
> and ut_inv_calendar functions.
>
> =======
>
>
> http://www.ncl.ucar.edu/____Document/Functions/Built-in/____cd_calendar.shtml
> <http://www.ncl.ucar.edu/__Document/Functions/Built-in/__cd_calendar.shtml>
> <http://www.ncl.ucar.edu/__Document/Functions/Built-in/__cd_calendar.shtml
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/cd_calendar.shtml>>
>
> http://www.ncl.ucar.edu/____Document/Functions/Built-in/____cd_inv_calendar.shtml
> <http://www.ncl.ucar.edu/__Document/Functions/Built-in/__cd_inv_calendar.shtml>
> <http://www.ncl.ucar.edu/__Document/Functions/Built-in/__cd_inv_calendar.shtml
> <http://www.ncl.ucar.edu/Document/Functions/Built-in/cd_inv_calendar.shtml>>
>
> Good luck
>
>
> On 7/10/11 9:55 PM, shinn wong wrote:
>
> Dear all,
> I've got a netcdf file with time in the MATLAB datenum
> format (eg.
> 730848.5, 730848.9, etc). How can I convert it into a
> UT-referenced date
> using ncl? Thanks in advance for any help and suggestions.
> Regards,
> Shinn
>
>
>
>
> --
> ==============================__========================
> Dennis J. Shea tel: 303-497-1361 |
> P.O. Box 3000 fax: 303-497-1333 |
> Climate Analysis Section |
> Climate & Global Dynamics Div. |
> National Center for Atmospheric Research |
> Boulder, CO 80307 |
> USA email: shea 'at' ucar.edu <http://ucar.edu> |
> ==============================__========================
>
>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Jul 18 07:47:08 2011

This archive was generated by hypermail 2.1.8 : Mon Jul 18 2011 - 15:57:57 MDT