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