visad/src/main/java/ucar/nc2/iosp/mcidas/AreaReader.java
public Array readVariable(Variable v2, Section section) throws IOException, InvalidRangeException {
    // not sure why timeRange isn't used...will comment out
    // for now
    // TODO: use timeRange in readVariable
    //Range timeRange = null;
    Range bandRange = null;
    Range geoXRange = null;
    Range geoYRange = null;
    Array dataArray;

    if (section == null) {
      dataArray = Array.factory(v2.getDataType(), v2.getShape());

    } else if (section.getRank() > 0) {
      if (section.getRank() > 3) {
        //timeRange = (Range) section.getRange(0);
        bandRange = section.getRange(1);
        geoYRange = section.getRange(2);
        geoXRange = section.getRange(3);
      } else if (section.getRank() > 2) {
        //timeRange = (Range) section.getRange(0);
        geoYRange = section.getRange(1);
        geoXRange = section.getRange(2);
      } else if (section.getRank() > 1) {
        geoYRange = section.getRange(0);
        geoXRange = section.getRange(1);
      }

      dataArray = Array.factory(v2.getDataType(), section.getShape());

    } else {
      String strRank = Integer.toString(section.getRank());
      String msg = "Invalid Rank: " + strRank + ". Must be > 0.";
      throw new IndexOutOfBoundsException(msg);
    }
    String varname = v2.getFullName();

    Index dataIndex = dataArray.getIndex();

    if (varname.equals("latitude") || varname.equals("longitude")) {
      double[][] pixel = new double[2][1];
      double[][] latLon;

      assert geoXRange != null;
      assert geoYRange != null;

      // Use Range object, which calculates requested i, j
      // values and incorporates stride
      for (int i = 0; i < geoXRange.length(); i++) {
        for (int j = 0; j < geoYRange.length(); j++) {
          pixel[0][0] = (double) geoXRange.element(i);
          pixel[1][0] = (double) geoYRange.element(j);
          latLon = nav.toLatLon(pixel);

          if (varname.equals("lat")) {
            dataArray.setFloat(dataIndex.set(j, i), (float) (latLon[0][0]));
          } else {
            dataArray.setFloat(dataIndex.set(j, i), (float) (latLon[1][0]));
          }
        }
      }
    }

    if (varname.equals("image")) {
      try {
        int[][] pixelData;
        if (bandRange != null) {
          for (int k = 0; k < bandRange.length(); k++) {
            int bandIndex = bandRange.element(k) + 1;  // band numbers in McIDAS are 1 based
            for (int j = 0; j < geoYRange.length(); j++) {
              for (int i = 0; i < geoXRange.length(); i++) {
                pixelData = af.getData(geoYRange.element(j),
                        geoXRange.element(i), 1, 1,
                        bandIndex);
                dataArray.setInt(dataIndex.set(0, k, j, i),
                        (pixelData[0][0]));
              }
            }
          }

        } else {
          assert geoXRange != null;
          assert geoYRange != null;

          for (int j = 0; j < geoYRange.length(); j++) {
            for (int i = 0; i < geoXRange.length(); i++) {
              pixelData = af.getData(geoYRange.element(j),
                      geoXRange.element(i), 1, 1);
              dataArray.setInt(dataIndex.set(0, j, i),
                      (pixelData[0][0]));
            }
          }
        }
      } catch (AreaFileException afe) {
        throw new IOException(afe.toString());
      }

    }

    return dataArray;
  }
public Array readVariable(Variable v2, Section section) throws IOException, InvalidRangeException {
    // not sure why timeRange isn't used...will comment out
    // for now
    // TODO: use timeRange in readVariable
    //Range timeRange = null;
    Range bandRange = null;
    Range geoXRange = null;
    Range geoYRange = null;
    Array dataArray;

    if (section == null) {
      dataArray = Array.factory(v2.getDataType(), v2.getShape());

    } else if (section.getRank() > 0) {
      if (section.getRank() > 3) {
        //timeRange = (Range) section.getRange(0);
        bandRange = section.getRange(1);
        geoYRange = section.getRange(2);
        geoXRange = section.getRange(3);
      } else if (section.getRank() > 2) {
        //timeRange = (Range) section.getRange(0);
        geoYRange = section.getRange(1);
        geoXRange = section.getRange(2);
      } else if (section.getRank() > 1) {
        geoYRange = section.getRange(0);
        geoXRange = section.getRange(1);
      }

      dataArray = Array.factory(v2.getDataType(), section.getShape());

    } else {
      String strRank = Integer.toString(section.getRank());
      String msg = "Invalid Rank: " + strRank + ". Must be > 0.";
      throw new IndexOutOfBoundsException(msg);
    }
    String varname = v2.getFullName();

    Index dataIndex = dataArray.getIndex();

    if (varname.equals("latitude") || varname.equals("longitude")) {
      double[][] pixel = new double[2][1];
      double[][] latLon;

      assert geoXRange != null;
      assert geoYRange != null;

      // Use Range object, which calculates requested i, j
      // values and incorporates stride
      for (int i = 0; i < geoXRange.length(); i++) {
        for (int j = 0; j < geoYRange.length(); j++) {
          pixel[0][0] = (double) geoXRange.element(i);
          pixel[1][0] = (double) geoYRange.element(j);
          latLon = nav.toLatLon(pixel);

          if (varname.equals("lat")) {
            dataArray.setFloat(dataIndex.set(j, i), (float) (latLon[0][0]));
          } else {
            dataArray.setFloat(dataIndex.set(j, i), (float) (latLon[1][0]));
          }
        }
      }
    }

    if (varname.equals("image")) {
      try {
        int[][] pixelData;
        if (bandRange != null) {
          for (int k = 0; k < bandRange.length(); k++) {
            int bandIndex = bandRange.element(k) + 1;  // band numbers in McIDAS are 1 based
            for (int j = 0; j < geoYRange.length(); j++) {
              for (int i = 0; i < geoXRange.length(); i++) {
                pixelData = af.getData(geoYRange.element(j),
                        geoXRange.element(i), 1, 1,
                        bandIndex);
                dataArray.setInt(dataIndex.set(0, k, j, i),
                        (pixelData[0][0]));
              }
            }
          }

        } else {
          assert geoXRange != null;
          assert geoYRange != null;

          for (int j = 0; j < geoYRange.length(); j++) {
            for (int i = 0; i < geoXRange.length(); i++) {
              pixelData = af.getData(geoYRange.element(j),
                      geoXRange.element(i), 1, 1);
              dataArray.setInt(dataIndex.set(0, j, i),
                      (pixelData[0][0]));
            }
          }
        }
      } catch (AreaFileException afe) {
        throw new IOException(afe.toString());
      }

    }

    return dataArray;
  }
public Array readVariable ( Variable v2 , Section section ) throws IOException , InvalidRangeException { // not sure why timeRange isn't used...will comment out
 // for now
 // TODO: use timeRange in readVariable
 //Range timeRange = null;
 Range bandRange = null ; Range geoXRange = null ; Range geoYRange = null ; Array dataArray ; if ( section == null ) { dataArray = Array . factory ( v2 . getDataType ( ) , v2 . getShape ( ) ) ; } else if ( section . getRank ( ) > 0 ) { if ( section . getRank ( ) > 3 ) { //timeRange = (Range) section.getRange(0);
 bandRange = section . getRange ( 1 ) ; geoYRange = section . getRange ( 2 ) ; geoXRange = section . getRange ( 3 ) ; } else if ( section . getRank ( ) > 2 ) { //timeRange = (Range) section.getRange(0);
 geoYRange = section . getRange ( 1 ) ; geoXRange = section . getRange ( 2 ) ; } else if ( section . getRank ( ) > 1 ) { geoYRange = section . getRange ( 0 ) ; geoXRange = section . getRange ( 1 ) ; } dataArray = Array . factory ( v2 . getDataType ( ) , section . getShape ( ) ) ; } else { String strRank = Integer . toString ( section . getRank ( ) ) ; String msg = "Invalid Rank: " + strRank + ". Must be > 0." ; throw new IndexOutOfBoundsException ( msg ) ; } String varname = v2 . getFullName ( ) ; Index dataIndex = dataArray . getIndex ( ) ; if ( varname . equals ( "latitude" ) || varname . equals ( "longitude" ) ) { double [ ] [ ] pixel = new double [ 2 ] [ 1 ] ; double [ ] [ ] latLon ; assert geoXRange != null ; assert geoYRange != null ; // Use Range object, which calculates requested i, j
 // values and incorporates stride
 for ( int i = 0 ; i < geoXRange . length ( ) ; i ++ ) { for ( int j = 0 ; j < geoYRange . length ( ) ; j ++ ) { pixel [ 0 ] [ 0 ] = ( double ) geoXRange . element ( i ) ; pixel [ 1 ] [ 0 ] = ( double ) geoYRange . element ( j ) ; latLon = nav . toLatLon ( pixel ) ; if ( varname . equals ( "lat" ) ) { dataArray . setFloat ( dataIndex . set ( j , i ) , ( float ) ( latLon [ 0 ] [ 0 ] ) ) ; } else { dataArray . setFloat ( dataIndex . set ( j , i ) , ( float ) ( latLon [ 1 ] [ 0 ] ) ) ; } } } } if ( varname . equals ( "image" ) ) { try { int [ ] [ ] pixelData ; if ( bandRange != null ) { for ( int k = 0 ; k < bandRange . length ( ) ; k ++ ) { int bandIndex = bandRange . element ( k ) + 1 ; // band numbers in McIDAS are 1 based
 for ( int j = 0 ; j < geoYRange . length ( ) ; j ++ ) { for ( int i = 0 ; i < geoXRange . length ( ) ; i ++ ) { pixelData = af . getData ( geoYRange . element ( j ) , geoXRange . element ( i ) , 1 , 1 , bandIndex ) ; dataArray . setInt ( dataIndex . set ( 0 , k , j , i ) , ( pixelData [ 0 ] [ 0 ] ) ) ; } } } } else { assert geoXRange != null ; assert geoYRange != null ; for ( int j = 0 ; j < geoYRange . length ( ) ; j ++ ) { for ( int i = 0 ; i < geoXRange . length ( ) ; i ++ ) { pixelData = af . getData ( geoYRange . element ( j ) , geoXRange . element ( i ) , 1 , 1 ) ; dataArray . setInt ( dataIndex . set ( 0 , j , i ) , ( pixelData [ 0 ] [ 0 ] ) ) ; } } } } catch ( AreaFileException afe ) { throw new IOException ( afe . toString ( ) ) ; } } return dataArray ; }
Read the values for a variable

@param v2      the variable
@param section the section info (time,x,y range);
@return the data
@throws IOException           problem reading file
@throws InvalidRangeException range doesn't match data
Read the values for a variable