Index: trunk/psphot/src/pmPSFtry.c
===================================================================
--- trunk/psphot/src/pmPSFtry.c	(revision 5058)
+++ trunk/psphot/src/pmPSFtry.c	(revision 5068)
@@ -183,4 +183,8 @@
   //   we use an outlier rejection to avoid this bias
 
+  FILE *f;
+  f = fopen ("apresid.dat", "w");
+  if (f == NULL) psAbort ("pmPSFtry", "can't open output file");
+
   // rflux = ten(0.4*fitMag);
   psVector *rflux = psVectorAlloc (try->sources->n, PS_TYPE_F64);
@@ -188,5 +192,7 @@
     if (try->mask->data.U8[i] & PSFTRY_MASK_ALL) continue;
     rflux->data.F64[i] = pow(10.0, 0.4*try->fitMag->data.F64[i]);
+    fprintf (f, "%3d %8.4f %12.5e %8.4f\n", i, try->fitMag->data.F64[i], rflux->data.F64[i], try->metric->data.F64[i]);
   }
+  fclose (f);
 
   // find min and max of (1/flux):
@@ -236,10 +242,4 @@
     // measure statistics only on upper 50% of points
     // this would be easier if we could sort in reverse:
-    //
-    // psVectorSort (tmp, tmp);
-    // tmp->n = 0.5*tmp->n;
-    // stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
-    // psVectorStats (stats, tmp, NULL, NULL, 0);
-    // psTrace ("psphot.metricmodel", 4, "rfBin %d (%g): %d pts, %g\n", i, rfBin->data.F64[i], tmp->n, stats->sampleMedian);
 
     psVectorSort (tmp, tmp);
@@ -267,5 +267,8 @@
 
   // XXX EAM : this is the intended API (cycle 7? cycle 8?) 
-  poly = VectorFitPolynomial1D_EAM (poly, maskB, 1, daBin, NULL, rfBin);
+  psStats *fitstat = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
+  poly = VectorClipFitPolynomial1D_EAM (poly, fitstat, maskB, 1, daBin, NULL, rfBin);
+
+  // poly = VectorFitPolynomial1D_EAM (poly, maskB, 1, daBin, NULL, rfBin);
 
   // XXX EAM : replace this when the above version is implemented
@@ -290,4 +293,5 @@
   psFree (poly);
   psFree (stats);
+  psFree (fitstat);
 
   return true;
