Index: /trunk/psModules/src/pmNonLinear.c
===================================================================
--- /trunk/psModules/src/pmNonLinear.c	(revision 2856)
+++ /trunk/psModules/src/pmNonLinear.c	(revision 2857)
@@ -3,8 +3,8 @@
  *  Provides polynomial or table lookup non-linearity corrections to readouts.
  *
- *  @author George Gusciora, MHPCC
+ *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-25 02:54:45 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-30 22:22:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,10 +31,10 @@
                                     const psPolynomial1D *coeff)
 {
-    int i;
-    int j;
-
     PS_PTR_CHECK_NULL(in,NULL);
     PS_PTR_CHECK_NULL(in->image, NULL);
     PS_PTR_CHECK_NULL(coeff,NULL);
+
+    psS32 i;
+    psS32 j;
 
     for (i=0;i<(in->image)->numRows;i++) {
@@ -63,19 +63,20 @@
     PS_PTR_CHECK_NULL(outFlux,NULL);
 
-    int i;
-    int j;
-    int tableSize = inFlux->n;
-    int binNum;
+    psS32 i;
+    psS32 j;
+    psS32 tableSize = inFlux->n;
+    psS32 binNum;
     psScalar x;
-    int numPixels = 0;
-    float slope;
+    psS32 numPixels = 0;
+    psF32 slope;
 
     x.type.type = PS_TYPE_F32;
     if (inFlux->n != outFlux->n) {
-        // XXX: psWarning("pmNonLinearityLookup(): input vectors have different size");
         tableSize = PS_MIN(inFlux->n, outFlux->n);
+        psLogMsg(__func__, PS_LOG_WARN,
+                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): input vectors have different sizes (%d, %d)\n", inFlux->n, outFlux->n);
     }
     if (inFlux->n < 2) {
-        // XXX: psWarning("pmNonLinearityLookup(): input vector less than 2 elements");
+        psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): input vector less than 2 elements.  Returning in image.");
         return(in);
     }
@@ -96,4 +97,9 @@
 
                 numPixels++;
+            } else if (binNum < -2) {
+                // We get here if there was some other problem.
+                psError(PS_ERR_UNKNOWN,true, "pmNonLinearityLookup(): Could not perform p_psVectorBinDisect().  Returning in image.");
+                return(in);
+                numPixels++;
             } else {
                 // Perform linear interpolation.
@@ -106,5 +112,6 @@
     }
     if (numPixels > 0) {
-        // XXX: psWarning("Warning: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
+        psLogMsg(__func__, PS_LOG_WARN,
+                 "WARNING: pmNonLinear.c: pmNonLinearityLookup(): %d pixels outside table.", numPixels);
     }
     return(in);
Index: /trunk/psModules/src/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/pmReadoutCombine.c	(revision 2856)
+++ /trunk/psModules/src/pmReadoutCombine.c	(revision 2857)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-27 23:16:51 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-30 22:22:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -82,5 +82,5 @@
     if (1 < DetermineNumBits(params->stats->options)) {
         psError(PS_ERR_UNKNOWN, true,
-                "Multiple statistical options have been requested.\n");
+                "Multiple statistical options have been requested.  Returning NULL.\n");
         return(NULL);
     }
@@ -128,5 +128,5 @@
         PS_VECTOR_CHECK_TYPE(zero, PS_TYPE_F32, NULL);
         if (numInputs > zero->n) {
-            psError(PS_ERR_UNKNOWN, true, "zero vector has incorrect size (%d)\n", zero->n);
+            psError(PS_ERR_UNKNOWN, true, "zero vector has incorrect size (%d).  Returning NULL.\n", zero->n);
             return(NULL);
         } else if (numInputs < zero->n) {
@@ -140,5 +140,5 @@
         PS_VECTOR_CHECK_TYPE(scale, PS_TYPE_F32, NULL);
         if (numInputs > scale->n) {
-            psError(PS_ERR_UNKNOWN, true, "scale vector has incorrect size (%d)\n", scale->n);
+            psError(PS_ERR_UNKNOWN, true, "scale vector has incorrect size (%d).  Returning NULL.\n", scale->n);
             return(NULL);
         } else if (numInputs < scale->n) {
@@ -163,5 +163,5 @@
                 ((output->row0 + output->numRows) < maxInputRows)) {
             psError(PS_ERR_UNKNOWN, true,
-                    "Output image (%d, %d) is too small to hold combined images.\n",
+                    "Output image (%d, %d) is too small to hold combined images.  Returning NULL.\n",
                     output->row0 + output->numRows,
                     output->col0 + output->numCols);
@@ -171,5 +171,5 @@
         if ((output->col0 > minInputCols) || (output->row0 > minInputRows)) {
             psError(PS_ERR_UNKNOWN, true,
-                    "Output image offset is larger then input image offset.\n");
+                    "Output image offset is larger then input image offset.  Returning NULL.\n");
             return(NULL);
         }
@@ -313,9 +313,13 @@
                 }
                 // Calculate the specified statistic on the stack of pixels.
