Index: trunk/psLib/src/math/psRegion.c
===================================================================
--- trunk/psLib/src/math/psRegion.c	(revision 13721)
+++ trunk/psLib/src/math/psRegion.c	(revision 13741)
@@ -8,4 +8,5 @@
 #include "psError.h"
 #include "psAssert.h"
+#include "psConstants.h"
 #include "psRegion.h"
 
@@ -83,4 +84,48 @@
 }
 
+psRegion psRegionAndParityFromString(int *xParity, int *yParity, const char* region)
+{
+    PS_ASSERT_PTR_NON_NULL (xParity, psRegionSet(NAN,NAN,NAN,NAN));
+    PS_ASSERT_PTR_NON_NULL (yParity, psRegionSet(NAN,NAN,NAN,NAN));
+
+    psS32 col0;
+    psS32 col1;
+    psS32 row0;
+    psS32 row1;
+
+    // unless otherwise detected
+    *xParity = +1;
+    *yParity = +1;
+
+    // section should be of the form '[col0:col1,row0:row1]'
+    if (region == NULL) {
+        return psRegionSet(0,0,0,0);
+    }
+
+    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                _("Specified subsection string, '%s', can not be parsed.  Must be in the form '[x1:x2,y1:y2]'."),
+                region);
+        return psRegionSet(NAN,NAN,NAN,NAN);
+    }
+
+    // [0:0,0:0] is complete image region
+    if ((col0 == 0) && (col1 == 0) && (row0 == 0) && (row1 == 0)) {
+        return psRegionSet(0,0,0,0);
+    }
+
+    if ((col1 > 0) && (col0 > col1)) {
+	*xParity = -1;
+	PS_SWAP (col0, col1);
+    }
+
+    if ((row1 > 0) && (row0 > row1)) {
+	*yParity = -1;
+	PS_SWAP (row0, row1);
+    }
+
+    return psRegionSet(col0-1,col1,row0-1,row1);
+}
+
 psString psRegionToString(const psRegion region)
 {
Index: trunk/psLib/src/math/psRegion.h
===================================================================
--- trunk/psLib/src/math/psRegion.h	(revision 13721)
+++ trunk/psLib/src/math/psRegion.h	(revision 13741)
@@ -2,6 +2,6 @@
  * @brief image regions and related functions
  *
- * $Revision: 1.8 $ $Name: not supported by cvs2svn $
- * $Date: 2007-01-23 22:47:23 $
+ * $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ * $Date: 2007-06-10 17:54:05 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -72,4 +72,18 @@
 );
 
+/** Create a psRegion from a string in IRAF form '[x0:x1,y0:y1]', returning range parities
+ *
+ *  Create a psRegion using the range defined by a string in the standard IRAF form
+ *  '[x0:x1,y0:y1]'.  Unlike psRegionFromString, the ranges may have x0 > x1 or y0 > y1, in
+ *  which case the xParity or yParity terms will be set to -1 (instead of the default +1).
+ *
+ *  @return psRegion:       A new psRegion struct, or NULL is not successful.
+ */
+psRegion psRegionAndParityFromString(
+    int *xParity,		      ///< +1 if x0 <= x1, -1 otherwise
+    int *yParity,		      ///< +1 if y0 <= y1, -1 otherwise
+    const char* region		      ///< image rectangular region in the form '[x0:x1,y0:y1]'
+);
+
 /** Create a string of the standard IRAF form '[x0:x1,y0:y1]' from a psRegion.
  *
