Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 6449)
+++ trunk/psLib/src/math/psStats.c	(revision 6484)
@@ -16,6 +16,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.169 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-02-18 00:56:44 $
+ *  @version $Revision: 1.170 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-02-24 23:43:15 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -569,4 +569,5 @@
     // Allocate temporary vectors for the data.
     unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
+    unsortedVector->n = nValues;
 
     // Determine if we must only use data points within a min/max range.
@@ -657,4 +658,5 @@
     psS32 numBins = histogram->nums->n;
     psVector *smooth = psVectorAlloc(numBins, PS_TYPE_F32);
+    smooth->n = smooth->nalloc;
     psS32 jMin = 0;
     psS32 jMax = 0;
@@ -783,4 +785,5 @@
     // Allocate temporary vectors for the data.
     unsortedVector = psVectorAlloc(nValues, PS_TYPE_F32);
+    unsortedVector->n = unsortedVector->nalloc;
 
     if (stats->options & PS_STAT_USE_RANGE) {
@@ -1037,4 +1040,5 @@
     // However, we do no want to modify the original mask vector.
     tmpMask = psVectorAlloc(myVector->n, PS_TYPE_U8);
+    tmpMask->n = tmpMask->nalloc;
 
     // If we were called with a mask vector, then initialize the temporary
@@ -1198,4 +1202,6 @@
     psVector *x = psVectorAlloc(3, PS_TYPE_F64);
     psVector *y = psVectorAlloc(3, PS_TYPE_F64);
+    x->n = 3;
+    y->n = 3;
     psF32 tmpFloat = 0.0f;
 
@@ -1313,4 +1319,5 @@
     if (deriv == NULL) {
         deriv = psVectorAlloc(2, PS_TYPE_F32);
+        deriv->n = 2;
     } else {
         PS_ASSERT_VECTOR_SIZE(deriv, 2, NAN);
@@ -1365,4 +1372,5 @@
     psS32 rcBool = false;
     psVector *tmpMaskVec = psVectorAlloc(myVector->n, PS_TYPE_U8);
+    tmpMaskVec->n = tmpMaskVec->nalloc;
     if (maskVector != NULL) {
         for (psS32 i = 0 ; i < myVector->n ; i++) {
@@ -1850,4 +1858,5 @@
         psArray *x = psArrayAlloc((1 + (binMax - binMin)));
         psS32 j = 0;
+        y->n = y->nalloc;
 
         for (psS32 i = binMin ; i <= binMax ; i++) {
@@ -1856,4 +1865,5 @@
             x->n++;
             ((psVector *) x->data[j])->data.F32[0] = PS_BIN_MIDPOINT(newHistogram, i);
+            ((psVector *) x->data[j])->n++;
             j++;
         }
@@ -1886,4 +1896,5 @@
         psMinimization *min = psMinimizationAlloc(100, 0.01);
         psVector *params = psVectorAlloc(2, PS_TYPE_F32);
+        params->n = params->nalloc;
         // Initial guess for the mean ([0]) and standard dev.
         params->data.F32[0] = stats->robustMedian;
@@ -2049,6 +2060,7 @@
     // Allocate the bins, and initialize them to zero.
     newHist->nums = psVectorAlloc(n, PS_TYPE_F32);
-    for (i = 0; i < newHist->nums->n; i++) {
+    for (i = 0; i < newHist->nums->nalloc; i++) {
         newHist->nums->data.F32[i] = 0.0;
+        newHist->nums->n++;
     }
 
@@ -2094,6 +2106,7 @@
     // then there are N-1 bins.
     newHist->nums = psVectorAlloc((bounds->n) - 1, PS_TYPE_F32);
-    for (i = 0; i < newHist->nums->n; i++) {
+    for (i = 0; i < newHist->nums->nalloc; i++) {
         newHist->nums->data.F32[i] = 0.0;
+        newHist->nums->n++;
     }
 
@@ -2366,4 +2379,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.S8[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_S16) {
@@ -2371,4 +2385,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32) in->data.S16[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_S32) {
@@ -2376,4 +2391,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.S32[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_S64) {
@@ -2381,4 +2397,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.S64[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_U8) {
@@ -2386,4 +2403,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.U8[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_U16) {
@@ -2391,4 +2409,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.U16[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_U32) {
@@ -2396,4 +2415,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.U32[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_U64) {
@@ -2401,4 +2421,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.U64[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_F64) {
@@ -2406,4 +2427,5 @@
         for (i = 0; i < in->n; i++) {
             tmp->data.F32[i] = (psF32)in->data.F64[i];
+            tmp->n++;
         }
     } else if (in->type.type == PS_TYPE_F32) {
@@ -2463,7 +2485,12 @@
     inF32 = p_psConvertToF32((psVector *) in);
     if (inF32 == NULL) {
-        inF32 = (psVector *) in;
-        mustFreeVectorIn = 0;
-    }
+        //        printf("\n\ninF32 is NULL\n\n");
+        //        inF32 = (psVector *) in;
+        //        mustFreeVectorIn = 0;
+        inF32 = psVectorCopy(inF32, in, PS_TYPE_F32);
+        inF32->n = inF32->nalloc;
+        mustFreeVectorIn = 1;
+    }
+    //    else printf("\ninF32 has n=%ld, nalloc=%ld\n", inF32->n, inF32->nalloc);
     errorsF32 = p_psConvertToF32((psVector *) errors);
     if (errorsF32 == NULL) {
@@ -2471,5 +2498,6 @@
         mustFreeVectorErrors = 0;
     }
-
+    //    inF32->n = inF32->nalloc;
+    //    errorsF32->n = errorsF32->nalloc;
     if ((stats->options & PS_STAT_USE_RANGE) && (stats->min >= stats->max)) {
         PS_ASSERT_FLOAT_LARGER_THAN_OR_EQUAL(stats->max, stats->min, stats);
