Index: trunk/psModules/src/detrend/pmMaskBadPixels.c
===================================================================
--- trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 15864)
+++ trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 15865)
@@ -5,4 +5,5 @@
 #include <stdio.h>
 #include <math.h>
+#include <strings.h>
 #include <pslib.h>
 
@@ -125,4 +126,6 @@
     psFree(stats);
 
+    psTrace ("psModules.detrend", 3, "suspect: %f +/- %f\n", median, stdev);
+
     if (!out) {
         out = psImageAlloc(image->numCols, image->numRows, PS_TYPE_S32);
@@ -142,6 +145,5 @@
 }
 
-
-psImage *pmMaskIdentifyBadPixels(const psImage *suspects, float thresh, psMaskType maskVal)
+psImage *pmMaskIdentifyBadPixels(const psImage *suspects, psMaskType maskVal, int nTotal, float thresh, pmMaskIdentifyMode mode)
 {
     PS_ASSERT_IMAGE_NON_NULL(suspects, NULL);
@@ -150,5 +152,15 @@
 
     float limit = NAN;                  // Limit for masking
-    if (thresh > 0) {
+
+    switch (mode) {
+      case PM_MASK_ID_VALUE:
+        limit = thresh;
+	break;
+
+      case PM_MASK_ID_FRACTION:
+        limit = thresh * nTotal;
+	break;
+
+      case PM_MASK_ID_SIGMA: {
         psStats *stats = psStatsAlloc(PS_STAT_CLIPPED_STDEV); // Statistics
         stats->clipSigma = 5.0;
@@ -160,6 +172,10 @@
         }
         limit = thresh * stats->clippedStdev;
-        psFree(stats);
-    } else if (thresh < 0) {
+	psTrace ("psModules.detrend", 3, "bad: %f -> %f\n", stats->clippedStdev, limit);
+        psFree(stats);
+	break;
+      }
+
+      case PM_MASK_ID_POISSON: {
         psStats *stats = psStatsAlloc(PS_STAT_MAX); // Statistics
         if (!psImageStats(stats, suspects, NULL, 0)) {
@@ -189,7 +205,9 @@
         limit = max + 1.0 - thresh * sqrtf((float)max + 1.0);
 
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                "Threshold (%f) must be a positive or negative real number.\n", thresh);
+	psTrace ("psModules.detrend", 3, "bad: mode: %d, stdev: %f, limit: %f\n", max, sqrtf((float)max + 1.0), limit);
+	break;
+      }
+      default:
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Invalid mask identify mode");
         return NULL;
     }
@@ -212,4 +230,6 @@
     }
 
+    psTrace ("psModules.detrend", 3, "bad pixel threshold: %f", limit);
+
     for (int y = 0; y < suspects->numRows; y++) {
         for (int x = 0; x < suspects->numCols; x++) {
@@ -222,2 +242,19 @@
     return badpix;
 }
+
+pmMaskIdentifyMode pmMaskIdentifyModeFromString (const char *string) {
+
+    if (!strcasecmp (string, "VALUE")) {
+      return PM_MASK_ID_VALUE;
+    } 
+    if (!strcasecmp (string, "FRACTION")) {
+      return PM_MASK_ID_FRACTION;
+    } 
+    if (!strcasecmp (string, "SIGMA")) {
+      return PM_MASK_ID_SIGMA;
+    } 
+    if (!strcasecmp (string, "POISSON")) {
+      return PM_MASK_ID_POISSON;
+    } 
+    return PM_MASK_ID_NONE;
+}
Index: trunk/psModules/src/detrend/pmMaskBadPixels.h
===================================================================
--- trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 15864)
+++ trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 15865)
@@ -5,6 +5,6 @@
  * @author Eugene Magnier, IfA
  *
- * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-03-30 21:12:56 $
+ * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-12-16 22:22:06 $
  * Copyright 2004 Institute for Astronomy, University of Hawaii
  */
@@ -15,4 +15,14 @@
 /// @addtogroup detrend Detrend Creation and Application
 /// @{
+
+typedef enum {
+  PM_MASK_ID_NONE,
+  PM_MASK_ID_VALUE,
+  PM_MASK_ID_FRACTION,
+  PM_MASK_ID_SIGMA,
+  PM_MASK_ID_POISSON,
+} pmMaskIdentifyMode;
+
+pmMaskIdentifyMode pmMaskIdentifyModeFromString (const char *string);
 
 /// Applies the bad pixel mask to the input
@@ -49,6 +59,8 @@
 /// pixels (output image).  If "thresh" is negative, a Poisson is assumed.
 psImage *pmMaskIdentifyBadPixels(const psImage *suspects, ///< Accumulated suspect pixels image
+                                 psMaskType maskVal, ///< Value to set for bad pixels
+				 int nTotal,
                                  float thresh, ///< Threshold for bad pixel (standard deviations)
-                                 psMaskType maskVal ///< Value to set for bad pixels
+				 pmMaskIdentifyMode mode
                                 );
 /// @}
