Index: /trunk/psLib/test/imageops/tst_psImageSmooth.c
===================================================================
--- /trunk/psLib/test/imageops/tst_psImageSmooth.c	(revision 6280)
+++ /trunk/psLib/test/imageops/tst_psImageSmooth.c	(revision 6280)
@@ -0,0 +1,198 @@
+/** @file  tst_psImageConvolve.c
+ *
+ *  This code will test the psImageSmooth() routine.
+ *
+ *  @author GLG, MHPCC
+ *
+ *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-02-01 21:35:59 $
+ *
+ *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
+ */
+
+#include <math.h>
+#include <float.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "psTest.h"
+#include "pslib_strict.h"
+#include "psType.h"
+
+static psS32 testImageSmooth();
+
+testDescription tests[] = {
+                              {testImageSmooth, 0, "psImageSmooth", true, false},
+                              {NULL}
+                          };
+
+psS32 main(psS32 argc, char* argv[])
+{
+    psLogSetFormat("HLNM");
+    psLogSetLevel(PS_LOG_INFO);
+
+    return ! runTestSuite(stderr, "psImage", tests, argc, argv);
+}
+
+#define NUM_ROWS 20
+#define NUM_COLS 20
+#define SIGMA 1.0
+#define NSIGMA 5.0
+#define TS00_IM_NULL            0x00000001
+#define TS00_IM_F32             0x00000002
+#define TS00_IM_F64             0x00000004
+#define TS00_IM_S32             0x00000008
+#define VERBOSE 0
+
+static psBool testImageSmoothGeneric(
+    psU32 flags,
+    psS32 numCols,
+    psS32 numRows,
+    psF64 sigma,
+    psF64 Nsigma,
+    psBool expectedRC)
+{
+    psBool testStatus = true;
+    psImage *img = NULL;
+
+    printPositiveTestHeader(stdout, "psImageConvolve.c", "Image Smoothing Routine");
+
+    if (expectedRC == false) {
+        printf("This test should generate FALSE.\n");
+    } else {
+        printf("This test should generate TRUE.\n");
+    }
+
+    if (flags & TS00_IM_NULL) {
+        printf("        using a NULL image\n");
+    }
+
+    if (flags & TS00_IM_F32) {
+        printf("        using a psF32 image\n");
+        img = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+        // Set a checkboard pattern
+        for (psS32 i = 0 ; i < numRows ; i++) {
+            for (psS32 j = 0 ; j < numCols ; j++) {
+                if ((i%2) != (j%2)) {
+                    img->data.F32[i][j] = 1.0;
+                } else {
+                    img->data.F32[i][j] = 0.0;
+                }
+            }
+        }
+    }
+    if (VERBOSE) {
+        p_psImagePrint(1, img, "The Smmothed Image");
+    }
+
+    if (flags & TS00_IM_F64) {
+        printf("        using a psF64 image\n");
+        img = psImageAlloc(numCols, numRows, PS_TYPE_F64);
+        // Set a checkboard pattern
+        for (psS32 i = 0 ; i < numRows ; i++) {
+            for (psS32 j = 0 ; j < numCols ; j++) {
+                if ((i%2) != (j%2)) {
+                    img->data.F64[i][j] = 1.0;
+                } else {
+                    img->data.F64[i][j] = 0.0;
+                }
+            }
+        }
+    }
+
+    if (flags & TS00_IM_S32) {
+        printf("        using a psS32 image\n");
+        img = psImageAlloc(numCols, numRows, PS_TYPE_S32);
+        // Set a checkboard pattern
+        for (psS32 i = 0 ; i < numRows ; i++) {
+            for (psS32 j = 0 ; j < numCols ; j++) {
+                if ((i%2) != (j%2)) {
+                    img->data.S32[i][j] = 1;
+                } else {
+                    img->data.S32[i][j] = 0;
+                }
+            }
+        }
+    }
+    printf(" %d columns\n", numCols);
+    printf(" %d rows\n", numRows);
+    printf(" sigma is %.2f\n", sigma);
+    printf(" Nsigma is %.2f\n", Nsigma);
+
+    psBool rc = psImageSmooth(img, sigma, Nsigma);
+    if (rc == false) {
+        if (expectedRC == true) {
+            printf("TEST ERROR: psImageSmooth returned FALSE\n");
+            testStatus = false;
+        }
+    } else {
+        if (expectedRC == false) {
+            printf("TEST ERROR: psImageSmooth returned TRUE\n");
+            testStatus = false;
+        }
+        if (VERBOSE) {
+            p_psImagePrint(1, img, "The Smmothed Image");
+        }
+
+        if (flags & TS00_IM_F32) {
+            for (psS32 i = 1 ; i < numRows-1 ; i++) {
+                for (psS32 j = 1 ; j < numCols-1 ; j++) {
+                    if ((fabs(img->data.F32[i][j] - 0.5) > 0.1)) {
+                        printf("TEST ERROR: img[%d][%d] was %f, expected 0.5\n", i, j, img->data.F32[i][j]);
+                        testStatus = false;
+                    }
+                }
+            }
+        }
+
+        if (flags & TS00_IM_F64) {
+            for (psS32 i = 1 ; i < numRows-1 ; i++) {
+                for (psS32 j = 1 ; j < numCols-1 ; j++) {
+                    if ((fabs(img->data.F64[i][j] - 0.5) > 0.1)) {
+                        printf("TEST ERROR: img[%d][%d] was %f, expected 0.5\n", i, j, img->data.F64[i][j]);
+                        testStatus = false;
+                    }
+                }
+            }
+        }
+    }
+    psFree(img);
+
+    return(testStatus);
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+static psS32 testImageSmooth()
+{
+    psBool rc = true;
+
+    rc&= testImageSmoothGeneric(TS00_IM_F32, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, true);
+    rc&= testImageSmoothGeneric(TS00_IM_F32, 1, NUM_ROWS, SIGMA, NSIGMA, true);
+    rc&= testImageSmoothGeneric(TS00_IM_F32, NUM_COLS, 1, SIGMA, NSIGMA, true);
+    rc&= testImageSmoothGeneric(TS00_IM_F32, 1, 1, SIGMA, NSIGMA, true);
+    rc&= testImageSmoothGeneric(TS00_IM_F64, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, true);
+    rc&= testImageSmoothGeneric(TS00_IM_S32, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, false);
+    rc&= testImageSmoothGeneric(TS00_IM_NULL, NUM_COLS, NUM_ROWS, SIGMA, NSIGMA, false);
+
+    return(rc);
+}
Index: /trunk/psLib/test/imageops/tst_psImageStats.c
===================================================================
--- /trunk/psLib/test/imageops/tst_psImageStats.c	(revision 6279)
+++ /trunk/psLib/test/imageops/tst_psImageStats.c	(revision 6280)
@@ -29,10 +29,10 @@
 
 testDescription tests[] = {
-                              {testPsImageHistogram, 0, "psImageHistogram", 0, false},
+                              {testPsImageHistogram, 0, "psImageHistogram", 0, true},
                               {testPsImageStats, 1, "psImageStats", 0, false},
-                              {testPsImageFitPolynomial, 2, "psImageFitPolynomial", 0, false},
-                              {testPsImagePixelInterpolate, 3, "psImagePixelInterpolate", 0, false},
-                              {testPsImageEvalPolynom, 4, "psImageEvalPolynom()", 0, false},
-                              {testImageCountPixel, 5, "psImageCountPixel", 0, false},
+                              {testPsImageFitPolynomial, 2, "psImageFitPolynomial", 0, true},
+                              {testPsImagePixelInterpolate, 3, "psImagePixelInterpolate", 0, true},
+                              {testPsImageEvalPolynom, 4, "psImageEvalPolynom()", 0, true},
+                              {testImageCountPixel, 5, "psImageCountPixel", 0, true},
                               {NULL}
                           };
@@ -220,6 +220,454 @@
 }
 
