Index: trunk/psModules/src/camera/pmFPAMaskWeight.c
===================================================================
--- trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 13567)
+++ trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 13591)
@@ -93,5 +93,5 @@
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
-bool pmReadoutSetMask(pmReadout *readout)
+bool pmReadoutSetMask(pmReadout *readout, psMaskType satMask, psMaskType badMask)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -131,8 +131,8 @@
         for (int j = 0; j < image->numCols; j++) {
             if (imageData[i][j] >= saturation) {
-                maskData[i][j] |= PM_MASK_SAT;
+                maskData[i][j] |= satMask;
             }
             if (imageData[i][j] <= bad) {
-                maskData[i][j] |= PM_MASK_BAD;
+                maskData[i][j] |= badMask;
             }
         }
@@ -145,5 +145,5 @@
 // pixels.  currently, it will set mask bits if (value <= BAD) or (value >= SATURATION)
 // should we optionally ignore these tests?
-bool pmReadoutGenerateMask(pmReadout *readout)
+bool pmReadoutGenerateMask(pmReadout *readout, psMaskType satMask, psMaskType badMask)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -188,5 +188,5 @@
     }
 
-    return pmReadoutSetMask(readout);
+    return pmReadoutSetMask(readout, satMask, badMask);
 }
 
@@ -282,5 +282,5 @@
 }
 
-bool pmReadoutGenerateMaskWeight(pmReadout *readout, bool poisson)
+bool pmReadoutGenerateMaskWeight(pmReadout *readout, psMaskType satMask, psMaskType badMask, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -288,5 +288,5 @@
     bool success = true;                // Was everything successful?
 
-    success &= pmReadoutGenerateMask(readout);
+    success &= pmReadoutGenerateMask(readout, satMask, badMask);
     success &= pmReadoutGenerateWeight(readout, poisson);
 
@@ -294,5 +294,5 @@
 }
 
