Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 2780)
+++ trunk/psLib/src/math/psStats.c	(revision 2782)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.106 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-21 23:25:14 $
+ *  @version $Revision: 1.107 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-22 00:54:28 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -682,5 +682,5 @@
                     robustHistogram->bounds->data.F32[j+1]) / 2.0;
             smooth->data.F32[i] +=
-                ((float) robustHistogram->nums->data.U32[j]) *
+                robustHistogram->nums->data.F32[j] *
                 psGaussian(jMid, iMid, sigma, true);
         }
@@ -1563,5 +1563,5 @@
     modeBinNum = LQBinNum;
     modeBinCount = robustHistogramVector->data.F32[LQBinNum];
-    sumN50 = (float)robustHistogram->nums->data.U32[LQBinNum];
+    sumN50 = robustHistogram->nums->data.F32[LQBinNum];
     for (i = LQBinNum + 1; i <= UQBinNum; i++) {
         if (robustHistogramVector->data.F32[i] > modeBinCount) {
@@ -1569,5 +1569,5 @@
             modeBinCount = robustHistogramVector->data.F32[i];
         }
-        sumN50 += (float)robustHistogram->nums->data.U32[i];
+        sumN50 += robustHistogram->nums->data.F32[i];
     }
 
@@ -1587,5 +1587,5 @@
         }
 
-        sumNfit += (float)robustHistogram->nums->data.U32[i];
+        sumNfit += robustHistogram->nums->data.F32[i];
     }
     // XXX: divide by zero?
@@ -1796,8 +1796,7 @@
 
     // Allocate the bins, and initialize them to zero.
-    newHist->nums = psVectorAlloc(n, PS_TYPE_U32);
-    newHist->nums->n = newHist->nums->nalloc;
+    newHist->nums = psVectorAlloc(n, PS_TYPE_F32);
     for (i = 0; i < newHist->nums->n; i++) {
-        newHist->nums->data.U32[i] = 0;
+        newHist->nums->data.F32[i] = 0.0;
     }
 
@@ -1839,8 +1838,7 @@
     // Allocate the bins, and initialize them to zero.  If there are N bounds,
     // then there are N-1 bins.
-    newHist->nums = psVectorAlloc((bounds->n) - 1, PS_TYPE_U32);
-    newHist->nums->n = newHist->nums->nalloc;
+    newHist->nums = psVectorAlloc((bounds->n) - 1, PS_TYPE_F32);
     for (i = 0; i < newHist->nums->n; i++) {
-        newHist->nums->data.U32[i] = 0;
+        newHist->nums->data.F32[i] = 0.0;
     }
 
@@ -1858,4 +1856,30 @@
     psFree(myHist->nums);
 }
+
+psS32 UpdateHistogramBins(psS32 binNum,
+                          psHistogram* out,
+                          psF32 data,
+                          psF32 error)
+{
+    PS_PTR_CHECK_NULL(out, -1);
+    PS_INT_CHECK_RANGE(binNum, 0, out->nums->n-1, -2);
+    /*
+        psF32 width = 2.35 * error;
+        psF32 centerBinWidth = out->bounds->data.F32[binNum+1] - out->bounds->data.F32[binNum]
+        psF32 boxcarCenter = (out->bounds->data.F32[binNum] + out->bounds->data.F32[binNum+1]) / 2.0;
+     
+        if (width <= centerBinWidth) {
+            out->nums->data.F32[binNum]+= 1.0;
+        } else {
+            out->nums->data.F32[binNum]+= centerBinWidth / width;
+            // XXX: walk to the left, adding fractional values.
+            // XXX: walk to the right, adding fractional values.
+     
+     
+        }
+    */
+    return(0);
+}
+
 
 /*****************************************************************************
@@ -1883,5 +1907,5 @@
     PS_PTR_CHECK_NULL(out, NULL);
     PS_VECTOR_CHECK_TYPE(out->bounds, PS_TYPE_F32, NULL);
-    PS_VECTOR_CHECK_TYPE(out->nums, PS_TYPE_U32, NULL);
+    PS_VECTOR_CHECK_TYPE(out->nums, PS_TYPE_F32, NULL);
     PS_INT_CHECK_NON_NEGATIVE(out->nums->n, NULL);
     PS_VECTOR_CHECK_NULL(in, out);
@@ -1913,6 +1937,5 @@
     for (i = 0; i < inF32->n; i++) {
         // Check if this pixel is masked, and if so, skip it.
-        if ((mask == NULL) ||
-                ((mask != NULL) && (!(mask->data.U8[i] & maskVal)))) {
+        if ((mask == NULL) || ((mask != NULL) && (!(mask->data.U8[i] & maskVal)))) {
             if (inF32->data.F32[i] < out->bounds->data.F32[0]) {
                 // If this pixel is below minimum value, count it, then skip.
@@ -1927,13 +1950,18 @@
                     binSize = out->bounds->data.F32[1] - out->bounds->data.F32[0];
                     binNum = (psS32)((inF32->data.F32[i] - out->bounds->data.F32[0]) / binSize);
-
-                    // XXX: This if-statement really shouldn't be necessary.
-                    // However, due to numerical lack of precision, we
-                    // occasionally produce a binNum outside the range.
-                    if (binNum >= out->nums->n) {
-                        binNum = out->nums->n - 1;
+                    if (errors != NULL) {
+                        // XXX: Check return codes.
+                        UpdateHistogramBins(binNum, out,
+                                            inF32->data.F32[i],
+                                            errors->data.F32[i]);
+                    } else {
+                        // XXX: This if-statement really shouldn't be necessary.
+                        // However, due to numerical lack of precision, we
+                        // occasionally produce a binNum outside the range.
+                        if (binNum >= out->nums->n) {
+                            binNum = out->nums->n - 1;
+                        }
+                        (out->nums->data.F32[binNum])+= 1.0;
                     }
-
-                    (out->nums->data.U32[binNum])++;
 
                 } else {
@@ -1946,5 +1974,12 @@
                                  "WARNING: psVectorHistogram(): element outside histogram bounds.\n");
                     } else {
-                        (out->nums->data.U32[tmp])++;
+                        if (errors != NULL) {
+                            // XXX: Check return codes.
+                            UpdateHistogramBins(tmp, out,
+                                                inF32->data.F32[i],
+                                                errors->data.F32[i]);
+                        } else {
+                            (out->nums->data.F32[tmp])+= 1.0;
+                        }
                     }
                 }
