static void doOne( String dir, String filename, int ngrids, int ncoordSys, int ncoordAxes, int nVertCooordAxes) throws Exception { System.out.println("test read GridDataset = " + dir + filename); ucar.nc2.dt.grid.GridDataset gridDs = GridDataset.open(dir + filename); int countGrids = gridDs.getGrids().size(); int countCoordAxes = gridDs.getNetcdfDataset().getCoordinateAxes().size(); int countCoordSys = gridDs.getNetcdfDataset().getCoordinateSystems().size(); // count vertical axes int countVertCooordAxes = 0; List axes = gridDs.getNetcdfDataset().getCoordinateAxes(); for (int i = 0; i < axes.size(); i++) { CoordinateAxis axis = (CoordinateAxis) axes.get(i); AxisType t = axis.getAxisType(); if ((t == AxisType.GeoZ) || (t == AxisType.Height) || (t == AxisType.Pressure)) countVertCooordAxes++; } Iterator iter = gridDs.getGridsets().iterator(); while (iter.hasNext()) { GridDataset.Gridset gridset = (GridDataset.Gridset) iter.next(); GridCoordSys gcs = gridset.getGeoCoordSys(); // if (gcs.hasTimeAxis()) // System.out.println(" "+gcs.isDate()+" "+gcs.getName()); } if (showCount) { System.out.println(" grids=" + countGrids + ((ngrids < 0) ? " *" : "")); System.out.println(" coordSys=" + countCoordSys + ((ncoordSys < 0) ? " *" : "")); System.out.println(" coordAxes=" + countCoordAxes + ((ncoordAxes < 0) ? " *" : "")); System.out.println(" vertAxes=" + countVertCooordAxes + ((nVertCooordAxes < 0) ? " *" : "")); } if (ngrids >= 0) assert ngrids == countGrids : "Grids " + ngrids + " != " + countGrids; // if (ncoordSys >= 0) // assert ncoordSys == countCoordSys : "CoordSys " + ncoordSys + " != " + countCoordSys; // if (ncoordAxes >= 0) // assert ncoordAxes == countCoordAxes : "CoordAxes " + ncoordAxes + " != " + countCoordAxes; if (nVertCooordAxes >= 0) assert nVertCooordAxes == countVertCooordAxes : "VertAxes " + nVertCooordAxes + " != " + countVertCooordAxes; gridDs.close(); }
public void utestReadNcMLInputStream() throws Exception { String ncmlLoc = "file:C:\\data\\work\\margolis\\test.ncml"; GridDataset fullDataset = GridDataset.open(ncmlLoc); System.out.printf("full size= %d%n", fullDataset.getGrids().size()); // real ncml through a InputStream. String ncml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='time'>\n" + " <attribute name='ncmlAdded' value='timeAtt'/>\n" + " </variable>\n" + " <aggregation dimName='time' type='joinExisting'>\n" + " <netcdf location='file:C:\\data\\work\\margolis\\f_0000000.nc'/>\n" + " <netcdf location='file:C:\\data\\work\\margolis\\f_0032400.nc'/>\n" + " </aggregation>\n" + "</netcdf>"; NetcdfDataset aggregatedDataset = NcMLReader.readNcML(new ByteArrayInputStream(ncml.getBytes()), null); GridDataset emptyDataset = new GridDataset(aggregatedDataset); System.out.printf("empty= %s%n", emptyDataset.getGrids().size()); assert emptyDataset.getGrids().size() == fullDataset.getGrids().size(); }