Index: trunk/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- trunk/psphot/src/psphotFitSourcesLinear.c	(revision 21366)
+++ trunk/psphot/src/psphotFitSourcesLinear.c	(revision 21519)
@@ -63,15 +63,18 @@
         pmSource *source = sources->data[i];
 
+	// turn this bit off and turn it on again if we pass this test
+	source->mode &= ~PM_SOURCE_MODE_LINEAR_FIT;
+
         // skip non-astronomical objects (very likely defects)
         if (source->type == PM_SOURCE_TYPE_DEFECT) continue;
         if (source->type == PM_SOURCE_TYPE_SATURATED) continue;
 
-        // if (source->type == PM_SOURCE_TYPE_STAR &&
+	// do not include CRs in the full ensemble fit
         if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
 
         if (final) {
-            if (source->mode &  PM_SOURCE_MODE_SUBTRACTED) continue;
+            if (source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED) continue;
         } else {
-            if (source->mode &  PM_SOURCE_MODE_BLEND) continue;
+            if (source->mode & PM_SOURCE_MODE_BLEND) continue;
         }
 
@@ -91,4 +94,5 @@
         if (y > AnalysisRegion.y1) continue;
 
+	source->mode |= PM_SOURCE_MODE_LINEAR_FIT;
         psArrayAdd (fitSources, 100, source);
     }
@@ -185,4 +189,10 @@
     psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "solve matrix: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem);
 
+    // XXXX **** philosophical question: 
+    // we measure bright objects in three passes: 1) linear fit; 2) non-linear fit; 3) linear fit:
+    // should retain the chisq and errors from the intermediate non-linear fit? 
+    // the non-linear fit provides better values for the position errors, and for 
+    // extended sources, the shape errors
+
     // adjust I0 for fitSources and subtract
     for (int i = 0; i < fitSources->n; i++) {
@@ -194,4 +204,5 @@
             psAbort("linear fitted source is nan");
         }
+
         model->params->data.F32[PM_PAR_I0] = norm->data.F32[i];
         model->dparams->data.F32[PM_PAR_I0] = errors->data.F32[i];
@@ -200,5 +211,5 @@
         // subtract object
         pmSourceSub (source, PM_MODEL_OP_FULL, maskVal);
-        source->mode |= PM_SOURCE_MODE_SUBTRACTED;
+        source->tmpFlags |= PM_SOURCE_TMPF_SUBTRACTED;
     }
     psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "sub models: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem);
@@ -207,4 +218,5 @@
     for (int i = 0; final && (i < fitSources->n); i++) {
         pmSource *source = fitSources->data[i];
+	if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) continue;
         pmModel *model = pmSourceGetModel (NULL, source);
         pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal);
