コード例 #1
0
ファイル: FireInputer.java プロジェクト: hgenet/dostem
  void initTransientFire(boolean useseverity, String dir) {
    String filename = dir + "fire.nc";

    NetcdfFile ncfile = null;
    File spfile = new File(filename);
    if (spfile.exists()) {
      try {
        ncfile = NetcdfFile.open(filename);
        Variable fyearV = ncfile.findVariable("FIRE");
        trfireyearA = fyearV.read();

        Variable fseasonV = ncfile.findVariable("SEASON");
        trfireseasonA = fseasonV.read();

        if (useseverity) {
          Variable fsevV = ncfile.findVariable("SEVERITY");
          trseverityA = fsevV.read();
        }

      } catch (IOException ioe) {
        System.out.println(ioe.getMessage());
      } finally {
        if (ncfile != null) {
          try {
            ncfile.close();
          } catch (IOException ioee) {
            System.out.println(ioee.getMessage());
          }
        }
      }
    } else { // file not exist
      System.out.println("Input file: " + filename + " NOT existed");
      System.exit(-1);
    }
  };
コード例 #2
0
ファイル: CompareNetcdf2.java プロジェクト: jnbek/thredds
  public boolean compareVariables(NetcdfFile org, NetcdfFile copy) {
    f.format("Original = %s%n", org.getLocation());
    f.format("CompareTo= %s%n", copy.getLocation());
    boolean ok = true;

    for (Variable orgV : org.getVariables()) {
      if (orgV.isCoordinateVariable()) continue;
      Variable copyVar = copy.findVariable(orgV.getShortName());
      if (copyVar == null) {
        f.format(" MISSING '%s' in 2nd file%n", orgV.getFullName());
        ok = false;
      } else {
        List<Dimension> dims1 = orgV.getDimensions();
        List<Dimension> dims2 = copyVar.getDimensions();
        if (!compare(dims1, dims2)) {
          f.format(" %s != %s%n", orgV.getNameAndDimensions(), copyVar.getNameAndDimensions());
        } else {
          // f.format("   ok %s%n", orgV.getName());
        }
      }
    }

    f.format("%n");
    for (Variable orgV : copy.getVariables()) {
      if (orgV.isCoordinateVariable()) continue;
      Variable copyVar = org.findVariable(orgV.getShortName());
      if (copyVar == null) {
        f.format(" MISSING '%s' in 1st file%n", orgV.getFullName());
        ok = false;
      }
    }

    return ok;
  }
コード例 #3
0
  private void check(NetcdfFile ncfile, int n) throws IOException, InvalidRangeException {
    Variable v = ncfile.findVariable("time");
    assert v != null;
    System.out.printf(" time= %s%n", v.getNameAndDimensions());
    assert v.getSize() == n : v.getSize();

    v = ncfile.findVariable("eta");
    assert v != null;
    assert v.getRank() == 3 : v.getRank();
  }
コード例 #4
0
  /* Structure {
      int LAT[0];
      ...
      int LAT[149];
  } IMAGE_LAT_ARRAY(3600);
     type = Layout(8);  type= 2 (chunked) storageSize = (1,600) dataSize=0 dataAddress=2548046
  */
  @Test
  public void testReadOneAtATime() throws java.io.IOException, InvalidRangeException {
    try (NetcdfFile ncfile = TestH5.openH5("IASI/IASI.h5")) {

      Variable dset = ncfile.findVariable("U-MARF/EPS/IASI_xxx_1C/DATA/IMAGE_LAT_ARRAY");
      assert (null != dset);
      assert (dset.getDataType() == DataType.STRUCTURE);
      assert (dset.getRank() == 1);
      assert (dset.getSize() == 3600);

      Dimension d = dset.getDimension(0);
      assert (d.getLength() == 3600);

      Structure s = (Structure) dset;

      // read last one - chunked
      StructureData sd = s.readStructure(3599);
      assert sd.getScalarInt("LAT[0]") == 70862722;
      assert sd.getScalarInt("LAT[149]") == 85302263;

      // read one at a time
      for (int i = 3590; i < d.getLength(); i++) {
        s.readStructure(i);
        System.out.println(" read structure " + i);
      }
    }
    System.out.println("*** testReadIASI ok");
  }
