Index: /branches/eam_branches/ipp-20101205/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- /branches/eam_branches/ipp-20101205/psphot/src/psphotFitSourcesLinear.c	(revision 30169)
+++ /branches/eam_branches/ipp-20101205/psphot/src/psphotFitSourcesLinear.c	(revision 30170)
@@ -46,4 +46,8 @@
             return false;
         }
+
+	psphotVisualShowResidualImage (readout, (num > 0)); 
+	psphotVisualShowPeaks (detections);
+	psphotVisualShowObjectRegions (readout, recipe, sources);
     }
     return true;
@@ -151,4 +155,18 @@
         if (x > AnalysisRegion.x1) continue;
         if (y > AnalysisRegion.y1) continue;
+
+	// check the integral of the model : is it large enough?
+	float modelSum = 0.0;
+	for (int iy = 0; iy < source->modelFlux->numRows; iy++) {
+	    for (int ix = 0; ix < source->modelFlux->numCols; ix++) {
+		modelSum += source->modelFlux->data.F32[iy][ix];
+	    }
+	}
+	if (modelSum < 0.01) continue; // skip sources with no model constraint (somewhat arbitrary limit)
+
+        pmModel *model = pmSourceGetModel (NULL, source);
+
+        psImageMaskPixels (source->maskObj, "AND", PS_NOT_IMAGE_MASK(markVal));
+        psImageKeepCircle (source->maskObj, source->peak->x, source->peak->y, model->fitRadius, "OR", markVal);
 
         source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
@@ -270,5 +288,4 @@
         model->params->data.F32[PM_PAR_I0] = norm->data.F32[i];
         model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i];
-        // XXX is the value of 'errors' modified by the sky fit?
 
         // subtract object
@@ -297,6 +314,4 @@
     psLogMsg ("psphot.ensemble", PS_LOG_INFO, "measure ensemble of PSFs: %f sec\n", psTimerMark ("psphot.linear"));
 
-    psphotVisualShowImage (readout);
-    psphotVisualShowResidualImage (readout);
     psphotVisualPlotChisq (sources);
     // psphotVisualShowFlags (sources);
