Exemplo n.º 1
0
  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");
  }
Exemplo n.º 2
0
 private Array convertToChar(Variable newVar, Array oldData) {
   ArrayChar newData = (ArrayChar) Array.factory(DataType.CHAR, newVar.getShape());
   Index ima = newData.getIndex();
   IndexIterator ii = oldData.getIndexIterator();
   while (ii.hasNext()) {
     String s = (String) ii.getObjectNext();
     int[] c = ii.getCurrentCounter();
     for (int i = 0; i < c.length; i++) ima.setDim(i, c[i]);
     newData.setString(ima, s);
   }
   return newData;
 }
Exemplo n.º 3
0
  private ArrayDouble.D1 makeHeight1D(
      Array eta, Array s, Array depth, Array c, double depth_c, int x_index, int y_index) {
    int nz = (int) s.getSize();
    Index sIndex = s.getIndex();
    Index cIndex = c.getIndex();

    Index etaIndex = eta.getIndex();
    Index depthIndex = depth.getIndex();

    ArrayDouble.D1 height = new ArrayDouble.D1(nz);

    for (int z = 0; z < nz; z++) {
      double sz = s.getDouble(sIndex.set(z));
      double cz = c.getDouble(cIndex.set(z));

      double term1 = depth_c * sz;

      double fac1 = depth.getDouble(depthIndex.set(y_index, x_index));
      double term2 = fac1 * cz;

      double Sterm = (term1 + term2) / (depth_c + fac1);

      double term3 = eta.getDouble(etaIndex.set(y_index, x_index));
      double term4 = (term3 + fac1) * Sterm;
      double hterm = term3 + term4;

      height.set(z, hterm);
    }

    return height;
  }
Exemplo n.º 4
0
  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");
  }
Exemplo n.º 5
0
  private void doWrite2(NetcdfFileWriteable ncfile, String varName) throws Exception {
    Variable v = ncfile.findVariable(varName);
    int[] w = getWeights(v);

    int[] shape = v.getShape();
    Array aa = Array.factory(v.getDataType().getPrimitiveClassType(), shape);
    Index ima = aa.getIndex();
    for (int i = 0; i < shape[0]; i++) {
      for (int j = 0; j < shape[1]; j++) {
        aa.setDouble(ima.set(i, j), (double) (i * w[0] + j * w[1]));
      }
    }

    ncfile.write(varName, aa);
  }
Exemplo n.º 6
0
  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");
  }
Exemplo n.º 7
0
  public void readDoubleMissing() throws Exception {
    VariableDS v = null;
    assert (null != (v = (VariableDS) dsRead.findVariable("m1")));
    assert (v.getDataType() == DataType.DOUBLE);

    Array A = v.read();
    Index ima = A.getIndex();

    double val = A.getFloat(ima.set(1, 1));
    assert Double.isNaN(val);
    assert v.isMissing(val);

    // reread with useNans off
    v.setUseNaNs(false);
    v.createNewCache();
    A = v.read();
    ima = A.getIndex();

    val = A.getFloat(ima.set(1, 1));
    assert TestAll.closeEnough(val, -999.99) : val;
    assert v.isMissing(val);
  }
Exemplo n.º 8
0
  public void readSlice(NetcdfFile ncfile, int[] origin, int[] shape, String name)
      throws IOException, InvalidRangeException {

    Variable v = ncfile.findVariable(name);

    Array data = v.read(origin, shape);
    assert data.getRank() == 3;
    assert data.getSize() == shape[0] * shape[1] * shape[2];
    assert data.getShape()[0] == shape[0] : data.getShape()[0] + " " + shape[0];
    assert data.getShape()[1] == shape[1];
    assert data.getShape()[2] == shape[2];
    assert data.getElementType() == double.class;

    Index tIndex = data.getIndex();
    for (int i = 0; i < shape[0]; i++)
      for (int j = 0; j < shape[1]; j++)
        for (int k = 0; k < shape[2]; k++) {
          double val = data.getDouble(tIndex.set(i, j, k));
          // System.out.println(" "+val);
          assert TestUtils.close(val, 100 * (i + origin[0]) + 10 * j + k) : val;
        }
  }
