Index: /trunk/doc/pslib/psLibSDRS.tex
===================================================================
--- /trunk/doc/pslib/psLibSDRS.tex	(revision 7990)
+++ /trunk/doc/pslib/psLibSDRS.tex	(revision 7991)
@@ -1,3 +1,3 @@
-%%% $Id: psLibSDRS.tex,v 1.423 2006-07-26 22:10:38 price Exp $
+%%% $Id: psLibSDRS.tex,v 1.424 2006-07-27 03:52:15 price Exp $
 \documentclass[panstarrs,spec]{panstarrs}
 
@@ -4791,16 +4791,22 @@
 so we specify functions to convert between strings and \code{psStats}:
 \begin{prototype}
+psStatsOptions psStatsOptionFromString(const char *string);
+psString psStatsOptionToString(psStatsOptions option);
 psStats *psStatsFromString(const char *string);
 psString psStatsToString(const psStats *stats);
 \end{prototype}
+\code{psStatsOptionFromString} shall parse the \code{string} for a
+single statistics option.  The options shall be specified by their
+\code{psStatsOptions} enum name, without the leading \code{PS_STAT_}.
+In addition, \code{SAMPLE_} may be excluded for the user's
+convenience, and \code{ROBUST} shall refer to a \code{ROBUST_MEDIAN},
+\code{FITTED} to a \code{FITTED_MEAN}, and \code{CLIPPED} to a
+\code{CLIPPED_MEAN}.  \code{psStatsOptionToString} shall translate in
+the reverse direction, returning the appropriate string given the
+\code{option} (which may be a blend of options).
 \code{psStatsFromString} shall parse the input \code{string} for
-statistics options.  Multiple options may be included in the same
-string, separated by spaces, commas or semi-colons.  The options shall
-be specified by their \code{psStatsOptions} enum, without the leading
-\code{PS_STAT_}.  In addition, \code{SAMPLE_} may be excluded for the
-user's convenience, and \code{ROBUST} shall refer to a
-\code{ROBUST_MEDIAN}, \code{FITTED} to a \code{FITTED_MEAN}, and
-\code{CLIPPED} to a \code{CLIPPED_MEAN}.  \code{psStatsToString} shall
-translate in the reverse direction.
+statistics options, where multiple options may be included in the same
+string, separated by spaces, commas or semi-colons.
+\code{psStatsToString} shall translate in the reverse direction.
 
 \begin{prototype}
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 7990)
+++ /trunk/psLib/src/math/psStats.c	(revision 7991)
@@ -16,6 +16,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.180 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-07-26 22:09:48 $
+ *  @version $Revision: 1.181 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-27 03:51:13 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -2126,65 +2126,41 @@
 }
 
-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
-
+psStatsOptions psStatsOptionFromString(const char *string)
+{
     #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)
+    if (strcasecmp(string, NAME) == 0) { \
+        return SYMBOL; \
+    }
+
+    READ_STAT("MEAN",     PS_STAT_SAMPLE_MEAN);
+    READ_STAT("STDEV",    PS_STAT_SAMPLE_STDEV);
+    READ_STAT("MEDIAN",   PS_STAT_SAMPLE_MEDIAN);
+    READ_STAT("QUARTILE", PS_STAT_SAMPLE_QUARTILE);
+    READ_STAT("SAMPLE_MEAN",     PS_STAT_SAMPLE_MEAN);
+    READ_STAT("SAMPLE_STDEV",    PS_STAT_SAMPLE_STDEV);
+    READ_STAT("SAMPLE_MEDIAN",   PS_STAT_SAMPLE_MEDIAN);
+    READ_STAT("SAMPLE_QUARTILE", PS_STAT_SAMPLE_QUARTILE);
+    READ_STAT("ROBUST",          PS_STAT_ROBUST_MEDIAN);
+    READ_STAT("ROBUST_MEDIAN",   PS_STAT_ROBUST_MEDIAN);
+    READ_STAT("ROBUST_STDEV",    PS_STAT_ROBUST_STDEV);
+    READ_STAT("ROBUST_QUARTILE", PS_STAT_ROBUST_QUARTILE);
+    READ_STAT("FITTED",       PS_STAT_FITTED_MEAN);
+    READ_STAT("FITTED_MEAN",  PS_STAT_FITTED_MEAN);
+    READ_STAT("FITTED_STDEV", PS_STAT_ROBUST_STDEV);
+    READ_STAT("CLIPPED",       PS_STAT_CLIPPED_MEAN);
+    READ_STAT("CLIPPED_MEAN",  PS_STAT_CLIPPED_MEAN);
+    READ_STAT("CLIPPED_STDEV", PS_STAT_CLIPPED_STDEV);
+
+    psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to parse statistic: %s\n", string);
+    return 0;
+}
+
+psString psStatsOptionToString(psStatsOptions option)
 {
     psString string = NULL;             // String to return
 
     #define WRITE_STAT(NAME, SYMBOL) \
-    if (stats->options & SYMBOL) { \
-        psStringAppend(&string, ",%s", NAME); \
+    if (option & SYMBOL) { \
+        psStringAppend(&string, "%s ", NAME); \
     }
 
@@ -2204,2 +2180,33 @@
     return string;
 }
+
+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
+    while ((statString = psListGetAndIncrement(iterator))) {
+        psStatsOptions option = psStatsOptionFromString(statString);
+        if (option == 0) {
+            psLogMsg(__func__, PS_LOG_WARN, "Unable to interpret statistic option: %s --- ignored.\n",
+                     statString);
+            continue;
+        }
+        stats->options |= option;
+    }
+    psFree(iterator);
+    psFree(subStrings);
+    return stats;
+}
+
+psString psStatsToString(const psStats *stats)
+{
+    return psStatsOptionToString(stats->options);
+}
Index: /trunk/psLib/src/math/psStats.h
===================================================================
--- /trunk/psLib/src/math/psStats.h	(revision 7990)
+++ /trunk/psLib/src/math/psStats.h	(revision 7991)
@@ -14,6 +14,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-07-26 22:09:48 $
+ *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-27 03:51:13 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -203,4 +203,8 @@
 
 
+// Get the statistics option from a string
+psStatsOptions psStatsOptionFromString(const char *string);
+// Write a string from the statistics options
+psString psStatsOptionToString(psStatsOptions option);
 // Generate a psStats from a string of statistics options
 psStats *psStatsFromString(const char *string);
