Index: /trunk/psLib/src/dataManip/psConstants.h
===================================================================
--- /trunk/psLib/src/dataManip/psConstants.h	(revision 1962)
+++ /trunk/psLib/src/dataManip/psConstants.h	(revision 1963)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-05 01:43:58 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,68 @@
 #define RIGHT_SPLINE_DERIV 0.0
 
+#define CONVERT_VECTOR_F64_TO_F32(OLD, NEW_PTR32, NEW_STATIC32) \
+if (OLD->type.type == PS_TYPE_F32) { \
+    NEW_PTR32 = (psVector *) OLD; \
+} else if (OLD->type.type == PS_TYPE_F64) { \
+    NEW_STATIC32 = psVectorRecycle(NEW_STATIC32, OLD->n, PS_TYPE_F32); \
+    p_psMemSetPersistent(NEW_STATIC32, true); \
+    p_psMemSetPersistent(NEW_STATIC32->data.V, true); \
+    for (i=0; i < OLD->n ; i++) { \
+        NEW_STATIC32->data.F32[i] = (float) OLD->data.F64[i]; \
+    } \
+    NEW_PTR32 = NEW_STATIC32; \
+} \
+
+#define CONVERT_VECTOR_F32_TO_F64(OLD, NEW_PTR64, NEW_STATIC64) \
+if (OLD->type.type == PS_TYPE_F64) { \
+    NEW_PTR64 = (psVector *) OLD; \
+} else if (OLD->type.type == PS_TYPE_F32) { \
+    NEW_STATIC64 = psVectorRecycle(NEW_STATIC64, OLD->n, PS_TYPE_F64); \
+    p_psMemSetPersistent(NEW_STATIC64, true); \
+    p_psMemSetPersistent(NEW_STATIC64->data.V, true); \
+    for (i=0; i < OLD->n ; i++) { \
+        NEW_STATIC64->data.F64[i] = (double) OLD->data.F32[i]; \
+    } \
+    NEW_PTR64 = NEW_STATIC64; \
+} \
+
+#define VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(VEC) \
+if ((VEC->type.type != PS_TYPE_F32) && (VEC->type.type != PS_TYPE_F64)) { \
+    psAbort(__func__, "Bad type for VEC (%d)", VEC->type.type); \
+    return(NULL); \
+} \
+
+#define GEN_PERSIST_YERR_VEC_F32(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F32[i] = 1.0; \
+} \
+
+#define GEN_PERSIST_YERR_VEC_F64(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F64[i] = 1.0; \
+} \
+
+#define GEN_PERSIST_X_INDEX_VEC_F32(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F32[i] = (float) i; \
+} \
+
+#define GEN_PERSIST_X_INDEX_VEC_F64(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F64[i] = (float) i; \
+} \
+
 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \
 static psVector *NAME = NULL; \
@@ -23,7 +87,4 @@
 p_psMemSetPersistent(NAME, true); \
 p_psMemSetPersistent(NAME->data.V, true); \
-
-
-
 
 /** Preprocessor macro to generate error on an incorrect type */
@@ -51,8 +112,22 @@
 }
 
+/** Preprocessor macro to generate error on a NULL vector */
+#define PS_CHECK_NULL_VECTOR_RETURN_NULL(NAME) \
+if (NAME == NULL || NAME->data.V == NULL) { \
+    psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \
+    return(NULL); \
+} \
+
 /** Preprocessor macro to generate error on a NULL poniter */
 #define PS_CHECK_NULL_PTR(NAME) \
 if (NAME == NULL) { \
     psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \
+}
+
+/** Preprocessor macro to generate error on a NULL poniter */
+#define PS_CHECK_NULL_PTR_RETURN_NULL(NAME) \
+if (NAME == NULL) { \
+    psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \
+    return(NULL); \
 }
 
@@ -75,8 +150,22 @@
 }
 
+/** Preprocessor macro to generate error for zero length vector */
+#define PS_CHECK_EMPTY_VECTOR_RETURN_NULL(NAME) \
+if (NAME->n < 1) { \
+    psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \
+    return(NULL); \
+} \
+
 /** Preprocessor macro to generate error on differing size vectors */
 #define PS_CHECK_VECTOR_SIZE_EQUAL(VEC1, VEC2) \
 if (VEC1->n != VEC2->n) { \
     psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
+}
+
+/** Preprocessor macro to generate error on differing size vectors */
+#define PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(VEC1, VEC2) \
+if (VEC1->n != VEC2->n) { \
+    psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
+    return(NULL); \
 }
 
@@ -112,4 +201,10 @@
 }
 
