Index: trunk/Ohana/src/relphot/src/setMrelCatalog.c
===================================================================
--- trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 39619)
+++ trunk/Ohana/src/relphot/src/setMrelCatalog.c	(revision 39620)
@@ -963,4 +963,43 @@
 }
 
+# if (0)
+// outlier warp measurements are driving bad mean values.  
+int magStatsByRankingClipped (StatDataSet *dataset, StatType *stats) {
+
+  liststats_init (stats);
+
+  if (dataset->Nlist == 0) return 0;
+
+  // we have a list of measurements for this Nsec value, along with errors, weights, and their rank
+  // first, sort by the rank (increasing)
+  sort_StatDataSet (dataset);
+
+  // find the values with the same minimum rank:
+  int Nranking = 0;
+  int minRank = dataset->ranking[0]; // MIN (5, result->psfData[Nsec].ranking[0]);  -- only allow rank 5 or <
+
+  int i;
+  for (i = 0; (i < dataset->Nlist) && (dataset->ranking[i] == minRank); i++, Nranking++);
+
+  // we want to measure the weighted average, but first we want to clip points which are > 3 sigma from the median
+  // since we are only allowed to clip at most 25% of the points, we need to have at least 4 points to do this clipping
+  if (Nranking > 3) {
+    // first, measure the median of the flxlist:
+    ALLOCATE (fluxes, double, Nranking);
+    for (i = 0; i < Nranking; i++) {
+      fluxes[i] = dataset->flxlist[i];
+    }
+    dsort (fluxes, Nranking);
+    int Nmidpoint = (int)(0.5*Nranking); // if Nranking is odd (e.g., 5), Nmidpoint is central bin (e.g., 2); if Nranking is even (e.g., 6), Nmidpoint is central bin + 1 (e.g., 3);
+    double medianFlux = (Nranking % 2) ? fluxes[Nmidpoint] : 0.5*(fluxes[Nmidpoint] + fluxes[Nmidpoint - 1]);
+  }
+
+  // get stats on only the first Nranking entries
+  liststats (dataset->flxlist, dataset->errlist, dataset->wgtlist, Nranking, stats);
+
+  return (Nranking);
+}
+# endif
+
 int markMeasureByRanking (StatDataSet *dataset, Measure *measure, int minrank, DVOMeasureFlags flags) {
   int i;
