Package ucar.ma2
Class ArrayStructure
- java.lang.Object
-
- ucar.ma2.Array
-
- ucar.ma2.ArrayStructure
-
- All Implemented Interfaces:
Iterable<StructureData>
- Direct Known Subclasses:
ArraySequence
,ArraySequenceNested
,ArrayStructureBB
,ArrayStructureComposite
,ArrayStructureMA
,ArrayStructureW
public abstract class ArrayStructure extends Array implements Iterable<StructureData>
Superclass for implementations of Array of StructureData. The general way to access data in an ArrayStructure is to useStructureData getStructureData(Index index).
For 1D arrays (or by calculating your own recnum for nD arrays), you can also use:StructureData getStructureData(int recnum).
Once you have a StructureData object, you can access data in a general way by using:Array StructureData.getArray(Member m)
When dealing with large arrays of Structures, there can be significant overhead in using the generic interfaces. A number of convenience routines may be able to avoid extra Object creation, and so are recommended for efficiency. The following may avoid the overhead of creating the StructureData object:Array getArray(int recno, StructureMembers.Member m)
The following can be convenient for accessing all the data in the ArrayStructure for one member, but its efficiency depends on the implementation:Array getMemberArray(StructureMembers.Member m)
These require that you know the data types of the member data, but they are the most efficent:getScalarXXX(int recnum, Member m) getJavaArrayXXX(int recnum, Member m)
where XXX is Byte, Char, Double, Float, Int, Long, Short, or String. For members that are themselves Structures, the equivilent is:StructureData getScalarStructure(int recnum, Member m) ArrayStructure getArrayStructure(int recnum, Member m)
These will return any compatible type as a double or float, but will have extra overhead when the types dont match:convertScalarXXX(int recnum, Member m) convertJavaArrayXXX(int recnum, Member m)
where XXX is Double or Float- See Also:
Array
,StructureData
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ArrayStructure.ArrayStructureIterator
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
convertScalarDouble(int recnum, StructureMembers.Member m)
Get scalar value as a double, with conversion as needed.float
convertScalarFloat(int recnum, StructureMembers.Member m)
Get scalar value as a float, with conversion as needed.int
convertScalarInt(int recnum, StructureMembers.Member m)
Get scalar value as an int, with conversion as needed.long
convertScalarLong(int recnum, StructureMembers.Member m)
Array
copy()
DO NOT USE, throws UnsupportedOperationExceptionArray
createView(Index index)
Array
extractMemberArray(StructureMembers.Member m)
Extract data for one member, over all structures.StructureMembers.Member
findMember(String memberName)
Find a member by its name.Array
getArray(int recno, StructureMembers.Member m)
Get member data of any type for a specific record as an Array.ArrayObject
getArrayObject(int recnum, StructureMembers.Member m)
Get member data of type ArrayObjectArraySequence
getArraySequence(int recnum, StructureMembers.Member m)
Get member data of type ArraySequenceArrayStructure
getArrayStructure(int recnum, StructureMembers.Member m)
Get member data of type array of Structure.boolean
getBoolean(int index)
boolean
getBoolean(Index i)
DO NOT USE, throw ForbiddenConversionExceptionbyte
getByte(int index)
byte
getByte(Index i)
DO NOT USE, throw ForbiddenConversionExceptionchar
getChar(int index)
char
getChar(Index i)
DO NOT USE, throw ForbiddenConversionExceptiondouble
getDouble(int index)
double
getDouble(Index i)
DO NOT USE, throw ForbiddenConversionExceptionClass
getElementType()
Get the element class type of this Arrayfloat
getFloat(int index)
float
getFloat(Index i)
DO NOT USE, throw ForbiddenConversionExceptionint
getInt(int index)
int
getInt(Index i)
DO NOT USE, throw ForbiddenConversionExceptionbyte[]
getJavaArrayByte(int recnum, StructureMembers.Member m)
Get member data of type byte as a 1D array.char[]
getJavaArrayChar(int recnum, StructureMembers.Member m)
Get member data of type char as a 1D array.double[]
getJavaArrayDouble(int recnum, StructureMembers.Member m)
Get member data of type double as a 1D array.float[]
getJavaArrayFloat(int recnum, StructureMembers.Member m)
Get member data of type float as a 1D array.int[]
getJavaArrayInt(int recnum, StructureMembers.Member m)
Get member data of type int as a 1D array.long[]
getJavaArrayLong(int recnum, StructureMembers.Member m)
Get member data of type long as a 1D array.short[]
getJavaArrayShort(int recnum, StructureMembers.Member m)
Get member data of type short as a 1D array.String[]
getJavaArrayString(int recnum, StructureMembers.Member m)
Get member data of type String as a 1D array.long
getLong(int index)
long
getLong(Index i)
DO NOT USE, throw ForbiddenConversionExceptionList<StructureMembers.Member>
getMembers()
Get a list of structure members.Object
getObject(int index)
Get the index-th StructureData of this ArrayStructure.Object
getObject(Index i)
Get the index-th StructureData of this ArrayStructure.byte
getScalarByte(int recnum, StructureMembers.Member m)
Get scalar member data of type byte.char
getScalarChar(int recnum, StructureMembers.Member m)
Get scalar member data of type char.double
getScalarDouble(int recnum, StructureMembers.Member m)
Get scalar member data of type double.float
getScalarFloat(int recnum, StructureMembers.Member m)
Get scalar member data of type float.int
getScalarInt(int recnum, StructureMembers.Member m)
Get scalar member data of type int.long
getScalarLong(int recnum, StructureMembers.Member m)
Get scalar member data of type long.Object
getScalarObject(int recno, StructureMembers.Member m)
Get member data array of any type as an Object, eg, Float, Double, String, StructureData etc.short
getScalarShort(int recnum, StructureMembers.Member m)
Get scalar member data of type short.String
getScalarString(int recnum, StructureMembers.Member m)
Get member data of type String or char.StructureData
getScalarStructure(int recnum, StructureMembers.Member m)
Get member data of type Structure.short
getShort(int index)
short
getShort(Index i)
DO NOT USE, throw ForbiddenConversionExceptionlong
getSizeBytes()
Get the total number of bytes in the array.Object
getStorage()
Get underlying primitive array storage.StructureData
getStructureData(int index)
Get the index-th StructureData of this ArrayStructure.StructureData
getStructureData(Index i)
Get the index-th StructureData of this ArrayStructure.StructureDataIterator
getStructureDataIterator()
List<String>
getStructureMemberNames()
Get a list structure member names.StructureMembers
getStructureMembers()
Get the StructureMembers object.int
getStructureSize()
Get the size of each StructureData object in bytes.Iterator<StructureData>
iterator()
Array
sectionNoReduce(List<Range> ranges)
Create a new Array as a subsection of this Array, without rank reduction.void
setBoolean(int index, boolean value)
void
setBoolean(Index i, boolean value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
setByte(int index, byte value)
void
setByte(Index i, byte value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
setChar(int index, char value)
void
setChar(Index i, char value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
setDouble(int index, double value)
void
setDouble(Index i, double value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
setFloat(int index, float value)
void
setFloat(Index i, float value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
setInt(int index, int value)
void
setInt(Index i, int value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
setLong(int index, long value)
void
setLong(Index i, long value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
setMemberArray(StructureMembers.Member m, Array memberArray)
Set data for one member, over all structures.void
setObject(int index, Object value)
Set the index-th StructureData of this ArrayStructure.void
setObject(Index i, Object value)
Set one of the StructureData of this ArrayStructure.void
setShort(int index, short value)
void
setShort(Index i, short value)
DO NOT USE, throw ForbiddenConversionExceptionvoid
showInternal(Formatter f, Indent indent)
void
showInternalMembers(Formatter f, Indent indent)
-
Methods inherited from class ucar.ma2.Array
arraycopy, copyTo1DJavaArray, copyToNDJavaArray, factory, factory, factory, factory, factoryConstant, factoryCopy, flip, get1DJavaArray, getDataAsByteBuffer, getDataAsByteBuffer, getDataAsByteBuffer, getDataType, getIndex, getIndexIterator, getRangeIterator, getRank, getShape, getSize, hasNext, isConstant, isUnsigned, isVlen, makeArray, makeArray, makeArray, makeArrayRankPlusOne, makeFromJavaArray, makeFromJavaArray, makeObjectArray, makeVlenArray, next, nextBoolean, nextByte, nextChar, nextDouble, nextFloat, nextInt, nextLong, nextShort, permute, reduce, reduce, resetLocalIterator, reshape, reshapeNoCopy, section, section, section, sectionNoReduce, shapeToString, slice, toString, transpose
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
getElementType
public Class getElementType()
Description copied from class:Array
Get the element class type of this Array- Specified by:
getElementType
in classArray
- Returns:
- the class of the element
-
getStructureMembers
public StructureMembers getStructureMembers()
Get the StructureMembers object.- Returns:
- the StructureMembers object.
-
getMembers
public List<StructureMembers.Member> getMembers()
Get a list of structure members.- Returns:
- the structure members.
-
getStructureMemberNames
public List<String> getStructureMemberNames()
Get a list structure member names.- Returns:
- the structure members.
-
findMember
public StructureMembers.Member findMember(String memberName)
Find a member by its name.- Parameters:
memberName
- find member with this name- Returns:
- StructureMembers.Member matching the name, or null if not found
-
getSizeBytes
public long getSizeBytes()
Description copied from class:Array
Get the total number of bytes in the array.- Overrides:
getSizeBytes
in classArray
- Returns:
- total number of bytes in the array
-
setObject
public void setObject(Index i, Object value)
Set one of the StructureData of this ArrayStructure.
-
getObject
public Object getObject(int index)
Get the index-th StructureData of this ArrayStructure.
-
setObject
public void setObject(int index, Object value)
Set the index-th StructureData of this ArrayStructure.
-
getStructureData
public StructureData getStructureData(Index i)
Get the index-th StructureData of this ArrayStructure.- Parameters:
i
- which one to get, specified by an Index.- Returns:
- object of type StructureData.
-
getStructureData
public StructureData getStructureData(int index)
Get the index-th StructureData of this ArrayStructure.- Parameters:
index
- which one to get, specified by an integer.- Returns:
- object of type StructureData.
-
getStorage
public Object getStorage()
Description copied from class:Array
Get underlying primitive array storage. Exposed for efficiency, use at your own risk.- Specified by:
getStorage
in classArray
- Returns:
- underlying primitive array storage
-
getStructureSize
public int getStructureSize()
Get the size of each StructureData object in bytes.- Returns:
- the size of each StructureData object in bytes.
-
iterator
public Iterator<StructureData> iterator()
- Specified by:
iterator
in interfaceIterable<StructureData>
-
getStructureDataIterator
public StructureDataIterator getStructureDataIterator()
-
getArray
public Array getArray(int recno, StructureMembers.Member m)
Get member data of any type for a specific record as an Array. This may avoid the overhead of creating the StructureData object, but is equivilent to getStructure(recno).getArray( Member m).- Parameters:
recno
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member.- Returns:
- Array values.
-
setMemberArray
public void setMemberArray(StructureMembers.Member m, Array memberArray)
Set data for one member, over all structures. This is used by VariableDS to do scale/offset.- Parameters:
m
- set data for this StructureMembers.Member.memberArray
- Array values.
-
extractMemberArray
public Array extractMemberArray(StructureMembers.Member m) throws IOException
Extract data for one member, over all structures.- Parameters:
m
- get data from this StructureMembers.Member.- Returns:
- Array values.
- Throws:
IOException
- on read error (only happens for Sequences, otherwise data is already read)
-
getScalarObject
public Object getScalarObject(int recno, StructureMembers.Member m)
Get member data array of any type as an Object, eg, Float, Double, String, StructureData etc.- Parameters:
recno
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member.- Returns:
- value as Float, Double, etc..
-
convertScalarFloat
public float convertScalarFloat(int recnum, StructureMembers.Member m)
Get scalar value as a float, with conversion as needed. Underlying type must be convertible to float.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- member Variable.- Returns:
- scalar float value
- Throws:
ForbiddenConversionException
- if not convertible to float.
-
convertScalarDouble
public double convertScalarDouble(int recnum, StructureMembers.Member m)
Get scalar value as a double, with conversion as needed. Underlying type must be convertible to double.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- member Variable.- Returns:
- scalar double value
- Throws:
ForbiddenConversionException
- if not convertible to double.
-
convertScalarInt
public int convertScalarInt(int recnum, StructureMembers.Member m)
Get scalar value as an int, with conversion as needed. Underlying type must be convertible to int.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- member Variable.- Returns:
- scalar double value
- Throws:
ForbiddenConversionException
- if not convertible to double.
-
convertScalarLong
public long convertScalarLong(int recnum, StructureMembers.Member m)
-
getScalarDouble
public double getScalarDouble(int recnum, StructureMembers.Member m)
Get scalar member data of type double.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type double.- Returns:
- scalar double value
-
getJavaArrayDouble
public double[] getJavaArrayDouble(int recnum, StructureMembers.Member m)
Get member data of type double as a 1D array. The member data may be any rank.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type double.- Returns:
- double[]
-
getScalarFloat
public float getScalarFloat(int recnum, StructureMembers.Member m)
Get scalar member data of type float.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type float.- Returns:
- scalar double value
-
getJavaArrayFloat
public float[] getJavaArrayFloat(int recnum, StructureMembers.Member m)
Get member data of type float as a 1D array.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type float.- Returns:
- float[]
-
getScalarByte
public byte getScalarByte(int recnum, StructureMembers.Member m)
Get scalar member data of type byte.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type byte.- Returns:
- scalar double value
-
getJavaArrayByte
public byte[] getJavaArrayByte(int recnum, StructureMembers.Member m)
Get member data of type byte as a 1D array.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type byte.- Returns:
- byte[]
-
getScalarShort
public short getScalarShort(int recnum, StructureMembers.Member m)
Get scalar member data of type short.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type short.- Returns:
- scalar double value
-
getJavaArrayShort
public short[] getJavaArrayShort(int recnum, StructureMembers.Member m)
Get member data of type short as a 1D array.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type float.- Returns:
- short[]
-
getScalarInt
public int getScalarInt(int recnum, StructureMembers.Member m)
Get scalar member data of type int.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type int.- Returns:
- scalar double value
-
getJavaArrayInt
public int[] getJavaArrayInt(int recnum, StructureMembers.Member m)
Get member data of type int as a 1D array.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type int.- Returns:
- int[]
-
getScalarLong
public long getScalarLong(int recnum, StructureMembers.Member m)
Get scalar member data of type long.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type long.- Returns:
- scalar double value
-
getJavaArrayLong
public long[] getJavaArrayLong(int recnum, StructureMembers.Member m)
Get member data of type long as a 1D array.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type long.- Returns:
- long[]
-
getScalarChar
public char getScalarChar(int recnum, StructureMembers.Member m)
Get scalar member data of type char.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type char.- Returns:
- scalar double value
-
getJavaArrayChar
public char[] getJavaArrayChar(int recnum, StructureMembers.Member m)
Get member data of type char as a 1D array.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type char.- Returns:
- char[]
-
getScalarString
public String getScalarString(int recnum, StructureMembers.Member m)
Get member data of type String or char.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type String or char.- Returns:
- scalar String value
-
getJavaArrayString
public String[] getJavaArrayString(int recnum, StructureMembers.Member m)
Get member data of type String as a 1D array.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type String.- Returns:
- String[]
-
getScalarStructure
public StructureData getScalarStructure(int recnum, StructureMembers.Member m)
Get member data of type Structure.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type Structure.- Returns:
- scalar StructureData
-
getArrayStructure
public ArrayStructure getArrayStructure(int recnum, StructureMembers.Member m)
Get member data of type array of Structure.- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type Structure.- Returns:
- nested ArrayStructure.
-
getArraySequence
public ArraySequence getArraySequence(int recnum, StructureMembers.Member m)
Get member data of type ArraySequence- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type Structure.- Returns:
- nested ArrayStructure.
-
getArrayObject
public ArrayObject getArrayObject(int recnum, StructureMembers.Member m)
Get member data of type ArrayObject- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type Structure.- Returns:
- ArrayObject.
-
sectionNoReduce
public Array sectionNoReduce(List<Range> ranges)
Description copied from class:Array
Create a new Array as a subsection of this Array, without rank reduction. No data is moved, so the new Array references the same backing store as the original. Vlen is transferred over unchanged.- Overrides:
sectionNoReduce
in classArray
- Parameters:
ranges
- list of Ranges that specify the array subset. Must be same rank as original Array. A particular Range: 1) may be a subset, or 2) may be null, meaning use entire Range.- Returns:
- the new Array
-
copy
public Array copy()
DO NOT USE, throws UnsupportedOperationException
-
getDouble
public double getDouble(Index i)
DO NOT USE, throw ForbiddenConversionException
-
setDouble
public void setDouble(Index i, double value)
DO NOT USE, throw ForbiddenConversionException
-
getFloat
public float getFloat(Index i)
DO NOT USE, throw ForbiddenConversionException
-
setFloat
public void setFloat(Index i, float value)
DO NOT USE, throw ForbiddenConversionException
-
getLong
public long getLong(Index i)
DO NOT USE, throw ForbiddenConversionException
-
setLong
public void setLong(Index i, long value)
DO NOT USE, throw ForbiddenConversionException
-
getInt
public int getInt(Index i)
DO NOT USE, throw ForbiddenConversionException
-
setInt
public void setInt(Index i, int value)
DO NOT USE, throw ForbiddenConversionException
-
getShort
public short getShort(Index i)
DO NOT USE, throw ForbiddenConversionException
-
setShort
public void setShort(Index i, short value)
DO NOT USE, throw ForbiddenConversionException
-
getByte
public byte getByte(Index i)
DO NOT USE, throw ForbiddenConversionException
-
setByte
public void setByte(Index i, byte value)
DO NOT USE, throw ForbiddenConversionException
-
getBoolean
public boolean getBoolean(Index i)
DO NOT USE, throw ForbiddenConversionException- Specified by:
getBoolean
in classArray
- Parameters:
i
- Index with current element set- Returns:
- value at
index
cast to boolean if necessary.
-
setBoolean
public void setBoolean(Index i, boolean value)
DO NOT USE, throw ForbiddenConversionException- Specified by:
setBoolean
in classArray
- Parameters:
i
- Index with current element setvalue
- the new value; cast to underlying data type if necessary.
-
getChar
public char getChar(Index i)
DO NOT USE, throw ForbiddenConversionException
-
setChar
public void setChar(Index i, char value)
DO NOT USE, throw ForbiddenConversionException
-
getBoolean
public boolean getBoolean(int index)
- Specified by:
getBoolean
in classArray
-
setBoolean
public void setBoolean(int index, boolean value)
- Specified by:
setBoolean
in classArray
-
-