Index: trunk/psphot/src/choose_psf_model.c
===================================================================
--- trunk/psphot/src/choose_psf_model.c	(revision 4251)
+++ trunk/psphot/src/choose_psf_model.c	(revision 4375)
@@ -3,5 +3,5 @@
 // test PSF models and select best option
 
-pmPSF *choose_psf_model (psMetadata *config, psArray *sources) 
+pmPSF *choose_psf_model (psMetadata *config, psArray *sources, psStats *skystats) 
 { 
     bool        status;
@@ -34,4 +34,25 @@
 	modelName = psMetadataLookupPtr (&status, config, key);
 	tests->data[i] = pmPSF_TestModel (stars, modelName, RADIUS);
+
+	// dump psf test data to file:
+	{
+	  sprintf (key, "metric.%d.dat", i);
+	  FILE *f = fopen (key, "w");
+	  test = tests->data[i];
+
+
+	  for (int j = 0; j < test->sources->n; j++) {
+	    psSource *source = test->sources->data[j];
+	    psModel  *model  = test->modelPSF->data[j];	    
+	    float sky = 0;
+
+	    if (model != NULL) sky = model->params->data.F32[0];
+
+	    fprintf (f, "%3d %6.1f %6.1f  %7.4f %7.4f  %8.4f\n", 
+		     j, source->moments->x, source->moments->y,
+		     test->metric->data.F64[j], test->fitMag->data.F64[j], sky);
+	  }
+	  fclose (f);
+	}
     }
 
@@ -40,8 +61,8 @@
     test = tests->data[0];
     int   bestN = 0;
-    float bestM = test->metricStats->clippedStdev;
+    float bestM = test->dApResid;
     for (int i = 1; i < Ntest; i++) {
 	test = tests->data[i];
-	int M = test->metricStats->clippedStdev;
+	int M = test->dApResid;
 	if (M < bestM) {
 	    bestM = M;
@@ -51,5 +72,5 @@
     test = tests->data[bestN];
     modelName = psModelGetType (test->modelType);
-    psLogMsg ("psphot.pspsf", 3, "selected psf model %s, metric: %f +/- %f\n", modelName, test->metricStats->clippedMean, test->metricStats->clippedStdev);
+    psLogMsg ("psphot.pspsf", 3, "selected psf model %s, ApResid: %f +/- %f\n", modelName, test->ApResid, test->dApResid);
 
     // set source->model based on best psf model fit