Exemplo n.º 9
0
  public void readByte() throws Exception {
    Variable v = null;
    assert (null != (v = ncfileRead.findVariable("t3")));
    assert (v.getDataType() == DataType.BYTE);

    assert (null != (v = dsRead.findVariable("t3")));
    assert v instanceof VariableEnhanced;
    assert v instanceof VariableDS;
    VariableDS vs = (VariableDS) v;
    assert (vs.getDataType() == DataType.BYTE);

    Attribute att = vs.findAttribute("_FillValue");
    assert (null != att);
    assert (!att.isArray());
    assert (1 == att.getLength());
    System.out.println("_FillValue = " + att.getNumericValue().byteValue());
    assert (((byte) 255) == att.getNumericValue().byteValue());
    assert (DataType.BYTE == att.getDataType());

    assert (vs.hasMissing());
    assert (vs.hasFillValue());
    assert (vs.isMissing((double) ((byte) 255)));
    assert (vs.isFillValue((double) ((byte) 255)));

    Array A = vs.read();
    assert (A.getElementType() == byte.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.getFloat(ima.set(i, j)) == (i * 10 + j));
      }
    }
    System.out.println("**************TestStandardVar ReadByte");
  }
Exemplo n.º 10
0
  public void testReadData(NetcdfFile ncfile, String name) throws IOException {

    Variable v = ncfile.findVariable(name);
    assert null != v;
    assert v.getShortName().equals(name);
    assert v.getRank() == 3;
    assert v.getSize() == 36 : v.getSize();
    assert v.getShape()[0] == 3;
    assert v.getShape()[1] == 3;
    assert v.getShape()[2] == 4;
    assert v.getDataType() == DataType.DOUBLE;

    assert !v.isCoordinateVariable();

    assert v.getDimension(0) == ncfile.findDimension("time");
    assert v.getDimension(1) == ncfile.findDimension("lat");
    assert v.getDimension(2) == ncfile.findDimension("lon");

    Array data = v.read();
    assert data.getRank() == 3;
    assert data.getSize() == 36;
    assert data.getShape()[0] == 3;
    assert data.getShape()[1] == 3;
    assert data.getShape()[2] == 4;
    assert data.getElementType() == double.class;

    int[] shape = data.getShape();
    Index tIndex = data.getIndex();
    for (int i = 0; i < shape[0]; i++)
      for (int j = 0; j < shape[1]; j++)
        for (int k = 0; k < shape[2]; k++) {
          double val = data.getDouble(tIndex.set(i, j, k));
          // System.out.println(" "+val);
          assert TestUtils.close(val, 100 * i + 10 * j + k) : val;
        }
  }
Exemplo n.º 11
0
  /**
   * Make height from the given data. <br>
   * height(x,y,z) = eta(x,y) + ( eta(x,y) + depth([n],x,y) ) * S(x,y,z)
   *
   * <p>where, S(x,y,z) = (depth_c*s(z) + (depth([n],x,y) * C(z)) / (depth_c + depth([n],x,y)) /
   *
   * @param eta eta Array
   * @param s s Array
   * @param depth depth Array
   * @param c c Array
   * @param depth_c value of depth_c
   * @return height data
   */
  private ArrayDouble.D3 makeHeight(Array eta, Array s, Array depth, Array c, double depth_c) {
    int nz = (int) s.getSize();
    Index sIndex = s.getIndex();
    Index cIndex = c.getIndex();

    int[] shape2D = eta.getShape();
    int ny = shape2D[0];
    int nx = shape2D[1];
    Index etaIndex = eta.getIndex();
    Index depthIndex = depth.getIndex();

    ArrayDouble.D3 height = new ArrayDouble.D3(nz, ny, nx);

    for (int z = 0; z < nz; z++) {
      double sz = s.getDouble(sIndex.set(z));
      double cz = c.getDouble(cIndex.set(z));

      double term1 = depth_c * sz;

      for (int y = 0; y < ny; y++) {
        for (int x = 0; x < nx; x++) {

          double fac1 = depth.getDouble(depthIndex.set(y, x));
          double term2 = fac1 * cz;

          double Sterm = (term1 + term2) / (depth_c + fac1);

          double term3 = eta.getDouble(etaIndex.set(y, x));
          double term4 = (term3 + fac1) * Sterm;
          double hterm = term3 + term4;

          height.set(z, y, x, hterm);
        }
      }
    }

    return height;
  }
Exemplo n.º 12
0
  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));
  }
Exemplo n.º 13
0
  public void testWritePermute() throws Exception {
    NetcdfFileWriteable ncfile = new NetcdfFileWriteable();
    ncfile.setName(TestLocal.cdmTestDataDir + "permuteTest.nc");

    // define dimensions
    Dimension xDim = ncfile.addDimension("x", 3);
    Dimension yDim = ncfile.addDimension("y", 5);
    Dimension zDim = ncfile.addDimension("z", 4);
    Dimension tDim = ncfile.addDimension("time", 2);

    // define Variables
    ncfile.addVariable("time", double.class, new Dimension[] {tDim});
    ncfile.addVariableAttribute("time", "units", "secs since 1-1-1 00:00");

    ncfile.addVariable("z", double.class, new Dimension[] {zDim});
    ncfile.addVariableAttribute("z", "units", "meters");
    ncfile.addVariableAttribute("z", "positive", "up");

    ncfile.addVariable("y", double.class, new Dimension[] {yDim});
    ncfile.addVariableAttribute("y", "units", "degrees_north");

    ncfile.addVariable("x", double.class, new Dimension[] {xDim});
    ncfile.addVariableAttribute("x", "units", "degrees_east");

    ncfile.addVariable("tzyx", double.class, new Dimension[] {tDim, zDim, yDim, xDim});
    ncfile.addVariableAttribute("tzyx", "units", "K");

    ncfile.addVariable("tzxy", double.class, new Dimension[] {tDim, zDim, xDim, yDim});
    ncfile.addVariableAttribute("tzxy", "units", "K");

    ncfile.addVariable("tyxz", double.class, new Dimension[] {tDim, yDim, xDim, zDim});
    ncfile.addVariableAttribute("tyxz", "units", "K");

    ncfile.addVariable("txyz", double.class, new Dimension[] {tDim, xDim, yDim, zDim});
    ncfile.addVariableAttribute("txyz", "units", "K");

    ncfile.addVariable("zyxt", double.class, new Dimension[] {zDim, yDim, xDim, tDim});
    ncfile.addVariableAttribute("zyxt", "units", "K");

    ncfile.addVariable("zxyt", double.class, new Dimension[] {zDim, xDim, yDim, tDim});
    ncfile.addVariableAttribute("zxyt", "units", "K");

    ncfile.addVariable("yxzt", double.class, new Dimension[] {yDim, xDim, zDim, tDim});
    ncfile.addVariableAttribute("yxzt", "units", "K");

    ncfile.addVariable("xyzt", double.class, new Dimension[] {xDim, yDim, zDim, tDim});
    ncfile.addVariableAttribute("xyzt", "units", "K");

    // missing one dimension
    ncfile.addVariable("zyx", double.class, new Dimension[] {zDim, yDim, xDim});
    ncfile.addVariable("txy", double.class, new Dimension[] {tDim, xDim, yDim});
    ncfile.addVariable("yxz", double.class, new Dimension[] {yDim, xDim, zDim});
    ncfile.addVariable("xzy", double.class, new Dimension[] {xDim, zDim, yDim});
    ncfile.addVariable("yxt", double.class, new Dimension[] {yDim, xDim, tDim});
    ncfile.addVariable("xyt", double.class, new Dimension[] {xDim, yDim, tDim});
    ncfile.addVariable("xyz", double.class, new Dimension[] {xDim, yDim, zDim});

    // missing two dimension
    ncfile.addVariable("yx", double.class, new Dimension[] {yDim, xDim});
    ncfile.addVariable("xy", double.class, new Dimension[] {xDim, yDim});
    ncfile.addVariable("yz", double.class, new Dimension[] {yDim, zDim});
    ncfile.addVariable("xz", double.class, new Dimension[] {xDim, zDim});
    ncfile.addVariable("yt", double.class, new Dimension[] {yDim, tDim});
    ncfile.addVariable("xt", double.class, new Dimension[] {xDim, tDim});
    ncfile.addVariable("ty", double.class, new Dimension[] {tDim, yDim});
    ncfile.addVariable("tx", double.class, new Dimension[] {tDim, xDim});

    // add global attributes
    ncfile.addGlobalAttribute("Convention", "COARDS");

    // create the file
    try {
      ncfile.create();
    } catch (IOException e) {
      System.err.println("ERROR creating file");
      assert (false);
    }

    // write time data
    int len = tDim.getLength();
    ArrayDouble A = new ArrayDouble.D1(len);
    Index ima = A.getIndex();
    for (int i = 0; i < len; i++) A.setDouble(ima.set(i), (double) (i * 3600));
    int[] origin = new int[1];
    try {
      ncfile.write("time", origin, A);
    } catch (IOException e) {
      System.err.println("ERROR writing time");
      assert (false);
    }

    // write z data
    len = zDim.getLength();
    A = new ArrayDouble.D1(len);
    ima = A.getIndex();
    for (int i = 0; i < len; i++) A.setDouble(ima.set(i), (double) (i * 10));
    try {
      ncfile.write("z", origin, A);
    } catch (IOException e) {
      System.err.println("ERROR writing z");
      assert (false);
    }

    // write y data
    len = yDim.getLength();
    A = new ArrayDouble.D1(len);
    ima = A.getIndex();
    for (int i = 0; i < len; i++) A.setDouble(ima.set(i), (double) (i * 3));
    try {
      ncfile.write("y", origin, A);
    } catch (IOException e) {
      System.err.println("ERROR writing y");
      assert (false);
    }

    // write x data
    len = xDim.getLength();
    A = new ArrayDouble.D1(len);
    ima = A.getIndex();
    for (int i = 0; i < len; i++) A.setDouble(ima.set(i), (double) (i * 5));
    try {
      ncfile.write("x", origin, A);
    } catch (IOException e) {
      System.err.println("ERROR writing x");
      assert (false);
    }

    // write tzyx data
    doWrite4(ncfile, "tzyx");
    doWrite4(ncfile, "tzxy");
    doWrite4(ncfile, "txyz");
    doWrite4(ncfile, "tyxz");
    doWrite4(ncfile, "zyxt");
    doWrite4(ncfile, "zxyt");
    doWrite4(ncfile, "xyzt");
    doWrite4(ncfile, "yxzt");

    doWrite3(ncfile, "zyx");
    doWrite3(ncfile, "txy");
    doWrite3(ncfile, "yxz");
    doWrite3(ncfile, "xzy");
    doWrite3(ncfile, "yxt");
    doWrite3(ncfile, "xyt");
    doWrite3(ncfile, "yxt");
    doWrite3(ncfile, "xyz");

    doWrite2(ncfile, "yx");
    doWrite2(ncfile, "xy");
    doWrite2(ncfile, "yz");
    doWrite2(ncfile, "xz");
    doWrite2(ncfile, "yt");
    doWrite2(ncfile, "xt");
    doWrite2(ncfile, "ty");
    doWrite2(ncfile, "tx");

    if (show) System.out.println("ncfile = " + ncfile);

    // all done
    try {
      ncfile.close();
    } catch (IOException e) {
      System.err.println("ERROR writing file");
      assert (false);
    }

    System.out.println("*****************Test Write done");
  }
Exemplo n.º 14
0
  public void testWriteStandardVar() throws Exception {
    NetcdfFileWriteable ncfile = new NetcdfFileWriteable(filename, false);

    // define dimensions
    Dimension latDim = ncfile.addDimension("lat", 2);
    Dimension lonDim = ncfile.addDimension("lon", 3);

    ArrayList dims = new ArrayList();
    dims.add(latDim);
    dims.add(lonDim);

    // case 1
    ncfile.addVariable("t1", DataType.DOUBLE, dims);
    ncfile.addVariableAttribute("t1", CDM.SCALE_FACTOR, new Double(2.0));
    ncfile.addVariableAttribute("t1", "add_offset", new Double(77.0));

    // case 2
    ncfile.addVariable("t2", DataType.BYTE, dims);
    ncfile.addVariableAttribute("t2", CDM.SCALE_FACTOR, new Short((short) 2));
    ncfile.addVariableAttribute("t2", "add_offset", new Short((short) 77));

    // case 3
    ncfile.addVariable("t3", DataType.BYTE, dims);
    ncfile.addVariableAttribute("t3", "_FillValue", new Byte((byte) 255));

    // case 4
    ncfile.addVariable("t4", DataType.SHORT, dims);
    ncfile.addVariableAttribute("t4", CDM.MISSING_VALUE, new Short((short) -9999));

    // case 5
    ncfile.addVariable("t5", DataType.SHORT, dims);
    ncfile.addVariableAttribute("t5", CDM.MISSING_VALUE, new Short((short) -9999));
    ncfile.addVariableAttribute("t5", CDM.SCALE_FACTOR, new Short((short) 2));
    ncfile.addVariableAttribute("t5", "add_offset", new Short((short) 77));

    // case 1
    ncfile.addVariable("m1", DataType.DOUBLE, dims);
    ncfile.addVariableAttribute("m1", CDM.MISSING_VALUE, -999.99);

    // create the file
    ncfile.create();

    // write t1
    ArrayDouble A = new ArrayDouble.D2(latDim.getLength(), lonDim.getLength());
    int i, j;
    Index ima = A.getIndex();
    // write
    for (i = 0; i < latDim.getLength(); i++)
      for (j = 0; j < lonDim.getLength(); j++) A.setDouble(ima.set(i, j), (double) (i * 10.0 + j));
    int[] origin = new int[2];
    ncfile.write("t1", origin, A);

    // write t2
    ArrayByte Ab = new ArrayByte.D2(latDim.getLength(), lonDim.getLength());
    ima = Ab.getIndex();
    for (i = 0; i < latDim.getLength(); i++)
      for (j = 0; j < lonDim.getLength(); j++) Ab.setByte(ima.set(i, j), (byte) (i * 10 + j));
    ncfile.write("t2", origin, Ab);

    // write t3
    ncfile.write("t3", origin, Ab);

    // write t4
    Array As = new ArrayShort.D2(latDim.getLength(), lonDim.getLength());
    ima = As.getIndex();
    for (i = 0; i < latDim.getLength(); i++)
      for (j = 0; j < lonDim.getLength(); j++) As.setShort(ima.set(i, j), (short) (i * 10 + j));
    ncfile.write("t4", origin, As);

    As.setShort(ima.set(0, 0), (short) -9999);
    ncfile.write("t5", origin, As);

    // write m1
    ArrayDouble.D2 Ad = new ArrayDouble.D2(latDim.getLength(), lonDim.getLength());
    for (i = 0; i < latDim.getLength(); i++)
      for (j = 0; j < lonDim.getLength(); j++) Ad.setDouble(ima.set(i, j), (double) (i * 10.0 + j));
    Ad.set(1, 1, -999.99);
    ncfile.write("m1", new int[2], Ad);

    // all done
    ncfile.close();

    System.out.println("**************TestStandardVar Write done");
  }