+#define PS_CHECK_NULL_1DPOLY_RETURN_NULL(NAME)                                                          \
+if (NAME == NULL || NAME->coeff == NULL) {                                                         \
+    psError(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME);                          \
+    return(NULL); \
+} \
+
 #define PS_PRINT_VECTOR(NAME) \
 for (int my_i=0;my_i<NAME->n;my_i++) { \
Index: /trunk/psLib/src/dataManip/psMinimize.c
===================================================================
--- /trunk/psLib/src/dataManip/psMinimize.c	(revision 1962)
+++ /trunk/psLib/src/dataManip/psMinimize.c	(revision 1963)
@@ -9,6 +9,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-05 01:43:58 $
+ *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -56,4 +56,5 @@
  
 XXX: change name
+XXX: Use a static vector.
  *****************************************************************************/
 void p_psBuildSums1D(double x,
@@ -63,6 +64,11 @@
     int i = 0;
     double xSum = 0.0;
+
     if (sums == NULL) {
         sums = psVectorAlloc(polyOrder, PS_TYPE_F64);
+    }
+
+    if (polyOrder > sums->n) {
+        sums = psVectorRealloc(sums, polyOrder);
     }
 
@@ -77,4 +83,6 @@
 VectorNormalizeGen(): this routine returns a psVector with "x" elements.  The
 values of the vector will be scaled uniformly between -1.0 and 1.0.
+ 
+XXX: use a static vector.
 *****************************************************************************/
 psVector* VectorNormalizeGen(int x)
@@ -100,4 +108,5 @@
  
 XXX: This algorithm is derived from the Numerical Recipes.
+XXX: use recyvled vectors for internal data.
  *****************************************************************************/
 float *CalculateSecondDerivs(const psVector* restrict x,        ///< Ordinates (or NULL to just use the indices)
@@ -119,12 +128,4 @@
     float qn;
 
-    if (x == NULL) {
-        X = (float *) psAlloc(n * sizeof(float));
-        for(i=0;i<n;i++) {
-            X[i] = (float) i;
-        }
-        mustFreeX = true;
-    }
-
     // XXX: The second derivatives at the endpoints, undefined in the SDR,
     // are set in psConstants.h: LEFT_SPLINE_DERIV, RIGHT_SPLINE_DERIV.
@@ -167,5 +168,4 @@
     return(derivs2);
 }
-
 
 /******************************************************************************
@@ -212,5 +212,4 @@
 }
 
-
 /*****************************************************************************/
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
@@ -258,17 +257,40 @@
     int i;
     float slope;
-
-    if (mySpline == NULL) {
-        //XXX psErrorMsg()
-    }
-    if (y == NULL) {
-        //XXX psErrorMsg()
-    }
+    psVector *x32 = NULL;
+    psVector *y32 = NULL;
+    psVector *yErr32 = NULL;
+    static psVector *x32Static = NULL;
+    static psVector *y32Static = NULL;
+    static psVector *yErr32Static = NULL;
+
+    PS_CHECK_NULL_PTR_RETURN_NULL(mySpline);
+    PS_CHECK_NULL_PTR_RETURN_NULL(y);
+    VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y);
+    CONVERT_VECTOR_F64_TO_F32(y, y32, y32Static);
+
+    // If yErr==NULL, set all errors equal.
+    if (yErr == NULL) {
+        GEN_PERSIST_YERR_VEC_F32(yErr32Static, y->n);
+        yErr32 = yErr32Static;
+    } else {
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr);
+        CONVERT_VECTOR_F64_TO_F32(yErr, yErr32, yErr32Static);
+    }
+
+    // If x==NULL, create an x32 vector with x values set to (0:n).
+    if (x == NULL) {
+        GEN_PERSIST_X_INDEX_VEC_F32(x32Static, y->n);
+        x32 = x32Static;
+    } else {
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x);
+        CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static);
+    }
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x, y);
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr, y);
 
     if (y->n != (1 + mySpline->n)) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "data size / spline size mismatch (%d %d)\n",
-                 y->n, mySpline->n);
-        // XXX: psErrorMsg()
+        psError(__func__, "data size / spline size mismatch (%d %d)\n",
+                y->n, mySpline->n);
+        return(NULL);
     }
 
@@ -295,8 +317,6 @@
     // Check if these are cubic splines (n==4).  If not, psError.
     if (4 != (mySpline->spline[0])->n) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "Don't know how to generate %d-order splines.",
-                 (mySpline->spline[0])->n-1);
-        // XXX: psErrorMsg()
+        psError(__func__, "Don't know how to generate %d-order splines.",
+                (mySpline->spline[0])->n-1);
         return(NULL);
     }
@@ -315,5 +335,5 @@
         H = x->data.F32[i+1] - x->data.F32[i];
         psTrace(".psLib.dataManip.psVectorFitSpline1D", 4,
-                "X data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
+                "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
         //
         // ******** Calculate 0-order term ********
@@ -630,11 +650,4 @@
 }
 
