NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: [netcdf-java] Best practice for getting the initial (and/or final) time values of a Variable?

  • To: James Adams - NOAA Affiliate <james.adams@xxxxxxxx>
  • Subject: Re: [netcdf-java] Best practice for getting the initial (and/or final) time values of a Variable?
  • From: Jon Blower <j.d.blower@xxxxxxxxxxxxx>
  • Date: Wed, 13 Aug 2014 07:02:20 +0000
Hi James,

The ncWMS libraries contain some high-level calls that might help here. The 
uk.ac.rdg.resc.edal.cdm.CdmUtils class is the one you want:

NetcdfDataset nc = NetcdfDataset.open(“/path/to/my/netcdf/file”);
GridDatatype grid = CdmUtils.getGridDatatype(nc, “myvar”);
CoverageMetadata cm = CdmUtils.readCoverageMetadata(grid);
List<DateTime> dateTimes = cm.getTimeValues();

This gives a list of all the DateTime objects (these are from the joda-time 
library) in the time axis of the variable “myvar”. They will be referenced to a 
given Chronology (i.e. calendar system), which you can find through 
cm.getChronology().

The main snag is that your variable has to be fully georeferenced, otherwise 
readCoverageMetadata() won’t work. A common problem here is that the vertical 
axis isn’t always well defined in NetCDF files.

If you’re interested in this solution you can build a jar containing the above 
code:

svn checkout svn://svn.code.sf.net/p/ncwms/code/trunk ncwms
cd ncwms
ant jar-for-THREDDS

Hope this helps,
Jon


--
Dr Jon Blower,
Technical Director, Reading e-Science Centre,
MELODIES project coordinator,
School of Mathematical and Physical Sciences,
University of Reading
Tel: +44 118 378 5213
Email: j.d.blower@xxxxxxxxxxxxx




  • 2014 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: