Index: /branches/eam_branches/ipp-20130904/psModules/src/camera/pmFPAfile.h
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/camera/pmFPAfile.h	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/camera/pmFPAfile.h	(revision 36157)
@@ -34,4 +34,5 @@
     PM_FPA_FILE_CMP,
     PM_FPA_FILE_CMF,
+    PM_FPA_FILE_CFF,
     PM_FPA_FILE_WCS,
     PM_FPA_FILE_RAW,
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/Makefile.am
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/Makefile.am	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/Makefile.am	(revision 36157)
@@ -40,4 +40,5 @@
 	pmSourceIO_SX.c \
 	pmSourceIO_CMP.c \
+	pmSourceIO_CFF.c \
 	pmSourceIO_SMPDATA.c \
 	pmSourceIO_PS1_DEV_0.c \
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSource.c	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSource.c	(revision 36157)
@@ -66,4 +66,5 @@
     psFree(tmp->extpars);
     psFree(tmp->diffStats);
+    psFree(tmp->galaxyFits);
     psFree(tmp->radialAper);
     psTrace("psModules.objects", 10, "---- end ----\n");
@@ -164,4 +165,5 @@
     source->extpars = NULL;
     source->diffStats = NULL;
+    source->galaxyFits = NULL;
     source->radialAper = NULL;
     source->parent = NULL;
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSource.h
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSource.h	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSource.h	(revision 36157)
@@ -117,4 +117,5 @@
     pmSourceExtendedPars *extpars;      ///< extended source parameters
     pmSourceDiffStats *diffStats;       ///< extra parameters for difference detections
+    pmSourceGalaxyFits *galaxyFits;     ///< fits to galaxy models (psphotFullForce only)
     psArray *radialAper;		///< radial flux in circular apertures
     pmSource *parent;			///< reference to the master source from which this is derived
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceExtendedPars.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceExtendedPars.c	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceExtendedPars.c	(revision 36157)
@@ -286,2 +286,25 @@
     return pars;
 }
+
+// *** pmSourceExtFitPars describes extra metadata related to an extended fit
+static void pmSourceGalaxyFitsFree (pmSourceGalaxyFits *tmp) {
+  
+    psFree (tmp->Io);
+    psFree (tmp->dIo);
+    psFree (tmp->chisq);
+
+    return;
+}
+
+pmSourceGalaxyFits *pmSourceGalaxyFitsAlloc (void) {
+
+    pmSourceGalaxyFits *tmp = (pmSourceGalaxyFits *) psAlloc(sizeof(pmSourceGalaxyFits));
+    psMemSetDeallocator(tmp, (psFreeFunc) pmSourceGalaxyFitsFree);
+
+    tmp->Io = psVectorAllocEmpty (25, PS_TYPE_F32);
+    tmp->dIo = psVectorAllocEmpty (25, PS_TYPE_F32);
+    tmp->chisq = psVectorAllocEmpty (25, PS_TYPE_F32);
+    tmp->nPix = 0;
+
+    return tmp;
+}
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceExtendedPars.h
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceExtendedPars.h	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceExtendedPars.h	(revision 36157)
@@ -82,4 +82,11 @@
 } pmSourceExtFitPars;
 
+typedef struct {
+  psVector *Io;
+  psVector *dIo;
+  psVector *chisq;
+  int nPix;
+} pmSourceGalaxyFits;
+
 pmSourceRadialFlux *pmSourceRadialFluxAlloc();
 bool psMemCheckSourceRadialFlux(psPtr ptr);
@@ -109,4 +116,7 @@
 pmSourceExtFitPars *pmSourceExtFitParsAlloc (void);
 
+pmSourceGalaxyFits *pmSourceGalaxyFitsAlloc (void);
+
+
 /// @}
 # endif /* PM_SOURCE_H */
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.c
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.c	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.c	(revision 36157)
@@ -915,4 +915,15 @@
     pmHDU *hdu;
 
