totalBytes = CFGridWriter2.writeFile(gds, null, null, null, 1, null, null, 1, true, writer); } catch (Throwable e) { e.printStackTrace();
/** * Compute the size of the file without writing * * @param gds the GridDataset * @param gridList the list of variables to be written, or null for all * @param llbb the lat/lon bounding box, or null for all * @param projRect the projection bounding box, or null for all * @param horizStride the x and y stride * @param zRange the z stride * @param dateRange date range, or null for all * @param stride_time the time stride * @param addLatLon add 2D lat/lon coordinates if needed * @return total bytes written * @throws IOException * @throws InvalidRangeException */ static public long makeSizeEstimate(ucar.nc2.dt.GridDataset gds, List<String> gridList, LatLonRect llbb, ProjectionRect projRect, int horizStride, Range zRange, CalendarDateRange dateRange, int stride_time, boolean addLatLon) throws IOException, InvalidRangeException { CFGridWriter2 writer2 = new CFGridWriter2(); return writer2.writeOrTestSize(gds, gridList, llbb, projRect, horizStride, zRange, dateRange, stride_time, addLatLon, true, null); }
Range timeRange = makeTimeRange(dateRange, gcsOrg.getTimeAxis1D(), stride_time); Range zRangeUse = makeVerticalRange(zRange, gcsOrg.getVerticalAxis()); // LOOK no vert stride makeHorizRange(gcsOrg, projRect, horizStride, yxRanges); gridWant = gridOrg.makeSubset(null, null, timeRange, zRangeUse, yxRanges.get(0), yxRanges.get(1)); addCoordinateAxis(gcsWant, varNameList, varList, axisList); addCoordinateTransform(gcsWant, ncd, varNameList, varList); total_size += processTransformationVars(varList, varNameList, ncd, gds, gridWant, timeRange, zRangeUse, yxRanges.get(0), yxRanges.get(1), horizStride, horizStride); Projection proj = gcsWant.getProjection(); if ((null != proj) && !(proj instanceof LatLonProjection)) { total_size += addLatLon2D(ncd, varList, proj, gcsWant.getXHorizAxis(), gcsWant.getYHorizAxis()); addLatLon = false; // ?? boolean isLargeFile = isLargeFile(total_size); writer.setLargeFile(isLargeFile); if (resultBB != null) addGlobalAttributes(writer, gds, resultBB); fileWriter.addVariable(v); addCFAnnotations(writer, gds, gridList, ncd, axisList, addLatLon);
private void convertProjectionCTV(NetcdfDataset ds, Variable ctv) { Attribute att = ctv.findAttribute(_Coordinate.TransformType); if ((null != att) && att.getStringValue().equals("Projection")) { Attribute east = ctv.findAttribute("false_easting"); Attribute north = ctv.findAttribute("false_northing"); if ((null != east) || (null != north)) { double scalef = AbstractTransformBuilder.getFalseEastingScaleFactor(ds, ctv); if (scalef != 1.0) { convertAttribute(ctv, east, scalef); convertAttribute(ctv, north, scalef); } } } }
convertProjectionCTV((NetcdfDataset) gds.getNetcdfFile(), v); ctvList.add(v);
Range timeRange = makeTimeRange(dateRange, gcsOrg.getTimeAxis1D(), stride_time); Range zRangeUse = makeVerticalRange(zRange, gcsOrg.getVerticalAxis()); // no stride makeHorizRange(gcsOrg, projRect, horizStride, yxRanges); grid = grid.makeSubset(null, null, timeRange, zRangeUse, yxRanges.get(0), yxRanges.get(1)); addCoordinateAxis(gcs, varNameList, varList, axisList); addCoordinateTransform(gcs, ncd, varNameList, varList); total_size += processTransformationVars(varList, varNameList, ncd, gds, grid, timeRange, zRangeUse, yxRanges.get(0), yxRanges.get(1), horizStride, horizStride); Projection proj = gcs.getProjection(); if ((null != proj) && !(proj instanceof LatLonProjection)) { total_size += addLatLon2D(ncd, varList, proj, gcs.getXHorizAxis(), gcs.getYHorizAxis()); addLatLon = false; // ?? boolean isLargeFile = isLargeFile(total_size); writer.setLargeFile(isLargeFile); addGlobalAttributes(writer, gds, resultBB); fileWriter.addVariable(v); addCFAnnotations(writer, gds, gridList, ncd, axisList, addLatLon);
private void convertProjectionCTV(NetcdfDataset ds, Variable ctv) { Attribute att = ctv.findAttribute(_Coordinate.TransformType); if ((null != att) && att.getStringValue().equals("Projection")) { Attribute east = ctv.findAttribute("false_easting"); Attribute north = ctv.findAttribute("false_northing"); if ((null != east) || (null != north)) { double scalef = AbstractCoordTransBuilder.getFalseEastingScaleFactor(ds, ctv); if (scalef != 1.0) { convertAttribute(ctv, east, scalef); convertAttribute(ctv, north, scalef); } } } }
convertProjectionCTV((NetcdfDataset) gds.getNetcdfFile(), v); ctvList.add(v);
totalBytes = CFGridWriter2.writeFile(gds, null, null, null, 1, null, null, 1, true, writer); } catch (Throwable e) { e.printStackTrace();
/** * Compute the size of the file without writing * * @param gds the GridDataset * @param gridList the list of variables to be written, or null for all * @param llbb the lat/lon bounding box, or null for all * @param projRect the projection bounding box, or null for all * @param horizStride the x and y stride * @param zRange the z stride * @param dateRange date range, or null for all * @param stride_time the time stride * @param addLatLon add 2D lat/lon coordinates if needed * @return total bytes written * @throws IOException * @throws InvalidRangeException */ static public long makeSizeEstimate(ucar.nc2.dt.GridDataset gds, List<String> gridList, LatLonRect llbb, ProjectionRect projRect, int horizStride, Range zRange, CalendarDateRange dateRange, int stride_time, boolean addLatLon) throws IOException, InvalidRangeException { CFGridWriter2 writer2 = new CFGridWriter2(); return writer2.writeOrTestSize(gds, gridList, llbb, projRect, horizStride, zRange, dateRange, stride_time, addLatLon, true, null); }
@Test public void testNullLatLonRect() throws IOException { String location = tempFolder.newFile().getAbsolutePath(); List<String> gridList = new ArrayList<>(); gridList.add("Temperature_surface"); int stride_time = 1; int horizStride = 1; try { NetcdfFileWriter ncwriter = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, location); CFGridWriter2.writeFile(gds, gridList, null, null, horizStride, null, null, stride_time, false, ncwriter); assert true; } catch (Exception exc) { exc.printStackTrace(); assert false; } }
/** * Write a netcdf/CF file from a GridDataset * * @param gds the GridDataset * @param gridList the list of variables to be written, or null for all * @param llbb the lat/lon bounding box, or null for all * @param projRect the projection bounding box, or null for all * @param horizStride the x and y stride * @param zRange the z stride * @param dateRange date range, or null for all * @param stride_time the time stride * @param addLatLon add 2D lat/lon coordinates if needed * @param writer this does the actual writing * @return total bytes written * @throws IOException * @throws InvalidRangeException */ static public long writeFile(ucar.nc2.dt.GridDataset gds, List<String> gridList, LatLonRect llbb, ProjectionRect projRect, int horizStride, Range zRange, CalendarDateRange dateRange, int stride_time, boolean addLatLon, NetcdfFileWriter writer) throws IOException, InvalidRangeException { CFGridWriter2 writer2 = new CFGridWriter2(); return writer2.writeOrTestSize(gds, gridList, llbb, projRect, horizStride, zRange, dateRange, stride_time, addLatLon, false, writer); }
totalBytes = CFGridWriter2.writeFile(gds, null, null, null, 1, null, null, 1, false, writer); totalBytes /= 1000 * 1000; } catch (Throwable e) {
/** * Write a netcdf/CF file from a GridDataset * * @param gds the GridDataset * @param gridList the list of variables to be written, or null for all * @param llbb the lat/lon bounding box, or null for all * @param projRect the projection bounding box, or null for all * @param horizStride the x and y stride * @param zRange the z stride * @param dateRange date range, or null for all * @param stride_time the time stride * @param addLatLon add 2D lat/lon coordinates if needed * @param writer this does the actual writing * @return total bytes written * @throws IOException * @throws InvalidRangeException */ static public long writeFile(ucar.nc2.dt.GridDataset gds, List<String> gridList, LatLonRect llbb, ProjectionRect projRect, int horizStride, Range zRange, CalendarDateRange dateRange, int stride_time, boolean addLatLon, NetcdfFileWriter writer) throws IOException, InvalidRangeException { CFGridWriter2 writer2 = new CFGridWriter2(); return writer2.writeOrTestSize(gds, gridList, llbb, projRect, horizStride, zRange, dateRange, stride_time, addLatLon, false, writer); }
@Test public void testNullHorizSubset2() throws IOException, InvalidRangeException { boolean addLatLon = false; LatLonRect llbb = null; Range zRange = null; CalendarDateRange dateRange = null; List<String> gridList = new ArrayList<>(); gridList.add("Temperature_surface"); int stride_time = 1; int horizStride = 1; File outFile = tempFolder.newFile(); NetcdfFileWriter writer = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, outFile.getAbsolutePath()); CFGridWriter2.writeFile(gds, gridList, null, null, horizStride, zRange, dateRange, stride_time, addLatLon, writer); assert outFile.exists(); try ( GridDataset result = ucar.nc2.dt.grid.GridDataset.open(outFile.getAbsolutePath())) { System.out.printf("result = %s%n", result.getLocation()); } }
@Test public void testSubset() throws Exception { String fileIn = TestDir.cdmUnitTestDir + "ft/grid/testCFwriter.nc"; String fileOut = tempFolder.newFile().getAbsolutePath(); String varName = "Temperature"; try (ucar.nc2.dt.grid.GridDataset gds = GridDataset.open(fileIn)) { List<String> gridList = new ArrayList<>(); gridList.add(varName); NetcdfFileWriter writer = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, fileOut); CFGridWriter2.writeFile(gds, gridList, new LatLonRect(new LatLonPointImpl(30, -109), 10, 50), null, 1, null, null, 1, true, writer); } try (ucar.nc2.dt.grid.GridDataset result = GridDataset.open(fileOut)) { GeoGrid grid = result.findGridByName(varName); assertTrue(grid != null); } }
subsetSize = CFGridWriter2.writeFile(dataset, gridList, null, rect, 1, null, dateRange, 1, false, writer); System.out.printf(" subset size %s only = %d%n", gridNames, subsetSize);