Index: /trunk/psLib/src/Makefile.am
===================================================================
--- /trunk/psLib/src/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/Makefile.am	(revision 4540)
@@ -1,28 +1,17 @@
-SUBDIRS = astronomy collections dataManip dataIO image sysUtils
-
-INCLUDES = \
-	-I$(top_srcdir)/src/astronomy \
-	-I$(top_srcdir)/src/collections \
-	-I$(top_srcdir)/src/dataManip \
-	-I$(top_srcdir)/src/dataIO \
-	-I$(top_srcdir)/src/image \
-	-I$(top_srcdir)/src/sysUtils \
-	$(all_includes)
+SUBDIRS = $(SRCDIRS)
 
 lib_LTLIBRARIES = libpslib.la
-bin_SCRIPTS = psParseErrorCodes
 
-libpslib_la_LIBADD = \
-	$(top_builddir)/src/astronomy/libpslibastronomy.la \
-	$(top_builddir)/src/collections/libpslibcollections.la \
-	$(top_builddir)/src/dataManip/libpslibdataManip.la \
-	$(top_builddir)/src/dataIO/libpslibdataIO.la \
-	$(top_builddir)/src/image/libpslibimage.la \
-	$(top_builddir)/src/sysUtils/libpslibsysUtils.la
+libpslib_la_LIBADD = $(SRCSUBLIBS)
 
 libpslib_la_SOURCES = psTest.c
 libpslib_la_LDFLAGS = -version-info $(PSLIB_LT_VERSION)
 
-EXTRA_DIST = mainpage.dox psErrorCodes.dat psTest.h psParseErrorCodes
+
+EXTRA_DIST = mainpage.dox psErrorCodes.dat psTest.h psErrorText.h.in psErrorText_en.dat
+
+BUILT_SOURCES = psErrorText.h
+psErrorText.h: psErrorText_$(LANG).dat
+	$(top_srcdir)/psParseErrorCodes --data=$? $@
 
 pslibincludedir = $(includedir)
Index: /trunk/psLib/src/astro/Makefile.am
===================================================================
--- /trunk/psLib/src/astro/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/astro/Makefile.am	(revision 4540)
@@ -3,17 +3,10 @@
 AM_CFLAGS=$(CFLAGS) -DPS_CONFIG_FILE_DEFAULT=\"$(sysconfdir)/pslib/psTime.config\"
 
-INCLUDES = `echo "$(SRCLIBS} | sed sed "s|\(\\w\+\)|-I\$(top_builddir)/src/\1|g"`
-
 noinst_LTLIBRARIES = libpslibastro.la
 libpslibastro_la_SOURCES = \
 	psTime.c \
-	psCoord.c 
-	
-BUILT_SOURCES = psAstroErrors.h
+	psCoord.c
 
-EXTRA_DIST = psAstroErrors_$(LANG).dat astro.i
-
-psAstroErrors.h: psAstroErrors_$(LANG).dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = astro.i
 
 pslibincludedir = $(includedir)
Index: unk/psLib/src/astro/psAstroErrors_en.dat
===================================================================
--- /trunk/psLib/src/astro/psAstroErrors_en.dat	(revision 4539)
+++ 	(revision )
@@ -1,34 +1,0 @@
-#
-#  This file is used to generate psAstroErrors.h content
-#
-#  Format is:
-#  ERRORNAME(one word)    ERROR_TEXT
-#
-#  N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME
-####################################################################
-psTime_FILE_NOT_FOUND                  Failed to open file %s.
-psTime_FILE_TOO_MANY_ROWS              Too many rows found in file %s. Max number of rows allowed is %d.
-psTime_TIME_POSTDATES_TABLE            Specified psTime postdates (%g) the table of %s information.
-psTime_TIME_PREDATES_TABLE             Specified psTime predates (%g) the table of %s information.
-psTime_TIME_POSTDATES_TABLES           Specified psTime postdates (%g) all tables of %s information.
-psTime_TIME_PREDATES_TABLES            Specified psTime predates (%g) all tables of %s information.
-psTime_TABLE_DUPLICATE_ROWS            The %s table was found to have two rows of the same time value.
-psTime_TYPE_UNKNOWN                    Specified type, %d, is not supported.
-psTime_TYPE_INCORRECT                  Specified type, %d, is incorrect.
-psTime_TYPE_MISMATCH                   Specified psTime parameters must have same type.
-psTime_GET_TOD_FAILED                  Failed to determine the current time from gettimeofday function.
-psTime_CONVERT_TIME_TO_STRING_FAILED   Failed to convert a time via strftime function.
-psTime_APPEND_MSEC_FAILED              Failed to append millisecond to time string with snprintf function.
-psTime_USEC_INVALID                    The psTime usec attribute value, %u, is invalid.  Must be less than 1e6.
-psTime_ISOTIME_MALFORMED               Specified ISO Time string, '%s', is malformed.  Must be in 'YYYY-MM-DDThh:mm:ss.sss' format.
-psTime_INTERPOLATION_FAILED            Failed time table interpolation.
-psTime_INTERPOLATION_FAILED_NAME       Failed time table interpolation for '%s'.
-psTime_LOOKUP_METADATA_FAILED          Failed find '%s' in time metadata.
-psTime_BAD_TABLE_COUNT                 Incorrect number of table files entered. Found: %d. Expected: %d.
-psTime_BAD_VECTOR                      Incorrect vector size. Size: %d, Expected %d.
-#
-psCoord_PROJECTION_TYPE_UNDEFINED      The projection type, %s, is undefined.
-psCoord_PROJECTION_TYPE_UNKNOWN        The projection type, %d, is unknown.
-psCoord_UNITS_UNKNOWN                  Specified units, 0x%x, is not supported.
-psCoord_OFFSET_MODE_UNKNOWN            Specified offset mode, 0x%x, is not supported.
-psCoord_INVALID_MJD                    Specified time is less than 1900.
Index: /trunk/psLib/src/astro/psCoord.c
===================================================================
--- /trunk/psLib/src/astro/psCoord.c	(revision 4539)
+++ /trunk/psLib/src/astro/psCoord.c	(revision 4540)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.78 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-27 20:38:11 $
+*  @version $Revision: 1.79 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:00 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -25,6 +25,5 @@
 #include "psError.h"
 #include "psLogMsg.h"
-#include "psAstronomyErrors.h"
-#include "psAstrometry.h"
+#include "psErrorText.h"
 #include "psMatrix.h"
 #include <math.h>
Index: /trunk/psLib/src/astro/psTime.c
===================================================================
--- /trunk/psLib/src/astro/psTime.c	(revision 4539)
+++ /trunk/psLib/src/astro/psTime.c	(revision 4540)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:00 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -31,8 +31,8 @@
 #include "psString.h"
 #include "psMetadata.h"
-#include "psMetadataIO.h"
+#include "psMetadataConfig.h"
 #include "psLookupTable.h"
 #include "psConstants.h"
-#include "psAstronomyErrors.h"
+#include "psErrorText.h"
 
 #include "config.h"
Index: /trunk/psLib/src/astronomy/psCoord.c
===================================================================
--- /trunk/psLib/src/astronomy/psCoord.c	(revision 4539)
+++ /trunk/psLib/src/astronomy/psCoord.c	(revision 4540)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.78 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-27 20:38:11 $
+*  @version $Revision: 1.79 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:00 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -30,7 +30,4 @@
 #include <math.h>
 #include <float.h>
-/******************************************************************************/
-/*  DEFINE STATEMENTS                                                         */
-/******************************************************************************/
 
 // Modified Julian Day 01/01/1900 00:00:00
@@ -40,32 +37,29 @@
 #define JULIAN_CENTURY 36525.0
 
-/******************************************************************************/
-/*  TYPE DEFINITIONS                                                          */
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  GLOBAL VARIABLES                                                         */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FILE STATIC VARIABLES                                                    */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
-/*****************************************************************************/
-
-/*****************************************************************************/
-/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
-/*****************************************************************************/
 static void planeFree(psPlane *p)
 {
     // There are non dynamic allocated items
+}
+
+static void sphereFree(psSphere *s)
+{
+    // There are non dynamic allocated items
+}
+
+static void planeTransformFree(psPlaneTransform *pt)
+{
+    psFree(pt->x);
+    psFree(pt->y);
+}
+
+static void planeDistortFree(psPlaneDistort *pt)
+{
+    psFree(pt->x);
+    psFree(pt->y);
+}
+
+static void projectionFree(psProjection *p)
+{
+    // There are no dynamically allocated items
 }
 
@@ -201,10 +195,4 @@
 }
 
-
-static void sphereFree(psSphere *s)
-{
-    // There are non dynamic allocated items
-}
-
 psSphere* psSphereAlloc(void)
 {
@@ -215,8 +203,41 @@
 }
 
-static void planeTransformFree(psPlaneTransform *pt)
-{
-    psFree(pt->x);
-    psFree(pt->y);
+psSphereRot* psSphereRotAlloc(double alphaP,
+                              double deltaP,
+                              double phiP)
+{
+    psSphereRot* rot = psAlloc(sizeof(psSphereRot));
+
+    double cosDelta = cos(deltaP);
+    double halfPhi = phiP / 2.0;
+    double sinHalfPhi = sin(halfPhi);
+
+    // equations are directly from ADD
+    double vx = cosDelta*cos(alphaP);
+    double vy = cosDelta*sin(alphaP);
+    double vz = sin(deltaP);
+
+    rot->q0 = vx*sinHalfPhi;
+    rot->q1 = vy*sinHalfPhi;
+    rot->q2 = vz*sinHalfPhi;
+    rot->q3 = cos(halfPhi);
+
+    return rot;
+}
+
+psSphereRot* psSphereRotQuat(double q0,
+                             double q1,
+                             double q2,
+                             double q3)
+{
+    psSphereRot* rot = psAlloc(sizeof(psSphereRot));
+
+    double len = sqrt(q0*q0 + q1*q1 + q2*q2 + q3*q3);
+    rot->q0 = q0 / len;
+    rot->q1 = q1 / len;
+    rot->q2 = q2 / len;
+    rot->q3 = q3 / len;
+
+    return rot;
 }
 
@@ -260,10 +281,4 @@
 
     return (out);
-}
-
-static void planeDistortFree(psPlaneDistort *pt)
-{
-    psFree(pt->x);
-    psFree(pt->y);
 }
 
@@ -319,51 +334,10 @@
 
 /******************************************************************************
-alpha is LONGITUDE
-delta is LATITUDE
- 
-    alphaP: Take the target pole in the source system; calculate its LONGITUDE
-     in the target system.  That longitude is alphaP.
-    DeltaP: Take the target pole in the source system; calculate its LATITUDE
-     in the target system.  That longitude is deltaP.
-    phiP:   This is the LONGITUDE of the ascending node in the target system.
- *****************************************************************************/
-psSphereTransform* psSphereTransformAlloc(psF64 alphaP,
-        psF64 deltaP,
-        psF64 phiP)
-{
-    psSphereTransform* tmp = (psSphereTransform* ) psAlloc(sizeof(psSphereTransform));
-
-    tmp->cosDeltaP = cos(deltaP);
-    tmp->sinDeltaP = sin(deltaP);
-    tmp->alphaP = alphaP;
-    tmp->phiP = phiP;
-
-    return (tmp);
-}
-
-/******************************************************************************
-XXX: Private Function.
- 
-piNormalize(): take an input angle in radians and convert it to the range 0:2*PI.
- *****************************************************************************/
-psF32 piNormalize(psF32 angle)
-{
-    while (angle < FLT_EPSILON) {
-        angle+=M_PI*2;
-    }
-
-    while (angle >= (M_PI*2)) {
-        angle-=M_PI*2;
-    }
-    return(angle);
-}
-
-/******************************************************************************
 XXX: We convert Right Ascension angles to the range 0:PI.  Is that acceptable?
 XXX: Should we do something for Declination as well?
  *****************************************************************************/
-psSphere* psSphereTransformApply(psSphere* out,
-                                 const psSphereTransform* transform,
-                                 const psSphere* coord)
+psSphere* psSphereRotApply(psSphere* out,
+                           const psSphereRot* transform,
+                           const psSphere* coord)
 {
     PS_ASSERT_PTR_NON_NULL(transform, NULL);
@@ -371,26 +345,64 @@
 
     if (out == NULL) {
-        out = (psSphere* ) psAlloc(sizeof(psSphere));
-    }
-
-    psF64 alpha = coord->r;
-    psF64 delta = coord->d;
-    psF64 alphaMinusAlphaP = alpha - transform->alphaP;
-
-    psF64 eq55 = (sin(delta) * transform->cosDeltaP) -
-                 (cos(delta) * transform->sinDeltaP * sin(alphaMinusAlphaP));
-    psF64 eq56 = (cos(delta) * transform->cosDeltaP * sin(alphaMinusAlphaP)) +
-                 (sin(delta) * transform->sinDeltaP);
-    psF64 eq57 = cos(delta) * cos(alphaMinusAlphaP);
-
-    psF64 theta = asin(eq55);
-    psF64 phi = atan2(eq56, eq57) + transform->phiP;
-    out->r = piNormalize(phi);
-    out->d = theta;
-
-    return(out);
-}
-
-psSphereTransform* psSphereTransformICRSToEcliptic(psTime *time)
+        out = psSphereAlloc();
+    }
+
+
+    // apply the transform by creating a new psSphereRot from the input coord
+    // and combining it with the input transform (see ADD)
+    psSphereRot* coordRot = psSphereRotAlloc(coord->r, coord->d, 0);
+    coordRot->q3 = 0.0;
+    coordRot = psSphereRotCombine(coordRot, transform, coordRot);
+    // N.B., we can recycle coordRot right away due to the implementation of
+    // psSphereRotCombine puts the values of coordRot in a local variable first
+
+    out->r = atan2(coordRot->q1,coordRot->q0);
+    out->d = atan2(coordRot->q2,sqrt(coordRot->q1*coordRot->q1+coordRot->q0*coordRot->q0));
+
+    return out;
+}
+
+psSphereRot* psSphereRotCombine(psSphereRot* out,
+                                const psSphereRot* rot1,
+                                const psSphereRot* rot2)
+{
+    PS_ASSERT_PTR_NON_NULL(rot1, NULL);
+    PS_ASSERT_PTR_NON_NULL(rot2, NULL);
+
+    if (out == NULL) {
+        out = (psSphereRot* ) psAlloc(sizeof(psSphereRot));
+    }
+
+    double a0 = rot1->q0;
+    double a1 = rot1->q1;
+    double a2 = rot1->q2;
+    double a3 = rot1->q3;
+    double b0 = rot2->q0;
+    double b1 = rot2->q1;
+    double b2 = rot2->q2;
+    double b3 = rot2->q3;
+
+    // following came from ADD
+    out->q0 = b3*a0 + b2*a1 - b1*a2 + b0*a3;
+    out->q1 = b3*a1 - b2*a0 + b1*a3 + b0*a2;
+    out->q2 = b3*a2 + b2*a3 + b1*a0 - b0*a1;
+    out->q3 = b3*a3 - b3*a2 - b1*a1 - b0*a0;
+
+    return out;
+}
+
+psSphereRot *psSphereRotInvert(psSphereRot *rot)
+{
+    PS_ASSERT_PTR_NON_NULL(rot, NULL);
+
+    double norm = sqrt(rot->q0*rot->q0 + rot->q1*rot->q1 + rot->q2*rot->q2 + rot->q3*rot->q3);
+    rot->q1 = -rot->q1 / norm;
+    rot->q2 = -rot->q2 / norm;
+    rot->q3 = -rot->q3 / norm;
+
+    return rot;
+}
+
+psSphereRot* psSphereRotICRSToEcliptic(const psTime *time)
 {
     psF64 T;
@@ -421,9 +433,9 @@
 
     // Don't neglect the minus sign on deltaP (bug 244):
-    return (psSphereTransformAlloc(alphaP, deltaP, phiP));
-}
-
-
-psSphereTransform* psSphereTransformEclipticToICRS(psTime *time)
+    return (psSphereRotAlloc(alphaP, deltaP, phiP));
+}
+
+
+psSphereRot* psSphereRotEclipticToICRS(const psTime *time)
 {
     psF64 T;
@@ -453,9 +465,9 @@
     psF64 phiP = 0.0;
 
-    return (psSphereTransformAlloc(alphaP, -deltaP, phiP));
+    return (psSphereRotAlloc(alphaP, -deltaP, phiP));
 }
 
 // XXX: This is bug 245: alphaP swaps with phiP from psSphereTransformGalacticToICRS()
-psSphereTransform* psSphereTransformGalacticToICRS(void)
+psSphereRot* psSphereRotGalacticToICRS(void)
 {
     psF64 alphaP = DEG_TO_RAD(32.93192);
@@ -463,8 +475,8 @@
     psF64 phiP = DEG_TO_RAD(282.85948);
 
-    return (psSphereTransformAlloc(alphaP, deltaP, phiP));
-}
-
-psSphereTransform* psSphereTransformICRSToGalactic(void)
+    return (psSphereRotAlloc(alphaP, deltaP, phiP));
+}
+
+psSphereRot* psSphereRotICRSToGalactic(void)
 {
     psF64 alphaP = DEG_TO_RAD(282.85948);
@@ -472,10 +484,5 @@
     psF64 phiP = DEG_TO_RAD(32.93192);
 
-    return (psSphereTransformAlloc(alphaP, deltaP, phiP));
-}
-
-void projectionFree(psProjection *p)
-{
-    // There are no dynamically allocated items
+    return (psSphereRotAlloc(alphaP, deltaP, phiP));
 }
 
@@ -837,8 +844,8 @@
 
     // Create transform with proper constants
-    psSphereTransform *tmpST = psSphereTransformAlloc(alphaP, deltaP, phiP);
+    psSphereRot* tmpST = psSphereRotAlloc(alphaP, deltaP, phiP);
 
     // Apply transform to coordinates
-    psSphere *out = psSphereTransformApply(NULL, tmpST, coords);
+    psSphere *out = psSphereRotApply(NULL, tmpST, coords);
 
     psFree(tmpST);
Index: /trunk/psLib/src/astronomy/psCoord.h
===================================================================
--- /trunk/psLib/src/astronomy/psCoord.h	(revision 4539)
+++ /trunk/psLib/src/astronomy/psCoord.h	(revision 4540)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-27 20:38:11 $
+*  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:00 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -24,5 +24,5 @@
 #include "psList.h"
 #include "psFunctions.h"
-#include "psTime.h"
+// N.B. inclusion of psTime.h was done to after the typedefs to handle cross-dependency of typedefs
 
 /// @addtogroup CoordinateTransform
@@ -38,8 +38,8 @@
 typedef struct
 {
-    double x;                   ///< x position
-    double y;                   ///< y position
-    double xErr;                ///< Error in x position
-    double yErr;                ///< Error in y position
+    double x;                          ///< x position
+    double y;                          ///< y position
+    double xErr;                       ///< Error in x position
+    double yErr;                       ///< Error in y position
 }
 psPlane;
@@ -52,12 +52,40 @@
  *
  */
-typedef struct psSphere
-{
-    double r;                   ///< RA
-    double d;                   ///< Dec
-    double rErr;                ///< Error in RA
-    double dErr;                ///< Error in Dec
+typedef struct
+{
+    double r;                          ///< RA
+    double d;                          ///< Dec
+    double rErr;                       ///< Error in RA
+    double dErr;                       ///< Error in Dec
 }
 psSphere;
+
+/** Cubic Coordinate System
+ *
+ */
+typedef struct
+{
+    double x;                          ///< cos (DEC) cos (RA)
+    double y;                          ///< cos (DEC) sic (RA)
+    double z;                          ///< sin (DEC)
+    double xErr;                       ///< Error in x
+    double yErr;                       ///< Error in y
+    double zErr;                       ///< Error in z
+}
+psCube;
+
+/** Spherical rotations represent coordinate transformation in 3-D, as well as
+ *  the effects of precession and nutation.  The structure contains the
+ *  elements of a quaternion to represent the spherical rotational.
+ *
+ */
+typedef struct
+{
+    double q0;                         ///< first element of the quaternion
+    double q1;                         ///< second element of the quaternion
+    double q2;                         ///< third element of the quaternion
+    double q3;                         ///< fourth element of the quaternion
+}
+psSphereRot;
 
 /** 2D Polynomial Transform
@@ -94,23 +122,4 @@
 }
 psPlaneDistort;
-
-/** Spherical Transform Definition
- *
- *  We need to be able to convert between ICRS, Galactic and Ecliptic
- *  coordinates, and potentially between arbitrary spherical coordinate
- *  systems. All of these basic spherical transformations represent rotations
- *  of the spherical coordinate reference. We specify a general
- *  transformation function which takes a structure, psSphereTransform,
- *  defining the transformation between two spherical coordinate systems
- *
- */
-typedef struct
-{
-    double alphaP;                    ///< Longitude of the target system pole in the source system
-    double cosDeltaP;                 ///< Cosine of target pole latitude in the source system
-    double sinDeltaP;                 ///< Sine of target pole latitude in the source system
-    double phiP;                      ///< Longitude of the ascending node in the target system
-}
-psSphereTransform;
 
 /** Projection type for projection/deprojection
@@ -167,4 +176,6 @@
 } psSphereOffsetUnit;
 
+#include "psTime.h"
+
 /** Allocates a psPlane
  *
@@ -178,7 +189,28 @@
  *  @return psSphere*     resulting sphere structure.
  */
-
 psSphere* psSphereAlloc(void);
 
+/** psSphereRot allocator which defines the rotation in terms of the coordinate
+ *  of the pole and the rotation about that pole.
+ *
+ *  @return psSphereRot*       Newly allocated psSphereRot object
+ */
+psSphereRot* psSphereRotAlloc(
+    double alphaP,
+    double deltaP,
+    double phiP
+);
+
+/** psSphereRot allocator which defines the rotation from the elements of the
+ *  quaternion.
+ *
+ *  @return psSphereRot*       Newly allocated psSphereRot object
+ */
+psSphereRot* psSphereRotQuat(
+    double q0,
+    double q1,
+    double q2,
+    double q3
+);
 
 /** Allocates a psPlaneTransform transform.
@@ -186,5 +218,4 @@
  *  @return psPlaneTransform*     resulting plane transform
  */
-
 psPlaneTransform* psPlaneTransformAlloc(
     int n1,                            ///< The order of the x term in the transform.
@@ -227,23 +258,32 @@
 );
 
-/** Allocator for psSphereTransform
- *
- *  @return psSphereTransform*         newly allocated struct
- */
-
-psSphereTransform* psSphereTransformAlloc(
-    double alphaP,                      ///< north pole latitude
-    double deltaP,                      ///< north pole longitude?
-    double phiP                         ///< defines the longitude in the input system of the equatorial intersection between the two systems (e.g, the first point of Ares).
-);
-
-/** Applies the psSphereTransform transform for a specified coordinate
+
+/** Applies the psSphereRot transform for a specified coordinate
  *
  *  @return psSphere*      resulting coordinate based on transform
  */
-psSphere* psSphereTransformApply(
+psSphere* psSphereRotApply(
     psSphere* out,                     ///< a psSphere to recycle.  If NULL, a new one is generated.
-    const psSphereTransform* transform,///< the transform to apply
+    const psSphereRot* transform,      ///< the transform to apply
     const psSphere* coord              ///< the coordinate to apply the transform above.x
+);
+
+/** Combines two rotations to produce a single rotation which is equivalent of
+ *  applying the first rotation and then the second.
+ *
+ *  @return psSphereRot*               new psSphereRot transform
+ */
+psSphereRot* psSphereRotCombine(
+    psSphereRot* out,
+    const psSphereRot* rot1,
+    const psSphereRot* rot2
+);
+
+/** Inverts a psSphereRot's rotation.
+ *
+ *  @return psSphereRot*               The inverted psSphereRot
+ */
+psSphereRot* psSphereRotInvert(
+    psSphereRot* rot                   ///< the psSphereRot to invert
 );
 
@@ -251,8 +291,8 @@
  *  coordinate systems.
  *
- *  @return psSphereTransform*     transform for ICRS->Ecliptic coordinate systems
- */
-psSphereTransform* psSphereTransformICRSToEcliptic(
-    psTime *time                        ///< the time for which the resulting transform will be valid
+ *  @return psSphereRot*               transform for ICRS->Ecliptic coordinate systems
+ */
+psSphereRot* psSphereRotICRSToEcliptic(
+    const psTime* time                 ///< the time for which the resulting transform will be valid
 );
 
@@ -260,8 +300,8 @@
  *  coordinate systems.
  *
- *  @return psSphereTransform*     transform for Ecliptic->ICRS coordinate systems
- */
-psSphereTransform* psSphereTransformEclipticToICRS(
-    psTime *time                        ///< the time for which the resulting transform will be valid
+ *  @return psSphereRot*               transform for Ecliptic->ICRS coordinate systems
+ */
+psSphereRot* psSphereRotEclipticToICRS(
+    const psTime* time                 ///< the time for which the resulting transform will be valid
 );
 
@@ -270,5 +310,5 @@
  *
  */
-psSphereTransform* psSphereTransformICRSToGalactic(void);
+psSphereRot* psSphereRotICRSToGalactic(void);
 
 /** Creates the appropriate transform for converting from Galactic to ICRS
@@ -276,5 +316,5 @@
  *
  */
-psSphereTransform* psSphereTransformGalacticToICRS(void);
+psSphereRot* psSphereRotGalacticToICRS(void);
 
 /** Allocates memory for a psProjection structure
Index: /trunk/psLib/src/astronomy/psTime.c
===================================================================
--- /trunk/psLib/src/astronomy/psTime.c	(revision 4539)
+++ /trunk/psLib/src/astronomy/psTime.c	(revision 4540)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.65 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.66 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:00 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -887,5 +887,5 @@
 }
 
-struct psSphere* p_psTimeGetPoleCoords(const psTime* time)
+psSphere* p_psTimeGetPoleCoords(const psTime* time)
 {
     psU32 nTables = 3;
@@ -896,5 +896,5 @@
     psF64 c = 0.0;
     psF64 mjdPred = 0.0;
-    struct psSphere* output = NULL;
+    psSphere* output = NULL;
     psLookupStatusType xStatus = PS_LOOKUP_SUCCESS;
     psLookupStatusType yStatus = PS_LOOKUP_SUCCESS;
@@ -908,6 +908,5 @@
     PS_ASSERT_INT_WITHIN_RANGE(time->nsec,0,(psU32)((1e9)-1),NULL);
 
-    if(time->type != PS_TIME_TAI)
-    {
+    if(time->type != PS_TIME_TAI) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_TYPE_INCORRECT, time->type);
         return NULL;
@@ -922,6 +921,5 @@
 
     // Value could not be found through table lookup and interpolation
-    if(xStatus==PS_LOOKUP_PAST_TOP && yStatus==PS_LOOKUP_PAST_TOP)
-    {
+    if(xStatus==PS_LOOKUP_PAST_TOP && yStatus==PS_LOOKUP_PAST_TOP) {
 
         // Date too earlier for tables. Get default polar coodinate values from metadata, and issue warning.
@@ -942,6 +940,5 @@
         y = tableMetadataItem->data.F64;
 
-    } else if(xStatus==PS_LOOKUP_PAST_BOTTOM && yStatus==PS_LOOKUP_PAST_BOTTOM)
-    {
+    } else if(xStatus==PS_LOOKUP_PAST_BOTTOM && yStatus==PS_LOOKUP_PAST_BOTTOM) {
 
         /* Date too late for tables. Issue warning and use following formulae for predicting
@@ -1000,6 +997,5 @@
             yp->data.F64[4]*sin(c);
 
-    } else if(xStatus!=PS_LOOKUP_SUCCESS || yStatus!=PS_LOOKUP_SUCCESS)
-    {
+    } else if(xStatus!=PS_LOOKUP_SUCCESS || yStatus!=PS_LOOKUP_SUCCESS) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, PS_ERRORTEXT_psTime_INTERPOLATION_FAILED);
         return NULL;
Index: /trunk/psLib/src/astronomy/psTime.h
===================================================================
--- /trunk/psLib/src/astronomy/psTime.h	(revision 4539)
+++ /trunk/psLib/src/astronomy/psTime.h	(revision 4540)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:00 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -25,11 +25,8 @@
 
 #include "psType.h"
-#include "psImage.h"
-
-struct psSphere;
+// N.B. inclusion of psCoord.h was done to after the typedefs to handle cross-dependency of typedefs
 
 /// @addtogroup Time
 /// @{
-
 
 /** Time type.
@@ -69,4 +66,6 @@
 psTime;
 
+#include "psCoord.h"
+#include "psImage.h"
 
 /** Initialize time data.
@@ -161,7 +160,7 @@
  *  @return  psSphere*: Spherical coordinates of Earth's polar axias.
  */
-struct psSphere* p_psTimeGetPoleCoords(
-                const psTime *time      ///< psTime determine polar orientation.
-            );
+psSphere* p_psTimeGetPoleCoords(
+    const psTime *time      ///< psTime determine polar orientation.
+);
 
 /** Calculate the number of leapseconds between two times.
Index: /trunk/psLib/src/db/Makefile.am
===================================================================
--- /trunk/psLib/src/db/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/db/Makefile.am	(revision 4540)
@@ -1,22 +1,13 @@
 #Makefile for db functions of psLib
 #
-INCLUDES = `echo "$(SRCLIBS} | sed sed "s|\(\\w\+\)|-I\$(top_builddir)/src/\1|g"`
-
 noinst_LTLIBRARIES = libpslibdb.la
 
-libpslibdataIO_la_SOURCES = \
+libpslibdb_la_SOURCES = \
 	psDB.c
 
-
-BUILT_SOURCES = psDBErrors.h
-EXTRA_DIST = psDBErrors_en.dat db.i
-
-psFileUtilsErrors.h: psFileUtilsErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = db.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
-	psLookupTable.h \
-	psFits.h \
 	psDB.h
 
Index: /trunk/psLib/src/db/psDB.c
===================================================================
--- /trunk/psLib/src/db/psDB.c	(revision 4539)
+++ /trunk/psLib/src/db/psDB.c	(revision 4540)
@@ -12,6 +12,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-29 20:33:37 $
+ *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:00 $
  *
  *  Copyright 2005 Joshua Hoblitt, University of Hawaii
@@ -35,5 +35,5 @@
 #include "psError.h"
 #include "psString.h"
-#include "psFileUtilsErrors.h"
+#include "psErrorText.h"
 
 typedef struct
Index: /trunk/psLib/src/db/psDB.h
===================================================================
--- /trunk/psLib/src/db/psDB.h	(revision 4539)
+++ /trunk/psLib/src/db/psDB.h	(revision 4540)
@@ -10,6 +10,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-29 19:43:55 $
+ *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:00 $
  *
  *  Copyright 2005 Joshua Hoblitt, University of Hawaii
@@ -34,5 +34,5 @@
 typedef struct
 {
-    void* mysql;   ///< MySQL database handle
+    void* mysql;                       ///< MySQL database handle
 }
 psDB;
@@ -44,8 +44,8 @@
  */
 psDB *psDBInit(
-    const char *host,                   ///< Database server hostname
-    const char *user,                   ///< Database username
-    const char *passwd,                 ///< Database password
-    const char *dbname                  ///< Database namespace
+    const char *host,                  ///< Database server hostname
+    const char *user,                  ///< Database username
+    const char *passwd,                ///< Database password
+    const char *dbname                 ///< Database namespace
 );
 
@@ -53,5 +53,5 @@
  */
 void psDBCleanup(
-    psDB *dbh                           ///< Database handle
+    psDB *dbh                          ///< Database handle
 );
 
@@ -61,6 +61,6 @@
  */
 bool psDBCreate(
-    psDB *dbh,                          ///< Database handle
-    const char *dbname                  ///< New database namespace
+    psDB *dbh,                         ///< Database handle
+    const char *dbname                 ///< New database namespace
 );
 
@@ -70,6 +70,6 @@
  */
 bool psDBChange(
-    psDB *dbh,                          ///< Database handle
-    const char *dbname                  ///< Database namespace
+    psDB *dbh,                         ///< Database handle
+    const char *dbname                 ///< Database namespace
 );
 
@@ -79,6 +79,6 @@
  */
 bool psDBDrop(
-    psDB *dbh,                          ///< Database handle
-    const char *dbname                  ///< Database namespace
+    psDB *dbh,                         ///< Database handle
+    const char *dbname                 ///< Database namespace
 );
 
@@ -92,6 +92,6 @@
  */
 bool p_psDBRunQuery(
-    psDB *dbh,                          ///< Database handle
-    const char *format                  ///< SQL string to execute
+    psDB *dbh,                         ///< Database handle
+    const char *format                 ///< SQL string to execute
 );
 
@@ -117,7 +117,7 @@
  */
 bool psDBCreateTable(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const psMetadata *md                ///< Column names, types, and indexes
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const psMetadata *md               ///< Column names, types, and indexes
 );
 
@@ -140,8 +140,8 @@
  */
 psArray *psDBSelectColumn(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const char *col,                    ///< Column name
-    unsigned long long limit                   ///< Maximum number of elements to return
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const char *col,                   ///< Column name
+    unsigned long long limit           ///< Maximum number of elements to return
 );
 
@@ -155,9 +155,9 @@
  */
 psVector *psDBSelectColumnNum(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const char *col,                    ///< Column name
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const char *col,                   ///< Column name
     psElemType type,                   ///< Resulting psVector type
-    unsigned long long limit            ///< Maximum number of elements to return
+    unsigned long long limit           ///< Maximum number of elements to return
 );
 
@@ -177,8 +177,8 @@
  */
 psArray *psDBSelectRows(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of elements to return
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const psMetadata *where,           ///< Row match criteria
+    unsigned long long limit           ///< Maximum number of elements to return
 );
 
@@ -195,7 +195,7 @@
  */
 bool psDBInsertOneRow(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const psMetadata *row               ///< Row description
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const psMetadata *row              ///< Row description
 );
 
@@ -210,7 +210,7 @@
  */
 bool psDBInsertRows(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const psArray *rowSet                     ///< Set of rows to insert
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const psArray *rowSet              ///< Set of rows to insert
 );
 
@@ -223,6 +223,6 @@
  */
 psArray *psDBDumpRows(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName               ///< Table name
+    psDB *dbh,                         ///< Database handle
+    const char *tableName              ///< Table name
 );
 
@@ -236,6 +236,6 @@
  */
 psMetadata *psDBDumpCols(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName               ///< Table name
+    psDB *dbh,                         ///< Database handle
+    const char *tableName              ///< Table name
 );
 
@@ -252,8 +252,8 @@
  */
 psS64 psDBUpdateRows(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const psMetadata *where,            ///< Row match criteria
-    const psMetadata *values            ///< new field values
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const psMetadata *where,           ///< Row match criteria
+    const psMetadata *values           ///< new field values
 );
 
@@ -269,8 +269,8 @@
  */
 psS64 psDBDeleteRows(
-    psDB *dbh,                          ///< Database handle
-    const char *tableName,              ///< Table name
-    const psMetadata *where,            ///< Row match criteria
-    unsigned long long limit            ///< Maximum number of rows to delete
+    psDB *dbh,                         ///< Database handle
+    const char *tableName,             ///< Table name
+    const psMetadata *where,           ///< Row match criteria
+    unsigned long long limit           ///< Maximum number of rows to delete
 );
 
Index: unk/psLib/src/db/psDBErrors_en.dat
===================================================================
--- /trunk/psLib/src/db/psDBErrors_en.dat	(revision 4539)
+++ 	(revision )
@@ -1,26 +1,0 @@
-#
-#  This file is used to generate psDBErrors.h content
-#
-#  Format is:
-#  ERRORNAME(one word)    ERROR_TEXT
-#
-#  N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME
-####################################################################
-psDB_INVALID_PSDB                      Invalid psDB has been specified.
-psDB_NULL_TABLE                        NULL table specified.
-psDB_FAILED_TO_CONNECT                 Failed to connect to database.  Error: %s
-psDB_FAILED_TO_CHANGE                  Failed to change database.  Error: %s
-psDB_TABLE_PARAM_NULL                  Create table parameters may not be NULL.
-psDB_QUERY_GEN_FAIL                    Query generation failed.
-psDB_TABLE_CREATE_FAIL                 Failed to create table.
-psDB_SQL_PREPARE_FAIL                  Failed to prepare query.  Error: %s
-psDB_SQL_QUERY_FAIL                    Failed to execute SQL query.  Error: %s
-psDB_TABLE_DROP_FAIL                   Failed to drop table.
-psDB_SEL_COL_FAIL                      Failed to select column.
-psDB_QUERY_NO_DATA                     Query returned no data.  Error: %s
-psDB_INSERT_ROW_FAIL                   Failed to insert row.
-psDB_UPDATE_ROW_FAIL                   Update row SQL generate fail: values and where params may not be NULL.
-psDB_SQL_SUBSTR_FAIL                   SQL substring generation failed.
-psDB_WHERE_SUBSTR_FAIL                 WHERE parameter my not be NULL.
-
-
Index: /trunk/psLib/src/fft/Makefile.am
===================================================================
--- /trunk/psLib/src/fft/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/fft/Makefile.am	(revision 4540)
@@ -1,38 +1,15 @@
-#Makefile for dataManip functions of psLib
+#Makefile for fft functions of psLib
 #
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+noinst_LTLIBRARIES = libpslibfft.la
 
-noinst_LTLIBRARIES = libpslibdataManip.la
+libpslibfft_la_SOURCES = \
+	psImageFFT.c \
+	psVectorFFT.c
 
-libpslibdataManip_la_SOURCES = psUnaryOp.c psBinaryOp.c psStats.c \
-		psFunctions.c psMatrix.c psVectorFFT.c psMinimize.c psRandom.c
-
-BUILT_SOURCES = psDataManipErrors.h
-EXTRA_DIST = psDataManipErrors.dat psDataManipErrors.h dataManip.i
-
-psDataManipErrors.h: psDataManipErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = fft.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
-	psConstants.h \
-	psStats.h  \
-	psFunctions.h \
-	psMatrix.h \
-    psBinaryOp.h \
-    psUnaryOp.h \
 	psVectorFFT.h \
-	psMinimize.h \
-	psRandom.h
+	psImageFFT.h
 
Index: /trunk/psLib/src/fft/fft.i
===================================================================
--- /trunk/psLib/src/fft/fft.i	(revision 4540)
+++ /trunk/psLib/src/fft/fft.i	(revision 4540)
@@ -0,0 +1,3 @@
+/* db headers */
+%include "psImageFFT.h"
+%include "psVectorFFT.h"
Index: /trunk/psLib/src/fft/psImageFFT.h
===================================================================
--- /trunk/psLib/src/fft/psImageFFT.h	(revision 4539)
+++ /trunk/psLib/src/fft/psImageFFT.h	(revision 4540)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-18 03:13:02 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -33,5 +33,5 @@
 psImage* psImageFFT(
     psImage* out,                      ///< a psImage to recycle.  If NULL, a new psImage is made.
-    const psImage* image,                 ///< the psImage to apply transform to
+    const psImage* image,              ///< the psImage to apply transform to
     psFFTFlags direction               ///< the direction of the transform
 );
@@ -79,6 +79,6 @@
  */
 psImage* psImagePowerSpectrum(
-    psImage* out,                       ///< a psImage to recycle.  If NULL, a new psImage is made.
-    const psImage* in                   ///< the psImage to power spectrum of
+    psImage* out,                      ///< a psImage to recycle.  If NULL, a new psImage is made.
+    const psImage* in                  ///< the psImage to power spectrum of
 );
 
Index: /trunk/psLib/src/fft/psVectorFFT.c
===================================================================
--- /trunk/psLib/src/fft/psVectorFFT.c	(revision 4539)
+++ /trunk/psLib/src/fft/psVectorFFT.c	(revision 4540)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-05-19 02:09:39 $
+ *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -22,5 +22,5 @@
 #include "psLogMsg.h"
 
-#include "psDataManipErrors.h"
+#include "psErrorText.h"
 
 #define P_FFTW_PLAN_RIGOR FFTW_ESTIMATE
Index: /trunk/psLib/src/fits/Makefile.am
===================================================================
--- /trunk/psLib/src/fits/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/fits/Makefile.am	(revision 4540)
@@ -1,35 +1,12 @@
-#Makefile for dataIO functions of psLib
+#Makefile for fits functions of psLib
 #
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+noinst_LTLIBRARIES = libpslibfits.la
 
-noinst_LTLIBRARIES = libpslibdataIO.la
+libpslibfits_la_SOURCES = \
+	psFits.c
 
-libpslibdataIO_la_SOURCES = \
-	psLookupTable.c \
-	psFits.c \
-	psDB.c
-
-
-BUILT_SOURCES = psFileUtilsErrors.h
-EXTRA_DIST = psFileUtilsErrors.dat psFileUtilsErrors.h dataIO.i
-
-psFileUtilsErrors.h: psFileUtilsErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = fits.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
-	psLookupTable.h \
-	psFits.h \
-	psDB.h
-
+	psFits.h
Index: /trunk/psLib/src/fits/fits.i
===================================================================
--- /trunk/psLib/src/fits/fits.i	(revision 4540)
+++ /trunk/psLib/src/fits/fits.i	(revision 4540)
@@ -0,0 +1,2 @@
+/* fits headers */
+%include "psFits.h"
Index: /trunk/psLib/src/fits/psFits.c
===================================================================
--- /trunk/psLib/src/fits/psFits.c	(revision 4539)
+++ /trunk/psLib/src/fits/psFits.c	(revision 4540)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 02:02:05 $
+ *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -18,5 +18,5 @@
 #include "string.h"
 #include "psError.h"
-#include "psFileUtilsErrors.h"
+#include "psErrorText.h"
 #include "psImageStructManip.h"
 #include "psMemory.h"
Index: /trunk/psLib/src/imageops/Makefile.am
===================================================================
--- /trunk/psLib/src/imageops/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/imageops/Makefile.am	(revision 4540)
@@ -1,43 +1,22 @@
-#Makefile for image functions of psLib
+#Makefile for image operation functions of psLib
 #
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+noinst_LTLIBRARIES = libpslibimageops.la
 
-noinst_LTLIBRARIES = libpslibimage.la
-
-libpslibimage_la_SOURCES = \
-	psImage.c \
+libpslibimageops_la_SOURCES = \
+	psImageConvolve.c \
+	psImageGeomManip.c \
 	psImagePixelExtract.c \
-	psImageStructManip.c \
-	psImageGeomManip.c \
 	psImagePixelManip.c \
 	psImageStats.c \
-	psImageFFT.c \
-	psImageConvolve.c
+	psImageStructManip.c
 
-BUILT_SOURCES = psImageErrors.h
-EXTRA_DIST = psImageErrors.dat psImageErrors.h image.i
-
-psImageErrors.h: psImageErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = imageops.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
-	psImage.h \
+	psImageConvolve.h \
+	psImageGeomManip.h \
 	psImagePixelExtract.h \
-	psImageStructManip.h \
-	psImageGeomManip.h \
 	psImagePixelManip.h \
 	psImageStats.h \
-	psImageFFT.h \
-	psImageConvolve.h
+	psImageStructManip.h
Index: /trunk/psLib/src/imageops/imageops.i
===================================================================
--- /trunk/psLib/src/imageops/imageops.i	(revision 4540)
+++ /trunk/psLib/src/imageops/imageops.i	(revision 4540)
@@ -0,0 +1,8 @@
+/* imageops headers */
+%include "psImageConvolve.h"
+%include "psImageGeomManip.h"
+%include "psImagePixelExtract.h"
+%include "psImagePixelManip.h"
+%include "psImageStats.h"
+%include "psImageStructManip.h"
+
Index: /trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- /trunk/psLib/src/imageops/psImageConvolve.c	(revision 4539)
+++ /trunk/psLib/src/imageops/psImageConvolve.c	(revision 4540)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 02:02:05 $
+ *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -65,8 +65,8 @@
     result->image = psImageAlloc(numCols,numRows,PS_TYPE_KERNEL);
     memset(result->image->rawDataBuffer,0,numCols*numRows*PSELEMTYPE_SIZEOF(PS_TYPE_KERNEL));
-    result->p_kernelRows = psAlloc(sizeof(psKernelType*)*numRows);
-
-    psKernelType** kernelRows = result->p_kernelRows;
-    psKernelType** imageRows = result->image->data.PS_TYPE_KERNEL_DATA;
+    result->p_kernelRows = psAlloc(sizeof(float*)*numRows);
+
+    float** kernelRows = result->p_kernelRows;
+    float** imageRows = result->image->data.PS_TYPE_KERNEL_DATA;
     for (psS32 i = 0; i < numRows; i++) {
         kernelRows[i] = imageRows[i] - xMin;
@@ -103,7 +103,7 @@
     psS32 yMax = 0;
     psS32 length = 0;
-    psKernelType normalizeTime = 1.0;  // fraction of total time for each shift clock
+    float normalizeTime = 1.0;  // fraction of total time for each shift clock
     psKernel* result = NULL;
-    psKernelType** kernel = NULL;
+    float** kernel = NULL;
 
     // got non-NULL vectors?
@@ -170,5 +170,5 @@
         } \
         \
-        normalizeTime = 1.0 / (psKernelType)(tShiftData[length-1]); \
+        normalizeTime = 1.0 / (float)(tShiftData[length-1]); \
         result = psKernelAlloc(xMin,xMax,yMin,yMax); \
         kernel = result->kernel; \
@@ -180,5 +180,5 @@
             y = lastY - yShiftData[i]; \
             \
-            kernel[y][x] += (psKernelType)t / (psKernelType)lastT; \
+            kernel[y][x] += (float)t / (float)lastT; \
             prevT = tShiftData[i]; \
         } \
@@ -216,9 +216,9 @@
         kernel = result->kernel; \
         \
-        normalizeTime = 1.0 / (psKernelType)t; \
+        normalizeTime = 1.0 / (float)t; \
         x = 0; \
         y = 0; \
         for (psS32 i = length-1; i >= 0; i--) { \
-            kernel[y][x] += (psKernelType)(tShiftData[i]) * normalizeTime; \
+            kernel[y][x] += (float)(tShiftData[i]) * normalizeTime; \
             x -= xShiftData[i]; \
             y -= yShiftData[i]; \
@@ -296,5 +296,5 @@
     psS32 yMin = kernel->yMin;
     psS32 yMax = kernel->yMax;
-    psKernelType** kData = kernel->kernel;
+    float** kData = kernel->kernel;
 
     // make the output image to the proper size and type
@@ -399,5 +399,5 @@
         // pad the kernel to the same size of paddedImage
         psImage* paddedKernel = psImageAlloc(paddedCols,paddedRows,PS_TYPE_KERNEL);
-        memset(paddedKernel->data.U8[0],0,sizeof(psKernelType)*numCols*numRows); // zero-out image
+        memset(paddedKernel->data.U8[0],0,sizeof(float)*numCols*numRows); // zero-out image
         psS32 yMax = kernel->yMax;
         psS32 xMax = kernel->xMax;
@@ -407,6 +407,6 @@
                 padRow += paddedRows;
             }
-            psKernelType* padData = paddedKernel->data.PS_TYPE_KERNEL_DATA[padRow];
-            psKernelType* kernelRow = kernel->kernel[row];
+            float* padData = paddedKernel->data.PS_TYPE_KERNEL_DATA[padRow];
+            float* kernelRow = kernel->kernel[row];
             for (psS32 col = kernel->xMin; col <= xMax; col++) {
                 if (col < 0) {
Index: /trunk/psLib/src/imageops/psImageConvolve.h
===================================================================
--- /trunk/psLib/src/imageops/psImageConvolve.h	(revision 4539)
+++ /trunk/psLib/src/imageops/psImageConvolve.h	(revision 4540)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-18 03:13:02 $
+ *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -25,9 +25,9 @@
 
 /** Kernel Type
- *  
+ *
  *  A floating-point data type used for storing kernel data.
- *  
+ *
  */
-typedef psF32 psKernelType;
+//typedef float psKernelType;
 
 /** A convolution kernel */
@@ -35,10 +35,10 @@
 {
     psImage* image;                    ///< Kernel data, in the form of an image
-    psS32 xMin;                          ///< Most negative x index
-    psS32 yMin;                          ///< Most negative y index
-    psS32 xMax;                          ///< Most positive x index
-    psS32 yMax;                          ///< Most positive y index
-    psKernelType** kernel;             ///< Pointer to the kernel data
-    psKernelType** p_kernelRows;       ///< Pointer to the rows of the kernel data; not intended for user use.
+    int xMin;                          ///< Most negative x index
+    int yMin;                          ///< Most negative y index
+    int xMax;                          ///< Most positive x index
+    int yMax;                          ///< Most positive y index
+    float** kernel;                    ///< Pointer to the kernel data
+    float** p_kernelRows;              ///< Pointer to the rows of the kernel data; not intended for user use.
 }
 psKernel;
Index: /trunk/psLib/src/imageops/psImageGeomManip.c
===================================================================
--- /trunk/psLib/src/imageops/psImageGeomManip.c	(revision 4539)
+++ /trunk/psLib/src/imageops/psImageGeomManip.c	(revision 4540)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 00:51:28 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -196,5 +196,5 @@
     }
 
-    if (mode < PS_INTERPOLATE_FLAT || mode >= PS_INTERPOLATE_NUM_MODES) {
+    if (mode > PS_INTERPOLATE_LANCZOS4_VARIANCE ) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
Index: /trunk/psLib/src/imageops/psImagePixelExtract.c
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 4539)
+++ /trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 4540)
@@ -8,6 +8,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 00:51:28 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -312,5 +312,5 @@
     }
 
-    if (mode < PS_INTERPOLATE_FLAT || mode >= PS_INTERPOLATE_NUM_MODES) {
+    if (mode < PS_INTERPOLATE_FLAT ) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
Index: /trunk/psLib/src/imageops/psImagePixelManip.c
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelManip.c	(revision 4539)
+++ /trunk/psLib/src/imageops/psImagePixelManip.c	(revision 4540)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 00:51:28 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -185,9 +185,9 @@
 }
 
-psS32 psImageOverlaySection(psImage* image,
-                            const psImage* overlay,
-                            psS32 col0,
-                            psS32 row0,
-                            const char *op)
+int psImageOverlaySection(psImage* image,
+                          const psImage* overlay,
+                          int col0,
+                          int row0,
+                          const char *op)
 {
     psU32 imageNumRows;
Index: /trunk/psLib/src/imageops/psImagePixelManip.h
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelManip.h	(revision 4539)
+++ /trunk/psLib/src/imageops/psImagePixelManip.h	(revision 4540)
@@ -8,6 +8,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 00:51:28 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -78,11 +78,11 @@
  *  function is defined for psU8, psS8, psS16, psF32, psF64, psC32, and psC64.
  *
- *  @return psS32         0 if success, non-zero if failed.
+ *  @return int         0 if success, non-zero if failed.
  */
-psS32 psImageOverlaySection(
+int psImageOverlaySection(
     psImage* image,                    ///< target image
     const psImage* overlay,            ///< the overlay image
-    psS32 col0,                        ///< the column to start overlay
-    psS32 row0,                        ///< the row to start overlay
+    int col0,                          ///< the column to start overlay
+    int row0,                          ///< the row to start overlay
     const char *op                     ///< the operation to perform for overlay
 );
Index: /trunk/psLib/src/imageops/psImageStructManip.c
===================================================================
--- /trunk/psLib/src/imageops/psImageStructManip.c	(revision 4539)
+++ /trunk/psLib/src/imageops/psImageStructManip.c	(revision 4540)
@@ -8,6 +8,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-05-19 05:18:20 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -31,5 +31,15 @@
 {
     psU32 elementSize;          // size of image element in bytes
-    psU32 inputColOffset;       // offset in bytes to first subset pixel in input row
+    psS32 inputColOffset;       // offset in bytes to first subset pixel in input row
+
+    if ( col0 < 0 || row0 < 0 ) {
+        //        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+        //                PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID);
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
+                col0, col1-1, row0, row1-1,
+                image->numCols-1, image->numRows-1);
+        return NULL;
+    }
 
     if (image == NULL || image->data.V == NULL) {
@@ -64,4 +74,7 @@
         return NULL;
     }
+
+
+
     psS32 numRows = row1-row0;
     psS32 numCols = col1-col0;
@@ -94,7 +107,9 @@
 
     out->data.V = psRealloc(out->data.V,sizeof(psPtr)*numRows); // resize row pointer array
-    *(psType*)&out->type = image->type;
-    *(psU32*)&out->numCols = numCols;
-    *(psU32*)&out->numRows = numRows;
+    *(psMathType*)&out->type = image->type;
+    //    *(psU32*)&out->numCols = numCols;
+    //    *(psU32*)&out->numRows = numRows;
+    *(psS32*)&out->numCols = numCols;
+    *(psS32*)&out->numRows = numRows;
     *(psS32*)&out->row0 = row0;
     *(psS32*)&out->col0 = col0;
Index: /trunk/psLib/src/math/Makefile.am
===================================================================
--- /trunk/psLib/src/math/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/math/Makefile.am	(revision 4540)
@@ -1,38 +1,27 @@
-#Makefile for dataManip functions of psLib
+#Makefile for math functions of psLib
 #
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+noinst_LTLIBRARIES = libpslibmath.la
 
-noinst_LTLIBRARIES = libpslibdataManip.la
+libpslibmath_la_SOURCES = \
+	psBinaryOp.c \
+	psCompare.c \
+	psMatrix.c \
+	psMinimize.c \
+	psRandom.c \
+	psFunctions.c \
+	psStats.c \
+	psUnaryOp.c
 
-libpslibdataManip_la_SOURCES = psUnaryOp.c psBinaryOp.c psStats.c \
-		psFunctions.c psMatrix.c psVectorFFT.c psMinimize.c psRandom.c
-
-BUILT_SOURCES = psDataManipErrors.h
-EXTRA_DIST = psDataManipErrors.dat psDataManipErrors.h dataManip.i
-
-psDataManipErrors.h: psDataManipErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = math.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
+	psBinaryOp.h \
+	psCompare.h \
 	psConstants.h \
-	psStats.h  \
+	psMatrix.h \
+	psMinimize.h \
+	psRandom.h \
 	psFunctions.h \
-	psMatrix.h \
-    psBinaryOp.h \
-    psUnaryOp.h \
-	psVectorFFT.h \
-	psMinimize.h \
-	psRandom.h
-
+	psStats.h \
+	psUnaryOp.h
Index: /trunk/psLib/src/math/math.i
===================================================================
--- /trunk/psLib/src/math/math.i	(revision 4540)
+++ /trunk/psLib/src/math/math.i	(revision 4540)
@@ -0,0 +1,11 @@
+/* math headers */
+
+%include "psBinaryOp.h"
+%include "psCompare.h"
+%include "psConstants.h"
+%include "psMatrix.h"
+%include "psMinimize.h"
+%include "psFunctions.h"
+%include "psRandom.h"
+%include "psStats.h"
+%include "psUnaryOp.h"
Index: /trunk/psLib/src/math/psBinaryOp.c
===================================================================
--- /trunk/psLib/src/math/psBinaryOp.c	(revision 4539)
+++ /trunk/psLib/src/math/psBinaryOp.c	(revision 4540)
@@ -30,6 +30,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-22 02:05:41 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -50,5 +50,5 @@
 #include "psLogMsg.h"
 #include "psConstants.h"
-#include "psDataManipErrors.h"
+#include "psErrorText.h"
 
 /*****************************************************************************
@@ -426,5 +426,5 @@
 }
 
-psPtr psBinaryOp(psPtr out, const psPtr in1, const char *op, const psPtr in2)
+psMathType* psBinaryOp(psPtr out, const psPtr in1, const char *op, const psPtr in2)
 {
 
Index: /trunk/psLib/src/math/psBinaryOp.h
===================================================================
--- /trunk/psLib/src/math/psBinaryOp.h	(revision 4539)
+++ /trunk/psLib/src/math/psBinaryOp.h	(revision 4540)
@@ -30,6 +30,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-22 02:05:41 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -55,5 +55,5 @@
  *  @return  psType* : Pointer to either psImage or psVector.
  */
-psType* psBinaryOp(
+psMathType* psBinaryOp(
     psPtr out,                         ///< Output type, either psImage or psVector.
     const psPtr in1,                   ///< First input, either psImage or psVector.
Index: /trunk/psLib/src/math/psFunctions.c
===================================================================
--- /trunk/psLib/src/math/psFunctions.c	(revision 4540)
+++ /trunk/psLib/src/math/psFunctions.c	(revision 4540)
@@ -0,0 +1,2201 @@
+/** @file  psFunctions.c
+ *
+ *  @brief Contains basic function allocation, deallocation, and evaluation
+ *         routines.
+ *
+ *  This file will hold the functions for allocated, freeing, and evaluating
+ *  polynomials.  It also contains a Gaussian functions.
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ *
+ *  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
+ *
+ *  XXX: In the various polyAlloc(n) functions, n is really the order of the
+ *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
+ */
+/*****************************************************************************/
+/*  INCLUDE FILES                                                            */
+/*****************************************************************************/
+#include <gsl/gsl_rng.h>
+#include <gsl/gsl_randist.h>
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <float.h>
+#include <math.h>
+
+#include "psMemory.h"
+#include "psVector.h"
+#include "psScalar.h"
+#include "psTrace.h"
+#include "psError.h"
+#include "psLogMsg.h"
+#include "psFunctions.h"
+#include "psConstants.h"
+
+#include "psErrorText.h"
+
+/*****************************************************************************/
+/* DEFINE STATEMENTS                                                         */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* TYPE DEFINITIONS                                                          */
+/*****************************************************************************/
+static void polynomial1DFree(psPolynomial1D* poly);
+static void polynomial2DFree(psPolynomial2D* poly);
+static void polynomial3DFree(psPolynomial3D* poly);
+static void polynomial4DFree(psPolynomial4D* poly);
+static void dPolynomial1DFree(psDPolynomial1D* poly);
+static void dPolynomial2DFree(psDPolynomial2D* poly);
+static void dPolynomial3DFree(psDPolynomial3D* poly);
+static void dPolynomial4DFree(psDPolynomial4D* poly);
+static void spline1DFree(psSpline1D *tmpSpline);
+static psS32 vectorBinDisectF32(psF32 *bins,psS32 numBins,psF32 x);
+static psS32 vectorBinDisectS32(psS32 *bins,psS32 numBins,psS32 x);
+
+/*****************************************************************************/
+/* GLOBAL VARIABLES                                                          */
+/*****************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/* FILE STATIC VARIABLES                                                     */
+/*****************************************************************************/
+
+// None
+
+/*****************************************************************************/
+/* FUNCTION IMPLEMENTATION - LOCAL                                           */
+/*****************************************************************************/
+
+static void spline1DFree(psSpline1D *tmpSpline)
+{
+    psS32 i;
+
+    if (tmpSpline == NULL) {
+        return;
+    }
+
+    if (tmpSpline->spline != NULL) {
+        for (i=0;i<tmpSpline->n;i++) {
+            psFree((tmpSpline->spline)[i]);
+        }
+        psFree(tmpSpline->spline);
+    }
+
+    if (tmpSpline->p_psDeriv2 != NULL) {
+        psFree(tmpSpline->p_psDeriv2);
+    }
+    psFree(tmpSpline->knots);
+
+    return;
+}
+
+static void polynomial1DFree(psPolynomial1D* poly)
+{
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+static void polynomial2DFree(psPolynomial2D* poly)
+{
+    unsigned int x = 0;
+
+    for (x = 0; x < poly->nX; x++) {
+        psFree(poly->coeff[x]);
+        psFree(poly->coeffErr[x]);
+        psFree(poly->mask[x]);
+    }
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+static void polynomial3DFree(psPolynomial3D* poly)
+{
+    unsigned int x = 0;
+    unsigned int y = 0;
+
+    for (x = 0; x < poly->nX; x++) {
+        for (y = 0; y < poly->nY; y++) {
+            psFree(poly->coeff[x][y]);
+            psFree(poly->coeffErr[x][y]);
+            psFree(poly->mask[x][y]);
+        }
+        psFree(poly->coeff[x]);
+        psFree(poly->coeffErr[x]);
+        psFree(poly->mask[x]);
+    }
+
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+static void polynomial4DFree(psPolynomial4D* poly)
+{
+    unsigned int x = 0;
+    unsigned int y = 0;
+    unsigned int z = 0;
+
+    for (x = 0; x < poly->nX; x++) {
+        for (y = 0; y < poly->nY; y++) {
+            for (z = 0; z < poly->nZ; z++) {
+                psFree(poly->coeff[x][y][z]);
+                psFree(poly->coeffErr[x][y][z]);
+                psFree(poly->mask[x][y][z]);
+            }
+            psFree(poly->coeff[x][y]);
+            psFree(poly->coeffErr[x][y]);
+            psFree(poly->mask[x][y]);
+        }
+        psFree(poly->coeff[x]);
+        psFree(poly->coeffErr[x]);
+        psFree(poly->mask[x]);
+    }
+
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+static void dPolynomial1DFree(psDPolynomial1D* poly)
+{
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+static void dPolynomial2DFree(psDPolynomial2D* poly)
+{
+    for (unsigned int x = 0; x < poly->nX; x++) {
+        psFree(poly->coeff[x]);
+        psFree(poly->coeffErr[x]);
+        psFree(poly->mask[x]);
+    }
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+static void dPolynomial3DFree(psDPolynomial3D* poly)
+{
+    unsigned int x = 0;
+    unsigned int y = 0;
+
+    for (x = 0; x < poly->nX; x++) {
+        for (y = 0; y < poly->nY; y++) {
+            psFree(poly->coeff[x][y]);
+            psFree(poly->coeffErr[x][y]);
+            psFree(poly->mask[x][y]);
+        }
+        psFree(poly->coeff[x]);
+        psFree(poly->coeffErr[x]);
+        psFree(poly->mask[x]);
+    }
+
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+static void dPolynomial4DFree(psDPolynomial4D* poly)
+{
+    unsigned int x = 0;
+    unsigned int y = 0;
+    unsigned int z = 0;
+
+    for (x = 0; x < poly->nX; x++) {
+        for (y = 0; y < poly->nY; y++) {
+            for (z = 0; z < poly->nZ; z++) {
+                psFree(poly->coeff[x][y][z]);
+                psFree(poly->coeffErr[x][y][z]);
+                psFree(poly->mask[x][y][z]);
+            }
+            psFree(poly->coeff[x][y]);
+            psFree(poly->coeffErr[x][y]);
+            psFree(poly->mask[x][y]);
+        }
+        psFree(poly->coeff[x]);
+        psFree(poly->coeffErr[x]);
+        psFree(poly->mask[x]);
+    }
+
+    psFree(poly->coeff);
+    psFree(poly->coeffErr);
+    psFree(poly->mask);
+}
+
+/*****************************************************************************
+createChebyshevPolys(n): this routine takes as input the required order n,
+and returns as output as a pointer to an array of n psPolynomial1D
+structures, corresponding to the first n Chebyshev polynomials.
+ 
+XXX: The output should be static since the Chebyshev polynomials might be
+used frequently and the data structure created here does not contain the
+outer coefficients of the Chebyshev polynomials.
+ *****************************************************************************/
+static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly)
+{
+    PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);
+
+    psPolynomial1D **chebPolys = NULL;
+
+    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
+    for (psS32 i = 0; i < maxChebyPoly; i++) {
+        chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
+    }
+
+    // Create the Chebyshev polynomials.
+    // Polynomial i has i-th order.
+    chebPolys[0]->coeff[0] = 1;
+
+    // XXX: Bug 296
+    if (maxChebyPoly > 1) {
+        chebPolys[1]->coeff[1] = 1;
+
+        for (psS32 i = 2; i < maxChebyPoly; i++) {
+            for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
+                chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
+            }
+            for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
+                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
+            }
+        }
+    } else {
+        // XXX: Code this.
+        printf("WARNING: %d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
+    }
+
+    return (chebPolys);
+}
+
+/*****************************************************************************
+    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
+ *****************************************************************************/
+static psF64 ordPolynomial1DEval(psF64 x, const psPolynomial1D* poly)
+{
+    psS32 loop_x = 0;
+    psF32 polySum = 0.0;
+    psF32 xSum = 1.0;
+
+    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
+            "---- Calling ordPolynomial1DEval(%f)\n", x);
+    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
+            "Polynomial order is %d\n", poly->n);
+    for (loop_x = 0; loop_x < poly->n; loop_x++) {
+        psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
+                "Polynomial coeff[%d] is %f\n", loop_x, poly->coeff[loop_x]);
+    }
+
+    for (loop_x = 0; loop_x < poly->n; loop_x++) {
+        if (poly->mask[loop_x] == 0) {
+            psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 10,
+                    "polysum+= sum*coeff [%f+= (%f * %f)\n", polySum, xSum, poly->coeff[loop_x]);
+            polySum += xSum * poly->coeff[loop_x];
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+// XXX: You can do this without having to psAlloc() vector d.
+// XXX: How does the mask vector effect Crenshaw's formula?
+// XXX: We assume that x is scaled between -1.0 and 1.0;
+static psF64 chebPolynomial1DEval(psF64 x, const psPolynomial1D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    // XXX: Create a macro for this in psConstants.h
+    if (poly->n < 1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %d.", poly->n);
+        return(NAN);
+    }
+    psVector *d;
+    psS32 n = poly->n;
+    psS32 i;
+    psF32 tmp = 0.0;
+
+    // Special case where the Chebyshev poly is constant.
+    if (n == 1) {
+        if (poly->mask[0] == 0) {
+            tmp += poly->coeff[0];
+        }
+        return(tmp);
+    }
+
+    // Special case where the Chebyshev poly is linear.
+    if (n == 2) {
+        if (poly->mask[0] == 0) {
+            tmp+= poly->coeff[0];
+        }
+        if (poly->mask[1] == 0) {
+            tmp+= poly->coeff[1] * x;
+        }
+        return(tmp);
+    }
+
+    // General case where the Chebyshev poly has 2 or more terms.
+    d = psVectorAlloc(n, PS_TYPE_F32);
+    if(poly->mask[n-1] == 0) {
+        d->data.F32[n-1] = poly->coeff[n-1];
+    } else {
+        d->data.F32[n-1] = 0.0;
+    }
+
+    d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]);
+    if(poly->mask[n-2] == 0) {
+        d->data.F32[n-2] += poly->coeff[n-2];
+    }
+
+    for (i=n-3;i>=1;i--) {
+        d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
+                         (d->data.F32[i+2]);
+        if(poly->mask[i] == 0) {
+            d->data.F32[i] += poly->coeff[i];
+        }
+    }
+
+    tmp = (x * d->data.F32[1]) -
+          (d->data.F32[2]);
+    if(poly->mask[0] == 0) {
+        tmp += (0.5 * poly->coeff[0]);
+    }
+    psFree(d);
+    return(tmp);
+
+    /* This is old code that does not use Clenshaw's formula.  Get rid of it.
+
+    psS32 n;
+    psS32 i;
+    psF32 tmp;
+    psPolynomial1D **chebPolys = NULL;
+
+    n = poly->n;
+    chebPolys = createChebyshevPolys(n);
+
+    tmp = 0.0;
+    for (i=0;i<poly->n;i++) {
+        tmp+= (poly->coeff[i] * psPolynomial1DEval(x, chebPolys[i]));
+    }
+    tmp-= (poly->coeff[0]/2.0);
+
+
+    return(tmp);
+    */
+}
+
+static psF64 ordPolynomial2DEval(psF64 x,
+                                 psF64 y,
+                                 const psPolynomial2D* poly)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psF32 polySum = 0.0;
+    psF32 xSum = 1.0;
+    psF32 ySum = 1.0;
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        ySum = xSum;
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            if (poly->mask[loop_x][loop_y] == 0) {
+                polySum += ySum * poly->coeff[loop_x][loop_y];
+            }
+            ySum *= y;
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+static psF64 chebPolynomial2DEval(psF64 x, psF64 y, const psPolynomial2D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 i = 0;
+    psF32 polySum = 0.0;
+    psPolynomial1D* *chebPolys = NULL;
+    psS32 maxChebyPoly = 0;
+
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
+    maxChebyPoly = poly->nX;
+    if (poly->nY > maxChebyPoly) {
+        maxChebyPoly = poly->nY;
+    }
+    chebPolys = createChebyshevPolys(maxChebyPoly);
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            if (poly->mask[loop_x][loop_y] == 0) {
+                polySum += poly->coeff[loop_x][loop_y] *
+                           psPolynomial1DEval(chebPolys[loop_x], x) *
+                           psPolynomial1DEval(chebPolys[loop_y], y);
+            }
+        }
+    }
+    for (i=0;i<maxChebyPoly;i++) {
+        psFree(chebPolys[i]);
+    }
+    psFree(chebPolys);
+    return(polySum);
+}
+
+static psF64 ordPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psPolynomial3D* poly)
+{
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psF32 polySum = 0.0;
+    psF32 xSum = 1.0;
+    psF32 ySum = 1.0;
+    psF32 zSum = 1.0;
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        ySum = xSum;
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            zSum = ySum;
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
+                    polySum += zSum * poly->coeff[loop_x][loop_y][loop_z];
+                }
+                zSum *= z;
+            }
+            ySum *= y;
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+static psF64 chebPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psPolynomial3D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psS32 i = 0;
+    psF32 polySum = 0.0;
+    psPolynomial1D* *chebPolys = NULL;
+    psS32 maxChebyPoly = 0;
+
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
+    maxChebyPoly = poly->nX;
+    if (poly->nY > maxChebyPoly) {
+        maxChebyPoly = poly->nY;
+    }
+    if (poly->nZ > maxChebyPoly) {
+        maxChebyPoly = poly->nZ;
+    }
+    chebPolys = createChebyshevPolys(maxChebyPoly);
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
+                    polySum += poly->coeff[loop_x][loop_y][loop_z] *
+                               psPolynomial1DEval(chebPolys[loop_x], x) *
+                               psPolynomial1DEval(chebPolys[loop_y], y) *
+                               psPolynomial1DEval(chebPolys[loop_z], z);
+                }
+            }
+        }
+    }
+
+    for (i=0;i<maxChebyPoly;i++) {
+        psFree(chebPolys[i]);
+    }
+    psFree(chebPolys);
+    return(polySum);
+}
+
+static psF64 ordPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psPolynomial4D* poly)
+{
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psS32 loop_t = 0;
+    psF32 polySum = 0.0;
+    psF32 xSum = 1.0;
+    psF32 ySum = 1.0;
+    psF32 zSum = 1.0;
+    psF32 tSum = 1.0;
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        ySum = xSum;
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            zSum = ySum;
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                tSum = zSum;
+                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
+                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
+                        polySum += tSum * poly->coeff[loop_x][loop_y][loop_z][loop_t];
+                    }
+                    tSum *= t;
+                }
+                zSum *= z;
+            }
+            ySum *= y;
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+static psF64 chebPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psPolynomial4D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(t, -1.0, 1.0, 0.0);
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psS32 loop_t = 0;
+    psS32 i = 0;
+    psF32 polySum = 0.0;
+    psPolynomial1D* *chebPolys = NULL;
+    psS32 maxChebyPoly = 0;
+
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
+    maxChebyPoly = poly->nX;
+    if (poly->nY > maxChebyPoly) {
+        maxChebyPoly = poly->nY;
+    }
+    if (poly->nZ > maxChebyPoly) {
+        maxChebyPoly = poly->nZ;
+    }
+    if (poly->nT > maxChebyPoly) {
+        maxChebyPoly = poly->nT;
+    }
+    chebPolys = createChebyshevPolys(maxChebyPoly);
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
+                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
+                        polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] *
+                                   psPolynomial1DEval(chebPolys[loop_x], x) *
+                                   psPolynomial1DEval(chebPolys[loop_y], y) *
+                                   psPolynomial1DEval(chebPolys[loop_z], z) *
+                                   psPolynomial1DEval(chebPolys[loop_t], t);
+                    }
+                }
+            }
+        }
+    }
+
+    for (i=0;i<maxChebyPoly;i++) {
+        psFree(chebPolys[i]);
+    }
+    psFree(chebPolys);
+    return(polySum);
+}
+
+/*****************************************************************************
+    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
+ *****************************************************************************/
+static psF64 dOrdPolynomial1DEval(psF64 x, const psDPolynomial1D* poly)
+{
+    psS32 loop_x = 0;
+    psF64 polySum = 0.0;
+    psF64 xSum = 1.0;
+
+    for (loop_x = 0; loop_x < poly->n; loop_x++) {
+        if (poly->mask[loop_x] == 0) {
+            polySum += xSum * poly->coeff[loop_x];
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+// XXX: You can do this without having to psAlloc() vector d.
+// XXX: How does the mask vector effect Crenshaw's formula?
+static psF64 dChebPolynomial1DEval(psF64 x, const psDPolynomial1D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    psVector *d;
+    psS32 n;
+    psS32 i;
+    psF64 tmp;
+
+    n = poly->n;
+    d = psVectorAlloc(n, PS_TYPE_F64);
+    if(poly->mask[n-1] == 0) {
+        d->data.F64[n-1] = poly->coeff[n-1];
+    } else {
+        d->data.F64[n-1] = 0.0;
+    }
+    d->data.F64[n-2] = (2.0 * x * d->data.F64[n-1]);
+    if(poly->mask[n-2] == 0) {
+        d->data.F64[n-2] += poly->coeff[n-2];
+    }
+    for (i=n-3;i>=1;i--) {
+        d->data.F64[i] = (2.0 * x * d->data.F64[i+1]) -
+                         (d->data.F64[i+2]);
+        if(poly->mask[i] == 0) {
+            d->data.F64[i] += poly->coeff[i];
+        }
+    }
+
+    tmp = (x * d->data.F64[1]) -
+          (d->data.F64[2]);
+    if(poly->mask[0] == 0) {
+        tmp += (0.5 * poly->coeff[0]);
+    }
+
+    psFree(d);
+    return(tmp);
+}
+
+static psF64 dOrdPolynomial2DEval(psF64 x,
+                                  psF64 y,
+                                  const psDPolynomial2D* poly)
+{
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psF64 polySum = 0.0;
+    psF64 xSum = 1.0;
+    psF64 ySum = 1.0;
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        ySum = xSum;
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            if (poly->mask[loop_x][loop_y] == 0) {
+                polySum += ySum * poly->coeff[loop_x][loop_y];
+            }
+            ySum *= y;
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+static psF64 dChebPolynomial2DEval(psF64 x, psF64 y, const psDPolynomial2D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 i = 0;
+    psF64 polySum = 0.0;
+    psPolynomial1D* *chebPolys = NULL;
+    psS32 maxChebyPoly = 0;
+
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
+    maxChebyPoly = poly->nX;
+    if (poly->nY > maxChebyPoly) {
+        maxChebyPoly = poly->nY;
+    }
+    chebPolys = createChebyshevPolys(maxChebyPoly);
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            if (poly->mask[loop_x][loop_y] == 0) {
+                polySum += poly->coeff[loop_x][loop_y] *
+                           psPolynomial1DEval(chebPolys[loop_x], x) *
+                           psPolynomial1DEval(chebPolys[loop_y], y);
+            }
+        }
+    }
+
+    for (i=0;i<maxChebyPoly;i++) {
+        psFree(chebPolys[i]);
+    }
+    psFree(chebPolys);
+    return(polySum);
+}
+
+static psF64 dOrdPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psDPolynomial3D* poly)
+{
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psF64 polySum = 0.0;
+    psF64 xSum = 1.0;
+    psF64 ySum = 1.0;
+    psF64 zSum = 1.0;
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        ySum = xSum;
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            zSum = ySum;
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
+                    polySum += zSum * poly->coeff[loop_x][loop_y][loop_z];
+                }
+                zSum *= z;
+            }
+            ySum *= y;
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+static psF64 dChebPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psDPolynomial3D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psS32 i = 0;
+    psF64 polySum = 0.0;
+    psPolynomial1D* *chebPolys = NULL;
+    psS32 maxChebyPoly = 0;
+
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
+    maxChebyPoly = poly->nX;
+    if (poly->nY > maxChebyPoly) {
+        maxChebyPoly = poly->nY;
+    }
+    if (poly->nZ > maxChebyPoly) {
+        maxChebyPoly = poly->nZ;
+    }
+    chebPolys = createChebyshevPolys(maxChebyPoly);
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
+                    polySum += poly->coeff[loop_x][loop_y][loop_z] *
+                               psPolynomial1DEval(chebPolys[loop_x], x) *
+                               psPolynomial1DEval(chebPolys[loop_y], y) *
+                               psPolynomial1DEval(chebPolys[loop_z], z);
+                }
+            }
+        }
+    }
+
+    for (i=0;i<maxChebyPoly;i++) {
+        psFree(chebPolys[i]);
+    }
+    psFree(chebPolys);
+    return(polySum);
+}
+
+static psF64 dOrdPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psDPolynomial4D* poly)
+{
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psS32 loop_t = 0;
+    psF64 polySum = 0.0;
+    psF64 xSum = 1.0;
+    psF64 ySum = 1.0;
+    psF64 zSum = 1.0;
+    psF64 tSum = 1.0;
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        ySum = xSum;
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            zSum = ySum;
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                tSum = zSum;
+                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
+                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
+                        polySum += tSum * poly->coeff[loop_x][loop_y][loop_z][loop_t];
+                    }
+                    tSum *= t;
+                }
+                zSum *= z;
+            }
+            ySum *= y;
+        }
+        xSum *= x;
+    }
+
+    return(polySum);
+}
+
+static psF64 dChebPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psDPolynomial4D* poly)
+{
+    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
+    PS_ASSERT_FLOAT_WITHIN_RANGE(t, -1.0, 1.0, 0.0);
+    psS32 loop_x = 0;
+    psS32 loop_y = 0;
+    psS32 loop_z = 0;
+    psS32 loop_t = 0;
+    psS32 i = 0;
+    psF64 polySum = 0.0;
+    psPolynomial1D* *chebPolys = NULL;
+    psS32 maxChebyPoly = 0;
+
+    // Determine how many Chebyshev polynomials
+    // are needed, then create them.
+    maxChebyPoly = poly->nX;
+    if (poly->nY > maxChebyPoly) {
+        maxChebyPoly = poly->nY;
+    }
+    if (poly->nZ > maxChebyPoly) {
+        maxChebyPoly = poly->nZ;
+    }
+    if (poly->nT > maxChebyPoly) {
+        maxChebyPoly = poly->nT;
+    }
+    chebPolys = createChebyshevPolys(maxChebyPoly);
+
+    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
+        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
+            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
+                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
+                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
+                        polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] *
+                                   psPolynomial1DEval(chebPolys[loop_x], x) *
+                                   psPolynomial1DEval(chebPolys[loop_y], y) *
+                                   psPolynomial1DEval(chebPolys[loop_z], z) *
+                                   psPolynomial1DEval(chebPolys[loop_t], t);
+                    }
+                }
+            }
+        }
+    }
+
+    for (i=0;i<maxChebyPoly;i++) {
+        psFree(chebPolys[i]);
+    }
+    psFree(chebPolys);
+    return(polySum);
+}
+
+
+/*****************************************************************************
+fullInterpolate1DF32(): This routine will take as input n-element floating
+point arrays domain and range, and the x value, assumed to lie with the
+domain vector.  It produces as output the (n-1)-order LaGrange interpolated
+value of x.
+ 
+XXX: do we error check for non-distinct domain values?
+ *****************************************************************************/
+#define FUNC_MACRO_FULL_INTERPOLATE_1D(TYPE) \
+static psF32 fullInterpolate1D##TYPE(ps##TYPE *domain, \
+                                     ps##TYPE *range, \
+                                     psS32 n, \
+                                     ps##TYPE x) \
+{ \
+    \
+    psS32 i; \
+    psS32 m; \
+    static psVector *p = NULL; \
+    p = psVectorRecycle(p, n, PS_TYPE_##TYPE); \
+    p_psMemSetPersistent(p, true); \
+    p_psMemSetPersistent(p->data.TYPE, true); \
+    \
+    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 4, \
+            "---- fullInterpolate1D##TYPE() begin (%d-order at x=%f) (%d data points)----\n", n-1, x, n); \
+    \
+    for (i=0;i<n;i++) { \
+        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
+                "domain/range is (%f %f)\n", domain[i], range[i]); \
+    } \
+    \
+    for (i=0;i<n;i++) { \
+        p->data.TYPE[i] = range[i]; \
+        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
+                "p->data.TYPE[%d] is %f\n", i, p->data.TYPE[i]); \
+        \
+    } \
+    \
+    /* From NR, during each iteration of the m loop, we are computing the \
+       p_{i ... i+m} terms. \
+    */ \
+    for (m=1;m<n;m++) { \
+        for (i=0;i<n-m;i++) { \
+            /* From NR: we are computing P_{i ... i+m} \
+             */ \
+            p->data.TYPE[i] = (((x-domain[i+m]) * p->data.TYPE[i]) + \
+                               ((domain[i]-x) * p->data.TYPE[i+1])) / \
+                              (domain[i] - domain[i+m]); \
+            /*printf("((%f-%f * %f) + (%f-%f * %f)) / (%f - %f)\n", x, domain[i+m], p->data.TYPE[i], domain[i], x, p->data.TYPE[i+1], domain[i], domain[i+m]); \
+             */ \
+            psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
+                    "p->data.TYPE[%d] is %f\n", i, p->data.TYPE[i]); \
+        } \
+    } \
+    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 4, \
+            "---- fullInterpolate1D##TYPE() end ----\n"); \
+    \
+    return(p->data.TYPE[0]); \
+} \
+
+/*
+FUNC_MACRO_FULL_INTERPOLATE_1D(U8)
+FUNC_MACRO_FULL_INTERPOLATE_1D(U16)
+FUNC_MACRO_FULL_INTERPOLATE_1D(U32)
+FUNC_MACRO_FULL_INTERPOLATE_1D(U64)
+FUNC_MACRO_FULL_INTERPOLATE_1D(S8)
+FUNC_MACRO_FULL_INTERPOLATE_1D(S16)
+FUNC_MACRO_FULL_INTERPOLATE_1D(S32)
+FUNC_MACRO_FULL_INTERPOLATE_1D(S64)
+FUNC_MACRO_FULL_INTERPOLATE_1D(F64)
+*/
+FUNC_MACRO_FULL_INTERPOLATE_1D(F32)
+
+
+/*****************************************************************************
+interpolate1DF32(): this is the base 1-D flat memory routine to perform
+LaGrange interpolation.
+ *****************************************************************************/
+static psF32 interpolate1DF32(psF32 *domain,
+                              psF32 *range,
+                              psS32 n,
+                              psS32 order,
+                              psF32 x)
+{
+    PS_ASSERT_PTR_NON_NULL(domain, NAN)
+    PS_ASSERT_PTR_NON_NULL(range, NAN)
+    // XXX: Check valid values for n, order, and x?
+
+    psS32 binNum;
+    psS32 numIntPoints = order+1;
+    psS32 origin;
+
+    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
+            "---- interpolate1DF32() begin ----\n");
+
+    binNum = vectorBinDisectF32(domain, n, x);
+
+    if (0 == numIntPoints%2) {
+        origin = binNum - ((numIntPoints/2) - 1);
+    } else {
+        origin = binNum - (numIntPoints/2);
+        if ((x-domain[binNum]) > (domain[binNum+1]-x)) {
+            // x is closer to binNum+1.
+            origin = 1 + (binNum - (numIntPoints/2));
+        }
+    }
+    if (origin < 0) {
+        origin = 0;
+    }
+    if ((origin + numIntPoints) > n) {
+        origin = n - numIntPoints;
+    }
+
+    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
+            "---- interpolate1DF32() end ----\n");
+    return(fullInterpolate1DF32(&domain[origin], &range[origin], order+1, x));
+}
+
+/*****************************************************************************/
+/*  FUNCTION IMPLEMENTATION - PUBLIC                                         */
+/*****************************************************************************/
+
+/*****************************************************************************
+    Evaluate a non-normalized Gaussian with the given mean and sigma at the
+    given coordianate.  Note that this is not a Gaussian deviate.  The
+    evaluated Gaussian is: \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
+ *****************************************************************************/
+float psGaussian(float x, float mean, float sigma, bool normal)
+{
+    psF32 tmp = 1.0;
+
+    psTrace(".psLib.dataManip.psFunctions.psGaussian", 4,
+            "---- psGaussian() begin ----\n");
+
+    if (normal == true) {
+        tmp = 1.0 / sqrtf(2.0 * M_PI * (sigma * sigma));
+    }
+
+    psTrace(".psLib.dataManip.psFunctions.psGaussian", 4,
+            "---- psGaussian() end ----\n");
+    return(tmp * exp(-((x - mean) * (x - mean)) / (2.0 * sigma * sigma)));
+}
+
+/*****************************************************************************
+    p_psGaussianDev()
+ This private routine (formerly a psLib API routine) creates a psVector of the
+ specified size and type F32 and fills it with a random Gaussian distribution
+ of numbers with the specified mean and sigma.  This routine makes use of the
+ GSL routines for generating both uniformly distributed numbers and the
+ Gaussian distribution as well.
+ 
+XXX: There is no way to seed the random generator.
+ *****************************************************************************/
+psVector* p_psGaussianDev(psF32 mean, psF32 sigma, psS32 Npts)
+{
+    PS_ASSERT_INT_NONNEGATIVE(Npts, NULL);
+
+    psVector* gauss = NULL;
+    const gsl_rng_type *T = NULL;
+    gsl_rng *r = NULL;
+    psS32 i = 0;
+
+
+    gauss = psVectorAlloc(Npts, PS_TYPE_F32);
+    gauss->n = Npts;
+    gsl_rng_env_setup();
+    T = gsl_rng_default;
+    r = gsl_rng_alloc(T);
+
+    for (i = 0; i < Npts; i++) {
+        gauss->data.F32[i] = mean + gsl_ran_gaussian(r, sigma);
+    }
+
+    // XXX: Should I free r, T as well?  This is a memory leak.
+    return(gauss);
+}
+
+/*****************************************************************************
+    This routine must allocate memory for the polynomial structures.
+ *****************************************************************************/
+psPolynomial1D* psPolynomial1DAlloc(int n,
+                                    psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(n, NULL);
+
+    int i = 0;
+    psPolynomial1D* newPoly = NULL;
+
+    newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree);
+
+    newPoly->type = type;
+    newPoly->n = n;
+    newPoly->coeff = (psF32 *)psAlloc(n * sizeof(psF32));
+    newPoly->coeffErr = (psF32 *)psAlloc(n * sizeof(psF32));
+    newPoly->mask = (char *)psAlloc(n * sizeof(char));
+    for (i = 0; i < n; i++) {
+        newPoly->coeff[i] = 0.0;
+        newPoly->coeffErr[i] = 0.0;
+        newPoly->mask[i] = 0;
+    }
+
+    return(newPoly);
+}
+
+psPolynomial2D* psPolynomial2DAlloc( int nX,  int nY,
+                                     psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(nX, NULL);
+    PS_ASSERT_INT_POSITIVE(nY, NULL);
+
+    int x = 0;
+    int y = 0;
+    psPolynomial2D* newPoly = NULL;
+
+    newPoly = (psPolynomial2D* ) psAlloc(sizeof(psPolynomial2D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial2DFree);
+
+    newPoly->type = type;
+    newPoly->nX = nX;
+    newPoly->nY = nY;
+
+    newPoly->coeff = (psF32 **)psAlloc(nX * sizeof(psF32 *));
+    newPoly->coeffErr = (psF32 **)psAlloc(nX * sizeof(psF32 *));
+    newPoly->mask = (char **)psAlloc(nX * sizeof(char *));
+    for (x = 0; x < nX; x++) {
+        newPoly->coeff[x] = (psF32 *)psAlloc(nY * sizeof(psF32));
+        newPoly->coeffErr[x] = (psF32 *)psAlloc(nY * sizeof(psF32));
+        newPoly->mask[x] = (char *)psAlloc(nY * sizeof(char));
+    }
+    for (x = 0; x < nX; x++) {
+        for (y = 0; y < nY; y++) {
+            newPoly->coeff[x][y] = 0.0;
+            newPoly->coeffErr[x][y] = 0.0;
+            newPoly->mask[x][y] = 0;
+        }
+    }
+
+    return(newPoly);
+}
+
+psPolynomial3D* psPolynomial3DAlloc( int nX,  int nY,  int nZ,
+                                     psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(nX, NULL);
+    PS_ASSERT_INT_POSITIVE(nY, NULL);
+    PS_ASSERT_INT_POSITIVE(nZ, NULL);
+
+    psS32 x = 0;
+    psS32 y = 0;
+    psS32 z = 0;
+    psPolynomial3D* newPoly = NULL;
+
+    newPoly = (psPolynomial3D* ) psAlloc(sizeof(psPolynomial3D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial3DFree);
+
+    newPoly->type = type;
+    newPoly->nX = nX;
+    newPoly->nY = nY;
+    newPoly->nZ = nZ;
+
+    newPoly->coeff = (psF32 ***)psAlloc(nX * sizeof(psF32 **));
+    newPoly->coeffErr = (psF32 ***)psAlloc(nX * sizeof(psF32 **));
+    newPoly->mask = (char ***)psAlloc(nX * sizeof(char **));
+    for (x = 0; x < nX; x++) {
+        newPoly->coeff[x] = (psF32 **)psAlloc(nY * sizeof(psF32 *));
+        newPoly->coeffErr[x] = (psF32 **)psAlloc(nY * sizeof(psF32 *));
+        newPoly->mask[x] = (char **)psAlloc(nY * sizeof(char *));
+        for (y = 0; y < nY; y++) {
+            newPoly->coeff[x][y] = (psF32 *)psAlloc(nZ * sizeof(psF32));
+            newPoly->coeffErr[x][y] = (psF32 *)psAlloc(nZ * sizeof(psF32));
+            newPoly->mask[x][y] = (char *)psAlloc(nZ * sizeof(char));
+        }
+    }
+    for (x = 0; x < nX; x++) {
+        for (y = 0; y < nY; y++) {
+            for (z = 0; z < nZ; z++) {
+                newPoly->coeff[x][y][z] = 0.0;
+                newPoly->coeffErr[x][y][z] = 0.0;
+                newPoly->mask[x][y][z] = 0;
+            }
+        }
+    }
+
+    return(newPoly);
+}
+
+psPolynomial4D* psPolynomial4DAlloc( int nX,  int nY,  int nZ,  int nT,
+                                     psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(nX, NULL);
+    PS_ASSERT_INT_POSITIVE(nY, NULL);
+    PS_ASSERT_INT_POSITIVE(nZ, NULL);
+    PS_ASSERT_INT_POSITIVE(nT, NULL);
+
+    psS32 x = 0;
+    psS32 y = 0;
+    psS32 z = 0;
+    psS32 t = 0;
+    psPolynomial4D* newPoly = NULL;
+
+    newPoly = (psPolynomial4D* ) psAlloc(sizeof(psPolynomial4D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial4DFree);
+
+    newPoly->type = type;
+    newPoly->nX = nX;
+    newPoly->nY = nY;
+    newPoly->nZ = nZ;
+    newPoly->nT = nT;
+
+    newPoly->coeff = (psF32 ****)psAlloc(nX * sizeof(psF32 ***));
+    newPoly->coeffErr = (psF32 ****)psAlloc(nX * sizeof(psF32 ***));
+    newPoly->mask = (char ****)psAlloc(nX * sizeof(char ***));
+    for (x = 0; x < nX; x++) {
+        newPoly->coeff[x] = (psF32 ***)psAlloc(nY * sizeof(psF32 **));
+        newPoly->coeffErr[x] = (psF32 ***)psAlloc(nY * sizeof(psF32 **));
+        newPoly->mask[x] = (char ***)psAlloc(nY * sizeof(char **));
+        for (y = 0; y < nY; y++) {
+            newPoly->coeff[x][y] = (psF32 **)psAlloc(nZ * sizeof(psF32 *));
+            newPoly->coeffErr[x][y] = (psF32 **)psAlloc(nZ * sizeof(psF32 *));
+            newPoly->mask[x][y] = (char **)psAlloc(nZ * sizeof(char *));
+            for (z = 0; z < nZ; z++) {
+                newPoly->coeff[x][y][z] = (psF32 *)psAlloc(nT * sizeof(psF32));
+                newPoly->coeffErr[x][y][z] = (psF32 *)psAlloc(nT * sizeof(psF32));
+                newPoly->mask[x][y][z] = (char *)psAlloc(nT * sizeof(char));
+            }
+        }
+    }
+    for (x = 0; x < nX; x++) {
+        for (y = 0; y < nY; y++) {
+            for (z = 0; z < nZ; z++) {
+                for (t = 0; t < nT; t++) {
+                    newPoly->coeff[x][y][z][t] = 0.0;
+                    newPoly->coeffErr[x][y][z][t] = 0.0;
+                    newPoly->mask[x][y][z][t] = 0;
+                }
+            }
+        }
+    }
+
+    return(newPoly);
+}
+
+psF64 psPolynomial1DEval(const psPolynomial1D* poly, psF64 x)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(ordPolynomial1DEval(x, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(chebPolynomial1DEval(x, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psPolynomial1DEvalVector(const psPolynomial1D *poly,
+                                   const psVector *x)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
+
+    psVector *tmp;
+
+    tmp = psVectorAlloc(x->n, PS_TYPE_F32);
+    for (psS32 i=0;i<x->n;i++) {
+        tmp->data.F32[i] = psPolynomial1DEval(poly, x->data.F32[i]);
+    }
+
+    return(tmp);
+}
+
+psF64 psPolynomial2DEval(const psPolynomial2D* poly, psF64 x, psF64 y)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(ordPolynomial2DEval(x, y, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(chebPolynomial2DEval(x, y, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psPolynomial2DEvalVector(const psPolynomial2D *poly,
+                                   const psVector *x,
+                                   const psVector *y)
+
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
+    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
+
+    psVector *tmp;
+    psS32 vecLen=x->n;
+
+    // Determine the length of the output vector to by the minimum of the x,y vectors
+    if (y->n < vecLen) {
+        vecLen = y->n;
+    }
+
+    // Create output vector to return
+    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
+
+    // Evaluate the polynomial at the specified points
+    for (psS32 i=0; i<vecLen; i++) {
+        tmp->data.F32[i] = psPolynomial2DEval(poly,x->data.F32[i],y->data.F32[i]);
+    }
+
+    // Return output vector
+    return(tmp);
+}
+
+psF64 psPolynomial3DEval(const psPolynomial3D* poly, psF64 x, psF64 y, psF64 z)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(ordPolynomial3DEval(x, y, z, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(chebPolynomial3DEval(x, y, z, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psPolynomial3DEvalVector(const psPolynomial3D *poly,
+                                   const psVector *x,
+                                   const psVector *y,
+                                   const psVector *z)
+
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
+    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
+    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F32, NULL);
+
+    psVector *tmp;
+    psS32 vecLen=x->n;
+
+    // Determine the length of output vector from min of the input vectors
+    if (y->n < vecLen) {
+        vecLen = y->n;
+    }
+    if (z->n < vecLen) {
+        vecLen = z->n;
+    }
+
+    // Allocate output vector
+    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
+
+    // Evaluate polynomial
+    for (psS32 i = 0; i < vecLen; i++) {
+        tmp->data.F32[i] = psPolynomial3DEval(poly,
+                                              x->data.F32[i],
+                                              y->data.F32[i],
+                                              z->data.F32[i]);
+    }
+
+    // Return output vector
+    return(tmp);
+}
+
+psF64 psPolynomial4DEval(const psPolynomial4D* poly, psF64 x, psF64 y, psF64 z, psF64 t)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(ordPolynomial4DEval(x,y,z,t, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(chebPolynomial4DEval(x,y,z,t, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psPolynomial4DEvalVector(const psPolynomial4D *poly,
+                                   const psVector *x,
+                                   const psVector *y,
+                                   const psVector *z,
+                                   const psVector *t)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
+    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
+    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F32, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(t, NULL);
+    PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F32, NULL);
+
+    psVector *tmp;
+    psS32 vecLen=x->n;
+
+    // Determine output vector size from min of input vectors
+    if (z->n < vecLen) {
+        vecLen = z->n;
+    }
+    if (y->n < vecLen) {
+        vecLen = y->n;
+    }
+    if (t->n < vecLen) {
+        vecLen = t->n;
+    }
+
+    // Allocate output vector
+    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
+
+    // Evaluate polynomial
+    for (psS32 i = 0; i < vecLen; i++) {
+        tmp->data.F32[i] = psPolynomial4DEval(poly,
+                                              x->data.F32[i],
+                                              y->data.F32[i],
+                                              z->data.F32[i],
+                                              t->data.F32[i]);
+    }
+
+    // Return output vector
+    return(tmp);
+}
+
+
+psDPolynomial1D* psDPolynomial1DAlloc( int n,
+                                       psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(n, NULL);
+
+    unsigned int i = 0;
+    psDPolynomial1D* newPoly = NULL;
+
+    newPoly = (psDPolynomial1D* ) psAlloc(sizeof(psDPolynomial1D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial1DFree);
+
+    newPoly->type = type;
+    newPoly->n = n;
+    newPoly->coeff = (psF64 *)psAlloc(n * sizeof(psF64));
+    newPoly->coeffErr = (psF64 *)psAlloc(n * sizeof(psF64));
+    newPoly->mask = (char *)psAlloc(n * sizeof(char));
+    for (i = 0; i < n; i++) {
+        newPoly->coeff[i] = 0.0;
+        newPoly->coeffErr[i] = 0.0;
+        newPoly->mask[i] = 0;
+    }
+
+    return(newPoly);
+}
+
+psDPolynomial2D* psDPolynomial2DAlloc( int nX,  int nY,
+                                       psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(nX, NULL);
+    PS_ASSERT_INT_POSITIVE(nY, NULL);
+
+    unsigned int x = 0;
+    unsigned int y = 0;
+    psDPolynomial2D* newPoly = NULL;
+
+    newPoly = (psDPolynomial2D* ) psAlloc(sizeof(psDPolynomial2D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial2DFree);
+
+    newPoly->type = type;
+    newPoly->nX = nX;
+    newPoly->nY = nY;
+
+    newPoly->coeff = (psF64 **)psAlloc(nX * sizeof(psF64 *));
+    newPoly->coeffErr = (psF64 **)psAlloc(nX * sizeof(psF64 *));
+    newPoly->mask = (char **)psAlloc(nX * sizeof(char *));
+    for (x = 0; x < nX; x++) {
+        newPoly->coeff[x] = (psF64 *)psAlloc(nY * sizeof(psF64));
+        newPoly->coeffErr[x] = (psF64 *)psAlloc(nY * sizeof(psF64));
+        newPoly->mask[x] = (char *)psAlloc(nY * sizeof(char));
+    }
+    for (x = 0; x < nX; x++) {
+        for (y = 0; y < nY; y++) {
+            newPoly->coeff[x][y] = 0.0;
+            newPoly->coeffErr[x][y] = 0.0;
+            newPoly->mask[x][y] = 0;
+        }
+    }
+
+    return(newPoly);
+}
+
+psDPolynomial3D* psDPolynomial3DAlloc( int nX,  int nY,  int nZ,
+                                       psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(nX, NULL);
+    PS_ASSERT_INT_POSITIVE(nY, NULL);
+    PS_ASSERT_INT_POSITIVE(nZ, NULL);
+
+    unsigned int x = 0;
+    unsigned int y = 0;
+    unsigned int z = 0;
+    psDPolynomial3D* newPoly = NULL;
+
+    newPoly = (psDPolynomial3D* ) psAlloc(sizeof(psDPolynomial3D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial3DFree);
+
+    newPoly->type = type;
+    newPoly->nX = nX;
+    newPoly->nY = nY;
+    newPoly->nZ = nZ;
+
+    newPoly->coeff = (psF64 ***)psAlloc(nX * sizeof(psF64 **));
+    newPoly->coeffErr = (psF64 ***)psAlloc(nX * sizeof(psF64 **));
+    newPoly->mask = (char ***)psAlloc(nX * sizeof(char **));
+    for (x = 0; x < nX; x++) {
+        newPoly->coeff[x] = (psF64 **)psAlloc(nY * sizeof(psF64 *));
+        newPoly->coeffErr[x] = (psF64 **)psAlloc(nY * sizeof(psF64 *));
+        newPoly->mask[x] = (char **)psAlloc(nY * sizeof(char *));
+        for (y = 0; y < nY; y++) {
+            newPoly->coeff[x][y] = (psF64 *)psAlloc(nZ * sizeof(psF64));
+            newPoly->coeffErr[x][y] = (psF64 *)psAlloc(nZ * sizeof(psF64));
+            newPoly->mask[x][y] = (char *)psAlloc(nZ * sizeof(char));
+        }
+    }
+    for (x = 0; x < nX; x++) {
+        for (y = 0; y < nY; y++) {
+            for (z = 0; z < nZ; z++) {
+                newPoly->coeff[x][y][z] = 0.0;
+                newPoly->coeffErr[x][y][z] = 0.0;
+                newPoly->mask[x][y][z] = 0;
+            }
+        }
+    }
+
+    return(newPoly);
+}
+
+psDPolynomial4D* psDPolynomial4DAlloc( int nX,  int nY,  int nZ,  int nT,
+                                       psPolynomialType type)
+{
+    PS_ASSERT_INT_POSITIVE(nX, NULL);
+    PS_ASSERT_INT_POSITIVE(nY, NULL);
+    PS_ASSERT_INT_POSITIVE(nZ, NULL);
+    PS_ASSERT_INT_POSITIVE(nT, NULL);
+
+    unsigned int x = 0;
+    unsigned int y = 0;
+    unsigned int z = 0;
+    unsigned int t = 0;
+    psDPolynomial4D* newPoly = NULL;
+
+    newPoly = (psDPolynomial4D* ) psAlloc(sizeof(psDPolynomial4D));
+    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial4DFree);
+
+    newPoly->type = type;
+    newPoly->nX = nX;
+    newPoly->nY = nY;
+    newPoly->nZ = nZ;
+    newPoly->nT = nT;
+
+    newPoly->coeff = (psF64 ****)psAlloc(nX * sizeof(psF64 ***));
+    newPoly->coeffErr = (psF64 ****)psAlloc(nX * sizeof(psF64 ***));
+    newPoly->mask = (char ****)psAlloc(nX * sizeof(char ***));
+    for (x = 0; x < nX; x++) {
+        newPoly->coeff[x] = (psF64 ***)psAlloc(nY * sizeof(psF64 **));
+        newPoly->coeffErr[x] = (psF64 ***)psAlloc(nY * sizeof(psF64 **));
+        newPoly->mask[x] = (char ***)psAlloc(nY * sizeof(char **));
+        for (y = 0; y < nY; y++) {
+            newPoly->coeff[x][y] = (psF64 **)psAlloc(nZ * sizeof(psF64 *));
+            newPoly->coeffErr[x][y] = (psF64 **)psAlloc(nZ * sizeof(psF64 *));
+            newPoly->mask[x][y] = (char **)psAlloc(nZ * sizeof(char *));
+            for (z = 0; z < nZ; z++) {
+                newPoly->coeff[x][y][z] = (psF64 *)psAlloc(nT * sizeof(psF64));
+                newPoly->coeffErr[x][y][z] = (psF64 *)psAlloc(nT * sizeof(psF64));
+                newPoly->mask[x][y][z] = (char *)psAlloc(nT * sizeof(char));
+            }
+        }
+    }
+    for (x = 0; x < nX; x++) {
+        for (y = 0; y < nY; y++) {
+            for (z = 0; z < nZ; z++) {
+                for (t = 0; t < nT; t++) {
+                    newPoly->coeff[x][y][z][t] = 0.0;
+                    newPoly->coeffErr[x][y][z][t] = 0.0;
+                    newPoly->mask[x][y][z][t] = 0;
+                }
+            }
+        }
+    }
+
+    return(newPoly);
+}
+
+
+psF64 psDPolynomial1DEval(const psDPolynomial1D* poly, psF64 x)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(dOrdPolynomial1DEval(x, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(dChebPolynomial1DEval(x, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psDPolynomial1DEvalVector(const psDPolynomial1D *poly,
+                                    const psVector *x)
+
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
+
+    psVector *tmp;
+
+    tmp = psVectorAlloc(x->n, PS_TYPE_F64);
+    for (psS32 i=0;i<x->n;i++) {
+        tmp->data.F64[i] = psDPolynomial1DEval(poly,
+                                               x->data.F64[i]);
+    }
+
+    return(tmp);
+}
+
+
+psF64 psDPolynomial2DEval(const psDPolynomial2D* poly,
+                          psF64 x,
+                          psF64 y)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(dOrdPolynomial2DEval(x, y, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(dChebPolynomial2DEval(x, y, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psDPolynomial2DEvalVector(const psDPolynomial2D *poly,
+                                    const psVector *x,
+                                    const psVector *y)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
+    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
+
+    psVector *tmp;
+    psS32 vecLen=x->n;
+
+    // Determine the output vector length from minimum length of input vectors
+    if (y->n < vecLen) {
+        vecLen = y->n;
+    }
+
+    // Allocate output vector
+    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
+
+    // Evaluate the polynomial
+    for (psS32 i = 0; i < vecLen; i++) {
+        tmp->data.F64[i] = psDPolynomial2DEval(poly,x->data.F64[i],y->data.F64[i]);
+    }
+
+    // Return output vector
+    return(tmp);
+}
+
+
+psF64 psDPolynomial3DEval(const psDPolynomial3D* poly,
+                          psF64 x,
+                          psF64 y,
+                          psF64 z)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(dOrdPolynomial3DEval(x, y, z, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(dChebPolynomial3DEval(x, y, z, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psDPolynomial3DEvalVector(const psDPolynomial3D *poly,
+                                    const psVector *x,
+                                    const psVector *y,
+                                    const psVector *z)
+
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
+    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
+    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);
+
+    psVector *tmp;
+    psS32 vecLen=x->n;
+
+    // Determine the size of output vector from min of input vectors
+    if (y->n < vecLen) {
+        vecLen = y->n;
+    }
+    if (z->n < vecLen) {
+        vecLen = z->n;
+    }
+
+    // Allocate output vector
+    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
+
+    // Evaluate polynomial
+    for (psS32 i = 0; i < vecLen; i++) {
+        tmp->data.F64[i] = psDPolynomial3DEval(poly,
+                                               x->data.F64[i],
+                                               y->data.F64[i],
+                                               z->data.F64[i]);
+    }
+
+    // Return output vector
+    return(tmp);
+}
+
+psF64 psDPolynomial4DEval(const psDPolynomial4D* poly,
+                          psF64 x,
+                          psF64 y,
+                          psF64 z,
+                          psF64 t)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NAN);
+
+    if (poly->type == PS_POLYNOMIAL_ORD) {
+        return(dOrdPolynomial4DEval(x,y,z,t, poly));
+    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
+        return(dChebPolynomial4DEval(x,y,z,t, poly));
+    } else {
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
+                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
+                poly->type);
+    }
+    return(NAN);
+}
+
+psVector *psDPolynomial4DEvalVector(const psDPolynomial4D *poly,
+                                    const psVector *x,
+                                    const psVector *y,
+                                    const psVector *z,
+                                    const psVector *t)
+{
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
+    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
+    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(t, NULL);
+    PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F64, NULL);
+
+    psVector *tmp;
+    psS32 vecLen=x->n;
+
+    // Determine the output vector size from min of input vectors
+    if (z->n < vecLen) {
+        vecLen = z->n;
+    }
+    if (y->n < vecLen) {
+        vecLen = y->n;
+    }
+    if (t->n < vecLen) {
+        vecLen = t->n;
+    }
+
+    // Allocate output vector
+    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
+
+    // Evaluate the polynomial
+    for (psS32 i = 0; i < vecLen; i++) {
+        tmp->data.F64[i] = psDPolynomial4DEval(poly,
+                                               x->data.F64[i],
+                                               y->data.F64[i],
+                                               z->data.F64[i],
+                                               t->data.F64[i]);
+    }
+
+    // Return output vector
+    return(tmp);
+}
+
+
+
+
+//typedef struct {
+//    psS32 n;
+//    psPolynomial1D **spline;
+//    psF32 *p_psDeriv2;
+//    psVector *knots;
+//} psSpline1D;
+
+/*****************************************************************************
+    NOTE: "n" specifies the number of spline polynomials.  Therefore, there
+    must exist n+1 points in "knots".
+ 
+XXX: Ensure that domain[i+1] != domain[i]
+ 
+XXX: What should be the defualty type for knots be?  psF32 is assumed.
+ *****************************************************************************/
+psSpline1D *psSpline1DAlloc( int numSplines,
+                             int order,
+                             float min,
+                             float max)
+{
+    PS_ASSERT_INT_NONNEGATIVE(numSplines, NULL);
+    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
+    PS_ASSERT_FLOAT_NON_EQUAL(max, min, NULL);
+
+    psSpline1D *tmp = NULL;
+    psS32 i;
+    psF32 tmpDomain;
+    psF32 width;
+
+    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
+    tmp->n = numSplines;
+
+    tmp->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
+    for (i=0;i<numSplines;i++) {
+        (tmp->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
+    }
+
+    // This should be set by the psVectorFitSpline1D()
+    tmp->p_psDeriv2 = NULL;
+
+    tmp->knots = psVectorAlloc(numSplines+1, PS_TYPE_F32);
+    width = (max - min) / ((psF32) numSplines);
+
+    tmp->knots->data.F32[0] = min;
+    tmpDomain = min+width;
+    for (i=1;i<numSplines+1;i++) {
+        tmp->knots->data.F32[i] = tmpDomain;
+        tmpDomain+= width;
+    }
+    tmp->knots->data.F32[numSplines] = max;
+
+    psMemSetDeallocator(tmp,(psFreeFunc)spline1DFree);
+    return(tmp);
+}
+
+
+/*****************************************************************************
+XXX: What should be the defualty type for knots be?  psF32 is assumed.
+ *****************************************************************************/
+psSpline1D *psSpline1DAllocGeneric(const psVector *bounds,
+                                   int order)
+{
+    PS_ASSERT_VECTOR_NON_NULL(bounds, NULL);
+    PS_ASSERT_VECTOR_NON_EMPTY(bounds, NULL);
+    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
+
+    psSpline1D *tmp = NULL;
+    unsigned int i;
+    unsigned int numSplines;
+
+    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
+
+    numSplines = bounds->n - 1;
+    tmp->n = numSplines;
+
+    tmp->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
+    for (i=0;i<numSplines;i++) {
+        (tmp->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
+    }
+
+    // This should be set by the psVectorFitSpline1D()
+    tmp->p_psDeriv2 = NULL;
+
+    tmp->knots = psVectorAlloc(bounds->n, PS_TYPE_F32);
+
+    for (i=0;i<bounds->n;i++) {
+        tmp->knots->data.F32[i] = bounds->data.F32[i];
+        if (i<(bounds->n-1)) {
+            if (FLT_EPSILON >= fabs(bounds->data.F32[i+1]-bounds->data.F32[i])) {
+                psError(PS_ERR_UNKNOWN, true, "data points must be distinct\n");
+            }
+        }
+    }
+
+    psMemSetDeallocator(tmp,(psFreeFunc)spline1DFree);
+    return(tmp);
+}
+
+/*****************************************************************************
+vectorBinDisectF32(): This is a macro for a private function which takes as
+input a vector an array of data as well as a single value for that data.  The
+input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all
+i).  This routine does a binary disection of the vector and returns "i" such
+that (v[i] <= x <= v[i+1).  If x lies outside the range of v[], then this
+routine prints a warning message and returns (-2 or -1).
+ *****************************************************************************/
+#define FUNC_MACRO_VECTOR_BIN_DISECT(TYPE) \
+static psS32 vectorBinDisect##TYPE(ps##TYPE *bins, \
+                                   psS32 numBins, \
+                                   ps##TYPE x) \
+{ \
+    psS32 min; \
+    psS32 max; \
+    psS32 mid; \
+    \
+    psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
+            "---- Calling vectorBinDisect##TYPE(%f)\n", x); \
+    \
+    if (x < bins[0]) { \
+        psLogMsg(__func__, PS_LOG_WARN, \
+                 "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
+                 #TYPE, x, bins[0], bins[numBins-1]); \
+        return(-2); \
+    } \
+    \
+    if (x > bins[numBins-1]) { \
+        psLogMsg(__func__, PS_LOG_WARN, \
+                 "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
+                 #TYPE, x, bins[0], bins[numBins-1]); \
+        return(-1); \
+    } \
+    \
+    min = 0; \
+    max = numBins-2; \
+    mid = ((max+1)-min)/2; \
+    \
+    while (min != max) { \
+        psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
+                "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", \
+                min, mid, max, x, bins[mid]); \
+        \
+        if (x == bins[mid]) { \
+            psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
+                    "---- Exiting vectorBinDisect##TYPE(): bin %d\n", mid); \
+            return(mid); \
+        } else if (x < bins[mid]) { \
+            max = mid-1; \
+        } else { \
+            min = mid; \
+        } \
+        mid = ((max+1)+min)/2; \
+    } \
+    \
+    psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
+            "---- Exiting vectorBinDisect##TYPE(): bin %d\n", min); \
+    return(min); \
+} \
+
+FUNC_MACRO_VECTOR_BIN_DISECT(S8)
+FUNC_MACRO_VECTOR_BIN_DISECT(S16)
+FUNC_MACRO_VECTOR_BIN_DISECT(S32)
+FUNC_MACRO_VECTOR_BIN_DISECT(S64)
+FUNC_MACRO_VECTOR_BIN_DISECT(U8)
+FUNC_MACRO_VECTOR_BIN_DISECT(U16)
+FUNC_MACRO_VECTOR_BIN_DISECT(U32)
+FUNC_MACRO_VECTOR_BIN_DISECT(U64)
+FUNC_MACRO_VECTOR_BIN_DISECT(F32)
+FUNC_MACRO_VECTOR_BIN_DISECT(F64)
+
+/*****************************************************************************
+p_psVectorBinDisect(): A wrapper to the above p_psVectorBinDisect().
+ *****************************************************************************/
+psS32 p_psVectorBinDisect(psVector *bins,
+                          psScalar *x)
+{
+    PS_ASSERT_VECTOR_NON_NULL(bins, -4);
+    PS_ASSERT_VECTOR_NON_EMPTY(bins, -4);
+    PS_ASSERT_PTR_NON_NULL(x, -6);
+    PS_ASSERT_PTR_TYPE_EQUAL(x, bins, -3);
+    char* strType;
+
+    switch (x->type.type) {
+    case PS_TYPE_U8:
+        return(vectorBinDisectU8(bins->data.U8, bins->n, x->data.U8));
+    case PS_TYPE_U16:
+        return(vectorBinDisectU16(bins->data.U16, bins->n, x->data.U16));
+    case PS_TYPE_U32:
+        return(vectorBinDisectU32(bins->data.U32, bins->n, x->data.U32));
+    case PS_TYPE_U64:
+        return(vectorBinDisectU64(bins->data.U64, bins->n, x->data.U64));
+    case PS_TYPE_S8:
+        return(vectorBinDisectS8(bins->data.S8, bins->n, x->data.S8));
+    case PS_TYPE_S16:
+        return(vectorBinDisectS16(bins->data.S16, bins->n, x->data.S16));
+    case PS_TYPE_S32:
+        return(vectorBinDisectS32(bins->data.S32, bins->n, x->data.S32));
+    case PS_TYPE_S64:
+        return(vectorBinDisectS64(bins->data.S64, bins->n, x->data.S64));
+    case PS_TYPE_F32:
+        return(vectorBinDisectF32(bins->data.F32, bins->n, x->data.F32));
+    case PS_TYPE_F64:
+        return(vectorBinDisectF64(bins->data.F64, bins->n, x->data.F64));
+    case PS_TYPE_C32:
+        PS_TYPE_NAME(strType,x->type.type);
+        psError(PS_ERR_BAD_PARAMETER_TYPE,
+                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
+                strType);
+        return 0;
+    case PS_TYPE_C64:
+        PS_TYPE_NAME(strType,x->type.type);
+        psError(PS_ERR_BAD_PARAMETER_TYPE,
+                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
+                strType);
+        return 0;
+    case PS_TYPE_BOOL:
+        PS_TYPE_NAME(strType,x->type.type);
+        psError(PS_ERR_BAD_PARAMETER_TYPE,
+                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
+                strType);
+        return 0;
+    }
+    return(-3);
+}
+
+/*****************************************************************************
+p_psVectorInterpolate(): This routine will take as input psVectors domain and
+range, and the x value, assumed to lie with the domain vector.  It produces
+as output the LaGrange interpolated value of a polynomial of the specified
+order around the point x.
+ 
+XXX: This stuff does not currently work with a mask.
+ 
+XXX: add another psScalar argument for the result.
+ 
+XXX: The VectorCopy routines seg fault when I declare range32 as static.
+ *****************************************************************************/
+psScalar *p_psVectorInterpolate(psVector *domain,
+                                psVector *range,
+                                int order,
+                                psScalar *x)
+{
+    PS_ASSERT_VECTOR_NON_NULL(domain, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(range, NULL);
+    PS_ASSERT_PTR_NON_NULL(x, NULL);
+    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
+    PS_ASSERT_VECTORS_SIZE_EQUAL(domain, range, NULL);
+    PS_ASSERT_PTR_TYPE_EQUAL(domain, range, NULL);
+    PS_ASSERT_PTR_TYPE_EQUAL(domain, x, NULL);
+
+    psVector *range32 = NULL;
+    psVector *domain32 = NULL;
+    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
+            "---- p_psVectorInterpolate() begin ----\n");
+
+    if (order > (domain->n - 1)) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                PS_ERRORTEXT_psFunctions_NOT_ENOUGH_DATAPOINTS,
+                order);
+        return(NULL);
+    }
+
+    if (x->type.type == PS_TYPE_F32) {
+        psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
+                "---- p_psVectorInterpolate() end ----\n");
+        return(psScalarAlloc(interpolate1DF32(domain->data.F32,
+                                              range->data.F32,
+                                              domain->n,
+                                              order,
+                                              x->data.F32), PS_TYPE_F32));
+    } else if (x->type.type == PS_TYPE_F64) {
+        // XXX: use recycled vectors here.
+        range32 = psVectorCopy(range32, range, PS_TYPE_F32);
+        domain32 = psVectorCopy(domain32, domain, PS_TYPE_F32);
+
+        psScalar *tmpScalar = psScalarAlloc((psF64)
+                                            interpolate1DF32(domain32->data.F32,
+                                                             range32->data.F32,
+                                                             domain32->n,
+                                                             order,
+                                                             (psF32) x->data.F64), PS_TYPE_F64);
+        psFree(range32);
+        psFree(domain32);
+
+        psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
+                "---- p_psVectorInterpolate() end ----\n");
+        // XXX: Convert data type to F64?
+        return(tmpScalar);
+
+    } else {
+        char* strType;
+        PS_TYPE_NAME(strType,x->type.type);
+        psError(PS_ERR_BAD_PARAMETER_TYPE,
+                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
+                strType);
+    }
+
+    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
+            "return(NULL)\n");
+    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
+            "---- p_psVectorInterpolate() end ----\n");
+
+    return(NULL);
+}
+
+
+/*****************************************************************************
+psSpline1DEval(): this routine takes an existing spline of arbitrary order
+and an independent x value.  Each determines which spline that x corresponds
+to by doing a bracket disection on the knots of the spline data structure
+(vectorBinDisectF32()).  Then it evaluates the spline at that x location
+by a call to the 1D polynomial functions.
+ 
+XXX: The spline eval functions require input and output to be F32.  however
+     the spline fit functions require F32 and F64.
+ 
+XXX: This only works if spline0>knots if psF32.  Must add support for psU32 and
+psF64.
+ *****************************************************************************/
+float psSpline1DEval(
+    const psSpline1D *spline,
+    float x
+)
+{
+    PS_ASSERT_PTR_NON_NULL(spline, NAN);
+    PS_ASSERT_INT_NONNEGATIVE(spline->n, NAN);
+    PS_ASSERT_VECTOR_TYPE(spline->knots, PS_TYPE_F32, NAN);
+
+    unsigned int binNum;
+    unsigned int n;
+
+    n = spline->n;
+    //XXX    binNum = vectorBinDisectF32(spline->domains, (spline->n)+1, x);
+    binNum = vectorBinDisectF32(spline->knots->data.F32, (spline->n)+1, x);
+    if (binNum < 0) {
+        psLogMsg(__func__, PS_LOG_WARN,
+                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).",
+                 x, spline->knots->data.F32[0],
+                 spline->knots->data.F32[n-1]);
+
+        if (x < spline->knots->data.F32[0]) {
+            return(psPolynomial1DEval(spline->spline[0],
+                                      x));
+        } else if (x > spline->knots->data.F32[n-1]) {
+            return(psPolynomial1DEval(spline->spline[n-1],
+                                      x));
+        }
+    }
+
+    return(psPolynomial1DEval(spline->spline[binNum],
+                              x));
+}
+
+// XXX: The spline eval functions require input and output to be F32.
+// however the spline fit functions require F32 and F64.
+psVector *psSpline1DEvalVector(
+    const psSpline1D *spline,
+    const psVector *x
+)
+{
+    PS_ASSERT_PTR_NON_NULL(spline, NULL);
+    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
+    PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL);
+    PS_ASSERT_VECTOR_TYPE(spline->knots, PS_TYPE_F32, NULL);
+
+    unsigned int i;
+    psVector *tmpVector;
+
+    tmpVector = psVectorAlloc(x->n, PS_TYPE_F32);
+    if (x->type.type == PS_TYPE_F32) {
+        for (i=0;i<x->n;i++) {
+            tmpVector->data.F32[i] = psSpline1DEval(
+                                         spline,
+                                         x->data.F32[i]
+                                     );
+        }
+    } else if (x->type.type == PS_TYPE_F64) {
+        for (i=0;i<x->n;i++) {
+            tmpVector->data.F32[i] = psSpline1DEval(
+                                         spline,
+                                         (psF32) x->data.F64[i]
+                                     );
+        }
+    } else {
+        char* strType;
+        PS_TYPE_NAME(strType,x->type.type);
+        psError(PS_ERR_BAD_PARAMETER_TYPE,
+                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
+                strType);
+        return(NULL);
+    }
+
+    return(tmpVector);
+}
Index: /trunk/psLib/src/math/psFunctions.h
===================================================================
--- /trunk/psLib/src/math/psFunctions.h	(revision 4540)
+++ /trunk/psLib/src/math/psFunctions.h	(revision 4540)
@@ -0,0 +1,519 @@
+/** @file psFunctions.h
+ *  @brief Standard Mathematical Functions.
+ *  @ingroup Stats
+ *
+ *  This file will hold the prototypes for procedures which allocate, free,
+ *  and evaluate various polynomials.  Those polynomial structures are also
+ *  defined here.
+ *
+ *  @ingroup Stats
+ *
+ *  @author Someone at IfA
+ *  @author GLG, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#ifndef PS_FUNCTIONS_H
+#define PS_FUNCTIONS_H
+
+#include <stdio.h>
+#include <stdbool.h>
+#include <float.h>
+#include <math.h>
+
+#include "psVector.h"
+#include "psScalar.h"
+
+/** \addtogroup Stats
+ *  \{
+ */
+
+/** Evaluate a non-normalized Gaussian with the given mean and sigma at the
+ *  given coordianate.
+ *
+ *  Note that this is not a Gaussian deviate.  The evaluated Gaussian is:
+ *        \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
+ *
+ *  @return float      value on the gaussian curve given the input parameters
+ */
+float psGaussian(
+    float x,                           ///< Value at which to evaluate
+    float mean,                        ///< Mean for the Gaussian
+    float sigma,                       ///< Standard deviation for the Gaussian
+    bool normal                        ///< Indicates whether result should be normalized
+);
+
+/** Produce a vector of random numbers from a Gaussian distribution with
+ *  the specified mean and sigma
+ *
+ *  @return psVector*    vector of random numbers
+ *
+ */
+psVector* p_psGaussianDev(
+    psF32 mean,                        ///< The mean of the Gaussian
+    psF32 sigma,                       ///< The sigma of the Gaussian
+    psS32 Npts                         ///< The size of the vector
+);
+
+/** Polynomial Type.
+ *
+ *  Enumeration for Polynomial types.
+ */
+typedef enum {
+    PS_POLYNOMIAL_ORD,                 ///< Ordinary Polynomial
+    PS_POLYNOMIAL_CHEB                 ///< Chebyshev Polynomial
+}
+psPolynomialType;
+
+/** One-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    psElemType ctype;                  ///< Polynomial precision
+    int n;                             ///< Number of terms
+    psF32 *coeff;                      ///< Coefficients
+    psF32 *coeffErr;                   ///< Error in coefficients
+    char *mask;                        ///< Coefficient mask
+}
+psPolynomial1D;
+
+/** Two-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    psElemType ctype;                  ///< Polynomial precision
+    int nX;                            ///< Number of terms in x
+    int nY;                            ///< Number of terms in y
+    psF32 **coeff;                     ///< Coefficients
+    psF32 **coeffErr;                  ///< Error in coefficients
+    char **mask;                       ///< Coefficients mask
+}
+psPolynomial2D;
+
+/** Three-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    psElemType ctype;                  ///< Polynomial precision
+    int nX;                           ///< Number of terms in x
+    int nY;                            ///< Number of terms in y
+    int nZ;                           ///< Number of terms in z
+    psF32 ***coeff;                    ///< Coefficients
+    psF32 ***coeffErr;                 ///< Error in coefficients
+    char ***mask;                      ///< Coefficients mask
+}
+psPolynomial3D;
+
+/** Four-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    psElemType ctype;                  ///< Polynomial precision
+    int nX;                            ///< Number of terms in x
+    int nY;                            ///< Number of terms in y
+    int nZ;                            ///< Number of terms in z
+    int nT;                            ///< Number of terms in t
+    psF32 ****coeff;                   ///< Coefficients
+    psF32 ****coeffErr;                ///< Error in coefficients
+    char ****mask;                     ///< Coefficients mask
+}
+psPolynomial4D;
+
+
+/** Allocates a psPolynomial1D structure with n terms
+ *
+ *  @return  psPolynomial1D*    new 1-D polynomial struct
+ */
+psPolynomial1D* psPolynomial1DAlloc(
+    int n,                             ///< Number of terms
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Allocates a 2-D polynomial structure
+ *
+ *  @return  psPolynomial2D*    new 2-D polynomial struct
+ */
+psPolynomial2D* psPolynomial2DAlloc(
+    int nX,                   ///< Number of terms in x
+    int nY,                   ///< Number of terms in y
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Allocates a 3-D polynomial structure
+ *
+ *  @return  psPolynomial3D*    new 3-D polynomial struct
+ */
+psPolynomial3D* psPolynomial3DAlloc(
+    int nX,                            ///< Number of terms in x
+    int nY,                            ///< Number of terms in y
+    int nZ,                            ///< Number of terms in z
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Allocates a 4-D polynomial structure
+ *
+ *  @return  psPolynomial4D*    new 4-D polynomial struct
+ */
+psPolynomial4D* psPolynomial4DAlloc(
+    int nX,                            ///< Number of terms in x
+    int nY,                            ///< Number of terms in y
+    int nZ,                            ///< Number of terms in z
+    int nT,                            ///< Number of terms in t
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Evaluates a 1-D polynomial at specific coordinates.
+ *
+ *  @return psF64    result of polynomial at given location
+ */
+psF64 psPolynomial1DEval(
+    const psPolynomial1D* poly,        ///< Coefficients for the polynomial
+    psF64 x                            ///< location at which to evaluate
+);
+
+/** Evaluates a 2-D polynomial at specific coordinates.
+ *
+ *  @return psF64    result of polynomial at given location
+ */
+psF64 psPolynomial2DEval(
+    const psPolynomial2D* poly,        ///< Coefficients for the polynomial
+    psF64 x,                           ///< x location at which to evaluate
+    psF64 y                            ///< y location at which to evaluate
+);
+
+/** Evaluates a 3-D polynomial at specific coordinates.
+ *
+ *  @return psF64    result of polynomial at given location
+ */
+psF64 psPolynomial3DEval(
+    const psPolynomial3D* poly,        ///< Coefficients for the polynomial
+    psF64 x,                           ///< x location at which to evaluate
+    psF64 y,                           ///< y location at which to evaluate
+    psF64 z                            ///< z location at which to evaluate
+);
+
+/** Evaluates a 4-D polynomial at specific coordinates.
+ *
+ *  @return psF64    result of polynomial at given location
+ */
+psF64 psPolynomial4DEval(
+    const psPolynomial4D* poly,        ///< Coefficients for the polynomial
+    psF64 x,                           ///< x location at which to evaluate
+    psF64 y,                           ///< y location at which to evaluate
+    psF64 z,                           ///< z location at which to evaluate
+    psF64 t                            ///< t location at which to evaluate
+);
+
+/** Evaluates a 1-D polynomial at specific sets of coordinates
+ *
+ *  @return psVector*    results of polynomials at given locations
+ */
+psVector *psPolynomial1DEvalVector(
+    const psPolynomial1D *poly,        ///< Coefficients for the polynomial
+    const psVector *x                  ///< x locations at which to evaluate
+);
+
+/** Evaluates a 2-D polynomial at specific sets of coordinates
+ *
+ *  @return psVector*    results of polynomial at given locations
+ */
+psVector *psPolynomial2DEvalVector(
+    const psPolynomial2D *poly,        ///< Coefficients for the polynomial
+    const psVector *x,                 ///< x locations at which to evaluate
+    const psVector *y                  ///< y locations at which to evaluate
+);
+
+/** Evaluates a 3-D polynomial at specific sets of coordinates
+ *
+ *  @return psVector*    results of polynomial at given locations
+ */
+psVector *psPolynomial3DEvalVector(
+    const psPolynomial3D *poly,        ///< Coefficients for the polynomial
+    const psVector *x,                 ///< x locations at which to evaluate
+    const psVector *y,                 ///< y locations at which to evaluate
+    const psVector *z                  ///< z locations at which to evaluate
+);
+
+/** Evaluates a 4-D polynomial at specific sets of coordinates
+ *
+ *  @return psVector*    results of polynomial at given locations
+ */
+psVector *psPolynomial4DEvalVector(
+    const psPolynomial4D *poly,        ///< Coefficients for the polynomial
+    const psVector *x,                 ///< x locations at which to evaluate
+    const psVector *y,                 ///< y locations at which to evaluate
+    const psVector *z,                 ///< z locations at which to evaluate
+    const psVector *t                  ///< t locations at which to evaluate
+);
+
+/*****************************************************************************/
+
+/* Double-precision polynomials, mainly for use in astrometry */
+
+/** Double-precision one-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    int n;                             ///< Number of terms
+    psF64 *coeff;                      ///< Coefficients
+    psF64 *coeffErr;                   ///< Error in coefficients
+    char *mask;                        ///< Coefficient mask
+}
+psDPolynomial1D;
+
+/** Double-precision two-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    int nX;                            ///< Number of terms in x
+    int nY;                            ///< Number of terms in y
+    psF64 **coeff;                     ///< Coefficients
+    psF64 **coeffErr;                  ///< Error in coefficients
+    char **mask;                       ///< Coefficients mask
+}
+psDPolynomial2D;
+
+/** Double-precision three-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    int nX;                            ///< Number of terms in x
+    int nY;                            ///< Number of terms in y
+    int nZ;                            ///< Number of terms in z
+    psF64 ***coeff;                    ///< Coefficients
+    psF64 ***coeffErr;                 ///< Error in coefficients
+    char ***mask;                      ///< Coefficient mask
+}
+psDPolynomial3D;
+
+/** Double-precision four-dimensional polynomial */
+typedef struct
+{
+    psPolynomialType type;             ///< Polynomial type
+    int nX;                            ///< Number of terms in w
+    int nY;                            ///< Number of terms in x
+    int nZ;                            ///< Number of terms in y
+    int nT;                            ///< Number of terms in z
+    psF64 ****coeff;                   ///< Coefficients
+    psF64 ****coeffErr;                ///< Error in coefficients
+    char ****mask;                     ///< Coefficients mask
+}
+psDPolynomial4D;
+
+/** Allocates a double-precision 1-D polynomial structure with n terms
+ *
+ *  @return  psPolynomial1D*    new double-precision 1-D polynomial struct
+ */
+psDPolynomial1D* psDPolynomial1DAlloc(
+    int n,                             ///< Number of terms
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Allocates a double-precision 2-D polynomial structure
+ *
+ *  @return  psPolynomial2D*    new double-precision 2-D polynomial struct
+ */
+psDPolynomial2D* psDPolynomial2DAlloc(
+    int nX,                            ///< Number of terms in x
+    int nY,                            ///< Number of terms in y
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Allocates a double-precision 3-D polynomial structure
+ *
+ *  @return  psPolynomial3D*    new double-precision 3-D polynomial struct
+ */
+psDPolynomial3D* psDPolynomial3DAlloc(
+    int nX,                            ///< Number of terms in x
+    int nY,                            ///< Number of terms in y
+    int nZ,                            ///< Number of terms in z
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Allocates a double-precision 4-D polynomial structure
+ *
+ *  @return  psPolynomial4D*    new double-precision 4-D polynomial struct
+ */
+psDPolynomial4D* psDPolynomial4DAlloc(
+    int nX,                            ///< Number of terms in w
+    int nY,                            ///< Number of terms in x
+    int nZ,                            ///< Number of terms in y
+    int nT,                            ///< Number of terms in z
+    psPolynomialType type              ///< Polynomial Type
+);
+
+/** Evaluates a double-precision 1-D polynomial at specific coordinates.
+ *
+ *  @return psF32    result of polynomial at given location
+ */
+psF64 psDPolynomial1DEval(
+    const psDPolynomial1D* poly,     ///< Coefficients for the polynomial
+    psF64 x                            ///< Value at which to evaluate
+);
+
+/** Evaluates a double-precision 2-D polynomial at specific coordinates.
+ *
+ *  @return psF32    result of polynomial at given location
+ */
+psF64 psDPolynomial2DEval(
+    const psDPolynomial2D* poly,      ///< Coefficients for the polynomial
+    psF64 x,                            ///< Value x at which to evaluate
+    psF64 y                             ///< Value y at which to evaluate
+);
+
+/** Evaluates a double-precision 3-D polynomial at specific coordinates.
+ *
+ *  @return psF64    result of polynomial at given location
+ */
+psF64 psDPolynomial3DEval(
+    const psDPolynomial3D* poly,     ///< Coefficients for the polynomial
+    psF64 x,                           ///< Value x at which to evaluate
+    psF64 y,                           ///< Value y at which to evaluate
+    psF64 z                            ///< Value z at which to evaluate
+);
+
+/** Evaluates a double-precision 4-D polynomial at specific coordinates.
+ *
+ *  @return psF64    result of polynomial at given location
+ */
+psF64 psDPolynomial4DEval(
+    const psDPolynomial4D* poly,     ///< Coefficients for the polynomial
+    psF64 x,                           ///< Value w at which to evaluate
+    psF64 y,                           ///< Value x at which to evaluate
+    psF64 z,                           ///< Value y at which to evaluate
+    psF64 t                            ///< Value z at which to evaluate
+);
+
+/** Evaluates a double-precision 1-D polynomial at specific sets of coordinates.
+ *
+ *  @return psVector*    results of polynomial at given locations
+ */
+psVector *psDPolynomial1DEvalVector(
+    const psDPolynomial1D *poly,     ///< Coefficients for the polynomial
+    const psVector *x                  ///< x locations at which to evaluate
+);
+
+/** Evaluates a double-precision 2-D polynomial at specific sets of coordinates.
+ *
+ *  @return psVector*    results of polynomial at given locations
+ */
+psVector *psDPolynomial2DEvalVector(
+    const psDPolynomial2D *poly,     ///< Coefficients for the polynomial
+    const psVector *x,                 ///< x locations at which to evaluate
+    const psVector *y                  ///< y locations at which to evaluate
+);
+
+/** Evaluates a double-precision 3-D polynomial at specific sets of coordinates.
+ *
+ *  @return psVector*    results of polynomial at given locations
+ */
+psVector *psDPolynomial3DEvalVector(
+    const psDPolynomial3D *poly,     ///< Coefficients for the polynomial
+    const psVector *x,                 ///< x locations at which to evaluate
+    const psVector *y,                 ///< y locations at which to evaluate
+    const psVector *z                  ///< z locations at which to evaluate
+);
+
+/** Evaluates a double-precision 4-D polynomial at specific sets of coordinates.
+ *
+ *  @return psVector*    results of polynomial at given locations
+ */
+psVector *psDPolynomial4DEvalVector(
+    const psDPolynomial4D *poly,     ///< Coefficients for the polynomial
+    const psVector *x,                 ///< w locations at which to evaluate
+    const psVector *y,                 ///< x locations at which to evaluate
+    const psVector *z,                 ///< y locations at which to evaluate
+    const psVector *t                  ///< z locations at which to evaluate
+);
+
+/** One-Dimensional Spline */
+typedef struct
+{
+    unsigned int n;                    ///< The number of spline polynomials
+    psPolynomial1D **spline;           ///< An array of n pointers to the spline polynomials
+    psF32 *p_psDeriv2;                 ///< For cubic splines, the second derivative at each domain point.  Size is n+1.
+    psF32 *domains;                    ///< The boundaries between each spline piece.  Size is n+1.
+    psVector *knots;                   ///< The boundaries between each spline piece.  Size is n+1.
+}
+psSpline1D;
+
+/** Allocates a psSpline1D structure
+ *
+ *  Allocator for psSpline1D where the bounds are implicitly specified through specifying
+ *  min and max values along with the number of splines.
+ *
+ *  @return psSpline1D*    new 1-D spline struct
+ */
+psSpline1D *psSpline1DAlloc(
+    int n,                             ///< Number of spline polynomials
+    int order,                         ///< Order of spline polynomials
+    float min,                         ///< Lower boundary value of spline polynomials
+    float max                          ///< Upper boundary value of spline polynomials
+);
+
+/** Allocates a psSpline1D structure
+ *
+ *  Allocator for psSpline1D where the bounds are explicitly specified.
+ *
+ *  @return psSpline1D*    new 1-D spline struct
+ */
+psSpline1D *psSpline1DAllocGeneric(
+    const psVector *bounds,            ///< Bounds for spline polynomials
+    int order                          ///< Order of spline polynomials
+);
+
+/** Evaluates 1-D spline polynomials at a specific coordinate.
+ *
+ *  @return float    result of spline polynomials evaluated at given location
+ */
+float psSpline1DEval(
+    const psSpline1D *spline,          ///< Coefficients for spline polynomials
+    float x                            ///< location at which to evaluate
+);
+
+/** Evaluates 1-D spline polynomials at a set of specific coordinates.
+ *
+ *  @return psVector*    results of spline polynomials evaluated at given locations
+ */
+psVector *psSpline1DEvalVector(
+    const psSpline1D *spline,          ///< Coefficients of spline polynomials
+    const psVector *x                  ///< locations at which to evaluate
+);
+
+/** Performs a binary disection on a given vector.
+ *  Searches through an array of data for a specified value.
+ *
+ *  @return psS32    corresponding index number of specified value
+ */
+psS32 p_psVectorBinDisect(
+    psVector *bins,                    ///< Array of non-decreasing values
+    psScalar *x                        ///< Target value to find
+);
+
+/** Interpolates a series of data points for evaluation at a specific coordinate.  Uses a
+ *  Lagrange interpolation method.
+ *
+ *  @return psScalar*    Lagrange interpolation value at given location
+ */
+psScalar *p_psVectorInterpolate(
+    psVector *domain,                  ///< Domain (x coords) for interpolation
+    psVector *range,                   ///< Range (y coords) for interpolation
+    int order,                         ///< Order of interpolation function
+    psScalar *x                        ///< Location at which to evaluate
+);
+
+#if 0
+psF32 p_psNRSpline1DEval(psSpline1D *spline,
+                         const psVector* x,
+                         const psVector* y,
+                         psF32 X);
+#endif // #if 0
+
+/** \} */ // End of MathGroup Functions
+
+#endif // #ifndef PS_FUNCTIONS_H
+
Index: /trunk/psLib/src/math/psMatrix.c
===================================================================
--- /trunk/psLib/src/math/psMatrix.c	(revision 4539)
+++ /trunk/psLib/src/math/psMatrix.c	(revision 4540)
@@ -21,6 +21,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 01:15:01 $
+ *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -43,5 +43,5 @@
 #include "psMatrix.h"
 #include "psConstants.h"
-#include "psDataManipErrors.h"
+#include "psErrorText.h"
 
 
Index: /trunk/psLib/src/math/psMinimize.c
===================================================================
--- /trunk/psLib/src/math/psMinimize.c	(revision 4539)
+++ /trunk/psLib/src/math/psMinimize.c	(revision 4540)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.123 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-20 22:42:30 $
+ *  @version $Revision: 1.124 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -1357,11 +1357,11 @@
 XXX: type F32 is done via vector conversion only.
  *****************************************************************************/
-psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* myPoly,
+psPolynomial1D* psVectorFitPolynomial1D(psPolynomial1D* poly,
                                         const psVector* x,
                                         const psVector* y,
                                         const psVector* yErr)
 {
-    PS_ASSERT_POLY_NON_NULL(myPoly, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(myPoly->n, NULL);
+    PS_ASSERT_POLY_NON_NULL(poly, NULL);
+    PS_ASSERT_INT_NONNEGATIVE(poly->n, NULL);
     PS_ASSERT_VECTOR_NON_NULL(y, NULL);
     PS_ASSERT_VECTOR_NON_EMPTY(y, NULL);
@@ -1389,5 +1389,5 @@
     if (x == NULL) {
         PS_VECTOR_GEN_X_INDEX_STATIC_F64(x64Static, y->n);
-        if (myPoly->type == PS_POLYNOMIAL_CHEB) {
+        if (poly->type == PS_POLYNOMIAL_CHEB) {
             p_psNormalizeVectorRangeF64(x64Static, -1.0, 1.0);
         }
@@ -1396,5 +1396,5 @@
         PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL);
         PS_VECTOR_CONVERT_F32_TO_F64_STATIC(x, x64, x64Static);
-        if (myPoly->type == PS_POLYNOMIAL_CHEB) {
+        if (poly->type == PS_POLYNOMIAL_CHEB) {
             p_psNormalizeVectorRangeF64(x64, -1.0, 1.0);
         }
@@ -1405,8 +1405,8 @@
     // Call the appropriate vector fitting routine.
     psPolynomial1D *rc = NULL;
-    if (myPoly->type == PS_POLYNOMIAL_CHEB) {
-        rc = vectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
-    } else if (myPoly->type == PS_POLYNOMIAL_ORD) {
-        rc = vectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
+    if (poly->type == PS_POLYNOMIAL_CHEB) {
+        rc = vectorFitPolynomial1DCheby(poly, x64, y64, yErr64);
+    } else if (poly->type == PS_POLYNOMIAL_ORD) {
+        rc = vectorFitPolynomial1DOrd(poly, x64, y64, yErr64);
     } else {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
@@ -1419,5 +1419,5 @@
     }
 
-    return(myPoly);
+    return(poly);
 }
 
@@ -1432,6 +1432,6 @@
 
     psMinimization *min = psAlloc(sizeof(psMinimization));
-    min->maxIter = maxIter;
-    min->tol = tol;
+    *(int*)&min->maxIter = maxIter;
+    *(float*)&min->tol = tol;
     min->value = 0.0;
     min->iter = 0;
@@ -1993,6 +1993,6 @@
         for (i=0;i<numDims;i++) {
             if (myParamMask->data.U8[i] == 0) {
-                dummyMin.maxIter = PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS;
-                dummyMin.tol = PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE;
+                *(int*)&dummyMin.maxIter = PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS;
+                *(float*)&dummyMin.tol = PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE;
                 mul = p_psLineMin(&dummyMin,
                                   Q,
Index: /trunk/psLib/src/math/psMinimize.h
===================================================================
--- /trunk/psLib/src/math/psMinimize.h	(revision 4539)
+++ /trunk/psLib/src/math/psMinimize.h	(revision 4540)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-21 03:01:37 $
+ *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -38,19 +38,19 @@
 
 /** A data structure for minimization routines.
- *  
+ *
  *  Contains numerical analysis parameters/values
  */
 typedef struct
 {
-    psS32 maxIter;                     ///< Convergence limit
-    psF32 tol;                         ///< Error Tolerance
-    psF32 value;                       ///< Value of function at minimum
-    psS32 iter;                        ///< Number of iterations to date
-    psF32 lastDelta;                   ///< The last difference for the fit
+    const int maxIter;                 ///< Convergence limit
+    const float tol;                   ///< Error Tolerance
+    float value;                       ///< Value of function at minimum
+    int iter;                          ///< Number of iterations to date
+    float lastDelta;                   ///< The last difference for the fit
 }
 psMinimization;
 
 /** Allocates a psMinimization structure.
- *  
+ *
  *  @return psMinimization* :   a new psMinimization struct
 */
@@ -74,5 +74,5 @@
  */
 psPolynomial1D* psVectorFitPolynomial1D(
-    psPolynomial1D* myPoly,            ///< Polynomial to fit
+    psPolynomial1D* poly,            ///< Polynomial to fit
     const psVector* x,                 ///< Ordinates (or NULL to just use the indices)
     const psVector* y,                 ///< Coordinates
@@ -81,8 +81,8 @@
 
 /** Derive a one-dimensional spline fit.
- *    
- *  Given a psSpline1D data structure and a set of x,y vectors, this routine 
+ *
+ *  Given a psSpline1D data structure and a set of x,y vectors, this routine
  *  generates the linear splines which satisfy those data points.
- *  
+ *
  *  @return psSpline1D*:  the calculated one-dimensional splines
  */
@@ -96,17 +96,17 @@
 /** Specifies the format of a user-defined function that the general Levenberg-
  *  Marquardt minimizer routine will accept.
- *  
- *  @return psF64:   the single float value of the function given the parameters, 
+ *
+ *  @return float:   the single float value of the function given the parameters,
  *       positions, and derivatives.
  */
 typedef
-psF64 (*psMinimizeLMChi2Func)(
+float (*psMinimizeLMChi2Func)(
     psVector *deriv,                   ///< derivatives of the function
-    psVector *params,                  ///< the parameters used to evaluate the function
-    psVector *x                        ///< positions for evaluation
+    const psVector *params,            ///< the parameters used to evaluate the function
+    const psVector *x                  ///< positions for evaluation
 );
 
 /** Minimizes a specified function based on the Levenberg-Marquardt method.
- *  
+ *
  *  @return bool:   True if successful.
  */
@@ -123,5 +123,5 @@
 
 /** Use specified alpha, beta, params to generate a new guess for Alpha, Beta, Params
- *  
+ *
  *  @return psBool:   True if successful.
  */
@@ -138,5 +138,5 @@
 
 /** Function used to set parameters for generating "best guess" in minimizing Chi-Squared value.
- *  
+ *
  *  @return psF64:    Chi-squared value for new guess
  */
@@ -153,10 +153,10 @@
 /** Specifies the format of a user-defined function that the general Powell
  *  minimizer routine will accept.
- *  
- *  @return psF32:   the single float value of the function given the parameters 
+ *
+ *  @return float:   the single float value of the function given the parameters
  *      and coordinate vectors.
 */
 typedef
-psF32 (*psMinimizePowellFunc)(
+float (*psMinimizePowellFunc)(
     const psVector *params,            ///< Parameters used to evaluate the function
     const psArray *coords              ///< Coordinates at which to evaluate
@@ -164,5 +164,5 @@
 
 /** Minimizes a specified function based on the Powell method.
- *  
+ *
  *  @return bool:   True if successful.
  */
@@ -177,5 +177,5 @@
 /** Calculates the one-dimensional Gaussian in a format acceptable to the Levenberg-
  *  Marquardt minimizer routine.
- * 
+ *
  *  @return psVector*:    Calculated values
  */
@@ -188,5 +188,5 @@
 /** Calculates the one-dimensional Gaussian in a format acceptable to the Powell
  *  chi-squared minimizer routine.
- *  
+ *
  *  @return psVector*:   Calculated values
  */
@@ -198,5 +198,5 @@
 /** Specifies the format of a user-defined function that the general Powell chi-
  *  squared minimizer routine will accept.
- *  
+ *
  *  @return psVector*:    Calculated values given the parameters and coordinates.
 */
@@ -208,5 +208,5 @@
 
 /** Minimizes a specified function based on the Powell chi-squared method.
- * 
+ *
  *  @return bool:   True is successful.
  */
@@ -222,5 +222,5 @@
 
 /** Gauss-Jordan numerical solver.
- *  
+ *
  *  @return bool:   True if successful.
  */
Index: unk/psLib/src/math/psPolynomial.c
===================================================================
--- /trunk/psLib/src/math/psPolynomial.c	(revision 4539)
+++ 	(revision )
@@ -1,2201 +1,0 @@
-/** @file  psFunctions.c
- *
- *  @brief Contains basic function allocation, deallocation, and evaluation
- *         routines.
- *
- *  This file will hold the functions for allocated, freeing, and evaluating
- *  polynomials.  It also contains a Gaussian functions.
- *
- *  @version $Revision: 1.114 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-29 03:23:19 $
- *
- *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
- *
- *  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
- *
- *  XXX: In the various polyAlloc(n) functions, n is really the order of the
- *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
- */
-/*****************************************************************************/
-/*  INCLUDE FILES                                                            */
-/*****************************************************************************/
-#include <gsl/gsl_rng.h>
-#include <gsl/gsl_randist.h>
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <float.h>
-#include <math.h>
-
-#include "psMemory.h"
-#include "psVector.h"
-#include "psScalar.h"
-#include "psTrace.h"
-#include "psError.h"
-#include "psLogMsg.h"
-#include "psFunctions.h"
-#include "psConstants.h"
-
-#include "psDataManipErrors.h"
-
-/*****************************************************************************/
-/* DEFINE STATEMENTS                                                         */
-/*****************************************************************************/
-
-/*****************************************************************************/
-/* TYPE DEFINITIONS                                                          */
-/*****************************************************************************/
-static void polynomial1DFree(psPolynomial1D* poly);
-static void polynomial2DFree(psPolynomial2D* poly);
-static void polynomial3DFree(psPolynomial3D* poly);
-static void polynomial4DFree(psPolynomial4D* poly);
-static void dPolynomial1DFree(psDPolynomial1D* poly);
-static void dPolynomial2DFree(psDPolynomial2D* poly);
-static void dPolynomial3DFree(psDPolynomial3D* poly);
-static void dPolynomial4DFree(psDPolynomial4D* poly);
-static void spline1DFree(psSpline1D *tmpSpline);
-static psS32 vectorBinDisectF32(psF32 *bins,psS32 numBins,psF32 x);
-static psS32 vectorBinDisectS32(psS32 *bins,psS32 numBins,psS32 x);
-
-/*****************************************************************************/
-/* GLOBAL VARIABLES                                                          */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/* FILE STATIC VARIABLES                                                     */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/* FUNCTION IMPLEMENTATION - LOCAL                                           */
-/*****************************************************************************/
-
-static void spline1DFree(psSpline1D *tmpSpline)
-{
-    psS32 i;
-
-    if (tmpSpline == NULL) {
-        return;
-    }
-
-    if (tmpSpline->spline != NULL) {
-        for (i=0;i<tmpSpline->n;i++) {
-            psFree((tmpSpline->spline)[i]);
-        }
-        psFree(tmpSpline->spline);
-    }
-
-    if (tmpSpline->p_psDeriv2 != NULL) {
-        psFree(tmpSpline->p_psDeriv2);
-    }
-    psFree(tmpSpline->knots);
-
-    return;
-}
-
-static void polynomial1DFree(psPolynomial1D* poly)
-{
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void polynomial2DFree(psPolynomial2D* poly)
-{
-    unsigned int x = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void polynomial3DFree(psPolynomial3D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void polynomial4DFree(psPolynomial4D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            for (z = 0; z < poly->nZ; z++) {
-                psFree(poly->coeff[x][y][z]);
-                psFree(poly->coeffErr[x][y][z]);
-                psFree(poly->mask[x][y][z]);
-            }
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial1DFree(psDPolynomial1D* poly)
-{
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial2DFree(psDPolynomial2D* poly)
-{
-    for (unsigned int x = 0; x < poly->nX; x++) {
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial3DFree(psDPolynomial3D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial4DFree(psDPolynomial4D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            for (z = 0; z < poly->nZ; z++) {
-                psFree(poly->coeff[x][y][z]);
-                psFree(poly->coeffErr[x][y][z]);
-                psFree(poly->mask[x][y][z]);
-            }
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-/*****************************************************************************
-createChebyshevPolys(n): this routine takes as input the required order n,
-and returns as output as a pointer to an array of n psPolynomial1D
-structures, corresponding to the first n Chebyshev polynomials.
- 
-XXX: The output should be static since the Chebyshev polynomials might be
-used frequently and the data structure created here does not contain the
-outer coefficients of the Chebyshev polynomials.
- *****************************************************************************/
-static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly)
-{
-    PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);
-
-    psPolynomial1D **chebPolys = NULL;
-
-    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
-    for (psS32 i = 0; i < maxChebyPoly; i++) {
-        chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
-    }
-
-    // Create the Chebyshev polynomials.
-    // Polynomial i has i-th order.
-    chebPolys[0]->coeff[0] = 1;
-
-    // XXX: Bug 296
-    if (maxChebyPoly > 1) {
-        chebPolys[1]->coeff[1] = 1;
-
-        for (psS32 i = 2; i < maxChebyPoly; i++) {
-            for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
-                chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
-            }
-            for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
-                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
-            }
-        }
-    } else {
-        // XXX: Code this.
-        printf("WARNING: %d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
-    }
-
-    return (chebPolys);
-}
-
-/*****************************************************************************
-    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
- *****************************************************************************/
-static psF32 ordPolynomial1DEval(psF32 x, const psPolynomial1D* poly)
-{
-    psS32 loop_x = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-
-    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
-            "---- Calling ordPolynomial1DEval(%f)\n", x);
-    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
-            "Polynomial order is %d\n", poly->n);
-    for (loop_x = 0; loop_x < poly->n; loop_x++) {
-        psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
-                "Polynomial coeff[%d] is %f\n", loop_x, poly->coeff[loop_x]);
-    }
-
-    for (loop_x = 0; loop_x < poly->n; loop_x++) {
-        if (poly->mask[loop_x] == 0) {
-            psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 10,
-                    "polysum+= sum*coeff [%f+= (%f * %f)\n", polySum, xSum, poly->coeff[loop_x]);
-            polySum += xSum * poly->coeff[loop_x];
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-// XXX: You can do this without having to psAlloc() vector d.
-// XXX: How does the mask vector effect Crenshaw's formula?
-// XXX: We assume that x is scaled between -1.0 and 1.0;
-static psF32 chebPolynomial1DEval(psF32 x, const psPolynomial1D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    // XXX: Create a macro for this in psConstants.h
-    if (poly->n < 1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %d.", poly->n);
-        return(NAN);
-    }
-    psVector *d;
-    psS32 n = poly->n;
-    psS32 i;
-    psF32 tmp = 0.0;
-
-    // Special case where the Chebyshev poly is constant.
-    if (n == 1) {
-        if (poly->mask[0] == 0) {
-            tmp += poly->coeff[0];
-        }
-        return(tmp);
-    }
-
-    // Special case where the Chebyshev poly is linear.
-    if (n == 2) {
-        if (poly->mask[0] == 0) {
-            tmp+= poly->coeff[0];
-        }
-        if (poly->mask[1] == 0) {
-            tmp+= poly->coeff[1] * x;
-        }
-        return(tmp);
-    }
-
-    // General case where the Chebyshev poly has 2 or more terms.
-    d = psVectorAlloc(n, PS_TYPE_F32);
-    if(poly->mask[n-1] == 0) {
-        d->data.F32[n-1] = poly->coeff[n-1];
-    } else {
-        d->data.F32[n-1] = 0.0;
-    }
-
-    d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]);
-    if(poly->mask[n-2] == 0) {
-        d->data.F32[n-2] += poly->coeff[n-2];
-    }
-
-    for (i=n-3;i>=1;i--) {
-        d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
-                         (d->data.F32[i+2]);
-        if(poly->mask[i] == 0) {
-            d->data.F32[i] += poly->coeff[i];
-        }
-    }
-
-    tmp = (x * d->data.F32[1]) -
-          (d->data.F32[2]);
-    if(poly->mask[0] == 0) {
-        tmp += (0.5 * poly->coeff[0]);
-    }
-    psFree(d);
-    return(tmp);
-
-    /* This is old code that does not use Clenshaw's formula.  Get rid of it.
-
-    psS32 n;
-    psS32 i;
-    psF32 tmp;
-    psPolynomial1D **chebPolys = NULL;
-
-    n = poly->n;
-    chebPolys = createChebyshevPolys(n);
-
-    tmp = 0.0;
-    for (i=0;i<poly->n;i++) {
-        tmp+= (poly->coeff[i] * psPolynomial1DEval(x, chebPolys[i]));
-    }
-    tmp-= (poly->coeff[0]/2.0);
-
-
-    return(tmp);
-    */
-}
-
-static psF32 ordPolynomial2DEval(psF32 x,
-                                 psF32 y,
-                                 const psPolynomial2D* poly)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-    psF32 ySum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += ySum * poly->coeff[loop_x][loop_y];
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF32 chebPolynomial2DEval(psF32 x, psF32 y, const psPolynomial2D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 i = 0;
-    psF32 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += poly->coeff[loop_x][loop_y] *
-                           psPolynomial1DEval(chebPolys[loop_x], x) *
-                           psPolynomial1DEval(chebPolys[loop_y], y);
-            }
-        }
-    }
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF32 ordPolynomial3DEval(psF32 x, psF32 y, psF32 z, const psPolynomial3D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-    psF32 ySum = 1.0;
-    psF32 zSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += zSum * poly->coeff[loop_x][loop_y][loop_z];
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF32 chebPolynomial3DEval(psF32 x, psF32 y, psF32 z, const psPolynomial3D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 i = 0;
-    psF32 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += poly->coeff[loop_x][loop_y][loop_z] *
-                               psPolynomial1DEval(chebPolys[loop_x], x) *
-                               psPolynomial1DEval(chebPolys[loop_y], y) *
-                               psPolynomial1DEval(chebPolys[loop_z], z);
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF32 ordPolynomial4DEval(psF32 x, psF32 y, psF32 z, psF32 t, const psPolynomial4D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-    psF32 ySum = 1.0;
-    psF32 zSum = 1.0;
-    psF32 tSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                tSum = zSum;
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += tSum * poly->coeff[loop_x][loop_y][loop_z][loop_t];
-                    }
-                    tSum *= t;
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF32 chebPolynomial4DEval(psF32 x, psF32 y, psF32 z, psF32 t, const psPolynomial4D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(t, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psS32 i = 0;
-    psF32 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    if (poly->nT > maxChebyPoly) {
-        maxChebyPoly = poly->nT;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] *
-                                   psPolynomial1DEval(chebPolys[loop_x], x) *
-                                   psPolynomial1DEval(chebPolys[loop_y], y) *
-                                   psPolynomial1DEval(chebPolys[loop_z], z) *
-                                   psPolynomial1DEval(chebPolys[loop_t], t);
-                    }
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-/*****************************************************************************
-    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
- *****************************************************************************/
-static psF64 dOrdPolynomial1DEval(psF64 x, const psDPolynomial1D* poly)
-{
-    psS32 loop_x = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->n; loop_x++) {
-        if (poly->mask[loop_x] == 0) {
-            polySum += xSum * poly->coeff[loop_x];
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-// XXX: You can do this without having to psAlloc() vector d.
-// XXX: How does the mask vector effect Crenshaw's formula?
-static psF64 dChebPolynomial1DEval(psF64 x, const psDPolynomial1D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    psVector *d;
-    psS32 n;
-    psS32 i;
-    psF64 tmp;
-
-    n = poly->n;
-    d = psVectorAlloc(n, PS_TYPE_F64);
-    if(poly->mask[n-1] == 0) {
-        d->data.F64[n-1] = poly->coeff[n-1];
-    } else {
-        d->data.F64[n-1] = 0.0;
-    }
-    d->data.F64[n-2] = (2.0 * x * d->data.F64[n-1]);
-    if(poly->mask[n-2] == 0) {
-        d->data.F64[n-2] += poly->coeff[n-2];
-    }
-    for (i=n-3;i>=1;i--) {
-        d->data.F64[i] = (2.0 * x * d->data.F64[i+1]) -
-                         (d->data.F64[i+2]);
-        if(poly->mask[i] == 0) {
-            d->data.F64[i] += poly->coeff[i];
-        }
-    }
-
-    tmp = (x * d->data.F64[1]) -
-          (d->data.F64[2]);
-    if(poly->mask[0] == 0) {
-        tmp += (0.5 * poly->coeff[0]);
-    }
-
-    psFree(d);
-    return(tmp);
-}
-
-static psF64 dOrdPolynomial2DEval(psF64 x,
-                                  psF64 y,
-                                  const psDPolynomial2D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-    psF64 ySum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += ySum * poly->coeff[loop_x][loop_y];
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF64 dChebPolynomial2DEval(psF64 x, psF64 y, const psDPolynomial2D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 i = 0;
-    psF64 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += poly->coeff[loop_x][loop_y] *
-                           psPolynomial1DEval(chebPolys[loop_x], x) *
-                           psPolynomial1DEval(chebPolys[loop_y], y);
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF64 dOrdPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psDPolynomial3D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-    psF64 ySum = 1.0;
-    psF64 zSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += zSum * poly->coeff[loop_x][loop_y][loop_z];
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF64 dChebPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psDPolynomial3D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 i = 0;
-    psF64 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += poly->coeff[loop_x][loop_y][loop_z] *
-                               psPolynomial1DEval(chebPolys[loop_x], x) *
-                               psPolynomial1DEval(chebPolys[loop_y], y) *
-                               psPolynomial1DEval(chebPolys[loop_z], z);
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF64 dOrdPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psDPolynomial4D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-    psF64 ySum = 1.0;
-    psF64 zSum = 1.0;
-    psF64 tSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                tSum = zSum;
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += tSum * poly->coeff[loop_x][loop_y][loop_z][loop_t];
-                    }
-                    tSum *= t;
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF64 dChebPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psDPolynomial4D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(t, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psS32 i = 0;
-    psF64 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    if (poly->nT > maxChebyPoly) {
-        maxChebyPoly = poly->nT;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] *
-                                   psPolynomial1DEval(chebPolys[loop_x], x) *
-                                   psPolynomial1DEval(chebPolys[loop_y], y) *
-                                   psPolynomial1DEval(chebPolys[loop_z], z) *
-                                   psPolynomial1DEval(chebPolys[loop_t], t);
-                    }
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-
-/*****************************************************************************
-fullInterpolate1DF32(): This routine will take as input n-element floating
-point arrays domain and range, and the x value, assumed to lie with the
-domain vector.  It produces as output the (n-1)-order LaGrange interpolated
-value of x.
- 
-XXX: do we error check for non-distinct domain values?
- *****************************************************************************/
-#define FUNC_MACRO_FULL_INTERPOLATE_1D(TYPE) \
-static psF32 fullInterpolate1D##TYPE(ps##TYPE *domain, \
-                                     ps##TYPE *range, \
-                                     psS32 n, \
-                                     ps##TYPE x) \
-{ \
-    \
-    psS32 i; \
-    psS32 m; \
-    static psVector *p = NULL; \
-    p = psVectorRecycle(p, n, PS_TYPE_##TYPE); \
-    p_psMemSetPersistent(p, true); \
-    p_psMemSetPersistent(p->data.TYPE, true); \
-    \
-    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 4, \
-            "---- fullInterpolate1D##TYPE() begin (%d-order at x=%f) (%d data points)----\n", n-1, x, n); \
-    \
-    for (i=0;i<n;i++) { \
-        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
-                "domain/range is (%f %f)\n", domain[i], range[i]); \
-    } \
-    \
-    for (i=0;i<n;i++) { \
-        p->data.TYPE[i] = range[i]; \
-        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
-                "p->data.TYPE[%d] is %f\n", i, p->data.TYPE[i]); \
-        \
-    } \
-    \
-    /* From NR, during each iteration of the m loop, we are computing the \
-       p_{i ... i+m} terms. \
-    */ \
-    for (m=1;m<n;m++) { \
-        for (i=0;i<n-m;i++) { \
-            /* From NR: we are computing P_{i ... i+m} \
-             */ \
-            p->data.TYPE[i] = (((x-domain[i+m]) * p->data.TYPE[i]) + \
-                               ((domain[i]-x) * p->data.TYPE[i+1])) / \
-                              (domain[i] - domain[i+m]); \
-            /*printf("((%f-%f * %f) + (%f-%f * %f)) / (%f - %f)\n", x, domain[i+m], p->data.TYPE[i], domain[i], x, p->data.TYPE[i+1], domain[i], domain[i+m]); \
-             */ \
-            psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
-                    "p->data.TYPE[%d] is %f\n", i, p->data.TYPE[i]); \
-        } \
-    } \
-    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 4, \
-            "---- fullInterpolate1D##TYPE() end ----\n"); \
-    \
-    return(p->data.TYPE[0]); \
-} \
-
-/*
-FUNC_MACRO_FULL_INTERPOLATE_1D(U8)
-FUNC_MACRO_FULL_INTERPOLATE_1D(U16)
-FUNC_MACRO_FULL_INTERPOLATE_1D(U32)
-FUNC_MACRO_FULL_INTERPOLATE_1D(U64)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S8)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S16)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S32)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S64)
-FUNC_MACRO_FULL_INTERPOLATE_1D(F64)
-*/
-FUNC_MACRO_FULL_INTERPOLATE_1D(F32)
-
-
-/*****************************************************************************
-interpolate1DF32(): this is the base 1-D flat memory routine to perform
-LaGrange interpolation.
- *****************************************************************************/
-static psF32 interpolate1DF32(psF32 *domain,
-                              psF32 *range,
-                              psS32 n,
-                              psS32 order,
-                              psF32 x)
-{
-    PS_ASSERT_PTR_NON_NULL(domain, NAN)
-    PS_ASSERT_PTR_NON_NULL(range, NAN)
-    // XXX: Check valid values for n, order, and x?
-
-    psS32 binNum;
-    psS32 numIntPoints = order+1;
-    psS32 origin;
-
-    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
-            "---- interpolate1DF32() begin ----\n");
-
-    binNum = vectorBinDisectF32(domain, n, x);
-
-    if (0 == numIntPoints%2) {
-        origin = binNum - ((numIntPoints/2) - 1);
-    } else {
-        origin = binNum - (numIntPoints/2);
-        if ((x-domain[binNum]) > (domain[binNum+1]-x)) {
-            // x is closer to binNum+1.
-            origin = 1 + (binNum - (numIntPoints/2));
-        }
-    }
-    if (origin < 0) {
-        origin = 0;
-    }
-    if ((origin + numIntPoints) > n) {
-        origin = n - numIntPoints;
-    }
-
-    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
-            "---- interpolate1DF32() end ----\n");
-    return(fullInterpolate1DF32(&domain[origin], &range[origin], order+1, x));
-}
-
-/*****************************************************************************/
-/*  FUNCTION IMPLEMENTATION - PUBLIC                                         */
-/*****************************************************************************/
-
-/*****************************************************************************
-    Evaluate a non-normalized Gaussian with the given mean and sigma at the
-    given coordianate.  Note that this is not a Gaussian deviate.  The
-    evaluated Gaussian is: \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
- *****************************************************************************/
-float psGaussian(float x, float mean, float sigma, bool normal)
-{
-    psF32 tmp = 1.0;
-
-    psTrace(".psLib.dataManip.psFunctions.psGaussian", 4,
-            "---- psGaussian() begin ----\n");
-
-    if (normal == true) {
-        tmp = 1.0 / sqrtf(2.0 * M_PI * (sigma * sigma));
-    }
-
-    psTrace(".psLib.dataManip.psFunctions.psGaussian", 4,
-            "---- psGaussian() end ----\n");
-    return(tmp * exp(-((x - mean) * (x - mean)) / (2.0 * sigma * sigma)));
-}
-
-/*****************************************************************************
-    p_psGaussianDev()
- This private routine (formerly a psLib API routine) creates a psVector of the
- specified size and type F32 and fills it with a random Gaussian distribution
- of numbers with the specified mean and sigma.  This routine makes use of the
- GSL routines for generating both uniformly distributed numbers and the
- Gaussian distribution as well.
- 
-XXX: There is no way to seed the random generator.
- *****************************************************************************/
-psVector* p_psGaussianDev(psF32 mean, psF32 sigma, psS32 Npts)
-{
-    PS_ASSERT_INT_NONNEGATIVE(Npts, NULL);
-
-    psVector* gauss = NULL;
-    const gsl_rng_type *T = NULL;
-    gsl_rng *r = NULL;
-    psS32 i = 0;
-
-
-    gauss = psVectorAlloc(Npts, PS_TYPE_F32);
-    gauss->n = Npts;
-    gsl_rng_env_setup();
-    T = gsl_rng_default;
-    r = gsl_rng_alloc(T);
-
-    for (i = 0; i < Npts; i++) {
-        gauss->data.F32[i] = mean + gsl_ran_gaussian(r, sigma);
-    }
-
-    // XXX: Should I free r, T as well?  This is a memory leak.
-    return(gauss);
-}
-
-/*****************************************************************************
-    This routine must allocate memory for the polynomial structures.
- *****************************************************************************/
-psPolynomial1D* psPolynomial1DAlloc(unsigned int n,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(n, NULL);
-
-    int i = 0;
-    psPolynomial1D* newPoly = NULL;
-
-    newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree);
-
-    newPoly->type = type;
-    newPoly->n = n;
-    newPoly->coeff = (psF32 *)psAlloc(n * sizeof(psF32));
-    newPoly->coeffErr = (psF32 *)psAlloc(n * sizeof(psF32));
-    newPoly->mask = (psU8 *)psAlloc(n * sizeof(psU8));
-    for (i = 0; i < n; i++) {
-        newPoly->coeff[i] = 0.0;
-        newPoly->coeffErr[i] = 0.0;
-        newPoly->mask[i] = 0;
-    }
-
-    return(newPoly);
-}
-
-psPolynomial2D* psPolynomial2DAlloc(unsigned int nX, unsigned int nY,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-
-    int x = 0;
-    int y = 0;
-    psPolynomial2D* newPoly = NULL;
-
-    newPoly = (psPolynomial2D* ) psAlloc(sizeof(psPolynomial2D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial2DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-
-    newPoly->coeff = (psF32 **)psAlloc(nX * sizeof(psF32 *));
-    newPoly->coeffErr = (psF32 **)psAlloc(nX * sizeof(psF32 *));
-    newPoly->mask = (psU8 **)psAlloc(nX * sizeof(psU8 *));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF32 *)psAlloc(nY * sizeof(psF32));
-        newPoly->coeffErr[x] = (psF32 *)psAlloc(nY * sizeof(psF32));
-        newPoly->mask[x] = (psU8 *)psAlloc(nY * sizeof(psU8));
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = 0.0;
-            newPoly->coeffErr[x][y] = 0.0;
-            newPoly->mask[x][y] = 0;
-        }
-    }
-
-    return(newPoly);
-}
-
-psPolynomial3D* psPolynomial3DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-
-    psS32 x = 0;
-    psS32 y = 0;
-    psS32 z = 0;
-    psPolynomial3D* newPoly = NULL;
-
-    newPoly = (psPolynomial3D* ) psAlloc(sizeof(psPolynomial3D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial3DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-
-    newPoly->coeff = (psF32 ***)psAlloc(nX * sizeof(psF32 **));
-    newPoly->coeffErr = (psF32 ***)psAlloc(nX * sizeof(psF32 **));
-    newPoly->mask = (psU8 ***)psAlloc(nX * sizeof(psU8 **));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF32 **)psAlloc(nY * sizeof(psF32 *));
-        newPoly->coeffErr[x] = (psF32 **)psAlloc(nY * sizeof(psF32 *));
-        newPoly->mask[x] = (psU8 **)psAlloc(nY * sizeof(psU8 *));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF32 *)psAlloc(nZ * sizeof(psF32));
-            newPoly->coeffErr[x][y] = (psF32 *)psAlloc(nZ * sizeof(psF32));
-            newPoly->mask[x][y] = (psU8 *)psAlloc(nZ * sizeof(psU8));
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = 0.0;
-                newPoly->coeffErr[x][y][z] = 0.0;
-                newPoly->mask[x][y][z] = 0;
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-psPolynomial4D* psPolynomial4DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nT,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-    PS_ASSERT_INT_POSITIVE(nT, NULL);
-
-    psS32 x = 0;
-    psS32 y = 0;
-    psS32 z = 0;
-    psS32 t = 0;
-    psPolynomial4D* newPoly = NULL;
-
-    newPoly = (psPolynomial4D* ) psAlloc(sizeof(psPolynomial4D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial4DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-    newPoly->nT = nT;
-
-    newPoly->coeff = (psF32 ****)psAlloc(nX * sizeof(psF32 ***));
-    newPoly->coeffErr = (psF32 ****)psAlloc(nX * sizeof(psF32 ***));
-    newPoly->mask = (psU8 ****)psAlloc(nX * sizeof(psU8 ***));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF32 ***)psAlloc(nY * sizeof(psF32 **));
-        newPoly->coeffErr[x] = (psF32 ***)psAlloc(nY * sizeof(psF32 **));
-        newPoly->mask[x] = (psU8 ***)psAlloc(nY * sizeof(psU8 **));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF32 **)psAlloc(nZ * sizeof(psF32 *));
-            newPoly->coeffErr[x][y] = (psF32 **)psAlloc(nZ * sizeof(psF32 *));
-            newPoly->mask[x][y] = (psU8 **)psAlloc(nZ * sizeof(psU8 *));
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = (psF32 *)psAlloc(nT * sizeof(psF32));
-                newPoly->coeffErr[x][y][z] = (psF32 *)psAlloc(nT * sizeof(psF32));
-                newPoly->mask[x][y][z] = (psU8 *)psAlloc(nT * sizeof(psU8));
-            }
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                for (t = 0; t < nT; t++) {
-                    newPoly->coeff[x][y][z][t] = 0.0;
-                    newPoly->coeffErr[x][y][z][t] = 0.0;
-                    newPoly->mask[x][y][z][t] = 0;
-                }
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-psF64 psPolynomial1DEval(const psPolynomial1D* poly, psF64 x)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial1DEval(x, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial1DEval(x, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial1DEvalVector(const psPolynomial1D *poly,
-                                   const psVector *x)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-
-    tmp = psVectorAlloc(x->n, PS_TYPE_F32);
-    for (psS32 i=0;i<x->n;i++) {
-        tmp->data.F32[i] = psPolynomial1DEval(poly, x->data.F32[i]);
-    }
-
-    return(tmp);
-}
-
-psF64 psPolynomial2DEval(const psPolynomial2D* poly, psF64 x, psF64 y)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial2DEval(x, y, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial2DEval(x, y, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial2DEvalVector(const psPolynomial2D *poly,
-                                   const psVector *x,
-                                   const psVector *y)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the length of the output vector to by the minimum of the x,y vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-
-    // Create output vector to return
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
-
-    // Evaluate the polynomial at the specified points
-    for (psS32 i=0; i<vecLen; i++) {
-        tmp->data.F32[i] = psPolynomial2DEval(poly,x->data.F32[i],y->data.F32[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-psF64 psPolynomial3DEval(const psPolynomial3D* poly, psF64 x, psF64 y, psF64 z)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial3DEval(x, y, z, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial3DEval(x, y, z, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial3DEvalVector(const psPolynomial3D *poly,
-                                   const psVector *x,
-                                   const psVector *y,
-                                   const psVector *z)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the length of output vector from min of the input vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
-
-    // Evaluate polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F32[i] = psPolynomial3DEval(poly,
-                                              x->data.F32[i],
-                                              y->data.F32[i],
-                                              z->data.F32[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-psF64 psPolynomial4DEval(const psPolynomial4D* poly, psF64 x, psF64 y, psF64 z, psF64 t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial4DEval(x,y,z,t, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial4DEval(x,y,z,t, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial4DEvalVector(const psPolynomial4D *poly,
-                                   const psVector *x,
-                                   const psVector *y,
-                                   const psVector *z,
-                                   const psVector *t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(t, NULL);
-    PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine output vector size from min of input vectors
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (t->n < vecLen) {
-        vecLen = t->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
-
-    // Evaluate polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F32[i] = psPolynomial4DEval(poly,
-                                              x->data.F32[i],
-                                              y->data.F32[i],
-                                              z->data.F32[i],
-                                              t->data.F32[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-
-psDPolynomial1D* psDPolynomial1DAlloc(unsigned int n,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(n, NULL);
-
-    unsigned int i = 0;
-    psDPolynomial1D* newPoly = NULL;
-
-    newPoly = (psDPolynomial1D* ) psAlloc(sizeof(psDPolynomial1D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial1DFree);
-
-    newPoly->type = type;
-    newPoly->n = n;
-    newPoly->coeff = (psF64 *)psAlloc(n * sizeof(psF64));
-    newPoly->coeffErr = (psF64 *)psAlloc(n * sizeof(psF64));
-    newPoly->mask = (psU8 *)psAlloc(n * sizeof(psU8));
-    for (i = 0; i < n; i++) {
-        newPoly->coeff[i] = 0.0;
-        newPoly->coeffErr[i] = 0.0;
-        newPoly->mask[i] = 0;
-    }
-
-    return(newPoly);
-}
-
-psDPolynomial2D* psDPolynomial2DAlloc(unsigned int nX, unsigned int nY,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-
-    unsigned int x = 0;
-    unsigned int y = 0;
-    psDPolynomial2D* newPoly = NULL;
-
-    newPoly = (psDPolynomial2D* ) psAlloc(sizeof(psDPolynomial2D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial2DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-
-    newPoly->coeff = (psF64 **)psAlloc(nX * sizeof(psF64 *));
-    newPoly->coeffErr = (psF64 **)psAlloc(nX * sizeof(psF64 *));
-    newPoly->mask = (psU8 **)psAlloc(nX * sizeof(psU8 *));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF64 *)psAlloc(nY * sizeof(psF64));
-        newPoly->coeffErr[x] = (psF64 *)psAlloc(nY * sizeof(psF64));
-        newPoly->mask[x] = (psU8 *)psAlloc(nY * sizeof(psU8));
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = 0.0;
-            newPoly->coeffErr[x][y] = 0.0;
-            newPoly->mask[x][y] = 0;
-        }
-    }
-
-    return(newPoly);
-}
-
-psDPolynomial3D* psDPolynomial3DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-    psDPolynomial3D* newPoly = NULL;
-
-    newPoly = (psDPolynomial3D* ) psAlloc(sizeof(psDPolynomial3D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial3DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-
-    newPoly->coeff = (psF64 ***)psAlloc(nX * sizeof(psF64 **));
-    newPoly->coeffErr = (psF64 ***)psAlloc(nX * sizeof(psF64 **));
-    newPoly->mask = (psU8 ***)psAlloc(nX * sizeof(psU8 **));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF64 **)psAlloc(nY * sizeof(psF64 *));
-        newPoly->coeffErr[x] = (psF64 **)psAlloc(nY * sizeof(psF64 *));
-        newPoly->mask[x] = (psU8 **)psAlloc(nY * sizeof(psU8 *));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF64 *)psAlloc(nZ * sizeof(psF64));
-            newPoly->coeffErr[x][y] = (psF64 *)psAlloc(nZ * sizeof(psF64));
-            newPoly->mask[x][y] = (psU8 *)psAlloc(nZ * sizeof(psU8));
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = 0.0;
-                newPoly->coeffErr[x][y][z] = 0.0;
-                newPoly->mask[x][y][z] = 0;
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-psDPolynomial4D* psDPolynomial4DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nT,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-    PS_ASSERT_INT_POSITIVE(nT, NULL);
-
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-    unsigned int t = 0;
-    psDPolynomial4D* newPoly = NULL;
-
-    newPoly = (psDPolynomial4D* ) psAlloc(sizeof(psDPolynomial4D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial4DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-    newPoly->nT = nT;
-
-    newPoly->coeff = (psF64 ****)psAlloc(nX * sizeof(psF64 ***));
-    newPoly->coeffErr = (psF64 ****)psAlloc(nX * sizeof(psF64 ***));
-    newPoly->mask = (psU8 ****)psAlloc(nX * sizeof(psU8 ***));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF64 ***)psAlloc(nY * sizeof(psF64 **));
-        newPoly->coeffErr[x] = (psF64 ***)psAlloc(nY * sizeof(psF64 **));
-        newPoly->mask[x] = (psU8 ***)psAlloc(nY * sizeof(psU8 **));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF64 **)psAlloc(nZ * sizeof(psF64 *));
-            newPoly->coeffErr[x][y] = (psF64 **)psAlloc(nZ * sizeof(psF64 *));
-            newPoly->mask[x][y] = (psU8 **)psAlloc(nZ * sizeof(psU8 *));
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = (psF64 *)psAlloc(nT * sizeof(psF64));
-                newPoly->coeffErr[x][y][z] = (psF64 *)psAlloc(nT * sizeof(psF64));
-                newPoly->mask[x][y][z] = (psU8 *)psAlloc(nT * sizeof(psU8));
-            }
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                for (t = 0; t < nT; t++) {
-                    newPoly->coeff[x][y][z][t] = 0.0;
-                    newPoly->coeffErr[x][y][z][t] = 0.0;
-                    newPoly->mask[x][y][z][t] = 0;
-                }
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-
-psF64 psDPolynomial1DEval(const psDPolynomial1D* poly, psF64 x)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial1DEval(x, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial1DEval(x, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial1DEvalVector(const psDPolynomial1D *poly,
-                                    const psVector *x)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-
-    tmp = psVectorAlloc(x->n, PS_TYPE_F64);
-    for (psS32 i=0;i<x->n;i++) {
-        tmp->data.F64[i] = psDPolynomial1DEval(poly,
-                                               x->data.F64[i]);
-    }
-
-    return(tmp);
-}
-
-
-psF64 psDPolynomial2DEval(const psDPolynomial2D* poly,
-                          psF64 x,
-                          psF64 y)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial2DEval(x, y, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial2DEval(x, y, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial2DEvalVector(const psDPolynomial2D *poly,
-                                    const psVector *x,
-                                    const psVector *y)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the output vector length from minimum length of input vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
-
-    // Evaluate the polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F64[i] = psDPolynomial2DEval(poly,x->data.F64[i],y->data.F64[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-
-psF64 psDPolynomial3DEval(const psDPolynomial3D* poly,
-                          psF64 x,
-                          psF64 y,
-                          psF64 z)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial3DEval(x, y, z, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial3DEval(x, y, z, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial3DEvalVector(const psDPolynomial3D *poly,
-                                    const psVector *x,
-                                    const psVector *y,
-                                    const psVector *z)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the size of output vector from min of input vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
-
-    // Evaluate polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F64[i] = psDPolynomial3DEval(poly,
-                                               x->data.F64[i],
-                                               y->data.F64[i],
-                                               z->data.F64[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-psF64 psDPolynomial4DEval(const psDPolynomial4D* poly,
-                          psF64 x,
-                          psF64 y,
-                          psF64 z,
-                          psF64 t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial4DEval(x,y,z,t, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial4DEval(x,y,z,t, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial4DEvalVector(const psDPolynomial4D *poly,
-                                    const psVector *x,
-                                    const psVector *y,
-                                    const psVector *z,
-                                    const psVector *t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(t, NULL);
-    PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the output vector size from min of input vectors
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (t->n < vecLen) {
-        vecLen = t->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
-
-    // Evaluate the polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F64[i] = psDPolynomial4DEval(poly,
-                                               x->data.F64[i],
-                                               y->data.F64[i],
-                                               z->data.F64[i],
-                                               t->data.F64[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-
-
-
-//typedef struct {
-//    psS32 n;
-//    psPolynomial1D **spline;
-//    psF32 *p_psDeriv2;
-//    psVector *knots;
-//} psSpline1D;
-
-/*****************************************************************************
-    NOTE: "n" specifies the number of spline polynomials.  Therefore, there
-    must exist n+1 points in "knots".
- 
-XXX: Ensure that domain[i+1] != domain[i]
- 
-XXX: What should be the defualty type for knots be?  psF32 is assumed.
- *****************************************************************************/
-psSpline1D *psSpline1DAlloc(int numSplines,
-                            int order,
-                            float min,
-                            float max)
-{
-    PS_ASSERT_INT_NONNEGATIVE(numSplines, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
-    PS_ASSERT_FLOAT_NON_EQUAL(max, min, NULL);
-
-    psSpline1D *tmp = NULL;
-    psS32 i;
-    psF32 tmpDomain;
-    psF32 width;
-
-    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
-    tmp->n = numSplines;
-
-    tmp->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
-    for (i=0;i<numSplines;i++) {
-        (tmp->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
-    }
-
-    // This should be set by the psVectorFitSpline1D()
-    tmp->p_psDeriv2 = NULL;
-
-    tmp->knots = psVectorAlloc(numSplines+1, PS_TYPE_F32);
-    width = (max - min) / ((psF32) numSplines);
-
-    tmp->knots->data.F32[0] = min;
-    tmpDomain = min+width;
-    for (i=1;i<numSplines+1;i++) {
-        tmp->knots->data.F32[i] = tmpDomain;
-        tmpDomain+= width;
-    }
-    tmp->knots->data.F32[numSplines] = max;
-
-    psMemSetDeallocator(tmp,(psFreeFunc)spline1DFree);
-    return(tmp);
-}
-
-
-/*****************************************************************************
-XXX: What should be the defualty type for knots be?  psF32 is assumed.
- *****************************************************************************/
-psSpline1D *psSpline1DAllocGeneric(const psVector *bounds,
-                                   int order)
-{
-    PS_ASSERT_VECTOR_NON_NULL(bounds, NULL);
-    PS_ASSERT_VECTOR_NON_EMPTY(bounds, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
-
-    psSpline1D *tmp = NULL;
-    psS32 i;
-    psS32 numSplines;
-
-    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
-
-    numSplines = bounds->n - 1;
-    tmp->n = numSplines;
-
-    tmp->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
-    for (i=0;i<numSplines;i++) {
-        (tmp->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
-    }
-
-    // This should be set by the psVectorFitSpline1D()
-    tmp->p_psDeriv2 = NULL;
-
-    tmp->knots = psVectorAlloc(bounds->n, PS_TYPE_F32);
-
-    for (i=0;i<bounds->n;i++) {
-        tmp->knots->data.F32[i] = bounds->data.F32[i];
-        if (i<(bounds->n-1)) {
-            if (FLT_EPSILON >= fabs(bounds->data.F32[i+1]-bounds->data.F32[i])) {
-                psError(PS_ERR_UNKNOWN, true, "data points must be distinct\n");
-            }
-        }
-    }
-
-    psMemSetDeallocator(tmp,(psFreeFunc)spline1DFree);
-    return(tmp);
-}
-
-/*****************************************************************************
-vectorBinDisectF32(): This is a macro for a private function which takes as
-input a vector an array of data as well as a single value for that data.  The
-input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all
-i).  This routine does a binary disection of the vector and returns "i" such
-that (v[i] <= x <= v[i+1).  If x lies outside the range of v[], then this
-routine prints a warning message and returns (-2 or -1).
- *****************************************************************************/
-#define FUNC_MACRO_VECTOR_BIN_DISECT(TYPE) \
-static psS32 vectorBinDisect##TYPE(ps##TYPE *bins, \
-                                   psS32 numBins, \
-                                   ps##TYPE x) \
-{ \
-    psS32 min; \
-    psS32 max; \
-    psS32 mid; \
-    \
-    psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-            "---- Calling vectorBinDisect##TYPE(%f)\n", x); \
-    \
-    if (x < bins[0]) { \
-        psLogMsg(__func__, PS_LOG_WARN, \
-                 "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
-                 #TYPE, x, bins[0], bins[numBins-1]); \
-        return(-2); \
-    } \
-    \
-    if (x > bins[numBins-1]) { \
-        psLogMsg(__func__, PS_LOG_WARN, \
-                 "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
-                 #TYPE, x, bins[0], bins[numBins-1]); \
-        return(-1); \
-    } \
-    \
-    min = 0; \
-    max = numBins-2; \
-    mid = ((max+1)-min)/2; \
-    \
-    while (min != max) { \
-        psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-                "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", \
-                min, mid, max, x, bins[mid]); \
-        \
-        if (x == bins[mid]) { \
-            psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-                    "---- Exiting vectorBinDisect##TYPE(): bin %d\n", mid); \
-            return(mid); \
-        } else if (x < bins[mid]) { \
-            max = mid-1; \
-        } else { \
-            min = mid; \
-        } \
-        mid = ((max+1)+min)/2; \
-    } \
-    \
-    psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-            "---- Exiting vectorBinDisect##TYPE(): bin %d\n", min); \
-    return(min); \
-} \
-
-FUNC_MACRO_VECTOR_BIN_DISECT(S8)
-FUNC_MACRO_VECTOR_BIN_DISECT(S16)
-FUNC_MACRO_VECTOR_BIN_DISECT(S32)
-FUNC_MACRO_VECTOR_BIN_DISECT(S64)
-FUNC_MACRO_VECTOR_BIN_DISECT(U8)
-FUNC_MACRO_VECTOR_BIN_DISECT(U16)
-FUNC_MACRO_VECTOR_BIN_DISECT(U32)
-FUNC_MACRO_VECTOR_BIN_DISECT(U64)
-FUNC_MACRO_VECTOR_BIN_DISECT(F32)
-FUNC_MACRO_VECTOR_BIN_DISECT(F64)
-
-/*****************************************************************************
-p_psVectorBinDisect(): A wrapper to the above p_psVectorBinDisect().
- *****************************************************************************/
-psS32 p_psVectorBinDisect(psVector *bins,
-                          psScalar *x)
-{
-    PS_ASSERT_VECTOR_NON_NULL(bins, -4);
-    PS_ASSERT_VECTOR_NON_EMPTY(bins, -4);
-    PS_ASSERT_PTR_NON_NULL(x, -6);
-    PS_ASSERT_PTR_TYPE_EQUAL(x, bins, -3);
-    char* strType;
-
-    switch (x->type.type) {
-    case PS_TYPE_U8:
-        return(vectorBinDisectU8(bins->data.U8, bins->n, x->data.U8));
-    case PS_TYPE_U16:
-        return(vectorBinDisectU16(bins->data.U16, bins->n, x->data.U16));
-    case PS_TYPE_U32:
-        return(vectorBinDisectU32(bins->data.U32, bins->n, x->data.U32));
-    case PS_TYPE_U64:
-        return(vectorBinDisectU64(bins->data.U64, bins->n, x->data.U64));
-    case PS_TYPE_S8:
-        return(vectorBinDisectS8(bins->data.S8, bins->n, x->data.S8));
-    case PS_TYPE_S16:
-        return(vectorBinDisectS16(bins->data.S16, bins->n, x->data.S16));
-    case PS_TYPE_S32:
-        return(vectorBinDisectS32(bins->data.S32, bins->n, x->data.S32));
-    case PS_TYPE_S64:
-        return(vectorBinDisectS64(bins->data.S64, bins->n, x->data.S64));
-    case PS_TYPE_F32:
-        return(vectorBinDisectF32(bins->data.F32, bins->n, x->data.F32));
-    case PS_TYPE_F64:
-        return(vectorBinDisectF64(bins->data.F64, bins->n, x->data.F64));
-    case PS_TYPE_C32:
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return 0;
-    case PS_TYPE_C64:
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return 0;
-    case PS_TYPE_BOOL:
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return 0;
-    }
-    return(-3);
-}
-
-/*****************************************************************************
-p_psVectorInterpolate(): This routine will take as input psVectors domain and
-range, and the x value, assumed to lie with the domain vector.  It produces
-as output the LaGrange interpolated value of a polynomial of the specified
-order around the point x.
- 
-XXX: This stuff does not currently work with a mask.
- 
-XXX: add another psScalar argument for the result.
- 
-XXX: The VectorCopy routines seg fault when I declare range32 as static.
- *****************************************************************************/
-psScalar *p_psVectorInterpolate(psVector *domain,
-                                psVector *range,
-                                psS32 order,
-                                psScalar *x)
-{
-    PS_ASSERT_VECTOR_NON_NULL(domain, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(range, NULL);
-    PS_ASSERT_PTR_NON_NULL(x, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
-    PS_ASSERT_VECTORS_SIZE_EQUAL(domain, range, NULL);
-    PS_ASSERT_PTR_TYPE_EQUAL(domain, range, NULL);
-    PS_ASSERT_PTR_TYPE_EQUAL(domain, x, NULL);
-
-    psVector *range32 = NULL;
-    psVector *domain32 = NULL;
-    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-            "---- p_psVectorInterpolate() begin ----\n");
-
-    if (order > (domain->n - 1)) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
-                PS_ERRORTEXT_psFunctions_NOT_ENOUGH_DATAPOINTS,
-                order);
-        return(NULL);
-    }
-
-    if (x->type.type == PS_TYPE_F32) {
-        psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-                "---- p_psVectorInterpolate() end ----\n");
-        return(psScalarAlloc(interpolate1DF32(domain->data.F32,
-                                              range->data.F32,
-                                              domain->n,
-                                              order,
-                                              x->data.F32), PS_TYPE_F32));
-    } else if (x->type.type == PS_TYPE_F64) {
-        // XXX: use recycled vectors here.
-        range32 = psVectorCopy(range32, range, PS_TYPE_F32);
-        domain32 = psVectorCopy(domain32, domain, PS_TYPE_F32);
-
-        psScalar *tmpScalar = psScalarAlloc((psF64)
-                                            interpolate1DF32(domain32->data.F32,
-                                                             range32->data.F32,
-                                                             domain32->n,
-                                                             order,
-                                                             (psF32) x->data.F64), PS_TYPE_F64);
-        psFree(range32);
-        psFree(domain32);
-
-        psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-                "---- p_psVectorInterpolate() end ----\n");
-        // XXX: Convert data type to F64?
-        return(tmpScalar);
-
-    } else {
-        char* strType;
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-    }
-
-    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-            "return(NULL)\n");
-    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-            "---- p_psVectorInterpolate() end ----\n");
-
-    return(NULL);
-}
-
-
-/*****************************************************************************
-psSpline1DEval(): this routine takes an existing spline of arbitrary order
-and an independent x value.  Each determines which spline that x corresponds
-to by doing a bracket disection on the knots of the spline data structure
-(vectorBinDisectF32()).  Then it evaluates the spline at that x location
-by a call to the 1D polynomial functions.
- 
-XXX: The spline eval functions require input and output to be F32.  however
-     the spline fit functions require F32 and F64.
- 
-XXX: This only works if spline0>knots if psF32.  Must add support for psU32 and
-psF64.
- *****************************************************************************/
-float psSpline1DEval(
-    const psSpline1D *spline,
-    float x
-)
-{
-    PS_ASSERT_PTR_NON_NULL(spline, NAN);
-    PS_ASSERT_INT_NONNEGATIVE(spline->n, NAN);
-    PS_ASSERT_VECTOR_TYPE(spline->knots, PS_TYPE_F32, NAN);
-
-    psS32 binNum;
-    psS32 n;
-
-    n = spline->n;
-    //XXX    binNum = vectorBinDisectF32(spline->domains, (spline->n)+1, x);
-    binNum = vectorBinDisectF32(spline->knots->data.F32, (spline->n)+1, x);
-    if (binNum < 0) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).",
-                 x, spline->knots->data.F32[0],
-                 spline->knots->data.F32[n-1]);
-
-        if (x < spline->knots->data.F32[0]) {
-            return(psPolynomial1DEval(spline->spline[0],
-                                      x));
-        } else if (x > spline->knots->data.F32[n-1]) {
-            return(psPolynomial1DEval(spline->spline[n-1],
-                                      x));
-        }
-    }
-
-    return(psPolynomial1DEval(spline->spline[binNum],
-                              x));
-}
-
-// XXX: The spline eval functions require input and output to be F32.
-// however the spline fit functions require F32 and F64.
-psVector *psSpline1DEvalVector(
-    const psSpline1D *spline,
-    const psVector *x
-)
-{
-    PS_ASSERT_PTR_NON_NULL(spline, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(spline->knots, PS_TYPE_F32, NULL);
-
-    psS32 i;
-    psVector *tmpVector;
-
-    tmpVector = psVectorAlloc(x->n, PS_TYPE_F32);
-    if (x->type.type == PS_TYPE_F32) {
-        for (i=0;i<x->n;i++) {
-            tmpVector->data.F32[i] = psSpline1DEval(
-                                         spline,
-                                         x->data.F32[i]
-                                     );
-        }
-    } else if (x->type.type == PS_TYPE_F64) {
-        for (i=0;i<x->n;i++) {
-            tmpVector->data.F32[i] = psSpline1DEval(
-                                         spline,
-                                         (psF32) x->data.F64[i]
-                                     );
-        }
-    } else {
-        char* strType;
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return(NULL);
-    }
-
-    return(tmpVector);
-}
Index: unk/psLib/src/math/psPolynomial.h
===================================================================
--- /trunk/psLib/src/math/psPolynomial.h	(revision 4539)
+++ 	(revision )
@@ -1,515 +1,0 @@
-/** @file psFunctions.h
- *  @brief Standard Mathematical Functions.
- *  @ingroup Stats
- *
- *  This file will hold the prototypes for procedures which allocate, free,
- *  and evaluate various polynomials.  Those polynomial structures are also
- *  defined here.
- *
- *  @ingroup Stats
- *
- *  @author Someone at IfA
- *  @author GLG, MHPCC
- *
- *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-29 03:23:19 $
- *
- *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
- */
-
-#ifndef PS_FUNCTIONS_H
-#define PS_FUNCTIONS_H
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <float.h>
-#include <math.h>
-
-#include "psVector.h"
-#include "psScalar.h"
-
-/** \addtogroup Stats
- *  \{
- */
-
-/** Evaluate a non-normalized Gaussian with the given mean and sigma at the
- *  given coordianate.
- *
- *  Note that this is not a Gaussian deviate.  The evaluated Gaussian is:
- *        \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
- *
- *  @return float      value on the gaussian curve given the input parameters
- */
-float psGaussian(
-    float x,                           ///< Value at which to evaluate
-    float mean,                        ///< Mean for the Gaussian
-    float sigma,                       ///< Standard deviation for the Gaussian
-    bool normal                        ///< Indicates whether result should be normalized
-);
-
-/** Produce a vector of random numbers from a Gaussian distribution with
- *  the specified mean and sigma
- *
- *  @return psVector*    vector of random numbers
- *
- */
-psVector* p_psGaussianDev(
-    psF32 mean,                        ///< The mean of the Gaussian
-    psF32 sigma,                       ///< The sigma of the Gaussian
-    psS32 Npts                         ///< The size of the vector
-);
-
-/** Polynomial Type.
- *
- *  Enumeration for Polynomial types.
- */
-typedef enum {
-    PS_POLYNOMIAL_ORD,                 ///< Ordinary Polynomial
-    PS_POLYNOMIAL_CHEB                 ///< Chebyshev Polynomial
-}
-psPolynomialType;
-
-/** One-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int n;                   ///< Number of terms
-    psF32 *coeff;                      ///< Coefficients
-    psF32 *coeffErr;                   ///< Error in coefficients
-    psU8 *mask;                        ///< Coefficient mask
-}
-psPolynomial1D;
-
-/** Two-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                   ///< Number of terms in x
-    unsigned int nY;                   ///< Number of terms in y
-    psF32 **coeff;                     ///< Coefficients
-    psF32 **coeffErr;                  ///< Error in coefficients
-    psU8 **mask;                       ///< Coefficients mask
-}
-psPolynomial2D;
-
-/** Three-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                   ///< Number of terms in x
-    unsigned int nY;                   ///< Number of terms in y
-    unsigned int nZ;                   ///< Number of terms in z
-    psF32 ***coeff;                    ///< Coefficients
-    psF32 ***coeffErr;                 ///< Error in coefficients
-    psU8 ***mask;                      ///< Coefficients mask
-}
-psPolynomial3D;
-
-/** Four-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                   ///< Number of terms in x
-    unsigned int nY;                   ///< Number of terms in y
-    unsigned int nZ;                   ///< Number of terms in z
-    unsigned int nT;                   ///< Number of terms in t
-    psF32 ****coeff;                   ///< Coefficients
-    psF32 ****coeffErr;                ///< Error in coefficients
-    psU8 ****mask;                     ///< Coefficients mask
-}
-psPolynomial4D;
-
-
-/** Allocates a psPolynomial1D structure with n terms
- *
- *  @return  psPolynomial1D*    new 1-D polynomial struct
- */
-psPolynomial1D* psPolynomial1DAlloc(
-    unsigned int n,                   ///< Number of terms
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 2-D polynomial structure
- *
- *  @return  psPolynomial2D*    new 2-D polynomial struct
- */
-psPolynomial2D* psPolynomial2DAlloc(
-    unsigned int nX,                   ///< Number of terms in x
-    unsigned int nY,                   ///< Number of terms in y
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 3-D polynomial structure
- *
- *  @return  psPolynomial3D*    new 3-D polynomial struct
- */
-psPolynomial3D* psPolynomial3DAlloc(
-    unsigned int nX,                   ///< Number of terms in x
-    unsigned int nY,                   ///< Number of terms in y
-    unsigned int nZ,                   ///< Number of terms in z
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 4-D polynomial structure
- *
- *  @return  psPolynomial4D*    new 4-D polynomial struct
- */
-psPolynomial4D* psPolynomial4DAlloc(
-    unsigned int nX,                   ///< Number of terms in x
-    unsigned int nY,                   ///< Number of terms in y
-    unsigned int nZ,                   ///< Number of terms in z
-    unsigned int nT,                   ///< Number of terms in t
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Evaluates a 1-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial1DEval(
-    const psPolynomial1D* poly,        ///< Coefficients for the polynomial
-    psF64 x                            ///< location at which to evaluate
-);
-
-/** Evaluates a 2-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial2DEval(
-    const psPolynomial2D* poly,        ///< Coefficients for the polynomial
-    psF64 x,                           ///< x location at which to evaluate
-    psF64 y                            ///< y location at which to evaluate
-);
-
-/** Evaluates a 3-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial3DEval(
-    const psPolynomial3D* poly,        ///< Coefficients for the polynomial
-    psF64 x,                           ///< x location at which to evaluate
-    psF64 y,                           ///< y location at which to evaluate
-    psF64 z                            ///< z location at which to evaluate
-);
-
-/** Evaluates a 4-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial4DEval(
-    const psPolynomial4D* poly,        ///< Coefficients for the polynomial
-    psF64 x,                           ///< x location at which to evaluate
-    psF64 y,                           ///< y location at which to evaluate
-    psF64 z,                           ///< z location at which to evaluate
-    psF64 t                            ///< t location at which to evaluate
-);
-
-/** Evaluates a 1-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomials at given locations
- */
-psVector *psPolynomial1DEvalVector(
-    const psPolynomial1D *poly,        ///< Coefficients for the polynomial
-    const psVector *x                  ///< x locations at which to evaluate
-);
-
-/** Evaluates a 2-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psPolynomial2DEvalVector(
-    const psPolynomial2D *poly,        ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y                  ///< y locations at which to evaluate
-);
-
-/** Evaluates a 3-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psPolynomial3DEvalVector(
-    const psPolynomial3D *poly,        ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y,                 ///< y locations at which to evaluate
-    const psVector *z                  ///< z locations at which to evaluate
-);
-
-/** Evaluates a 4-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psPolynomial4DEvalVector(
-    const psPolynomial4D *poly,        ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y,                 ///< y locations at which to evaluate
-    const psVector *z,                 ///< z locations at which to evaluate
-    const psVector *t                  ///< t locations at which to evaluate
-);
-
-/*****************************************************************************/
-
-/* Double-precision polynomials, mainly for use in astrometry */
-
-/** Double-precision one-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int n;                           ///< Number of terms
-    psF64 *coeff;                      ///< Coefficients
-    psF64 *coeffErr;                   ///< Error in coefficients
-    psU8 *mask;                        ///< Coefficient mask
-}
-psDPolynomial1D;
-
-/** Double-precision two-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                          ///< Number of terms in x
-    unsigned int nY;                          ///< Number of terms in y
-    psF64 **coeff;                     ///< Coefficients
-    psF64 **coeffErr;                  ///< Error in coefficients
-    psU8 **mask;                       ///< Coefficients mask
-}
-psDPolynomial2D;
-
-/** Double-precision three-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                          ///< Number of terms in x
-    unsigned int nY;                          ///< Number of terms in y
-    unsigned int nZ;                          ///< Number of terms in z
-    psF64 ***coeff;                    ///< Coefficients
-    psF64 ***coeffErr;                 ///< Error in coefficients
-    psU8 ***mask;                      ///< Coefficient mask
-}
-psDPolynomial3D;
-
-/** Double-precision four-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                          ///< Number of terms in w
-    unsigned int nY;                          ///< Number of terms in x
-    unsigned int nZ;                          ///< Number of terms in y
-    unsigned int nT;                          ///< Number of terms in z
-    psF64 ****coeff;                   ///< Coefficients
-    psF64 ****coeffErr;                ///< Error in coefficients
-    psU8 ****mask;                     ///< Coefficients mask
-}
-psDPolynomial4D;
-
-/** Allocates a double-precision 1-D polynomial structure with n terms
- *
- *  @return  psPolynomial1D*    new double-precision 1-D polynomial struct
- */
-psDPolynomial1D* psDPolynomial1DAlloc(
-    unsigned int n,                           ///< Number of terms
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a double-precision 2-D polynomial structure
- *
- *  @return  psPolynomial2D*    new double-precision 2-D polynomial struct
- */
-psDPolynomial2D* psDPolynomial2DAlloc(
-    unsigned int nX,                          ///< Number of terms in x
-    unsigned int nY,                          ///< Number of terms in y
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a double-precision 3-D polynomial structure
- *
- *  @return  psPolynomial3D*    new double-precision 3-D polynomial struct
- */
-psDPolynomial3D* psDPolynomial3DAlloc(
-    unsigned int nX,                          ///< Number of terms in x
-    unsigned int nY,                          ///< Number of terms in y
-    unsigned int nZ,                          ///< Number of terms in z
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a double-precision 4-D polynomial structure
- *
- *  @return  psPolynomial4D*    new double-precision 4-D polynomial struct
- */
-psDPolynomial4D* psDPolynomial4DAlloc(
-    unsigned int nX,                          ///< Number of terms in w
-    unsigned int nY,                          ///< Number of terms in x
-    unsigned int nZ,                          ///< Number of terms in y
-    unsigned int nT,                          ///< Number of terms in z
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Evaluates a double-precision 1-D polynomial at specific coordinates.
- *
- *  @return psF32    result of polynomial at given location
- */
-psF64 psDPolynomial1DEval(
-    const psDPolynomial1D* poly,     ///< Coefficients for the polynomial
-    psF64 x                            ///< Value at which to evaluate
-);
-
-/** Evaluates a double-precision 2-D polynomial at specific coordinates.
- *
- *  @return psF32    result of polynomial at given location
- */
-psF64 psDPolynomial2DEval(
-    const psDPolynomial2D* poly,      ///< Coefficients for the polynomial
-    psF64 x,                            ///< Value x at which to evaluate
-    psF64 y                             ///< Value y at which to evaluate
-);
-
-/** Evaluates a double-precision 3-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psDPolynomial3DEval(
-    const psDPolynomial3D* poly,     ///< Coefficients for the polynomial
-    psF64 x,                           ///< Value x at which to evaluate
-    psF64 y,                           ///< Value y at which to evaluate
-    psF64 z                            ///< Value z at which to evaluate
-);
-
-/** Evaluates a double-precision 4-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psDPolynomial4DEval(
-    const psDPolynomial4D* poly,     ///< Coefficients for the polynomial
-    psF64 x,                           ///< Value w at which to evaluate
-    psF64 y,                           ///< Value x at which to evaluate
-    psF64 z,                           ///< Value y at which to evaluate
-    psF64 t                            ///< Value z at which to evaluate
-);
-
-/** Evaluates a double-precision 1-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial1DEvalVector(
-    const psDPolynomial1D *poly,     ///< Coefficients for the polynomial
-    const psVector *x                  ///< x locations at which to evaluate
-);
-
-/** Evaluates a double-precision 2-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial2DEvalVector(
-    const psDPolynomial2D *poly,     ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y                  ///< y locations at which to evaluate
-);
-
-/** Evaluates a double-precision 3-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial3DEvalVector(
-    const psDPolynomial3D *poly,     ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y,                 ///< y locations at which to evaluate
-    const psVector *z                  ///< z locations at which to evaluate
-);
-
-/** Evaluates a double-precision 4-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial4DEvalVector(
-    const psDPolynomial4D *poly,     ///< Coefficients for the polynomial
-    const psVector *x,                 ///< w locations at which to evaluate
-    const psVector *y,                 ///< x locations at which to evaluate
-    const psVector *z,                 ///< y locations at which to evaluate
-    const psVector *t                  ///< z locations at which to evaluate
-);
-
-/** One-Dimensional Spline */
-typedef struct
-{
-    psS32 n;                           ///< The number of spline polynomials
-    psPolynomial1D **spline;           ///< An array of n pointers to the spline polynomials
-    psF32 *p_psDeriv2;                 ///< For cubic splines, the second derivative at each domain point.  Size is n+1.
-    psF32 *domains;                    ///< The boundaries between each spline piece.  Size is n+1.
-    psVector *knots;                   ///< The boundaries between each spline piece.  Size is n+1.
-}
-psSpline1D;
-
-/** Allocates a psSpline1D structure
- *  
- *  Allocator for psSpline1D where the bounds are implicitly specified through specifying
- *  min and max values along with the number of splines.
- *
- *  @return psSpline1D*    new 1-D spline struct
- */
-psSpline1D *psSpline1DAlloc(
-    int n,                             ///< Number of spline polynomials
-    int order,                         ///< Order of spline polynomials
-    float min,                         ///< Lower boundary value of spline polynomials
-    float max                          ///< Upper boundary value of spline polynomials
-);
-
-/** Allocates a psSpline1D structure
- *  
- *  Allocator for psSpline1D where the bounds are explicitly specified. 
- *
- *  @return psSpline1D*    new 1-D spline struct
- */
-psSpline1D *psSpline1DAllocGeneric(
-    const psVector *bounds,            ///< Bounds for spline polynomials
-    int order                          ///< Order of spline polynomials
-);
-
-/** Evaluates 1-D spline polynomials at a specific coordinate.
- *  
- *  @return float    result of spline polynomials evaluated at given location
- */
-float psSpline1DEval(
-    const psSpline1D *spline,          ///< Coefficients for spline polynomials
-    float x                            ///< location at which to evaluate
-);
-
-/** Evaluates 1-D spline polynomials at a set of specific coordinates.
- *  
- *  @return psVector*    results of spline polynomials evaluated at given locations
- */
-psVector *psSpline1DEvalVector(
-    const psSpline1D *spline,          ///< Coefficients of spline polynomials
-    const psVector *x                  ///< locations at which to evaluate
-);
-
-/** Performs a binary disection on a given vector.
- *  Searches through an array of data for a specified value.
- *  
- *  @return psS32    corresponding index number of specified value
- */
-psS32 p_psVectorBinDisect(
-    psVector *bins,                    ///< Array of non-decreasing values
-    psScalar *x                        ///< Target value to find
-);
-
-/** Interpolates a series of data points for evaluation at a specific coordinate.  Uses a
- *  Lagrange interpolation method.
- *
- *  @return psScalar*    Lagrange interpolation value at given location
- */
-psScalar *p_psVectorInterpolate(
-    psVector *domain,                  ///< Domain (x coords) for interpolation
-    psVector *range,                   ///< Range (y coords) for interpolation
-    psS32 order,                       ///< Order of interpolation function
-    psScalar *x                        ///< Location at which to evaluate
-);
-
-#if 0
-psF32 p_psNRSpline1DEval(psSpline1D *spline,
-                         const psVector* x,
-                         const psVector* y,
-                         psF32 X);
-#endif // #if 0
-
-/** \} */ // End of MathGroup Functions
-
-#endif // #ifndef PS_FUNCTIONS_H
-
Index: /trunk/psLib/src/math/psRandom.c
===================================================================
--- /trunk/psLib/src/math/psRandom.c	(revision 4539)
+++ /trunk/psLib/src/math/psRandom.c	(revision 4540)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-21 03:01:37 $
+*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -31,5 +31,5 @@
 #include "psLogMsg.h"
 #include "psConstants.h"
-#include "psDataManipErrors.h"
+#include "psErrorText.h"
 
 psU64 p_psRandomGetSystemSeed()
Index: unk/psLib/src/math/psSpline.c
===================================================================
--- /trunk/psLib/src/math/psSpline.c	(revision 4539)
+++ 	(revision )
@@ -1,2201 +1,0 @@
-/** @file  psFunctions.c
- *
- *  @brief Contains basic function allocation, deallocation, and evaluation
- *         routines.
- *
- *  This file will hold the functions for allocated, freeing, and evaluating
- *  polynomials.  It also contains a Gaussian functions.
- *
- *  @version $Revision: 1.114 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-29 03:23:19 $
- *
- *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
- *
- *  XXX: Should the "coeffErr[]" be used as well?  Bug ???.  Ignore coeffErr
- *
- *  XXX: In the various polyAlloc(n) functions, n is really the order of the
- *  polynomial plus 1.  To create a 2nd-order polynomial, n == 3.
- */
-/*****************************************************************************/
-/*  INCLUDE FILES                                                            */
-/*****************************************************************************/
-#include <gsl/gsl_rng.h>
-#include <gsl/gsl_randist.h>
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <float.h>
-#include <math.h>
-
-#include "psMemory.h"
-#include "psVector.h"
-#include "psScalar.h"
-#include "psTrace.h"
-#include "psError.h"
-#include "psLogMsg.h"
-#include "psFunctions.h"
-#include "psConstants.h"
-
-#include "psDataManipErrors.h"
-
-/*****************************************************************************/
-/* DEFINE STATEMENTS                                                         */
-/*****************************************************************************/
-
-/*****************************************************************************/
-/* TYPE DEFINITIONS                                                          */
-/*****************************************************************************/
-static void polynomial1DFree(psPolynomial1D* poly);
-static void polynomial2DFree(psPolynomial2D* poly);
-static void polynomial3DFree(psPolynomial3D* poly);
-static void polynomial4DFree(psPolynomial4D* poly);
-static void dPolynomial1DFree(psDPolynomial1D* poly);
-static void dPolynomial2DFree(psDPolynomial2D* poly);
-static void dPolynomial3DFree(psDPolynomial3D* poly);
-static void dPolynomial4DFree(psDPolynomial4D* poly);
-static void spline1DFree(psSpline1D *tmpSpline);
-static psS32 vectorBinDisectF32(psF32 *bins,psS32 numBins,psF32 x);
-static psS32 vectorBinDisectS32(psS32 *bins,psS32 numBins,psS32 x);
-
-/*****************************************************************************/
-/* GLOBAL VARIABLES                                                          */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/* FILE STATIC VARIABLES                                                     */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/* FUNCTION IMPLEMENTATION - LOCAL                                           */
-/*****************************************************************************/
-
-static void spline1DFree(psSpline1D *tmpSpline)
-{
-    psS32 i;
-
-    if (tmpSpline == NULL) {
-        return;
-    }
-
-    if (tmpSpline->spline != NULL) {
-        for (i=0;i<tmpSpline->n;i++) {
-            psFree((tmpSpline->spline)[i]);
-        }
-        psFree(tmpSpline->spline);
-    }
-
-    if (tmpSpline->p_psDeriv2 != NULL) {
-        psFree(tmpSpline->p_psDeriv2);
-    }
-    psFree(tmpSpline->knots);
-
-    return;
-}
-
-static void polynomial1DFree(psPolynomial1D* poly)
-{
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void polynomial2DFree(psPolynomial2D* poly)
-{
-    unsigned int x = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void polynomial3DFree(psPolynomial3D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void polynomial4DFree(psPolynomial4D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            for (z = 0; z < poly->nZ; z++) {
-                psFree(poly->coeff[x][y][z]);
-                psFree(poly->coeffErr[x][y][z]);
-                psFree(poly->mask[x][y][z]);
-            }
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial1DFree(psDPolynomial1D* poly)
-{
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial2DFree(psDPolynomial2D* poly)
-{
-    for (unsigned int x = 0; x < poly->nX; x++) {
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial3DFree(psDPolynomial3D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-static void dPolynomial4DFree(psDPolynomial4D* poly)
-{
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-
-    for (x = 0; x < poly->nX; x++) {
-        for (y = 0; y < poly->nY; y++) {
-            for (z = 0; z < poly->nZ; z++) {
-                psFree(poly->coeff[x][y][z]);
-                psFree(poly->coeffErr[x][y][z]);
-                psFree(poly->mask[x][y][z]);
-            }
-            psFree(poly->coeff[x][y]);
-            psFree(poly->coeffErr[x][y]);
-            psFree(poly->mask[x][y]);
-        }
-        psFree(poly->coeff[x]);
-        psFree(poly->coeffErr[x]);
-        psFree(poly->mask[x]);
-    }
-
-    psFree(poly->coeff);
-    psFree(poly->coeffErr);
-    psFree(poly->mask);
-}
-
-/*****************************************************************************
-createChebyshevPolys(n): this routine takes as input the required order n,
-and returns as output as a pointer to an array of n psPolynomial1D
-structures, corresponding to the first n Chebyshev polynomials.
- 
-XXX: The output should be static since the Chebyshev polynomials might be
-used frequently and the data structure created here does not contain the
-outer coefficients of the Chebyshev polynomials.
- *****************************************************************************/
-static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly)
-{
-    PS_ASSERT_INT_NONNEGATIVE(maxChebyPoly, NULL);
-
-    psPolynomial1D **chebPolys = NULL;
-
-    chebPolys = (psPolynomial1D **) psAlloc(maxChebyPoly * sizeof(psPolynomial1D *));
-    for (psS32 i = 0; i < maxChebyPoly; i++) {
-        chebPolys[i] = psPolynomial1DAlloc(i + 1, PS_POLYNOMIAL_ORD);
-    }
-
-    // Create the Chebyshev polynomials.
-    // Polynomial i has i-th order.
-    chebPolys[0]->coeff[0] = 1;
-
-    // XXX: Bug 296
-    if (maxChebyPoly > 1) {
-        chebPolys[1]->coeff[1] = 1;
-
-        for (psS32 i = 2; i < maxChebyPoly; i++) {
-            for (psS32 j = 0; j < chebPolys[i - 1]->n; j++) {
-                chebPolys[i]->coeff[j + 1] = 2 * chebPolys[i - 1]->coeff[j];
-            }
-            for (psS32 j = 0; j < chebPolys[i - 2]->n; j++) {
-                chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
-            }
-        }
-    } else {
-        // XXX: Code this.
-        printf("WARNING: %d-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
-    }
-
-    return (chebPolys);
-}
-
-/*****************************************************************************
-    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
- *****************************************************************************/
-static psF32 ordPolynomial1DEval(psF32 x, const psPolynomial1D* poly)
-{
-    psS32 loop_x = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-
-    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
-            "---- Calling ordPolynomial1DEval(%f)\n", x);
-    psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
-            "Polynomial order is %d\n", poly->n);
-    for (loop_x = 0; loop_x < poly->n; loop_x++) {
-        psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 4,
-                "Polynomial coeff[%d] is %f\n", loop_x, poly->coeff[loop_x]);
-    }
-
-    for (loop_x = 0; loop_x < poly->n; loop_x++) {
-        if (poly->mask[loop_x] == 0) {
-            psTrace(".psLib.dataManip.psFunctions.ordPolynomial1DEval", 10,
-                    "polysum+= sum*coeff [%f+= (%f * %f)\n", polySum, xSum, poly->coeff[loop_x]);
-            polySum += xSum * poly->coeff[loop_x];
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-// XXX: You can do this without having to psAlloc() vector d.
-// XXX: How does the mask vector effect Crenshaw's formula?
-// XXX: We assume that x is scaled between -1.0 and 1.0;
-static psF32 chebPolynomial1DEval(psF32 x, const psPolynomial1D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    // XXX: Create a macro for this in psConstants.h
-    if (poly->n < 1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial as order %d.", poly->n);
-        return(NAN);
-    }
-    psVector *d;
-    psS32 n = poly->n;
-    psS32 i;
-    psF32 tmp = 0.0;
-
-    // Special case where the Chebyshev poly is constant.
-    if (n == 1) {
-        if (poly->mask[0] == 0) {
-            tmp += poly->coeff[0];
-        }
-        return(tmp);
-    }
-
-    // Special case where the Chebyshev poly is linear.
-    if (n == 2) {
-        if (poly->mask[0] == 0) {
-            tmp+= poly->coeff[0];
-        }
-        if (poly->mask[1] == 0) {
-            tmp+= poly->coeff[1] * x;
-        }
-        return(tmp);
-    }
-
-    // General case where the Chebyshev poly has 2 or more terms.
-    d = psVectorAlloc(n, PS_TYPE_F32);
-    if(poly->mask[n-1] == 0) {
-        d->data.F32[n-1] = poly->coeff[n-1];
-    } else {
-        d->data.F32[n-1] = 0.0;
-    }
-
-    d->data.F32[n-2] = (2.0 * x * d->data.F32[n-1]);
-    if(poly->mask[n-2] == 0) {
-        d->data.F32[n-2] += poly->coeff[n-2];
-    }
-
-    for (i=n-3;i>=1;i--) {
-        d->data.F32[i] = (2.0 * x * d->data.F32[i+1]) -
-                         (d->data.F32[i+2]);
-        if(poly->mask[i] == 0) {
-            d->data.F32[i] += poly->coeff[i];
-        }
-    }
-
-    tmp = (x * d->data.F32[1]) -
-          (d->data.F32[2]);
-    if(poly->mask[0] == 0) {
-        tmp += (0.5 * poly->coeff[0]);
-    }
-    psFree(d);
-    return(tmp);
-
-    /* This is old code that does not use Clenshaw's formula.  Get rid of it.
-
-    psS32 n;
-    psS32 i;
-    psF32 tmp;
-    psPolynomial1D **chebPolys = NULL;
-
-    n = poly->n;
-    chebPolys = createChebyshevPolys(n);
-
-    tmp = 0.0;
-    for (i=0;i<poly->n;i++) {
-        tmp+= (poly->coeff[i] * psPolynomial1DEval(x, chebPolys[i]));
-    }
-    tmp-= (poly->coeff[0]/2.0);
-
-
-    return(tmp);
-    */
-}
-
-static psF32 ordPolynomial2DEval(psF32 x,
-                                 psF32 y,
-                                 const psPolynomial2D* poly)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-    psF32 ySum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += ySum * poly->coeff[loop_x][loop_y];
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF32 chebPolynomial2DEval(psF32 x, psF32 y, const psPolynomial2D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 i = 0;
-    psF32 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += poly->coeff[loop_x][loop_y] *
-                           psPolynomial1DEval(chebPolys[loop_x], x) *
-                           psPolynomial1DEval(chebPolys[loop_y], y);
-            }
-        }
-    }
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF32 ordPolynomial3DEval(psF32 x, psF32 y, psF32 z, const psPolynomial3D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-    psF32 ySum = 1.0;
-    psF32 zSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += zSum * poly->coeff[loop_x][loop_y][loop_z];
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF32 chebPolynomial3DEval(psF32 x, psF32 y, psF32 z, const psPolynomial3D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 i = 0;
-    psF32 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += poly->coeff[loop_x][loop_y][loop_z] *
-                               psPolynomial1DEval(chebPolys[loop_x], x) *
-                               psPolynomial1DEval(chebPolys[loop_y], y) *
-                               psPolynomial1DEval(chebPolys[loop_z], z);
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF32 ordPolynomial4DEval(psF32 x, psF32 y, psF32 z, psF32 t, const psPolynomial4D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psF32 polySum = 0.0;
-    psF32 xSum = 1.0;
-    psF32 ySum = 1.0;
-    psF32 zSum = 1.0;
-    psF32 tSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                tSum = zSum;
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += tSum * poly->coeff[loop_x][loop_y][loop_z][loop_t];
-                    }
-                    tSum *= t;
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF32 chebPolynomial4DEval(psF32 x, psF32 y, psF32 z, psF32 t, const psPolynomial4D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(t, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psS32 i = 0;
-    psF32 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    if (poly->nT > maxChebyPoly) {
-        maxChebyPoly = poly->nT;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] *
-                                   psPolynomial1DEval(chebPolys[loop_x], x) *
-                                   psPolynomial1DEval(chebPolys[loop_y], y) *
-                                   psPolynomial1DEval(chebPolys[loop_z], z) *
-                                   psPolynomial1DEval(chebPolys[loop_t], t);
-                    }
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-/*****************************************************************************
-    Polynomial coefficients will be accessed in [w][x][y][z] fashion.
- *****************************************************************************/
-static psF64 dOrdPolynomial1DEval(psF64 x, const psDPolynomial1D* poly)
-{
-    psS32 loop_x = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->n; loop_x++) {
-        if (poly->mask[loop_x] == 0) {
-            polySum += xSum * poly->coeff[loop_x];
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-// XXX: You can do this without having to psAlloc() vector d.
-// XXX: How does the mask vector effect Crenshaw's formula?
-static psF64 dChebPolynomial1DEval(psF64 x, const psDPolynomial1D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    psVector *d;
-    psS32 n;
-    psS32 i;
-    psF64 tmp;
-
-    n = poly->n;
-    d = psVectorAlloc(n, PS_TYPE_F64);
-    if(poly->mask[n-1] == 0) {
-        d->data.F64[n-1] = poly->coeff[n-1];
-    } else {
-        d->data.F64[n-1] = 0.0;
-    }
-    d->data.F64[n-2] = (2.0 * x * d->data.F64[n-1]);
-    if(poly->mask[n-2] == 0) {
-        d->data.F64[n-2] += poly->coeff[n-2];
-    }
-    for (i=n-3;i>=1;i--) {
-        d->data.F64[i] = (2.0 * x * d->data.F64[i+1]) -
-                         (d->data.F64[i+2]);
-        if(poly->mask[i] == 0) {
-            d->data.F64[i] += poly->coeff[i];
-        }
-    }
-
-    tmp = (x * d->data.F64[1]) -
-          (d->data.F64[2]);
-    if(poly->mask[0] == 0) {
-        tmp += (0.5 * poly->coeff[0]);
-    }
-
-    psFree(d);
-    return(tmp);
-}
-
-static psF64 dOrdPolynomial2DEval(psF64 x,
-                                  psF64 y,
-                                  const psDPolynomial2D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-    psF64 ySum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += ySum * poly->coeff[loop_x][loop_y];
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF64 dChebPolynomial2DEval(psF64 x, psF64 y, const psDPolynomial2D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 i = 0;
-    psF64 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            if (poly->mask[loop_x][loop_y] == 0) {
-                polySum += poly->coeff[loop_x][loop_y] *
-                           psPolynomial1DEval(chebPolys[loop_x], x) *
-                           psPolynomial1DEval(chebPolys[loop_y], y);
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF64 dOrdPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psDPolynomial3D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-    psF64 ySum = 1.0;
-    psF64 zSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += zSum * poly->coeff[loop_x][loop_y][loop_z];
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF64 dChebPolynomial3DEval(psF64 x, psF64 y, psF64 z, const psDPolynomial3D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 i = 0;
-    psF64 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                if (poly->mask[loop_x][loop_y][loop_z] == 0) {
-                    polySum += poly->coeff[loop_x][loop_y][loop_z] *
-                               psPolynomial1DEval(chebPolys[loop_x], x) *
-                               psPolynomial1DEval(chebPolys[loop_y], y) *
-                               psPolynomial1DEval(chebPolys[loop_z], z);
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-static psF64 dOrdPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psDPolynomial4D* poly)
-{
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psF64 polySum = 0.0;
-    psF64 xSum = 1.0;
-    psF64 ySum = 1.0;
-    psF64 zSum = 1.0;
-    psF64 tSum = 1.0;
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        ySum = xSum;
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            zSum = ySum;
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                tSum = zSum;
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += tSum * poly->coeff[loop_x][loop_y][loop_z][loop_t];
-                    }
-                    tSum *= t;
-                }
-                zSum *= z;
-            }
-            ySum *= y;
-        }
-        xSum *= x;
-    }
-
-    return(polySum);
-}
-
-static psF64 dChebPolynomial4DEval(psF64 x, psF64 y, psF64 z, psF64 t, const psDPolynomial4D* poly)
-{
-    PS_ASSERT_FLOAT_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(y, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(z, -1.0, 1.0, 0.0);
-    PS_ASSERT_FLOAT_WITHIN_RANGE(t, -1.0, 1.0, 0.0);
-    psS32 loop_x = 0;
-    psS32 loop_y = 0;
-    psS32 loop_z = 0;
-    psS32 loop_t = 0;
-    psS32 i = 0;
-    psF64 polySum = 0.0;
-    psPolynomial1D* *chebPolys = NULL;
-    psS32 maxChebyPoly = 0;
-
-    // Determine how many Chebyshev polynomials
-    // are needed, then create them.
-    maxChebyPoly = poly->nX;
-    if (poly->nY > maxChebyPoly) {
-        maxChebyPoly = poly->nY;
-    }
-    if (poly->nZ > maxChebyPoly) {
-        maxChebyPoly = poly->nZ;
-    }
-    if (poly->nT > maxChebyPoly) {
-        maxChebyPoly = poly->nT;
-    }
-    chebPolys = createChebyshevPolys(maxChebyPoly);
-
-    for (loop_x = 0; loop_x < poly->nX; loop_x++) {
-        for (loop_y = 0; loop_y < poly->nY; loop_y++) {
-            for (loop_z = 0; loop_z < poly->nZ; loop_z++) {
-                for (loop_t = 0; loop_t < poly->nT; loop_t++) {
-                    if (poly->mask[loop_x][loop_y][loop_z][loop_t] == 0) {
-                        polySum += poly->coeff[loop_x][loop_y][loop_z][loop_t] *
-                                   psPolynomial1DEval(chebPolys[loop_x], x) *
-                                   psPolynomial1DEval(chebPolys[loop_y], y) *
-                                   psPolynomial1DEval(chebPolys[loop_z], z) *
-                                   psPolynomial1DEval(chebPolys[loop_t], t);
-                    }
-                }
-            }
-        }
-    }
-
-    for (i=0;i<maxChebyPoly;i++) {
-        psFree(chebPolys[i]);
-    }
-    psFree(chebPolys);
-    return(polySum);
-}
-
-
-/*****************************************************************************
-fullInterpolate1DF32(): This routine will take as input n-element floating
-point arrays domain and range, and the x value, assumed to lie with the
-domain vector.  It produces as output the (n-1)-order LaGrange interpolated
-value of x.
- 
-XXX: do we error check for non-distinct domain values?
- *****************************************************************************/
-#define FUNC_MACRO_FULL_INTERPOLATE_1D(TYPE) \
-static psF32 fullInterpolate1D##TYPE(ps##TYPE *domain, \
-                                     ps##TYPE *range, \
-                                     psS32 n, \
-                                     ps##TYPE x) \
-{ \
-    \
-    psS32 i; \
-    psS32 m; \
-    static psVector *p = NULL; \
-    p = psVectorRecycle(p, n, PS_TYPE_##TYPE); \
-    p_psMemSetPersistent(p, true); \
-    p_psMemSetPersistent(p->data.TYPE, true); \
-    \
-    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 4, \
-            "---- fullInterpolate1D##TYPE() begin (%d-order at x=%f) (%d data points)----\n", n-1, x, n); \
-    \
-    for (i=0;i<n;i++) { \
-        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
-                "domain/range is (%f %f)\n", domain[i], range[i]); \
-    } \
-    \
-    for (i=0;i<n;i++) { \
-        p->data.TYPE[i] = range[i]; \
-        psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
-                "p->data.TYPE[%d] is %f\n", i, p->data.TYPE[i]); \
-        \
-    } \
-    \
-    /* From NR, during each iteration of the m loop, we are computing the \
-       p_{i ... i+m} terms. \
-    */ \
-    for (m=1;m<n;m++) { \
-        for (i=0;i<n-m;i++) { \
-            /* From NR: we are computing P_{i ... i+m} \
-             */ \
-            p->data.TYPE[i] = (((x-domain[i+m]) * p->data.TYPE[i]) + \
-                               ((domain[i]-x) * p->data.TYPE[i+1])) / \
-                              (domain[i] - domain[i+m]); \
-            /*printf("((%f-%f * %f) + (%f-%f * %f)) / (%f - %f)\n", x, domain[i+m], p->data.TYPE[i], domain[i], x, p->data.TYPE[i+1], domain[i], domain[i+m]); \
-             */ \
-            psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 6, \
-                    "p->data.TYPE[%d] is %f\n", i, p->data.TYPE[i]); \
-        } \
-    } \
-    psTrace(".psLib.dataManip.psFunctions.fullInterpolate1D##TYPE", 4, \
-            "---- fullInterpolate1D##TYPE() end ----\n"); \
-    \
-    return(p->data.TYPE[0]); \
-} \
-
-/*
-FUNC_MACRO_FULL_INTERPOLATE_1D(U8)
-FUNC_MACRO_FULL_INTERPOLATE_1D(U16)
-FUNC_MACRO_FULL_INTERPOLATE_1D(U32)
-FUNC_MACRO_FULL_INTERPOLATE_1D(U64)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S8)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S16)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S32)
-FUNC_MACRO_FULL_INTERPOLATE_1D(S64)
-FUNC_MACRO_FULL_INTERPOLATE_1D(F64)
-*/
-FUNC_MACRO_FULL_INTERPOLATE_1D(F32)
-
-
-/*****************************************************************************
-interpolate1DF32(): this is the base 1-D flat memory routine to perform
-LaGrange interpolation.
- *****************************************************************************/
-static psF32 interpolate1DF32(psF32 *domain,
-                              psF32 *range,
-                              psS32 n,
-                              psS32 order,
-                              psF32 x)
-{
-    PS_ASSERT_PTR_NON_NULL(domain, NAN)
-    PS_ASSERT_PTR_NON_NULL(range, NAN)
-    // XXX: Check valid values for n, order, and x?
-
-    psS32 binNum;
-    psS32 numIntPoints = order+1;
-    psS32 origin;
-
-    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
-            "---- interpolate1DF32() begin ----\n");
-
-    binNum = vectorBinDisectF32(domain, n, x);
-
-    if (0 == numIntPoints%2) {
-        origin = binNum - ((numIntPoints/2) - 1);
-    } else {
-        origin = binNum - (numIntPoints/2);
-        if ((x-domain[binNum]) > (domain[binNum+1]-x)) {
-            // x is closer to binNum+1.
-            origin = 1 + (binNum - (numIntPoints/2));
-        }
-    }
-    if (origin < 0) {
-        origin = 0;
-    }
-    if ((origin + numIntPoints) > n) {
-        origin = n - numIntPoints;
-    }
-
-    psTrace(".psLib.dataManip.psFunctions.interpolate1DF32", 4,
-            "---- interpolate1DF32() end ----\n");
-    return(fullInterpolate1DF32(&domain[origin], &range[origin], order+1, x));
-}
-
-/*****************************************************************************/
-/*  FUNCTION IMPLEMENTATION - PUBLIC                                         */
-/*****************************************************************************/
-
-/*****************************************************************************
-    Evaluate a non-normalized Gaussian with the given mean and sigma at the
-    given coordianate.  Note that this is not a Gaussian deviate.  The
-    evaluated Gaussian is: \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
- *****************************************************************************/
-float psGaussian(float x, float mean, float sigma, bool normal)
-{
-    psF32 tmp = 1.0;
-
-    psTrace(".psLib.dataManip.psFunctions.psGaussian", 4,
-            "---- psGaussian() begin ----\n");
-
-    if (normal == true) {
-        tmp = 1.0 / sqrtf(2.0 * M_PI * (sigma * sigma));
-    }
-
-    psTrace(".psLib.dataManip.psFunctions.psGaussian", 4,
-            "---- psGaussian() end ----\n");
-    return(tmp * exp(-((x - mean) * (x - mean)) / (2.0 * sigma * sigma)));
-}
-
-/*****************************************************************************
-    p_psGaussianDev()
- This private routine (formerly a psLib API routine) creates a psVector of the
- specified size and type F32 and fills it with a random Gaussian distribution
- of numbers with the specified mean and sigma.  This routine makes use of the
- GSL routines for generating both uniformly distributed numbers and the
- Gaussian distribution as well.
- 
-XXX: There is no way to seed the random generator.
- *****************************************************************************/
-psVector* p_psGaussianDev(psF32 mean, psF32 sigma, psS32 Npts)
-{
-    PS_ASSERT_INT_NONNEGATIVE(Npts, NULL);
-
-    psVector* gauss = NULL;
-    const gsl_rng_type *T = NULL;
-    gsl_rng *r = NULL;
-    psS32 i = 0;
-
-
-    gauss = psVectorAlloc(Npts, PS_TYPE_F32);
-    gauss->n = Npts;
-    gsl_rng_env_setup();
-    T = gsl_rng_default;
-    r = gsl_rng_alloc(T);
-
-    for (i = 0; i < Npts; i++) {
-        gauss->data.F32[i] = mean + gsl_ran_gaussian(r, sigma);
-    }
-
-    // XXX: Should I free r, T as well?  This is a memory leak.
-    return(gauss);
-}
-
-/*****************************************************************************
-    This routine must allocate memory for the polynomial structures.
- *****************************************************************************/
-psPolynomial1D* psPolynomial1DAlloc(unsigned int n,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(n, NULL);
-
-    int i = 0;
-    psPolynomial1D* newPoly = NULL;
-
-    newPoly = (psPolynomial1D* ) psAlloc(sizeof(psPolynomial1D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial1DFree);
-
-    newPoly->type = type;
-    newPoly->n = n;
-    newPoly->coeff = (psF32 *)psAlloc(n * sizeof(psF32));
-    newPoly->coeffErr = (psF32 *)psAlloc(n * sizeof(psF32));
-    newPoly->mask = (psU8 *)psAlloc(n * sizeof(psU8));
-    for (i = 0; i < n; i++) {
-        newPoly->coeff[i] = 0.0;
-        newPoly->coeffErr[i] = 0.0;
-        newPoly->mask[i] = 0;
-    }
-
-    return(newPoly);
-}
-
-psPolynomial2D* psPolynomial2DAlloc(unsigned int nX, unsigned int nY,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-
-    int x = 0;
-    int y = 0;
-    psPolynomial2D* newPoly = NULL;
-
-    newPoly = (psPolynomial2D* ) psAlloc(sizeof(psPolynomial2D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial2DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-
-    newPoly->coeff = (psF32 **)psAlloc(nX * sizeof(psF32 *));
-    newPoly->coeffErr = (psF32 **)psAlloc(nX * sizeof(psF32 *));
-    newPoly->mask = (psU8 **)psAlloc(nX * sizeof(psU8 *));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF32 *)psAlloc(nY * sizeof(psF32));
-        newPoly->coeffErr[x] = (psF32 *)psAlloc(nY * sizeof(psF32));
-        newPoly->mask[x] = (psU8 *)psAlloc(nY * sizeof(psU8));
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = 0.0;
-            newPoly->coeffErr[x][y] = 0.0;
-            newPoly->mask[x][y] = 0;
-        }
-    }
-
-    return(newPoly);
-}
-
-psPolynomial3D* psPolynomial3DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-
-    psS32 x = 0;
-    psS32 y = 0;
-    psS32 z = 0;
-    psPolynomial3D* newPoly = NULL;
-
-    newPoly = (psPolynomial3D* ) psAlloc(sizeof(psPolynomial3D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial3DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-
-    newPoly->coeff = (psF32 ***)psAlloc(nX * sizeof(psF32 **));
-    newPoly->coeffErr = (psF32 ***)psAlloc(nX * sizeof(psF32 **));
-    newPoly->mask = (psU8 ***)psAlloc(nX * sizeof(psU8 **));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF32 **)psAlloc(nY * sizeof(psF32 *));
-        newPoly->coeffErr[x] = (psF32 **)psAlloc(nY * sizeof(psF32 *));
-        newPoly->mask[x] = (psU8 **)psAlloc(nY * sizeof(psU8 *));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF32 *)psAlloc(nZ * sizeof(psF32));
-            newPoly->coeffErr[x][y] = (psF32 *)psAlloc(nZ * sizeof(psF32));
-            newPoly->mask[x][y] = (psU8 *)psAlloc(nZ * sizeof(psU8));
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = 0.0;
-                newPoly->coeffErr[x][y][z] = 0.0;
-                newPoly->mask[x][y][z] = 0;
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-psPolynomial4D* psPolynomial4DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nT,
-                                    psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-    PS_ASSERT_INT_POSITIVE(nT, NULL);
-
-    psS32 x = 0;
-    psS32 y = 0;
-    psS32 z = 0;
-    psS32 t = 0;
-    psPolynomial4D* newPoly = NULL;
-
-    newPoly = (psPolynomial4D* ) psAlloc(sizeof(psPolynomial4D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) polynomial4DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-    newPoly->nT = nT;
-
-    newPoly->coeff = (psF32 ****)psAlloc(nX * sizeof(psF32 ***));
-    newPoly->coeffErr = (psF32 ****)psAlloc(nX * sizeof(psF32 ***));
-    newPoly->mask = (psU8 ****)psAlloc(nX * sizeof(psU8 ***));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF32 ***)psAlloc(nY * sizeof(psF32 **));
-        newPoly->coeffErr[x] = (psF32 ***)psAlloc(nY * sizeof(psF32 **));
-        newPoly->mask[x] = (psU8 ***)psAlloc(nY * sizeof(psU8 **));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF32 **)psAlloc(nZ * sizeof(psF32 *));
-            newPoly->coeffErr[x][y] = (psF32 **)psAlloc(nZ * sizeof(psF32 *));
-            newPoly->mask[x][y] = (psU8 **)psAlloc(nZ * sizeof(psU8 *));
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = (psF32 *)psAlloc(nT * sizeof(psF32));
-                newPoly->coeffErr[x][y][z] = (psF32 *)psAlloc(nT * sizeof(psF32));
-                newPoly->mask[x][y][z] = (psU8 *)psAlloc(nT * sizeof(psU8));
-            }
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                for (t = 0; t < nT; t++) {
-                    newPoly->coeff[x][y][z][t] = 0.0;
-                    newPoly->coeffErr[x][y][z][t] = 0.0;
-                    newPoly->mask[x][y][z][t] = 0;
-                }
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-psF64 psPolynomial1DEval(const psPolynomial1D* poly, psF64 x)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial1DEval(x, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial1DEval(x, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial1DEvalVector(const psPolynomial1D *poly,
-                                   const psVector *x)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-
-    tmp = psVectorAlloc(x->n, PS_TYPE_F32);
-    for (psS32 i=0;i<x->n;i++) {
-        tmp->data.F32[i] = psPolynomial1DEval(poly, x->data.F32[i]);
-    }
-
-    return(tmp);
-}
-
-psF64 psPolynomial2DEval(const psPolynomial2D* poly, psF64 x, psF64 y)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial2DEval(x, y, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial2DEval(x, y, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial2DEvalVector(const psPolynomial2D *poly,
-                                   const psVector *x,
-                                   const psVector *y)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the length of the output vector to by the minimum of the x,y vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-
-    // Create output vector to return
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
-
-    // Evaluate the polynomial at the specified points
-    for (psS32 i=0; i<vecLen; i++) {
-        tmp->data.F32[i] = psPolynomial2DEval(poly,x->data.F32[i],y->data.F32[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-psF64 psPolynomial3DEval(const psPolynomial3D* poly, psF64 x, psF64 y, psF64 z)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial3DEval(x, y, z, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial3DEval(x, y, z, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial3DEvalVector(const psPolynomial3D *poly,
-                                   const psVector *x,
-                                   const psVector *y,
-                                   const psVector *z)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the length of output vector from min of the input vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
-
-    // Evaluate polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F32[i] = psPolynomial3DEval(poly,
-                                              x->data.F32[i],
-                                              y->data.F32[i],
-                                              z->data.F32[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-psF64 psPolynomial4DEval(const psPolynomial4D* poly, psF64 x, psF64 y, psF64 z, psF64 t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(ordPolynomial4DEval(x,y,z,t, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(chebPolynomial4DEval(x,y,z,t, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psPolynomial4DEvalVector(const psPolynomial4D *poly,
-                                   const psVector *x,
-                                   const psVector *y,
-                                   const psVector *z,
-                                   const psVector *t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F32, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(t, NULL);
-    PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F32, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine output vector size from min of input vectors
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (t->n < vecLen) {
-        vecLen = t->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F32);
-
-    // Evaluate polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F32[i] = psPolynomial4DEval(poly,
-                                              x->data.F32[i],
-                                              y->data.F32[i],
-                                              z->data.F32[i],
-                                              t->data.F32[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-
-psDPolynomial1D* psDPolynomial1DAlloc(unsigned int n,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(n, NULL);
-
-    unsigned int i = 0;
-    psDPolynomial1D* newPoly = NULL;
-
-    newPoly = (psDPolynomial1D* ) psAlloc(sizeof(psDPolynomial1D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial1DFree);
-
-    newPoly->type = type;
-    newPoly->n = n;
-    newPoly->coeff = (psF64 *)psAlloc(n * sizeof(psF64));
-    newPoly->coeffErr = (psF64 *)psAlloc(n * sizeof(psF64));
-    newPoly->mask = (psU8 *)psAlloc(n * sizeof(psU8));
-    for (i = 0; i < n; i++) {
-        newPoly->coeff[i] = 0.0;
-        newPoly->coeffErr[i] = 0.0;
-        newPoly->mask[i] = 0;
-    }
-
-    return(newPoly);
-}
-
-psDPolynomial2D* psDPolynomial2DAlloc(unsigned int nX, unsigned int nY,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-
-    unsigned int x = 0;
-    unsigned int y = 0;
-    psDPolynomial2D* newPoly = NULL;
-
-    newPoly = (psDPolynomial2D* ) psAlloc(sizeof(psDPolynomial2D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial2DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-
-    newPoly->coeff = (psF64 **)psAlloc(nX * sizeof(psF64 *));
-    newPoly->coeffErr = (psF64 **)psAlloc(nX * sizeof(psF64 *));
-    newPoly->mask = (psU8 **)psAlloc(nX * sizeof(psU8 *));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF64 *)psAlloc(nY * sizeof(psF64));
-        newPoly->coeffErr[x] = (psF64 *)psAlloc(nY * sizeof(psF64));
-        newPoly->mask[x] = (psU8 *)psAlloc(nY * sizeof(psU8));
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = 0.0;
-            newPoly->coeffErr[x][y] = 0.0;
-            newPoly->mask[x][y] = 0;
-        }
-    }
-
-    return(newPoly);
-}
-
-psDPolynomial3D* psDPolynomial3DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-    psDPolynomial3D* newPoly = NULL;
-
-    newPoly = (psDPolynomial3D* ) psAlloc(sizeof(psDPolynomial3D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial3DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-
-    newPoly->coeff = (psF64 ***)psAlloc(nX * sizeof(psF64 **));
-    newPoly->coeffErr = (psF64 ***)psAlloc(nX * sizeof(psF64 **));
-    newPoly->mask = (psU8 ***)psAlloc(nX * sizeof(psU8 **));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF64 **)psAlloc(nY * sizeof(psF64 *));
-        newPoly->coeffErr[x] = (psF64 **)psAlloc(nY * sizeof(psF64 *));
-        newPoly->mask[x] = (psU8 **)psAlloc(nY * sizeof(psU8 *));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF64 *)psAlloc(nZ * sizeof(psF64));
-            newPoly->coeffErr[x][y] = (psF64 *)psAlloc(nZ * sizeof(psF64));
-            newPoly->mask[x][y] = (psU8 *)psAlloc(nZ * sizeof(psU8));
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = 0.0;
-                newPoly->coeffErr[x][y][z] = 0.0;
-                newPoly->mask[x][y][z] = 0;
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-psDPolynomial4D* psDPolynomial4DAlloc(unsigned int nX, unsigned int nY, unsigned int nZ, unsigned int nT,
-                                      psPolynomialType type)
-{
-    PS_ASSERT_INT_POSITIVE(nX, NULL);
-    PS_ASSERT_INT_POSITIVE(nY, NULL);
-    PS_ASSERT_INT_POSITIVE(nZ, NULL);
-    PS_ASSERT_INT_POSITIVE(nT, NULL);
-
-    unsigned int x = 0;
-    unsigned int y = 0;
-    unsigned int z = 0;
-    unsigned int t = 0;
-    psDPolynomial4D* newPoly = NULL;
-
-    newPoly = (psDPolynomial4D* ) psAlloc(sizeof(psDPolynomial4D));
-    psMemSetDeallocator(newPoly, (psFreeFunc) dPolynomial4DFree);
-
-    newPoly->type = type;
-    newPoly->nX = nX;
-    newPoly->nY = nY;
-    newPoly->nZ = nZ;
-    newPoly->nT = nT;
-
-    newPoly->coeff = (psF64 ****)psAlloc(nX * sizeof(psF64 ***));
-    newPoly->coeffErr = (psF64 ****)psAlloc(nX * sizeof(psF64 ***));
-    newPoly->mask = (psU8 ****)psAlloc(nX * sizeof(psU8 ***));
-    for (x = 0; x < nX; x++) {
-        newPoly->coeff[x] = (psF64 ***)psAlloc(nY * sizeof(psF64 **));
-        newPoly->coeffErr[x] = (psF64 ***)psAlloc(nY * sizeof(psF64 **));
-        newPoly->mask[x] = (psU8 ***)psAlloc(nY * sizeof(psU8 **));
-        for (y = 0; y < nY; y++) {
-            newPoly->coeff[x][y] = (psF64 **)psAlloc(nZ * sizeof(psF64 *));
-            newPoly->coeffErr[x][y] = (psF64 **)psAlloc(nZ * sizeof(psF64 *));
-            newPoly->mask[x][y] = (psU8 **)psAlloc(nZ * sizeof(psU8 *));
-            for (z = 0; z < nZ; z++) {
-                newPoly->coeff[x][y][z] = (psF64 *)psAlloc(nT * sizeof(psF64));
-                newPoly->coeffErr[x][y][z] = (psF64 *)psAlloc(nT * sizeof(psF64));
-                newPoly->mask[x][y][z] = (psU8 *)psAlloc(nT * sizeof(psU8));
-            }
-        }
-    }
-    for (x = 0; x < nX; x++) {
-        for (y = 0; y < nY; y++) {
-            for (z = 0; z < nZ; z++) {
-                for (t = 0; t < nT; t++) {
-                    newPoly->coeff[x][y][z][t] = 0.0;
-                    newPoly->coeffErr[x][y][z][t] = 0.0;
-                    newPoly->mask[x][y][z][t] = 0;
-                }
-            }
-        }
-    }
-
-    return(newPoly);
-}
-
-
-psF64 psDPolynomial1DEval(const psDPolynomial1D* poly, psF64 x)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial1DEval(x, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial1DEval(x, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial1DEvalVector(const psDPolynomial1D *poly,
-                                    const psVector *x)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-
-    tmp = psVectorAlloc(x->n, PS_TYPE_F64);
-    for (psS32 i=0;i<x->n;i++) {
-        tmp->data.F64[i] = psDPolynomial1DEval(poly,
-                                               x->data.F64[i]);
-    }
-
-    return(tmp);
-}
-
-
-psF64 psDPolynomial2DEval(const psDPolynomial2D* poly,
-                          psF64 x,
-                          psF64 y)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial2DEval(x, y, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial2DEval(x, y, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial2DEvalVector(const psDPolynomial2D *poly,
-                                    const psVector *x,
-                                    const psVector *y)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the output vector length from minimum length of input vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
-
-    // Evaluate the polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F64[i] = psDPolynomial2DEval(poly,x->data.F64[i],y->data.F64[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-
-psF64 psDPolynomial3DEval(const psDPolynomial3D* poly,
-                          psF64 x,
-                          psF64 y,
-                          psF64 z)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial3DEval(x, y, z, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial3DEval(x, y, z, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial3DEvalVector(const psDPolynomial3D *poly,
-                                    const psVector *x,
-                                    const psVector *y,
-                                    const psVector *z)
-
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the size of output vector from min of input vectors
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
-
-    // Evaluate polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F64[i] = psDPolynomial3DEval(poly,
-                                               x->data.F64[i],
-                                               y->data.F64[i],
-                                               z->data.F64[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-psF64 psDPolynomial4DEval(const psDPolynomial4D* poly,
-                          psF64 x,
-                          psF64 y,
-                          psF64 z,
-                          psF64 t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NAN);
-
-    if (poly->type == PS_POLYNOMIAL_ORD) {
-        return(dOrdPolynomial4DEval(x,y,z,t, poly));
-    } else if (poly->type == PS_POLYNOMIAL_CHEB) {
-        return(dChebPolynomial4DEval(x,y,z,t, poly));
-    } else {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psFunctions_INVALID_POLYNOMIAL_TYPE,
-                poly->type);
-    }
-    return(NAN);
-}
-
-psVector *psDPolynomial4DEvalVector(const psDPolynomial4D *poly,
-                                    const psVector *x,
-                                    const psVector *y,
-                                    const psVector *z,
-                                    const psVector *t)
-{
-    PS_ASSERT_POLY_NON_NULL(poly, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(x, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(y, NULL);
-    PS_ASSERT_VECTOR_TYPE(y, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(z, NULL);
-    PS_ASSERT_VECTOR_TYPE(z, PS_TYPE_F64, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(t, NULL);
-    PS_ASSERT_VECTOR_TYPE(t, PS_TYPE_F64, NULL);
-
-    psVector *tmp;
-    psS32 vecLen=x->n;
-
-    // Determine the output vector size from min of input vectors
-    if (z->n < vecLen) {
-        vecLen = z->n;
-    }
-    if (y->n < vecLen) {
-        vecLen = y->n;
-    }
-    if (t->n < vecLen) {
-        vecLen = t->n;
-    }
-
-    // Allocate output vector
-    tmp = psVectorAlloc(vecLen, PS_TYPE_F64);
-
-    // Evaluate the polynomial
-    for (psS32 i = 0; i < vecLen; i++) {
-        tmp->data.F64[i] = psDPolynomial4DEval(poly,
-                                               x->data.F64[i],
-                                               y->data.F64[i],
-                                               z->data.F64[i],
-                                               t->data.F64[i]);
-    }
-
-    // Return output vector
-    return(tmp);
-}
-
-
-
-
-//typedef struct {
-//    psS32 n;
-//    psPolynomial1D **spline;
-//    psF32 *p_psDeriv2;
-//    psVector *knots;
-//} psSpline1D;
-
-/*****************************************************************************
-    NOTE: "n" specifies the number of spline polynomials.  Therefore, there
-    must exist n+1 points in "knots".
- 
-XXX: Ensure that domain[i+1] != domain[i]
- 
-XXX: What should be the defualty type for knots be?  psF32 is assumed.
- *****************************************************************************/
-psSpline1D *psSpline1DAlloc(int numSplines,
-                            int order,
-                            float min,
-                            float max)
-{
-    PS_ASSERT_INT_NONNEGATIVE(numSplines, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
-    PS_ASSERT_FLOAT_NON_EQUAL(max, min, NULL);
-
-    psSpline1D *tmp = NULL;
-    psS32 i;
-    psF32 tmpDomain;
-    psF32 width;
-
-    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
-    tmp->n = numSplines;
-
-    tmp->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
-    for (i=0;i<numSplines;i++) {
-        (tmp->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
-    }
-
-    // This should be set by the psVectorFitSpline1D()
-    tmp->p_psDeriv2 = NULL;
-
-    tmp->knots = psVectorAlloc(numSplines+1, PS_TYPE_F32);
-    width = (max - min) / ((psF32) numSplines);
-
-    tmp->knots->data.F32[0] = min;
-    tmpDomain = min+width;
-    for (i=1;i<numSplines+1;i++) {
-        tmp->knots->data.F32[i] = tmpDomain;
-        tmpDomain+= width;
-    }
-    tmp->knots->data.F32[numSplines] = max;
-
-    psMemSetDeallocator(tmp,(psFreeFunc)spline1DFree);
-    return(tmp);
-}
-
-
-/*****************************************************************************
-XXX: What should be the defualty type for knots be?  psF32 is assumed.
- *****************************************************************************/
-psSpline1D *psSpline1DAllocGeneric(const psVector *bounds,
-                                   int order)
-{
-    PS_ASSERT_VECTOR_NON_NULL(bounds, NULL);
-    PS_ASSERT_VECTOR_NON_EMPTY(bounds, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
-
-    psSpline1D *tmp = NULL;
-    psS32 i;
-    psS32 numSplines;
-
-    tmp = (psSpline1D *) psAlloc(sizeof(psSpline1D));
-
-    numSplines = bounds->n - 1;
-    tmp->n = numSplines;
-
-    tmp->spline = (psPolynomial1D **) psAlloc(numSplines * sizeof(psPolynomial1D *));
-    for (i=0;i<numSplines;i++) {
-        (tmp->spline)[i] = psPolynomial1DAlloc(order+1, PS_POLYNOMIAL_ORD);
-    }
-
-    // This should be set by the psVectorFitSpline1D()
-    tmp->p_psDeriv2 = NULL;
-
-    tmp->knots = psVectorAlloc(bounds->n, PS_TYPE_F32);
-
-    for (i=0;i<bounds->n;i++) {
-        tmp->knots->data.F32[i] = bounds->data.F32[i];
-        if (i<(bounds->n-1)) {
-            if (FLT_EPSILON >= fabs(bounds->data.F32[i+1]-bounds->data.F32[i])) {
-                psError(PS_ERR_UNKNOWN, true, "data points must be distinct\n");
-            }
-        }
-    }
-
-    psMemSetDeallocator(tmp,(psFreeFunc)spline1DFree);
-    return(tmp);
-}
-
-/*****************************************************************************
-vectorBinDisectF32(): This is a macro for a private function which takes as
-input a vector an array of data as well as a single value for that data.  The
-input vector values are assumed to be non-decreasing (v[i-1] <= v[i] for all
-i).  This routine does a binary disection of the vector and returns "i" such
-that (v[i] <= x <= v[i+1).  If x lies outside the range of v[], then this
-routine prints a warning message and returns (-2 or -1).
- *****************************************************************************/
-#define FUNC_MACRO_VECTOR_BIN_DISECT(TYPE) \
-static psS32 vectorBinDisect##TYPE(ps##TYPE *bins, \
-                                   psS32 numBins, \
-                                   ps##TYPE x) \
-{ \
-    psS32 min; \
-    psS32 max; \
-    psS32 mid; \
-    \
-    psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-            "---- Calling vectorBinDisect##TYPE(%f)\n", x); \
-    \
-    if (x < bins[0]) { \
-        psLogMsg(__func__, PS_LOG_WARN, \
-                 "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
-                 #TYPE, x, bins[0], bins[numBins-1]); \
-        return(-2); \
-    } \
-    \
-    if (x > bins[numBins-1]) { \
-        psLogMsg(__func__, PS_LOG_WARN, \
-                 "vectorBinDisect%s(): ordinate %f is outside vector range (%f - %f).", \
-                 #TYPE, x, bins[0], bins[numBins-1]); \
-        return(-1); \
-    } \
-    \
-    min = 0; \
-    max = numBins-2; \
-    mid = ((max+1)-min)/2; \
-    \
-    while (min != max) { \
-        psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-                "(min, mid, max) is (%d, %d, %d): (x, bins) is (%f, %f)\n", \
-                min, mid, max, x, bins[mid]); \
-        \
-        if (x == bins[mid]) { \
-            psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-                    "---- Exiting vectorBinDisect##TYPE(): bin %d\n", mid); \
-            return(mid); \
-        } else if (x < bins[mid]) { \
-            max = mid-1; \
-        } else { \
-            min = mid; \
-        } \
-        mid = ((max+1)+min)/2; \
-    } \
-    \
-    psTrace(".psLib.dataManip.psFunctions.vectorBinDisect##TYPE", 4, \
-            "---- Exiting vectorBinDisect##TYPE(): bin %d\n", min); \
-    return(min); \
-} \
-
-FUNC_MACRO_VECTOR_BIN_DISECT(S8)
-FUNC_MACRO_VECTOR_BIN_DISECT(S16)
-FUNC_MACRO_VECTOR_BIN_DISECT(S32)
-FUNC_MACRO_VECTOR_BIN_DISECT(S64)
-FUNC_MACRO_VECTOR_BIN_DISECT(U8)
-FUNC_MACRO_VECTOR_BIN_DISECT(U16)
-FUNC_MACRO_VECTOR_BIN_DISECT(U32)
-FUNC_MACRO_VECTOR_BIN_DISECT(U64)
-FUNC_MACRO_VECTOR_BIN_DISECT(F32)
-FUNC_MACRO_VECTOR_BIN_DISECT(F64)
-
-/*****************************************************************************
-p_psVectorBinDisect(): A wrapper to the above p_psVectorBinDisect().
- *****************************************************************************/
-psS32 p_psVectorBinDisect(psVector *bins,
-                          psScalar *x)
-{
-    PS_ASSERT_VECTOR_NON_NULL(bins, -4);
-    PS_ASSERT_VECTOR_NON_EMPTY(bins, -4);
-    PS_ASSERT_PTR_NON_NULL(x, -6);
-    PS_ASSERT_PTR_TYPE_EQUAL(x, bins, -3);
-    char* strType;
-
-    switch (x->type.type) {
-    case PS_TYPE_U8:
-        return(vectorBinDisectU8(bins->data.U8, bins->n, x->data.U8));
-    case PS_TYPE_U16:
-        return(vectorBinDisectU16(bins->data.U16, bins->n, x->data.U16));
-    case PS_TYPE_U32:
-        return(vectorBinDisectU32(bins->data.U32, bins->n, x->data.U32));
-    case PS_TYPE_U64:
-        return(vectorBinDisectU64(bins->data.U64, bins->n, x->data.U64));
-    case PS_TYPE_S8:
-        return(vectorBinDisectS8(bins->data.S8, bins->n, x->data.S8));
-    case PS_TYPE_S16:
-        return(vectorBinDisectS16(bins->data.S16, bins->n, x->data.S16));
-    case PS_TYPE_S32:
-        return(vectorBinDisectS32(bins->data.S32, bins->n, x->data.S32));
-    case PS_TYPE_S64:
-        return(vectorBinDisectS64(bins->data.S64, bins->n, x->data.S64));
-    case PS_TYPE_F32:
-        return(vectorBinDisectF32(bins->data.F32, bins->n, x->data.F32));
-    case PS_TYPE_F64:
-        return(vectorBinDisectF64(bins->data.F64, bins->n, x->data.F64));
-    case PS_TYPE_C32:
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return 0;
-    case PS_TYPE_C64:
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return 0;
-    case PS_TYPE_BOOL:
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return 0;
-    }
-    return(-3);
-}
-
-/*****************************************************************************
-p_psVectorInterpolate(): This routine will take as input psVectors domain and
-range, and the x value, assumed to lie with the domain vector.  It produces
-as output the LaGrange interpolated value of a polynomial of the specified
-order around the point x.
- 
-XXX: This stuff does not currently work with a mask.
- 
-XXX: add another psScalar argument for the result.
- 
-XXX: The VectorCopy routines seg fault when I declare range32 as static.
- *****************************************************************************/
-psScalar *p_psVectorInterpolate(psVector *domain,
-                                psVector *range,
-                                psS32 order,
-                                psScalar *x)
-{
-    PS_ASSERT_VECTOR_NON_NULL(domain, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(range, NULL);
-    PS_ASSERT_PTR_NON_NULL(x, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(order, NULL);
-    PS_ASSERT_VECTORS_SIZE_EQUAL(domain, range, NULL);
-    PS_ASSERT_PTR_TYPE_EQUAL(domain, range, NULL);
-    PS_ASSERT_PTR_TYPE_EQUAL(domain, x, NULL);
-
-    psVector *range32 = NULL;
-    psVector *domain32 = NULL;
-    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-            "---- p_psVectorInterpolate() begin ----\n");
-
-    if (order > (domain->n - 1)) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
-                PS_ERRORTEXT_psFunctions_NOT_ENOUGH_DATAPOINTS,
-                order);
-        return(NULL);
-    }
-
-    if (x->type.type == PS_TYPE_F32) {
-        psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-                "---- p_psVectorInterpolate() end ----\n");
-        return(psScalarAlloc(interpolate1DF32(domain->data.F32,
-                                              range->data.F32,
-                                              domain->n,
-                                              order,
-                                              x->data.F32), PS_TYPE_F32));
-    } else if (x->type.type == PS_TYPE_F64) {
-        // XXX: use recycled vectors here.
-        range32 = psVectorCopy(range32, range, PS_TYPE_F32);
-        domain32 = psVectorCopy(domain32, domain, PS_TYPE_F32);
-
-        psScalar *tmpScalar = psScalarAlloc((psF64)
-                                            interpolate1DF32(domain32->data.F32,
-                                                             range32->data.F32,
-                                                             domain32->n,
-                                                             order,
-                                                             (psF32) x->data.F64), PS_TYPE_F64);
-        psFree(range32);
-        psFree(domain32);
-
-        psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-                "---- p_psVectorInterpolate() end ----\n");
-        // XXX: Convert data type to F64?
-        return(tmpScalar);
-
-    } else {
-        char* strType;
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-    }
-
-    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-            "return(NULL)\n");
-    psTrace(".psLib.dataManip.psFunctions.p_psVectorInterpolate", 4,
-            "---- p_psVectorInterpolate() end ----\n");
-
-    return(NULL);
-}
-
-
-/*****************************************************************************
-psSpline1DEval(): this routine takes an existing spline of arbitrary order
-and an independent x value.  Each determines which spline that x corresponds
-to by doing a bracket disection on the knots of the spline data structure
-(vectorBinDisectF32()).  Then it evaluates the spline at that x location
-by a call to the 1D polynomial functions.
- 
-XXX: The spline eval functions require input and output to be F32.  however
-     the spline fit functions require F32 and F64.
- 
-XXX: This only works if spline0>knots if psF32.  Must add support for psU32 and
-psF64.
- *****************************************************************************/
-float psSpline1DEval(
-    const psSpline1D *spline,
-    float x
-)
-{
-    PS_ASSERT_PTR_NON_NULL(spline, NAN);
-    PS_ASSERT_INT_NONNEGATIVE(spline->n, NAN);
-    PS_ASSERT_VECTOR_TYPE(spline->knots, PS_TYPE_F32, NAN);
-
-    psS32 binNum;
-    psS32 n;
-
-    n = spline->n;
-    //XXX    binNum = vectorBinDisectF32(spline->domains, (spline->n)+1, x);
-    binNum = vectorBinDisectF32(spline->knots->data.F32, (spline->n)+1, x);
-    if (binNum < 0) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "psSpline1DEval(): x ordinate (%f) is outside the spline range (%f - %f).",
-                 x, spline->knots->data.F32[0],
-                 spline->knots->data.F32[n-1]);
-
-        if (x < spline->knots->data.F32[0]) {
-            return(psPolynomial1DEval(spline->spline[0],
-                                      x));
-        } else if (x > spline->knots->data.F32[n-1]) {
-            return(psPolynomial1DEval(spline->spline[n-1],
-                                      x));
-        }
-    }
-
-    return(psPolynomial1DEval(spline->spline[binNum],
-                              x));
-}
-
-// XXX: The spline eval functions require input and output to be F32.
-// however the spline fit functions require F32 and F64.
-psVector *psSpline1DEvalVector(
-    const psSpline1D *spline,
-    const psVector *x
-)
-{
-    PS_ASSERT_PTR_NON_NULL(spline, NULL);
-    PS_ASSERT_VECTOR_NON_NULL(x, NULL);
-    PS_ASSERT_VECTOR_TYPE_F32_OR_F64(x, NULL);
-    PS_ASSERT_VECTOR_TYPE(spline->knots, PS_TYPE_F32, NULL);
-
-    psS32 i;
-    psVector *tmpVector;
-
-    tmpVector = psVectorAlloc(x->n, PS_TYPE_F32);
-    if (x->type.type == PS_TYPE_F32) {
-        for (i=0;i<x->n;i++) {
-            tmpVector->data.F32[i] = psSpline1DEval(
-                                         spline,
-                                         x->data.F32[i]
-                                     );
-        }
-    } else if (x->type.type == PS_TYPE_F64) {
-        for (i=0;i<x->n;i++) {
-            tmpVector->data.F32[i] = psSpline1DEval(
-                                         spline,
-                                         (psF32) x->data.F64[i]
-                                     );
-        }
-    } else {
-        char* strType;
-        PS_TYPE_NAME(strType,x->type.type);
-        psError(PS_ERR_BAD_PARAMETER_TYPE,
-                PS_ERRORTEXT_psFunctions_TYPE_NOT_SUPPORTED,
-                strType);
-        return(NULL);
-    }
-
-    return(tmpVector);
-}
Index: unk/psLib/src/math/psSpline.h
===================================================================
--- /trunk/psLib/src/math/psSpline.h	(revision 4539)
+++ 	(revision )
@@ -1,515 +1,0 @@
-/** @file psFunctions.h
- *  @brief Standard Mathematical Functions.
- *  @ingroup Stats
- *
- *  This file will hold the prototypes for procedures which allocate, free,
- *  and evaluate various polynomials.  Those polynomial structures are also
- *  defined here.
- *
- *  @ingroup Stats
- *
- *  @author Someone at IfA
- *  @author GLG, MHPCC
- *
- *  @version $Revision: 1.51 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-29 03:23:19 $
- *
- *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
- */
-
-#ifndef PS_FUNCTIONS_H
-#define PS_FUNCTIONS_H
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <float.h>
-#include <math.h>
-
-#include "psVector.h"
-#include "psScalar.h"
-
-/** \addtogroup Stats
- *  \{
- */
-
-/** Evaluate a non-normalized Gaussian with the given mean and sigma at the
- *  given coordianate.
- *
- *  Note that this is not a Gaussian deviate.  The evaluated Gaussian is:
- *        \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f]
- *
- *  @return float      value on the gaussian curve given the input parameters
- */
-float psGaussian(
-    float x,                           ///< Value at which to evaluate
-    float mean,                        ///< Mean for the Gaussian
-    float sigma,                       ///< Standard deviation for the Gaussian
-    bool normal                        ///< Indicates whether result should be normalized
-);
-
-/** Produce a vector of random numbers from a Gaussian distribution with
- *  the specified mean and sigma
- *
- *  @return psVector*    vector of random numbers
- *
- */
-psVector* p_psGaussianDev(
-    psF32 mean,                        ///< The mean of the Gaussian
-    psF32 sigma,                       ///< The sigma of the Gaussian
-    psS32 Npts                         ///< The size of the vector
-);
-
-/** Polynomial Type.
- *
- *  Enumeration for Polynomial types.
- */
-typedef enum {
-    PS_POLYNOMIAL_ORD,                 ///< Ordinary Polynomial
-    PS_POLYNOMIAL_CHEB                 ///< Chebyshev Polynomial
-}
-psPolynomialType;
-
-/** One-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int n;                   ///< Number of terms
-    psF32 *coeff;                      ///< Coefficients
-    psF32 *coeffErr;                   ///< Error in coefficients
-    psU8 *mask;                        ///< Coefficient mask
-}
-psPolynomial1D;
-
-/** Two-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                   ///< Number of terms in x
-    unsigned int nY;                   ///< Number of terms in y
-    psF32 **coeff;                     ///< Coefficients
-    psF32 **coeffErr;                  ///< Error in coefficients
-    psU8 **mask;                       ///< Coefficients mask
-}
-psPolynomial2D;
-
-/** Three-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                   ///< Number of terms in x
-    unsigned int nY;                   ///< Number of terms in y
-    unsigned int nZ;                   ///< Number of terms in z
-    psF32 ***coeff;                    ///< Coefficients
-    psF32 ***coeffErr;                 ///< Error in coefficients
-    psU8 ***mask;                      ///< Coefficients mask
-}
-psPolynomial3D;
-
-/** Four-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                   ///< Number of terms in x
-    unsigned int nY;                   ///< Number of terms in y
-    unsigned int nZ;                   ///< Number of terms in z
-    unsigned int nT;                   ///< Number of terms in t
-    psF32 ****coeff;                   ///< Coefficients
-    psF32 ****coeffErr;                ///< Error in coefficients
-    psU8 ****mask;                     ///< Coefficients mask
-}
-psPolynomial4D;
-
-
-/** Allocates a psPolynomial1D structure with n terms
- *
- *  @return  psPolynomial1D*    new 1-D polynomial struct
- */
-psPolynomial1D* psPolynomial1DAlloc(
-    unsigned int n,                   ///< Number of terms
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 2-D polynomial structure
- *
- *  @return  psPolynomial2D*    new 2-D polynomial struct
- */
-psPolynomial2D* psPolynomial2DAlloc(
-    unsigned int nX,                   ///< Number of terms in x
-    unsigned int nY,                   ///< Number of terms in y
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 3-D polynomial structure
- *
- *  @return  psPolynomial3D*    new 3-D polynomial struct
- */
-psPolynomial3D* psPolynomial3DAlloc(
-    unsigned int nX,                   ///< Number of terms in x
-    unsigned int nY,                   ///< Number of terms in y
-    unsigned int nZ,                   ///< Number of terms in z
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a 4-D polynomial structure
- *
- *  @return  psPolynomial4D*    new 4-D polynomial struct
- */
-psPolynomial4D* psPolynomial4DAlloc(
-    unsigned int nX,                   ///< Number of terms in x
-    unsigned int nY,                   ///< Number of terms in y
-    unsigned int nZ,                   ///< Number of terms in z
-    unsigned int nT,                   ///< Number of terms in t
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Evaluates a 1-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial1DEval(
-    const psPolynomial1D* poly,        ///< Coefficients for the polynomial
-    psF64 x                            ///< location at which to evaluate
-);
-
-/** Evaluates a 2-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial2DEval(
-    const psPolynomial2D* poly,        ///< Coefficients for the polynomial
-    psF64 x,                           ///< x location at which to evaluate
-    psF64 y                            ///< y location at which to evaluate
-);
-
-/** Evaluates a 3-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial3DEval(
-    const psPolynomial3D* poly,        ///< Coefficients for the polynomial
-    psF64 x,                           ///< x location at which to evaluate
-    psF64 y,                           ///< y location at which to evaluate
-    psF64 z                            ///< z location at which to evaluate
-);
-
-/** Evaluates a 4-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psPolynomial4DEval(
-    const psPolynomial4D* poly,        ///< Coefficients for the polynomial
-    psF64 x,                           ///< x location at which to evaluate
-    psF64 y,                           ///< y location at which to evaluate
-    psF64 z,                           ///< z location at which to evaluate
-    psF64 t                            ///< t location at which to evaluate
-);
-
-/** Evaluates a 1-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomials at given locations
- */
-psVector *psPolynomial1DEvalVector(
-    const psPolynomial1D *poly,        ///< Coefficients for the polynomial
-    const psVector *x                  ///< x locations at which to evaluate
-);
-
-/** Evaluates a 2-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psPolynomial2DEvalVector(
-    const psPolynomial2D *poly,        ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y                  ///< y locations at which to evaluate
-);
-
-/** Evaluates a 3-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psPolynomial3DEvalVector(
-    const psPolynomial3D *poly,        ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y,                 ///< y locations at which to evaluate
-    const psVector *z                  ///< z locations at which to evaluate
-);
-
-/** Evaluates a 4-D polynomial at specific sets of coordinates
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psPolynomial4DEvalVector(
-    const psPolynomial4D *poly,        ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y,                 ///< y locations at which to evaluate
-    const psVector *z,                 ///< z locations at which to evaluate
-    const psVector *t                  ///< t locations at which to evaluate
-);
-
-/*****************************************************************************/
-
-/* Double-precision polynomials, mainly for use in astrometry */
-
-/** Double-precision one-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int n;                           ///< Number of terms
-    psF64 *coeff;                      ///< Coefficients
-    psF64 *coeffErr;                   ///< Error in coefficients
-    psU8 *mask;                        ///< Coefficient mask
-}
-psDPolynomial1D;
-
-/** Double-precision two-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                          ///< Number of terms in x
-    unsigned int nY;                          ///< Number of terms in y
-    psF64 **coeff;                     ///< Coefficients
-    psF64 **coeffErr;                  ///< Error in coefficients
-    psU8 **mask;                       ///< Coefficients mask
-}
-psDPolynomial2D;
-
-/** Double-precision three-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                          ///< Number of terms in x
-    unsigned int nY;                          ///< Number of terms in y
-    unsigned int nZ;                          ///< Number of terms in z
-    psF64 ***coeff;                    ///< Coefficients
-    psF64 ***coeffErr;                 ///< Error in coefficients
-    psU8 ***mask;                      ///< Coefficient mask
-}
-psDPolynomial3D;
-
-/** Double-precision four-dimensional polynomial */
-typedef struct
-{
-    psPolynomialType type;             ///< Polynomial type
-    unsigned int nX;                          ///< Number of terms in w
-    unsigned int nY;                          ///< Number of terms in x
-    unsigned int nZ;                          ///< Number of terms in y
-    unsigned int nT;                          ///< Number of terms in z
-    psF64 ****coeff;                   ///< Coefficients
-    psF64 ****coeffErr;                ///< Error in coefficients
-    psU8 ****mask;                     ///< Coefficients mask
-}
-psDPolynomial4D;
-
-/** Allocates a double-precision 1-D polynomial structure with n terms
- *
- *  @return  psPolynomial1D*    new double-precision 1-D polynomial struct
- */
-psDPolynomial1D* psDPolynomial1DAlloc(
-    unsigned int n,                           ///< Number of terms
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a double-precision 2-D polynomial structure
- *
- *  @return  psPolynomial2D*    new double-precision 2-D polynomial struct
- */
-psDPolynomial2D* psDPolynomial2DAlloc(
-    unsigned int nX,                          ///< Number of terms in x
-    unsigned int nY,                          ///< Number of terms in y
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a double-precision 3-D polynomial structure
- *
- *  @return  psPolynomial3D*    new double-precision 3-D polynomial struct
- */
-psDPolynomial3D* psDPolynomial3DAlloc(
-    unsigned int nX,                          ///< Number of terms in x
-    unsigned int nY,                          ///< Number of terms in y
-    unsigned int nZ,                          ///< Number of terms in z
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Allocates a double-precision 4-D polynomial structure
- *
- *  @return  psPolynomial4D*    new double-precision 4-D polynomial struct
- */
-psDPolynomial4D* psDPolynomial4DAlloc(
-    unsigned int nX,                          ///< Number of terms in w
-    unsigned int nY,                          ///< Number of terms in x
-    unsigned int nZ,                          ///< Number of terms in y
-    unsigned int nT,                          ///< Number of terms in z
-    psPolynomialType type              ///< Polynomial Type
-);
-
-/** Evaluates a double-precision 1-D polynomial at specific coordinates.
- *
- *  @return psF32    result of polynomial at given location
- */
-psF64 psDPolynomial1DEval(
-    const psDPolynomial1D* poly,     ///< Coefficients for the polynomial
-    psF64 x                            ///< Value at which to evaluate
-);
-
-/** Evaluates a double-precision 2-D polynomial at specific coordinates.
- *
- *  @return psF32    result of polynomial at given location
- */
-psF64 psDPolynomial2DEval(
-    const psDPolynomial2D* poly,      ///< Coefficients for the polynomial
-    psF64 x,                            ///< Value x at which to evaluate
-    psF64 y                             ///< Value y at which to evaluate
-);
-
-/** Evaluates a double-precision 3-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psDPolynomial3DEval(
-    const psDPolynomial3D* poly,     ///< Coefficients for the polynomial
-    psF64 x,                           ///< Value x at which to evaluate
-    psF64 y,                           ///< Value y at which to evaluate
-    psF64 z                            ///< Value z at which to evaluate
-);
-
-/** Evaluates a double-precision 4-D polynomial at specific coordinates.
- *
- *  @return psF64    result of polynomial at given location
- */
-psF64 psDPolynomial4DEval(
-    const psDPolynomial4D* poly,     ///< Coefficients for the polynomial
-    psF64 x,                           ///< Value w at which to evaluate
-    psF64 y,                           ///< Value x at which to evaluate
-    psF64 z,                           ///< Value y at which to evaluate
-    psF64 t                            ///< Value z at which to evaluate
-);
-
-/** Evaluates a double-precision 1-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial1DEvalVector(
-    const psDPolynomial1D *poly,     ///< Coefficients for the polynomial
-    const psVector *x                  ///< x locations at which to evaluate
-);
-
-/** Evaluates a double-precision 2-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial2DEvalVector(
-    const psDPolynomial2D *poly,     ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y                  ///< y locations at which to evaluate
-);
-
-/** Evaluates a double-precision 3-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial3DEvalVector(
-    const psDPolynomial3D *poly,     ///< Coefficients for the polynomial
-    const psVector *x,                 ///< x locations at which to evaluate
-    const psVector *y,                 ///< y locations at which to evaluate
-    const psVector *z                  ///< z locations at which to evaluate
-);
-
-/** Evaluates a double-precision 4-D polynomial at specific sets of coordinates.
- *  
- *  @return psVector*    results of polynomial at given locations
- */
-psVector *psDPolynomial4DEvalVector(
-    const psDPolynomial4D *poly,     ///< Coefficients for the polynomial
-    const psVector *x,                 ///< w locations at which to evaluate
-    const psVector *y,                 ///< x locations at which to evaluate
-    const psVector *z,                 ///< y locations at which to evaluate
-    const psVector *t                  ///< z locations at which to evaluate
-);
-
-/** One-Dimensional Spline */
-typedef struct
-{
-    psS32 n;                           ///< The number of spline polynomials
-    psPolynomial1D **spline;           ///< An array of n pointers to the spline polynomials
-    psF32 *p_psDeriv2;                 ///< For cubic splines, the second derivative at each domain point.  Size is n+1.
-    psF32 *domains;                    ///< The boundaries between each spline piece.  Size is n+1.
-    psVector *knots;                   ///< The boundaries between each spline piece.  Size is n+1.
-}
-psSpline1D;
-
-/** Allocates a psSpline1D structure
- *  
- *  Allocator for psSpline1D where the bounds are implicitly specified through specifying
- *  min and max values along with the number of splines.
- *
- *  @return psSpline1D*    new 1-D spline struct
- */
-psSpline1D *psSpline1DAlloc(
-    int n,                             ///< Number of spline polynomials
-    int order,                         ///< Order of spline polynomials
-    float min,                         ///< Lower boundary value of spline polynomials
-    float max                          ///< Upper boundary value of spline polynomials
-);
-
-/** Allocates a psSpline1D structure
- *  
- *  Allocator for psSpline1D where the bounds are explicitly specified. 
- *
- *  @return psSpline1D*    new 1-D spline struct
- */
-psSpline1D *psSpline1DAllocGeneric(
-    const psVector *bounds,            ///< Bounds for spline polynomials
-    int order                          ///< Order of spline polynomials
-);
-
-/** Evaluates 1-D spline polynomials at a specific coordinate.
- *  
- *  @return float    result of spline polynomials evaluated at given location
- */
-float psSpline1DEval(
-    const psSpline1D *spline,          ///< Coefficients for spline polynomials
-    float x                            ///< location at which to evaluate
-);
-
-/** Evaluates 1-D spline polynomials at a set of specific coordinates.
- *  
- *  @return psVector*    results of spline polynomials evaluated at given locations
- */
-psVector *psSpline1DEvalVector(
-    const psSpline1D *spline,          ///< Coefficients of spline polynomials
-    const psVector *x                  ///< locations at which to evaluate
-);
-
-/** Performs a binary disection on a given vector.
- *  Searches through an array of data for a specified value.
- *  
- *  @return psS32    corresponding index number of specified value
- */
-psS32 p_psVectorBinDisect(
-    psVector *bins,                    ///< Array of non-decreasing values
-    psScalar *x                        ///< Target value to find
-);
-
-/** Interpolates a series of data points for evaluation at a specific coordinate.  Uses a
- *  Lagrange interpolation method.
- *
- *  @return psScalar*    Lagrange interpolation value at given location
- */
-psScalar *p_psVectorInterpolate(
-    psVector *domain,                  ///< Domain (x coords) for interpolation
-    psVector *range,                   ///< Range (y coords) for interpolation
-    psS32 order,                       ///< Order of interpolation function
-    psScalar *x                        ///< Location at which to evaluate
-);
-
-#if 0
-psF32 p_psNRSpline1DEval(psSpline1D *spline,
-                         const psVector* x,
-                         const psVector* y,
-                         psF32 X);
-#endif // #if 0
-
-/** \} */ // End of MathGroup Functions
-
-#endif // #ifndef PS_FUNCTIONS_H
-
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 4539)
+++ /trunk/psLib/src/math/psStats.c	(revision 4540)
@@ -14,6 +14,6 @@
  *      stats->binsize
  *
- *  @version $Revision: 1.136 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.137 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -41,5 +41,5 @@
 #include "psConstants.h"
 
-#include "psDataManipErrors.h"
+#include "psErrorText.h"
 
 /*****************************************************************************/
@@ -77,5 +77,6 @@
 psBool p_psGetStatValue(const psStats* stats, psF64 *value)
 {
-    switch (stats->options & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
+    //    switch (stats->options & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
+    switch (stats->options & ~(PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE)) {
     case PS_STAT_SAMPLE_MEAN:
         *value = stats->sampleMean;
@@ -658,5 +659,5 @@
         x.data.F32 = iMid - (PS_GAUSS_WIDTH * sigma);
         if ((x.data.F32 >= firstBound) && (x.data.F32 <= lastBound)) {
-            jMin = p_psVectorBinDisect(robustHistogram->bounds, &x);
+            jMin = p_psVectorBinDisect( *(psVector* *)&robustHistogram->bounds, &x);
             if (jMin < 0) {
                 psError(PS_ERR_UNEXPECTED_NULL,
@@ -673,5 +674,5 @@
         x.data.F32 = iMid + (PS_GAUSS_WIDTH * sigma);
         if ((x.data.F32 >= firstBound) && (x.data.F32 <= lastBound)) {
-            jMax = p_psVectorBinDisect(robustHistogram->bounds, &x);
+            jMax = p_psVectorBinDisect( *(psVector* *)&robustHistogram->bounds, &x);
             if (jMax < 0) {
                 psError(PS_ERR_UNEXPECTED_NULL,
@@ -1705,5 +1706,5 @@
         //Determine id that is okay.
         stats->robustMedian = fitQuadraticSearchForYThenReturnX(
-                                  robustHistogram->bounds,
+                                  *(psVector* *)&robustHistogram->bounds,
                                   cumulativeRobustSums,
                                   medianBinNum,
@@ -1721,5 +1722,5 @@
         //Determine id that is okay.
         stats->robustLQ = fitQuadraticSearchForYThenReturnX(
-                              robustHistogram->bounds,
+                              *(psVector* *)&robustHistogram->bounds,
                               cumulativeRobustSums,
                               LQBinNum,
@@ -1728,5 +1729,5 @@
         //Determine id that is okay.
         stats->robustUQ = fitQuadraticSearchForYThenReturnX(
-                              robustHistogram->bounds,
+                              *(psVector* *)&robustHistogram->bounds,
                               cumulativeRobustSums,
                               UQBinNum,
@@ -1812,5 +1813,5 @@
     psMemSetDeallocator(newHist, (psFreeFunc) histogramFree);
     newHist->bounds = psVectorAlloc(n + 1, PS_TYPE_F32);
-    newHist->bounds->n = newHist->bounds->nalloc;
+    *(int *)&newHist->bounds->n = newHist->bounds->nalloc;
 
     // Calculate the bounds for each bin.
@@ -1859,5 +1860,5 @@
     psMemSetDeallocator(newHist, (psFreeFunc) histogramFree);
     newHist->bounds = psVectorAlloc(bounds->n, PS_TYPE_F32);
-    newHist->bounds->n = newHist->bounds->nalloc;
+    *(int *)&newHist->bounds->n = newHist->bounds->nalloc;
     for (i = 0; i < bounds->n; i++) {
         newHist->bounds->data.F32[i] = bounds->data.F32[i];
@@ -2067,5 +2068,5 @@
                     // correct bin number requires a bit more work.
                     tmpScalar.data.F32 = inF32->data.F32[i];
-                    binNum = p_psVectorBinDisect(out->bounds, &tmpScalar);
+                    binNum = p_psVectorBinDisect( *(psVector* *)&out->bounds, &tmpScalar);
                     if (binNum < 0) {
                         psLogMsg(__func__, PS_LOG_WARN,
Index: /trunk/psLib/src/math/psStats.h
===================================================================
--- /trunk/psLib/src/math/psStats.h	(revision 4539)
+++ /trunk/psLib/src/math/psStats.h	(revision 4540)
@@ -14,6 +14,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -52,5 +52,5 @@
     PS_STAT_USE_RANGE =  0x002000,          ///< Range
     PS_STAT_USE_BINSIZE = 0x004000,         ///< Binsize
-    PS_STAT_ROBUST_FOR_SAMPLE = 0x008000    ///< Robust for sample
+    //    PS_STAT_ROBUST_FOR_SAMPLE = 0x008000    ///< Robust for sample
 } psStatsOptions;
 
@@ -60,26 +60,26 @@
 typedef struct
 {
-    psF64 sampleMean;          ///< formal mean of sample
-    psF64 sampleMedian;        ///< formal median of sample
-    psF64 sampleStdev;         ///< standard deviation of sample
-    psF64 sampleUQ;            ///< upper quartile of sample
-    psF64 sampleLQ;            ///< lower quartile of sample
-    psF64 robustMean;          ///< robust mean of array
-    psF64 robustMedian;        ///< robust median of array
-    psF64 robustMode;          ///< Robust mode of array
-    psF64 robustStdev;         ///< robust standard deviation of array
-    psF64 robustUQ;            ///< robust upper quartile
-    psF64 robustLQ;            ///< robust lower quartile
-    psS32 robustN50;           ///< Number of points in Gaussian fit.  XXX: This is currently never set.
-    psS32 robustNfit;          ///< The number of points between the quartiles.
-    psF64 clippedMean;         ///< Nsigma clipped mean
-    psF64 clippedStdev;        ///< standard deviation after clipping
-    psS32 clippedNvalues;      ///< Number of data points used for clipped mean:  This value is never used.
-    psF64 clipSigma;           ///< Nsigma used for clipping; user input
-    psS32 clipIter;            ///< Number of clipping iterations; user input
-    psF64 min;                 ///< minimum data value in array
-    psF64 max;                 ///< maximum data value in array
-    psF64 binsize;             ///< binsize for robust fit (input/ouput)
-    psStatsOptions options;    ///< bitmask of calculated values
+    double sampleMean;                 ///< formal mean of sample
+    double sampleMedian;               ///< formal median of sample
+    double sampleStdev;                ///< standard deviation of sample
+    double sampleUQ;                   ///< upper quartile of sample
+    double sampleLQ;                   ///< lower quartile of sample
+    double robustMean;                 ///< robust mean of array
+    double robustMedian;               ///< robust median of array
+    double robustMode;                 ///< Robust mode of array
+    double robustStdev;                ///< robust standard deviation of array
+    double robustUQ;                   ///< robust upper quartile
+    double robustLQ;                   ///< robust lower quartile
+    int robustN50;                     ///< Number of points in Gaussian fit.  XXX: This is currently never set.
+    int robustNfit;                    ///< The number of points between the quartiles.
+    double clippedMean;                ///< Nsigma clipped mean
+    double clippedStdev;               ///< standard deviation after clipping
+    int clippedNvalues;                ///< Number of data points used for clipped mean:  This value is never used.
+    double clipSigma;                  ///< Nsigma used for clipping; user input
+    int clipIter;                      ///< Number of clipping iterations; user input
+    double min;                        ///< minimum data value in array
+    double max;                        ///< maximum data value in array
+    double binsize;                    ///< binsize for robust fit (input/ouput)
+    psStatsOptions options;            ///< bitmask of calculated values
 }
 psStats;
@@ -90,9 +90,9 @@
  */
 psStats* psVectorStats(
-    psStats* stats,          ///< stats structure defines stats to be calculated and how
-    const psVector* in,      ///< Vector to be analysed.
-    const psVector* errors,  ///< Errors.
-    const psVector* mask,    ///< Ignore elements where (maskVector & maskVal) != 0: must be INT or NULL
-    psMaskType maskVal       ///< Only mask elements with one of these bits set in maskVector
+    psStats* stats,                    ///< stats structure defines stats to be calculated and how
+    const psVector* in,                ///< Vector to be analysed.
+    const psVector* errors,            ///< Errors.
+    const psVector* mask,              ///< Ignore elements where (maskVector & maskVal) != 0: must be INT or NULL
+    psMaskType maskVal                 ///< Only mask elements with one of these bits set in maskVector
 );
 
@@ -121,9 +121,9 @@
 typedef struct
 {
-    psVector* bounds;                  ///< Bounds for the bins (type F32)
+    const psVector* bounds;            ///< Bounds for the bins (type F32)
     psVector* nums;                    ///< Number in each of the bins (INT)
-    psS32 minNum;                      ///< Number below the minimum
-    psS32 maxNum;                      ///< Number above the maximum
-    psBool uniform;                    ///< Is it a uniform distribution?
+    int minNum;                        ///< Number below the minimum
+    int maxNum;                        ///< Number above the maximum
+    bool uniform;                      ///< Is it a uniform distribution?
 }
 psHistogram;
Index: /trunk/psLib/src/math/psUnaryOp.c
===================================================================
--- /trunk/psLib/src/math/psUnaryOp.c	(revision 4539)
+++ /trunk/psLib/src/math/psUnaryOp.c	(revision 4540)
@@ -30,6 +30,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -51,5 +51,5 @@
 #include "psLogMsg.h"
 #include "psConstants.h"
-#include "psDataManipErrors.h"
+#include "psErrorText.h"
 
 /*****************************************************************************
@@ -304,5 +304,5 @@
 }
 
-psPtr psUnaryOp(psPtr out, const psPtr in, const char *op)
+psMathType* psUnaryOp(psPtr out, const psPtr in, const char *op)
 {
     #define psUnaryOp_EXIT { \
Index: /trunk/psLib/src/math/psUnaryOp.h
===================================================================
--- /trunk/psLib/src/math/psUnaryOp.h	(revision 4539)
+++ /trunk/psLib/src/math/psUnaryOp.h	(revision 4540)
@@ -30,6 +30,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -59,5 +59,5 @@
  *  @return  psType* : Pointer to either psImage or psVector.
  */
-psType* psUnaryOp(
+psMathType* psUnaryOp(
     psPtr out,                         ///< Output type, either psImage or psVector.
     const psPtr in,                    ///< Input, either psImage or psVector.
Index: /trunk/psLib/src/mathtypes/Makefile.am
===================================================================
--- /trunk/psLib/src/mathtypes/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/mathtypes/Makefile.am	(revision 4540)
@@ -1,49 +1,16 @@
-#Makefile for collections functions of psLib
+#Makefile for mathtypes functions of psLib
 #
+noinst_LTLIBRARIES = libpslibmathtypes.la
 
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+libpslibmathtypes_la_SOURCES = \
+	psImage.c \
+	psScalar.c \
+	psVector.c
 
-noinst_LTLIBRARIES = libpslibcollections.la
-
-libpslibcollections_la_SOURCES = \
-	psBitSet.c \
-	psVector.c \
-	psPixels.c \
-	psList.c \
-	psScalar.c \
-	psCompare.c \
-	psArray.c \
-	psHash.c \
-	psMetadata.c \
-	psMetadataIO.c
-
-BUILT_SOURCES = psCollectionsErrors.h
-EXTRA_DIST = psCollectionsErrors.dat psCollectionsErrors.h collections.i
-
-psCollectionsErrors.h:psCollectionsErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = mathtypes.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
-	psBitSet.h \
-	psVector.h \
-	psPixels.h \
-	psList.h \
+	psImage.h \
 	psScalar.h \
-	psCompare.h \
-	psArray.h \
-	psHash.h \
-	psMetadata.h \
-	psMetadataIO.h
-
+	psVector.h
Index: /trunk/psLib/src/mathtypes/mathtypes.i
===================================================================
--- /trunk/psLib/src/mathtypes/mathtypes.i	(revision 4540)
+++ /trunk/psLib/src/mathtypes/mathtypes.i	(revision 4540)
@@ -0,0 +1,5 @@
+/* mathtypes headers */
+
+%include "psImage.h"
+%include "psScalar.h"
+%include "psVector.h"
Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 4539)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 4540)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.72 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.73 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -48,6 +48,6 @@
 }
 
-psImage* psImageAlloc(psU32 numCols,
-                      psU32 numRows,
+psImage* psImageAlloc(int numCols,
+                      int numRows,
                       psElemType type)
 {
@@ -91,8 +91,8 @@
 }
 
-psRegion psRegionSet(psF32 x0,
-                     psF32 x1,
-                     psF32 y0,
-                     psF32 y1)
+psRegion psRegionSet(float x0,
+                     float x1,
+                     float y0,
+                     float y1)
 {
     psRegion out;
@@ -149,6 +149,6 @@
 
 psImage* psImageRecycle(psImage* old,
-                        psU32 numCols,
-                        psU32 numRows,
+                        int numCols,
+                        int numRows,
                         const psElemType type)
 {
@@ -369,11 +369,11 @@
 }
 
-psC64 psImagePixelInterpolate(const psImage* input,
-                              float x,
-                              float y,
-                              const psImage* mask,
-                              psU32 maskVal,
-                              psC64 unexposedValue,
-                              psImageInterpolateMode mode)
+complex psImagePixelInterpolate(const psImage* input,
+                                float x,
+                                float y,
+                                const psImage* mask,
+                                psMaskType maskVal,
+                                complex unexposedValue,
+                                psImageInterpolateMode mode)
 {
 
Index: /trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.h	(revision 4539)
+++ /trunk/psLib/src/mathtypes/psImage.h	(revision 4540)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.60 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -40,5 +40,5 @@
     PS_INTERPOLATE_LANCZOS3_VARIANCE,  ///< Variance version of PS_INTERPOLATE_LANCZOS3
     PS_INTERPOLATE_LANCZOS4_VARIANCE,  ///< Variance version of PS_INTERPOLATE_LANCZOS4
-    PS_INTERPOLATE_NUM_MODES           ///< enum end-marker; does not coorespond to a interpolation mode
+    //    PS_INTERPOLATE_NUM_MODES           ///< enum end-marker; does not coorespond to a interpolation mode
 } psImageInterpolateMode;
 
@@ -51,9 +51,9 @@
 typedef struct psImage
 {
-    const psType type;                 ///< Image data type and dimension.
-    const psU32 numCols;               ///< Number of columns in image
-    const psU32 numRows;               ///< Number of rows in image.
-    const psS32 col0;                  ///< Column position relative to parent.
-    const psS32 row0;                  ///< Row position relative to parent.
+    const psMathType type;             ///< Image data type and dimension.
+    const int numCols;                 ///< Number of columns in image
+    const int numRows;                 ///< Number of rows in image.
+    const int col0;                    ///< Column position relative to parent.
+    const int row0;                    ///< Row position relative to parent.
 
     union {
@@ -77,4 +77,5 @@
 
     psPtr rawDataBuffer;               ///< Raw data buffer for Allocating/Freeing Images
+    void *lock;                        ///< Optional lock for thread safety
 }
 psImage;
@@ -87,8 +88,8 @@
 typedef struct
 {
-    psF32 x0;                         ///< the first column of the region.
-    psF32 x1;                         ///< the last column of the region.
-    psF32 y0;                         ///< the first row of the region.
-    psF32 y1;                         ///< the last row of the region.
+    float x0;                         ///< the first column of the region.
+    float x1;                         ///< the last column of the region.
+    float y0;                         ///< the first row of the region.
+    float y1;                         ///< the last row of the region.
 }
 psRegion;
@@ -103,8 +104,9 @@
  */
 psImage* psImageAlloc(
-    psU32 numCols,                     ///< Number of rows in image.
-    psU32 numRows,                     ///< Number of columns in image.
+    int numCols,                       ///< Number of rows in image.
+    int numRows,                       ///< Number of columns in image.
     psElemType type                    ///< Type of data for image.
-);
+)
+;
 
 /** Create a psRegion with the specified attributes.
@@ -113,8 +115,8 @@
  */
 psRegion psRegionSet(
-    psF32 x0,                         ///< the first column of the region.
-    psF32 x1,                         ///< the last column of the region + 1.
-    psF32 y0,                         ///< the first row of the region.
-    psF32 y1                          ///< the last row of the region + 1.
+    float x0,                          ///< the first column of the region.
+    float x1,                          ///< the last column of the region + 1.
+    float y0,                          ///< the first row of the region.
+    float y1                           ///< the last row of the region + 1.
 );
 
@@ -146,11 +148,11 @@
 psImage* psImageRecycle(
     psImage* old,                      ///< the psImage to recycle by resizing image buffer
-    psU32 numCols,                     ///< the desired number of columns in image
-    psU32 numRows,                     ///< the desired number of rows in image
+    int numCols,                       ///< the desired number of columns in image
+    int numRows,                       ///< the desired number of rows in image
     const psElemType type              ///< the desired datatype of the image
 );
 
 /** Copy an image to a new buffer
- *  
+ *
  *  @return True if image copied or false if error
  */
@@ -195,11 +197,11 @@
  *                   given x,y doesn't coorespond to a valid image location
  */
-psC64 psImagePixelInterpolate(
+complex psImagePixelInterpolate(
     const psImage* input,              ///< input image for interpolation
     float x,                           ///< column location to derive value of
     float y,                           ///< row location ot derive value of
     const psImage* mask,               ///< if not NULL, the mask of the input image
-    psU32 maskVal,              ///< the mask value
-    psC64 unexposedValue,              ///< return value if x,y location is not in image.
+    psMaskType maskVal,                ///< the mask value
+    complex unexposedValue,            ///< return value if x,y location is not in image.
     psImageInterpolateMode mode        ///< interpolation mode
 );
Index: /trunk/psLib/src/mathtypes/psScalar.c
===================================================================
--- /trunk/psLib/src/mathtypes/psScalar.c	(revision 4539)
+++ /trunk/psLib/src/mathtypes/psScalar.c	(revision 4540)
@@ -8,6 +8,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -20,5 +20,5 @@
 #include "psAbort.h"
 
-#include "psCollectionsErrors.h"
+#include "psErrorText.h"
 
 psScalar* psScalarAlloc(complex value, psElemType type)
Index: /trunk/psLib/src/mathtypes/psScalar.h
===================================================================
--- /trunk/psLib/src/mathtypes/psScalar.h	(revision 4539)
+++ /trunk/psLib/src/mathtypes/psScalar.h	(revision 4540)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -32,5 +32,5 @@
 typedef struct
 {
-    psType type;                ///< Type of data.
+    psMathType type;            ///< Type of data.
 
     union {
Index: /trunk/psLib/src/mathtypes/psVector.c
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.c	(revision 4539)
+++ /trunk/psLib/src/mathtypes/psVector.c	(revision 4540)
@@ -9,6 +9,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-28 20:17:52 $
+*  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -26,5 +26,5 @@
 #include "psCompare.h"
 
-#include "psCollectionsErrors.h"
+#include "psErrorText.h"
 
 typedef struct
@@ -48,5 +48,5 @@
 // FUNCTION IMPLEMENTATION - PUBLIC
 
-psVector* psVectorAlloc(unsigned long nalloc, psElemType type)
+psVector* psVectorAlloc( long nalloc, psElemType type)
 {
     psVector* psVec = NULL;
@@ -67,5 +67,5 @@
     psVec->type.dimen = PS_DIMEN_VECTOR;
     psVec->type.type = type;
-    *(int*)&psVec->nalloc = nalloc;
+    *(long*)&psVec->nalloc = nalloc;
     psVec->n = nalloc;
 
@@ -76,5 +76,5 @@
 }
 
-psVector* psVectorRealloc(psVector* vector, unsigned long nalloc)
+psVector* psVectorRealloc(psVector* vector, long nalloc)
 {
     psS32 elementSize = 0;
@@ -93,5 +93,5 @@
         // Realloc after decrementation to avoid accessing freed array elements
         vector->data.U8 = psRealloc(vector->data.U8, nalloc * elementSize);
-        *(int*)&vector->nalloc = nalloc;
+        *(long*)&vector->nalloc = nalloc;
     }
 
@@ -99,5 +99,5 @@
 }
 
-psVector* psVectorRecycle(psVector* vector, unsigned long nalloc, psElemType type)
+psVector* psVectorRecycle(psVector* vector, long nalloc, psElemType type)
 {
     psS32 byteSize;
@@ -120,5 +120,5 @@
     if (byteSize > vector->nalloc*PSELEMTYPE_SIZEOF(vector->type.type)) {
         vector->data.U8 = psRealloc(vector->data.U8, byteSize);
-        *(int*)&vector->nalloc = nalloc;
+        *(long*)&vector->nalloc = nalloc;
     }
 
Index: /trunk/psLib/src/mathtypes/psVector.h
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.h	(revision 4539)
+++ /trunk/psLib/src/mathtypes/psVector.h	(revision 4540)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -51,8 +51,9 @@
 typedef struct
 {
-    psType type;                       ///< Type of data.
-    int n;                             ///< Number of elements in use.
-    const int nalloc;                  ///< Total number of elements available.
+    psMathType type;                       ///< Type of data.
+    long n;                            ///< Number of elements in use.
+    const long nalloc;                 ///< Total number of elements available.
     p_psVectorData data;               ///< Union for data types.
+    void *lock;                        ///< Optional lock for thread safety.
 }
 psVector;
@@ -73,7 +74,8 @@
  */
 psVector* psVectorAlloc(
-    unsigned long nalloc,              ///< Total number of elements to make available.
+    long nalloc,                       ///< Total number of elements to make available.
     psElemType type                    ///< Type of data to be held by vector.
-);
+)
+;
 
 /** Reallocate a vector.
@@ -88,5 +90,5 @@
 psVector* psVectorRealloc(
     psVector* vector,                  ///< Vector to reallocate.
-    unsigned long nalloc               ///< Total number of elements to make available.
+    long nalloc                        ///< Total number of elements to make available.
 );
 
@@ -120,5 +122,5 @@
     ///< taken to preserve the values.
 
-    unsigned long nalloc,              ///< Total number of elements to make available.
+    long nalloc,                       ///< Total number of elements to make available.
     psElemType type                    ///< the datatype of the returned vector
 );
Index: unk/psLib/src/psErrorCodes.dat
===================================================================
--- /trunk/psLib/src/psErrorCodes.dat	(revision 4539)
+++ 	(revision )
@@ -1,19 +1,0 @@
-#
-#  This file is used to generate psErrorCode.h content
-#
-# Format:
-#    ERROR_CLASS_NAME    ERROR_CLASS_DESCRIPTION
-#
-# Note: the ERROR_CLASS_NAME will appear in the code with a "PS_ERR_" prefix
-#
-UNKNOWN                        unknown error
-IO                             I/O error
-LOCATION_INVALID               specified location is unknown
-MEMORY_CORRUPTION              memory corruption detected
-MEMORY_DEREF_USAGE             dereferenced memory still used
-BAD_PARAMETER_VALUE            parameter is out-of-range
-BAD_PARAMETER_TYPE             parameter is of unsupported type
-BAD_PARAMETER_NULL             parameter is null
-BAD_PARAMETER_SIZE             size of parameter's data is outside of acceptable range.
-UNEXPECTED_NULL                unexpected NULL found
-OS_CALL_FAILED                 unexpected result from an OS standard library call.
Index: /trunk/psLib/src/psErrorCodes_en.dat
===================================================================
--- /trunk/psLib/src/psErrorCodes_en.dat	(revision 4540)
+++ /trunk/psLib/src/psErrorCodes_en.dat	(revision 4540)
@@ -0,0 +1,19 @@
+#
+#  This file is used to generate psErrorCode.h content
+#
+# Format:
+#    ERROR_CLASS_NAME    ERROR_CLASS_DESCRIPTION
+#
+# Note: the ERROR_CLASS_NAME will appear in the code with a "PS_ERR_" prefix
+#
+UNKNOWN                        unknown error
+IO                             I/O error
+LOCATION_INVALID               specified location is unknown
+MEMORY_CORRUPTION              memory corruption detected
+MEMORY_DEREF_USAGE             dereferenced memory still used
+BAD_PARAMETER_VALUE            parameter is out-of-range
+BAD_PARAMETER_TYPE             parameter is of unsupported type
+BAD_PARAMETER_NULL             parameter is null
+BAD_PARAMETER_SIZE             size of parameter's data is outside of acceptable range.
+UNEXPECTED_NULL                unexpected NULL found
+OS_CALL_FAILED                 unexpected result from an OS standard library call.
Index: /trunk/psLib/src/psErrorText.h.in
===================================================================
--- /trunk/psLib/src/psErrorText.h.in	(revision 4540)
+++ /trunk/psLib/src/psErrorText.h.in	(revision 4540)
@@ -0,0 +1,20 @@
+/** @file  psErrorText.h
+ *
+ *  @brief Contains the error text for the psLib library
+ *
+ *  @ingroup ErrorHandling
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:00 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#ifndef PS_ERROR_TEXT_H
+#define PS_ERROR_TEXT_H
+
+#define PS_ERRORTEXT_${ErrorCode} "${ErrorDescription}"
+
+#endif // #ifndef PS_ERROR_TEXT_H
Index: /trunk/psLib/src/psErrorText_en.dat
===================================================================
--- /trunk/psLib/src/psErrorText_en.dat	(revision 4540)
+++ /trunk/psLib/src/psErrorText_en.dat	(revision 4540)
@@ -0,0 +1,334 @@
+#
+#  This file is used to generate psErrorText.h content
+#
+#  Format is:
+#  ERRORNAME(one word)    ERROR_TEXT
+#
+#  N.B. in code, the ERRORNAME appears as PS_ERRORTEXT_ERRORNAME
+####################################################################
+psTime_FILE_NOT_FOUND                  Failed to open file %s.
+psTime_FILE_TOO_MANY_ROWS              Too many rows found in file %s. Max number of rows allowed is %d.
+psTime_TIME_POSTDATES_TABLE            Specified psTime postdates (%g) the table of %s information.
+psTime_TIME_PREDATES_TABLE             Specified psTime predates (%g) the table of %s information.
+psTime_TIME_POSTDATES_TABLES           Specified psTime postdates (%g) all tables of %s information.
+psTime_TIME_PREDATES_TABLES            Specified psTime predates (%g) all tables of %s information.
+psTime_TABLE_DUPLICATE_ROWS            The %s table was found to have two rows of the same time value.
+psTime_TYPE_UNKNOWN                    Specified type, %d, is not supported.
+psTime_TYPE_INCORRECT                  Specified type, %d, is incorrect.
+psTime_TYPE_MISMATCH                   Specified psTime parameters must have same type.
+psTime_GET_TOD_FAILED                  Failed to determine the current time from gettimeofday function.
+psTime_CONVERT_TIME_TO_STRING_FAILED   Failed to convert a time via strftime function.
+psTime_APPEND_MSEC_FAILED              Failed to append millisecond to time string with snprintf function.
+psTime_USEC_INVALID                    The psTime usec attribute value, %u, is invalid.  Must be less than 1e6.
+psTime_ISOTIME_MALFORMED               Specified ISO Time string, '%s', is malformed.  Must be in 'YYYY-MM-DDThh:mm:ss.sss' format.
+psTime_INTERPOLATION_FAILED            Failed time table interpolation.
+psTime_INTERPOLATION_FAILED_NAME       Failed time table interpolation for '%s'.
+psTime_LOOKUP_METADATA_FAILED          Failed find '%s' in time metadata.
+psTime_BAD_TABLE_COUNT                 Incorrect number of table files entered. Found: %d. Expected: %d.
+psTime_BAD_VECTOR                      Incorrect vector size. Size: %d, Expected %d.
+#
+psCoord_PROJECTION_TYPE_UNDEFINED      The projection type, %s, is undefined.
+psCoord_PROJECTION_TYPE_UNKNOWN        The projection type, %d, is unknown.
+psCoord_UNITS_UNKNOWN                  Specified units, 0x%x, is not supported.
+psCoord_OFFSET_MODE_UNKNOWN            Specified offset mode, 0x%x, is not supported.
+psCoord_INVALID_MJD                    Specified time is less than 1900.
+#
+psAstrometry_NONLINEAR_TRANSFORM       The %s transfrom is not linear.  Only linear transforms are supported.
+#
+psMetadata_METATYPE_INVALID            Specified psMetadataType, %d, is not supported.
+psMetadata_FORMAT_INVALID              Specified print format, %%%c, is not supported.
+psMetadata_METATYPE_MISMATCH           Specified psMetadataType, %d, is incorrect. Expected %d.
+psMetadata_ADD_LIST_FAILED             Failed to add metadata item, %s, to items list.
+psMetadata_ADD_TABLE_FAILED            Failed to add metadata item, %s, to items table.
+psMetadata_REMOVE_LIST_FAILED          Failed to remove metadata item, %s, from metadata list.
+psMetadata_REMOVE_LIST_INDEX_FAILED    Failed to remove metadata item, at index %d, from metadata list.
+psMetadata_REMOVE_TABLE_FAILED         Failed to remove metadata item, %s, from metadata table.
+psMetadata_ADD_COLLECTION_FAILED       Failed to add metadata item, %s, to metadata collection list.
+psMetadata_ADD_FAILED                  Failed to add metadata item to metadata collection list.
+psMetadata_FIND_FAILED                 Could not find metadata item, %s.
+psMetadata_FIND_INDEX_FAILED           Could not find metadata item at index %d.
+psMetadata_DUPLICATE_NOT_ALLOWED       Duplicate metadata item name is not allowed.  Use a psMetadataFlags option to allow such action.
+psMetadata_REGEX_INVALID               Specified regular expression is invalid.  %s.
+psMetadata_LOCATION_INVALID            Specified location, %d, is invalid.
+#
+psMetadataIO_TYPE_INVALID              Specified type, %d, is not supported.
+psMetadataIO_EXTNUM_NOTPOSITIVE        Specified extension number, %d, is invalid.  Value must be positive if no extension name is given.
+psMetadataIO_FITS_METATYPE_INVALID     Specified FITS metadata type, %c, is not supported.
+psMetadataIO_ADD_FAILED                Failed to add metadata item, %s.
+psMetadataIO_FILE_OPEN_FAILED          Failed to open file '%s'. Check if it exists and it has the proper permissions.
+psMetadataIO_FILE_MULTIPLE_CHAR        More than one '%c' character not allowed.  Found on line %u of %s.
+psMetadataIO_FILE_ELEMENT_NULL         Failed to read a metadata %s on line %u of %s.
+psMetadataIO_FILE_TYPE_INVALID         Metadata type '%s', found on line %u of %s, is invalid.
+psMetadataIO_OVERWRITE_ITEM            Duplicate Metadata item, %s, found on line %u of %s.  Overwrite not allowed.
+psMetadataIO_PARSE_FAILED              Failed to parse the value '%s' of metadata item %s, type %s, on line %u of %s.
+psMetadataIO_NO_NAME                   Failed to find key 'name' in table on line %u of %s.
+psMetadataIO_TYPE_INVALID_LINE_FILE    Specified type, %s, is not supported on line %u of %s.
+psMetadataIO_TAG_MISMATCH              Start tag, %s and end tag, %s do not agree.
+psMetadataIO_TAG_UNKNOWN               Invalid end tag name, %s.
+psMetadataIO_TYPE_DUPLICATE            Specified type, %s, on line %u of %s is already defined.
+psMetadataIO_DUPLICATE_MULTI           Duplicate MULTI specifier on line %u of %s.
+#
+psArray_REALLOC_NULL                   psArrayRealloc must be given a non-NULL psArray to resize.
+psArray_ARRAY_NULL                     Specified psArray can not be NULL.
+psArray_POSITION_BEYOND_NALLOC         Specified position, %d, is greater than the allocated size of the array, %d.
+#
+psVector_REALLOC_NULL                  psVectorRealloc must a given a non-NULL psVector to resize.  Desired datatype unknown.
+psVector_NOT_A_VECTOR                  The input psVector must have a vector dimension type.
+psVector_SORT_NULL                     psVectorSort can not sort a NULL psVector.
+psVector_UNSUPPORTED_TYPE              Input psVector is an unsupported type (0x%x).
+psVector_NULL                          The input psVector can not be NULL.
+psVector_EXTENDSIZE_NEG                The input number of elements to extend must be non-negative.
+#
+psBitSet_ALLOC_NEG_SIZE                The number of bit in a psBitSet (%d) must be greater than zero.
+psBitSet_SET_NULL                      Can not operate on a NULL psBitSet.
+psBitSet_BIT_OUTOFRANGE                The specified bit position (%d) is invalid.  Position must be between 0 and %d.
+psBitSet_OPERATOR_NULL                 Specified operator is NULL.  Must specify desired operator.
+psBitSet_OPERATOR_INVALID              Specified operator, %s, is invalid.  Valid operators are AND, OR, and XOR.
+psBitSet_FIRST_OPERAND_NULL            First psBitSet operand can not be NULL.
+psBitSet_SECOND_OPERAND_NULL           Second psBitSet operand can not be NULL.
+psBitSet_OPERANDS_SIZE_DIFFER          The psBitSet operand must be the same size.
+psBitSet_NOT_OP_FAILED                 Could not perform NOT operation.
+psBitSet_OPERAND_NULL                  Operand can not be NULL.
+#
+psScalar_UNSUPPORTED_TYPE              Specified datatype (%d) is unsupported by psScalar.
+psScalar_COPY_NULL                     Can not copy a NULL psScalar.
+#
+psHash_KEY_NULL                        Input key can not be NULL.
+psHash_TABLE_NULL                      Input psHash can not be NULL.
+psHash_DATA_NULL                       Input data can not be NULL.
+#
+psList_LOCATION_INVALID                Specified location, %d, is invalid.
+psList_ITERATOR_INVALID                Specified iterator is not valid.
+psList_ITERATOR_NULL                   Specified iterator is NULL.
+psList_ITERATOR_NONMUTABLE             Specified iterator indicates list is non-mutable.
+psList_LIST_NULL                       Specified psList reference is NULL.
+psList_DATA_NULL                       Specified data item is NULL.
+psList_DATA_NOT_FOUND                  Specified data item is not found in the psList.
+#
+psPixels_NULL                          Input psPixels can not be NULL.
+psPixels_MASK_NULL                     Specified mask can not be NULL.
+psPixels_MASK_TYPE                     Specified mask's type, %s, is invalid.  Should be PS_TYPE_MASK.
+psPixels_DATA_NULL                     Input psPixels contains no data.
+psPixels_REGION_INVALID                Specified psRegion, [%d:%d,%d:%d], does not specify a valid region.
+psPixels_FAILED_IMAGE_CREATE           Failed to create image of size %dx%d.
+#
+psLookupTable_FILE_NOT_FOUND           Failed to open file %s.
+psLookupTable_PARSE_VALUE              Unable to parse string, %s on line %lld.
+psLookupTable_PARSE_TYPE               Unable to parse type, %s on line %lld.
+psLookupTable_PARSE_GENERAL            Unable to read lookup table item, %s on line %lld
+psLookupTable_INTERPOLATE_HIGH         High index too big, %d.
+psLookupTable_INTERPOLATE_LOW          Low index too small, %d.
+psLookupTable_DIVIDE_BY_ZERO           Divide by zero error during interpolation.
+psLookupTable_INVALID_TYPE             Invalid psLookupType, %d;
+psLookupTable_TABLE_INVALID            Lookup table is invalid.
+#
+psFits_NULL                            The input psFits object can not NULL.
+psFits_FILENAME_INVALID                Could not open file,'%s'.\nCFITSIO Error: %s
+psFits_FILENAME_NULL                   Specified filename can not be NULL.
+psFits_EXTNAME_NULL                    Specified extension name can not be NULL.
+psFits_EXTNAME_INVALID                 Could not find HDU '%s' in file %s.\nCFITSIO Error: %s
+psFits_EXTNUM_ABS_MOVE_FAILED          Could not move to specified HDU #%d in file %s.\nCFITSIO Error: %s
+psFits_EXTNUM_REL_MOVE_FAILED          Could not move %d HDUs from current position in file %s.\nCFITSIO Error: %s
+psFits_GET_EXTNUM_FAILED               Failed to determine the current HDU number in file %s.\nCFITSIO Error: %s
+psFits_GETNUMHDUS_FAILED               Failed to determine the number of HDUs in file %s.\nCFITSIO Error: %s
+psFits_GETHDUTYPE_FAILED               Failed to determine an HDU type in file %s.\nCFITSIO Error: %s
+psFits_GETNUMKEYS_FAILED               Failed to determine the number of header keys in file %s.\nCFITSIO Error: %s
+psFits_GET_TABLE_SIZE_FAILED           Failed to determine the size of the current HDU table.\nCFITSIO Error: %s
+psFits_FILENAME_CREATE_FAILED          Could not create file,'%s'.\nCFITSIO Error: %s
+psFits_TYPE_UNSUPPORTED                Specified type, %s, is not supported.
+psFits_CREATE_HDU_FAILED               Could not create new image HDU in file,'%s'.\nCFITSIO Error: %s
+psFits_GET_HDU_TYPE_FAILED             Could not determine the HDU type.\nCFITSIO Error: %s
+psFits_NOT_IMAGE_TYPE                  Current FITS HDU type must be an image.
+psFits_NOT_TABLE_TYPE                  Current FITS HDU type must be a table.
+psFits_TABLE_EMPTY                     Can't create a table without any rows.
+psFits_CFITSIO_ERROR                   CFITSIO error: %s
+psFits_METATYPE_INVALID                Specified FITS metadata type, %c, is not supported.
+psFits_METADATA_ADD_FAILED             Failed to add metadata item, %s.
+psFits_WRITE_FAILED                    Could not write data to file,'%s'.\nCFITSIO Error: %s
+psFits_IMAGE_NULL                      The input psImage was NULL.  Need a non-NULL psImage for operation to be performed.
+psFits_METADATA_NULL                   The input psMetadata was NULL.  Need a non-NULL psMetadata for operation to be performed.
+psFits_METADATA_PTYPE_UNSUPPORTED      A metadata item's primative type, %d, is not supported.
+psFits_ROW_INVALID                     Specified row, %d, is not valid for current table of %d rows.
+psFits_GET_TABLE_ELEMENT               Failed to retrieve table element (%d,%d).\nCFITSIO Error: %s
+psFits_FIND_COLUMN                     Specified column, %s, was not found.\nCFITSIO Error: %s
+psFits_GET_COLTYPE                     Could not determine the datatype of the table column.\nCFITSIO Error: %s
+psFits_TABLE_READ_COL                  Failed to read table column.\nCFITSIO Error: %s
+psFits_DATATYPE_UNKNOWN                Could not determine image data type.\nCFITSIO Error: %s
+psFits_IMAGE_DIM_UNKNOWN               Could not determine image dimensions.\nCFITSIO Error: %s
+psFits_IMAGE_DIMENSION_UNSUPPORTED     Image number of dimensions, %d, is not valid.  Only two or three dimensions supported for FITS I/O.
+psFits_IMAGE_SIZE_UNKNOWN              Could not determine image size.\nCFITSIO Error: %s
+psFits_FITS_TYPE_UNSUPPORTED           FITS image type, BITPIX=%d, is not supported.
+psFits_READ_FAILED                     Reading FITS file failed.\nCFITSIO Error: %s
+psFits_IMAGE_UPDATE_TYPE_MISMATCH      Can not update a %s image given a %s image.
+psFits_FITS_Z_SMALL                    Current FITS HDU has %d z-planes, but z-plane %d was specified.
+#
+psDB_INVALID_PSDB                      Invalid psDB has been specified.
+psDB_NULL_TABLE                        NULL table specified.
+psDB_FAILED_TO_CONNECT                 Failed to connect to database.  Error: %s
+psDB_FAILED_TO_CHANGE                  Failed to change database.  Error: %s
+psDB_TABLE_PARAM_NULL                  Create table parameters may not be NULL.
+psDB_QUERY_GEN_FAIL                    Query generation failed.
+psDB_TABLE_CREATE_FAIL                 Failed to create table.
+psDB_SQL_PREPARE_FAIL                  Failed to prepare query.  Error: %s
+psDB_SQL_QUERY_FAIL                    Failed to execute SQL query.  Error: %s
+psDB_TABLE_DROP_FAIL                   Failed to drop table.
+psDB_SEL_COL_FAIL                      Failed to select column.
+psDB_QUERY_NO_DATA                     Query returned no data.  Error: %s
+psDB_INSERT_ROW_FAIL                   Failed to insert row.
+psDB_UPDATE_ROW_FAIL                   Update row SQL generate fail: values and where params may not be NULL.
+psDB_SQL_SUBSTR_FAIL                   SQL substring generation failed.
+psDB_WHERE_SUBSTR_FAIL                 WHERE parameter my not be NULL.
+#
+psVectorFFT_TYPE_NOT_F32_C32           Input psVector type, %s, is not supported. Valid data types are psF32 and psC32.
+psVectorFFT_REVERSE_NOT_COMPLEX        Input psVector (%s) is not complex.  Reverse FFT operation requires a complex input.
+psVectorFFT_FORWARD_NOT_REAL           Input psVector (%s) is not real.  Forward FFT operation requires a real input.
+psVectorFFT_FFTW_PLAN_NULL             Could not create a valid FFT plan to perform the transform.
+psVectorFFT_TYPE_UNSUPPORTED           Specified psVector type, %s, is not supported.
+psVectorFFT_REAL_IMAG_TYPE_MISMATCH    Real psVector type, %s, and imaginary psVector type, %s, must be the same.
+psVectorFFT_REAL_IMAG_SIZE_MISMATCH    Real psVector size, %d, and imaginary psVector size, %d, must be the same.
+psVectorFFT_NONREAL_NOTSUPPORTED       Input psVector type, %s, is required to be either psF32 or psF64.
+psVectorFFT_NONCOMPLEX_NOTSUPPORTED    Input psVector type, %s, is required to be either psC32 or psC64.
+psVectorFFT_DIRECTION_NOTSET           Must specify the direction as either PS_FFT_FORWARD or PS_FFT_REVERSE.
+#
+psStats_NOT_F32_F64                    Invalid data type, %s.  Only psF32 and psF64 data types are supported.
+psStats_VECTOR_TYPE_UNSUPPORTED        Input psVector type, %s, is not supported.
+psStats_YVAL_OUT_OF_RANGE              Specified yVal, %g, is not within y-range, %g to %g.
+psStats_ROBUST_QUARTILE_BINS_FAILED    Could not determine the robust lower/upper quartile bin numbers.
+psStats_STATS_FAILED                   Failed to calculate the specified statistic.
+psStats_STATS_SAMPLE_MEDIAN_SORT_PROBLEM            Failed to sort input data.
+psStats_STATS_VECTOR_BIN_DISECT_PROBLEM		Failed to determine the bin number of a data element.
+psStats_STATS_FIT_QUADRATIC_POLYNOMIAL_1D_FIT Failed to fit a 1-dimensional polynomial to the three specified data points.  Returning NAN.
+psStats_STATS_FIT_QUADRATIC_POLY_MEDIAN Failed to determine the median of the fitted polynomial.  Returning NAN.
+psStats_ROBUST_STATS_CLIPPED_STATS	Failed to determine clipped statistics.
+psStats_STATS_POLY_MEDIAN_OUT_OF_RANGE The requested y-value does not fall with the specified range of x-values.  Returning NAN.
+#
+psFunctions_INVALID_POLYNOMIAL_TYPE    Unknown polynomial type 0x%x found.  Evaluation failed.
+psFunctions_TYPE_NOT_SUPPORTED         Input psVector type, %s, is not supported.
+psFunctions_NOT_ENOUGH_DATAPOINTS      Given vector does not have enough data points for %d-order interpolation.
+#
+psRandom_UNKNOWN_RANDFOM_NUMBER_GENERATOR_TYPE Unknown Random Number Generator Type
+psRandom_NULL_RANDOM_VAR               Random variable is NULL.
+#
+psMatrix_COUNT_DIFFERS                 Number of elements inconsistent, %d vs %d.  Number of elements must match.
+psMatrix_IMAGE_SIZE_DIFFERS            Specified psImage dimensions differed, %dx%d vs %dx%d.
+psMatrix_TYPE_MISMATCH                 Specified data type, %s, is not supported.
+psMatrix_MIN_COMPLEX_SUPPORT           The minimum operation is not supported with complex data.
+psMatrix_MAX_COMPLEX_SUPPORT           The maximum operation is not supported with complex data.
+psMatrix_OPERATION_UNSUPPORTED         Specified operation, %s, is not supported.
+psMatrix_DIMEN_OTHER_FOUND             %s's dimensionality is PS_DIMEN_OTHER, which is  not allowed.
+psMatrix_OUTPUT_VECTOR_NOT_CREATED     Couldn't create a proper output psVector.
+psMatrix_OUTPUT_IMAGE_NOT_CREATED      Couldn't create a proper output psImage.
+psMatrix_DIMEN_INVALID                 Specified parameter, %s, has invalid dimensionality, %d.
+psMatrix_VECTOR_EMPTY                  Input psVector contains no elements.  No data to perform operation with.
+psMatrix_IMAGE_EMPTY                   Input psImage contains no pixels.  No data to perform operation with.
+psMatrix_TRANSPOSE_MISMATCH            Number of rows do not match number of columns.
+#
+psImage_AREA_NEGATIVE                  Specified number of rows (%d) or columns (%d) is invalid.
+psImage_NOT_AN_IMAGE                   The input psImage must have a PS_DIMEN_IMAGE dimension type.
+psImage_IMAGE_NULL                     Can not operate on a NULL psImage.
+psImage_IMAGE_TYPE_UNSUPPORTED         Specified psImage type, %s, is not supported.
+psImage_INTERPOLATE_METHOD_INVALID     Specified interpolation method (%d) is not supported.
+psImage_REGION_NULL                    Specified psRegion is NULL.  Operation could not be performed.
+psImage_SUBSET_RANGE_INVALID           Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d].
+psImage_SUBSET_RANGE_MALFORMED         Specified subset range, [%d:%d,%d:%d], is invalid.  Ranges must be incremental.
+psImage_SUBSECTION_NULL                Specified subsection string can not be NULL.
+psImage_SUBSECTION_INVALID             Specified subsection string, '%s', can not be parsed.  Must be in the form '[x1:x2,y1:y2]'.
+psImage_NOT_PARENT                     Specified psImage can not be a child of another psImage.
+psImage_INPLACE_NOTSUPPORTED           Specified input and output psImage can not reference the same psImage.
+psImage_SUBSET_ZERO_SIZE               Specified subset, [%d:%d,%d:%d], contains no pixel data.
+psImage_IMAGE_MASK_SIZE                Input psImage mask size, %dx%d, does not match psImage input size, %dx%d.
+psImage_IMAGE_MASK_TYPE                Input psImage mask type, %s, is not the supported mask datatype of %s.
+psImage_BAD_STAT                       Specified statistic option, %d, is not valid.  Must specify one and only one statistic type.
+psImage_NO_STAT_OPTIONS                Specified statistic option did not indicate any operation to perform.
+psImage_STAT_NULL                      Specified statistic can not be NULL.
+psImage_SLICE_DIRECTION_INVALID        Specified slice direction, %d, is invalid.
+psImage_PARAMETER_OUTOF_TYPERANGE      Specified %s value, %g, is outside of psImage type's range (%s: %g to %g).
+psImage_nSamples_TOOSMALL              Specified number of samples, %d, must be greater than 1 to make a line.
+psImage_LINE_NOT_IN_IMAGE              Specified line, (%f,%f)->(%f,%f), does not entirely lie in psImage's boundaries, [0:%d,0:%d].
+psImage_RADII_VECTOR_NULL              Specified radii vector can not be NULL.
+psImage_CENTER_NOT_IN_IMAGE            Specified center, (%g,%g), is outside of the psImage boundaries, [0:%d,0:%d].
+psImage_RADII_VECTOR_TOOSMALL          Input radii vector size, %d, can not be less than 2.
+#
+psImageFFT_IMAGE_TYPE_UNSUPPORTED      Input psImage type (%s) is not supported. Valid image types are psF32 and psC32.
+psImageFFT_REVERSE_NOT_COMPLEX         Input psImage (%s) is not complex.  Reverse FFT operation requires a complex psImage input.
+psImageFFT_FORWARD_NOT_REAL            Input psImage (%s) is not real.  Forward FFT operation requires a real psImage input.
+psImageFFT_FFTW_PLAN_NULL              Could not create a valid FFT plan to perform the transform.
+psImageFFT_REAL_IMAG_TYPE_MISMATCH     Real psImage type (%s) and imaginary psImage type (%s) must be the same.
+psImageFFT_REAL_IMAG_SIZE_MISMATCH     Real psImage size (%dx%d) and imaginary psImage size (%dx%d) must be the same.
+psImageFFT_NONREAL_NOTSUPPORTED        Input psImage type, %s, is required to be either psF32 or psF64.
+psImageFFT_NONCOMPLEX_NOTSUPPORTED     Input psImage type, %s, is required to be either psC32 or psC64.
+psImageFFT_REAL_FORWARD_NOTSUPPORTED   The PS_FFT_FORWARD and PS_FFT_REAL_RESULT combinition is not supported.
+psImageFFT_FORWARD_REVERSE             Can not specify both PS_FFT_FORWARD and PS_FFT_REVERSE options.
+psImageFFT_NO_DIRECTION_OPTION         Must specify either PS_FFT_FORWARD or PS_FFT_REVERSE option.
+#
+psImageIO_FILENAME_NULL                Specified filename can not be NULL.
+psImageIO_FILENAME_INVALID             Could not open file,'%s'.\nCFITSIO Error: %s
+psImageIO_EXTNAME_INVALID              Could not find HDU with extension name '%s' in file %s.\nCFITSIO Error: %s
+psImageIO_EXTNUM_INVALID               Could not find HDU #%d in file %s.\nCFITSIO Error: %s
+psImageIO_DATATYPE_UNKNOWN             Could not determine image data type for file %s.\nCFITSIO Error: %s
+psImageIO_IMAGE_DIM_UNKNOWN            Could not determine image dimensions for file %s.\nCFITSIO Error: %s
+psImageIO_IMAGE_SIZE_UNKNOWN           Could not determine image size for file %s.\nCFITSIO Error: %s
+psImageIO_IMAGE_DIMENSION_UNSUPPORTED  Image number of dimensions, %d, is not valid.  Only two or three dimensions supported for FITS I/O.
+psImageIO_FITS_TYPE_UNSUPPORTED        FITS image type, BITPIX=%d, in file %s is not supported.
+psImageIO_READ_FAILED                  Reading from FITS file %s failed.\nCFITSIO Error: %s
+psImageIO_TYPE_UNSUPPORTED             Input psImage type, %s, is not supported.
+psImageIO_WRITE_EXTNUM_INVALID         Specified extension number, %d, must not exceed number of HDUs, %d, by more than one.
+psImageIO_FILENAME_CREATE_FAILED       Could not create file,'%s'.\nCFITSIO Error: %s
+psImageIO_CREATE_EXTENSION_FAILED      Could not create EXTNAME keyword for file,'%s'.\nCFITSIO Error: %s
+psImageIO_CREATE_HDU_FAILED            Could not create HDU for writing psImage in file,'%s'.\nCFITSIO Error: %s
+psImageIO_WRITE_FAILED                 Could not write psImage data to file,'%s'.\nCFITSIO Error: %s
+#
+psImageManip_MAXMIN                    Specified min value, %g, can not be greater than the specified max value, %g.
+psImageManip_MAXMIN_REAL               Specified real-portion of min value, %g, can not be greater than the real-portion of max value, %g.
+psImageManip_MAXMIN_IMAG               Specified imaginary-portion of min value, %g, can not be greater than the imaginary-portion of max value, %g.
+psImageManip_OPERATION_NULL            Operation can not be NULL.
+psImageManip_OVERLAY_TYPE_MISMATCH     Input overlay psImage type, %s, must match input psImage type, %s.
+psImageManip_CLIP_VALUE_INVALID        Specified %s value, %g%+gi, is not the the range of input psImage's valid pixel values (%s), i.e. [%g:%g].
+psImageManip_OVERLAY_OPERATOR_INVALID  Specified operation, '%s', is not supported.
+psImageManip_SCALE_NOT_POSITIVE        Specified scale value, %d, must be a positive value.
+psImageManip_INTERPOLATION_MODE_UNSUPPORTED Specified interpolation mode, %d, is unsupported.
+psImageConvolve_SHIFT_NULL             Specified shift vectors can not be NULL.
+psImageConvolve_KERNEL_NULL            Specified psKernel can not be NULL.
+psImageConvolve_SHIFT_TYPE_MISMATCH    Input t-, x-, and y-shift vector types (%s/%s/%s) must match.
+psImageConvolve_FFT_FAILED             Failed to perform a fourier transform of input image.
+psImageConvolve_KERNEL_FFT_FAILED      Failed to perform a fourier transform of kernel.
+psImageConvolve_KERNEL_TOO_LARGE       Specified psKernel size, %dx%d, can not be larger than input psImage size, %dx%d.
+psImage_COEFF_NULL                     Polynomial coefficients cannot be NULL.
+psImageManip_TRANSFORM_NULL            Specified input transform can not be NULL.
+#
+psLogMsg_DESTINATION_MALFORMED         The specified destination, %s, is malformed.
+psLogMsg_DEST_LOCATION_INVALID         The location, %s, for protocol 'dest' is invalid.
+psLogMsg_OPEN_FILE_FAILED              Could not open file '%s' for output.
+psLogMsg_UNSUPPORTED_PROTOCOL          Do not know how to handle the protocol '%s'.
+psLogMsg_UNKNOWN_KEY                   Unknown logging keyword %c.
+#
+# Error Messages from psMemory.c:
+#
+psMemory_NULL_BLOCK                    NULL memory block found.
+psMemory_DEREF_BLOCK_USE               Memory block %lld was freed but still being used.
+psMemory_UNDERFLOW                     Memory block %lld is corrupted; buffer underflow detected.
+psMemory_OVERFLOW                      Memory block %lld is corrupted; buffer overflow detected.
+psMemory_MULTIPLE_FREE                 Block %lld, allocated at %s:%d, freed multiple times at %s:%d.
+#
+# Error Messages from psString.c:
+#
+psString_NCHAR_NEGATIVE                Can not copy a negative number of characters (%d).
+#
+# Error Messages from psTrace.c:
+#
+psTrace_NULL_SUBCOMPONENT              Sub-component %d of node %s in trace tree is NULL.
+psTrace_NULL_TRACETREE                 Function %s called on a NULL trace level tree.
+psTrace_ADD_NULL_COMPONENT             Failed to add null component to trace tree.
+psTrace_MALFORMED_COMPONENT_NAME       Failed to add '%s' to the root component tree; component must start with '.'.
+psTrace_FAILED_TO_ADD_COMPONENT        Failed to set trace level (%d) to '%s'.
+#
+# Error Messages from psErrorCodes.c
+#
+psErrorCode_NULL_ERRORDESCRIPTION      Specified psErrorDescription pointer can not be NULL.
+psErrorCode_ERRORCODE_REGISTER_FAILED  Failed to add input psErrorDescription at array index %d.
+#
+# Error Messages from psConfigure.c
+#
+psConfigure_INITIALIZATION_FAILED      Failed to initialize %s.
+psConfigure_FINALIZATION_FAILED        Failed to finalize %s.
+
Index: unk/psLib/src/psParseErrorCodes
===================================================================
--- /trunk/psLib/src/psParseErrorCodes	(revision 4539)
+++ 	(revision )
@@ -1,97 +1,0 @@
-#!/usr/bin/perl
-
-# Provides functions for handling long command line options
-use Getopt::Long;
-
-my @ErrorCodes        = ();
-my @ErrorDescriptions = ();
-
-my $data = "psErrorCodes.dat";
-
-# Assign variables based on the presence of command line options to the script
-GetOptions(
-    "data=s"  => \$data,
-    "verbose" => \$verbose,
-    "help"    => \$help
-);
-
-if ($help) {
-    print "Usage: parseErrorCodes ", "[--data=$data] ", "[--help] ",
-      "[--verbose] filename [filename ...]\n\n";
-    exit(0);
-}
-
-print "Using data file '$data'\n" if $verbose;
-unless ( open( DATAFILE, "<", $data ) ) {
-    die "Can not open data file $data.";
-}
-
-print "Datafile:\n" if $verbose;
-while (<DATAFILE>) {
-    chop;
-    if (/^\s*\#/) {
-        print "C $_\n" if $verbose;
-    }
-    else {
-        if (/^\s*(\w+)\s+([\%\w].*)/) {
-            my $ErrorCode        = $1;
-            my $ErrorDescription = $2;
-            print "  $ErrorCode: '$ErrorDescription'\n" if $verbose;
-            push( @ErrorCodes,        $ErrorCode );
-            push( @ErrorDescriptions, $ErrorDescription );
-        } else {
-            print "I $_\n" if $verbose;
-        }
-    }
-}
-close(DATAFILE);
-
-my $found = $#ErrorCodes + 1;
-print "\nFound $found error codes.\n" if $verbose;
-
-foreach (@ARGV) {
-    my $filename = $_;
-    my @result   = ();
-
-    die "Failed to open input file '$filename'"
-      if !open( INFILE, "<", $filename );
-
-    print "\nOutput File:\n" if $verbose;
-    while (<INFILE>) {
-        chop;
-        push( @result, $_ );
-        if (/^\s*\/\/~Start(.*)$/) {
-            $line = $1;
-            for ( $n = 0 ; $n < $found ; $n++ ) {
-                $_ = $line;
-                s/\$1/$ErrorCodes[$n]/g;
-                s/\$2/$ErrorDescriptions[$n]/g;
-                s/\$n/$n/g;
-                push( @result, $_ );
-                print "$_\n" if $verbose;
-            }
-
-            $break = 0;
-            while ( ( $break == 0 ) && ( $_ = <INFILE> ) ) {
-                if (/^\s*\/\/~End/) {
-                    $break = 1;
-                }
-            }
-            chop;
-            push( @result, $_ );
-        }
-    }
-
-    close(INFILE);
-
-    die "Failed to overwrite input file"
-      if !open( OUTFILE, ">", $filename );
-
-    foreach (@result) {
-        print OUTFILE "$_\n";
-        print "$_\n" if $verbose;
-    }
-
-    close(OUTFILE);
-
-}
Index: /trunk/psLib/src/pslib_strict.h
===================================================================
--- /trunk/psLib/src/pslib_strict.h	(revision 4539)
+++ /trunk/psLib/src/pslib_strict.h	(revision 4540)
@@ -9,6 +9,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-08 23:40:45 $
+*  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:00 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -26,159 +26,84 @@
 #endif // #else
 
-// // System Utilities
-
-/// @defgroup SysUtils System Utilities
+/// @defgroup astro Astrometry Functions
 /// @{
-
-/** @defgroup MemoryManagement Memory Management Utilities
- *
- *  This is the generic memory management system put inbetween the user's high level code and the OS-level
- *  memory allocation routines.  This system adds such features as callback routines for memory error events,
- *  tracing capabilities, and reference counting.
- *
- *  @ingroup SysUtils
- */
-
-#include "fitsio.h"
-
-#include "psMemory.h"
-
-/// @defgroup LogTrace Tracing and Logging
-/// @ingroup SysUtils
-#include "psLogMsg.h"
-#include "psTrace.h"
-
-/// @defgroup ErrorHandling Error Handling
-/// @ingroup SysUtils
-#include "psAbort.h"
-#include "psError.h"
-
-#include "psString.h"
-
-/// @defgroup Configure Configure psLib
-/// @ingroup SysUtils
-#include "psConfigure.h"
-
+#include "psTime.h"
+#include "psCoord.h"
 /// @}
 
-// Collections
-/// @defgroup DataContainer Data Containers
+/// @defgroup db Database Functions
 /// @{
+#include "psDB.h"
+/// @}
 
-#include "psType.h"
+/// @defgroup fft Fourier Functions
+/// @{
+#include "psVectorFFT.h"
+#include "psImageFFT.h"
+/// @}
 
-/// @defgroup LinkedList Linked List
-/// @ingroup DataContainer
-#include "psList.h"
+/// @defgroup fits FITS I/O Functions
+/// @{
+#include "psFits.h"
+/// @}
 
-/// @defgroup HashTable Hash Table
-/// @ingroup DataContainer
-#include "psHash.h"
+/// @defgroup imageops Image Operations
+/// @{
+#include "psImageConvolve.h"
+#include "psImageGeomManip.h"
+#include "psImagePixelExtract.h"
+#include "psImagePixelManip.h"
+#include "psImageStats.h"
+#include "psImageStructManip.h"
+/// @}
 
-/// @defgroup Scalar Scalar
-/// @ingroup DataContainer
-#include "psScalar.h"
+/// @defgroup math Math Functions
+/// @{
+#include "psBinaryOp.h"
+#include "psCompare.h"
+#include "psConstants.h"
+#include "psMatrix.h"
+#include "psMinimize.h"
+#include "psRandom.h"
+#include "psFunctions.h"
+#include "psStats.h"
+#include "psUnaryOp.h"
+/// @}
 
-/// @defgroup Vector Vector Container
-/// @ingroup DataContainer
-#include "psVector.h"
-
-/// @defgroup Array Array Container
-/// @ingroup DataContainer
-#include "psArray.h"
-
-/// @defgroup Image Image Container
-/// @ingroup DataContainer
+/// @defgroup mathtypes Mathematical Data Objects
 /// @{
 #include "psImage.h"
-#include "psImagePixelExtract.h"
-#include "psImageStructManip.h"
-#include "psImageGeomManip.h"
-#include "psImagePixelManip.h"
-#include "psImageConvolve.h"
-
-/// @defgroup ImageStats Image Statistical Functions
-/// @ingroup Image
-#include "psImageStats.h"
-
+#include "psScalar.h"
+#include "psVector.h"
 /// @}
 
-/// @defgroup BitSet Bit Set Container
-/// @ingroup DataContainer
-#include "psBitSet.h"
-
+/// @defgroup sys System-Level Functions
+/// @{
+#include "psAbort.h"
+#include "psConfigure.h"
+#include "psError.h"
+#include "psErrorCodes.h"
+#include "psLogMsg.h"
+#include "psMemory.h"
+#include "psString.h"
+#include "psTrace.h"
+#include "psType.h"
 /// @}
 
-// Data Manipulation
-/// @defgroup DataManip Data Manipulation
+/// @defgroup types Basic Data Types
 /// @{
-
-/// @defgroup Compare Comparison Functions
-/// @ingroup DataManip
-#include "psCompare.h"
-
-/// @defgroup Stats Statistic Functions
-/// @ingroup DataManip
-#include "psStats.h"
-
-/// @defgroup Matrix Matrix Operations
-/// @ingroup DataManip
-#include "psMatrix.h"
-
-/// @defgroup MatrixArithmetic Matrix Arithmetic Operations
-/// @ingroup DataManip
-#include "psBinaryOp.h"
-#include "psUnaryOp.h"
-
-#include "psRandom.h"
-
-/// @defgroup Transform Fourier Transform Operations
-/// @ingroup DataManip
-#include "psVectorFFT.h"
-#include "psImageFFT.h"
-
-#include "psFunctions.h"
-#include "psMinimize.h"
-
+#include "psArray.h"
+#include "psBitSet.h"
+#include "psHash.h"
+#include "psList.h"
+#include "psLookupTable.h"
+#include "psMetadata.h"
+#include "psMetadataConfig.h"
+#include "psPixels.h"
 /// @}
 
-// Astronomy
-/// @defgroup Astronomy Astronomy Functions
+/// @defgroup xml XML Functions
 /// @{
-
-/// @defgroup CoordinateTransform Coordinate Functions
-/// @ingroup Astronomy
-#include "psCoord.h"
-
-/// @defgroup Photometry Photometry
-/// @ingroup Astronomy
-#include "psPhotometry.h"
-
-/// @defgroup Time Time Functions
-/// @ingroup Astronomy
-#include "psTime.h"
-
-/// @defgroup Metadata Metadata Functions
-/// @ingroup Astronomy
-#include "psMetadata.h"
-#include "psMetadataIO.h"
-
-/// @defgroup AstroImage Astrometry Functions
-/// @ingroup Astronomy
-#include "psAstrometry.h"
-#include "psConstants.h"
-#include "psDB.h"
-
-/// @}
-
-// FileUtils
-/// @defgroup FileUtils File Utilities
-/// @{
-#include "psFits.h"
-
-/// @defgroup LookupTable Lookup Table
-/// @ingroup FileUtils
-#include "psLookupTable.h"
-
+#include "psXML.h"
 /// @}
 
Index: /trunk/psLib/src/sys/Makefile.am
===================================================================
--- /trunk/psLib/src/sys/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/sys/Makefile.am	(revision 4540)
@@ -1,45 +1,37 @@
-#Makefile for sysUtils functions of psLib
+#Makefile for sys functions of psLib
 #
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+noinst_LTLIBRARIES = libpslibsys.la
 
-noinst_LTLIBRARIES = libpslibsysUtils.la
+libpslibsys_la_SOURCES = \
+	psAbort.c \
+	psConfigure.c  \
+	psError.c      \
+	psErrorCodes.c \
+	psLogMsg.c     \
+	psMemory.c     \
+	psString.c     \
+	psTrace.c
 
-libpslibsysUtils_la_SOURCES = \
-	psMemory.c     \
-	psError.c      \
-	psTrace.c      \
-	psLogMsg.c     \
-	psAbort.c      \
-	psString.c     \
-	psConfigure.c  \
-	psErrorCodes.c
+EXTRA_DIST = sys.i
 
-BUILT_SOURCES = psSysUtilsErrors.h
-EXTRA_DIST = psSysUtilsErrors.dat psSysUtilsErrors.h sysUtils.i
+BUILT_SOURCES = psErrorCodes.c
 
-psSysUtilsErrors.h: psSysUtilsErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+psErrorCodes.c: ../psErrorCodes_$(LANG).dat psErrorCodes.c.in psErrorCodes.h
+	$(top_srcdir)/psParseErrorCodes --data=../psErrorCodes_$(LANG).dat $@
+
+psError.h: psErrorCodes.h
+
+psErrorCodes.h: ../psErrorCodes_$(LANG).dat psErrorCodes.h.in
+	$(top_srcdir)/psParseErrorCodes --data=../psErrorCodes_$(LANG).dat $@
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
-	psType.h       \
+	psAbort.h \
+	psConfigure.h  \
+	psError.h      \
+	psErrorCodes.h \
+	psLogMsg.h     \
 	psMemory.h     \
-	psError.h      \
+	psString.h     \
 	psTrace.h      \
-	psLogMsg.h     \
-	psAbort.h      \
-	psString.h     \
-	psConfigure.h  \
-	psErrorCodes.h
-
+	psType.h
Index: /trunk/psLib/src/sys/psConfigure.c
===================================================================
--- /trunk/psLib/src/sys/psConfigure.c	(revision 4539)
+++ /trunk/psLib/src/sys/psConfigure.c	(revision 4540)
@@ -13,6 +13,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-11 02:19:05 $
+ *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -22,5 +22,5 @@
 #include "psError.h"
 #include "psConfigure.h"
-#include "psSysUtilsErrors.h"
+#include "psErrorText.h"
 #include "config.h"
 
Index: /trunk/psLib/src/sys/psErrorCodes.c
===================================================================
--- /trunk/psLib/src/sys/psErrorCodes.c	(revision 4539)
+++ /trunk/psLib/src/sys/psErrorCodes.c	(revision 4540)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 02:02:05 $
+ *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -20,21 +20,9 @@
 #include "psMemory.h"
 
-#include "psSysUtilsErrors.h"
-
-/* N.B., lines between '//~Start' and '//~End' are automatic generated from
- * the template following the '//~Start'.  The template is used to generate
- * the other lines by, for each error class in psErrorCodes.dat, the following
- * substitutions are made:
- *     $1  The error code name (first word in the psErrorCodes.dat lines)
- *     $2  The error description (rest of the line in psErrorCodes.dat)
- *     $n  The order of the source line in psErrorCodes.dat (comments excluded)
- *
- * DO NOT EDIT THE LINES BETWEEN //~Start and //~End!  ANY CHANGES WILL BE OVERWRITTEN.
- */
+#include "psErrorText.h"
 
 static psErrorDescription staticErrorCodes[] = {
             {PS_ERR_NONE,"not an error"},
             {PS_ERR_BASE,"base error"},
-            //~Start    {PS_ERR_$1,"$2"},
             {PS_ERR_UNKNOWN,"unknown error"},
             {PS_ERR_IO,"I/O error"},
@@ -48,5 +36,4 @@
             {PS_ERR_UNEXPECTED_NULL,"unexpected NULL found"},
             {PS_ERR_OS_CALL_FAILED,"unexpected result from an OS standard library call"},
-            //~End
             {PS_ERR_N_ERR_CLASSES,"error classes end marker"}
         };
Index: unk/psLib/src/sys/psErrorCodes.h
===================================================================
--- /trunk/psLib/src/sys/psErrorCodes.h	(revision 4539)
+++ 	(revision )
@@ -1,111 +1,0 @@
-/** @file  psErrorCodes.h
- *
- *  @brief Contains the error codes for the error classes
- *
- *  @ingroup ErrorHandling
- *
- *  @author Robert DeSonia, MHPCC
- *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-08 23:40:45 $
- *
- *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
- */
-
-#ifndef PS_ERROR_CODES_H
-#define PS_ERROR_CODES_H
-
-#include "psType.h"
-
-/* N.B., lines between '//~Start' and '//~End' are automatic generated from
- * the template following the '//~Start'.  The template is used to generate
- * the other lines by, for each error class in psErrorCodes.dat, the following
- * substitutions are made:
- *     $1  The error code name (first word in the psErrorCodes.dat lines)
- *     $2  The error description (rest of the line in psErrorCodes.dat)
- *     $n  The order of the source line in psErrorCodes.dat (comments excluded)
- *
- * DO NOT EDIT THE LINES BETWEEN //~Start and //~End!  ANY CHANGES WILL BE OVERWRITTEN.
- */
-
-/** @addtogroup ErrorHandling
- *  @{
- */
-
-/** enumeration of the static error code classes
- */
-typedef enum {
-    PS_ERR_NONE = 0,                   ///< not an error
-    PS_ERR_BASE = 256,
-    /**< base error.  Any psErrorCode less than this should be taken to be
-     *   valid values of errno
-     */
-
-    //~Start     PS_ERR_$1,   ///< $2
-    PS_ERR_UNKNOWN,   ///< unknown error
-    PS_ERR_IO,   ///< I/O error
-    PS_ERR_LOCATION_INVALID,   ///< specified location is unknown
-    PS_ERR_MEMORY_CORRUPTION,   ///< memory corruption detected
-    PS_ERR_MEMORY_DEREF_USAGE,   ///< dereferenced memory still used
-    PS_ERR_BAD_PARAMETER_VALUE,   ///< parameter is out-of-range
-    PS_ERR_BAD_PARAMETER_TYPE,   ///< parameter is of unsupported type
-    PS_ERR_BAD_PARAMETER_NULL,   ///< parameter is null
-    PS_ERR_BAD_PARAMETER_SIZE,   ///< size of parameter's data is outside of acceptable range.
-    PS_ERR_UNEXPECTED_NULL,   ///< unexpected NULL found
-    PS_ERR_OS_CALL_FAILED,   ///< unexpected result from an OS standard library call
-    //~End
-    PS_ERR_N_ERR_CLASSES               ///< end marker - should not be used as a true error
-} psErrorCode;
-
-/** An error code with description
- */
-typedef struct
-{
-    psErrorCode code;                  ///< An error code
-    const char *description;           ///< the associated description
-}
-psErrorDescription;
-
-/** Allocates a new psErrorDescription
- *
- *  @return psErrorDescription*        new psErrorDescription struct.
- */
-psErrorDescription* psErrorDescriptionAlloc(
-    psErrorCode code,                  ///< An error code
-    const char *description            ///< the associated description
-);
-
-/** Retrieves the description of an error code.
- *
- *  The routine psErrorCodeString returns the string associated with an error
- *  code.
- *
- *  @return const char*     the description associated with the given code.
- */
-const char *psErrorCodeString(
-    psErrorCode code                   ///< the associated error code
-);
-
-/** Register an error code
- *
- *  Any project needed to use psLib must define the necessary error codes and
- *  associated message strings.  This function registers an array of error
- *  codes with the error handling subsystem.
- *
- */
-void psErrorRegister(
-    const psErrorDescription* errors,  ///< Array of error codes to register
-    psS32 nerror                         ///< number of errors in input array
-);
-
-/** Clears error codes registered via psErrorRegister.
- *
- *  @return psBool    TRUE if given errorcode was removed, otherwise FALSE.
- */
-psBool p_psErrorUnregister(
-    psErrorCode code                   ///< the error code to find and remove
-);
-
-/// @}
-
-#endif // #ifndef PS_ERROR_CODES_H
Index: /trunk/psLib/src/sys/psErrorCodes.h.in
===================================================================
--- /trunk/psLib/src/sys/psErrorCodes.h.in	(revision 4540)
+++ /trunk/psLib/src/sys/psErrorCodes.h.in	(revision 4540)
@@ -0,0 +1,87 @@
+/** @file  psErrorCodes.h
+ *
+ *  @brief Contains the error codes for the error classes
+ *
+ *  @ingroup ErrorHandling
+ *
+ *  @author Robert DeSonia, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#ifndef PS_ERROR_CODES_H
+#define PS_ERROR_CODES_H
+
+#include "psType.h"
+
+/** @addtogroup ErrorHandling
+ *  @{
+ */
+
+/** enumeration of the static error code classes
+ */
+typedef enum {
+    PS_ERR_NONE = 0,                   ///< not an error
+    PS_ERR_BASE = 256,
+    /**< base error.  Any psErrorCode less than this should be taken to be
+     *   valid values of errno
+     */
+    PS_ERR_${ErrorCode},
+    PS_ERR_N_ERR_CLASSES               ///< end marker - should not be used as a true error
+} psErrorCode;
+
+/** An error code with description
+ */
+typedef struct
+{
+    psErrorCode code;                  ///< An error code
+    const char *description;           ///< the associated description
+}
+psErrorDescription;
+
+/** Allocates a new psErrorDescription
+ *
+ *  @return psErrorDescription*        new psErrorDescription struct.
+ */
+psErrorDescription* psErrorDescriptionAlloc(
+    psErrorCode code,                  ///< An error code
+    const char *description            ///< the associated description
+);
+
+/** Retrieves the description of an error code.
+ *
+ *  The routine psErrorCodeString returns the string associated with an error
+ *  code.
+ *
+ *  @return const char*     the description associated with the given code.
+ */
+const char *psErrorCodeString(
+    psErrorCode code                   ///< the associated error code
+);
+
+/** Register an error code
+ *
+ *  Any project needed to use psLib must define the necessary error codes and
+ *  associated message strings.  This function registers an array of error
+ *  codes with the error handling subsystem.
+ *
+ */
+void psErrorRegister(
+    const psErrorDescription* errors,  ///< Array of error codes to register
+    psS32 nerror                         ///< number of errors in input array
+);
+
+/** Clears error codes registered via psErrorRegister.
+ *
+ *  @return psBool    TRUE if given errorcode was removed, otherwise FALSE.
+ */
+psBool p_psErrorUnregister(
+    psErrorCode code                   ///< the error code to find and remove
+);
+
+/// @}
+
+#endif // #ifndef PS_ERROR_CODES_H
Index: /trunk/psLib/src/sys/psLogMsg.c
===================================================================
--- /trunk/psLib/src/sys/psLogMsg.c	(revision 4539)
+++ /trunk/psLib/src/sys/psLogMsg.c	(revision 4540)
@@ -12,6 +12,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-23 03:50:29 $
+ *  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -42,5 +42,5 @@
 #include "psTrace.h"
 
-#include "psSysUtilsErrors.h"
+#include "psErrorText.h"
 
 #define MIN_LOG_LEVEL 0
Index: /trunk/psLib/src/sys/psMemory.c
===================================================================
--- /trunk/psLib/src/sys/psMemory.c	(revision 4539)
+++ /trunk/psLib/src/sys/psMemory.c	(revision 4540)
@@ -8,6 +8,6 @@
 *  @author Robert Lupton, Princeton University
 *
-*  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-27 20:38:12 $
+*  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -25,5 +25,5 @@
 #include "psLogMsg.h"
 
-#include "psSysUtilsErrors.h"
+#include "psErrorText.h"
 
 #define P_PS_MEMMAGIC (psPtr )0xdeadbeef   // Magic number in psMemBlock header
Index: /trunk/psLib/src/sys/psString.c
===================================================================
--- /trunk/psLib/src/sys/psString.c	(revision 4539)
+++ /trunk/psLib/src/sys/psString.c	(revision 4540)
@@ -12,6 +12,6 @@
  *  @author Eric Van Alst, MHPCC
  *
- *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-30 00:33:36 $
+ *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -25,5 +25,5 @@
 #include "psError.h"
 
-#include "psSysUtilsErrors.h"
+#include "psErrorText.h"
 
 psString psStringCopy(const char *string)
Index: /trunk/psLib/src/sys/psTrace.c
===================================================================
--- /trunk/psLib/src/sys/psTrace.c	(revision 4539)
+++ /trunk/psLib/src/sys/psTrace.c	(revision 4540)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -51,5 +51,5 @@
 #include "psLogMsg.h"
 
-#include "psSysUtilsErrors.h"
+#include "psErrorText.h"
 
 static p_psComponent* cRoot = NULL; // The root of the trace component
Index: /trunk/psLib/src/sys/psType.h
===================================================================
--- /trunk/psLib/src/sys/psType.h	(revision 4539)
+++ /trunk/psLib/src/sys/psType.h	(revision 4540)
@@ -10,6 +10,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-22 02:05:41 $
+*  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -94,4 +94,50 @@
 } psElemType;
 
+/** Enumeration primarily used with metadata which defines a data structure
+ *  e.g., list, array, FITS file, etc.
+*/
+typedef enum {
+    PS_DATA_S32  = PS_TYPE_S32,        ///< psS32
+    PS_DATA_F32  = PS_TYPE_F32,        ///< psF32
+    PS_DATA_F64  = PS_TYPE_F64,        ///< psF64
+    PS_DATA_BOOL = PS_TYPE_BOOL,       ///< psBool
+    PS_DATA_STRING = 0x10000,          ///< psString (char *)
+    PS_DATA_ARRAY,                     ///< psArray
+    PS_DATA_BITSET,                    ///< psBitSet
+    PS_DATA_CELL,                      ///< psCell
+    PS_DATA_CHIP,                      ///< psChip
+    PS_DATA_CUBE,                      ///< psCube
+    PS_DATA_FITS,                      ///< psFits
+    PS_DATA_HASH,                      ///< psHash
+    PS_DATA_HISTOGRAM,                 ///< psHistogram
+    PS_DATA_IMAGE,                     ///< psImage
+    PS_DATA_KERNEL,                    ///< psKernel
+    PS_DATA_LIST,                      ///< psList
+    PS_DATA_LOOKUPTABLE,               ///< psLookupTable
+    PS_DATA_METADATA,                  ///< psMetadata
+    PS_DATA_METADATAITEM,              ///< psMetadataItem
+    PS_DATA_MINIMIZATION,              ///< psMinimization
+    PS_DATA_PIXELS,                    ///< psPixels
+    PS_DATA_PLANE,                     ///< psPlane
+    PS_DATA_PLANEDISTORT,              ///< psPlaneDistort
+    PS_DATA_PLANETRANSFORM,            ///< psPlaneTransform
+    PS_DATA_POLYNOMIAL1D,              ///< psPolynomial1D
+    PS_DATA_POLYNOMIAL2D,              ///< psPolynomial2D
+    PS_DATA_POLYNOMIAL3D,              ///< psPolynomial3D
+    PS_DATA_POLYNOMIAL4D,              ///< psPolynomial4D
+    PS_DATA_PROJECTION,                ///< psProjection
+    PS_DATA_READOUT,                   ///< psReadout
+    PS_DATA_REGION,                    ///< psRegion
+    PS_DATA_SCALAR,                    ///< psScalar
+    PS_DATA_SPHERE,                    ///< psSphere
+    PS_DATA_SPHERETRANSFORM,           ///< psSphereTransform
+    PS_DATA_SPLINE1D,                  ///< psSpline1D
+    PS_DATA_STATS,                     ///< psStats
+    PS_DATA_TIME,                      ///< psTime
+    PS_DATA_VECTOR,                    ///< psVector
+    PS_DATA_UNKNOWN,                   ///< Other data of an unknown type
+    PS_DATA_METADATA_MULTI             ///< Used internally for metadata; not a 'real' type
+} psDataType;
+
 #define PS_TYPE_MASK PS_TYPE_U8        /**< the psElemType to use for mask image */
 #define PS_TYPE_MASK_DATA U8           /**< the data member to use for mask image */
@@ -232,8 +278,16 @@
 typedef struct
 {
-    psElemType type;            ///< Primitive type.
-    psDimen dimen;              ///< Dimensionality.
+    psElemType type;                   ///< Primitive type.
+    psDimen dimen;                     ///< Dimensionality.
 }
 psType;
+
+typedef struct
+{
+    psElemType type;                   ///< The type
+    psDimen dimen;                     ///< The dimensionality.
+    //    psElemType type;                   ///< The type
+}
+psMathType;
 
 /** The type of a basic data type
@@ -245,5 +299,5 @@
 typedef struct
 {
-    psType  type;              ///< Data type information
+    psMathType type;              ///< Data type information
 }
 psMath;
Index: /trunk/psLib/src/sys/sys.i
===================================================================
--- /trunk/psLib/src/sys/sys.i	(revision 4540)
+++ /trunk/psLib/src/sys/sys.i	(revision 4540)
@@ -0,0 +1,11 @@
+/* sys headers */
+
+%include "psAbort.h"
+%include "psConfigure.h"
+%include "psErrorCodes.h"
+%include "psError.h"
+%include "psLogMsg.h"
+%include "psMemory.h"
+%include "psString.h"
+%include "psTrace.h"
+%include "psType.h"
Index: /trunk/psLib/src/types/Makefile.am
===================================================================
--- /trunk/psLib/src/types/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/types/Makefile.am	(revision 4540)
@@ -1,49 +1,26 @@
-#Makefile for collections functions of psLib
+#Makefile for types functions of psLib
 #
+noinst_LTLIBRARIES = libpslibtypes.la
 
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+libpslibtypes_la_SOURCES = \
+	psArray.c \
+	psBitSet.c \
+	psHash.c \
+	psList.c \
+	psLookupTable.c \
+	psMetadata.c \
+	psMetadataConfig.c \
+	psPixels.c
 
-noinst_LTLIBRARIES = libpslibcollections.la
-
-libpslibcollections_la_SOURCES = \
-	psBitSet.c \
-	psVector.c \
-	psPixels.c \
-	psList.c \
-	psScalar.c \
-	psCompare.c \
-	psArray.c \
-	psHash.c \
-	psMetadata.c \
-	psMetadataIO.c
-
-BUILT_SOURCES = psCollectionsErrors.h
-EXTRA_DIST = psCollectionsErrors.dat psCollectionsErrors.h collections.i
-
-psCollectionsErrors.h:psCollectionsErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = types.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
+	psArray.h \
 	psBitSet.h \
-	psVector.h \
-	psPixels.h \
+	psHash.h \
 	psList.h \
-	psScalar.h \
-	psCompare.h \
-	psArray.h \
-	psHash.h \
+	psLookupTable.h \
 	psMetadata.h \
-	psMetadataIO.h
-
+	psMetadataConfig.h \
+	psPixels.h
Index: /trunk/psLib/src/types/psArray.c
===================================================================
--- /trunk/psLib/src/types/psArray.c	(revision 4539)
+++ /trunk/psLib/src/types/psArray.c	(revision 4540)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 02:02:04 $
+ *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -28,5 +28,5 @@
 #include "psLogMsg.h"
 
-#include "psCollectionsErrors.h"
+#include "psErrorText.h"
 
 /*****************************************************************************
Index: /trunk/psLib/src/types/psBitSet.c
===================================================================
--- /trunk/psLib/src/types/psBitSet.c	(revision 4539)
+++ /trunk/psLib/src/types/psBitSet.c	(revision 4540)
@@ -11,6 +11,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 02:02:05 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -28,5 +28,5 @@
 #include "psString.h"
 
-#include "psCollectionsErrors.h"
+#include "psErrorText.h"
 
 enum {
Index: /trunk/psLib/src/types/psHash.c
===================================================================
--- /trunk/psLib/src/types/psHash.c	(revision 4539)
+++ /trunk/psLib/src/types/psHash.c	(revision 4540)
@@ -12,6 +12,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-25 02:02:05 $
+*  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -27,5 +27,5 @@
 #include "psConstants.h"
 
-#include "psCollectionsErrors.h"
+#include "psErrorText.h"
 
 static psHashBucket* hashBucketAlloc(const char *key, psPtr data, psHashBucket* next);
Index: /trunk/psLib/src/types/psList.c
===================================================================
--- /trunk/psLib/src/types/psList.c	(revision 4539)
+++ /trunk/psLib/src/types/psList.c	(revision 4540)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-25 02:02:05 $
+ *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -23,5 +23,5 @@
 #include "psLogMsg.h"
 
-#include "psCollectionsErrors.h"
+#include "psErrorText.h"
 
 #define ITER_INIT_HEAD ((psPtr )1)         // next iteration should return head
Index: /trunk/psLib/src/types/psLookupTable.c
===================================================================
--- /trunk/psLib/src/types/psLookupTable.c	(revision 4539)
+++ /trunk/psLib/src/types/psLookupTable.c	(revision 4540)
@@ -7,6 +7,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-25 02:02:05 $
+*  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
@@ -25,5 +25,5 @@
 #include "psError.h"
 #include "psLookupTable.h"
-#include "psFileUtilsErrors.h"
+#include "psErrorText.h"
 #include "psConstants.h"
 
Index: /trunk/psLib/src/types/psMetadata.c
===================================================================
--- /trunk/psLib/src/types/psMetadata.c	(revision 4539)
+++ /trunk/psLib/src/types/psMetadata.c	(revision 4540)
@@ -12,6 +12,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-27 20:38:12 $
+*  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -36,5 +36,5 @@
 #include "psLookupTable.h"
 #include "psString.h"
-#include "psAstronomyErrors.h"
+#include "psErrorText.h"
 #include "psConstants.h"
 #include "psLogMsg.h"
Index: /trunk/psLib/src/types/psMetadataConfig.c
===================================================================
--- /trunk/psLib/src/types/psMetadataConfig.c	(revision 4539)
+++ /trunk/psLib/src/types/psMetadataConfig.c	(revision 4540)
@@ -1,3 +1,3 @@
-/** @file  psMetadataIO.c
+/** @file  psMetadataConfig.c
 *
 *  @brief Contains metadata input/output functions.
@@ -10,11 +10,10 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-30 00:04:12 $
+*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 */
 
-#include <libxml/parser.h>
 #include <fitsio.h>
 #include <string.h>
@@ -31,11 +30,7 @@
 #include "psVector.h"
 #include "psMetadata.h"
-#include "psMetadataIO.h"
+#include "psMetadataConfig.h"
 #include "psConstants.h"
-#include "psAstronomyErrors.h"
-
-/******************************************************************************/
-/*  DEFINE STATEMENTS                                                         */
-/******************************************************************************/
+#include "psErrorText.h"
 
 /** Check for FITS errors */
@@ -59,39 +54,19 @@
 #define MAX_STRING_LENGTH 256
 
-
-/******************************************************************************/
-/*  TYPE DEFINITIONS                                                          */
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  GLOBAL VARIABLES                                                         */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FILE STATIC VARIABLES                                                    */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
-/*****************************************************************************/
-
-static void saxEndElement(void *ctx, const xmlChar *tagName);
-static void initVectorXml(void *ctx, char *tagName);
-static void initMetadataItemXml(void *ctx, char *tagName);
-static void saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts);
 static psMetadata* getMetadataType(char *linePtr);
+
 static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)
 ;
+
 static void parseLevelInfoFree(p_psParseLevelInfo* info);
+
 static psBool parseLine(psS32* level,   psArray* levelArray,
-                        char*  linePtr, psS32 lineCount,     char* fileName, psBool overwrite);
-static psBool parseMetadataItem(char* keyName, psS32* level,     psArray* levelArray,
-                                char* linePtr, psS32  lineCount, char*    fileName,    psMetadataFlags flags);
+                        char*  linePtr, psS32 lineCount, char* fileName,
+                        psBool overwrite);
+
+static psBool parseMetadataItem(char* keyName, psS32* level,
+                                psArray* levelArray, char* linePtr,
+                                psS32 lineCount, char* fileName,
+                                psMetadataFlags flags);
 
 static void parseLevelInfoFree(p_psParseLevelInfo* info)
@@ -106,5 +81,5 @@
 // Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string
 // must be null terminated.
-psBool ignoreLine(char *inString)
+static psBool ignoreLine(char *inString)
 {
     while(*inString!='\0' && *inString!='#') {
@@ -121,5 +96,5 @@
 //  Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
 //  terminated copy of the original input string.
-char *cleanString(char *inString, psS32 sLen, psBool ignoreComment)
+static char *cleanString(char *inString, psS32 sLen, psBool ignoreComment)
 {
     char *ptrB = NULL;
@@ -167,5 +142,5 @@
 
 // Count repeat occurances of a single character within a line. The input string must be null terminated.
-psS32 repeatedChars(char *inString, char ch)
+static psS32 repeatedChars(char *inString, char ch)
 {
     psS32 count = 0;
@@ -183,5 +158,5 @@
 // Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location
 // the beginning of the string. Tokens are newly allocated null terminated strings.
-char* getToken(char **inString, char *delimiter, psS32 *status, psBool ignoreComment)
+static char* getToken(char **inString, char *delimiter, psS32 *status, psBool ignoreComment)
 {
     char *cleanToken = NULL;
@@ -217,5 +192,5 @@
 // Returns single parsed value as a double precision number. The input string must be cleaned and null
 // terminated.
-double parseValue(char *inString, psS32 *status)
+static double parseValue(char *inString, psS32 *status)
 {
     char *end = NULL;
@@ -233,5 +208,5 @@
 
 /** Returns true or false. 'T', 't', '1', 'F', 'f', and '0' are acceptable, parsable variations. */
-psBool parseBool(char *inString, psS32 *status)
+static psBool parseBool(char *inString, psS32 *status)
 {
     psBool value = false;
@@ -250,5 +225,5 @@
 
 /** Returns parsed vector filled with with data. The input string must be null terminated. */
-psVector* parseVector(char *inString, psElemType elemType, psS32 *status)
+static psVector* parseVector(char *inString, psElemType elemType, psS32 *status)
 {
     char*      end       = NULL;
@@ -1138,443 +1113,2 @@
 }
 
-
-static void saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts)
-{
-    psU64 i = 0;
-    char* psTagName = NULL;
-    char *psAttName = NULL;
-    char *psAttValue = NULL;
-    const xmlChar *attName = NULL;
-    const xmlChar *attValue = NULL;
-    psMetadata* md = NULL;
-    psHash* htAtts = NULL;
-    xmlParserCtxtPtr ctxt = NULL;
-    xmlParserInputPtr input = NULL;
-
-
-    // Get and check initial data pointers
-    ctxt = (xmlParserCtxtPtr)ctx;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
-    md = (psMetadata*)ctxt->sax->_private;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
-    input = (xmlParserInputPtr)ctxt->input;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
-
-    // Copy XML strings to psStrings to avoid libxml2/psLib memory corruption problems
-    psTagName = psStringCopy((const char*)tagName);
-
-    // Metadata containter for housing element attributes used by other SAX events
-    htAtts = psHashAlloc(10);
-
-
-    // Get tag name
-    if(psTagName != NULL) {
-        psHashAdd(htAtts, "tagName", psTagName);
-    } else {
-        PS_ASSERT_GENERAL_PTR_NON_NULL(psTagName, return);
-        psFree(htAtts);
-        psFree(psTagName);
-        return;
-    }
-
-    // Get all attribute names and attribute values
-    if(atts != NULL) {
-        attName = atts[i++];
-        attValue = atts[i++];
-        while(attName != NULL) {
-            if(attValue != NULL) {
-
-                // Copy XML strings to psStrings to avoid libxml2/psLib memory corruption problems
-                psAttName = psStringCopy((const char*)attName);
-                psAttValue = psStringCopy((const char*)attValue);
-                psHashAdd(htAtts, psAttName, psAttValue);
-                psFree(psAttName);
-                psFree(psAttValue);
-            } else {
-                PS_ASSERT_GENERAL_PTR_NON_NULL(psAttValue, return);
-                psFree(htAtts);
-                psFree(psTagName);
-                return;
-            }
-            attName = atts[i++];
-            attValue = atts[i++];
-        }
-    }
-
-    // Add attributes to metadata
-
-    psMetadataAdd(md, PS_LIST_TAIL, "htAtts",
-                  PS_META_HASH | PS_META_DUPLICATE_OK,
-                  NULL, htAtts);
-
-    psFree(psTagName);
-    psFree(htAtts);
-
-    return;
-}
-
-static void initMetadataItemXml(void *ctx, char *tagName)
-{
-    psBool overwrite = false;
-    psBool tempBool = false;
-    psS32 status = 0;
-    psU32 lineNumber = 0;
-    psF64 tempDbl = 0.0;
-    psS32 tempInt = 0.0;
-    psMetadataType mdType = PS_META_UNKNOWN;
-    char *fileName = NULL;
-    char *strName = NULL;
-    char *strType = NULL;
-    char *strValue = NULL;
-    psMetadata* md = NULL;
-    psHash* htAtts = NULL;
-    psMetadataItem *metadataItem = NULL;
-    xmlParserCtxtPtr ctxt = NULL;
-    xmlParserInputPtr input = NULL;
-
-
-    // Get and check initial data pointers
-    ctxt = (xmlParserCtxtPtr)ctx;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
-    md = (psMetadata*)ctxt->sax->_private;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
-    input = (xmlParserInputPtr)ctxt->input;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
-    metadataItem = psMetadataLookup(md, "htAtts");
-    PS_ASSERT_GENERAL_PTR_NON_NULL(metadataItem, return);
-    PS_ASSERT_GENERAL_PTR_NON_NULL(metadataItem->data.list, return);
-    metadataItem = (psMetadataItem*)psListGet(metadataItem->data.list,PS_LIST_TAIL);
-    htAtts = (psHash*)metadataItem->data.list;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(htAtts, return);
-    fileName = (char*)input->filename;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(fileName, return);
-    lineNumber = input->line;
-
-    // Get attribute name
-    strName = psHashLookup(htAtts, "name");
-    if(strName == NULL) {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_NO_NAME, lineNumber, fileName);
-        return;
-    }
-
-    // Get attribute type, if there is one
-    strType = psHashLookup(htAtts, "psType");
-    if(strType!= NULL) {
-        if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psString")) {
-            mdType = PS_META_STR;
-        } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psBool")) {
-            mdType = PS_META_BOOL;
-        } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psS32")) {
-            mdType = PS_META_S32;
-        } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF32")) {
-            mdType = PS_META_F32;
-        } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF64")) {
-            mdType = PS_META_F64;
-        } else {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TYPE_INVALID_LINE_FILE, strType, lineNumber,
-                    fileName);
-            return;
-        }
-    }
-
-    // Get attribute value, if there is one
-    strValue = psHashLookup(htAtts, "value");
-
-    /* If metadata item is found, and is not a folder node, and overwrite is allowed, then remove
-    existing and allow switch/case below to add new item. If overwrite is false, then report error. If
-    found item is folder node, then psMetadataAdd will automatically add a new child. */
-    metadataItem = psMetadataLookup(md, "overwrite");
-    if(metadataItem != NULL) {
-        overwrite = parseBool((char*)strValue, &status);
-        if(status) {
-            status = 0;
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
-                    lineNumber, fileName);
-        }
-        metadataItem = psMetadataLookup(md, strName);
-        if(metadataItem != NULL) {
-            if(metadataItem->type != PS_META_LIST) {
-                if(overwrite) {
-                    psMetadataRemove(md, INT_MIN, strName);
-                } else {
-                    psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM, strName, lineNumber,
-                            fileName);
-                    return;
-                }
-            }
-        }
-    }
-
-    // Create metadata item and add to metadata
-    switch(mdType) {
-    case PS_META_LIST:
-        psMetadataAdd(md, PS_LIST_TAIL, strName,
-                      mdType | PS_META_DUPLICATE_OK,
-                      NULL, NULL);
-        break;
-    case PS_META_STR:
-        psMetadataAdd(md, PS_LIST_TAIL, strName,
-                      mdType | PS_META_DUPLICATE_OK,
-                      NULL, strValue);
-        break;
-    case PS_META_BOOL:
-        tempBool = parseBool((char*)strValue, &status);
-        if(!status) {
-            psMetadataAdd(md, PS_LIST_TAIL, strName,
-                          mdType | PS_META_DUPLICATE_OK,
-                          NULL, tempBool);
-        } else {
-            status = 0;
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
-                    lineNumber, fileName);
-        }
-        break;
-    case PS_META_S32:
-        tempInt = (psS32)parseValue((char*)strValue, &status);
-        if(!status) {
-            psMetadataAdd(md, PS_LIST_TAIL, strName,
-                          mdType | PS_META_DUPLICATE_OK,
-                          NULL, tempInt);
-        } else {
-            status = 0;
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
-                    lineNumber, fileName);
-        }
-        break;
-    case PS_META_F32:
-    case PS_META_F64:
-        tempDbl = parseValue((char*)strValue, &status);
-        if(!status) {
-            psMetadataAdd(md, PS_LIST_TAIL, strName,
-                          mdType | PS_META_DUPLICATE_OK,
-                          NULL, tempDbl);
-        } else {
-            status = 0;
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
-                    lineNumber, fileName);
-        }
-        break;
-    default:
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID, strType, lineNumber, fileName);
-    } // End switch
-
-    return;
-}
-
-
-static void initVectorXml(void *ctx, char *tagName)
-{
-    bool overwrite = false;
-    psS32 status = 0;
-    psU32 lineNumber = 0;
-    psElemType pType = 0;
-    char *strName = NULL;
-    char *strType = NULL;
-    char *strValue = NULL;
-    char *fileName = NULL;
-    psMetadataItem *table = NULL;
-    psMetadataItem *tables = NULL;
-    psMetadataItem *metadataItem = NULL;
-    psVector *vec = NULL;
-    psMetadata* md = NULL;
-    psHash* htAtts = NULL;
-    xmlParserCtxtPtr ctxt = NULL;
-    xmlParserInputPtr input = NULL;
-
-
-    // Get and check initial data pointers
-    ctxt = (xmlParserCtxtPtr)ctx;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
-    md = (psMetadata*)ctxt->sax->_private;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
-    input = (xmlParserInputPtr)ctxt->input;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
-    tables = psMetadataLookup(md, "htAtts");
-    PS_ASSERT_GENERAL_PTR_NON_NULL(tables, return);
-    PS_ASSERT_GENERAL_PTR_NON_NULL(tables->data.list, return);
-    table = (psMetadataItem*)psListGet(tables->data.list,PS_LIST_TAIL);
-    htAtts = (psHash*)table->data.list;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(htAtts, return);
-    fileName = (char*)input->filename;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(fileName, return);
-    lineNumber = input->line;
-
-    // Get attribute name
-    strName = psHashLookup(htAtts, "name");
-    if(strName == NULL) {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_NO_NAME, lineNumber, fileName);
-        return;
-    }
-
-    // Get attribute type, if there is one
-    strType = psHashLookup(htAtts, "psType");
-    if(strType!= NULL) {
-        if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psBool")) {
-            pType = PS_TYPE_U8;
-        } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psS32")) {
-            pType = PS_TYPE_S32;
-        } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF32")) {
-            pType = PS_TYPE_F32;
-        } else if(xmlStrEqual(BAD_CAST strType, BAD_CAST "psF64")) {
-            pType = PS_TYPE_F64;
-        } else {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TYPE_INVALID_LINE_FILE, strName, lineNumber,
-                    fileName);
-            return;
-        }
-    }
-
-    strValue = psHashLookup(htAtts, "value");
-    PS_ASSERT_GENERAL_PTR_NON_NULL(strValue, return);
-
-
-    /* If metadata item is found, and is not a folder node, and overwrite is allowed, then remove
-    existing and allow switch/case below to add new item. If overwrite is false, then report error. If
-    found item is folder node, then psMetadataAdd will automatically add a new child. */
-    metadataItem = psMetadataLookup(md, "overwrite");
-    if(metadataItem != NULL) {
-        overwrite = parseBool((char*)strValue, &status);
-        if(status) {
-            status = 0;
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
-                    input->line, input->filename);
-        }
-        metadataItem = psMetadataLookup(md, strName);
-        if(metadataItem != NULL) {
-            if(metadataItem->type != PS_META_LIST) {
-                if(overwrite) {
-                    psMetadataRemove(md, INT_MIN, strName);
-                } else {
-                    psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM, strName, lineNumber,
-                            fileName);
-                    return;
-                }
-            }
-        }
-    }
-
-    // Get value
-    vec = parseVector((char*)strValue, pType, &status);
-    if(!status) {
-        psMetadataAdd(md, PS_LIST_TAIL, strName+1,
-                      PS_META_VEC | PS_META_DUPLICATE_OK,
-                      NULL, vec);
-    } else {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, strName, strType,
-                lineNumber, fileName);
-    }
-    psFree(vec);
-}
-
-static void saxEndElement(void *ctx, const xmlChar *tagName)
-{
-    char *psStartTagName = NULL;
-    char *psEndTagName = NULL;
-    psMetadata* md = NULL;
-    psHash* htAtts = NULL;
-    psMetadataItem *table = NULL;
-    psMetadataItem *tables = NULL;
-    xmlParserCtxtPtr ctxt = NULL;
-    xmlParserInputPtr input = NULL;
-
-
-    // Get and check initial data pointers
-    ctxt = (xmlParserCtxtPtr)ctx;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(ctxt, return);
-    md = (psMetadata*)ctxt->sax->_private;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(md, return);
-    input = (xmlParserInputPtr)ctxt->input;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(input, return);
-    tables = psMetadataLookup(md, "htAtts");
-    PS_ASSERT_GENERAL_PTR_NON_NULL(tables, return);
-    PS_ASSERT_GENERAL_PTR_NON_NULL(tables->data.list, return);
-    table = (psMetadataItem*)psListGet(tables->data.list,PS_LIST_TAIL);
-    htAtts = (psHash*)table->data.list;
-    PS_ASSERT_GENERAL_PTR_NON_NULL(htAtts, return);
-
-    // Copy XML strings to psStrings to avoid libxml2/psLib memory corruption problems
-    psEndTagName = psStringCopy((const char*)tagName);
-
-    // Compare start and end tag names
-    psStartTagName = psHashLookup(htAtts, "tagName");
-    PS_ASSERT_GENERAL_PTR_NON_NULL(psStartTagName, return);
-    if(strcmp(psEndTagName, psStartTagName)) {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TAG_MISMATCH, psStartTagName, psEndTagName);
-    }
-
-    // Initialize psLib structs
-    if(!strcmp(psEndTagName, "psMetadataItem")) {
-        initMetadataItemXml(ctx, psEndTagName);
-    } else if(!strcmp(psEndTagName, "psVector")) {
-        initVectorXml(ctx, psEndTagName);
-    } else if(strcmp(psEndTagName, "psRoot")) {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_TAG_UNKNOWN, psEndTagName);
-    }
-
-    // Free temporary metadata item and its hash table
-    psListRemove(tables->data.list, PS_LIST_TAIL);
-
-    psFree(psEndTagName);
-
-    return;
-}
-
-psMetadata*  psMetadataConfigParseXml(psMetadata* md, psU32 *nFail, const char *fileName, psBool overwrite)
-{
-    xmlSAXHandler saxHandler;
-
-
-    // Error checks
-    PS_ASSERT_PTR_NON_NULL(fileName, NULL);
-
-    // Allocate metadata if necessary
-    if (md == NULL) {
-        md = psMetadataAlloc();
-    }
-
-    // Sax handler initializations
-    saxHandler.internalSubset           = NULL;
-    saxHandler.isStandalone             = NULL;
-    saxHandler.hasInternalSubset        = NULL;
-    saxHandler.hasExternalSubset        = NULL;
-    saxHandler.resolveEntity            = NULL;
-    saxHandler.getEntity                = NULL;
-    saxHandler.entityDecl               = NULL;
-    saxHandler.notationDecl             = NULL;
-    saxHandler.attributeDecl            = NULL;
-    saxHandler.elementDecl              = NULL;
-    saxHandler.unparsedEntityDecl       = NULL;
-    saxHandler.setDocumentLocator       = NULL;
-    saxHandler.startDocument            = NULL;
-    saxHandler.endDocument              = NULL;
-    saxHandler.startElement             = saxStartElement;
-    saxHandler.endElement               = saxEndElement;
-    saxHandler.reference                = NULL;
-    saxHandler.characters               = NULL;
-    saxHandler.ignorableWhitespace      = NULL;
-    saxHandler.processingInstruction    = NULL;
-    saxHandler.comment                  = NULL;
-    saxHandler.warning                  = xmlParserError;
-    saxHandler.error                    = xmlParserError;
-    saxHandler.fatalError               = xmlParserError;
-    saxHandler.getParameterEntity       = NULL;
-    saxHandler.cdataBlock               = NULL;
-    saxHandler.externalSubset           = NULL;
-    saxHandler.initialized              = 1;
-    saxHandler._private                 = md;
-    saxHandler.startElementNs           = NULL;
-    saxHandler.endElementNs             = NULL;
-    saxHandler.serror                   = NULL;
-
-    // Parse XML file
-    if (xmlSAXUserParseFile(&saxHandler, NULL, fileName)) {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_OPEN_FAILED, fileName);
-        return NULL;
-    }
-
-    // Parser and memory cleanups for libxml2
-    xmlCleanupParser();
-    xmlMemoryDump();
-
-    return md;
-}
Index: /trunk/psLib/src/types/psMetadataConfig.h
===================================================================
--- /trunk/psLib/src/types/psMetadataConfig.h	(revision 4539)
+++ /trunk/psLib/src/types/psMetadataConfig.h	(revision 4540)
@@ -1,3 +1,3 @@
-/** @file  psMetadataIO.h
+/** @file  psMetadataConfig.h
  *
  *  @brief Contains metadata input/output functions.
@@ -10,11 +10,13 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
-#ifndef PS_METADATAIO_H
-#define PS_METADATAIO_H
+#ifndef PS_METADATACONFIG_H
+#define PS_METADATACONFIG_H
+
+#include "psMetadata.h"
 
 /// @addtogroup Metadata
@@ -22,5 +24,5 @@
 
 /** A metadata data structure used in parsing arrays.
- *  
+ *
  *  Contains array information and the metadata storage location.
 */
@@ -36,5 +38,5 @@
 
 /** Allocates a p_psParseLevelInfo structure
- *   
+ *
  *  @return p_psParseLevelInfo* :   new p_psParseLevelInfo struct
  */
@@ -86,18 +88,4 @@
 );
 
-/** Read XML metadata configuration file.
- *
- *  Loads pre-defined XML settings by parsing a configuration file into a psMetadata structure.
- *
- *  @return psMetadata* : Resulting metadata from read.
- */
-
-psMetadata*  psMetadataConfigParseXml(
-    psMetadata* md,                    ///< Resulting metadata from read.
-    psU32 *nFail,                      ///< Number of failed lines.
-    const char *fileName,              ///< Name of file to read.
-    psBool overwrite                   ///< Allow overwrite of duplicate specifications.
-);
-
 /// @}
 
Index: /trunk/psLib/src/types/psPixels.c
===================================================================
--- /trunk/psLib/src/types/psPixels.c	(revision 4539)
+++ /trunk/psLib/src/types/psPixels.c	(revision 4540)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-27 20:38:12 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -20,5 +20,5 @@
 
 #include "psError.h"
-#include "psCollectionsErrors.h"
+#include "psErrorText.h"
 
 typedef int(*qsortCompareFcn)(const void *, const void *);
Index: /trunk/psLib/src/types/types.i
===================================================================
--- /trunk/psLib/src/types/types.i	(revision 4540)
+++ /trunk/psLib/src/types/types.i	(revision 4540)
@@ -0,0 +1,10 @@
+/* types headers */
+
+%include "psArray.h"
+%include "psBitSet.h"
+%include "psHash.h"
+%include "psList.h"
+%include "psLookupTable.h"
+%include "psMetadataConfig.h"
+%include "psMetadata.h"
+%include "psPixels.h"
Index: /trunk/psLib/src/xml/Makefile.am
===================================================================
--- /trunk/psLib/src/xml/Makefile.am	(revision 4539)
+++ /trunk/psLib/src/xml/Makefile.am	(revision 4540)
@@ -1,35 +1,12 @@
-#Makefile for dataIO functions of psLib
+#Makefile for xml functions of psLib
 #
-INCLUDES = \
-	-I$(top_srcdir)/src/astro \
-	-I$(top_srcdir)/src/db \
-	-I$(top_srcdir)/src/fft \
-	-I$(top_srcdir)/src/fits \
-	-I$(top_srcdir)/src/imageops \
-	-I$(top_srcdir)/src/math \
-	-I$(top_srcdir)/src/mathtypes \
-	-I$(top_srcdir)/src/sys \
-	-I$(top_srcdir)/src/types \
-	-I$(top_srcdir)/src/xml \
-	$(all_includes)
+noinst_LTLIBRARIES = libpslibxml.la
 
-noinst_LTLIBRARIES = libpslibdataIO.la
+libpslibxml_la_SOURCES = \
+	psXML.c
 
-libpslibdataIO_la_SOURCES = \
-	psLookupTable.c \
-	psFits.c \
-	psDB.c
-
-
-BUILT_SOURCES = psFileUtilsErrors.h
-EXTRA_DIST = psFileUtilsErrors.dat psFileUtilsErrors.h dataIO.i
-
-psFileUtilsErrors.h: psFileUtilsErrors.dat
-	$(top_srcdir)/src/psParseErrorCodes --data=$? $@
+EXTRA_DIST = xml.i
 
 pslibincludedir = $(includedir)
 pslibinclude_HEADERS = \
-	psLookupTable.h \
-	psFits.h \
-	psDB.h
-
+	psXML.h
Index: /trunk/psLib/src/xml/psXML.c
===================================================================
--- /trunk/psLib/src/xml/psXML.c	(revision 4539)
+++ /trunk/psLib/src/xml/psXML.c	(revision 4540)
@@ -1,15 +1,15 @@
-/** @file  psMetadataIO.c
+/** @file  psXML.c
 *
-*  @brief Contains metadata input/output functions.
+*  @brief Contains XML input/output functions.
 *
-*  This file defines functions to read and write metadata to/from an external file.
+*  This file defines functions to read metadata from an XML file.
 *
-*  @ingroup Metadata
+*  @ingroup XML
 *
 *  @author Ross Harman, MHPCC
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-06-30 00:04:12 $
+*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-07-12 19:12:01 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -17,21 +17,14 @@
 
 #include <libxml/parser.h>
-#include <fitsio.h>
 #include <string.h>
 #include <ctype.h>
 #include <limits.h>
 
-#include "psAbort.h"
-#include "psType.h"
+#include "psXML.h"
 #include "psMemory.h"
 #include "psError.h"
 #include "psString.h"
-#include "psList.h"
-#include "psHash.h"
-#include "psVector.h"
-#include "psMetadata.h"
-#include "psMetadataIO.h"
 #include "psConstants.h"
-#include "psAstronomyErrors.h"
+#include "psErrorText.h"
 
 /******************************************************************************/
@@ -39,18 +32,4 @@
 /******************************************************************************/
 
-/** Check for FITS errors */
-#define FITS_ERROR(STRING,PS_ERROR)                                                                          \
-fits_get_errstatus(status, fitsErr);                                                                         \
-psError(PS_ERR_IO,true, STRING, PS_ERROR, fitsErr);                                                          \
-status = 0;                                                                                                  \
-fits_close_file(fd, &status);                                                                                \
-if(status){                                                                                                  \
-    fits_get_errstatus(status, fitsErr);                                                                     \
-    psError(PS_ERR_IO,true, "Couldn't close FITS file. FITS error: %s", fitsErr);                            \
-}                                                                                                            \
-status = 0;                                                                                                  \
-psFree(output);                                                                                              \
-return NULL;
-
 /** Maximum size of a FITS line */
 #define FITS_LINE_SIZE 80
@@ -59,163 +38,7 @@
 #define MAX_STRING_LENGTH 256
 
-
-/******************************************************************************/
-/*  TYPE DEFINITIONS                                                          */
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  GLOBAL VARIABLES                                                         */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FILE STATIC VARIABLES                                                    */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
-/*****************************************************************************/
-
-static void saxEndElement(void *ctx, const xmlChar *tagName);
-static void initVectorXml(void *ctx, char *tagName);
-static void initMetadataItemXml(void *ctx, char *tagName);
-static void saxStartElement(void *ctx, const xmlChar *tagName, const xmlChar **atts);
-static psMetadata* getMetadataType(char *linePtr);
-static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)
-;
-static void parseLevelInfoFree(p_psParseLevelInfo* info);
-static psBool parseLine(psS32* level,   psArray* levelArray,
-                        char*  linePtr, psS32 lineCount,     char* fileName, psBool overwrite);
-static psBool parseMetadataItem(char* keyName, psS32* level,     psArray* levelArray,
-                                char* linePtr, psS32  lineCount, char*    fileName,    psMetadataFlags flags);
-
-static void parseLevelInfoFree(p_psParseLevelInfo* info)
-{
-    psFree(info->nonUniqueKeyArray);
-    psFree(info->typeArray);
-    psFree(info->templateArray);
-    psFree(info->name);
-    psFree(info->metadata);
-}
-
-// Determines if a line is blank (whitespace only) or a commentline. It returns true if so. The input string
-// must be null terminated.
-psBool ignoreLine(char *inString)
-{
-    while(*inString!='\0' && *inString!='#') {
-        if(!isspace(*inString)) {
-            return false;
-        }
-        inString++;
-    }
-
-    return true;
-}
-
-
-//  Removes leading and trailing whitespace and # characters from a string. The cleaned string is a new null
-//  terminated copy of the original input string.
-char *cleanString(char *inString, psS32 sLen, psBool ignoreComment)
-{
-    char *ptrB = NULL;
-    char *ptrE = NULL;
-    char *cleaned = NULL;
-
-    // Initialize begining of string pointer
-    ptrB = inString;
-
-    // Skip over leading # or whitespace
-    if(ignoreComment) {
-        while (isspace(*ptrB) || *ptrB=='#') {
-            ptrB++;
-        }
-    } else {
-        while (isspace(*ptrB)) {
-            ptrB++;
-        }
-    }
-
-    // Skip over trailing whitespace, null terminators, and # characters
-    ptrE = inString + sLen;
-    if(ignoreComment) {
-        while(isspace(*ptrE) || *ptrE=='\0' || *ptrE=='#') {
-            ptrE--;
-        }
-    } else {
-        while(isspace(*ptrE) || *ptrE=='\0') {
-            ptrE--;
-        }
-    }
-
-    // Length, sLen, does not include '\0'
-    sLen = ptrE - ptrB + 1;
-
-    // Adds '\0' to end of string and +1 to sLen
-    if(sLen < 0 ) {
-        cleaned = NULL;
-    } else {
-        cleaned = psStringNCopy(ptrB, sLen);
-    }
-
-    return cleaned;
-}
-
-// Count repeat occurances of a single character within a line. The input string must be null terminated.
-psS32 repeatedChars(char *inString, char ch)
-{
-    psS32 count = 0;
-
-    while(*inString!='\0') {
-        if(*inString == ch) {
-            count++;
-        }
-        inString++;
-    }
-
-    return count;
-}
-
-// Returns cleaned token based on delimiter, but not including delimiter. Also changes the pointer location
-// the beginning of the string. Tokens are newly allocated null terminated strings.
-char* getToken(char **inString, char *delimiter, psS32 *status, psBool ignoreComment)
-{
-    char *cleanToken = NULL;
-    char *convertChar = NULL;
-    psS32 sLen = 0;
-
-    // Convert tab characters to white space
-    while((convertChar=strchr(*inString,'\t')) != NULL ) {
-        *convertChar = ' ';
-    }
-
-    // Skip over leading whitespace
-    while(isspace(**inString)) {
-        (*inString)++;
-    }
-
-    // Length of token, not including delimiter
-    sLen = strcspn(*inString, delimiter);
-    if(sLen) {
-
-        // Create new, cleaned, and null terminated token
-        cleanToken = cleanString(*inString, sLen,ignoreComment);
-
-        // Move to end of token
-        (*inString) += sLen;
-    } else if(**inString!='\0' && sLen==0) {
-        *status = 1;
-    }
-
-    return cleanToken;
-}
-
 // Returns single parsed value as a double precision number. The input string must be cleaned and null
 // terminated.
-double parseValue(char *inString, psS32 *status)
+static double parseValue(char *inString, psS32 *status)
 {
     char *end = NULL;
@@ -233,5 +56,5 @@
 
 /** Returns true or false. 'T', 't', '1', 'F', 'f', and '0' are acceptable, parsable variations. */
-psBool parseBool(char *inString, psS32 *status)
+static psBool parseBool(char *inString, psS32 *status)
 {
     psBool value = false;
@@ -250,5 +73,5 @@
 
 /** Returns parsed vector filled with with data. The input string must be null terminated. */
-psVector* parseVector(char *inString, psElemType elemType, psS32 *status)
+static psVector* parseVector(char *inString, psElemType elemType, psS32 *status)
 {
     char*      end       = NULL;
@@ -332,808 +155,4 @@
 
     return vec;
-}
-
-/*****************************************************************************/
-/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
-/*****************************************************************************/
-
-p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)
-{
-
-    p_psParseLevelInfo* info = NULL;
-
-    // Allocate memory for parse level info
-    info = (p_psParseLevelInfo*)psAlloc(sizeof(p_psParseLevelInfo));
-
-    // If allocation successful then initialize members
-    if(info != NULL) {
-
-        info->nonUniqueKeyArray = psArrayAlloc(10);
-        info->nonUniqueKeyArray->n = 0;
-
-        info->typeArray = psArrayAlloc(10);
-        info->typeArray->n = 0;
-
-        info->templateArray = psArrayAlloc(10);
-        info->templateArray->n = 0;
-
-        info->metadata = NULL;
-        info->name = NULL;
-
-        // Set memory deallocator
-        psMemSetDeallocator(info,(psFreeFunc)parseLevelInfoFree);
-    }
-    return info;
-}
-
-bool psMetadataItemPrint(FILE * fd, const char *format, const psMetadataItem* item)
-{
-    psMetadataType type;
-    psBool success = true;
-
-    PS_ASSERT_PTR_NON_NULL(fd, success);
-    PS_ASSERT_PTR_NON_NULL(format, success);
-    PS_ASSERT_PTR_NON_NULL(item, success);
-
-    type = item->type;
-
-    // determining the format type
-    char* fType = strchr(format,'%');
-    if (fType == NULL) {
-        // well, the format contains no reference to the metadataItem's data:
-        // that is truly trival to do!
-        fprintf(fd,format);
-        return success;
-    }
-
-    // skip over any format modifiers
-    const char* formatEnd = format+strlen(format);
-    while ( (fType < formatEnd) &&
-        (strchr(" +-01234567890.$#, hlL",*(++fType)) != NULL) ) {}
-
-    #define METADATAITEM_NUMERIC_CAST(FORMAT_TYPE) { \
-        switch(type) { \
-        case PS_META_BOOL: \
-            fprintf(fd, format, (FORMAT_TYPE) item->data.B); \
-            break; \
-        case PS_META_S32: \
-            fprintf(fd,format,(FORMAT_TYPE)  item->data.S32); \
-            break; \
-        case PS_META_F32: \
-            fprintf(fd, format,(FORMAT_TYPE)  item->data.F32); \
-            break; \
-        case PS_META_F64: \
-            fprintf(fd, format,(FORMAT_TYPE) item->data.F64); \
-            break; \
-        default: \
-            psError(PS_ERR_BAD_PARAMETER_TYPE,true, \
-                    PS_ERRORTEXT_psMetadata_METATYPE_INVALID, (int)type); \
-            success = false; \
-        } \
-    }
-
-    switch(*fType) {
-    case 'd':
-    case 'i':
-    case 'c':
-        METADATAITEM_NUMERIC_CAST(int)
-        break;
-    case 'o':
-    case 'u':
-    case 'x':
-    case 'X':
-        METADATAITEM_NUMERIC_CAST(unsigned int)
-        break;
-    case 'e':
-    case 'E':
-    case 'f':
-    case 'F':
-    case 'g':
-    case 'G':
-    case 'a':
-    case 'A':
-        METADATAITEM_NUMERIC_CAST(double)
-        break;
-    case 's':
-        if (type == PS_META_STR) {
-            fprintf(fd,format,(char*)item->data.V);
-        } else {
-            psError(PS_ERR_BAD_PARAMETER_TYPE,true,
-                    PS_ERRORTEXT_psMetadata_METATYPE_INVALID, (int)type);
-            success = false;
-        }
-        break;
-    case 'p':
-        fprintf(fd,format,item->data.V);
-        break;
-    default:
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                PS_ERRORTEXT_psMetadata_FORMAT_INVALID, *fType);
-        break;
-    }
-
-    return success;
-}
-
-
-psMetadata* psMetadataReadHeader(psMetadata* output, char *extName, psS32 extNum, char *fileName)
-{
-    psBool tempBool;
-    psBool success;
-    char keyType;
-    char keyName[FITS_LINE_SIZE];
-    char keyValue[FITS_LINE_SIZE];
-    char keyComment[FITS_LINE_SIZE];
-    char fitsErr[MAX_STRING_LENGTH];
-    psS32 i;
-    psS32 hduType = 0;
-    psS32 status = 0;
-    psS32 numKeys = 0;
-    psS32 keyNum = 0;
-    fitsfile *fd = NULL;
-
-    PS_ASSERT_PTR_NON_NULL(fileName,NULL);
-
-    fits_open_file(&fd, fileName, READONLY, &status);
-    if(fd == NULL || status != 0) {
-        FITS_ERROR("FITS error while opening file: %s %s", fileName);
-        return NULL;
-    }
-
-    if (extName == NULL && extNum < 1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                PS_ERRORTEXT_psMetadataIO_EXTNUM_NOTPOSITIVE,
-                extNum);
-        return NULL;
-    }
-
-    // Allocate metadata if user didn't
-    if (output == NULL) {
-        output = psMetadataAlloc();
-    }
-
-    // Move to user designated HDU number or HDU name in FITS file. HDU numbers starts at one.
-    if (extName != NULL) {
-        if (fits_movnam_hdu(fd, ANY_HDU, extName, 0, &status) != 0) {
-            FITS_ERROR("FITS error while locating header %s: %s", extName);
-        }
-    } else {
-        if (fits_movabs_hdu(fd, extNum, &hduType, &status) != 0) {
-            FITS_ERROR("FITS error while locating header %d: %s", extNum);
-        }
-    }
-
-    // Get number of key names
-    if (fits_get_hdrpos(fd, &numKeys, &keyNum, &status) != 0) {
-        FITS_ERROR("FITS error while reading key %d: %s", keyNum);
-    }
-
-    // Get each key name. Keywords start at one.
-    for (i = 1; i <= numKeys; i++) {
-        if (fits_read_keyn(fd, i, keyName, keyValue, keyComment, &status) != 0) {
-            FITS_ERROR("FITS error while reading key %d: %s", keyNum);
-        }
-        if (fits_get_keytype(keyValue, &keyType, &status) != 0) {
-            fits_get_errstatus(status, fitsErr);
-            if (status != VALUE_UNDEFINED) {
-                FITS_ERROR("FITS error while determining key %d type: %s", keyNum);
-            } else {
-                // Some keywords are still valid if they don't have a type (like COMMENTS and HISTORY)
-                keyType = 'C';
-                status = 0;
-            }
-        }
-
-        switch (keyType) {
-        case 'I':
-            success = psMetadataAdd(output, PS_LIST_TAIL, keyName,
-                                    PS_META_S32 | PS_META_DUPLICATE_OK,
-                                    keyComment, atoi(keyValue));
-            break;
-        case 'F':
-            success = psMetadataAdd(output, PS_LIST_TAIL, keyName,
-                                    PS_META_F64 | PS_META_DUPLICATE_OK,
-                                    keyComment, atof(keyValue));
-            break;
-        case 'C':
-            success = psMetadataAdd(output, PS_LIST_TAIL, keyName,
-                                    PS_META_STR | PS_META_DUPLICATE_OK,
-                                    keyComment, keyValue);
-            break;
-        case 'L':
-            tempBool = (keyValue[0] == 'T') ? 1 : 0;
-            success = psMetadataAdd(output, PS_LIST_TAIL, keyName,
-                                    PS_META_BOOL | PS_META_DUPLICATE_OK,
-                                    keyComment, tempBool);
-            break;
-        case 'U':
-        case 'X':
-        default:
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FITS_METATYPE_INVALID, keyType);
-            return output;
-        }
-
-        if (!success) {
-            psError(PS_ERR_UNKNOWN, false, PS_ERRORTEXT_psMetadataIO_ADD_FAILED, keyName);
-            return output;
-        }
-    }
-
-    return output;
-}
-
-static psMetadata* getMetadataType(char* linePtr)
-{
-    psMetadata*     metadataTemplate = NULL;
-    psS32           status           = 0;
-    char*           token            = NULL;
-    psMetadataItem* tempItem         = NULL;
-
-    // Loop through line and generate metadata items for each token found
-    while((token = getToken(&linePtr," ",&status,false)) != NULL ) {
-
-        // If not allocated then allocate new metadata
-        if(metadataTemplate == NULL) {
-            metadataTemplate = psMetadataAlloc();
-        }
-
-        // Look for comment indicator #
-        if(strstr(token,"#") != 0) {
-            psFree(token);
-            break;
-        }
-
-        // Create metadata item to represent token read
-        tempItem = psMetadataItemAllocStr(token,"","");
-        if(tempItem == NULL) {
-            psFree(metadataTemplate);
-            psFree(token);
-            metadataTemplate = NULL;
-            break;
-        }
-
-        // Add item to template
-        if(!psMetadataAddItem(metadataTemplate, tempItem, PS_LIST_TAIL, PS_META_DEFAULT)) {
-            psFree(metadataTemplate);
-            psFree(tempItem);
-            psFree(token);
-            metadataTemplate = NULL;
-            break;
-        }
-        psFree(tempItem);
-        psFree(token);
-    }
-
-    return metadataTemplate;
-}
-
-static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)
-{
-    psMetadata*      md           = NULL;
-    psS32            items        = 0;
-    char*            token        = NULL;
-    psS32            status       = 0;
-    psMetadataItem*  mdItem       = NULL;
-    psMetadataItem*  templateItem = NULL;
-    psListIterator*  iter         = NULL;
-
-    // Determine the number of items in template
-    items = template->list->size;
-    if(items > 0 ) {
-
-        // Allocate metadata
-        md = psMetadataAlloc()
-             ;
-
-        // Point to first item in template
-        iter = psListIteratorAlloc(template->
-                                   list,PS_LIST_HEAD,true);
-
-        // For each item in template parse line string for values
-        for(psS32 i = 0;
-                i < items;
-                i++) {
-
-            // Get template item
-            templateItem = psListGetAndIncrement(iter)
-                           ;
-            if(templateItem == NULL) {
-                psFree(md);
-                md = NULL;
-                break;
-            }
-
-            // Get the next token on the line
-            token = getToken(&linePtr," ",&status,false);
-            if(token != NULL) {
-                // Allocate metadata item
-                mdItem = psMetadataItemAllocStr(templateItem->name,templateItem->comment,token);
-                if(mdItem == NULL) {
-                    psFree(md);
-                    md = NULL;
-                    psFree(token);
-                    break;
-                }
-                // Add item to metadata
-                if(!psMetadataAddItem(md, mdItem, PS_LIST_TAIL, PS_META_DEFAULT)) {
-                    psFree(md);
-                    md = NULL;
-                    psFree(mdItem);
-                    psFree(token);
-                    break;
-                }
-                psFree(mdItem);
-            } else {
-                // Missing items
-                psFree(md);
-                md = NULL;
-                break;
-            }
-
-            psFree(token);
-        }
-        psFree(iter);
-    }
-    return md;
-}
-
-psBool parseMetadataItem(char* keyName, psS32* level,     psArray* levelArray,
-                         char* linePtr, psS32  lineCount, char*    fileName,   psMetadataFlags flags)
-{
-    psBool               returnValue   = true;
-    psBool               addStatus     = false;
-    psMetadataType       mdType        = PS_META_UNKNOWN;
-    psElemType           vectorType    = PS_TYPE_S8;
-    char*                strType       = NULL;
-    char*                strValue      = NULL;
-    char*                strComment    = NULL;
-    psS32                status        = 0;
-    psMetadata*          md            = NULL;
-    psF64                tempDbl       = 0.0;
-    psBool               tempBool      = false;
-    psS32                tempInt       = 0;
-    psVector*            tempVec       = NULL;
-    char*                tempStr       = NULL;
-    psArray*             nonUniqueKeys = NULL;
-    psBool               typeFound     = false;
-    psArray*             typeArray     = NULL;
-    psArray*             templateArray = NULL;
-    psMetadata*          tempMeta      = NULL;
-    p_psParseLevelInfo*  nextLevelInfo = NULL;
-
-    // Get the metadata item type
-    strType = getToken(&linePtr, " ", &status,true);
-
-    // Check for no type
-    if(strType==NULL) {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, "type",lineCount,
-                fileName);
-        returnValue = false;
-    } else {
-
-        // Set metadata type based on type token
-
-        // Check if the keyName specifies a vector and if so use strType token to find vector type
-        if(*keyName == '@') {
-            mdType = PS_META_VEC;
-            // Get the type of vector
-            if(!strncmp(strType, "U8", 2)) {
-                vectorType = PS_TYPE_U8;
-            } else if (!strncmp(strType,"U16",3)) {
-                vectorType = PS_TYPE_U16;
-            } else if (!strncmp(strType,"U32",3)) {
-                vectorType = PS_TYPE_U32;
-            } else if (!strncmp(strType,"U64",3)) {
-                vectorType = PS_TYPE_U64;
-            } else if (!strncmp(strType,"S8",2)) {
-                vectorType = PS_TYPE_S8;
-            } else if (!strncmp(strType,"S16",3)) {
-                vectorType = PS_TYPE_S16;
-            } else if (!strncmp(strType,"S32",3)) {
-                vectorType = PS_TYPE_S32;
-            } else if (!strncmp(strType,"S64",3)) {
-                vectorType = PS_TYPE_S64;
-            } else if (!strncmp(strType,"F32",3)) {
-                vectorType = PS_TYPE_F32;
-            } else if (!strncmp(strType,"F64",3)) {
-                vectorType = PS_TYPE_F64;
-            } else {
-                psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, "", keyName,
-                        strType, lineCount, fileName);
-                psFree(strType);
-                return false;
-            }
-        } else if(!strncmp(strType, "STR", 3)) {
-            mdType = PS_META_STR;
-        } else if(!strncmp(strType, "BOOL", 4)) {
-            mdType = PS_META_BOOL;
-        } else if(!strncmp(strType, "S32", 3)) {
-            mdType = PS_META_S32;
-        } else if(!strncmp(strType, "F32", 3)) {
-            mdType = PS_META_F32;
-        } else if(!strncmp(strType, "F64", 3)) {
-            mdType = PS_META_F64;
-        } else if(!strncmp(strType, "MULTI", 5)) {
-            mdType = PS_META_MULTI;
-        } else if(!strncmp(strType, "METADATA", 8)) {
-            mdType = PS_META_META;
-        } else {
-            // Search through user types
-            typeArray = ((p_psParseLevelInfo*)(levelArray->data[*level]))->typeArray;
-            templateArray = ((p_psParseLevelInfo*)(levelArray->data[*level]))->templateArray;
-            for(psS32 k = 0; k < typeArray->n; k++) {
-                if(strcmp(strType,(char*)typeArray->data[k]) == 0) {
-                    tempMeta = setMetadataItem((psMetadata*)templateArray->data[k],linePtr);
-                    if(tempMeta != NULL) {
-                        // Add metadata item
-                        md = ((p_psParseLevelInfo*)(levelArray->data[*level]))->metadata;
-                        addStatus = psMetadataAdd(md,PS_LIST_TAIL,keyName,PS_META_META | flags,"",tempMeta);
-                        // Check for add failure
-                        if (! addStatus) {
-                            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM,
-                                    keyName, lineCount, fileName);
-                            psFree(strType);
-                            psFree(tempMeta);
-                            return false;
-                        }
-                        psFree(tempMeta);
-                    } else {
-                        // Metadata type read error
-                        psError(PS_ERR_IO,true,PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL,
-                                keyName,lineCount,fileName);
-                        psFree(strType);
-                        return false;
-                    }
-                    typeFound = true;
-                    break;
-                }
-            }
-            if(!typeFound) {
-                psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID,
-                        strType, lineCount,fileName);
-                psFree(strType);
-                return false;
-            } else {
-                psFree(strType);
-                return true;
-            }
-        }
-    }
-
-    // If type is not MULTI or META then get the value and comment
-    if((mdType != PS_META_MULTI) && (mdType != PS_META_META)) {
-        // Get the metadata item value if there is one.
-        status = 0;
-        strValue = getToken(&linePtr, "#", &status,true);
-        if(status) {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, "value", lineCount,
-                    fileName);
-            psFree(strType);
-            psFree(strValue);
-            return false;
-        }
-        if(strValue==NULL) {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, "value", lineCount,
-                    fileName);
-            psFree(strType);
-            psFree(strValue);
-            return false;
-        }
-        // Not all lines will have comments, so NULL is ok.
-        status = 0;
-        strComment = getToken(&linePtr,"~", &status,true);
-        if(status) {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, "comment", lineCount,
-                    fileName);
-            psFree(strType);
-            psFree(strValue);
-            psFree(strComment);
-        }
-    }
-
-    // Need to add item to metadata so get pointer to metadata
-    status = 0;
-    md = ((p_psParseLevelInfo*)(levelArray->data[*level]))->metadata;
-    nonUniqueKeys = ((p_psParseLevelInfo*)(levelArray->data[*level]))->nonUniqueKeyArray;
-    switch(mdType) {
-    case PS_META_STR:
-        addStatus = psMetadataAdd(md, PS_LIST_TAIL, keyName,
-                                  mdType | flags,
-                                  strComment, strValue);
-        break;
-    case PS_META_BOOL:
-        tempBool = parseBool(strValue, &status);
-        if(!status) {
-            addStatus = psMetadataAdd(md, PS_LIST_TAIL, keyName,
-                                      mdType | flags,
-                                      strComment, tempBool);
-        } else {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, keyName,
-                    strType, lineCount, fileName);
-            returnValue = false;
-        }
-        break;
-    case PS_META_F32:
-    case PS_META_F64:
-        tempDbl = parseValue(strValue, &status);
-        if(!status) {
-            addStatus = psMetadataAdd(md, PS_LIST_TAIL, keyName,
-                                      mdType | flags,
-                                      strComment, tempDbl);
-        } else {
-            psError(PS_ERR_IO, true,
-                    PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, keyName, strType, lineCount,
-                    fileName);
-            returnValue = false;
-        }
-        break;
-    case PS_META_S32:
-        tempInt = (psS32)parseValue(strValue, &status);
-        if(!status) {
-            addStatus = psMetadataAdd(md, PS_LIST_TAIL, keyName,
-                                      mdType | flags,
-                                      strComment, tempInt);
-        } else {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, keyName,
-                    strType, lineCount, fileName);
-            returnValue = false;
-        }
-        break;
-    case PS_META_VEC:
-        tempVec = parseVector(strValue, vectorType, &status);
-        if(!status) {
-            addStatus = psMetadataAdd(md, PS_LIST_TAIL, keyName+1,
-                                      mdType | flags,
-                                      strComment, tempVec);
-        } else {
-            psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_PARSE_FAILED, strValue, keyName,
-                    strType, lineCount, fileName);
-            returnValue = false;
-        }
-        psFree(tempVec);
-        break;
-    case PS_META_MULTI:
-        // Add key to non-unique array of keys
-        // Check for duplicate MULTI lines
-        addStatus = true;
-        for(psS32 k=0; k < nonUniqueKeys->n; k++) {
-            if(strcmp(keyName,(char*)nonUniqueKeys->data[k]) == 0) {
-                psError(PS_ERR_IO,true,PS_ERRORTEXT_psMetadataIO_DUPLICATE_MULTI,
-                        lineCount,fileName);
-                psFree(strType);
-                return false;
-            }
-        }
-        tempStr = psStringCopy(keyName);
-        nonUniqueKeys = psArrayAdd(nonUniqueKeys,0,tempStr);
-        addStatus = true;
-        psFree(tempStr);
-        break;
-    case PS_META_META:
-        // Create next level info
-        nextLevelInfo = p_psParseLevelInfoAlloc();
-        // Create new metadata
-        nextLevelInfo->metadata = psMetadataAlloc();
-        // Save name of metadata
-        nextLevelInfo->name = psStringCopy(keyName);
-        // Add next level to levelArray
-        levelArray = psArrayAdd(levelArray,1,nextLevelInfo);
-        psFree(nextLevelInfo);
-        // Increment level counter
-        (*level)++;
-        addStatus = true;
-        break;
-    default:
-        psError(PS_ERR_IO,true,PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID,
-                lineCount,fileName);
-        break;
-    }
-
-    // Check if the add status was successful
-    if (! addStatus) {
-        //        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_OVERWRITE_ITEM, keyName, lineCount,
-        //                fileName);
-        returnValue = false;
-    }
-
-    psFree(strComment);
-    psFree(strValue);
-    psFree(strType);
-
-    return returnValue;
-}
-
-psBool parseLine(psS32* level,     psArray* levelArray, char*  linePtr,
-                 psS32  lineCount, char*    fileName,   psBool overwrite)
-{
-    psBool              returnValue    = true;
-    psMetadataFlags     flags          = PS_META_DEFAULT;
-    char*               keyName        = NULL;
-    psS32               status         = 0;
-    psS32               limit          = 0;
-    psMetadata*         tempTemplate   = NULL;
-    char*               strType        = NULL;
-    psArray*            typeArray      = NULL;
-    psArray*            templateArray  = NULL;
-    p_psParseLevelInfo* upperLevelInfo = NULL;
-    p_psParseLevelInfo* lowerLevelInfo = NULL;
-    psBool              addStatus      = 0;
-
-    // Set flags if overwrite specified
-    if(overwrite) {
-        flags = PS_META_REPLACE;
-    }
-
-    // If line is not a comment or blank, then extract data
-    if(!ignoreLine(linePtr)) {
-
-        // Check for more than one '@' in a line
-        if(repeatedChars(linePtr, '@') > 1) {
-            psError(PS_ERR_IO, true,
-                    PS_ERRORTEXT_psMetadataIO_FILE_MULTIPLE_CHAR, '@', lineCount, fileName);
-            return false;
-        }
-
-        // Get metadata item name
-        keyName = getToken(&linePtr, " ", &status,true);
-        if(status) {
-            psError(PS_ERR_IO, true,
-                    PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL, "keyName", lineCount, fileName);
-            psFree(keyName);
-            return false;
-        }
-
-        // Check for special keyName values "TYPE", "END"
-        if(strcmp(keyName,"TYPE") == 0 ) {
-            // Get the type name
-            strType = getToken(&linePtr," ",&status,true);
-            if(strType == NULL) {
-                psError(PS_ERR_IO,true,PS_ERRORTEXT_psMetadataIO_FILE_ELEMENT_NULL,"type",lineCount,
-                        fileName);
-                psFree(keyName);
-                return false;
-            }
-            tempTemplate = getMetadataType(linePtr);
-            // Check if type was parsed succesfully
-            if(tempTemplate != NULL) {
-                // Access type array
-                typeArray = ((p_psParseLevelInfo*)(levelArray->data[*level]))->typeArray;
-                // Check if type already exists in array
-                for(psS32 k=0; k < typeArray->n; k++) {
-                    // Compare type name with the list of current types
-                    if(strcmp(strType,(char*)typeArray->data[k]) == 0) {
-                        psError(PS_ERR_IO,true,PS_ERRORTEXT_psMetadataIO_TYPE_DUPLICATE,
-                                strType,lineCount,fileName);
-                        psFree(tempTemplate);
-                        psFree(keyName);
-                        psFree(strType);
-                        return false;
-                    }
-                }
-                // Add key name to array of type
-                typeArray = psArrayAdd(typeArray,1,strType);
-                // Add template to array of templates
-                templateArray = ((p_psParseLevelInfo*)(levelArray->data[*level]))->templateArray;
-                templateArray = psArrayAdd(templateArray,1,tempTemplate);
-                psFree(tempTemplate);
-            } else {
-                psError(PS_ERR_IO,true,PS_ERRORTEXT_psMetadataIO_FILE_TYPE_INVALID,
-                        strType,lineCount,fileName);
-                psFree(keyName);
-                psFree(strType);
-                return false;
-            }
-            psFree(strType);
-        } else if (strcmp(keyName,"END") == 0 ) {
-            if(*level > 0) {
-                upperLevelInfo = ((p_psParseLevelInfo*)(levelArray->data[*level-1]));
-                lowerLevelInfo = ((p_psParseLevelInfo*)(levelArray->data[*level]));
-                // Check name in nonunique list
-                for(psS32 k=0; k < upperLevelInfo->nonUniqueKeyArray->n; k++) {
-                    if(strcmp(upperLevelInfo->nonUniqueKeyArray->data[k],lowerLevelInfo->name) == 0) {
-                        flags = PS_META_DUPLICATE_OK;
-                        break;
-                    }
-                }
-                // Add metadata to upper level metadata
-                addStatus = psMetadataAdd(upperLevelInfo->metadata,
-                                          PS_LIST_TAIL,lowerLevelInfo->name,
-                                          PS_META_META | flags,
-                                          "",
-                                          lowerLevelInfo->metadata);
-                if(!addStatus) {
-                    psFree(keyName);
-                    return false;
-                } else {
-                    // Remove lower info level
-                    if(!psArrayRemove(levelArray,levelArray->data[*level])) {
-                        psFree(keyName);
-                        return false;
-                    }
-                    psFree(lowerLevelInfo);
-                    (*level)--;
-                }
-            } else {
-                psFree(keyName);
-                return false;
-            }
-        } else {
-            // Check if key name present in array of non-unique key names
-            limit = ((p_psParseLevelInfo*)(levelArray->data[*level]))->nonUniqueKeyArray->n;
-            for(psS32 k=0; k < limit; k++) {
-                char* name = (char*)((p_psParseLevelInfo*)
-                                     (levelArray->data[*level]))->nonUniqueKeyArray->data[k];
-                if(strcmp(name,keyName) == 0) {
-                    flags = PS_META_DUPLICATE_OK;
-                }
-            }
-            // Parse metadataItem
-            if(!parseMetadataItem(keyName,level, levelArray, linePtr, lineCount, fileName, flags)) {
-                psFree(keyName);
-                return false;
-            }
-        }
-        psFree(keyName);
-    }
-    return returnValue;
-}
-
-psMetadata* psMetadataConfigParse(psMetadata* md, unsigned int *nFail, const char *fileName, bool overwrite)
-{
-    FILE*               fp                   = NULL;
-    char*               line                 = NULL;
-    char*               linePtr              = NULL;
-    psArray*            parseLevelInfoArray  = NULL;
-    psS32               lineCount            = 0;
-    psS32               nestingLevel         = 0;
-    p_psParseLevelInfo* topLevelInfo         = NULL;
-
-    // Check for NULL file name
-    PS_ASSERT_PTR_NON_NULL(fileName,NULL);
-
-    // Check for NULL nFail
-    PS_ASSERT_PTR_NON_NULL(nFail,NULL);
-
-    // Attempt to open specified file
-    if((fp=fopen(fileName, "r")) == NULL) {
-        psError(PS_ERR_IO, true, PS_ERRORTEXT_psMetadataIO_FILE_OPEN_FAILED, fileName);
-        return NULL;
-    }
-
-    // Allocate metadata if necessary
-    if (md == NULL) {
-        md = psMetadataAlloc();
-    }
-
-    // Allocate array to store parse level information
-    parseLevelInfoArray = psArrayAlloc(10);
-    parseLevelInfoArray->n = 0;
-
-    // Set parse level info for the top level
-    topLevelInfo = p_psParseLevelInfoAlloc();
-    topLevelInfo->metadata = psMemIncrRefCounter(md);
-    parseLevelInfoArray = psArrayAdd(parseLevelInfoArray,1,topLevelInfo);
-    psFree(topLevelInfo);
-
-    // Create reusable line for continuous read
-    line = (char*)psAlloc(MAX_STRING_LENGTH*sizeof(char));
-
-    // While loop to parse the file
-    while(fgets(line, MAX_STRING_LENGTH, fp) != NULL) {
-
-        // Initialize variables for new line
-        linePtr = line;
-        lineCount++;
-
-        if(!parseLine(&nestingLevel,parseLevelInfoArray,linePtr,lineCount,(char*)fileName,overwrite)) {
-            (*nFail)++;
-        }
-    }
-
-    // Free parse array and line buffer
-    psFree(parseLevelInfoArray);
-    psFree(line);
-
-    return md;
 }
 
Index: /trunk/psLib/src/xml/psXML.h
===================================================================
--- /trunk/psLib/src/xml/psXML.h	(revision 4539)
+++ /trunk/psLib/src/xml/psXML.h	(revision 4540)
@@ -1,95 +1,26 @@
-/** @file  psMetadataIO.h
+/** @file  psXML.h
  *
- *  @brief Contains metadata input/output functions.
+ *  @brief Contains XML functions.
  *
- *  This file defines functions to read and write metadata to/from an external file.
+ *  This file defines functions to read metadata from an XML file.
  *
- *  @ingroup Metadata
+ *  @ingroup XML
  *
  *  @author Ross Harman, MHPCC
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-28 20:17:52 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-07-12 19:12:01 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
-#ifndef PS_METADATAIO_H
-#define PS_METADATAIO_H
+#ifndef PS_XML_H
+#define PS_XML_H
 
-/// @addtogroup Metadata
+#include "psMetadata.h"
+#include "psMetadataConfig.h"
+
+/// @addtogroup XML
 /// @{
-
-/** A metadata data structure used in parsing arrays.
- *  
- *  Contains array information and the metadata storage location.
-*/
-typedef struct
-{
-    psArray*    nonUniqueKeyArray;     ///< non-unique key names
-    psArray*    typeArray;             ///< array of user defined types
-    psArray*    templateArray;         ///< array of user type templates
-    psMetadata* metadata;              ///< metadata container
-    char*       name;                  ///< name of key
-}
-p_psParseLevelInfo;
-
-/** Allocates a p_psParseLevelInfo structure
- *   
- *  @return p_psParseLevelInfo* :   new p_psParseLevelInfo struct
- */
-p_psParseLevelInfo* p_psParseLevelInfoAlloc(void);
-
-/** Print metadata item to file.
- *
- *  Metadata items may be printed to an open file descriptor based on a
- *  provided format. The format is a sprintf format statement with exactly
- *  one % formatting command. If the metadata item type is a numeric type,
- *  this formatting command must also be numeric, and the type conversion
- *  performed to the value to match the format type. If the metadata type is
- *  a string, the fromatting command must also be for a string. If the
- *  metadata type is any other data type, printing is not allowed.
- *
- * @return psMetadataItem* : Pointer metadata item.
- */
-bool psMetadataItemPrint(
-    FILE * fd,                         ///< Pointer to file to write metadata item.
-    const char *format,                ///< Format to print metadata item.
-    const psMetadataItem* item         ///< Metadata item to print.
-);
-
-/** Read metadata header.
- *
- *  Read a metadata header from file. If the file is not found, an error is
- *  reported.
- *
- *  @return psMetadata* : Pointer to resulting metadata.
- */
-psMetadata* psMetadataReadHeader(
-    psMetadata* output,                ///< Resulting metadata from read.
-    char *extName,                     ///< File name extension string.
-    psS32 extNum,                      ///< File name extension number. Starts at 1.
-    char *fileName                     ///< Name of file to read.
-);
-
-/** Read metadata configuration file.
- *
- *  Loads pre-defined settings by parsing a configuration file into a psMetadata structure.
- *
- *  @return psMetadata* : Resulting metadata from read.
- */
-psMetadata* psMetadataConfigParse(
-    psMetadata* md,                    ///< Resulting metadata from read.
-    unsigned int *nFail,               ///< Number of failed lines.
-    const char *fileName,              ///< Name of file to read.
-    bool overwrite                     ///< Allow overwrite of duplicate specifications.
-);
-
-/** Read XML metadata configuration file.
- *
- *  Loads pre-defined XML settings by parsing a configuration file into a psMetadata structure.
- *
- *  @return psMetadata* : Resulting metadata from read.
- */
 
 psMetadata*  psMetadataConfigParseXml(
@@ -102,3 +33,3 @@
 /// @}
 
-#endif // #ifndef PS_METADATAIO_H
+#endif // #ifndef PS_XML_H
Index: /trunk/psLib/src/xml/xml.i
===================================================================
--- /trunk/psLib/src/xml/xml.i	(revision 4540)
+++ /trunk/psLib/src/xml/xml.i	(revision 4540)
@@ -0,0 +1,2 @@
+/* xml headers */
+%include "psXML.h"
