Program: 11498
Project: 11498
Buggy source:
private void computeTileStackForNormalProduct(final Map<Band,Tile> targetTileMap,Rectangle targetRectangle,final ProgressMonitor pm) throws OperatorException {
  try {
    final int cohx0=targetRectangle.x - (cohWinRg - 1) / 2;
    final int cohy0=targetRectangle.y - (cohWinAz - 1) / 2;
    final int cohw=targetRectangle.width + cohWinRg - 1;
    final int cohh=targetRectangle.height + cohWinAz - 1;
    targetRectangle=new Rectangle(cohx0,cohy0,cohw,cohh);
    final BorderExtender border=BorderExtender.createInstance(BorderExtender.BORDER_ZERO);
    final int y0=targetRectangle.y;
    final int yN=y0 + targetRectangle.height - 1;
    final int x0=targetRectangle.x;
    final int xN=targetRectangle.x + targetRectangle.width - 1;
    for (    String ifgKey : targetMap.keySet()) {
      final ProductContainer product=targetMap.get(ifgKey);
      final Tile mstTileReal=getSourceTile(product.sourceMaster.realBand,targetRectangle,border);
      final Tile mstTileImag=getSourceTile(product.sourceMaster.imagBand,targetRectangle,border);
      final ComplexDoubleMatrix dataMaster=TileUtilsDoris.pullComplexDoubleMatrix(mstTileReal,mstTileImag);
      final Tile slvTileReal=getSourceTile(product.sourceSlave.realBand,targetRectangle,border);
      final Tile slvTileImag=getSourceTile(product.sourceSlave.imagBand,targetRectangle,border);
      final ComplexDoubleMatrix dataSlave=TileUtilsDoris.pullComplexDoubleMatrix(slvTileReal,slvTileImag);
      ComplexDoubleMatrix dataMaster2=null, dataSlave2=null;
      if (includeCoherence) {
        dataMaster2=new ComplexDoubleMatrix(mstTileReal.getHeight(),mstTileReal.getWidth());
        dataSlave2=new ComplexDoubleMatrix(slvTileReal.getHeight(),slvTileReal.getWidth());
        dataMaster2.copy(dataMaster);
        dataSlave2.copy(dataSlave);
      }
      if (subtractFlatEarthPhase) {
        DoubleMatrix rangeAxisNormalized=DoubleMatrix.linspace(x0,xN,dataMaster.columns);
        rangeAxisNormalized=normalizeDoubleMatrix(rangeAxisNormalized,0,sourceImageWidth - 1);
        DoubleMatrix azimuthAxisNormalized=DoubleMatrix.linspace(y0,yN,dataMaster.rows);
        azimuthAxisNormalized=normalizeDoubleMatrix(azimuthAxisNormalized,0,sourceImageHeight - 1);
        final DoubleMatrix polyCoeffs=flatEarthPolyMap.get(product.sourceSlave.name);
        final DoubleMatrix realReferencePhase=PolyUtils.polyval(azimuthAxisNormalized,rangeAxisNormalized,polyCoeffs,PolyUtils.degreeFromCoefficients(polyCoeffs.length));
        final ComplexDoubleMatrix complexReferencePhase=new ComplexDoubleMatrix(MatrixFunctions.cos(realReferencePhase),MatrixFunctions.sin(realReferencePhase));
        dataSlave.muli(complexReferencePhase);
      }
      dataMaster.muli(dataSlave.conji());
      final Band targetBand_I=targetProduct.getBand(product.getBandName(Unit.REAL));
      final Tile tileOutReal=targetTileMap.get(targetBand_I);
      final Band targetBand_Q=targetProduct.getBand(product.getBandName(Unit.IMAGINARY));
      final Tile tileOutImag=targetTileMap.get(targetBand_Q);
      DoubleMatrix cohMatrix=null;
      ProductData samplesCoh=null;
      if (includeCoherence) {
        for (int i=0; i < dataMaster.length; i++) {
          double tmp=norm(dataMaster2.get(i));
          dataMaster2.put(i,dataMaster2.get(i).mul(dataSlave2.get(i).conj()));
          dataSlave2.put(i,new ComplexDouble(norm(dataSlave2.get(i)),tmp));
        }
        cohMatrix=SarUtils.coherence2(dataMaster2,dataSlave2,cohWinAz,cohWinRg);
        final Band targetBandCoh=targetProduct.getBand(product.getBandName(Unit.COHERENCE));
        final Tile tileOutCoh=targetTileMap.get(targetBandCoh);
        samplesCoh=tileOutCoh.getDataBuffer();
      }
      final ProductData samplesReal=tileOutReal.getDataBuffer();
      final ProductData samplesImag=tileOutImag.getDataBuffer();
      final DoubleMatrix dataReal=dataMaster.real();
      final DoubleMatrix dataImag=dataMaster.imag();
      final Rectangle rect=tileOutReal.getRectangle();
      final int maxX=rect.x + rect.width;
      final int maxY=rect.y + rect.height;
      final TileIndex tgtIndex=new TileIndex(tileOutReal);
      for (int y=rect.y; y < maxY; y++) {
        tgtIndex.calculateStride(y);
        final int yy=y - rect.y;
        for (int x=rect.x; x < maxX; x++) {
          final int trgIndex=tgtIndex.getIndex(x);
          final int xx=x - rect.x;
          samplesReal.setElemFloatAt(trgIndex,(float)dataReal.get(yy,xx));
          samplesImag.setElemFloatAt(trgIndex,(float)dataImag.get(yy,xx));
          if (samplesCoh != null) {
            samplesCoh.setElemFloatAt(trgIndex,(float)cohMatrix.get(yy,xx));
          }
        }
      }
    }
  }
 catch (  Throwable e) {
    OperatorUtils.catchOperatorException(getId(),e);
  }
 finally {
    pm.done();
  }
}

Fixed version (ground truth):
private void computeTileStackForNormalProduct(final Map<Band,Tile> targetTileMap,Rectangle targetRectangle,final ProgressMonitor pm) throws OperatorException {
  try {
    final int rgOffset=(cohWinRg - 1) / 2;
    final int azOffset=(cohWinAz - 1) / 2;
    final int cohx0=targetRectangle.x - rgOffset;
    final int cohy0=targetRectangle.y - azOffset;
    final int cohw=targetRectangle.width + cohWinRg - 1;
    final int cohh=targetRectangle.height + cohWinAz - 1;
    targetRectangle=new Rectangle(cohx0,cohy0,cohw,cohh);
    final BorderExtender border=BorderExtender.createInstance(BorderExtender.BORDER_ZERO);
    final int y0=targetRectangle.y;
    final int yN=y0 + targetRectangle.height - 1;
    final int x0=targetRectangle.x;
    final int xN=targetRectangle.x + targetRectangle.width - 1;
    for (    String ifgKey : targetMap.keySet()) {
      final ProductContainer product=targetMap.get(ifgKey);
      final Tile mstTileReal=getSourceTile(product.sourceMaster.realBand,targetRectangle,border);
      final Tile mstTileImag=getSourceTile(product.sourceMaster.imagBand,targetRectangle,border);
      final ComplexDoubleMatrix dataMaster=TileUtilsDoris.pullComplexDoubleMatrix(mstTileReal,mstTileImag);
      final Tile slvTileReal=getSourceTile(product.sourceSlave.realBand,targetRectangle,border);
      final Tile slvTileImag=getSourceTile(product.sourceSlave.imagBand,targetRectangle,border);
      final ComplexDoubleMatrix dataSlave=TileUtilsDoris.pullComplexDoubleMatrix(slvTileReal,slvTileImag);
      ComplexDoubleMatrix dataMaster2=null, dataSlave2=null;
      if (includeCoherence) {
        dataMaster2=new ComplexDoubleMatrix(mstTileReal.getHeight(),mstTileReal.getWidth());
        dataSlave2=new ComplexDoubleMatrix(slvTileReal.getHeight(),slvTileReal.getWidth());
        dataMaster2.copy(dataMaster);
        dataSlave2.copy(dataSlave);
      }
      if (subtractFlatEarthPhase) {
        DoubleMatrix rangeAxisNormalized=DoubleMatrix.linspace(x0,xN,dataMaster.columns);
        rangeAxisNormalized=normalizeDoubleMatrix(rangeAxisNormalized,0,sourceImageWidth - 1);
        DoubleMatrix azimuthAxisNormalized=DoubleMatrix.linspace(y0,yN,dataMaster.rows);
        azimuthAxisNormalized=normalizeDoubleMatrix(azimuthAxisNormalized,0,sourceImageHeight - 1);
        final DoubleMatrix polyCoeffs=flatEarthPolyMap.get(product.sourceSlave.name);
        final DoubleMatrix realReferencePhase=PolyUtils.polyval(azimuthAxisNormalized,rangeAxisNormalized,polyCoeffs,PolyUtils.degreeFromCoefficients(polyCoeffs.length));
        final ComplexDoubleMatrix complexReferencePhase=new ComplexDoubleMatrix(MatrixFunctions.cos(realReferencePhase),MatrixFunctions.sin(realReferencePhase));
        dataSlave.muli(complexReferencePhase);
      }
      dataMaster.muli(dataSlave.conji());
      final Band targetBand_I=targetProduct.getBand(product.getBandName(Unit.REAL));
      final Tile tileOutReal=targetTileMap.get(targetBand_I);
      final Band targetBand_Q=targetProduct.getBand(product.getBandName(Unit.IMAGINARY));
      final Tile tileOutImag=targetTileMap.get(targetBand_Q);
      DoubleMatrix cohMatrix=null;
      ProductData samplesCoh=null;
      if (includeCoherence) {
        for (int i=0; i < dataMaster.length; i++) {
          double tmp=norm(dataMaster2.get(i));
          dataMaster2.put(i,dataMaster2.get(i).mul(dataSlave2.get(i).conj()));
          dataSlave2.put(i,new ComplexDouble(norm(dataSlave2.get(i)),tmp));
        }
        cohMatrix=SarUtils.coherence2(dataMaster2,dataSlave2,cohWinAz,cohWinRg);
        final Band targetBandCoh=targetProduct.getBand(product.getBandName(Unit.COHERENCE));
        final Tile tileOutCoh=targetTileMap.get(targetBandCoh);
        samplesCoh=tileOutCoh.getDataBuffer();
      }
      final ProductData samplesReal=tileOutReal.getDataBuffer();
      final ProductData samplesImag=tileOutImag.getDataBuffer();
      final DoubleMatrix dataReal=dataMaster.real();
      final DoubleMatrix dataImag=dataMaster.imag();
      final Rectangle rect=tileOutReal.getRectangle();
      final int maxX=rect.x + rect.width;
      final int maxY=rect.y + rect.height;
      final TileIndex tgtIndex=new TileIndex(tileOutReal);
      for (int y=rect.y; y < maxY; y++) {
        tgtIndex.calculateStride(y);
        final int yy=y - rect.y;
        for (int x=rect.x; x < maxX; x++) {
          final int trgIndex=tgtIndex.getIndex(x);
          final int xx=x - rect.x;
          samplesReal.setElemFloatAt(trgIndex,(float)dataReal.get(yy,xx));
          samplesImag.setElemFloatAt(trgIndex,(float)dataImag.get(yy,xx));
          if (samplesCoh != null) {
            samplesCoh.setElemFloatAt(trgIndex,(float)cohMatrix.get(yy,xx));
          }
        }
      }
    }
  }
 catch (  Throwable e) {
    OperatorUtils.catchOperatorException(getId(),e);
  }
 finally {
    pm.done();
  }
}