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