cdm/src/main/java/ucar/nc2/iosp/hdf5/H5iosp.java
void convertHeap(ArrayStructureBB asbb, int pos, StructureMembers sm) throws java.io.IOException, InvalidRangeException {
    ByteBuffer bb = asbb.getByteBuffer();
    for (StructureMembers.Member m : sm.getMembers()) {
      if (m.getDataType() == DataType.STRING) {
        m.setDataObject(ByteOrder.nativeOrder()); // the index is always written in "native order"
        int size = m.getSize();
        int destPos = pos + m.getDataParam();
        String[] result = new String[size];
        for (int i = 0; i < size; i++)
          result[i] = headerParser.readHeapString(bb, destPos + i * 16); // 16 byte "heap ids" are in the ByteBuffer

        int index = asbb.addObjectToHeap(result);
        bb.order(ByteOrder.nativeOrder()); // the string index is always written in "native order"
        bb.putInt(destPos, index); // overwrite with the index into the StringHeap

      } else if (m.isVariableLength()) {
        int startPos = pos + m.getDataParam();
        bb.order(ByteOrder.LITTLE_ENDIAN);

        ByteOrder bo = (ByteOrder) m.getDataObject();
        int endian = bo.equals(ByteOrder.LITTLE_ENDIAN) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;
        // Compute rank and size upto the first (and ideally last) VLEN
        int[] fieldshape = m.getShape();
        int prefixrank = 0;
        int size = 1;
        for(;prefixrank < fieldshape.length;prefixrank++) {
            if(fieldshape[prefixrank] < 0) break;
            size *= fieldshape[prefixrank];
        }
        assert size == m.getSize() : "Internal error: field size mismatch";
        Array[] fieldarray = new Array[size]; // hold all the vlen instance data
        // destPos will point to each vlen instance in turn
        // assuming we have 'size' such instances in a row.
        int destPos = startPos;
        for(int i = 0;i < size;i++) {
          // vlenarray extracts the i'th vlen contents (struct not supported).
          Array vlenArray = headerParser.readHeapVlen(bb, destPos, m.getDataType(), endian);
          fieldarray[i] = vlenArray;
          destPos += VLEN_T_SIZE;  // Apparentlly no way to compute VLEN_T_SIZE on the fly
        }
        Array result;
        if(prefixrank == 0) // if scalar, return just the singleton vlen array
          result = fieldarray[0];
        else {
          int[] newshape = new int[prefixrank];
          System.arraycopy(fieldshape, 0, newshape, 0, prefixrank);
          // result = Array.makeObjectArray(m.getDataType(), fieldarray[0].getClass(), newshape, fieldarray);
          result = Array.makeVlenArray(newshape, fieldarray);
        }

        /* if (prefixrank == 1)
          result = Array.makeObjectArray(m.getDataType(), fieldarray[0].getClass(), new int[]{size}, fieldarray);
        else {
          // Otherwise create and fill in an n-dimensional Array Of Arrays
          int[] newshape = new int[prefixrank];
          System.arraycopy(fieldshape, 0, newshape, 0, prefixrank);
          Array ndimarray = Array.makeObjectArray(m.getDataType(), Array.class, newshape, null);
          // Transfer the elements of data into the n-dim arrays
          IndexIterator iter = ndimarray.getIndexIterator();
          for(int i = 0;iter.hasNext();i++) {
              iter.setObjectNext(fieldarray[i]);
          }
          result = ndimarray;
        } */

        //Array vlenArray = headerParser.readHeapVlen(bb, destPos, m.getDataType(), endian);

        int index = asbb.addObjectToHeap(result);
        bb.order(ByteOrder.nativeOrder());
        bb.putInt(startPos, index); // overwrite with the index into the Heap
      }
    }
  }
