cdm/src/main/java/ucar/nc2/iosp/hdf5/H5iosp.java
private Array readData(ucar.nc2.Variable v2, long dataPos, Section wantSection) throws IOException, InvalidRangeException {
    H5header.Vinfo vinfo = (H5header.Vinfo) v2.getSPobject();
    DataType dataType = v2.getDataType();
    Object data;
    Layout layout;

    if (vinfo.useFillValue) { // fill value only
      Object pa = IospHelper.makePrimitiveArray((int) wantSection.computeSize(), dataType, vinfo.getFillValue());
      if (dataType == DataType.CHAR)
        pa = IospHelper.convertByteToChar((byte[]) pa);
      return Array.factory(dataType, wantSection.getShape(), pa);
    }

    if (vinfo.mfp != null) { // filtered
      if (debugFilter) System.out.println("read variable filtered " + v2.getFullName() + " vinfo = " + vinfo);
      assert vinfo.isChunked;
      ByteOrder bo = (vinfo.typeInfo.endian == 0) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
      layout = new H5tiledLayoutBB(v2, wantSection, raf, vinfo.mfp.getFilters(), bo);
      if (vinfo.typeInfo.isVString) {
        data = readFilteredStringData((LayoutBB) layout);
      } else{
        data = IospHelper.readDataFill((LayoutBB) layout, v2.getDataType(), vinfo.getFillValue());
      }

    } else { // normal case
      if (debug) System.out.println("read variable " + v2.getFullName() + " vinfo = " + vinfo);

      DataType readDtype = v2.getDataType();
      int elemSize = v2.getElementSize();
      Object fillValue = vinfo.getFillValue();
      int endian = vinfo.typeInfo.endian;

      // fill in the wantSection
      wantSection = Section.fill(wantSection, v2.getShape());

      if (vinfo.typeInfo.hdfType == 2) { // time
        readDtype = vinfo.mdt.timeType;
        elemSize = readDtype.getSize();
        fillValue = N3iosp.getFillValueDefault(readDtype);

      } else if (vinfo.typeInfo.hdfType == 8) { // enum
        H5header.TypeInfo baseInfo = vinfo.typeInfo.base;
        readDtype = baseInfo.dataType;
        elemSize = readDtype.getSize();
        fillValue = N3iosp.getFillValueDefault(readDtype);
        endian = baseInfo.endian;

      } else if (vinfo.typeInfo.hdfType == 9) { // vlen
        elemSize = vinfo.typeInfo.byteSize;
        endian = vinfo.typeInfo.endian;
        //wantSection = wantSection.removeVlen(); // remove vlen dimension
      }

      if (vinfo.isChunked) {
        layout = new H5tiledLayout((H5header.Vinfo) v2.getSPobject(), readDtype, wantSection);
      } else {
        layout = new LayoutRegular(dataPos, elemSize, v2.getShape(), wantSection);
      }
      data = readData(vinfo, v2, layout, readDtype, wantSection.getShape(), fillValue, endian);
    }

    if (data instanceof Array)
      return (Array) data;
    else if (dataType == DataType.STRUCTURE)
      return convertStructure((Structure) v2, layout, wantSection.getShape(), (byte[]) data);  // LOOK
    else
      return Array.factory(dataType, wantSection.getShape(), data);
  }
private Array readData(ucar.nc2.Variable v2, long dataPos, Section wantSection) throws IOException, InvalidRangeException {
    H5header.Vinfo vinfo = (H5header.Vinfo) v2.getSPobject();
    DataType dataType = v2.getDataType();
    Object data;
    Layout layout;

    if (vinfo.useFillValue) { // fill value only
      Object pa = IospHelper.makePrimitiveArray((int) wantSection.computeSize(), dataType, vinfo.getFillValue());
      if (dataType == DataType.CHAR)
        pa = IospHelper.convertByteToChar((byte[]) pa);
      return Array.factory(dataType, wantSection.getShape(), pa);
    }

    if (vinfo.mfp != null) { // filtered
      if (debugFilter) System.out.println("read variable filtered " + v2.getFullName() + " vinfo = " + vinfo);
      assert vinfo.isChunked;
      ByteOrder bo = (vinfo.typeInfo.endian == 0) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
      layout = new H5tiledLayoutBB(v2, wantSection, raf, vinfo.mfp.getFilters(), bo);
      if (vinfo.typeInfo.isVString) {
        data = readFilteredStringData((LayoutBB) layout);
      } else{
        data = IospHelper.readDataFill((LayoutBB) layout, v2.getDataType(), vinfo.getFillValue());
      }

    } else { // normal case
      if (debug) System.out.println("read variable " + v2.getFullName() + " vinfo = " + vinfo);

      DataType readDtype = v2.getDataType();
      int elemSize = v2.getElementSize();
      Object fillValue = vinfo.getFillValue();
      int endian = vinfo.typeInfo.endian;

      // fill in the wantSection
      wantSection = Section.fill(wantSection, v2.getShape());

      if (vinfo.typeInfo.hdfType == 2) { // time
        readDtype = vinfo.mdt.timeType;
        elemSize = readDtype.getSize();
        fillValue = N3iosp.getFillValueDefault(readDtype);

      } else if (vinfo.typeInfo.hdfType == 8) { // enum
        H5header.TypeInfo baseInfo = vinfo.typeInfo.base;
        readDtype = baseInfo.dataType;
        elemSize = readDtype.getSize();
        fillValue = N3iosp.getFillValueDefault(readDtype);
        endian = baseInfo.endian;

      } else if (vinfo.typeInfo.hdfType == 9) { // vlen
        elemSize = vinfo.typeInfo.byteSize;
        endian = vinfo.typeInfo.endian;
        //wantSection = wantSection.removeVlen(); // remove vlen dimension
      }

      if (vinfo.isChunked) {
        layout = new H5tiledLayout((H5header.Vinfo) v2.getSPobject(), readDtype, wantSection);
      } else {
        layout = new LayoutRegular(dataPos, elemSize, v2.getShape(), wantSection);
      }
      data = readData(vinfo, v2, layout, readDtype, wantSection.getShape(), fillValue, endian);
    }

    if (data instanceof Array)
      return (Array) data;
    else if (dataType == DataType.STRUCTURE)
      return convertStructure((Structure) v2, layout, wantSection.getShape(), (byte[]) data);  // LOOK
    else
      return Array.factory(dataType, wantSection.getShape(), data);
  }
private Array readData ( ucar . nc2 . Variable v2 , long dataPos , Section wantSection ) throws IOException , InvalidRangeException { H5header . Vinfo vinfo = ( H5header . Vinfo ) v2 . getSPobject ( ) ; DataType dataType = v2 . getDataType ( ) ; Object data ; Layout layout ; if ( vinfo . useFillValue ) { // fill value only Object pa = IospHelper . makePrimitiveArray ( ( int ) wantSection . computeSize ( ) , dataType , vinfo . getFillValue ( ) ) ; if ( dataType == DataType . CHAR ) pa = IospHelper . convertByteToChar ( ( byte [ ] ) pa ) ; return Array . factory ( dataType , wantSection . getShape ( ) , pa ) ; } if ( vinfo . mfp != null ) { // filtered if ( debugFilter ) System . out . println ( "read variable filtered " + v2 . getFullName ( ) + " vinfo = " + vinfo ) ; assert vinfo . isChunked ; ByteOrder bo = ( vinfo . typeInfo . endian == 0 ) ? ByteOrder . BIG_ENDIAN : ByteOrder . LITTLE_ENDIAN ; layout = new H5tiledLayoutBB ( v2 , wantSection , raf , vinfo . mfp . getFilters ( ) , bo ) ; if ( vinfo . typeInfo . isVString ) { data = readFilteredStringData ( ( LayoutBB ) layout ) ; } else { data = IospHelper . readDataFill ( ( LayoutBB ) layout , v2 . getDataType ( ) , vinfo . getFillValue ( ) ) ; } } else { // normal case if ( debug ) System . out . println ( "read variable " + v2 . getFullName ( ) + " vinfo = " + vinfo ) ; DataType readDtype = v2 . getDataType ( ) ; int elemSize = v2 . getElementSize ( ) ; Object fillValue = vinfo . getFillValue ( ) ; int endian = vinfo . typeInfo . endian ; // fill in the wantSection wantSection = Section . fill ( wantSection , v2 . getShape ( ) ) ; if ( vinfo . typeInfo . hdfType == 2 ) { // time readDtype = vinfo . mdt . timeType ; elemSize = readDtype . getSize ( ) ; fillValue = N3iosp . getFillValueDefault ( readDtype ) ; } else if ( vinfo . typeInfo . hdfType == 8 ) { // enum H5header . TypeInfo baseInfo = vinfo . typeInfo . base ; readDtype = baseInfo . dataType ; elemSize = readDtype . getSize ( ) ; fillValue = N3iosp . getFillValueDefault ( readDtype ) ; endian = baseInfo . endian ; } else if ( vinfo . typeInfo . hdfType == 9 ) { // vlen elemSize = vinfo . typeInfo . byteSize ; endian = vinfo . typeInfo . endian ; //wantSection = wantSection.removeVlen(); // remove vlen dimension } if ( vinfo . isChunked ) { layout = new H5tiledLayout ( ( H5header . Vinfo ) v2 . getSPobject ( ) , readDtype , wantSection ) ; } else { layout = new LayoutRegular ( dataPos , elemSize , v2 . getShape ( ) , wantSection ) ; } data = readData ( vinfo , v2 , layout , readDtype , wantSection . getShape ( ) , fillValue , endian ) ; } if ( data instanceof Array ) return ( Array ) data ; else if ( dataType == DataType . STRUCTURE ) return convertStructure ( ( Structure ) v2 , layout , wantSection . getShape ( ) , ( byte [ ] ) data ) ; // LOOK else return Array . factory ( dataType , wantSection . getShape ( ) , data ) ; }
all the work is here, so can be called recursively
all the work is here so can be called recursively