Index: trunk/psphot/src/psphotOutput.c
===================================================================
--- trunk/psphot/src/psphotOutput.c	(revision 6056)
+++ trunk/psphot/src/psphotOutput.c	(revision 6117)
@@ -2,9 +2,14 @@
 
 // output functions: we have several fixed modes (sx, obj, cmp)
-void psphotOutput (pmReadout *readout, psMetadata *header, psMetadata *config, psArray *sources, pmPSF *psf, psStats *sky) {
+void psphotOutput (pmReadout *readout, psMetadata *config) {
 
     bool status;
 
     psTimerStart ("psphot");
+
+    psMetadata *header = pmReadoutGetHeader (readout);
+
+    psArray *sources = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.SOURCES");
+    pmPSF *psf = psMetadataLookupPtr (&status, readout->analysis, "PSPHOT.PSF");
 
     char *outputMode = psMetadataLookupPtr (&status, config, "OUTPUT_MODE");
@@ -29,24 +34,24 @@
 	return;
     }
+    if (!strcasecmp (outputMode, "SX")) {
+	pmSourcesWriteSX (sources, outputFile);
+	return;
+    }
     if (!strcasecmp (outputMode, "OBJ")) {
-	pmSourcesWriteOBJ (readout, config, outputFile, sources, psf, sky);
+	pmSourcesWriteOBJ (sources, outputFile);
 	return;
     }
-    if (!strcasecmp (outputMode, "SX")) {
-	pmSourcesWriteSX (readout, config, outputFile, sources, psf, sky);
+    if (!strcasecmp (outputMode, "CMP")) {
+	pmSourcesWriteCMP (sources, outputFile, header);
 	return;
     }
-    if (!strcasecmp (outputMode, "CMP")) {
-	pmSourcesWriteCMP (readout, header, config, outputFile, sources, psf, sky);
+    if (!strcasecmp (outputMode, "CMF")) {
+	pmSourcesWriteCMF (sources, outputFile, header);
 	return;
     }
-    if (!strcasecmp (outputMode, "CMF")) {
-	pmSourcesWriteCMF (readout, header, config, outputFile, sources, psf, sky);
+    if (!strcasecmp (outputMode, "TEXT")) {
+	pmSourcesWriteText (sources, outputFile);
 	return;
     }
-    if (!strcasecmp (outputMode, "TEXT")) {
-	pmSourcesWriteText (readout, config, outputFile, sources, psf, sky);
-	return;
-    }
 
     psAbort ("psphot", "unknown output mode %s", outputMode);
@@ -54,11 +59,9 @@
 
 // dophot-style output list with fixed line width
-bool pmSourcesWriteOBJ (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
+bool pmSourcesWriteOBJ (psArray *sources, char *filename) {
 
     int type;
-    pmModel *model;
     psF32 *PAR, *dPAR;
     float dmag, apResid;
-    bool status;
 
     psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
@@ -69,12 +72,9 @@
 	return false;
     }
-
-    float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
 
     // write sources with models 
     for (int i = 0; i < sources->n; i++) {
 	pmSource *source = (pmSource *) sources->data[i];
-
-	model = pmSourceMagnitudes (source, psf, RADIUS);
+	pmModel *model = pmModelSelect (source);
 	if (model == NULL) continue;
 
@@ -106,10 +106,8 @@
 
 // elixir-mode / sextractor-style output list with fixed line width
-bool pmSourcesWriteSX (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
-
-    pmModel *model;
+bool pmSourcesWriteSX (psArray *sources, char *filename) {
+
     psF32 *PAR, *dPAR;
     float dmag;
-    bool status;
 
     psLine *line = psLineAlloc (110);  // 110 is sextractor line length
@@ -120,12 +118,9 @@
 	return false;
     }
-
-    float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
 
     // write sources with models 
     for (int i = 0; i < sources->n; i++) {
 	pmSource *source = (pmSource *) sources->data[i];
-
-	model = pmSourceMagnitudes (source, psf, RADIUS);
+	pmModel *model = pmModelSelect (source);
 	if (model == NULL) continue;
 
@@ -157,8 +152,7 @@
 
 // elixir-style pseudo FITS table (header + ascii list)
-bool pmSourcesWriteCMP (pmReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
+bool pmSourcesWriteCMP (psArray *sources, char *filename, psMetadata *header) {
 
     int i, type;
-    pmModel *model;
     psMetadataItem *mdi;
     psF32 *PAR, *dPAR;
@@ -167,10 +161,8 @@
 
     // find config information for output header
-    float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
-    float ZERO_POINT = psMetadataLookupF32 (&status, config, "ZERO_POINT");
+    float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT");
     if (!status) ZERO_POINT = 25.0;
 
     // write necessary information to output header
-    psphotUpdateHeader (header, config);
     psMetadataAdd (header, PS_LIST_TAIL, "NSTARS",   PS_DATA_S32 | PS_META_REPLACE, "NUMBER OF STARS", sources->n);
 
@@ -200,6 +192,5 @@
     for (i = 0; i < sources->n; i++) {
 	pmSource *source = (pmSource *) sources->data[i];
-
-	model = pmSourceMagnitudes (source, psf, RADIUS);
+	pmModel *model = pmModelSelect (source);
 	if (model == NULL) continue;
 
@@ -232,5 +223,5 @@
 // this format consists of a header derived from the image header
 // followed by a zero-size matrix, followed by the table data
-bool pmSourcesWriteCMF (pmReadout *readout, psMetadata *header, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *skyStats) {
+bool pmSourcesWriteCMF (psArray *sources, char *filename, psMetadata *header) {
 
     psArray *table;
@@ -239,5 +230,4 @@
     psMetadata *theader;
     int i, type;
-    pmModel *model;
     psF32 *PAR, *dPAR;
     float dmag, lsky;
@@ -245,9 +235,5 @@
 
     // find config information for output header
-    float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
-    float ZERO_POINT = psMetadataLookupF32 (&status, config, "ZERO_POINT");
-
-    // write necessary information to output header
-    psphotUpdateHeader (header, config);
+    float ZERO_POINT = psMetadataLookupF32 (&status, header, "ZERO_PT");
 
     table = psArrayAlloc (sources->n);
@@ -256,6 +242,5 @@
     for (i = 0; i < sources->n; i++) {
 	pmSource *source = (pmSource *) sources->data[i];
-
-	model = pmSourceMagnitudes (source, psf, RADIUS);
+	pmModel *model = pmModelSelect (source);
 	if (model == NULL) continue;
 
@@ -309,10 +294,10 @@
 /***** Text Output Methods *****/
 
-bool pmSourcesWriteText (pmReadout *readout, psMetadata *config, char *filename, psArray *sources, pmPSF *psf, psStats *sky) {
+bool pmSourcesWriteText (psArray *sources, char *filename) {
 
     char *name = (char *) psAlloc (strlen(filename) + 10);
 
     sprintf (name, "%s.psf.dat", filename);
-    pmModelWritePSFs (sources, config, name, psf);
+    pmModelWritePSFs (sources, name);
 
     sprintf (name, "%s.ext.dat", filename);
@@ -330,5 +315,5 @@
 
 // write the PSF sources to an output file
-bool pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf) {
+bool pmModelWritePSFs (psArray *sources, char *filename) {
 
     double dPos, dMag;
@@ -337,7 +322,4 @@
     psF32 *PAR, *dPAR;
     pmModel  *model;
-    bool status;
-
-    float RADIUS = psMetadataLookupF32 (&status, config, "AP_RADIUS");
 
     f = fopen (filename, "w");
@@ -350,7 +332,6 @@
     for (i = 0; i < sources->n; i++) {
 	pmSource *source = (pmSource *) sources->data[i];
-
 	if (source->type != PM_SOURCE_STAR) continue;
-	model = pmSourceMagnitudes (source, psf, RADIUS);
+	model = source->modelPSF;
 	if (model == NULL) continue;
 
