Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 2227)
+++ trunk/psLib/src/math/psStats.c	(revision 2228)
@@ -9,7 +9,7 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.79 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-28 00:46:04 $
-n *
+ *  @version $Revision: 1.80 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-28 22:46:57 $
+ *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  */
@@ -123,22 +123,4 @@
     default:
         return false;
-    }
-}
-
-/*****************************************************************************
-p_psVectorPrint(myVector, maskVector, maskVal, stats): a private internal
-function that simply prints a vector to STDOUT.  Used primarily for
-debugging.
- *****************************************************************************/
-
-void p_psVectorPrint(psVector* myVector, psVector* maskVector, psU32 maskVal, psStats* stats)
-{
-    psS32 i = 0;                  // Loop index variable.
-
-    for (i = 0; i < myVector->n; i++) {
-        if (maskVector != NULL)
-            printf("Element %d is %f (mask is %d)\n", i, myVector->data.F32[i], maskVector->data.U8[i]);
-        else
-            printf("Element %d is %f\n", i, myVector->data.F32[i]);
     }
 }
@@ -428,8 +410,5 @@
     // Allocate temporary vectors for the data.
     unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
-    unsortedVector->n = unsortedVector->nalloc;
-
     sortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
-    sortedVector->n = sortedVector->nalloc;
 
     // Determine if we must only use data points within a min/max range.
@@ -579,7 +558,5 @@
     // Allocate temporary vectors for the data.
     unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
-    unsortedVector->n = unsortedVector->nalloc;
     sortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
-    sortedVector->n = sortedVector->nalloc;
 
     // Determine if we must only use data points within a min/max range.
@@ -817,4 +794,6 @@
 p_psNormalizeVectorF32(myData): this is a private function which normalizes the
 elements of a vector to a range between 0.0 and 1.0.
+ 
+XXX: how about an arbitrary p_psNormalizeVectorF32(myData, min, max)?
  *****************************************************************************/
 void p_psNormalizeVectorF32(psVector* myData)
@@ -847,4 +826,6 @@
 elements of a vector to a range between -1.0 and 1.0.
 XXX: 0-1 or -1:1?
+ 
+XXX: how about an arbitrary p_psNormalizeVectorF64(myData, min, max)?
  *****************************************************************************/
 void p_psNormalizeVectorF64(psVector* myData)
@@ -876,4 +857,5 @@
 }
 
+// XXX: how about an arbitrary p_psNormalizeVector(myData, min, max)?
 void p_psNormalizeVector(psVector* myData)
 {
@@ -885,87 +867,4 @@
         psError(__func__, "Unalowable data type.\n");
     }