void convertHeap(ArrayStructureBB asbb, int pos, StructureMembers sm) throws java.io.IOException, InvalidRangeException {
    ByteBuffer bb = asbb.getByteBuffer();
    for (StructureMembers.Member m : sm.getMembers()) {
      if (m.getDataType() == DataType.STRING) {
        m.setDataObject(ByteOrder.nativeOrder()); // the index is always written in "native order"
        int size = m.getSize();
        int destPos = pos + m.getDataParam();
        String[] result = new String[size];
        for (int i = 0; i < size; i++)
          result[i] = headerParser.readHeapString(bb, destPos + i * 16); // 16 byte "heap ids" are in the ByteBuffer

        int index = asbb.addObjectToHeap(result);
        bb.order(ByteOrder.nativeOrder()); // the string index is always written in "native order"
        bb.putInt(destPos, index); // overwrite with the index into the StringHeap

      } else if (m.isVariableLength()) {
        int startPos = pos + m.getDataParam();
        bb.order(ByteOrder.LITTLE_ENDIAN);

        ByteOrder bo = (ByteOrder) m.getDataObject();
        int endian = bo.equals(ByteOrder.LITTLE_ENDIAN) ? RandomAccessFile.LITTLE_ENDIAN : RandomAccessFile.BIG_ENDIAN;
        // Compute rank and size upto the first (and ideally last) VLEN
        int[] fieldshape = m.getShape();
        int prefixrank = 0;
        int size = 1;
        for(;prefixrank < fieldshape.length;prefixrank++) {
            if(fieldshape[prefixrank] < 0) break;
            size *= fieldshape[prefixrank];
        }
        assert size == m.getSize() : "Internal error: field size mismatch";
        Array[] fieldarray = new Array[size]; // hold all the vlen instance data
        // destPos will point to each vlen instance in turn
        // assuming we have 'size' such instances in a row.
        int destPos = startPos;
        for(int i = 0;i < size;i++) {
          // vlenarray extracts the i'th vlen contents (struct not supported).
          Array vlenArray = headerParser.readHeapVlen(bb, destPos, m.getDataType(), endian);
          fieldarray[i] = vlenArray;
          destPos += VLEN_T_SIZE;  // Apparentlly no way to compute VLEN_T_SIZE on the fly
        }
        Array result;
        if(prefixrank == 0) // if scalar, return just the singleton vlen array
          result = fieldarray[0];
        else {
          int[] newshape = new int[prefixrank];
          System.arraycopy(fieldshape, 0, newshape, 0, prefixrank);
          // result = Array.makeObjectArray(m.getDataType(), fieldarray[0].getClass(), newshape, fieldarray);
          result = Array.makeVlenArray(newshape, fieldarray);
        }

        /* if (prefixrank == 1)
          result = Array.makeObjectArray(m.getDataType(), fieldarray[0].getClass(), new int[]{size}, fieldarray);
        else {
          // Otherwise create and fill in an n-dimensional Array Of Arrays
          int[] newshape = new int[prefixrank];
          System.arraycopy(fieldshape, 0, newshape, 0, prefixrank);
          Array ndimarray = Array.makeObjectArray(m.getDataType(), Array.class, newshape, null);
          // Transfer the elements of data into the n-dim arrays
          IndexIterator iter = ndimarray.getIndexIterator();
          for(int i = 0;iter.hasNext();i++) {
              iter.setObjectNext(fieldarray[i]);
          }
          result = ndimarray;
        } */

        //Array vlenArray = headerParser.readHeapVlen(bb, destPos, m.getDataType(), endian);

        int index = asbb.addObjectToHeap(result);
        bb.order(ByteOrder.nativeOrder());
        bb.putInt(startPos, index); // overwrite with the index into the Heap
      }
    }
  }
