Exemple #1
0
  private RowInfo[] createRowInfos() throws IOException {
    final ISINGrid grid = this.grid;
    final RowInfo[] binLines = new RowInfo[sceneHeight];
    final Variable idxVariable =
        ncFile.getRootGroup().findGroup("Level-3_Binned_Data").findVariable("BinList");
    final Structure idxStructure = (Structure) idxVariable;
    final Variable idx = idxStructure.findVariable("bin_num");
    final int[] idxValues;
    synchronized (ncFile) {
      idxValues = (int[]) idx.read().getStorage();
    }
    if (bins == null) {
      bins = idxValues; // (int[]) idxVariable.read().copyTo1DJavaArray();
    }
    final Point gridPoint = new Point();
    int lastBinIndex = -1;
    int lastRowIndex = -1;
    int lineOffset = 0;
    int lineLength = 0;
    for (int i = 0; i < idxValues.length; i++) {

      final int binIndex = idxValues[i];
      if (binIndex < lastBinIndex) {
        throw new IOException(
            "Unrecognized level-3 format. Bins numbers expected to appear in ascending order.");
      }
      lastBinIndex = binIndex;

      grid.getGridPoint(binIndex, gridPoint);
      final int rowIndex = gridPoint.y;

      if (rowIndex != lastRowIndex) {
        if (lineLength > 0) {
          binLines[lastRowIndex] = new RowInfo(lineOffset, lineLength);
        }
        lineOffset = i;
        lineLength = 0;
      }

      lineLength++;
      lastRowIndex = rowIndex;
    }

    if (lineLength > 0) {
      binLines[lastRowIndex] = new RowInfo(lineOffset, lineLength);
    }

    return binLines;
  }