-                stats = psVectorStats(stats,
-                                      tmpPixels,
-                                      tmpPixelErrors,
-                                      tmpPixelMaskNKeep,
-                                      1);
+                psStats *rc = psVectorStats(stats,
+                                            tmpPixels,
+                                            tmpPixelErrors,
+                                            tmpPixelMaskNKeep,
+                                            1);
+                if (rc == NULL) {
+                    psError(PS_ERR_UNKNOWN, false, "psVectorStats(): could not perform requested statistical operation.  Returning NULL.\n");
+                    return(NULL);
+                }
             } else {
                 if (scale != NULL) {
@@ -333,9 +337,13 @@
 
                 // Calculate the specified statistic on the stack of pixels.
-                stats = psVectorStats(stats,
-                                      tmpPixels,
-                                      NULL,
-                                      tmpPixelMaskNKeep,
-                                      1);
+                psStats *rc = psVectorStats(stats,
+                                            tmpPixels,
+                                            NULL,
+                                            tmpPixelMaskNKeep,
+                                            1);
+                if (rc == NULL) {
+                    psError(PS_ERR_UNKNOWN, false, "psVectorStats(): could not perform requested statistical operation.  Returning NULL.\n");
+                    return(NULL);
+                }
             }
 
@@ -344,5 +352,5 @@
             double statValue;
             if (!p_psGetStatValue(stats, &statValue)) {
-                psError(PS_ERR_UNKNOWN, true, "Could not determine stats value.\n");
+                psError(PS_ERR_UNKNOWN, true, "Could not determine stats value.  Returning NULL.\n");
                 return(NULL);
             } else {
Index: /trunk/psModules/src/pmSubtractBias.c
===================================================================
--- /trunk/psModules/src/pmSubtractBias.c	(revision 2856)
+++ /trunk/psModules/src/pmSubtractBias.c	(revision 2857)
@@ -6,6 +6,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-30 21:35:03 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-30 22:22:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -39,9 +39,9 @@
 
     if (((in->image)->numRows + in->row0 - bias->row0) > (bias->image)->numRows) {
-        psError(PS_ERR_UNKNOWN,true, "bias image does not have enough rows\n");
+        psError(PS_ERR_UNKNOWN,true, "bias image does not have enough rows.  Returning in image\n");
         return(in);
     }
     if (((in->image)->numCols + in->row0 - bias->row0) > (bias->image)->numCols) {
-        psError(PS_ERR_UNKNOWN,true, "bias image does not have enough columns\n");
+        psError(PS_ERR_UNKNOWN,true, "bias image does not have enough columns.  Returning in image\n");
         return(in);
     }
@@ -129,5 +129,5 @@
 
     if (numOptions == 0) {
-        psError(PS_ERR_UNKNOWN,true, "No statistics options have been specified\n");
+        psError(PS_ERR_UNKNOWN,true, "No statistics options have been specified.\n");
     }
     if (numOptions != 1) {
@@ -225,5 +225,7 @@
 
     } else {
-        psError(PS_ERR_UNKNOWN, true, "unknown fit type\n");
+        psError(PS_ERR_UNKNOWN, true, "unknown fit type.  Returning NULL.\n");
+        psFree(newVec);
+        return(NULL);
     }
 
@@ -251,5 +253,5 @@
     PS_READOUT_CHECK_TYPE(in, PS_TYPE_F32, NULL);
     if ((overscans == NULL) && (overScanAxis != PM_OVERSCAN_NONE)) {
-        psError(PS_ERR_UNKNOWN,true, "(overscans == NULL) && (overScanAxis != PM_OVERSCAN_NONE)\n");
+        psError(PS_ERR_UNKNOWN,true, "(overscans == NULL) && (overScanAxis != PM_OVERSCAN_NONE).  Returning in image\n");
         return(in);
     }
@@ -260,5 +262,5 @@
             (fit != PM_OVERSCAN_COLUMNS) &&
             (fit != PM_OVERSCAN_ALL)) {
-        psError(PS_ERR_UNKNOWN, true, "fit is unallowable (%d)\n", fit);
+        psError(PS_ERR_UNKNOWN, true, "fit is unallowable (%d).  Returning in image.\n", fit);
         return(in);
     }
@@ -268,5 +270,5 @@
             (overScanAxis != PM_OVERSCAN_COLUMNS) &&
             (overScanAxis != PM_OVERSCAN_ALL)) {
-        psError(PS_ERR_UNKNOWN, true, "overScanAxis is unallowable (%d)\n", overScanAxis);
+        psError(PS_ERR_UNKNOWN, true, "overScanAxis is unallowable (%d).  Returning in image.\n", overScanAxis);
         return(in);
     }
