Package ucar.ma2

Class ArrayStructureBB

  • All Implemented Interfaces:
    Iterable<StructureData>
    Direct Known Subclasses:
    ArrayStructureBBpos, ArrayStructureBBsection

    public class ArrayStructureBB
    extends ArrayStructure
    Concrete implementation of ArrayStructure, data storage is in a ByteBuffer, which is converted to member data on the fly. In order to use this, the records must have the same size, and the member offset must be the same for each record. Use StructureMembers.setStructureSize() to set the record size. Use StructureMembers.Member.setDataParam() to set the offset of the member from the start of each record. The member data will then be located in the BB at offset = recnum * getStructureSize() + member.getDataParam(). This defers object creation for efficiency. Use getArray() and getScalar() data accessors if possible.
     Structure pdata = (Structure) ncfile.findVariable(name);
     StructureMembers members = pdata.makeStructureMembers();
     members.findMember("value").setDataParam(0); // these are the offsets into the record
     members.findMember("x_start").setDataParam(2);
     members.findMember("y_start").setDataParam(4);
     members.findMember("direction").setDataParam(6);
     members.findMember("speed").setDataParam(8);
     int recsize = pos[1] - pos[0]; // each record must be all the same size
     members.setStructureSize(recsize);
     ArrayStructureBB asbb = new ArrayStructureBB(members, new int[] {size}, bos, pos[0]);
     
    For String members, you must store the Strings in the stringHeap. An integer index into the heap is used in the ByteBuffer.
    See Also:
    Array
    • Field Detail

      • bb_offset

        protected int bb_offset
    • Constructor Detail

      • ArrayStructureBB

        public ArrayStructureBB​(StructureMembers members,
                                int[] shape)
        Create a new Array of type StructureData and the given members and shape. Generally, you extract the byte array and fill it:
         byte[] result = (byte[]) structureArray.getStorage();
         
        Parameters:
        members - a description of the structure members
        shape - the shape of the Array.
      • ArrayStructureBB

        public ArrayStructureBB​(StructureMembers members,
                                int[] shape,
                                ByteBuffer bbuffer,
                                int offset)
        Construct an ArrayStructureBB with the given ByteBuffer.
        Parameters:
        members - the list of structure members.
        shape - the shape of the structure array
        bbuffer - the data is stored in this ByteBuffer. bbuffer.order must already be set.
        offset - offset from the start of the ByteBufffer to the first record.
    • Method Detail

      • setOffsets

        public static int setOffsets​(StructureMembers members)
        Set the offsets, based on m.getSizeBytes(). Also sets members.setStructureSize().
        Parameters:
        members - set offsets for these members
        Returns:
        the total size
      • getByteBuffer

        public ByteBuffer getByteBuffer()
        Return backing storage as a ByteBuffer
        Returns:
        backing storage as a ByteBuffer
      • getScalarDouble

        public double getScalarDouble​(int recnum,
                                      StructureMembers.Member m)
        Description copied from class: ArrayStructure
        Get scalar member data of type double.
        Overrides:
        getScalarDouble in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type double as a 1D array. The member data may be any rank.
        Overrides:
        getJavaArrayDouble in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get scalar member data of type float.
        Overrides:
        getScalarFloat in class ArrayStructure
        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
      • getArray

        public Array getArray​(int recnum,
                              StructureMembers.Member m)
        Description copied from class: ArrayStructure
        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).
        Overrides:
        getArray in class ArrayStructure
        Parameters:
        recnum - 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.
      • getJavaArrayFloat

        public float[] getJavaArrayFloat​(int recnum,
                                         StructureMembers.Member m)
        Description copied from class: ArrayStructure
        Get member data of type float as a 1D array.
        Overrides:
        getJavaArrayFloat in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get scalar member data of type byte.
        Overrides:
        getScalarByte in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type byte as a 1D array.
        Overrides:
        getJavaArrayByte in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get scalar member data of type short.
        Overrides:
        getScalarShort in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type short as a 1D array.
        Overrides:
        getJavaArrayShort in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get scalar member data of type int.
        Overrides:
        getScalarInt in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type int as a 1D array.
        Overrides:
        getJavaArrayInt in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get scalar member data of type long.
        Overrides:
        getScalarLong in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type long as a 1D array.
        Overrides:
        getJavaArrayLong in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get scalar member data of type char.
        Overrides:
        getScalarChar in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type char as a 1D array.
        Overrides:
        getJavaArrayChar in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type String or char.
        Overrides:
        getScalarString in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type String as a 1D array.
        Overrides:
        getJavaArrayString in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type Structure.
        Overrides:
        getScalarStructure in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type array of Structure.
        Overrides:
        getArrayStructure in class ArrayStructure
        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)
        Description copied from class: ArrayStructure
        Get member data of type ArraySequence
        Overrides:
        getArraySequence in class ArrayStructure
        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.
      • addObjectToHeap

        public int addObjectToHeap​(Object s)
      • getHeap

        public List<Object> getHeap()
        DO NOT MODIFY
        Returns:
        heap