+    // define the EXTNAME values for the different data segments:
+    psString headname = NULL;
+    psString dataname = NULL;
+    psString deteffname = NULL;
+    psString xsrcname = NULL;
+    psString xfitname = NULL;
+    psString xradname = NULL;
+
+    psMetadata *tableHeader = NULL;
+    char *xtension = NULL;
+
     switch (file->type) {
       case PM_FPA_FILE_OBJ:
@@ -962,12 +973,4 @@
         // read in header, if not yet loaded
         hdu = pmFPAviewThisHDU (view, file->fpa);
-
-        // define the EXTNAME values for the different data segments:
-        psString headname = NULL;
-        psString dataname = NULL;
-        psString deteffname = NULL;
-        psString xsrcname = NULL;
-        psString xfitname = NULL;
-        psString xradname = NULL;
 
         // determine the output table format. Assume if we need to output extendend source
@@ -1033,8 +1036,8 @@
         }
 
-        psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
+        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
         if (!tableHeader) psAbort("cannot read table header");
 
-        char *xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
+        xtension = psMetadataLookupStr (NULL, tableHeader, "XTENSION");
         if (!xtension) psAbort("cannot read table type");
 	if (strcmp (xtension, "BINTABLE")) {
@@ -1141,6 +1144,6 @@
 
         // define the EXTNAME values for the different data segments:
-        psString headname = pmFPAfileNameFromRule("{CHIP.NAME}.hdr", file, view);
-        psString dataname = pmFPAfileNameFromRule("{CHIP.NAME}.cff", file, view);
+        headname = pmFPAfileNameFromRule("{CHIP.NAME}.hdr", file, view);
+        dataname = pmFPAfileNameFromRule("{CHIP.NAME}.cff", file, view);
 
         // advance to the IMAGE HEADER extension
@@ -1162,5 +1165,5 @@
         }
 
-        psMetadata *tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
+        tableHeader = psFitsReadHeader(NULL, file->fits); // The FITS header
         if (!tableHeader) psAbort("cannot read table header");
 
Index: /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.h
===================================================================
--- /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.h	(revision 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO.h	(revision 36157)
@@ -52,4 +52,5 @@
 
 psArray *pmSourcesReadCMP (char *filename, psMetadata *header);
+psArray *pmSourcesRead_CFF (psFits *fits, psMetadata *header);
 
 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 36156)
+++ /branches/eam_branches/ipp-20130904/psModules/src/objects/pmSourceIO_CFF.c	(revision 36157)
@@ -59,5 +59,4 @@
 
     bool status;
-    psF32 *PAR, *dPAR;
     psEllipseAxes axes;
 
@@ -92,7 +91,7 @@
 	// 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");
+	unsigned int ID  = psMetadataLookupU32 (&status, row, "ID");
+	float X          = psMetadataLookupF32 (&status, row, "X");
+	float Y          = psMetadataLookupF32 (&status, row, "Y");
 
         float apRadius   = psMetadataLookupS32 (&status, row, "AP_RADIUS");
@@ -172,5 +171,5 @@
 
         if (fitGalaxy) {
-            source->modelFits = psArrayAllocEmpty (models->list->n);
+            source->modelFits = psArrayAllocEmpty (1);
 	    pmModel *model = pmModelAlloc(modelType);
 	    psF32 *xPAR = model->params->data.F32;
@@ -181,11 +180,13 @@
 	    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;
+	    psEllipseAxes galaxyAxes;
+	    galaxyAxes.major = Rmajor;
+	    galaxyAxes.minor = Rminor;
+	    galaxyAxes.theta = theta; // XXX degrees or radians?
+
+	    pmPSF_AxesToModel (PAR, galaxyAxes, galaxyModelType);
+	    if (model->params->n > 7) {
+	      xPAR[PM_PAR_7] = Sindex;
+	    }
 
 	    psArrayAdd (source->modelFits, 1, model);
