/** * Get the total number of bytes in the array. * * @return total number of bytes in the array */ public long getSizeBytes() { DataType dtype = DataType.getType( getElementType()); return indexCalc.getSize() * dtype.getSize(); }
/** * Reads all the data for this variable and returns them as an array of a Java primitive type. * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a vector). * This method may cache the returned vector, at UCAR library choice. */ @Override public Vector read() throws IOException { final Array array = variable.read(); // May be cached by the UCAR library. return Vector.create(array.get1DJavaArray(array.getElementType()), variable.isUnsigned()); }
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getElementType(), getShape()); MAMath.copy(newA, this); newA.setUnsigned(isUnsigned()); return newA; }
/** * Create a copy of this Array, copying the data so that physical order is the same as * logical order * * @return the new Array */ public Array copy() { Array newA = factory(getElementType(), getShape()); MAMath.copy(newA, this); newA.setUnsigned( isUnsigned()); return newA; }
void CheckSValue( Array a) { assert a.getRank() == 0; assert a.getElementType() == String.class; String str = (String) a.getObject(a.getIndex()); assert str.equals("This is a data test string (pass 0)."); }
void CheckSValue( Array a) { assert a.getRank() == 0; assert a.getElementType() == String.class; String str = (String) a.getObject(a.getIndex()); assert str.equals("This is a data test string (pass 0)."); }
void CheckLongValue( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == long.class; assert a instanceof ArrayLong.D0; long vall = ((ArrayLong.D0)a).get(); assert (vall == 0); }
void CheckUInt32Value( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == int.class; assert a instanceof ArrayInt.D0; int vall = ((ArrayInt.D0)a).get(); assert (vall == 0); }
void CheckInt16Value( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == short.class; assert a instanceof ArrayShort.D0; short vals = ((ArrayShort.D0)a).get(); assert (vals == 0); }
void CheckInt32Value( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == int.class; assert a instanceof ArrayInt.D0; int vali = ((ArrayInt.D0)a).get(); assert (vali == 1) : vali; }
void CheckDValue( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == double.class; assert a instanceof ArrayDouble.D0; double vald = ((ArrayDouble.D0)a).get(); assert (vald == 1000.0); }
void CheckInt16Value( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == short.class; assert a instanceof ArrayShort.D0; short vals = ((ArrayShort.D0)a).get(); assert (vals == 0); }
void CheckLongValue( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == long.class; assert a instanceof ArrayLong.D0; long vall = ((ArrayLong.D0)a).get(); assert (vall == 0); }
void CheckFValue( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == float.class; assert a instanceof ArrayFloat.D0; float valf = ((ArrayFloat.D0)a).get(); assert (valf == 0.0); }
void CheckInt32Value( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == int.class; assert a instanceof ArrayInt.D0; int vali = ((ArrayInt.D0)a).get(); assert (vali == 1) : vali; }
void CheckFValue( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == float.class; assert a instanceof ArrayFloat.D0; float valf = ((ArrayFloat.D0)a).get(); assert (valf == 0.0); }
void CheckByteValue( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == byte.class; assert a instanceof ArrayByte.D0; byte valb = ((ArrayByte.D0)a).get(); assert (valb == 0); }
void CheckUint32Value( Array a) { assert a.getRank() == 0; assert a.getSize() == 1; assert a.getElementType() == int.class; assert a instanceof ArrayInt.D0; long vall = ((ArrayInt.D0)a).get(); assert (vall == 0); }
@org.junit.Test public void test2() throws IOException { try (NetcdfFile ncfile = TestH5.open(testDir +"HIRDLS2-AFGL_b027_na.he5")) { Variable dset = ncfile.findVariable("HDFEOS/SWATHS/HIRDLS/Data_Fields/Altitude"); //H5header.setDebugFlags( new ucar.nc2.util.DebugFlagsImpl("H5header/dataBtree")); Array data = dset.read(); assert data.getElementType() == float.class; } }
static public void testVarMatchesData( Variable v, boolean showStatus) throws IOException { Array data = v.read(); assert data.getSize() == v.getSize(); assert data.getElementType() == v.getDataType().getPrimitiveClassType(); assert data.getRank() == v.getRank(); int[] dataShape = data.getShape(); int[] varShape = v.getShape(); for (int i=0; i<data.getRank(); i++) assert dataShape[i] == varShape[i]; if (showStatus) logger.debug( "**** testReadData done on {}", v.getFullName()); } }