Index: /trunk/psModules/src/camera/Makefile.am
===================================================================
--- /trunk/psModules/src/camera/Makefile.am	(revision 13897)
+++ /trunk/psModules/src/camera/Makefile.am	(revision 13898)
@@ -26,5 +26,6 @@
 	pmFPALevel.c \
 	pmFPAExtent.c \
-	pmCellSquish.c
+	pmCellSquish.c \
+	pmReadoutStack.c
 
 pkginclude_HEADERS = \
@@ -51,5 +52,6 @@
 	pmFPALevel.h \
 	pmFPAExtent.h \
-	pmCellSquish.h
+	pmCellSquish.h \
+	pmReadoutStack.h
 
 CLEANFILES = *~
Index: /trunk/psModules/src/camera/pmFPAMosaic.c
===================================================================
--- /trunk/psModules/src/camera/pmFPAMosaic.c	(revision 13897)
+++ /trunk/psModules/src/camera/pmFPAMosaic.c	(revision 13898)
@@ -22,4 +22,9 @@
 
 #define CELL_LIST_BUFFER 10             // Buffer size for cell lists
+
+#define BLANK_VALUE 0.0                 // Value for pixels that are blank in the mosaicked image (e.g., //
+                                        // between cells).
+                                        // XXX This should ultimately be set to NAN, but psphot doesn't like
+                                        // that (masking needs to be more thorough).
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -397,5 +402,5 @@
                     for (int x = 0; x < image->numCols; x++) { \
                         int xTarget = xTargetBase + xParity * x; \
-                        mosaic->data.TYPE[yTarget][xTarget] += image->data.TYPE[y][x]; \
+                        mosaic->data.TYPE[yTarget][xTarget] = image->data.TYPE[y][x]; \
                     } \
                 } \
@@ -416,5 +421,5 @@
                         for (int k = 0; k < xBinSource->data.S32[i]; k++) { \
                             int xTarget = (int)(xTargetBinBase + xParity * (float)k / (float)xBinTarget); \
-                            mosaic->data.TYPE[yTarget][xTarget] += image->data.TYPE[y][x]; \
+                            mosaic->data.TYPE[yTarget][xTarget] = image->data.TYPE[y][x]; \
                         } \
                     } \
@@ -504,5 +509,5 @@
     psTrace("psModules.camera", 3, "Spliced image will be %dx%d\n", (int)xSize, (int)ySize);
     psImage *mosaic = psImageAlloc((int)xSize, (int)ySize, type); // The mosaic image
-    psImageInit(mosaic, 0);
+    psImageInit(mosaic, unexposed);
 
     // Next pass through the images to do the mosaicking
@@ -524,5 +529,5 @@
             (yFlip->data.U8[i] == 0)) {
             // Let someone else do the hard work
-            psImageOverlaySection(mosaic, image, xTargetBase, yTargetBase, "+");
+            psImageOverlaySection(mosaic, image, xTargetBase, yTargetBase, "=");
             continue;
         }
@@ -723,5 +728,6 @@
                        int *xBinChip, int *yBinChip, // The binning in x and y, to be returned
                        const pmChip *chip, // Chip to mosaic
-                       const pmCell *targetCell // Cell to which to mosaic
+                       const pmCell *targetCell, // Cell to which to mosaic
+                       psMaskType blank // Mask value to give blank pixels
                       )
 {
@@ -804,7 +810,7 @@
     // Mosaic the images together and we're done
     if (allGood) {
-        *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, NAN);
-        *mosaicWeights = imageMosaic(weights, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, NAN);
-        *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, 0xff);
+        *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE);
+        *mosaicWeights = imageMosaic(weights, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, BLANK_VALUE);
+        *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinChip, *yBinChip, x0, y0, blank);
     }
 
@@ -830,5 +836,6 @@
                       const pmFPA *fpa,  // FPA to mosaic
                       const pmChip *targetChip, // Chip to which to mosaic
-                      const pmCell *targetCell // Cell to which to mosaic
+                      const pmCell *targetCell, // Cell to which to mosaic
+                      psMaskType blank  // Mask value to give blank pixels
                      )
 {
@@ -937,7 +944,7 @@
     // Mosaic the images together and we're done
     if (allGood) {
-        *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, NAN);
-        *mosaicWeights = imageMosaic(weights, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, NAN);
-        *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, 0xff);
+        *mosaicImage = imageMosaic(images, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE);
+        *mosaicWeights = imageMosaic(weights, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, BLANK_VALUE);
+        *mosaicMask = imageMosaic(masks, xFlip, yFlip, xBin, yBin, *xBinFPA, *yBinFPA, x0, y0, blank);
     }
 
@@ -986,5 +993,5 @@
 // the mosaic image.
 
