Program: 11425
Project: 11425
Buggy source:
public static double crossCorrelateFFT(double[] offset,ComplexDoubleMatrix master,ComplexDoubleMatrix mask,int ovsfactor,int AccL,int AccP){
  final int L=master.rows;
  final int P=master.columns;
  final int twoL=2 * L;
  final int twoP=2 * P;
  final int halfL=L / 2;
  final int halfP=P / 2;
  double offsetL;
  double offsetP;
  if (master.rows != mask.rows || master.columns != mask.columns) {
    logger.severe("String_Node_Str");
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (!(MathUtils.isPower2(L) || MathUtils.isPower2(P))) {
    logger.severe("String_Node_Str");
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (!MathUtils.isPower2(ovsfactor)) {
    logger.severe("String_Node_Str");
    throw new IllegalArgumentException("String_Node_Str");
  }
  logger.info("String_Node_Str");
  DoubleMatrix magMaster=SarUtils.magnitude(master);
  DoubleMatrix magMask=SarUtils.magnitude(mask);
  magMaster.subi(magMaster.mean());
  magMask.subi(magMask.mean());
  ComplexDoubleMatrix master2=ComplexDoubleMatrix.zeros(twoL,twoP);
  ComplexDoubleMatrix mask2=ComplexDoubleMatrix.zeros(twoL,twoP);
  Window windef=new Window();
  Window win1=new Window(0,L - 1,0,P - 1);
  Window win2=new Window(halfL,halfL + L - 1,halfP,halfP + P - 1);
  LinearAlgebraUtils.setdata(master2,win1,new ComplexDoubleMatrix(magMaster),windef);
  LinearAlgebraUtils.setdata(mask2,win2,new ComplexDoubleMatrix(magMask),windef);
  SpectralUtils.fft2D_inplace(master2);
  SpectralUtils.fft2D_inplace(mask2);
  master2.conji();
  mask2.muli(master2);
  SpectralUtils.invfft2D_inplace(mask2);
  master2=ComplexDoubleMatrix.zeros(twoL,twoP);
  int l, p;
  for (l=L; l < twoL; ++l) {
    for (p=P; p < twoP; ++p) {
      double realPart=magMaster.get(twoL - 1 - l,twoP - 1 - p);
      double imagPart=magMask.get(l - L,p - P);
      ComplexDouble value=new ComplexDouble(FastMath.pow(realPart,2),FastMath.pow(imagPart,2));
      master2.put(l,p,value);
    }
  }
  ComplexDoubleMatrix BLOCK=new ComplexDoubleMatrix(0,0);
  if (BLOCK.rows != twoL || BLOCK.columns != twoP) {
    logger.info("String_Node_Str" + twoL + "String_Node_Str"+ twoP+ "String_Node_Str");
    BLOCK.resize(twoL,twoP);
    for (l=halfL; l < halfL + L; ++l)     for (p=halfP; p < halfP + P; ++p)     BLOCK.put(l,p,new ComplexDouble(1,0));
    SpectralUtils.fft2D_inplace(BLOCK);
    BLOCK.conji();
  }
  SpectralUtils.fft2D_inplace(master2);
  master2.muli(BLOCK);
  SpectralUtils.invfft2D_inplace(master2);
  DoubleMatrix Covar=new DoubleMatrix(L + 1,P + 1);
  double maxCorr=-999.0f;
  long maxcorrL=0;
  long maxcorrP=0;
  ComplexDouble maskValueTemp;
  ComplexDouble master2ValueTemp;
  for (l=0; l <= L; ++l) {
    for (p=0; p <= P; ++p) {
      maskValueTemp=mask2.get(l,p);
      master2ValueTemp=master2.get(l,p);
      Covar.put(l,p,maskValueTemp.real() / Math.sqrt(master2ValueTemp.real() * master2ValueTemp.imag()));
      if (Covar.get(l,p) > maxCorr) {
        maxCorr=Covar.get(l,p);
        maxcorrL=l;
        maxcorrP=p;
      }
    }
  }
  offsetL=-halfL + maxcorrL;
  offsetP=-halfP + maxcorrP;
  logger.info("String_Node_Str" + offsetL + "String_Node_Str"+ offsetP+ "String_Node_Str"+ maxCorr+ "String_Node_Str");
  if (ovsfactor > 1) {
    if (maxcorrL < AccL) {
      logger.info("String_Node_Str");
      maxcorrL=AccL;
    }
    if (maxcorrP < AccP) {
      logger.info("String_Node_Str");
      maxcorrP=AccP;
    }
    if (maxcorrL > (L - AccL)) {
      logger.info("String_Node_Str");
      maxcorrL=L - AccL;
    }
    if (maxcorrP > (P - AccP)) {
      logger.info("String_Node_Str");
      maxcorrP=P - AccP;
    }
    Window win3=new Window(maxcorrL - AccL,maxcorrL + AccL - 1,maxcorrP - AccP,maxcorrP + AccP - 1);
    final DoubleMatrix chip=new DoubleMatrix((int)win3.lines(),(int)win3.pixels());
    LinearAlgebraUtils.setdata(chip,Covar,win3);
    DoubleMatrix chipOversampled=SarUtils.oversample(new ComplexDoubleMatrix(chip),ovsfactor,ovsfactor).getReal();
    int corrIndex=chipOversampled.argmax();
    if (corrIndex >= 0) {
      int offL=chipOversampled.indexColumns(corrIndex);
      int offP=chipOversampled.indexRows(corrIndex);
      maxCorr=chipOversampled.get(corrIndex);
      offsetL=-halfL + maxcorrL - AccL + (double)offL / (double)ovsfactor;
      offsetP=-halfP + maxcorrP - AccP + (double)offP / (double)ovsfactor;
    }
    logger.info("String_Node_Str" + ovsfactor);
    logger.info("String_Node_Str" + offsetL + "String_Node_Str"+ offsetP+ "String_Node_Str"+ maxCorr+ "String_Node_Str");
    logger.info("String_Node_Str" + offsetL + "String_Node_Str"+ offsetP+ "String_Node_Str"+ maxCorr+ "String_Node_Str");
  }
  offset[0]=offsetL;
  offset[1]=offsetP;
  return maxCorr;
}

Fixed version (ground truth):
public static double crossCorrelateFFT(double[] offset,ComplexDoubleMatrix master,ComplexDoubleMatrix mask,int ovsfactor,int AccL,int AccP){
  final int L=master.rows;
  final int P=master.columns;
  final int twoL=2 * L;
  final int twoP=2 * P;
  final int halfL=L / 2;
  final int halfP=P / 2;
  double offsetL;
  double offsetP;
  if (master.rows != mask.rows || master.columns != mask.columns) {
    logger.severe("String_Node_Str");
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (!(MathUtils.isPower2(L) || MathUtils.isPower2(P))) {
    logger.severe("String_Node_Str");
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (!MathUtils.isPower2(ovsfactor)) {
    logger.severe("String_Node_Str");
    throw new IllegalArgumentException("String_Node_Str");
  }
  logger.info("String_Node_Str");
  DoubleMatrix magMaster=SarUtils.magnitude(master);
  DoubleMatrix magMask=SarUtils.magnitude(mask);
  magMaster.subi(magMaster.mean());
  magMask.subi(magMask.mean());
  ComplexDoubleMatrix master2=ComplexDoubleMatrix.zeros(twoL,twoP);
  ComplexDoubleMatrix mask2=ComplexDoubleMatrix.zeros(twoL,twoP);
  Window windef=new Window();
  Window win1=new Window(0,L - 1,0,P - 1);
  Window win2=new Window(halfL,halfL + L - 1,halfP,halfP + P - 1);
  LinearAlgebraUtils.setdata(master2,win1,new ComplexDoubleMatrix(magMaster),windef);
  LinearAlgebraUtils.setdata(mask2,win2,new ComplexDoubleMatrix(magMask),windef);
  SpectralUtils.fft2D_inplace(master2);
  SpectralUtils.fft2D_inplace(mask2);
  master2.conji();
  mask2.muli(master2);
  SpectralUtils.invfft2D_inplace(mask2);
  master2=ComplexDoubleMatrix.zeros(twoL,twoP);
  int l, p;
  for (l=L; l < twoL; ++l) {
    for (p=P; p < twoP; ++p) {
      double realPart=magMaster.get(twoL - 1 - l,twoP - 1 - p);
      double imagPart=magMask.get(l - L,p - P);
      ComplexDouble value=new ComplexDouble(FastMath.pow(realPart,2),FastMath.pow(imagPart,2));
      master2.put(l,p,value);
    }
  }
  ComplexDoubleMatrix BLOCK=new ComplexDoubleMatrix(0,0);
  if (BLOCK.rows != twoL || BLOCK.columns != twoP) {
    logger.info("String_Node_Str" + twoL + "String_Node_Str"+ twoP+ "String_Node_Str");
    BLOCK.resize(twoL,twoP);
    for (l=halfL; l < halfL + L; ++l)     for (p=halfP; p < halfP + P; ++p)     BLOCK.put(l,p,new ComplexDouble(1,0));
    SpectralUtils.fft2D_inplace(BLOCK);
    BLOCK.conji();
  }
  SpectralUtils.fft2D_inplace(master2);
  master2.muli(BLOCK);
  SpectralUtils.invfft2D_inplace(master2);
  DoubleMatrix Covar=new DoubleMatrix(L + 1,P + 1);
  double maxCorr=-999.0f;
  long maxcorrL=0;
  long maxcorrP=0;
  ComplexDouble maskValueTemp;
  ComplexDouble master2ValueTemp;
  for (l=0; l <= L; ++l) {
    for (p=0; p <= P; ++p) {
      maskValueTemp=mask2.get(l,p);
      master2ValueTemp=master2.get(l,p);
      Covar.put(l,p,maskValueTemp.real() / Math.sqrt(master2ValueTemp.real() * master2ValueTemp.imag()));
      if (Covar.get(l,p) > maxCorr) {
        maxCorr=Covar.get(l,p);
        maxcorrL=l;
        maxcorrP=p;
      }
    }
  }
  offsetL=-halfL + maxcorrL;
  offsetP=-halfP + maxcorrP;
  logger.info("String_Node_Str" + offsetL + "String_Node_Str"+ offsetP+ "String_Node_Str"+ maxCorr+ "String_Node_Str");
  if (ovsfactor > 1) {
    if (maxcorrL < AccL) {
      logger.info("String_Node_Str");
      maxcorrL=AccL;
    }
    if (maxcorrP < AccP) {
      logger.info("String_Node_Str");
      maxcorrP=AccP;
    }
    if (maxcorrL > (L - AccL)) {
      logger.info("String_Node_Str");
      maxcorrL=L - AccL;
    }
    if (maxcorrP > (P - AccP)) {
      logger.info("String_Node_Str");
      maxcorrP=P - AccP;
    }
    Window win3=new Window(maxcorrL - AccL,maxcorrL + AccL - 1,maxcorrP - AccP,maxcorrP + AccP - 1);
    final DoubleMatrix chip=new DoubleMatrix((int)win3.lines(),(int)win3.pixels());
    LinearAlgebraUtils.setdata(chip,Covar,win3);
    DoubleMatrix chipOversampled=SarUtils.oversample(new ComplexDoubleMatrix(chip),ovsfactor,ovsfactor).getReal();
    int corrIndex=chipOversampled.argmax();
    if (corrIndex >= 0) {
      int offP=chipOversampled.indexColumns(corrIndex);
      int offL=chipOversampled.indexRows(corrIndex);
      maxCorr=chipOversampled.get(corrIndex);
      offsetL=-halfL + maxcorrL - AccL + (double)offL / (double)ovsfactor;
      offsetP=-halfP + maxcorrP - AccP + (double)offP / (double)ovsfactor;
    }
    logger.info("String_Node_Str" + ovsfactor);
    logger.info("String_Node_Str" + offsetL + "String_Node_Str"+ offsetP+ "String_Node_Str"+ maxCorr+ "String_Node_Str");
    logger.info("String_Node_Str" + offsetL + "String_Node_Str"+ offsetP+ "String_Node_Str"+ maxCorr+ "String_Node_Str");
  }
  offset[0]=offsetL;
  offset[1]=offsetP;
  return maxCorr;
}