コード例 #5
0
  /**
   * Clones the attributes of one NetCDF file into another.
   *
   * @param infile - The source NetCDF file
   * @param inVarName - The variable name to be copied
   * @param outfile - The destination NetCDF file
   * @param outVarName - The output variable name
   */
  private void cloneAttributes(
      NetcdfFile infile, String inVarName, NetcdfFileWriteable outfile, String outVarName) {

    // Find the variable

    Variable vi = infile.findVariable(inVarName);

    // Grab all of its attributes - unchecked, but should be OK.

    List<Attribute> l = vi.getAttributes();
    for (Attribute a : l) {
      if (a.getName().equalsIgnoreCase("units") && inVarName.equalsIgnoreCase("time")) {
        Attribute aa = new Attribute("units", "days since 1900-12-31 00:00:00");
        outfile.addVariableAttribute(outVarName, aa);
      } else if (a.getName().equalsIgnoreCase("time_origin")
          && inVarName.equalsIgnoreCase("time")) {
        Attribute aa = new Attribute("time_origin", "1900-12-31 00:00:00");
        outfile.addVariableAttribute(outVarName, aa);
      } else if (a.getName().equalsIgnoreCase("calendar")) {
        Attribute aa = new Attribute("calendar", "standard");
        outfile.addVariableAttribute(outVarName, aa);
      } else {
        outfile.addVariableAttribute(outVarName, a);
      }
    }
  }
コード例 #6
0
  public void testAggCoordVar2(NetcdfFile ncfile) {

    Variable time = ncfile.findVariable("time");
    assert null != time;
    assert time.getShortName().equals("time");
    assert time.getRank() == 1 : time.getRank();
    assert time.getShape()[0] == 3;
    assert time.getDataType() == DataType.INT;

    assert time.getDimension(0) == ncfile.findDimension("time");

    try {
      Array data = time.read();

      assert (data instanceof ArrayInt);
      IndexIterator dataI = data.getIndexIterator();
      assert dataI.getIntNext() == 0 : dataI.getIntCurrent();
      assert dataI.getIntNext() == 1 : dataI.getIntCurrent();
      assert dataI.getIntNext() == 2 : dataI.getIntCurrent();

    } catch (IOException io) {
      io.printStackTrace();
      assert false;
    }
  }
コード例 #7
0
ファイル: TestStandardVar.java プロジェクト: kenkyu/thredds
  public void readByte2Short() throws Exception {
    Variable t2 = null;
    assert (null != (t2 = ncfileRead.findVariable("t2")));
    assert (t2.getDataType() == DataType.BYTE);

    Attribute att = t2.findAttribute(CDM.SCALE_FACTOR);
    assert (null != att);
    assert (!att.isArray());
    assert (1 == att.getLength());
    assert (2 == att.getNumericValue().doubleValue());
    assert (DataType.SHORT == att.getDataType());

    assert (null != (t2 = dsRead.findVariable("t2")));
    assert t2 instanceof VariableEnhanced;
    VariableDS vs = (VariableDS) t2;
    assert (vs.getDataType() == DataType.SHORT) : vs.getDataType();
    assert (!vs.hasMissing());

    Array A = vs.read();
    assert (A.getElementType() == short.class) : A.getElementType();
    Index ima = A.getIndex();
    int[] shape = A.getShape();
    int i, j;
    for (i = 0; i < shape[0]; i++) {
      for (j = 0; j < shape[1]; j++) {
        assert (A.getShort(ima.set(i, j)) == (2 * (i * 10 + j) + 77));
      }
    }
    System.out.println("**************TestStandardVar readByte2Short");
  }
コード例 #8
0
ファイル: SeadasFileReader.java プロジェクト: bcdev/seadas
  public void addInputParamMetadata(Product product) throws ProductIOException {

    Variable inputParams = ncFile.findVariable("Input_Parameters");
    if (inputParams != null) {
      final MetadataElement inputParamsMeta = new MetadataElement("Input_Parameters");
      Array array;
      try {
        array = inputParams.read();
      } catch (IOException e) {
        throw new ProductIOException(e.getMessage());
      }

      String[] lines = array.toString().split("\n");
      for (String line : lines) {
        String[] parts = line.split("=");
        if (parts.length == 2) {
          final String name = parts[0].trim();
          final String value = parts[1].trim();
          final ProductData data = ProductData.createInstance(ProductData.TYPE_ASCII, value);
          final MetadataAttribute attribute = new MetadataAttribute(name, data, true);
          inputParamsMeta.addAttribute(attribute);
        }
      }

      final MetadataElement metadataRoot = product.getMetadataRoot();
      metadataRoot.addElement(inputParamsMeta);
    }
  }
コード例 #9
0
  public void testAggCoordVar(NetcdfFile ncfile) {
    Variable time = ncfile.findVariable("time");
    assert null != time;

    assert time.getShortName().equals("time");
    assert time.getRank() == 1;
    assert time.getSize() == 3;
    assert time.getShape()[0] == 3;
    assert time.getDataType() == DataType.DOUBLE;

    assert time.getDimension(0) == ncfile.findDimension("time");

    try {
      Array data = time.read();
      assert data.getRank() == 1;
      assert data.getSize() == 3;
      assert data.getShape()[0] == 3;
      assert data.getElementType() == double.class;

      int count = 0;
      IndexIterator dataI = data.getIndexIterator();
      while (dataI.hasNext()) {
        assert Misc.closeEnough(dataI.getDoubleNext(), result[count]);
        count++;
      }

    } catch (IOException io) {
      io.printStackTrace();
      assert false;
    }
  }
コード例 #10
0
 /**
  * Sets the v-velocity file to be used by this class
  *
  * @param _velocityFile - the v-velocity NetCDF object
  * @param vName - the name of the v variable
  * @throws IOException
  */
 public void setVFile(String _velocityFile, String vName) throws IOException {
   this.vName = vName;
   vFile = NetcdfFile.open(_velocityFile);
   if (vFile != null) {
     vVar = vFile.findVariable(vName);
   }
 }
コード例 #11
0
  /*
   Structure {
    int a_name;
    byte b_name(3);
    byte c_name(3);
    short d_name(3);
    int e_name(3);
    long f_name(3);
    int g_name(3);
    short h_name(3);
    int i_name(3);
    long j_name(3);
    float k_name(3);
    double l_name(3);
  } CompoundNative(15);
      type = Layout(8);  type= 1 (contiguous) storageSize = (15,144) dataSize=0 dataAddress=2048
  */
  @Test
  public void testReadH5StructureArrayMembers() throws java.io.IOException {
    try (NetcdfFile ncfile = TestH5.openH5("complex/compound_native.h5")) {

      Variable dset = ncfile.findVariable("CompoundNative");
      assert (null != dset);
      assert (dset.getDataType() == DataType.STRUCTURE);
      assert (dset.getRank() == 1);
      assert (dset.getSize() == 15);

      Dimension d = dset.getDimension(0);
      assert (d.getLength() == 15);

      Structure s = (Structure) dset;

      // read all with the iterator
      StructureDataIterator iter = s.getStructureIterator();
      while (iter.hasNext()) {
        StructureData sd = iter.next();

        for (StructureMembers.Member m : sd.getMembers()) {
          Array data = sd.getArray(m);
          NCdumpW.printArray(data, m.getName(), out, null);
        }
      }
    }
    System.out.println("*** testReadH5StructureArrayMembers ok");
  }
コード例 #12
0
  public void testAggCoordVar(NetcdfFile ncfile) {

    Variable time = ncfile.findVariable("time");
    assert null != time;
    assert time.getShortName().equals("time");
    assert time.getRank() == 1 : time.getRank();
    assert time.getShape()[0] == 3;
    assert time.getDataType() == DataType.INT;

    assert time.getDimension(0) == ncfile.findDimension("time");

    try {
      Array data = time.read();

      assert (data instanceof ArrayInt.D1) : data.getClass().getName();
      ArrayInt.D1 dataI = (ArrayInt.D1) data;
      assert dataI.get(0) == 0;
      assert dataI.get(1) == 10;
      assert dataI.get(2) == 99;

    } catch (IOException io) {
      io.printStackTrace();
      assert false;
    }
  }
