Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 20515)
+++ trunk/psLib/src/math/psStats.c	(revision 21183)
@@ -13,6 +13,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.230 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-11-04 00:55:14 $
+ *  @version $Revision: 1.231 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  Copyright 2006 IfA, University of Hawaii
@@ -68,5 +68,6 @@
 #define PS_CLIPPED_SIGMA_UB 10.0
 #define PS_POLY_MEDIAN_MAX_ITERATIONS 30
-#define MASK_MARK 0x80   // bit to use internally to mark data as bad
+
+#define MASK_MARK 0x80   // XXX : can we change this? bit to use internally to mark data as bad
 #define PS_ROBUST_MAX_ITERATIONS 20     // Maximum number of iterations for robust statistics
 
@@ -178,5 +179,5 @@
                                  const psVector* errors,
                                  const psVector* maskVector,
-                                 psMaskType maskVal,
+                                 psVectorMaskType maskVal,
                                  psStats* stats)
 {
@@ -190,5 +191,5 @@
     int numData = myVector->n;          // Number of data points
 
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
 
@@ -245,5 +246,5 @@
     static long vectorMinMax(const psVector* myVector,
                              const psVector* maskVector,
-                             psMaskType maskVal,
+                             psVectorMaskType maskVal,
                              psStats* stats
         )
@@ -257,5 +258,5 @@
     int numValid = 0;                   // Number of valid values
 
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
 
@@ -302,5 +303,5 @@
 static bool vectorSampleMedian(const psVector* inVector,
                                const psVector* maskVector,
-                               psMaskType maskVal,
+                               psVectorMaskType maskVal,
                                psStats* stats)
 {
@@ -308,5 +309,5 @@
 
     bool useRange = stats->options & PS_STAT_USE_RANGE;
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8; // Dereference the vector
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA; // Dereference the vector
     psF32 *input = inVector->data.F32; // Dereference the vector
 
@@ -387,5 +388,5 @@
                               const psVector* errors,
                               const psVector* maskVector,
-                              psMaskType maskVal,
+                              psVectorMaskType maskVal,
                               psStats* stats)
 {
@@ -407,5 +408,5 @@
 
     psF32 *data = myVector->data.F32;   // Dereference
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
     psF32 *errorsData = (errors == NULL) ? NULL : errors->data.F32;
@@ -468,5 +469,5 @@
 static bool vectorSampleMoments(const psVector* myVector,
                                 const psVector* maskVector,
-                                psMaskType maskVal,
+                                psVectorMaskType maskVal,
                                 psStats* stats)
 {
@@ -490,5 +491,5 @@
 
     psF32 *data = myVector->data.F32;   // Dereference
-    psU8 *maskData = (maskVector == NULL) ? NULL : maskVector->data.U8;
+    psVectorMaskType *maskData = (maskVector == NULL) ? NULL : maskVector->data.PS_TYPE_VECTOR_MASK_DATA;
     bool useRange = stats->options & PS_STAT_USE_RANGE;
 
@@ -557,5 +558,5 @@
                                const psVector* errors,
                                psVector* maskInput,
-                               psMaskType maskValInput,
+                               psVectorMaskType maskValInput,
                                psStats* stats
     )
@@ -580,14 +581,14 @@
 
     // We copy the mask vector, to preserve the original
-    psMaskType maskVal = MASK_MARK | maskValInput;
+    psVectorMaskType maskVal = MASK_MARK | maskValInput;
 
     // use the temporary vector for local temporary mask
-    stats->tmpMask = psVectorRecycle (stats->tmpMask, myVector->n, PS_TYPE_U8);
+    stats->tmpMask = psVectorRecycle (stats->tmpMask, myVector->n, PS_TYPE_VECTOR_MASK);
     psVector *tmpMask = stats->tmpMask;
     psVectorInit(tmpMask, 0);
     if (maskInput) {
         for (long i = 0; i < myVector->n; i++) {
-            if (maskInput->data.U8[i] & maskValInput) {
-                tmpMask->data.U8[i] = maskVal;
+            if (maskInput->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValInput) {
+                tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
             }
         }
@@ -629,7 +630,7 @@
             // sqrt(A))
             for (long j = 0; j < myVector->n; j++) {
-                if (!tmpMask->data.U8[j] &&
+                if (!tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] &&
                     fabsf(myVector->data.F32[j] - clippedMean) > stats->clipSigma * errors->data.F32[j]) {
-                    tmpMask->data.U8[j] = 0xff;
+                    tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff;
                     psTrace(TRACE, 10, "Clipped %ld: %f +/- %f\n", j,
                             myVector->data.F32[j], errors->data.F32[j]);
@@ -640,7 +641,7 @@
         } else {
             for (long j = 0; j < myVector->n; j++) {
-                if (!tmpMask->data.U8[j] &&
+                if (!tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] &&
                     fabsf(myVector->data.F32[j] - clippedMean) > (stats->clipSigma * clippedStdev)) {
-                    tmpMask->data.U8[j] = 0xff;
+                    tmpMask->data.PS_TYPE_VECTOR_MASK_DATA[j] = 0xff;
                     psTrace(TRACE, 10, "Clipped %ld: %f\n", j, myVector->data.F32[j]);
                     numClipped++;
@@ -715,5 +716,5 @@
                               const psVector* errors,
                               psVector* maskInput,
-                              psMaskType maskValInput,
+                              psVectorMaskType maskValInput,
                               psStats* stats)
 {
@@ -726,11 +727,11 @@
     // and tested even if there is no supplied mask (and/or the maskVal is 0)
     // XXX this would be better if we had globally defined mask values
-    psMaskType maskVal = MASK_MARK | maskValInput;
-    psVector *mask = psVectorAlloc(myVector->n, PS_TYPE_MASK); // The actual mask we will use
+    psVectorMaskType maskVal = MASK_MARK | maskValInput;
+    psVector *mask = psVectorAlloc(myVector->n, PS_TYPE_VECTOR_MASK); // The actual mask we will use
     psVectorInit(mask, 0);
     if (maskInput) {
         for (long i = 0; i < myVector->n; i++) {
-            if (maskInput->data.U8[i] & maskValInput) {
-                mask->data.U8[i] = maskVal;
+            if (maskInput->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValInput) {
+                mask->data.PS_TYPE_VECTOR_MASK_DATA[i] = maskVal;
             }
         }
@@ -934,5 +935,5 @@
                 if ((myVector->data.F32[i] < medianLo) || (myVector->data.F32[i] > medianHi)) {
                     // XXXX is this correct?  is MASK_MARK safe?
-                    mask->data.U8[i] |= MASK_MARK;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= MASK_MARK;
                     psTrace(TRACE, 6, "Masking element %ld is %f\n", i, myVector->data.F32[i]);
                 }
@@ -998,5 +999,5 @@
     long N50 = 0;
     for (long i = 0 ; i < myVector->n ; i++) {
-        if (!mask->data.U8[i] &&
+        if (!mask->data.PS_TYPE_VECTOR_MASK_DATA[i] &&
             (binLo25F32 <= myVector->data.F32[i]) && (binHi25F32 >= myVector->data.F32[i])) {
             N50++;
@@ -1046,5 +1047,5 @@
                                const psVector* errors,
                                psVector* mask,
-                               psMaskType maskVal,
+                               psVectorMaskType maskVal,
                                psStats* stats)
 {
@@ -1224,5 +1225,5 @@
                                   const psVector* errors,
                                   psVector* mask,
-                                  psMaskType maskVal,
+                                  psVectorMaskType maskVal,
                                   psStats* stats)
 {
@@ -1347,5 +1348,5 @@
         // fitStats->clipIter = 3.0;
         // fitStats->clipSigma = 3.0;
-        // psVector *fitMask = psVectorAlloc(y->n, PS_TYPE_U8);
+        // psVector *fitMask = psVectorAlloc(y->n, PS_TYPE_VECTOR_MASK);
         // psVectorInit (fitMask, 0);
 
@@ -1418,5 +1419,5 @@
                                   const psVector* errors,
                                   psVector* mask,
-                                  psMaskType maskVal,
+                                  psVectorMaskType maskVal,
                                   psStats* stats)
 {
@@ -1713,5 +1714,5 @@
                                   const psVector* errors,
                                   psVector* mask,
-                                  psMaskType maskVal,
+                                  psVectorMaskType maskVal,
                                   psStats* stats)
 {
@@ -2225,5 +2226,5 @@
                    const psVector* errors,
                    const psVector* mask,
-                   psMaskType maskVal)
+                   psVectorMaskType maskVal)
 {
     psTrace(TRACE, 3,"---- %s() begin  ----\n", __func__);
@@ -2233,5 +2234,5 @@
     if (mask) {
         PS_ASSERT_VECTORS_SIZE_EQUAL(mask, in, false);
-        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_VECTOR_TYPE(mask, PS_TYPE_VECTOR_MASK, false);
     }
     if (errors) {
@@ -2255,10 +2256,10 @@
         }
     }
-    psVector *maskU8 = NULL;            // Input mask vector, U8 version
+    psVector *maskVector = NULL;            // Input mask vector, U8 version
     if (mask) {
-        if (mask->type.type == PS_TYPE_MASK) {
-            maskU8 = psMemIncrRefCounter((psPtr)mask);
+        if (mask->type.type == PS_TYPE_VECTOR_MASK) {
+            maskVector = psMemIncrRefCounter((psPtr)mask);
         } else {
-            maskU8 = psVectorCopy(NULL, mask, PS_TYPE_MASK);
+            maskVector = psVectorCopy(NULL, mask, PS_TYPE_VECTOR_MASK);
         }
     }
@@ -2279,5 +2280,5 @@
     // ************************************************************************
     if (stats->options & PS_STAT_SAMPLE_MEAN) {
-        if (!vectorSampleMean(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleMean(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate vector sample mean");
             status &= false;
@@ -2287,5 +2288,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_QUARTILE)) {
-        if (!vectorSampleMedian(inF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleMedian(inF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample median");
             status &= false;
@@ -2295,5 +2296,5 @@
     // ************************************************************************
     if (stats->options & PS_STAT_SAMPLE_STDEV) {
-        if (!vectorSampleStdev(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleStdev(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample stdev");
             status &= false;
@@ -2302,5 +2303,5 @@
 
     if (stats->options & (PS_STAT_SAMPLE_SKEWNESS | PS_STAT_SAMPLE_KURTOSIS)) {
-        if (!vectorSampleMoments(inF32, maskU8, maskVal, stats)) {
+        if (!vectorSampleMoments(inF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate sample moments");
             status &= false;
@@ -2310,5 +2311,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_MAX | PS_STAT_MIN)) {
-        if (vectorMinMax(inF32, maskU8, maskVal, stats) == 0) {
+        if (vectorMinMax(inF32, maskVector, maskVal, stats) == 0) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate vector minimum and maximum");
             status &= false;
@@ -2318,5 +2319,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_ROBUST_MEDIAN | PS_STAT_ROBUST_STDEV | PS_STAT_ROBUST_QUARTILE)) {
-        if (!vectorRobustStats(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorRobustStats(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate robust statistics"));
             status &= false;
@@ -2326,5 +2327,5 @@
     // ************************************************************************
     if (stats->options & (PS_STAT_FITTED_MEAN | PS_STAT_FITTED_STDEV)) {
-        if (!vectorFittedStats(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2337,5 +2338,5 @@
             psAbort("you may not specify both FITTED_MEAN and FITTED_MEAN_V2");
         }
-        if (!vectorFittedStats_v2(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats_v2(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2348,5 +2349,5 @@
             psAbort("you may not specify both FITTED_MEAN and FITTED_MEAN_V3");
         }
-        if (!vectorFittedStats_v3(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats_v3(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2359,5 +2360,5 @@
             psAbort("you may not specify both FITTED_MEAN and FITTED_MEAN_V4");
         }
-        if (!vectorFittedStats_v4(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorFittedStats_v4(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, _("Failed to calculate fitted statistics"));
             status &= false;
@@ -2367,5 +2368,5 @@
     // ************************************************************************
     if ((stats->options & PS_STAT_CLIPPED_MEAN) || (stats->options & PS_STAT_CLIPPED_STDEV)) {
-        if (!vectorClippedStats(inF32, errorsF32, maskU8, maskVal, stats)) {
+        if (!vectorClippedStats(inF32, errorsF32, maskVector, maskVal, stats)) {
             psError(PS_ERR_UNKNOWN, false, "Failed to calculate clipped statistics\n");
             status &= false;
@@ -2375,5 +2376,5 @@
     psFree(inF32);
     psFree(errorsF32);
-    psFree(maskU8);
+    psFree(maskVector);
     psTrace(TRACE, 3,"---- %s() end  ----\n", __func__);
     return status;