Exemplo n.º 15
0
  public void readShort2FloatMissing() throws Exception {
    Variable v = null;
    assert (null != (v = ncfileRead.findVariable("t5")));
    assert (v.getDataType() == DataType.SHORT);

    // standard convert with missing data
    assert (null != (v = dsRead.findVariable("t5")));
    assert v instanceof VariableEnhanced;
    assert v instanceof VariableDS;
    VariableDS vs = (VariableDS) v;
    assert (vs.getDataType() == DataType.FLOAT);

    assert (vs.hasMissing());
    assert (vs.hasMissingValue());
    double mv = 2 * (-9999) + 77;
    assert (vs.isMissing((double) mv));
    assert (vs.isMissingValue((double) mv));

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

    assert (vs.isMissing(A.getFloat(ima.set(0, 0))));

    for (i = 0; i < shape[0]; i++) {
      for (j = 1; j < shape[1]; j++) {
        float val = A.getFloat(ima.set(i, j));
        float want = 2 * (i * 10 + j) + 77;
        if (val != want) System.out.println(i + " " + j + " " + val + " " + want);
        assert (val == want);
      }
    }

    // useNaNs
    vs.setUseNaNs(true);
    assert (vs.getDataType() == DataType.FLOAT);

    assert (vs.hasMissing());
    assert (vs.hasMissingValue());
    double mv2 = 2 * (-9999) + 77;
    assert (vs.isMissing((double) mv2));
    assert (vs.isMissingValue((double) mv2));

    Array A2 = vs.read();
    Index ima2 = A2.getIndex();
    int[] shape2 = A2.getShape();

    double mval = A2.getFloat(ima2.set(0, 0));
    assert vs.isMissing(mval);
    assert Double.isNaN(mval);

    for (i = 0; i < shape2[0]; i++) {
      for (j = 1; j < shape2[1]; j++) {
        float val = A2.getFloat(ima2.set(i, j));
        float want = 2 * (i * 10 + j) + 77;
        if (val != want) System.out.println(i + " " + j + " " + val + " " + want);
        assert (val == want) : val + " != " + want;
      }
    }

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

    System.out.println("**************TestStandardVar Read readShort2FloatMissing");
  }
