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.
Hi All,I've been exploring the use of GridDataset object in order to get a Date object from the NetcdfDataset without identifying time units, etc.
So far I'm only getting nulls when using gds.getStartDate(), gds.getEndDate()
I've attached my test class. The other bounds are retrieved without problem.
Thanks for your suggestions. Dave
package gov.noaa.eds.threddsutilities.util; import java.util.List; import org.junit.Test; import ucar.nc2.constants.AxisType; import ucar.nc2.dataset.CoordinateAxis; import ucar.nc2.dataset.NetcdfDataset; import ucar.nc2.dt.TypedDatasetFactory; import ucar.nc2.dt.grid.GridDataset; import static org.junit.Assert.*; public class ThreddsExtentUtilTest { @Test public void gdsTest() { String urlStr = "http://edac-dap.northerngulfinstitute.org/thredds/dodsC/ncom_reg1_agg/NCOM_Region_1_Aggregation_fmrc.ncd"; try { NetcdfDataset ncd = NetcdfDataset.openDataset(urlStr); List<CoordinateAxis> coordAxes = ncd.getCoordinateAxes(); StringBuilder errlog = new StringBuilder(); GridDataset gds = (GridDataset)TypedDatasetFactory.open(ucar.nc2.constants.FeatureType.GRID, ncd, null, errlog); for (CoordinateAxis coordAxis : coordAxes) { if (coordAxis.getAxisType()==AxisType.Lat) { System.out.println("GridDataset minLat=" + gds.getBoundingBox().getLatMin()); System.out.println("GridDataset maxLat=" + gds.getBoundingBox().getLatMax()); System.out.println("CoordAxis minLat=" + Double.toString(coordAxis.getMaxValue())); System.out.println("CoordAxis maxLat=" + Double.toString(coordAxis.getMaxValue())); } if (coordAxis.getAxisType()==AxisType.Time) { if (gds.getStartDate()!=null) { //Ideal if we can get a Date object System.out.println("GridDataset startTime=" + gds.getStartDate().toGMTString()); } else { System.out.println("GridDataset startTime=null"); } if (gds.getEndDate()!=null) { //Ideal if we can get a Date object System.out.println("GridDataset endTime=" + gds.getEndDate().toGMTString()); } else { System.out.println("GridDataset endTime=null"); } System.out.println("CoordAxis startTime=" + Double.toString(coordAxis.getMinValue())); System.out.println("CoordAxis endTime=" + Double.toString(coordAxis.getMaxValue())); } } } catch (Exception e) { e.printStackTrace(); } } }
netcdf-java
archives: