Program: 11463
Project: 11463
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.snap.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
@Override 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;
  Band sourceBand1;
  Tile sourceRaster1;
  ProductData srcData1;
  ProductData srcData2=null;
  final String[] srcBandNames=targetBandNameToSourceBandName.get(targetBand.getName());
  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(targetBand);
  if (bandUnit == Unit.UnitType.PHASE) {
    targetTile.setRawSamples(sourceRaster1.getRawSamples());
    return;
  }
  final String pol=OperatorUtils.getBandPolarization(srcBandNames[0],absRoot);
  int prodBand=0;
  if (pol != null && mdsPolar[1] != null && mdsPolar[1].contains(pol)) {
    prodBand=1;
  }
  final ProductData trgData=targetTile.getDataBuffer();
  final TileIndex srcIndex=new TileIndex(sourceRaster1);
  final TileIndex tgtIndex=new TileIndex(targetTile);
  final int maxY=y0 + h;
  final int maxX=x0 + w;
  final double[] incidenceAnglesArray=new double[w];
  final double[] slantRangeTimeArray=new double[w];
  double[][] targetTileOldAntPat=null;
  double[][] targetTileNewAntPat=null;
  double[][] targetTileSlantRange=null;
  if (applyAntennaPatternCorr) {
    targetTileNewAntPat=new double[h][w];
    targetTileSlantRange=new double[h][w];
    if (retroCalibrationFlag) {
      targetTileOldAntPat=new double[h][w];
    }
    if (wideSwathProductFlag) {
      computeWideSwathAntennaPatternForCurrentTile(x0,y0,w,h,targetTileOldAntPat,targetTileNewAntPat,targetTileSlantRange,slantRangeTPGInterp);
    }
 else {
      computeSingleSwathAntennaPatternForCurrentTile(x0,y0,w,h,targetTileOldAntPat,targetTileNewAntPat,targetTileSlantRange,prodBand,slantRangeTPGInterp);
    }
  }
  double sigma, dn, dn2, i, q, phaseTerm=0.0;
  final double theCalibrationFactor=newCalibrationConstant[prodBand];
  int srcIdx, tgtIdx;
  for (int y=y0, yy=0; y < maxY; ++y, ++yy) {
    srcIndex.calculateStride(y);
    tgtIndex.calculateStride(y);
    incidenceTPGInterp.getPixels(x0,y,w,1,incidenceAnglesArray,pm,TiePointInterpolator.InterpMode.QUADRATIC);
    if (applyRangeSpreadingCorr) {
      slantRangeTPGInterp.getPixels(x0,y,w,1,slantRangeTimeArray,pm,TiePointInterpolator.InterpMode.QUADRATIC);
    }
    for (int x=x0, xx=0; x < maxX; ++x, ++xx) {
      srcIdx=srcIndex.getIndex(x);
      tgtIdx=tgtIndex.getIndex(x);
      if (bandUnit == Unit.UnitType.AMPLITUDE) {
        dn=srcData1.getElemDoubleAt(srcIdx);
        dn2=dn * dn;
      }
 else       if (bandUnit == Unit.UnitType.INTENSITY) {
        dn2=srcData1.getElemDoubleAt(srcIdx);
      }
 else       if (bandUnit == Unit.UnitType.REAL) {
        i=srcData1.getElemDoubleAt(srcIdx);
        q=srcData2.getElemDoubleAt(srcIdx);
        dn2=i * i + q * q;
        if (outputImageInComplex) {
          phaseTerm=i / Math.sqrt(dn2);
        }
      }
 else       if (bandUnit == Unit.UnitType.IMAGINARY) {
        i=srcData1.getElemDoubleAt(srcIdx);
        q=srcData2.getElemDoubleAt(srcIdx);
        dn2=i * i + q * q;
        if (outputImageInComplex) {
          phaseTerm=q / Math.sqrt(dn2);
        }
      }
 else {
        throw new OperatorException("String_Node_Str");
      }
      double calFactor=1.0;
      if (retroCalibrationFlag) {
        calFactor*=targetTileOldAntPat[yy][xx];
      }
      calFactor*=FastMath.sin(incidenceAnglesArray[xx] * Constants.DTOR) / theCalibrationFactor;
      if (applyRangeSpreadingCorr && targetTileSlantRange != null) {
        calFactor*=FastMath.pow(targetTileSlantRange[yy][xx] / refSlantRange800km,rangeSpreadingCompPower);
      }
      if (applyAntennaPatternCorr) {
        calFactor/=targetTileNewAntPat[yy][xx];
      }
      sigma=dn2 * calFactor;
      if (isComplex && outputImageInComplex) {
        sigma=Math.sqrt(sigma) * phaseTerm;
      }
      if (outputImageScaleInDb) {
        if (sigma < underFlowFloat) {
          sigma=-underFlowFloat;
        }
 else {
          sigma=10.0 * Math.log10(sigma);
        }
      }
      trgData.setElemDoubleAt(tgtIdx,sigma);
    }
  }
}

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.snap.framework.gpf.OperatorException If an error occurs during computation of the target raster.
 */
@Override 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;
  Band sourceBand1;
  Tile sourceRaster1;
  ProductData srcData1;
  ProductData srcData2=null;
  final String[] srcBandNames=targetBandNameToSourceBandName.get(targetBand.getName());
  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 tgtBandUnit=Unit.getUnitType(targetBand);
  final Unit.UnitType srcBandUnit=Unit.getUnitType(sourceBand1);
  if (tgtBandUnit == Unit.UnitType.PHASE) {
    targetTile.setRawSamples(sourceRaster1.getRawSamples());
    return;
  }
  final String pol=OperatorUtils.getBandPolarization(srcBandNames[0],absRoot);
  int prodBand=0;
  if (pol != null && mdsPolar[1] != null && mdsPolar[1].contains(pol)) {
    prodBand=1;
  }
  final ProductData trgData=targetTile.getDataBuffer();
  final TileIndex srcIndex=new TileIndex(sourceRaster1);
  final TileIndex tgtIndex=new TileIndex(targetTile);
  final int maxY=y0 + h;
  final int maxX=x0 + w;
  final double[] incidenceAnglesArray=new double[w];
  final double[] slantRangeTimeArray=new double[w];
  double[][] targetTileOldAntPat=null;
  double[][] targetTileNewAntPat=null;
  double[][] targetTileSlantRange=null;
  if (applyAntennaPatternCorr) {
    targetTileNewAntPat=new double[h][w];
    targetTileSlantRange=new double[h][w];
    if (retroCalibrationFlag) {
      targetTileOldAntPat=new double[h][w];
    }
    if (wideSwathProductFlag) {
      computeWideSwathAntennaPatternForCurrentTile(x0,y0,w,h,targetTileOldAntPat,targetTileNewAntPat,targetTileSlantRange,slantRangeTPGInterp);
    }
 else {
      computeSingleSwathAntennaPatternForCurrentTile(x0,y0,w,h,targetTileOldAntPat,targetTileNewAntPat,targetTileSlantRange,prodBand,slantRangeTPGInterp);
    }
  }
  double sigma, dn, dn2, i, q, phaseTerm=0.0;
  final double theCalibrationFactor=newCalibrationConstant[prodBand];
  int srcIdx, tgtIdx;
  for (int y=y0, yy=0; y < maxY; ++y, ++yy) {
    srcIndex.calculateStride(y);
    tgtIndex.calculateStride(y);
    incidenceTPGInterp.getPixels(x0,y,w,1,incidenceAnglesArray,pm,TiePointInterpolator.InterpMode.QUADRATIC);
    if (applyRangeSpreadingCorr) {
      slantRangeTPGInterp.getPixels(x0,y,w,1,slantRangeTimeArray,pm,TiePointInterpolator.InterpMode.QUADRATIC);
    }
    for (int x=x0, xx=0; x < maxX; ++x, ++xx) {
      srcIdx=srcIndex.getIndex(x);
      tgtIdx=tgtIndex.getIndex(x);
      if (srcBandUnit == Unit.UnitType.AMPLITUDE) {
        dn=srcData1.getElemDoubleAt(srcIdx);
        dn2=dn * dn;
      }
 else       if (srcBandUnit == Unit.UnitType.INTENSITY) {
        dn2=srcData1.getElemDoubleAt(srcIdx);
      }
 else       if (srcBandUnit == Unit.UnitType.REAL) {
        i=srcData1.getElemDoubleAt(srcIdx);
        q=srcData2.getElemDoubleAt(srcIdx);
        dn2=i * i + q * q;
        if (tgtBandUnit == Unit.UnitType.REAL) {
          phaseTerm=i / Math.sqrt(dn2);
        }
 else         if (tgtBandUnit == Unit.UnitType.IMAGINARY) {
          phaseTerm=q / Math.sqrt(dn2);
        }
      }
 else {
        throw new OperatorException("String_Node_Str");
      }
      double calFactor=1.0;
      if (retroCalibrationFlag) {
        calFactor*=targetTileOldAntPat[yy][xx];
      }
      calFactor*=FastMath.sin(incidenceAnglesArray[xx] * Constants.DTOR) / theCalibrationFactor;
      if (applyRangeSpreadingCorr && targetTileSlantRange != null) {
        calFactor*=FastMath.pow(targetTileSlantRange[yy][xx] / refSlantRange800km,rangeSpreadingCompPower);
      }
      if (applyAntennaPatternCorr) {
        calFactor/=targetTileNewAntPat[yy][xx];
      }
      sigma=dn2 * calFactor;
      if (isComplex && outputImageInComplex) {
        sigma=Math.sqrt(sigma) * phaseTerm;
      }
      if (outputImageScaleInDb) {
        if (sigma < underFlowFloat) {
          sigma=-underFlowFloat;
        }
 else {
          sigma=10.0 * Math.log10(sigma);
        }
      }
      trgData.setElemDoubleAt(tgtIdx,sigma);
    }
  }
}