Index: trunk/psphot/src/psphotOutput.c
===================================================================
--- trunk/psphot/src/psphotOutput.c	(revision 6379)
+++ trunk/psphot/src/psphotOutput.c	(revision 6481)
@@ -11,4 +11,6 @@
 static char *extNameKey = NULL;
 static char *extRoot    = NULL;
+static char *psfFile    = NULL;
+static char *psfSample  = NULL;
 
 void psphotOutputCleanup () {
@@ -21,4 +23,6 @@
     psFree (extNameKey);
     psFree (extRoot);
+    psFree (psfFile);
+    psFree (psfSample);
     return;
 }
@@ -34,4 +38,7 @@
     outputMode      = psMetadataLookupStr (&status, config->recipe, "OUTPUT_MODE");
     outputFormat    = psMetadataLookupStr (&status, config->recipe, "OUTPUT_FORMAT");
+
+    psfFile         = psMetadataLookupStr (&status, config->recipe, "PSF_OUTPUT_FILE");
+    psfSample       = psMetadataLookupStr (&status, config->recipe, "PSF_SAMPLE_FILE");
 
     // rules to construct output names
@@ -75,4 +82,7 @@
     }
 
+    // register background image-file names
+    psphotBackgroundNames (config->arguments);
+
     // save so freeing config will not drop these references
     psMemCopy (outputRoot);
@@ -83,4 +93,6 @@
     psMemCopy (extNameKey);
     psMemCopy (extRoot);
+    psMemCopy (psfFile);
+    psMemCopy (psfSample);
 
     return;
@@ -165,6 +177,4 @@
     char *outputFile;
 
-    psTimerStart ("psphot");
-
     psMetadata *header = pmReadoutGetHeader (readout);
 
@@ -180,6 +190,4 @@
     } 
 
-    char *psfFile    = psMetadataLookupStr (&status, arguments, "PSF_OUTPUT_FILE");
-    char *psfSample  = psMetadataLookupStr (&status, arguments, "PSF_SAMPLE_FILE");
     char *residImage = psMetadataLookupStr (&status, arguments, "RESID_IMAGE");
 
@@ -236,4 +244,6 @@
     psF32 *PAR, *dPAR;
     float dmag, apResid;
+
+    psTimerStart ("string");
 
     psLine *line = psLineAlloc (104);  // 104 is dophot-defined line length
@@ -274,4 +284,48 @@
     }
     fclose (f);
+    psFree (line);
+    fprintf (stderr, "%f seconds for %d objects with psLine\n", psTimerMark ("string"), (int)sources->n);
+
+    psTimerStart ("string");
+
+    f = fopen ("test.obj", "w");
+    if (f == NULL) {
+	psLogMsg ("WriteSourceOBJ", 3, "can't open output file for output %s\n", "test.obj");
+	return false;
+    }
+
+    char *string;
+    // write sources with models 
+    for (int i = 0; i < sources->n; i++) {
+	pmSource *source = (pmSource *) sources->data[i];
+	pmModel *model = pmModelSelect (source);
+	if (model == NULL) continue;
+
+	PAR = model->params->data.F32;
+	dPAR = model->dparams->data.F32;
+
+	dmag = dPAR[1] / PAR[1];
+	type = pmSourceDophotType (source);
+	apResid = source->apMag - source->fitMag;
+
+	string = NULL;
+	psStringAppend (&string, "%3d",   type);
+	psStringAppend (&string, "%8.2f", PAR[2]);
+	psStringAppend (&string, "%8.2f", PAR[3]);
+	psStringAppend (&string, "%8.3f", source->fitMag);
+	psStringAppend (&string, "%6.3f", dmag);
+	psStringAppend (&string, "%9.2f", PAR[0]);
+	psStringAppend (&string, "%9.3f", PAR[4]);
+	psStringAppend (&string, "%9.3f", PAR[5]);
+	psStringAppend (&string, "%7.2f", PAR[6]);
+	psStringAppend (&string, "%8.3f", 99.999);
+	psStringAppend (&string, "%8.3f", source->apMag);
+	psStringAppend (&string, "%8.2f\n", apResid);
+	fwrite (string, 1, strlen(string), f);
+	psFree (string);
+    }
+    fclose (f);
+    fprintf (stderr, "%f seconds for %d objects with psString\n", psTimerMark ("string"), (int)sources->n);
+
     return true;
 }
@@ -501,5 +555,5 @@
     }
 
-   // write sources with models first 
+    // write sources with models first 
     for (i = 0; i < sources->n; i++) {
 	pmSource *source = (pmSource *) sources->data[i];
@@ -525,5 +579,5 @@
 	    fprintf (f, "%9.6f ", dPAR[j]);
 	}
-	fprintf (f, ": %7.4f %2d %#5x %7.3f %7.1f %7.2f %4d %2d\n", 
+	fprintf (f, ": %8.4f %2d %#5x %7.3f %7.1f %7.2f %4d %2d\n", 
 		 source[0].apMag, source[0].type, source[0].mode, 
 		 log10(model[0].chisq/model[0].nDOF), 
@@ -617,7 +671,7 @@
 	    
 	if (source->moments == NULL) {
-	  moment = empty;
+	    moment = empty;
 	} else {
-	  moment = source->moments;
+	    moment = source->moments;
 	}
 
