Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.c	(revision 36298)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.c	(revision 36299)
@@ -658,5 +658,5 @@
         file->header = hdu->header;
         file->wrote_phu = true;
-	if (!pmSourcesWrite_CFF(file->fits, sources, hdu->header, recipe)) {
+	if (!pmSourcesWrite_CFF(readout, file->fits, sources, hdu->header, recipe)) {
             psError(PS_ERR_UNKNOWN, false, "failed to write CFF");
             return false;
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.h
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.h	(revision 36298)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.h	(revision 36299)
@@ -54,5 +54,5 @@
 psArray *pmSourcesReadCMP (char *filename, psMetadata *header);
 psArray *pmSourcesRead_CFF (psFits *fits, psMetadata *header);
-bool pmSourcesWrite_CFF (psFits *fits, psArray *sources, psMetadata *header, psMetadata *recipe);
+bool pmSourcesWrite_CFF (pmReadout *readout, psFits *fits, psArray *sources, psMetadata *header, psMetadata *recipe);
 
 bool pmSourcesWritePSFs (psArray *sources, char *filename);
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO_CFF.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO_CFF.c	(revision 36298)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO_CFF.c	(revision 36299)
@@ -69,5 +69,5 @@
         modelType = pmModelClassGetType (PSF_NAME);
     }
-    assert (modelType > -1);
+    PS_ASSERT_INT_NONNEGATIVE(modelType, NULL);
 
     // We get the size of the table, and allocate the array of sources first because the table
@@ -90,8 +90,14 @@
 	unsigned int ID  = psMetadataLookupU32 (&status, row, "ID");
 	float X          = psMetadataLookupF32 (&status, row, "X");
-        assert(status);
+        assert(status);  // poorly constructed cff
 	float Y          = psMetadataLookupF32 (&status, row, "Y");
-        assert(status);
+        assert(status);  // poorly constructed cff
         float flux       = psMetadataLookupF32 (&status, row, "FLUX"); // guess at the instrumental flux
+        if (!isfinite(X) || !isfinite(Y) || !isfinite(flux)) {
+            psError(PS_ERR_IO, true, "source ID %d is invalid x: %f y: %f flux: %f", ID, X, Y, flux);
+            psFree(sources);
+            return NULL;
+        }
+
 
         float apRadius   = psMetadataLookupF32 (&status, row, "AP_RADIUS");
@@ -155,5 +161,5 @@
 	pmPSF_AxesToModel (PAR, axes, modelType);
 
-	// peak->detValue, rawFlux, smoothFlux are all set to the flux argument
+	// peak->detValue, rawFlux, smoothFlux are all set to the flux argument which is counts per second
         source->peak      = pmPeakAlloc(X, Y, flux, PM_PEAK_LONE);
         source->peak->xf  = X; // pmPeakAlloc converts X,Y to int, so reset here
@@ -167,5 +173,5 @@
 	source->moments->Mrf = kronRadius * 0.4; // kronRadius is 2.5 * first radial moment
 	source->tmpFlags |= PM_SOURCE_TMPF_MOMENTS_MEASURED;
-	// XXX does the above cause a problem with pmSourceMoments (do we run it?)
+	// XXX does the above cause a problem with pmSourceMoments (do we run it? yes we do)
 
 	if (isfinite(petRadius)) {
@@ -195,8 +201,20 @@
                 xPAR[PM_PAR_7] = 0.5 / Sindex;
 	    }
+
+	    psArrayAdd (source->modelFits, 1, model);
+
+#ifdef notyet
             // XXX: set source->modelEXT to this model and flag as extended so that we have a better
             // shot at subtracting extended sources?
 
-	    psArrayAdd (source->modelFits, 1, model);
+            // This doesn't work right. Need to do some more work to flesh out the model before it can be
+            // used in subtaction. Better idea might be to do 2 passes in psphotFullForceReadout to
+            // First find the best extended models and then do everything else.
+            source->modelEXT = psMemIncrRefCounter(model);
+            // is this safe? (no see above)
+            source->type = PM_SOURCE_TYPE_EXTENDED;
+            source->mode |= PM_SOURCE_MODE_EXTMODEL; 
+#endif
+
 	    psFree (model);
         }
