Index: trunk/psModules/src/pmSubtractBias.c
===================================================================
--- trunk/psModules/src/pmSubtractBias.c	(revision 2848)
+++ trunk/psModules/src/pmSubtractBias.c	(revision 2849)
@@ -6,6 +6,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-29 22:44:33 $
+ *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-30 00:34:02 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -159,7 +159,5 @@
 {
     psTrace(".psModule.pmSubtracBias.ScaleOverscanVector", 4,
-            "---- ScaleOverscanVector() begin ----\n");
-
-    printf("HMMM: fit is %d\n", fit);
+            "---- ScaleOverscanVector() begin (%d -> %d) ----\n", overscanVector->n, n);
 
     if (NULL == overscanVector) {
@@ -196,6 +194,15 @@
         }
     } else if (fit == PM_FIT_SPLINE) {
+        psS32 mustFreeSpline = 0;
         // Fit a spline to the old overscan vector.
         mySpline = (psSpline1D *) fitSpec;
+        if (mySpline == NULL) {
+            mustFreeSpline = 1;
+        }
+        //
+        // NOTE: Since the X arg in the psVectorFitSpline1D() function is NULL,
+        // splines enpoints will be from 0.0 to overscanVector->n-1.  Must scale
+        // properly when doing the spline eval.
+        //
         mySpline = psVectorFitSpline1D(mySpline, NULL, overscanVector, NULL);
 
@@ -204,7 +211,12 @@
         // interpolated value at that point, and set the new vector.
         for (i=0;i<n;i++) {
-            x = ((float) i) * ((float) overscanVector->n) / ((float) n);
+            // Scale to [0 : overscanVector->n - 1]
+            x = ((float) i) * ((float) (overscanVector->n-1)) / ((float) n);
             newVec->data.F32[i] = psSpline1DEval(mySpline, x);
         }
+        if (mustFreeSpline ==1) {
+            psFree(mySpline);
+        }
+
     } else {
         psError(PS_ERR_UNKNOWN, true, "unknown fit type\n");
@@ -226,5 +238,5 @@
 {
     psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4,
-            "---- ScaleOverscanVector() begin ----\n");
+            "---- pmSubtractBias() begin ----\n");
     PS_READOUT_CHECK_NULL(in, NULL);
     PS_READOUT_CHECK_EMPTY(in, NULL);
@@ -335,5 +347,5 @@
                 overscanVector->data.F32[i] = 0.0;
             }
-            tmpRow = psVectorAlloc((in->image)->numRows, PS_TYPE_F32);
+            tmpRow = psVectorAlloc(myOverscanImage->numRows, PS_TYPE_F32);
 
             // For each column of the input image, loop through every row,
@@ -378,5 +390,5 @@
                 overscanVector->data.F32[i] = 0.0;
             }
-            tmpCol = psVectorAlloc((in->image)->numCols, PS_TYPE_F32);
+            tmpCol = psVectorAlloc(myOverscanImage->numCols, PS_TYPE_F32);
 
             // For each row of the input image, loop through every column,
@@ -449,4 +461,5 @@
         // image divided by numBins.
         //
+
         if (!((fitSpec == NULL) || (fit == PM_FIT_NONE))) {
             //
@@ -482,5 +495,4 @@
                         tmpF32 = psSpline1DEval(mySpline, ((float) i) / ((float) nBin));
                     }
-
                     for (j=0;j<(in->image)->numRows;j++) {
                         (in->image)->data.F32[j][i]-= tmpF32;
@@ -541,5 +553,5 @@
 
     psTrace(".psModule.pmSubtracBias.pmSubtractBias", 4,
-            "---- ScaleOverscanVector() exit ----\n");
+            "---- pmSubtractBias() exit ----\n");
 
     if (bias != NULL) {