-bool pmCellGenerateMaskWeight(pmCell *cell, bool poisson)
+bool pmCellGenerateMaskWeight(pmCell *cell, psMaskType satMask, psMaskType badMask, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(cell, false);
@@ -302,5 +302,5 @@
     for (int i = 0; i < readouts->n; i++) {
         pmReadout *readout = readouts->data[i]; // The readout
-        pmReadoutGenerateMaskWeight(readout, poisson);
+        pmReadoutGenerateMaskWeight(readout, poisson, satMask, badMask);
     }
 
Index: trunk/psModules/src/camera/pmFPAMaskWeight.h
===================================================================
--- trunk/psModules/src/camera/pmFPAMaskWeight.h	(revision 13567)
+++ trunk/psModules/src/camera/pmFPAMaskWeight.h	(revision 13591)
@@ -5,6 +5,6 @@
  * @author Eugene Magnier, IfA
  *
- * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-03-30 21:12:56 $
+ * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-02 03:51:03 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -16,17 +16,24 @@
 /// @{
 
+#if 0
 /// Pixel mask values
 typedef enum {
-    PM_MASK_CLEAR   = 0x00,   ///< The pixel is not masked
-    PM_MASK_TRAP    = 0x01,   ///< The pixel is a charge trap.
-    PM_MASK_BADCOL  = 0x02,   ///< The pixel is a bad column.
-    PM_MASK_SAT     = 0x04,   ///< The pixel is saturated.
-    PM_MASK_BAD     = 0x08,   ///< The pixel is low
-    PM_MASK_FLAT    = 0x10,   ///< The pixel is non-positive in the flat-field.
-    PM_MASK_MARK    = 0x20,   ///< The pixel is marked as temporarily ignored
-    PM_MASK_EXT1    = 0x40,   ///< This mask value is not used
-    PM_MASK_EXT2    = 0x80,   ///< This mask value is not used
+    PM_MASK_CLEAR    = 0x00,            ///< The pixel is not masked
+    PM_MASK_BLANK    = 0x01,            ///< The pixel is blank or has no (valid) data
+    PM_MASK_FLAT     = 0x02,            ///< The pixel is non-positive in the flat-field
+    PM_MASK_DETECTOR = 0x02,            ///< The detector pixel is bad (e.g., bad column, charge trap)
+    PM_MASK_SAT      = 0x04,            ///< The pixel is saturated in the image of interest
+    PM_MASK_BAD      = 0x04,            ///< The pixel is low in the image of interest
+    PM_MASK_RANGE    = 0x04,            ///< The pixel is out of range in the image of interest
+    PM_MASK_CR       = 0x08,            ///< The pixel is probably a CR
+    PM_MASK_SPARE1   = 0x10,            ///< Spare mask value
+    PM_MASK_SPARE2   = 0x20,            ///< Spare mask value
+    PM_MASK_SUSPECT  = 0x40,            ///< The pixel is suspected of being bad, but may not be
+    PM_MASK_MARK     = 0x80,            ///< The pixel is marked as temporarily ignored
 } pmMaskValue;
-
+#else
+#define PM_MASK_MARK 0x80            ///< The pixel is marked as temporarily ignored
+#define PM_MASK_SAT  0x04            ///< The pixel is saturated in the image of interest
+#endif
 
 /// Set a temporary readout mask using CELL.SATURATION and CELL.BAD
@@ -35,6 +42,8 @@
 /// within the readout is temporary --- it is not added to the HDU.  This is intended for when the user is
 /// iterating using pmReadoutReadNext, in which case the HDU can't be generated.
-bool pmReadoutSetMask(pmReadout *readout ///< Readout for which to set mask
-                     );
+bool pmReadoutSetMask(pmReadout *readout, ///< Readout for which to set mask
+                      psMaskType sat,   ///< Mask value to give saturated pixels
+                      psMaskType bad    ///< Mask value to give bad (low) pixels
+    );
 
 
@@ -53,6 +62,8 @@
 /// Identifies pixels that are saturated (>= CELL.SATURATION) or bad (<= CELL.BAD).  The mask that is produced
 /// is suitable for output (complete with HDU entry).  This is intended for most operations.
-bool pmReadoutGenerateMask(pmReadout *readout ///< Readout for which to generate mask
-                          );
+bool pmReadoutGenerateMask(pmReadout *readout, ///< Readout for which to generate mask
+                           psMaskType sat, ///< Mask value to give saturated pixels
+                           psMaskType bad ///< Mask value to give bad (low) pixels
+    );
 
 /// Generate a weight map (suitable for output) using CELL.GAIN and CELL.READNOISE
@@ -69,5 +80,7 @@
 /// Calls pmReadoutGenerateMask and pmReadoutGenerateWeight for the readout
 bool pmReadoutGenerateMaskWeight(pmReadout *readout, ///< Readout for which to generate mask and weights
-                                 bool poisson    ///< Use poisson weights (in addition to read noise)?
+                                 psMaskType sat, ///< Mask value to give saturated pixels
+                                 psMaskType bad, ///< Mask value to give bad (low) pixels
+                                 bool poisson ///< Use poisson weights (in addition to read noise)?
                                 );
 
@@ -76,5 +89,7 @@
 /// Calls pmReadoutGenerateMaskWeight for each readout within the cell.
 bool pmCellGenerateMaskWeight(pmCell *cell, ///< Cell for which to generate mask and weights
-                              bool poisson    ///< Use poisson weights (in addition to read noise)?
+                              psMaskType sat, ///< Mask value to give saturated pixels
+                              psMaskType bad, ///< Mask value to give bad (low) pixels
+                              bool poisson ///< Use poisson weights (in addition to read noise)?
                              );
 /// @}
Index: trunk/psModules/src/config/Makefile.am
===================================================================
--- trunk/psModules/src/config/Makefile.am	(revision 13567)
+++ trunk/psModules/src/config/Makefile.am	(revision 13591)
@@ -8,4 +8,5 @@
     pmConfigCamera.c \
     pmConfigCommand.c \
+    pmConfigMask.c \
     pmVersion.c \
     pmErrorCodes.c
@@ -16,4 +17,5 @@
     pmConfigCamera.h \
     pmConfigCommand.h \
+    pmConfigMask.h \
     pmVersion.h \
     pmErrorCodes.h
Index: trunk/psModules/src/config/pmConfigMask.c
===================================================================
--- trunk/psModules/src/config/pmConfigMask.c	(revision 13591)
+++ trunk/psModules/src/config/pmConfigMask.c	(revision 13591)
@@ -0,0 +1,40 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <pslib.h>
+
+#include "pmConfigMask.h"
+
+
+psMaskType pmConfigMask(const char *masks, const pmConfig *config)
+{
+    PS_ASSERT_STRING_NON_EMPTY(masks, 0);
+
+    psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, "MASKS"); // The recipe
+    if (!recipe) {
+        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find MASKS recipe.");
+        return 0;
+    }
+
+    psMaskType mask = 0;                // Mask value, to return
+
+    psArray *names = psStringSplitArray(masks, " ,;", false); // Array of symbolic names
+    for (int i = 0; i < names->n; i++) {
+        const char *name = names->data[i]; // Symbolic name of interest
+        bool mdok;                      // Status of MD lookup
+        psMaskType value = psMetadataLookupU8(&mdok, recipe, name);
+        if (!mdok) {
+            psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                    "Unable to find mask value for %s in MASK recipe", name);
+            psFree(names);
+            return 0;
+        }
+        mask |= value;
+    }
+    psFree(names);
+
+    return mask;
+}
Index: trunk/psModules/src/config/pmConfigMask.h
===================================================================
--- trunk/psModules/src/config/pmConfigMask.h	(revision 13591)
+++ trunk/psModules/src/config/pmConfigMask.h	(revision 13591)
@@ -0,0 +1,30 @@
+/*  @file pmConfigMask.h
+ *  @brief Mask configuration functions
+ *
+ *  @author Paul Price, IfA
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-02 03:51:03 $
+ *  Copyright 2007 Institute for Astronomy, University of Hawaii
+ */
+
+#ifndef PM_CONFIG_MASK_H
+#define PM_CONFIG_MASK_H
+
+#include <pslib.h>
+#include <pmConfig.h>
+
+#define PM_MASKS_RECIPE "MASKS"
+
+/// @addtogroup Config Configuration System
+/// @{
+
+/// Return a mask value given a list of symbolic names
+///
+/// The mask values are derived from the MASKS recipe
+psMaskType pmConfigMask(const char *masks, ///< List of symbolic names, space/comma delimited
+                        const pmConfig *config ///< Configuration
+                        );
+
+
+#endif
Index: trunk/psModules/src/detrend/pmFlatField.c
===================================================================
--- trunk/psModules/src/detrend/pmFlatField.c	(revision 13567)
+++ trunk/psModules/src/detrend/pmFlatField.c	(revision 13591)
@@ -12,5 +12,5 @@
 #include "pmFlatField.h"
 
