Index: trunk/psModules/src/objects/pmSource.c
===================================================================
--- trunk/psModules/src/objects/pmSource.c	(revision 13338)
+++ 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);
