Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotApResid.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotApResid.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotApResid.c	(revision 30764)
@@ -1,3 +1,4 @@
 # include "psphotInternal.h"
+// # define DEBUG
 
 # define SKIPSTAR(MSG) { psTrace ("psphot", 3, "invalid : %s", MSG); continue; }
@@ -481,5 +482,5 @@
         if (!isfinite(source->apMag) || !isfinite(source->psfMag)) {
             Nfail ++;
-            psTrace ("psphot", 3, "fail : nan mags : %f %f", source->apMag, source->psfMag);
+            psTrace ("psphot", 3, "fail : %f, %f : nan mags : %f %f", source->peak->xf, source->peak->yf, source->apMag, source->psfMag);
             continue;
         }
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotBlendFit.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotBlendFit.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotBlendFit.c	(revision 30764)
@@ -94,4 +94,5 @@
     fitOptions->weight        = PS_SQR(skySig);
     fitOptions->mode          = PM_SOURCE_FIT_PSF;
+    fitOptions->covarFactor   = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix
 
     psphotInitLimitsPSF (recipe, readout);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotChoosePSF.c	(revision 30764)
@@ -160,4 +160,6 @@
     options->fitOptions->weight        = PS_SQR(SKY_SIG);
     options->fitOptions->mode          = PM_SOURCE_FIT_PSF;
+    options->fitOptions->covarFactor   = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix
+
     
     psArray *stars = psArrayAllocEmpty (sources->n);
@@ -178,5 +180,5 @@
     psphotCheckStarDistribution (stars, sources, options);
 
-    psLogMsg ("psphot.pspsf", PS_LOG_DETAIL, "selected candidate %ld PSF objects\n", stars->n);
+    psLogMsg ("psphot.pspsf", PS_LOG_DETAIL, "selected %ld candidate PSF objects\n", stars->n);
 
     if (stars->n < 50) {
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotExtendedSourceFits.c	(revision 30764)
@@ -275,6 +275,7 @@
     // Define source fitting parameters for extended source fits
     pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
-    fitOptions->mode          = PM_SOURCE_FIT_EXT;
+    fitOptions->mode           = PM_SOURCE_FIT_EXT;
     fitOptions->saveCovariance = true;  // XXX make this a user option?
+    fitOptions->covarFactor    = psImageCovarianceFactorForAperture(readout->covariance, 10.0); // Covariance matrix
 
     // XXX for now, use the defaults for the rest:
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSet.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSet.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSet.c	(revision 30764)
@@ -27,4 +27,5 @@
     pmSourceFitOptions *fitOptions = pmSourceFitOptionsAlloc();
     fitOptions->mode          = PM_SOURCE_FIT_EXT;
+    fitOptions->covarFactor   = 1.0;
     // XXX for now, use the defaults for the rest:
     // fitOptions->nIter         = fitIter;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinear.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinear.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinear.c	(revision 30764)
@@ -121,4 +121,6 @@
     // covarFactor = 1.0;
 
+    int Nsat = 0;
+
     // select the sources which will be used for the fitting analysis
     for (int i = 0; i < sources->n; i++) {
@@ -134,4 +136,9 @@
         // do not include CRs in the full ensemble fit
         if (source->mode & PM_SOURCE_MODE_CR_LIMIT) continue;
+
+	// XXX count saturated stars
+        if (source->mode & PM_SOURCE_MODE_SATSTAR) {
+	    Nsat ++;
+	}
 
         if (final) {
@@ -180,4 +187,6 @@
     psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "built fitSources: %f sec (%ld objects)\n", psTimerMark ("psphot.linear"), sources->n);
 
+    fprintf (stderr, "****** Nsat : %d ********\n", Nsat);
+
     if (fitSources->n == 0) {
         psFree(fitSources);
@@ -305,5 +314,5 @@
         if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) continue;
         pmModel *model = pmSourceGetModel (NULL, source);
-        pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, covarFactor);
+        pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, covarFactor, 1);
     }
     psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "get chisqs: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem);
@@ -324,5 +333,5 @@
     // We have to place this visualization here because the models are not realized until
     // psphotGuessModels or fitted until psphotFitSourcesLinear.
-    psphotVisualShowPSFStars (recipe, psf, sources);
+    // psphotVisualShowPSFStars (recipe, psf, sources);
 
     return true;
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinearStack.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinearStack.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotFitSourcesLinearStack.c	(revision 30764)
@@ -165,5 +165,5 @@
         if (source->mode & PM_SOURCE_MODE_NONLINEAR_FIT) continue;
         pmModel *model = pmSourceGetModel (NULL, source);
-        pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, COVAR_FACTOR);
+        pmSourceChisq (model, source->pixels, source->maskObj, source->variance, maskVal, COVAR_FACTOR, 1);
     }
     psLogMsg ("psphot.ensemble", PS_LOG_MINUTIA, "get chisqs: %f sec (%d elements)\n", psTimerMark ("psphot.linear"), sparse->Nelem);
Index: /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c
===================================================================
--- /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c	(revision 30763)
+++ /branches/eam_branches/ipp-20110213/psphot/src/psphotVisual.c	(revision 30764)
@@ -845,5 +845,13 @@
 
 	if (source->type != type) continue;
-	if (mode && !(source->mode & mode)) continue;
+
+	if (mode == PM_SOURCE_MODE_PSFSTAR) {
+	    bool keep = false;
+	    keep |= (source->tmpFlags & PM_SOURCE_TMPF_CANDIDATE_PSFSTAR);
+	    keep |= (source->mode & PM_SOURCE_MODE_PSFSTAR);
+	    if (!keep) continue;
+	} else {
+	    if (mode && !(source->mode & mode)) continue;
+	}
 
 	pmMoments *moments = source->moments;
@@ -1361,5 +1369,5 @@
     graphdata.xmax = +30.05;
     graphdata.ymin = -0.05;
-    graphdata.ymax = +5.05;
+    graphdata.ymax = +8.05;
     KapaSetLimits (myKapa, &graphdata);
 
@@ -1421,5 +1429,5 @@
     graphdata.xmax = +1.51;
     graphdata.ymin = -0.05;
-    graphdata.ymax = +5.05;
+    graphdata.ymax = +8.05;
     graphdata.color = KapaColorByName ("black");
     KapaSetLimits (myKapa, &graphdata);
@@ -2664,6 +2672,4 @@
     graphdata.ymax = -32.0;
 
-    FILE *f = fopen ("chisq.dat", "w");
-
     // construct the plot vectors
     int n = 0;
@@ -2683,11 +2689,7 @@
 	graphdata.ymin = PS_MIN(graphdata.ymin, y->data.F32[n]);
 	graphdata.ymax = PS_MAX(graphdata.ymax, y->data.F32[n]);
-
-	fprintf (f, "%d %d %f %f\n", i, n, x->data.F32[n], y->data.F32[n]);
-
 	n++;
     }
     x->n = y->n = n;
-    fclose (f);
 
     float range;
