Index: trunk/psModules/src/objects/pmSourceIO.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.c	(revision 25754)
+++ trunk/psModules/src/objects/pmSourceIO.c	(revision 25907)
@@ -342,7 +342,4 @@
     pmHDU *hdu;
     psMetadata *updates;
-    psMetadata *outhead;
-
-    char *exttype  = NULL;
 
     // if sources is NULL, write out an empty table
@@ -368,37 +365,38 @@
         break;
 
-      case PM_FPA_FILE_CMP:
-        // a SPLIT format : only one header and object table per file
-        hdu = pmFPAviewThisHDU (view, fpa);
-        if (!hdu) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
-            return false;
-        }
-
-        // copy the header to an output header, add the output header data
-        outhead = psMetadataCopy (NULL, hdu->header);
-
-        // copy over the entries saved by PSPHOT
-        updates = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.HEADER");
-        if (updates) {
-            psMetadataCopy (outhead, updates);
-        }
-
-        // copy over the entries saved by PSASTRO
-        updates = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.HEADER");
-        if (updates) {
-            psMetadataCopy (outhead, updates);
-        }
-
-        bool status = pmSourcesWriteCMP (sources, file->filename, outhead);
-        psFree (outhead);
-
-        if (!status) {
-            psError(PS_ERR_IO, false, "Failed to write CMP file\n");
-            return false;
-        }
-        break;
-
-      case PM_FPA_FILE_CMF:
+      case PM_FPA_FILE_CMP: {
+	  // a SPLIT format : only one header and object table per file
+	  hdu = pmFPAviewThisHDU (view, fpa);
+	  if (!hdu) {
+	      psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find HDU to write sources.");
+	      return false;
+	  }
+
+	  // copy the header to an output header, add the output header data
+	  psMetadata *outhead = psMetadataCopy (NULL, hdu->header);
+
+	  // copy over the entries saved by PSPHOT
+	  updates = psMetadataLookupPtr (NULL, readout->analysis, "PSPHOT.HEADER");
+	  if (updates) {
+	      psMetadataCopy (outhead, updates);
+	  }
+
+	  // copy over the entries saved by PSASTRO
+	  updates = psMetadataLookupPtr (NULL, readout->analysis, "PSASTRO.HEADER");
+	  if (updates) {
+	      psMetadataCopy (outhead, updates);
+	  }
+
+	  bool status = pmSourcesWriteCMP (sources, file->filename, outhead);
+	  psFree (outhead);
+
+	  if (!status) {
+	      psError(PS_ERR_IO, false, "Failed to write CMP file\n");
+	      return false;
+	  }
+	  break;
+      }
+
+      case PM_FPA_FILE_CMF: 
         // write a header? (only if this is the first readout for cell)
         //   note that the file->header is set to track the last hdu->header written
@@ -415,6 +413,6 @@
         psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PSPHOT");
         if (!status) {
-          psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
-          return false;
+	    psError(PS_ERR_UNKNOWN, true, "missing recipe PSPHOT in config data");
+	    return false;
         }
 
@@ -429,6 +427,8 @@
         psString xsrcname = NULL;
         psString xfitname = NULL;
-        if (!sourceExtensions(&headname, &dataname, &deteffname, XSRC_OUTPUT ? &xsrcname : NULL,
-                              XFIT_OUTPUT ? &xfitname : NULL, file, view)) {
+        if (!sourceExtensions(&headname, &dataname, &deteffname, 
+			      XSRC_OUTPUT ? &xsrcname : NULL,
+                              XFIT_OUTPUT ? &xfitname : NULL, 
+			      file, view)) {
             return false;
         }
@@ -489,10 +489,10 @@
         }
 
-        // write out the TABLE data segment
+        // write out the Object TABLE data segment(s)
         {
             // create a header to hold the output data
-            outhead = psMetadataAlloc ();
-
-            exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));
+            psMetadata *outhead = psMetadataAlloc ();
+	    
+	    char *exttype = psMemIncrRefCounter (psMetadataLookupStr(&status, recipe, "OUTPUT.FORMAT"));
             if (!exttype) {
                 exttype = psStringCopy ("SMPDATA");
@@ -502,12 +502,11 @@
             psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname);
             psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", exttype);
-            psFree (exttype);
 
             // if we request XSRC output, add the XSRC name to this header
             if (xsrcname) {
-              psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);
+		psMetadataAddStr (outhead, PS_LIST_TAIL, "XSRCNAME", PS_META_REPLACE, "name of XSRC table extension", xsrcname);
             }
             if (xfitname) {
-              psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);
+		psMetadataAddStr (outhead, PS_LIST_TAIL, "XFITNAME", PS_META_REPLACE, "name of XFIT table extension", xfitname);
             }
 
@@ -533,57 +532,73 @@
             }
 
-            if (deteffname) {
-                status &= pmReadoutWriteDetEff(file->fits, readout, outhead, deteffname);
-            }
-
             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, sources, xsrcname, recipe);
-              }
-              if (!strcmp (exttype, "PS1_V2")) {
-                  status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, sources, xsrcname, recipe);
-              }
+		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, sources, xsrcname, recipe);
+		}
+		if (!strcmp (exttype, "PS1_V2")) {
+		    status &= pmSourcesWrite_CMF_PS1_V2_XSRC (file->fits, sources, 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, sources, xfitname);
-              }
-              if (!strcmp (exttype, "PS1_V2")) {
-                  status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, sources, 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, sources, xfitname);
+		}
+		if (!strcmp (exttype, "PS1_V2")) {
+		    status &= pmSourcesWrite_CMF_PS1_V2_XFIT (file->fits, sources, xfitname);
+		}
+            }
+	    psFree (outhead);
+	    psFree (exttype);
+
             if (!status) {
                 psError(PS_ERR_IO, false, "writing CMF data to %s with format %s\n", file->filename, exttype);
-                psFree (headname);
-                psFree (dataname);
-                psFree (xsrcname);
-                psFree (xfitname);
-                psFree (outhead);
-                psFree (deteffname);
-                return false;
-            }
-        }
+		goto escape;
+            }
+        }
+
+
+	// write out the detection efficiency TABLE segments
+	if (deteffname) {
+            // create a header to hold the output data
+            psMetadata *outhead = psMetadataAlloc ();
+            psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTHEAD", PS_META_REPLACE, "name of image extension w/", headname);
+	    psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTTYPE", PS_META_REPLACE, "extension type", "DETEFF");
+
+	    status = pmReadoutWriteDetEff(file->fits, readout, outhead, deteffname);
+	    psFree (outhead);
+
+            if (!status) {
+                psError(PS_ERR_IO, false, "writing DETEFF data to %s\n", file->filename);
+		goto escape;
+            }
+	}
+	psFree (headname);
+	psFree (dataname);
+	psFree (xsrcname);
+	psFree (xfitname);
+	psFree (deteffname);
 
         psTrace ("pmFPAfile", 5, "wrote ext data %s (type: %d)\n", file->filename, file->type);
-
-        psFree (headname);
-        psFree (dataname);
-        psFree (xsrcname);
-        psFree (xfitname);
-        psFree (outhead);
+        break;
+
+      escape:
+	psFree (headname);
+	psFree (dataname);
+	psFree (xsrcname);
+	psFree (xfitname);
 	psFree (deteffname);
-        break;
+	return false;
 
       default:
@@ -592,4 +607,5 @@
     }
     return true;
+
 }
 // a MEF CMF file has: PHU, CELL-HEAD, TABLE, CELL-HEAD, TABLE, TABLE, TABLE...