@@ -302,10 +304,10 @@
         if (fit != PM_FIT_NONE) {
             psLogMsg(__func__, PS_LOG_WARN,
-                     "WARNING: pmSubtractBias.(): overScanAxis equals NONE, and fit does not equal NONE\n");
+                     "WARNING: pmSubtractBias.(): overScanAxis equals NONE, and fit does not equal NONE.  Proceeding to full fram subtraction.\n");
         }
 
         if (overscans != NULL) {
             psLogMsg(__func__, PS_LOG_WARN,
-                     "WARNING: pmSubtractBias.(): overScanAxis equals NONE and overscans does not equal NULL\n");
+                     "WARNING: pmSubtractBias.(): overScanAxis equals NONE and overscans does not equal NULL.  Proceeding to full fram subtraction.\n");
         }
         return(psSubtractFrame(in, bias));
@@ -314,5 +316,5 @@
     if ((overScanAxis == PM_OVERSCAN_ALL) && (fit != PM_FIT_NONE)) {
         psLogMsg(__func__, PS_LOG_WARN,
-                 "WARNING: pmSubtractBias.(): overScanAxis equals ALL, and fit does not equal NONE\n");
+                 "WARNING: pmSubtractBias.(): overScanAxis equals ALL, and fit does not equal NONE.  Proceeding with the rest of the module.\n");
     }
 
@@ -321,14 +323,17 @@
     // We subtract each overscan region from the image data.
     //
-    // XXX: Do we generate a single stat from all the overscan regions, and
-    // subtract that from the input image?  Or do we generate a single stat
-    // from each overscan region, and subtract them from the input image?
-    // The SDR is ambiguous.
     if (overScanAxis == PM_OVERSCAN_ALL) {
         tmpOverscan = (psListElem *) overscans->head;
         while (NULL != tmpOverscan) {
             myOverscanImage = (psImage *) tmpOverscan->data;
-            psImageStats(myStats, myOverscanImage, NULL, 0xffffffff);
-            p_psGetStatValue(myStats, &statValue);
+            psStats *rc = psImageStats(myStats, myOverscanImage, NULL, 0xffffffff);
+            if (rc == NULL) {
+                psError(PS_ERR_UNKNOWN, false, "psImageStats(): could not perform requested statistical operation.  Returning in image.\n");
+                return(in);
+            }
+            if (false == p_psGetStatValue(myStats, &statValue)) {
+                psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result from requested statistical operation.  Returning in image.\n");
+                return(in);
+            }
             p_psImageSubtractScalar(in->image, statValue);
 
@@ -340,5 +345,5 @@
     // This check is redundant with above code.
     if (!((overScanAxis == PM_OVERSCAN_ROWS) || (overScanAxis == PM_OVERSCAN_COLUMNS))) {
-        psError(PS_ERR_UNKNOWN, true, "overScanAxis is unallowable (%d)\n", overScanAxis);
+        psError(PS_ERR_UNKNOWN, true, "overScanAxis is unallowable (%d).\nReturning in image.\n", overScanAxis);
         return(in);
     }
@@ -371,6 +376,13 @@
                     tmpRow->data.F32[j] = myOverscanImage->data.F32[j][i];
                 }
-                myStats = psVectorStats(myStats, tmpRow, NULL, NULL, 0);
-                p_psGetStatValue(myStats, &statValue);
+                psStats *rc = psVectorStats(myStats, tmpRow, NULL, NULL, 0);
+                if (rc == NULL) {
+                    psError(PS_ERR_UNKNOWN, false, "psVectorStats(): could not perform requested statistical operation.  Returning in image.\n");
+                    return(in);
+                }
+                if (false ==  p_psGetStatValue(rc, &statValue)) {
+                    psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result from requested statistical operation.  Returning in image.\n");
+                    return(in);
+                }
                 overscanVector->data.F32[i] = statValue;
             }
