Examples of NetcdfFile


Examples of ucar.nc2.NetcdfFile

     float b_name(3);
   } ArrayOfStructures(10);
    type = Layout(8);  type= 1 (contiguous) storageSize = (10,16) dataSize=0 dataAddress=2048
   */
   public void testStructureWithArrayMember() throws IOException {
    NetcdfFile ncfile = TestH5.openH5("support/DSwith_array_member.h5");

    Variable v = ncfile.findVariable("ArrayOfStructures");
    v.setCaching(false);
    assert( null != v);
    assert( v.getDataType() == DataType.STRUCTURE);
    assert( v instanceof Structure);
    assert( v.getRank() == 1);
    assert( v.getShape()[0] == 10);

    try {
      Array data = v.read(new int[] {4}, new int[] {3});
      assert(data.getElementType() == StructureData.class);
      assert (data instanceof ArrayStructure);
      assert (data.getSize() == 3) : data.getSize();
      assert (data.getRank() == 1);

      int count = 0;
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        Object o = iter.next();
        assert (o instanceof StructureData);
        StructureData d = (StructureData) o;

        Array arr = d.getArray("a_name");
        assert (arr != null);
        assert (arr.getElementType() == int.class);
        assert (arr instanceof ArrayInt);
        assert (arr.getInt( arr.getIndex()) == 4 + count);
        NCdump.printArray( arr, "a_name", out, null);

        arr = d.getArray("b_name");
        assert (arr != null);
        assert (arr.getElementType() == float.class);
        assert (arr instanceof ArrayFloat);
        assert (arr.getSize() == 3);
        assert (arr.getFloat( arr.getIndex()) == (float) 4.0 + count);
        NCdump.printArray( arr, "b_name", out, null);

        count++;
      }

    }
    catch (InvalidRangeException e) { assert false; }
    catch (IOException e) { assert false; }

    try {
      Array data = v.read();
      assert(data.getElementType() == StructureData.class);
      assert (data instanceof ArrayStructure);
      assert (data.getSize() == 10);
      assert (data.getRank() == 1);

      int count = 0;
      IndexIterator iter = data.getIndexIterator();
      while (iter.hasNext()) {
        Object o = iter.next();
        assert (o instanceof StructureData);
        StructureData d = (StructureData) o;

        Array arr = d.getArray("a_name");
        assert (arr != null);
        assert (arr.getElementType() == int.class);
        assert (arr instanceof ArrayInt);
        assert (arr.getInt( arr.getIndex()) == count);
        NCdump.printArray( arr, "a_name", out, null);

        arr = d.getArray("b_name");
        assert (arr != null);
        assert (arr.getElementType() == float.class);
        assert (arr instanceof ArrayFloat);
        assert (arr.getSize() == 3);
        assert (arr.getFloat( arr.getIndex()) == (float) count);
        NCdump.printArray( arr, "b_name", out, null);

        count++;
      }

    } catch (IOException e) { assert false; }

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

