Index: /trunk/psLib/test/imageops/tst_psImageStats.c
===================================================================
--- /trunk/psLib/test/imageops/tst_psImageStats.c	(revision 6303)
+++ /trunk/psLib/test/imageops/tst_psImageStats.c	(revision 6304)
@@ -718,9 +718,4 @@
             }
         }
-        tmpImage->data.F32[ tmpImage->numRows/4 ][ tmpImage->numCols/4 ] = 10000000.0;
-        tmpImage->data.F32[ tmpImage->numRows/4 ][ 3 * tmpImage->numCols/4 ] = 10000000.0;
-        tmpImage->data.F32[ 3 * tmpImage->numRows/4 ][ tmpImage->numCols/4 ] = 10000000.0;
-        tmpImage->data.F32[ 3 * tmpImage->numRows/4 ][ 3 * tmpImage->numCols/4 ] = 10000000.0;
-
 
         for ( i = 0;i < tmpMask->numRows;i++ ) {
@@ -736,5 +731,4 @@
 
         myStats = psStatsAlloc( PS_STAT_SAMPLE_MEAN );
-        //        myStats = psStatsAlloc( PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV | PS_STAT_ROBUST_QUARTILE | PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV );
         /*************************************************************************/
         /*  Calculate Sample Mean with no mask                           */
Index: /trunk/psLib/test/math/Makefile.am
===================================================================
--- /trunk/psLib/test/math/Makefile.am	(revision 6303)
+++ /trunk/psLib/test/math/Makefile.am	(revision 6304)
@@ -8,4 +8,5 @@
     tst_psHist02 \
     tst_psHist03 \
+    tst_psMathUtils \
     tst_psMatrix01 \
     tst_psMatrix02 \
@@ -47,4 +48,5 @@
 tst_psHist02_SOURCES =  tst_psHist02.c
 tst_psHist03_SOURCES =  tst_psHist03.c
+tst_psMathUtils_SOURCES =  tst_psMathUtils.c
 tst_psMatrix01_SOURCES =  tst_psMatrix01.c
 tst_psMatrix02_SOURCES =  tst_psMatrix02.c
Index: /trunk/psLib/test/math/tst_psMathUtils.c
===================================================================
--- /trunk/psLib/test/math/tst_psMathUtils.c	(revision 6304)
+++ /trunk/psLib/test/math/tst_psMathUtils.c	(revision 6304)
@@ -0,0 +1,216 @@
+/*****************************************************************************
+This routine contains code which tests the general math utility functions.
+ *****************************************************************************/
+#include <stdio.h>
+#include <math.h>
+#include "pslib.h"
+#include "psTest.h"
+#define NUM_DATA 10
+#define VERBOSE 0
+#define TS00_X_F32  0x00000001
+#define TS00_X_F64  0x00000002
+#define TS00_X_NULL  0x00000004
+#define TS00_DOMAIN_F32  0x00000008
+#define TS00_DOMAIN_F64  0x00000010
+#define TS00_DOMAIN_NULL 0x00000020
+#define TS00_RANGE_F32  0x00000040
+#define TS00_RANGE_F64  0x00000080
+#define TS00_RANGE_NULL  0x00000200
+
+psS32 genericInterpolateTest(
+    psU32 flags,
+    psS32 order,
+    psS32 numData,
+    psF64 xValue,
+    psBool expectedRC)
+{
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psScalar *x = NULL;
+    psVector *domain = NULL;
+    psVector *range = NULL;
+    psScalar *out = NULL;
+
+    printPositiveTestHeader(stdout, "psMathUtils functions", "1D Interpolation routines");
+
+    if (expectedRC == false) {
+        printf("This test should generate an error message, and return NULL.\n");
+    }
+
+    if (flags & TS00_X_NULL) {
+        printf(" using a NULL x scalar\n");
+    }
+
+    if (flags & TS00_X_F32) {
+        printf(" using a psF32 x scalar\n");
+        x = psScalarAlloc((psF32) xValue, PS_TYPE_F32);
+    }
+
+    if (flags & TS00_X_F64) {
+        printf(" using a psF64 x scalar\n");
+        x = psScalarAlloc((psF64) xValue, PS_TYPE_F64);
+    }
+
+    if (flags & TS00_DOMAIN_NULL) {
+        printf(" using a NULL domain vector\n");
+    }
+
+    if (flags & TS00_DOMAIN_F32) {
+        printf(" using a psF32 domain vector\n");
+        domain = psVectorAlloc(numData, PS_TYPE_F32);
+        for (psS32 i=0;i<numData;i++) {
+            domain->data.F32[i] = (psF32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original domain data %d: (%.1f)\n", i, domain->data.F32[i]);
+            }
+        }
+    }
+
+    if (flags & TS00_DOMAIN_F64) {
+        printf(" using a psF64 domain vector\n");
+        domain = psVectorAlloc(numData, PS_TYPE_F64);
+        for (psS64 i=0;i<numData;i++) {
+            domain->data.F64[i] = (psF64) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original domain data %d: (%.1f)\n", i, domain->data.F64[i]);
+            }
+        }
+    }
+
+    if (flags & TS00_RANGE_NULL) {
+        printf(" using a NULL range vector\n");
+    }
+
+    if (flags & TS00_RANGE_F32) {
+        printf(" using a psF32 range vector\n");
+        range = psVectorAlloc(numData, PS_TYPE_F32);
+        for (psS32 i=0;i<numData;i++) {
+            range->data.F32[i] = (psF32) 2*i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original range data %d: (%.1f)\n", i, range->data.F32[i]);
+            }
+        }
+    }
+
+    if (flags & TS00_RANGE_F64) {
+        printf(" using a psF64 range vector\n");
+        range = psVectorAlloc(numData, PS_TYPE_F64);
+        for (psS64 i=0;i<numData;i++) {
+            range->data.F64[i] = (psF64) 2*i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original range data %d: (%.1f)\n", i, range->data.F64[i]);
+            }
+        }
+    }
+
+
+    out = p_psVectorInterpolate(NULL, domain, range, order, x);
+
+    if (out == NULL) {
+        if (expectedRC == true) {
+            printf("TEST ERROR: the p_psVectorInterpolate function returned NULL.\n");
+            testStatus = false;
+        }
+    } else {
+        if (expectedRC == false) {
+            printf("TEST ERROR: the p_psVectorInterpolate function returned non-NULL.\n");
+            testStatus = false;
+        }
+
+        if (flags & TS00_X_F32) {
+            printf("The interpolated value was %.2f: should be %.2f\n", out->data.F32, 2.0 * x->data.F32);
+        } else if (flags & TS00_X_F64) {
+            printf("The interpolated value was %.2f: should be %.2f\n", out->data.F64, 2.0 * x->data.F64);
+        }
+
+        /*
+        if (0) {
+                if (flags & TS00_F_F32) {
+                    expectData = f->data.F32[i];
+                } else if (flags & TS00_F_F64) {
+                    expectData = (psF32) f->data.F64[i];
+                } else if (flags & TS00_F_S32) {
+                    expectData = (psF32) f->data.S32[i];
+                }
+         
+                    if (flags & TS00_X_F32) {
+                        xData = x->data.F32[i];
+                    } else if (flags & TS00_X_F64) {
+                        xData = (psF32) x->data.F64[i];
+                    } else if (flags & TS00_X_S32) {
+                        xData = (psF32) x->data.S32[i];
+                    } else if (flags & TS00_X_NULL) {
+                        if (flags & TS00_POLY_ORD) {
+                            xData = (psF32) i;
+                        } else if (flags & TS00_POLY_CHEB) {
+                            xData = ((2.0 / ((psF32) (numData - 1))) * ((psF32) i)) - 1.0;
+                        }
+                    }
+         
+                    psF32 actualData = psPolynomial1DEval(myPoly, xData);
+         
+                    if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+                        printf("TEST ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                               i, xData, actualData, expectData);
+                        testStatus = false;
+                     } else {
+                        if (VERBOSE) {
+                            printf("GOOD: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                                     i, xData, actualData, expectData);
+                        }
+                    }
+                }
+        }
+        */
+    }
+
+    psMemCheckCorruption(1);
+    psFree(x);
+    psFree(out);
+    psFree(domain);
+    psFree(range);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout, "psMinimize functions", "1D Interpolation routines", testStatus);
+
+    return (testStatus);
+}
+
+/*****************************************************************************
+We test a variety of 
+ *****************************************************************************/
+psS32 main()
+{
+    psBool testStatus = true;
+    psLogSetFormat("HLNM");
+    psTraceSetLevel(".", 0);
+    printPositiveTestHeader(stdout, "psMathUtils functions: 1D Interpolation routines", "");
+
+    //
+    // F32 tests:
+    //
+    // All Vectors non-NULL
+
+    testStatus &= genericInterpolateTest(TS00_X_F32 | TS00_DOMAIN_F32 | TS00_RANGE_F32, 5, NUM_DATA, 5.5, true);
+
+    printFooter(stdout, "psMinimize functions: 1D Polynomial Fitting Functions", "", testStatus);
+}
+
+//This code will
Index: /trunk/psLib/test/math/tst_psPolyFit1D.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolyFit1D.c	(revision 6303)
+++ /trunk/psLib/test/math/tst_psPolyFit1D.c	(revision 6304)
@@ -104,5 +104,5 @@
 
         if (flags & TS00_POLY_CHEB) {
-            p_psNormalizeVectorRangeF32(x, -1.0, 1.0);
+            p_psNormalizeVectorRange(x, -1.0, 1.0);
         }
     }
@@ -116,5 +116,5 @@
 
         if (flags & TS00_POLY_CHEB) {
-            p_psNormalizeVectorRangeS32(x, -1, 1);
+            p_psNormalizeVectorRange(x, -1, 1);
         }
     }
@@ -128,5 +128,5 @@
 
         if (flags & TS00_POLY_CHEB) {
-            p_psNormalizeVectorRangeF64(x, -1.0, 1.0);
+            p_psNormalizeVectorRange(x, -1.0, 1.0);
         }
     }
