Index: trunk/psphot/src/psphotReadout.c
===================================================================
--- trunk/psphot/src/psphotReadout.c	(revision 6715)
+++ trunk/psphot/src/psphotReadout.c	(revision 6727)
@@ -1,6 +1,5 @@
 # include "psphot.h"
 
-// XXX 2006.02.07 : no leaks!
-// XXX change 'config' to 'recipe' eventually
+// XXX 2006.03.28 : no leaks!
 bool psphotReadout (pmConfig *config, pmFPAview *view) {
 
@@ -15,9 +14,4 @@
     pmReadout  *readout = pmFPAviewThisReadout (view, input->fpa);
 
-    sources = psphotFakeSources();
-    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES",   PS_DATA_ARRAY,   "psphot sources", sources);
-    psFree (sources);
-    return true;
-
     // XXX does this need to invoke I/O?
     pmReadoutSetWeights (readout);
@@ -25,4 +19,7 @@
     // I have a valid mask, now mask in the analysis region of interest
     psphotMaskReadout (readout, recipe); 
+
+    // run a single-model test if desired
+    psphotModelTest (readout, recipe);
 
     // generate a background model (median, smoothed image)
@@ -55,5 +52,5 @@
     psphotReplaceUnfit (sources);
 
-    // find remaining peaks after first source subtraction pass
+    // XXX find remaining peaks after first source subtraction pass
     // psphotFindPeaks ();
 
@@ -67,21 +64,18 @@
     psphotMagnitudes (sources, recipe, psf);
 
-    // update the header with stats results
-    // XXX need to do this conditionally?
-    // XXX psMetadata *header = pmReadoutGetHeader (readout);
-    // XXX psphotUpdateHeader (header, config);
+    // create an output header with stats results
+    psMetadata *header = psphotDefineHeader (recipe);
 
-    // XXX make this an option?
     // replace background in residual image
     psphotSkyReplace (config, view);
 
-    // need to do something with the sources, psf, and sky
-    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES",   PS_DATA_ARRAY,   "psphot sources", sources);
-    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF",       PS_DATA_UNKNOWN, "psphot psf", psf);
-    // XXX : replace? status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SKY.MEAN",  PS_DATA_F32,     "psphot sky mean", sky->sampleMean);
-    // XXX : replace? status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SKY.SIGMA", PS_DATA_F32,     "psphot sky stdev", sky->sampleStdev);
+    // save the results of the analysis 
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY,    "psphot sources", sources);
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.HEADER",  PS_DATA_METADATA, "header stats", header);
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.PSF",     PS_DATA_UNKNOWN,  "psphot psf", psf);
 
     // free up the local copies of the data
     psFree (psf);
+    psFree (header);
     psFree (sources);
     psFree (peaks);
@@ -89,31 +83,12 @@
 }
 
-
-// XXX Deprecate or allow these versions?
-# if (0)
-    // select analysis method
-    char *FITMODE = psMetadataLookupStr (&status, config, "FITMODE");
-    if (!strcasecmp(FITMODE, "ENSEMBLE")) {
-	psphotEnsemblePSF (readout, config, sources, psf);
-    }
-
-    if (!strcasecmp(FITMODE, "FULL")) {
-	psphotEnsemblePSF (readout, config, sources, psf);
-	psphotFullFit (readout, config, sources, psf);
-	psphotReplaceUnfit (sources);
-	psphotApResid (readout, sources, config, psf);
-    }
-
-    if (!strcasecmp(FITMODE, "BASIC")) {
-	psphotApplyPSF (readout, config, sources, psf);
-	psphotFitExtended (readout, config, sources);
-    }
-
-
-
-    psphotSaveImage (NULL, readout->image,  "pixels.fits");
-    psphotSaveImage (NULL, readout->weight, "weight.fits");
-    psphotSaveImage (NULL, readout->mask,   "mask.fits");
-    exit (1);
-
-# endif
+    # if (1)
+    fprintf (stderr, "making fake sources\n");
+    sources = psphotFakeSources ();
+    psMetadata *tmp = psMetadataAlloc ();
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.SOURCES", PS_DATA_ARRAY,    "psphot sources", sources);
+    status = psMetadataAdd (readout->analysis, PS_LIST_TAIL, "PSPHOT.HEADER",  PS_DATA_METADATA, "header stats", tmp);
+    psFree (sources);
+    psFree (tmp);
+    return true;
+    # endif