+// HEY: XXX
+static psS32 testPsImageFitPolynomial()
+{
+    const int IMAGE_SIZE = 16;
+    const int CHEBY_X_DIM = 8;
+    const int CHEBY_Y_DIM = 8;
+    const int THRESHOLD = 10;
+
+    psStats * myStats = NULL;
+    psImage *tmpImage = NULL;
+    psImage *outImage = NULL;
+    psImage *nullImage = NULL;
+    psPolynomial2D *my2DPoly = NULL;
+    psPolynomial2D *null2DPoly = NULL;
+    psS32 testStatus = true;
+    psS32 i = 0;
+    psS32 j = 0;
+    psS32 currentId = 0;
+
+    currentId = psMemGetId();
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    tmpImage = psImageAlloc( IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32 );
+    outImage = psImageAlloc( IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32 );
+    for ( i = 0;i < IMAGE_SIZE;i++ ) {
+        for ( j = 0;j < IMAGE_SIZE;j++ ) {
+            tmpImage->data.F32[ i ][ j ] = 4.0;
+            tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j );
+            tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j ) + ( 4.0 * ( float ) i );
+            outImage->data.F32[ i ][ j ] = 0.0;
+        }
+    }
+    my2DPoly = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, CHEBY_X_DIM-1, CHEBY_Y_DIM-1);
+    /*************************************************************************/
+    /*  Calculate Chebyshev Polynomials, no mask                     */
+    /*************************************************************************/
+    my2DPoly = psImageFitPolynomial( my2DPoly, tmpImage );
+    if (my2DPoly == NULL) {
+        printf("TEST ERROR: psImageFitPolynomial() returned NULL.\n");
+        testStatus = false;
+    }
+    for ( i = 0;i < CHEBY_X_DIM;i++ ) {
+        for ( j = 0;j < CHEBY_Y_DIM;j++ ) {
+            fprintf(stderr, "Cheby Polynomial (%d, %d) coefficient is %.2f\n", i, j, 0.0001f+my2DPoly->coeff[ i ][ j ] );
+        }
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error message for NULL coeffs argument.");
+    null2DPoly = psImageFitPolynomial( NULL, tmpImage );
+    if ( null2DPoly != NULL ) {
+        fprintf(stderr,"ERROR: psImageFitPolynomial did not return NULL with invalid coeffs argument.");
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be a error message for NULL input argument.");
+    null2DPoly = psImageFitPolynomial( null2DPoly, NULL );
+    if ( null2DPoly != NULL ) {
+        fprintf(stderr,"ERROR: psImageFitPolynomial did not return NULL with null input image.");
+    }
+
+    /*************************************************************************/
+    /*  Evaluate Chebyshev Polynomials, no mask                      */
+    /*************************************************************************/
+    outImage = psImageEvalPolynomial( outImage, my2DPoly );
+    for ( i = 0;i < IMAGE_SIZE;i++ ) {
+        for ( j = 0;j < IMAGE_SIZE;j++ ) {
+
+            //             fprintf(stderr,"pixel[%d][%d] is (%.2f, %.2f)\n", i, j,
+            //                     tmpImage->data.F32[i][j],
+            //                     outImage->data.F32[i][j]);
+            if ( fabs( outImage->data.F32[ i ][ j ] - tmpImage->data.F32[ i ][ j ] ) > THRESHOLD ) {
+                fprintf(stderr, "Pixel (%d, %d) is %.2f, should be %.2f\n", i, j,
+                        outImage->data.F32[ i ][ j ],
+                        tmpImage->data.F32[ i ][ j ] );
+            }
+
+        }
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error message for NULL coeffs argument.");
+    nullImage = psImageEvalPolynomial( outImage, NULL );
+    if ( nullImage != NULL ) {
+        fprintf(stderr,"ERROR: psImageEvalPolynomial did not return NULL with invalid coeffs argument.");
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be a error message for NULL input argument.");
+    nullImage = psImageEvalPolynomial( NULL, my2DPoly );
+    if ( nullImage != NULL ) {
+        fprintf(stderr,"ERROR: psImageEvalPolynomial did not return NULL with null input image.");
+    }
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    psFree( myStats );
+    psFree( tmpImage );
+    psFree( outImage );
+    psFree( my2DPoly );
+
+    return ( !testStatus );
+}
+
+static psS32 testPsImagePixelInterpolate()
+{
+    const int IMAGE_SIZE = 10;
+
+    psImage *tmpImage   = NULL;
+    psS32 testStatus      = true;
+    psS32 i               = 0;
+    psS32 j               = 0;
+    float pixel         = 0.0;
+    float x             = 0.0;
+    float y             = 0.0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    tmpImage = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32);
+    for (i=0;i<IMAGE_SIZE;i++) {
+        for (j=0;j<IMAGE_SIZE;j++) {
+            tmpImage->data.F32[i][j] = 4.0;
+            tmpImage->data.F32[i][j] = (float) (i + j) + (4.0 * (float) i);
+            tmpImage->data.F32[i][j] = (float) (i + j);
+            fprintf(stderr,"%.1f ", tmpImage->data.F32[i][j]);
+        }
+        fprintf(stderr,"\n");
+    }
+    for (i=0;i<IMAGE_SIZE-1;i++) {
+        for (j=0;j<IMAGE_SIZE-1;j++) {
+            x = 0.2 + (float) i;
+            y = 0.2 + (float) j;
+            pixel = psImagePixelInterpolate(tmpImage,
+                                            x, y,
+                                            NULL, 0,
+                                            0,
+                                            PS_INTERPOLATE_BILINEAR);
+            fprintf(stderr,"%.1f ", pixel);
+        }
+        fprintf(stderr,"\n");
+    }
+
+    for (i=0;i<IMAGE_SIZE-1;i++) {
+        for (j=0;j<IMAGE_SIZE-1;j++) {
+            x = 0.2 + (float) i;
+            y = 0.2 + (float) j;
+            pixel = psImagePixelInterpolate(tmpImage,
+                                            x, y,
+                                            NULL,0,
+                                            0,
+                                            PS_INTERPOLATE_BILINEAR);
+            fprintf(stderr,"image[%.1f][%.1f] is interpolated at %.1f\n", x, y, pixel);
+        }
+    }
+
+    psFree(tmpImage);
+
+    return (!testStatus);
+}
+
+#define I_POLY(X, Y) \
+((A) + (B * X) + (C * Y) + (D * X * Y) + (E * X * X) + (F * Y * Y)) \
+
+static bool FitChebyF32(int numCols, int numRows)
+{
+    const double A = 1.0;
+    const double B = 2.0;
+    const double C = 3.0;
+    const double D = 4.0;
+    const double E = 5.0;
+    const double F = 6.0;
+    const double ERROR_TOL = 0.1;
+
+    psImage *tmpImage     = NULL;
+    psImage *outImage     = NULL;
+    bool testStatus      = true;
+    psS32 i               = 0;
+    psS32 j               = 0;
+    float chi2 = 0.0;
+
+
+    fprintf(stderr,"psImageFitPolynomial(), psImageEvalPolynom(): (%d by %d)\n", numRows, numCols);
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+
+    tmpImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+    outImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            tmpImage->data.F32[i][j] = I_POLY(((float) i), ((float) j));
+        }
+    }
+
+    psPolynomial2D *chebys = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, 5, 5);
+
+    chebys = psImageFitPolynomial(chebys, tmpImage);
+
+    outImage = psImageEvalPolynomial(outImage, chebys);
+
+    chi2 = 0.0;
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            float expect = tmpImage->data.F32[i][j];
+            float actual = outImage->data.F32[i][j];
+            chi2+= (actual-expect) * (actual-expect);
+            if (fabs((actual - expect) / expect) > ERROR_TOL) {
+                fprintf(stderr,"pixel [%d][%d] is %.2f should be %.2f\n", i, j, actual, expect);
+            }
+        }
+    }
+    chi2/= ((float) (numCols * numRows));
+    fprintf(stderr,"The chi-squared per pixel is %.2f\n", chi2);
+
+    psFree(tmpImage);
+    psFree(outImage);
+    psFree(chebys);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+
+    return(testStatus);
+}
+
+static bool FitChebyF64(int numCols, int numRows)
+{
+    const double A = 1.0;
+    const double B = 2.0;
+    const double C = 3.0;
+    const double D = 4.0;
+    const double E = 5.0;
+    const double F = 6.0;
+    const double ERROR_TOL = 0.1;
+
+    psImage *tmpImage     = NULL;
+    psImage *outImage     = NULL;
+    bool testStatus      = true;
+    psS32 i               = 0;
+    psS32 j               = 0;
+    double chi2 = 0.0;
+
+
+    fprintf(stderr,"psImageFitPolynomial(), psImageEvalPolynom(): (%d by %d)\n", numRows, numCols);
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+
+    tmpImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
+    outImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            tmpImage->data.F64[i][j] = I_POLY(((double) i), ((double) j));
+        }
+    }
+
+    psPolynomial2D *chebys = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, 5, 5);
+
+    chebys = psImageFitPolynomial(chebys, tmpImage);
+
+    outImage = psImageEvalPolynomial(outImage, chebys);
+
+    chi2 = 0.0;
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            double expect = tmpImage->data.F64[i][j];
+            double actual = outImage->data.F64[i][j];
+            chi2+= (actual-expect) * (actual-expect);
+            if (fabs((actual - expect) / expect) > ERROR_TOL) {
+                fprintf(stderr,"pixel [%d][%d] is %.2f should be %.2f\n", i, j, actual, expect);
+            }
+        }
+    }
+    chi2/= ((double) (numCols * numRows));
+    fprintf(stderr,"The chi-squared per pixel is %.2f\n", chi2);
+
+    psFree(tmpImage);
+    psFree(outImage);
+    psFree(chebys);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+
+    return(testStatus);
+}
+
+static psS32 testPsImageEvalPolynom()
+{
+    if (!FitChebyF32(1, 1)) {
+        return 1;
+    }
+    if (!FitChebyF32(1, 5)) {
+        return 2;
+    }
+    if (!FitChebyF32(5, 1)) {
+        return 3;
+    }
+    if (!FitChebyF32(5, 5)) {
+        return 4;
+    }
+    if (!FitChebyF64(1, 1)) {
+        return 5;
+    }
+    if (!FitChebyF64(1, 5)) {
+        return 6;
+    }
+    if (!FitChebyF64(5, 1)) {
+        return 7;
+    }
+    if (!FitChebyF64(5, 5)) {
+        return 8;
+    }
+    return 0;
+}
+
+psS32 testImageCountPixel(void)
+{
+    long numPix = 0;
+    long numPix2 = 0;
+    psImage *in = NULL;
+    psRegion reg;
+    reg.x0 = 0;
+    reg.x1 = 1;
+    reg.y0 = 0;
+    reg.y1 = 5;
+    numPix = psImageCountPixelMask(in, reg, 1);
+
+    if (numPix != -1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask failed to return -1 for NULL Vector input.\n");
+        return 1;
+    }
+
+    numPix = 0;
+    in = psImageAlloc(5, 5, PS_TYPE_S32);
+
+    psImage *in2 = NULL;
+    in2 = psImageAlloc(1, 5, PS_TYPE_U8);
+
+    in->data.S32[0][0] = 0;
+    in->data.S32[1][0] = 1;
+    in->data.S32[2][0] = 0;
+    in->data.S32[3][0] = 1;
+    in->data.S32[4][0] = 0;
+    in2->data.U8[0][0] = 0;
+    in2->data.U8[1][0] = 1;
+    in2->data.U8[2][0] = 0;
+    in2->data.U8[3][0] = 1;
+    in2->data.U8[4][0] = 0;
+
+    //    numPix = psImageCountPixelMask(in, reg, 1);
+    numPix2 = psImageCountPixelMask(in2, reg, 1);
+    numPix = -1;
+    //numPix should be -1 from using S32's
+    if (numPix != -1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask failed to return -1 for wrong type of Image input.\n");
+        return 2;
+    }
+    if (numPix2 == -1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask returned -1 for Correct Image input\n");
+        return 3;
+    }
+    if (numPix2 != 2) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
+        return 4;
+    }
+    //Test for smaller region than image returns only 1 pixel counted
+    reg.y1 = 2.1;
+    numPix2 = psImageCountPixelMask(in2, reg, 1);
+    if (numPix2 != 1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
+        return 5;
+    }
+    //Test for -1 upper bnds in region = 5, 1 limits = 2 pixels returned
+    reg.x1 = 0;
+    reg.y1 = -1;
+    numPix2 = psImageCountPixelMask(in2, reg, 1);
+    if (numPix2 != 2) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
+        return 100;
+    }
+
+    //Test for invalid region (0 pixels, lower = upper)
+    reg.x0 = 1;
+    reg.y0 = 1;
+    reg.x1 = 1;
+    reg.y1 = 1;
+    numPix2 = psImageCountPixelMask(in2, reg, 1);
+    if (numPix2 != -1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask failed to return -1 for empty Region input.\n");
+        return 9;
+    }
+
+    //Test for whole image (region = 0,0 0,0 )
+    reg.x0 = 0;
+    reg.x1 = 0;
+    reg.y0 = 0;
+    reg.y1 = 0;
+    numPix2 = psImageCountPixelMask(in2, reg, 1);
+    if (numPix2 != 2) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
+        return 10;
+    }
+
+    psFree(in);
+    psFree(in2);
+    return 0;
+}
+
+int trentBug()
+{
+    psTraceSetLevel("p_psVectorRobustStats", 6);
+    psTraceSetLevel("vectorBinDisectF32", 6);
+
+    psFits *fits = psFitsOpen("f0230_c01_606365_12k_i.fits", "r");
+    psRegion region = {0, 0, 0, 0};
+    psImage *image = psFitsReadImage(NULL, fits, region, 0);
+    psFitsClose(fits);
+    int numNaN = psImageClipNaN(image, 0.0);
+    printf("Clipped %d NaN pixels.\n", numNaN);
+
+    psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV);
+    stats->clipSigma = 2;
+    stats->clipIter = 5;
+    stats = psImageStats(stats, image, NULL, 0);
+
+    printf("%lf %lf\n", stats->robustMedian, stats->robustStdev);
+    psFree(image);
+    psFree(stats);
+
+    return(0);
+}
+
+
 static psS32 testPsImageStats()
 {
+    trentBug();
+    return(0);
+
+    psTraceSetLevel("p_psVectorRobustStats", 0);
+
     const int N  = 32;
     const int M = 64;
@@ -299,4 +747,10 @@
             }
         }