Index: /trunk/psLib/test/math/tst_psPolynomial.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolynomial.c	(revision 6304)
+++ /trunk/psLib/test/math/tst_psPolynomial.c	(revision 6304)
@@ -0,0 +1,353 @@
+/** tst_Func00.c
+*
+*    This routine must ensure that the psPolynomial structures are
+*    allocated and deallocated by the psPolynomialXXXlloc() procedures.
+*    It also calls the various psPolynomialXXXEval() procedures.
+*
+*    The F32 and F64 polynomials are tested for all orders (1 - 4) and for
+*    both ordinary and chebyshev polynomials.
+*
+*    NOTE: This test code requries the stdout file to verify that the results
+*    are good.
+*
+*    XXX: Modify these tests so that polynomials with a variety of different
+*    orders are created.
+* 
+*    XXX: Compare to FLT_EPSILON
+* 
+*    @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
+*    @date $Date: 2006-02-02 21:05:51 $
+*
+*  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
+*
+*****************************************************************************/
+#include <stdio.h>
+#include "pslib_strict.h"
+#include "psTest.h"
+
+// Defines
+#define ORDER    3
+
+static psS32 testPolynomial1DAlloc(void);
+static psS32 testPolynomial2DAlloc(void);
+static psS32 testPolynomial3DAlloc(void);
+static psS32 testPolynomial4DAlloc(void);
+
+testDescription tests[] = {
+                              {testPolynomial1DAlloc,578,"psPolynomial1DAlloc",0,false},
+                              {testPolynomial2DAlloc,578,"psPolynomial2DAlloc",0,false},
+                              {testPolynomial3DAlloc,578,"psPolynomial3DAlloc",0,false},
+                              {testPolynomial4DAlloc,578,"psPolynomial4DAlloc",0,false},
+                              {NULL}
+                          };
+
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
+
+    return !runTestSuite(stderr,"psPolynomialXD", tests, argc, argv);
+}
+
+
+// This test will allocate a 1D polynomial and verify the structure allocated
+psS32 testPolynomial1DAlloc(void)
+{
+    psPolynomial1D*  my1DPoly  = NULL;
+
+    // Allocate polynomial
+    my1DPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, ORDER);
+    // Verify structure allocated
+    if(my1DPoly == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected");
+        return 1;
+    }
+    // Verify polynomial structure members set properly
+    if(my1DPoly->nX != ORDER) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my1DPoly->nX, ORDER);
+        return 2;
+    }
+    if(my1DPoly->type != PS_POLYNOMIAL_ORD) {
+        psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d",
+                my1DPoly->type, PS_POLYNOMIAL_ORD);
+        return 3;
+    }
+    for(psS32 i = 0; i < ORDER+1; i++) {
+        if(my1DPoly->coeff[i] != 0.0) {
+            psError(PS_ERR_UNKNOWN,true,"Coeff[%d] %lg not as expected %lg",
+                    i, my1DPoly->coeff[i], 0.0);
+            return 4;
+        }
+        if(my1DPoly->coeffErr[i] != 0.0) {
+            psError(PS_ERR_UNKNOWN,true,"CoeffErr[%d] %lg not as expected %lg",
+                    i, my1DPoly->coeffErr[i], 0.0);
+            return 5;
+        }
+        if(my1DPoly->mask[i] != 0) {
+            psError(PS_ERR_UNKNOWN,true,"Mask[%d] %d not as expected %d",
+                    i, my1DPoly->mask[i], 0);
+            return 6;
+        }
+    }
+    psFree(my1DPoly);
+
+    if (0) {
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, -1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 7;
+        }
+    }
+
+    return 0;
+}
+
+// This test will allocate a 2D polynomial and verify the structure allocated
+psS32 testPolynomial2DAlloc(void)
+{
+    psPolynomial2D* my2DPoly = NULL;
+
+    // Allocate polynomial
+    my2DPoly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, ORDER,ORDER+1);
+    // Verify structure allocated
+    if(my2DPoly == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected");
+        return 1;
+    }
+    // Verify polynomial structure members set properly
+    if(my2DPoly->nX != ORDER) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my2DPoly->nX, ORDER);
+        return 2;
+    }
+    // Verify polynomial structure members set properly
+    if(my2DPoly->nY != ORDER+1) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my2DPoly->nY, ORDER+1);
+        return 3;
+    }
+    if(my2DPoly->type != PS_POLYNOMIAL_ORD) {
+        psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d",
+                my2DPoly->type, PS_POLYNOMIAL_ORD);
+        return 4;
+    }
+
+    for(psS32 i = 0; i < ORDER+1; i++) {
+        for(psS32 j = 0; j < ORDER+2; j++) {
+            if(fabs(my2DPoly->coeff[i][j]) > FLT_EPSILON) {
+                psError(PS_ERR_UNKNOWN,true,"Coeff[%d][%d] %lg not as expected %lg",
+                        i, j, my2DPoly->coeff[i][j], 0.0);
+                return 5;
+            }
+            if(my2DPoly->coeffErr[i][j] != 0.0) {
+                psError(PS_ERR_UNKNOWN,true,"CoeffErr[%d][%d] %lg not as expected %lg",
+                        i, j, my2DPoly->coeffErr[i][j], 0.0);
+                return 6;
+            }
+            if(my2DPoly->mask[i][j] != 0) {
+                psError(PS_ERR_UNKNOWN,true,"Mask[%d][%d] %d not as expected %d",
+                        i, j, my2DPoly->mask[i][j], 0);
+                return 7;
+            }
+        }
+    }
+    psFree(my2DPoly);
+
+    if (0) {
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, -1, 1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 8;
+        }
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, 1, -1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 9;
+        }
+    }
+    return 0;
+}
+
+// This test will allocate a 3D polynomial and verify the structure allocated
+psS32 testPolynomial3DAlloc(void)
+{
+    psPolynomial3D* my3DPoly = NULL;
+
+    // Allocate polynomial
+    my3DPoly = psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, ORDER, ORDER+1, ORDER+2);
+    // Verify structure allocated
+    if(my3DPoly == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected");
+        return 1;
+    }
+    // Verify polynomial structure members set properly
+    if(my3DPoly->nX != ORDER) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my3DPoly->nX, ORDER);
+        return 2;
+    }
+    // Verify polynomial structure members set properly
+    if(my3DPoly->nY != ORDER+1) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my3DPoly->nY, ORDER+1);
+        return 3;
+    }
+    // Verify polynomial structure members set properly
+    if(my3DPoly->nZ != ORDER+2) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my3DPoly->nZ, ORDER+2);
+        return 4;
+    }
+    if(my3DPoly->type != PS_POLYNOMIAL_ORD) {
+        psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d",
+                my3DPoly->type, PS_POLYNOMIAL_ORD);
+        return 5;
+    }
+    for(psS32 i = 0; i < ORDER+1; i++) {
+        for(psS32 j = 0; j < ORDER+2; j++) {
+            for(psS32 k = 0; k < ORDER+3; k++) {
+                if(my3DPoly->coeff[i][j][k] != 0.0) {
+                    psError(PS_ERR_UNKNOWN,true,"Coeff[%d][%d][%d] %lg not as expected %lg",
+                            i, j, k, my3DPoly->coeff[i][j][k], 0.0);
+                    return 6;
+                }
+                if(my3DPoly->coeffErr[i][j][k] != 0.0) {
+                    psError(PS_ERR_UNKNOWN,true,"CoeffErr[%d][%d][%d] %lg not as expected %lg",
+                            i, j, k, my3DPoly->coeffErr[i][j][k], 0.0);
+                    return 7;
+                }
+                if(my3DPoly->mask[i][j][k] != 0) {
+                    psError(PS_ERR_UNKNOWN,true,"Mask[%d][%d] %d not as expected %d",
+                            i, j, k, my3DPoly->mask[i][j][k], 0);
+                    return 8;
+                }
+            }
+        }
+    }
+    psFree(my3DPoly);
+
+    if (0) {
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, -1, 1, 1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 9;
+        }
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, 1, -1, 1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 10;
+        }
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, 1, 1, -1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 11;
+        }
+    }
+
+    return 0;
+}
+
+// This test will allocate a 4D polynomial and verify the structure allocated
+psS32 testPolynomial4DAlloc(void)
+{
+    psPolynomial4D* my4DPoly = NULL;
+
+    // Allocate polynomial
+    my4DPoly = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, ORDER,ORDER+1,ORDER+2,ORDER+3);
+    // Verify structure allocated
+    if(my4DPoly == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Returned NULL not expected");
+        return 1;
+    }
+    // Verify polynomial structure members set properly
+    if(my4DPoly->nX != ORDER) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my4DPoly->nX, ORDER);
+        return 2;
+    }
+    // Verify polynomial structure members set properly
+    if(my4DPoly->nY != ORDER+1) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my4DPoly->nX, ORDER+1);
+        return 3;
+    }
+    // Verify polynomial structure members set properly
+    if(my4DPoly->nZ != ORDER+2) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my4DPoly->nZ, ORDER+2);
+        return 4;
+    }
+    // Verify polynomial structure members set properly
+    if(my4DPoly->nT != ORDER+3) {
+        psError(PS_ERR_UNKNOWN,true,"Number of terms %d not as expected %d",
+                my4DPoly->nT, ORDER+3);
+        return 5;
+    }
+    if(my4DPoly->type != PS_POLYNOMIAL_ORD) {
+        psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d",
+                my4DPoly->type, PS_POLYNOMIAL_ORD);
+        return 6;
+    }
+    for(psS32 i = 0; i < ORDER+1; i++) {
+        for(psS32 j = 0; j < ORDER+2; j++) {
+            for(psS32 k = 0; k < ORDER+3; k++) {
+                for(psS32 l = 0; l < ORDER+4; l++) {
+                    if(my4DPoly->coeff[i][j][k][l] != 0.0) {
+                        psError(PS_ERR_UNKNOWN,true,"Coeff[%d][%d][%d][%d] %lg not as expected %lg",
+                                i, j, k, l, my4DPoly->coeff[i][j][k][l], 0.0);
+                        return 7;
+                    }
+                    if(my4DPoly->coeffErr[i][j][k][l] != 0.0) {
+                        psError(PS_ERR_UNKNOWN,true,"CoeffErr[%d][%d][%d][l] %lg not as expected %lg",
+                                i, j, k, l, my4DPoly->coeffErr[i][j][k][l], 0.0);
+                        return 8;
+                    }
+                    if(my4DPoly->mask[i][j][k][l] != 0) {
+                        psError(PS_ERR_UNKNOWN,true,"Mask[%d][%d][%d][%d] %d not as expected %d",
+                                i, j, k, l, my4DPoly->mask[i][j][k][l], 0);
+                        return 9;
+                    }
+                }
+            }
+        }
+    }
+    psFree(my4DPoly);
+
+    if (0) {
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, -1, 1, 1, 1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 10;
+        }
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, 1, -1, 1, 1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 11;
+        }
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, 1, 1, -1, 1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 12;
+        }
+        // Attempt to allocate with negative order
+        psLogMsg(__func__,PS_LOG_INFO,"Following should generate error msg for negative terms");
+        if(psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, 1, 1, 1, -1) != NULL) {
+            psError(PS_ERR_UNKNOWN,true,"Returned structure but expected NULL");
+            return 13;
+        }
+    }
+
+    return 0;
+}
+
Index: /trunk/psLib/test/math/tst_psPolynomialEval1D.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolynomialEval1D.c	(revision 6304)
+++ /trunk/psLib/test/math/tst_psPolynomialEval1D.c	(revision 6304)
@@ -0,0 +1,195 @@
+/** tst_psFunc08.c
+*
+*  This test driver will exercise the psPolynomialXDEval functions for both
+*  ORD and CHEB type polynomials.
+*
+*  @version  $Revision: 1.1 $  $Name: not supported by cvs2svn $
+*  @date  $Date: 2006-02-02 21:05:51 $
+*
+*  XXX: Probably should test single- and multi-dimensional polynomials in
+*  which one diminsion is constant (n == 1).
+*
+*  XXX: define ORDERS, not TERMS
+* 
+*
+* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
+*
+***************************************************************************/
+
+#include "pslib_strict.h"
+#include "psTest.h"
+
+#define  TERMS        4
+#define  TESTPOINTS   5
+#define  ERROR_TOL    0.001
+
+static psS32 testPoly1DEval(void);
+static psS32 testPoly1DEvalVector(void);
+
+testDescription tests[] = {
+                              {testPoly1DEval,000,"psPolynomial1DEval",0,false},
+                              {testPoly1DEvalVector,000,"psPolynomial1DEvalVector",0,false},
+                              {NULL}
+                          };
+
+psF32 poly1DCoeff[TERMS]        = { -4.3, 2.3, -3.2, 1.9};
+psF64 Dpoly1DCoeff[TERMS]        = { -4.3, 2.3, -3.2, 1.9};
+psF32 poly1DMask[TERMS]         = {    0,   0,    1,   0  };
+
+psF32 poly1DXValue[TESTPOINTS]   = { 2.550000,    -9.8000,   0.00134,   -12.2500,   0.000};
+psF64 Dpoly1DXValue[TESTPOINTS]  = { 2.550000,    -9.8000,   0.00134,   -12.2500,   0.000};
+psF32 poly1DXResult[TESTPOINTS]  = {33.069613, -1815.1048, -4.296918, -3525.1797, -4.3000};
+psF64 Dpoly1DXResult[TESTPOINTS] = {33.069613, -1815.1048, -4.296918, -3525.1797, -4.3000};
+
+psF32 poly1DXChebValue[TESTPOINTS]   = { -0.99,    -0.33,     0.125,    0.564,    0.875};
+psF64 Dpoly1DXChebValue[TESTPOINTS]  = { -0.99,    -0.33,     0.125,    0.564,    0.875};
+psF32 poly1DXChebResult[TESTPOINTS]  = { -1.401196, 1.016252, 0.257813, 0.089625, 1.429688};
+psF64 Dpoly1DXChebResult[TESTPOINTS] = { -1.401196, 1.016252, 0.257813, 0.089625, 1.429688};
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
+
+    return !runTestSuite(stderr,"psPolynomialXDEval", tests, argc, argv);
+}
+
+// This test will verify operation of 1D polynomial evaluation
+psS32 testPoly1DEval(void)
+{
+    psF64  result;
+    psF64  resultCheb;
+
+    // Allocate polynomial structure
+    psPolynomial1D*  polyOrd = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, TERMS-1);
+    psPolynomial1D*  polyCheb = psPolynomial1DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1);
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        polyOrd->coeff[i] = poly1DCoeff[i];
+        polyOrd->mask[i]  = poly1DMask[i];
+        polyCheb->coeff[i] = 1.0;
+        polyCheb->mask[i]  = poly1DMask[i];
+    }
+    // Evaluate test points and verify results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        result = psPolynomial1DEval(polyOrd,poly1DXValue[i]);
+        if(fabs(poly1DXResult[i]-result) > ERROR_TOL ) {
+            psError(PS_ERR_UNKNOWN,true,"Evaluated value %g not as expected %g",
+                    result, poly1DXResult[i]);
+            return i;
+        }
+        resultCheb = psPolynomial1DEval(polyCheb,poly1DXChebValue[i]);
+        if(fabs(poly1DXChebResult[i]-resultCheb) > ERROR_TOL ) {
+            psError(PS_ERR_UNKNOWN,true,"Evaluated Chebyshev value %lg not as expected %lg",
+                    resultCheb, poly1DXChebResult[i]);
+            return 5*i;
+        }
+    }
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    // Allocate polynomial with invalid type
+    polyOrd = psPolynomial1DAlloc(99, TERMS-1);
+    // Attempt to evaluation invalid polynomial type
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type");
+    result = psPolynomial1DEval(polyOrd,0.0);
+    if ( !isnan(result) ) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");
+        return 20;
+    }
+    psFree(polyOrd);
+
+    return 0;
+}
+
+
+psS32 testPoly1DEvalVector(void)
+{
+    // Allocate polynomial
+    psPolynomial1D* polyOrd = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, TERMS-1);
+    psPolynomial1D* polyCheb = psPolynomial1DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1);
+
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        polyOrd->coeff[i] = poly1DCoeff[i];
+        polyOrd->mask[i]  = poly1DMask[i];
+        polyCheb->coeff[i] = 1.0;
+        polyCheb->mask[i]  = poly1DMask[i];
+    }
+
+    // Create input vectors
+    psVector* inputOrd = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputCheb = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        inputOrd->data.F64[i] = poly1DXValue[i];
+        inputCheb->data.F64[i] = poly1DXChebValue[i];
+    }
+
+    // Evaluate the vectors
+    psVector* outputOrd = psPolynomial1DEvalVector(polyOrd, inputOrd);
+    if(outputOrd == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
+        return 1;
+    }
+    if(outputOrd->type.type != PS_TYPE_F64) {
+        psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",
+                outputOrd->type.type, PS_TYPE_F64);
+        return 2;
+    }
+    psVector* outputCheb = psPolynomial1DEvalVector(polyCheb, inputCheb);
+    if(outputCheb == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Unexpected return of NULL.");
+        return 1;
+    }
+    if(outputCheb->type.type != PS_TYPE_F64) {
+        psError(PS_ERR_UNKNOWN,true,"Output vector of type %d expected %d",
+                outputCheb->type.type, PS_TYPE_F64);
+        return 2;
+    }
+
+    // Verify the results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        if(fabs(poly1DXResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) {
+            psError(PS_ERR_UNKNOWN,true,"Result[%d] %lg not equal to expected %lg",
+                    i, outputOrd->data.F64[i], poly1DXResult[i]);
+            return i*5;
+        }
+        if(fabs(poly1DXChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) {
+            psError(PS_ERR_UNKNOWN,true,"ResultCheb[%d] %lg not equal to expected %lg",
+                    i, outputCheb->data.F64[i], poly1DXChebResult[i]);
+            return i*10;
+        }
+    }
+
+    // Attempt to invoke function with null polynomial
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
+    if(psPolynomial1DEvalVector(NULL, inputOrd) != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL polynomial");
+        return 60;
+    }
+
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial1DEvalVector(polyOrd,NULL) != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Return of NULL expected for NULL input vector");
+        return 61;
+    }
+
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrd->type.type = PS_TYPE_U8;
+    if(psPolynomial1DEvalVector(polyOrd,inputOrd) != NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Return NULL expected for non-F64 input vector");
+        return 62;
+    }
+    inputOrd->type.type = PS_TYPE_F64;
+
+    psFree(inputOrd);
+    psFree(inputCheb);
+    psFree(outputOrd);
+    psFree(outputCheb);
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    return 0;
+}
Index: /trunk/psLib/test/math/tst_psPolynomialEval2D.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolynomialEval2D.c	(revision 6304)
+++ /trunk/psLib/test/math/tst_psPolynomialEval2D.c	(revision 6304)
@@ -0,0 +1,243 @@
+/** tst_psFunc09.c
+*
+*  This test driver will exercise the psPolynomialXDEval functions for both
+*  ORD and CHEB type polynomials.
+*
+*  @version  $Revision: 1.1 $  $Name: not supported by cvs2svn $
+*  @date  $Date: 2006-02-02 21:05:51 $
+*
+* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
+*
+***************************************************************************/
+
+#include "pslib_strict.h"
+#include "psTest.h"
+
+#define  TERMS        4
+#define  TESTPOINTS   5
+#define  ERROR_TOL    0.001
+
+static psS32 testPoly2DEval(void);
+static psS32 testPoly2DEvalVector(void);
+
+testDescription tests[] = {
+                              {testPoly2DEval,583,"psPolynomial2DEval",true,false},
+                              {testPoly2DEvalVector,000,"psPolynomial2DEvalVector",true,false},
+                              {NULL}
+                          };
+
+psF32 poly2DCoeff[TERMS][TERMS]   = {  { -4.3,  2.3, -3.2,  1.9},
+                                       {  1.2,  0.7, -0.3,  1.3},
+                                       {  0.4, -2.9,  0.8, -3.1},
+                                       { -1.1,  2.1,  1.9,  0.6}
+                                    };
+psF64 Dpoly2DCoeff[TERMS][TERMS]  = {  { -4.3,  2.3, -3.2,  1.9},
+                                       {  1.2,  0.7, -0.3,  1.3},
+                                       {  0.4, -2.9,  0.8, -3.1},
+                                       { -1.1,  2.1,  1.9,  0.6}
+                                    };
+psF32 poly2DMask[TERMS][TERMS]    = {  {  0,    0,    0,    1},
+                                       {  0,    0,    1,    0},
+                                       {  1,    0,    0,    0},
+                                       {  0,    0,    0,    1}
+                                    };
+
+psF32 poly2DXYValue[TESTPOINTS][2] = {  {  1.40,  0.55},
+                                        { -0.55,  1.40},
+                                        {  0.00,  2.34},
+                                        { -0.88,  0.00},
+                                        {  3.45, -0.78}
+                                     };
+psF32 Dpoly2DXYValue[TESTPOINTS][2] = {  {  1.40,  0.55},
+                                      { -0.55,  1.40},
+                                      {  0.00,  2.34},
+                                      { -0.88,  0.00},
+                                      {  3.45, -0.78}
+                                      };
+psF32 poly2DResult[TESTPOINTS] = {  -3.415938, -14.765687, -16.43992, -4.606381, -22.650702 };
+psF64 Dpoly2DResult[TESTPOINTS] = {  -3.415938, -14.765687, -16.43992, -4.606381, -22.650702 };
+
+psF32 poly2DXYChebValue[TESTPOINTS][2] = {  {  0.500,  0.500},
+        {  0.000,  0.250},
+        { -0.250,  0.000},
+        {  0.990,  0.150},
+        {  0.333, -0.666}
+                                         };
+psF32 Dpoly2DXYChebValue[TESTPOINTS][2] = {  {  0.500,  0.500},
+        {  0.000,  0.250},
+        { -0.250,  0.000},
+        {  0.990,  0.150},
+        {  0.333, -0.666}
+                                          };
+psF32 poly2DChebResult[TESTPOINTS] = {  0.750000, 1.687500, 0.625000, -0.113040, 0.386786 };
+psF32 Dpoly2DChebResult[TESTPOINTS] = {  0.750000, 1.687500, 0.625000, -0.113040, 0.386786 };
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
+
+    return !runTestSuite(stderr,"psPolynomialXDEval", tests, argc, argv);
+}
+
+// This test will verify operation of 1D polynomial evaluation
+psS32 testPoly2DEval(void)
+{
+    psF64  result;
+    psF64  resultCheb;
+    psBool testStatus = true;
+
+    // Allocate polynomial structure
+    psPolynomial2D*  polyOrd = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, TERMS-1, TERMS-1);
+    psPolynomial2D*  polyCheb = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1, TERMS-1);
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        for(psS32 j = 0; j < TERMS; j++) {
+            polyOrd->coeff[i][j] = poly2DCoeff[i][j];
+            polyOrd->mask[i][j]  = poly2DMask[i][j];
+            polyCheb->coeff[i][j] = 1.0;
+            polyCheb->mask[i][j]  = poly2DMask[i][j];
+        }
+    }
+    // Evaluate test points and verify results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        result = psPolynomial2DEval(polyOrd,Dpoly2DXYValue[i][0],Dpoly2DXYValue[i][1]);
+        if(fabs(Dpoly2DResult[i]-result) > ERROR_TOL ) {
+            printf("TEST ERROR: Evaluated value %f, should be %f\n", result, Dpoly2DResult[i]);
+            testStatus = false;
+        }
+        resultCheb = psPolynomial2DEval(polyCheb,Dpoly2DXYChebValue[i][0],Dpoly2DXYChebValue[i][1]);
+        if(fabs(Dpoly2DChebResult[i]-resultCheb) > ERROR_TOL ) {
+            printf("TEST ERROR: Evaluated value %f, should be %f\n", resultCheb, Dpoly2DChebResult[i]);
+            testStatus = false;
+        }
+    }
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    // Allocate polynomial with invalid type
+    polyOrd = psPolynomial2DAlloc(99, TERMS-1, TERMS-1);
+    // Attempt to evaluation invalid polynomial type
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type");
+    result = psPolynomial2DEval(polyOrd,0.0, 0.0);
+    if ( !isnan(result) ) {
+        psError(PS_ERR_UNKNOWN,true,"Did not return NAN for invalid polynomial type");
+        testStatus = false;
+    }
+    psFree(polyOrd);
+
+    return(testStatus);
+}
+
+psS32 testPoly2DEvalVector(void)
+{
+    psBool testStatus = true;
+    // Allocate polynomial
+    psPolynomial2D* polyOrd = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, TERMS-1, TERMS-1);
+    psPolynomial2D* polyCheb = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1, TERMS-1);
+
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        for(psS32 j = 0; j < TERMS; j++) {
+            polyOrd->coeff[i][j] = poly2DCoeff[i][j];
+            polyOrd->mask[i][j]  = poly2DMask[i][j];
+            polyCheb->coeff[i][j] = 1.0;
+            polyCheb->mask[i][j]  = poly2DMask[i][j];
+        }
+    }
+
+    // Create input vectors
+    psVector* inputOrdX  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputOrdY  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebX = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebY = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        inputOrdX->data.F64[i]  = poly2DXYValue[i][0];
+        inputOrdY->data.F64[i]  = poly2DXYValue[i][1];
+        inputChebX->data.F64[i] = poly2DXYChebValue[i][0];
+        inputChebY->data.F64[i] = poly2DXYChebValue[i][1];
+    }
+
+    // Evaluate the vectors
+    psVector* outputOrd = psPolynomial2DEvalVector(polyOrd, inputOrdX, inputOrdY);
+    if(outputOrd == NULL) {
+        printf("TEST ERROR: Unexpected return of NULL.\n");
+        testStatus = false;
+    }
+    if(outputOrd->type.type != PS_TYPE_F64) {
+        printf("TEST ERROR: Output vector of type %d expected %d\n", outputOrd->type.type, PS_TYPE_F64);
+        testStatus = false;
+    }
+    psVector* outputCheb = psPolynomial2DEvalVector(polyCheb, inputChebX, inputChebY);
+    if(outputCheb == NULL) {
+        printf("TEST ERROR: Unexpected return of NULL.\n");
+        testStatus = false;
+    }
+    if(outputCheb->type.type != PS_TYPE_F64) {
+        printf("TEST ERROR: Output vector of type %d expected %d.\n", outputCheb->type.type, PS_TYPE_F64);
+        testStatus = false;
+    }
+
+    // Verify the results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        if(fabs(poly2DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) {
+            printf("TEST ERROR: Result[%d] %lg not equal to expected %lg.\n",
+                   i, outputOrd->data.F64[i], poly2DResult[i]);
+            testStatus = false;
+        }
+        if(fabs(poly2DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) {
+            printf("TEST ERROR: ResultCheb[%d] %lg not equal to expected %lg.\n",
+                   i, outputCheb->data.F64[i], poly2DChebResult[i]);
+            testStatus = false;
+        }
+    }
+
+    // Attempt to invoke function with null polynomial
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
+    if(psPolynomial2DEvalVector(NULL, inputOrdX, inputOrdY) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL polynomial.\n");
+        testStatus = false;
+    }
+
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial2DEvalVector(polyOrd,NULL,inputOrdY) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector.\n");
+        testStatus = false;
+    }
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial2DEvalVector(polyOrd,inputOrdX,NULL) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector.\n");
+        testStatus = false;
+    }
+
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdX->type.type = PS_TYPE_U8;
+    if(psPolynomial2DEvalVector(polyOrd,inputOrdX, inputOrdY) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n");
+        testStatus = false;
+    }
+    inputOrdX->type.type = PS_TYPE_F64;
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdY->type.type = PS_TYPE_U8;
+    if(psPolynomial2DEvalVector(polyOrd,inputOrdX, inputOrdY) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n");
+        testStatus = false;
+    }
+    inputOrdY->type.type = PS_TYPE_F64;
+
+    psFree(inputOrdX);
+    psFree(inputOrdY);
+    psFree(inputChebX);
+    psFree(inputChebY);
+    psFree(outputOrd);
+    psFree(outputCheb);
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    return(testStatus);
+}
+
Index: /trunk/psLib/test/math/tst_psPolynomialEval3D.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolynomialEval3D.c	(revision 6304)
+++ /trunk/psLib/test/math/tst_psPolynomialEval3D.c	(revision 6304)
@@ -0,0 +1,324 @@
+/** tst_psFunc10.c
+*
+*  This test driver will exercise the psPolynomialXDEval functions for both
+*  ORD and CHEB type polynomials.
+*
+*  @version  $Revision: 1.1 $  $Name: not supported by cvs2svn $
+*  @date  $Date: 2006-02-02 21:05:51 $
+*
+* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
+*
+***************************************************************************/
+
+#include "pslib_strict.h"
+#include "psTest.h"
+
+#define  TERMS        4
+#define  TESTPOINTS   5
+#define  ERROR_TOL    0.001
+
+static psS32 testPoly3DEval(void);
+static psS32 testPoly3DEvalVector(void);
+
+testDescription tests[] = {
+                              {testPoly3DEval,583,"psPolynomial3DEval",true,false},
+                              {testPoly3DEvalVector,000,"psPolynomial3DEvalVector",true,false},
+                              {NULL}
+                          };
+
+psF32 poly3DCoeff[TERMS][TERMS][TERMS] = {  { { -1.1,  1.2, -1.3,  1.4},
+        {  1.5, -1.6,  1.7, -1.8},
+        {  0.1, -0.2,  0.3, -0.4},
+        { -0.5,  0.6, -0.7,  0.8}
+                                            },
+        { { -2.1,  2.2, -2.3,  2.4},
+          {  2.5, -2.6,  2.7, -2.8},
+          {  3.1, -3.2,  3.3, -3.4},
+          { -3.5,  3.6, -3.7,  3.8}
+        },
+        { { -4.1,  4.2, -4.3,  4.4},
+          {  4.5, -4.6,  4.7, -4.8},
+          {  5.1, -5.2,  5.3, -5.4},
+          { -5.5,  5.6, -5.7,  5.8}
+        },
+        { { -6.1,  6.2, -6.3,  6.4},
+          {  6.5, -6.6,  6.7, -6.8},
+          {  7.1, -7.2,  7.3, -7.4},
+          { -7.5,  7.6, -7.7,  7.8}
+        }
+                                         };
+psF64 Dpoly3DCoeff[TERMS][TERMS][TERMS] = {  { { -1.1,  1.2, -1.3,  1.4},
+        {  1.5, -1.6,  1.7, -1.8},
+        {  0.1, -0.2,  0.3, -0.4},
+        { -0.5,  0.6, -0.7,  0.8}
+                                             },
+        { { -2.1,  2.2, -2.3,  2.4},
+          {  2.5, -2.6,  2.7, -2.8},
+          {  3.1, -3.2,  3.3, -3.4},
+          { -3.5,  3.6, -3.7,  3.8}
+        },
+        { { -4.1,  4.2, -4.3,  4.4},
+          {  4.5, -4.6,  4.7, -4.8},
+          {  5.1, -5.2,  5.3, -5.4},
+          { -5.5,  5.6, -5.7,  5.8}
+        },
+        { { -6.1,  6.2, -6.3,  6.4},
+          {  6.5, -6.6,  6.7, -6.8},
+          {  7.1, -7.2,  7.3, -7.4},
+          { -7.5,  7.6, -7.7,  7.8}
+        }
+                                          };
+
+
+psF32 poly3DMask[TERMS][TERMS][TERMS]    = { {  {  0,    0,    0,    1},
+        {  0,    0,    1,    0},
+        {  1,    0,    0,    0},
+        {  0,    0,    0,    1}
+                                             },
+        {  {  1,    0,    0,    0},
+           {  1,    0,    0,    0},
+           {  1,    0,    0,    0},
+           {  1,    0,    0,    0}
+        },
+        {  {  0,    1,    0,    0},
+           {  0,    0,    1,    0},
+           {  0,    1,    0,    0},
+           {  0,    0,    1,    0}
+        },
+        {  {  1,    0,    0,    0},
+           {  0,    0,    0,    1},
+           {  1,    0,    0,    0},
+           {  0,    0,    0,    1}
+        },
+                                           };
+
+psF32 poly3DXYZValue[TESTPOINTS][3] = {  {  0.450, -0.780,  0.500},
+                                      {  0.297,  0.153, -0.354},
+                                      {  0.000,  0.153, -0.354},
+                                      {  0.297,  0.000, -0.354},
+                                      {  0.297,  0.153,  0.000}
+                                      };
+psF64 Dpoly3DXYZValue[TESTPOINTS][3] = {  {  0.450, -0.780,  0.500},
+                                       {  0.297,  0.153, -0.354},
+                                       {  0.000,  0.153, -0.354},
+                                       {  0.297,  0.000, -0.354},
+                                       {  0.297,  0.153,  0.000}
+                                       };
+psF32 poly3DResult[TESTPOINTS]  = { -1.298691, -2.011591, -1.359247, -2.548266, -1.139072};
+psF64 Dpoly3DResult[TESTPOINTS] = { -1.298691, -2.011591, -1.359247, -2.548266, -1.139072};
+
+
+psF32 poly3DXYZChebValue[TESTPOINTS][3] = {  {  0.000,  0.250, -0.250},
+        { -0.250,  0.000,  0.250},
+        {  0.250, -0.250,  0.000},
+        {  0.100, -0.300, -0.400},
+        {  0.990, -0.010,  0.500}
+                                          };
+psF64 Dpoly3DXYZChebValue[TESTPOINTS][3] = {  {  0.000,  0.250, -0.250},
+        { -0.250,  0.000,  0.250},
+        {  0.250, -0.250,  0.000},
+        {  0.100, -0.300, -0.400},
+        {  0.990, -0.010,  0.500}
+                                           };
+psF32 poly3DChebResult[TESTPOINTS]  = {  1.230469, 1.687500, 0.187500, -1.452707, 2.032344 };
+psF64 Dpoly3DChebResult[TESTPOINTS] = {  1.230469, 1.687500, 0.187500, -1.452707, 2.032344 };
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
+
+    return !runTestSuite(stderr,"psPolynomialXDEval", tests, argc, argv);
+}
+
+// This test will verify operation of 1D polynomial evaluation
+psS32 testPoly3DEval(void)
+{
+    psF64  result;
+    psF64  resultCheb;
+    psBool testStatus = true;
+
+    // Allocate polynomial structure
+    psPolynomial3D*  polyOrd = psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, TERMS-1, TERMS-1, TERMS-1);
+    psPolynomial3D*  polyCheb = psPolynomial3DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1, TERMS-1, TERMS-1);
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        for(psS32 j = 0; j < TERMS; j++) {
+            for(psS32 k = 0; k < TERMS; k++) {
+                polyOrd->coeff[i][j][k] = Dpoly3DCoeff[i][j][k];
+                polyOrd->mask[i][j][k]  = poly3DMask[i][j][k];
+                polyCheb->coeff[i][j][k] = 1.0;
+                polyCheb->mask[i][j][k]  = poly3DMask[i][j][k];
+            }
+        }
+    }
+    // Evaluate test points and verify results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        result = psPolynomial3DEval(polyOrd,Dpoly3DXYZValue[i][0],Dpoly3DXYZValue[i][1],
+                                    Dpoly3DXYZValue[i][2]);
+        if(fabs(Dpoly3DResult[i]-result) > ERROR_TOL ) {
+            printf("TEST ERROR: Evaluated value %lg not as expected %lg.\n",
+                   result, Dpoly3DResult[i]);
+            testStatus = false;
+        }
+        resultCheb = psPolynomial3DEval(polyCheb,Dpoly3DXYZChebValue[i][0],Dpoly3DXYZChebValue[i][1],
+                                        Dpoly3DXYZChebValue[i][2]);
+        if(fabs(Dpoly3DChebResult[i]-resultCheb) > ERROR_TOL ) {
+            printf("TEST ERROR: Evaluated Chebyshev value %lg not as expected %lg.\n",
+                   resultCheb, Dpoly3DChebResult[i]);
+            testStatus = false;
+        }
+    }
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    // Allocate polynomial with invalid type
+    polyOrd = psPolynomial3DAlloc(99, TERMS-1, TERMS-1, TERMS-1);
+    // Attempt to evaluation invalid polynomial type
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type");
+    result = psPolynomial3DEval(polyOrd,0.0, 0.0, 0.0);
+    if ( !isnan(result) ) {
+        printf("TEST ERROR: Did not return NAN for invalid polynomial type.\n");
+        testStatus = false;
+    }
+    psFree(polyOrd);
+
+    return(testStatus);
+}
+
+psS32 testPoly3DEvalVector(void)
+{
+    psBool testStatus = true;
+    // Allocate polynomial
+    psPolynomial3D* polyOrd = psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, TERMS-1, TERMS-1, TERMS-1);
+    psPolynomial3D* polyCheb = psPolynomial3DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1, TERMS-1, TERMS-1);
+
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        for(psS32 j = 0; j < TERMS; j++) {
+            for(psS32 k = 0; k < TERMS; k++) {
+                polyOrd->coeff[i][j][k] = Dpoly3DCoeff[i][j][k];
+                polyOrd->mask[i][j][k]  = poly3DMask[i][j][k];
+                polyCheb->coeff[i][j][k] = 1.0;
+                polyCheb->mask[i][j][k]  = poly3DMask[i][j][k];
+            }
+        }
+    }
+
+    // Create input vectors
+    psVector* inputOrdX  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputOrdY  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputOrdZ  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebX = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebY = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebZ = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        inputOrdX->data.F64[i]  = Dpoly3DXYZValue[i][0];
+        inputOrdY->data.F64[i]  = Dpoly3DXYZValue[i][1];
+        inputOrdZ->data.F64[i]  = Dpoly3DXYZValue[i][2];
+        inputChebX->data.F64[i] = Dpoly3DXYZChebValue[i][0];
+        inputChebY->data.F64[i] = Dpoly3DXYZChebValue[i][1];
+        inputChebZ->data.F64[i] = Dpoly3DXYZChebValue[i][2];
+    }
+
+    // Evaluate the vectors
+    psVector* outputOrd = psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ);
+    if(outputOrd == NULL) {
+        printf("TEST ERROR: Unexpected return of NULL.\n");
+        testStatus = false;
+    }
+    if(outputOrd->type.type != PS_TYPE_F64) {
+        printf("TEST ERROR: Output vector of type %d expected %d.\n",
+               outputOrd->type.type, PS_TYPE_F64);
+        testStatus = false;
+    }
+    psVector* outputCheb = psPolynomial3DEvalVector(polyCheb,inputChebX,inputChebY,inputChebZ);
+    if(outputCheb == NULL) {
+        printf("TEST ERROR: Unexpected return of NULL.\n");
+        testStatus = false;
+    }
+    if(outputCheb->type.type != PS_TYPE_F64) {
+        printf("TEST ERROR: Output vector of type %d expected %d.\n",
+               outputCheb->type.type, PS_TYPE_F64);
+        testStatus = false;
+    }
+
+    // Verify the results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        if(fabs(Dpoly3DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) {
+            printf("TEST ERROR: Result[%d] %lg not equal to expected %lg.\n",
+                   i, outputOrd->data.F64[i], Dpoly3DResult[i]);
+            testStatus = false;
+        }
+        if(fabs(Dpoly3DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) {
+            printf("TEST ERROR: ResultCheb[%d] %lg not equal to expected %lg.\n",
+                   i, outputCheb->data.F64[i], Dpoly3DChebResult[i]);
+            testStatus = false;
+        }
+    }
+
+    // Attempt to invoke function with null polynomial
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
+    if(psPolynomial3DEvalVector(NULL,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL polynomial.\n");
+        testStatus = false;
+    }
+
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial3DEvalVector(polyOrd,NULL,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector.\n");
+        testStatus = false;
+    }
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,NULL,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector.\n");
+        testStatus = false;
+    }
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,NULL) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector.\n");
+        testStatus = false;
+    }
+
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdX->type.type = PS_TYPE_U8;
+    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n");
+        testStatus = false;
+    }
+    inputOrdX->type.type = PS_TYPE_F64;
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdY->type.type = PS_TYPE_U8;
+    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n");
+        testStatus = false;
+    }
+    inputOrdY->type.type = PS_TYPE_F64;
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdZ->type.type = PS_TYPE_U8;
+    if(psPolynomial3DEvalVector(polyOrd,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector.\n");
+        testStatus = false;
+    }
+    inputOrdZ->type.type = PS_TYPE_F64;
+
+    psFree(inputOrdX);
+    psFree(inputOrdY);
+    psFree(inputOrdZ);
+    psFree(inputChebX);
+    psFree(inputChebY);
+    psFree(inputChebZ);
+    psFree(outputOrd);
+    psFree(outputCheb);
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    return(testStatus);
+}
+
Index: /trunk/psLib/test/math/tst_psPolynomialEval4D.c
===================================================================
--- /trunk/psLib/test/math/tst_psPolynomialEval4D.c	(revision 6304)
+++ /trunk/psLib/test/math/tst_psPolynomialEval4D.c	(revision 6304)
@@ -0,0 +1,590 @@
+/** tst_psFunc11.c
+*
+*  This test driver will exercise the psPolynomialXDEval functions for both
+*  ORD and CHEB type polynomials.
+*
+*  @version  $Revision: 1.1 $  $Name: not supported by cvs2svn $
+*  @date  $Date: 2006-02-02 21:05:51 $
+*
+* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
+*
+***************************************************************************/
+
+#include "pslib_strict.h"
+#include "psTest.h"
+
+#define  TERMS        4
+#define  TESTPOINTS   5
+#define  ERROR_TOL    0.001
+
+static psS32 testPoly4DEval(void);
+static psS32 testPoly4DEvalVector(void);
+
+testDescription tests[] = {
+                              {testPoly4DEval,583,"psPolynomial4DEval",true,false},
+                              {testPoly4DEvalVector,000,"psPolynomial4DEvalVector",true,false},
+                              {NULL}
+                          };
+
+psF32 poly4DCoeff[TERMS][TERMS][TERMS][TERMS] = {
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            },
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            },
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            },
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            }
+        };
+psF64 Dpoly4DCoeff[TERMS][TERMS][TERMS][TERMS] = {
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            },
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            },
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            },
+            {
+                {
+                    { -1.1,  1.2, -1.3,  1.4},
+                    {  1.5, -1.6,  1.7, -1.8},
+                    {  0.1, -0.2,  0.3, -0.4},
+                    { -0.5,  0.6, -0.7,  0.8}
+                },
+                {
+                    { -2.1,  2.2, -2.3,  2.4},
+                    {  2.5, -2.6,  2.7, -2.8},
+                    {  3.1, -3.2,  3.3, -3.4},
+                    { -3.5,  3.6, -3.7,  3.8}
+                },
+                { { -4.1,  4.2, -4.3,  4.4},
+                  {  4.5, -4.6,  4.7, -4.8},
+                  {  5.1, -5.2,  5.3, -5.4},
+                  { -5.5,  5.6, -5.7,  5.8}
+                },
+                { { -6.1,  6.2, -6.3,  6.4},
+                  {  6.5, -6.6,  6.7, -6.8},
+                  {  7.1, -7.2,  7.3, -7.4},
+                  { -7.5,  7.6, -7.7,  7.8}
+                }
+            }
+        };
+
+psF32 poly4DMask[TERMS][TERMS][TERMS][TERMS]    = {
+            {
+                {
+                    {  0,    0,    0,    1},
+                    {  0,    0,    1,    0},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0}
+                },
+                {
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0},
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                }
+            },
+            {
+                {
+                    {  0,    0,    0,    1},
+                    {  0,    0,    1,    0},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0}
+                },
+                {
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0},
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                }
+            },
+            {
+                {
+                    {  0,    0,    0,    1},
+                    {  0,    0,    1,    0},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0}
+                },
+                {
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0},
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                }
+            },
+            {
+                {
+                    {  0,    0,    0,    1},
+                    {  0,    0,    1,    0},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0},
+                    {  1,    0,    0,    0}
+                },
+                {
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0},
+                    {  0,    1,    0,    0},
+                    {  0,    0,    1,    0}
+                },
+                {
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1},
+                    {  1,    0,    0,    0},
+                    {  0,    0,    0,    1}
+                }
+            }
+        };
+
+psF32 poly4DWXYZValue[TESTPOINTS][4] = {
+                                           {  0.450, -0.780,  0.500, -0.123},
+                                           {  0.297,  0.153, -0.354,  0.000},
+                                           {  0.000,  0.153, -0.354,  0.321},
+                                           {  0.297,  0.000, -0.354,  0.321},
+                                           {  0.297,  0.153,  0.000,  0.321}
+                                       };
+psF64 Dpoly4DWXYZValue[TESTPOINTS][4] = {
+                                            {  0.450, -0.780,  0.500, -0.123},
+                                            {  0.297,  0.153, -0.354,  0.000},
+                                            {  0.000,  0.153, -0.354,  0.321},
+                                            {  0.297,  0.000, -0.354,  0.321},
+                                            {  0.297,  0.153,  0.000,  0.321}
+                                        };
+
+psF32 poly4DResult[TESTPOINTS]  = { -3.588753, -2.439566, -1.175955, -1.645497, -1.216915};
+psF64 Dpoly4DResult[TESTPOINTS]  = { -3.588753, -2.439566, -1.175955, -1.645497, -1.216915};
+
+psF32 poly4DWXYZChebValue[TESTPOINTS][4] = {
+            {  0.100,  0.000,  0.250, -0.250},
+            {  0.100, -0.250,  0.000,  0.250},
+            {  0.100,  0.250, -0.250,  0.000},
+            {  0.300,  0.200, -0.300, -0.400},
+            { -0.780,  0.990, -0.010,  0.500}
+        };
+psF64 Dpoly4DWXYZChebValue[TESTPOINTS][4] = {
+            {  0.100,  0.000,  0.250, -0.250},
+            {  0.100, -0.250,  0.000,  0.250},
+            {  0.100,  0.250, -0.250,  0.000},
+            {  0.300,  0.200, -0.300, -0.400},
+            { -0.780,  0.990, -0.010,  0.500}
+        };
+psF32 poly4DChebResult[TESTPOINTS]   = { -0.216563, -0.297000, -0.033000, 0.432198, 1.785601 };
+psF64 Dpoly4DChebResult[TESTPOINTS]  = { -0.216563, -0.297000, -0.033000, 0.432198, 1.785601 };
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
+
+    return !runTestSuite(stderr,"psPolynomialXDEval", tests, argc, argv);
+}
+
+// This test will verify operation of 4D polynomial evaluation
+psS32 testPoly4DEval(void)
+{
+    psBool testStatus = true;
+    // Allocate polynomial structure
+    psPolynomial4D*  polyOrd = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, TERMS-1, TERMS-1, TERMS-1, TERMS-1);
+    psPolynomial4D*  polyCheb = psPolynomial4DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1, TERMS-1, TERMS-1, TERMS-1);
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        for(psS32 j = 0; j < TERMS; j++) {
+            for(psS32 k = 0; k < TERMS; k++) {
+                for(psS32 l = 0; l < TERMS; l++) {
+                    polyOrd->coeff[i][j][k][l] = Dpoly4DCoeff[i][j][k][l];
+                    polyOrd->mask[i][j][k][l]  = poly4DMask[i][j][k][l];
+                    polyCheb->coeff[i][j][k][l] = 1.0;
+                    polyCheb->mask[i][j][k][l]  = poly4DMask[i][j][k][l];
+                }
+            }
+        }
+    }
+
+    // Evaluate test points and verify results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        psF64 result = psPolynomial4DEval(polyOrd, Dpoly4DWXYZValue[i][0], Dpoly4DWXYZValue[i][1],
+                                          Dpoly4DWXYZValue[i][2], Dpoly4DWXYZValue[i][3]);
+        if(fabs(Dpoly4DResult[i]-result) > ERROR_TOL ) {
+            printf("TEST ERROR: Evaluated value %lg not as expected %lg.\n",
+                   result, Dpoly4DResult[i]);
+            testStatus = false;
+        }
+
+        psF64 resultCheb = psPolynomial4DEval(polyCheb, Dpoly4DWXYZChebValue[i][0], Dpoly4DWXYZChebValue[i][1],
+                                              Dpoly4DWXYZChebValue[i][2], Dpoly4DWXYZChebValue[i][3]);
+        if(fabs(Dpoly4DChebResult[i]-resultCheb) > ERROR_TOL ) {
+            printf("TEST ERROR: Evaluated Chebyshev value %lg not as expected %lg.\n",
+                   resultCheb, Dpoly4DChebResult[i]);
+            testStatus = false;
+        }
+    }
+
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    // Allocate polynomial with invalid type
+    polyOrd = psPolynomial4DAlloc(99, TERMS-1, TERMS-1, TERMS-1, TERMS-1);
+    // Attempt to evaluation invalid polynomial type
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message invalid type");
+    psF64 result = psPolynomial4DEval(polyOrd,0.0, 0.0, 0.0, 0.0);
+    if ( !isnan(result) ) {
+        printf("TEST ERROR: Did not return NAN for invalid polynomial type");
+        testStatus = false;
+    }
+    psFree(polyOrd);
+
+    return(testStatus);
+}
+
+psS32 testPoly4DEvalVector(void)
+{
+    psBool testStatus = true;
+    // Allocate polynomial
+    psPolynomial4D* polyOrd = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, TERMS-1, TERMS-1, TERMS-1, TERMS-1);
+    psPolynomial4D* polyCheb = psPolynomial4DAlloc(PS_POLYNOMIAL_CHEB, TERMS-1, TERMS-1, TERMS-1, TERMS-1);
+
+    // Set polynomial members
+    for(psS32 i = 0; i < TERMS; i++) {
+        for(psS32 j = 0; j < TERMS; j++) {
+            for(psS32 k = 0; k < TERMS; k++) {
+                for(psS32 l = 0; l < TERMS; l++) {
+                    polyOrd->coeff[i][j][k][l] = Dpoly4DCoeff[i][j][k][l];
+                    polyOrd->mask[i][j][k][l]  = poly4DMask[i][j][k][l];
+                    polyCheb->coeff[i][j][k][l] = 1.0;
+                    polyCheb->mask[i][j][k][l]  = poly4DMask[i][j][k][l];
+                }
+            }
+        }
+    }
+
+    // Create input vectors
+    psVector* inputOrdW  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputOrdX  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputOrdY  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputOrdZ  = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebW = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebX = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebY = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    psVector* inputChebZ = psVectorAlloc(TESTPOINTS, PS_TYPE_F64);
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        inputOrdW->data.F64[i]  = Dpoly4DWXYZValue[i][0];
+        inputOrdX->data.F64[i]  = Dpoly4DWXYZValue[i][1];
+        inputOrdY->data.F64[i]  = Dpoly4DWXYZValue[i][2];
+        inputOrdZ->data.F64[i]  = Dpoly4DWXYZValue[i][3];
+        inputChebW->data.F64[i] = Dpoly4DWXYZChebValue[i][0];
+        inputChebX->data.F64[i] = Dpoly4DWXYZChebValue[i][1];
+        inputChebY->data.F64[i] = Dpoly4DWXYZChebValue[i][2];
+        inputChebZ->data.F64[i] = Dpoly4DWXYZChebValue[i][3];
+    }
+
+    // Evaluate the vectors
+    psVector* outputOrd = psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ);
+    if(outputOrd == NULL) {
+        printf("TEST ERROR: Unexpected return of NULL.");
+        testStatus = false;
+    }
+    if(outputOrd->type.type != PS_TYPE_F64) {
+        printf("TEST ERROR: Output vector of type %d expected %d",
+               outputOrd->type.type, PS_TYPE_F64);
+        testStatus = false;
+    }
+
+    psVector* outputCheb = psPolynomial4DEvalVector(polyCheb,inputChebW,inputChebX,inputChebY,inputChebZ);
+    if(outputCheb == NULL) {
+        printf("TEST ERROR: Unexpected return of NULL.");
+        testStatus = false;
+    }
+    if(outputCheb->type.type != PS_TYPE_F64) {
+        printf("TEST ERROR: Output vector of type %d expected %d",
+               outputCheb->type.type, PS_TYPE_F64);
+        testStatus = false;
+    }
+
+    // Verify the results
+    for(psS32 i = 0; i < TESTPOINTS; i++) {
+        if(fabs(Dpoly4DResult[i]-outputOrd->data.F64[i]) > ERROR_TOL) {
+            printf("TEST ERROR: Result[%d] %lg not equal to expected %lg",
+                   i, outputOrd->data.F64[i], Dpoly4DResult[i]);
+            testStatus = false;
+        }
+        if(fabs(Dpoly4DChebResult[i]-outputCheb->data.F64[i]) > ERROR_TOL) {
+            printf("TEST ERROR: ResultCheb[%d] %lg not equal to expected %lg",
+                   i, outputCheb->data.F64[i], Dpoly4DChebResult[i]);
+            testStatus = false;
+        }
+    }
+
+    // Attempt to invoke function with null polynomial
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL polynomial");
+    if(psPolynomial4DEvalVector(NULL,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL polynomial");
+        testStatus = false;
+    }
+
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial4DEvalVector(polyOrd,NULL,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector");
+        testStatus = false;
+    }
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial4DEvalVector(polyOrd,inputOrdW,NULL,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector");
+        testStatus = false;
+    }
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,NULL,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector");
+        testStatus = false;
+    }
+    // Attempt to invoke function with null input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for NULL input vector");
+    if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,NULL) != NULL) {
+        printf("TEST ERROR: Return of NULL expected for NULL input vector");
+        testStatus = false;
+    }
+
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdX->type.type = PS_TYPE_U8;
+    if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector");
+        testStatus = false;
+    }
+    inputOrdX->type.type = PS_TYPE_F64;
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdY->type.type = PS_TYPE_U8;
+    if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector");
+        testStatus = false;
+    }
+    inputOrdY->type.type = PS_TYPE_F64;
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdZ->type.type = PS_TYPE_U8;
+    if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector");
+        testStatus = false;
+    }
+    inputOrdZ->type.type = PS_TYPE_F64;
+    // Attempt to invoke function with a non F64 type input vector
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate an error message for invalid input type");
+    inputOrdW->type.type = PS_TYPE_U8;
+    if(psPolynomial4DEvalVector(polyOrd,inputOrdW,inputOrdX,inputOrdY,inputOrdZ) != NULL) {
+        printf("TEST ERROR: Return NULL expected for non-F64 input vector");
+        testStatus = false;
+    }
+    inputOrdW->type.type = PS_TYPE_F64;
+
+    psFree(inputOrdX);
+    psFree(inputOrdY);
+    psFree(inputOrdZ);
+    psFree(inputOrdW);
+    psFree(inputChebW);
+    psFree(inputChebX);
+    psFree(inputChebY);
+    psFree(inputChebZ);
+    psFree(outputOrd);
+    psFree(outputCheb);
+    psFree(polyOrd);
+    psFree(polyCheb);
+
+    return(testStatus);
+}
Index: /trunk/psLib/test/math/tst_psStats07.c
===================================================================
--- /trunk/psLib/test/math/tst_psStats07.c	(revision 6303)
+++ /trunk/psLib/test/math/tst_psStats07.c	(revision 6304)
@@ -13,8 +13,9 @@
 #include <math.h>
 
