Index: branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO_CFF.c
===================================================================
--- branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO_CFF.c	(revision 36152)
+++ branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO_CFF.c	(revision 36154)
@@ -72,4 +72,7 @@
     assert (modelType > -1);
 
+    // how to deal with this?
+    int galaxyModelType = pmModelClassGetType ("PS_MODEL_EXP");
+
     // We get the size of the table, and allocate the array of sources first because the table
     // is large and ephemeral --- when the table gets blown away, whatever is allocated after
@@ -87,9 +90,9 @@
         }
 
-	// here are the things we read from the FITS table
-
-	unsigned int ID = psMetadataLookupU32 (&status, row, "IPP_IDET");
-	float X = psMetadataLookupF32 (&status, row, "X_PSF");
-	float Y = psMetadataLookupF32 (&status, row, "Y_PSF");
+	// here are the things we read from the FITS table (XXX modify names if needed)
+
+	unsigned int ID  = psMetadataLookupU32 (&status, row, "IPP_IDET");
+	float X          = psMetadataLookupF32 (&status, row, "X_PSF");
+	float Y          = psMetadataLookupF32 (&status, row, "Y_PSF");
 
         float apRadius   = psMetadataLookupS32 (&status, row, "AP_RADIUS");
@@ -97,4 +100,5 @@
         float petRadius  = psMetadataLookupU32 (&status, row, "PETRO_RADIUS");
         bool fitGalaxy   = psMetadataLookupU32 (&status, row, "FIT_GALAXY");
+        bool psfStar     = psMetadataLookupU32 (&status, row, "PSF_STAR");
 
         float Rmajor     = psMetadataLookupU32 (&status, row, "R_MAJOR");
@@ -108,11 +112,16 @@
         source->type = PM_SOURCE_TYPE_STAR; // XXX this should be added to the flags
 
+	// XXX we can set this in general, but for a specific image, we need to weed out SATSTARS
+        if (psfStar) {
+	    source->tmpFlags |= PM_SOURCE_TMPF_CANDIDATE_PSFSTAR;
+	}
+
 	// NOTE: A SEGV here because "model" is NULL is probably caused by not initialising the models.
 	psF32 *PAR = model->params->data.F32;
 	psF32 *dPAR = model->dparams->data.F32;
 
-        source->seq          = ID;
-        PAR[PM_PAR_XPOS]     = X;
-        PAR[PM_PAR_YPOS]     = Y;
+        source->seq       = ID;
+        PAR[PM_PAR_XPOS]  = X;
+        PAR[PM_PAR_YPOS]  = Y;
 
 	dPAR[PM_PAR_XPOS] = 0.0;
@@ -129,7 +138,11 @@
 
 	source->psfMag    = 0.0;
-	source->psfMagErr    = 0.0;
+	source->psfMagErr = 0.0;
 	source->apMag     = 0.0;
-
+        source->apRadius  = apRadius;
+
+	// we generate a somewhat fake PSF model here -- 
+	// in most (all?) contexts, we will replace this with a measured psf model
+	// elsewhere
 	axes.major        = 1.0;
 	axes.minor        = 1.0;
@@ -138,14 +151,46 @@
 
 	float peakFlux    = 1.0;
-
-        source->peak = pmPeakAlloc(PAR[PM_PAR_XPOS], PAR[PM_PAR_YPOS], peakFlux, PM_PEAK_LONE);
+        source->peak      = pmPeakAlloc(X, Y, peakFlux, PM_PEAK_LONE);
+        source->peak->xf  = X; // more accurate position
+        source->peak->yf  = Y; // more accurate position
+        source->peak->dx  = 0.0;
+        source->peak->dy  = 0.0;
         source->peak->rawFlux = peakFlux;
         source->peak->smoothFlux = peakFlux;
-        source->peak->xf   = PAR[PM_PAR_XPOS]; // more accurate position
-        source->peak->yf   = PAR[PM_PAR_YPOS]; // more accurate position
-        source->peak->dx   = dPAR[PM_PAR_XPOS];
-        source->peak->dy   = dPAR[PM_PAR_YPOS];
-
-        assert (status);
+
+        source->moments = pmMomentsAlloc ();
+	source->moments->Mx = X;
+	source->moments->My = Y;
+	source->moments->Mrf = kronRadius;
+	source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
+	// XXX does the above cause a problem with pmSourceMoments (do we run it?)
+
+	if (isfinite(petRadius)) {
+	    source->extpars = pmSourceExtendedParsAlloc ();
+	    source->extpars->petrosianRadius = petRadius;
+	}
+
+        if (fitGalaxy) {
+            source->modelFits = psArrayAllocEmpty (models->list->n);
+	    pmModel *model = pmModelAlloc(modelType);
+	    psF32 *xPAR = model->params->data.F32;
+
+	    xPAR[PM_PAR_SKY]  = 0.0;
+	    xPAR[PM_PAR_I0]   = 1.0;
+	    xPAR[PM_PAR_XPOS] = X;
+	    xPAR[PM_PAR_YPOS] = Y;
+	    
+	    psEllipseAxes galAxes;
+	    galAxes.major = Rmajor;
+	    galAxes.minor = Rminor;
+	    galAxes.theta = theta; // XXX degrees or radians?
+
+	    pmPSF_AxesToModel (PAR, guessAxes, galModelType);
+	    xPAR[PM_PAR_7] = Sindex;
+
+	    psArrayAdd (source->modelFits, 1, model);
+	    psFree (model);
+	    
+        }
 
         sources->data[i] = source;
