cdm/src/main/java/ucar/nc2/iosp/IospHelper.java
static public Object readData(RandomAccessFile raf, Layout layout, DataType dataType, Object arr, int byteOrder, boolean convertChar) throws java.io.IOException {
    if (showLayoutTypes) System.out.println("***RAF LayoutType=" + layout.getClass().getName());

    if (dataType.getPrimitiveClassType() == byte.class || dataType == DataType.CHAR) {
      byte[] pa = (byte[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readFully(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      if (convertChar && dataType == DataType.CHAR) return convertByteToChar(pa);
      else return pa; // javac ternary compile error

    } else if (dataType.getPrimitiveClassType() == short.class) {
      short[] pa = (short[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readShort(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == int.class) {
      int[] pa = (int[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readInt(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType == DataType.FLOAT) {
      float[] pa = (float[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readFloat(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType == DataType.DOUBLE) {
      double[] pa = (double[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readDouble(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == long.class) {
      long[] pa = (long[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readLong(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType == DataType.STRUCTURE) {
      byte[] pa = (byte[]) arr;
      int recsize = layout.getElemSize();
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readFully(pa, (int) chunk.getDestElem() * recsize, chunk.getNelems() * recsize);
      }
      return pa;
    }

    throw new IllegalStateException("unknown type= " + dataType);
  }
static public Object readData(RandomAccessFile raf, Layout layout, DataType dataType, Object arr, int byteOrder, boolean convertChar) throws java.io.IOException {
    if (showLayoutTypes) System.out.println("***RAF LayoutType=" + layout.getClass().getName());

    if (dataType.getPrimitiveClassType() == byte.class || dataType == DataType.CHAR) {
      byte[] pa = (byte[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readFully(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      if (convertChar && dataType == DataType.CHAR) return convertByteToChar(pa);
      else return pa; // javac ternary compile error

    } else if (dataType.getPrimitiveClassType() == short.class) {
      short[] pa = (short[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readShort(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == int.class) {
      int[] pa = (int[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readInt(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType == DataType.FLOAT) {
      float[] pa = (float[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readFloat(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType == DataType.DOUBLE) {
      double[] pa = (double[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readDouble(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType.getPrimitiveClassType() == long.class) {
      long[] pa = (long[]) arr;
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readLong(pa, (int) chunk.getDestElem(), chunk.getNelems());
      }
      return pa;

    } else if (dataType == DataType.STRUCTURE) {
      byte[] pa = (byte[]) arr;
      int recsize = layout.getElemSize();
      while (layout.hasNext()) {
        Layout.Chunk chunk = layout.next();
        raf.order(byteOrder);
        raf.seek(chunk.getSrcPos());
        raf.readFully(pa, (int) chunk.getDestElem() * recsize, chunk.getNelems() * recsize);
      }
      return pa;
    }

    throw new IllegalStateException("unknown type= " + dataType);
  }
static public Object readData ( RandomAccessFile raf , Layout layout , DataType dataType , Object arr , int byteOrder , boolean convertChar ) throws java . io . IOException { if ( showLayoutTypes ) System . out . println ( "***RAF LayoutType=" + layout . getClass ( ) . getName ( ) ) ; if ( dataType . getPrimitiveClassType ( ) == byte . class || dataType == DataType . CHAR ) { byte [ ] pa = ( byte [ ] ) arr ; while ( layout . hasNext ( ) ) { Layout . Chunk chunk = layout . next ( ) ; raf . order ( byteOrder ) ; raf . seek ( chunk . getSrcPos ( ) ) ; raf . readFully ( pa , ( int ) chunk . getDestElem ( ) , chunk . getNelems ( ) ) ; } if ( convertChar && dataType == DataType . CHAR ) return convertByteToChar ( pa ) ; else return pa ; // javac ternary compile error
 } else if ( dataType . getPrimitiveClassType ( ) == short . class ) { short [ ] pa = ( short [ ] ) arr ; while ( layout . hasNext ( ) ) { Layout . Chunk chunk = layout . next ( ) ; raf . order ( byteOrder ) ; raf . seek ( chunk . getSrcPos ( ) ) ; raf . readShort ( pa , ( int ) chunk . getDestElem ( ) , chunk . getNelems ( ) ) ; } return pa ; } else if ( dataType . getPrimitiveClassType ( ) == int . class ) { int [ ] pa = ( int [ ] ) arr ; while ( layout . hasNext ( ) ) { Layout . Chunk chunk = layout . next ( ) ; raf . order ( byteOrder ) ; raf . seek ( chunk . getSrcPos ( ) ) ; raf . readInt ( pa , ( int ) chunk . getDestElem ( ) , chunk . getNelems ( ) ) ; } return pa ; } else if ( dataType == DataType . FLOAT ) { float [ ] pa = ( float [ ] ) arr ; while ( layout . hasNext ( ) ) { Layout . Chunk chunk = layout . next ( ) ; raf . order ( byteOrder ) ; raf . seek ( chunk . getSrcPos ( ) ) ; raf . readFloat ( pa , ( int ) chunk . getDestElem ( ) , chunk . getNelems ( ) ) ; } return pa ; } else if ( dataType == DataType . DOUBLE ) { double [ ] pa = ( double [ ] ) arr ; while ( layout . hasNext ( ) ) { Layout . Chunk chunk = layout . next ( ) ; raf . order ( byteOrder ) ; raf . seek ( chunk . getSrcPos ( ) ) ; raf . readDouble ( pa , ( int ) chunk . getDestElem ( ) , chunk . getNelems ( ) ) ; } return pa ; } else if ( dataType . getPrimitiveClassType ( ) == long . class ) { long [ ] pa = ( long [ ] ) arr ; while ( layout . hasNext ( ) ) { Layout . Chunk chunk = layout . next ( ) ; raf . order ( byteOrder ) ; raf . seek ( chunk . getSrcPos ( ) ) ; raf . readLong ( pa , ( int ) chunk . getDestElem ( ) , chunk . getNelems ( ) ) ; } return pa ; } else if ( dataType == DataType . STRUCTURE ) { byte [ ] pa = ( byte [ ] ) arr ; int recsize = layout . getElemSize ( ) ; while ( layout . hasNext ( ) ) { Layout . Chunk chunk = layout . next ( ) ; raf . order ( byteOrder ) ; raf . seek ( chunk . getSrcPos ( ) ) ; raf . readFully ( pa , ( int ) chunk . getDestElem ( ) * recsize , chunk . getNelems ( ) * recsize ) ; } return pa ; } throw new IllegalStateException ( "unknown type= " + dataType ) ; }
Read data subset from RandomAccessFile, place in given primitive array.
Reading is controlled by the Layout object.

@param raf         read from here.
@param layout      handles skipping around in the file.
@param dataType    dataType of the variable
@param arr         primitive array to read data into
@param byteOrder   if equal to RandomAccessFile.ORDER_XXXX, set the byte order just before reading
@param convertChar true if bytes should be converted to char for dataType CHAR
@return primitive array with data read in
@throws java.io.IOException on read error
Read data subset from RandomAccessFile place in given primitive array . Reading is controlled by the Layout object .