Index: trunk/psModules/src/detrend/pmSubtractBias.c
===================================================================
--- trunk/psModules/src/detrend/pmSubtractBias.c	(revision 7604)
+++ 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
 