-bool pmChipMosaic(pmChip *target, const pmChip *source, bool deepCopy)
+bool pmChipMosaic(pmChip *target, const pmChip *source, bool deepCopy, psMaskType blank)
 {
     // Target exists, and has only a single cell
@@ -1039,5 +1046,5 @@
         // Case 2 --- we need to mosaic by cut and paste
         psTrace("psModules.camera", 1, "Case 2 mosaicking: cut and paste.\n");
-        if (!chipMosaic(&mosaicImage, &mosaicMask, &mosaicWeights, &xBin, &yBin, source, targetCell)) {
+        if (!chipMosaic(&mosaicImage, &mosaicMask, &mosaicWeights, &xBin, &yBin, source, targetCell, blank)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to mosaic cells.\n");
             return false;
@@ -1217,5 +1224,5 @@
 
 
-bool pmFPAMosaic(pmFPA *target, const pmFPA *source, bool deepCopy)
+bool pmFPAMosaic(pmFPA *target, const pmFPA *source, bool deepCopy, psMaskType blank)
 {
     // Target exists, and has only a single chip with single cell
@@ -1260,5 +1267,5 @@
         psTrace("psModules.camera", 1, "Case 2 mosaicking: cut and paste.\n");
         if (!fpaMosaic(&mosaicImage, &mosaicMask, &mosaicWeights, &xBin, &yBin, source,
-                       targetChip, targetCell)) {
+                       targetChip, targetCell, blank)) {
             psError(PS_ERR_UNKNOWN, false, "Unable to mosaic chips.\n");
             return false;
Index: /trunk/psModules/src/camera/pmFPAMosaic.h
===================================================================
--- /trunk/psModules/src/camera/pmFPAMosaic.h	(revision 13897)
+++ /trunk/psModules/src/camera/pmFPAMosaic.h	(revision 13898)
@@ -4,6 +4,6 @@
  * @author Paul Price, IfA
  *
- * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-03-30 21:12:56 $
+ * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  * Copyright 2005-2006 Institute for Astronomy, University of Hawaii
  */
@@ -22,6 +22,7 @@
 /// the pixels, if possible.
 bool pmChipMosaic(pmChip *target,       ///< Target chip --- may contain only a single cell
-                  const pmChip *source,  ///< Source chip whose cells will be mosaicked
-		  bool deepCopy		///< require a deep copy (disregard 'nice' chip) 
+                  const pmChip *source, ///< Source chip whose cells will be mosaicked
+                  bool deepCopy,        ///< Require a deep copy (disregard 'nice' chip)
+                  psMaskType blank      ///< Mask value to give blank pixels
     );
 
@@ -32,8 +33,9 @@
 /// CELL.X0 and CELL.Y0 offsets.  This is useful for getting an image of the FPA on the sky.  The mosaicking
 /// is done so as to avoid performing a deep copy of the pixels, if possible.
-bool pmFPAMosaic(pmFPA *target,	///< Target FPA --- may contain only a single chip with a single cell
-                 const pmFPA *source,	///< FPA whose chips and cells will be mosaicked
-                 bool deepCopy		///< require a deep copy (disregard 'nice' chip) 
-                );			// 
+bool pmFPAMosaic(pmFPA *target, ///< Target FPA --- may contain only a single chip with a single cell
+                 const pmFPA *source,   ///< FPA whose chips and cells will be mosaicked
+                 bool deepCopy,         ///< Require a deep copy (disregard 'nice' chip)
+                 psMaskType blank       ///< Mask value to give blank pixels
+                );
 /// @}
 #endif
Index: /trunk/psModules/src/objects/pmModel.c
===================================================================
--- /trunk/psModules/src/objects/pmModel.c	(revision 13897)
+++ /trunk/psModules/src/objects/pmModel.c	(revision 13898)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-13 23:41:51 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-20 02:22:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -60,5 +60,5 @@
     tmp->radiusFit = 0;
     tmp->flags = PM_MODEL_STATUS_NONE;
-    tmp->residuals = NULL;		// XXX should the model own this memory?
+    tmp->residuals = NULL;              // XXX should the model own this memory?
 
     psS32 Nparams = pmModelParameterCount(type);
@@ -105,7 +105,7 @@
 /******************************************************************************
     pmModelEval(source, level, row): evaluates the model function at the specified coords.
- 
+
     NOTE: The coords are in subImage source->pixel coords, not image coords.
- 
+
     XXX: Use static vectors for x (NO: needs to be thread safe)
 *****************************************************************************/
@@ -132,10 +132,11 @@
 }
 
-bool AddOrSubModel(psImage *image,
-                   psImage *mask,
-                   pmModel *model,
-                   pmModelOpMode mode,
-                   bool add
-                      )
+static bool AddOrSubModel(psImage *image,
+                          psImage *mask,
+                          pmModel *model,
+                          pmModelOpMode mode,
+                          bool add,
+                          psMaskType maskVal
+    )
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -151,5 +152,5 @@
     psS32 imageRow;
     psF32 pixelValue;
-    
+
     // save original values; restore before returning
     // use the true source position for the residual model
@@ -161,12 +162,12 @@
 
     if (mode & PM_MODEL_OP_NORM) {
-	params->data.F32[PM_PAR_I0] = 1.0;
+        params->data.F32[PM_PAR_I0] = 1.0;
     }
     if (!(mode & PM_MODEL_OP_SKY)) {
-	params->data.F32[PM_PAR_SKY] = 0.0;
+        params->data.F32[PM_PAR_SKY] = 0.0;
     }
     if (mode & PM_MODEL_OP_CENTER) {
-	params->data.F32[PM_PAR_XPOS] = image->col0 + 0.5*image->numCols;
-	params->data.F32[PM_PAR_YPOS] = image->row0 + 0.5*image->numRows;
+        params->data.F32[PM_PAR_XPOS] = image->col0 + 0.5*image->numCols;
+        params->data.F32[PM_PAR_YPOS] = image->row0 + 0.5*image->numRows;
     }
 
@@ -185,65 +186,65 @@
     psImageInterpolateOptions *Ry = NULL;
     if (model->residuals && (mode & (PM_MODEL_OP_RES0 | PM_MODEL_OP_RES1))) {
-	Ro = psImageInterpolateOptionsAlloc(
-	    PS_INTERPOLATE_BILINEAR,
-	    model->residuals->Ro, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
-	Rx = psImageInterpolateOptionsAlloc(
-	    PS_INTERPOLATE_BILINEAR,
-	    model->residuals->Rx, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
-	Ry = psImageInterpolateOptionsAlloc(
-	    PS_INTERPOLATE_BILINEAR,
-	    model->residuals->Ry, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
-
-	xBin = model->residuals->xBin;
-	yBin = model->residuals->yBin;
-	xResidCenter = model->residuals->xCenter;
-	yResidCenter = model->residuals->yCenter;
+        Ro = psImageInterpolateOptionsAlloc(
+            PS_INTERPOLATE_BILINEAR,
+            model->residuals->Ro, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
+        Rx = psImageInterpolateOptionsAlloc(
+            PS_INTERPOLATE_BILINEAR,
+            model->residuals->Rx, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
+        Ry = psImageInterpolateOptionsAlloc(
+            PS_INTERPOLATE_BILINEAR,
+            model->residuals->Ry, NULL, NULL, 0, 0.0, 0.0, 1, 0, 0.0);
+
+        xBin = model->residuals->xBin;
+        yBin = model->residuals->yBin;
+        xResidCenter = model->residuals->xCenter;
+        yResidCenter = model->residuals->yCenter;
     }
 
     for (psS32 iy = 0; iy < image->numRows; iy++) {
         for (psS32 ix = 0; ix < image->numCols; ix++) {
-            if ((mask != NULL) && mask->data.U8[iy][ix])
+            if ((mask != NULL) && (mask->data.U8[iy][ix] & maskVal))
                 continue;
 
             // Convert i/j to image coord space:
-	    // XXX should we use using 0.5 pixel offset?
-	    imageCol = ix + image->col0;
-	    imageRow = iy + image->row0;
+            // XXX should we use using 0.5 pixel offset?
+            imageCol = ix + image->col0;
+            imageRow = iy + image->row0;
 
             x->data.F32[0] = (float) imageCol;
             x->data.F32[1] = (float) imageRow;
 
-	    pixelValue = 0.0;
+            pixelValue = 0.0;
 
             // add in the desired components for this coordinate
             if (mode & PM_MODEL_OP_FUNC) {
                 pixelValue += modelFunc (NULL, params, x);
-            } 
-
-	    // get the contribution from the residual model
-	    if (Ro) {
-		// fractional image position
-		float ox = xBin*(imageCol + 0.5 - xCenter) + xResidCenter;
-		float oy = yBin*(imageRow + 0.5 - yCenter) + yResidCenter;
-
-		if (mode & PM_MODEL_OP_RES0) {
-		    psU8 mflux = 0;
-		    double Fo = 0.0;
-		    psImageInterpolate (&Fo, NULL, &mflux, ox, oy, Ro);
-		    if (!mflux && isfinite(Fo)) {
-			pixelValue += Io*Fo;
-		    }
-		}
-		if (mode & PM_MODEL_OP_RES1) {
-		    psU8 mflux = 0;
-		    double Fx = 0.0;
-		    double Fy = 0.0;
-		    psImageInterpolate (&Fx, NULL, &mflux, ox, oy, Rx);
-		    psImageInterpolate (&Fy, NULL, &mflux, ox, oy, Ry);
-		    if (!mflux && isfinite(Fx) && isfinite(Fy)) {
-			pixelValue += Io*(xPos*Fx + yPos*Fy);
-		    }
-		}
-	    }
+            }
+
+            // get the contribution from the residual model
+            if (Ro) {
+                // fractional image position
+                float ox = xBin*(imageCol + 0.5 - xCenter) + xResidCenter;
+                float oy = yBin*(imageRow + 0.5 - yCenter) + yResidCenter;
+
+                if (mode & PM_MODEL_OP_RES0) {
+                    psU8 mflux = 0;
+                    double Fo = 0.0;
+                    psImageInterpolate (&Fo, NULL, &mflux, ox, oy, Ro);
+                    if (!mflux && isfinite(Fo)) {
+                        pixelValue += Io*Fo;
+                    }
+                }
+                if (mode & PM_MODEL_OP_RES1) {
+                    psU8 mflux = 0;
+                    double Fx = 0.0;
+                    double Fy = 0.0;
+                    psImageInterpolate (&Fx, NULL, &mflux, ox, oy, Rx);
+                    psImageInterpolate (&Fy, NULL, &mflux, ox, oy, Ry);
+                    if (!mflux && isfinite(Fx) && isfinite(Fy)) {
+                        pixelValue += Io*(xPos*Fx + yPos*Fy);
+                    }
+                }
+            }
 
             // add or subtract the value
@@ -275,8 +276,9 @@
                 psImage *mask,
                 pmModel *model,
-                pmModelOpMode mode)
-{
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
-    psBool rc = AddOrSubModel(image, mask, model, mode, true);
+                pmModelOpMode mode,
+                psMaskType maskVal)
+{
+    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    psBool rc = AddOrSubModel(image, mask, model, mode, true, maskVal);
     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     return(rc);
@@ -288,8 +290,9 @@
                 psImage *mask,
                 pmModel *model,
-                pmModelOpMode mode)
-{
-    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
-    psBool rc = AddOrSubModel(image, mask, model, mode, false);
+                pmModelOpMode mode,
+                psMaskType maskVal)
+{
+    psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
+    psBool rc = AddOrSubModel(image, mask, model, mode, false, maskVal);
     psTrace("psModules.objects", 3, "---- %s(%d) end ----\n", __func__, rc);
     return(rc);
Index: /trunk/psModules/src/objects/pmModel.h
===================================================================
--- /trunk/psModules/src/objects/pmModel.h	(revision 13897)
+++ /trunk/psModules/src/objects/pmModel.h	(revision 13898)
@@ -5,6 +5,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-13 23:41:51 $
+ * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  *
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -30,13 +30,13 @@
 
 typedef enum {
-    PM_MODEL_OP_NONE 	= 0x00,
-    PM_MODEL_OP_FUNC 	= 0x01,
-    PM_MODEL_OP_RES0 	= 0x02,
-    PM_MODEL_OP_RES1 	= 0x04,
+    PM_MODEL_OP_NONE    = 0x00,
+    PM_MODEL_OP_FUNC    = 0x01,
+    PM_MODEL_OP_RES0    = 0x02,
+    PM_MODEL_OP_RES1    = 0x04,
     PM_MODEL_OP_FULL    = 0x07,
-    PM_MODEL_OP_SKY  	= 0x08,
+    PM_MODEL_OP_SKY     = 0x08,
     PM_MODEL_OP_CENTER  = 0x10,
-    PM_MODEL_OP_NORM  	= 0x20,
-    PM_MODEL_OP_NOISE  	= 0x40,
+    PM_MODEL_OP_NORM    = 0x20,
+    PM_MODEL_OP_NOISE   = 0x40,
 } pmModelOpMode;
 
@@ -52,14 +52,14 @@
 typedef struct
 {
-    pmModelType type;			///< Model to be used.
-    psVector *params;			///< Paramater values.
-    psVector *dparams;			///< Parameter errors.
-    float chisq;			///< Fit chi-squared.
-    float chisqNorm;			///< re-normalized fit chi-squared.
-    int nDOF;				///< number of degrees of freedom
-    int nIter;				///< number of iterations to reach min
-    pmModelStatus flags;		///< model status flags
-    float radiusFit;			///< fit radius actually used
-    pmResiduals *residuals; 		///< normalized PSF residuals 
+    pmModelType type;                   ///< Model to be used.
+    psVector *params;                   ///< Paramater values.
+    psVector *dparams;                  ///< Parameter errors.
+    float chisq;                        ///< Fit chi-squared.
+    float chisqNorm;                    ///< re-normalized fit chi-squared.
+    int nDOF;                           ///< number of degrees of freedom
+    int nIter;                          ///< number of iterations to reach min
+    pmModelStatus flags;                ///< model status flags
+    float radiusFit;                    ///< fit radius actually used
+    pmResiduals *residuals;             ///< normalized PSF residuals
 }
 pmModel;
@@ -105,8 +105,9 @@
  */
 bool pmModelAdd(
-    psImage *image,			///< The output image (float)
-    psImage *mask,			///< The image pixel mask (valid == 0)
-    pmModel *model,			///< The input pmModel
-    pmModelOpMode mode		     ///< mode to control how the model is added into the image
+    psImage *image,                     ///< The output image (float)
+    psImage *mask,                      ///< The image pixel mask (valid == 0)
+    pmModel *model,                     ///< The input pmModel
+    pmModelOpMode mode,                 ///< mode to control how the model is added into the image
+    psMaskType maskVal                  ///< Value to mask
 );
 
@@ -122,8 +123,9 @@
  */
 bool pmModelSub(
-    psImage *image,			///< The output image (float)
-    psImage *mask,			///< The image pixel mask (valid == 0)
-    pmModel *model,			///< The input pmModel
-    pmModelOpMode mode		     ///< mode to control how the model is added into the image
+    psImage *image,                     ///< The output image (float)
+    psImage *mask,                      ///< The image pixel mask (valid == 0)
+    pmModel *model,                     ///< The input pmModel
+    pmModelOpMode mode,                 ///< mode to control how the model is added into the image
+    psMaskType maskVal                  ///< Value to mask
 );
 
Index: /trunk/psModules/src/objects/pmPSF.c
===================================================================
--- /trunk/psModules/src/objects/pmPSF.c	(revision 13897)
+++ /trunk/psModules/src/objects/pmPSF.c	(revision 13898)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-13 23:41:51 $
+ *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-20 02:22:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -81,9 +81,9 @@
 /*****************************************************************************
  pmPSFAlloc (type): allocate a pmPSF.
- 
+
  NOTE: PSF model parameters which are not modeled on an image are set to NULL in psf->params.
- 
+
  These are normally:
- 
+
  X-center
  Y-center
@@ -180,7 +180,7 @@
     // set model parameters for this source based on PSF information
     if (!modelFromPSFFunc (modelPSF, modelEXT, psf)) {
-	psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
-	psFree(modelPSF);
-	return NULL;
+        psError(PM_ERR_PSF, false, "Failed to set model params from PSF");
+        psFree(modelPSF);
+        return NULL;
     }
     // XXX note that model->residuals is just a reference
@@ -245,5 +245,5 @@
 // New Concept: the PSF modelling function fits the polarization terms e0, e1, e2:
 
-// convert the parameters used in the fitted source model 
+// convert the parameters used in the fitted source model
 // to the parameters used in the 2D PSF model
 bool pmPSF_FitToModel (psF32 *fittedPar, float minMinorAxis)
@@ -257,7 +257,7 @@
     psEllipseAxes axes;
     if (psEllipsePolToAxes (pol, minMinorAxis, &axes) != PS_ERR_NONE) {
-	psError(PM_ERR_PSF, false, "Failed to convert e[012] (%g,%g,%g) to axes",
-		pol.e0, pol.e1, pol.e2);
-	return false;
+        psError(PM_ERR_PSF, false, "Failed to convert e[012] (%g,%g,%g) to axes",
+                pol.e0, pol.e1, pol.e2);
+        return false;
     }
     psEllipseShape shape = psEllipseAxesToShape (axes);
@@ -279,7 +279,7 @@
     shape.sy  = modelPar[PM_PAR_SYY] / M_SQRT2;
     shape.sxy = modelPar[PM_PAR_SXY];
-    
+
     psEllipsePol pol = psEllipseShapeToPol (shape);
-    
+
     return pol;
 }
@@ -297,12 +297,12 @@
 
     if ((shape.sx == 0) || (shape.sy == 0)) {
-	axes.major = 0.0;
-	axes.minor = 0.0;
-	axes.theta = 0.0;
+        axes.major = 0.0;
+        axes.minor = 0.0;
+        axes.theta = 0.0;
     } else {
-	// XXX this is not really consistent with the model fit range above
-	axes = psEllipseShapeToAxes (shape, maxAR);
-    }
-    
+        // XXX this is not really consistent with the model fit range above
+        axes = psEllipseShapeToAxes (shape, maxAR);
+    }
+
     return axes;
 }
@@ -313,10 +313,10 @@
 {
     if ((axes.major <= 0) || (axes.minor <= 0)) {
-	modelPar[PM_PAR_SXX] = 0.0;
-	modelPar[PM_PAR_SYY] = 0.0;
-	modelPar[PM_PAR_SXY] = 0.0;
-	return true;
-    }	
-    
+        modelPar[PM_PAR_SXX] = 0.0;
+        modelPar[PM_PAR_SYY] = 0.0;
+        modelPar[PM_PAR_SXY] = 0.0;
+        return true;
+    }
+
     psEllipseShape shape = psEllipseAxesToShape (axes);
 
@@ -478,5 +478,5 @@
 
 // we generate the growth curve for the center of the image with the specified psf model
-bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore)
+bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType mark)
 {
 
@@ -526,10 +526,10 @@
     // no need to mask the source here
     // XXX should we measure this for the analytical model only or the full model?
-    pmModelAdd (image, NULL, model, PM_MODEL_OP_FULL);
+    pmModelAdd (image, NULL, model, PM_MODEL_OP_FULL, maskVal);
 
     // loop over a range of source fluxes
     // no need to interpolate since we have forced the object center
     // to 0.5, 0.5 above
-    bool completeGrowthCurve = true;		// do we have a complete curve of growth?
+    bool completeGrowthCurve = true;            // do we have a complete curve of growth?
     for (int i = 0; i < psf->growth->radius->n; i++) {
 
@@ -537,13 +537,13 @@
 
         // mask the given aperture and measure the apMag
-        psImageKeepCircle (mask, xc, yc, radius, "OR", PM_MASK_MARK);
-        if (!pmSourcePhotometryAper (&apMag, model, image, mask)) {
-	    psError(PM_ERR_PHOTOM, false, "Measuring apMag for radius == %g", radius);
-	    completeGrowthCurve = false;
-	    break;
-	}
-
-	// XXX since we re-mask on each pass, this could be dropped.
-        psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_U8(PM_MASK_MARK));
+        psImageKeepCircle (mask, xc, yc, radius, "OR", mark);
+        if (!pmSourcePhotometryAper (&apMag, model, image, mask, maskVal)) {
+            psError(PM_ERR_PHOTOM, false, "Measuring apMag for radius == %g", radius);
+            completeGrowthCurve = false;
+            break;
+        }
+
+        // XXX since we re-mask on each pass, this could be dropped.
+        psImageKeepCircle (mask, xc, yc, radius, "AND", PS_NOT_U8(mark));
 
         // the 'ignore' mode is for testing
@@ -556,9 +556,9 @@
 
     if (completeGrowthCurve) {
-	psf->growth->apRef = psVectorInterpolate (psf->growth->radius, psf->growth->apMag, psf->growth->refRadius);
-	psf->growth->apLoss = psf->growth->fitMag - psf->growth->apRef;
+        psf->growth->apRef = psVectorInterpolate (psf->growth->radius, psf->growth->apMag, psf->growth->refRadius);
+        psf->growth->apLoss = psf->growth->fitMag - psf->growth->apRef;
     } else {
-	psf->growth->apRef = NAN;
-	psf->growth->apLoss = 0;
+        psf->growth->apRef = NAN;
+        psf->growth->apLoss = 0;
     }
 
Index: /trunk/psModules/src/objects/pmPSF.h
===================================================================
--- /trunk/psModules/src/objects/pmPSF.h	(revision 13897)
+++ /trunk/psModules/src/objects/pmPSF.h	(revision 13898)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-04-27 22:14:08 $
+ * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -31,5 +31,5 @@
 
 /** pmPSF data structure
- * 
+ *
  * It is useful to generate a model to define the point-spread-function which
  * describes the flux distribution for unresolved sources in an image. In
@@ -40,5 +40,5 @@
  * psArray. The other elements of the structure define the quality of the PSF
  * determination.
- * 
+ *
  */
 typedef struct
@@ -49,16 +49,16 @@
     // unfitted elements (So, Io, Xo, Yo) and leave them as NULL
     // I am using a new name to catch all refs to params with gcc
-    psPolynomial1D *ChiTrend;	      ///< Chisq vs flux fit (correction for systematic errors)
-    psPolynomial4D *ApTrend;		///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst))
-    float ApResid;			///< apMag - psfMag (for PSF stars)
-    float dApResid;			///< scatter of ApResid
-    float skyBias;			///< implied residual sky offset from ApResid fit
-    float skySat;			///< roll-over of ApResid fit
-    float chisq;			///< PSF goodness statistic (unused??)
-    int nPSFstars;			///< number of stars used to measure PSF
-    int nApResid;			///< number of stars used to measure ApResid
+    psPolynomial1D *ChiTrend;         ///< Chisq vs flux fit (correction for systematic errors)
+    psPolynomial4D *ApTrend;            ///< ApResid vs (x,y,rflux) (rflux = ten(0.4*mInst))
+    float ApResid;                      ///< apMag - psfMag (for PSF stars)
+    float dApResid;                     ///< scatter of ApResid
+    float skyBias;                      ///< implied residual sky offset from ApResid fit
+    float skySat;                       ///< roll-over of ApResid fit
+    float chisq;                        ///< PSF goodness statistic (unused??)
+    int nPSFstars;                      ///< number of stars used to measure PSF
+    int nApResid;                       ///< number of stars used to measure ApResid
     bool poissonErrors;
-    pmGrowthCurve *growth;		///< apMag vs Radius
-    pmResiduals *residuals;		///< normalized residual image (no spatial variation)
+    pmGrowthCurve *growth;              ///< apMag vs Radius
+    pmResiduals *residuals;             ///< normalized residual image (no spatial variation)
 }
 pmPSF;
@@ -69,7 +69,7 @@
 
 /**
- * 
+ *
  * Allocator for the pmPSF structure.
- * 
+ *
  */
 pmPSF *pmPSFAlloc(
@@ -80,5 +80,5 @@
 
 /**
- * 
+ *
  * This function constructs a pmModel instance based on the pmPSF description
  * of the PSF. The input is a pmModel with at least the values of the centroid
@@ -86,5 +86,5 @@
  * the PSF-dependent parameters are specified for the specific realization based
  * on the coordinates of the object.
- * 
+ *
  */
 pmModel *pmModelFromPSF(
@@ -100,5 +100,5 @@
 double pmPSF_SXYtoModel (psF32 *fittedPar);
 
-bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore);
+bool pmGrowthCurveGenerate (pmReadout *readout, pmPSF *psf, bool ignore, psMaskType maskVal, psMaskType mark);
 pmPSF *pmPSFBuildSimple (char *typeName, float sxx, float syy, float sxy, ...);
 
Index: /trunk/psModules/src/objects/pmPSFtry.c
===================================================================
--- /trunk/psModules/src/objects/pmPSFtry.c	(revision 13897)
+++ /trunk/psModules/src/objects/pmPSFtry.c	(revision 13898)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-13 23:41:51 $
+ *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-20 02:22:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -96,5 +96,5 @@
 
 // generate a pmPSFtry with a copy of the test PSF sources
-pmPSFtry *pmPSFtryModel (psArray *sources, char *modelName, float RADIUS, bool poissonErrors, psPolynomial2D *psfTrendMask, bool applyWeights)
+pmPSFtry *pmPSFtryModel (psArray *sources, char *modelName, float RADIUS, bool poissonErrors, psPolynomial2D *psfTrendMask, bool applyWeights, psMaskType maskVal, psMaskType mark)
 {
     bool status;
@@ -116,13 +116,13 @@
         if (source->modelEXT == NULL) {
             psError(PS_ERR_UNKNOWN, false, "failed to build model");
-	    psFree(psfTry);
+            psFree(psfTry);
             return NULL;
         }
 
         // set object mask to define valid pixels
-        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, RADIUS, "OR", PM_MASK_MARK);
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, RADIUS, "OR", mark);
 
         // fit model as EXT, not PSF
-        status = pmSourceFitModel (source, source->modelEXT, PM_SOURCE_FIT_EXT);
+        status = pmSourceFitModel (source, source->modelEXT, PM_SOURCE_FIT_EXT, maskVal);
 
         // exclude the poor fits
@@ -139,5 +139,5 @@
     if (!pmPSFFromPSFtry (psfTry, applyWeights)) {
         psError(PS_ERR_UNKNOWN, false, "failed to construct a psf model from collection of sources");
-	psFree(psfTry);
+        psFree(psfTry);
         return NULL;
     }
@@ -154,28 +154,28 @@
         // set shape for this model based on PSF
         source->modelPSF = pmModelFromPSF (source->modelEXT, psfTry->psf);
-	if (source->modelPSF == NULL) {
+        if (source->modelPSF == NULL) {
             psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_MODEL;
-	    abort();
-	    continue;
-	}
+            abort();
+            continue;
+        }
         source->modelPSF->radiusFit = RADIUS;
 
         // set object mask to define valid pixels
-        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, RADIUS, "OR", PM_MASK_MARK);
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, RADIUS, "OR", mark);
 
         // fit the PSF model to the source
-        status = pmSourceFitModel (source, source->modelPSF, PM_SOURCE_FIT_PSF);
+        status = pmSourceFitModel (source, source->modelPSF, PM_SOURCE_FIT_PSF, maskVal);
 
         // skip poor fits
         if (!status) {
             psfTry->mask->data.U8[i] = PSFTRY_MASK_PSF_FAIL;
-	    psTrace ("psModules.pmPSFtry", 4, "dropping %d (%d,%d) : failed PSF fit\n", i, source->peak->x, source->peak->y);
+            psTrace ("psModules.pmPSFtry", 4, "dropping %d (%d,%d) : failed PSF fit\n", i, source->peak->x, source->peak->y);
             continue;
         }
 
         // XXX : use a different aperture radius from the fit radius?
-        if (!pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP)) {
+        if (!pmSourceMagnitudes (source, psfTry->psf, PM_SOURCE_PHOT_INTERP, maskVal, mark)) {
             psfTry->mask->data.U8[i] = PSFTRY_MASK_BAD_PHOT;
-	    psTrace ("psModules.pmPSFtry", 4, "dropping %d (%d,%d) : poor photometry\n", i, source->peak->x, source->peak->y);
+            psTrace ("psModules.pmPSFtry", 4, "dropping %d (%d,%d) : poor photometry\n", i, source->peak->x, source->peak->y);
             continue;
         }
@@ -203,5 +203,5 @@
             flux->data.F64[i] = 0.0;
             chisq->data.F64[i] = 0.0;
-            mask->data.U8[i] = 1;
+            mask->data.U8[i] = 0xff;
         } else {
             flux->data.F64[i] = source->modelPSF->params->data.F32[PM_PAR_I0];
@@ -217,5 +217,5 @@
 
     // linear clipped fit of chisq trend vs flux
-    bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, stats, mask, 1, chisq, NULL, flux);
+    bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, stats, mask, 0xff, chisq, NULL, flux);
     psLogMsg ("pmPSFtry", 4, "chisq vs flux fit: %f +/- %f\n", stats->robustMedian, stats->robustStdev);
 
@@ -289,7 +289,7 @@
         psError(PS_ERR_UNKNOWN, false, "Failed to fit clipped poly");
 
-	psFree(poly);
-	psFree(r2rflux);
-	psFree(stats);
+        psFree(poly);
+        psFree(r2rflux);
+        psFree(stats);
 
         return false;
@@ -373,8 +373,8 @@
         y->data.F64[i] = source->modelEXT->params->data.F32[PM_PAR_YPOS];
 
-	// weight by the error on the source flux
-	if (dz) {
-	    dz->data.F64[i] = source->modelEXT->dparams->data.F32[PM_PAR_I0];
-	}
+        // weight by the error on the source flux
+        if (dz) {
+            dz->data.F64[i] = source->modelEXT->dparams->data.F32[PM_PAR_I0];
+        }
     }
 
@@ -399,12 +399,12 @@
     psVector *e2   = psVectorAlloc (psfTry->sources->n, PS_TYPE_F64);
     for (int i = 0; i < psfTry->sources->n; i++) {
-	pmSource *source = psfTry->sources->data[i];
-	if (source->modelEXT == NULL) continue;
-
-	psEllipsePol pol = pmPSF_ModelToFit (source->modelEXT->params->data.F32);
-
-	e0->data.F64[i] = pol.e0;
-	e1->data.F64[i] = pol.e1;
-	e2->data.F64[i] = pol.e2;
+        pmSource *source = psfTry->sources->data[i];
+        if (source->modelEXT == NULL) continue;
+
+        psEllipsePol pol = pmPSF_ModelToFit (source->modelEXT->params->data.F32);
+
+        e0->data.F64[i] = pol.e0;
+        e1->data.F64[i] = pol.e1;
+        e2->data.F64[i] = pol.e2;
     }
 
@@ -413,20 +413,20 @@
     for (int i = 0; i < stats->clipIter; i++) {
         psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E0], stats, psfTry->mask, 0xff, e0, dz, x, y);
-	psTrace ("psModules.pmPSFtry", 4, "clipped E0 : keeping %ld of %ld\n", stats->clippedNvalues, e0->n);
+        psTrace ("psModules.pmPSFtry", 4, "clipped E0 : keeping %ld of %ld\n", stats->clippedNvalues, e0->n);
         psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E1], stats, psfTry->mask, 0xff, e1, dz, x, y);
