Index: /trunk/psModules/src/Makefile.am
===================================================================
--- /trunk/psModules/src/Makefile.am	(revision 1821)
+++ /trunk/psModules/src/Makefile.am	(revision 1822)
@@ -2,6 +2,6 @@
 bin_PROGRAMS = tst_pmFlatField
 
-libpsmodule_a_SOURCES = pmFlatField.c
-libpsmodule_a_HEADERS =  pmFlatField.h
+libpsmodule_a_SOURCES = pmFlatField.c pmMaskBadPixels.c
+libpsmodule_a_HEADERS = pmFlatField.h pmMaskBadPixels.h
 libpsmodule_adir = .
 
Index: /trunk/psModules/src/Makefile.in
===================================================================
--- /trunk/psModules/src/Makefile.in	(revision 1821)
+++ /trunk/psModules/src/Makefile.in	(revision 1822)
@@ -134,6 +134,6 @@
 bin_PROGRAMS = tst_pmFlatField
 
-libpsmodule_a_SOURCES = pmFlatField.c
-libpsmodule_a_HEADERS = pmFlatField.h
+libpsmodule_a_SOURCES = pmFlatField.c pmMaskBadPixels.c
+libpsmodule_a_HEADERS = pmFlatField.h pmMaskBadPixels.h
 libpsmodule_adir = .
 
@@ -149,5 +149,6 @@
 libpsmodule_a_AR = $(AR) cru
 libpsmodule_a_LIBADD =
-am_libpsmodule_a_OBJECTS = pmFlatField.$(OBJEXT)
+am_libpsmodule_a_OBJECTS = pmFlatField.$(OBJEXT) \
+	pmMaskBadPixels.$(OBJEXT)
 libpsmodule_a_OBJECTS = $(am_libpsmodule_a_OBJECTS)
 bin_PROGRAMS = tst_pmFlatField$(EXEEXT)
@@ -163,4 +164,5 @@
 am__depfiles_maybe = depfiles
 @AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/pmFlatField.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/pmMaskBadPixels.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/tst_pmFlatField.Po
 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -279,4 +281,5 @@
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pmFlatField.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pmMaskBadPixels.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tst_pmFlatField.Po@am__quote@
 