-#define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \
-static psVector *NAME = NULL; \
-NAME = psVectorRecycle(NAME, SIZE, TYPE); \
-p_psMemSetPersistent(NAME, true); \
-p_psMemSetPersistent(NAME->data.V, true); \
-
-
 /******************************************************************************
 p_psVectorFitPolynomial1DCheb():  This routine will fit a Chebyshev
@@ -854,7 +867,7 @@
     int i;
     psPolynomial1D *tmpPoly;
-    PS_CHECK_NULL_1DPOLY_ACTION(myPoly, 0);
-    PS_CHECK_NULL_VECTOR_ACTION(y, 0);
-    PS_CHECK_EMPTY_VECTOR_ACTION(y, 0);
+    PS_CHECK_NULL_1DPOLY_RETURN_NULL(myPoly);
+    PS_CHECK_NULL_VECTOR_RETURN_NULL(y);
+    PS_CHECK_EMPTY_VECTOR_RETURN_NULL(y);
     psVector *x64 = NULL;
     psVector *y64 = NULL;
@@ -864,82 +877,33 @@
     static psVector *yErr64Static = NULL;
 
-    if (y->type.type == PS_TYPE_F64) {
-        y64 = (psVector *) y;
-    } else if (y->type.type == PS_TYPE_F32) {
-        y64Static = psVectorRecycle(y64Static, y->n, PS_TYPE_F64);
-        p_psMemSetPersistent(y64Static, true);
-        p_psMemSetPersistent(y64Static->data.V, true);
-        y64 = y64Static;
-    } else {
-        // XXX: psError() bad type.
-        psAbort(__func__, "Bad type for y64 (%d)", y->type.type);
-    }
-
+    VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y);
+    CONVERT_VECTOR_F32_TO_F64(y, y64, y64Static);
 
     // If yErr==NULL, set all errors equal.
     if (yErr == NULL) {
-        yErr64Static = psVectorRecycle(yErr64Static, y->n, PS_TYPE_F64);
-        p_psMemSetPersistent(yErr64Static, true);
-        p_psMemSetPersistent(yErr64Static->data.V, true);
-
-        for (i=0;i<yErr64Static->n;i++) {
-            yErr64Static->data.F64[i] = 1.0;
-        }
+        GEN_PERSIST_YERR_VEC_F64(yErr64Static, y->n);
         yErr64 = yErr64Static;
     } else {
-        if (yErr->type.type == PS_TYPE_F64) {
-            yErr64 = (psVector *) yErr;
-        } else if (yErr->type.type == PS_TYPE_F32) {
-            yErr64Static = psVectorRecycle(yErr64Static, yErr->n, PS_TYPE_F64);
-            p_psMemSetPersistent(yErr64Static, true);
-            p_psMemSetPersistent(yErr64Static->data.V, true);
-        } else {
-            // XXX: psError() bad type.
-            psAbort(__func__, "Bad type for yErr64");
-        }
-    }
-
-    // If x==NULL, create an x64 vector with x values set to (0:n), and if
-    // this is a Chebyshev polynomial, we must scale to (-1:1).
-    // XXX: Verify that this is the correct action.
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr);
+        CONVERT_VECTOR_F32_TO_F64(yErr, yErr64, yErr64Static);
+    }
+
+    // If x==NULL, create an x64 vector with x values set to (0:n).
     if (x == NULL) {
-        x64Static = psVectorRecycle(x64Static, y->n, PS_TYPE_F64);
-        p_psMemSetPersistent(x64Static, true);
-        p_psMemSetPersistent(x64Static->data.V, true);
+        GEN_PERSIST_X_INDEX_VEC_F64(x64Static, y->n);
+        if (myPoly->type == PS_POLYNOMIAL_CHEB) {
+            p_psNormalizeVector(x64Static);
+        }
         x64 = x64Static;
-
-        if (myPoly->type == PS_POLYNOMIAL_ORD) {
-            for (i=0;i<x64->n;i++) {
-                x64->data.F64[i] = (float) i;
-            }
-        } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
-            double min = 0.0;
-            double max = (double) (y->n - 1);
-
-            for (i=0;i<x64->n;i++) {
-                x64->data.F64[i] = (((double) i) - 0.5 * (min + max)) /
-                                   (0.5 * (max - min));
-            }
-        }
     } else {
-        if (x->type.type == PS_TYPE_F64) {
-            x64 = (psVector *) x;
-        } else if (x->type.type == PS_TYPE_F32) {
-            x64Static = psVectorRecycle(x64Static, x->n, PS_TYPE_F64);
-            p_psMemSetPersistent(x64Static, true);
-            p_psMemSetPersistent(x64Static->data.V, true);
-            x64 = x64Static;
-        } else {
-            // XXX: psError() bad type.
-            psAbort(__func__, "Bad type for x64");
-        }
-    }
-
-    PS_CHECK_VECTOR_SIZE_EQUAL(y64, x64);
-    PS_CHECK_VECTOR_SIZE_EQUAL(y64, yErr64);
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x);
+        CONVERT_VECTOR_F32_TO_F64(x, x64, x64Static);
+    }
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x64, y64);
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr64, y64);
 
     // Call the appropriate vector fitting routine.
     if (myPoly->type == PS_POLYNOMIAL_CHEB) {
-        tmpPoly = p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
+        p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
     } else if (myPoly->type == PS_POLYNOMIAL_ORD) {
         tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
@@ -948,17 +912,4 @@
         return(NULL);
     }
-
-    // Free any allocated memory.
-    /*
-        if ((yErr == NULL) || (yErr->type.type != PS_TYPE_F64)) {
-            psFree(yErr64);
-        }
-        if ((x == NULL) || (x->type.type != PS_TYPE_F64)) {
-            psFree(x64);
-        }
-        if ((y == NULL) || (y->type.type != PS_TYPE_F64)) {
-            psFree(y64);
-        }
-    */
 
     return(myPoly);