-	psTrace ("psModules.pmPSFtry", 4, "clipped E1 : keeping %ld of %ld\n", stats->clippedNvalues, e1->n);
+        psTrace ("psModules.pmPSFtry", 4, "clipped E1 : keeping %ld of %ld\n", stats->clippedNvalues, e1->n);
         psVectorClipFitPolynomial2D (psf->params_NEW->data[PM_PAR_E2], stats, psfTry->mask, 0xff, e2, dz, x, y);
-	psTrace ("psModules.pmPSFtry", 4, "clipped E2 : keeping %ld of %ld\n", stats->clippedNvalues, e2->n);
+        psTrace ("psModules.pmPSFtry", 4, "clipped E2 : keeping %ld of %ld\n", stats->clippedNvalues, e2->n);
     }
 
     // XXX temporary dump of the psf parameters
     if (psTraceGetLevel("psModules.objects") >= 4) {
-	FILE *f = fopen ("pol.dat", "w");
-	for (int i = 0; i < e0->n; i++) {
-	    fprintf (f, "%f %f  :  %f %f %f  : %d\n", 
-		     x->data.F64[i], y->data.F64[i], 
-		     e0->data.F64[i], e1->data.F64[i], e2->data.F64[i], psfTry->mask->data.U8[i]);
-	}
-	fclose (f);
+        FILE *f = fopen ("pol.dat", "w");
+        for (int i = 0; i < e0->n; i++) {
+            fprintf (f, "%f %f  :  %f %f %f  : %d\n",
+                     x->data.F64[i], y->data.F64[i],
+                     e0->data.F64[i], e1->data.F64[i], e2->data.F64[i], psfTry->mask->data.U8[i]);
+        }
+        fclose (f);
     }
 
