@Test
  public void testCacheIsUsed() throws IOException, InvalidRangeException {
    String filename = "file:TestAggExistingCache.xml";
    System.out.printf("%s%n", filename);

    String cacheDirName = TestDir.temporaryLocalDataDir + "testAggExistingCache/";
    System.out.printf("cacheDir=%s%n", cacheDirName);
    File cacheDir = new File(cacheDirName);
    FileUtils.deleteDirectory(cacheDir); // from commons-io
    assert !cacheDir.exists();

    DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0);
    cache.setAlwaysUseCache(true);
    Assert.assertEquals(cache.getRootDirectory(), cacheDirName);
    assert new File(cache.getRootDirectory()).exists();

    Aggregation.setPersistenceCache(cache);
    AggregationExisting.countCacheUse = 0;

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) {
      System.out.println(" TestNcmlAggExisting.open " + filename);
      Array ATssta = ncfile.readSection("ATssta(:,0,0,0)");
      Assert.assertEquals(4, ATssta.getSize());
    }
    Assert.assertEquals(0, AggregationExisting.countCacheUse);
    AggregationExisting.countCacheUse = 0;

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null)) {
      System.out.println(" TestNcmlAggExisting.open " + filename);
      Array ATssta = ncfile.readSection("ATssta(:,0,0,0)");
      Assert.assertEquals(4, ATssta.getSize());
    }
    Assert.assertEquals(8, AggregationExisting.countCacheUse);
  }
Example #2
0
  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();
  }
  @Ignore("files not available")
  @Test
  public void testCacheTiming() throws IOException, InvalidRangeException {
    String filename = "file:testCacheTiming.xml";
    System.out.printf("%s%n", filename);

    String cacheDirName = TestDir.temporaryLocalDataDir + "testAggExistingCache/";
    System.out.printf("cacheDir=%s%n", cacheDirName);
    File cacheDir = new File(cacheDirName);
    FileUtils.deleteDirectory(cacheDir); // from commons-io
    assert !cacheDir.exists();

    DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0);
    cache.setAlwaysUseCache(true);
    Assert.assertEquals(cache.getRootDirectory(), cacheDirName);
    assert new File(cache.getRootDirectory()).exists();

    Aggregation.setPersistenceCache(cache);
    AggregationExisting.countCacheUse = 0;

    long start = System.currentTimeMillis();

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml2), filename, null)) {
      System.out.printf("%nTestNcmlAggExisting.open %s%n", filename);
      Variable time = ncfile.findVariable("time");
      System.out.printf(" Variable %s%n", time.getNameAndDimensions());
      time.read();
    }
    System.out.printf(" countCacheUse = %d%n", AggregationExisting.countCacheUse);

    long took = System.currentTimeMillis() - start;
    System.out.printf(" first took %d msecs%n", took);

    AggregationExisting.countCacheUse = 0;
    start = System.currentTimeMillis();

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml2), filename, null)) {
      System.out.printf("%nTestNcmlAggExisting.open %s%n", filename);
      Variable time = ncfile.findVariable("time");
      System.out.printf(" Variable %s%n", time.getNameAndDimensions());
      time.read();
    }
    System.out.printf(" countCacheUse = %d%n", AggregationExisting.countCacheUse);
    took = System.currentTimeMillis() - start;
    System.out.printf(" second took %d msecs%n", took);
  }
Example #4
0
 public void setUp() {
   try {
     ncfile = NcMLReader.readNcML(location, null);
     // System.out.println("ncfile opened = "+location);
   } catch (java.net.MalformedURLException e) {
     System.out.println("bad URL error = " + e);
   } catch (IOException e) {
     System.out.println("IO error = " + e);
     e.printStackTrace();
   }
 }
  public void testUpdate() throws IOException, InvalidRangeException, InterruptedException {
    String dir = TestAll.cdmUnitTestDir + "agg/updating";
    File dirFile = new File(dir);
    assert dirFile != null;
    assert dirFile.exists();
    assert dirFile.isDirectory();

    // make sure that the extra file is not in the agg
    for (File f : dirFile.listFiles()) {
      if (f.getName().equals("extra.nc")) {
        if (!f.renameTo(new File(dirFile, "extra.wait"))) {
          System.out.printf("Rename fails on %s.extra.nc %n", dirFile);
        }
        break;
      }
    }

    String ncml =
        "<?xml version='1.0' encoding='UTF-8'?>\n"
            + "<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'>\n"
            + "       <aggregation dimName='time' type='joinExisting' recheckEvery='1 nsec'>\n"
            + "         <scan location='"
            + dir
            + "' suffix='*.nc' />\n"
            + "         <variable name='depth'>\n"
            + "           <attribute name='coordinates' value='lon lat'/>\n"
            + "         </variable>\n"
            + "         <variable name='wvh'>\n"
            + "           <attribute name='coordinates' value='lon lat'/>\n"
            + "         </variable>\n"
            + "       </aggregation>\n"
            + "       <attribute name='Conventions' type='String' value='CF-1.0'/>\n"
            + "</netcdf>";

    String location = dir + "agg/updating.ncml";
    System.out.println(" TestOffAggExistingTimeUnitsChange.testNarrGrib=\n" + ncml);
    NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), location, null);

    check(ncfile, 12);

    // make sure that the extra file is  in the agg
    for (File f : dirFile.listFiles()) {
      if (f.getName().equals("extra.wait")) {
        if (!f.renameTo(new File(dirFile, "extra.nc")))
          System.out.println(" rename fails on " + f.getPath());
        break;
      }
    }

    ncfile.sync();
    check(ncfile, 18);

    ncfile.close();
  }
Example #6
0
  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();
  }
Example #7
0
  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();
  }
Example #8
0
  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();
  }