Index: /trunk/psLib/src/dataManip/psMinimize.h
===================================================================
--- /trunk/psLib/src/dataManip/psMinimize.h	(revision 1962)
+++ /trunk/psLib/src/dataManip/psMinimize.h	(revision 1963)
@@ -8,6 +8,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-05 01:43:58 $
+ *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,4 +28,5 @@
 #include "psMatrix.h"
 #include "psFunctions.h"
+#include "psStats.h"
 #include "psTrace.h"
 #include "psLogMsg.h"
Index: /trunk/psLib/src/dataManip/psStats.c
===================================================================
--- /trunk/psLib/src/dataManip/psStats.c	(revision 1962)
+++ /trunk/psLib/src/dataManip/psStats.c	(revision 1963)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-29 19:52:53 $
+ *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -836,8 +836,8 @@
 
 /*****************************************************************************
-p_psNormalizeVector(myData): this is a private function which normalizes the
+p_psNormalizeVectorF32(myData): this is a private function which normalizes the
 elements of a vector to a range between 0.0 and 1.0.
  *****************************************************************************/
-void p_psNormalizeVector(psVector* myData)
+void p_psNormalizeVectorF32(psVector* myData)
 {
     float min = (float)HUGE;
@@ -867,14 +867,11 @@
 p_psNormalizeVectorF64(myData): this is a private function which normalizes the
 elements of a vector to a range between -1.0 and 1.0.
- 
-XXX: incorporate this into above
- 
 XXX: 0-1 or -1:1?
  *****************************************************************************/
 void p_psNormalizeVectorF64(psVector* myData)
 {
-    float min = (float)HUGE;
-    float max = (float)-HUGE;
-    float range = 0.0;
+    float min = (double)HUGE;
+    float max = (double)-HUGE;
+    double range = 0.0;
     int i = 0;
 
@@ -892,4 +889,20 @@
         myData->data.F64[i] = -1.0 + 2.0 *
                               ((myData->data.F64[i] - min) / range);
+    }
+
+    //    for (i = 0; i < myData->n; i++) {
+    //        myData->data.F64[i] = (myData->data.F64[i] - 0.5 * (min + max)) /
+    //                              (0.5 * (max - min));
+    //    }
+}
+
+void p_psNormalizeVector(psVector* myData)
+{
+    if (myData->type.type == PS_TYPE_F32) {
+        p_psNormalizeVectorF32(myData);
+    } else if (myData->type.type == PS_TYPE_F64) {
+        p_psNormalizeVectorF64(myData);
+    } else {
+        psError(__func__, "Unalowable data type.\n");
     }
 }
@@ -1191,5 +1204,5 @@
     // The following was necessary to fit a gaussian to the data, since
     // gaussian functions produce data between 0.0 and 1.0.
