Index: /trunk/psLib/src/astro/psCoord.c
===================================================================
--- /trunk/psLib/src/astro/psCoord.c	(revision 5812)
+++ /trunk/psLib/src/astro/psCoord.c	(revision 5813)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-12-05 21:33:29 $
+*  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-12-19 23:58:47 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -61,6 +61,4 @@
 should rename this.
  
-XXX: Use the ADD version which is based on determinants.
- 
 XXX: This code no longer makes sense.  The merge must be reviewed.
  *****************************************************************************/
@@ -85,27 +83,5 @@
 
     if (0) {
-        //This is sample code from IfA.  It didn't work initially, and I did not
-        //spend any time debugging it.
-        psF64 a = transform->x->coeff[1][0];
-        psF64 b = transform->x->coeff[0][1];
-        psF64 c = transform->y->coeff[1][0];
-        psF64 d = transform->y->coeff[0][1];
-        psF64 e = transform->x->coeff[0][0];
-        psF64 f = transform->y->coeff[0][0];
-
-        psF64 invDet = 1.0 / (a * d - b * c); // Inverse of the determinant
-
-        // Not entirely sure why this works, but it appears to do so
-        out->x->coeff[1][0] = invDet * a;
-        out->x->coeff[0][1] = - invDet * b;
-        out->y->coeff[1][0] = - invDet * c;
-        out->y->coeff[0][1] = invDet * d;
-
-        out->x->coeff[0][0] = - invDet * (d * e + c * f);
-        out->y->coeff[0][0] = - invDet * (b * e + a * f);
-    }
-
-    if (1) {
-        // XXX: There is no reason to execute this code and the following code.
+        // XXX: Get rid of this code.
         psF64 A = transform->x->coeff[1][0];
         psF64 B = transform->x->coeff[0][1];
@@ -129,7 +105,4 @@
     }
 
-
-    // XXX: There is no reason to execute this code and the previous codes.
-    // unless the cross terms are available, set these matrix elements to 0
     psF64 r12 = 0.0;
     if (transform->x->nY == 1) {
Index: /trunk/psLib/src/math/psPolynomial.c
===================================================================
--- /trunk/psLib/src/math/psPolynomial.c	(revision 5812)
+++ /trunk/psLib/src/math/psPolynomial.c	(revision 5813)
@@ -7,6 +7,6 @@
 *  polynomials.  It also contains a Gaussian functions.
 *
-*  @version $Revision: 1.133 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-11-30 02:00:09 $
+*  @version $Revision: 1.134 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-12-19 23:58:47 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -165,23 +165,61 @@
 not nOrder.
  *****************************************************************************/
-static psPolynomial1D **createChebyshevPolys(psS32 maxChebyPoly)
+psPolynomial1D **createChebyshevPolys(psS32 numPolys)
+{
+    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(numPolys, 1, NULL);
+
+    if (0) {
+        psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
+        for (psS32 i = 0; i < numPolys; i++) {
+            chebPolys[i] = psPolynomial1DAlloc(i, PS_POLYNOMIAL_ORD);
+            chebPolys[i]->coeff[i] = 1;
+        }
+        return (chebPolys);
+    } else {
+        psPolynomial1D **chebPolys = (psPolynomial1D **) psAlloc(numPolys * sizeof(psPolynomial1D *));
+        for (psS32 i = 0; i < numPolys; i++) {
+            chebPolys[i] = psPolynomial1DAlloc(i, PS_POLYNOMIAL_ORD);
+        }
+
+        // Create the Chebyshev polynomials.
+        // Polynomial i has i-th order.
+        chebPolys[0]->coeff[0] = 1.0;
+        if (numPolys >= 2) {
+            chebPolys[1]->coeff[1] = 1.0;
+
+            for (psS32 i = 2; i < numPolys; i++) {
+                for (psS32 j = 0; j < chebPolys[i - 1]->nX+1; j++) {
+                    chebPolys[i]->coeff[j + 1] = 2.0 * chebPolys[i - 1]->coeff[j];
+                }
+                for (psS32 j = 0; j < chebPolys[i - 2]->nX+1; j++) {
+                    chebPolys[i]->coeff[j] -= chebPolys[i - 2]->coeff[j];
+                }
+            }
+        }
+
+        return (chebPolys);
+    }
+}
+
+/*
+static psPolynomial1D **createChebyshevPolysOld(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]->nX; j++) {
@@ -196,7 +234,8 @@
         printf("WARNING: %u-order chebyshev polynomials not correctly implemented.\n", maxChebyPoly);
     }
-
+ 
     return (chebPolys);
 }
+*/
 
 /*****************************************************************************
@@ -236,21 +275,20 @@
 // 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_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, 0.0);
-    // XXX: Create a macro for this in psConstants.h
-    if (poly->nX < 1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Chebyshev polynomial is order %u.", poly->nX);
-        return(NAN);
-    }
+// XXX: Create a faster version for low-order Chebyshevs.
+static psF64 chebPolynomial1DEval(
+    psF64 x,
+    const psPolynomial1D* poly)
+{
+    PS_ASSERT_DOUBLE_WITHIN_RANGE(x, -1.0, 1.0, NAN);
+    PS_ASSERT_INT_LARGER_THAN_OR_EQUAL(poly->nX, 0, NAN);
     psVector *d;
+
     // XXX: n should be nTerms here (for clarity).  Or get rid of the variable.
-    unsigned int n = 1 + poly->nX;
+    unsigned int nTerms = 1 + poly->nX;
     unsigned int i;
     psF64 tmp = 0.0;
 
     // Special case where the Chebyshev poly is constant.
-    if (n == 1) {
+    if (nTerms == 1) {
         if (poly->mask[0] == 0) {
             tmp += poly->coeff[0];
@@ -260,5 +298,5 @@
 
     // Special case where the Chebyshev poly is linear.
-    if (n == 2) {
+    if (nTerms == 2) {
         if (poly->mask[0] == 0) {
             tmp+= poly->coeff[0];
@@ -270,50 +308,49 @@
     }
 
-    // General case where the Chebyshev poly has 2 or more terms.
-    d = psVectorAlloc(n, PS_TYPE_F64);
-    if(poly->mask[n-1] == 0) {
-        d->data.F64[n-1] = poly->coeff[n-1];
+    if (1) {
+        // General case where the Chebyshev poly has 2 or more terms.
+        d = psVectorAlloc(nTerms, PS_TYPE_F64);
+        if(poly->mask[nTerms-1] == 0) {
+            d->data.F64[nTerms-1] = poly->coeff[nTerms-1];
+        } else {
+            d->data.F64[nTerms-1] = 0.0;
+        }
+
+        d->data.F64[nTerms-2] = (2.0 * x * d->data.F64[nTerms-1]);
+        if(poly->mask[nTerms-2] == 0) {
+            d->data.F64[nTerms-2] += poly->coeff[nTerms-2];
+        }
+
+        for (i=nTerms-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);
     } 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);
+        // This is old code that does not use Clenshaw's formula.  Get rid of it.
+        psPolynomial1D **chebPolys = createChebyshevPolys(1 + poly->nX);
+
+        tmp = 0.0;
+        for (psS32 i=0;i<(1 + poly->nX);i++) {
+            tmp+= (poly->coeff[i] * psPolynomial1DEval(chebPolys[i], x));
+        }
+        tmp-= (poly->coeff[0]/2.0);
+
+        for (psS32 i=0;i<(1 + poly->nX);i++) {
+            psFree(chebPolys[i]);
+        }
+        psFree(chebPolys);
+    }
+
     return(tmp);
-
-    /* This is old code that does not use Clenshaw's formula.  Get rid of it.
-
-    psS32 i;
-    psF32 tmp;
-    psPolynomial1D **chebPolys = NULL;
-
-    chebPolys = createChebyshevPolys(1 + poly->nX);
-
-    tmp = 0.0;
-    for (i=0;i<(1 + poly->nX);i++) {
-        tmp+= (poly->coeff[i] * psPolynomial1DEval(x, chebPolys[i]));
-    }
-    tmp-= (poly->coeff[0]/2.0);
-
-
-    return(tmp);
-    */
 }
 
