Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 7986)
+++ trunk/psLib/src/math/psStats.c	(revision 7989)
@@ -16,6 +16,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.179 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-07-26 04:21:39 $
+ *  @version $Revision: 1.180 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-26 22:09:48 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,9 +24,9 @@
 #include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdarg.h>
 #include <float.h>
 #include <math.h>
 #include <limits.h>
+#include <strings.h>
 
 /*****************************************************************************/
@@ -45,4 +45,6 @@
 #include "psAssert.h"
 #include "psMathUtils.h"
+#include "psList.h"
+#include "psString.h"
 
 #include "psErrorText.h"
@@ -2124,2 +2126,80 @@
 }
 
+psStats *psStatsFromString(const char *string)
+{
+    psList *subStrings = psStringSplit(string, " ,;", false); // List of sub-strings
+    if (!subStrings || psListLength(subStrings) == 0) {
+        // Nothing here
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false, "No string to parse for statistics: %s\n", string);
+        psFree(subStrings);
+        return NULL;
+    }
+    psStats *stats = psStatsAlloc(0);   // Generate empty stats structure
+    psListIterator *iterator = psListIteratorAlloc(subStrings, PS_LIST_HEAD, false); // Iterator
+    psString statString;                // Statistic string, from iteration
+
+    #define READ_STAT(NAME, SYMBOL) \
+    if (strcasecmp(statString, NAME) == 0) { \
+        stats->options |= SYMBOL; \
+    }
+
+    while ((statString = psListGetAndIncrement(iterator))) {
+        // This might look a little weird if automatically formated,
+        // but it's legal C once the pre-processing has been done, and
+        // it reads a lot better than a whole heap of "if-then-else" statements.
+        READ_STAT("MEAN",     PS_STAT_SAMPLE_MEAN) else
+            READ_STAT("STDEV",    PS_STAT_SAMPLE_STDEV) else
+                READ_STAT("MEDIAN",   PS_STAT_SAMPLE_MEDIAN) else
+                    READ_STAT("QUARTILE", PS_STAT_SAMPLE_QUARTILE) else
+                        READ_STAT("SAMPLE_MEAN",     PS_STAT_SAMPLE_MEAN) else
+                            READ_STAT("SAMPLE_STDEV",    PS_STAT_SAMPLE_STDEV) else
+                                READ_STAT("SAMPLE_MEDIAN",   PS_STAT_SAMPLE_MEDIAN) else
+                                    READ_STAT("SAMPLE_QUARTILE", PS_STAT_SAMPLE_QUARTILE) else
+                                        READ_STAT("ROBUST",          PS_STAT_ROBUST_MEDIAN) else
+                                            READ_STAT("ROBUST_MEDIAN",   PS_STAT_ROBUST_MEDIAN) else
+                                                READ_STAT("ROBUST_STDEV",    PS_STAT_ROBUST_STDEV) else
+                                                    READ_STAT("ROBUST_QUARTILE", PS_STAT_ROBUST_QUARTILE) else
+                                                        READ_STAT("FITTED",       PS_STAT_FITTED_MEAN) else
+                                                            READ_STAT("FITTED_MEAN",  PS_STAT_FITTED_MEAN) else
+                                                                READ_STAT("FITTED_STDEV", PS_STAT_ROBUST_STDEV) else
+                                                                    READ_STAT("CLIPPED",       PS_STAT_CLIPPED_MEAN) else
+                                                                        READ_STAT("CLIPPED_MEAN",  PS_STAT_CLIPPED_MEAN) else
+                                                                            READ_STAT("CLIPPED_STDEV", PS_STAT_CLIPPED_STDEV) else {
+                                                                                psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Can't interpret string as statistic: %s\n",
+                                                                                        statString);
+                                                                                psFree(iterator);
+                                                                                psFree(subStrings);
+                                                                                psFree(stats);
+                                                                                return NULL;
+                                                                            }
+    }
+
+    psFree(iterator);
+    psFree(subStrings);
+    return stats;
+}
+
+psString psStatsToString(const psStats *stats)
+{
+    psString string = NULL;             // String to return
+
+    #define WRITE_STAT(NAME, SYMBOL) \
+    if (stats->options & SYMBOL) { \
+        psStringAppend(&string, ",%s", NAME); \
+    }
+
+    // Same list as above (for psStatsFromString), but with repeat symbols removed
+    WRITE_STAT("SAMPLE_MEAN",     PS_STAT_SAMPLE_MEAN);
+    WRITE_STAT("SAMPLE_STDEV",    PS_STAT_SAMPLE_STDEV);
+    WRITE_STAT("SAMPLE_MEDIAN",   PS_STAT_SAMPLE_MEDIAN);
+    WRITE_STAT("SAMPLE_QUARTILE", PS_STAT_SAMPLE_QUARTILE);
+    WRITE_STAT("ROBUST_MEDIAN",   PS_STAT_ROBUST_MEDIAN);
+    WRITE_STAT("ROBUST_STDEV",    PS_STAT_ROBUST_STDEV);
+    WRITE_STAT("ROBUST_QUARTILE", PS_STAT_ROBUST_QUARTILE);
+    WRITE_STAT("FITTED_MEAN",  PS_STAT_FITTED_MEAN);
+    WRITE_STAT("FITTED_STDEV", PS_STAT_ROBUST_STDEV);
+    WRITE_STAT("CLIPPED_MEAN",  PS_STAT_CLIPPED_MEAN);
+    WRITE_STAT("CLIPPED_STDEV", PS_STAT_CLIPPED_STDEV);
+
+    return string;
+}
Index: trunk/psLib/src/math/psStats.h
===================================================================
--- trunk/psLib/src/math/psStats.h	(revision 7986)
+++ trunk/psLib/src/math/psStats.h	(revision 7989)
@@ -14,6 +14,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-05-22 22:46:01 $
+ *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-26 22:09:48 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -202,4 +202,11 @@
 );
 
+
+// Generate a psStats from a string of statistics options
+psStats *psStatsFromString(const char *string);
+// Generate a string of statistics options from a psStats
+psString psStatsToString(const psStats *stats);
+
+
 /// @}
 