-    // p_psNormalizeVector(robustHistogramVector);
+    // p_psNormalizeVectorF32(robustHistogramVector);
 
     /**************************************************************************
Index: /trunk/psLib/src/dataManip/psStats.h
===================================================================
--- /trunk/psLib/src/dataManip/psStats.h	(revision 1962)
+++ /trunk/psLib/src/dataManip/psStats.h	(revision 1963)
@@ -10,6 +10,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-27 23:41:42 $
+ *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -176,6 +176,4 @@
 
 void p_psNormalizeVector(psVector* myData);
-void p_psNormalizeVectorF64(psVector* myData);
-
 
 /// @}
Index: /trunk/psLib/src/math/psConstants.h
===================================================================
--- /trunk/psLib/src/math/psConstants.h	(revision 1962)
+++ /trunk/psLib/src/math/psConstants.h	(revision 1963)
@@ -6,6 +6,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-05 01:43:58 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,68 @@
 #define RIGHT_SPLINE_DERIV 0.0
 
+#define CONVERT_VECTOR_F64_TO_F32(OLD, NEW_PTR32, NEW_STATIC32) \
+if (OLD->type.type == PS_TYPE_F32) { \
+    NEW_PTR32 = (psVector *) OLD; \
+} else if (OLD->type.type == PS_TYPE_F64) { \
+    NEW_STATIC32 = psVectorRecycle(NEW_STATIC32, OLD->n, PS_TYPE_F32); \
+    p_psMemSetPersistent(NEW_STATIC32, true); \
+    p_psMemSetPersistent(NEW_STATIC32->data.V, true); \
+    for (i=0; i < OLD->n ; i++) { \
+        NEW_STATIC32->data.F32[i] = (float) OLD->data.F64[i]; \
+    } \
+    NEW_PTR32 = NEW_STATIC32; \
+} \
+
+#define CONVERT_VECTOR_F32_TO_F64(OLD, NEW_PTR64, NEW_STATIC64) \
+if (OLD->type.type == PS_TYPE_F64) { \
+    NEW_PTR64 = (psVector *) OLD; \
+} else if (OLD->type.type == PS_TYPE_F32) { \
+    NEW_STATIC64 = psVectorRecycle(NEW_STATIC64, OLD->n, PS_TYPE_F64); \
+    p_psMemSetPersistent(NEW_STATIC64, true); \
+    p_psMemSetPersistent(NEW_STATIC64->data.V, true); \
+    for (i=0; i < OLD->n ; i++) { \
+        NEW_STATIC64->data.F64[i] = (double) OLD->data.F32[i]; \
+    } \
+    NEW_PTR64 = NEW_STATIC64; \
+} \
+
+#define VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(VEC) \
+if ((VEC->type.type != PS_TYPE_F32) && (VEC->type.type != PS_TYPE_F64)) { \
+    psAbort(__func__, "Bad type for VEC (%d)", VEC->type.type); \
+    return(NULL); \
+} \
+
+#define GEN_PERSIST_YERR_VEC_F32(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F32[i] = 1.0; \
+} \
+
+#define GEN_PERSIST_YERR_VEC_F64(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F64[i] = 1.0; \
+} \
+
+#define GEN_PERSIST_X_INDEX_VEC_F32(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F32); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F32[i] = (float) i; \
+} \
+
+#define GEN_PERSIST_X_INDEX_VEC_F64(VEC, N) \
+VEC = psVectorRecycle(VEC, N, PS_TYPE_F64); \
+p_psMemSetPersistent(VEC, true); \
+p_psMemSetPersistent(VEC->data.V, true); \
+for (int i=0;i<N;i++) { \
+    VEC->data.F64[i] = (float) i; \
+} \
+
 #define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \
 static psVector *NAME = NULL; \
@@ -23,7 +87,4 @@
 p_psMemSetPersistent(NAME, true); \
 p_psMemSetPersistent(NAME->data.V, true); \
-
-
-
 
 /** Preprocessor macro to generate error on an incorrect type */
@@ -51,8 +112,22 @@
 }
 