-#define N 90
+#define NUM_DATA 10000
 #define MEAN 32.0
 #define STDEV 2.0
 #define ERROR_TOLERANCE 0.15
+#define PERCENT_OUTLIERS 10
 
 psS32 t00()
@@ -27,7 +28,4 @@
     psVector *myVector = NULL;
     psVector *maskVector = NULL;
-    // NOTE: These values were calculated by running the function on the data.
-    // They must be changed if we adjust the number of data points.
-    // We don't really know that they are correct.
     psS32 count = 0;
     psS32 currentId = psMemGetId();
@@ -35,19 +33,18 @@
     float realMeanNoMask = MEAN;
     float realMedianNoMask = MEAN;
-    //    float realModeNoMask = MEAN;
     float realStdevNoMask = STDEV;
     float realLQNoMask = MEAN - ( 0.6 * STDEV );
     float realUQNoMask = MEAN + ( 0.6 * STDEV );
-    psS32 realN50NoMask = N / 4;
+    psS32 realN50NoMask = NUM_DATA / 4;
 
     /*************************************************************************/
     /*  Allocate and initialize data structures                              */
     /*************************************************************************/
-    maskVector = psVectorAlloc( N, PS_TYPE_U8 );
-    maskVector->n = N;
-    myVector = p_psGaussianDev( MEAN, STDEV, N );
+    maskVector = psVectorAlloc( NUM_DATA, PS_TYPE_U8 );
+    maskVector->n = NUM_DATA;
+    myVector = p_psGaussianDev( MEAN, STDEV, NUM_DATA );
     // Set the mask vector and calculate the expected maximum.