@@ -628,4 +665,6 @@
     newPoly->type = type;
     newPoly->nX = n;
+    newPoly->p_min = NAN;
+    newPoly->p_max = NAN;
     newPoly->coeff = psAlloc((n + 1) * sizeof(psF64));
     newPoly->coeffErr = psAlloc((n + 1) * sizeof(psF64));
Index: /trunk/psLib/src/math/psPolynomial.h
===================================================================
--- /trunk/psLib/src/math/psPolynomial.h	(revision 5812)
+++ /trunk/psLib/src/math/psPolynomial.h	(revision 5813)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-12 21:02:20 $
+ *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-12-19 23:58:47 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -77,4 +77,6 @@
     psPolynomialType type;              ///< Polynomial type
     unsigned int nX;             ///< Polynomial order
+    psF64 p_min;
+    psF64 p_max;
     psF64 *coeff;                       ///< Coefficients
     psF64 *coeffErr;                    ///< Error in coefficients
@@ -298,4 +300,18 @@
 );
 
+
+// XXX: Coding Standard
+psPolynomial1D **createChebyshevPolys(psS32 numPolys);
+
+typedef struct
+{
+    int n;                              ///< The number of Chebyshev polys.
+    psPolynomial1D **chebyPolys;        ///< THe chebyshev polys
+
+}
+p_chebyPolys;
+
+
+
 /** \} */ // End of MathGroup Functions
 
Index: /trunk/psLib/test/math/Makefile.am
===================================================================
--- /trunk/psLib/test/math/Makefile.am	(revision 5812)
+++ /trunk/psLib/test/math/Makefile.am	(revision 5813)
@@ -26,8 +26,4 @@
     tst_psMatrixVectorArithmetic03 \
     tst_psMatrixVectorArithmetic04 \
-    tst_psMinimize04 \
-    tst_psMinimize04_F32 \
-    tst_psMinimize04b \
-    tst_psMinimize04b_F32 \
     tst_psMinimize05 \
     tst_psMinimize06 \
@@ -44,5 +40,9 @@
     tst_psStats09 \
     tst_psSpline1D \
-    tst_psRandom
+    tst_psRandom \
+    tst_psPolyFit1DCheby \
+    tst_psPolyFit1DOrd \
+    tst_psPolyFit2DOrd
+
 
 tst_psFunc00_SOURCES =  tst_psFunc00.c
@@ -67,8 +67,4 @@
 tst_psMatrixVectorArithmetic03_SOURCES =  tst_psMatrixVectorArithmetic03.c
 tst_psMatrixVectorArithmetic04_SOURCES =  tst_psMatrixVectorArithmetic04.c
-tst_psMinimize04_SOURCES =  tst_psMinimize04.c
-tst_psMinimize04_F32_SOURCES =  tst_psMinimize04_F32.c
-tst_psMinimize04b_SOURCES =  tst_psMinimize04b.c
-tst_psMinimize04b_F32_SOURCES =  tst_psMinimize04b_F32.c
 tst_psMinimizeVector2D_F64_SOURCES = tst_psMinimizeVector2D_F64.c
 tst_psMinimizeVector2D_F32_SOURCES = tst_psMinimizeVector2D_F32.c
@@ -85,4 +81,7 @@
 tst_psStats09_SOURCES =  tst_psStats09.c
 tst_psRandom_SOURCES =  tst_psRandom.c
+tst_psPolyFit1DCheby_SOURCES = tst_psPolyFit1DCheby.c
+tst_psPolyFit1DOrd_SOURCES = tst_psPolyFit1DOrd.c
+tst_psPolyFit2DOrd_SOURCES = tst_psPolyFit2DOrd.c
 
 check_DATA =
