Examples of NetcdfFile


Examples of ucar.nc2.NetcdfFile

  public static String testDir = TestAll.cdmUnitTestDir + "formats/hdf5/";

public static NetcdfFile open( String filename) {
    try {
      System.out.println("**** Open "+filename);
      NetcdfFile ncfile = NetcdfFile.open(filename);
      if (TestH5.dumpFile) System.out.println("open "+ncfile);
      return ncfile;

    } catch (java.io.IOException e) {
      System.out.println(" fail = "+e);
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  }

  public static NetcdfFile openH5( String filename) {
    try {
      System.out.println("**** Open "+ testDir+filename);
      NetcdfFile ncfile = NetcdfFile.open( testDir+filename);
      if (TestH5.dumpFile) System.out.println("open H5 "+ncfile);
      return ncfile;

    } catch (java.io.IOException e) {
      System.out.println(" fail = "+e);
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  }   */

  static void readFromNetcdf(String filename) throws IOException {
    long start = System.currentTimeMillis();

    NetcdfFile ncfile = NetcdfFile.open(filename);
    ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE);

    Structure record = (Structure) ncfile.findVariable("record");
    List<Variable> members = record.getVariables();
    for (Variable v : members) {
      if (v.getDataType() != DataType.CHAR)
        new MetarField(v.getShortName());
    }

    StructureDataIterator siter = record.getStructureIterator();
    int count = 0;
    while (siter.hasNext()) {
      StructureData sdata = siter.next();
      List<StructureMembers.Member> sm = sdata.getMembers();
      for (StructureMembers.Member m : sm) {
        MetarField f = MetarField.fields.get(m.getName());
        if (null != f) f.sum( sdata, m);
      }
      count++;
    }

    System.out.println("Read from NetCDF; # metars= " + count);
    double took = .001 * (System.currentTimeMillis() - start);
    System.out.println(" that took = " + took + " sec; "+ Format.d(count/took,0)+" metars/sec");

    for (MetarField f : MetarField.fields.values())
      System.out.println(" "+f.name+ " = "+f.sum);
           
    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    List<String> openfiles = RandomAccessFile.getOpenFiles();
    int count = openfiles.size();
    System.out.println("count files at start="+count);

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

    Array ATssta = ncfile.readSection("ATssta(:,0,0,0)");

    int count1 = RandomAccessFile.getOpenFiles().size();
    System.out.println("count files after open="+count1);

    ncfile.close();

    int count2 = RandomAccessFile.getOpenFiles().size();
    System.out.println("count files after close="+count2);
    assert count1 == count2 : "openFile count "+count +"!="+ count2;
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  }

  public void openFile(Average avg) throws IOException, InvalidRangeException {
    long start = System.nanoTime();

    NetcdfFile ncfile = NetcdfDataset.openFile(TestAll.cdmUnitTestDir +"ft/grid/netcdf/AZ.000000000.nc", null);
    Variable v = ncfile.findVariable("qc");
    assert null != v;
    assert v.getDataType() == DataType.BYTE;

    Array data = v.read();
    assert data.getElementType() == byte.class;
    double sum = MAMath.sumDoubleSkipMissingData(data, Double.NaN);
    long end = System.nanoTime();
    double took = (double)((end - start))/1000/1000/1000;
    double perelem = (double)((end - start)) / data.getSize();
    //System.out.println(sum+" "+enhance+" took="+took+" secs; size= "+data.getSize()+"; nanosecs/elem= "+perelem);
    ncfile.close();

    if (avg != null) avg.add(took);
  }
View Full Code Here

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 xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2' enhance='true' >\n" +
      "  <aggregation dimName='runtime' type='forecastModelRunCollection' timeUnitsChange='true'>\n" +
      "    <scan location='D:/work/signell/efine' suffix='.nc' dateFormatMark='#yyyyMMddHH' enhance='true' />" +
      "  </aggregation>\n" +
      "</netcdf>";
    NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(xml), "aggFmrcScaling", null);

    // make sure that scaling is applied
    VariableDS vs = (VariableDS) ncfile.findVariable("hs");
    Array data = vs.read("0,1,:,:)");
    while (data.hasNext()) {
      float val = data.nextFloat();
      if (!vs.isMissing(val))
        assert (val < 10.0) : val;
      //System.out.printf("%f %n",val);
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

    ncfile.close();
  }

  public void testScaling2() throws Exception {
    NetcdfFile ncfile = NetcdfDataset.acquireFile("file:D:/work/signell/efine/fine.ncml", null);

    // make sure that scaling is applied
    VariableDS vs = (VariableDS) ncfile.findVariable("hs");
    Array data = vs.read("0,1,:,:)");
    while (data.hasNext()) {
      float val = data.nextFloat();
      if (!vs.isMissing(val))
        assert (val < 10.0) : val;
      //System.out.printf("%f %n",val);
    }

    ncfile.close();
  }
View Full Code Here

Examples of ucar.nc2.NetcdfFile

  // test dataset handler
  static private ucar.nc2.dt.grid.GridDataset openGridDataset(String filename) throws IOException {

    // fetch it as a NetcdfFile; this deals with possible NcML
    NetcdfFile ncfile = NetcdfDataset.acquireFile(filename, null);

    if (ncfile == null) return null;

    NetcdfDataset ncd;
    if (ncfile instanceof NetcdfDataset) {
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.