Ejemplo n.º 1
0
  @Test
  public void testSubset() throws IOException {
    DODSNetcdfFile dodsfile = TestDODSRead.open("test.05?types.integers");

    Variable v = null;
    Array a = null;

    // byte
    assert null != (v = dodsfile.findVariable("types.integers.b"));
    CheckByte(v);

    // int16
    assert null != (v = dodsfile.findVariable("types.integers.i16"));
    CheckInt16(v);

    // int32
    assert null != (v = dodsfile.findVariable("types.integers.i32"));
    CheckInt32(v);

    // uint32
    assert null != (v = dodsfile.findVariable("types.integers.ui32"));
    CheckUint32(v);

    // uint16
    assert null != (v = dodsfile.findVariable("types.integers.ui16"));
    CheckUint16(v);

    // uint32
    assert null != (v = dodsfile.findVariable("types.integers.ui32"));
    CheckUint32(v);

    dodsfile.close();
  }
Ejemplo n.º 2
0
  @Test
  public void testArraySubset() throws IOException {
    DODSNetcdfFile dodsfile = TestDODSRead.open("test.02?i32[1:10],f64[2:2:10]");

    Variable v = null;
    Array a = null;

    // int32
    assert (null != (v = dodsfile.findVariable("i32")));
    assert v.getFullName().equals("i32");
    assert v.getRank() == 1;
    assert v.getSize() == 10;
    assert v.getDataType() == DataType.INT;
    a = v.read();
    assert a.getRank() == 1;
    assert a.getSize() == 25;
    assert a.getElementType() == int.class;
    assert a instanceof ArrayInt.D1;

    ArrayInt.D1 ai = (ArrayInt.D1) a;
    for (int i = 0; i < 10; i++) {
      int val = ai.get(i);
      assert (val == i * 2048) : val + " != " + (i * 2048);
    }

    // uint16
    assert null == (v = dodsfile.findVariable("ui16"));
    assert null == (v = dodsfile.findVariable("ui32"));

    // double
    assert (null != (v = dodsfile.findVariable("f64")));
    assert v.getFullName().equals("f64");
    assert v.getRank() == 1;
    assert v.getSize() == 5;
    assert v.getDataType() == DataType.DOUBLE : v.getDataType();
    a = v.read();
    assert a.getRank() == 1;
    assert a.getSize() == 25;
    assert a.getElementType() == double.class;
    assert a instanceof ArrayDouble.D1;
    ArrayDouble.D1 ad = (ArrayDouble.D1) a;
    double[] tFloat64 =
        new double[] {
          1.0,
          0.9999500004166653,
          0.9998000066665778,
          0.9995500337489875,
          0.9992001066609779,
          0.9987502603949663,
          0.9982005399352042,
          0.9975510002532796,
          0.9968017063026194,
          0.9959527330119943,
          0.9950041652780257,
          0.9939560979566968,
          0.9928086358538663,
          0.9915618937147881,
          0.9902159962126371,
          0.9887710779360422,
          0.9872272833756269,
          0.9855847669095608,
          0.9838436927881214,
          0.9820042351172703,
          0.9800665778412416,
          0.9780309147241483,
          0.9758974493306055,
          0.9736663950053749,
          0.9713379748520297
        };

    for (int i = 0; i < 5; i++) {
      double val = ad.get(i);
      assert Misc.closeEnough(val, tFloat64[i], 1.0e-9);
    }

    dodsfile.close();
  }