Program: 11596
Project: 11596
Buggy source:
/** 
 * contour is a contouring subroutine for rectangularly spaced data It emits calls to a line drawing subroutine supplied by the user which draws a contour map corresponding to real*4data on a randomly spaced rectangular grid. The coordinates emitted are in the same units given in the x() and y() arrays. Any number of contour levels may be specified but they must be in order of increasing value.
 * @param d  - matrix of data to contour
 * @param ilb,iub,jlb,jub - index bounds of data matrixThe following two, one dimensional arrays (x and y) contain the horizontal and vertical coordinates of each sample points.
 * @param x  - data matrix column coordinates
 * @param y  - data matrix row coordinates
 * @param nc - number of contour levels
 * @param z  - contour levels in increasing order.
 */
public void contour(double[][] d,int ilb,int iub,int jlb,int jub,double[] x,double[] y,int nc,double[] z){
  int m1;
  int m2;
  int m3;
  int case_value;
  double dmin;
  double dmax;
  double x1=0.0;
  double x2=0.0;
  double y1=0.0;
  double y2=0.0;
  int i, j, k, m;
  int[] im={0,1,1,0};
  int[] jm={0,0,1,1};
  int[][][] castab={{{0,0,8},{0,2,5},{7,6,9}},{{0,3,4},{1,3,1},{4,3,0}},{{9,6,7},{5,2,0},{8,0,0}}};
  double z_0=z[0];
  double z_n=z[nc - 1];
  double z_k;
  double d_i0j0, d_i0j1, d_i1j0, d_i1j1;
  double temp1, temp2;
  for (i=ilb; i <= iub - 1; i++) {
    final float[] d_i0=d[i];
    final float[] d_i1=d[i + 1];
    for (j=jlb; j <= jub - 1; j++) {
      d_i0j0=d_i0[j];
      d_i0j1=d_i0[j + 1];
      d_i1j0=d_i1[j];
      d_i1j1=d_i1[j + 1];
      temp1=Math.min(d_i0j0,d_i0j1);
      temp2=Math.min(d_i1j0,d_i1j1);
      dmin=Math.min(temp1,temp2);
      temp1=Math.max(d_i0j0,d_i0j1);
      temp2=Math.max(d_i1j0,d_i1j1);
      dmax=Math.max(temp1,temp2);
      if (z_0 <= dmax && dmin <= z_n) {
        for (k=0; k < nc; k++) {
          z_k=z[k];
          if (dmin <= z_k && z_k <= dmax) {
            for (m=4; m >= 0; m--) {
              if (m > 0) {
                h[m]=d[i + im[m - 1]][j + jm[m - 1]] - z_k;
                xh[m]=x[i + im[m - 1]];
                yh[m]=y[j + jm[m - 1]];
              }
 else {
                h[0]=0.25 * (h[1] + h[2] + h[3]+ h[4]);
                xh[0]=0.5 * (x[i] + x[i + 1]);
                yh[0]=0.5 * (y[j] + y[j + 1]);
              }
              if (h[m] > 0.0) {
                sh[m]=1;
              }
 else               if (h[m] < 0.0) {
                sh[m]=-1;
              }
 else               sh[m]=0;
            }
            for (m=1; m <= 4; m++) {
              m1=m;
              m2=0;
              if (m != 4) {
                m3=m + 1;
              }
 else {
                m3=1;
              }
              case_value=castab[sh[m1] + 1][sh[m2] + 1][sh[m3] + 1];
              if (case_value != 0) {
switch (case_value) {
case 1:
                  x1=xh[m1];
                y1=yh[m1];
              x2=xh[m2];
            y2=yh[m2];
          break;
case 2:
        x1=xh[m2];
      y1=yh[m2];
    x2=xh[m3];
  y2=yh[m3];
break;
case 3:
x1=xh[m3];
y1=yh[m3];
x2=xh[m1];
y2=yh[m1];
break;
case 4:
x1=xh[m1];
y1=yh[m1];
x2=xsect(m2,m3);
y2=ysect(m2,m3);
break;
case 5:
x1=xh[m2];
y1=yh[m2];
x2=xsect(m3,m1);
y2=ysect(m3,m1);
break;
case 6:
x1=xh[m3];
y1=yh[m3];
x2=xsect(m1,m2);
y2=ysect(m1,m2);
break;
case 7:
x1=xsect(m1,m2);
y1=ysect(m1,m2);
x2=xsect(m2,m3);
y2=ysect(m2,m3);
break;
case 8:
x1=xsect(m2,m3);
y1=ysect(m2,m3);
x2=xsect(m3,m1);
y2=ysect(m3,m1);
break;
case 9:
x1=xsect(m3,m1);
y1=ysect(m3,m1);
x2=xsect(m1,m2);
y2=ysect(m1,m2);
break;
default :
break;
}
render.drawContour(x1,y1,x2,y2,z[k]);
}
}
}
}
}
}
}
}

