Index: trunk/psModules/src/objects/pmSourceIO.c
===================================================================
--- trunk/psModules/src/objects/pmSourceIO.c	(revision 7382)
+++ trunk/psModules/src/objects/pmSourceIO.c	(revision 7725)
@@ -3,6 +3,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-07 03:27:52 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-28 19:21:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -218,26 +218,30 @@
 
     case PM_FPA_FILE_CMF:
-        // write a PHU?
-        // write a header?
-        // write the data
+        // write a PHU? (only if input image is MEF)
+        // 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
+        // write the data? (always?)
 
         // get the current header
         hdu = pmFPAviewThisHDU (view, file->fpa);
 
-        // if file does not yet have a PHU, write it to disk
+        // if file does not yet have a PHU, attempt to write one to disk
         if (file->phu == NULL) {
             // get the corresponding phu
             phu = pmFPAviewThisPHU (view, file->fpa);
 
-            // CMF always has extensions
-            outhead = psMetadataCopy (NULL, phu->header);
-            psMetadataAdd (outhead, PS_LIST_TAIL, "EXTEND", PS_DATA_BOOL | PS_META_REPLACE, "this file has extensions", true);
-            psFitsWriteBlank (file->fits, outhead);
-            file->phu = phu->header;
-            psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
-            psFree (outhead);
-        }
-
-        // this this header block is new, write it to disk,
+            // if there is no PHU, this is a single header+image (extension-less) file
+            // if there is a PHU, write it out as a 'blank'
+            if (phu) {
+                outhead = psMetadataCopy (NULL, phu->header);
+                psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
+                psFitsWriteBlank (file->fits, outhead);
+                file->phu = phu->header;
+                psTrace ("pmFPAfile", 5, "wrote phu %s (type: %d)\n", file->filename, file->type);
+                psFree (outhead);
+            }
+        }
+
+        // this header block is new, write it to disk
         if (hdu->header != file->header) {
             // determine name for header extension
@@ -245,4 +249,13 @@
             outhead = psMetadataCopy (NULL, hdu->header);
             psMetadataAddStr (outhead, PS_LIST_TAIL, "EXTNAME", PS_META_REPLACE, "extension name", headname);
+            if (file->phu == NULL) {
+                // this hdu->header acts as the PHU: set EXTEND to be true
+                psMetadataAddBool (outhead, PS_LIST_TAIL, "EXTEND", PS_META_REPLACE, "this file has extensions", true);
+            }
+
+            // XXX : see note below about DVO/addstar expectations
+            updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
+            psMetadataCopy (outhead, updates);
+
             psFitsWriteBlank (file->fits, outhead);
             psTrace ("pmFPAfile", 5, "wrote ext head %s (type: %d)\n", file->filename, file->type);
@@ -254,4 +267,12 @@
         // write this table to disk
         dataname = pmFPAfileNameFromRule (file->extrule, file, view);
+
+        // XXX : currently, this is being added to the TABLE header
+        //       this may be the correct location for a MEF file, but it is
+        //       inconsistent with DVO/addstar expectations.  DVO/addstar
+        //       currently only expects a single header/table pair, and the
+        //       metadata are in the blank (image) header, not the table header
+        //       it may be necessary to put the results from the first readout
+        //       in the blank image header to cover this case.
         updates = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.HEADER");
         pmSourcesWriteCMF (file->fits, sources, updates, dataname);
