Index: /trunk/psLib/src/dataManip/psMinimize.c
===================================================================
--- /trunk/psLib/src/dataManip/psMinimize.c	(revision 2264)
+++ /trunk/psLib/src/dataManip/psMinimize.c	(revision 2265)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-02 01:04:37 $
+ *  @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-02 03:57:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1361,5 +1361,5 @@
         min->value = func(params, coords);
         psTrace(".psLib.dataManip.p_psLineMin", 2,
-                "p_psLineMin() called with zero line vector.  Return 0.0.  Function valus is %f\n", min->value);
+                "p_psLineMin() called with zero line vector.  Return 0.0.  Function value is %f\n", min->value);
         return(0.0);
     }
@@ -1469,8 +1469,9 @@
 XXX: Define constants for default dummy number of iterations and tolerance.
  
-XXX: Must define behavior on various NULL inputs.
- 
 XXX: Check for F32 types?
  *****************************************************************************/
+#define PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS 20
+#define PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE 0.01
+
 psBool psMinimizePowell(psMinimization *min,
                         psVector *params,
@@ -1485,5 +1486,4 @@
     PS_PTR_CHECK_NULL(coords, NULL);
     PS_PTR_CHECK_NULL(func, NULL);
-
     psS32 numDims = params->n;
     PS_VECTOR_GEN_STATIC_RECYCLED(pQP, numDims, PS_TYPE_F32);
@@ -1492,6 +1492,5 @@
     psS32 i = 0;
     psS32 j = 0;
-    psVector **v = NULL;
-    psVector *myParamMask = NULL;  // XXX: Use a recylced vector here.
+    psVector *myParamMask = NULL;
     psMinimization dummyMin;
     float mul = 0.0;
@@ -1500,8 +1499,4 @@
     psS32 biggestIter = 0;
     float biggestDiff = 0.0;
-    float term1 = 0.0;
-    float term2 = 0.0;
-    float fqp = 0.0;
-    float diff = 0.0;
     int iterationNumber = 0;
 
@@ -1526,12 +1521,13 @@
 
     // 1: Set v[i] to be the unit vectors for each dimension in params
-    v = (psVector **) psAlloc(params->n * sizeof(psVector **));
+
+    psArray *v = psArrayAlloc(numDims);
     for (i=0;i<numDims;i++) {
-        v[i] = psVectorAlloc(numDims, PS_TYPE_F32);
+        (v->data[i]) = (psVector *) psVectorAlloc(numDims, PS_TYPE_F32);
         for (j=0;j<numDims;j++) {
             if (i == j) {
-                v[i]->data.F32[j] = 1.0;
+                ((psVector *) (v->data[i]))->data.F32[j] = 1.0;
             } else {
-                v[i]->data.F32[j] = 0.0;
+                ((psVector *) (v->data[i]))->data.F32[j] = 0.0;
             }
         }
@@ -1558,17 +1554,13 @@
                 "Current function value is %f\n", currFuncVal);
 
-        diff = 0.0;
         biggestDiff = 0;
         biggestIter = 0;
         for (i=0;i<numDims;i++) {
             if (myParamMask->data.U8[i] == 0) {
-                dummyMin.maxIter = 20;
-                dummyMin.tol = 0.01;
-                mul = p_psLineMin(&dummyMin, Q, v[i], myParamMask, coords, func);
+                dummyMin.maxIter = PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS;
+                dummyMin.tol = PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE;
+                mul = p_psLineMin(&dummyMin, Q, ((psVector *) v->data[i]), myParamMask, coords, func);
                 if (isnan(mul)) {
                     psError(__func__, "Could not perform line minimization (1).\n");
-                    for (j=0;j<numDims;j++) {
-                        psFree(v[j]);
-                    }
                     psFree(v);
                     return(false);
@@ -1608,10 +1600,7 @@
         }
 
-        mul = p_psLineMin(min, params, u, myParamMask, coords, func);
+        mul = p_psLineMin(&dummyMin, params, u, myParamMask, coords, func);
         if (isnan(mul)) {
             psError(__func__, "Could not perform line minimization. (2)\n");
-            for (i=0;i<numDims;i++) {
-                psFree(v[i]);
-            }
             psFree(v);
             return(false);
@@ -1619,8 +1608,5 @@
 
         // 6:
-        if (min->value > currFuncVal) {
-            for (i=0;i<numDims;i++) {
-                psFree(v[i]);
-            }
+        if (dummyMin.value > currFuncVal) {
             psFree(v);
             min->iter = iterationNumber;
@@ -1637,15 +1623,14 @@
             }
         }
-        fqp = func(pQP, coords);
-
-        term1 = (baseFuncVal - currFuncVal) - biggestDiff;
+        float fqp = func(pQP, coords);
+        float term1 = (baseFuncVal - currFuncVal) - biggestDiff;
         term1*= term1;
         term1*= 2.0 * (baseFuncVal - (2.0 * currFuncVal) + fqp);
-        term2 = baseFuncVal - fqp;
+        float term2 = baseFuncVal - fqp;
         term2*= term2 * biggestDiff;
         if (term1 < term2) {
             for (i=0;i<numDims;i++) {
                 if (myParamMask->data.U8[i] == 0) {
-                    v[biggestIter]->data.F32[i] = u->data.F32[i];
+                    ((psVector *) v->data[biggestIter])->data.F32[i] = u->data.F32[i];
                 }
             }
@@ -1661,7 +1646,4 @@
         // 8: Go to step 3 until the change is less than some tolerance.
         if (fabs(baseFuncVal - currFuncVal) <= min->tol) {
-            for (i=0;i<numDims;i++) {
-                psFree(v[i]);
-            }
             psFree(v);
             min->iter = iterationNumber;
@@ -1672,7 +1654,4 @@
     }
 
-    for (i=0;i<numDims;i++) {
-        psFree(v[i]);
-    }
     psFree(v);
     min->iter = iterationNumber;
Index: /trunk/psLib/src/image/psImageStats.c
===================================================================
--- /trunk/psLib/src/image/psImageStats.c	(revision 2264)
+++ /trunk/psLib/src/image/psImageStats.c	(revision 2265)
@@ -9,6 +9,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-11-02 02:03:56 $
+*  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-11-02 03:57:21 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -149,35 +149,4 @@
 }
 
-double *CalcScaleFactors(psS32 n)
-{
-    psS32 i = 0;
-    double tmp = 0.0;
-    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
-
-    for (i = 0; i < n; i++) {
-        tmp = (double)(n - i);
-        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
-        scalingFactors[i] = cos(tmp);
-    }
-
-    return (scalingFactors);
-}
-
-// XXX: Why do we have this function?
-double *CalcScaleFactorsFit(psS32 n)
-{
-    psS32 i = 0;
-    double tmp = 0.0;
-    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
-
-    for (i = 0; i < n; i++) {
-        tmp = (double)(n - i);
-        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
-        scalingFactors[i] = cos(tmp);
-    }
-
-    return (scalingFactors);
-}
-
 /*****************************************************************************
 CalcScaleFactorsEval(n): The Chebyshev polynomials are defined over the
@@ -187,11 +156,9 @@
 output a vector of evenly spaced floating point values between -1.0:1.0.
  *****************************************************************************/
-double *CalcScaleFactorsEval(psS32 n)
-{
+double *CalcScaleFactors(psS32 n)
+{
+    PS_INT_CHEC_NON_NEGATIVE(n, NULL);
     psS32 i = 0;
     double tmp = 0.0;
-
-    return(CalcScaleFactorsFit(n));
-
     double *scalingFactors = (double *)psAlloc(n * sizeof(double));
 
@@ -201,8 +168,26 @@
         scalingFactors[i] = cos(tmp);
     }
+
     return (scalingFactors);
 }
 
-// XXX: Use a static array of CHebyshev polynomials.
+psVector *VecCalcScaleFactors(psVector *scalingFactors, psS32 n)
+{
+    PS_VECTOR_CHECK_NULL(scalingFactors, NULL);
+    PS_VECTOR_CHECK_TYPE(scalingFactors, PS_TYPE_F64, NULL);
+    PS_INT_CHEC_NON_NEGATIVE(n, NULL);
+    psS32 i = 0;
+    double tmp = 0.0;
+
+    for (i = 0; i < n; i++) {
+        tmp = (double)(n - i);
+        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
+        scalingFactors->data.F64[i] = cos(tmp);
+    }
+
+    return (scalingFactors);
+}
+
+// XXX: Use a static array of Chebyshev polynomials.
 psPolynomial1D **p_psCreateChebyshevPolys(psS32 maxChebyPoly)
 {
Index: /trunk/psLib/src/imageops/psImageStats.c
===================================================================
--- /trunk/psLib/src/imageops/psImageStats.c	(revision 2264)
+++ /trunk/psLib/src/imageops/psImageStats.c	(revision 2265)
@@ -9,6 +9,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.48 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-11-02 02:03:56 $
+*  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-11-02 03:57:21 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -149,35 +149,4 @@
 }
 
-double *CalcScaleFactors(psS32 n)
-{
-    psS32 i = 0;
-    double tmp = 0.0;
-    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
-
-    for (i = 0; i < n; i++) {
-        tmp = (double)(n - i);
-        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
-        scalingFactors[i] = cos(tmp);
-    }
-
-    return (scalingFactors);
-}
-
-// XXX: Why do we have this function?
-double *CalcScaleFactorsFit(psS32 n)
-{
-    psS32 i = 0;
-    double tmp = 0.0;
-    double *scalingFactors = (double *)psAlloc(n * sizeof(double));
-
-    for (i = 0; i < n; i++) {
-        tmp = (double)(n - i);
-        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
-        scalingFactors[i] = cos(tmp);
-    }
-
-    return (scalingFactors);
-}
-
 /*****************************************************************************
 CalcScaleFactorsEval(n): The Chebyshev polynomials are defined over the
@@ -187,11 +156,9 @@
 output a vector of evenly spaced floating point values between -1.0:1.0.
  *****************************************************************************/
-double *CalcScaleFactorsEval(psS32 n)
-{
+double *CalcScaleFactors(psS32 n)
+{
+    PS_INT_CHEC_NON_NEGATIVE(n, NULL);
     psS32 i = 0;
     double tmp = 0.0;
-
-    return(CalcScaleFactorsFit(n));
-
     double *scalingFactors = (double *)psAlloc(n * sizeof(double));
 
@@ -201,8 +168,26 @@
         scalingFactors[i] = cos(tmp);
     }
+
     return (scalingFactors);
 }
 
-// XXX: Use a static array of CHebyshev polynomials.
+psVector *VecCalcScaleFactors(psVector *scalingFactors, psS32 n)
+{
+    PS_VECTOR_CHECK_NULL(scalingFactors, NULL);
+    PS_VECTOR_CHECK_TYPE(scalingFactors, PS_TYPE_F64, NULL);
+    PS_INT_CHEC_NON_NEGATIVE(n, NULL);
+    psS32 i = 0;
+    double tmp = 0.0;
+
+    for (i = 0; i < n; i++) {
+        tmp = (double)(n - i);
+        tmp = (M_PI * (tmp - 0.5)) / ((double)n);
+        scalingFactors->data.F64[i] = cos(tmp);
+    }
+
+    return (scalingFactors);
+}
+
+// XXX: Use a static array of Chebyshev polynomials.
 psPolynomial1D **p_psCreateChebyshevPolys(psS32 maxChebyPoly)
 {
Index: /trunk/psLib/src/math/psMinimize.c
===================================================================
--- /trunk/psLib/src/math/psMinimize.c	(revision 2264)
+++ /trunk/psLib/src/math/psMinimize.c	(revision 2265)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-02 01:04:37 $
+ *  @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-02 03:57:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -1361,5 +1361,5 @@
         min->value = func(params, coords);
         psTrace(".psLib.dataManip.p_psLineMin", 2,
-                "p_psLineMin() called with zero line vector.  Return 0.0.  Function valus is %f\n", min->value);
+                "p_psLineMin() called with zero line vector.  Return 0.0.  Function value is %f\n", min->value);
         return(0.0);
     }
@@ -1469,8 +1469,9 @@
 XXX: Define constants for default dummy number of iterations and tolerance.
  
-XXX: Must define behavior on various NULL inputs.
- 
 XXX: Check for F32 types?
  *****************************************************************************/
+#define PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS 20
+#define PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE 0.01
+
 psBool psMinimizePowell(psMinimization *min,
                         psVector *params,
@@ -1485,5 +1486,4 @@
     PS_PTR_CHECK_NULL(coords, NULL);
     PS_PTR_CHECK_NULL(func, NULL);
-
     psS32 numDims = params->n;
     PS_VECTOR_GEN_STATIC_RECYCLED(pQP, numDims, PS_TYPE_F32);
@@ -1492,6 +1492,5 @@
     psS32 i = 0;
     psS32 j = 0;
-    psVector **v = NULL;
-    psVector *myParamMask = NULL;  // XXX: Use a recylced vector here.
+    psVector *myParamMask = NULL;
     psMinimization dummyMin;
     float mul = 0.0;
@@ -1500,8 +1499,4 @@
     psS32 biggestIter = 0;
     float biggestDiff = 0.0;
-    float term1 = 0.0;
-    float term2 = 0.0;
-    float fqp = 0.0;
-    float diff = 0.0;
     int iterationNumber = 0;
 
@@ -1526,12 +1521,13 @@
 
     // 1: Set v[i] to be the unit vectors for each dimension in params
-    v = (psVector **) psAlloc(params->n * sizeof(psVector **));
+
+    psArray *v = psArrayAlloc(numDims);
     for (i=0;i<numDims;i++) {
-        v[i] = psVectorAlloc(numDims, PS_TYPE_F32);
+        (v->data[i]) = (psVector *) psVectorAlloc(numDims, PS_TYPE_F32);
         for (j=0;j<numDims;j++) {
             if (i == j) {
-                v[i]->data.F32[j] = 1.0;
+                ((psVector *) (v->data[i]))->data.F32[j] = 1.0;
             } else {
-                v[i]->data.F32[j] = 0.0;
+                ((psVector *) (v->data[i]))->data.F32[j] = 0.0;
             }
         }
@@ -1558,17 +1554,13 @@
                 "Current function value is %f\n", currFuncVal);
 
-        diff = 0.0;
         biggestDiff = 0;
         biggestIter = 0;
         for (i=0;i<numDims;i++) {
             if (myParamMask->data.U8[i] == 0) {
-                dummyMin.maxIter = 20;
-                dummyMin.tol = 0.01;
-                mul = p_psLineMin(&dummyMin, Q, v[i], myParamMask, coords, func);
+                dummyMin.maxIter = PS_MINIMIZE_POWELL_LINEMIN_MAX_ITERATIONS;
+                dummyMin.tol = PS_MINIMIZE_POWELL_LINEMIN_ERROR_TOLERANCE;
+                mul = p_psLineMin(&dummyMin, Q, ((psVector *) v->data[i]), myParamMask, coords, func);
                 if (isnan(mul)) {
                     psError(__func__, "Could not perform line minimization (1).\n");
-                    for (j=0;j<numDims;j++) {
-                        psFree(v[j]);
-                    }
                     psFree(v);
                     return(false);
@@ -1608,10 +1600,7 @@
         }
 
-        mul = p_psLineMin(min, params, u, myParamMask, coords, func);
+        mul = p_psLineMin(&dummyMin, params, u, myParamMask, coords, func);
         if (isnan(mul)) {
             psError(__func__, "Could not perform line minimization. (2)\n");
-            for (i=0;i<numDims;i++) {
-                psFree(v[i]);
-            }
             psFree(v);
             return(false);
@@ -1619,8 +1608,5 @@
 
         // 6:
-        if (min->value > currFuncVal) {
-            for (i=0;i<numDims;i++) {
-                psFree(v[i]);
-            }
+        if (dummyMin.value > currFuncVal) {
             psFree(v);
             min->iter = iterationNumber;
@@ -1637,15 +1623,14 @@
             }
         }
-        fqp = func(pQP, coords);
-
-        term1 = (baseFuncVal - currFuncVal) - biggestDiff;
+        float fqp = func(pQP, coords);
+        float term1 = (baseFuncVal - currFuncVal) - biggestDiff;
         term1*= term1;
         term1*= 2.0 * (baseFuncVal - (2.0 * currFuncVal) + fqp);
-        term2 = baseFuncVal - fqp;
+        float term2 = baseFuncVal - fqp;
         term2*= term2 * biggestDiff;
         if (term1 < term2) {
             for (i=0;i<numDims;i++) {
                 if (myParamMask->data.U8[i] == 0) {
-                    v[biggestIter]->data.F32[i] = u->data.F32[i];
+                    ((psVector *) v->data[biggestIter])->data.F32[i] = u->data.F32[i];
                 }
             }
@@ -1661,7 +1646,4 @@
         // 8: Go to step 3 until the change is less than some tolerance.
         if (fabs(baseFuncVal - currFuncVal) <= min->tol) {
-            for (i=0;i<numDims;i++) {
-                psFree(v[i]);
-            }
             psFree(v);
             min->iter = iterationNumber;
@@ -1672,7 +1654,4 @@
     }
 
-    for (i=0;i<numDims;i++) {
-        psFree(v[i]);
-    }
     psFree(v);
     min->iter = iterationNumber;
