cdm/src/main/java/ucar/nc2/iosp/IospHelper.java
static public Object readData(LayoutBB layout, DataType dataType, Object arr) throws java.io.IOException {
    if (showLayoutTypes) System.out.println("***BB LayoutType=" + layout.getClass().getName());

    if (dataType.getPrimitiveClassType() == byte.class || (dataType == DataType.CHAR)) {
      byte[] pa = (byte[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        ByteBuffer bb = chunk.getByteBuffer();
        bb.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = bb.get();
      }
      //return (dataType == DataType.CHAR) ? convertByteToChar(pa) : pa;
      if (dataType == DataType.CHAR) return convertByteToChar(pa);
      else return pa;

    } else if (dataType.getPrimitiveClassType() == short.class) {
      short[] pa = (short[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        ShortBuffer buff = chunk.getShortBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == int.class) {
      int[] pa = (int[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        IntBuffer buff = chunk.getIntBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType == DataType.FLOAT) {
      float[] pa = (float[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        FloatBuffer buff = chunk.getFloatBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType == DataType.DOUBLE) {
      double[] pa = (double[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        DoubleBuffer buff = chunk.getDoubleBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == long.class) {
      long[] pa = (long[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        LongBuffer buff = chunk.getLongBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType == DataType.STRUCTURE) {
      byte[] pa = (byte[]) arr;
      int recsize = layout.getElemSize();
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        ByteBuffer bb = chunk.getByteBuffer();
        bb.position(chunk.getSrcElem() * recsize);
        int pos = (int) chunk.getDestElem() * recsize;
        for (int i = 0; i < chunk.getNelems() * recsize; i++)
          pa[pos++] = bb.get();
      }
      return pa;
    }

    throw new IllegalStateException();
  }
static public Object readData(LayoutBB layout, DataType dataType, Object arr) throws java.io.IOException {
    if (showLayoutTypes) System.out.println("***BB LayoutType=" + layout.getClass().getName());

    if (dataType.getPrimitiveClassType() == byte.class || (dataType == DataType.CHAR)) {
      byte[] pa = (byte[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        ByteBuffer bb = chunk.getByteBuffer();
        bb.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = bb.get();
      }
      //return (dataType == DataType.CHAR) ? convertByteToChar(pa) : pa;
      if (dataType == DataType.CHAR) return convertByteToChar(pa);
      else return pa;

    } else if (dataType.getPrimitiveClassType() == short.class) {
      short[] pa = (short[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        ShortBuffer buff = chunk.getShortBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == int.class) {
      int[] pa = (int[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        IntBuffer buff = chunk.getIntBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType == DataType.FLOAT) {
      float[] pa = (float[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        FloatBuffer buff = chunk.getFloatBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType == DataType.DOUBLE) {
      double[] pa = (double[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        DoubleBuffer buff = chunk.getDoubleBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == long.class) {
      long[] pa = (long[]) arr;
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        LongBuffer buff = chunk.getLongBuffer();
        buff.position(chunk.getSrcElem());
        int pos = (int) chunk.getDestElem();
        for (int i = 0; i < chunk.getNelems(); i++)
          pa[pos++] = buff.get();
      }
      return pa;

    } else if (dataType == DataType.STRUCTURE) {
      byte[] pa = (byte[]) arr;
      int recsize = layout.getElemSize();
      while (layout.hasNext()) {
        LayoutBB.Chunk chunk = layout.next();
        ByteBuffer bb = chunk.getByteBuffer();
        bb.position(chunk.getSrcElem() * recsize);
        int pos = (int) chunk.getDestElem() * recsize;
        for (int i = 0; i < chunk.getNelems() * recsize; i++)
          pa[pos++] = bb.get();
      }
      return pa;
    }

    throw new IllegalStateException();
  }
static public Object readData ( LayoutBB layout , DataType dataType , Object arr ) throws java . io . IOException { if ( showLayoutTypes ) System . out . println ( "***BB LayoutType=" + layout . getClass ( ) . getName ( ) ) ; if ( dataType . getPrimitiveClassType ( ) == byte . class || ( dataType == DataType . CHAR ) ) { byte [ ] pa = ( byte [ ] ) arr ; while ( layout . hasNext ( ) ) { LayoutBB . Chunk chunk = layout . next ( ) ; ByteBuffer bb = chunk . getByteBuffer ( ) ; bb . position ( chunk . getSrcElem ( ) ) ; int pos = ( int ) chunk . getDestElem ( ) ; for ( int i = 0 ; i < chunk . getNelems ( ) ; i ++ ) pa [ pos ++ ] = . get ( ) ; } //return (dataType == DataType.CHAR) ? convertByteToChar(pa) : pa;
 if ( dataType == DataType . CHAR ) return convertByteToChar ( pa ) ; else return pa ; } else if ( dataType . getPrimitiveClassType ( ) == short . class ) { short [ ] pa = ( short [ ] ) arr ; while ( layout . hasNext ( ) ) { LayoutBB . Chunk chunk = layout . next ( ) ; ShortBuffer buff = chunk . getShortBuffer ( ) ; buff . position ( chunk . getSrcElem ( ) ) ; int pos = ( int ) chunk . getDestElem ( ) ; for ( int i = 0 ; i < chunk . getNelems ( ) ; i ++ ) pa [ pos ++ ] = buff . get ( ) ; } return pa ; } else if ( dataType . getPrimitiveClassType ( ) == int . class ) { int [ ] pa = ( int [ ] ) arr ; while ( layout . hasNext ( ) ) { LayoutBB . Chunk chunk = layout . next ( ) ; IntBuffer buff = chunk . getIntBuffer ( ) ; buff . position ( chunk . getSrcElem ( ) ) ; int pos = ( int ) chunk . getDestElem ( ) ; for ( int i = 0 ; i < chunk . getNelems ( ) ; i ++ ) pa [ pos ++ ] = buff . get ( ) ; } return pa ; } else if ( dataType == DataType . FLOAT ) { float [ ] pa = ( float [ ] ) arr ; while ( layout . hasNext ( ) ) { LayoutBB . Chunk chunk = layout . next ( ) ; FloatBuffer buff = chunk . getFloatBuffer ( ) ; buff . position ( chunk . getSrcElem ( ) ) ; int pos = ( int ) chunk . getDestElem ( ) ; for ( int i = 0 ; i < chunk . getNelems ( ) ; i ++ ) pa [ pos ++ ] = buff . get ( ) ; } return pa ; } else if ( dataType == DataType . DOUBLE ) { double [ ] pa = ( double [ ] ) arr ; while ( layout . hasNext ( ) ) { LayoutBB . Chunk chunk = layout . next ( ) ; DoubleBuffer buff = chunk . getDoubleBuffer ( ) ; buff . position ( chunk . getSrcElem ( ) ) ; int pos = ( int ) chunk . getDestElem ( ) ; for ( int i = 0 ; i < chunk . getNelems ( ) ; i ++ ) pa [ pos ++ ] = buff . get ( ) ; } return pa ; } else if ( dataType . getPrimitiveClassType ( ) == long . class ) { long [ ] pa = ( long [ ] ) arr ; while ( layout . hasNext ( ) ) { LayoutBB . Chunk chunk = layout . next ( ) ; LongBuffer buff = chunk . getLongBuffer ( ) ; buff . position ( chunk . getSrcElem ( ) ) ; int pos = ( int ) chunk . getDestElem ( ) ; for ( int i = 0 ; i < chunk . getNelems ( ) ; i ++ ) pa [ pos ++ ] = buff . get ( ) ; } return pa ; } else if ( dataType == DataType . STRUCTURE ) { byte [ ] pa = ( byte [ ] ) arr ; int recsize = layout . getElemSize ( ) ; while ( layout . hasNext ( ) ) { LayoutBB . Chunk chunk = layout . next ( ) ; ByteBuffer bb = chunk . getByteBuffer ( ) ; bb . position ( chunk . getSrcElem ( ) * recsize ) ; int pos = ( int ) chunk . getDestElem ( ) * recsize ; for ( int i = 0 ; i < chunk . getNelems ( ) * recsize ; i ++ ) pa [ pos ++ ] = . get ( ) ; } return pa ; } throw new IllegalStateException ( ) ; }
Read data subset from ByteBuffer, place in given primitive array.
Reading is controlled by the LayoutBB object.

@param layout   handles skipping around in the file, privide ByteBuffer to read from
@param dataType dataType of the variable
@param arr      primitive array to read data into
@return the primitive array with data read in
@throws java.io.IOException on read error
Read data subset from ByteBuffer place in given primitive array . Reading is controlled by the LayoutBB object .