@@ -209,11 +227,15 @@
 }
 
-bool pmSourcesWrite_CFF(psFits *fits, psArray *sources, psMetadata *header, psMetadata *recipe) {
+bool pmSourcesWrite_CFF(pmReadout *readout, psFits *fits, psArray *sources, psMetadata *header, psMetadata *recipe) {
     
     char *extname = "SkyChip.cff";
     
+    bool mdok;
+    psF32 exptime = psMetadataLookupF32(&mdok, readout->parent->concepts, "CELL.EXPOSURE");
+    PS_ASSERT(mdok, false);
+
     psArray *table = psArrayAllocEmpty(sources->n);
 
-    pmModelType sersicModelType = pmModelClassGetType("PS_MODEL_SERSCIC");
+    pmModelType sersicModelType = pmModelClassGetType("PS_MODEL_SERSIC");
 
     for (int i = 0; i < sources->n; i++) {
@@ -225,5 +247,5 @@
         bool fitGalaxy = false;
         bool psfStar = false;
-        psS32 sersicIndex = 0;
+        psF32 sersicIndex = 0;
         if (source->modelFits == NULL) {
             pmModel *model = source->modelPSF;
@@ -286,4 +308,5 @@
             modelType = model->type;
             if (modelType == sersicModelType) {
+                PS_ASSERT_FLOAT_LARGER_THAN(PAR[PM_PAR_7], 0.0, false);
                 sersicIndex = 0.5 / PAR[PM_PAR_7];
             }
@@ -293,5 +316,5 @@
         psMetadataAddF32 (row, PS_LIST_TAIL, "X",                0, "x coordinate",          xPos);
         psMetadataAddF32 (row, PS_LIST_TAIL, "Y",                0, "y coordinate",          yPos);
-        psMetadataAddF32 (row, PS_LIST_TAIL, "FLUX",             0, "flux",                  flux);
+        psMetadataAddF32 (row, PS_LIST_TAIL, "FLUX",             0, "flux per second",       flux/exptime);
         psMetadataAddF32 (row, PS_LIST_TAIL, "AP_RADIUS",        0, "aperture radius",       source->apRadius);
         psMetadataAddF32 (row, PS_LIST_TAIL, "KRON_RADIUS",      0, "Kron radius",           source->moments->Mrf * 2.5);
@@ -303,5 +326,5 @@
         psMetadataAddF32 (row, PS_LIST_TAIL, "THETA",            0, "theta",                 theta);
         psMetadataAddS32 (row, PS_LIST_TAIL, "MODEL_TYPE",       0, "model type",            modelType);
-        psMetadataAddS32 (row, PS_LIST_TAIL, "INDEX",            0, "sersic index",          sersicIndex);
+        psMetadataAddF32 (row, PS_LIST_TAIL, "INDEX",            0, "sersic index",          sersicIndex);
 
         psArrayAdd(table, 100, row);
Index: /branches/eam_branches/ipp-20130904/psphot/src/psphotMergeSources.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psphot/src/psphotMergeSources.c	(revision 36298)
+++ /branches/eam_branches/ipp-20130904/psphot/src/psphotMergeSources.c	(revision 36299)
@@ -129,4 +129,5 @@
         extCFF = psMetadataLookupPtr (NULL, readoutCFF->analysis, "PSPHOT.DETECTIONS");
         if (extCFF) {
+            psF32 exptime = psMetadataLookupF32(NULL, readout->parent->concepts, "CELL.EXPOSURE");
             for (int i = 0; i < extCFF->allSources->n; i++) {
                 pmSource *source = extCFF->allSources->data[i];
@@ -136,5 +137,9 @@
                 source->mode |= PM_SOURCE_MODE_EXTERNAL;
 
-		// source->peak->detValue,rawFlux,smoothFlux all set to input flux value
+		// source->peak->detValue,rawFlux,smoothFlux all set to input flux value which is scaled
+                // to 1 second exposure time. Scale to this image's exposure.
+                source->peak->rawFlux    *= exptime;
+                source->peak->smoothFlux *= exptime;
+                source->peak->detValue   *= exptime;
 		// source->peak->xf,yf, moments->Mx,My all set to input position
 
