Changeset 7991
- Timestamp:
- Jul 26, 2006, 5:52:15 PM (20 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
doc/pslib/psLibSDRS.tex (modified) (2 diffs)
-
psLib/src/math/psStats.c (modified) (3 diffs)
-
psLib/src/math/psStats.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/pslib/psLibSDRS.tex
r7990 r7991 1 %%% $Id: psLibSDRS.tex,v 1.42 3 2006-07-26 22:10:38price Exp $1 %%% $Id: psLibSDRS.tex,v 1.424 2006-07-27 03:52:15 price Exp $ 2 2 \documentclass[panstarrs,spec]{panstarrs} 3 3 … … 4791 4791 so we specify functions to convert between strings and \code{psStats}: 4792 4792 \begin{prototype} 4793 psStatsOptions psStatsOptionFromString(const char *string); 4794 psString psStatsOptionToString(psStatsOptions option); 4793 4795 psStats *psStatsFromString(const char *string); 4794 4796 psString psStatsToString(const psStats *stats); 4795 4797 \end{prototype} 4798 \code{psStatsOptionFromString} shall parse the \code{string} for a 4799 single statistics option. The options shall be specified by their 4800 \code{psStatsOptions} enum name, without the leading \code{PS_STAT_}. 4801 In addition, \code{SAMPLE_} may be excluded for the user's 4802 convenience, 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 4805 the reverse direction, returning the appropriate string given the 4806 \code{option} (which may be a blend of options). 4796 4807 \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. 4808 statistics options, where multiple options may be included in the same 4809 string, separated by spaces, commas or semi-colons. 4810 \code{psStatsToString} shall translate in the reverse direction. 4805 4811 4806 4812 \begin{prototype} -
trunk/psLib/src/math/psStats.c
r7989 r7991 16 16 * use ->min and ->max (PS_STAT_USE_RANGE) 17 17 * 18 * @version $Revision: 1.18 0$ $Name: not supported by cvs2svn $19 * @date $Date: 2006-07-2 6 22:09:48$18 * @version $Revision: 1.181 $ $Name: not supported by cvs2svn $ 19 * @date $Date: 2006-07-27 03:51:13 $ 20 20 * 21 21 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 2126 2126 } 2127 2127 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 2128 psStatsOptions psStatsOptionFromString(const char *string) 2129 { 2141 2130 #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 2158 psString psStatsOptionToString(psStatsOptions option) 2183 2159 { 2184 2160 psString string = NULL; // String to return 2185 2161 2186 2162 #define WRITE_STAT(NAME, SYMBOL) \ 2187 if ( stats->options& SYMBOL) { \2188 psStringAppend(&string, " ,%s", NAME); \2163 if (option & SYMBOL) { \ 2164 psStringAppend(&string, "%s ", NAME); \ 2189 2165 } 2190 2166 … … 2204 2180 return string; 2205 2181 } 2182 2183 psStats *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 2209 psString psStatsToString(const psStats *stats) 2210 { 2211 return psStatsOptionToString(stats->options); 2212 } -
trunk/psLib/src/math/psStats.h
r7989 r7991 14 14 * @author GLG, MHPCC 15 15 * 16 * @version $Revision: 1.5 3$ $Name: not supported by cvs2svn $17 * @date $Date: 2006-07-2 6 22:09:48$16 * @version $Revision: 1.54 $ $Name: not supported by cvs2svn $ 17 * @date $Date: 2006-07-27 03:51:13 $ 18 18 * 19 19 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 203 203 204 204 205 // Get the statistics option from a string 206 psStatsOptions psStatsOptionFromString(const char *string); 207 // Write a string from the statistics options 208 psString psStatsOptionToString(psStatsOptions option); 205 209 // Generate a psStats from a string of statistics options 206 210 psStats *psStatsFromString(const char *string);
Note:
See TracChangeset
for help on using the changeset viewer.