+/** Preprocessor macro to generate error on a NULL vector */
+#define PS_CHECK_NULL_VECTOR_RETURN_NULL(NAME) \
+if (NAME == NULL || NAME->data.V == NULL) { \
+    psError(__func__,"Unallowable operation: %s or its data is NULL.", #NAME); \
+    return(NULL); \
+} \
+
 /** Preprocessor macro to generate error on a NULL poniter */
 #define PS_CHECK_NULL_PTR(NAME) \
 if (NAME == NULL) { \
     psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \
+}
+
+/** Preprocessor macro to generate error on a NULL poniter */
+#define PS_CHECK_NULL_PTR_RETURN_NULL(NAME) \
+if (NAME == NULL) { \
+    psError(__func__,"Unallowable operation: %s is NULL.", #NAME); \
+    return(NULL); \
 }
 
@@ -75,8 +150,22 @@
 }
 
+/** Preprocessor macro to generate error for zero length vector */
+#define PS_CHECK_EMPTY_VECTOR_RETURN_NULL(NAME) \
+if (NAME->n < 1) { \
+    psError(__func__,"Unallowable operation: %s has zero n value.", #NAME); \
+    return(NULL); \
+} \
+
 /** Preprocessor macro to generate error on differing size vectors */
 #define PS_CHECK_VECTOR_SIZE_EQUAL(VEC1, VEC2) \
 if (VEC1->n != VEC2->n) { \
     psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
+}
+
+/** Preprocessor macro to generate error on differing size vectors */
+#define PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(VEC1, VEC2) \
+if (VEC1->n != VEC2->n) { \
+    psError(__func__,"Vector %s has size %d, Vector %s has size %d.", #VEC1, VEC1->n, #VEC2, VEC2->n); \
+    return(NULL); \
 }
 
@@ -112,4 +201,10 @@
 }
 
+#define PS_CHECK_NULL_1DPOLY_RETURN_NULL(NAME)                                                          \
+if (NAME == NULL || NAME->coeff == NULL) {                                                         \
+    psError(__func__,"Unallowable operation: %s or its coeffs is NULL.", #NAME);                          \
+    return(NULL); \
+} \
+
 #define PS_PRINT_VECTOR(NAME) \
 for (int my_i=0;my_i<NAME->n;my_i++) { \
Index: /trunk/psLib/src/math/psMinimize.c
===================================================================
--- /trunk/psLib/src/math/psMinimize.c	(revision 1962)
+++ /trunk/psLib/src/math/psMinimize.c	(revision 1963)
@@ -9,6 +9,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.52 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-05 01:43:58 $
+ *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -56,4 +56,5 @@
  
 XXX: change name
+XXX: Use a static vector.
  *****************************************************************************/
 void p_psBuildSums1D(double x,
@@ -63,6 +64,11 @@
     int i = 0;
     double xSum = 0.0;
+
     if (sums == NULL) {
         sums = psVectorAlloc(polyOrder, PS_TYPE_F64);
+    }
+
+    if (polyOrder > sums->n) {
+        sums = psVectorRealloc(sums, polyOrder);
     }
 
@@ -77,4 +83,6 @@
 VectorNormalizeGen(): this routine returns a psVector with "x" elements.  The
 values of the vector will be scaled uniformly between -1.0 and 1.0.
+ 
+XXX: use a static vector.
 *****************************************************************************/
 psVector* VectorNormalizeGen(int x)
@@ -100,4 +108,5 @@
  
 XXX: This algorithm is derived from the Numerical Recipes.
+XXX: use recyvled vectors for internal data.
  *****************************************************************************/
 float *CalculateSecondDerivs(const psVector* restrict x,        ///< Ordinates (or NULL to just use the indices)
@@ -119,12 +128,4 @@
     float qn;
 
-    if (x == NULL) {
-        X = (float *) psAlloc(n * sizeof(float));
-        for(i=0;i<n;i++) {
-            X[i] = (float) i;
-        }
-        mustFreeX = true;
-    }
-
     // XXX: The second derivatives at the endpoints, undefined in the SDR,
     // are set in psConstants.h: LEFT_SPLINE_DERIV, RIGHT_SPLINE_DERIV.
@@ -167,5 +168,4 @@
     return(derivs2);
 }
-
 
 /******************************************************************************
@@ -212,5 +212,4 @@
 }
 
-
 /*****************************************************************************/
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
@@ -258,17 +257,40 @@
     int i;
     float slope;
-
-    if (mySpline == NULL) {
-        //XXX psErrorMsg()
-    }
-    if (y == NULL) {
-        //XXX psErrorMsg()
-    }
+    psVector *x32 = NULL;
+    psVector *y32 = NULL;
+    psVector *yErr32 = NULL;
+    static psVector *x32Static = NULL;
+    static psVector *y32Static = NULL;
+    static psVector *yErr32Static = NULL;
+
+    PS_CHECK_NULL_PTR_RETURN_NULL(mySpline);
+    PS_CHECK_NULL_PTR_RETURN_NULL(y);
+    VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y);
+    CONVERT_VECTOR_F64_TO_F32(y, y32, y32Static);
+
+    // If yErr==NULL, set all errors equal.
+    if (yErr == NULL) {
+        GEN_PERSIST_YERR_VEC_F32(yErr32Static, y->n);
+        yErr32 = yErr32Static;
+    } else {
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr);
+        CONVERT_VECTOR_F64_TO_F32(yErr, yErr32, yErr32Static);
+    }
+
+    // If x==NULL, create an x32 vector with x values set to (0:n).
+    if (x == NULL) {
+        GEN_PERSIST_X_INDEX_VEC_F32(x32Static, y->n);
+        x32 = x32Static;
+    } else {
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x);
+        CONVERT_VECTOR_F64_TO_F32(x, x32, x32Static);
+    }
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x, y);
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr, y);
 
     if (y->n != (1 + mySpline->n)) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "data size / spline size mismatch (%d %d)\n",
-                 y->n, mySpline->n);
-        // XXX: psErrorMsg()
+        psError(__func__, "data size / spline size mismatch (%d %d)\n",
+                y->n, mySpline->n);
+        return(NULL);
     }
 
@@ -295,8 +317,6 @@
     // Check if these are cubic splines (n==4).  If not, psError.
     if (4 != (mySpline->spline[0])->n) {
-        psLogMsg(__func__, PS_LOG_WARN,
-                 "Don't know how to generate %d-order splines.",
-                 (mySpline->spline[0])->n-1);
-        // XXX: psErrorMsg()
+        psError(__func__, "Don't know how to generate %d-order splines.",
+                (mySpline->spline[0])->n-1);
         return(NULL);
     }
@@ -315,5 +335,5 @@
         H = x->data.F32[i+1] - x->data.F32[i];
         psTrace(".psLib.dataManip.psVectorFitSpline1D", 4,
-                "X data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
+                "x data (%f - %f) (%f)\n", x->data.F32[i], x->data.F32[i+1], H);
         //
         // ******** Calculate 0-order term ********
@@ -630,11 +650,4 @@
 }
 
