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.
+            //
 
             //
