Index: /trunk/psLib/test/dataManip/Makefile
===================================================================
--- /trunk/psLib/test/dataManip/Makefile	(revision 886)
+++ /trunk/psLib/test/dataManip/Makefile	(revision 887)
@@ -3,6 +3,6 @@
 ##  Makefile:   test/sysUtils
 ##
-##  $Revision: 1.8 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-05-29 01:15:41 $
+##  $Revision: 1.9 $  $Name: not supported by cvs2svn $
+##  $Date: 2004-06-07 00:31:55 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -17,15 +17,27 @@
 
 TARGET = tst_psMatrix01 \
-         tst_psMatrix02 \
-         tst_psMatrix03 \
-         tst_psMatrix04 \
-         tst_psMatrix05 \
-         tst_psMatrix06 \
-         tst_psMatrix07
-#         tst_psStats00 \
-#         tst_psStats01 \
-#         tst_psStats02 \
-#         tst_psStats03 \
-#         tst_psStats04
+ tst_psMatrix02 \
+ tst_psMatrix03 \
+ tst_psMatrix04 \
+ tst_psMatrix05 \
+ tst_psMatrix06 \
+ tst_psMatrix07 \
+ tst_psStats00 \
+ tst_psStats01 \
+ tst_psStats02 \
+ tst_psStats03 \
+ tst_psStats05 \
+ tst_psStats06 \
+ tst_psStats07 \
+ tst_psStats08 \
+ tst_psStats09 \
+ tst_psHist00 \
+ tst_psHist01 \
+ tst_psHist02 \
+ tst_psFunc00 \
+ tst_psFunc01 \
+ tst_psImageStats00 \
+ tst_psImageStats01 \
+ tst_psImageStats02
 
 all: $(TARGET)
@@ -43,4 +55,20 @@
 tst_psStats03:		tst_psStats03.o
 tst_psStats04:		tst_psStats04.o
+tst_psStats05:		tst_psStats05.o
+tst_psStats06:		tst_psStats06.o
+tst_psStats07:		tst_psStats07.o
+tst_psStats08:		tst_psStats08.o
+tst_psStats09:		tst_psStats09.o
+tst_psHist00:		tst_psHist00.o
+tst_psHist01:		tst_psHist01.o
+tst_psHist02:		tst_psHist02.o
+tst_psFunc00:		tst_psFunc00.o
+tst_psFunc01:		tst_psFunc01.o
+tst_psFunc02:		tst_psFunc02.o
+tst_psFunc03:		tst_psFunc03.o
+tst_psImageStats00:	tst_psImageStats00.o
+tst_psImageStats01:	tst_psImageStats01.o
+tst_psImageStats02:	tst_psImageStats02.o
+tst_psImageStats03:	tst_psImageStats03.o
 
 clean:
@@ -54,4 +82,9 @@
 	$(CC) -o $@ $< -L$(PSLIB_LIB_DIR) -lpslib -lpstest -lgsl -lgslcblas $(LDFLAGS)
 
+## NOTE: The distclean target does not remove the .o files.  The Makefiles must
+## be repaired.
+distclean:
+	$(RM) $(TARGET)
+
 %.lint: %.c
 	splint +posixlib -exportlocal -realcompare $(INCLUDE_GLOBAL) $? > $@; cat $@