Index: unk/psLib/test/math/tst_psMinimize04.c
===================================================================
--- /trunk/psLib/test/math/tst_psMinimize04.c	(revision 5812)
+++ 	(revision )
@@ -1,130 +1,0 @@
-/*****************************************************************************
-This routine must ensure that the psVectorFitPolynomial2D works correctly.
-We create a vectors of data points (x and y), and populate them with the
-values from an arbitrary function setData().  We then call
-psVectorFitPolynomial2D() with a regular polynomial data structure.  We then
-evaluate the polynomial with the coefficients generated above and determine
-if they are within an error tolerance of the expected values.
- 
-    t00(): all input vectors are non-NULL.
-    t01(): yErr is NULL.
-    t02(): x, yErr is NULL.
-    t03(): x, y, yErr is NULL.
- *****************************************************************************/
-#include <stdio.h>
-#include "pslib_strict.h"
-#include "psTest.h"
-#include "psMemory.h"
-#include "psVector.h"
-#include "psImage.h"
-#include "psMinimize.h"
-#include <math.h>
-#define NUM_DATA 10
-#define POLY_ORDER 5
-#define A 3.0
-#define B 2.0
-#define C 3.0
-#define D 3.0
-#define E 3.0
-#define F 3.0
-#define ERROR_TOLERANCE 0.10
-#define FERR 1.0
-#define PRINT_RESULTS 0
-
-double setData(double x, double y)
-{
-    return(A + (B * x) + (C * x * x) + (D * y) + (E * y * y) + (E * x * y));
-}
-
-psS32 t00()
-{
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-    double expectData;
-    double actualData;
-
-    psPolynomial2D *myPoly = psPolynomial2DAlloc(POLY_ORDER, POLY_ORDER, PS_POLYNOMIAL_ORD);
-    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-
-    for (psS32 i=0;i<NUM_DATA;i++) {
-        x->data.F32[i] = (double) i;
-        y->data.F32[i] = (double) i;
-        f->data.F32[i] = setData(x->data.F32[i], y->data.F32[i]);
-        fErr->data.F32[i] = FERR;
-    }
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial2D(): equal difference in variable fErr");
-
-    psVectorFitPolynomial2D(myPoly, NULL, 0, f, fErr, x, y);
-
-    //    for (i=0;i<POLY_ORDER+1;i++) {
-    //        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
-    //    }
-
-    for (psS32 i=0;i<NUM_DATA;i++) {
-        expectData = setData(x->data.F32[i],  y->data.F32[i]);
-        actualData = psPolynomial2DEval(myPoly, x->data.F32[i], y->data.F32[i]);
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F32[i], y->data.F32[i], actualData, expectData);
-            testStatus = false;
-        }
-        if (PRINT_RESULTS) {
-            printf("Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
-        }
-    }
-
-
-    printf("Running test with fErr set to NULL.\n");
-    psVectorFitPolynomial2D(myPoly, NULL, 0, f, NULL, x, y);
-    for (psS32 i=0;i<NUM_DATA;i++) {
-        expectData = setData(x->data.F32[i],  y->data.F32[i]);
-        actualData = psPolynomial2DEval(myPoly, x->data.F32[i], y->data.F32[i]);
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F32[i], y->data.F32[i], actualData, expectData);
-            testStatus = false;
-        }
-        if (PRINT_RESULTS) {
-            printf("Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
-        }
-    }
-    psFree(myPoly);
-
-    printf("Running test with x, y set to NULL.  Should generate error.\n");
-    myPoly = psVectorFitPolynomial2D(NULL, NULL, 0, f, fErr, NULL, NULL);
-    if (myPoly != NULL) {
-        printf("TEST ERROR: psVectorFitPolynomial2D() returned non-NULL.\n");
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
-    psFree(x);
-    psFree(y);
-    psFree(f);
-    psFree(fErr);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial2D(): equal differences in variable fErr",
-                testStatus);
-
-    return (!testStatus);
-}
-
-psS32 main()
-{
-    psLogSetFormat("HLNM");
-    t00();
-}
Index: unk/psLib/test/math/tst_psMinimize04_F32.c
===================================================================
--- /trunk/psLib/test/math/tst_psMinimize04_F32.c	(revision 5812)
+++ 	(revision )
@@ -1,268 +1,0 @@
-/*****************************************************************************
-This routine must ensure that the psVectorFitPolynomial1D works correctly.
-We create a vectors of data points (x and y), and populate them with the
-values from an arbitrary function setData().  We then call
-psVectorFitPolynomial1D() with a regular polynomial data structure.  We then
-evaluate the polynomial with the coefficients generated above and determine
-if they are within an error tolerance of the expected values.
- 
-    t00(): all input vectors are non-NULL.
-    t01(): yErr is NULL.
-    t02(): x, yErr is NULL.
-    t03(): x, y, yErr is NULL.
- *****************************************************************************/
-#include <stdio.h>
-#include "pslib_strict.h"
-#include "psTest.h"
-#include "psMemory.h"
-#include "psVector.h"
-#include "psImage.h"
-#include "psMinimize.h"
-#include <math.h>
-#define NUM_DATA 10
-#define POLY_ORDER 5
-#define A 3.0
-#define B 2.0
-#define C 3.0
-#define ERROR_TOLERANCE 0.10
-#define YERR 10.0
-float setData(float x)
-{
-    return(A + (B * x) + (C * x * x));
-}
-
-psS32 t00()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psVector *yErr = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-    float expectData;
-    float actualData;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F32[i] = (float) i;
-        y->data.F32[i] = setData(x->data.F32[i]);
-        yErr->data.F32[i] = YERR;
-        //        printf("Original data %d: (%.1f %.1f)\n", i, x->data.F32[i], y->data.F32[i]);
-    }
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): equal errors in yErr");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x);
-
-    //    for (i=0;i<POLY_ORDER+1;i++) {
-    //        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
-    //    }
-
-    for (i=0;i<NUM_DATA;i++) {
-        expectData = setData(x->data.F32[i]);
-        actualData = psPolynomial1DEval(
-                         myPoly,
-                         x->data.F32[i]
-                     );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F32[i], actualData, expectData);
-            testStatus = false;
-            //        } else {
-            //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-            //                   i, x->data.F32[i], actualData, expectData);
-        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psFree(yErr);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): equal errors in yErr",
-                testStatus);
-
-    return (!testStatus);
-}
-
-psS32 t01()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-    float expectData;
-    float actualData;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F32[i] = (float) i;
-        y->data.F32[i] = setData(x->data.F32[i]);
-        //        printf("Original data %d: (%.1f %.1f)\n", i, x->data.F32[i], y->data.F32[i]);
-    }
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): yErr is NULL");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x);
-
-    //    for (i=0;i<POLY_ORDER+1;i++) {
-    //        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
-    //    }
-
-    for (i=0;i<NUM_DATA;i++) {
-        expectData = setData(x->data.F32[i]);
-        actualData = psPolynomial1DEval(
-                         myPoly,
-                         x->data.F32[i]
-                     );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F32[i], actualData, expectData);
-            testStatus = false;
-            //        } else {
-            //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-            //                   i, x->data.F32[i], actualData, expectData);
-        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): yErr is NULL",
-                testStatus);
-
-    return (!testStatus);
-}
-
-psS32 t02()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *y = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-    float expectData;
-    float actualData;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-
-    for (i=0;i<NUM_DATA;i++) {
-        y->data.F32[i] = setData((float) i);
-        //        printf("Original data %d: (%.1f)\n", i, y->data.F32[i]);
-    }
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): x, yErr is NULL");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL);
-
-    //    for (i=0;i<POLY_ORDER+1;i++) {
-    //        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
-    //    }
-
-    for (i=0;i<NUM_DATA;i++) {
-        expectData = setData((float) i);
-        actualData = psPolynomial1DEval(
-                         myPoly,
-                         (float) i
-                     );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, (float) i, actualData, expectData);
-            testStatus = false;
-            //        } else {
-            //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-            //                   i, (float) i, actualData, expectData);
-        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(y);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): x, yErr is NULL",
-                testStatus);
-
-    return (!testStatus);
-}
-
-psS32 t03()
-{
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): all inputs are NULL");
-
-    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null arguments.");
-
-    psVectorFitPolynomial1D(NULL, NULL, 0, NULL, NULL, NULL);
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): all inputs are NULL",
-                testStatus);
-
-    return (!testStatus);
-}
-
-
-psS32 main()
-{
-    psLogSetFormat("HLNM");
-    t00();
-    t01();
-    t02();
-    t03();
-}
Index: unk/psLib/test/math/tst_psMinimize04b.c
===================================================================
--- /trunk/psLib/test/math/tst_psMinimize04b.c	(revision 5812)
+++ 	(revision )
@@ -1,261 +1,0 @@
-/*****************************************************************************
-    This routine must ensure that the psVectorFitPolynomial1D works correctly.
- 
-    We use Chebyshev polynomials here.
- *****************************************************************************/
-#include <stdio.h>
-#include "pslib_strict.h"
-#include "psTest.h"
-#include "psMemory.h"
-#include "psVector.h"
-#include "psImage.h"
-#include "psMinimize.h"
-#include <math.h>
-#define NUM_DATA 21
-#define POLY_ORDER 10
-#define A 2.0
-#define B 3.0
-#define C 2.0
-#define D 4.0
-#define E 5.0
-#define ERROR_TOLERANCE 0.10
-#define IGNORE (ERROR_TOLERANCE * NUM_DATA)
-
-double setData(double x)
-{
-    return(A + (B * x) + (C * x * x) + (D * x * x * x) + (E * x * x * x * x));
-}
-
-psS32 t00()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psVector *yErr = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
-    yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F64[i] = (double) i;
-        y->data.F64[i] = setData(x->data.F64[i]);
-        yErr->data.F64[i] = 1.0;
-    }
-    p_psNormalizeVectorRangeF64(x, -1.0, 1.0);
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, equal errors in yErr");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x);
-
-    //  Remove for testing since print out differs from platforms
-    //    for (i=0;i<POLY_ORDER+1;i++) {
-    //        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
-    //    }
-
-    // We don't test the first or last few data items.
-    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
-        double expectData = y->data.F64[i];
-        double actualData = psPolynomial1DEval(
-                                myPoly,
-                                x->data.F64[i]
-                            );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F64[i], actualData, expectData);
-            testStatus = false;
-        }
-        //      Remove for testing since print out differs from platforms
-        //        } else {
-        //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-        //                   i, x->data.F64[i], actualData, expectData);
-        //        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psFree(yErr);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, equal errors in yErr",
-                testStatus);
-    return (!testStatus);
-}
-
-
-psS32 t01()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F64[i] = (double) i;
-        y->data.F64[i] = setData(x->data.F64[i]);
-    }
-    p_psNormalizeVectorRangeF64(x, -1.0, 1.0);
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x);
-
-    // We don't test the first or last few data items.
-    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
-        double expectData = y->data.F64[i];
-        double actualData = psPolynomial1DEval(
-                                myPoly,
-                                x->data.F64[i]
-                            );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F64[i], actualData, expectData);
-            testStatus = false;
-        }
-        //      Remove for testing since print out differs from platforms
-        //        } else {
-        //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-        //                   i, x->data.F64[i], actualData, expectData);
-        //        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
-                testStatus);
-    return (!testStatus);
-}
-
-
-psS32 t02()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F64[i] = (double) i;
-        y->data.F64[i] = setData(x->data.F64[i]);
-    }
-    p_psNormalizeVectorRangeF64(x, -1.0, 1.0);
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL);
-    //    psVectorFitPolynomial1D(myPoly, x, y, NULL);
-
-    // We don't test the first or last few data items.
-    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
-        double expectData = y->data.F64[i];
-        double actualData = psPolynomial1DEval(myPoly, x->data.F64[i]);
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.2f %.2f), expected was (%.2f)\n",
-                   i, x->data.F64[i], actualData, expectData);
-            testStatus = false;
-        }
-        //      Remove for testing since print out differs from platforms
-        //        } else {
-        //            printf("Fitted data %d: (%.2f %.2f), expected was (%.2f)\n",
-        //                   i, x->data.F64[i], actualData, expectData);
-        //        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL",
-                testStatus);
-    return (!testStatus);
-}
-
-psS32 t03()
-{
-    psPolynomial1D *myPoly = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
-
-    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for null arguments.");
-    psVectorFitPolynomial1D(myPoly, NULL, 0, NULL, NULL, NULL);
-    if (myPoly != NULL) {
-        printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n");
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
-                testStatus);
-    return (!testStatus);
-}
-
-psS32 main()
-{
-    psLogSetFormat("HLNM");
-    t00();
-    t01();
-    t02();
-    t03();
-}
Index: unk/psLib/test/math/tst_psMinimize04b_F32.c
===================================================================
--- /trunk/psLib/test/math/tst_psMinimize04b_F32.c	(revision 5812)
+++ 	(revision )
@@ -1,263 +1,0 @@
-/*****************************************************************************
-    This routine must ensure that the psVectorFitPolynomial1D works correctly.
- 
-    We use Chebyshev polynomials here.
- *****************************************************************************/
-#include <stdio.h>
-#include "pslib_strict.h"
-#include "psTest.h"
-#include "psMemory.h"
-#include "psVector.h"
-#include "psImage.h"
-#include "psMinimize.h"
-#include <math.h>
-#define NUM_DATA 20
-#define POLY_ORDER 10
-#define A 2.0
-#define B 3.0
-#define C 2.0
-#define D 4.0
-#define E 5.0
-#define ERROR_TOLERANCE 0.10
-#define IGNORE (ERROR_TOLERANCE * NUM_DATA)
-
-float setData(float x)
-{
-    return(A + (B * x) + (C * x * x) + (D * x * x * x) + (E * x * x * x * x));
-}
-
-psS32 t00()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psVector *yErr = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F32[i] = (float) i;
-        y->data.F32[i] = setData(x->data.F32[i]);
-        yErr->data.F32[i] = 1.0;
-    }
-    p_psNormalizeVectorRangeF32(x, -1.0f, 1.0f);
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, equal errors in yErr");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x);
-
-    //  Remove for testing since printout differs between platforms
-    //    for (i=0;i<POLY_ORDER+1;i++) {
-    //        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
-    //    }
-
-    // We don't test the first or last few data items.
-    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
-        float expectData = y->data.F32[i];
-        float actualData = psPolynomial1DEval(
-                               myPoly,
-                               x->data.F32[i]
-                           );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F32[i], actualData, expectData);
-            testStatus = false;
-        }
-        //       REMOVE for testing since printout is different for different platforms
-        //        } else {
-        //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-        //                   i, x->data.F32[i], actualData, expectData);
-        //        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psFree(yErr);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, equal errors in yErr",
-                testStatus);
-    return (!testStatus);
-}
-
-
-psS32 t01()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F32[i] = (float) i;
-        y->data.F32[i] = setData(x->data.F32[i]);
-    }
-    p_psNormalizeVectorRangeF32(x, -1.0f, 1.0f);
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x);
-
-    // We don't test the first or last few data items.
-    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
-        float expectData = y->data.F32[i];
-        float actualData = psPolynomial1DEval(
-                               myPoly,
-                               x->data.F32[i]
-                           );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F32[i], actualData, expectData);
-            testStatus = false;
-        }
-        //      Removed for testing since printout different on different platforms
-        //        } else {
-        //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-        //                   i, x->data.F32[i], actualData, expectData);
-        //        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
-                testStatus);
-    return (!testStatus);
-}
-
-
-psS32 t02()
-{
-    psPolynomial1D *myPoly = NULL;
-    psVector *x = NULL;
-    psVector *y = NULL;
-    psS32 i = 0;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
-    x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-    y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
-
-    for (i=0;i<NUM_DATA;i++) {
-        x->data.F32[i] = (float) i;
-        y->data.F32[i] = setData(x->data.F32[i]);
-    }
-    p_psNormalizeVectorRangeF32(x, -1.0, 1.0);
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL");
-
-    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL);
-
-    // We don't test the first or last few data items.
-    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
-        float expectData = y->data.F32[i];
-        float  actualData = psPolynomial1DEval(
-                                myPoly,
-                                x->data.F32[i]
-                            );
-        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
-            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-                   i, x->data.F32[i], actualData, expectData);
-            testStatus = false;
-        }
-        //      Remove for testing since printout different for different platforms
-        //        } else {
-        //            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
-        //                   i, x->data.F32[i], actualData, expectData);
-        //        }
-    }
-
-    psMemCheckCorruption(1);
-    psFree(myPoly);
-    psFree(x);
-    psFree(y);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL",
-                testStatus);
-    return (!testStatus);
-}
-
-psS32 t03()
-{
-    psPolynomial1D *myPoly = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 testStatus = true;
-    psS32 memLeaks = 0;
-
-    printPositiveTestHeader(stdout,
-                            "psMinimize functions",
-                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
-
-    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null arguments.");
-    psVectorFitPolynomial1D(myPoly, NULL, 0, NULL, NULL, NULL);
-    if (myPoly != NULL) {
-        printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n");
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-    printFooter(stdout,
-                "psMinimize functions",
-                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
-                testStatus);
-    return (!testStatus);
-}
-
-psS32 main()
-{
-    psLogSetFormat("HLNM");
-    t00();
-    t01();
-    t02();
-    t03();
-}
Index: /trunk/psLib/test/math/tst_psPolyFit1DCheby.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolyFit1DCheby.c	(revision 5813)
+++ /trunk/psLib/test/math/tst_psPolyFit1DCheby.c	(revision 5813)
@@ -0,0 +1,480 @@
+/*****************************************************************************
+    This routine must ensure that the psVectorFitPolynomial1D works correctly.
+ 
+    We use Chebyshev polynomials here.
+ 
+    We use psF32 and psF64 types here.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib_strict.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psVector.h"
+#include "psImage.h"
+#include "psMinimize.h"
+#include <math.h>
+#define NUM_DATA 21
+#define POLY_ORDER 4
+#define A 2.0
+#define B 3.0
+#define C 5.0
+#define D 3.0
+#define E 2.0
+#define ERROR_TOLERANCE 0.10
+#define IGNORE (ERROR_TOLERANCE * NUM_DATA)
+#define VERBOSE 0
+
+psF64 setDataF64(psF64 x)
+{
+    return(A + (B * x) + (C * x * x) + (D * x * x * x) + (E * x * x * x * x));
+}
+
+psF32 setDataF32(psF32 x)
+{
+    return(A + (B * x) + (C * x * x) + (D * x * x * x) + (E * x * x * x * x));
+}
+
+psS32 t00F64()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    psVector *yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F64[i] = (psF64) i;
+        y->data.F64[i] = setDataF64(x->data.F64[i]);
+        yErr->data.F64[i] = 1.0;
+    }
+    p_psNormalizeVectorRangeF64(x, -1.0, 1.0);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, equal errors in yErr");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.4f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        psF64 expectData = y->data.F64[i];
+        psF64 actualData = psPolynomial1DEval(myPoly, x->data.F64[i]);
+
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F64[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psFree(yErr);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, equal errors in yErr",
+                testStatus);
+    return (testStatus);
+}
+
+
+psS32 t01F64()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F64[i] = (psF64) i;
+        y->data.F64[i] = setDataF64(x->data.F64[i]);
+    }
+    p_psNormalizeVectorRangeF64(x, -1.0, 1.0);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x);
+
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        psF64 expectData = y->data.F64[i];
+        psF64 actualData = psPolynomial1DEval(
+                               myPoly,
+                               x->data.F64[i]
+                           );
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F64[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
+                testStatus);
+    return (testStatus);
+}
+
+
+psS32 t02F64()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F64[i] = (psF64) i;
+        y->data.F64[i] = setDataF64(x->data.F64[i]);
+    }
+    p_psNormalizeVectorRangeF64(x, -1.0, 1.0);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL);
+    //    psVectorFitPolynomial1D(myPoly, x, y, NULL);
+
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        psF64 expectData = y->data.F64[i];
+        psF64 actualData = psPolynomial1DEval(myPoly, x->data.F64[i]);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.2f %.2f), expected was (%.2f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.2f %.2f), expected was (%.2f)\n",
+                       i, x->data.F64[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL",
+                testStatus);
+    return (testStatus);
+}
+
+psS32 t03F64()
+{
+    psPolynomial1D *myPoly = NULL;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error for null arguments.");
+    psVectorFitPolynomial1D(myPoly, NULL, 0, NULL, NULL, NULL);
+    if (myPoly != NULL) {
+        printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n");
+        testStatus = false;
+    }
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
+                testStatus);
+    return (testStatus);
+}
+
+psS32 t00F32()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F32[i] = (psF32) i;
+        y->data.F32[i] = setDataF32(x->data.F32[i]);
+        yErr->data.F32[i] = 1.0;
+    }
+    p_psNormalizeVectorRangeF32(x, -1.0f, 1.0f);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, equal errors in yErr");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        psF32 expectData = y->data.F32[i];
+        psF32 actualData = psPolynomial1DEval(
+                               myPoly,
+                               x->data.F32[i]
+                           );
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F32[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F32[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psFree(yErr);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, equal errors in yErr",
+                testStatus);
+    return (testStatus);
+}
+
+
+psS32 t01F32()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F32[i] = (psF32) i;
+        y->data.F32[i] = setDataF32(x->data.F32[i]);
+    }
+    p_psNormalizeVectorRangeF32(x, -1.0f, 1.0f);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x);
+
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        psF32 expectData = y->data.F32[i];
+        psF32 actualData = psPolynomial1DEval(
+                               myPoly,
+                               x->data.F32[i]
+                           );
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F32[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F32[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
+                testStatus);
+    return (testStatus);
+}
+
+
+psS32 t02F32()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_CHEB);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F32[i] = (psF32) i;
+        y->data.F32[i] = setDataF32(x->data.F32[i]);
+    }
+    p_psNormalizeVectorRangeF32(x, -1.0, 1.0);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL);
+
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        psF32 expectData = y->data.F32[i];
+        psF32 actualData = psPolynomial1DEval(myPoly, x->data.F32[i]);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F32[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F32[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL",
+                testStatus);
+    return (testStatus);
+}
+
+psS32 t03F32()
+{
+    psPolynomial1D *myPoly = NULL;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null arguments.");
+    psVectorFitPolynomial1D(myPoly, NULL, 0, NULL, NULL, NULL);
+    if (myPoly != NULL) {
+        printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n");
+        testStatus = false;
+    }
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
+                testStatus);
+    return (testStatus);
+}
+
+
+
+
+psS32 main()
+{
+    psBool testStatus = true;
+
+    psLogSetFormat("HLNM");
+
+    printPositiveTestHeader(stdout, "psMinimize functions: testing the Chebyshev fitting routines.", "");
+    testStatus &= t00F64();
+    testStatus &= t01F64();
+    testStatus &= t02F64();
+    testStatus &= t03F64();
+    testStatus &= t00F32();
+    testStatus &= t01F32();
+    testStatus &= t02F32();
+    testStatus &= t03F32();
+
+    printFooter(stdout, "psMinimize functions: testing the Chebyshev fitting routines.", "", testStatus);
+}
Index: /trunk/psLib/test/math/tst_psPolyFit1DOrd.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolyFit1DOrd.c	(revision 5813)
+++ /trunk/psLib/test/math/tst_psPolyFit1DOrd.c	(revision 5813)
@@ -0,0 +1,518 @@
+/*****************************************************************************
+This routine must ensure that the psVectorFitPolynomial1D works correctly.
+We create a vectors of data points (x and y), and populate them with the
+values from an arbitrary function setData().  We then call
+psVectorFitPolynomial1D() with a regular polynomial data structure.  We then
+evaluate the polynomial with the coefficients generated above and determine
+if they are within an error tolerance of the expected values.
+ 
+    t00F32(): all input vectors are non-NULL.
+    t01F32(): yErr is NULL.
+    t02F32(): x, yErr is NULL.
+    t03F32(): x, y, yErr is NULL.
+ 
+    We use psF32 and psF64 types here.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib_strict.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psVector.h"
+#include "psImage.h"
+#include "psMinimize.h"
+#include <math.h>
+#define NUM_DATA 10
+#define POLY_ORDER 5
+#define A 2.0
+#define B 3.0
+#define C 4.0
+#define D 5.0
+#define E 2.0
+#define ERROR_TOLERANCE 0.10
+#define YERR 10.0
+#define VERBOSE 0
+
+
+psF32 setDataF32(psF32 x)
+{
+    return(A + (B * x) + (C * x * x) + (D * x * x * x) + (E * x * x * x * x));
+}
+
+psF64 setDataF64(psF64 x)
+{
+    return(A + (B * x) + (C * x * x) + (D * x * x * x) + (E * x * x * x * x));
+}
+
+psS32 t00F32()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psF32 expectData;
+    psF32 actualData;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F32[i] = (psF32) i;
+        y->data.F32[i] = setDataF32(x->data.F32[i]);
+        yErr->data.F32[i] = YERR;
+        if (VERBOSE) {
+            printf("Original data %d: (%.1f %.1f)\n", i, x->data.F32[i], y->data.F32[i]);
+        }
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): equal errors in yErr");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setDataF32(x->data.F32[i]);
+        actualData = psPolynomial1DEval(myPoly, x->data.F32[i]);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F32[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F32[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psFree(yErr);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): equal errors in yErr",
+                testStatus);
+
+    return (testStatus);
+}
+
+psS32 t01F32()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psF32 expectData;
+    psF32 actualData;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F32[i] = (psF32) i;
+        y->data.F32[i] = setDataF32(x->data.F32[i]);
+        if (VERBOSE) {
+            printf("Original data %d: (%.1f %.1f)\n", i, x->data.F32[i], y->data.F32[i]);
+        }
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setDataF32(x->data.F32[i]);
+        actualData = psPolynomial1DEval(
+                         myPoly,
+                         x->data.F32[i]
+                     );
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F32[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F32[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): yErr is NULL",
+                testStatus);
+
+    return (testStatus);
+}
+
+psS32 t02F32()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psF32 expectData;
+    psF32 actualData;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+
+    for (i=0;i<NUM_DATA;i++) {
+        y->data.F32[i] = setDataF32((psF32) i);
+        if (VERBOSE) {
+            printf("Original data %d: (%.1f)\n", i, y->data.F32[i]);
+        }
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): x, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setDataF32((psF32) i);
+        actualData = psPolynomial1DEval(myPoly, (psF32) i);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, (psF32) i, actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, (psF32) i, actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout, "psMinimize functions",
+                "psVectorFitPolynomial1D(): x, yErr is NULL", testStatus);
+
+    return (testStatus);
+}
+
+psS32 t03F32()
+{
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): all inputs are NULL");
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null arguments.");
+
+    psVectorFitPolynomial1D(NULL, NULL, 0, NULL, NULL, NULL);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): all inputs are NULL",
+                testStatus);
+
+    return(testStatus);
+}
+
+
+
+psS32 t00F64()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psF64 expectData;
+    psF64 actualData;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    psVector *yErr = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F64[i] = (psF64) i;
+        y->data.F64[i] = setDataF64(x->data.F64[i]);
+        yErr->data.F64[i] = YERR;
+        if (VERBOSE) {
+            printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);
+        }
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): equal errors in yErr");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, yErr, x);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setDataF64(x->data.F64[i]);
+        actualData = psPolynomial1DEval(myPoly, x->data.F64[i]);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F64[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psFree(yErr);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): equal errors in yErr",
+                testStatus);
+
+    return (testStatus);
+}
+
+psS32 t01F64()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psF64 expectData;
+    psF64 actualData;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F64[i] = (psF64) i;
+        y->data.F64[i] = setDataF64(x->data.F64[i]);
+        if (VERBOSE) {
+            printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);
+        }
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, x);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setDataF64(x->data.F64[i]);
+        actualData = psPolynomial1DEval(
+                         myPoly,
+                         x->data.F64[i]
+                     );
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, x->data.F64[i], actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): yErr is NULL",
+                testStatus);
+
+    return (testStatus);
+}
+
+psS32 t02F64()
+{
+    psS32 i = 0;
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psF64 expectData;
+    psF64 actualData;
+
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(POLY_ORDER, PS_POLYNOMIAL_ORD);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        y->data.F64[i] = setDataF64((psF64) i);
+        if (VERBOSE) {
+            printf("Original data %d: (%.1f)\n", i, y->data.F64[i]);
+        }
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): x, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, 0, y, NULL, NULL);
+
+    if (VERBOSE) {
+        for (i=0;i<POLY_ORDER+1;i++) {
+            printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+        }
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setDataF64((psF64) i);
+        actualData = psPolynomial1DEval(myPoly, (psF64) i);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, (psF64) i, actualData, expectData);
+            testStatus = false;
+        } else {
+            if (VERBOSE) {
+                printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                       i, (psF64) i, actualData, expectData);
+            }
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout, "psMinimize functions",
+                "psVectorFitPolynomial1D(): x, yErr is NULL", testStatus);
+
+    return (testStatus);
+}
+
+psS32 t03F64()
+{
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): all inputs are NULL");
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null arguments.");
+
+    psVectorFitPolynomial1D(NULL, NULL, 0, NULL, NULL, NULL);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): all inputs are NULL",
+                testStatus);
+
+    return(testStatus);
+}
+
+psS32 main()
+{
+    psBool testStatus = true;
+    psLogSetFormat("HLNM");
+    printPositiveTestHeader(stdout, "psMinimize functions: testing the 1-D Polynomial fitting routines.", "");
+    testStatus &= t00F32();
+    testStatus &= t01F32();
+    testStatus &= t02F32();
+    testStatus &= t03F32();
+    testStatus &= t00F64();
+    testStatus &= t01F64();
+    testStatus &= t02F64();
+    testStatus &= t03F64();
+
+    printFooter(stdout, "psMinimize functions: testing the 1-D Polynomial fitting routines.", "", testStatus);
+}
+
Index: /trunk/psLib/test/math/tst_psPolyFit2DOrd.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolyFit2DOrd.c	(revision 5813)
+++ /trunk/psLib/test/math/tst_psPolyFit2DOrd.c	(revision 5813)
@@ -0,0 +1,129 @@
+/*****************************************************************************
+This routine must ensure that the psVectorFitPolynomial2D works correctly.
+We create a vectors of data points (x and y), and populate them with the
+values from an arbitrary function setData().  We then call
+psVectorFitPolynomial2D() with a regular polynomial data structure.  We then
+evaluate the polynomial with the coefficients generated above and determine
+if they are within an error tolerance of the expected values.
+     *****************************************************************************/
+#include <stdio.h>
+#include "pslib_strict.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psVector.h"
+#include "psImage.h"
+#include "psMinimize.h"
+#include <math.h>
+#define NUM_DATA 10
+#define POLY_ORDER 3
+#define A 3.0
+#define B 2.0
+#define C 3.0
+#define D 3.0
+#define E 3.0
+#define F 3.0
+#define ERROR_TOLERANCE 0.10
+#define FERR 1.0
+#define VERBOSE 0
+
+double setData(double x, double y)
+{
+    return(A + (B * x) + (C * x * x) + (D * y) + (E * y * y) + (F * x * y));
+}
+
+psS32 t00()
+{
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    double expectData;
+    double actualData;
+
+    psPolynomial2D *myPoly = psPolynomial2DAlloc(POLY_ORDER, POLY_ORDER, PS_POLYNOMIAL_ORD);
+    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+
+    for (psS32 i=0;i<NUM_DATA;i++) {
+        x->data.F32[i] = (double) i;
+        y->data.F32[i] = (double) (2 * i);
+        f->data.F32[i] = setData(x->data.F32[i], y->data.F32[i]);
+        fErr->data.F32[i] = FERR;
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial2D(): equal difference in variable fErr");
+
+    psVectorFitPolynomial2D(myPoly, NULL, 0, f, fErr, x, y);
+
+    if (VERBOSE) {
+        for (psS32 i=0;i<POLY_ORDER+1;i++) {
+            for (psS32 j=0;j<POLY_ORDER+1;j++) {
+                printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i][j]);
+            }
+        }
+    }
+
+    for (psS32 i=0;i<NUM_DATA;i++) {
+        expectData = setData(x->data.F32[i],  y->data.F32[i]);
+        actualData = psPolynomial2DEval(myPoly, x->data.F32[i], y->data.F32[i]);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F32[i], y->data.F32[i], actualData, expectData);
+            testStatus = false;
+        }
+        if (VERBOSE) {
+            printf("GOOD: Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
+        }
+    }
+
+
+    printf("Running test with fErr set to NULL.\n");
+    psVectorFitPolynomial2D(myPoly, NULL, 0, f, NULL, x, y);
+    for (psS32 i=0;i<NUM_DATA;i++) {
+        expectData = setData(x->data.F32[i],  y->data.F32[i]);
+        actualData = psPolynomial2DEval(myPoly, x->data.F32[i], y->data.F32[i]);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("TEST ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F32[i], y->data.F32[i], actualData, expectData);
+            testStatus = false;
+        }
+        if (VERBOSE) {
+            printf("Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
+        }
+    }
+    psFree(myPoly);
+
+    printf("Running test with x, y set to NULL.  Should generate error.\n");
+    myPoly = psVectorFitPolynomial2D(NULL, NULL, 0, f, fErr, NULL, NULL);
+    if (myPoly != NULL) {
+        printf("TEST ERROR: psVectorFitPolynomial2D() returned non-NULL.\n");
+        testStatus = false;
+    }
+
+    psMemCheckCorruption(1);
+    psFree(x);
+    psFree(y);
+    psFree(f);
+    psFree(fErr);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial2D(): equal differences in variable fErr",
+                testStatus);
+
+    return (!testStatus);
+}
+
+psS32 main()
+{
+    psLogSetFormat("HLNM");
+    t00();
+}
Index: /trunk/psLib/test/math/tst_psStats07.c
===================================================================
--- /trunk/psLib/test/math/tst_psStats07.c	(revision 5812)
+++ /trunk/psLib/test/math/tst_psStats07.c	(revision 5813)
@@ -20,4 +20,5 @@
 psS32 t00()
 {
+
     psStats * myStats = NULL;
     psS32 testStatus = true;
@@ -510,4 +511,5 @@
 {
     psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
     //
     // We list pertinent psStats.c functions here for debugging ease.