Index: /trunk/psModules/src/pmFlatField.c
===================================================================
--- /trunk/psModules/src/pmFlatField.c	(revision 1821)
+++ /trunk/psModules/src/pmFlatField.c	(revision 1822)
@@ -1,20 +1,23 @@
-/** @file  pmFlatField.cS
+/** @file  pmFlatField.c
  *
- *  @brief Given an input image and a flat-field image, pmFlatField shall divide the input image by the flat-field image.
+ *  @brief Given an input image and a flat field image, pmFlatField shall divide the input image by the flat
+ *  field image.
  *
- *  The input image, in, and the flat-field image, flat, need not be the same size, since the input image may already have
- *  been trimmed (following overscan subtraction), but the function shall use the offsets in the image (in->x0
- *  and in->y0) to determine the appropriate offsets to obtain the correct pixel on the flat-field. In the event that the flat
- *  image is too small (i.e., pixels on the input image refer to pixels outside the range of the flat image), the function shall
- *  generate an error. Pixels which are negative or zero in the flat shall be masked in the input image with the value PM_MASK_FLAT
- *  Negative pixels in the flat may be set to zero so that they are treated identically to zeroes. Any pixels masked in the flat
- *  shall be masked with corresponding values in the output. The function shall not normalize the flat; this responsibility is
- *  left to the caller. This function is basically equivalent to a divide (with psImageOp), but with care for the region that is
- *  divided, checking for negative pixels, and copying of the mask from the flat to the output.
+ *  The input image, in, and the flat field image, flat, need not be the same size, since the input image may
+ *  already have been trimmed (following overscan subtraction), but the function shall use the offsets in the
+ *  image (in->x0 and in->y0) to determine the appropriate offsets to obtain the correct pixel on the flat
+ *  field. In the event that the flat image is too small (i.e., pixels on the input image refer to pixels
+ *  outside the range of the flat image), the function shall generate an error. Pixels which are negative or
+ *  zero in the flat shall be masked in the input image with the value PM_MASK_FLAT. Negative pixels in the
+ *  flat may be set to zero so that they are treated identically to zeroes. Any pixels masked in the flat
+ *  shall be masked with corresponding values in the output. The function shall not normalize the flat; this
+ *  responsibility is left to the caller. This function is basically equivalent to a divide (with psImageOp),
+ *  but with care for the region that is divided, checking for negative pixels, and copying of the mask from
+ *  the flat to the output.
  *
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-15 01:08:23 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-17 00:49:04 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -29,13 +32,7 @@
 
 #include "pmFlatField.h"
+#include "pmMaskBadPixels.h"
 
-
-#define CHECK_NULL(STRUCT)                                                                                   \
-if (STRUCT == NULL) {                                                                                        \
-    psError(__func__, " : Line %d - Null not allowed for %s", __LINE__, #STRUCT);                            \
-    return false;                                                                                            \
-}                                                                                                            \
-
-bool pmFlatField(psReadout *in, psReadout *inMask, const psReadout *flat)
+bool pmFlatField(psReadout *in, const psReadout *flat)
 {
     int i = 0;
@@ -47,85 +44,98 @@
     psElemType maskType;
     psImage *inImage = NULL;
+    psImage *inMask = NULL;
     psImage *flatImage = NULL;
-    psImage *maskImage = NULL;
 
-    CHECK_NULL(in);
-    CHECK_NULL(flat);
-    CHECK_NULL(inMask);
 
-    inImage = in->image;
-    flatImage = flat->image;
-    maskImage = inMask->image;
-
-    CHECK_NULL(inImage);
-    CHECK_NULL(flatImage);
-    CHECK_NULL(maskImage);
-
-    totOffCol = inImage->col0 + in->col0;
-    totOffRow = inImage->row0 + in->row0;
-
-    if(inImage->numRows > flatImage->numRows) {
-        psError(__func__, " : Line %d - Input image exceeds flat image in number of rows. (%d vs %d).",
-                __LINE__, inImage->numRows, flatImage->numRows);
+    // Check for nulls
+    if (in == NULL) {
+        psError(__func__, " : Line %d - Null not allowed for input readout", __LINE__);
+        return false;
+    } else if(flat==NULL) {
+        psError(__func__, " : Line %d - Null not allowed for flat readout", __LINE__);
         return false;
     }
 
-    if(inImage->numCols > flatImage->numCols) {
-        psError(__func__, " : Line %d - Input image exceeds flat image in number of columns. (%d vs %d).",
+    inImage = in->image;
+    inMask = in->mask;
+    flatImage = flat->image;
+    if (inImage == NULL) {
+        psError(__func__, " : Line %d - Null not allowed for input image", __LINE__);
+        return false;
+    } else if(flatImage) {
+        psError(__func__, " : Line %d - Null not allowed for flat image", __LINE__);
+        return false;
+    } else if(inMask == NULL) {
+        inMask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK);
+    }
+
+    // Check input image and its mask are not larger than flat image
+    if(inImage->numRows > flatImage->numRows) {
+        psError(__func__, " : Line %d - Input image exceeds mask image in number of rows. (%d vs %d).",
+                __LINE__, inImage->numRows, flatImage->numRows);
+        return false;
+    } else if(inImage->numCols > flatImage->numCols) {
+        psError(__func__, " : Line %d - Input image exceeds mask image in number of columns. (%d vs %d).",
+                __LINE__, inImage->numCols, flatImage->numCols);
+        return false;
+    } else if(inMask->numRows > flatImage->numRows) {
+        psError(__func__, " : Line %d - Input image mask exceeds mask image in number of rows. (%d vs %d).",
+                __LINE__, inImage->numRows, flatImage->numRows);
+        return false;
+    } else if(inMask->numCols > flatImage->numCols) {
+        psError(__func__, " : Line %d - Input image mask exceeds mask image in number of columns. (%d vs %d).",
                 __LINE__, inImage->numCols, flatImage->numCols);
         return false;
     }
 
+    // Determine total offset based on image offset with chip offset
+    totOffCol = inImage->col0 + in->col0;
+    totOffRow = inImage->row0 + in->row0;
+
+    // Check that offsets are within image limits
     if(totOffRow > flatImage->numRows-1) {
-        psError(__func__, " : Line %d - Initial row offset exceeds that of flat image. (%d vs %d).",
+        psError(__func__, " : Line %d - Initial row offset exceeds that of mask image. (%d vs %d).",
                 __LINE__, totOffRow, flatImage->numRows);
+        return false;
+    } else if(totOffCol > flatImage->numCols-1) {
+        psError(__func__, " : Line %d - Initial column offset exceeds that of mask image. (%d vs %d).",
+                __LINE__, totOffCol, flatImage->numCols);
+        return false;
+    } else if(totOffRow > inImage->numRows-1) {
+        psError(__func__, " : Line %d - Initial row offset exceeds that of input image. (%d vs %d).",
+                __LINE__, totOffRow, inImage->numRows);
+        return false;
+    } else if(totOffCol > inImage->numCols-1) {
+        psError(__func__, " : Line %d - Initial column offset exceeds that of input image. (%d vs %d).",
+                __LINE__, totOffCol, inImage->numCols);
+        return false;
+    } else if(totOffRow > inMask->numRows-1) {
+        psError(__func__, " : Line %d - Initial row offset exceeds that of input image mask. (%d vs %d).",
+                __LINE__, totOffRow, inMask->numRows);
+        return false;
+    } else if(totOffCol > inMask->numCols-1) {
+        psError(__func__, " : Line %d - Initial column offset exceeds that of input image mask. (%d vs %d).",
+                __LINE__, totOffCol, inMask->numCols);
         return false;
     }
 
-    if(totOffCol > flatImage->numCols-1) {
-        psError(__func__, " : Line %d - Initial column offset exceeds that of flat image. (%d vs %d).",
-                __LINE__, totOffCol, flatImage->numCols);
-        return false;
-    }
-
-    if(totOffRow > inImage->numRows-1) {
-        psError(__func__, " : Line %d - Initial row offset exceeds that of input image. (%d vs %d).",
-                __LINE__, totOffRow, inImage->numRows);
-        return false;
-    }
-
-    if(totOffCol > inImage->numCols-1) {
-        psError(__func__, " : Line %d - Initial column offset exceeds that of input image. (%d vs %d).",
-                __LINE__, totOffCol, inImage->numCols);
-        return false;
-    }
-
+    // Check for incorrect types
     inType = inImage->type.type;
     flatType = flatImage->type.type;
-    maskType = maskImage->type.type;
-
+    maskType = inMask->type.type;
     if(PS_IS_PSELEMTYPE_COMPLEX(inType)) {
-        psError(__func__, " : Line %d - Complex types not allowed for input image", __LINE__);
+        psError(__func__, " : Line %d - Complex types not allowed for input image. Type: %d", __LINE__,
+                inType);
         return false;
-    }
-
-    if(PS_IS_PSELEMTYPE_COMPLEX(flatType)) {
-        psError(__func__, " : Line %d - Complex types not allowedfor flat image", __LINE__);
+    } else if(PS_IS_PSELEMTYPE_COMPLEX(flatType)) {
+        psError(__func__, " : Line %d - Complex types not allowed for flat image. Type: %d", __LINE__,
+                flatType);
         return false;
-    }
-
-    if(PS_IS_PSELEMTYPE_COMPLEX(maskType)) {
-        psError(__func__, " : Line %d - Complex types not allowed for mask image", __LINE__);
+    } else if(maskType != PS_TYPE_MASK) {
+        psError(__func__, " : Line %d - Mask must be PS_TYPE_MASK type. Type: %d", __LINE__, maskType);
         return false;
-    }
-
-    if(PS_IS_PSELEMTYPE_REAL(maskType)) {
-        psError(__func__, " : Line %d - Floating point types not allowed for mask image", __LINE__);
-        return false;
-    }
-
-    if(inType != flatType) {
-        psError(__func__, " : Line %d - Input and flat image types don't agree. (%d vs %d).",
-                __LINE__, inType, flatType);
+    } else if(inType != flatType) {
+        psError(__func__, " : Line %d - Input and flat image types differ. (%d vs %d)", __LINE__, inType,
+                flatType);
         return false;
     }
@@ -133,5 +143,5 @@
     // Macro for all PS types
     #define PM_FLAT_DIVISION(TYPE)                                                                           \
-case PS_TYPE_##TYPE:                                                                                     \
+case PS_TYPE_##TYPE:                                                                                         \
     /* Per Eugene's request, use two sets of loops: first to fill mask, second to avoid div with bad pix */  \
     for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
