Index: /trunk/psphot/src/psphotPSFResiduals.c
===================================================================
--- /trunk/psphot/src/psphotPSFResiduals.c	(revision 18438)
+++ /trunk/psphot/src/psphotPSFResiduals.c	(revision 18439)
@@ -4,34 +4,38 @@
 bool psphotResidPSF (pmReadout *readout, psArray *sources, psMetadata *recipe, pmPSF *psf) {
 
-  psTimerStart ("psphot");
+    psTimerStart ("psphot");
 
-  for (int i = 0; i < sources->n; i++) {
-    pmSource *source = sources->data[i];
+    // bit-mask to mark pixels not used in analysis
+    psMaskType markVal = psMetadataLookupU8(&status, recipe, "MARK.PSPHOT");
+    assert (markVal);
 
-    // only use the psf stars to build the residual model
-    if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
+    for (int i = 0; i < sources->n; i++) {
+	pmSource *source = sources->data[i];
 
-    if (source->mode & PM_SOURCE_MODE_SATSTAR) {
-	Xo = source->moments->x;
-	Yo = source->moments->y;
-	Io = source->peak->flux;
-    } else {
-	Xo = source->peak->xf;
-	Yo = source->peak->yf;
-	Io = source->peak->flux;
+	// only use the psf stars to build the residual model
+	if (!(source->mode & PM_SOURCE_MODE_PSFSTAR)) continue;
+
+	if (source->mode & PM_SOURCE_MODE_SATSTAR) {
+	    Xo = source->moments->x;
+	    Yo = source->moments->y;
+	    Io = source->peak->flux;
+	} else {
+	    Xo = source->peak->xf;
+	    Yo = source->peak->yf;
+	    Io = source->peak->flux;
+	}
+
+	// set PSF parameters for this model (apply 2D shape model)
+	pmModel *modelPSF = pmModelFromPSFforXY (psf, Xo, Yo, Io);
+
+	// XXX need to define the guess flux?
+	// set the fit radius based on the object flux limit and the model
+	psphotCheckRadiusPSF (readout, source, modelPSF, markVal);
+
+	// set the source PSF model
+	source->modelPSF = modelPSF;
     }
-
-    // set PSF parameters for this model (apply 2D shape model)
-    pmModel *modelPSF = pmModelFromPSFforXY (psf, Xo, Yo, Io);
-
-    // XXX need to define the guess flux?
-    // set the fit radius based on the object flux limit and the model
-    psphotCheckRadiusPSF (readout, source, modelPSF);
-
-    // set the source PSF model
-    source->modelPSF = modelPSF;
-  }
-  psLogMsg ("psphot.models", 4, "built models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot"));
-  return true;
+    psLogMsg ("psphot.models", 4, "built models for %ld objects: %f sec\n", sources->n, psTimerMark ("psphot"));
+    return true;
 }
 