コード例 #13
0
ファイル: OceanSG2.java プロジェクト: feihugis/NetCDF
  /**
   * Create a new vertical transform for Ocean_S_coordinate_g2
   *
   * @param ds dataset
   * @param timeDim time dimension
   * @param params list of transformation Parameters
   */
  public OceanSG2(NetcdfFile ds, Dimension timeDim, List<Parameter> params) {

    super(timeDim);
    String etaName = getParameterStringValue(params, ETA);
    String sName = getParameterStringValue(params, S);
    String depthName = getParameterStringValue(params, DEPTH);
    String depthCName = getParameterStringValue(params, DEPTH_C);
    String cName = getParameterStringValue(params, C);

    etaVar = ds.findVariable(etaName);
    sVar = ds.findVariable(sName);
    depthVar = ds.findVariable(depthName);
    depthCVar = ds.findVariable(depthCName);
    cVar = ds.findVariable(cName);

    units = ds.findAttValueIgnoreCase(depthVar, CDM.UNITS, "none");
  }
コード例 #14
0
  @Ignore("files not available")
  @Test
  public void testCacheTiming() throws IOException, InvalidRangeException {
    String filename = "file:testCacheTiming.xml";
    System.out.printf("%s%n", filename);

    String cacheDirName = TestDir.temporaryLocalDataDir + "testAggExistingCache/";
    System.out.printf("cacheDir=%s%n", cacheDirName);
    File cacheDir = new File(cacheDirName);
    FileUtils.deleteDirectory(cacheDir); // from commons-io
    assert !cacheDir.exists();

    DiskCache2 cache = new DiskCache2(cacheDirName, false, 0, 0);
    cache.setAlwaysUseCache(true);
    Assert.assertEquals(cache.getRootDirectory(), cacheDirName);
    assert new File(cache.getRootDirectory()).exists();

    Aggregation.setPersistenceCache(cache);
    AggregationExisting.countCacheUse = 0;

    long start = System.currentTimeMillis();

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml2), filename, null)) {
      System.out.printf("%nTestNcmlAggExisting.open %s%n", filename);
      Variable time = ncfile.findVariable("time");
      System.out.printf(" Variable %s%n", time.getNameAndDimensions());
      time.read();
    }
    System.out.printf(" countCacheUse = %d%n", AggregationExisting.countCacheUse);

    long took = System.currentTimeMillis() - start;
    System.out.printf(" first took %d msecs%n", took);

    AggregationExisting.countCacheUse = 0;
    start = System.currentTimeMillis();

    try (NetcdfFile ncfile = NcMLReader.readNcML(new StringReader(ncml2), filename, null)) {
      System.out.printf("%nTestNcmlAggExisting.open %s%n", filename);
      Variable time = ncfile.findVariable("time");
      System.out.printf(" Variable %s%n", time.getNameAndDimensions());
      time.read();
    }
    System.out.printf(" countCacheUse = %d%n", AggregationExisting.countCacheUse);
    took = System.currentTimeMillis() - start;
    System.out.printf(" second took %d msecs%n", took);
  }
コード例 #15
0
  private boolean checkTime(long time) {

    /*
     * Right now, the lookups are based solely on the dimensions (lats,
     * lons, depth, time) of the u velocity files, assuming that u, v and w
     * share common Dimensions. Otherwise we'd need to set up independent
     * XYZ and T lookups for UV and W increasing computational overhead,
     * when this really shouldn't be necessary. BUT, it might be a good idea
     * to ensure that the velocity files are consistent.
     */

    int uidx = Collections.binarySearch(uKeys, time);
    // int vidx = Collections.binarySearch(vKeys, time);
    // int widx = Collections.binarySearch(wKeys, time);

    if (uidx == -1 || uidx > uKeys.size()) {
      return false;
    }

    if (uidx < 0) {
      uidx = -(uidx + 2);
    }

    // if (vidx < 0) {
    // vidx = -(vidx + 2);
    // }

    // if (widx < 0) {
    // widx = -(widx + 2);
    // }

    if (pidx != uidx) {

      uFile = uFiles.get(uKeys.get(uidx));
      vFile = vFiles.get(vKeys.get(uidx));
      wFile = wFiles.get(wKeys.get(uidx));

      uVar = uFile.findVariable(uName);
      vVar = vFile.findVariable(vName);
      wVar = wFile.findVariable(wName);

      setTLookup(tName);
      pidx = uidx;
    }
    return true;
  }
コード例 #16
0
 /**
  * Sets the name of the lookup variable for the Time position
  *
  * @param name
  */
 public void setTLookup(String name) {
   tVar = uFile.findVariable(tName);
   if (tVar == null) {
     System.out.println(
         "Incorrect variable match:\n\nVariables in local config file: " + tName + ".");
     System.out.println("Velocity file variables: " + uFile.getVariables().toString() + "\n");
   }
   tloc = new IndexLookup_Nearest(tVar);
 }
コード例 #17
0
ファイル: TestNcMLStrides.java プロジェクト: kenkyu/thredds
  public void testStride() throws IOException, InvalidRangeException {
    System.out.println("ncfile opened = " + location + "\n" + ncfile);
    Variable time = ncfile.findVariable("time");

    ArrayInt all = (ArrayInt) time.read();
    for (int i = 0; i < all.getSize(); i++) assert (all.getInt(i) == i + 1);

    testStride("0:13:3");

    for (int i = 1; i < 12; i++) testStride("0:13:" + i);
  }
コード例 #18
0
 /**
  * Sets the name of the lookup variable for the North-South position
  *
  * @param name
  */
 public void setYLookup(String name) {
   latVar = uFile.findVariable(latName);
   if (latVar == null) {
     System.out.println(
         "Incorrect variable match:\n\nVariables in local config file: " + latName + ".");
     System.out.println("Velocity file variables: " + uFile.getVariables().toString() + "\n");
   }
   yloc = new IndexLookup_Nearest(latVar, 0); // dimension 0 because slices
   // have 2D lat/lon
   bounds[2][0] = yloc.getMinVal();
   bounds[2][1] = yloc.getMaxVal();
 }
コード例 #19
0
ファイル: TestStandardVar.java プロジェクト: kenkyu/thredds
  public void readShortMissing() throws Exception {
    Variable v = null;
    assert (null != (v = ncfileRead.findVariable("t4")));
    assert (v.getDataType() == DataType.SHORT);

    // default use of missing_value
    assert (null != (v = dsRead.findVariable("t4")));
    assert v instanceof VariableEnhanced;
    assert v instanceof VariableDS;
    VariableDS vs = (VariableDS) v;
    assert (vs.getDataType() == DataType.SHORT);

    Attribute att = vs.findAttribute(CDM.MISSING_VALUE);
    assert (null != att);
    assert (!att.isArray());
    assert (1 == att.getLength());
    System.out.println("missing_value = " + att.getNumericValue().shortValue());
    assert (((short) -9999) == att.getNumericValue().shortValue());
    assert (DataType.SHORT == att.getDataType());

    assert (vs.hasMissing());
    assert (vs.hasMissingValue());
    assert (vs.isMissing((double) ((short) -9999)));
    assert (vs.isMissingValue((double) ((short) -9999)));

    Array A = vs.read();
    Index ima = A.getIndex();
    int[] shape = A.getShape();
    int i, j;
    for (i = 0; i < shape[0]; i++) {
      for (j = 0; j < shape[1]; j++) {
        assert (A.getFloat(ima.set(i, j)) == (i * 10 + j));
      }
    }

    // turn off missing data
    vs.setMissingDataIsMissing(false);
    assert (vs.getDataType() == DataType.SHORT);

    assert (!vs.hasMissing());
    assert (vs.hasMissingValue());
    assert (!vs.isMissing((double) ((short) -9999)));
    assert (vs.isMissingValue((double) ((short) -9999)));

    vs.setMissingDataIsMissing(true);
    assert (vs.hasMissing());
    assert (vs.isMissing((double) ((short) -9999)));

    System.out.println("**************TestStandardVar Read readShortMissing");
  }
コード例 #20
0
  /*
      Structure {
      int a_name;
      String b_name(4);
      char c_name(6);
      short d_name(5, 4);
      float e_name;
      double f_name(10);
      byte g_name;
    } CompoundComplex(6);
     type = Layout(8);  type= 1 (contiguous) storageSize = (6,224) dataSize=0 dataAddress=2048
  */
  @Test
  public void testReadH5Structure() throws java.io.IOException {
    int a_name = 0;
    String[] b_name =
        new String[] {
          "A fight is a contract that takes two people to honor.",
          "A combative stance means that you've accepted the contract.",
          "In which case, you deserve what you get.",
          "  --  Professor Cheng Man-ch'ing"
        };
    String c_name = "Hello!";

    // H5header.setDebugFlags(new ucar.nc2.util.DebugFlagsImpl("H5header/header"));
    try (NetcdfFile ncfile = TestH5.openH5("complex/compound_complex.h5")) {

      Variable dset = ncfile.findVariable("CompoundComplex");
      assert (null != dset);
      assert (dset.getDataType() == DataType.STRUCTURE);
      assert (dset.getRank() == 1);
      assert (dset.getSize() == 6);

      Dimension d = dset.getDimension(0);
      assert (d.getLength() == 6);

      Structure s = (Structure) dset;

      // read all with the iterator
      StructureDataIterator iter = s.getStructureIterator();
      while (iter.hasNext()) {
        StructureData sd = iter.next();
        assert sd.getScalarInt("a_name") == a_name;
        a_name++;
        assert sd.getScalarString("c_name").equals(c_name);
        String[] results = sd.getJavaArrayString(sd.findMember("b_name"));
        assert results.length == b_name.length;
        int count = 0;
        for (String r : results) assert r.equals(b_name[count++]);

        for (StructureMembers.Member m : sd.getMembers()) {
          Array data = sd.getArray(m);
          NCdumpW.printArray(data, m.getName(), out, null);
        }
      }
    }
    System.out.println("*** testReadH5Structure ok");
  }
コード例 #21
0
ファイル: NOWRadiosp.java プロジェクト: feihugis/NetCDF
  public static void main(String args[])
      throws Exception, IOException, InstantiationException, IllegalAccessException {
    String fileIn = "z:/nowrad/BREF_951207_2230";

    // String fileIn = "c:/data/image/Nids/n0r_20041013_1852";
    ucar.nc2.NetcdfFile.registerIOProvider(ucar.nc2.iosp.nowrad.NOWRadiosp.class);

    ucar.nc2.NetcdfFile ncf = ucar.nc2.NetcdfFile.open(fileIn);

    // List alist = ncf.getGlobalAttributes();
    ucar.nc2.Variable v = ncf.findVariable("BaseReflectivity");
    int[] origin = {0, 0};
    int[] shape = {300, 36};
    ArrayByte data = (ArrayByte) v.read(origin, shape);

    ncf.close();
  }
コード例 #22
0
ファイル: ConvertNetCDF.java プロジェクト: jkachika/galileo
  public static Map<String, Metadata> readFile(String file) throws Exception {
    NetcdfFile n = NetcdfFile.open(file);
    System.out.println("Opened: " + file);

    /* Determine the size of our grid */
    int xLen = n.findDimension("x").getLength();
    int yLen = n.findDimension("y").getLength();
    System.out.println("Grid size: " + xLen + "x" + yLen);

    /* What time is this set of readings for? */
    Variable timeVar = n.findVariable("time");
    String timeStr = timeVar.getUnitsString().toUpperCase();
    timeStr = timeStr.replace("HOURS SINCE ", "");
    timeStr = timeStr.replace("HOUR SINCE ", "");

    /* Find the base date (the day) the reading was taken */
    Date baseDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX").parse(timeStr);

    /* Get the number of hours since the base date this reading was taken */
    int offset = timeVar.read().getInt(0);

    /* Generate the actual date for this reading */
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(baseDate);
    calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + offset);
    System.out.println("Time of collection: " + calendar.getTime());

    /* We'll keep a mapping of geolocations -> Galileo Metadata */
    Map<String, Metadata> metaMap = new HashMap<>();

    /* Determine the lat, lon coordinates for the grid points, and get each
     * reading at each grid point. */
    NetcdfDataset dataset = new NetcdfDataset(n);
    @SuppressWarnings("resource")
    GridDataset gridData = new GridDataset(dataset);
    for (GridDatatype g : gridData.getGrids()) {
      /* Let's look at 3D variables: these have WxH dimensions, plus a
       * single plane.  A 4D variable would contain elevation
       * and multiple planes as a result */
      if (g.getShape().length == 3) {
        convert3DVariable(g, calendar.getTime(), metaMap);
      }
    }

    return metaMap;
  }
コード例 #23
0
ファイル: TestStandardVar.java プロジェクト: kenkyu/thredds
  public void readDouble() throws Exception {

    Variable t1 = null;
    assert (null != (t1 = ncfileRead.findVariable("t1")));
    assert (t1.getDataType() == DataType.DOUBLE);

    Attribute att = t1.findAttribute(CDM.SCALE_FACTOR);
    assert (null != att);
    assert (!att.isArray());
    assert (1 == att.getLength());
    assert (2.0 == att.getNumericValue().doubleValue());
    assert (DataType.DOUBLE == att.getDataType());

    // read
    Array A = t1.read();
    int i, j;
    Index ima = A.getIndex();
    int[] shape = A.getShape();

    for (i = 0; i < shape[0]; i++) {
      for (j = 0; j < shape[1]; j++) {
        assert (A.getDouble(ima.set(i, j)) == (double) (i * 10.0 + j));
      }
    }

    assert (null != (t1 = dsRead.findVariable("t1")));
    assert t1 instanceof VariableEnhanced;
    VariableEnhanced dsVar = (VariableEnhanced) t1;
    assert (dsVar.getDataType() == DataType.DOUBLE);

    A = dsVar.read();
    ima = A.getIndex();
    shape = A.getShape();

    for (i = 0; i < shape[0]; i++) {
      for (j = 0; j < shape[1]; j++) {
        assert (A.getDouble(ima.set(i, j)) == (2.0 * (i * 10.0 + j) + 77.0));
      }
    }

    assert (null == t1.findAttribute(CDM.SCALE_FACTOR));
    assert (null == t1.findAttribute("add_offset"));

    System.out.println("**************TestStandardVar ReadDouble");
  }
コード例 #24
0
  public void test1() throws IOException, InvalidRangeException {
    String filename = "file:./" + TestNcML.topDir + "aggSynthetic.xml";
    NetcdfFile ncfile = NcMLReader.readNcML(filename, null);

    Variable v = ncfile.findVariable("time");
    assert v != null;
    String testAtt = ncfile.findAttValueIgnoreCase(v, "units", null);
    assert testAtt != null;
    assert testAtt.equals("months since 2000-6-16 6:00");

    testDimensions(ncfile);
    testCoordVar(ncfile);
    testAggCoordVar(ncfile);
    testReadData(ncfile, "T");
    testReadSlice(ncfile, "T");

    ncfile.close();
  }
コード例 #25
0
  public void testAggCoordVar3(NetcdfFile ncfile) throws IOException {
    Variable time = ncfile.findVariable("time");
    assert null != time;
    assert time.getShortName().equals("time");
    assert time.getRank() == 1 : time.getRank();
    assert time.getShape()[0] == 3;
    assert time.getDataType() == DataType.DOUBLE : time.getDataType();

    assert time.getDimension(0) == ncfile.findDimension("time");

    Array data = time.read();

    assert (data instanceof ArrayDouble);
    IndexIterator dataI = data.getIndexIterator();
    double val = dataI.getDoubleNext();
    assert Misc.closeEnough(val, 0.0) : val;
    assert Misc.closeEnough(dataI.getDoubleNext(), 10.0) : dataI.getDoubleCurrent();
    assert Misc.closeEnough(dataI.getDoubleNext(), 99.0) : dataI.getDoubleCurrent();
  }
コード例 #26
0
  public void testAggCoordVarScan(NetcdfFile ncfile) throws IOException {
    Variable time = ncfile.findVariable("time");
    assert null != time;
    assert time.getShortName().equals("time");
    assert time.getRank() == 1 : time.getRank();
    assert time.getShape()[0] == 3;
    assert time.getDataType() == DataType.INT : time.getDataType();

    assert time.getDimension(0) == ncfile.findDimension("time");

    int count = 0;
    Array data = time.read();
    assert (data instanceof ArrayInt);
    while (data.hasNext()) {
      int val = data.nextInt();
      assert val == count * 10 : val + "!=" + count * 10;
      count++;
    }
  }
コード例 #27
0
  /** Sets the name of the lookup variable for vertical position */
  public void setZLookup(String name) {
    zVar = uFile.findVariable(zName);
    if (zVar == null) {
      throw new IllegalArgumentException(
          "Incorrect variable match:\n\nVariables in local config file: "
              + zName
              + ".\nVelocity file variables: "
              + uFile.getVariables().toString()
              + "\n");
    }

    zloc = new IndexLookup_Nearest(zVar);

    if (positiveDown) {
      zloc.setNegate(true);
    }

    bounds[1][0] = zloc.getMinVal();
    bounds[1][1] = zloc.getMaxVal();
  }
コード例 #28
0
ファイル: TestNcMLStrides.java プロジェクト: kenkyu/thredds
  public void testStride(String stride) throws IOException, InvalidRangeException {
    Variable time = ncfile.findVariable("time");
    ArrayInt all = (ArrayInt) time.read();

    ArrayInt correct = (ArrayInt) all.section(new Section(stride).getRanges());
    System.out.printf("correct(%s) %s", stride, NCdumpW.toString(correct));
    ArrayInt data = (ArrayInt) time.read(stride);
    System.out.printf("data(%s) %s%n", stride, NCdumpW.toString(data));
    Index ci = correct.getIndex();
    Index di = data.getIndex();
    for (int i = 0; i < data.getSize(); i++)
      assert (data.getInt(di.set(i)) == correct.getInt(ci.set(i)))
          : stride
              + " index "
              + i
              + " = "
              + data.getInt(di.set(i))
              + " != "
              + correct.getInt(ci.set(i));
  }
コード例 #29
0
  /**
   * Sets the name of the lookup variable for the East-West position
   *
   * @param name
   */
  public void setXLookup(String name) {
    lonVar = uFile.findVariable(lonName);
    if (lonVar == null) {
      System.out.println(
          "Incorrect variable match:\n\nVariables in local config file: " + lonName + ".");
      System.out.println("Velocity file variables: " + uFile.getVariables().toString() + "\n");
    }

    int dim = 0;

    if (lonVar.getRank() > 1) {
      dim = 1;
    }

    xloc = new IndexLookup_Nearest(lonVar, dim); // dimension 1 because
    // slices
    // have 2D lat/lon
    bounds[3][0] = xloc.getMinVal();
    bounds[3][1] = xloc.getMaxVal();
  }
コード例 #30
0
  public void testAggCoordVarSubsetDefeatLocalCache(NetcdfFile ncfile)
      throws InvalidRangeException, IOException {
    Variable time = ncfile.findVariable("time");
    assert null != time;

    assert time.getShortName().equals("time");
    assert time.getRank() == 1;
    assert time.getSize() == 3;
    assert time.getShape()[0] == 3;
    assert time.getDataType() == DataType.DOUBLE;

    assert time.getDimension(0) == ncfile.findDimension("time");

    time.setCachedData(null, false);
    Array data = time.read("1:2");
    assert data.getRank() == 1;
    assert data.getSize() == 2;
    assert data.getShape()[0] == 2;
    assert data.getElementType() == double.class;

    int count = 0;
    IndexIterator dataI = data.getIndexIterator();
    while (dataI.hasNext()) {
      assert Misc.closeEnough(dataI.getDoubleNext(), result[count + 1]);
      count++;
    }

    time.setCachedData(null, false);
    data = time.read("0:2:2");
    assert data.getRank() == 1;
    assert data.getSize() == 2;
    assert data.getShape()[0] == 2;
    assert data.getElementType() == double.class;

    count = 0;
    dataI = data.getIndexIterator();
    while (dataI.hasNext()) {
      assert Misc.closeEnough(dataI.getDoubleNext(), result[count * 2]);
      count++;
    }
  }