+        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++ ) {
             for ( j = 0;j < tmpMask->numCols;j++ ) {
@@ -310,5 +764,7 @@
         }
 
-        myStats = psStatsAlloc( PS_STAT_SAMPLE_MEAN );
+        //HEY
+        //        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                           */
@@ -320,5 +776,6 @@
             psAbort(__func__,"Failed input psStats equal to returned psStats");
         }
-        fprintf(stderr, "The sample mean was %.2f\n", myStats->sampleMean );
+        //        fprintf(stderr, "The sample mean was %.2f\n", myStats->sampleMean );
+        fprintf(stderr, "The fitted mean was %.2f\n", myStats->fittedMean );
 
         /*************************************************************************/
@@ -327,5 +784,10 @@
 
         myStats = psImageStats( myStats, tmpImage, tmpMask, 1 );
-        fprintf(stderr, "The sample mean was %.2f\n", myStats->sampleMean );
+        if (myStats == NULL) {
+            fprintf(stderr,"TEST ERROR: psImageStats() returned NULL.\n");
+        } else {
+            //        fprintf(stderr, "The fitted mean was %.2f\n", myStats->fittedMean );
+            fprintf(stderr, "The fitted mean was %.2f\n", myStats->fittedMean );
+        }
 
         /*************************************************************************/
