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