@@ -139,5 +149,5 @@
             if(flatImage->data.TYPE[j][i] <= 0.0) {                                                          \
                 /* Negative or zero flat pixels shall be masked in input image as  PM_MASK_FLAT */           \
-                maskImage->data.F64[j][i] = PM_MASK_FLAT;                                                    \
+                inMask->data.PS_TYPE_MASK_DATA[j][i] = PM_MASK_FLAT;                                         \
             }                                                                                                \
         }                                                                                                    \
@@ -145,5 +155,5 @@
     for(j = totOffRow; j < inImage->numRows; j++) {                                                          \
         for(i = totOffCol; i < inImage->numCols; i++) {                                                      \
-            if(!maskImage->data.F64[j][i]) {                                                                 \
+            if(!inMask->data.PS_TYPE_MASK_DATA[j][i]) {                                                      \
                 /* Module shall divide the input image by the flat-fielded image */                          \
                 inImage->data.TYPE[j][i] /= flatImage->data.TYPE[j][i];                                      \
@@ -165,7 +175,7 @@
         PM_FLAT_DIVISION(F64);
     default:
-        psError(__func__, "Unsupported image datatype (%d)", inType);
+        psError(__func__, "Unsupported image datatype. Type: %d", inType);
     }
 
-    return in;
+    return true;
 }
Index: /trunk/psModules/src/pmFlatField.h
===================================================================
--- /trunk/psModules/src/pmFlatField.h	(revision 1821)
+++ /trunk/psModules/src/pmFlatField.h	(revision 1822)
@@ -1,20 +1,23 @@
 /** @file  pmFlatField.h
  *
- *  @brief Given an input image and a flat-field image, pmFlatField shall divide the input image by the flat-field image.
+ *  @brief Given an input image and a flat field image, pmFlatField shall divide the input image by the flat
+ *  field image.
  *
- *  The input image, in, and the flat-field image, flat, need not be the same size, since the input image may already have
- *  been trimmed (following overscan subtraction), but the function shall use the offsets in the image (in->x0
- *  and in->y0) to determine the appropriate offsets to obtain the correct pixel on the flat-field. In the event that the flat
- *  image is too small (i.e., pixels on the input image refer to pixels outside the range of the flat image), the function shall
- *  generate an error. Pixels which are negative or zero in the flat shall be masked in the input image with the value PM_MASK_FLAT
- *  Negative pixels in the flat may be set to zero so that they are treated identically to zeroes. Any pixels masked in the flat
- *  shall be masked with corresponding values in the output. The function shall not normalize the flat; this responsibility is
- *  left to the caller. This function is basically equivalent to a divide (with psImageOp), but with care for the region that is
- *  divided, checking for negative pixels, and copying of the mask from the flat to the output.
+ *  The input image, in, and the flat field image, flat, need not be the same size, since the input image may
+ *  already have been trimmed (following overscan subtraction), but the function shall use the offsets in the
+ *  image (in->x0 and in->y0) to determine the appropriate offsets to obtain the correct pixel on the flat
+ *  field. In the event that the flat image is too small (i.e., pixels on the input image refer to pixels
+ *  outside the range of the flat image), the function shall generate an error. Pixels which are negative or
+ *  zero in the flat shall be masked in the input image with the value PM_MASK_FLAT. Negative pixels in the
+ *  flat may be set to zero so that they are treated identically to zeroes. Any pixels masked in the flat
+ *  shall be masked with corresponding values in the output. The function shall not normalize the flat; this
+ *  responsibility is left to the caller. This function is basically equivalent to a divide (with psImageOp),
+ *  but with care for the region that is divided, checking for negative pixels, and copying of the mask from
+ *  the flat to the output.
  *
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-15 01:04:50 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-17 00:49:04 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -23,12 +26,14 @@
 #include "pslib.h"
 
-/** Mask values */
-typedef enum {
-    PM_MASK_TRAP    = 0x0001,   ///< The pixel is a charge trap
-    PM_MASK_BADCOL  = 0x0002,   ///< The pixel is a bad column
-    PM_MASK_SAT     = 0x0004,   ///< The pixel is saturated
-    PM_MASK_FLAT    = 0x0008    ///< The pixel is non-positive in the flat-field
-} pmMaskValue;
+/** Execute flat field module.
+ *
+ *  Given an input image and a flat-field image, pmFlatField shall divide the input image by the flat field
+ *  image.
+ *
+ *  @return  bool: True or false for success or failure
+ */
+bool pmFlatField(
+    psReadout *in,          ///< Redout with input image and mask
+    const psReadout *flat   ///< Readout with flat image
+);
 
-bool pmFlatField(psReadout *in, psReadout *inMask, const psReadout *flat);
-
Index: /trunk/psModules/src/pmMaskBadPixels.c
===================================================================
--- /trunk/psModules/src/pmMaskBadPixels.c	(revision 1822)
+++ /trunk/psModules/src/pmMaskBadPixels.c	(revision 1822)
@@ -0,0 +1,186 @@
+/** @file  pmMaskBadPixels.c
+ *
+ *  @brief Given an input image, a bad pixel mask, a corresponding value in the bad pixel mask to mask, a
+ *  saturation level, and a growing radius, mask in the input image those pixels in the bad pixel mask that
+ *  match the value to mask.
+ *
+ *  Given an input image, in, a bad pixel mask, a corresponding value in the bad pixel mask to mask in the
+ * input image, maskVal, a saturation level, and a growing radius, pmMaskBadPixels shall mask in the input
+ * image those pixels in the bad pixel mask that match the value to mask. Note that the input image, in, is
+ * modified in-place. All pixels in the mask which satisfy the maskVal shall have their corresponding pixels
+ * masked in the input image, in. All pixels which satisfy the growVal shall have their corresponding
+ * pixels, along with all pixels within the grow radius masked. Pixels which have flux greater than sat shall
+ * also be masked, but not grown. Note that the input image, in, and the mask need not be the same size, since
+ * the input image may already have been trimmed (following overscan subtraction), but the function shall use
+ * the offsets in the image (in->x0 and in->y0) to determine the appropriate offsets to obtain the correct
+ * pixel on the mask. In the event that the mask image is too small (i.e., pixels on the input image refer to
+ * pixels outside the range of the mask image), the function shall generate an error.
+ *  @author Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-17 00:49:04 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include<stdio.h>
+#include<math.h>
+
+#include "pmMaskBadPixels.h"
+
+bool pmMaskBadPixels(psReadout *in, const psImage *mask, unsigned int maskVal, float sat,
+                     unsigned int growVal, int grow)
+{
+    int i = 0;
+    int j = 0;
+    int jj = 0;
+    int ii = 0;
+    int rowMin = 0;
+    int rowMax = 0;
+    int colMin = 0;
+    int colMax = 0;
+    int totOffCol = 0;
+    int totOffRow = 0;
+    float r = 0.0;
+    psElemType inType;
+    psElemType maskType;
+    psImage *inImage = NULL;
+    psImage *inMask = NULL;
+
+
+    // Check for nulls
+    if (in == NULL) {
+        psError(__func__, " : Line %d - Null not allowed for input readout", __LINE__);
+        return false;
+    } else if(mask==NULL) {
+        psError(__func__, " : Line %d - Null not allowed for mask", __LINE__);
+        return false;
+    }
+
+    inImage = in->image;
+    inMask = in->mask;
+    if (inImage == NULL) {
+        psError(__func__, " : Line %d - Null not allowed for input image", __LINE__);
+        return false;
+    } else if(inMask == NULL) {
+        inMask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK);
+    }
+
+    // Check input image and its mask are not larger than mask
+    if(inImage->numRows > mask->numRows) {
+        psError(__func__, " : Line %d - Input image exceeds mask image in number of rows. (%d vs %d).",
+                __LINE__, inImage->numRows, mask->numRows);
+        return false;
+    } else if(inImage->numCols > mask->numCols) {
+        psError(__func__, " : Line %d - Input image exceeds mask image in number of columns. (%d vs %d).",
+                __LINE__, inImage->numCols, mask->numCols);
+        return false;
+    } else if(inMask->numRows > mask->numRows) {
+        psError(__func__, " : Line %d - Input image mask exceeds mask image in number of rows. (%d vs %d).",
+                __LINE__, inImage->numRows, mask->numRows);
+        return false;
+    } else if(inMask->numCols > mask->numCols) {
+        psError(__func__, " : Line %d - Input image mask exceeds mask image in number of columns. (%d vs %d).",
+                __LINE__, inImage->numCols, mask->numCols);
+        return false;
+    }
+
+    // Determine total offset based on image offset with chip offset
+    totOffCol = inImage->col0 + in->col0;
+    totOffRow = inImage->row0 + in->row0;
+
+    // Check that offsets are within image limits
+    if(totOffRow > mask->numRows-1) {
+        psError(__func__, " : Line %d - Initial row offset exceeds that of mask image. (%d vs %d).",
+                __LINE__, totOffRow, mask->numRows);
+        return false;
+    } else if(totOffCol > mask->numCols-1) {
+        psError(__func__, " : Line %d - Initial column offset exceeds that of mask image. (%d vs %d).",
+                __LINE__, totOffCol, mask->numCols);
+        return false;
+    } else if(totOffRow > inImage->numRows-1) {
+        psError(__func__, " : Line %d - Initial row offset exceeds that of input image. (%d vs %d).",
+                __LINE__, totOffRow, inImage->numRows);
+        return false;
+    } else if(totOffCol > inImage->numCols-1) {
+        psError(__func__, " : Line %d - Initial column offset exceeds that of input image. (%d vs %d).",
+                __LINE__, totOffCol, inImage->numCols);
+        return false;
+    } else if(totOffRow > inMask->numRows-1) {
+        psError(__func__, " : Line %d - Initial row offset exceeds that of input image mask. (%d vs %d).",
+                __LINE__, totOffRow, inMask->numRows);
+        return false;
+    } else if(totOffCol > inMask->numCols-1) {
+        psError(__func__, " : Line %d - Initial column offset exceeds that of input image mask. (%d vs %d).",
+                __LINE__, totOffCol, inMask->numCols);
+        return false;
+    }
+
+    // Check for incorrect types
+    inType = inImage->type.type;
+    maskType = mask->type.type;
+    if(PS_IS_PSELEMTYPE_COMPLEX(inType)) {
+        psError(__func__, " : Line %d - Complex types not allowed for input image. Type: %d", __LINE__,
+                inType);
+        return false;
+    } else if(maskType!=PS_TYPE_MASK) {
+        psError(__func__, " : Line %d - Mask must be PS_TYPE_MASK type. Type: %d", __LINE__, maskType);
+        return false;
+    }
+
+    // Macro for all PS types
+    #define PM_BAD_PIXELS(TYPE)                                                                              \
+case PS_TYPE_##TYPE:                                                                                 \
+    for(j=totOffRow; j<inImage->numRows; j++) {                                                      \
+        for(i=totOffCol; i<inImage->numCols; i++) {                                                  \
+            if(inImage->data.TYPE[j][i] > sat) {                                                     \
+                /* Pixels with flux greater than sat shall be masked */                              \
+                inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT;                                 \
+            }                                                                                        \
+            if(mask->data.PS_TYPE_MASK_DATA[j][i] & maskVal) {                                       \
+                /* Pixels in mask which satisfy maskVal shall have their pixels masked in inMask */  \
+                inMask->data.PS_TYPE_MASK_DATA[j][i] |= mask->data.PS_TYPE_MASK_DATA[j][i]|maskVal;  \
+            }                                                                                        \
+            rowMin = MAX(j-grow, 0);                                                                 \
+            rowMax = MIN(j+grow, inImage->numRows-1);                                                \
+            colMin = MAX(i-grow, 0);                                                                 \
+            colMax = MIN(i+grow, inImage->numCols-1);                                                \
+            for(jj=rowMin; jj<rowMax; jj++) {                                                        \
+                for(ii=colMin; ii<colMax; ii++) {                                                    \
+                    if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) {                               \
+                        r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j));                                      \
+                        if(r <= grow) {                                                              \
+                            /* Pixels in mask which satisfy growVal shall have their corresponding   \
+                            pixels,along with all pixels within the grow radius masked */            \
+                            inMask->data.PS_TYPE_MASK_DATA[j][i] |=                                  \
+                                    mask->data.PS_TYPE_MASK_DATA[j][i]&growVal;                          \
+                        }                                                                            \
+                    }                                                                                \
+                }                                                                                    \
+            }                                                                                        \
+        }                                                                                            \
+    }                                                                                                \
+    break;
+
+    // Switch to call bad pixel masking macro defined above
+    switch(inType) {
+        PM_BAD_PIXELS(U8);
+        PM_BAD_PIXELS(U16);
+        PM_BAD_PIXELS(U32);
+        PM_BAD_PIXELS(U64);
+        PM_BAD_PIXELS(S8);
+        PM_BAD_PIXELS(S16);
+        PM_BAD_PIXELS(S32);
+        PM_BAD_PIXELS(S64);
+        PM_BAD_PIXELS(F32);
+        PM_BAD_PIXELS(F64);
+    default:
+        psError(__func__, "Unsupported image datatype. Type: %d", inType);
+    }
+
+    return false;
+}
Index: /trunk/psModules/src/pmMaskBadPixels.h
===================================================================
--- /trunk/psModules/src/pmMaskBadPixels.h	(revision 1822)
+++ /trunk/psModules/src/pmMaskBadPixels.h	(revision 1822)
@@ -0,0 +1,60 @@
+/** @file  pmMaskBadPixels.h
+ *
+ *  @brief Given an input image, a bad pixel mask, a corresponding value in the bad pixel mask to mask, a
+ *  saturation level, and a growing radius, mask in the input image those pixels in the bad pixel mask that
+ *  match the value to mask.
+ *
+ *  Given an input image, in, a bad pixel mask, a corresponding value in the bad pixel mask to mask in the
+ *  input image, maskVal, a saturation level, and a growing radius, pmMaskBadPixels shall mask in the input
+ *  image those pixels in the bad pixel mask that match the value to mask. Note that the input image, in, is
+ *  modified in-place. All pixels in the mask which satisfy the maskVal shall have their corresponding pixels
+ *  masked in the input image, in. All pixels which satisfy the growVal shall have their corresponding
+ *  pixels, along with all pixels within the grow radius masked. Pixels which have flux greater than sat shall
+ *  also be masked, but not grown. Note that the input image, in, and the mask need not be the same size,
+ *  since the input image may already have been trimmed (following overscan subtraction), but the function
+ *  shall use the offsets in the image (in->x0 and in->y0) to determine the appropriate offsets to obtain the
+ *  correct pixel on the mask. In the event that the mask image is too small (i.e., pixels on the input image
+ *  refer to pixels outside the range of the mask image), the function shall generate an error.
+ *
+ *  @author Ross Harman, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-17 00:49:04 $
+ *
+ *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include "pslib.h"
+
+/** Mask values */
+typedef enum {
+    PM_MASK_TRAP    = 0x0001,   ///< The pixel is a charge trap.
+    PM_MASK_BADCOL  = 0x0002,   ///< The pixel is a bad column.
+    PM_MASK_SAT     = 0x0004,   ///< The pixel is saturated.
+    PM_MASK_FLAT    = 0x0008    ///< The pixel is non-positive in the flat-field.
+} pmMaskValue;
+
+/** Macro to find maximum of two numbers */
+#define MAX(A,B)((A)>=(B)?(A):(B))
+
+/** Macro to find minimum of two numbers */
+#define MIN(A,B)((A)<=(B)?(A):(B))
+
+
+/** Execute bad pixels module.
+ *
+ *  Given an input image, a bad pixel mask, a corresponding value in the bad pixel mask to mask, a
+ *  saturation level, and a growing radius, mask in the input image those pixels in the bad pixel mask that
+ *  match the value to mask.
+ *
+ *  @return  bool: True or false for success or failure
+ */
+bool pmMaskBadPixels(
+    psReadout *in,          ///< Readout containing input image data.
+    const psImage *mask,    ///< Mask data to be added to readout mask data.
+    unsigned int maskVal,   ///< Mask value to determine what to add to input mask.
+    float sat,              ///< Saturation limit to mask bad pixels.
+    unsigned int growVal,   ///< Mask data to determine if a circurlar area should be masked.
+    int grow                ///< Radius of mask to apply around pixel.
+);
+
