Index: trunk/psModules/src/objects/pmSourceIO.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.c	(revision 28013)
+++ trunk/psModules/src/objects/pmSourceIO.c	(revision 29004)
@@ -31,16 +31,25 @@
 #include "pmConceptsRead.h"
 
+#include "pmTrend2D.h"
+#include "pmResiduals.h"
+#include "pmGrowthCurve.h"
 #include "pmSpan.h"
+#include "pmFootprintSpans.h"
 #include "pmFootprint.h"
 #include "pmPeaks.h"
 #include "pmMoments.h"
-#include "pmGrowthCurve.h"
-#include "pmResiduals.h"
-#include "pmTrend2D.h"
+#include "pmModelFuncs.h"
+#include "pmModel.h"
+#include "pmModelUtils.h"
+#include "pmModelClass.h"
+#include "pmSourceMasks.h"
+#include "pmSourceExtendedPars.h"
+#include "pmSourceDiffStats.h"
+#include "pmSource.h"
+#include "pmSourceFitModel.h"
 #include "pmPSF.h"
-#include "pmModel.h"
+#include "pmPSFtry.h"
+
 #include "pmDetections.h"
-#include "pmSource.h"
-#include "pmModelClass.h"
 #include "pmDetEff.h"
 #include "pmSourceIO.h"
@@ -326,4 +335,15 @@
 }
 
+# define PM_SOURCES_WRITE(NAME,TYPE)					\
+    if (!strcmp (exttype, NAME)) {					\
+	status &= pmSourcesWrite_##TYPE(file->fits, readout, sources, file->header, outhead, dataname, recipe); \
+	if (xsrcname) {							\
+	    status &= pmSourcesWrite_##TYPE##_XSRC(file->fits, readout, sources, file->header, xsrcname, recipe); \
+	}								\
+	if (xfitname) {							\
+	    status &= pmSourcesWrite_##TYPE##_XFIT (file->fits, readout, sources, file->header, xfitname); \
+	}								\
+    }
+
 // write out all readout-level Objects files for this cell
 bool pmReadoutWriteObjects (pmReadout *readout, const pmFPAview *view, pmFPAfile *file, const pmConfig *config)
@@ -360,4 +380,5 @@
     }
 
+    // the older types (RAW, OBJ, SX, CMP) are for backwards compatibility -- deprecate eventually?
     switch (file->type) {
       case PM_FPA_FILE_RAW:
@@ -518,72 +539,19 @@
 		psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);
             }
-
-            // XXX these are case-sensitive since the EXTYPE is case-sensitive
+    
+
+            // these are case-sensitive since the EXTYPE is case-sensitive
             status = true;