@@ -377,420 +839,7 @@
 }
 
-// HEY: XXX
-static psS32 testPsImageFitPolynomial()
-{
-    const int IMAGE_SIZE = 16;
-    const int CHEBY_X_DIM = 8;
-    const int CHEBY_Y_DIM = 8;
-    const int THRESHOLD = 10;
-
-    psStats * myStats = NULL;
-    psImage *tmpImage = NULL;
-    psImage *outImage = NULL;
-    psImage *nullImage = NULL;
-    psPolynomial2D *my2DPoly = NULL;
-    psPolynomial2D *null2DPoly = NULL;
-    psS32 testStatus = true;
-    psS32 i = 0;
-    psS32 j = 0;
-    psS32 currentId = 0;
-
-    currentId = psMemGetId();
-    /*************************************************************************/
-    /*  Allocate and initialize data structures                      */
-    /*************************************************************************/
-    tmpImage = psImageAlloc( IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32 );
-    outImage = psImageAlloc( IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32 );
-    for ( i = 0;i < IMAGE_SIZE;i++ ) {
-        for ( j = 0;j < IMAGE_SIZE;j++ ) {
-            tmpImage->data.F32[ i ][ j ] = 4.0;
-            tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j );
-            tmpImage->data.F32[ i ][ j ] = ( float ) ( i + j ) + ( 4.0 * ( float ) i );
-            outImage->data.F32[ i ][ j ] = 0.0;
-        }
-    }
-    my2DPoly = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, CHEBY_X_DIM-1, CHEBY_Y_DIM-1);
-    /*************************************************************************/
-    /*  Calculate Chebyshev Polynomials, no mask                     */
-    /*************************************************************************/
-    my2DPoly = psImageFitPolynomial( my2DPoly, tmpImage );
-    if (my2DPoly == NULL) {
-        printf("TEST ERROR: psImageFitPolynomial() returned NULL.\n");
-        testStatus = false;
-    }
-    for ( i = 0;i < CHEBY_X_DIM;i++ ) {
-        for ( j = 0;j < CHEBY_Y_DIM;j++ ) {
-            fprintf(stderr, "Cheby Polynomial (%d, %d) coefficient is %.2f\n", i, j, 0.0001f+my2DPoly->coeff[ i ][ j ] );
-        }
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error message for NULL coeffs argument.");
-    null2DPoly = psImageFitPolynomial( NULL, tmpImage );
-    if ( null2DPoly != NULL ) {
-        fprintf(stderr,"ERROR: psImageFitPolynomial did not return NULL with invalid coeffs argument.");
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"Following should be a error message for NULL input argument.");
-    null2DPoly = psImageFitPolynomial( null2DPoly, NULL );
-    if ( null2DPoly != NULL ) {
-        fprintf(stderr,"ERROR: psImageFitPolynomial did not return NULL with null input image.");
-    }
-
-    /*************************************************************************/
-    /*  Evaluate Chebyshev Polynomials, no mask                      */
-    /*************************************************************************/
-    outImage = psImageEvalPolynomial( outImage, my2DPoly );
-    for ( i = 0;i < IMAGE_SIZE;i++ ) {
-        for ( j = 0;j < IMAGE_SIZE;j++ ) {
-
-            //             fprintf(stderr,"pixel[%d][%d] is (%.2f, %.2f)\n", i, j,
-            //                     tmpImage->data.F32[i][j],
-            //                     outImage->data.F32[i][j]);
-            if ( fabs( outImage->data.F32[ i ][ j ] - tmpImage->data.F32[ i ][ j ] ) > THRESHOLD ) {
-                fprintf(stderr, "Pixel (%d, %d) is %.2f, should be %.2f\n", i, j,
-                        outImage->data.F32[ i ][ j ],
-                        tmpImage->data.F32[ i ][ j ] );
-            }
-
-        }
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error message for NULL coeffs argument.");
-    nullImage = psImageEvalPolynomial( outImage, NULL );
-    if ( nullImage != NULL ) {
-        fprintf(stderr,"ERROR: psImageEvalPolynomial did not return NULL with invalid coeffs argument.");
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"Following should be a error message for NULL input argument.");
-    nullImage = psImageEvalPolynomial( NULL, my2DPoly );
-    if ( nullImage != NULL ) {
-        fprintf(stderr,"ERROR: psImageEvalPolynomial did not return NULL with null input image.");
-    }
-
-    /*************************************************************************/
-    /*  Deallocate data structures                                   */
-    /*************************************************************************/
-    psFree( myStats );
-    psFree( tmpImage );
-    psFree( outImage );
-    psFree( my2DPoly );
-
-    return ( !testStatus );
-}
-
-static psS32 testPsImagePixelInterpolate()
-{
-    const int IMAGE_SIZE = 10;
-
-    psImage *tmpImage   = NULL;
-    psS32 testStatus      = true;
-    psS32 i               = 0;
-    psS32 j               = 0;
-    float pixel         = 0.0;
-    float x             = 0.0;
-    float y             = 0.0;
-
-    /*************************************************************************/
-    /*  Allocate and initialize data structures                      */
-    /*************************************************************************/
-    tmpImage = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_F32);
-    for (i=0;i<IMAGE_SIZE;i++) {
-        for (j=0;j<IMAGE_SIZE;j++) {
-            tmpImage->data.F32[i][j] = 4.0;
-            tmpImage->data.F32[i][j] = (float) (i + j) + (4.0 * (float) i);
-            tmpImage->data.F32[i][j] = (float) (i + j);
-            fprintf(stderr,"%.1f ", tmpImage->data.F32[i][j]);
-        }
-        fprintf(stderr,"\n");
-    }
-    for (i=0;i<IMAGE_SIZE-1;i++) {
-        for (j=0;j<IMAGE_SIZE-1;j++) {
-            x = 0.2 + (float) i;
-            y = 0.2 + (float) j;
-            pixel = psImagePixelInterpolate(tmpImage,
-                                            x, y,
-                                            NULL, 0,
-                                            0,
-                                            PS_INTERPOLATE_BILINEAR);
-            fprintf(stderr,"%.1f ", pixel);
-        }
-        fprintf(stderr,"\n");
-    }
-
-    for (i=0;i<IMAGE_SIZE-1;i++) {
-        for (j=0;j<IMAGE_SIZE-1;j++) {
-            x = 0.2 + (float) i;
-            y = 0.2 + (float) j;
-            pixel = psImagePixelInterpolate(tmpImage,
-                                            x, y,
-                                            NULL,0,
-                                            0,
-                                            PS_INTERPOLATE_BILINEAR);
-            fprintf(stderr,"image[%.1f][%.1f] is interpolated at %.1f\n", x, y, pixel);
-        }
-    }
-
-    psFree(tmpImage);
-
-    return (!testStatus);
-}
-
-#define I_POLY(X, Y) \
-((A) + (B * X) + (C * Y) + (D * X * Y) + (E * X * X) + (F * Y * Y)) \
-
-static bool FitChebyF32(int numCols, int numRows)
-{
-    const double A = 1.0;
-    const double B = 2.0;
-    const double C = 3.0;
-    const double D = 4.0;
-    const double E = 5.0;
-    const double F = 6.0;
-    const double ERROR_TOL = 0.1;
-
-    psImage *tmpImage     = NULL;
-    psImage *outImage     = NULL;
-    bool testStatus      = true;
-    psS32 i               = 0;
-    psS32 j               = 0;
-    float chi2 = 0.0;
-
-
-    fprintf(stderr,"psImageFitPolynomial(), psImageEvalPolynom(): (%d by %d)\n", numRows, numCols);
-
-    /*************************************************************************/
-    /*  Allocate and initialize data structures                      */
-    /*************************************************************************/
-
-    tmpImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
-    outImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
-    for (i=0;i<numRows;i++) {
-        for (j=0;j<numCols;j++) {
-            tmpImage->data.F32[i][j] = I_POLY(((float) i), ((float) j));
-        }
-    }
-
-    psPolynomial2D *chebys = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, 5, 5);
-
-    chebys = psImageFitPolynomial(chebys, tmpImage);
-
-    outImage = psImageEvalPolynomial(outImage, chebys);
-
-    chi2 = 0.0;
-    for (i=0;i<numRows;i++) {
-        for (j=0;j<numCols;j++) {
-            float expect = tmpImage->data.F32[i][j];
-            float actual = outImage->data.F32[i][j];
-            chi2+= (actual-expect) * (actual-expect);
-            if (fabs((actual - expect) / expect) > ERROR_TOL) {
-                fprintf(stderr,"pixel [%d][%d] is %.2f should be %.2f\n", i, j, actual, expect);
-            }
-        }
-    }
-    chi2/= ((float) (numCols * numRows));
-    fprintf(stderr,"The chi-squared per pixel is %.2f\n", chi2);
-
-    psFree(tmpImage);
-    psFree(outImage);
-    psFree(chebys);
-
-    /*************************************************************************/
-    /*  Deallocate data structures                                   */
-    /*************************************************************************/
-
-    return(testStatus);
-}
-
-static bool FitChebyF64(int numCols, int numRows)
-{
-    const double A = 1.0;
-    const double B = 2.0;
-    const double C = 3.0;
-    const double D = 4.0;
-    const double E = 5.0;
-    const double F = 6.0;
-    const double ERROR_TOL = 0.1;
-
-    psImage *tmpImage     = NULL;
-    psImage *outImage     = NULL;
-    bool testStatus      = true;
-    psS32 i               = 0;
-    psS32 j               = 0;
-    double chi2 = 0.0;
-
-
-    fprintf(stderr,"psImageFitPolynomial(), psImageEvalPolynom(): (%d by %d)\n", numRows, numCols);
-
-    /*************************************************************************/
-    /*  Allocate and initialize data structures                      */
-    /*************************************************************************/
-
-    tmpImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
-    outImage = psImageAlloc(numCols, numRows, PS_TYPE_F64);
-    for (i=0;i<numRows;i++) {
-        for (j=0;j<numCols;j++) {
-            tmpImage->data.F64[i][j] = I_POLY(((double) i), ((double) j));
-        }
-    }
-
-    psPolynomial2D *chebys = psPolynomial2DAlloc(PS_POLYNOMIAL_CHEB, 5, 5);
-
-    chebys = psImageFitPolynomial(chebys, tmpImage);
-
-    outImage = psImageEvalPolynomial(outImage, chebys);
-
-    chi2 = 0.0;
-    for (i=0;i<numRows;i++) {
-        for (j=0;j<numCols;j++) {
-            double expect = tmpImage->data.F64[i][j];
-            double actual = outImage->data.F64[i][j];
-            chi2+= (actual-expect) * (actual-expect);
-            if (fabs((actual - expect) / expect) > ERROR_TOL) {
-                fprintf(stderr,"pixel [%d][%d] is %.2f should be %.2f\n", i, j, actual, expect);
-            }
-        }
-    }
-    chi2/= ((double) (numCols * numRows));
-    fprintf(stderr,"The chi-squared per pixel is %.2f\n", chi2);
-
-    psFree(tmpImage);
-    psFree(outImage);
-    psFree(chebys);
-
-    /*************************************************************************/
-    /*  Deallocate data structures                                   */
-    /*************************************************************************/
-
-    return(testStatus);
-}
-
-static psS32 testPsImageEvalPolynom()
-{
-    if (!FitChebyF32(1, 1)) {
-        return 1;
-    }
-    if (!FitChebyF32(1, 5)) {
-        return 2;
-    }
-    if (!FitChebyF32(5, 1)) {
-        return 3;
-    }
-    if (!FitChebyF32(5, 5)) {
-        return 4;
-    }
-    if (!FitChebyF64(1, 1)) {
-        return 5;
-    }
-    if (!FitChebyF64(1, 5)) {
-        return 6;
-    }
-    if (!FitChebyF64(5, 1)) {
-        return 7;
-    }
-    if (!FitChebyF64(5, 5)) {
-        return 8;
-    }
-    return 0;
-}
-
-psS32 testImageCountPixel(void)
-{
-    long numPix = 0;
-    long numPix2 = 0;
-    psImage *in = NULL;
-    psRegion reg;
-    reg.x0 = 0;
-    reg.x1 = 1;
-    reg.y0 = 0;
-    reg.y1 = 5;
-    numPix = psImageCountPixelMask(in, reg, 1);
-
-    if (numPix != -1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask failed to return -1 for NULL Vector input.\n");
-        return 1;
-    }
-
-    numPix = 0;
-    in = psImageAlloc(5, 5, PS_TYPE_S32);
-
-    psImage *in2 = NULL;
-    in2 = psImageAlloc(1, 5, PS_TYPE_U8);
-
-    in->data.S32[0][0] = 0;
-    in->data.S32[1][0] = 1;
-    in->data.S32[2][0] = 0;
-    in->data.S32[3][0] = 1;
-    in->data.S32[4][0] = 0;
-    in2->data.U8[0][0] = 0;
-    in2->data.U8[1][0] = 1;
-    in2->data.U8[2][0] = 0;
-    in2->data.U8[3][0] = 1;
-    in2->data.U8[4][0] = 0;
-
-    //    numPix = psImageCountPixelMask(in, reg, 1);
-    numPix2 = psImageCountPixelMask(in2, reg, 1);
-    numPix = -1;
-    //numPix should be -1 from using S32's
-    if (numPix != -1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask failed to return -1 for wrong type of Image input.\n");
-        return 2;
-    }
-    if (numPix2 == -1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask returned -1 for Correct Image input\n");
-        return 3;
-    }
-    if (numPix2 != 2) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
-        return 4;
-    }
-    //Test for smaller region than image returns only 1 pixel counted
-    reg.y1 = 2.1;
-    numPix2 = psImageCountPixelMask(in2, reg, 1);
-    if (numPix2 != 1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
-        return 5;
-    }
-    //Test for -1 upper bnds in region = 5, 1 limits = 2 pixels returned
-    reg.x1 = 0;
-    reg.y1 = -1;
-    numPix2 = psImageCountPixelMask(in2, reg, 1);
-    if (numPix2 != 2) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
-        return 100;
-    }
-
-    //Test for invalid region (0 pixels, lower = upper)
-    reg.x0 = 1;
-    reg.y0 = 1;
-    reg.x1 = 1;
-    reg.y1 = 1;
-    numPix2 = psImageCountPixelMask(in2, reg, 1);
-    if (numPix2 != -1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask failed to return -1 for empty Region input.\n");
-        return 9;
-    }
-
-    //Test for whole image (region = 0,0 0,0 )
-    reg.x0 = 0;
-    reg.x1 = 0;
-    reg.y0 = 0;
-    reg.y1 = 0;
-    numPix2 = psImageCountPixelMask(in2, reg, 1);
-    if (numPix2 != 2) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
-                "psImageCountPixelMask returned incorrect pixel count %ld\n", numPix2);
-        return 10;
-    }
-
-    psFree(in);
-    psFree(in2);
-    return 0;
-}
-
+
+
+
+
+//This code will
Index: /trunk/psLib/test/math/tst_psMinimizePowell.c
===================================================================
--- /trunk/psLib/test/math/tst_psMinimizePowell.c	(revision 6280)
+++ /trunk/psLib/test/math/tst_psMinimizePowell.c	(revision 6280)
@@ -0,0 +1,283 @@
+/*****************************************************************************
+    This routine must ensure that psMinimizePowell() works correctly.
+ 
+    We test with a NULL and non-NULL paramMask.
+ 
+    XXX: Must verify the stderr for the NULL parameter tests.
+ *****************************************************************************/
+#include <stdio.h>
+#include <math.h>
+#include "pslib.h"
+#include "psTest.h"
+#define N 5
+#define MIN_VALUE 20.0
+#define NUM_PARAMS 10
+#define ERROR_TOLERANCE 0.10
+float expectedParm[NUM_PARAMS];
+psS32 testStatus = true;
+
+/*****************************************************************************
+myFunc(): This routine subtracts the associate value in expectedParm[] from
+each parameter and then squares it, then sums that for all parameters, then
+adds MIN_VALUE to it.  The minimum for this function will be MIN_VALUE, and
+will occur when each parameter equals the associated value in expectedParm[].
+ 
+This procedure ignores the coordinates, other than to ensure that they were
+passed correctly from psMinimizePowell().
+ *****************************************************************************/
+float myFunc(psVector *myParams,
+             psArray *myCoords)
+{
+    float sum = 0.0;
+    float coordData = 0.0;
+    float expData = 0.0;
+    psS32 i;
+
+    //
+    // Simply ensure that the coordinate data was passed correctly.
+    //
+    for (i=0;i<N;i++) {
+        coordData = ((psVector *) (myCoords->data[i]))->data.F32[0];
+        expData = (float) (i+10);
+        if (fabs(coordData - expData) > FLT_EPSILON) {
+            printf("ERROR(1): coordinate data was incorrectly passed to myFunc()\n");
+            printf("ERROR(1): was (%f) should be (%f)\n", coordData, expData);
+            testStatus = false;
+        }
+        coordData = ((psVector *) (myCoords->data[i]))->data.F32[1];
+        expData = (float) (i+3);
+        if (fabs(coordData - expData) > FLT_EPSILON) {
+            printf("ERROR(2): coordinate data was incorrectly passed to myFunc()\n");
+            printf("ERROR(2): was (%f) should be (%f)\n", coordData, expData);
+            testStatus = false;
+        }
+    }
+
+
+    sum = 0.0;
+    for (i=0;i<NUM_PARAMS;i++) {
+        sum+= (myParams->data.F32[i] - expectedParm[i]) * (myParams->data.F32[i] - expectedParm[i]);
+    }
+    sum = MIN_VALUE + (sum * sum);
+
+    return(sum);
+}
+
+
+psS32 t00()
+{
+    psS32 currentId = psMemGetId();
+    psS32 memLeaks = 0;
+    psS32 i = 0;
+    psArray *myCoords;
+    psVector *myParams;
+    psVector *myParamMask;
+    psMinimization *min;
+
+    psTraceSetLevel(".psLib", 0);
+    /**************************************************************************
+     *************************************************************************/
+    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    myParamMask = psVectorAlloc(NUM_PARAMS, PS_TYPE_U8);
+    min = psMinimizationAlloc(100, 0.01);
+
+    myCoords = psArrayAlloc(N);
+    for (i=0;i<N;i++) {
+        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
+        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
+        ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
+    }
+    for (i=0;i<NUM_PARAMS;i++) {
+        expectedParm[i] = 2.32 + (float) (2 * i);
+        myParams->data.F32[i] = 0.0;
+        myParams->data.F32[i] = (float) i;
+        myParamMask->data.U8[i] = 0;
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psMinimizePowell()");
+
+    psMinimizePowell(min,
+                     myParams,
+                     myParamMask,
+                     myCoords,
+                     (psMinimizePowellFunc) myFunc);
+
+    printf("\nThe minimum is %f (expected: %f)\n", min->value, MIN_VALUE);
+
+    for (i=0;i<NUM_PARAMS;i++) {
+        printf("Parameter %d at the minimum is %f (expected: %f)\n", i,
+               myParams->data.F32[i], expectedParm[i]);
+
+        if (fabs(myParams->data.F32[i] - expectedParm[i]) > fabs(ERROR_TOLERANCE * expectedParm[i])) {
+            printf("ERROR: Parameter %d: (%.1f), expected was (%.1f)\n",
+                   i, myParams->data.F32[i], expectedParm[i]);
+            testStatus = false;
+        } else {
+            printf("Parameter %d: (%.1f), expected was (%.1f)\n",
+                   i, myParams->data.F32[i], expectedParm[i]);
+        }
+    }
+
+
+    psFree(myCoords);
+    psFree(myParams);
+    psFree(myParamMask);
+    psFree(min);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psMinimize functions",
+                "psMinimizePowell()",
+                testStatus);
+
+
+    return (!testStatus);
+}
+
+psS32 t01()
+{
+    psS32 currentId = psMemGetId();
+    psS32 memLeaks = 0;
+    psS32 i = 0;
+    psArray *myCoords;
+    psVector *myParams;
+    psMinimization *min;
+
+    psTraceSetLevel(".psLib", 0);
+    /**************************************************************************
+     *************************************************************************/
+    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    min = psMinimizationAlloc(100, 0.01);
+
+    myCoords = psArrayAlloc(N);
+    for (i=0;i<N;i++) {
+        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
+        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
+        ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
+    }
+    for (i=0;i<NUM_PARAMS;i++) {
+        expectedParm[i] = 2.32 + (float) (2 * i);
+        myParams->data.F32[i] = 0.0;
+        myParams->data.F32[i] = (float) i;
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psMinimizePowell()");
+
+    psMinimizePowell(min,
+                     myParams,
+                     NULL,
+                     myCoords,
+                     (psMinimizePowellFunc) myFunc);
+
+    printf("\nThe minimum is %f (expected: %f)\n", min->value, MIN_VALUE);
+
+    for (i=0;i<NUM_PARAMS;i++) {
+        printf("Parameter %d at the minimum is %f (expected: %f)\n", i,
+               myParams->data.F32[i], expectedParm[i]);
+
+        if (fabs(myParams->data.F32[i] - expectedParm[i]) > fabs(ERROR_TOLERANCE * expectedParm[i])) {
+            printf("ERROR: Parameter %d: (%.1f), expected was (%.1f)\n",
+                   i, myParams->data.F32[i], expectedParm[i]);
+            testStatus = false;
+        } else {
+            printf("Parameter %d: (%.1f), expected was (%.1f)\n",
+                   i, myParams->data.F32[i], expectedParm[i]);
+        }
+    }
+
+
+    psFree(myCoords);
+    psFree(myParams);
+    psFree(min);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psMinimize functions",
+                "psMinimizePowell()",
+                testStatus);
+
+
+    return (!testStatus);
+}
+
+psS32 t02()
+{
+    psS32 currentId = psMemGetId();
+    psS32 memLeaks = 0;
+    psS32 i = 0;
+    psArray *myCoords;
+    psVector *myParams;
+    psVector *myParamMask;
+    psMinimization *min;
+
+    psTraceSetLevel(".psLib", 0);
+    /**************************************************************************
+     *************************************************************************/
+    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    myParamMask = psVectorAlloc(NUM_PARAMS, PS_TYPE_U8);
+    min = psMinimizationAlloc(100, 0.01);
+
+    myCoords = psArrayAlloc(N);
+    for (i=0;i<N;i++) {
+        myCoords->data[i] = (psPtr *) psVectorAlloc(2, PS_TYPE_F32);
+        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
+        ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
+    }
+    for (i=0;i<NUM_PARAMS;i++) {
+        expectedParm[i] = 2.32 + (float) (2 * i);
+        myParams->data.F32[i] = 0.0;
+        myParams->data.F32[i] = (float) i;
+        myParamMask->data.U8[i] = 0;
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psMinimizePowell(): various NULL inputs");
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null minimize.");
+    psMinimizePowell(NULL, myParams, myParamMask, myCoords, (psMinimizePowellFunc) myFunc);
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null parameter vector");
+    psMinimizePowell(min, NULL, myParamMask, myCoords,(psMinimizePowellFunc) myFunc);
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null coords.");
+    psMinimizePowell(min, myParams, myParamMask, NULL, (psMinimizePowellFunc) myFunc);
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error for null function");
+    psMinimizePowell(min, myParams, myParamMask, myCoords, NULL);
+
+    psFree(myCoords);
+    psFree(myParams);
+    psFree(myParamMask);
+    psFree(min);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psMinimize functions",
+                "psMinimizePowell(): various NULL inputs",
+                testStatus);
+
+
+    return (!testStatus);
+}
+
+psS32 main()
+{
+    psLogSetFormat("HLNM");
+    t00();
+    t01();
+    t02();
+}
Index: /trunk/psLib/test/math/verified/tst_psMinimizePowell.stderr
===================================================================
--- /trunk/psLib/test/math/verified/tst_psMinimizePowell.stderr	(revision 6280)
+++ /trunk/psLib/test/math/verified/tst_psMinimizePowell.stderr	(revision 6280)
@@ -0,0 +1,16 @@
+<HOST>|I|t02
+    Following should generate error for null minimize.
+<HOST>|E|psMinimizePowell (FILE:LINENO)
+    Unallowable operation: min is NULL.
+<HOST>|I|t02
+    Following should generate error for null parameter vector
+<HOST>|E|psMinimizePowell (FILE:LINENO)
+    Unallowable operation: psVector params or its data is NULL.
+<HOST>|I|t02
+    Following should generate error for null coords.
+<HOST>|E|psMinimizePowell (FILE:LINENO)
+    Unallowable operation: coords is NULL.
+<HOST>|I|t02
+    Following should generate error for null function
+<HOST>|E|psMinimizePowell (FILE:LINENO)
+    Unallowable operation: func is NULL.
Index: /trunk/psLib/test/math/verified/tst_psMinimizePowell.stdout
===================================================================
--- /trunk/psLib/test/math/verified/tst_psMinimizePowell.stdout	(revision 6280)
+++ /trunk/psLib/test/math/verified/tst_psMinimizePowell.stdout	(revision 6280)
@@ -0,0 +1,71 @@
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psMinimizePowell.c                                     *
+*            TestPoint: psMinimize functions{psMinimizePowell()}                   *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+The minimum is 20.000000 (expected: 20.000000)
+Parameter 0 at the minimum is 2.307660 (expected: 2.320000)
+Parameter 0: (2.3), expected was (2.3)
+Parameter 1 at the minimum is 4.310108 (expected: 4.320000)
+Parameter 1: (4.3), expected was (4.3)
+Parameter 2 at the minimum is 6.305460 (expected: 6.320000)
+Parameter 2: (6.3), expected was (6.3)
+Parameter 3 at the minimum is 8.309398 (expected: 8.320000)
+Parameter 3: (8.3), expected was (8.3)
+Parameter 4 at the minimum is 10.311120 (expected: 10.320000)
+Parameter 4: (10.3), expected was (10.3)
+Parameter 5 at the minimum is 12.309612 (expected: 12.320000)
+Parameter 5: (12.3), expected was (12.3)
+Parameter 6 at the minimum is 14.320016 (expected: 14.320000)
+Parameter 6: (14.3), expected was (14.3)
+Parameter 7 at the minimum is 16.318933 (expected: 16.320000)
+Parameter 7: (16.3), expected was (16.3)
+Parameter 8 at the minimum is 18.323397 (expected: 18.320000)
+Parameter 8: (18.3), expected was (18.3)
+Parameter 9 at the minimum is 20.314043 (expected: 20.320000)
+Parameter 9: (20.3), expected was (20.3)
+
+---> TESTPOINT PASSED (psMinimize functions{psMinimizePowell()} | tst_psMinimizePowell.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psMinimizePowell.c                                     *
+*            TestPoint: psMinimize functions{psMinimizePowell()}                   *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+The minimum is 20.000000 (expected: 20.000000)
+Parameter 0 at the minimum is 2.307660 (expected: 2.320000)
+Parameter 0: (2.3), expected was (2.3)
+Parameter 1 at the minimum is 4.310108 (expected: 4.320000)
+Parameter 1: (4.3), expected was (4.3)
+Parameter 2 at the minimum is 6.305460 (expected: 6.320000)
+Parameter 2: (6.3), expected was (6.3)
+Parameter 3 at the minimum is 8.309398 (expected: 8.320000)
+Parameter 3: (8.3), expected was (8.3)
+Parameter 4 at the minimum is 10.311120 (expected: 10.320000)
+Parameter 4: (10.3), expected was (10.3)
+Parameter 5 at the minimum is 12.309612 (expected: 12.320000)
+Parameter 5: (12.3), expected was (12.3)
+Parameter 6 at the minimum is 14.320016 (expected: 14.320000)
+Parameter 6: (14.3), expected was (14.3)
+Parameter 7 at the minimum is 16.318933 (expected: 16.320000)
+Parameter 7: (16.3), expected was (16.3)
+Parameter 8 at the minimum is 18.323397 (expected: 18.320000)
+Parameter 8: (18.3), expected was (18.3)
+Parameter 9 at the minimum is 20.314043 (expected: 20.320000)
+Parameter 9: (20.3), expected was (20.3)
+
+---> TESTPOINT PASSED (psMinimize functions{psMinimizePowell()} | tst_psMinimizePowell.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psMinimizePowell.c                                     *
+*            TestPoint: psMinimize functions{psMinimizePowell(): various NULL inputs} *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psMinimize functions{psMinimizePowell(): various NULL inputs} | tst_psMinimizePowell.c)
+