@@ -437,16 +437,16 @@
     // skip the unfitted parameters (X, Y, Io, Sky) and the shape parameters (SXX, SYY, SXY)
     for (int i = 0; i < psf->params_NEW->n; i++) {
-	switch (i) {
-	  case PM_PAR_SKY:
-	  case PM_PAR_I0:
-	  case PM_PAR_XPOS:
-	  case PM_PAR_YPOS:            
-	  case PM_PAR_SXX:            
-	  case PM_PAR_SYY:            
-	  case PM_PAR_SXY:            
-	    continue;
-	  default:
-	    break;
-	}
+        switch (i) {
+          case PM_PAR_SKY:
+          case PM_PAR_I0:
+          case PM_PAR_XPOS:
+          case PM_PAR_YPOS:
+          case PM_PAR_SXX:
+          case PM_PAR_SYY:
+          case PM_PAR_SXY:
+            continue;
+          default:
+            break;
+        }
 
         // select the per-object fitted data for this parameter
@@ -463,9 +463,9 @@
         if (!psVectorClipFitPolynomial2D(psf->params_NEW->data[i], stats, psfTry->mask, 0xff, z, NULL, x, y)) {
             psError(PS_ERR_UNKNOWN, false, "failed to build psf model for parameter %d", i);
-	    psFree(stats);
-	    psFree(x);
-	    psFree(y);
-	    psFree(z);
-	    psFree(dz);
+            psFree(stats);
+            psFree(x);
+            psFree(y);
+            psFree(z);
+            psFree(dz);
             return false;
         }
Index: /trunk/psModules/src/objects/pmPSFtry.h
===================================================================
--- /trunk/psModules/src/objects/pmPSFtry.h	(revision 13897)
+++ /trunk/psModules/src/objects/pmPSFtry.h	(revision 13898)
@@ -6,6 +6,6 @@
  * @author EAM, IfA
  *
- * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-06-13 23:41:51 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -18,5 +18,5 @@
 
 /**
- * 
+ *
  * This structure contains a pointer to the collection of sources which will
  * be used to test the PSF model form. It lists the pmModelType type of model
@@ -38,9 +38,9 @@
  * ultimate metric to intercompare multiple types of PSF models is the value of
  * the aperture correction scatter.
- * 
+ *
  * XXX: There are many more members in the SDRS then in the prototype code.
  * I stuck with the prototype code.
- * 
- * 
+ *
+ *
  */
 typedef struct
@@ -57,8 +57,8 @@
 
 /** pmPSFtryMaskValues
- * 
+ *
  * The following datatype defines the masks used by the pmPSFtry analysis to
  * identify sources which should or should not be included in the analysis.
- * 
+ *
  */
 typedef enum {
@@ -74,24 +74,24 @@
 
 /** pmPSFtryAlloc()
- * 
+ *
  * Allocate a pmPSFtry data structure.
- * 
+ *
  */
 pmPSFtry *pmPSFtryAlloc (psArray *sources, char *modelName, bool poissonErrors, psPolynomial2D *psfTrendMask);
 
 /** pmPSFtryModel()
- * 
+ *
  * This function takes the input collection of sources and performs a complete
  * analysis to determine a PSF model of the given type (specified by model name).
  * The result is a pmPSFtry with the results of the analysis.
- * 
+ *
  */
-pmPSFtry *pmPSFtryModel (psArray *sources, char *modelName, float RADIUS, bool poissonErrors, psPolynomial2D *psfTrendMask, bool applyWeights);
+pmPSFtry *pmPSFtryModel (psArray *sources, char *modelName, float RADIUS, bool poissonErrors, psPolynomial2D *psfTrendMask, bool applyWeights, psMaskType maskVal, psMaskType mark);
 
 /** pmPSFtryMetric()
- * 
+ *
  * This function is used to measure the PSF model metric for the set of
  * results contained in the pmPSFtry structure.
- * 
+ *
  */
 bool pmPSFtryMetric(
@@ -113,5 +113,5 @@
 
 /**
- * 
+ *
  * This function takes a collection of pmModel fitted models from across a
  * single image and builds a pmPSF representation of the PSF. The input array of
@@ -122,5 +122,5 @@
  * outliers and excluded from the fit. These elements will be marked with a
  * specific mask value (1 == PSFTRY_MASK_OUTLIER).
- * 
+ *
  */
 bool pmPSFFromPSFtry (pmPSFtry *psfTry, bool applyWeights);
Index: /trunk/psModules/src/objects/pmSource.c
===================================================================
--- /trunk/psModules/src/objects/pmSource.c	(revision 13897)
+++ /trunk/psModules/src/objects/pmSource.c	(revision 13898)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-10 20:25:05 $
+ *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-20 02:22:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -135,5 +135,5 @@
     *source->moments = *in->moments;
 
-    // These images are all views to the parent.  
+    // These images are all views to the parent.
     // We want a new view, but pointing at the same pixels.
     source->pixels   = psImageCopyView (NULL, in->pixels);
@@ -143,5 +143,5 @@
     // the maskObj is a unique mask array; create a new mask image
     if (in->maskObj) {
-	source->maskObj = psImageCopy (NULL, in->maskObj, PS_TYPE_MASK);
+        source->maskObj = psImageCopy (NULL, in->maskObj, PS_TYPE_MASK);
     }
 
@@ -216,11 +216,11 @@
         mySource->region   = newRegion;
 
-	// re-copy the main mask pixels.  NOTE: the user will need to reset the object mask
-	// pixels (eg, with psImageKeepCircle)
-	mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_MASK);
-	
-	// drop the old modelFlux pixels and force the user to re-create
-	psFree (mySource->modelFlux);
-	mySource->modelFlux = NULL;
+        // re-copy the main mask pixels.  NOTE: the user will need to reset the object mask
+        // pixels (eg, with psImageKeepCircle)
+        mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_MASK);
+
+        // drop the old modelFlux pixels and force the user to re-create
+        psFree (mySource->modelFlux);
+        mySource->modelFlux = NULL;
     }
     return extend;
