Index: trunk/psphot/src/psphotOutput.c
===================================================================
--- trunk/psphot/src/psphotOutput.c	(revision 5772)
+++ trunk/psphot/src/psphotOutput.c	(revision 5773)
@@ -367,5 +367,5 @@
 }
 
-// dump the sources to an output file
+// write the PSF sources to an output file
 bool pmModelWritePSFs (psArray *sources, psMetadata *config, char *filename, pmPSF *psf) {
 
@@ -389,10 +389,9 @@
 	pmSource *source = (pmSource *) sources->data[i];
 
-	// write out sources fitted as PSFs
 	if (source->type != PM_SOURCE_STAR) continue;
-	if (source->mode & PM_SOURCE_FAIL) continue;
-	if (source->mode & PM_SOURCE_POOR) continue;
-
-	model = pmSourceMagnitudes (source, psf, RADIUS);
+	// if (source->mode & PM_SOURCE_FAIL) continue;
+	// if (source->mode & PM_SOURCE_POOR) continue;
+
+	model = pmSourceMagnitudes (source, psf, RADIUS, true);
 	if (model == NULL) continue;
 
@@ -400,4 +399,5 @@
 	dPAR = model->dparams->data.F32;
 	
+	// dP is positional error
 	dP = 0;
 	dP += PS_SQR(dPAR[2]);
@@ -410,13 +410,13 @@
 		 PAR[2], PAR[3], PAR[0], source->fitMag, dmag, dP);
 
-	for (j = 0; j < model->params->n - 4; j++) {
-	    fprintf (f, "%9.6f ", PAR[j+4]);
+	for (j = 4; j < model->params->n; j++) {
+	    fprintf (f, "%9.6f ", PAR[j]);
 	}
 	fprintf (f, " : ");
-	for (j = 0; j < model->params->n - 4; j++) {
-	    fprintf (f, "%9.6f ", dPAR[j+4]);
+	for (j = 4; j < model->params->n; j++) {
+	    fprintf (f, "%9.6f ", dPAR[j]);
 	}
-	fprintf (f, ": %2d %7.3f %7.3f %7.2f %4d %2d\n", 
-		 source[0].type, 
+	fprintf (f, ": %2d %2d %7.3f %7.3f %7.2f %4d %2d\n", 
+		 source[0].type, source[0].mode, 
 		 log10(model[0].chisq/model[0].nDOF), 
 		 source[0].moments->SN, 
@@ -448,38 +448,38 @@
     for (i = 0; i < sources->n; i++) {
 	pmSource *source = (pmSource *) sources->data[i];
-	model = (pmModel  *) source->modelFLT;
+
+	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->type != PM_SOURCE_GALAXY) continue;
-	if (source->mode & PM_SOURCE_FAIL) continue;
-	if (source->mode & PM_SOURCE_POOR) continue;
+
+	PAR  = model->params->data.F32;
+	dPAR = model->dparams->data.F32;
 	
-	params = model->params;
-	dparams = model->dparams;
-
-	// XXX these are hardwired for SGAUSS : this should be pushed into the
-	// model functions as an abstract function 
+	// dP is shape error
+	// XXX these are hardwired for SGAUSS
 	dP = 0;
-	dP += PS_SQR(dparams[0].data.F32[4] / params[0].data.F32[4]);
-	dP += PS_SQR(dparams[0].data.F32[5] / params[0].data.F32[5]);
-	dP += PS_SQR(dparams[0].data.F32[7] / params[0].data.F32[7]);
+	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  ", 
-		 params[0].data.F32[2], 
-		 params[0].data.F32[3], 
-		 params[0].data.F32[0], 
-		 -2.5*log10(params[0].data.F32[1]), 
-		 (dparams[0].data.F32[1]/params[0].data.F32[1]),
-		 dP);
+		 PAR[2], PAR[3], PAR[0], source->fitMag, dmag, dP);
 
 	for (j = 4; j < model->params->n; j++) {
-	    fprintf (f, "%9.6f ", params[0].data.F32[j]);
+	    fprintf (f, "%9.6f ", PAR[j]);
 	}
 	fprintf (f, " : ");
 	for (j = 4; j < model->params->n; j++) {
-	    fprintf (f, "%9.6f ", dparams[0].data.F32[j]);
+	    fprintf (f, "%9.6f ", dPAR[j]);
 	}
-	fprintf (f, ": %2d %7.3f %7.3f %7.2f %4d %2d\n", 
-		 source[0].type, log10(model[0].chisq/model[0].nDOF), 
+	fprintf (f, ": %2d %2d %7.3f %7.3f %7.2f %4d %2d\n", 
+		 source[0].type, source[0].mode,
+		 log10(model[0].chisq/model[0].nDOF), 
 		 source[0].moments->SN, 
 		 model[0].radius, 
@@ -497,4 +497,6 @@
     int i;
     FILE *f;
+    pmMoments *moment = NULL;
+    pmSource *source = NULL;
 
     f = fopen (filename, "w");
@@ -508,37 +510,23 @@
     // write sources with models first 
     for (i = 0; i < sources->n; i++) {
-	pmSource *source = (pmSource *) sources->data[i];
+	source = sources->data[i];
 
 	// skip these sources (in PSF or FLT)
-	if (source->type == PM_SOURCE_STAR) {
-	    if (source->mode & PM_SOURCE_FAIL) goto isNULL;
-	    if (source->mode & PM_SOURCE_POOR) goto isNULL;
-	    continue;
+	if (source->type == PM_SOURCE_STAR) continue;
+	if (source->type == PM_SOURCE_GALAXY) continue;
+	    
+	if (source->moments == NULL) {
+	  moment = empty;
+	} else {
+	  moment = source->moments;
 	}
-	if (source->type == PM_SOURCE_GALAXY) {
-	    if (source->mode & PM_SOURCE_FAIL) goto isNULL;
-	    if (source->mode & PM_SOURCE_POOR) goto isNULL;
-	    continue;
-	}
-	    
-    isNULL:
-	
-	if (source->moments == NULL) {
-	  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", 
-		   source->peak->x, source->peak->y, source->peak->counts, 
-		   empty->x, empty->y, 
-		   empty->Sx, empty->Sy, 
-		   empty->Sum, empty->Peak, 
-		   empty->Sky, empty->SN, 
-		   empty->nPixels, source->type); 
-	} else {
-	  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", 
-		   source->peak->x, source->peak->y, source->peak->counts, 
-		   source->moments->x, source->moments->y, 
-		   source->moments->Sx, source->moments->Sy, 
-		   source->moments->Sum, source->moments->Peak, 
-		   source->moments->Sky, source->moments->SN, 
-		   source->moments->nPixels, source->type); 
-	}
+
+	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", 
+		 source->peak->x, source->peak->y, source->peak->counts, 
+		 source->moments->x, source->moments->y, 
+		 source->moments->Sx, source->moments->Sy, 
+		 source->moments->Sum, source->moments->Peak, 
+		 source->moments->Sky, source->moments->SN, 
+		 source->moments->nPixels, source->type); 
     }
     fclose (f);
@@ -552,5 +540,5 @@
     int i;
     FILE *f;
-    pmSource *source;
+    pmSource *source = NULL;
 
     f = fopen (filename, "w");
@@ -561,5 +549,5 @@
 
     for (i = 0; i < sources->n; i++) {
-        source = (pmSource *) sources->data[i];
+        source = sources->data[i];
         if (source->moments == NULL)
             continue;
