Index: /trunk/psModules/src/detrend/Makefile.am
===================================================================
--- /trunk/psModules/src/detrend/Makefile.am	(revision 9615)
+++ /trunk/psModules/src/detrend/Makefile.am	(revision 9616)
@@ -19,8 +19,6 @@
 pkginclude_HEADERS = \
 	pmFlatField.h \
-	pmFlatFieldErrors.h \
 	pmFlatNormalize.h \
 	pmFringeStats.h \
-	pmMaskBadPixelsErrors.h \
 	pmMaskBadPixels.h \
 	pmNonLinear.h \
@@ -31,9 +29,5 @@
 	psIOBuffer.h
 
-#	pmSubtractSky.c
-
-EXTRA_DIST = \
-	pmFlatFieldErrors.dat \
-	pmMaskBadPixelsErrors.dat
+#	pmSubtractSky.h
 
 CLEANFILES = *~
Index: unk/psModules/src/detrend/pmFlatFieldErrors.dat
===================================================================
--- /trunk/psModules/src/detrend/pmFlatFieldErrors.dat	(revision 9615)
+++ 	(revision )
@@ -1,22 +1,0 @@
-#
-#  This file is used to generate pmFlatFieldErrors.h content
-#
-#  Format is:
-#  ERRORNAME(one word)    ERRORTEXT
-#
-#  N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME
-####################################################################
-#
-pmFlatField_NULL_FLAT_READOUT          Null not allowed for flat readout.
-pmFlatField_NULL_INPUT_IMAGE           Null not allowed for input image.
-pmFlatField_NULL_FLAT_IMAGE            Null not allowed for flat image.
-pmFlatField_SIZE_INPUT_IMAGE           Input image size exceeds that of flat image: (%d, %d) vs (%d, %d)
-pmFlatField_SIZE_MASK_IMAGE            Input image mask size exceeds that of flat image: (%d, %d) vs (%d, %d)
-pmFlatField_OFFSET_FLAT_IMAGE          Total offset >= flat image size: (%d, %d) vs (%d, %d)
-pmFlatField_OFFSET_INPUT_IMAGE         Total offset >= input image: (%d, %d) vs (%d, %d)
-pmFlatField_OFFSET_MASK_IMAGE          Total offset >= input image mask: (%d, %d) vs (%d, %d)
-pmFlatField_TYPE_INPUT_IMAGE           Complex types not allowed for input image. Type: %d
-pmFlatField_TYPE_FLAT_IMAGE            Complex types not allowed for flat image. Type: %d
-pmFlatField_TYPE_MASK_IMAGE            Mask must be PS_TYPE_MASK type. Type: %d
-pmFlatField_TYPE_MISMATCH              Input and flat image types differ: (%d vs %d)
-pmFlatField_TYPE_UNSUPPORTED           Unsupported image datatype. Type: %d
Index: unk/psModules/src/detrend/pmFlatFieldErrors.h
===================================================================
--- /trunk/psModules/src/detrend/pmFlatFieldErrors.h	(revision 9615)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/** @file  pmFlatFieldErrors.h
- *
- *  @brief Contains the error text for the flat field module
- *
- *  @ingroup ErrorHandling
- *
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-28 20:43:52 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
-
-#ifndef PM_FLATFIELD_ERRORS_H
-#define PM_FLATFIELD_ERRORS_H
-
-/* N.B., lines between '//~Start' and '//~End' are automatic generated from
- * the template following the '//~Start'.  The template is used to generate
- * the other lines by, for each error text in psDataManipErrors.dat, the following
- * substitutions are made:
- *     $1  The error text macro name (first word in the psFlatFieldErrors.h lines)
- *     $2  The error text (rest of the line in psFlatFieldErrors.h)
- *     $n  The order of the source line in psFlatFieldErrors.h (comments excluded)
- *
- * DO NOT EDIT THE LINES BETWEEN //~Start and //~End!  ANY CHANGES WILL BE OVERWRITTEN.
- */
-
-#define PS_ERRORNAME_DOMAIN "psModule.src."
-
-//~Start #define PS_ERRORTEXT_$1 "$2"
-#define PS_ERRORTEXT_pmFlatField_NULL_FLAT_READOUT "Null not allowed for flat readout."
-#define PS_ERRORTEXT_pmFlatField_NULL_INPUT_IMAGE "Null not allowed for input image."
-#define PS_ERRORTEXT_pmFlatField_NULL_FLAT_IMAGE "Null not allowed for flat image."
-#define PS_ERRORTEXT_pmFlatField_SIZE_INPUT_IMAGE "Input image size exceeds that of flat image: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmFlatField_SIZE_MASK_IMAGE "Input image mask size exceeds that of flat image: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmFlatField_OFFSET_FLAT_IMAGE "Total offset >= flat image size: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmFlatField_OFFSET_INPUT_IMAGE "Total offset >= input image: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmFlatField_OFFSET_MASK_IMAGE "Total offset >= input image mask: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmFlatField_TYPE_INPUT_IMAGE "Complex types not allowed for input image. Type: %d"
-#define PS_ERRORTEXT_pmFlatField_TYPE_FLAT_IMAGE "Complex types not allowed for flat image. Type: %d"
-#define PS_ERRORTEXT_pmFlatField_TYPE_MASK_IMAGE "Mask must be PS_TYPE_MASK type. Type: %d"
-#define PS_ERRORTEXT_pmFlatField_TYPE_MISMATCH "Input and flat image types differ: (%d vs %d)"
-#define PS_ERRORTEXT_pmFlatField_TYPE_UNSUPPORTED "Unsupported image datatype. Type: %d"
-//~End
-
-#endif
Index: /trunk/psModules/src/detrend/pmMaskBadPixels.c
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 9615)
+++ /trunk/psModules/src/detrend/pmMaskBadPixels.c	(revision 9616)
@@ -1,34 +1,2 @@
-/** @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.
- *
- *  Apply the supplied bad pixel mask readout (mask) to the given science readout (input).
- *  The science readout must already have a supplied mask element (use eg. pmReadoutSetMask)
- *  The supplied mask image must be of MASK type
- 
- *  If maskVal is non-zero, all pixels in the mask have any of the same bits sets as maskVal
- *  shall have the corresponding bits raised.
- 
- *  If maskVal is zero, any zero pixels in the mask be OR-ed with PM_MASK_BAD 
- 
- * Note that the input image and the mask need not be the same size, since the input image may
- * already have been trimmed (following overscan subtraction).  The function assumes the pixels
- * originate from the same detector and uses the values of col0,row0 in both the input and the
- * mask to match corresponding pixels.
- 
- * 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
- *  @author Eugene Magnier, IfA
- *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-10 02:59:23 $
- *
- *  Copyright 2004 IfA, University of Hawaii
- */
-
 #if HAVE_CONFIG_H
 #include <config.h>
