IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7991


Ignore:
Timestamp:
Jul 26, 2006, 5:52:15 PM (20 years ago)
Author:
Paul Price
Message:

Adding psStatsOptionFromString and psStatsOptionToString.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r7990 r7991  
    1 %%% $Id: psLibSDRS.tex,v 1.423 2006-07-26 22:10:38 price Exp $
     1%%% $Id: psLibSDRS.tex,v 1.424 2006-07-27 03:52:15 price Exp $
    22\documentclass[panstarrs,spec]{panstarrs}
    33
     
    47914791so we specify functions to convert between strings and \code{psStats}:
    47924792\begin{prototype}
     4793psStatsOptions psStatsOptionFromString(const char *string);
     4794psString psStatsOptionToString(psStatsOptions option);
    47934795psStats *psStatsFromString(const char *string);
    47944796psString psStatsToString(const psStats *stats);
    47954797\end{prototype}
     4798\code{psStatsOptionFromString} shall parse the \code{string} for a
     4799single statistics option.  The options shall be specified by their
     4800\code{psStatsOptions} enum name, without the leading \code{PS_STAT_}.
     4801In addition, \code{SAMPLE_} may be excluded for the user's
     4802convenience, and \code{ROBUST} shall refer to a \code{ROBUST_MEDIAN},
     4803\code{FITTED} to a \code{FITTED_MEAN}, and \code{CLIPPED} to a
     4804\code{CLIPPED_MEAN}.  \code{psStatsOptionToString} shall translate in
     4805the reverse direction, returning the appropriate string given the
     4806\code{option} (which may be a blend of options).
    47964807\code{psStatsFromString} shall parse the input \code{string} for
    4797 statistics options.  Multiple options may be included in the same
    4798 string, separated by spaces, commas or semi-colons.  The options shall
    4799 be specified by their \code{psStatsOptions} enum, without the leading
    4800 \code{PS_STAT_}.  In addition, \code{SAMPLE_} may be excluded for the
    4801 user's convenience, and \code{ROBUST} shall refer to a
    4802 \code{ROBUST_MEDIAN}, \code{FITTED} to a \code{FITTED_MEAN}, and
    4803 \code{CLIPPED} to a \code{CLIPPED_MEAN}.  \code{psStatsToString} shall
    4804 translate in the reverse direction.
     4808statistics options, where multiple options may be included in the same
     4809string, separated by spaces, commas or semi-colons.
     4810\code{psStatsToString} shall translate in the reverse direction.
    48054811
    48064812\begin{prototype}
  • trunk/psLib/src/math/psStats.c

    r7989 r7991  
    1616 * use ->min and ->max (PS_STAT_USE_RANGE)
    1717 *
    18  *  @version $Revision: 1.180 $ $Name: not supported by cvs2svn $
    19  *  @date $Date: 2006-07-26 22:09:48 $
     18 *  @version $Revision: 1.181 $ $Name: not supported by cvs2svn $
     19 *  @date $Date: 2006-07-27 03:51:13 $
    2020 *
    2121 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    21262126}
    21272127
    2128 psStats *psStatsFromString(const char *string)
    2129 {
    2130     psList *subStrings = psStringSplit(string, " ,;", false); // List of sub-strings
    2131     if (!subStrings || psListLength(subStrings) == 0) {
    2132         // Nothing here
    2133         psError(PS_ERR_BAD_PARAMETER_VALUE, false, "No string to parse for statistics: %s\n", string);
    2134         psFree(subStrings);
    2135         return NULL;
    2136     }
    2137     psStats *stats = psStatsAlloc(0);   // Generate empty stats structure
    2138     psListIterator *iterator = psListIteratorAlloc(subStrings, PS_LIST_HEAD, false); // Iterator
    2139     psString statString;                // Statistic string, from iteration
    2140 
     2128psStatsOptions psStatsOptionFromString(const char *string)
     2129{
    21412130    #define READ_STAT(NAME, SYMBOL) \
    2142     if (strcasecmp(statString, NAME) == 0) { \
    2143         stats->options |= SYMBOL; \
    2144     }
    2145 
    2146     while ((statString = psListGetAndIncrement(iterator))) {
    2147         // This might look a little weird if automatically formated,
    2148         // but it's legal C once the pre-processing has been done, and
    2149         // it reads a lot better than a whole heap of "if-then-else" statements.
    2150         READ_STAT("MEAN",     PS_STAT_SAMPLE_MEAN) else
    2151             READ_STAT("STDEV",    PS_STAT_SAMPLE_STDEV) else
    2152                 READ_STAT("MEDIAN",   PS_STAT_SAMPLE_MEDIAN) else
    2153                     READ_STAT("QUARTILE", PS_STAT_SAMPLE_QUARTILE) else
    2154                         READ_STAT("SAMPLE_MEAN",     PS_STAT_SAMPLE_MEAN) else
    2155                             READ_STAT("SAMPLE_STDEV",    PS_STAT_SAMPLE_STDEV) else
    2156                                 READ_STAT("SAMPLE_MEDIAN",   PS_STAT_SAMPLE_MEDIAN) else
    2157                                     READ_STAT("SAMPLE_QUARTILE", PS_STAT_SAMPLE_QUARTILE) else
    2158                                         READ_STAT("ROBUST",          PS_STAT_ROBUST_MEDIAN) else
    2159                                             READ_STAT("ROBUST_MEDIAN",   PS_STAT_ROBUST_MEDIAN) else
    2160                                                 READ_STAT("ROBUST_STDEV",    PS_STAT_ROBUST_STDEV) else
    2161                                                     READ_STAT("ROBUST_QUARTILE", PS_STAT_ROBUST_QUARTILE) else
    2162                                                         READ_STAT("FITTED",       PS_STAT_FITTED_MEAN) else
    2163                                                             READ_STAT("FITTED_MEAN",  PS_STAT_FITTED_MEAN) else
    2164                                                                 READ_STAT("FITTED_STDEV", PS_STAT_ROBUST_STDEV) else
    2165                                                                     READ_STAT("CLIPPED",       PS_STAT_CLIPPED_MEAN) else
    2166                                                                         READ_STAT("CLIPPED_MEAN",  PS_STAT_CLIPPED_MEAN) else
    2167                                                                             READ_STAT("CLIPPED_STDEV", PS_STAT_CLIPPED_STDEV) else {
    2168                                                                                 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Can't interpret string as statistic: %s\n",
    2169                                                                                         statString);
    2170                                                                                 psFree(iterator);
    2171                                                                                 psFree(subStrings);
    2172                                                                                 psFree(stats);
    2173                                                                                 return NULL;
    2174                                                                             }
    2175     }
    2176 
    2177     psFree(iterator);
    2178     psFree(subStrings);
    2179     return stats;
    2180 }
    2181 
    2182 psString psStatsToString(const psStats *stats)
     2131    if (strcasecmp(string, NAME) == 0) { \
     2132        return SYMBOL; \
     2133    }
     2134
     2135    READ_STAT("MEAN",     PS_STAT_SAMPLE_MEAN);
     2136    READ_STAT("STDEV",    PS_STAT_SAMPLE_STDEV);
     2137    READ_STAT("MEDIAN",   PS_STAT_SAMPLE_MEDIAN);
     2138    READ_STAT("QUARTILE", PS_STAT_SAMPLE_QUARTILE);
     2139    READ_STAT("SAMPLE_MEAN",     PS_STAT_SAMPLE_MEAN);
     2140    READ_STAT("SAMPLE_STDEV",    PS_STAT_SAMPLE_STDEV);
     2141    READ_STAT("SAMPLE_MEDIAN",   PS_STAT_SAMPLE_MEDIAN);
     2142    READ_STAT("SAMPLE_QUARTILE", PS_STAT_SAMPLE_QUARTILE);
     2143    READ_STAT("ROBUST",          PS_STAT_ROBUST_MEDIAN);
     2144    READ_STAT("ROBUST_MEDIAN",   PS_STAT_ROBUST_MEDIAN);
     2145    READ_STAT("ROBUST_STDEV",    PS_STAT_ROBUST_STDEV);
     2146    READ_STAT("ROBUST_QUARTILE", PS_STAT_ROBUST_QUARTILE);
     2147    READ_STAT("FITTED",       PS_STAT_FITTED_MEAN);
     2148    READ_STAT("FITTED_MEAN",  PS_STAT_FITTED_MEAN);
     2149    READ_STAT("FITTED_STDEV", PS_STAT_ROBUST_STDEV);
     2150    READ_STAT("CLIPPED",       PS_STAT_CLIPPED_MEAN);
     2151    READ_STAT("CLIPPED_MEAN",  PS_STAT_CLIPPED_MEAN);
     2152    READ_STAT("CLIPPED_STDEV", PS_STAT_CLIPPED_STDEV);
     2153
     2154    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to parse statistic: %s\n", string);
     2155    return 0;
     2156}
     2157
     2158psString psStatsOptionToString(psStatsOptions option)
    21832159{
    21842160    psString string = NULL;             // String to return
    21852161
    21862162    #define WRITE_STAT(NAME, SYMBOL) \
    2187     if (stats->options & SYMBOL) { \
    2188         psStringAppend(&string, ",%s", NAME); \
     2163    if (option & SYMBOL) { \
     2164        psStringAppend(&string, "%s ", NAME); \
    21892165    }
    21902166
     
    22042180    return string;
    22052181}
     2182
     2183psStats *psStatsFromString(const char *string)
     2184{
     2185    psList *subStrings = psStringSplit(string, " ,;", false); // List of sub-strings
     2186    if (!subStrings || psListLength(subStrings) == 0) {
     2187        // Nothing here
     2188        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "No string to parse for statistics: %s\n", string);
     2189        psFree(subStrings);
     2190        return NULL;
     2191    }
     2192    psStats *stats = psStatsAlloc(0);   // Generate empty stats structure
     2193    psListIterator *iterator = psListIteratorAlloc(subStrings, PS_LIST_HEAD, false); // Iterator
     2194    psString statString;                // Statistic string, from iteration
     2195    while ((statString = psListGetAndIncrement(iterator))) {
     2196        psStatsOptions option = psStatsOptionFromString(statString);
     2197        if (option == 0) {
     2198            psLogMsg(__func__, PS_LOG_WARN, "Unable to interpret statistic option: %s --- ignored.\n",
     2199                     statString);
     2200            continue;
     2201        }
     2202        stats->options |= option;
     2203    }
     2204    psFree(iterator);
     2205    psFree(subStrings);
     2206    return stats;
     2207}
     2208
     2209psString psStatsToString(const psStats *stats)
     2210{
     2211    return psStatsOptionToString(stats->options);
     2212}
  • trunk/psLib/src/math/psStats.h

    r7989 r7991  
    1414 *  @author GLG, MHPCC
    1515 *
    16  *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
    17  *  @date $Date: 2006-07-26 22:09:48 $
     16 *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
     17 *  @date $Date: 2006-07-27 03:51:13 $
    1818 *
    1919 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    203203
    204204
     205// Get the statistics option from a string
     206psStatsOptions psStatsOptionFromString(const char *string);
     207// Write a string from the statistics options
     208psString psStatsOptionToString(psStatsOptions option);
    205209// Generate a psStats from a string of statistics options
    206210psStats *psStatsFromString(const char *string);
Note: See TracChangeset for help on using the changeset viewer.