Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 24789)
+++ /trunk/psLib/src/math/psStats.c	(revision 24790)
@@ -128,4 +128,17 @@
         RESULT = Xt; }
 
+# define COUNT_WARNING(LIMIT, INTERVAL, ...) { \
+	static int nCalls = 1; \
+	if (nCalls < LIMIT) { \
+	    psWarning(__VA_ARGS__); \
+	} \
+	if (!(nCalls % INTERVAL)) { \
+	    psWarning(__VA_ARGS__); \
+            psWarning("(warning raised %d times)", nCalls); \
+	} \
+	nCalls ++; \
+}
+ 
+
 /*****************************************************************************/
 /* TYPE DEFINITIONS                                                          */
@@ -331,5 +344,5 @@
 
     if (count == 0) {
-        psLogMsg(TRACE, PS_LOG_DETAIL, "No valid data in input vector.\n");
+        COUNT_WARNING(10, 100, "No valid data in input vector.\n");
         stats->sampleUQ = NAN;
         stats->sampleLQ = NAN;
@@ -394,5 +407,5 @@
     // If the mean is NAN, then generate a warning and set the stdev to NAN.
     if (isnan(stats->sampleMean)) {
-        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): sample mean is NAN. Setting stats->sampleStdev = NAN.\n");
+	COUNT_WARNING(10, 100, "WARNING: vectorSampleStdev(): sample mean is NAN. Setting stats->sampleStdev = NAN.");
         stats->sampleStdev = NAN;
         return true;
@@ -438,11 +451,10 @@
         // Assume that the user knows what he's doing when he masks out everything --> no error.
         stats->sampleStdev = NAN;
-        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): no valid psVector elements (%ld). Setting stats->sampleStdev = NAN.\n", count);
+        COUNT_WARNING(10, 100, "WARNING: vectorSampleStdev(): no valid psVector elements (%ld). Setting stats->sampleStdev = NAN.\n", count);
         return true;
     }
     if (count == 1) {
         stats->sampleStdev = 0.0;
-        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): only one valid psVector elements (%ld).  "
-                "Setting stats->sampleStdev = 0.0.\n", count);
+        COUNT_WARNING(10, 100, "WARNING: vectorSampleStdev(): only one valid psVector elements (%ld). Setting stats->sampleStdev = 0.0.\n", count);
         return true;
     }
@@ -468,5 +480,5 @@
     }
     if (isnan(stats->sampleMean)) {
-        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleMoments(): sample mean is NAN.\n");
+        COUNT_WARNING(10, 100, "WARNING: vectorSampleMoments(): sample mean is NAN.\n");
         goto SAMPLE_MOMENTS_BAD;
     }
@@ -475,5 +487,5 @@
     }
     if (isnan(stats->sampleStdev) || stats->sampleStdev == 0.0) {
-        psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleMoments(): sample stdev is NAN or 0.\n");
+        COUNT_WARNING(10, 100, "WARNING: vectorSampleMoments(): sample stdev is NAN or 0.\n");
         goto SAMPLE_MOMENTS_BAD;
     }
@@ -583,5 +595,5 @@
     vectorSampleMedian(myVector, tmpMask, maskVal, stats);
     if (isnan(stats->sampleMedian)) {
-        psLogMsg(TRACE, PS_LOG_DETAIL, "Call to vectorSampleMedian returned NAN\n");
+        COUNT_WARNING(10, 100, "Call to vectorSampleMedian returned NAN\n");
         return true;
     }
@@ -591,5 +603,5 @@
     vectorSampleStdev(myVector, errors, tmpMask, maskVal, stats);
     if (isnan(stats->sampleStdev)) {
-        psLogMsg(TRACE, PS_LOG_DETAIL, "Call to vectorSampleStdev returned NAN\n");
+        COUNT_WARNING(10, 100, "Call to vectorSampleStdev returned NAN\n");
         return true;
     }