@@ -383,8 +395,12 @@
                                                            in->image->numCols,
                                                            fitSpec, fit);
+                    if (newVec == NULL) {
+                        psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector(): could not scale the overscan vector.  Returning in image.\n");
+                        return(in);
+                    }
                     psFree(overscanVector);
                     overscanVector = newVec;
                 } else {
-                    psError(PS_ERR_UNKNOWN, true, "Don't know how to scale the overscan vector.  Set fit to PM_FIT_SPLINE or PM_FIT_POLYNOMIAL.\n");
+                    psError(PS_ERR_UNKNOWN, true, "Don't know how to scale the overscan vector.  Set fit to PM_FIT_SPLINE or PM_FIT_POLYNOMIAL.  Returning in image.\n");
                     psFree(overscanVector);
                     return(in);
@@ -414,6 +430,13 @@
                     tmpCol->data.F32[j] = myOverscanImage->data.F32[i][j];
                 }
-                myStats = psVectorStats(myStats, tmpCol, NULL, NULL, 0);
-                p_psGetStatValue(myStats, &statValue);
+                psStats *rc = psVectorStats(myStats, tmpCol, NULL, NULL, 0);
+                if (rc == NULL) {
+                    psError(PS_ERR_UNKNOWN, false, "psVectorStats(): could not perform requested statistical operation.  Returning in image.\n");
+                    return(in);
+                }
+                if (false ==  p_psGetStatValue(rc, &statValue)) {
+                    psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result from requested statistical operation.  Returning in image.\n");
+                    return(in);
+                }
                 overscanVector->data.F32[i] = statValue;
             }
@@ -426,8 +449,12 @@
                                                            in->image->numRows,
                                                            fitSpec, fit);
+                    if (newVec == NULL) {
+                        psError(PS_ERR_UNKNOWN, false, "ScaleOverscanVector(): could not scale the overscan vector.  Returning in image.\n");
+                        return(in);
+                    }
                     psFree(overscanVector);
                     overscanVector = newVec;
                 } else {
-                    psError(PS_ERR_UNKNOWN, true, "Don't know how to scale the overscan vector.  Set fit to PM_FIT_SPLINE or PM_FIT_POLYNOMIAL.\n");
+                    psError(PS_ERR_UNKNOWN, true, "Don't know how to scale the overscan vector.  Set fit to PM_FIT_SPLINE or PM_FIT_POLYNOMIAL.  Returning in image.\n");
                     psFree(overscanVector);
                     return(in);
@@ -456,6 +483,13 @@
                     }
                 }
-                myStats = psVectorStats(myStats, binVec, NULL, NULL, 0);
-                p_psGetStatValue(myStats, &statValue);
+                psStats *rc = psVectorStats(myStats, binVec, NULL, NULL, 0);
+                if (rc == NULL) {
+                    psError(PS_ERR_UNKNOWN, false, "psVectorStats(): could not perform requested statistical operation.  Returning in image.\n");
+                    return(in);
+                }
+                if (false ==  p_psGetStatValue(rc, &statValue)) {
+                    psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result from requested statistical operation.  Returning in image.\n");
+                    return(in);
+                }
                 myBin->data.F32[i] = statValue;
             }
