Examples of NetcdfDataset


Examples of ucar.nc2.dataset.NetcdfDataset

  }


  public void testDatasetAddRecord() throws InvalidRangeException, IOException {
    NetcdfDataset nc = NetcdfDataset.openDataset(TestLocal.cdmTestDataDir + "testWriteRecord.nc", NetcdfDataset.getDefaultEnhanceMode(),
        -1, null, NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);

    // record variable
    Variable record = nc.findVariable("record");
    assert record instanceof StructureDS;
    StructureDS rs = (StructureDS) record;
    assert rs.getRank() == 1;
    assert rs.getDimension(0).getLength() == 2;

    /* Read a record */
    Array rsValues = rs.read("1:1:2");
    assert (rsValues instanceof ArrayStructure);
    assert rsValues.getRank() == 1;
    assert rsValues.getShape()[0] == 1;

    StructureData sdata = (StructureData) rsValues.getObject(rsValues.getIndex());
    Array gdata = sdata.getArray("time");
    assert gdata instanceof ArrayInt.D0 : gdata.getClass().getName();
    ArrayInt.D0 tdata = (ArrayInt.D0) gdata;
    int t = tdata.get();
    assert t == 18;

    int t2 = sdata.getScalarInt("time");
    assert t2 == 18;

    /* Read the times: unlimited dimension */
    Variable time = rs.findVariable("time");
    assert time != null;
    Array timeValues = time.read();
    assert (timeValues instanceof ArrayInt.D0);
    ArrayInt.D0 ta = (ArrayInt.D0) timeValues;
    assert (ta.get() == 6) : ta.get();

    nc.close();
  }
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

    nc.close();
  }

  public void testDatasetAddRecordAfter() throws InvalidRangeException, IOException {
    NetcdfDataset nc = NetcdfDataset.openDataset(TestLocal.cdmTestDataDir + "testWriteRecord.nc");
    assert (Boolean) nc.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);

    // record variable
    Variable record = nc.findVariable("record");
    assert record instanceof StructureDS;
    StructureDS rs = (StructureDS) record;
    assert rs.getRank() == 1;
    assert rs.getDimension(0).getLength() == 2;

    /* Read a record */
    Array rsValues = rs.read("1:1:2");
    assert (rsValues instanceof ArrayStructure);
    assert rsValues.getRank() == 1;
    assert rsValues.getShape()[0] == 1;

    StructureData sdata = (StructureData) rsValues.getObject(rsValues.getIndex());
    Array gdata = sdata.getArray("time");
    assert gdata instanceof ArrayInt.D0 : gdata.getClass().getName();
    ArrayInt.D0 tdata = (ArrayInt.D0) gdata;
    int t = tdata.get();
    assert t == 18;

    int t2 = sdata.getScalarInt("time");
    assert t2 == 18;

    /* Read the times: unlimited dimension */
    Variable time = rs.findVariable("time");
    Array timeValues = time.read();
    assert (timeValues instanceof ArrayInt.D0);
    ArrayInt.D0 ta = (ArrayInt.D0) timeValues;
    assert (ta.get() == 6) : ta.get();

    nc.close();
  }
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

      System.out.printf("errlog= %s%n", errlog.toString());
      return;
    }

    ucar.nc2.dt.GridDataset gridDs = fmrc.getDataset2D(null);
    NetcdfDataset ncd = (NetcdfDataset) gridDs.getNetcdfFile();

    int countGrids = gridDs.getGrids().size();
    int countCoordAxes = ncd.getCoordinateAxes().size();
    int countCoordSys = ncd.getCoordinateSystems().size();

    // count vertical axes
    int countVertCooordAxes = 0;
    List axes = ncd.getCoordinateAxes();
    for (int i = 0; i < axes.size(); i++) {
      CoordinateAxis axis =  (CoordinateAxis) axes.get(i);
      AxisType t = axis.getAxisType();
      if ((t == AxisType.GeoZ) || (t == AxisType.Height) || (t == AxisType.Pressure) )
        countVertCooordAxes++;
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

      System.out.printf("errlog= %s%n", errlog.toString());
      return;
    }

    ucar.nc2.dt.GridDataset gridDs = fmrc.getDatasetBest();
    NetcdfDataset ncd = (NetcdfDataset) gridDs.getNetcdfFile();

    int countGrids = gridDs.getGrids().size();
    int countCoordAxes = ncd.getCoordinateAxes().size();
    int countCoordSys = ncd.getCoordinateSystems().size();

    // count vertical axes
    int countVertCooordAxes = 0;
    List axes = ncd.getCoordinateAxes();
    for (int i = 0; i < axes.size(); i++) {
      CoordinateAxis axis =  (CoordinateAxis) axes.get(i);
      AxisType t = axis.getAxisType();
      if ((t == AxisType.GeoZ) || (t == AxisType.Height) || (t == AxisType.Pressure) )
        countVertCooordAxes++;
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

    }

    public Bean(File f) {
      this.f = f;

      NetcdfDataset ds = null;
      try {
        if (debug) System.out.printf(" featureScan=%s%n", f.getPath());
        ds = NetcdfDataset.openDataset(f.getPath());
        fileType = ds.getFileTypeId();
        setCoordMap(ds.getCoordinateSystems());

        Formatter errlog = new Formatter();
        try {
          FeatureDataset featureDataset = FeatureDatasetFactoryManager.wrap(null, ds, null, errlog);
          if (featureDataset != null) {
            featureType = featureDataset.getFeatureType();
            if (featureType != null)
              ftype = featureType.toString();
            ftImpl = featureDataset.getImplementationName();
            Formatter infof = new Formatter();
            featureDataset.getDetailInfo(infof);
            info = infof.toString();
          } else {
            ftype = "FAIL: " + errlog.toString();
          }
        } catch (Throwable t) {
          ftype = "ERR: " + t.getMessage();
          info = errlog.toString();
          problem = t;
        }

      } catch (Throwable t) {
        fileType = "ERR: " + t.getMessage();
        problem = t;

      } finally {
        if (ds != null) try {
          ds.close();
        } catch (IOException ioe) {
        }
      }
    }
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

  public void testRemove() throws IOException, InvalidRangeException {
    try {
      String inName = TestLocal.cdmTestDataDir + "testWrite.nc";
      String outName = TestLocal.temporaryDataDir + "testRemove.nc";

      NetcdfDataset ncd = NetcdfDataset.acquireDataset(inName, null);
      System.out.println(ncd);
      System.out.println(ncd.removeVariable(null, "temperature"));
      System.out.println(ncd);

      ncd.finish();

      NetcdfFile ncdnew = ucar.nc2.FileWriter.writeToFile(ncd, outName, true);
      ncdnew.close();
      ncd.close();

      NetcdfDataset ncdnew2 = NetcdfDataset.acquireDataset(outName, null);
      assert ncdnew2.findVariable("temperature") == null;
      ncdnew2.close();
     
    } catch (IOException e) {
      e.printStackTrace();
    }
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

  }

  public void utestWarning() throws IOException {
    String org = "C:/tmp/example.nc";
    NetcdfDataset dds = NetcdfDataset.openDataset(org);
    FileWriter.writeToFile(dds, "C:/tmp/testOut.nc", true);
    dds.close();
  }
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

  }

  public void utestBufrEnhanced() throws IOException, InvalidRangeException {
    //String fileIn = "C:/data/bufr/edition3/ecmwf/synop.bufr";
    String fileIn = TestAll.cdmUnitTestDir +"bufr/edition3/ecmwf/synop.bufr";
    NetcdfDataset ncf = NetcdfDataset.openDataset(fileIn);
    System.out.println(ncf.toString());

    Structure s = (Structure) ncf.findVariable(BufrIosp.obsRecord);
    Array data = s.read();
    test.testArrayStructure( (ArrayStructure) data);

    Array data2 = s.read(new Section().appendRange(1,3));
    assert data2.getSize() == 3;
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

      String spec = location.substring(CompositeDatasetFactory.SCHEME.length());
      DatasetCollectionManager dcm = DatasetCollectionManager.open(spec, null, errlog);
      return CompositeDatasetFactory.factory(location, wantFeatureType, dcm, errlog);
    }

    NetcdfDataset ncd = NetcdfDataset.acquireDataset(location, task);
    return wrap(wantFeatureType, ncd, task, errlog);
  }
View Full Code Here

Examples of ucar.nc2.dataset.NetcdfDataset

    super(name);
  }

  public void testStrings() throws IOException, InvalidRangeException {
    String url = TestLocalDodsServer.testdata+"testWrite.nc";
    NetcdfDataset dodsfile = NetcdfDataset.openDataset(url);
    Variable v = null;

    // string
    assert(null != (v = dodsfile.findVariable("svar")));
    assert v.getFullName().equals("svar");
    assert v.getRank() == 1;
    assert v.getSize() == 80;
    assert v.getDataType() == DataType.CHAR : v.getDataType();

    Array a = v.read();
    assert a.getRank() == 1;
    assert a.getSize() == 80 : a.getSize();
    assert a.getElementType() == DataType.CHAR.getPrimitiveClassType();

    a = v.read("1:10");
    assert a.getRank() == 1;
    assert a.getSize() == 10 : a.getSize();
    assert a.getElementType() == DataType.CHAR.getPrimitiveClassType();

    // string array
    assert(null != (v = dodsfile.findVariable("names")));
    assert v.getFullName().equals("names");
    assert v.getRank() == 2;
    assert v.getSize() == 3 * 80;
    assert v.getDataType() == DataType.CHAR : v.getDataType();

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.