public void testNcmlCached() throws IOException, InvalidRangeException { System.out.println("\n TestNcmlAggExistingCached.acquire at " + new Date()); NetcdfFile ncfile = NetcdfDataset.acquireDataset(filename, null); testAggCoordVar(ncfile); ncfile.close(); System.out.println("\n TestNcmlAggExistingCached.acquire again at " + new Date()); ncfile = NetcdfDataset.acquireDataset(filename, null); testAggCoordVar(ncfile); ncfile.close(); try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("\n TestNcmlAggExistingCached.acquire after sleeping " + new Date()); ncfile = NetcdfDataset.acquireDataset(filename, null); testAggCoordVar(ncfile); ncfile.close(); NetcdfDataset.getNetcdfFileCache().clearCache(false); System.out.println("\n TestNcmlAggExistingCached.acquire after flushing cache " + new Date()); ncfile = NetcdfDataset.acquireDataset(filename, null); testAggCoordVar(ncfile); testAggCoordVarSubset(ncfile); ncfile.close(); }
public void testScan() throws IOException, InvalidRangeException { String xml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='time' type='int' shape='time'>\n" + " <attribute name='long_name' type='string' value='time coordinate' />\n" + " <attribute name='units' type='string' value='days since 2001-8-31 00:00:00 UTC' />\n" + " <values start='0' increment='10' />\n" + " </variable>\n" + " <aggregation dimName='time' type='joinNew'>\n" + " <variableAgg name='T'/>\n" + " <scan location='src/test/data/ncml/nc/' suffix='Dir.nc' subdirs='false'/>\n" + " </aggregation>\n" + "</netcdf>"; String filename = "file:./" + TestNcML.topDir + "aggSynScan.xml"; NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(xml), null); testDimensions(ncfile); testCoordVar(ncfile); testAggCoordVarScan(ncfile); testReadData(ncfile, "T"); testReadSlice(ncfile, "T"); ncfile.close(); }
public void testNcmlDirect() throws IOException, InvalidRangeException { NetcdfFile ncfile = NetcdfDataset.openDataset(filename, false, null); System.out.println("\n TestNcmlAggExistingCached.open " + filename); // System.out.println(" "+ ncfile); testAggCoordVar(ncfile); testAggCoordVarSubset(ncfile); testAggCoordVarSubsetDefeatLocalCache(ncfile); ncfile.close(); }
void writeNetCDF(String filename) { try { FileWriter2 writer = new FileWriter2(ds, filename, NetcdfFileWriter.Version.netcdf3); NetcdfFile result = writer.write(); result.close(); JOptionPane.showMessageDialog(this, "File successfully written"); } catch (Exception ioe) { JOptionPane.showMessageDialog(this, "ERROR: " + ioe.getMessage()); ioe.printStackTrace(); } }
public void testNoCoord() throws IOException, InvalidRangeException { String filename = "file:./" + TestNcML.topDir + "aggSynNoCoord.xml"; NetcdfFile ncfile = NcMLReader.readNcML(filename, null); testDimensions(ncfile); testCoordVar(ncfile); testAggCoordVarNoCoord(ncfile); testReadData(ncfile, "T"); testReadSlice(ncfile, "T"); ncfile.close(); }
private void read( String filename, int ndims, int nvars, int ngatts, int natts, int nstructFields, int ngroups) throws IOException { NetcdfFile ncfile = NetcdfFile.open(filename); Counter c = new Counter(); c.count(ncfile.getRootGroup()); if (false) { filename = filename.substring(testDir.length()); filename = StringUtil2.replace(filename, '\\', "/"); System.out.println( "read(testDir+\"" + filename + "\"," + c.ndims + "," + c.nvars + "," + c.ngatts + "," + c.natts + "," + c.nstructFields + "," + c.ngroups + ");"); ncfile.close(); return; } print(ndims, c.ndims); print(nvars, c.nvars); print(ngatts, c.ngatts); print(natts, c.natts); print(nstructFields, c.nstructFields); print(ngroups, c.ngroups); System.out.println(" " + filename); ncfile.close(); }
public void testReadStandardVar() throws Exception { ncfileRead = NetcdfFile.open(filename); dsRead = NetcdfDataset.openDataset(filename); readDouble(); readByte2Short(); readByte(); readShortMissing(); readShort2FloatMissing(); readDoubleMissing(); ncfileRead.close(); dsRead.close(); }
public void test1() throws IOException, InvalidRangeException { String filename = "file:./" + TestNcML.topDir + "aggSynthetic.xml"; NetcdfFile ncfile = NcMLReader.readNcML(filename, null); Variable v = ncfile.findVariable("time"); assert v != null; String testAtt = ncfile.findAttValueIgnoreCase(v, "units", null); assert testAtt != null; assert testAtt.equals("months since 2000-6-16 6:00"); testDimensions(ncfile); testCoordVar(ncfile); testAggCoordVar(ncfile); testReadData(ncfile, "T"); testReadSlice(ncfile, "T"); ncfile.close(); }
public void testRename() throws IOException, InvalidRangeException { String xml = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n" + " <variable name='Temperature' orgName='T' />\n" + " <aggregation dimName='time' type='joinNew'>\n" + " <variableAgg name='T'/>\n" + " <scan location='src/test/data/ncml/nc/' suffix='Dir.nc' subdirs='false'/>\n" + " </aggregation>\n" + "</netcdf>"; String filename = "file:./" + TestNcML.topDir + "aggSynRename.xml"; NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(xml), null); testDimensions(ncfile); testCoordVar(ncfile); testAggCoordVarNoCoordsDir(ncfile); testReadData(ncfile, "Temperature"); testReadSlice(ncfile, "Temperature"); ncfile.close(); }
private void compareDataset(CompareDialog.Data data) { if (data.name == null) return; NetcdfFile compareFile = null; try { compareFile = NetcdfDataset.openFile(data.name, null); Formatter f = new Formatter(); CompareNetcdf2 cn = new CompareNetcdf2(f, data.showCompare, data.showDetails, data.readData); if (data.howMuch == CompareDialog.HowMuch.All) cn.compare(ds, compareFile); else { NestedTable nested = nestedTableList.get(0); Variable org = getCurrentVariable(nested.table); if (org == null) return; Variable ov = compareFile.findVariable(org.getFullNameEscaped()); if (ov != null) cn.compareVariable(org, ov); } infoTA.setText(f.toString()); infoTA.gotoTop(); infoWindow.setTitle("Compare"); infoWindow.show(); } catch (Throwable ioe) { ByteArrayOutputStream bos = new ByteArrayOutputStream(10000); ioe.printStackTrace(new PrintStream(bos)); infoTA.setText(bos.toString()); infoTA.gotoTop(); infoWindow.show(); } finally { if (compareFile != null) try { compareFile.close(); } catch (Exception eek) { } } }
public void testNC3Read() throws IOException { NetcdfFile ncfile = TestDir.openFileLocal("testWrite.nc"); assert (null != ncfile.findDimension("lat")); assert (null != ncfile.findDimension("lon")); Variable temp = null; assert (null != (temp = ncfile.findVariable("temperature"))); // read entire array Array A; try { A = temp.read(); } catch (IOException e) { System.err.println("ERROR reading file"); assert (false); return; } assert (A.getRank() == 2); int i, j; Index ima = A.getIndex(); int[] shape = A.getShape(); assert shape[0] == 64; assert shape[1] == 128; for (i = 0; i < shape[0]; i++) { for (j = 0; j < shape[1]; j++) { double dval = A.getDouble(ima.set(i, j)); assert (dval == (double) (i * 1000000 + j * 1000)) : dval; } } // read part of array int[] origin2 = new int[2]; int[] shape2 = new int[2]; shape2[0] = 1; shape2[1] = temp.getShape()[1]; try { A = temp.read(origin2, shape2); } catch (InvalidRangeException e) { System.err.println("ERROR reading file " + e); assert (false); return; } catch (IOException e) { System.err.println("ERROR reading file"); assert (false); return; } assert (A.getRank() == 2); for (j = 0; j < shape2[1]; j++) { assert (A.getDouble(ima.set(0, j)) == (double) (j * 1000)); } // rank reduction Array Areduce = A.reduce(); Index ima2 = Areduce.getIndex(); assert (Areduce.getRank() == 1); for (j = 0; j < shape2[1]; j++) { assert (Areduce.getDouble(ima2.set(j)) == (double) (j * 1000)); } // read char variable Variable c = null; assert (null != (c = ncfile.findVariable("svar"))); try { A = c.read(); } catch (IOException e) { assert (false); } assert (A instanceof ArrayChar); ArrayChar ac = (ArrayChar) A; String val = ac.getString(ac.getIndex()); assert val.equals("Testing 1-2-3") : val; // System.out.println( "val = "+ val); // read char variable 2 Variable c2 = null; assert (null != (c2 = ncfile.findVariable("svar2"))); try { A = c2.read(); } catch (IOException e) { assert (false); } assert (A instanceof ArrayChar); ArrayChar ac2 = (ArrayChar) A; assert (ac2.getString().equals("Two pairs of ladies stockings!")); // read String Array Variable c3 = null; assert (null != (c3 = ncfile.findVariable("names"))); try { A = c3.read(); } catch (IOException e) { assert (false); } assert (A instanceof ArrayChar); ArrayChar ac3 = (ArrayChar) A; ima = ac3.getIndex(); assert (ac3.getString(ima.set(0)).equals("No pairs of ladies stockings!")); assert (ac3.getString(ima.set(1)).equals("One pair of ladies stockings!")); assert (ac3.getString(ima.set(2)).equals("Two pairs of ladies stockings!")); // read String Array - 2 Variable c4 = null; assert (null != (c4 = ncfile.findVariable("names2"))); try { A = c4.read(); } catch (IOException e) { assert (false); } assert (A instanceof ArrayChar); ArrayChar ac4 = (ArrayChar) A; ima = ac4.getIndex(); assert (ac4.getString(0).equals("0 pairs of ladies stockings!")); assert (ac4.getString(1).equals("1 pair of ladies stockings!")); assert (ac4.getString(2).equals("2 pairs of ladies stockings!")); // System.out.println( "ncfile = "+ ncfile); ncfile.close(); System.out.println("**************TestRead done"); }
protected void tearDown() throws IOException { ncfile.close(); }