Examples of NetcdfFile


Examples of ucar.nc2.NetcdfFile

    ncfile.close();
  }

  public void testEndian() throws IOException {
    String testDir = TestN4.testDir;
    NetcdfFile ncfile = TestNC2.open(testDir+"endianTest.nc4");
    Variable v = ncfile.findVariable("TMP");
    assert v != null;
    assert v.getDataType() == DataType.FLOAT;

    Array data = v.read();
    assert data.getElementType() == float.class;
View Full Code Here

Examples of ucar.nc2.NetcdfFile

     * @throws IOException  problem reading the file
     */
    public static void main(String[] args) throws IOException {
        IOServiceProvider areaiosp = new AreaServiceProvider();
        RandomAccessFile  rf     = new RandomAccessFile(args[0], "r", 2048);
        NetcdfFile ncfile = new MakeNetcdfFile(areaiosp, rf, args[0], null);
        if (args.length > 1) {
            ucar.nc2.FileWriter.writeToFile(ncfile, args[1]);
        }
    }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  public TestH5ReadArray(String name) {
    super(name);
  }

  public void testReadArrayType() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/SDS_array_type.h5");

    Variable dset = null;
    assert(null != (dset = ncfile.findVariable("IntArray")));
    assert(dset.getDataType() == DataType.INT);

    assert(dset.getRank() == 3);
    assert(dset.getShape()[0] == 10);
    assert(dset.getShape()[1] == 5);
    assert(dset.getShape()[2] == 4);

    // read entire array
    Array A;
    try {
      A = dset.read();
    }
    catch (IOException e) {
      System.err.println("ERROR reading file");
      assert(false);
      return;
    }
    assert(A.getRank() == 3);

    Index ima = A.getIndex();
    int[] shape = A.getShape();

    for (int i = 0; i < shape[0]; i++)
      for (int j = 0; j < shape[1]; j++)
        for (int k = 0; k < shape[2]; k++)
          if (A.getInt(ima.set(i, j, k)) != i) {
            assert false;
          }


          // read part of array
    dset.setCachedData(null, false); // turn off caching to test read subset
    dset.setCaching(false);
    int[] origin2 = new int[3];
    int[] shape2 = new int[] {
        10, 1, 1};
    try {
      A = dset.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() == 3);
    assert(A.getShape()[0] == 10);
    assert(A.getShape()[1] == 1);
    assert(A.getShape()[2] == 1);

    ima = A.getIndex();
    for (int j = 0; j < shape2[0]; j++) {
      assert(A.getInt(ima.set0(j)) == j):A.getInt(ima);
    }

    // rank reduction
    Array Areduce = A.reduce();
    Index ima2 = Areduce.getIndex();
    assert(Areduce.getRank() == 1);
    ima = A.getIndex();

    for (int j = 0; j < shape2[0]; j++) {
      assert(A.getInt(ima.set0(j)) == j);
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    out.close();
    tempFile.delete();
  }

  public void testVlengthAttribute() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/vlstra.h5");

    Attribute att = ncfile.findGlobalAttribute("test_scalar");
    assert (null != att);
    assert (!att.isArray());
    assert (att.isString());
    assert (att.getStringValue().equals("This is the string for the attribute"));
    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    assert (att.getStringValue().equals("This is the string for the attribute"));
    ncfile.close();
  }

  public void testVlengthVariableChunked() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/uvlstr.h5");

    Variable v = ncfile.findVariable("Space1");
    assert (null != v);
    assert (v.getDataType() == DataType.STRING);
    assert (v.getRank() == 1);
    assert (v.getShape()[0] == 9);

    try {
      Array data = v.read();
      assert (data.getElementType() == String.class);
      assert (data instanceof ArrayObject);
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        out.println(iter.next());
      }

    } catch (IOException e) {
      e.printStackTrace();
      assert false;
    }

    int[] origin = new int[]{3};
    int[] shape = new int[]{3};
    try {
      Array data2 = v.read(origin, shape);
      Index ima = data2.getIndex();
      assert (data2.getElementType() == String.class);
      assert (data2 instanceof ArrayObject);
      assert ((String) data2.getObject(ima.set(0))).startsWith("testing whether that nation");
      assert ((String) data2.getObject(ima.set(1))).startsWith("O Gloria inmarcesible!");
      assert ((String) data2.getObject(ima.set(2))).startsWith("bien germina ya!");
    }
    catch (IOException e) {
      assert false;
    }
    catch (InvalidRangeException e) {
      assert false;
    }

    ncfile.close();
  } // */
 
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    ncfile.close();
  } // */

  public void testVlengthVariable() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/vlslab.h5");

    Variable v = ncfile.findVariable("Space1");
    assert (null != v);
    assert (v.getDataType() == DataType.STRING);
    assert (v.getRank() == 1);
    assert (v.getShape()[0] == 12);

    try {
      Array data = v.read();
      assert (data.getElementType() == String.class);
      assert (data instanceof ArrayObject);
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        out.println(iter.next());
      }

    } catch (IOException e) {
      assert false;
    }

    int[] origin = new int[]{4};
    int[] shape = new int[]{1};
    try {
      Array data2 = v.read(origin, shape);
      Index ima = data2.getIndex();
      assert (data2.getElementType() == String.class);
      assert (data2 instanceof ArrayObject);
      assert ((String) data2.getObject(ima.set(0))).equals("Five score and seven years ago our forefathers brought forth on this continent a new nation,");
    }
    catch (IOException e) {
      assert false;
    }
    catch (InvalidRangeException e) {
      assert false;
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    testVlenEndian(TestN4.testDir+"vlenLittleEndian.nc", 100);
    //testVlenEndian("C:/data/work/bruno/fpscminicodac_1.nc", 100);
  }

  private void testVlenEndian(String filename, int n) throws IOException {
    NetcdfFile ncfile = NetcdfDataset.openFile(filename, null);

    Variable v = ncfile.findVariable("levels");
    assert (null != v);
    assert (v.getDataType() == DataType.INT);
    assert (v.getRank() == 2);
    assert (v.getShape()[0] == n) : v.getShape()[0];

    try {
      Array data = v.read();
      // assert(data.getElementType() instanceof ucar.ma2.ArrayInt.class) : data.getElementType();
      assert (data instanceof ArrayObject);
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        Array inner = (Array) iter.next();
        assert (inner instanceof ArrayInt.D1);
        int firstVal = inner.getInt(0);
        System.out.printf("%d (%d) = %s%n", firstVal, inner.getSize(), inner);
        assert (firstVal < Short.MAX_VALUE) : firstVal;
      }

    } catch (IOException e) {
      assert false;
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    super(name);
  }

  public void test1() throws IOException {
    //H5header.setDebugFlags( new ucar.nc2.util.DebugFlagsImpl("H5header/header"));
    NetcdfFile ncfile = TestH5.open(testDir +"HIRDLS1_v4.0.2a-aIrix-c2_2003d106.he5");
    Variable dset = ncfile.findVariable("HDFEOS/SWATHS/HIRDLS_L1_Swath/Data Fields/Scaled Ch01 Radiance");
    dset.read();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    Variable dset = ncfile.findVariable("HDFEOS/SWATHS/HIRDLS_L1_Swath/Data Fields/Scaled Ch01 Radiance");
    dset.read();
  }

  public void test2() throws IOException {
    NetcdfFile ncfile = TestH5.open(testDir +"HIRDLS2-AFGL_b027_na.he5");
    Variable dset = ncfile.findVariable("HDFEOS/SWATHS/HIRDLS/Data Fields/Altitude");
   
    //H5header.setDebugFlags( new ucar.nc2.util.DebugFlagsImpl("H5header/dataBtree"));
    Array data = dset.read();
    assert data.getElementType() == float.class;
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    assert data.getElementType() == float.class;
  }

  public void testEosMetadata() {
    //NetcdfFile ncfile = TestH5.open("c:/data/hdf5/HIRDLS/HIRDLS2_v0.3.1-aIrix-c3_2003d106.h5");
    NetcdfFile ncfile = TestH5.open(testDir +"HIRDLS2-Aura73p_b029_2000d275.he5");

    Group root = ncfile.getRootGroup();
    Group g = root.findGroup("HDFEOS INFORMATION");
    Variable dset = g.findVariable("StructMetadata.0");
    assert(null != dset );
    assert(dset.getDataType() == DataType.CHAR);
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.