@@ -233,5 +233,5 @@
 
 // XXX EAM include a S/N cutoff in selecting the sources?
-// XXX this function should probably accept the values, not a recipe. wrap with a 
+// XXX this function should probably accept the values, not a recipe. wrap with a
 // psphot-specific function which applies the recipe values
 pmPSFClump pmSourcePSFClump(psArray *sources, psMetadata *recipe)
@@ -436,5 +436,5 @@
 *****************************************************************************/
 
-bool pmSourceRoughClass(psArray *sources, psMetadata *recipe, pmPSFClump clump)
+bool pmSourceRoughClass(psArray *sources, psMetadata *recipe, pmPSFClump clump, psMaskType maskSat)
 {
     psTrace("psModules.objects", 5, "---- begin ----");
@@ -487,5 +487,5 @@
         inner = psRegionForSquare (source->peak->x, source->peak->y, 2);
         inner = psRegionForImage (source->maskView, inner);
-        int Nsatpix = psImageCountPixelMask (source->maskView, inner, PM_MASK_SAT);
+        int Nsatpix = psImageCountPixelMask (source->maskView, inner, maskSat);
 
         // saturated star (size consistent with PSF or larger)
@@ -747,11 +747,11 @@
 }
 
-// construct a realization of the source model 
-bool pmSourceCacheModel (pmSource *source) {
+// construct a realization of the source model
+bool pmSourceCacheModel (pmSource *source, psMaskType maskVal) {
 
     // select appropriate model
     pmModel *model = pmSourceGetModel (NULL, source);
     if (model == NULL) return false;  // model must be defined
-	
+
     // if we already have a cached image, re-use that memory
     source->modelFlux = psImageCopy (source->modelFlux, source->pixels, PS_TYPE_F32);
@@ -761,17 +761,17 @@
     // in others, we just want the model.  which is more commonly used?
     // modelFlux always has unity normalization (I0 = 1.0)
-    pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM);
+    pmModelAdd (source->modelFlux, source->maskObj, model, PM_MODEL_OP_FULL | PM_MODEL_OP_NORM, maskVal);
     return true;
 }
 
 // should we call pmSourceCacheModel if it does not exist?
-bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add) {
+bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal) {
 
     bool status;
 
     if (add) {
-	psTrace ("psphot", 3, "replacing object at %f,%f\n", source->peak->xf, source->peak->yf);
+        psTrace ("psphot", 3, "replacing object at %f,%f\n", source->peak->xf, source->peak->yf);
     } else {
-	psTrace ("psphot", 3, "removing object at %f,%f\n", source->peak->xf, source->peak->yf);
+        psTrace ("psphot", 3, "removing object at %f,%f\n", source->peak->xf, source->peak->yf);
     }
 
@@ -780,53 +780,53 @@
 
     if (source->modelFlux) {
-	// add in the pixels from the modelFlux image
-	int dX = source->modelFlux->col0 - source->pixels->col0;
-	int dY = source->modelFlux->row0 - source->pixels->row0;
-	assert (dX >= 0);
-	assert (dY >= 0);
-	assert (dX + source->modelFlux->numCols <= source->pixels->numCols);
-	assert (dY + source->modelFlux->numRows <= source->pixels->numRows);
-	
-	// modelFlux has unity normalization
-	float Io = model->params->data.F32[PM_PAR_I0];
-	if (mode & PM_MODEL_OP_NORM) {
-	    Io = 1.0;
-	}
-
-	psU8 **mask = NULL;
-	if (source->maskObj) {
-	    mask = source->maskObj->data.U8;
-	}
-
-	psF32 **target = source->pixels->data.F32;
-	if (mode & PM_MODEL_OP_NOISE) {
-	    target = source->weight->data.F32;
-	}
-
-	// XXX need to respect the source and model masks?
-	for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
-	    int oy = iy + dY;
-	    for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
-		int ox = ix + dX;
-		if (mask && mask[iy][ix]) continue;
-		float value = Io*source->modelFlux->data.F32[iy][ix];
-		if (add) {
-		    target[oy][ox] += value;
-		} else {
-		    target[oy][ox] -= value;
-		}
-	    }
-	}
-	return true;
-    } 
+        // add in the pixels from the modelFlux image
+        int dX = source->modelFlux->col0 - source->pixels->col0;
+        int dY = source->modelFlux->row0 - source->pixels->row0;
+        assert (dX >= 0);
+        assert (dY >= 0);
+        assert (dX + source->modelFlux->numCols <= source->pixels->numCols);
+        assert (dY + source->modelFlux->numRows <= source->pixels->numRows);
+
+        // modelFlux has unity normalization
+        float Io = model->params->data.F32[PM_PAR_I0];
+        if (mode & PM_MODEL_OP_NORM) {
+            Io = 1.0;
+        }
+
+        psU8 **mask = NULL;
+        if (source->maskObj) {
+            mask = source->maskObj->data.U8;
+        }
+
+        psF32 **target = source->pixels->data.F32;
+        if (mode & PM_MODEL_OP_NOISE) {
+            target = source->weight->data.F32;
+        }
+
+        // XXX need to respect the source and model masks?
+        for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
+            int oy = iy + dY;
+            for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
+                int ox = ix + dX;
+                if (mask && (mask[iy][ix] & maskVal)) continue;
+                float value = Io*source->modelFlux->data.F32[iy][ix];
+                if (add) {
+                    target[oy][ox] += value;
+                } else {
+                    target[oy][ox] -= value;
+                }
+            }
+        }
+        return true;
+    }
 
     psImage *target = source->pixels;
     if (mode & PM_MODEL_OP_NOISE) {
-	target = source->weight;
+        target = source->weight;
     }
     if (add) {
-	status = pmModelAdd (target, source->maskObj, model, PM_MODEL_OP_FULL);
+        status = pmModelAdd (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     } else {
-	status = pmModelSub (target, source->maskObj, model, PM_MODEL_OP_FULL);
+        status = pmModelSub (target, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     }
 
@@ -834,12 +834,10 @@
 }
 
-bool pmSourceAdd (pmSource *source, pmModelOpMode mode) {
-    bool status = pmSourceOp (source, mode, true);
-    return status;
-}
-
-bool pmSourceSub (pmSource *source, pmModelOpMode mode) {
-    bool status = pmSourceOp (source, mode, false);
-    return status;
+bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
+    return pmSourceOp (source, mode, true, maskVal);
+}
+
+bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal) {
+    return pmSourceOp (source, mode, false, maskVal);
 }
 
@@ -863,5 +861,5 @@
         if (isPSF) {
             *isPSF = true;
-	}
+        }
         return model;
 
@@ -871,6 +869,6 @@
             if (isPSF) {
                 *isPSF = true;
-	    }
-	    return source->modelPSF;
+            }
+            return source->modelPSF;
         }
         return (model);