@@ -486,5 +520,5 @@
                 myPoly = psVectorFitPolynomial1D(myPoly, NULL, overscanVector, NULL);
                 if (myPoly == NULL) {
-                    psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to overscan vector.\n");
+                    psError(PS_ERR_UNKNOWN, false, "Could not fit a polynomial to overscan vector.  Returning in image.\n");
                     psFree(overscanVector);
                     return(in);
@@ -494,5 +528,5 @@
                 mySpline = psVectorFitSpline1D(mySpline, NULL, overscanVector, NULL);
                 if (mySpline == NULL) {
-                    psError(PS_ERR_UNKNOWN, false, "Could not fit a spline to overscan vector.\n");
+                    psError(PS_ERR_UNKNOWN, false, "Could not fit a spline to overscan vector.  Returning in image.\n");
                     psFree(overscanVector);
                     return(in);
@@ -535,7 +569,9 @@
             }
         } else {
+            //
             // If we get here, then no polynomials were fit to the overscan
             // vector.  We simply subtract it, taking into account binning,
             // from the image.
+            //
 
             //
Index: /trunk/psModules/src/pmSubtractSky.c
===================================================================
--- /trunk/psModules/src/pmSubtractSky.c	(revision 2856)
+++ /trunk/psModules/src/pmSubtractSky.c	(revision 2857)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-29 22:44:33 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-30 22:22:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -106,7 +106,11 @@
                 }
             }
-            myStats = psVectorStats(myStats, binVector, NULL, binMask, 1);
+            psStats *rc1 = psVectorStats(myStats, binVector, NULL, binMask, 1);
+            if (rc1 == NULL) {
+                psError(PS_ERR_UNKNOWN, false, "psVectorStats(): could not perform requested statistical operation.  Returning in image.\n");
+                return(origImage);
+            }
             psF64 statValue;
-            psBool rc = p_psGetStatValue(myStats, &statValue);
+            psBool rc = p_psGetStatValue(rc1, &statValue);
 
             if (rc == true) {
@@ -427,5 +431,5 @@
             (fit != PM_FIT_POLYNOMIAL) &&
             (fit != PM_FIT_SPLINE)) {
-        psError(PS_ERR_UNKNOWN, true, "psFit is unallowable (%d)\n", fit);
+        psError(PS_ERR_UNKNOWN, true, "psFit is unallowable (%d).  Returning in image.\n", fit);
         return(in);
     }
@@ -436,4 +440,5 @@
     if ((fitSpec == NULL) ||
             ((fit == PM_FIT_NONE) || (fit == PM_FIT_SPLINE))) {
+        psLogMsg(__func__, PS_LOG_WARN, "Fit specs are poorly defined.  Returning in image.\n");
         return(in);
     }
@@ -452,5 +457,8 @@
             psLogMsg(__func__, PS_LOG_WARN, "WARNING: Multiple statistical options have been requested.\n");
             statOptions = getHighestPriorityStatOption(statOptions);
-
+            if (statOptions == -1) {
+                psError(PS_ERR_UNKNOWN, true, "Not allowable stats->option was specified.  Returning in image.\n");
+                return(in);
+            }
             // Save old input "stats" parameter.
             oldStatOptions = stats->options;
@@ -483,6 +491,16 @@
         // and a mask.
         binnedImage = psImageCopy(binnedImage, origImage, PS_TYPE_F32);
