Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 7163)
+++ /trunk/psLib/src/math/psStats.c	(revision 7164)
@@ -16,6 +16,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.173 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-18 03:10:06 $
+ *  @version $Revision: 1.174 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-05-22 22:46:12 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -832,7 +832,8 @@
 
     // 5. Repeat N (stats->clipIter) times:
-    long numClipped = LONG_MAX;         // Number of values clipped in this iteration
-    for (int iter = 0; iter < stats->clipIter && numClipped > 0; iter++) {
-        numClipped = 0;
+    long numClipped = 0;                // Number of values clipped
+    bool clipped = true;                // Have we clipped anything in this iteration
+    for (int iter = 0; iter < stats->clipIter && clipped; iter++) {
+        clipped = false;
         psTrace(__func__, 6, "------------ Iteration %d ------------\n", iter);
         // a) Exclude all values x_i for which |x_i - x| > K * stdev
@@ -844,4 +845,5 @@
                             myVector->data.F32[j], errors->data.F32[j]);
                     numClipped++;
+                    clipped = true;
                 }
             }
@@ -852,4 +854,5 @@
                     psTrace(__func__, 10, "Clipped %d: %f\n", j, myVector->data.F32[j]);
                     numClipped++;
+                    clipped = true;
                 }
             }
@@ -875,4 +878,7 @@
         }
     }
+
+    // Number of values used in calculation is the total number of data values, minus those we clipped
+    stats->clippedNvalues = myVector->n - numClipped;
 
     // 7. The last calcuated value of x is the clipped mean.
