Index: branches/eam_branches/ipp-20100621/psphot/src/psphotChoosePSF.c
===================================================================
--- branches/eam_branches/ipp-20100621/psphot/src/psphotChoosePSF.c	(revision 28657)
+++ branches/eam_branches/ipp-20100621/psphot/src/psphotChoosePSF.c	(revision 28677)
@@ -244,4 +244,5 @@
 
     // try each model option listed in config
+    // pmPSFtryModel makes a local copy of the sources -- those points are not the same as those for 'sources'
     for (int i = 0; i < modelNames->n; i++) {
         char *modelName = modelNames->data[i];
@@ -321,10 +322,42 @@
 
     // unset the PSFSTAR flag for stars not used for PSF model
+    // XXX a more efficient way of achieving this would be to record a pair of arrays
+    // of the source index and the source id for the psf stars.  but that would require we do
+    // not re-sort the source list in the meanwhile
+    int nDrop = 0;
     for (int i = 0; i < try->sources->n; i++) {
         pmSource *source = try->sources->data[i];
         if (try->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]) {
-            source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
-        }
-    }
+	    // need to find this source in the original list (these are copies, not pointers)
+	    for (int j = 0; j < sources->n; j++) {
+		pmSource *realSource = sources->data[j];
+		if (realSource->id != source->id) continue;
+		realSource->mode &= ~PM_SOURCE_MODE_PSFSTAR;
+		source->mode &= ~PM_SOURCE_MODE_PSFSTAR;
+		nDrop ++;
+		break;
+	    }
+        }
+    }
+    // fprintf (stderr, "drop %d stars as PSF stars\n", nDrop);
+
+    // XXX is this working?
+    // int N1 = 0;
+    // for (int i = 0; i < try->sources->n; i++) {
+    //     pmSource *source = try->sources->data[i];
+    // 	fprintf (stderr, "%llx : %d\n", (long long int) source, (source->mode & PM_SOURCE_MODE_PSFSTAR));
+    // 	if (source->mode & PM_SOURCE_MODE_PSFSTAR) {
+    // 	    N1 ++;
+    //     }
+    // }
+    // int N2 = 0;
+    // for (int i = 0; i < sources->n; i++) {
+    //     pmSource *source = sources->data[i];
+    // 	fprintf (stderr, "%llx : %d\n", (long long int) source, (source->mode & PM_SOURCE_MODE_PSFSTAR));
+    // 	if (source->mode & PM_SOURCE_MODE_PSFSTAR) {
+    // 	    N2 ++;
+    //     }
+    // }
+    // fprintf (stderr, "N1: %d, N2: %d\n", N1, N2);
 
     // build a PSF residual image
Index: branches/eam_branches/ipp-20100621/psphot/src/psphotSourceFits.c
===================================================================
--- branches/eam_branches/ipp-20100621/psphot/src/psphotSourceFits.c	(revision 28657)
+++ branches/eam_branches/ipp-20100621/psphot/src/psphotSourceFits.c	(revision 28677)
@@ -345,5 +345,5 @@
 
     // copy most data from the primary source (modelEXT, blends stay NULL)
-    pmSource *newSrc = pmSourceCopy (source);
+    pmSource *newSrc = pmSourceCopyData (source);
     newSrc->modelPSF = psMemIncrRefCounter (DBL->data[1]);
     newSrc->modelPSF->fitRadius = radius;
@@ -447,5 +447,5 @@
     maskVal |= markVal;
 
-    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
+    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 5);
 
     // use the source moments, etc to guess basic model parameters
@@ -460,18 +460,22 @@
     }
 
-    // for sersic models, get the initial guess more carefully
+    // for sersic models, use a grid search to choose an index, then float the params there
     if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
     	psphotFitSersicIndex (source, EXT, fitOptions, maskVal);
     }
 
-    // fit EXT (not PSF) model (set/unset the pixel mask)
-    options.mode = PM_SOURCE_FIT_EXT;
+    if (modelType == pmModelClassGetType("PS_MODEL_SERSIC")) {
+	options.mode = PM_SOURCE_FIT_NO_INDEX;
+    } else {
+	options.mode = PM_SOURCE_FIT_EXT;
+    }
     pmSourceFitModel (source, EXT, &options, maskVal);
 
-    psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
+    // psTraceSetLevel("psLib.math.psMinimizeLMChi2", 0);
     return (EXT);
 }
 
-float indexGuess[] = {0.5, 0.25, 0.125};
+// note that these should be 1/2n of the standard sersic index
+float indexGuess[] = {0.5, 0.33, 0.25, 0.167, 0.125, 0.083};
 
 // A sersic model is very sensitive to the index.  attempt to find the index first by grid search in just the index
Index: branches/eam_branches/ipp-20100621/psphot/src/psphotSourceSize.c
===================================================================
--- branches/eam_branches/ipp-20100621/psphot/src/psphotSourceSize.c	(revision 28657)
+++ branches/eam_branches/ipp-20100621/psphot/src/psphotSourceSize.c	(revision 28677)
@@ -364,6 +364,6 @@
         float nSigmaMYY = (Myy - psfClump->Y) / hypot(psfClump->dY, psfClump->Y*psfClump->Y*source->errMag);
 
-	fprintf (stderr, "Mxx: %f, Myy: %f, dx: %f, dy: %f, psfMag: %f, apMag: %f, dMag: %f, errMag: %f, nSigmaMag: %f\n", 
-		 Mxx, Myy, source->peak->xf - source->moments->Mx, source->peak->yf - source->moments->My, 
+	fprintf (stderr, "%f %f : Mxx: %f, Myy: %f, dx: %f, dy: %f, psfMag: %f, apMag: %f, dMag: %f, errMag: %f, nSigmaMag: %f\n", 
+		 source->peak->xf, source->peak->yf, Mxx, Myy, source->peak->xf - source->moments->Mx, source->peak->yf - source->moments->My, 
 		 source->psfMag, apMag, dMag, source->errMag, nSigmaMAG);
 