@@ -36,26 +4,18 @@
 
 #include <stdio.h>
-#include <math.h>
-#include <strings.h>
+#include <pslib.h>
 
 #include "pmFPAMaskWeight.h"
 #include "pmMaskBadPixels.h"
-#include "pmMaskBadPixelsErrors.h"
 
-// apply an externally-supplied mask image to the current science image
-// this function
-bool pmMaskBadPixels(pmReadout *input, pmReadout *mask, psMaskType maskVal)
+bool pmMaskBadPixels(pmReadout *input, const pmReadout *mask, psMaskType maskVal)
 {
-
-    int xI;
-    int xJ;
-
     PS_ASSERT_PTR_NON_NULL(input, false);
     PS_ASSERT_PTR_NON_NULL(input->mask, false);
-    PS_ASSERT_IMAGE_TYPE(input->mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(input->mask, PS_TYPE_MASK, false);
 
     PS_ASSERT_PTR_NON_NULL(mask, false);
     PS_ASSERT_PTR_NON_NULL(mask->mask, false);
-    PS_ASSERT_IMAGE_TYPE(mask->mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask->mask, PS_TYPE_MASK, false);
 
     psImage *inMask = input->mask;
@@ -65,25 +25,8 @@
     int colMax = inMask->col0 + inMask->numCols;
 
-    if (exMask->row0 > inMask->row0) {
+    if (exMask->row0 > inMask->row0 || exMask->col0 > inMask->col0 ||
+            exMask->row0 + exMask->numRows < rowMax || exMask->col0 + exMask->numCols < colMax) {
         psError( PS_ERR_BAD_PARAMETER_SIZE, true,
-                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
-                 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
-        return false;
-    }
-    if (exMask->col0 > inMask->col0) {
-        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
-                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
-                 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
-        return false;
-    }
-    if (exMask->row0 + exMask->numRows < rowMax) {
-        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
-                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
-                 inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
-        return false;
-    }
-    if (exMask->col0 + exMask->numCols < colMax) {
-        psError( PS_ERR_BAD_PARAMETER_SIZE, true,
-                 PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE,
+                 "Input image size exceeds that of mask image: (%d, %d) vs (%d, %d)",
                  inMask->numRows, inMask->numCols, exMask->numRows, exMask->numCols);
         return false;
@@ -103,7 +46,7 @@
         // set raised pixels in exMask which are selected by maskVal
         for (int j = 0; j < inMask->numRows; j++) {
-            xJ = j - offRow;
+            int xJ = j - offRow;
             for (int i = 0; i < inMask->numCols; i++) {
-                xI = i - offCol;
+                int xI = i - offCol;
                 inVal[j][i] |= (maskVal & exVal[xJ][xI]);
             }
@@ -112,7 +55,7 @@
         // set raised pixels in exMask which are selected by maskVal
         for (int j = 0; j < inMask->numRows; j++) {
-            xJ = j - offRow;
+            int xJ = j - offRow;
             for (int i = 0; i < inMask->numCols; i++) {
-                xI = i - offCol;
+                int xI = i - offCol;
                 if (exVal[xJ][xI] == 0) {
                     inVal[j][i] |= PM_MASK_BAD;
Index: /trunk/psModules/src/detrend/pmMaskBadPixels.h
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 9615)
+++ /trunk/psModules/src/detrend/pmMaskBadPixels.h	(revision 9616)
@@ -1,40 +1,35 @@
-/** @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.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-10 02:59:23 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
+/// @file pmMaskBadPixels.h
+///
+/// @brief Mask bad pixels
+///
+/// @ingroup Detrend
+///
+/// @author Ross Harman, MHPCC
+/// @author Eugene Magnier, IfA
+///
+/// @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2006-10-17 22:17:38 $
+///
+/// Copyright 2004 Institute for Astronomy, University of Hawaii
+///
+
 #ifndef PM_MASK_BAD_PIXELS_H
 #define PM_MASK_BAD_PIXELS_H
 
-#include "pslib.h"
+#include <pslib.h>
 #include "pmFPA.h"
 
-/** Execute bad pixels module.
- *
- *
- *  @return  bool: True or false for success or failure
- */
-
-bool pmMaskBadPixels(pmReadout *input, pmReadout *mask, psMaskType maskVal);
+/// Applies the bad pixel mask to the input
+///
+/// Pixels marked as bad within the mask are marked as bad within the input image's mask.  If maskVal is
+/// non-zero, all pixels in the mask have any of the same bits sets as maskVal shall have the corresponding
+/// bits raised.  If maskVal is zero, any zero pixels in the mask are OR-ed with PM_MASK_BAD.  Position
+/// offsets (such as due to trimming) between the input and mask are applied so that the same pixels are
+/// referred to.  The science readout must already have a supplied mask element (use eg. pmReadoutSetMask).
+/// The supplied mask image must be of MASK type
+bool pmMaskBadPixels(pmReadout *input,  ///< Input science image
+                     const pmReadout *mask, ///< Mask image to apply
+                     psMaskType maskVal ///< Mask value to apply
+                    );
 
 #endif
Index: unk/psModules/src/detrend/pmMaskBadPixelsErrors.dat
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixelsErrors.dat	(revision 9615)
+++ 	(revision )
@@ -1,20 +1,0 @@
-#
-#  This file is used to generate pmMaskBadPixelsErrors.h content
-#
-#  Format is:
-#  ERRORNAME(one word)    ERRORTEXT
-#
-#  N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME
-####################################################################
-#
-pmMaskBadPixels_NULL_MASK_IMAGE            Null not allowed for mask image.
-pmMaskBadPixels_NULL_INPUT_IMAGE           Null not allowed for input image.
-pmMaskBadPixels_SIZE_INPUT_IMAGE           Input image size exceeds that of mask image: (%d, %d) vs (%d, %d)
-pmMaskBadPixels_SIZE_MASK_IMAGE            Input image mask size exceeds that of mask image: (%d, %d) vs (%d, %d)
-pmMaskBadPixels_OFFSET_MASK_IMAGE          Total offset >= mask image: (%d, %d) vs (%d, %d)
-pmMaskBadPixels_OFFSET_INPUT_IMAGE         Total offset >= input image: (%d, %d) vs (%d, %d)
-pmMaskBadPixels_OFFSET_INPUT_IMAGE_MASK    Total offset >= input image mask: (%d, %d) vs (%d, %d)
-pmMaskBadPixels_TYPE_INPUT_IMAGE           Complex types not allowed for input image. Type: %d
-pmMaskBadPixels_TYPE_MASK_IMAGE            Mask must be PS_TYPE_MASK type. Type: %d
-pmMaskBadPixels_TYPE_MISMATCH              Input and flat image types differ: (%d vs %d)
-pmMaskBadPixels_TYPE_UNSUPPORTED           Unsupported image datatype. Type: %d
Index: unk/psModules/src/detrend/pmMaskBadPixelsErrors.h
===================================================================
--- /trunk/psModules/src/detrend/pmMaskBadPixelsErrors.h	(revision 9615)
+++ 	(revision )
@@ -1,50 +1,0 @@
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// XXX WARNING: I have completely replaced this file with an OLD VERSION (that works) instead of the
-// one that was being worked on.
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-/** @file  pmMaskBadPixelsErrors.h
- *
- *  @brief Contains the error text for the mask bad pixels module
- *
- *  @ingroup ErrorHandling
- *
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-17 18:10:08 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
-
-#ifndef PM_FLATFIELD_ERRORS_H
-#define PM_FLATFIELD_ERRORS_H
-
-/* N.B., lines between '//~Start' and '//~End' are automatic generated from
- * the template following the '//~Start'.  The template is used to generate
- * the other lines by, for each error text in pmMaskBadPixelsErrors.dat, the following
- * substitutions are made:
- *     $1  The error text macro name (first word in the pmMaskBadPixelsErrors.h lines)
- *     $2  The error text (rest of the line in pmMaskBadPixelsErrors.h)
- *     $n  The order of the source line in pmMaskBadPixelsErrors.h (comments excluded)
- *
- * DO NOT EDIT THE LINES BETWEEN //~Start and //~End!  ANY CHANGES WILL BE OVERWRITTEN.
- */
-
-#define PS_ERRORNAME_DOMAIN "psModule.src."
-
-//~Start #define PS_ERRORTEXT_$1 "$2"
-#define PS_ERRORTEXT_pmMaskBadPixels_NULL_MASK_IMAGE "Null not allowed for mask image."
-#define PS_ERRORTEXT_pmMaskBadPixels_NULL_INPUT_IMAGE "Null not allowed for input image."
-#define PS_ERRORTEXT_pmMaskBadPixels_SIZE_INPUT_IMAGE "Input image size exceeds that of mask image: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmMaskBadPixels_SIZE_MASK_IMAGE "Input image mask size exceeds that of mask image: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmMaskBadPixels_OFFSET_MASK_IMAGE "Total offset >= mask image: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE "Total offset >= input image: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmMaskBadPixels_OFFSET_INPUT_IMAGE_MASK "Total offset >= input image mask: (%d, %d) vs (%d, %d)"
-#define PS_ERRORTEXT_pmMaskBadPixels_TYPE_INPUT_IMAGE "Complex types not allowed for input image. Type: %d"
-#define PS_ERRORTEXT_pmMaskBadPixels_TYPE_MASK_IMAGE "Mask must be PS_TYPE_MASK type. Type: %d"
-#define PS_ERRORTEXT_pmMaskBadPixels_TYPE_MISMATCH "Input and flat image types differ: (%d vs %d)"
-#define PS_ERRORTEXT_pmMaskBadPixels_TYPE_UNSUPPORTED "Unsupported image datatype. Type: %d"
-//~End
-
-#endif
