public static NetcdfDataset acquireFeatureCollection(String path) throws IOException { Formatter formatter = new Formatter(System.err); FeatureCollectionConfigBuilder builder = new FeatureCollectionConfigBuilder(formatter); FeatureCollectionConfig config = builder.readConfigFromFile( path.toString()); // this is the path to the feature collection XML Fmrc fmrc = Fmrc.open(config, formatter); NetcdfDataset dataset = new NetcdfDataset(); fmrc.getDataset2D(dataset); dataset.setLocation(path); return dataset; }
public static void main(String args[]) throws IOException { //String filename = "C:/data/199707010200.CHRTOUT_DOMAIN2"; String filename = "C:/data/199707010000.LAKEOUT_DOMAIN2"; NetcdfDataset ncds = new NetcdfDataset(); UnidataStationObsDataset ods = new UnidataStationObsDataset(ncds.openDataset(filename)); StringBuffer sbuff = new StringBuffer(50 * 1000); ods.checkLinks(sbuff); System.out.println("\n\n" + sbuff.toString()); ncds.shutdown(); }
public static NetcdfDataset acquireFeatureCollection(String path) throws IOException { Formatter formatter = new Formatter(System.err); FeatureCollectionConfigBuilder builder = new FeatureCollectionConfigBuilder(formatter); FeatureCollectionConfig config = builder.readConfigFromFile( path.toString()); // this is the path to the feature collection XML Fmrc fmrc = Fmrc.open(config, formatter); NetcdfDataset dataset = new NetcdfDataset(); fmrc.getDataset2D(dataset); dataset.setLocation(path); return dataset; }
/** * Use NCML to modify the referenced dataset, create a new dataset with the merged info * Used to wrap each dataset of an aggregation before its aggregated * * @param ref referenced dataset * @param parentElem parent element - usually the aggregation element of the ncml * @return new dataset with the merged info * @throws IOException on read error */ static public NetcdfDataset mergeNcML(NetcdfFile ref, Element parentElem) throws IOException { NetcdfDataset targetDS = new NetcdfDataset(ref, null); // no enhance NcMLReader reader = new NcMLReader(); reader.readGroup(targetDS, targetDS, null, null, parentElem); targetDS.finish(); return targetDS; }
@Override public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group, String filename, FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException { ucar.nc2.grib.collection.Grib2Iosp iosp = new ucar.nc2.grib.collection.Grib2Iosp(group, ds.getType()); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null); return new NetcdfDataset(ncfile); }
@Override public ucar.nc2.dataset.NetcdfDataset getNetcdfDataset(Dataset ds, GroupGC group, String filename, FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException { ucar.nc2.grib.collection.Grib1Iosp iosp = new ucar.nc2.grib.collection.Grib1Iosp(group, ds.getType()); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null); return new NetcdfDataset(ncfile); }
@Override public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, String filename, FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException { ucar.nc2.grib.collection.Grib2Iosp iosp = new ucar.nc2.grib.collection.Grib2Iosp(group, ds.getType()); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null); NetcdfDataset ncd = new NetcdfDataset(ncfile); return new ucar.nc2.dt.grid.GridDataset(ncd); }
@Override public ucar.nc2.dt.grid.GridDataset getGridDataset(Dataset ds, GroupGC group, String filename, FeatureCollectionConfig config, Formatter errlog, org.slf4j.Logger logger) throws IOException { ucar.nc2.grib.collection.Grib1Iosp iosp = new ucar.nc2.grib.collection.Grib1Iosp(group, ds.getType()); NetcdfFile ncfile = new NetcdfFileSubclass(iosp, null, getLocation(), null); NetcdfDataset ncd = new NetcdfDataset(ncfile); return new ucar.nc2.dt.grid.GridDataset(ncd); }
@Test public void testTimeAxisEval() throws IOException { /** * The following tests BugFixes.evalTimeAxes, called by ucar.nc2.dt.grid.GridCoordSys.isGridCoordSys */ String testFileFullPath = TestDir.cdmUnitTestDir + "ft/grid/echoTops_runtime.nc"; GridDataset runtimeDataset = new GridDataset(new NetcdfDataset(NetcdfFile.open(testFileFullPath))); if (runtimeDataset.getGrids().isEmpty()) { throw new RuntimeException("Runtime data file did not generate a dataset with grids"); } if (runtimeDataset.getGrids().get(0).getCoordinateSystem().getRunTimeAxis() == null) { throw new RuntimeException("Runtime data file did not generate a dataset with a RunTime axis"); } System.out.println("BugFixesTest - completed."); }
private void processBufrMessageAsDataset(MessageScanner scan, Message m) throws Exception { byte[] mbytes = scan.getMessageBytes(m); NetcdfFile ncfile = NetcdfFile.openInMemory("test", mbytes, "ucar.nc2.iosp.bufr.BufrIosp"); NetcdfDataset ncd = new NetcdfDataset(ncfile); SequenceDS obs = (SequenceDS) ncd.findVariable(BufrIosp.obsRecord); StructureDataIterator sdataIter = obs.getStructureIterator(-1); //writeSequence(obs, sdataIter); extractFirst(sdataIter, new Extract()); }
public void writeXMLexplicit(NetcdfFile ncfile, OutputStream os, String location) throws IOException { if (ncfile instanceof NetcdfDataset) ncd = (NetcdfDataset) ncfile; else ncd = new NetcdfDataset(ncfile, false); fmt = new XMLOutputter(Format.getPrettyFormat()); Document doc = makeDocument(location); Element root = doc.getRootElement(); root.addContent( new Element("explicit", ncNS)); fmt.output(doc, os); }
public void writeXMLexplicit(NetcdfFile ncfile, OutputStream os, String location) throws IOException { if (ncfile instanceof NetcdfDataset) ncd = (NetcdfDataset) ncfile; else ncd = new NetcdfDataset(ncfile, false); fmt = new XMLOutputter(Format.getPrettyFormat()); Document doc = makeDocument(location); Element root = doc.getRootElement(); root.addContent( new Element("explicit", ncNS)); fmt.output(doc, os); }
@Test public void doOne() throws Exception { try (NetcdfFile ncfile = NetcdfDataset.acquireFile(durl, null); NetcdfDataset ncWrap = new NetcdfDataset(ncfile, true)) { NetcdfDataset ncd = NetcdfDataset.acquireDataset(durl, true, null); System.out.println(" dataset wraps= " + durl.trueurl); ucar.unidata.util.test.CompareNetcdf.compareFiles(ncd, ncWrap); } } }
@Test public void checkGrid() throws Exception { String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/gribCollection/GFS_CONUS_80km/GFS_CONUS_80km_20120227_0000.grib1?var=Temperature_isobaric"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory try (NetcdfFile nf = NetcdfFile.openInMemory("test_data.nc", content)) { GridDataset gdsDataset = new GridDataset(new NetcdfDataset(nf)); assertNotNull(gdsDataset.findGridByName("Temperature_isobaric")); logger.debug("{}", nf); } }
@Test public void checkFmrcBest() throws Exception { String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd?var=Relative_humidity_height_above_ground,Temperature_height_above_ground"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory try (NetcdfFile nf = NetcdfFile.openInMemory("test_data.nc", content)) { GridDataset gdsDataset = new GridDataset(new NetcdfDataset(nf)); assertNotNull(gdsDataset.findGridByName("Relative_humidity_height_above_ground")); logger.debug("{}", nf); } }
@Test public void testNcssFailure() throws Exception{ String filename = "scanCdmUnitTests/formats/netcdf4/COMPRESS_LEV2_20140201000000-GLOBCURRENT-L4-CURekm_15m-ERAWS_EEM-v02.0-fv01.0.nc"; String endpoint = TestOnLocalServer.withHttpPath("/ncss/grid/"+filename+ "?var=eastward_ekman_current_velocity&north=79.8750&west=-140&east=170&south=-79.8750&horizStride=1&"+ "time_start=2014-02-01T00%3A00%3A00Z&time_end=2014-02-01T00%3A00%3A00Z&timeStride=1&accept=netcdf4"); byte[] content = TestOnLocalServer.getContent(endpoint, 200, ContentType.netcdf); // Open the binary response in memory try (NetcdfFile nf = NetcdfFile.openInMemory("test_data.nc", content)) { GridDataset gdsDataset = new GridDataset(new NetcdfDataset(nf)); assertNotNull(gdsDataset.findGridByName("eastward_ekman_current_velocity")); logger.debug("{}", nf); } } }
@Test public void testDODSwithDataset() throws IOException { DODSNetcdfFile dodsfile = TestDODSRead.open("test.04"); NetcdfDataset ds = new NetcdfDataset( dodsfile, false); // bug in forming dods name Variable v = null; assert null != (v = ds.findVariable("types.b")); v.invalidateCache(); v.read(); }
private void testEnhanceEquals(String ncmlLocation) throws IOException { System.out.println("testEnhanceEquals"); NetcdfDataset ncml = NcMLReader.readNcML(ncmlLocation, null); NetcdfDataset ncmlEnhanced = new NetcdfDataset(ncml, true); String locref = ncml.getReferencedFile().getLocation(); NetcdfDataset ncdrefEnhanced = NetcdfDataset.openDataset(locref, true, null); ucar.unidata.util.test.CompareNetcdf.compareFiles(ncmlEnhanced, ncdrefEnhanced, false, false, false); ncml.close(); ncdrefEnhanced.close(); }
private void doOne(String filename) throws Exception { try (NetcdfFile ncfile = NetcdfDataset.acquireFile(new DatasetUrl(null, filename), null); NetcdfDataset ncWrap = new NetcdfDataset(ncfile, true)) { NetcdfDataset ncd = NetcdfDataset.acquireDataset(new DatasetUrl(null, filename), true , null); System.out.println(" dataset wraps= " + filename); ucar.unidata.util.test.CompareNetcdf.compareFiles(ncd, ncWrap); ncd.close(); ncWrap.close(); } }
public void testMA() throws IOException, InvalidRangeException { NetcdfFile ncfile = TestDir.openFileLocal("jan.nc"); NetcdfDataset ncd = new NetcdfDataset( ncfile); Dimension dim = ncd.findDimension("time"); assert dim != null; Structure p = new ucar.nc2.dataset.StructurePseudoDS( ncd, null, "Psuedo", null, dim); assert( p.getDataType() == DataType.STRUCTURE); Array data = p.read(); assert( data instanceof ArrayStructure); assert( data instanceof ArrayStructureMA); assert(data.getElementType() == StructureData.class); test.testArrayStructure( (ArrayStructure) data); ncfile.close(); }