Index: /branches/eam_branches/ipp-20140423/psModules/src/extras/pmVisual.c
===================================================================
--- /branches/eam_branches/ipp-20140423/psModules/src/extras/pmVisual.c	(revision 36815)
+++ /branches/eam_branches/ipp-20140423/psModules/src/extras/pmVisual.c	(revision 36816)
@@ -162,4 +162,77 @@
 
 
+// ask the user to continue or not.  give up after 2 seconds.
+bool pmVisualAskUserOrDump(bool *plotFlag, bool *dumpData)
+{
+    struct timeval timeout;
+    fd_set fdSet;
+    int status;
+
+    if (dumpData) *dumpData = false;
+
+    char key[10];
+    if (plotFlag && dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [d]ump the data? [a]bort all visual plots? (c) ");
+    } 
+    if (plotFlag && !dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots? (c) ");
+    } 
+    if (!plotFlag && dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [d]ump the data? [a]bort all visual plots? (c) ");
+    } 
+    if (!plotFlag && !dumpData) {
+	fprintf (stderr, "[p]ause? [c]ontinue? [a]bort all visual plots? (c) ");
+    }
+
+    /* Wait up to 1.0 second for a response, then continue */
+    timeout.tv_sec = 10;
+    timeout.tv_usec = 0;
+
+    FD_ZERO (&fdSet);
+    FD_SET (STDIN_FILENO, &fdSet);
+
+    status = select (1, &fdSet, NULL, NULL, &timeout);
+    if (status <= 0) {
+	fprintf (stderr, "\n");
+	return true; // if no data, give up
+    }
+
+    while (true) {
+	if (!fgets(key, 8, stdin)) {
+	    psWarning("Unable to read option");
+	}
+	switch (key[0]) {
+	  case 's':
+	    if (plotFlag) *plotFlag = false;
+	    return true;
+	  case 'd':
+	    if (dumpData) *dumpData = true;
+	    return true;
+	  case 'a':
+	    isVisual = false;
+	    return true;
+	  case 'c':
+	  case '\n':
+	    return true;
+	  default:
+	    break;
+	}
+	
+	if (plotFlag && dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [d]ump the data? [a]bort all visual plots? (c) ");
+	} 
+	if (plotFlag && !dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [s]kip the rest of these plots? [a]bort all visual plots? (c) ");
+	} 
+	if (!plotFlag && dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [d]ump the data? [a]bort all visual plots? (c) ");
+	} 
+	if (!plotFlag && !dumpData) {
+	  fprintf (stderr, "[p]ause? [c]ontinue? [a]bort all visual plots? (c) ");
+	}
+    }
+    return true;
+}
+
 bool pmVisualImStats(psImage *image, double *mean, double *stdev, double *min, double *max) {
 
Index: /branches/eam_branches/ipp-20140423/psModules/src/extras/pmVisual.h
===================================================================
--- /branches/eam_branches/ipp-20140423/psModules/src/extras/pmVisual.h	(revision 36815)
+++ /branches/eam_branches/ipp-20140423/psModules/src/extras/pmVisual.h	(revision 36816)
@@ -52,4 +52,12 @@
  */
 bool pmVisualAskUser(bool *plotFlag);
+
+
+/** Ask the user how to proceed.
+ * At the user's request, this will disable diagnostic plotting.
+ * @param plotFlag, set to false if this plot should be disabled in the future
+ * @param dumpData, set to true if user requests a data dump
+ */
+bool pmVisualAskUserOrDump(bool *plotFlag, bool *dumpData);
 
 
@@ -138,4 +146,5 @@
 bool pmVisualInitGraph (int kapa, void *section, void *graphdata);
 bool pmVisualAskUser(bool *plotFlag);
+bool pmVisualAskUserOrDump(bool *plotFlag, bool *dumpData);
 bool pmVisualScaleImage(int kapaFD, psImage *inImage,
                         const char *name, int channel, bool clip);
Index: /branches/eam_branches/ipp-20140423/psModules/src/objects/pmPSFtryMakePSF.c
===================================================================
--- /branches/eam_branches/ipp-20140423/psModules/src/objects/pmPSFtryMakePSF.c	(revision 36815)
+++ /branches/eam_branches/ipp-20140423/psModules/src/objects/pmPSFtryMakePSF.c	(revision 36816)
@@ -220,4 +220,26 @@
     }
 
+    // weed out extreme e0 outliers here: find the median and exclude points not in the
+    // range MEDIAN / 5 < e0 < 5 * MEDIAN
+    { 
+      psStats *e0stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
+      if (psVectorStats (e0stats, e0, NULL, srcMask, 0xff)) {
+	float e0med = e0stats->sampleMedian;
+    
+	for (int i = 0; i < sources->n; i++) {
+	  // skip any masked sources (failed to fit one of the model steps or get a magnitude)
+	  if (srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i]) continue;
+
+	  if (e0->data.F32[i] < 0.2*e0med) {
+	    srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_OUTLIER;
+	  }
+	  if (e0->data.F32[i] > 5.0*e0med) {
+	    srcMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = PSFTRY_MASK_OUTLIER;
+	  }
+	}
+      }
+      psFree (e0stats);
+    }
+
     // we run 'clipIter' cycles clipping in each of x and y, with only one iteration each.
     // This way, the parameters masked by one of the fits will be applied to the others
Index: /branches/eam_branches/ipp-20140423/psModules/src/objects/pmSourceVisual.c
===================================================================
--- /branches/eam_branches/ipp-20140423/psModules/src/objects/pmSourceVisual.c	(revision 36815)
+++ /branches/eam_branches/ipp-20140423/psModules/src/objects/pmSourceVisual.c	(revision 36816)
@@ -545,7 +545,31 @@
     psFree (model);
 
+    bool dumpData = false;
+
     // pause and wait for user input:
     // continue, save (provide name), ??
-    pmVisualAskUser(&plotPSF);
+retry:
+    pmVisualAskUserOrDump(&plotPSF, &dumpData);
+    if (dumpData) {
+      char name[128];
+      fprintf (stderr, "filename: ");
+      int status = fscanf (stdin, "%127s", name);
+      if (status != 1) {
+	fprintf (stderr, "odd response\n");
+	goto retry;
+      }
+
+      FILE *f = fopen (name, "w");
+      if (!f) {
+	fprintf (stderr, "cannot open %s for output\n", name);
+	goto retry;
+      }
+      for (int i = 0; i < x->n; i++) {
+        float vModel = pmTrend2DEval (trend, x->data.F32[i], y->data.F32[i]);
+	fprintf (f, "%f %f %f %f %d\n", x->data.F32[i], y->data.F32[i], param->data.F32[i], vModel, mask->data.PS_TYPE_VECTOR_MASK_DATA[i]);
+      }
+      fclose (f);
+      goto retry;
+    }
 
     return true;
