Java源码示例:ucar.nc2.dods.DODSNetcdfFile

示例1
boolean process1(Testcase testcase) throws Exception {
  DODSNetcdfFile ncfile = new DODSNetcdfFile(testcase.url);
  if (ncfile == null)
    throw new Exception("Cannot read: " + testcase.url);
  StringWriter ow = new StringWriter();
  PrintWriter pw = new PrintWriter(ow);
  CDLWriter.writeCDL(ncfile, pw, false);
  pw.close();
  ow.close();
  String captured = ow.toString();
  boolean pass = true;
  visual(testcase.title, captured);
  if (System.getProperty("baseline") != null) {
    baseline(testcase, captured);
  } else
    pass = diff(testcase, captured);
  return pass;
}
 
示例2
public static void main(String args[]) throws IOException, InvalidRangeException {
  Stat stat1 = new Stat("CDM4", false);
  Stat stat2 = new Stat("DODS", false);

  CdmRemote.setAllowCompression(true);
  DODSNetcdfFile.setAllowCompression(true);

  doOne("scanCdmUnitTests/formats/grib1/Mercator.grib1", stat1, stat2);
  doOne("scanCdmUnitTests/formats/grib2/ds.pop12.bin", stat1, stat2);
  doOne("scanCdmUnitTests/formats/grib2/AVOR_000.grb", stat1, stat2);
  doOne("scanCdmUnitTests/conventions/cf/bora_feb_001.nc", stat1, stat2);
  doOne("scanCdmUnitTests/conventions/cf/ccsm2.nc", stat1, stat2);

  System.out.printf("%n %s MB/sec%n", stat1);
  // System.out.printf(" %s MB/sec%n", stat2);
}
 
示例3
long computeArraySize(SDArray da) throws Exception {
  assert (da.getContainerVar() instanceof DPrimitive);
  BaseType base = da.getPrimitiveVector().getTemplate();
  DataType dtype = DODSNetcdfFile.convertToNCType(base, false);
  int elemSize = dtype.getSize();
  int n = da.numDimensions();
  List<Range> ranges = new ArrayList<>(n);
  long size = 0;
  for (int i = 0; i < n; i++) {
    ranges.add(new Range(da.getStart(i), da.getStop(i), da.getStride(i)));
  }
  Section s = new Section(ranges);
  size += s.computeSize() * elemSize;

  return size;
}
 
示例4
boolean process1(Testcase testcase) throws Exception {
  DODSNetcdfFile ncfile = new DODSNetcdfFile(testcase.url);
  if (ncfile == null)
    throw new Exception("Cannot read: " + testcase.url);
  StringWriter ow = new StringWriter();
  PrintWriter pw = new PrintWriter(ow);
  CDLWriter.writeCDL(ncfile, pw, false);
  try {
    pw.close();
    ow.close();
  } catch (IOException ioe) {
  } ;
  String captured = ow.toString();
  visual(testcase.title, captured);

  // See if the cdl is in a file or a string.
  Reader baserdr = null;
  if (testcase.cdl.startsWith("file://")) {
    File f = new File(testcase.cdl.substring("file://".length(), testcase.cdl.length()));
    try {
      baserdr = new FileReader(f);
    } catch (Exception e) {
      return false;
    }
  } else
    baserdr = new StringReader(testcase.cdl);
  StringReader resultrdr = new StringReader(captured);
  // Diff the two files
  Diff diff = new Diff("Testing " + testcase.title);
  boolean pass = !diff.doDiff(baserdr, resultrdr);
  baserdr.close();
  resultrdr.close();
  return pass;
}
 
示例5
static void testDodsCompress(String url, Stat statCompress, Stat statNone, int n, boolean readData)
    throws IOException, InvalidRangeException {
  for (int i = 0; i < n; i++) {
    DODSNetcdfFile.setAllowCompression(false);
    testRead("dods:" + server + "/dodsC/" + url, statNone, readData);
    DODSNetcdfFile.setAllowCompression(true);
    testRead("dods:" + server + "/dodsC/" + url, statCompress, readData);
  }
}
 
示例6
public void setDebugFlags() {
  log.debug("setDebugFlags");

  NetcdfFile.setDebugFlags(debugFlags);
  H5iosp.setDebugFlags(debugFlags);
  ucar.nc2.ncml.NcMLReader.setDebugFlags(debugFlags);
  DODSNetcdfFile.setDebugFlags(debugFlags);
  CdmRemote.setDebugFlags(debugFlags);
  Nc4Iosp.setDebugFlags(debugFlags);
  DataFactory.setDebugFlags(debugFlags);

  NetcdfCopier.setDebugFlags(debugFlags);
  ucar.nc2.ft.point.standard.PointDatasetStandardFactory.setDebugFlags(debugFlags);
  ucar.nc2.grib.collection.Grib.setDebugFlags(debugFlags);
}
 
