Index: trunk/psphot/src/psphotOutput.c
===================================================================
--- trunk/psphot/src/psphotOutput.c	(revision 5073)
+++ trunk/psphot/src/psphotOutput.c	(revision 5084)
@@ -26,5 +26,5 @@
 
     if (!strcasecmp (outputMode, "OBJ")) {
-	pmSourcesWriteOBJ (imdata, outputFile, sources, psf, sky);
+	pmSourcesWriteOBJ (imdata, config, outputFile, sources, psf, sky);
 	return;
     }
@@ -36,10 +36,10 @@
   
     if (!strcasecmp (outputMode, "CMP")) {
-	pmSourcesWriteCMP (imdata, outputFile, sources, psf, sky);
+	pmSourcesWriteCMP (imdata, config, outputFile, sources, psf, sky);
 	return;
     }
   
     if (!strcasecmp (outputMode, "CMF")) {
-	pmSourcesWriteCMF (imdata, outputFile, sources, psf, sky);
+	pmSourcesWriteCMF (imdata, config, outputFile, sources, psf, sky);
 	return;
     }
@@ -68,5 +68,5 @@
 
 // dophot-style output list with fixed line width
-bool pmSourcesWriteOBJ (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
+bool pmSourcesWriteOBJ (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
 
     int i, type, status;
@@ -74,4 +74,6 @@
     psF32 *PAR, *dPAR;
     float sky, dmag, apMag, fitMag;
+    float x, y, rflux;
+    bool result;
 
     psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
@@ -82,4 +84,6 @@
 	return false;
     }
+
+    float RADIUS = psMetadataLookupF32 (&result, config, "PSF_FIT_RADIUS");
 
     // write sources with models first 
@@ -296,14 +300,24 @@
 
 // elixir-style pseudo FITS table (header + ascii list)
-bool pmSourcesWriteCMP (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
+bool pmSourcesWriteCMP (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
 
     int i, type, status;
     pmModel *model;
+    psMetadataItem *mdi;
     psF32 *PAR, *dPAR;
-    float sky, dmag, apMag, fitMag, lsky, Theta;
+    float sky, dmag, apMag, fitMag, lsky;
+    float x, y, rflux;
+    bool result;
 
     // create file, write-out header
     unlink (filename);
     psFits *fits = psFitsAlloc (filename);
+
+    // set NAXIS to 0 : CFITSIO requires isolated header to have NAXIS = 0
+    mdi = psMetadataLookup (imdata->header, "NAXIS");
+    mdi->data.S32 = 0;
+    mdi->type = PS_META_S32;
+
+    // psMetadataAdd (imdata->header, PS_LIST_HEAD, "NAXIS", PS_META_S32 | PS_META_REPLACE, "", 0);
     psFitsWriteHeader (imdata->header, fits);
     psFree (fits);
@@ -317,5 +331,16 @@
     fseek (f, 0, SEEK_END);
 
-    psLine *line = psLineAlloc (66);  // 66 is imclean-defined line length
+    psLine *line = psLineAlloc (67);  // 66 is imclean-defined line length
+
+    float RADIUS = psMetadataLookupF32 (&result, config, "PSF_FIT_RADIUS");
+
+    // XXX EAM : need to add these concepts to the header (from psf and config)
+    // fits_modify (header, "ZERO_PT", "%lf", 1, ZERO_POINT);
+    // fits_modify (header, "FWHM_X", "%lf", 1, FWHMx);
+    // fits_modify (header, "FWHM_Y", "%lf", 1, FWHMy);
+    // fits_modify (header, "ANGLE", "%lf", 1, angle);
+    // fits_modify (header, "FSATUR", "%lf", 1, saturate);  // can use 0.0
+    // fits_modify (header, "FLIMIT", "%lf", 1, complete);  // can use 0.0
+    // fits_modify (header, "NSTARS", "%d", 1, N);
 
     // write sources with models first 
@@ -404,5 +429,5 @@
 	psLineAdd (line, "%6.2f ", PAR[4]);  // should be 'FHWM x'
 	psLineAdd (line, "%6.2f ", PAR[5]);  // should be 'FHWM y'
-	psLineAdd (line, "%5.1f\n", Theta);   // should be theta
+	psLineAdd (line, "%5.1f\n", 0);   // should be theta
 	fwrite (line->line, 1, line->Nline, f);
     }
@@ -414,15 +439,29 @@
 // this format consists of a header derived from the image header
 // followed by a zero-size matrix, followed by the table data
-bool pmSourcesWriteCMF (eamReadout *imdata, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
+bool pmSourcesWriteCMF (eamReadout *imdata, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
 
     psArray *table;
+    psMetadataItem *mdi;
     psMetadata *row;
     psMetadata *theader;
+    int i, type, status;
+    pmModel *model;
+    psF32 *PAR, *dPAR;
+    float sky, dmag, apMag, fitMag;
+    float x, y, rflux, lsky;
+    bool result;
 
     // set NAXIS to 0
-    psMetadataAdd (header, PS_LIST_HEAD, "NAXIS", PS_META_S32 | PS_META_REPLACE, "", 0);
+    fprintf (stderr, "setting naxis\n"); 
+    mdi = psMetadataLookup (imdata->header, "NAXIS");
+    mdi->data.S32 = 0;
+    mdi->type = PS_META_S32;
+
+    // psMetadataAdd (imdata->header, PS_LIST_HEAD, "NAXIS", PS_META_S32 | PS_META_REPLACE, "", 0);
 
     table = psArrayAlloc (sources->n);
     sources->n = 0;
+
+    float RADIUS = psMetadataLookupF32 (&result, config, "PSF_FIT_RADIUS");
 
     for (i = 0; i < sources->n; i++) {
@@ -499,16 +538,16 @@
 	lsky = (PAR[0] < 1.0) ? 0.0 : log10(PAR[0]);
 
-	table = psMetdataAlloc ();
-	psMetadataAdd (table, PS_LIST_HEAD, "X_PIX",   PS_META_F32, "", PAR[2]);
-	psMetadataAdd (table, PS_LIST_HEAD, "Y_PIX",   PS_META_F32, "", PAR[3]);
-	psMetadataAdd (table, PS_LIST_HEAD, "MAG_RAW", PS_META_F32, "", fitMag + 25.0);
-	psMetadataAdd (table, PS_LIST_HEAD, "MAG_ERR", PS_META_F32, "", (int)(1000*dmag));
-	psMetadataAdd (table, PS_LIST_HEAD, "MAG_GAL", PS_META_F32, "", type);
-	psMetadataAdd (table, PS_LIST_HEAD, "MAG_AP",  PS_META_F32, "", lsky);
-	psMetadataAdd (table, PS_LIST_HEAD, "LOG_SKY", PS_META_F32, "", 32.0);    // should be 'Mgal'
-	psMetadataAdd (table, PS_LIST_HEAD, "FWHM_X",  PS_META_F32, "", apMag + 25.0); // 25.0 should come from config
-	psMetadataAdd (table, PS_LIST_HEAD, "FWHM_Y",  PS_META_F32, "", PAR[4]);  // should be 'FHWM x'
-	psMetadataAdd (table, PS_LIST_HEAD, "THETA",   PS_META_F32, "", PAR[5]);  // should be 'FHWM y'
-	psMetadataAdd (table, PS_LIST_HEAD, "DOPHOT",  PS_META_S8,  "", Theta);   // should be theta
+	row = psMetadataAlloc ();
+	psMetadataAdd (row, PS_LIST_HEAD, "X_PIX",   PS_META_F32, "", PAR[2]);
+	psMetadataAdd (row, PS_LIST_HEAD, "Y_PIX",   PS_META_F32, "", PAR[3]);
+	psMetadataAdd (row, PS_LIST_HEAD, "MAG_RAW", PS_META_F32, "", fitMag + 25.0);
+	psMetadataAdd (row, PS_LIST_HEAD, "MAG_ERR", PS_META_F32, "", (int)(1000*dmag));
+	psMetadataAdd (row, PS_LIST_HEAD, "MAG_GAL", PS_META_F32, "", type);
+	psMetadataAdd (row, PS_LIST_HEAD, "MAG_AP",  PS_META_F32, "", lsky);
+	psMetadataAdd (row, PS_LIST_HEAD, "LOG_SKY", PS_META_F32, "", 32.0);    // should be 'Mgal'
+	psMetadataAdd (row, PS_LIST_HEAD, "FWHM_X",  PS_META_F32, "", apMag + 25.0); // 25.0 should come from config
+	psMetadataAdd (row, PS_LIST_HEAD, "FWHM_Y",  PS_META_F32, "", PAR[4]);  // should be 'FHWM x'
+	psMetadataAdd (row, PS_LIST_HEAD, "THETA",   PS_META_F32, "", PAR[5]);  // should be 'FHWM y'
+	psMetadataAdd (row, PS_LIST_HEAD, "DOPHOT",  PS_TYPE_S8,  "", 0);   // should be theta
 	// psMetadataAdd (header, PS_LIST_HEAD, "DUMMY",   PS_META_STR, "", NULL);
     
@@ -517,10 +556,15 @@
     }
 
-    image = psImageAlloc (0, 0, PS_TYPE_F32);
-    theader = psFitsHeaderFromTable (NULL, table, "SMPFILE");
+    // psAbort ("psphotOutput", "FITS table output not finished");
+
+    psImage *image = psImageAlloc (1, 1, PS_TYPE_F32);
+    // XXX missing: theader = psFitsHeaderFromTable (NULL, table, "SMPFILE");
+
+    theader = psMetadataAlloc ();
+    psMetadataAdd (theader, PS_LIST_HEAD, "EXTNAME", PS_META_STR, "extension name", "SMPFILE");
 
     unlink (filename);
     psFits *fits = psFitsAlloc (filename);
-    psFitsWriteImage (fits, header, image, 0, NULL);
+    psFitsWriteImage (fits, imdata->header, image, 0);
     psFitsWriteTable (fits, theader, table);
     psFree (fits);
