Index: trunk/psModules/src/detrend/pmSkySubtract.c
===================================================================
--- trunk/psModules/src/detrend/pmSkySubtract.c	(revision 12696)
+++ trunk/psModules/src/detrend/pmSkySubtract.c	(revision 12742)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-03-30 21:12:56 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-04-04 22:42:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,5 +35,5 @@
 DetermineNumBits(data): This routine takes an enum psStatsOptions as an
 argument and returns the number of non-zero bits.
- 
+
 XXX: This code is duplicated in the ReadoutCombine file.
  *****************************************************************************/
@@ -91,5 +91,5 @@
 input psImage and scales it smaller by a factor of binFactor.  The statistic
 used in combining input pixels is specified in statOptions.
- 
+
 XXX: use static vectors for myStats, binVector and binMask.
 XXX: I coded this before I was aware of a psLib reBin function.  I don't
@@ -163,7 +163,7 @@
 CalculatePolyTerms(xOrder, yOrder): this routine will calculate the number of
 coefficients (or terms) in a 2-D polynomial of order (xOrder, yOrder).
- 
+
 XXX: Use your brain and figure out the analytical expression.
- 
+
 XXX: Why isn't it simply (xOrder+1) * (yOrder+1)?
  *****************************************************************************/
@@ -199,5 +199,5 @@
     polyTerms[i][0] = the power to which X is raised in the i-th term of in an
     poly-order sky background polynomial.
- 
+
     polyTerms[i][1] = the power to which Y is raised in the i-th term of in an
     poly-order sky background polynomial.
@@ -248,7 +248,7 @@
 This procedure calculates various combinations of powers of x and y and stores
 them in the data structure p_psPolySums[][].  After it completes:
- 
+
     p_psPolySums[i][j] == x^i * y^j
- 
+
 XXX: Use a psImage for the p_psPolySums data structure?
 XXX: p_psPolySums: should this be a global?  Did you get the storage classifier
@@ -296,5 +296,5 @@
 used in this routine is based on that of the pilot project ADD, but is not
 documented anywhere.
- 
+
 XXX: Different trace message facilities in use here.
  *****************************************************************************/
@@ -471,9 +471,9 @@
 /******************************************************************************
 pmReadout pmSubtractSky():
- 
+
 XXX: use static vectors for myStats, and the binned image
- 
+
 XXX: The SDR is silent about types.  PS_TYPE_F32 is implemented here.
- 
+
 XXX: Sync the psTrace message facilities.
  *****************************************************************************/
@@ -691,4 +691,9 @@
         }
     } else {
+
+        psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR,
+                                                                           binnedImage, NULL, NULL, 0,
+                                                                           0.0, 0.0, 0, 0, 0.0);
+
         for (psS32 row = 0; row < trimmedImg->numRows ; row++) {
             for (psS32 col = 0; col < trimmedImg->numCols ; col++) {
@@ -705,14 +710,19 @@
                 binColF64+= 0.5;
 
-                psF32 binPixel = (psF32) psImagePixelInterpolate(
-                                     binnedImage, binColF64, binRowF64,
-                                     NULL, 0, 0.0, PS_INTERPOLATE_BILINEAR);
-                trimmedImg->data.F32[row][col]-= binPixel;
+                double binPixel;
+                if (!psImagePixelInterpolate(&binPixel, NULL, NULL, binColF64, binRowF64, interp)) {
+                    psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
+                    psFree(interp);
+                    psFree(binnedImage);
+                    return NULL;
+                }
+                trimmedImg->data.F32[row][col] -= binPixel;
 
                 psTrace("psModules.detrend", 8,
-                        "image[%d][%d] <--> binnedImage[%.2f][%.2f]: %f\n",
+                        "image[%d][%d] <--> binnedImage[%.2f][%.2f]: %lf\n",
                         row, col, binRowF64-0.5, binColF64-0.5, binPixel);
             }
         }
+        psFree(interp);
 
     }