@@ -649,5 +661,5 @@
         if (isnan(stats->sampleMean) || isnan(stats->sampleStdev)) {
             iter = stats->clipIter;
-            psLogMsg(TRACE, PS_LOG_DETAIL, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n");
+            COUNT_WARNING(10, 100, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n");
             clippedMean = NAN;
             clippedStdev = NAN;
@@ -747,5 +759,5 @@
         if (numValid == 0 || isnan(min) || isnan(max)) {
             // Data range calculation failed
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
+            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             goto escape;
         }
@@ -763,5 +775,5 @@
             stats->results |= PS_STAT_ROBUST_STDEV;
             stats->results |= PS_STAT_ROBUST_QUARTILE;
-            psLogMsg(TRACE, PS_LOG_DETAIL, "All data points have the same value: %f.\n", min);
+            COUNT_WARNING(10, 100, "All data points have the same value: %f.\n", min);
             psFree(mask);
             psFree(statsMinMax);
@@ -832,5 +844,5 @@
 	// convert bin to bin value: this is the robust histogram median.
         if (isnan(stats->robustMedian)) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a quadratic and calculate the 50-percent position.\n");
+            COUNT_WARNING(10, 100, "Failed to fit a quadratic and calculate the 50-percent position.\n");
             goto escape;
         }
@@ -854,5 +866,5 @@
 
         if ((binLo < 0) || (binHi < 0)) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the 15.8655%% and 84.1345%% data points.\n");
+            COUNT_WARNING(10, 100, "Failed to calculate the 15.8655%% and 84.1345%% data points.\n");
             goto escape;
         }
@@ -950,5 +962,5 @@
                 stats->results |= PS_STAT_ROBUST_STDEV;
                 stats->results |= PS_STAT_ROBUST_QUARTILE;
-                psLogMsg(TRACE, PS_LOG_DETAIL, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
+                COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
                 psFree(mask);
                 psFree(statsMinMax);
@@ -978,5 +990,5 @@
     psF32 binHi25F32 = fitQuadraticSearchForYThenReturnBin(cumulative->bounds, cumulative->nums, binHi25, totalDataPoints * 0.75f);
     if (isnan(binLo25F32) || isnan(binHi25F32)) {
-        psLogMsg(TRACE, PS_LOG_DETAIL, "could not determine the robustUQ: fitQuadraticSearchForYThenReturnBin() returned a NAN.\n");
+        COUNT_WARNING(10, 100, "could not determine the robustUQ: fitQuadraticSearchForYThenReturnBin() returned a NAN.\n");
         goto escape;
     }
@@ -1263,5 +1275,5 @@
         float max = statsMinMax->max;
         if (numValid == 0 || isnan(min) || isnan(max)) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
+            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
             psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
@@ -1460,5 +1472,5 @@
         float max = statsMinMax->max;
         if (numValid == 0 || isnan(min) || isnan(max)) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
+            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
             psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
@@ -1508,5 +1520,5 @@
         PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
         if (binMin == binMax) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
+            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
             return true;
@@ -1756,5 +1768,5 @@
         float max = statsMinMax->max;
         if (numValid == 0 || isnan(min) || isnan(max)) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
+            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
 	    stats->fittedStdev = NAN;
@@ -1774,5 +1786,5 @@
         psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers)
         if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Unable to generate histogram for fitted statistics v4.\n");
+            COUNT_WARNING(10, 100, "Unable to generate histogram for fitted statistics v4.\n");
             psFree(histogram);
             psFree(statsMinMax);
@@ -1809,5 +1821,5 @@
         PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
         if (binMin == binMax) {
-            psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
+            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
             psFree(statsMinMax);
 	    stats->fittedStdev = NAN;
@@ -1882,5 +1894,5 @@
 
             if (!status) {
-                psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a gaussian to the robust histogram.\n");
+                COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
                 psFree(poly);
                 psFree(histogram);
@@ -1892,5 +1904,5 @@
 
             if (poly->coeff[2] >= 0.0) {
-                psLogMsg(TRACE, PS_LOG_MINUTIA, "Failed parabolic fit: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]);
+                COUNT_WARNING(10, 100, "Failed parabolic fit: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]);
                 psFree(poly);
                 psFree(histogram);
@@ -1906,5 +1918,5 @@
                 }
 
-                psLogMsg(TRACE, PS_LOG_DETAIL, "fit did not converge\n");
+                COUNT_WARNING(10, 100, "fit did not converge\n");
 		stats->fittedStdev = NAN;
 		stats->fittedStdev = NAN;
@@ -1975,5 +1987,5 @@
 
             if (!status) {
-                psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a gaussian to the robust histogram.\n");
+                COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
                 psFree(poly);
                 psFree(histogram);
