Index: trunk/ppStack/src/ppStackReadout.c
===================================================================
--- trunk/ppStack/src/ppStackReadout.c	(revision 18918)
+++ trunk/ppStack/src/ppStackReadout.c	(revision 19172)
@@ -10,7 +10,7 @@
 #include "ppStack.h"
 
-//#define REJECTION_FILES                 // Write rejection mask?
-//#define INSPECTION_FILES                // Write inspection mask?
-//#define COMBINED_FILES                  // Write combined images?
+#define REJECTION_FILES                 // Write rejection mask?
+#define INSPECTION_FILES                // Write inspection mask?
+#define COMBINED_FILES                  // Write combined images?
 
 
@@ -34,5 +34,4 @@
     int iter = psMetadataLookupS32(NULL, recipe, "ITER"); // Rejection iterations
     float combineRej = psMetadataLookupF32(NULL, recipe, "COMBINE.REJ"); // Combination threshold
-    psMaskType maskVal = pmConfigMaskGet("BLANK", config); // Value to mask
     bool useVariance = psMetadataLookupBool(&mdok, recipe, "VARIANCE"); // Use variance for rejection?
     bool safe = psMetadataLookupBool(&mdok, recipe, "SAFE"); // Be safe when combining small numbers of pixels
@@ -40,4 +39,9 @@
     psMetadata *ppsub = psMetadataLookupMetadata(NULL, config->recipes, "PPSUB"); // PPSUB recipe
     int kernelSize = psMetadataLookupS32(NULL, ppsub, "KERNEL.SIZE"); // Kernel half-size
+
+    psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in
+    psMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
+    psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
+    psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
 
     int num = readouts->n;              // Number of inputs
@@ -67,5 +71,5 @@
     }
 
-    if (!pmStackCombine(outRO, stack, maskVal, maskVal, kernelSize, iter, combineRej, true,
+    if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, kernelSize, iter, combineRej, true,
                         useVariance, safe)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts with rejection.");
@@ -93,5 +97,5 @@
                                             psRegionSet(0, outRO->image->numCols - 1,
                                                         0, outRO->image->numRows - 1),
-                                            maskVal);
+                                            maskBad);
         psString name = NULL;           // Name of image
         psStringAppend(&name, "inspect_%03d_%03d.fits", sectionNum, i);
@@ -143,6 +147,10 @@
 
     bool mdok;                          // Status of MD lookup
-    psMaskType maskVal = pmConfigMaskGet("BLANK", config); // Value to mask
     bool useVariance = psMetadataLookupBool(&mdok, recipe, "VARIANCE"); // Use variance for rejection?
+
+    psString maskValStr = psMetadataLookupStr(NULL, recipe, "MASK.VAL"); // Name of bits to mask going in
+    psMaskType maskVal = pmConfigMaskGet(maskValStr, config); // Bits to mask going in to pmSubtractionMatch
+    psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits to mask for bad
+    psMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
 
     int num = readouts->n;              // Number of inputs
@@ -210,5 +218,5 @@
                                              psRegionSet(0, outRO->image->numCols - 1,
                                                          0, outRO->image->numRows - 1),
-                                             maskVal);
+                                             maskBad);
             psString name = NULL;           // Name of image
             psStringAppend(&name, "reject_%03d.fits", i);
@@ -222,5 +230,6 @@
 #endif
 
-    if (!pmStackCombine(outRO, stack, maskVal, maskVal, 0, 0, NAN, numGood != num, useVariance, false)) {
+    if (!pmStackCombine(outRO, stack, maskVal | maskBad, maskBad, 0, 0, NAN,
+                        numGood != num, useVariance, false)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to combine input readouts.");
         psFree(fpaList);