Index: /trunk/psModules/src/objects/pmSource.h
===================================================================
--- /trunk/psModules/src/objects/pmSource.h	(revision 13897)
+++ /trunk/psModules/src/objects/pmSource.h	(revision 13898)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-05-31 12:30:19 $
+ * @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -59,24 +59,24 @@
 typedef struct
 {
-    const int id;			///< Unique ID for object
-    pmPeak *peak;			///< Description of peak pixel.
-    psImage *pixels;			///< Rectangular region including object pixels.
-    psImage *weight;			///< Image variance.
-    psImage *modelFlux;			///< cached copy of the model for this source
-    psImage *maskObj;			///< unique mask for this object which marks included pixels associated with objects.
-    psImage *maskView;			///< view into global image mask for this object region
-    pmMoments *moments;			///< Basic moments measure for the object.
-    pmModel *modelPSF;			///< PSF Model fit (parameters and type)
-    pmModel *modelEXT;			///< EXT (floating) Model fit (parameters and type).
-    pmSourceType type;			///< Best identification of object.
-    pmSourceMode mode;			///< Best identification of object.
+    const int id;                       ///< Unique ID for object
+    pmPeak *peak;                       ///< Description of peak pixel.
+    psImage *pixels;                    ///< Rectangular region including object pixels.
+    psImage *weight;                    ///< Image variance.
+    psImage *modelFlux;                 ///< cached copy of the model for this source
+    psImage *maskObj;                   ///< unique mask for this object which marks included pixels associated with objects.
+    psImage *maskView;                  ///< view into global image mask for this object region
+    pmMoments *moments;                 ///< Basic moments measure for the object.
+    pmModel *modelPSF;                  ///< PSF Model fit (parameters and type)
+    pmModel *modelEXT;                  ///< EXT (floating) Model fit (parameters and type).
+    pmSourceType type;                  ///< Best identification of object.
+    pmSourceMode mode;                  ///< Best identification of object.
     psArray *blends;
-    float psfMag;			///< calculated from flux in modelPsf
-    float extMag;			///< calculated from flux in modelEXT
-    float errMag;			///< error in psfMag OR extMag (depending on type)
-    float apMag;	       ///< apMag corresponding to psfMag or extMag (depending on type)
-    float pixWeight;			// model-weighted coverage of valid pixels
-    psRegion region;			// area on image covered by selected pixels
-    float sky, skyErr;			//?< The sky and its error at the center of the object
+    float psfMag;                       ///< calculated from flux in modelPsf
+    float extMag;                       ///< calculated from flux in modelEXT
+    float errMag;                       ///< error in psfMag OR extMag (depending on type)
+    float apMag;               ///< apMag corresponding to psfMag or extMag (depending on type)
+    float pixWeight;                    // model-weighted coverage of valid pixels
+    psRegion region;                    // area on image covered by selected pixels
+    float sky, skyErr;                  //?< The sky and its error at the center of the object
 }
 pmSource;
@@ -192,5 +192,6 @@
     psArray *source,   ///< The input pmSource
     psMetadata *metadata,  ///< Contains classification parameters
-    pmPSFClump clump   ///< Statistics about the PSF clump
+    pmPSFClump clump,   ///< Statistics about the PSF clump
+    psMaskType maskSat                  ///< Mask value for saturated pixels
 );
 
@@ -213,9 +214,9 @@
 pmModel *pmSourceGetModel (bool *isPSF, const pmSource *source);
 
-bool pmSourceAdd (pmSource *source, pmModelOpMode mode);
-bool pmSourceSub (pmSource *source, pmModelOpMode mode);
-
-bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add);
-bool pmSourceCacheModel (pmSource *source);
+bool pmSourceAdd (pmSource *source, pmModelOpMode mode, psMaskType maskVal);
+bool pmSourceSub (pmSource *source, pmModelOpMode mode, psMaskType maskVal);
+
+bool pmSourceOp (pmSource *source, pmModelOpMode mode, bool add, psMaskType maskVal);
+bool pmSourceCacheModel (pmSource *source, psMaskType maskVal);
 
 /// @}
Index: /trunk/psModules/src/objects/pmSourceFitModel.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceFitModel.c	(revision 13897)
+++ /trunk/psModules/src/objects/pmSourceFitModel.c	(revision 13898)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-06-13 23:41:51 $
+ *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-20 02:22:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -52,5 +52,6 @@
 bool pmSourceFitModel (pmSource *source,
                        pmModel *model,
-                       pmSourceFitMode mode)
+                       pmSourceFitMode mode,
+                       psMaskType maskVal)
 {
     psTrace("psModules.objects", 5, "---- %s begin ----\n", __func__);
@@ -77,5 +78,5 @@
         for (psS32 j = 0; j < source->pixels->numCols; j++) {
             // skip masked points
-            if (source->maskObj->data.U8[i][j]) {
+            if (source->maskObj->data.U8[i][j] & maskVal) {
                 continue;
             }
@@ -324,5 +325,6 @@
 bool pmSourceFitSet (pmSource *source,
                      psArray *modelSet,
-                     pmSourceFitMode mode)
+                     pmSourceFitMode mode,
+                     psMaskType maskVal)
 {
     psTrace("psModules.objects", 3, "---- %s begin ----\n", __func__);
@@ -349,5 +351,5 @@
         for (psS32 j = 0; j < source->pixels->numCols; j++) {
             // skip masked points
-            if (source->maskObj->data.U8[i][j]) {
+            if (source->maskObj->data.U8[i][j] & maskVal) {
                 continue;
             }
@@ -524,6 +526,6 @@
 
         // set the model success or failure status
-	model->flags |= PM_MODEL_STATUS_FITTED;
-	if (!fitStatus) model->flags |= PM_MODEL_STATUS_NONCONVERGE;
+        model->flags |= PM_MODEL_STATUS_FITTED;
+        if (!fitStatus) model->flags |= PM_MODEL_STATUS_NONCONVERGE;
 
         // models can go insane: reject these
Index: /trunk/psModules/src/objects/pmSourceFitModel.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceFitModel.h	(revision 13897)
+++ /trunk/psModules/src/objects/pmSourceFitModel.h	(revision 13898)
@@ -3,6 +3,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:15 $
+ * @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -40,5 +40,6 @@
     pmSource *source,   ///< The input pmSource
     pmModel *model,   ///< model to be fitted
-    pmSourceFitMode mode  ///< define parameters to be fitted
+    pmSourceFitMode mode,  ///< define parameters to be fitted
+    psMaskType maskVal                  ///< Value to mask
 );
 
@@ -69,5 +70,7 @@
     pmSource *source,   ///< The input pmSource
     psArray *modelSet,   ///< model to be fitted
-    pmSourceFitMode mode  ///< define parameters to be fitted
+    pmSourceFitMode mode,  ///< define parameters to be fitted
+    psMaskType maskVal                  ///< Vale to mask
+
 );
 
Index: /trunk/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 13897)
+++ /trunk/psModules/src/objects/pmSourcePhotometry.c	(revision 13898)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA; GLG, MHPCC
  *
- *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-05-22 21:45:00 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-20 02:22:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -58,10 +58,10 @@
         - the source is a STAR (PSF)
         - the option is selected (mode & PM_SOURCE_PHOT_APCORR)
- 
+
     - extMag : all sources with non-NULL modelEXT
 **/
 
 // XXX masked region should be (optionally) elliptical
-bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode)
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal, psMaskType mark)
 {
 
@@ -110,5 +110,5 @@
     // XXX use pmSourceAdd instead?
     if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
-        pmModelAdd (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL);
+        pmModelAdd (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     }
 
@@ -185,21 +185,21 @@
     // XXX can I remove this?  the source should have the mask defined when it is constructed or
     // when the fit / aperture radius is changed...
-    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "OR", PM_MASK_MARK);
+    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "OR", mark);
 
     // measure the weight of included pixels
     // XXX is this supposed to use the weight or the flux?
     if (mode & PM_SOURCE_PHOT_WEIGHT) {
-        pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj);
+        pmSourcePixelWeight (&source->pixWeight, model, source->pixels, source->maskObj, maskVal);
     }
 
     // measure object aperture photometry
-    status = pmSourcePhotometryAper  (&source->apMag, model, flux, source->maskObj);
+    status = pmSourcePhotometryAper  (&source->apMag, model, flux, source->maskObj, maskVal);
     if (!status) {
-	psErrorCode last = psErrorCodeLast();
-	if (last == PM_ERR_PHOTOM) {
-	    // the aper mag was undefined (flux < 0).  bad object, but
-	    // don't keep the error on the stack
-	    psErrorClear();
-	}
+        psErrorCode last = psErrorCodeLast();
+        if (last == PM_ERR_PHOTOM) {
+            // the aper mag was undefined (flux < 0).  bad object, but
+            // don't keep the error on the stack
+            psErrorClear();
+        }
     }
 
@@ -220,10 +220,10 @@
     // unmask aperture
     // XXX can I remove this?  this will probably break things downstream...
-    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "AND", PS_NOT_U8(PM_MASK_MARK));
+    psImageKeepCircle (source->maskObj, x, y, model->radiusFit, "AND", PS_NOT_U8(mark));
 
     // if source was originally subtracted, re-subtract object, leave local sky
     // XXX replace with pmSourceSub...
     if (source->mode & PM_SOURCE_MODE_SUBTRACTED) {
-        pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL);
+        pmModelSub (source->pixels, source->maskObj, model, PM_MODEL_OP_FULL, maskVal);
     }
 
