Program: 11527
Project: 11527
Buggy source:
/** 
 * Called by the framework in order to compute a tile for the given target band. <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand,Tile targetTile,ProgressMonitor pm) throws OperatorException {
  final Rectangle targetTileRectangle=targetTile.getRectangle();
  final int x0=targetTileRectangle.x;
  final int y0=targetTileRectangle.y;
  final int w=targetTileRectangle.width;
  final int h=targetTileRectangle.height;
  Tile sourceRaster1=null;
  ProductData srcData1=null;
  ProductData srcData2=null;
  Band sourceBand1=null;
  final String targetBandName=targetBand.getName();
  final String[] srcBandNames=targetBandNameToSourceBandName.get(targetBandName);
  if (srcBandNames.length == 1) {
    sourceBand1=sourceProduct.getBand(srcBandNames[0]);
    sourceRaster1=calibrationOp.getSourceTile(sourceBand1,targetTileRectangle);
    srcData1=sourceRaster1.getDataBuffer();
  }
 else {
    sourceBand1=sourceProduct.getBand(srcBandNames[0]);
    final Band sourceBand2=sourceProduct.getBand(srcBandNames[1]);
    sourceRaster1=calibrationOp.getSourceTile(sourceBand1,targetTileRectangle);
    final Tile sourceRaster2=calibrationOp.getSourceTile(sourceBand2,targetTileRectangle);
    srcData1=sourceRaster1.getDataBuffer();
    srcData2=sourceRaster2.getDataBuffer();
  }
  final Unit.UnitType bandUnit=Unit.getUnitType(sourceBand1);
  final ProductData trgData=targetTile.getDataBuffer();
  final TileIndex srcIndex=new TileIndex(sourceRaster1);
  final TileIndex trgIndex=new TileIndex(targetTile);
  final int maxY=y0 + h;
  final int maxX=x0 + w;
  final boolean complexData=bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY;
  final CalibrationInfo calInfo=targetBandToCalInfo.get(targetBandName);
  final Sentinel1Calibrator.CALTYPE calType=Sentinel1Calibrator.getCalibrationType(targetBandName);
  double dn, dn2, i, q, muX, lutVal, retroLutVal=1.0;
  int srcIdx, trgIdx;
  for (int y=y0; y < maxY; ++y) {
    srcIndex.calculateStride(y);
    trgIndex.calculateStride(y);
    final int calVecIdx=calInfo.getCalibrationVectorIndex(y);
    final Sentinel1Utils.CalibrationVector vec0=calInfo.getCalibrationVector(calVecIdx);
    final Sentinel1Utils.CalibrationVector vec1=calInfo.getCalibrationVector(calVecIdx + 1);
    final float[] vec0LUT=Sentinel1Calibrator.getVector(calType,vec0);
    final float[] vec1LUT=Sentinel1Calibrator.getVector(calType,vec1);
    float[] retroVec0LUT=null;
    float[] retroVec1LUT=null;
    if (dataType != null) {
      retroVec0LUT=Sentinel1Calibrator.getVector(dataType,vec0);
      retroVec1LUT=Sentinel1Calibrator.getVector(dataType,vec1);
    }
    final double azTime=calInfo.firstLineTime + y * calInfo.lineTimeInterval;
    final double muY=(azTime - vec0.timeMJD) / (vec1.timeMJD - vec0.timeMJD);
    for (int x=x0; x < maxX; ++x) {
      srcIdx=srcIndex.getIndex(x);
      trgIdx=trgIndex.getIndex(x);
      final int pixelIdx=calInfo.getPixelIndex(x,calVecIdx);
      muX=(x - vec0.pixels[pixelIdx]) / (double)(vec0.pixels[pixelIdx + 1] - vec0.pixels[pixelIdx]);
      lutVal=(1 - muY) * ((1 - muX) * vec0LUT[pixelIdx] + muX * vec0LUT[pixelIdx + 1]) + muY * ((1 - muX) * vec1LUT[pixelIdx] + muX * vec1LUT[pixelIdx + 1]);
      if (dataType != null) {
        retroLutVal=(1 - muY) * ((1 - muX) * retroVec0LUT[pixelIdx] + muX * retroVec0LUT[pixelIdx + 1]) + muY * ((1 - muX) * retroVec1LUT[pixelIdx] + muX * retroVec1LUT[pixelIdx + 1]);
      }
      if (complexData) {
        i=srcData1.getElemDoubleAt(srcIdx);
        q=srcData2.getElemDoubleAt(srcIdx);
        trgData.setElemDoubleAt(trgIdx,(i * i + q * q) / (lutVal * lutVal));
      }
 else       if (bandUnit == Unit.UnitType.AMPLITUDE) {
        dn=srcData1.getElemDoubleAt(srcIdx);
        trgData.setElemDoubleAt(trgIdx,(dn * dn) / (lutVal * lutVal));
      }
 else {
        dn2=srcData1.getElemDoubleAt(srcIdx);
        trgData.setElemDoubleAt(trgIdx,dn2 * retroLutVal / (lutVal * lutVal));
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Called by the framework in order to compute a tile for the given target band. <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 * @param targetBand The target band.
 * @param targetTile The current tile associated with the target band to be computed.
 * @param pm         A progress monitor which should be used to determine computation cancelation requests.
 * @throws org.esa.beam.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
public void computeTile(Band targetBand,Tile targetTile,ProgressMonitor pm) throws OperatorException {
  final Rectangle targetTileRectangle=targetTile.getRectangle();
  final int x0=targetTileRectangle.x;
  final int y0=targetTileRectangle.y;
  final int w=targetTileRectangle.width;
  final int h=targetTileRectangle.height;
  Tile sourceRaster1=null;
  ProductData srcData1=null;
  ProductData srcData2=null;
  Band sourceBand1=null;
  final String targetBandName=targetBand.getName();
  final String[] srcBandNames=targetBandNameToSourceBandName.get(targetBandName);
  if (srcBandNames.length == 1) {
    sourceBand1=sourceProduct.getBand(srcBandNames[0]);
    sourceRaster1=calibrationOp.getSourceTile(sourceBand1,targetTileRectangle);
    srcData1=sourceRaster1.getDataBuffer();
  }
 else {
    sourceBand1=sourceProduct.getBand(srcBandNames[0]);
    final Band sourceBand2=sourceProduct.getBand(srcBandNames[1]);
    sourceRaster1=calibrationOp.getSourceTile(sourceBand1,targetTileRectangle);
    final Tile sourceRaster2=calibrationOp.getSourceTile(sourceBand2,targetTileRectangle);
    srcData1=sourceRaster1.getDataBuffer();
    srcData2=sourceRaster2.getDataBuffer();
  }
  final Unit.UnitType bandUnit=Unit.getUnitType(sourceBand1);
  final ProductData trgData=targetTile.getDataBuffer();
  final TileIndex srcIndex=new TileIndex(sourceRaster1);
  final TileIndex trgIndex=new TileIndex(targetTile);
  final int maxY=y0 + h;
  final int maxX=x0 + w;
  final boolean complexData=bandUnit == Unit.UnitType.REAL || bandUnit == Unit.UnitType.IMAGINARY;
  final CalibrationInfo calInfo=targetBandToCalInfo.get(targetBandName);
  final Sentinel1Calibrator.CALTYPE calType=Sentinel1Calibrator.getCalibrationType(targetBandName);
  double dn, dn2, i, q, muX, lutVal, retroLutVal=1.0;
  int srcIdx, trgIdx;
  for (int y=y0; y < maxY; ++y) {
    srcIndex.calculateStride(y);
    trgIndex.calculateStride(y);
    final int calVecIdx=calInfo.getCalibrationVectorIndex(y);
    final Sentinel1Utils.CalibrationVector vec0=calInfo.getCalibrationVector(calVecIdx);
    final Sentinel1Utils.CalibrationVector vec1=calInfo.getCalibrationVector(calVecIdx + 1);
    final float[] vec0LUT=getVector(calType,vec0);
    final float[] vec1LUT=getVector(calType,vec1);
    float[] retroVec0LUT=null;
    float[] retroVec1LUT=null;
    if (dataType != null) {
      retroVec0LUT=getVector(dataType,vec0);
      retroVec1LUT=getVector(dataType,vec1);
    }
    final double azTime=calInfo.firstLineTime + y * calInfo.lineTimeInterval;
    final double muY=(azTime - vec0.timeMJD) / (vec1.timeMJD - vec0.timeMJD);
    for (int x=x0; x < maxX; ++x) {
      srcIdx=srcIndex.getIndex(x);
      trgIdx=trgIndex.getIndex(x);
      final int pixelIdx=calInfo.getPixelIndex(x,calVecIdx);
      muX=(x - vec0.pixels[pixelIdx]) / (double)(vec0.pixels[pixelIdx + 1] - vec0.pixels[pixelIdx]);
      lutVal=(1 - muY) * ((1 - muX) * vec0LUT[pixelIdx] + muX * vec0LUT[pixelIdx + 1]) + muY * ((1 - muX) * vec1LUT[pixelIdx] + muX * vec1LUT[pixelIdx + 1]);
      if (dataType != null) {
        retroLutVal=(1 - muY) * ((1 - muX) * retroVec0LUT[pixelIdx] + muX * retroVec0LUT[pixelIdx + 1]) + muY * ((1 - muX) * retroVec1LUT[pixelIdx] + muX * retroVec1LUT[pixelIdx + 1]);
      }
      if (complexData) {
        i=srcData1.getElemDoubleAt(srcIdx);
        q=srcData2.getElemDoubleAt(srcIdx);
        trgData.setElemDoubleAt(trgIdx,(i * i + q * q) / (lutVal * lutVal));
      }
 else       if (bandUnit == Unit.UnitType.AMPLITUDE) {
        dn=srcData1.getElemDoubleAt(srcIdx);
        trgData.setElemDoubleAt(trgIdx,(dn * dn) / (lutVal * lutVal));
      }
 else {
        dn2=srcData1.getElemDoubleAt(srcIdx);
        trgData.setElemDoubleAt(trgIdx,dn2 * retroLutVal / (lutVal * lutVal));
      }
    }
  }
}