+        if (binnedImage == NULL) {
+            psError(PS_ERR_UNKNOWN, false, "psImageCopy() returned NULL.  Returning in image.\n");
+            return(in);
+        }
+
         if (in->mask != NULL) {
             binnedMaskImage = psImageCopy(binnedMaskImage, in->mask, PS_TYPE_U8);
+            if (binnedMaskImage == NULL) {
+                psError(PS_ERR_UNKNOWN, false, "psImageCopy() returned NULL.  Returning in image.\n");
+                psFree(binnedImage);
+                return(in);
+            }
         } else {
             binnedMaskImage = psImageAlloc(binnedImage->numCols,
@@ -493,4 +511,8 @@
     } else {
         binnedImage = psImageRebin(NULL, origImage, in->mask, 0, binFactor, stats);
+        if (binnedImage == NULL) {
+            psError(PS_ERR_UNKNOWN, false, "psImageRebin() returned NULL.  Returning in image.\n");
+            return(in);
+        }
         binnedMaskImage = psImageAlloc(binnedImage->numCols,
                                        binnedImage->numRows,
@@ -512,12 +534,26 @@
         psF64 binnedStdev;
         psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
-        myStats =  psImageStats(myStats, binnedImage, NULL, 0);
-        p_psGetStatValue(myStats, &binnedMean);
+        psStats *rc =  psImageStats(myStats, binnedImage, NULL, 0);
+        if (rc == NULL) {
+            psError(PS_ERR_UNKNOWN, false, "psImageStats(): could not perform requested statistical operation.  Returning in image.\n");
+            return(in);
+        }
+        if (false == p_psGetStatValue(rc, &binnedMean)) {
+            psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine requested statistical operation.  Returning in image.\n");
+            return(in);
+        }
         psTrace(".psModule.pmSubtractSky", 6,
                 "binned Mean is %f\n", binnedMean);
 
         myStats->options = PS_STAT_SAMPLE_STDEV;
-        myStats =  psImageStats(myStats, binnedImage, NULL, 0);
-        p_psGetStatValue(myStats, &binnedStdev);
+        rc =  psImageStats(myStats, binnedImage, NULL, 0);
+        if (rc == NULL) {
+            psError(PS_ERR_UNKNOWN, false, "psImageStats(): could not perform requested statistical operation.  Returning in image.\n");
+            return(in);
+        }
+        if (false == p_psGetStatValue(myStats, &binnedStdev)) {
+            psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine requested statistical operation.  Returning in image.\n");
+            return(in);
+        }
         psFree(myStats);
         psTrace(".psModule.pmSubtractSky", 6,
@@ -551,4 +587,15 @@
             // Set the pixels in the binned image to that of the polynomial.
             binnedImage = psImageEvalPolynomial(binnedImage, myPoly);
+            if (binnedImage == NULL) {
+                psError(PS_ERR_UNKNOWN, false, "psImageEvalPolynomial() returned NULL.  Returning in image.\n");
+                psFree(binnedMaskImage);
+                if (!((binFactor <= 1) || (stats == NULL))) {
+                    psFree(binnedImage);
+                }
+                if (oldStatOptions != 0) {
+                    stats->options = statOptions;
+                }
+                return(in);
+            }
         } else {
             psLogMsg(__func__, PS_LOG_WARN,
@@ -565,5 +612,13 @@
     } else {
         // We shouldn't get here since we check this above.
-        psError(PS_ERR_UNKNOWN, true, "Unallowable fit type.");
+        psError(PS_ERR_UNKNOWN, true, "Unallowable fit type.  Returning in image.\n");
+        psFree(binnedMaskImage);
+        if (!((binFactor <= 1) || (stats == NULL))) {
+            psFree(binnedImage);
+        }
+        if (oldStatOptions != 0) {
+            stats->options = statOptions;
+        }
+        return(in);
     }
 
Index: /trunk/psModules/test/tst_pmNonLinear.c
===================================================================
--- /trunk/psModules/test/tst_pmNonLinear.c	(revision 2856)
+++ /trunk/psModules/test/tst_pmNonLinear.c	(revision 2857)
@@ -13,6 +13,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-01 22:08:15 $
+ *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-30 22:22:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -46,5 +46,7 @@
     int testStatus = 0;
     psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
-    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
+    //    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
+    psReadout *myReadout = psReadoutAlloc();
+    myReadout->image = myImage;
     psPolynomial1D *myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
     myPoly->coeff[1] = 1.0;
@@ -95,5 +97,7 @@
     int tableSize = PS_MAX(numCols, numRows)*2;
     psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
-    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
+    //    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
+    psReadout *myReadout = psReadoutAlloc();
+    myReadout->image = myImage;
     psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
     psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