void convertHeap ( ArrayStructureBB asbb , int pos , StructureMembers sm ) throws java . io . IOException , InvalidRangeException { ByteBuffer bb = asbb . getByteBuffer ( ) ; for ( StructureMembers . Member m : sm . getMembers ( ) ) { if ( m . getDataType ( ) == DataType . STRING ) { m . setDataObject ( ByteOrder . nativeOrder ( ) ) ; // the index is always written in "native order" int size = m . getSize ( ) ; int destPos = pos + m . getDataParam ( ) ; String [ ] result = new String [ size ] ; for ( int i = 0 ; i < size ; i ++ ) result [ i ] = headerParser . readHeapString ( , destPos + i * 16 ) ; // 16 byte "heap ids" are in the ByteBuffer int index = asbb . addObjectToHeap ( result ) ; bb . order ( ByteOrder . nativeOrder ( ) ) ; // the string index is always written in "native order" bb . putInt ( destPos , index ) ; // overwrite with the index into the StringHeap } else if ( m . isVariableLength ( ) ) { int startPos = pos + m . getDataParam ( ) ; bb . order ( ByteOrder . LITTLE_ENDIAN ) ; ByteOrder bo = ( ByteOrder ) m . getDataObject ( ) ; int endian = bo . equals ( ByteOrder . LITTLE_ENDIAN ) ? RandomAccessFile . LITTLE_ENDIAN : RandomAccessFile . BIG_ENDIAN ; // Compute rank and size upto the first (and ideally last) VLEN int [ ] fieldshape = m . getShape ( ) ; int prefixrank = 0 ; int size = 1 ; for ( ; prefixrank < fieldshape . length ; prefixrank ++ ) { if ( fieldshape [ prefixrank ] < 0 ) break ; size *= fieldshape [ prefixrank ] ; } assert size == m . getSize ( ) : "Internal error: field size mismatch" ; Array [ ] fieldarray = new Array [ size ] ; // hold all the vlen instance data // destPos will point to each vlen instance in turn // assuming we have 'size' such instances in a row. int destPos = startPos ; for ( int i = 0 ; i < size ; i ++ ) { // vlenarray extracts the i'th vlen contents (struct not supported). Array vlenArray = headerParser . readHeapVlen ( bb , destPos , m . getDataType ( ) , endian ) ; fieldarray [ i ] = vlenArray ; destPos += VLEN_T_SIZE ; // Apparentlly no way to compute VLEN_T_SIZE on the fly } Array result ; if ( prefixrank == 0 ) // if scalar, return just the singleton vlen array result = fieldarray [ 0 ] ; else { int [ ] newshape = new int [ prefixrank ] ; System . arraycopy ( fieldshape , 0 , newshape , 0 , prefixrank ) ; // result = Array.makeObjectArray(m.getDataType(), fieldarray[0].getClass(), newshape, fieldarray); result = Array . makeVlenArray ( newshape , fieldarray ) ; } /* if (prefixrank == 1)
          result = Array.makeObjectArray(m.getDataType(), fieldarray[0].getClass(), new int[]{size}, fieldarray);
        else {
          // Otherwise create and fill in an n-dimensional Array Of Arrays
          int[] newshape = new int[prefixrank];
          System.arraycopy(fieldshape, 0, newshape, 0, prefixrank);
          Array ndimarray = Array.makeObjectArray(m.getDataType(), Array.class, newshape, null);
          // Transfer the elements of data into the n-dim arrays
          IndexIterator iter = ndimarray.getIndexIterator();
          for(int i = 0;iter.hasNext();i++) {
              iter.setObjectNext(fieldarray[i]);
          }
          result = ndimarray;
        } */ //Array vlenArray = headerParser.readHeapVlen(bb, destPos, m.getDataType(), endian); int index = asbb . addObjectToHeap ( result ) ; bb . order ( ByteOrder . nativeOrder ( ) ) ; bb . putInt ( startPos , index ) ; // overwrite with the index into the Heap } } }
/*
public static int setOffsets(StructureMembers members) {
int offset = 0;
for (StructureMembers.Member m : members.getMembers()) {
m.setDataParam(offset);
offset += m.getSizeBytes();

set inner offsets (starts again at 0)
if (m.getStructureMembers() != null)
setOffsets(m.getStructureMembers());
}
members.setStructureSize(offset);
return offset;
}
/ * public static int setOffsets ( StructureMembers members ) { int offset = 0 ; for ( StructureMembers . Member m : members . getMembers () ) { m . setDataParam ( offset ) ; offset + = m . getSizeBytes () ;