Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/models/pmModel_DEV.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/models/pmModel_DEV.c	(revision 36195)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/models/pmModel_DEV.c	(revision 36196)
@@ -117,5 +117,4 @@
 
     assert (isfinite(q));
-    assert (isfinite(f0));
 
     // only worry about the central pixels at most
@@ -129,4 +128,5 @@
 	f0 = pmModelCP_SersicSubpix (X, Y, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], 4.0, Nsub);
     }   
+    assert (isfinite(f0));
 
     float f1 = PAR[PM_PAR_I0]*f0;
@@ -243,4 +243,12 @@
 bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
 {
+    // for the moment, we are going to require moments and KronFlux
+    if (!source->moments) return false;
+    pmMoments *moments = source->moments;
+
+    if (!isfinite(moments->KronFlux)) return false;
+    if (!isfinite(moments->Mrf)) return false;
+    if (moments->Mrf < 0.0) return false;
+
     psF32 *PAR  = model->params->data.F32;
 
@@ -248,13 +256,31 @@
     PAR[PM_PAR_SKY]  = 0.0;
 
-    // set the shape parameters
-    if (!pmModelSetShape(&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], source->moments, true)) {
-      return false;
-    }
-
-    // set the model normalization
-    if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) {
-      return false;
-    }
+    psEllipseMoments emoments;
+    emoments.x2 = moments->Mxx;
+    emoments.xy = moments->Mxy;
+    emoments.y2 = moments->Myy;
+
+    // force the axis ratio to be < 20.0
+    psEllipseAxes axes = psEllipseMomentsToAxes (emoments, 20.0);
+
+    if (!isfinite(axes.major)) return false;
+    if (!isfinite(axes.minor)) return false;
+    if (!isfinite(axes.theta)) return false;
+
+    // Mxx, Mxy, Myy define the elliptical shape, but Mrf defines the width 
+    float scale = moments->Mrf / axes.major;
+    axes.major *= scale;
+    axes.minor *= scale;
+
+    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], axes, true);
+
+    // psEllipseAxes axes;
+    // use the code in SetShape here to avoid doing this 2x
+    // pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
+
+    // float norm = pmSersicNorm (4);  // hardwire
+    float norm = 0.00168012;
+    float normFlux = 2.0 * M_PI * axes.major * axes.minor * norm;
+    PAR[PM_PAR_I0] = moments->KronFlux / normFlux;
 
     // set the model position
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/models/pmModel_EXP.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/models/pmModel_EXP.c	(revision 36195)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/models/pmModel_EXP.c	(revision 36196)
@@ -237,4 +237,12 @@
 bool PM_MODEL_GUESS (pmModel *model, pmSource *source, psImageMaskType maskVal, psImageMaskType markVal)
 {
+    // for the moment, we are going to require moments and KronFlux
+    if (!source->moments) return false;
+    pmMoments *moments = source->moments;
+
+    if (!isfinite(moments->KronFlux)) return false;
+    if (!isfinite(moments->Mrf)) return false;
+    if (moments->Mrf < 0.0) return false;
+
     psF32 *PAR  = model->params->data.F32;
 
@@ -242,13 +250,31 @@
     PAR[PM_PAR_SKY]  = 0.0;
 
-    // set the shape parameters
-    if (!pmModelSetShape(&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], source->moments, true)) {
-      return false;
-    }
-
-    // set the model normalization
-    if (!pmModelSetNorm(&PAR[PM_PAR_I0], source)) {
-      return false;
-    }
+    psEllipseMoments emoments;
+    emoments.x2 = moments->Mxx;
+    emoments.xy = moments->Mxy;
+    emoments.y2 = moments->Myy;
+
+    // force the axis ratio to be < 20.0
+    psEllipseAxes axes = psEllipseMomentsToAxes (emoments, 20.0);
+
+    if (!isfinite(axes.major)) return false;
+    if (!isfinite(axes.minor)) return false;
+    if (!isfinite(axes.theta)) return false;
+
+    // Mxx, Mxy, Myy define the elliptical shape, but Mrf defines the width 
+    float scale = moments->Mrf / axes.major;
+    axes.major *= scale;
+    axes.minor *= scale;
+
+    pmModelAxesToParams (&PAR[PM_PAR_SXX], &PAR[PM_PAR_SXY], &PAR[PM_PAR_SYY], axes, true);
+
+    // psEllipseAxes axes;
+    // use the code in SetShape here to avoid doing this 2x
+    // pmModelParamsToAxes (&axes, PAR[PM_PAR_SXX], PAR[PM_PAR_SXY], PAR[PM_PAR_SYY], true);
+
+    // float norm = pmSersicNorm (4);  // hardwire
+    float norm = 0.34578;
+    float normFlux = 2.0 * M_PI * axes.major * axes.minor * norm;
+    PAR[PM_PAR_I0] = moments->KronFlux / normFlux;
 
     // set the model position