-            if (!strcmp (exttype, "SMPDATA")) {
-                status &= pmSourcesWrite_SMPDATA (file->fits, sources, file->header, outhead, dataname);
-            }
-            if (!strcmp (exttype, "PS1_DEV_0")) {
-                status &= pmSourcesWrite_PS1_DEV_0 (file->fits, sources, file->header, outhead, dataname);
-            }
-            if (!strcmp (exttype, "PS1_DEV_1")) {
-                status &= pmSourcesWrite_PS1_DEV_1 (file->fits, sources, file->header, outhead, dataname);
-            }
-            if (!strcmp (exttype, "PS1_CAL_0")) {
-                status &= pmSourcesWrite_PS1_CAL_0 (file->fits, readout, sources, file->header, outhead, dataname);
-            }
-            if (!strcmp (exttype, "PS1_V1")) {
-                status &= pmSourcesWrite_CMF_PS1_V1 (file->fits, readout, sources, file->header, outhead, dataname);
-            }
-            if (!strcmp (exttype, "PS1_V2")) {
-                status &= pmSourcesWrite_CMF_PS1_V2 (file->fits, readout, sources, file->header, outhead, dataname);
-            }
-            if (!strcmp (exttype, "PS1_SV1")) {
-                status &= pmSourcesWrite_CMF_PS1_SV1 (file->fits, readout, sources, file->header, outhead, dataname, recipe);
-            }
-            if (!strcmp (exttype, "PS1_DV1")) {
-                status &= pmSourcesWrite_CMF_PS1_DV1 (file->fits, readout, sources, file->header, outhead, dataname);
-            }
-
-            if (xsrcname) {
-		if (!strcmp (exttype, "PS1_DEV_1")) {
-		    status &= pmSourcesWrite_PS1_DEV_1_XSRC (file->fits, sources, xsrcname, recipe);
-		}
-		if (!strcmp (exttype, "PS1_CAL_0")) {
-		    status &= pmSourcesWrite_PS1_CAL_0_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
-		}
-		if (!strcmp (exttype, "PS1_V1")) {
-		    status &= pmSourcesWrite_CMF_PS1_V1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
-		}
-		if (!strcmp (exttype, "PS1_V2")) {
-		    status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
-		}
-		if (!strcmp (exttype, "PS1_SV1")) {
-		    status &= pmSourcesWrite_CMF_PS1_SV1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
-		}
-		if (!strcmp (exttype, "PS1_DV1")) {
-		    status &= pmSourcesWrite_CMF_PS1_DV1_XSRC (file->fits, readout, sources, file->header, xsrcname, recipe);
-		}
-            }
-            if (xfitname) {
-		if (!strcmp (exttype, "PS1_DEV_1")) {
-		    status &= pmSourcesWrite_PS1_DEV_1_XFIT (file->fits, sources, xfitname);
-		}
-		if (!strcmp (exttype, "PS1_CAL_0")) {
-		    status &= pmSourcesWrite_PS1_CAL_0_XFIT (file->fits, readout, sources, file->header, xfitname);
-		}
-		if (!strcmp (exttype, "PS1_V1")) {
-		    status &= pmSourcesWrite_CMF_PS1_V1_XFIT (file->fits, readout, sources, xfitname);
-		}
-		if (!strcmp (exttype, "PS1_V2")) {
-		    status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, readout, sources, xfitname);
-		}
-		if (!strcmp (exttype, "PS1_SV1")) {
-		    status &= pmSourcesWrite_CMF_PS1_SV1_XFIT (file->fits, readout, sources, xfitname);
-		}
-		if (!strcmp (exttype, "PS1_DV1")) {
-		    status &= pmSourcesWrite_CMF_PS1_DV1_XFIT (file->fits, readout, sources, xfitname);
-		}
-            }
+	    PM_SOURCES_WRITE("SMPDATA",   SMPDATA);
+	    PM_SOURCES_WRITE("PS1_DEV_0", PS1_DEV_0);
+	    PM_SOURCES_WRITE("PS1_DEV_1", PS1_DEV_1);
+	    PM_SOURCES_WRITE("PS1_CAL_0", PS1_CAL_0);
+	    PM_SOURCES_WRITE("PS1_V1",    CMF_PS1_V1);
+	    PM_SOURCES_WRITE("PS1_V2",    CMF_PS1_V2);
+	    PM_SOURCES_WRITE("PS1_V3",    CMF_PS1_V3);
+	    PM_SOURCES_WRITE("PS1_SV1",   CMF_PS1_SV1);
+	    PM_SOURCES_WRITE("PS1_DV1",   CMF_PS1_DV1);
+	    PM_SOURCES_WRITE("PS1_DV2",   CMF_PS1_DV2);
+
 	    psFree (outhead);
 	    psFree (exttype);
@@ -1039,4 +1007,7 @@
                 sources = pmSourcesRead_CMF_PS1_DV1 (file->fits, hdu->header);
             }
+            if (!strcmp (exttype, "PS1_DV2")) {
+                sources = pmSourcesRead_CMF_PS1_DV2 (file->fits, hdu->header);
+            }
 
             if (!pmReadoutReadDetEff(file->fits, readout, deteffname)) {
