Index: /trunk/psLib/test/math/tst_psStats00.c
===================================================================
--- /trunk/psLib/test/math/tst_psStats00.c	(revision 7130)
+++ /trunk/psLib/test/math/tst_psStats00.c	(revision 7131)
@@ -3,5 +3,5 @@
 *  @brief Contains tests for psVectorStats with sample mean calculations
 *
-*  We extensively test the code with data type PS_TYPE_F32.  If these pass, we 
+*  We extensively test the code with data type PS_TYPE_F32.  If these pass, we
 *  do a much simpler test with data type PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_F64.
 *
@@ -10,7 +10,7 @@
 *
 *  @author GLG, MHPCC
-* 
-*  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
-*  @date $Date: 2006-02-03 01:34:11 $
+*
+*  @version $Revision: 1.7 $  $Name: not supported by cvs2svn $
+*  @date $Date: 2006-05-18 01:20:10 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
@@ -85,24 +85,18 @@
 psS32 testStatsSampleMeanF32(void)
 {
-    psStats*  myStats    = NULL;
-    psVector* myVector   = NULL;
-    psVector* maskVector = NULL;
-    psVector* myErrors   = NULL;
-    psF64     mean       = 0.0;
-
     /*************************************************************************/
     /*  Allocate and initialize data structures                      */
     /*************************************************************************/
-    myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
-    myVector = psVectorAlloc(N, PS_TYPE_F32);
+    psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+    psVector *myVector = psVectorAlloc(N, PS_TYPE_F32);
     myVector->n = N;
-    myErrors = psVectorAlloc(N, PS_TYPE_F32);
+    psVector *myErrors = psVectorAlloc(N, PS_TYPE_F32);
     myErrors->n = N;
-    maskVector = psVectorAlloc(N, PS_TYPE_U8);
+    psVector *maskVector = psVectorAlloc(N, PS_TYPE_U8);
     maskVector->n = N;
 
-    mean = 0.0;
+    psF64 mean = 0.0;
     // Set the appropriate values for the vector data.
-    for (psS32 i = 0; i < N; i++) {
+    for (long i = 0; i < N; i++) {
         myVector->data.F32[i] =  samplesF32[i];
         myErrors->data.F32[i] =  errorsF32[i];
Index: /trunk/psLib/test/math/tst_psStats09.c
===================================================================
--- /trunk/psLib/test/math/tst_psStats09.c	(revision 7130)
+++ /trunk/psLib/test/math/tst_psStats09.c	(revision 7131)
@@ -14,8 +14,8 @@
 
 #define NUM_DATA 1000
-#define VERBOSE 0
+#define VERBOSE 1
 #define PERCENT_OUTLIERS 2
 #define ERROR_TOLERANCE .10
-#define ERRORS 1000.0
+#define ERRORS 1.0
 #define SEED 1995
 
@@ -52,4 +52,12 @@
     printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine");
 
+    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
+    psVector *truth = psVectorAlloc(numData, PS_TYPE_F64);
+    truth->n = numData;
+    for (long i = 0; i < numData; i++) {
+        truth->data.F64[i] = psRandomGaussian(rng);
+    }
+    psFree(rng);
+
     if (expectedRC == true) {
         printf("This test should not generate any errors.\n");
@@ -65,10 +73,5 @@
     if (flags & TST_IN_F32) {
         printf("        using a psF32 in vector\n");
-        in = psVectorAlloc(numData, PS_TYPE_F32);
-        for (psS32 i=0;i<numData;i++) {
-            in->data.F32[i] = (psF32) i;
-            in->n++;
-        }
-
+        in = psVectorCopy(in, truth, PS_TYPE_F32);
         if (VERBOSE) {
             for (psS32 i=0;i<numData;i++) {
@@ -80,9 +83,5 @@
     if (flags & TST_IN_F64) {
         printf("        using a psF64 in vector\n");
-        in = psVectorAlloc(numData, PS_TYPE_F64);
-        for (psS32 i=0;i<numData;i++) {
-            in->data.F64[i] = (psF64) i;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_F64);
 
         if (VERBOSE) {
@@ -95,9 +94,5 @@
     if (flags & TST_IN_S8) {
         printf("        using a psS8 in vector\n");
-        in = psVectorAlloc(numData, PS_TYPE_S8);
-        for (psS32 i=0;i<numData;i++) {
-            in->data.S8[i] = (psS8) i;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_S8);
 
         if (VERBOSE) {
@@ -110,9 +105,5 @@
     if (flags & TST_IN_U16) {
         printf("        using a psU16 in vector\n");
-        in = psVectorAlloc(numData, PS_TYPE_U16);
-        for (psS32 i=0;i<numData;i++) {
-            in->data.U16[i] = (psU16) i;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_U16);
 
         if (VERBOSE) {
@@ -125,9 +116,5 @@
     if (flags & TST_IN_S32) {
         printf("        using a psS32 in vector\n");
-        in = psVectorAlloc(numData, PS_TYPE_S32);
-        for (psS32 i=0;i<numData;i++) {
-            in->data.S32[i] = (psS32) i;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_S32);
 
         if (VERBOSE) {
@@ -252,4 +239,81 @@
     }
 
+
+    //
+    // We add a few outliers to the input data.
+    //
+    psVector *outliers = psVectorAlloc(numData, PS_TYPE_U8);
+    outliers->n = numData;
+    psVectorInit(outliers, 0);
+    if (flags & TST_IN_F32) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.F32[i] = 100.0;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]);
+            }
+        }
+    }
+    if (flags & TST_IN_F64) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.F64[i] = 100.0;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]);
+            }
+        }
+    }
+    if (flags & TST_IN_S8) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.S8[i] = 100;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.S8[i]);
+            }
+        }
+    }
+    if (flags & TST_IN_U16) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.U16[i] = 100;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.U16[i]);
+            }
+        }
+    }
+    if (flags & TST_IN_S32) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.S32[i] = 100;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.S32[i]);
+            }
+        }
+    }
 
     //