@@ -259,5 +285,4 @@
     return(true);
 }
-
 // An exponential model is equivalent to a Sersic with index = 1.0
 psF64 PM_MODEL_FLUX (const psVector *params)
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmPSFtryFitPSF.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmPSFtryFitPSF.c	(revision 36195)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmPSFtryFitPSF.c	(revision 36196)
@@ -118,30 +118,4 @@
     psfTry->psf->nPSFstars = Npsf;
 
-    // DEBUG code: save the PSF model fit data in detail
-# ifdef DEBUG
-
-    char filename[64];
-    snprintf (filename, 64, "psffit.%dx%d.dat", psfTry->psf->trendNx, psfTry->psf->trendNy);
-    FILE *f = fopen (filename, "w");
-    psAssert (f, "failed open");
-
-    for (int i = 0; i < psfTry->sources->n; i++) {
-
-	// skip masked sources
-        if (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) continue;
-
-        pmSource *source = psfTry->sources->data[i];
-
-	fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f\n",
-		 source->peak->xf, source->peak->yf, 
-		 source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS], 
-		 source->psfMag, source->apMag, source->psfMagErr,
-		 source->modelPSF->params->data.F32[PM_PAR_I0], 
-		 source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], 
-		 source->modelPSF->params->data.F32[PM_PAR_SYY], source->modelPSF->params->data.F32[PM_PAR_7]);
-    }
-    fclose (f);
-# endif
-
     pmSourceVisualShowModelFits (psfTry->psf, psfTry->sources, maskVal);
 
@@ -150,6 +124,37 @@
 
     if (Npsf == 0) {
-        psError(PS_ERR_UNKNOWN, false, "No sources with good PSF fits after model is built.");
-        return false;
+	// DEBUG code: save the PSF model fit data in detail
+
+	char hostname[256];
+	gethostname (hostname, 256);
+
+	int pid = getpid();
+
+	char filename[64];
+	snprintf (filename, 64, "psffit.%s.%d.%dx%d.dat", hostname, pid, psfTry->psf->trendNx, psfTry->psf->trendNy);
+	FILE *f = fopen (filename, "w");
+	psAssert (f, "failed open");
+
+	for (int i = 0; i < psfTry->sources->n; i++) {
+
+	    // skip masked sources
+	  // if (psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & PSFTRY_MASK_ALL) continue;
+
+	    pmSource *source = psfTry->sources->data[i];
+
+	    float par7 = (source->modelPSF->params->n == 7) ? -100 : source->modelPSF->params->data.F32[PM_PAR_7];
+	    fprintf (f, "%6.1f %6.1f : %6.1f %6.1f : %8.3f %8.3f %8.3f : %f : %f %f %f : %f %d\n",
+		     source->peak->xf, source->peak->yf, 
+		     source->modelPSF->params->data.F32[PM_PAR_XPOS], source->modelPSF->params->data.F32[PM_PAR_YPOS], 
+		     source->psfMag, source->apMag, source->psfMagErr,
+		     source->modelPSF->params->data.F32[PM_PAR_I0], 
+		     source->modelPSF->params->data.F32[PM_PAR_SXX], source->modelPSF->params->data.F32[PM_PAR_SXY], 
+		     source->modelPSF->params->data.F32[PM_PAR_SYY], par7,
+		     psfTry->mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
+	}
+	fclose (f);
+
+	psError(PS_ERR_UNKNOWN, false, "No sources with good PSF fits after model is built.");
+	return false;
     }
 
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmPSFtryModel.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmPSFtryModel.c	(revision 36195)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmPSFtryModel.c	(revision 36196)
@@ -236,4 +236,14 @@
     // linear clipped fit of chisq trend vs flux
     if (options->chiFluxTrend) {
+
+	if (0) {
+	    FILE *f = fopen ("test.psf.dat", "w");
+	    int fd = fileno (f);
+	    p_psVectorPrint (fd, flux, "flux");
+	    p_psVectorPrint (fd, chisq, "chisq");
+	    p_psVectorPrint (fd, mask, "mask");
+	    fclose (f);
+	}
+
         bool result = psVectorClipFitPolynomial1D(psfTry->psf->ChiTrend, options->stats,
                                                   mask, 0xff, chisq, NULL, flux);
