Package ucar.ma2

Class 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 use

      StructureData 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
    • Constructor Detail

      • ArrayStructure

        protected ArrayStructure​(StructureMembers members,
                                 int[] shape)
        Create a new Array of type StructureData and the given members and shape. dimensions.length determines the rank of the new Array.
        Parameters:
        members - a description of the structure members
        shape - the shape of the Array.
    • Method Detail

      • getElementType

        public Class getElementType()
        Description copied from class: Array
        Get the element class type of this Array
        Specified by:
        getElementType in class Array
        Returns:
        the class of the element
      • getStructureMembers

        public StructureMembers getStructureMembers()
        Get the StructureMembers object.
        Returns:
        the StructureMembers object.
      • 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 class Array
        Returns:
        total number of bytes in the array
      • getObject

        public Object getObject​(Index i)
        Get the index-th StructureData of this ArrayStructure.
        Specified by:
        getObject in class Array
        Parameters:
        i - which one to get, specified by an Index.
        Returns:
        object of type StructureData.
      • setObject

        public void setObject​(Index i,
                              Object value)
        Set one of the StructureData of this ArrayStructure.
        Specified by:
        setObject in class Array
        Parameters:
        i - which one to set, specified by an Index.
        value - must be type StructureData.
      • getObject

        public Object getObject​(int index)
        Get the index-th StructureData of this ArrayStructure.
        Specified by:
        getObject in class Array
        Parameters:
        index - which one to get, specified by an integer.
        Returns:
        object of type StructureData.
      • setObject

        public void setObject​(int index,
                              Object value)
        Set the index-th StructureData of this ArrayStructure.
        Specified by:
        setObject in class Array
        Parameters:
        index - which one to set.
        value - must be type StructureData.
      • 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 class Array
        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.
      • 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.
      • 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.
      • showInternalMembers

        public void showInternalMembers​(Formatter f,
                                        Indent indent)
      • createView

        public Array createView​(Index index)
        Description copied from class: Array
        create new Array with given Index and the same backing store
        Specified by:
        createView in class Array
        Parameters:
        index - use this Index
        Returns:
        a view of the Array using the given Index
      • 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 class Array
        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
        Overrides:
        copy in class Array
        Returns:
        the new Array
      • getDouble

        public double getDouble​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getDouble in class Array
        Parameters:
        i - Index with current element set
        Returns:
        value at index cast to double if necessary.
      • setDouble

        public void setDouble​(Index i,
                              double value)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        setDouble in class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getFloat

        public float getFloat​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getFloat in class Array
        Parameters:
        i - Index with current element set
        Returns:
        value at index cast to float if necessary.
      • setFloat

        public void setFloat​(Index i,
                             float value)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        setFloat in class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getLong

        public long getLong​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getLong in class Array
        Parameters:
        i - Index with current element set
        Returns:
        value at index cast to long if necessary.
      • setLong

        public void setLong​(Index i,
                            long value)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        setLong in class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getInt

        public int getInt​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getInt in class Array
        Parameters:
        i - Index with current element set
        Returns:
        value at index cast to int if necessary.
      • setInt

        public void setInt​(Index i,
                           int value)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        setInt in class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getShort

        public short getShort​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getShort in class Array
        Parameters:
        i - Index with current element set
        Returns:
        value at index cast to short if necessary.
      • setShort

        public void setShort​(Index i,
                             short value)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        setShort in class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getByte

        public byte getByte​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getByte in class Array
        Parameters:
        i - Index with current element set
        Returns:
        value at index cast to float if necessary.
      • setByte

        public void setByte​(Index i,
                            byte value)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        setByte in class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getBoolean

        public boolean getBoolean​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getBoolean in class Array
        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 class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getChar

        public char getChar​(Index i)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        getChar in class Array
        Parameters:
        i - Index with current element set
        Returns:
        value at index cast to char if necessary.
      • setChar

        public void setChar​(Index i,
                            char value)
        DO NOT USE, throw ForbiddenConversionException
        Specified by:
        setChar in class Array
        Parameters:
        i - Index with current element set
        value - the new value; cast to underlying data type if necessary.
      • getDouble

        public double getDouble​(int index)
        Specified by:
        getDouble in class Array
      • setDouble

        public void setDouble​(int index,
                              double value)
        Specified by:
        setDouble in class Array
      • getFloat

        public float getFloat​(int index)
        Specified by:
        getFloat in class Array
      • setFloat

        public void setFloat​(int index,
                             float value)
        Specified by:
        setFloat in class Array
      • getLong

        public long getLong​(int index)
        Specified by:
        getLong in class Array
      • setLong

        public void setLong​(int index,
                            long value)
        Specified by:
        setLong in class Array
      • getInt

        public int getInt​(int index)
        Specified by:
        getInt in class Array
      • setInt

        public void setInt​(int index,
                           int value)
        Specified by:
        setInt in class Array
      • getShort

        public short getShort​(int index)
        Specified by:
        getShort in class Array
      • setShort

        public void setShort​(int index,
                             short value)
        Specified by:
        setShort in class Array
      • getByte

        public byte getByte​(int index)
        Specified by:
        getByte in class Array
      • setByte

        public void setByte​(int index,
                            byte value)
        Specified by:
        setByte in class Array
      • getChar

        public char getChar​(int index)
        Specified by:
        getChar in class Array
      • setChar

        public void setChar​(int index,
                            char value)
        Specified by:
        setChar in class Array
      • getBoolean

        public boolean getBoolean​(int index)
        Specified by:
        getBoolean in class Array
      • setBoolean

        public void setBoolean​(int index,
                               boolean value)
        Specified by:
        setBoolean in class Array