[ncl-talk] Strange units of time

Beáta Szabó-Takács szabo.b at czechglobe.cz
Thu May 31 09:23:31 MDT 2018


Hi Rick,
Please ignore my previous email. I checked again my test.h5 file with a brief ncl script where I used cd_calendar function:

begin

f = addfile("test.h5","r")

time = f->time(0)

utc_date = cd_calendar(time,0)
  year   = tointeger(utc_date(:,0))    ; Convert to integer for
   month  = tointeger(utc_date(:,1))    ; use sprinti
   day    = tointeger(utc_date(:,2))
   hour   = tointeger(utc_date(:,3))
   minute = tointeger(utc_date(:,4))
   second = tointeger(utc_date(:,5))

date_str = sprinti("%0.4i", year) +"-"+ sprinti("%0.2i", month) +"-"+ sprinti("%0.2i ", day) + \
               sprinti("%0.2i ", hour) + sprinti("%0.2i ", minute)+ sprinti("%0.2i ", second)


print(date_str)
print(time)
print(utc_date)

and I got correct time value with this function:
Variable: date_str
Type: string
Total Size: 8 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes:   [1]
Coordinates:
(0)     2017-07-01 00 00 05


Variable: time
Type: double
Total Size: 8 bytes
            1 values
Number of Dimensions: 1
Dimensions and sizes:   [DIM_000 | 1]
Coordinates:
Number Of Attributes: 1
  units :       days since 1970-01-01
(0)     17348.00006944444


Variable: utc_date
Type: float
Total Size: 24 bytes
            6 values
Number of Dimensions: 2
Dimensions and sizes:   [1] x [6]
Coordinates:
Number Of Attributes: 1
  calendar :    standard
(0,0)   2017
(0,1)    7
(0,2)    1
(0,3)    0
(0,4)    0
(0,5)   06

However, date_str gives one second earlier time. Moreover, I also checked the test.h5 file in CDO with cdo sinfo test.h5 and it also gives correct time values.
Best regards, Beata


________________________________
From: ncl-talk <ncl-talk-bounces at ucar.edu> on behalf of Beáta Szabó-Takács <szabo.b at czechglobe.cz>
Sent: Wednesday, May 30, 2018 5:56:48 PM
To: Rick Brownrigg
Cc: ncl-talk (ncl-talk at ucar.edu)
Subject: Re: [ncl-talk] Strange units of time


Hi Rick,

Thank you for your response. I use NCL in a server where NCL 6.3 and NCL 6.4.0 are installed. If I want to use NCL 6.4.0 I have to export NCARG_ROOT=/opt/ncl640 export PATH=$NCARG_ROOT/bin/:$PATH. To be honest I forgot to export. I checked it with NCL 6.4.0 as well and I got correct units. I checked the test.h5 in Panoply as well.



I do not understand why NCL and Panoply are not able to convert the serial date to date even though I add an attribute as units is days since 1971-01-01? I created also NetCDF file in Java based on https://www.unidata.ucar.edu/software/thredds/current/netcdf-java/tutorial/NetcdfWriting.html and I used the same serial date number with same attribute and both Panoply and NCL are able to convert it to date. Is it possible that the matter is that the time can be declared as dimension in NetCDF file e.g:



Dimension timeDim = ncfile.addUnlimitedDimension("time");

Variable time = ncfile.addVariable(null, "time", DataType.DOUBLE, "time");

time.addAttribute( new Attribute("units", "days since 1970-01-01"));



but it is not possible in HDF5?

Thank you for your response in advance!

Best regards,

Beata





From: Rick Brownrigg [mailto:brownrig at ucar.edu]
Sent: Wednesday, May 30, 2018 3:15 PM
To: Beáta Szabó-Takács <szabo.b at czechglobe.cz>
Cc: ncl-talk (ncl-talk at ucar.edu) <ncl-talk at ucar.edu>
Subject: Re: [ncl-talk] Strange units of time



Hi,

Its hard to say where the issue lies, offhand. Do you have other tools that can look at that HDF5 file, and is the odd units string absent there?

If so, what version of NCL are you using?  If you are using the latest, 6.4.0, are you able to send that HDF5 file to me? (either email directly, is not too large, or see the instructions about our FTP site:

   http://ncl.ucar.edu/ftp_files.shtml

)

Rick





On Wed, May 30, 2018 at 2:38 AM, Beáta Szabó-Takács <szabo.b at czechglobe.cz<mailto:szabo.b at czechglobe.cz>> wrote:

Dear NCL Users,

I wrote a HDF5 file in Java by IHDF5Writer http://svnsis.ethz.ch/doc/openbis/S176.0/ch/systemsx/cisd/hdf5/IHDF5Writer.html

Because IHDF5Writer can write timestamps as number of milliseconds since January 1, 1970, 00:00:00 GMT I converted the java.Util.Date to serial date number as days since 1970-01-01.

I wrote the time values into HDF5 file

writer.writeDoubleArray("time", time);

writer.string().setAttr("time", "units", "days since 1970-01-01");



I checked the resulted test.h5 in NCL and printed the time variable and I got the following result:

fn = "test.h5"

fi = addfile(fn, "r")

time = fi->time

time1 = time(0)

print(time1)



Variable: time1

Type: double

Total Size: 8 bytes

            1 values

Number of Dimensions: 1

Dimensions and sizes:   [1]

Coordinates:

Number Of Attributes: 1

  units :       days since 1970-01-01tyeratelatedofileion

(0)     17348.00006944444



Can someone let me know why ncl receive a strange units?



_______________________________________________
ncl-talk mailing list
ncl-talk at ucar.edu<mailto:ncl-talk at ucar.edu>
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/20180531/3db661d2/attachment.html>


More information about the ncl-talk mailing list