-#define GEN_STATIC_RECYCLED_VECTOR(NAME, SIZE, TYPE) \
-static psVector *NAME = NULL; \
-NAME = psVectorRecycle(NAME, SIZE, TYPE); \
-p_psMemSetPersistent(NAME, true); \
-p_psMemSetPersistent(NAME->data.V, true); \
-
-
 /******************************************************************************
 p_psVectorFitPolynomial1DCheb():  This routine will fit a Chebyshev
@@ -854,7 +867,7 @@
     int i;
     psPolynomial1D *tmpPoly;
-    PS_CHECK_NULL_1DPOLY_ACTION(myPoly, 0);
-    PS_CHECK_NULL_VECTOR_ACTION(y, 0);
-    PS_CHECK_EMPTY_VECTOR_ACTION(y, 0);
+    PS_CHECK_NULL_1DPOLY_RETURN_NULL(myPoly);
+    PS_CHECK_NULL_VECTOR_RETURN_NULL(y);
+    PS_CHECK_EMPTY_VECTOR_RETURN_NULL(y);
     psVector *x64 = NULL;
     psVector *y64 = NULL;
@@ -864,82 +877,33 @@
     static psVector *yErr64Static = NULL;
 
-    if (y->type.type == PS_TYPE_F64) {
-        y64 = (psVector *) y;
-    } else if (y->type.type == PS_TYPE_F32) {
-        y64Static = psVectorRecycle(y64Static, y->n, PS_TYPE_F64);
-        p_psMemSetPersistent(y64Static, true);
-        p_psMemSetPersistent(y64Static->data.V, true);
-        y64 = y64Static;
-    } else {
-        // XXX: psError() bad type.
-        psAbort(__func__, "Bad type for y64 (%d)", y->type.type);
-    }
-
+    VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(y);
+    CONVERT_VECTOR_F32_TO_F64(y, y64, y64Static);
 
     // If yErr==NULL, set all errors equal.
     if (yErr == NULL) {
-        yErr64Static = psVectorRecycle(yErr64Static, y->n, PS_TYPE_F64);
-        p_psMemSetPersistent(yErr64Static, true);
-        p_psMemSetPersistent(yErr64Static->data.V, true);
-
-        for (i=0;i<yErr64Static->n;i++) {
-            yErr64Static->data.F64[i] = 1.0;
-        }
+        GEN_PERSIST_YERR_VEC_F64(yErr64Static, y->n);
         yErr64 = yErr64Static;
     } else {
-        if (yErr->type.type == PS_TYPE_F64) {
-            yErr64 = (psVector *) yErr;
-        } else if (yErr->type.type == PS_TYPE_F32) {
-            yErr64Static = psVectorRecycle(yErr64Static, yErr->n, PS_TYPE_F64);
-            p_psMemSetPersistent(yErr64Static, true);
-            p_psMemSetPersistent(yErr64Static->data.V, true);
-        } else {
-            // XXX: psError() bad type.
-            psAbort(__func__, "Bad type for yErr64");
-        }
-    }
-
-    // If x==NULL, create an x64 vector with x values set to (0:n), and if
-    // this is a Chebyshev polynomial, we must scale to (-1:1).
-    // XXX: Verify that this is the correct action.
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(yErr);
+        CONVERT_VECTOR_F32_TO_F64(yErr, yErr64, yErr64Static);
+    }
+
+    // If x==NULL, create an x64 vector with x values set to (0:n).
     if (x == NULL) {
-        x64Static = psVectorRecycle(x64Static, y->n, PS_TYPE_F64);
-        p_psMemSetPersistent(x64Static, true);
-        p_psMemSetPersistent(x64Static->data.V, true);
+        GEN_PERSIST_X_INDEX_VEC_F64(x64Static, y->n);
+        if (myPoly->type == PS_POLYNOMIAL_CHEB) {
+            p_psNormalizeVector(x64Static);
+        }
         x64 = x64Static;
-
-        if (myPoly->type == PS_POLYNOMIAL_ORD) {
-            for (i=0;i<x64->n;i++) {
-                x64->data.F64[i] = (float) i;
-            }
-        } else if (myPoly->type == PS_POLYNOMIAL_CHEB) {
-            double min = 0.0;
-            double max = (double) (y->n - 1);
-
-            for (i=0;i<x64->n;i++) {
-                x64->data.F64[i] = (((double) i) - 0.5 * (min + max)) /
-                                   (0.5 * (max - min));
-            }
-        }
     } else {
-        if (x->type.type == PS_TYPE_F64) {
-            x64 = (psVector *) x;
-        } else if (x->type.type == PS_TYPE_F32) {
-            x64Static = psVectorRecycle(x64Static, x->n, PS_TYPE_F64);
-            p_psMemSetPersistent(x64Static, true);
-            p_psMemSetPersistent(x64Static->data.V, true);
-            x64 = x64Static;
-        } else {
-            // XXX: psError() bad type.
-            psAbort(__func__, "Bad type for x64");
-        }
-    }
-
-    PS_CHECK_VECTOR_SIZE_EQUAL(y64, x64);
-    PS_CHECK_VECTOR_SIZE_EQUAL(y64, yErr64);
+        VECTOR_CHECK_TYPE_F32_OR_F64_RETURN_NULL(x);
+        CONVERT_VECTOR_F32_TO_F64(x, x64, x64Static);
+    }
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(x64, y64);
+    PS_CHECK_VECTOR_SIZE_EQUAL_RETURN_NULL(yErr64, y64);
 
     // Call the appropriate vector fitting routine.
     if (myPoly->type == PS_POLYNOMIAL_CHEB) {
-        tmpPoly = p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
+        p_psVectorFitPolynomial1DCheby(myPoly, x64, y64, yErr64);
     } else if (myPoly->type == PS_POLYNOMIAL_ORD) {
         tmpPoly = p_psVectorFitPolynomial1DOrd(myPoly, x64, y64, yErr64);
@@ -948,17 +912,4 @@
         return(NULL);
     }
-
-    // Free any allocated memory.
-    /*
-        if ((yErr == NULL) || (yErr->type.type != PS_TYPE_F64)) {
-            psFree(yErr64);
-        }
-        if ((x == NULL) || (x->type.type != PS_TYPE_F64)) {
-            psFree(x64);
-        }
-        if ((y == NULL) || (y->type.type != PS_TYPE_F64)) {
-            psFree(y64);
-        }
-    */
 
     return(myPoly);
