Changeset 7989 for trunk/psLib/src/math/psStats.c
- Timestamp:
- Jul 26, 2006, 12:09:48 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/math/psStats.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/math/psStats.c
r7986 r7989 16 16 * use ->min and ->max (PS_STAT_USE_RANGE) 17 17 * 18 * @version $Revision: 1.1 79$ $Name: not supported by cvs2svn $19 * @date $Date: 2006-07-26 04:21:39$18 * @version $Revision: 1.180 $ $Name: not supported by cvs2svn $ 19 * @date $Date: 2006-07-26 22:09:48 $ 20 20 * 21 21 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 24 24 #include <stdlib.h> 25 25 #include <stdio.h> 26 #include <string.h>27 26 #include <stdarg.h> 28 27 #include <float.h> 29 28 #include <math.h> 30 29 #include <limits.h> 30 #include <strings.h> 31 31 32 32 /*****************************************************************************/ … … 45 45 #include "psAssert.h" 46 46 #include "psMathUtils.h" 47 #include "psList.h" 48 #include "psString.h" 47 49 48 50 #include "psErrorText.h" … … 2124 2126 } 2125 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 2141 #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) 2183 { 2184 psString string = NULL; // String to return 2185 2186 #define WRITE_STAT(NAME, SYMBOL) \ 2187 if (stats->options & SYMBOL) { \ 2188 psStringAppend(&string, ",%s", NAME); \ 2189 } 2190 2191 // Same list as above (for psStatsFromString), but with repeat symbols removed 2192 WRITE_STAT("SAMPLE_MEAN", PS_STAT_SAMPLE_MEAN); 2193 WRITE_STAT("SAMPLE_STDEV", PS_STAT_SAMPLE_STDEV); 2194 WRITE_STAT("SAMPLE_MEDIAN", PS_STAT_SAMPLE_MEDIAN); 2195 WRITE_STAT("SAMPLE_QUARTILE", PS_STAT_SAMPLE_QUARTILE); 2196 WRITE_STAT("ROBUST_MEDIAN", PS_STAT_ROBUST_MEDIAN); 2197 WRITE_STAT("ROBUST_STDEV", PS_STAT_ROBUST_STDEV); 2198 WRITE_STAT("ROBUST_QUARTILE", PS_STAT_ROBUST_QUARTILE); 2199 WRITE_STAT("FITTED_MEAN", PS_STAT_FITTED_MEAN); 2200 WRITE_STAT("FITTED_STDEV", PS_STAT_ROBUST_STDEV); 2201 WRITE_STAT("CLIPPED_MEAN", PS_STAT_CLIPPED_MEAN); 2202 WRITE_STAT("CLIPPED_STDEV", PS_STAT_CLIPPED_STDEV); 2203 2204 return string; 2205 }
Note:
See TracChangeset
for help on using the changeset viewer.