示例7
long computeFieldSize(BaseType bt, boolean isAscii) throws Exception {
  long fieldsize = 0;
  // Figure out what this field is (e.g. primitive or not)
  // Somewhat convoluted.
  if (bt instanceof DConstructor) {
    // simple struct, seq, or grid => recurse
    fieldsize = computeSize((DConstructor) bt, isAscii);
  } else if (bt instanceof DArray) {
    SDArray da = (SDArray) bt;
    // Separate structure arrays from primitive arrays
    if (da.getContainerVar() instanceof DPrimitive) {
      fieldsize = computeArraySize(da);
    } else if (da.getContainerVar() instanceof DStructure) {
      fieldsize = computeSize((DStructure) da.getContainerVar(), isAscii); // recurse
    } else { // Some kind of problem
      throw new NoSuchTypeException("Computesize: unexpected type for " + bt.getLongName());
    }
  } else if (bt instanceof DPrimitive) {
    DPrimitive dp = (DPrimitive) bt;
    if (dp instanceof DString) {
      String v = ((DString) dp).getValue();
      fieldsize = (v == null ? 0 : v.length());
    } else {
      DataType dtype = DODSNetcdfFile.convertToNCType(bt, false);
      fieldsize = dtype.getSize();
    }
  } else { // Some kind of problem
    throw new NoSuchTypeException("Computesize: unknown type for " + bt.getLongName());
  }
  return fieldsize;
}
 
示例8
private void downloadDapFile(File targetDir, String dapURI, boolean isLargeFile) throws IOException {
    String[] uriComponents = dapURI.split("\\?");
    String constraintExpression = "";
    String fileName = dapURI.substring(uriComponents[0].lastIndexOf("/") + 1);
    if (uriComponents.length > 1) {
        constraintExpression = uriComponents[1];
    }
    updateProgressBar(fileName, 0);
    DODSNetcdfFile netcdfFile = new DODSNetcdfFile(dapURI);
    writeNetcdfFile(targetDir, fileName, constraintExpression, netcdfFile, isLargeFile);
}
 
示例9
@Ignore
@Test
public void testActualWriting() throws Exception {
    final DAPDownloader dapDownloader = new DAPDownloader(null, null, new NullDownloadContext(), new NullLabelledProgressBarPM());
    final DODSNetcdfFile sourceNetcdfFile = new DODSNetcdfFile(
            "http://test.opendap.org:80/opendap/data/nc/coads_climatology.nc");
    dapDownloader.writeNetcdfFile(TESTDATA_DIR, "deleteme.nc", "", sourceNetcdfFile, false);

    final File testFile = getTestFile("deleteme.nc");
    assertTrue(testFile.exists());
    assertTrue(NetcdfFile.canOpen(testFile.getAbsolutePath()));
    final NetcdfFile netcdfFile = NetcdfFileOpener.open(testFile.getAbsolutePath());
    assertNotNull(netcdfFile.findVariable("SST"));
}
 
示例10
@Ignore
@Test
public void testActualWriting_WithConstraint() throws Exception {
    final DAPDownloader dapDownloader = new DAPDownloader(null, null, new NullDownloadContext(), new NullLabelledProgressBarPM());
    final DODSNetcdfFile sourceNetcdfFile = new DODSNetcdfFile(
            "http://test.opendap.org:80/opendap/data/nc/coads_climatology.nc");
    dapDownloader.writeNetcdfFile(TESTDATA_DIR, "deleteme.nc", "COADSX[0:1:4]", sourceNetcdfFile, false);

    final File testFile = getTestFile("deleteme.nc");
    assertTrue(testFile.exists());
    assertTrue(NetcdfFile.canOpen(testFile.getAbsolutePath()));
    final NetcdfFile netcdfFile = NetcdfFileOpener.open(testFile.getAbsolutePath());
    assertNull(netcdfFile.findVariable("SST"));
    assertNotNull(netcdfFile.findVariable("COADSX"));
}
 
示例11
@Test
public void testDuplicates() throws Exception {
  // Check if we are running against remote or localhost, or what.
  String testserver = TestDir.dap2TestServer;

  List<Result> results = new ArrayList<Result>();
  if (true) {
    results.add(new Result("Top and field vars have same names", "http://" + testserver + "/dts/structdupname",
        "netcdf dods://" + testserver + "/dts/structdupname {\n" + " variables:\n" + "   int time;\n"
            + "Structure {\n" + "   float time;\n" + "} record;\n" + "}"));
  }
  if (true) {
    results.add(new Result("TestFailure", "http://" + testserver + "/dts/simplestruct", "netcdf dods://" + testserver
        + "/dts/simplestruct {\n" + " variables:\n" + "Structure {\n" + "   int i32;\n" + "} types;\n" + "}"));
  }
  boolean pass = true;
  for (Result result : results) {
    System.out.println("TestDuplicates: " + result.url);
    boolean localpass = true;
    try {
      DODSNetcdfFile ncfile = new DODSNetcdfFile(result.url);
      if (ncfile == null)
        throw new Exception("Cannot read: " + result.url);
      StringWriter ow = new StringWriter();
      PrintWriter pw = new PrintWriter(ow);
      CDLWriter.writeCDL(ncfile, pw, false);
      try {
        pw.close();
        ow.close();
      } catch (IOException ioe) {
      } ;
      StringReader baserdr = new StringReader(result.cdl);
      String captured = ow.toString();
      StringReader resultrdr = new StringReader(captured);
      // Diff the two files
      Diff diff = new Diff("Testing " + result.title);
      localpass = !diff.doDiff(baserdr, resultrdr);
      baserdr.close();
      resultrdr.close();
      // Dump the output for visual comparison
      if (System.getProperty("visual") != null) {
        System.out.println("Testing " + result.title + " visual:");
        System.out.println("---------------");
        System.out.print(captured);
        System.out.println("---------------");
      }
    } catch (IllegalArgumentException e) {
      localpass = false;
    }
    if (!localpass)
      pass = false;
  }
  System.out.flush();
  System.err.flush();
  Assert.assertTrue("Testing " + getTitle(), pass);
}