Examples of NetcdfFile


Examples of ucar.nc2.NetcdfFile

    final NcMLWriter writer = new NcMLWriter();

    testAllInDir( new File("C:/data/grib/"), new MClosure() {
      public void run(String filename) throws IOException, InvalidRangeException {
        if (!filename.endsWith("grib1")) return;
        NetcdfFile ncfile = NetcdfDataset.openFile(filename, null);
        File fileout = new File(filename+".ncml");
        if (fileout.exists()) fileout.delete();
        writer.writeXMLexplicit( ncfile, new FileOutputStream(fileout), null);
        System.out.println(" wrote ncml file  ="+fileout);
      }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  }

  static void openFile(String filename, Average avg, boolean enhance) throws IOException, InvalidRangeException {
    try {
    long start = System.nanoTime();
    NetcdfFile ncfile = enhance ? NetcdfDataset.openDataset(filename) : NetcdfDataset.openFile(filename, null);
    long end = System.nanoTime();
    double took = (double)((end - start))/1000/1000/1000;
    ncfile.close();
    if (avg != null) avg.add(took);
    } catch (Exception e) {
      System.out.println("BAD "+filename);
      e.printStackTrace();
    }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

          "</netcdf>";

  public void testValuesFromAttribute() throws IOException, InvalidRangeException {
    String filename = "file:./" + TestNcML.topDir + "TestValuesFromAttribute.xml";

    NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), filename, null);
    System.out.println(" TestNcmlAggExisting.open " + filename + "\n" + ncfile);

    Variable newVar = ncfile.findVariable("titleAsVariable");
    assert null != newVar;

    assert newVar.getShortName().equals("titleAsVariable");
    assert newVar.getRank() == 0;
    assert newVar.getSize() == 1;
    assert newVar.getDataType() == DataType.STRING;

    Array data = newVar.read();
    assert data.getElementType() == String.class;

    Object val = data.getObject(0);
    assert val instanceof String;
    assert val.equals("COADS 1-degree Equatorial Enhanced");

    ////////////////
    newVar = ncfile.findVariable("titleAsVariable2");
    assert null != newVar;

    assert newVar.getShortName().equals("titleAsVariable2");
    assert newVar.getRank() == 0;
    assert newVar.getSize() == 1;
    assert newVar.getDataType() == DataType.STRING;

    data = newVar.read();
    assert data.getElementType() == String.class;

    val = data.getObject(0);
    assert val instanceof String;
    assert val.equals("COADS 1-degree Equatorial Enhanced");

    ///////////////
    newVar = ncfile.findVariable("VariableAttribute");
    assert null != newVar;

    assert newVar.getShortName().equals("VariableAttribute");
    assert newVar.getRank() == 1;
    assert newVar.getSize() == 2;
    assert newVar.getDataType() == DataType.DOUBLE;

    data = newVar.read();
    assert data.getRank() == 1;
    assert data.getSize() == 2;
    assert data.getElementType() == double.class;

    double[] result = new double[] { 715511.0, 729360.0};
    for (int i=0; i<result.length; i++) {
      assert result[i] == data.getDouble(i);
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

          "  </aggregation>\n"+
          "</netcdf>";

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

    TestAll.readAllData(ncfile);

     Variable v = ncfile.findVariable("time");
     Array data = v.read();
     assert data.getSize() == 20;
     NCdumpW.printArray(data);

    ncfile.close();   
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  }

  public void testNestedAgg() throws IOException, InvalidRangeException, InterruptedException {
    String filename = "file:./" + TestAll.cdmLocalTestDataDir+ "testNested.ncml";

   NetcdfFile ncfile = NetcdfDataset.openFile(filename, null);

   TestAll.readAllData(ncfile);

    Variable v = ncfile.findVariable("time");
    Array data = v.read();
    assert data.getSize() == 59;
    NCdumpW.printArray(data);

   ncfile.close();
}
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  private ForecastModelRunInventory(ucar.nc2.dt.GridDataset gds, Date runDate) {

    this.gds = gds;
    name = gds.getTitle();

    NetcdfFile ncfile = gds.getNetcdfFile();
    if (runDate == null) {
      runTime = ncfile.findAttValueIgnoreCase(null, _Coordinate.ModelBaseDate, null);
      if (runTime == null)
        runTime = ncfile.findAttValueIgnoreCase(null, _Coordinate.ModelRunDate, null);
      if (runTime == null)
        throw new IllegalArgumentException("File must have " + _Coordinate.ModelBaseDate + " or " +
                _Coordinate.ModelRunDate + " attribute ");
      this.runDate = DateUnit.getStandardOrISO(runTime);
      if (this.runDate == null)
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  // Grib files are collections of 2D horizontal arrays.
  // LOOK: breaking encapsolation !!!

  private void getIosp() {
    NetcdfDataset ncd = (NetcdfDataset) gds.getNetcdfFile();
    NetcdfFile ncfile = ncd.getReferencedFile();
    while (ncfile instanceof NetcdfDataset) {
      ncd = (NetcdfDataset) ncfile;
      ncfile = ncd.getReferencedFile();
    }
    if (ncfile == null) return;
    IOServiceProvider iosp = ncfile.getIosp();
    if (iosp == null) return;
    if (!(iosp instanceof GridServiceProvider)) return;
    gribIosp = (GridServiceProvider) iosp;
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    ArrayChar.D1 data = new ArrayChar.D1(dim.getLength());
    data.setString(helloGreek);
    ncfile.write(helloGreek, data);
    ncfile.close();

    NetcdfFile nc = NetcdfFile.open(filename);
    Variable v = ncfile.findVariable(helloGreek);
    assert v != null;
    assert v.getShortName().equals(helloGreek);

    Attribute att = v.findAttribute("units");
    assert att != null;
    assert att.isString();
    assert(helloGreek.equals(att.getStringValue()));
    nc.close();   
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

      "       <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();   
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

                    "  </variable>\n" +
                    "</netcdf>";

    String location = "testTimeUnitErrorMessage";
    System.out.println("testTimeUnitErrorMessage=\n" + ncml);
    NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), location, null);
    NetcdfDataset ncd = new NetcdfDataset(ncfile, true);
    VariableDS v = (VariableDS) ncd.findVariable("time");
    assert v != null;
    assert v.getDataType() == DataType.INT;
    assert v instanceof CoordinateAxis;
    CoordinateAxis axis = (CoordinateAxis) v;
    assert axis.getAxisType() == AxisType.Time;
   
    GridDataset gd = new GridDataset(ncd, null);

    GeoGrid grid = (GeoGrid) gd.findGridByName("rh");
    assert grid != null;
    assert grid.getDataType() == DataType.INT;
    System.out.printf("%s%n", ncd);

    ncfile.close();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.