private double[] interpolateNonZeroValues(double[] contour){
  for (int i=0; i < contour.length; i++) {
    if (contour[i] == 0) {
      int index=findNextIndexNonZero(contour,i);
      if (index == -1) {
        for (int j=i; j < contour.length; j++) {
          contour[j]=contour[j - 1];
        }
        break;
      }
 else {
        for (int j=i; j < index; j++) {
          if (i == 0) {
            contour[j]=contour[index];
          }
 else {
            contour[j]=contour[j - 1] + ((contour[index] - contour[i - 1]) / (index - i));
          }
        }
        i=index - 1;
      }
    }
  }
  return contour;
}

private double [ ] interpolateNonZeroValues ( double [ ] contour ) { for ( int i = 0 ; i < contour . length ; i ++ ) { if ( contour [ i ] == 0 ) { int index = findNextIndexNonZero ( contour , i ) ; if ( index == - 1 ) { for ( int j = i ; j < contour . length ; j ++ ) { contour [ j ] = contour [ j - 1 ] ; } break ; } else { for ( int j = i ; j < index ; j ++ ) { if ( i == 0 ) { contour [ j ] = contour [ index ] ; } else { contour [ j ] = contour [ j - 1 ] + ( ( contour [ index ] - contour [ i - 1 ] ) / ( index - i ) ) ; } } i = index - 1 ; } } } return contour ; }
to interpolate zero values with respect to nonzero values
