Index: trunk/psModules/src/detrend/pmSubtractBias.c
===================================================================
--- trunk/psModules/src/detrend/pmSubtractBias.c	(revision 7953)
+++ trunk/psModules/src/detrend/pmSubtractBias.c	(revision 8004)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-21 03:21:16 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-28 03:21:19 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -165,58 +165,4 @@
 }
 
-
-/******************************************************************************
-GenNewStatOptions(): this routine will take as input the options member of the
-stat data structure, determine if multiple options have been specified, issue
-a warning message if so, and return the highest priority option (according to
-the order of the if-statements in this code).  The higher priority options are
-listed lower in the code.
- *****************************************************************************/
-static psStatsOptions GenNewStatOptions(const psStats *stat)
-{
-    assert(stat);
-
-    psS32 numOptions = 0;
-    psStatsOptions opt = 0;
-
-    if (stat->options & PS_STAT_ROBUST_MEDIAN) {
-        if (numOptions == 0) {
-            opt = PS_STAT_ROBUST_MEDIAN;
-        }
-        numOptions++;
-    }
-
-    if (stat->options & PS_STAT_CLIPPED_MEAN) {
-        if (numOptions == 0) {
-            opt = PS_STAT_CLIPPED_MEAN;
-        }
-        numOptions++;
-    }
-
-    if (stat->options & PS_STAT_SAMPLE_MEDIAN) {
-        if (numOptions == 0) {
-            opt = PS_STAT_SAMPLE_MEDIAN;
-        }
-        numOptions++;
-    }
-
-    if (stat->options & PS_STAT_SAMPLE_MEAN) {
-        numOptions++;
-        opt = PS_STAT_SAMPLE_MEAN;
-    }
-
-
-    if (numOptions == 0) {
-        psError(PS_ERR_UNKNOWN,true, "No statistics options have been specified.\n");
-    }
-    if (numOptions != 1) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "WARNING: pmSubtractBias.c: GenNewStatOptions(): Too many statistics options "
-                 "have been specified\n");
-    }
-    return opt;
-}
-
-
 // Produce an overscan vector from an array of pixels
 static psVector *overscanVector(pmOverscanOptions *overscanOpts, // Overscan options
@@ -228,4 +174,7 @@
     assert(pixels);
     assert(myStats);
+
+    psStatsOptions statistic = psStatsSingleOption(myStats->options); // Statistic to use
+    assert(statistic != 0);
 
     // Reduce the overscans
@@ -241,11 +190,5 @@
             ordinate->data.F32[i] = 2.0*(float)i/(float)pixels->n - 1.0; // Scale to [-1,1]
             psVectorStats(myStats, values, NULL, NULL, 0);
-            double reducedVal = NAN; // Result of statistics
-            if (! p_psGetStatValue(myStats, &reducedVal)) {
-                psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result "
-                        "of statistics on row %d.\n", i);
-                return NULL;
-            }
-            reduced->data.F32[i] = reducedVal;
+            reduced->data.F32[i] = psStatsGetValue(myStats, statistic);
         } else if (overscanOpts->fitType == PM_FIT_NONE) {
             psError(PS_ERR_UNKNOWN, true, "The overscan is not supplied for all points on the "
@@ -344,6 +287,11 @@
         psList *overscans = in->bias; // List of the overscan images
 
-        psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN); // A new psStats, to avoid clobbering original
-        myStats->options = GenNewStatOptions(overscanOpts->stat);
+        psStatsOptions statistic = psStatsSingleOption(overscanOpts->stat->options); // Statistic to use
+        if (statistic == 0) {
+            psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics options set: %x\n",
+                    overscanOpts->stat);
+            return false;
+        }
+        psStats *stats = psStatsAlloc(statistic); // A new psStats, to avoid clobbering original
 
         // Reduce all overscan pixels to a single value
@@ -365,10 +313,6 @@
             psFree(iter);
 
-            (void)psVectorStats(myStats, pixels, NULL, NULL, 0);
-            double reduced = NAN;     // Result of statistics
-            if (! p_psGetStatValue(myStats, &reduced)) {
-                psError(PS_ERR_UNKNOWN, false, "p_psGetStatValue(): could not determine result from requested statistical operation.  Returning input image.\n");
-                return false;
-            }
+            (void)psVectorStats(stats, pixels, NULL, NULL, 0);
+            double reduced = psStatsGetValue(stats, statistic); // Result of statistics
             (void)psBinaryOp(image, image, "-", psScalarAlloc((float)reduced, PS_TYPE_F32));
         } else {
@@ -408,5 +352,5 @@
 
                 // Reduce the overscans
-                psVector *reduced = overscanVector(overscanOpts, pixels, myStats);
+                psVector *reduced = overscanVector(overscanOpts, pixels, stats);
                 psFree(pixels);
                 if (! reduced) {
@@ -452,5 +396,5 @@
 
                 // Reduce the overscans
-                psVector *reduced = overscanVector(overscanOpts, pixels, myStats);
+                psVector *reduced = overscanVector(overscanOpts, pixels, stats);
                 psFree(pixels);
                 if (! reduced) {
@@ -467,5 +411,5 @@
             }
         }
-        psFree(myStats);
+        psFree(stats);
     } // End of overscan subtraction
 
