IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24790


Ignore:
Timestamp:
Jul 14, 2009, 6:35:11 PM (17 years ago)
Author:
eugene
Message:

added COUNT_WARNING macro to limit the number of repeated warning messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psStats.c

    r24092 r24790  
    128128        RESULT = Xt; }
    129129
     130# define COUNT_WARNING(LIMIT, INTERVAL, ...) { \
     131        static int nCalls = 1; \
     132        if (nCalls < LIMIT) { \
     133            psWarning(__VA_ARGS__); \
     134        } \
     135        if (!(nCalls % INTERVAL)) { \
     136            psWarning(__VA_ARGS__); \
     137            psWarning("(warning raised %d times)", nCalls); \
     138        } \
     139        nCalls ++; \
     140}
     141 
     142
    130143/*****************************************************************************/
    131144/* TYPE DEFINITIONS                                                          */
     
    331344
    332345    if (count == 0) {
    333         psLogMsg(TRACE, PS_LOG_DETAIL, "No valid data in input vector.\n");
     346        COUNT_WARNING(10, 100, "No valid data in input vector.\n");
    334347        stats->sampleUQ = NAN;
    335348        stats->sampleLQ = NAN;
     
    394407    // If the mean is NAN, then generate a warning and set the stdev to NAN.
    395408    if (isnan(stats->sampleMean)) {
    396         psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): sample mean is NAN. Setting stats->sampleStdev = NAN.\n");
     409        COUNT_WARNING(10, 100, "WARNING: vectorSampleStdev(): sample mean is NAN. Setting stats->sampleStdev = NAN.");
    397410        stats->sampleStdev = NAN;
    398411        return true;
     
    438451        // Assume that the user knows what he's doing when he masks out everything --> no error.
    439452        stats->sampleStdev = NAN;
    440         psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): no valid psVector elements (%ld). Setting stats->sampleStdev = NAN.\n", count);
     453        COUNT_WARNING(10, 100, "WARNING: vectorSampleStdev(): no valid psVector elements (%ld). Setting stats->sampleStdev = NAN.\n", count);
    441454        return true;
    442455    }
    443456    if (count == 1) {
    444457        stats->sampleStdev = 0.0;
    445         psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleStdev(): only one valid psVector elements (%ld).  "
    446                 "Setting stats->sampleStdev = 0.0.\n", count);
     458        COUNT_WARNING(10, 100, "WARNING: vectorSampleStdev(): only one valid psVector elements (%ld). Setting stats->sampleStdev = 0.0.\n", count);
    447459        return true;
    448460    }
     
    468480    }
    469481    if (isnan(stats->sampleMean)) {
    470         psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleMoments(): sample mean is NAN.\n");
     482        COUNT_WARNING(10, 100, "WARNING: vectorSampleMoments(): sample mean is NAN.\n");
    471483        goto SAMPLE_MOMENTS_BAD;
    472484    }
     
    475487    }
    476488    if (isnan(stats->sampleStdev) || stats->sampleStdev == 0.0) {
    477         psLogMsg(TRACE, PS_LOG_DETAIL, "WARNING: vectorSampleMoments(): sample stdev is NAN or 0.\n");
     489        COUNT_WARNING(10, 100, "WARNING: vectorSampleMoments(): sample stdev is NAN or 0.\n");
    478490        goto SAMPLE_MOMENTS_BAD;
    479491    }
     
    583595    vectorSampleMedian(myVector, tmpMask, maskVal, stats);
    584596    if (isnan(stats->sampleMedian)) {
    585         psLogMsg(TRACE, PS_LOG_DETAIL, "Call to vectorSampleMedian returned NAN\n");
     597        COUNT_WARNING(10, 100, "Call to vectorSampleMedian returned NAN\n");
    586598        return true;
    587599    }
     
    591603    vectorSampleStdev(myVector, errors, tmpMask, maskVal, stats);
    592604    if (isnan(stats->sampleStdev)) {
    593         psLogMsg(TRACE, PS_LOG_DETAIL, "Call to vectorSampleStdev returned NAN\n");
     605        COUNT_WARNING(10, 100, "Call to vectorSampleStdev returned NAN\n");
    594606        return true;
    595607    }
     
    649661        if (isnan(stats->sampleMean) || isnan(stats->sampleStdev)) {
    650662            iter = stats->clipIter;
    651             psLogMsg(TRACE, PS_LOG_DETAIL, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n");
     663            COUNT_WARNING(10, 100, "vectorSampleMean() or vectorSampleStdev() returned a NAN.\n");
    652664            clippedMean = NAN;
    653665            clippedStdev = NAN;
     
    747759        if (numValid == 0 || isnan(min) || isnan(max)) {
    748760            // Data range calculation failed
    749             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
     761            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    750762            goto escape;
    751763        }
     
    763775            stats->results |= PS_STAT_ROBUST_STDEV;
    764776            stats->results |= PS_STAT_ROBUST_QUARTILE;
    765             psLogMsg(TRACE, PS_LOG_DETAIL, "All data points have the same value: %f.\n", min);
     777            COUNT_WARNING(10, 100, "All data points have the same value: %f.\n", min);
    766778            psFree(mask);
    767779            psFree(statsMinMax);
     
    832844        // convert bin to bin value: this is the robust histogram median.
    833845        if (isnan(stats->robustMedian)) {
    834             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a quadratic and calculate the 50-percent position.\n");
     846            COUNT_WARNING(10, 100, "Failed to fit a quadratic and calculate the 50-percent position.\n");
    835847            goto escape;
    836848        }
     
    854866
    855867        if ((binLo < 0) || (binHi < 0)) {
    856             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the 15.8655%% and 84.1345%% data points.\n");
     868            COUNT_WARNING(10, 100, "Failed to calculate the 15.8655%% and 84.1345%% data points.\n");
    857869            goto escape;
    858870        }
     
    950962                stats->results |= PS_STAT_ROBUST_STDEV;
    951963                stats->results |= PS_STAT_ROBUST_QUARTILE;
    952                 psLogMsg(TRACE, PS_LOG_DETAIL, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
     964                COUNT_WARNING(10, 100, "Maximum number of iterations (%d) exceeded.", PS_ROBUST_MAX_ITERATIONS);
    953965                psFree(mask);
    954966                psFree(statsMinMax);
     
    978990    psF32 binHi25F32 = fitQuadraticSearchForYThenReturnBin(cumulative->bounds, cumulative->nums, binHi25, totalDataPoints * 0.75f);
    979991    if (isnan(binLo25F32) || isnan(binHi25F32)) {
    980         psLogMsg(TRACE, PS_LOG_DETAIL, "could not determine the robustUQ: fitQuadraticSearchForYThenReturnBin() returned a NAN.\n");
     992        COUNT_WARNING(10, 100, "could not determine the robustUQ: fitQuadraticSearchForYThenReturnBin() returned a NAN.\n");
    981993        goto escape;
    982994    }
     
    12631275        float max = statsMinMax->max;
    12641276        if (numValid == 0 || isnan(min) || isnan(max)) {
    1265             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
     1277            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    12661278            psFree(statsMinMax);
    12671279            psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
     
    14601472        float max = statsMinMax->max;
    14611473        if (numValid == 0 || isnan(min) || isnan(max)) {
    1462             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
     1474            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    14631475            psFree(statsMinMax);
    14641476            psTrace(TRACE, 4, "---- %s(false) end  ----\n", __func__);
     
    15081520        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
    15091521        if (binMin == binMax) {
    1510             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
     1522            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    15111523            psFree(statsMinMax);
    15121524            return true;
     
    17561768        float max = statsMinMax->max;
    17571769        if (numValid == 0 || isnan(min) || isnan(max)) {
    1758             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
     1770            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    17591771            psFree(statsMinMax);
    17601772            stats->fittedStdev = NAN;
     
    17741786        psHistogram *histogram = psHistogramAlloc(min, max, numBins); // A new histogram (without outliers)
    17751787        if (!psVectorHistogram(histogram, myVector, errors, mask, maskVal)) {
    1776             psLogMsg(TRACE, PS_LOG_DETAIL, "Unable to generate histogram for fitted statistics v4.\n");
     1788            COUNT_WARNING(10, 100, "Unable to generate histogram for fitted statistics v4.\n");
    17771789            psFree(histogram);
    17781790            psFree(statsMinMax);
     
    18091821        PS_BIN_FOR_VALUE (binMax, histogram->bounds, guessMean + maxFitSigma*guessStdev, 0);
    18101822        if (binMin == binMax) {
    1811             psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to calculate the min/max of the input vector.\n");
     1823            COUNT_WARNING(10, 100, "Failed to calculate the min/max of the input vector.\n");
    18121824            psFree(statsMinMax);
    18131825            stats->fittedStdev = NAN;
     
    18821894
    18831895            if (!status) {
    1884                 psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a gaussian to the robust histogram.\n");
     1896                COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
    18851897                psFree(poly);
    18861898                psFree(histogram);
     
    18921904
    18931905            if (poly->coeff[2] >= 0.0) {
    1894                 psLogMsg(TRACE, PS_LOG_MINUTIA, "Failed parabolic fit: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]);
     1906                COUNT_WARNING(10, 100, "Failed parabolic fit: %f + %f x + %f x^2\n", poly->coeff[0], poly->coeff[1], poly->coeff[2]);
    18951907                psFree(poly);
    18961908                psFree(histogram);
     
    19061918                }
    19071919
    1908                 psLogMsg(TRACE, PS_LOG_DETAIL, "fit did not converge\n");
     1920                COUNT_WARNING(10, 100, "fit did not converge\n");
    19091921                stats->fittedStdev = NAN;
    19101922                stats->fittedStdev = NAN;
     
    19751987
    19761988            if (!status) {
    1977                 psLogMsg(TRACE, PS_LOG_DETAIL, "Failed to fit a gaussian to the robust histogram.\n");
     1989                COUNT_WARNING(10, 100, "Failed to fit a gaussian to the robust histogram.\n");
    19781990                psFree(poly);
    19791991                psFree(histogram);
Note: See TracChangeset for help on using the changeset viewer.