Index: trunk/psphot/src/psphotOutput.c
===================================================================
--- trunk/psphot/src/psphotOutput.c	(revision 5773)
+++ trunk/psphot/src/psphotOutput.c	(revision 5802)
@@ -370,5 +370,5 @@
 bool pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf) {
 
-    double dP, dmag;
+    double dPos, dMag;
     int i, j;
     FILE *f;
@@ -393,5 +393,5 @@
 	// if (source->mode & PM_SOURCE_POOR) continue;
 
-	model = pmSourceMagnitudes (source, psf, RADIUS, true);
+	model = pmSourceMagnitudes (source, psf, RADIUS);
 	if (model == NULL) continue;
 
@@ -399,14 +399,10 @@
 	dPAR = model->dparams->data.F32;
 	
-	// dP is positional error
-	dP = 0;
-	dP += PS_SQR(dPAR[2]);
-	dP += PS_SQR(dPAR[3]);
-	dP = sqrt (dP);
-	
-	dmag = dPAR[1] / PAR[1];
-
-	fprintf (f, "%7.1f %7.1f  %5.1f %7.4f  %7.4f %7.4f  ", 
-		 PAR[2], PAR[3], PAR[0], source->fitMag, dmag, dP);
+	// dPos is positional error, dMag is mag error
+	dPos = hypot (dPAR[2], dPAR[3]);
+	dMag = dPAR[1] / PAR[1];
+
+	fprintf (f, "%7.1f %7.1f  %5.1f %8.4f  %7.4f %7.4f  ", 
+		 PAR[2], PAR[3], PAR[0], source->fitMag, dMag, dPos);
 
 	for (j = 4; j < model->params->n; j++) {
@@ -417,5 +413,5 @@
 	    fprintf (f, "%9.6f ", dPAR[j]);
 	}
-	fprintf (f, ": %2d %2d %7.3f %7.3f %7.2f %4d %2d\n", 
+	fprintf (f, ": %2d %#5x %7.3f %7.1f %7.2f %4d %2d\n", 
 		 source[0].type, source[0].mode, 
 		 log10(model[0].chisq/model[0].nDOF), 
@@ -432,9 +428,8 @@
 bool pmModelWriteFLTs (psArray *sources, char *filename) {
 
-    double dP;
+    double dPos, dMag;
     int i, j;
     FILE *f;
-    psVector *params;
-    psVector *dparams;
+    psF32 *PAR, *dPAR;
     pmModel  *model;
 
@@ -450,25 +445,22 @@
 
 	if (source->type != PM_SOURCE_GALAXY) continue;
-	// if (source->mode & PM_SOURCE_FAIL) continue;
-	// if (source->mode & PM_SOURCE_POOR) continue;
 	
-	model = pmSourceMagnitudes (source->modelFLT, NULL, model->radius);
-	if (model == NULL) continue;
+	if (source->modelFLT == NULL) continue;
+	model = pmSourceMagnitudes (source, NULL, source->modelFLT->radius);
 
 	PAR  = model->params->data.F32;
 	dPAR = model->dparams->data.F32;
 	
-	// dP is shape error
+	// dPos is shape error
 	// XXX these are hardwired for SGAUSS
-	dP = 0;
-	dP += PS_SQR(dPAR[4] / PAR[4]);
-	dP += PS_SQR(dPAR[5] / PAR[5]);
-	dP += PS_SQR(dPAR[7] / PAR[7]);
-	dP = sqrt (dP);
-
-	dmag = dPAR[1] / PAR[1];
-
-	fprintf (f, "%7.1f %7.1f  %5.1f %7.3f  %7.4f %7.4f  ", 
-		 PAR[2], PAR[3], PAR[0], source->fitMag, dmag, dP);
+	dPos = 0;
+	dPos += PS_SQR(dPAR[4] / PAR[4]);
+	dPos += PS_SQR(dPAR[5] / PAR[5]);
+	// dPos += PS_SQR(dPAR[7] / PAR[7]);
+	dPos = sqrt (dPos);
+	dMag = dPAR[1] / PAR[1];
+
+	fprintf (f, "%7.1f %7.1f  %7.1f %7.3f  %7.4f %7.4f  ", 
+		 PAR[2], PAR[3], PAR[0], source->fitMag, dMag, dPos);
 
 	for (j = 4; j < model->params->n; j++) {
@@ -479,5 +471,5 @@
 	    fprintf (f, "%9.6f ", dPAR[j]);
 	}
-	fprintf (f, ": %2d %2d %7.3f %7.3f %7.2f %4d %2d\n", 
+	fprintf (f, ": %2d %#5x %7.3f %7.1f %7.2f %4d %2d\n", 
 		 source[0].type, source[0].mode,
 		 log10(model[0].chisq/model[0].nDOF), 
@@ -548,9 +540,10 @@
     }
 
+    fprintf (stderr, "writing out moments\n");
     for (i = 0; i < sources->n; i++) {
         source = sources->data[i];
         if (source->moments == NULL)
             continue;
-        fprintf (f, "%5d %5d  %7.1f  %7.1f %7.1f  %6.3f %6.3f  %8.1f %7.1f %7.1f %7.1f  %4d %2d\n",
+        fprintf (f, "%5d %5d  %7.1f  %7.1f %7.1f  %6.3f %6.3f  %10.1f %7.1f %7.1f %7.1f  %4d %2d %#5x\n",
                  source->peak->x, source->peak->y, source->peak->counts,
                  source->moments->x, source->moments->y,
@@ -558,5 +551,5 @@
                  source->moments->Sum, source->moments->Peak,
                  source->moments->Sky, source->moments->SN,
-                 source->moments->nPixels, source->type);
+                 source->moments->nPixels, source->type, source->mode);
     }
     fclose (f);
@@ -599,5 +592,6 @@
 
     psRegion region = {x - dx, x + dx, y - dy, y + dy};
-    psImage *sample = psImageSubset (image, region);
+    psImage *view = psImageSubset (image, region);
+    psImage *sample = psImageCopy (NULL, view, PS_TYPE_F32);
     psImageInit (sample, 0);
     modelFLT->params->data.F32[2] = x;
@@ -635,2 +629,17 @@
     return (TRUE);
 }
+
+bool psphotDumpMoments (psMetadata *config, psArray *sources) {
+
+    bool status;
+
+    // optional dump of all rough source data
+    char *output = psMetadataLookupPtr (&status, config, "MOMENTS_OUTPUT_FILE");
+    if (!status) return false;
+    if (output == NULL) return false;
+    if (output[0] == 0) return false;
+
+    pmMomentsWriteText (sources, output);
+    psFree (output);
+    return true;
+}