@@ -261,5 +325,5 @@
     if (expectedRC == true) {
         psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
-        psStats *rc = psVectorStats(myStats, in, NULL, NULL, maskValue);
+        psStats *rc = psVectorStats(myStats, in, errors, outliers, 1);
         if (rc == NULL) {
             printf("TEST ERROR: the psVectorStats() function returned NULL.\n");
@@ -271,73 +335,5 @@
         psFree(myStats);
     }
-
-    //
-    // We add a few outliers to the input data.
-    //
-    if (flags & TST_IN_F32) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.F32[i] = (psF32) (10 * numData);
-            }
-        }
-
-        if (VERBOSE) {
-            for (psS32 i=0;i<numData;i++) {
-                printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]);
-            }
-        }
-    }
-    if (flags & TST_IN_F64) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.F64[i] = (psF64) (10 * numData);
-            }
-        }
-
-        if (VERBOSE) {
-            for (psS32 i=0;i<numData;i++) {
-                printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]);
-            }
-        }
-    }
-    if (flags & TST_IN_S8) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.S8[i] = (psS8) (10 * numData);
-            }
-        }
-
-        if (VERBOSE) {
-            for (psS32 i=0;i<numData;i++) {
-                printf("Original in data %d: (%d)\n", i, in->data.S8[i]);
-            }
-        }
-    }
-    if (flags & TST_IN_U16) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.U16[i] = (psU16) (10 * numData);
-            }
-        }
-
-        if (VERBOSE) {
-            for (psS32 i=0;i<numData;i++) {
-                printf("Original in data %d: (%d)\n", i, in->data.U16[i]);
-            }
-        }
-    }
-    if (flags & TST_IN_S32) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.S32[i] = (psS32) (10 * numData);
-            }
-        }
-
-        if (VERBOSE) {
-            for (psS32 i=0;i<numData;i++) {
-                printf("Original in data %d: (%d)\n", i, in->data.S32[i]);
-            }
-        }
-    }
+    psFree(outliers);
 
     //
@@ -345,4 +341,5 @@
     //
     psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
+    myStats->clipSigma = 5.0;
     psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);
     if (rc == NULL) {
@@ -358,15 +355,15 @@
 
         if (fabs(myStats->clippedMean - sampleMean) > (ERROR_TOLERANCE * sampleMean)) {
-            printf("TEST ERROR: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean);
+            printf("TEST ERROR: the clipped mean was %f, should have been %f\n", myStats->clippedMean, sampleMean);
             testStatus = false;
         } else if (VERBOSE) {
-            printf("GOOD: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean);
+            printf("GOOD: the clipped mean was %f, should have been %f\n", myStats->clippedMean, sampleMean);
         }
 
         if (fabs(myStats->clippedStdev - sampleStdev) > (ERROR_TOLERANCE * sampleStdev)) {
-            printf("TEST ERROR: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);
+            printf("TEST ERROR: the clipped stdev was %f, should have been %f\n", myStats->clippedStdev, sampleStdev);
             testStatus = false;
         } else if (VERBOSE) {
-            printf("GOOD: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);
+            printf("GOOD: the clipped stdev was %f, should have been %f\n", myStats->clippedStdev, sampleStdev);
         }
 
@@ -374,4 +371,5 @@
 
     psFree(myStats);
+    psFree(truth);
     psFree(in);
     psFree(errors);