Index: /trunk/psLib/test/dataManip/tst_psFunc00.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psFunc00.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psFunc00.c	(revision 887)
@@ -0,0 +1,286 @@
+/*****************************************************************************
+    This routine must ensure that the psPolynomial structures are
+    allocated and deallocated by the psPolynomialXXXlloc() procedures.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psFunctions.h"
+#define MISC_FLOAT_NUMBER 345.0
+#define MISC_X_VALUE 5.0
+#define MISC_INT_NUMBER 35
+#define NUM_BINS 200
+#define AN 2
+#define BN 4
+#define CN 6
+#define DN 8
+int main()
+{
+    psPolynomial1D *my1DPoly = NULL;
+    psPolynomial2D *my2DPoly = NULL;
+    psPolynomial3D *my3DPoly = NULL;
+    psPolynomial4D *my4DPoly = NULL;
+    psDPolynomial1D *my1DPolyD = NULL;
+    psDPolynomial2D *my2DPolyD = NULL;
+    psDPolynomial3D *my3DPolyD = NULL;
+    psDPolynomial4D *my4DPolyD = NULL;
+    int testStatus      = true;
+    int memLeaks        = 0;
+    int a               = 0;
+    int b               = 0;
+    int c               = 0;
+    int d               = 0;
+    int currentId       = 0;
+
+    currentId       = psMemGetId();
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psPolynomial1D structure.");
+
+    my1DPoly = psPolynomial1DAlloc(AN);
+    for (a = 0; a < AN ; a++) {
+        my1DPoly->coeff[a] = MISC_FLOAT_NUMBER;
+        my1DPoly->coeffErr[a] = MISC_FLOAT_NUMBER;
+        my1DPoly->mask[a] = MISC_INT_NUMBER;
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (x) = (%f): %f\n", MISC_X_VALUE,
+           psEvalPolynomial1D(MISC_X_VALUE, my1DPoly));
+
+    psPolynomial1DFree(my1DPoly);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psPolynomial1D structure.",
+                testStatus);
+
+
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psPolynomial2D structure.");
+    my2DPoly = psPolynomial2DAlloc(AN, BN);
+    for (a = 0; a < AN ; a++) {
+        for (b = 0; b < BN ; b++) {
+            my2DPoly->coeff[a][b] = MISC_FLOAT_NUMBER;
+            my2DPoly->coeffErr[a][b] = MISC_FLOAT_NUMBER;
+            my2DPoly->mask[a][b] = MISC_INT_NUMBER;
+        }
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (x, y) = (%f, %f): %f\n", MISC_X_VALUE, MISC_X_VALUE,
+           psEvalPolynomial2D(MISC_X_VALUE, MISC_X_VALUE, my2DPoly));
+
+    psPolynomial2DFree(my2DPoly);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psPolynomial2D structure.",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psPolynomial3D structure.");
+    my3DPoly = psPolynomial3DAlloc(AN, BN, CN);
+    for (a = 0; a < AN ; a++) {
+        for (b = 0; b < BN ; b++) {
+            for (c = 0; c < CN ; c++) {
+                my3DPoly->coeff[a][b][c] = MISC_FLOAT_NUMBER;
+                my3DPoly->coeffErr[a][b][c] = MISC_FLOAT_NUMBER;
+                my3DPoly->mask[a][b][c] = MISC_INT_NUMBER;
+            }
+        }
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (x, y, z) = (%f, %f, %f): %f\n", MISC_X_VALUE, MISC_X_VALUE,
+           MISC_X_VALUE,
+           psEvalPolynomial3D(MISC_X_VALUE, MISC_X_VALUE, MISC_X_VALUE, my3DPoly));
+
+    psPolynomial3DFree(my3DPoly);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psPolynomial3D structure.",
+                testStatus);
+
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psPolynomial4D structure.");
+    my4DPoly = psPolynomial4DAlloc(AN, BN, CN, DN);
+    for (a = 0; a < AN ; a++) {
+        for (b = 0; b < BN ; b++) {
+            for (c = 0; c < CN ; c++) {
+                for (d = 0; d < DN ; d++) {
+                    my4DPoly->coeff[a][b][c][d] = MISC_FLOAT_NUMBER;
+                    my4DPoly->coeffErr[a][b][c][d] = MISC_FLOAT_NUMBER;
+                    my4DPoly->mask[a][b][c][d] = MISC_INT_NUMBER;
+                }
+            }
+        }
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (w, x, y, z) = (%f, %f, %f, %f): %f\n", MISC_X_VALUE, MISC_X_VALUE,
+           MISC_X_VALUE, MISC_X_VALUE,
+           psEvalPolynomial4D(MISC_X_VALUE, MISC_X_VALUE, MISC_X_VALUE, MISC_X_VALUE, my4DPoly));
+
+    psPolynomial4DFree(my4DPoly);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psPolynomial4D structure.",
+                testStatus);
+
+
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psDPolynomial1D structure.");
+
+    my1DPolyD = psDPolynomial1DAlloc(AN);
+    for (a = 0; a < AN ; a++) {
+        my1DPolyD->coeff[a] = MISC_FLOAT_NUMBER;
+        my1DPolyD->coeffErr[a] = MISC_FLOAT_NUMBER;
+        my1DPolyD->mask[a] = MISC_INT_NUMBER;
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (x) = (%f): %f\n", MISC_X_VALUE,
+           psDEvalPolynomial1D(MISC_X_VALUE, my1DPolyD));
+
+    psDPolynomial1DFree(my1DPolyD);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psDPolynomial1D structure.",
+                testStatus);
+
+
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psDPolynomial2D structure.");
+    my2DPolyD = psDPolynomial2DAlloc(AN, BN);
+    for (a = 0; a < AN ; a++) {
+        for (b = 0; b < BN ; b++) {
+            my2DPolyD->coeff[a][b] = MISC_FLOAT_NUMBER;
+            my2DPolyD->coeffErr[a][b] = MISC_FLOAT_NUMBER;
+            my2DPolyD->mask[a][b] = MISC_INT_NUMBER;
+        }
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (x, y) = (%f, %f): %f\n", MISC_X_VALUE, MISC_X_VALUE,
+           psDEvalPolynomial2D(MISC_X_VALUE, MISC_X_VALUE, my2DPolyD));
+
+    psDPolynomial2DFree(my2DPolyD);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psDPolynomial2D structure.",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psDPolynomial3D structure.");
+    my3DPolyD = psDPolynomial3DAlloc(AN, BN, CN);
+    for (a = 0; a < AN ; a++) {
+        for (b = 0; b < BN ; b++) {
+            for (c = 0; c < CN ; c++) {
+                my3DPolyD->coeff[a][b][c] = MISC_FLOAT_NUMBER;
+                my3DPolyD->coeffErr[a][b][c] = MISC_FLOAT_NUMBER;
+                my3DPolyD->mask[a][b][c] = MISC_INT_NUMBER;
+            }
+        }
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (x, y, z) = (%f, %f, %f): %f\n", MISC_X_VALUE, MISC_X_VALUE,
+           MISC_X_VALUE,
+           psDEvalPolynomial3D(MISC_X_VALUE, MISC_X_VALUE, MISC_X_VALUE, my3DPolyD));
+
+    psDPolynomial3DFree(my3DPolyD);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psDPolynomial3D structure.",
+                testStatus);
+
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "Allocate/Deallocate the psDPolynomial4D structure.");
+    my4DPolyD = psDPolynomial4DAlloc(AN, BN, CN, DN);
+    for (a = 0; a < AN ; a++) {
+        for (b = 0; b < BN ; b++) {
+            for (c = 0; c < CN ; c++) {
+                for (d = 0; d < DN ; d++) {
+                    my4DPolyD->coeff[a][b][c][d] = MISC_FLOAT_NUMBER;
+                    my4DPolyD->coeffErr[a][b][c][d] = MISC_FLOAT_NUMBER;
+                    my4DPolyD->mask[a][b][c][d] = MISC_INT_NUMBER;
+                }
+            }
+        }
+    }
+    psMemCheckCorruption(1);
+
+    printf("At (w, x, y, z) = (%f, %f, %f, %f): %f\n", MISC_X_VALUE, MISC_X_VALUE,
+           MISC_X_VALUE, MISC_X_VALUE,
+           psDEvalPolynomial4D(MISC_X_VALUE, MISC_X_VALUE, MISC_X_VALUE, MISC_X_VALUE, my4DPolyD));
+
+    psDPolynomial4DFree(my4DPolyD);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate/Deallocate the psDPolynomial4D structure.",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psFunc01.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psFunc01.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psFunc01.c	(revision 887)
@@ -0,0 +1,72 @@
+/*****************************************************************************
+    This routine must ensure that the psGaussian() shall evaluate a
+    specified Gaussian at some X.
+ 
+    It also tests the psGaussianDev() procedure.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psFunctions.h"
+#define MY_MEAN 30.0
+#define MY_STDEV 2.0
+#define N 30
+int main()
+{
+    int testStatus = true;
+    float x = 0.0;
+    int  memLeaks;
+    int  currentId = psMemGetId();
+    psVector *myGaussData = NULL;
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "psGaussian()");
+
+
+    for (x = 0.0 ; x < (MY_MEAN * 2.0) ; x+= 1.0) {
+        printf("normal psGaussian(%f) is %f\n", x, psGaussian(x, MY_MEAN, MY_STDEV, 1));
+        x = x + 1.0;
+    }
+
+    for (x = 0.0 ; x < (MY_MEAN * 2.0) ; x+= 1.0) {
+        printf("NON-normal psGaussian(%f) is %f\n", x, psGaussian(x, MY_MEAN, MY_STDEV, 0));
+        x = x + 1.0;
+    }
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psFunctions functions",
+                "psGaussian()",
+                testStatus);
+
+
+    printPositiveTestHeader(stdout,
+                            "psFunctions functions",
+                            "psGaussianDev()");
+
+    myGaussData = psGaussianDev(MY_MEAN, MY_STDEV, N);
+    for (int i = 0; i < N ; i++) {
+        printf("Gaussian Deviate [%d] is %f\n", i, myGaussData->data.F32[i]);
+    }
+
+    psVectorFree(myGaussData);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psFunctions functions",
+                "psGaussianDev()",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psHist00.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psHist00.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psHist00.c	(revision 887)
@@ -0,0 +1,72 @@
+/*****************************************************************************
+    This routine must ensure that the psHistogram structure is correctly
+    allocated and deallocated by the procedure psHistogramAlloc().
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#define MISC_FLOAT_NUMBER 345.0
+#define MISC_INT_NUMBER 345
+#define LOWER 20.0
+#define UPPER 30.0
+#define NUM_BINS 200
+
+int main()
+{
+    psHistogram *myHist = NULL;
+    int testStatus      = true;
+    int memLeaks        = 0;
+    int i               = 0;
+    int currentId       = 0;
+
+    currentId       = psMemGetId();
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Allocate the psHistogram structure.");
+
+    myHist = psHistogramAlloc(LOWER, UPPER, NUM_BINS);
+    for (i=0;i<NUM_BINS;i++) {
+        myHist->nums->data.S32[i] = MISC_INT_NUMBER;
+    }
+    for (i=0;i<NUM_BINS;i++) {
+        printf("Bin number %d bounds: (%f - %f)\n", i,
+               myHist->bounds->data.F32[i],
+               myHist->bounds->data.F32[i+1]);
+    }
+    printf("myHist->minNum is %d\n", myHist->minNum);
+    printf("myHist->maxNum is %d\n", myHist->maxNum);
+    printf("myHist->uniform is %d\n", myHist->uniform);
+
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate the psHistogram structure.",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Deallocate the psHistogram structure.");
+    psHistogramFree(myHist);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Deallocate the psHistogram structure.",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psHist01.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psHist01.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psHist01.c	(revision 887)
@@ -0,0 +1,81 @@
+/*****************************************************************************
+    This routine must ensure that the psHistogram structure is correctly
+    allocated and deallocated by the procedure psHistogramAllocGeneric().
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#define MISC_FLOAT_NUMBER 345.0
+#define MISC_INT_NUMBER 345
+#define LOWER 20.0
+#define UPPER 30.0
+#define NUM_BINS 200
+
+int main()
+{
+    psHistogram *myHist = NULL;
+    psVector *myBounds  = NULL;
+    int testStatus      = true;
+    int memLeaks        = 0;
+    int i               = 0;
+    int currentId       = 0;
+
+    currentId       = psMemGetId();
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Allocate the psHistogram structure.");
+    myBounds = psVectorAlloc(NUM_BINS+1, PS_TYPE_F32);
+    myBounds->n = myBounds->nalloc;
+    for (i=0;i<NUM_BINS+1;i++) {
+        myBounds->data.F32[i] = LOWER + ((UPPER - LOWER) / (float) NUM_BINS) *
+                                (float) i;
+    }
+    myHist = psHistogramAllocGeneric(myBounds);
+
+    for (i=0;i<NUM_BINS;i++) {
+        myHist->nums->data.S32[i] = MISC_INT_NUMBER;
+    }
+
+    for (i=0;i<NUM_BINS;i++) {
+        printf("Bin number %d bounds: (%f - %f)\n", i,
+               myHist->bounds->data.F32[i],
+               myHist->bounds->data.F32[i+1]);
+    }
+    printf("myHist->minNum is %d\n", myHist->minNum);
+    printf("myHist->maxNum is %d\n", myHist->maxNum);
+    printf("myHist->uniform is %d\n", myHist->uniform);
+
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate the psHistogram structure.",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Deallocate the psHistogram structure.");
+    psHistogramFree(myHist);
+    psVectorFree(myBounds);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Deallocate the psHistogram structure.",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psHist02.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psHist02.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psHist02.c	(revision 887)
@@ -0,0 +1,112 @@
+/*****************************************************************************
+    This routine must ensure that the psHistogram structure is correctly
+    populated by the procedure psGetArrayHistogram().
+ 
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#define MISC_FLOAT_NUMBER 345.0
+#define MISC_INT_NUMBER 345
+#define LOWER 20.0
+#define UPPER 30.0
+#define NUM_BINS 20
+#define NUM_DATA 10000
+
+int main()
+{
+    psHistogram *myHist = NULL;
+    psVector *myData    = NULL;
+    psVector *myMask    = NULL;
+    int testStatus      = true;
+    int memLeaks        = 0;
+    int i               = 0;
+    int currentId       = 0;
+
+    currentId       = psMemGetId();
+
+    myData = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+    myData->n = myData->nalloc;
+    for (i=0;i<NUM_DATA;i++) {
+        myData->data.F32[i] = LOWER + ((UPPER - LOWER) / (float) NUM_DATA) * (float) i;
+    }
+
+    myMask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+    myMask->n = myMask->nalloc;
+    for (i=0;i<NUM_DATA;i++) {
+        if (i >= (NUM_DATA/2)) {
+            myMask->data.U8[i] = 1;
+        } else {
+            myMask->data.U8[i] = 0;
+        }
+    }
+    /*************************************************************************/
+    /*  Allocate and Perform Histogram, no mask                      */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Allocate and Perform Histogram, no mask");
+
+    myHist = psHistogramAlloc(LOWER, UPPER, NUM_BINS);
+    myHist = psHistogramVector(myHist, myData, NULL, 0);
+
+    for (i=0;i<NUM_BINS;i++) {
+        printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
+               myHist->bounds->data.F32[i],
+               myHist->bounds->data.F32[i+1],
+               myHist->nums->data.S32[i]);
+    }
+    psHistogramFree(myHist);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate and Perform Histogram, no mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Allocate and Perform Histogram with mask                     */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Allocate and Perform Histogram with mask");
+
+    myHist = psHistogramAlloc(LOWER, UPPER, NUM_BINS);
+    myHist = psHistogramVector(myHist, myData, myMask, 1);
+
+    for (i=0;i<NUM_BINS;i++) {
+        printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
+               myHist->bounds->data.F32[i],
+               myHist->bounds->data.F32[i+1],
+               myHist->nums->data.S32[i]);
+    }
+
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate and Perform Histogram with mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Deallocate the psHistogram structure.");
+    psHistogramFree(myHist);
+    psVectorFree(myData);
+    psVectorFree(myMask);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Deallocate the psHistogram structure.",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psStats00.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats00.c	(revision 886)
+++ /trunk/psLib/test/dataManip/tst_psStats00.c	(revision 887)
@@ -11,67 +11,115 @@
 {
     psStats *myStats    = NULL;
-    psStats *myStats2   = NULL;
     int testStatus      = true;
+    int globalTestStatus = true;
     int i               = 0;
     psVector *myVector  = NULL;
     psVector *maskVector= NULL;
     float mean          = 0.0;
-    float realMean1     = 0.0;
-    float realMean2     = 0.0;
+    float realMeanNoMask   = 0.0;
+    float realMeanWithMask = 0.0;
     int count           = 0;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
 
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_SAMPLE_MEAN");
-
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
     myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
-    myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
     myVector->n = N;
-    maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
     maskVector->n = N;
 
     mean = 0.0;
-    realMean2 = 0.0;
+    realMeanWithMask = 0.0;
+    // Set the appropriate values for the vector data.
     for (i=0;i<N;i++) {
-        myVector->vec.f[i] = (float) i;
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // Set the mask vector and calculate the expected maximum.
+    for (i=0;i<N;i++) {
+        realMeanNoMask+= myVector->data.F32[i];
+
         if (i < (N/2)) {
-            maskVector->vec.ui8[i] = 0;
-            realMean2+= myVector->vec.f[i];
+            maskVector->data.U8[i] = 0;
+            realMeanWithMask+= myVector->data.F32[i];
             count++;
         } else {
-            printf("Masking element %d\n", i);
-            maskVector->vec.ui8[i] = 1;
+            maskVector->data.U8[i] = 1;
         }
-        realMean1+= myVector->vec.f[i];
     }
-    realMean1 /= (float) N;
-    realMean2 /= (float) count;
+    realMeanNoMask /= (float) N;
+    realMeanWithMask /= (float) count;
 
-    myStats2 = psArrayStats(myVector, NULL, 0, myStats);
-    mean = myStats2->sampleMean;
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_MEAN: no vector mask");
 
-    printf("Called psArrayStats() on a vector with no elements masked.\n");
-    printf("The expected mean was %f; the calculated mean was %f\n", realMean1, mean);
-    if (mean == realMean1) {
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+    mean = myStats->sampleMean;
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+    printf("The expected mean was %f; the calculated mean was %f\n", realMeanNoMask, mean);
+    if (mean == realMeanNoMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_SAMPLE_MEAN: no vector mask",
+                testStatus);
 
-    myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
-    mean = myStats2->sampleMean;
-    printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
-    printf("The expected mean was %f; the calculated mean was %f\n", realMean2, mean);
-    if (mean == realMean2) {
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_MEAN: with vector mask");
+
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+    mean = myStats->sampleMean;
+    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
+    printf("The expected mean was %f; the calculated mean was %f\n", realMeanWithMask, mean);
+    if (mean == realMeanWithMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
 
     printFooter(stdout,
-                "psHash functions",
-                "psHashAlloc()",
+                "psVector functions",
+                "PS_STAT_SAMPLE_MEAN: with vector mask",
                 testStatus);
 
-    return (!testStatus);
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "psStats(): deallocating memory");
+
+    psStatsFree(myStats);
+    psVectorFree(myVector);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
 }
Index: /trunk/psLib/test/dataManip/tst_psStats01.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats01.c	(revision 886)
+++ /trunk/psLib/test/dataManip/tst_psStats01.c	(revision 887)
@@ -1,5 +1,5 @@
 /*****************************************************************************
     This routine must ensure that PS_STAT_MAX is correctly computed
-    by the procedure psArrayStats().
+    by the procedure psVectorStats().
  *****************************************************************************/
 #include <stdio.h>
@@ -11,65 +11,115 @@
 {
     psStats *myStats    = NULL;
-    psStats *myStats2   = NULL;
     int testStatus      = true;
+    int globalTestStatus = true;
     int i               = 0;
     psVector *myVector  = NULL;
     psVector *maskVector= NULL;
     float max           = 0.0;
-    float realMax1      = 0.0;
-    float realMax2      = 0.0;
+    float realMaxNoMask   = 0.0;
+    float realMaxWithMask = 0.0;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
 
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_MAX");
-
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
     myStats = psStatsAlloc(PS_STAT_MAX);
-    myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
     myVector->n = N;
-    maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
     maskVector->n = N;
 
+    // Set the appropriate values for the vector data.
     for (i=0;i<N;i++) {
-        myVector->vec.f[i] = (float) i;
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // Set the mask vector and calculate the expected maximum.
+    for (i=0;i<N;i++) {
+        if (myVector->data.F32[i] > realMaxNoMask) {
+            realMaxNoMask = myVector->data.F32[i];
+        }
+
         if (i < (N/2)) {
-            maskVector->vec.ui8[i] = 0;
-            if (myVector->vec.f[i] > realMax2) {
-                realMax2 = myVector->vec.f[i];
+            maskVector->data.U8[i] = 0;
+
+            if (myVector->data.F32[i] > realMaxWithMask) {
+                realMaxWithMask = myVector->data.F32[i];
             }
         } else {
+            maskVector->data.U8[i] = 1;
             printf("Masking element %d\n", i);
-            maskVector->vec.ui8[i] = 1;
-            if (myVector->vec.f[i] > realMax1) {
-                realMax1 = myVector->vec.f[i];
-            }
         }
     }
 
-    myStats2 = psArrayStats(myVector, NULL, 0, myStats);
-    max = myStats2->max;
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_MAX: no vector mask");
 
-    printf("Called psArrayStats() on a vector with no elements masked.\n");
-    printf("The expected max was %f; the calculated max was %f\n", realMax1, max);
-    if (max == realMax1) {
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+    max = myStats->max;
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+    printf("The expected max was %f; the calculated max was %f\n", realMaxNoMask, max);
+    if (max == realMaxNoMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_MAX: no vector mask",
+                testStatus);
 
-    myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
-    max = myStats2->max;
-    printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
-    printf("The expected max was %f; the calculated max was %f\n", realMax2, max);
-    if (max == realMax2) {
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_MAX: with vector mask");
+
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+    max = myStats->max;
+    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
+    printf("The expected max was %f; the calculated max was %f\n", realMaxWithMask, max);
+    if (max == realMaxWithMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
 
     printFooter(stdout,
-                "psHash functions",
-                "psHashAlloc()",
+                "psVector functions",
+                "PS_STAT_MAX: with vector mask",
                 testStatus);
 
-    return (!testStatus);
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "psStats(): deallocating memory");
+
+    psStatsFree(myStats);
+    psVectorFree(myVector);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
 }
Index: /trunk/psLib/test/dataManip/tst_psStats02.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats02.c	(revision 886)
+++ /trunk/psLib/test/dataManip/tst_psStats02.c	(revision 887)
@@ -1,5 +1,5 @@
 /*****************************************************************************
     This routine must ensure that PS_STAT_MIN is correctly computed
-    by the procedure psArrayStats().
+    by the procedure psVectorStats().
  *****************************************************************************/
 #include <stdio.h>
@@ -11,65 +11,115 @@
 {
     psStats *myStats    = NULL;
-    psStats *myStats2   = NULL;
     int testStatus      = true;
+    int globalTestStatus = true;
     int i               = 0;
     psVector *myVector  = NULL;
     psVector *maskVector= NULL;
     float min           = 1e99;
-    float realMin1      = 1e99;
-    float realMin2      = 1e99;
+    float realMinNoMask   = 1e99;
+    float realMinWithMask = 1e99;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
 
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_MIN");
-
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
     myStats = psStatsAlloc(PS_STAT_MIN);
-    myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
     myVector->n = N;
-    maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
     maskVector->n = N;
 
+    // Set the appropriate values for the vector data.
     for (i=0;i<N;i++) {
-        myVector->vec.f[i] = (float) i;
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // Set the mask vector and calculate the expected minimum.
+    for (i=0;i<N;i++) {
+        if (myVector->data.F32[i] < realMinNoMask) {
+            realMinNoMask = myVector->data.F32[i];
+        }
+
         if (i < (N/2)) {
-            maskVector->vec.ui8[i] = 0;
-            if (myVector->vec.f[i] < realMin2) {
-                realMin2 = myVector->vec.f[i];
-            }
+            maskVector->data.U8[i] = 1;
         } else {
-            printf("Masking element %d\n", i);
-            maskVector->vec.ui8[i] = 1;
-            if (myVector->vec.f[i] < realMin1) {
-                realMin1 = myVector->vec.f[i];
+            maskVector->data.U8[i] = 0;
+            if (myVector->data.F32[i] < realMinWithMask) {
+                realMinWithMask = myVector->data.F32[i];
             }
         }
     }
 
-    myStats2 = psArrayStats(myVector, NULL, 0, myStats);
-    min = myStats2->min;
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_MIN: no vector mask");
 
-    printf("Called psArrayStats() on a vector with no elements masked.\n");
-    printf("The expected min was %f; the calculated min was %f\n", realMin1, min);
-    if (min == realMin1) {
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+    min = myStats->min;
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+    printf("The expected min was %f; the calculated min was %f\n",
+           realMinNoMask, min);
+    if (min == realMinNoMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_MIN: no vector mask",
+                testStatus);
 
-    myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
-    min = myStats2->min;
-    printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
-    printf("The expected min was %f; the calculated min was %f\n", realMin2, min);
-    if (min == realMin2) {
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_MIN: with vector mask");
+
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+    min = myStats->min;
+    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
+    printf("The expected min was %f; the calculated min was %f\n",
+           realMinWithMask, min);
+    if (min == realMinWithMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
 
     printFooter(stdout,
-                "psHash functions",
-                "psHashAlloc()",
+                "psVector functions",
+                "PS_STAT_MIN: with vector mask",
                 testStatus);
 
-    return (!testStatus);
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "psStats(): deallocating memory");
+
+    psStatsFree(myStats);
+    psVectorFree(myVector);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
 }
Index: /trunk/psLib/test/dataManip/tst_psStats03.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats03.c	(revision 886)
+++ /trunk/psLib/test/dataManip/tst_psStats03.c	(revision 887)
@@ -1,10 +1,10 @@
 /*****************************************************************************
     This routine must ensure that PS_STAT_SAMPLE_MEDIAN is correctly computed
-    by the procedure psArrayStats().
+    by the procedure psVectorStats().
  *****************************************************************************/
 #include <stdio.h>
 #include "pslib.h"
 #include "psTest.h"
-#define N1 1029
+#define N1 1029   // This should be an odd number.
 #define N ((4 * N1) + 1)
 
@@ -12,66 +12,109 @@
 {
     psStats *myStats    = NULL;
-    psStats *myStats2   = NULL;
     int testStatus      = true;
+    int globalTestStatus = true;
     int i               = 0;
     psVector *myVector  = NULL;
     psVector *maskVector= NULL;
     float median        = 1e99;
-    float realMedian1   = 1e99;
-    float realMedian2   = 1e99;
+    float realMedianWithMask = (float) (N-3)/4;
+    float realMedianNoMask = (float) (N-1)/2;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
 
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_SAMPLE_MEDIAN");
-
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
     myStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
-    myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
     myVector->n = N;
-    maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
     maskVector->n = N;
 
+    // Set the appropriate values for the vector data.
     for (i=0;i<N;i++) {
-        myVector->vec.f[i] = (float) i;
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // Set the mask vector and calculate the expected median.
+    for (i=0;i<N;i++) {
         if (i < (N/2)) {
-            maskVector->vec.ui8[i] = 0;
-            if (myVector->vec.f[i] < realMedian2) {
-                realMedian2 = myVector->vec.f[i];
-            }
+            maskVector->data.U8[i] = 0;
         } else {
-            maskVector->vec.ui8[i] = 1;
-            if (myVector->vec.f[i] < realMedian1) {
-                realMedian1 = myVector->vec.f[i];
-            }
+            maskVector->data.U8[i] = 1;
         }
     }
 
-    myStats2 = psArrayStats(myVector, NULL, 0, myStats);
-    median = myStats2->sampleMedian;
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_MEDIAN: no vector mask");
 
-    printf("Called psArrayStats() on a vector with no elements masked.\n");
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+    median = myStats->sampleMedian;
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
     printf("The expected median was %f.  The calculated median was %f.\n",
-           (float) (N-1)/2, median);
-    if (median == (float) (N-1)/2) {
+           realMedianNoMask, median);
+    if (median == realMedianNoMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
 
-    myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
-    median = myStats2->sampleMedian;
-    printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
+    printFooter(stdout,
+                "psStats functions",
+                "PS_STAT_SAMPLE_MEDIAN: no vector mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_MEDIAN: with vector mask");
+
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+    median = myStats->sampleMedian;
+    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
     printf("The expected median was %f.  The calculated median was %f.\n",
-           (float) (N-3)/4, median);
-    if (median == (float) (N-3)/4) {
+           realMedianWithMask, median);
+    if (median == realMedianWithMask) {
         testStatus = true;
     } else {
         testStatus = false;
+        globalTestStatus = false;
     }
 
     printFooter(stdout,
-                "psHash functions",
-                "psHashAlloc()",
+                "psStats functions",
+                "PS_STAT_SAMPLE_MEDIAN: with vector mask",
                 testStatus);
 
-    return (!testStatus);
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "psStats(): deallocating memory");
+
+    psStatsFree(myStats);
+    psVectorFree(myVector);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psStats functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
 }
Index: /trunk/psLib/test/dataManip/tst_psStats04.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats04.c	(revision 886)
+++ /trunk/psLib/test/dataManip/tst_psStats04.c	(revision 887)
@@ -1,5 +1,8 @@
 /*****************************************************************************
     This routine must ensure that PS_STAT_NVALUES is correctly computed
-    by the procedure psArrayStats().
+    by the procedure psVectorStats().
+ 
+    Note: The NVALUES stat was removed from the IfA requirements spec.  So,
+    this test is no longer in use.
  *****************************************************************************/
 #include <stdio.h>
@@ -12,5 +15,4 @@
 {
     psStats *myStats    = NULL;
-    psStats *myStats2   = NULL;
     int testStatus      = true;
     int i               = 0;
@@ -18,29 +20,40 @@
     psVector *maskVector= NULL;
 
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    myStats = psStatsAlloc(PS_STAT_NVALUES);
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
+    myVector->n = N;
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
+    maskVector->n = N;
+
+    // Set the appropriate values for the vector data.
+    for (i=0;i<N;i++) {
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // Set the mask vector and calculate the expected maximum.
+    for (i=0;i<N;i++) {
+        if (i < (N/2)) {
+            maskVector->data.U8[i] = 0;
+        } else {
+            maskVector->data.U8[i] = 1;
+        }
+    }
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
     printPositiveTestHeader(stdout,
                             "psStats functions",
                             "PS_STAT_NVALUES");
 
-    myStats = psStatsAlloc(PS_STAT_NVALUES);
-    myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
-    myVector->n = N;
-    maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
-    maskVector->n = N;
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
 
-    for (i=0;i<N;i++) {
-        myVector->vec.f[i] = (float) i;
-        if (i < (N/2)) {
-            maskVector->vec.ui8[i] = 0;
-        } else {
-            maskVector->vec.ui8[i] = 1;
-        }
-    }
-
-    myStats2 = psArrayStats(myVector, NULL, 0, myStats);
-
-    printf("Called psArrayStats() on a vector with no elements masked.\n");
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
     printf("The expected nvalues was %d.  The calculated nvalues was %d.\n",
-           N, myStats2->nValues);
-    if (myStats2->nValues == N) {
+           N, myStats->nValues);
+    if (myStats->nValues == N) {
         testStatus = true;
     } else {
@@ -48,9 +61,12 @@
     }
 
-    myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
-    printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
     printf("The expected nvalues was %d.  The calculated nvalues was %d.\n",
-           N/2, myStats2->nValues);
-    if (myStats2->nValues == N/2) {
+           N/2, myStats->nValues);
+    if (myStats->nValues == N/2) {
         testStatus = true;
     } else {
Index: /trunk/psLib/test/dataManip/tst_psStats05.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats05.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psStats05.c	(revision 887)
@@ -0,0 +1,76 @@
+/*****************************************************************************
+    This routine must ensure that the psStats structure is correctly
+    allocated and deallocated by the procedure psArrayStats().
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#define MISC_FLOAT_NUMBER 345.0
+
+int main()
+{
+    psStats *myStats    = NULL;
+    int testStatus      = true;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Allocate the psStats structure.");
+
+    myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+    myStats->sampleMean = MISC_FLOAT_NUMBER;
+    myStats->sampleMedian = MISC_FLOAT_NUMBER;
+    myStats->sampleStdev = MISC_FLOAT_NUMBER;
+    myStats->sampleUQ = MISC_FLOAT_NUMBER;
+    myStats->sampleLQ = MISC_FLOAT_NUMBER;
+    myStats->sampleLimit = MISC_FLOAT_NUMBER;
+    myStats->robustMean = MISC_FLOAT_NUMBER;
+    myStats->robustMedian = MISC_FLOAT_NUMBER;
+    myStats->robustMode = MISC_FLOAT_NUMBER;
+    myStats->robustStdev = MISC_FLOAT_NUMBER;
+    myStats->robustUQ = MISC_FLOAT_NUMBER;
+    myStats->robustLQ = MISC_FLOAT_NUMBER;
+    myStats->robustN50 = MISC_FLOAT_NUMBER;
+    myStats->robustNfit = MISC_FLOAT_NUMBER;
+    myStats->clippedMean = MISC_FLOAT_NUMBER;
+    myStats->clippedStdev = MISC_FLOAT_NUMBER;
+    myStats->clipSigma = MISC_FLOAT_NUMBER;
+    myStats->clipIter = MISC_FLOAT_NUMBER;
+    myStats->min = MISC_FLOAT_NUMBER;
+    myStats->max = MISC_FLOAT_NUMBER;
+    myStats->binsize = MISC_FLOAT_NUMBER;
+    myStats->options = 0x0;
+
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Allocate the psStats structure.",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "Deallocate the psStats structure.");
+    psStatsFree(myStats);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psStats functions",
+                "Deallocate the psStats structure.",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psStats06.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats06.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psStats06.c	(revision 887)
@@ -0,0 +1,128 @@
+/*****************************************************************************
+    This routine must ensure that PS_STAT_SAMPLE_STDEV is correctly computed
+    by the procedure psArrayStats().
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psTest.h"
+#include "float.h"
+#include <math.h>
+
+#define N 15
+
+int main()
+{
+    psStats *myStats    = NULL;
+    int testStatus      = true;
+    int globalTestStatus = true;
+    int i               = 0;
+    psVector *myVector  = NULL;
+    psVector *maskVector= NULL;
+    float stdev         = 0.0;
+    // 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 realStdevNoMask   = 4.472136;
+    float realStdevWithMask = 2.160247;
+    int count           = 0;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    myStats = psStatsAlloc(PS_STAT_SAMPLE_STDEV);
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
+    myVector->n = N;
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
+    maskVector->n = N;
+
+    stdev = 0.0;
+    // Set the appropriate values for the vector data.
+    for (i=0;i<N;i++) {
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // 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_SAMPLE_STDEV: no vector mask");
+
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+    stdev = myStats->sampleStdev;
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+    printf("The expected stdev was %f; the calculated stdev was %f\n",
+           realStdevNoMask, stdev);
+    if (fabs(stdev - realStdevNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_SAMPLE_STDEV: no vector mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_STDEV: with vector mask");
+
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+    stdev = myStats->sampleStdev;
+    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
+    printf("The expected stdev was %f; the calculated stdev was %f\n",
+           realStdevWithMask, stdev);
+    if (fabs(stdev - realStdevWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_SAMPLE_STDEV: with vector mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "psStats(): deallocating memory");
+
+    psStatsFree(myStats);
+    psVectorFree(myVector);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psStats07.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats07.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psStats07.c	(revision 887)
@@ -0,0 +1,413 @@
+/*****************************************************************************
+    This routine must ensure that PS_STAT_ROBUST_QUARTILE is correctly computed
+    by the procedure psArrayStats().
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psTest.h"
+#include "float.h"
+#include <math.h>
+
+#define N 15
+
+int main()
+{
+    psStats *myStats    = NULL;
+    int testStatus      = true;
+    int globalTestStatus = true;
+    int i               = 0;
+    psVector *myVector  = NULL;
+    psVector *maskVector= 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 realMeanNoMask   = 0.0;
+    float realMedianNoMask = 0.0;
+    float realModeNoMask   = 0.0;
+    float realStdevNoMask  = 0.0;
+    float realLQNoMask     = 0.0;
+    float realUQNoMask     = 0.0;
+    float realN50NoMask    = 0.0;
+    float realNfitNoMask   = 0.0;
+    float realMeanWithMask   = 0.0;
+    float realMedianWithMask = 0.0;
+    float realModeWithMask   = 0.0;
+    float realStdevWithMask  = 0.0;
+    float realLQWithMask     = 0.0;
+    float realUQWithMask     = 0.0;
+    float realN50WithMask    = 0.0;
+    float realNfitWithMask   = 0.0;
+    int count           = 0;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    myStats = psStatsAlloc(PS_STAT_ROBUST_MEAN |
+                           PS_STAT_ROBUST_MEDIAN |
+                           PS_STAT_ROBUST_MODE |
+                           PS_STAT_ROBUST_STDEV |
+                           PS_STAT_ROBUST_QUARTILE);
+
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
+    myVector->n = N;
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
+    maskVector->n = N;
+
+    // Set the appropriate values for the vector data.
+    for (i=0;i<N;i++) {
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // 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_ROBUST_STATS: robust mean: no vector mask");
+
+    printf("Calling psVectorStats() on a vector with no elements masked.\n");
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+
+    printf("The expected Mean was %f; the calculated Mean was %f\n",
+           realMeanNoMask, myStats->robustMean);
+    if (fabs(myStats->robustMean - realMeanNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust mean: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Median: no vector mask");
+
+    printf("The expected Median was %f; the calculated Median was %f\n",
+           realMedianNoMask, myStats->robustMedian);
+    if (fabs(myStats->robustMedian - realMedianNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Median: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Mode: no vector mask");
+
+    printf("The expected Mode was %f; the calculated Mode was %f\n",
+           realModeNoMask, myStats->robustMode);
+    if (fabs(myStats->robustMode - realModeNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Mode: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Stdev: no vector mask");
+
+    printf("The expected Stdev was %f; the calculated Stdev was %f\n",
+           realStdevNoMask, myStats->robustStdev);
+    if (fabs(myStats->robustStdev - realStdevNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Stdev: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: lower quartile: no vector mask");
+
+    printf("The expected LQ was %f; the calculated LQ was %f\n",
+           realLQNoMask, myStats->robustLQ);
+    if (fabs(myStats->robustLQ - realLQNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: lower quartile: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: upper quartile: no vector mask");
+
+    printf("The expected UQ was %f; the calculated UQ was %f\n",
+           realUQNoMask, myStats->robustUQ);
+    if (fabs(myStats->robustUQ - realUQNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: lower quartile: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust N50: no vector mask");
+
+    printf("The expected N50 was %f; the calculated N50 was %f\n",
+           realN50NoMask, myStats->robustN50);
+    if (fabs(myStats->robustN50 - realN50NoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust N50: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Nfit: no vector mask");
+
+    printf("The expected Nfit was %f; the calculated Nfit was %f\n",
+           realNfitNoMask, myStats->robustNfit);
+    if (fabs(myStats->robustNfit - realNfitNoMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Nfit: no vector mask",
+                testStatus);
+
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust mean: with vector mask");
+
+    printf("Calling psVectorStats() on a vector with elements masked.\n");
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+    printf("Called psVectorStats() on a vector with elements masked.\n");
+    printf("The expected Mean was %f; the calculated Mean was %f\n",
+           realMeanWithMask, myStats->robustMean);
+    if (fabs(myStats->robustMean - realMeanWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust mean: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Median: with vector mask");
+
+    printf("The expected Median was %f; the calculated Median was %f\n",
+           realMedianWithMask, myStats->robustMedian);
+    if (fabs(myStats->robustMedian - realMedianWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Median: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Mode: with vector mask");
+
+    printf("The expected Mode was %f; the calculated Mode was %f\n",
+           realModeWithMask, myStats->robustMode);
+    if (fabs(myStats->robustMode - realModeWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Mode: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Stdev: with vector mask");
+
+    printf("The expected Stdev was %f; the calculated Stdev was %f\n",
+           realStdevWithMask, myStats->robustStdev);
+    if (fabs(myStats->robustStdev - realStdevWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Stdev: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: lower quartile: with vector mask");
+
+    printf("The expected LQ was %f; the calculated LQ was %f\n",
+           realLQWithMask, myStats->robustLQ);
+    if (fabs(myStats->robustLQ - realLQWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: lower quartile: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: upper quartile: with vector mask");
+
+    printf("The expected UQ was %f; the calculated UQ was %f\n",
+           realUQWithMask, myStats->robustUQ);
+    if (fabs(myStats->robustUQ - realUQWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: lower quartile: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust N50: with vector mask");
+
+    printf("The expected N50 was %f; the calculated N50 was %f\n",
+           realN50WithMask, myStats->robustN50);
+    if (fabs(myStats->robustN50 - realN50WithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust N50: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_ROBUST_STATS: robust Nfit: with vector mask");
+
+    printf("The expected Nfit was %f; the calculated Nfit was %f\n",
+           realNfitWithMask, myStats->robustNfit);
+    if (fabs(myStats->robustNfit - realNfitWithMask) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_ROBUST_STATS: robust Nfit: with vector mask",
+                testStatus);
+
+
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "psStats(): deallocating memory");
+
+    psStatsFree(myStats);
+    psVectorFree(myVector);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psStats08.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats08.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psStats08.c	(revision 887)
@@ -0,0 +1,172 @@
+/*****************************************************************************
+    This routine must ensure that PS_STAT_SAMPLE_QUARTILE is correctly computed
+    by the procedure psArrayStats().
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psTest.h"
+#include "float.h"
+#include <math.h>
+
+#define N1 25  //
+#define N (8 * N1) // Don't change this (N must be a multiple of 8)
+
+int main()
+{
+    psStats *myStats    = NULL;
+    int testStatus      = true;
+    int globalTestStatus = true;
+    int i               = 0;
+    psVector *myVector  = NULL;
+    psVector *maskVector= 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 realLQNoMask   = N/4.0;
+    float realUQNoMask   = 3.0 * (N/4.0);
+    float realLQWithMask   = N/8.0;
+    float realUQWithMask   = 3.0 * (N/8.0);
+    int count           = 0;
+    int currentId       = psMemGetId();
+    int memLeaks        = 0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    myStats = psStatsAlloc(PS_STAT_SAMPLE_QUARTILE);
+    myVector = psVectorAlloc(N, PS_TYPE_F32);
+    myVector->n = N;
+    maskVector = psVectorAlloc(N, PS_TYPE_U8);
+    maskVector->n = N;
+
+    // Set the appropriate values for the vector data.
+    for (i=0;i<N;i++) {
+        myVector->data.F32[i] = (float) i;
+    }
+
+    // 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_SAMPLE_LQ: no vector mask");
+
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+    printf("The expected sampleLQ was %f; the calculated sampleLQ was %f\n",
+           realLQNoMask, myStats->sampleLQ);
+    if (fabs(realLQNoMask - myStats->sampleLQ) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_SAMPLE_LQ: no vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_UQ: no vector mask");
+
+    myStats = psVectorStats(myStats, myVector, NULL, 0);
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+    printf("The expected sampleUQ was %f; the calculated sampleUQ was %f\n",
+           realUQNoMask, myStats->sampleUQ);
+    if (fabs(realUQNoMask - myStats->sampleUQ) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_SAMPLE_UQ: no vector mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with vector mask.                       */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_LQ: with vector mask");
+
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+
+    printf("Called psVectorStats() on a vector with elements masked.\n");
+    printf("The expected sampleLQ was %f; the calculated sampleLQ was %f\n",
+           realLQWithMask, myStats->sampleLQ);
+    if (fabs(realLQWithMask - myStats->sampleLQ) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_SAMPLE_LQ: with vector mask",
+                testStatus);
+
+
+
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "PS_STAT_SAMPLE_UQ: with vector mask");
+
+    myStats = psVectorStats(myStats, myVector, maskVector, 1);
+
+    printf("Called psVectorStats() on a vector with elements masked.\n");
+    printf("The expected sampleUQ was %f; the calculated sampleUQ was %f\n",
+           realUQWithMask, myStats->sampleUQ);
+    if (fabs(realUQWithMask - myStats->sampleUQ) <= 2.0 * FLT_EPSILON) {
+        testStatus = true;
+    } else {
+        testStatus = false;
+        globalTestStatus = false;
+    }
+    printFooter(stdout,
+                "psVector functions",
+                "PS_STAT_SAMPLE_UQ: with vector mask",
+                testStatus);
+
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psStats functions",
+                            "psStats(): deallocating memory");
+
+    psStatsFree(myStats);
+    psVectorFree(myVector);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
+}
Index: /trunk/psLib/test/dataManip/tst_psStats09.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats09.c	(revision 887)
+++ /trunk/psLib/test/dataManip/tst_psStats09.c	(revision 887)
@@ -0,0 +1,146 @@
+/*****************************************************************************
+    This routine must ensure that PS_STAT_CLIPPED_MEAN and
+    PS_STAT_CLIPPED_STDEV is calculate correctly by the procedure
+    psVectorStats().
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psTest.h"
+#include "psImageStats.h"
+#include "float.h"
+#include <math.h>
+
+#define N 500
+#define MY_MEAN  30.0
+#define MY_RANGE 2.0
+
+int main()
+{
+    psStats *myStats    = NULL;
+    int testStatus      = true;
+    int globalTestStatus = true;
+    int 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;
+    int count           = 0;
+    int currentId       = psMemGetId();
+    int 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, 0);
+
+    printf("Called psVectorStats() on a vector with no elements masked.\n");
+    printf("The calculated clippedMean was %f\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 %f\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, maskVector, 1);
+
+    printf("Called psVectorStats() on a vector with elements masked.\n");
+    printf("The calculated clippedMean was %f\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 %f\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");
+
+    psStatsFree(myStats);
+    psVectorFree(myGaussData);
+    psVectorFree(maskVector);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psVector functions",
+                "psStats(): deallocating memory",
+                testStatus);
+
+    return (!globalTestStatus);
+}
Index: /trunk/psLib/test/image/tst_psImageStats00.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageStats00.c	(revision 887)
+++ /trunk/psLib/test/image/tst_psImageStats00.c	(revision 887)
@@ -0,0 +1,113 @@
+/*****************************************************************************
+    This routine must ensure that the psHistogram structure is correctly
+    allocated and populated by the psImageHistogram() function.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psImage.h"
+#include "psImageStats.h"
+#define NUM_BINS 20
+#define IMAGE_SIZE 20
+
+int main()
+{
+    psHistogram *myHist = NULL;
+    psImage *tmpImage   = NULL;
+    psImage *tmpMask    = NULL;
+    int testStatus      = true;
+    int memLeaks        = 0;
+    int i               = 0;
+    int j               = 0;
+    int currentId       = 0;
+
+    currentId       = psMemGetId();
+    /*************************************************************************/
+    /*  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] = (float) (i + j);
+        }
+    }
+    tmpMask = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_U8);
+    for (i=0;i<IMAGE_SIZE;i++) {
+        for (j=0;j<IMAGE_SIZE;j++) {
+            if ((i > (IMAGE_SIZE/2)) &&
+                    (j > (IMAGE_SIZE/2))) {
+                tmpMask->data.U8[i][j] = 1;
+            } else {
+                tmpMask->data.U8[i][j] = 0;
+            }
+        }
+    }
+    /*************************************************************************/
+    /*  Calculate Histogram with no mask                             */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Calculate Histogram, no mask");
+
+    myHist = psHistogramAlloc(0.0, (float) (2 * IMAGE_SIZE), NUM_BINS);
+    myHist = psImageHistogram(myHist, tmpImage, NULL, 0);
+    for (i=0;i<NUM_BINS;i++) {
+        printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
+               myHist->bounds->data.F32[i],
+               myHist->bounds->data.F32[i+1],
+               myHist->nums->data.S32[i]);
+    }
+    psHistogramFree(myHist);
+
+    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psImageStats functions",
+                "Calculate Histogram, no mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Calculate Histogram with mask                                */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Calculate Histogram with mask");
+
+    myHist = psHistogramAlloc(0.0, (float) (2 * IMAGE_SIZE), NUM_BINS);
+    myHist = psImageHistogram(myHist, tmpImage, tmpMask, 1);
+    for (i=0;i<NUM_BINS;i++) {
+        printf("Bin number %d bounds: (%f - %f) data (%d)\n", i,
+               myHist->bounds->data.F32[i],
+               myHist->bounds->data.F32[i+1],
+               myHist->nums->data.S32[i]);
+    }
+
+    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psImageStats functions",
+                "Calculate Histogram with mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Deallocate the psHistogram/psImage structure.");
+    psHistogramFree(myHist);
+    psImageFree(tmpImage);
+    psImageFree(tmpMask);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psImageStats functions",
+                "Deallocate the psHistogram/psImage structure.",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/image/tst_psImageStats01.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageStats01.c	(revision 887)
+++ /trunk/psLib/test/image/tst_psImageStats01.c	(revision 887)
@@ -0,0 +1,106 @@
+/*****************************************************************************
+    This routine must ensure that the psImageStats() routine can correctly
+    call the psVectorStats() routine.  Since the psVectorStats() will be
+    thouroughly tested elsewhere, we will only test psImageStats() with
+    the PS_STAT_SAMPLE_MEAN here.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psImage.h"
+#include "psImageStats.h"
+#define NUM_BINS 20
+#define IMAGE_SIZE 512
+
+int main()
+{
+    psStats *myStats    = NULL;
+    psImage *tmpImage   = NULL;
+    psImage *tmpMask    = NULL;
+    int testStatus      = true;
+    int memLeaks        = 0;
+    int i               = 0;
+    int j               = 0;
+    int currentId       = 0;
+
+    currentId       = psMemGetId();
+    /*************************************************************************/
+    /*  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] = (float) (i + j);
+        }
+    }
+    tmpMask = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_U8);
+    for (i=0;i<IMAGE_SIZE;i++) {
+        for (j=0;j<IMAGE_SIZE;j++) {
+            if ((i > (IMAGE_SIZE/2)) &&
+                    (j > (IMAGE_SIZE/2))) {
+                tmpMask->data.U8[i][j] = 1;
+            } else {
+                tmpMask->data.U8[i][j] = 0;
+            }
+        }
+    }
+
+    myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+    /*************************************************************************/
+    /*  Calculate Sample Mean with no mask                           */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Calculate Sample Mean, no mask");
+
+    myStats = psImageStats(myStats, tmpImage, NULL, 0);
+    printf("The sample mean was %f\n", myStats->sampleMean);
+
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psImageStats functions",
+                "Calculate Sample Mean, no mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Calculate Sample Mean with mask                              */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Calculate Sample Mean with mask");
+
+    myStats = psImageStats(myStats, tmpImage, tmpMask, 1);
+    printf("The sample mean was %f\n", myStats->sampleMean);
+
+    psMemCheckCorruption(1);
+
+    printFooter(stdout,
+                "psImageStats functions",
+                "Calculate Sample Mean with mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Deallocate the psStats/psImage structure.");
+    psStatsFree(myStats);
+    psImageFree(tmpImage);
+    psImageFree(tmpMask);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psImageStats functions",
+                "Deallocate the psStats/psImage structure.",
+                testStatus);
+
+    return (!testStatus);
+}
Index: /trunk/psLib/test/image/tst_psImageStats02.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageStats02.c	(revision 887)
+++ /trunk/psLib/test/image/tst_psImageStats02.c	(revision 887)
@@ -0,0 +1,108 @@
+/*****************************************************************************
+    This routine must ensure that the psImageStats() routine can correctly
+    call the psVectorStats() routine.  Since the psVectorStats() will be
+    thouroughly tested elsewhere, we will only test psImageStats() with
+    the PS_STAT_SAMPLE_MEAN here.
+ *****************************************************************************/
+#include <stdio.h>
+#include "pslib.h"
+#include "psTest.h"
+#include "psMemory.h"
+#include "psImage.h"
+#include "psImageStats.h"
+#define NUM_BINS 20
+#define IMAGE_SIZE 10
+#define CHEBY_X_DIM 5
+#define CHEBY_Y_DIM 3
+
+int main()
+{
+    psStats *myStats    = NULL;
+    psImage *tmpImage   = NULL;
+    psImage *outImage   = NULL;
+    psPolynomial2D *my2DPoly = NULL;
+    int testStatus      = true;
+    int memLeaks        = 0;
+    int i               = 0;
+    int j               = 0;
+    int rc              = 0;
+    int 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] = (float) (i + j);
+            outImage->data.F32[i][j] = 0.0;
+        }
+    }
+    for (i=0;i<IMAGE_SIZE;i++) {
+        for (j=0;j<IMAGE_SIZE;j++) {
+            printf("(%f, %f)\n", tmpImage->data.F32[i][j],
+                   outImage->data.F32[i][j]);
+        }
+    }
+    my2DPoly = psPolynomial2DAlloc(CHEBY_X_DIM, CHEBY_Y_DIM);
+    /*************************************************************************/
+    /*  Calculate Chebyshev Polynomials, no mask                     */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Calculate Chebyshev Polynomials, no mask");
+
+    my2DPoly = psImageFitPolynomial(tmpImage, my2DPoly);
+
+    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psImageStats functions",
+                "Calculate Chebyshev Polynomials, no mask",
+                testStatus);
+    /*************************************************************************/
+    /*  Evaluate Chebyshev Polynomials, no mask                      */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Calculate Chebyshev Polynomials, no mask");
+
+    rc = psImageEvalPolynomial(outImage, my2DPoly);
+    for (i=0;i<IMAGE_SIZE;i++) {
+        for (j=0;j<IMAGE_SIZE;j++) {
+            printf("(%f, %f)\n", tmpImage->data.F32[i][j],
+                   outImage->data.F32[i][j]);
+        }
+    }
+
+    psMemCheckCorruption(1);
+    printFooter(stdout,
+                "psImageStats functions",
+                "Calculate Chebyshev Polynomials, no mask",
+                testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                   */
+    /*************************************************************************/
+    printPositiveTestHeader(stdout,
+                            "psImageStats functions",
+                            "Deallocate the psStats/psImage structure.");
+    psStatsFree(myStats);
+    psImageFree(tmpImage);
+    psImageFree(outImage);
+    psPolynomial2DFree(my2DPoly);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psImageStats functions",
+                "Deallocate the psStats/psImage structure.",
+                testStatus);
+
+    return (!testStatus);
+}