@@ -235,5 +235,5 @@
 (aprMag - flux*skySat - r^2*rflux*skyBias) - fitMAg = ApTrend(x,y)
 (aprMag - flux*skySat - r^2*rflux*skyBias) = fitMAg + ApTrend(x,y)
- 
+
 */
 
@@ -262,5 +262,5 @@
 
 // return source aperture magnitude
-bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask)
+bool pmSourcePhotometryAper (float *apMag, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
 {
     float apSum = 0;
@@ -269,5 +269,5 @@
 
     if (model == NULL) {
-	psError(PM_ERR_OBJECTS, true, "Model is NULL");
+        psError(PM_ERR_OBJECTS, true, "Model is NULL");
         return false;
     }
@@ -285,5 +285,5 @@
     for (int ix = 0; ix < image->numCols; ix++) {
         for (int iy = 0; iy < image->numRows; iy++) {
-            if (mkData[iy][ix])
+            if (mkData[iy][ix] & maskVal)
                 continue;
             apSum += imData[iy][ix] - sky;
@@ -291,5 +291,5 @@
     }
     if (apSum <= 0) {
-	psError(PM_ERR_PHOTOM, true, "apSum is negative");
+        psError(PM_ERR_PHOTOM, true, "apSum is negative");
         return false;
     }
@@ -300,5 +300,5 @@
 
 // return source aperture magnitude
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask)
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal)
 {
     float modelSum = 0;
@@ -366,5 +366,5 @@
             if (my >= NY)
                 continue;
-            if (mask->data.U8[my][mx])
+            if (mask->data.U8[my][mx] & maskVal)
                 continue;
 
@@ -400,5 +400,5 @@
     const psImage *Wi = Mi->weight;
     if (!unweighted_sum) {
-	assert (Wi != NULL);
+        assert (Wi != NULL);
     }
 
@@ -463,5 +463,5 @@
     const psImage *Wi = Mi->weight;
     if (!unweighted_sum) {
-	assert (Wi != NULL);
+        assert (Wi != NULL);
     }
 
@@ -518,5 +518,5 @@
     const psImage *Wi = Mi->weight;
     if (!unweighted_sum) {
-	assert (Wi != NULL);
+        assert (Wi != NULL);
     }
     const psImage *Ti = Mi->maskObj;
@@ -561,5 +561,5 @@
 # endif
 
-bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight)
+bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psMaskType maskVal)
 {
 
@@ -568,5 +568,5 @@
     for (int j = 0; j < image->numRows; j++) {
         for (int i = 0; i < image->numCols; i++) {
-            if (mask->data.U8[j][i])
+            if (mask->data.U8[j][i] & maskVal)
                 continue;
             if (weight->data.F32[j][i] <= 0)
@@ -593,5 +593,5 @@
     const psImage *Wi = Mi->weight;
     if (!unweighted_sum) {
-	assert (Wi != NULL);
+        assert (Wi != NULL);
     }
     const psImage *Ti = Mi->maskObj;
@@ -633,6 +633,6 @@
 
 double pmSourceModelDotModel (const pmSource *Mi,
-			      const pmSource *Mj,
-			      const bool unweighted_sum) // should the cross product be weighted?
+                              const pmSource *Mj,
+                              const bool unweighted_sum) // should the cross product be weighted?
 {
     int Xs, Xe, Ys, Ye;
@@ -649,5 +649,5 @@
     const psImage *Wi = Mi->weight;
     if (!unweighted_sum) {
-	assert (Wi != NULL);
+        assert (Wi != NULL);
     }
 
@@ -680,5 +680,5 @@
                 continue;
 
-	    // XXX skip the nonsense weight pixels?
+            // XXX skip the nonsense weight pixels?
             if (unweighted_sum) {
                 flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
@@ -712,5 +712,5 @@
     const psImage *Wi = Mi->weight;
     if (!unweighted_sum) {
-	assert (Wi != NULL);
+        assert (Wi != NULL);
     }
 
@@ -743,5 +743,5 @@
                 continue;
 
-	    // XXX skip the nonsense weight pixels?
+            // XXX skip the nonsense weight pixels?
             if (unweighted_sum) {
                 flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
Index: /trunk/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 13897)
+++ /trunk/psModules/src/objects/pmSourcePhotometry.h	(revision 13898)
@@ -4,6 +4,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-04-26 01:20:29 $
+ * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -45,11 +45,12 @@
     pmModel *model,                     ///< model used for photometry
     psImage *image,                     ///< image pixels to be used
-    psImage *mask                       ///< mask of pixels to ignore
+    psImage *mask,                      ///< mask of pixels to ignore
+    psMaskType maskVal                  ///< Value to mask
 );
 
 bool pmSourceMagnitudesInit (psMetadata *config);
-bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode);
-bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask);
-bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight);
+bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal, psMaskType mark);
+bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal);
+bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psMaskType maskVal);
 
 
Index: /trunk/psModules/src/objects/pmSourceSky.c
===================================================================
--- /trunk/psModules/src/objects/pmSourceSky.c	(revision 13897)
+++ /trunk/psModules/src/objects/pmSourceSky.c	(revision 13898)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-26 01:20:29 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-06-20 02:22:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -44,5 +44,7 @@
     pmSource *source,
     psStatsOptions statsOptions,
-    psF32 Radius)
+    psF32 Radius,
+    psMaskType maskVal,
+    psMaskType mark)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -68,12 +70,12 @@
     srcRegion = psRegionForImage(mask, srcRegion);
 
-    psImageMaskRegion(mask, srcRegion, "OR", PM_MASK_MARK);
+    psImageMaskRegion(mask, srcRegion, "OR", mark);
     psStats *myStats = psStatsAlloc(statsOptions);
-    if (!psImageStats(myStats, image, mask, 0xff)) {
+    if (!psImageStats(myStats, image, mask, maskVal | mark)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
         psFree(myStats);
         return false;
     }
-    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(PM_MASK_MARK));
+    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(mark));
     double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
@@ -95,5 +97,8 @@
     pmSource *source,
     psStatsOptions statsOptions,
-    psF32 Radius)
+    psF32 Radius,
+    psMaskType maskVal,
+    psMaskType mark
+)
 {
     psTrace("psModules.objects", 3, "---- %s() begin ----\n", __func__);
@@ -119,12 +124,12 @@
     srcRegion = psRegionForImage(mask, srcRegion);
 
-    psImageMaskRegion(mask, srcRegion, "OR", PM_MASK_MARK);
+    psImageMaskRegion(mask, srcRegion, "OR", mark);
     psStats *myStats = psStatsAlloc(statsOptions);
-    if (!psImageStats(myStats, image, mask, 0xff)) {
+    if (!psImageStats(myStats, image, mask, maskVal | mark)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to get image statistics.\n");
         psFree(myStats);
         return false;
     }
-    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(PM_MASK_MARK));
+    psImageMaskRegion(mask, srcRegion, "AND", PS_NOT_U8(mark));
     double value = psStatsGetValue(myStats, statistic);
     psFree(myStats);
Index: /trunk/psModules/src/objects/pmSourceSky.h
===================================================================
--- /trunk/psModules/src/objects/pmSourceSky.h	(revision 13897)
+++ /trunk/psModules/src/objects/pmSourceSky.h	(revision 13898)
@@ -2,6 +2,6 @@
  * @author EAM, IfA; GLG, MHPCC
  *
- * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-24 02:54:15 $
+ * @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2007-06-20 02:22:26 $
  * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -29,5 +29,7 @@
     pmSource *source,   ///< The input image (float)
     psStatsOptions statsOptions, ///< The statistic used in calculating the background sky
-    float Radius   ///< The inner radius of the square annulus to exclude
+    float Radius,   ///< The inner radius of the square annulus to exclude
+    psMaskType maskVal,                 ///< Value to mask
+    psMaskType mark                     ///< Mask value for marking
 );
 
@@ -37,5 +39,7 @@
     pmSource *source,   ///< The input image (float)
     psStatsOptions statsOptions, ///< The statistic used in calculating the background sky
-    float Radius   ///< The inner radius of the square annulus to exclude
+    float Radius,   ///< The inner radius of the square annulus to exclude
+    psMaskType maskVal,                 ///< Value to mask
+    psMaskType mark                     ///< Mask value for marking
 );
 
Index: /trunk/psModules/src/psmodules.h
===================================================================
--- /trunk/psModules/src/psmodules.h	(revision 13897)
+++ /trunk/psModules/src/psmodules.h	(revision 13898)
@@ -53,4 +53,5 @@
 #include <pmFPAExtent.h>
 #include <pmFPACalibration.h>
+#include <pmReadoutStack.h>
 
 // the following headers are from psModule:detrend