-    for ( i = 0;i < N;i++ ) {
-        if ( i < ( N / 2 ) ) {
+    for ( i = 0;i < NUM_DATA;i++ ) {
+        if ( i < ( NUM_DATA / 2 ) ) {
             maskVector->data.U8[ i ] = 0;
             count++;
@@ -56,4 +53,8 @@
         }
     }
+
+    //
+    // We calculate the exact mean, median, stdev and quartiles with no mask.
+    //
     psStats *mySampleStats = psStatsAlloc( PS_STAT_SAMPLE_MEAN |
                                            PS_STAT_SAMPLE_MEDIAN |
@@ -67,4 +68,7 @@
     psFree(mySampleStats);
 
+    //
+    // We calculate the exact mean, median, stdev and quartiles with mask.
+    //
     psStats *mySampleStatsWithMask = psStatsAlloc( PS_STAT_SAMPLE_MEAN |
                                      PS_STAT_SAMPLE_MEDIAN |
@@ -84,6 +88,9 @@
                            PS_STAT_FITTED_STDEV);
     // Create a full outliers:
-    myVector->data.F32[N/4] = -1000.0 * MEAN;
-    myVector->data.F32[N/2] = 1000.0 * MEAN;
+    for (psS32 i = 0 ; i < NUM_DATA ; i++) {
+        if (PERCENT_OUTLIERS > (random() % 100)) {
+            myVector->data.F32[i] = 1000.0 * MEAN;
+        }
+    }
     /*************************************************************************/
     /*  Call psVectorStats() with no vector mask.                            */
@@ -130,24 +137,4 @@
                  "PS_STAT_ROBUST_STATS: robust Median: no vector mask",
                  testStatus );
-
-    /* XXX: Should we test mode?
-        printPositiveTestHeader( stdout,
-                                 "psStats functions",
-                                 "PS_STAT_ROBUST_STATS: robust Mode: no vector mask" );
-     
-     
-        printf( "The expected Mode was %.2f; the calculated Mode was %.2f\n",
-                realModeNoMask, myStats->robustMode );
-        if ( fabs( myStats->robustMode - realModeNoMask ) < ( ERROR_TOLERANCE * realModeNoMask ) ) {
-            testStatus = true;
-        } else {
-            testStatus = false;
-            globalTestStatus = false;
-        }
-        printFooter( stdout,
-                     "psVector functions",
-                     "PS_STAT_ROBUST_STATS: robust Mode: no vector mask",
-                     testStatus );
-    */
 
     printPositiveTestHeader( stdout,
@@ -268,9 +255,8 @@
     float realMeanWithMask = MEAN;
     float realMedianWithMask = MEAN;
-    //    float realModeWithMask = MEAN;
     float realStdevWithMask = STDEV;
     float realLQWithMask = MEAN;
     float realUQWithMask = MEAN;
-    psS32 realN50WithMask = N / 4;
+    psS32 realN50WithMask = NUM_DATA / 4;
     /*************************************************************************/
     /*  Allocate and initialize data structures                              */
@@ -282,14 +268,19 @@
                            PS_STAT_FITTED_STDEV);
 
-    maskVector = psVectorAlloc( N, PS_TYPE_U8 );
-    maskVector->n = N;
-    myVector = p_psGaussianDev( MEAN, STDEV, N );
+    maskVector = psVectorAlloc( NUM_DATA, PS_TYPE_U8 );
+    maskVector->n = NUM_DATA;
+    myVector = p_psGaussianDev( MEAN, STDEV, NUM_DATA );
     // Set the mask vector and calculate the expected maximum.
-    for ( i = 0;i < N;i++ ) {
-        if ( i < ( N / 2 ) ) {
+    for ( i = 0;i < NUM_DATA;i++ ) {
+        if ( i < ( NUM_DATA / 2 ) ) {
             maskVector->data.U8[ i ] = 0;
             count++;
         } else {
             maskVector->data.U8[ i ] = 1;
+        }
+    }
+    for (psS32 i = 0 ; i < NUM_DATA ; i++) {
+        if (PERCENT_OUTLIERS < (random() % 100)) {
+            myVector->data.F32[i] = 1000.0 * MEAN;
         }
     }
@@ -338,24 +329,4 @@
                  "PS_STAT_ROBUST_STATS: robust Median: with vector mask",
                  testStatus );
-
-
-    /* XXX: mode is not set?
-        printPositiveTestHeader( stdout,
-                                 "psStats functions",
-                                 "PS_STAT_ROBUST_STATS: robust Mode: with vector mask" );
-     
-        printf( "The expected Mode was %.2f; the calculated Mode was %.2f\n",
-                realModeWithMask, myStats->robustMode );
-        if ( fabs( myStats->robustMode - realModeWithMask ) < ( ERROR_TOLERANCE * realModeWithMask ) ) {
-            testStatus = true;
-        } else {
-            testStatus = false;
-            globalTestStatus = false;
-        }
-        printFooter( stdout,
-                     "psVector functions",
-                     "PS_STAT_ROBUST_STATS: robust Mode: with vector mask",
-                     testStatus );
-    */
 
 
@@ -469,24 +440,26 @@
     // We list pertinent psStats.c functions here for debugging ease.
     //
-    psTraceSetLevel(".", 0);
-    psTraceSetLevel("psGaussian", 0);
-    psTraceSetLevel("p_psGetStatValue", 0);
-    psTraceSetLevel("p_psVectorMax", 0);
-    psTraceSetLevel("p_psVectorMin", 0);
-    psTraceSetLevel("p_psVectorCheckNonEmpty", 0);
-    psTraceSetLevel("p_psNormalizeVectorRange", 0);
-    psTraceSetLevel("p_ps1DPolyMedian", 0);
-    psTraceSetLevel("fitQuadraticSearchForYThenReturnX", 0);
-    psTraceSetLevel("PsVectorDup", 0);
-    psTraceSetLevel("psMinimizeLMChi2Gauss1D", 0);
-    psTraceSetLevel("LinInterpolate", 0);
-    psTraceSetLevel("p_psVectorRobustStats", 0);
-    psTraceSetLevel("psStatsAlloc", 0);
-    psTraceSetLevel("psHistogramAlloc", 0);
-    psTraceSetLevel("psHistogramAllocGeneric", 0);
-    psTraceSetLevel("UpdateHistogramBins", 0);
-    psTraceSetLevel("psVectorHistogram", 0);
-    psTraceSetLevel("p_psConvertToF32", 0);
-    psTraceSetLevel("psVectorStats", 0);
+    #define TRACE_LEVEL 0
+
+    psTraceSetLevel(".", TRACE_LEVEL);
+    psTraceSetLevel("psGaussian", TRACE_LEVEL);
+    psTraceSetLevel("p_psGetStatValue", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorMax", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorMin", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorCheckNonEmpty", TRACE_LEVEL);
+    psTraceSetLevel("p_psNormalizeVectorRange", TRACE_LEVEL);
+    psTraceSetLevel("p_ps1DPolyMedian", TRACE_LEVEL);
+    psTraceSetLevel("fitQuadraticSearchForYThenReturnX", TRACE_LEVEL);
+    psTraceSetLevel("PsVectorDup", TRACE_LEVEL);
+    psTraceSetLevel("psMinimizeLMChi2Gauss1D", TRACE_LEVEL);
+    psTraceSetLevel("LinInterpolate", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorRobustStats", TRACE_LEVEL);
+    psTraceSetLevel("psStatsAlloc", TRACE_LEVEL);
+    psTraceSetLevel("psHistogramAlloc", TRACE_LEVEL);
+    psTraceSetLevel("psHistogramAllocGeneric", TRACE_LEVEL);
+    psTraceSetLevel("UpdateHistogramBins", TRACE_LEVEL);
+    psTraceSetLevel("psVectorHistogram", TRACE_LEVEL);
+    psTraceSetLevel("p_psConvertToF32", TRACE_LEVEL);
+    psTraceSetLevel("psVectorStats", TRACE_LEVEL);
     psBool rc0 = t00();
     psBool rc1 = t01();
Index: /trunk/psLib/test/math/tst_psStats09.c
===================================================================
--- /trunk/psLib/test/math/tst_psStats09.c	(revision 6303)
+++ /trunk/psLib/test/math/tst_psStats09.c	(revision 6304)
@@ -18,4 +18,249 @@
 #define MY_MEAN  30.0
 #define MY_RANGE 2.0
+#define VERBOSE 1
+
+#define TST_IN_NULL  0x00000000
+#define TST_IN_F32  0x00000000
+#define TST_IN_F64  0x00000000
+#define TST_IN_S8  0x00000000
+#define TST_IN_U16  0x00000000
+#define TST_IN_S32  0x00000000
+#define TST_ERRORS_NULL  0x00000000
+#define TST_ERRORS_F32  0x00000000
+#define TST_ERRORS_F64  0x00000000
+#define TST_ERRORS_S8  0x00000000
+#define TST_ERRORS_U16  0x00000000
+#define TST_ERRORS_S32  0x00000000
+#define TST_MASK_NULL  0x00000000
+#define TST_MASK_U8  0x00000000
+#define TST_MASK_S32  0x00000000
+
+psS32 genericClippedStatsTest(
+    unsigned int flags,
+    psS32 numData,
+    psU32 maskValue,
+    psBool expectedRC)
+{
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psVector *in = NULL;
+    psVector *errors = NULL;
+    psVector *mask = NULL;
+    printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine");
+
+    if (expectedRC == false) {
+        printf("This test should generate an error message, and return NULL.\n");
+    }
+
+    if (flags & TST_IN_NULL) {
+        printf("        using a NULL in vector\n");
+    }
+
+    if (flags & TST_IN_F32) {
+        printf("        using a psF32 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_F32);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.F32[i] = (psF32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_F64) {
+        printf("        using a psF64 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_F64);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.F64[i] = (psF64) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_S8) {
+        printf("        using a psS8 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_S8);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.S8[i] = (psS8) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.S8[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_U16) {
+        printf("        using a psU16 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_U16);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.U16[i] = (psU16) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.U16[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_S32) {
+        printf("        using a psS32 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_S32);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.S32[i] = (psS32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.S32[i]);
+            }
+        }
+    }
+
+
+    if (flags & TST_ERRORS_NULL) {
+        printf("        using a NULL errors vector\n");
+    }
+
+    if (flags & TST_ERRORS_F32) {
+        printf("        using a psF32 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_F32);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.F32[i] = (psF32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%.1f)\n", i, errors->data.F32[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_F64) {
+        printf("        using a psF64 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_F64);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.F64[i] = (psF64) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%.1f)\n", i, errors->data.F64[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_S8) {
+        printf("        using a psS8 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_S8);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.S8[i] = (psS8) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%d)\n", i, errors->data.S8[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_U16) {
+        printf("        using a psU16 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_U16);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.U16[i] = (psU16) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%d)\n", i, errors->data.U16[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_S32) {
+        printf("        using a psS32 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_S32);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.S32[i] = (psS32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%d)\n", i, errors->data.S32[i]);
+            }
+        }
+    }
+
+
+    if (flags & TST_MASK_NULL) {
+        printf("        using a NULL mask vector\n");
+    }
+
+    if (flags & TST_MASK_U8) {
+        printf("        using a psU8 mask vector\n");
+        mask = psVectorAlloc(numData, PS_TYPE_U8);
+        for (psS32 i=0;i<numData;i++) {
+            mask->data.U8[i] = (psU8) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original mask data %d: (%d)\n", i, mask->data.U8[i]);
+            }
+        }
+    }
+
+    if (flags & TST_MASK_S32) {
+        printf("        using a psS32 mask vector\n");
+        mask = psVectorAlloc(numData, PS_TYPE_S32);
+        for (psS32 i=0;i<numData;i++) {
+            mask->data.S32[i] = (psS32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original mask data %d: (%d)\n", i, mask->data.S32[i]);
+            }
+        }
+    }
+
+    psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
+    psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);
+
+    if (rc == NULL) {
+        if (expectedRC == true) {
+            printf("TEST ERROR: the psVectorStats() function returned NULL.\n");
+            testStatus = false;
+        }
+    } else {
+        if (expectedRC == false) {
+            printf("TEST ERROR: the psVectorStats() function returned non-NULL.\n");
+            testStatus = false;
+        }
+
+    }
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    return(testStatus);
+}
+
+
+
 
 psS32 main()
@@ -38,129 +283,3 @@
     psTraceSetLevel("psVectorStats", 0);
 
-    psStats *myStats    = NULL;
-    psS32 testStatus      = true;
-    psS32 globalTestStatus = true;
-    psS32 i               = 0;
-    psVector *maskVector= NULL;
-    psVector *myGaussData  = NULL;
-    // NOTE: These values were calculated by running the function on the data.
-    // A: They must be changed if we adjust the number of data points.
-    // B: We don't really know that they are correct.
-    //    float realclippedMeanNoMask  = 0.0;
-    //    float realclippedStdevNoMask = 0.0;
-    //    float realclippedMeanWithMask  = 0.0;
-    //    float realclippedStdevWithMask = 0.0;
-    psS32 count           = 0;
-    psS32 currentId       = psMemGetId();
-    psS32 memLeaks        = 0;
-
-    /*************************************************************************/
-    /*  Allocate and initialize data structures                      */
-    /*************************************************************************/
-    myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN |
-                           PS_STAT_CLIPPED_STDEV);
-
-    myGaussData = psVectorAlloc(N, PS_TYPE_F32);
-    myGaussData->n = myGaussData->nalloc;
-    for (i=0;i<N;i++) {
-        myGaussData->data.F32[i] = MY_MEAN - (MY_RANGE/1.9) +
-                                   (MY_RANGE) * ((float) i) / ((float) N);
-    }
-
-    maskVector = psVectorAlloc(N, PS_TYPE_U8);
-    maskVector->n = N;
-
-    // Set the mask vector and calculate the expected maximum.
-    for (i=0;i<N;i++) {
-        if (i < (N/2)) {
-            maskVector->data.U8[i] = 0;
-            count++;
-        } else {
-            maskVector->data.U8[i] = 1;
-        }
-    }
-
-    /*************************************************************************/
-    /*  Call psVectorStats() with no vector mask.                    */
-    /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_MEAN: no vector mask");
-
-    myStats = psVectorStats(myStats, myGaussData, NULL, NULL, 0);
-
-    printf("Called psVectorStats() on a vector with no elements masked.\n");
-    printf("The calculated clippedMean was %.2f\n", myStats->clippedMean);
-
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: no vector mask",
-                testStatus);
-
-
-
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_STDEV: no vector mask");
-
-    printf("Called psVectorStats() on a vector with no elements masked.\n");
-    printf("The calculated clippedStdev was %.2f\n", myStats->clippedStdev);
-
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: no vector mask",
-                testStatus);
-
-    /*************************************************************************/
-    /*  Call psVectorStats() with vector mask.                       */
-    /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_MEAN: vector mask");
-
-    myStats = psVectorStats(myStats, myGaussData, NULL, maskVector, 1);
-
-    printf("Called psVectorStats() on a vector with elements masked.\n");
-    printf("The calculated clippedMean was %.2f\n", myStats->clippedMean);
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: vector mask",
-                testStatus);
-
-
-
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_STDEV: vector mask");
-
-    printf("Called psVectorStats() on a vector with elements masked.\n");
-    printf("The calculated clippedStdev was %.2f\n", myStats->clippedStdev);
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: vector mask",
-                testStatus);
-
-    /*************************************************************************/
-    /*  Deallocate data structures                                   */
-    /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "psStats(): deallocating memory");
-
-    psFree(myStats);
-    psFree(myGaussData);
-    psFree(maskVector);
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psVector functions",
-                "psStats(): deallocating memory",
-                testStatus);
-
-    return (!globalTestStatus);
 }