Examples of ucar.nc2.NetcdfFile

    compare(filename, remote);
  }

  void compare(String file, String remote) throws IOException {
    System.out.printf("---------------------------\n");
    NetcdfFile ncfile = NetcdfDataset.openFile(file, null);
    NetcdfFile ncfileRemote = new CdmRemote(remote);

    Formatter f= new Formatter();
    CompareNetcdf2 cn = new CompareNetcdf2(f, false, false, false);
    boolean ok = cn.compare(ncfile, ncfileRemote);
    if (ok)
      System.out.printf("compare %s ok %n", file);
    else
      System.out.printf("compare %s NOT OK %n%s", file, f.toString());
    ncfile.close();
    ncfileRemote.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  //////////////////////////////////////////////////////////////
  public static void main2(String[] args) {
    try {
      String filename = "C:/data/formats/netcdf3/testWrite.nc";
      NetcdfFile ncfile = NetcdfFile.open(filename);
      NcStreamWriter writer = new NcStreamWriter(ncfile, null);

      File file = new File("C:/temp/out.ncs");
      FileOutputStream fos = new FileOutputStream(file);
      WritableByteChannel wbc = fos.getChannel();
      writer.streamAll( wbc);
      wbc.close();

      NetcdfFile ncfileBack = NetcdfFile.open(file.getPath());

      Formatter f = new Formatter();
      CompareNetcdf2 cn = new CompareNetcdf2(f, false, false, true);
      boolean ok = cn.compare(ncfile, ncfileBack);
      if (ok)
        System.out.printf("compare %s ok %n", file);
      else
        System.out.printf("compare %s NOT OK %n%s", file, f.toString());

      ncfileBack.close();
      ncfile.close();


    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

Examples of ucar.nc2.NetcdfFile

      String remote = "http://localhost:8080/thredds/cdmremote/testCdmremote/netcdf3/testWrite.nc";
      CdmRemote ncfileRemote = new CdmRemote(remote);

      String fileOut = "C:/temp/out2.ncs";
      ncfileRemote.writeToFile(fileOut);
      NetcdfFile ncfileBack = NetcdfFile.open(fileOut);

      String filename = "C:/data/formats/netcdf3/testWrite.nc";
      NetcdfFile ncfileOrg = NetcdfFile.open(filename);

      Formatter f = new Formatter();
      CompareNetcdf2 cn = new CompareNetcdf2(f, false, false, true);
      boolean ok = cn.compare(ncfileOrg, ncfileBack);
      if (ok)
        System.out.printf("compare %s ok %n", fileOut);
      else
        System.out.printf("compare %s NOT OK %n%s", fileOut, f.toString());

      ncfileBack.close();
      ncfileOrg.close();
      ncfileRemote.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  public void testNamExtract() throws IOException, InvalidRangeException {
    String location = TestAll.cdmUnitTestDir + "ncml/nc/namExtract/test_agg.ncml";
    System.out.println(" TestOffAggExistingTimeUnitsChange.open "+ location);

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

    Variable v = ncfile.findVariable("time");
    assert v != null;
    assert v.getDataType() == DataType.DOUBLE;

    String units = v.getUnitsString();
    assert units != null;
    assert units.equals("hours since 2006-09-25T06:00:00Z");

    int count = 0;
    Array data = v.read();
    NCdumpW.printArray(data, "time", new PrintWriter(System.out), null);
    while (data.hasNext()) {
      assert TestAll.closeEnough(data.nextInt(), (count + 1) * 3);
      count++;
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

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

    String location = "file:"+ TestAll.cdmUnitTestDir + "ncml/nc/narr/";
    System.out.println(" TestOffAggExistingTimeUnitsChange.testNarrGrib=\n"+ ncml);
    NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml), location, null);

    Variable v = ncfile.findVariable("time");
    assert v != null;
    assert v.getDataType() == DataType.DOUBLE;

    String units = v.getUnitsString();
    assert units != null;
    assert units.equals("hours since 2007-04-11T00:00:00Z") : units;

    int count = 0;
    Array data = v.read();
    NCdumpW.printArray(data, "time", new PrintWriter(System.out), null);
    while (data.hasNext()) {
      assert data.nextInt() == count * 3;
      count++;
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

            infile=args[0];
        } else { System.out.println("Usage: java SigmetIOServiceProvider inputFile");
        System.exit(0)}
        try {
            NetcdfFile.registerIOProvider(SigmetIOServiceProvider.class);
            NetcdfFile ncfile=NetcdfFile.open(infile);
            System.out.println("ncfile = \n"+ncfile);
        } catch (Exception e) { System.out.println("MAIN!!!   "+e.toString());
        e.printStackTrace(); }
    }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  public void testOneCDL() throws IOException, InterruptedException {
    testCDL("C:\\data\\netcdf4\\files\\tst_ncml.nc", true);
  }

  private void testCDL(String filename, boolean show) throws IOException, InterruptedException {
    NetcdfFile ncfile = TestNC2.open(filename);
    System.out.println("File "+filename);

    ByteArrayOutputStream bout = new ByteArrayOutputStream(30 * 1000);
    NCdump.print(ncfile, bout, false, false, false, true, null, null);
    String njCDL = bout.toString();
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  }

  public void testReadCompressedInt() throws IOException {
    // actually doesnt seem to be compressed ??

    NetcdfFile ncfile = TestH5.openH5("support/zip.h5");
    Variable dset = ncfile.findVariable("Data/Compressed_Data");
    assert dset != null;
    assert(dset.getDataType() == DataType.INT);

    assert(dset.getRank() == 2);
    assert(dset.getShape()[0] == 1000);
    assert(dset.getShape()[1] == 20);

    // read entire array
    Array A = dset.read();
    assert(A.getRank() == 2);
    assert(A.getShape()[0] == 1000);
    assert(A.getShape()[1] == 20);

    int[] shape = A.getShape();
    Index ima = A.getIndex();
    for (int i = 0; i < shape[0]; i++)
      for (int j = 0; j < shape[1]; j++)
        assertA.getInt(ima.set(i,j)) == i+j) : i+" "+j+" "+A.getInt(ima);

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  }

  public void testReadCompressedByte() throws IOException {
    // actually doesnt seem to be compressed ??

    NetcdfFile ncfile = TestH5.openH5("msg/MSG1_8bit_HRV.H5");
    Variable dset = ncfile.findVariable("image1/image_preview");
    assert dset != null;
    assert(dset.getDataType() == DataType.BYTE);

    assert(dset.getRank() == 2);
    assert(dset.getShape()[0] == 64);
    assert(dset.getShape()[1] == 96);

    // read entire array
    Array A = dset.read();
    assert(A.getRank() == 2);
    assert(A.getShape()[0] == 64);
    assert(A.getShape()[1] == 96);

    byte[] firstRow = new byte[] {
       0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
      31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
      31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 33, 34, 35, 36, 37, 39, 39,
      40, 42, 42, 44, 44, 57, 59, 52, 52, 53, 55, 59, 62, 63, 66, 71, 79, 81,
      83, 85, 87, 89, 90, 87, 84, 84, 87, 94, 82, 80, 76, 77, 68, 59, 57, 61,
      68, 81, 42};

    byte[] lastRow = new byte[] {
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17, 31, 31,
      31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
      31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
      31, 31, 30, 31, 28, 20, 11, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

    int[] shape = A.getShape();
    Index ima = A.getIndex();
    int lrow = shape[0]-1;
    for (int j = 0; j < shape[1]; j++) {
      assertA.getByte(ima.set(0,j)) == firstRow[j]) : A.getByte(ima)+" should be "+firstRow[j];
      assertA.getByte(ima.set(lrow,j)) == lastRow[j]) : A.getByte(ima)+" should be "+lastRow[j];
    }

    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.