Fixed version (ground truth):
/** 
 * contour is a contouring subroutine for rectangularly spaced data It emits calls to a line drawing subroutine supplied by the user which draws a contour map corresponding to real*4data on a randomly spaced rectangular grid. The coordinates emitted are in the same units given in the x() and y() arrays. Any number of contour levels may be specified but they must be in order of increasing value.
 * @param d  - matrix of data to contour
 * @param ilb,iub,jlb,jub - index bounds of data matrixThe following two, one dimensional arrays (x and y) contain the horizontal and vertical coordinates of each sample points.
 * @param x  - data matrix column coordinates
 * @param y  - data matrix row coordinates
 * @param nc - number of contour levels
 * @param z  - contour levels in increasing order.
 */
public void contour(double[][] d,int ilb,int iub,int jlb,int jub,double[] x,double[] y,int nc,double[] z){
  int m1;
  int m2;
  int m3;
  int case_value;
  double dmin;
  double dmax;
  double x1=0.0;
  double x2=0.0;
  double y1=0.0;
  double y2=0.0;
  int i, j, k, m;
  int[] im={0,1,1,0};
  int[] jm={0,0,1,1};
  int[][][] castab={{{0,0,8},{0,2,5},{7,6,9}},{{0,3,4},{1,3,1},{4,3,0}},{{9,6,7},{5,2,0},{8,0,0}}};
  double z_0=z[0];
  double z_n=z[nc - 1];
  double z_k;
  double d_i0j0, d_i0j1, d_i1j0, d_i1j1;
  double temp1, temp2;
  for (i=ilb; i <= iub - 1; i++) {
    final float[] d_i0=d[i];
    final float[] d_i1=d[i + 1];
    for (j=jlb; j <= jub - 1; j++) {
      d_i0j0=d_i0[j];
      d_i0j1=d_i0[j + 1];
      d_i1j0=d_i1[j];
      d_i1j1=d_i1[j + 1];
      temp1=Math.min(d_i0j0,d_i0j1);
      temp2=Math.min(d_i1j0,d_i1j1);
      dmin=Math.min(temp1,temp2);
      temp1=Math.max(d_i0j0,d_i0j1);
      temp2=Math.max(d_i1j0,d_i1j1);
      dmax=Math.max(temp1,temp2);
      if (z_0 <= dmax && dmin <= z_n) {
        for (k=0; k < nc; k++) {
          z_k=z[k];
          if (dmin == z_k && z_k == dmax)           continue;
          if (dmin <= z_k && z_k <= dmax) {
            for (m=4; m >= 0; m--) {
              if (m > 0) {
                h[m]=d[i + im[m - 1]][j + jm[m - 1]] - z_k;
                xh[m]=x[i + im[m - 1]];
                yh[m]=y[j + jm[m - 1]];
              }
 else {
                h[0]=0.25 * (h[1] + h[2] + h[3]+ h[4]);
                xh[0]=0.5 * (x[i] + x[i + 1]);
                yh[0]=0.5 * (y[j] + y[j + 1]);
              }
              if (h[m] > 0.0) {
                sh[m]=1;
              }
 else               if (h[m] < 0.0) {
                sh[m]=-1;
              }
 else               sh[m]=0;
            }
            for (m=1; m <= 4; m++) {
              m1=m;
              m2=0;
              if (m != 4) {
                m3=m + 1;
              }
 else {
                m3=1;
              }
              case_value=castab[sh[m1] + 1][sh[m2] + 1][sh[m3] + 1];
              if (case_value != 0) {
switch (case_value) {
case 1:
                  x1=xh[m1];
                y1=yh[m1];
              x2=xh[m2];
            y2=yh[m2];
          break;
case 2:
        x1=xh[m2];
      y1=yh[m2];
    x2=xh[m3];
  y2=yh[m3];
break;
case 3:
x1=xh[m3];
y1=yh[m3];
x2=xh[m1];
y2=yh[m1];
break;
case 4:
x1=xh[m1];
y1=yh[m1];
x2=xsect(m2,m3);
y2=ysect(m2,m3);
break;
case 5:
x1=xh[m2];
y1=yh[m2];
x2=xsect(m3,m1);
y2=ysect(m3,m1);
break;
case 6:
x1=xh[m3];
y1=yh[m3];
x2=xsect(m1,m2);
y2=ysect(m1,m2);
break;
case 7:
x1=xsect(m1,m2);
y1=ysect(m1,m2);
x2=xsect(m2,m3);
y2=ysect(m2,m3);
break;
case 8:
x1=xsect(m2,m3);
y1=ysect(m2,m3);
x2=xsect(m3,m1);
y2=ysect(m3,m1);
break;
case 9:
x1=xsect(m3,m1);
y1=ysect(m3,m1);
x2=xsect(m1,m2);
y2=ysect(m1,m2);
break;
default :
break;
}
render.drawContour(x1,y1,x2,y2,z[k]);
}
}
}
}
}
}
}
}