Exemplo n.º 16
0
  private void makeCoordinateDataWithMissing(
      int datatype,
      Variable time,
      Variable elev,
      Variable azi,
      Variable nradialsVar,
      Variable ngatesVar,
      List groups) {

    Array timeData = Array.factory(time.getDataType().getPrimitiveClassType(), time.getShape());
    Index timeIndex = timeData.getIndex();

    Array elevData = Array.factory(elev.getDataType().getPrimitiveClassType(), elev.getShape());
    Index elevIndex = elevData.getIndex();

    Array aziData = Array.factory(azi.getDataType().getPrimitiveClassType(), azi.getShape());
    Index aziIndex = aziData.getIndex();

    Array nradialsData =
        Array.factory(nradialsVar.getDataType().getPrimitiveClassType(), nradialsVar.getShape());
    IndexIterator nradialsIter = nradialsData.getIndexIterator();

    Array ngatesData =
        Array.factory(ngatesVar.getDataType().getPrimitiveClassType(), ngatesVar.getShape());
    IndexIterator ngatesIter = ngatesData.getIndexIterator();

    // first fill with missing data
    IndexIterator ii = timeData.getIndexIterator();
    while (ii.hasNext()) ii.setIntNext(MISSING_INT);

    ii = elevData.getIndexIterator();
    while (ii.hasNext()) ii.setFloatNext(MISSING_FLOAT);

    ii = aziData.getIndexIterator();
    while (ii.hasNext()) ii.setFloatNext(MISSING_FLOAT);

    // now set the  coordinate variables from the Cinrad2Record radial
    int last_msecs = Integer.MIN_VALUE;
    int nscans = groups.size();
    try {
      for (int scan = 0; scan < nscans; scan++) {
        List scanGroup = (List) groups.get(scan);
        int nradials = scanGroup.size();

        Cinrad2Record first = null;
        for (int j = 0; j < nradials; j++) {
          Cinrad2Record r = (Cinrad2Record) scanGroup.get(j);
          if (first == null) first = r;

          int radial = r.radial_num - 1;
          timeData.setInt(timeIndex.set(scan, radial), r.data_msecs);
          elevData.setFloat(elevIndex.set(scan, radial), r.getElevation());
          aziData.setFloat(aziIndex.set(scan, radial), r.getAzimuth());

          if (r.data_msecs < last_msecs)
            logger.warn("makeCoordinateData time out of order " + r.data_msecs);
          last_msecs = r.data_msecs;
        }

        nradialsIter.setIntNext(nradials);
        ngatesIter.setIntNext(first.getGateCount(datatype));
      }
    } catch (java.lang.ArrayIndexOutOfBoundsException ae) {
      logger.debug("Cinrad2IOSP.uncompress ", ae);
    }
    time.setCachedData(timeData, false);
    elev.setCachedData(elevData, false);
    azi.setCachedData(aziData, false);
    nradialsVar.setCachedData(nradialsData, false);
    ngatesVar.setCachedData(ngatesData, false);
  }