Index: trunk/psModules/src/detrend/pmSubtractSky.c
===================================================================
--- trunk/psModules/src/detrend/pmSubtractSky.c	(revision 7953)
+++ trunk/psModules/src/detrend/pmSubtractSky.c	(revision 8004)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-30 23:59:49 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-28 03:21:19 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -90,5 +90,5 @@
 requirements change and we might need a custom reBin function.
  *****************************************************************************/
-/*
+#if 0
 static psImage *binImage(psImage *origImage,
                          int binFactor,
@@ -96,5 +96,5 @@
 {
     psTrace("SubtractSky.binImage", 4, "Calling binImage(%d)\n", binFactor);
- 
+
     if (binFactor <= 0) {
         psLogMsg(__func__, PS_LOG_WARN,
@@ -105,9 +105,9 @@
         return(origImage);
     }
- 
+
     psVector *binVector = psVectorAlloc(binFactor * binFactor, PS_TYPE_F32);
     psVector *binMask = psVectorAlloc(binFactor * binFactor, PS_TYPE_U8);
     psStats *myStats = psStatsAlloc(statOptions);
- 
+
     for (psS32 row = 0; row < origImage->numRows ; row+=binFactor) {
         for (psS32 col = 0; col < origImage->numCols ; col+=binFactor) {
@@ -134,5 +134,5 @@
             psF64 statValue;
             psBool rc = p_psGetStatValue(rc1, &statValue);
- 
+
             if (rc == true) {
                 origImage->data.F32[row][col] = (psF32) statValue;
@@ -147,9 +147,9 @@
     psFree(binMask);
     psFree(myStats);
- 
+
     psTrace("SubtractSky.binImage", 4, "Exiting binImage(%d)\n", binFactor);
     return(origImage);
 }
-*/
+#endif
 
 /******************************************************************************
@@ -601,29 +601,11 @@
     } else {
         // Determine the mean and standard deviation of the binned image.
-        psF64 binnedMean;
-        psF64 binnedStdev;
-        psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
-        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;
-        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);
-        }
+        psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
+        if (!psImageStats(myStats, binnedImage, NULL, 0)) {
+            psError(PS_ERR_UNEXPECTED_NULL, false, "Couldn't get statistics for image.\n");
+            return NULL;
+        }
+        psF64 binnedMean = myStats->sampleMean;
+        psF64 binnedStdev = myStats->sampleStdev;
         psFree(myStats);
         psTrace(".psModule.pmSubtractSky", 6,
Index: trunk/psModules/src/imcombine/pmImageCombine.c
===================================================================
--- trunk/psModules/src/imcombine/pmImageCombine.c	(revision 7953)
+++ trunk/psModules/src/imcombine/pmImageCombine.c	(revision 8004)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-30 23:59:49 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-28 03:21:19 $
  *
  *  XXX: pmRejectPixels() has a known bug with the pmImageTransform() call.
@@ -45,5 +45,5 @@
     psS32 numIter,                      ///< Number of rejection iterations
     psF32 sigmaClip,                    ///< Number of standard deviations at which to reject
-    const psStats *stats)               ///< Statistics to use in the combination
+    psStats *stats)               ///< Statistics to use in the combination
 {
 
@@ -98,4 +98,9 @@
     }
     PS_ASSERT_PTR_NON_NULL(stats, combine);
+    psStatsOptions statistic = psStatsSingleOption(stats->options);
+    if (statistic == 0) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics options set: %x\n", statistic);
+        return combine;
+    }
 
     // Allocate and initialize the combined image, if necessary.
@@ -185,10 +190,7 @@
                 // Combine all the pixels, using the specified stat.
 
-                stats = psVectorStats((psStats *) stats, pixelData, pixelErrors, pixelMask, maskVal);
-                psF64 combinedPixel;
-                psBool rc = p_psGetStatValue(stats, &combinedPixel);
-                if (rc != true) {
-                    psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not combine pixels (%d, %d) with the specified stat.\n", row, col);
-                }
+                stats = psVectorStats(stats, pixelData, pixelErrors, pixelMask, maskVal);
+                psF64 combinedPixel = psStatsGetValue(stats, statistic);
+
                 if (iter == 0) {
                     combine->data.F32[row][col] = (psF32) combinedPixel;
@@ -202,10 +204,5 @@
                 for (psS32 im = 0 ; im < numImages ; im++) {
                     stdevStats = psVectorStats(stdevStats, pixelData, pixelErrors, pixelMask, maskVal);
-                    psF64 stdev;
-                    psBool rc = p_psGetStatValue(stdevStats, &stdev);
-                    if (rc != true) {
-                        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not compute the standard deviation of pixel (%d, %d).\n", row, col);
-                        psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not combine pixels (%d, %d) with the specified stat.\n", row, col);
-                    }
+                    psF64 stdev = stdevStats->sampleStdev;
 
                     if (!(pixelMask->data.U8[im] & maskVal)) {
@@ -289,11 +286,6 @@
                 }
                 // Combine all the pixels, using the specified stat.
-                stats = psVectorStats((psStats *) stats, pixelData, pixelErrors, pixelMask, maskVal);
-                psF64 tmpF64;
-                psBool rc = p_psGetStatValue(stats, &tmpF64);
-                combine->data.F32[row][col] = (psF32) tmpF64;
-                if (rc != true) {
-                    psLogMsg(__func__, PS_LOG_WARN, "WARNING: could not combine pixels (%d, %d) with the specified stat.\n", row, col);
-                }
+                stats = psVectorStats(stats, pixelData, pixelErrors, pixelMask, maskVal);
+                combine->data.F32[row][col] = psStatsGetValue(stats, statistic);
             }
         }
Index: trunk/psModules/src/imcombine/pmImageCombine.h
===================================================================
--- trunk/psModules/src/imcombine/pmImageCombine.h	(revision 7953)
+++ trunk/psModules/src/imcombine/pmImageCombine.h	(revision 8004)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:43:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-28 03:21:19 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -36,5 +36,5 @@
     psS32 numIter,                      ///< Number of rejection iterations
     psF32 sigmaClip,                    ///< Number of standard deviations at which to reject
-    const psStats *stats                ///< Statistics to use in the combination
+    psStats *stats                      ///< Statistics to use in the combination
 );
 
Index: trunk/psModules/src/objects/pmSourceSky.c
===================================================================
--- trunk/psModules/src/objects/pmSourceSky.c	(revision 7953)
+++ trunk/psModules/src/objects/pmSourceSky.c	(revision 8004)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-21 03:21:16 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-28 03:21:19 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -49,4 +49,10 @@
     PS_ASSERT_INT_NONNEGATIVE(Radius, false);
 
+    psStatsOptions statistic = psStatsSingleOption(statsOptions);
+    if (statistic == 0) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics specified: %x\n", statsOptions);
+        return NULL;
+    }
+
     psImage *image = source->pixels;
     psImage *mask  = source->mask;
@@ -61,10 +67,8 @@
     myStats = psImageStats(myStats, image, mask, 0xff);
     psImageMaskRegion(mask, srcRegion, "AND", NOT_U8(PM_MASK_MARK));
-
-    psF64 tmpF64;
-    p_psGetStatValue(myStats, &tmpF64);
+    double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
 
-    if (isnan(tmpF64)) {
+    if (isnan(value)) {
         psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);
         return(false);
@@ -73,5 +77,5 @@
         source->moments = pmMomentsAlloc();
     }
-    source->moments->Sky = (psF32) tmpF64;
+    source->moments->Sky = value;
     psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);
     return (true);
@@ -92,4 +96,10 @@
     PS_ASSERT_INT_NONNEGATIVE(Radius, false);
 
+    psStatsOptions statistic = psStatsSingleOption(statsOptions);
+    if (statistic == 0) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Multiple or no statistics specified: %x\n", statsOptions);
+        return NULL;
+    }
+
     psImage *image = source->weight;
     psImage *mask  = source->mask;
@@ -104,10 +114,8 @@
     myStats = psImageStats(myStats, image, mask, 0xff);
     psImageMaskRegion(mask, srcRegion, "AND", NOT_U8(PM_MASK_MARK));
-
-    psF64 tmpF64;
-    p_psGetStatValue(myStats, &tmpF64);
+    double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
 
-    if (isnan(tmpF64)) {
+    if (isnan(value)) {
         psTrace(__func__, 3, "---- %s(false) end ----\n", __func__);
         return(false);
@@ -116,5 +124,5 @@
         source->moments = pmMomentsAlloc();
     }
-    source->moments->dSky = (psF32) tmpF64;
+    source->moments->dSky = value;
     psTrace(__func__, 3, "---- %s(true) end ----\n", __func__);
     return (true);