Index: /trunk/psLib/src/math/psMinimize.h
===================================================================
--- /trunk/psLib/src/math/psMinimize.h	(revision 1962)
+++ /trunk/psLib/src/math/psMinimize.h	(revision 1963)
@@ -8,6 +8,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-05 01:43:58 $
+ *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,4 +28,5 @@
 #include "psMatrix.h"
 #include "psFunctions.h"
+#include "psStats.h"
 #include "psTrace.h"
 #include "psLogMsg.h"
Index: /trunk/psLib/src/math/psStats.c
===================================================================
--- /trunk/psLib/src/math/psStats.c	(revision 1962)
+++ /trunk/psLib/src/math/psStats.c	(revision 1963)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-29 19:52:53 $
+ *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -836,8 +836,8 @@
 
 /*****************************************************************************
-p_psNormalizeVector(myData): this is a private function which normalizes the
+p_psNormalizeVectorF32(myData): this is a private function which normalizes the
 elements of a vector to a range between 0.0 and 1.0.
  *****************************************************************************/
-void p_psNormalizeVector(psVector* myData)
+void p_psNormalizeVectorF32(psVector* myData)
 {
     float min = (float)HUGE;
@@ -867,14 +867,11 @@
 p_psNormalizeVectorF64(myData): this is a private function which normalizes the
 elements of a vector to a range between -1.0 and 1.0.
- 
-XXX: incorporate this into above
- 
 XXX: 0-1 or -1:1?
  *****************************************************************************/
 void p_psNormalizeVectorF64(psVector* myData)
 {
-    float min = (float)HUGE;
-    float max = (float)-HUGE;
-    float range = 0.0;
+    float min = (double)HUGE;
+    float max = (double)-HUGE;
+    double range = 0.0;
     int i = 0;
 
@@ -892,4 +889,20 @@
         myData->data.F64[i] = -1.0 + 2.0 *
                               ((myData->data.F64[i] - min) / range);
+    }
+
+    //    for (i = 0; i < myData->n; i++) {
+    //        myData->data.F64[i] = (myData->data.F64[i] - 0.5 * (min + max)) /
+    //                              (0.5 * (max - min));
+    //    }
+}
+
+void p_psNormalizeVector(psVector* myData)
+{
+    if (myData->type.type == PS_TYPE_F32) {
+        p_psNormalizeVectorF32(myData);
+    } else if (myData->type.type == PS_TYPE_F64) {
+        p_psNormalizeVectorF64(myData);
+    } else {
+        psError(__func__, "Unalowable data type.\n");
     }
 }
@@ -1191,5 +1204,5 @@
     // The following was necessary to fit a gaussian to the data, since
     // gaussian functions produce data between 0.0 and 1.0.
-    // p_psNormalizeVector(robustHistogramVector);
+    // p_psNormalizeVectorF32(robustHistogramVector);
 
     /**************************************************************************
Index: /trunk/psLib/src/math/psStats.h
===================================================================
--- /trunk/psLib/src/math/psStats.h	(revision 1962)
+++ /trunk/psLib/src/math/psStats.h	(revision 1963)
@@ -10,6 +10,6 @@
  *  @author George Gusciora, MHPCC
  *
- *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-27 23:41:42 $
+ *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-05 22:47:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -176,6 +176,4 @@
 
 void p_psNormalizeVector(psVector* myData);
-void p_psNormalizeVectorF64(psVector* myData);
-
 
 /// @}