-bool pmFlatField(pmReadout *in, const pmReadout *flat)
+bool pmFlatField(pmReadout *in, const pmReadout *flat, psMaskType badFlat)
 {
     PS_ASSERT_PTR_NON_NULL(in, false);
@@ -79,5 +79,5 @@
             if (flatValue <= 0.0 || (flatMask && flatMask->data.U8[j + yOffset][i + xOffset])) { \
                 if (inMask) { \
-                    inMask->data.U8[j][i] |= PM_MASK_FLAT; \
+                    inMask->data.PS_TYPE_MASK_DATA[j][i] |= badFlat; \
                 } \
                 inImage->data.TYPE[j][i] = SPECIAL; \
Index: trunk/psModules/src/detrend/pmFlatField.h
===================================================================
--- trunk/psModules/src/detrend/pmFlatField.h	(revision 13567)
+++ trunk/psModules/src/detrend/pmFlatField.h	(revision 13591)
@@ -5,6 +5,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-03-30 21:12:56 $
+ * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-02 03:51:03 $
  * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
  */
@@ -24,5 +24,6 @@
 /// are masked, if there is a mask present in the input readout.
 bool pmFlatField(pmReadout *in,         ///< Readout with input image
-                 const pmReadout *flat  ///< Readout with flat image
+                 const pmReadout *flat,  ///< Readout with flat image
+                 psMaskType badFlat     ///< Mask value to give bad flat pixels
                 );
 /// @}
Index: trunk/psModules/src/detrend/pmMaskBadPixels.c
===================================================================
--- trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 13567)
+++ trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 13591)
@@ -66,15 +66,4 @@
             }
         }
-    } else {
-        // set raised pixels in exMask which are selected by maskVal
-        for (int j = 0; j < inMask->numRows; j++) {
-            int xJ = j - offRow;
-            for (int i = 0; i < inMask->numCols; i++) {
-                int xI = i - offCol;
-                if (exVal[xJ][xI] == 0) {
-                    inVal[j][i] |= PM_MASK_BAD;
-                }
-            }
-        }
     }
 
@@ -82,5 +71,5 @@
     psString timeString = psTimeToISO(time); // String with time
     psFree(time);
-    psStringPrepend(&timeString, "Static mask applied at ");
+    psStringPrepend(&timeString, "Static mask (selecting %x) applied at ", maskVal);
     psMetadataAddStr(hdu->header, PS_LIST_TAIL, "HISTORY", PS_META_DUPLICATE_OK,
                      timeString, "");
Index: trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 13567)
+++ trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 13591)
@@ -29,4 +29,5 @@
     params->combine = combine;
     params->maskVal = 0;
+    params->blank = 0;
     params->nKeep = 0;
     params->fracHigh = 0.0;
@@ -335,5 +336,5 @@
 
             if (numValid == 0) {
-                outputMask[yOut][xOut] = PM_MASK_FLAT;
+                outputMask[yOut][xOut] = params->blank;
                 outputImage[yOut][xOut] = NAN;
                 continue;
Index: trunk/psModules/src/imcombine/pmReadoutCombine.h
===================================================================
--- trunk/psModules/src/imcombine/pmReadoutCombine.h	(revision 13567)
+++ trunk/psModules/src/imcombine/pmReadoutCombine.h	(revision 13591)
@@ -1,10 +1,10 @@
 /* @file  pmReadoutCombine.h
  * @brief Combine multiple readouts
- * 
+ *
  * @author George Gusciora, MHPCC
  * @author Paul Price, IfA
- * 
- * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-03-30 21:12:56 $
+ *
+ * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-02 03:51:03 $
  * Copyright 2004-2006 Institute for Astronomy, University of Hawaii
  */
@@ -24,4 +24,5 @@
     psStatsOptions combine;             ///< Statistic to use when performing the combination
     psMaskType maskVal;                 ///< Mask value
+    psMaskType blank;                   ///< Mask value to give blank (i.e., no data) pixels
     int nKeep;                          ///< Mimimum number of pixels to keep
     float fracHigh;                     ///< Fraction of high pixels to immediately throw
Index: trunk/psModules/src/psmodules.h
===================================================================
--- trunk/psModules/src/psmodules.h	(revision 13567)
+++ trunk/psModules/src/psmodules.h	(revision 13591)
@@ -24,4 +24,5 @@
 #include <pmConfigCamera.h>
 #include <pmConfigCommand.h>
+#include <pmConfigMask.h>
 #include <pmVersion.h>
 