-}
-
-/*****************************************************************************
-p_psGaussian(myData, myParams): an internal function, used by robust stats,
-intended to compute the Gaussian with a specified sigma/mean, at the
-specified data point.
- *****************************************************************************/
-float p_psGaussian(const psVector* restrict myData,
-                   const psVector* restrict myParams)
-{
-    float x = myData->data.F32[0];
-    float mean = myParams->data.F32[0];
-    float stdev = myParams->data.F32[1];
-    float tmp = exp(-((x - mean) * (x - mean)) / (2.0 * stdev * stdev));
-
-    tmp /= ((float)sqrt(2.0 * M_PI * (stdev * stdev)));
-
-    // printf("p_psGaussian((%.2f), %.2f, %.2f) is %.2f\n", x, mean, stdev, tmp);
-    return (tmp);
-}
-
-/*****************************************************************************
-p_psGaussianDeriv(myData, myParams, whichParam): an internal function, which
-calculates the specified partial derivative of the above Gaussian function.
- *****************************************************************************/
-float p_psGaussianDeriv(const psVector* restrict myData,
-                        const psVector* restrict myParams, psS32 whichParam)
-{
-    float x = myData->data.F32[0];
-    float mean = myParams->data.F32[0];
-    float stdev = myParams->data.F32[1];
-    float tmp = 0.0;
-
-    if (whichParam == 0) {
-        // Return the derivative w.r.t. the mean.
-        tmp = (x - mean) * p_psGaussian(myData, myParams);
-        tmp /= (stdev * stdev);
-    } else if (whichParam == 1) {
-        // Return the derivative w.r.t. the stdev.
-        tmp = (x - mean) * (x - mean) * p_psGaussian(myData, myParams);
-        tmp /= (stdev * stdev * stdev);
-    }
-    printf("p_psGaussianDeriv((%.2f), %.2f, %.2f, (%d)) is %.2f\n", x, mean, stdev, whichParam, tmp);
-
-    return (tmp);
-}
-
-/*****************************************************************************
-p_psQuadratic(myData, myParams): an internal function, used by robust stats,
-intended to compute a quadratic, with the specified parameters, at the
-specified data point.
- *****************************************************************************/
-float p_psQuadratic(const psVector* restrict myParams, const psVector* restrict myCoords)
-{
-    float x = myCoords->data.F32[0];
-    float A = myParams->data.F32[0];
-    float B = myParams->data.F32[1];
-    float C = myParams->data.F32[2];
-    float tmp = 0.0;
-
-    tmp = (A * x * x) + (B * x) + C;
-    return (tmp);
-}
-
-/*****************************************************************************
-p_psQuadraticDeriv(myData, myParams, whichParam): an internal function, which
-calculates the specified partial derivative of the above quadratic function.
- *****************************************************************************/
-float p_psQuadraticDeriv(const psVector* restrict myParams,
-                         const psVector* restrict myCoords, psS32 whichParamDeriv)
-{
-    float x = myCoords->data.F32[0];
-    float tmp = 0.0;
-
-    if (whichParamDeriv == 0) {
-        tmp = x * x;
-    } else if (whichParamDeriv == 1) {
-        tmp = x;
-    } else if (whichParamDeriv == 2) {
-        tmp = 1.0;
-    }
-
-    return (tmp);
 }
 
@@ -1022,6 +921,4 @@
 and i+1 is used for x[i]).  It then determines for what value x does that
 quadratic f(x) = yVal (the input parameter).
- 
-// XXX: Use static variables.
 *****************************************************************************/
 float fitQuadraticSearchForYThenReturnX(psVector *xVec,
@@ -1030,26 +927,13 @@
                                         float yVal)
 {
-    //    static psVector* x = NULL;
-    //    static psVector* y = NULL;
-    //    static psVector* yErr = NULL;
-    psVector* x = psVectorAlloc(3, PS_TYPE_F64);
-    psVector* y = psVectorAlloc(3, PS_TYPE_F64);
-    psVector* yErr = psVectorAlloc(3, PS_TYPE_F64);
-
-    /*
-        if (x == NULL) {
-            x = psVectorAlloc(3, PS_TYPE_F64);
-            p_psMemSetPersistent(x, true);
-        }
-        if (y == NULL) {
-            y = psVectorAlloc(3, PS_TYPE_F64);
-            p_psMemSetPersistent(y, true);
-        }
-        if (yErr == NULL) {
-            yErr = psVectorAlloc(3, PS_TYPE_F64);
-            p_psMemSetPersistent(yErr, true);
-        }
-    */
-    psPolynomial1D* myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
+    PS_VECTOR_DECLARE_ALLOC_STATIC(x, 3, PS_TYPE_F64);
+    PS_VECTOR_DECLARE_ALLOC_STATIC(y, 3, PS_TYPE_F64);
+    PS_VECTOR_DECLARE_ALLOC_STATIC(yErr, 3, PS_TYPE_F64);
+    static psPolynomial1D* myPoly = NULL;
+
+    if (myPoly == NULL) {
+        myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
+        p_psMemSetPersistent(myPoly, true);
+    }
     float tmpFloat;
 
@@ -1090,8 +974,4 @@
     }
 
-    psFree(x);
-    psFree(y);
-    psFree(yErr);
-    psFree(myPoly);
     return(tmpFloat);
 }
@@ -1475,5 +1355,5 @@
 
 /******************************************************************************
-psHistogramAllocGenric(bounds): allocate a non-uniform histogram structure
+psHistogramAllocGeneric(bounds): allocate a non-uniform histogram structure
 with the specifed bounds.
  
