Index: /trunk/psLib/test/dataManip/Makefile
===================================================================
--- /trunk/psLib/test/dataManip/Makefile	(revision 1964)
+++ /trunk/psLib/test/dataManip/Makefile	(revision 1965)
@@ -3,6 +3,6 @@
 ##  Makefile:   test/sysUtils
 ##
-##  $Revision: 1.48 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-10-03 23:35:47 $
+##  $Revision: 1.49 $  $Name: not supported by cvs2svn $
+##  $Date: 2004-10-06 00:28:18 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -41,5 +41,7 @@
 tst_psMatrixVectorArithmetic03 \
 tst_psMinimize04 \
+tst_psMinimize04_F32 \
 tst_psMinimize04b \
+tst_psMinimize04b_F32 \
 tst_psMinimize05 \
 tst_psMinimize06 \
Index: /trunk/psLib/test/dataManip/tst_psMinimize04_F32.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psMinimize04_F32.c	(revision 1965)
+++ /trunk/psLib/test/dataManip/tst_psMinimize04_F32.c	(revision 1965)
@@ -0,0 +1,258 @@
+/*****************************************************************************
+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.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psVector.h"
+#include "psImage.h"
+#include "psFunctions.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));
+}
+
+int t00()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    psVector *yErr = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+    float expectData;
+    float actualData;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, 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, x, y, yErr);
+
+    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(x->data.F32[i], myPoly);
+        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);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): equal errors in yErr",
+                testStatus);
+
+    return (!testStatus);
+}
+
+int t01()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+    float expectData;
+    float actualData;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, 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, x, y, 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(x->data.F32[i]);
+        actualData = psPolynomial1DEval(x->data.F32[i], myPoly);
+        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);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): yErr is NULL",
+                testStatus);
+
+    return (!testStatus);
+}
+
+int t02()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *y = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+    float expectData;
+    float actualData;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, 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, y, 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((float) i, myPoly);
+        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);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): x, yErr is NULL",
+                testStatus);
+
+    return (!testStatus);
+}
+
+int t03()
+{
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): all inputs are NULL");
+
+    psVectorFitPolynomial1D(NULL, NULL, NULL, NULL);
+
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): all inputs are NULL",
+                testStatus);
+
+    return (!testStatus);
+}
+
+
+int main()
+{
+    t00();
+    t01();
+    t02();
+    t03();
+}
Index: /trunk/psLib/test/dataManip/tst_psMinimize04b_F32.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psMinimize04b_F32.c	(revision 1965)
+++ /trunk/psLib/test/dataManip/tst_psMinimize04b_F32.c	(revision 1965)
@@ -0,0 +1,244 @@
+/*****************************************************************************
+    This routine must ensure that the psVectorFitPolynomial1D works correctly.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psVector.h"
+#include "psImage.h"
+#include "psFunctions.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));
+}
+
+int t00()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    psVector *yErr = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, 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_psNormalizeVector(x);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, equal errors in yErr");
+
+    psVectorFitPolynomial1D(myPoly, x, y, yErr);
+
+    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(x->data.F32[i], myPoly);
+        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);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, equal errors in yErr",
+                testStatus);
+    return (!testStatus);
+}
+
+
+int t01()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, 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_psNormalizeVector(x);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is 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++) {
+        float expectData = y->data.F32[i];
+        float actualData = psPolynomial1DEval(x->data.F32[i], myPoly);
+        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);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
+                testStatus);
+    return (!testStatus);
+}
+
+
+int t02()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, 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_psNormalizeVector(x);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, y, 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(x->data.F32[i], myPoly);
+        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);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL",
+                testStatus);
+    return (!testStatus);
+}
+
+int t03()
+{
+    psPolynomial1D *myPoly = NULL;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
+
+    myPoly = psVectorFitPolynomial1D(NULL, NULL, NULL, NULL);
+    if (myPoly != NULL) {
+        printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n");
+        testStatus = false;
+    }
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
+                testStatus);
+    return (!testStatus);
+}
+
+int main()
+{
+    t00();
+    t01();
+    t02();
+    t03();
+}
