Index: trunk/psLib/src/astro/psCoord.c
===================================================================
--- trunk/psLib/src/astro/psCoord.c	(revision 9720)
+++ trunk/psLib/src/astro/psCoord.c	(revision 9730)
@@ -10,6 +10,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.125 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-13 22:04:58 $
+*  @version $Revision: 1.126 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-24 22:52:55 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -795,13 +795,9 @@
     psVector *xOut = psVectorAlloc(numCoords, PS_TYPE_F64);
     psVector *yOut = psVectorAlloc(numCoords, PS_TYPE_F64);
-    for (psS32 g = 0; g < numCoords; g++) {
+    for (int g = 0; g < numCoords; g++) {
         xIn->data.F64[g] = ((psPlane *) source->data[g])->x;
-        xIn->n++;
         yIn->data.F64[g] = ((psPlane *) source->data[g])->y;
-        yIn->n++;
         xOut->data.F64[g] = ((psPlane *) dest->data[g])->x;
-        xOut->n++;
         yOut->data.F64[g] = ((psPlane *) dest->data[g])->y;
-        yOut->n++;
     }
 
Index: trunk/psLib/src/db/psDB.c
===================================================================
--- trunk/psLib/src/db/psDB.c	(revision 9720)
+++ trunk/psLib/src/db/psDB.c	(revision 9730)
@@ -12,6 +12,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.106 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-21 01:09:37 $
+ *  @version $Revision: 1.107 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:55 $
  *
  *  Copyright (C) 2005-2006  Joshua Hoblitt, University of Hawaii
@@ -395,6 +395,5 @@
     // then reset n to 0 so elements are added from the beginning of
     // the array
-    column = psArrayAlloc(rowCount);
-    column->n = 0;
+    column = psArrayAllocEmpty(rowCount);
 
     // Fetch each result
@@ -459,51 +458,39 @@
 
     psVector *column = psVectorAlloc(stringColumn->n, type);
-    //    column->n = column->nalloc;
 
     // conversion functions are a portability issue
     switch (type) {
     case PS_TYPE_S8:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.S8, stringColumn, atoi, psS8, PS_TYPE_S8);
         break;
     case PS_TYPE_S16:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.S16, stringColumn, atoi, psS16, PS_TYPE_S16);
         break;
     case PS_TYPE_S32:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.S32, stringColumn, atoi, psS32, PS_TYPE_S32);
         break;
     case PS_TYPE_S64:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.S64, stringColumn, atoll, psS64, PS_TYPE_S64);
         break;
     case PS_TYPE_U8:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.U8, stringColumn, atoi, psU8, PS_TYPE_U8);
         break;
     case PS_TYPE_U16:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.U16, stringColumn, atoi, psU16, PS_TYPE_U16);
         break;
     case PS_TYPE_U32:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.U32, stringColumn, atoi, psU32, PS_TYPE_U32);
         break;
     case PS_TYPE_U64:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.U64, stringColumn, atoll, psU64, PS_TYPE_U64);
         break;
     case PS_TYPE_F32:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.F32, stringColumn, atof, psF32, PS_TYPE_F32);
         break;
     case PS_TYPE_F64:
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.F64, stringColumn, atof, psF64, PS_TYPE_F64);
         break;
     case PS_TYPE_C32:
         // this is a bogus SQL type
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.C32, stringColumn, atof, psC32, PS_TYPE_C32);
         break;
@@ -514,5 +501,4 @@
     case PS_TYPE_BOOL:
         // valid for psVector?
-        column->n = column->nalloc;
         PS_STR_ARRAY_TO_PTYPE(column->data.U8, stringColumn, atoi, psU8, PS_TYPE_U8);
         break;
@@ -567,6 +553,5 @@
 
     // Create array to store single row
-    psArray *rowSet = psArrayAlloc(1);
-    rowSet->n = 0;
+    psArray *rowSet = psArrayAllocEmpty(1);
     psArrayAdd(rowSet, 0, (psPtr)row);
 
@@ -697,5 +682,5 @@
     }
 
-    psArray *rowData = psArrayAlloc(1);
+    psArray *rowData = psArrayAllocEmpty(1);
     psArrayAdd(rowData, 0, values);
     long rowsAffected = p_psDBRunQueryPrepared(dbh, rowData, query);
@@ -966,5 +951,5 @@
     // then reset n to 0 so elements are added from the beginning of
     // the array
-    resultSet = psArrayAlloc(rowCount);
+    resultSet = psArrayAllocEmpty(rowCount);
 
     field = mysql_fetch_fields(result);
@@ -1304,5 +1289,5 @@
     // Reset iterator to head of list
     psListIteratorSet(cursor, 0);
-    psArray *pKeys = psArrayAlloc(1);
+    psArray *pKeys = psArrayAllocEmpty(1);
     while ((item = psListGetAndIncrement(cursor))) {
         if (strstr(item->comment, "Primary Key")) {
Index: trunk/psLib/src/fits/psFitsImage.c
===================================================================
--- trunk/psLib/src/fits/psFitsImage.c	(revision 9720)
+++ trunk/psLib/src/fits/psFitsImage.c	(revision 9730)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 21:13:47 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -519,5 +519,4 @@
     if (nAxis == 2) {
         psArray *images = psArrayAlloc(1); // Single image plane
-        images->n = 1;
         images->data[0] = psFitsReadImage(fits, region, 0);
         return images;
@@ -533,5 +532,4 @@
 
         psArray *images = psArrayAlloc(nAxes[2]); // Array of image planes
-        images->n = nAxes[2];
         for (int i = 0; i < nAxes[2]; i++) {
             images->data[i] = psFitsReadImage(fits, region, i);
Index: trunk/psLib/src/fits/psFitsTable.c
===================================================================
--- trunk/psLib/src/fits/psFitsTable.c	(revision 9720)
+++ trunk/psLib/src/fits/psFitsTable.c	(revision 9730)
@@ -7,6 +7,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-08-26 04:34:28 $
+ *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -237,5 +237,4 @@
         result->data[row] = psAlloc((width+1)*sizeof(char));
     }
-    result->n = numRows;
 
     fits_read_col_str(fits->fd,
@@ -319,5 +318,4 @@
 
     psVector* result = psVectorAlloc(numRows, p_psFitsTypeFromCfitsio(typecode));
-    result->n = numRows;
 
     fits_read_col(fits->fd,
@@ -389,5 +387,4 @@
         psTrace("psLib.fits",5,"Reading row %i of %li\n",row, numRows);
         table->data[row] = psFitsReadTableRow(fits,row);
-        table->n++;
     }
 
@@ -564,6 +561,4 @@
     psArray *columnNames = psArrayAlloc(numColumns); // Array of column names, for cfitsio
     psArray *columnTypes = psArrayAlloc(numColumns); // Array of column types, for cfitsio
-    columnNames->n = numColumns;
-    columnTypes->n = numColumns;
     psMetadataIterator *colSpecsIter = psMetadataIteratorAlloc(colSpecs, PS_LIST_HEAD, NULL); // Iterator
     psMetadataItem *colSpecItem;        // Column specification item, from iteration
@@ -644,5 +639,4 @@
             size_t dataSize = PSELEMTYPE_SIZEOF(spec->type); // Size (in bytes) of this type
             psVector *columnData = psVectorAlloc(table->n, spec->type); // The raw row data, to be written
-            columnData->n = table->n;
             psVectorInit(columnData, 0);
             for (long i = 0; i < table->n; i++) {
@@ -667,5 +661,4 @@
             case PS_DATA_STRING: {
                     psArray *strings = psArrayAlloc(table->n); // Array of strings
-                    strings->n = table->n;
                     for (long i = 0; i < table->n; i++) {
                         psMetadata *row = table->data[i]; // The row of interest
Index: trunk/psLib/src/imageops/psImageBackground.c
===================================================================
--- trunk/psLib/src/imageops/psImageBackground.c	(revision 9720)
+++ trunk/psLib/src/imageops/psImageBackground.c	(revision 9730)
@@ -36,5 +36,5 @@
     int Npixels = nx*ny;                // Total number of pixels
 
-    psVector *values = psVectorAlloc(Nsubset, PS_TYPE_F32); // Vector containing subsample
+    psVector *values = psVectorAllocEmpty(Nsubset, PS_TYPE_F32); // Vector containing subsample
 
     // Minimum and maximum values
Index: trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.c	(revision 9720)
+++ trunk/psLib/src/imageops/psImageConvolve.c	(revision 9730)
@@ -5,6 +5,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 21:13:48 $
+ *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -505,5 +505,4 @@
         /* generate normalized gaussian */ \
         psVector *gaussnorm = psVectorAlloc(Npixel, PS_TYPE_##TYPE); \
-        gaussnorm->n = gaussnorm->nalloc; \
         { \
             double sum = 0.0; \
@@ -522,5 +521,4 @@
         { \
             psVector *calculation = psVectorAlloc(Nx, PS_TYPE_##TYPE); \
-            calculation->n = calculation->nalloc; \
             for (int j = 0; j < Ny; j++) { \
                 ps##TYPE *vi = image->data.TYPE[j]; \
@@ -573,5 +571,4 @@
         /* Smooth in Y direction */ \
         psArray *rows = psArrayAlloc(Nrange); \
-        rows->n = Nrange; \
         /* Smooth the first Nrange pixels, with renorm */ \
         int yMax = PS_MIN(Nrange, Ny); \
@@ -579,5 +576,4 @@
         for (int j = 0; j < yMax; j++) { \
             psVector *calculation = psVectorAlloc(Nx, PS_TYPE_##TYPE); \
-            calculation->n = calculation->nalloc; \
             /* Zero the output row */ \
             memset(calculation->data.TYPE, 0, Nx*sizeof(ps##TYPE)); \
Index: trunk/psLib/src/imageops/psImageGeomManip.c
===================================================================
--- trunk/psLib/src/imageops/psImageGeomManip.c	(revision 9720)
+++ trunk/psLib/src/imageops/psImageGeomManip.c	(revision 9730)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-08-08 23:32:23 $
+ *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -80,5 +80,5 @@
     }
 
-    vec = psVectorAlloc(scale * scale, in->type.type);
+    vec = psVectorAllocEmpty(scale * scale, in->type.type);
 
     if (mask != NULL) {
@@ -93,6 +93,5 @@
             return NULL;
         }
-        maskVec = psVectorAlloc(scale * scale, PS_TYPE_MASK);
-        maskVec->n = maskVec->nalloc;
+        maskVec = psVectorAllocEmpty(scale * scale, PS_TYPE_MASK);
         maskData = maskVec->data.PS_TYPE_MASK_DATA;
     }
@@ -134,4 +133,5 @@
                 } \
                 vec->n = n; \
+                maskVec->n = n; \
                 myStats = psVectorStats(myStats, vec, NULL, maskVec, maskVal); \
                 outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
Index: trunk/psLib/src/imageops/psImagePixelExtract.c
===================================================================
--- trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 9720)
+++ trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 9730)
@@ -8,6 +8,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-08-26 04:34:28 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -18,4 +18,5 @@
 
 #include "psMemory.h"
+#include "psVector.h"
 #include "psImagePixelExtract.h"
 #include "psError.h"
@@ -392,5 +393,4 @@
     if (direction == PS_CUT_X_POS || direction == PS_CUT_X_NEG) {
         psVector* imgVec = psVectorAlloc(numRows, type);
-        imgVec->n = imgVec->nalloc;
         psVector* maskVec = NULL;
         psMaskType* maskData = NULL;
@@ -417,5 +417,4 @@
         if (mask != NULL) {
             maskVec = psVectorAlloc(numRows, mask->type.type);
-            maskVec->n = maskVec->nalloc;
         }
         #define PSIMAGE_CUT_VERTICAL(TYPE) \
@@ -855,13 +854,11 @@
         // n.b. alloc enough for the data by making the vectors slightly larger
         // than the area of the region of interest.
-        buffer[lcv] = psVectorAlloc(1+4*(rSq[lcv+1]-rSq[lcv]),
-                                    input->type.type);
-        buffer[lcv]->n = 0;
+        buffer[lcv] = psVectorAllocEmpty(1+4*(rSq[lcv+1]-rSq[lcv]),
+                                         input->type.type);
 
         bufferMask[lcv] = NULL;
         if (mask != NULL) {
-            bufferMask[lcv] = psVectorAlloc(1+4*(rSq[lcv+1]-rSq[lcv]),
-                                            PS_TYPE_MASK);
-            bufferMask[lcv]->n = 0;
+            bufferMask[lcv] = psVectorAllocEmpty(1+4*(rSq[lcv+1]-rSq[lcv]),
+                                                 PS_TYPE_MASK);
         }
     }
Index: trunk/psLib/src/imageops/psImageStats.c
===================================================================
--- trunk/psLib/src/imageops/psImageStats.c	(revision 9720)
+++ trunk/psLib/src/imageops/psImageStats.c	(revision 9730)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.100 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-08-26 04:34:28 $
+ *  @version $Revision: 1.101 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -76,5 +76,4 @@
 
         junkData = psVectorAlloc(numRows*numCols, in->type.type);
-        junkData->n = junkData->nalloc;
 
         psU8* data = junkData->data.U8;
@@ -100,5 +99,4 @@
 
             junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
-            junkMask->n = junkMask->nalloc;
 
             psU8* data = junkMask->data.U8;
@@ -149,5 +147,4 @@
 
         junkData = psVectorAlloc(numRows*numCols, in->type.type);
-        junkData->n = junkData->nalloc;
 
         psU8* data = junkData->data.U8;
@@ -173,5 +170,4 @@
 
             junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
-            junkMask->n = junkMask->nalloc;
 
             psU8* data = junkMask->data.U8;
@@ -592,9 +588,9 @@
         return -1;
     }/* else if (col0 == col1 && row0 == row1) {
-                                                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                                                        "Invalid psRegion specified.  Region contains only 1 pixel.\n");
-                                                return -1;
-                                            }
-                                        */
+                                                    psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                                                            "Invalid psRegion specified.  Region contains only 1 pixel.\n");
+                                                    return -1;
+                                                }
+                                            */
     x0 = col0;
     x1 = col1;
Index: trunk/psLib/src/jpeg/psImageJpeg.c
===================================================================
--- trunk/psLib/src/jpeg/psImageJpeg.c	(revision 9720)
+++ trunk/psLib/src/jpeg/psImageJpeg.c	(revision 9730)
@@ -33,8 +33,4 @@
     map->blue  = psVectorAlloc(256, PS_TYPE_U8);
     map->green = psVectorAlloc(256, PS_TYPE_U8);
-
-    map->red->n = 256;
-    map->blue->n = 256;
-    map->green->n = 256;
 
     return map;
Index: trunk/psLib/src/math/psMinimizeLMM.c
===================================================================
--- trunk/psLib/src/math/psMinimizeLMM.c	(revision 9720)
+++ trunk/psLib/src/math/psMinimizeLMM.c	(revision 9730)
@@ -10,6 +10,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-14 00:15:47 $
+ *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -163,7 +163,5 @@
     psImage  *Alpha  = psImageAlloc (params->n, params->n, PS_TYPE_F64);
     psVector *beta   = psVectorAlloc(params->n, PS_TYPE_F64);
-    beta->n = beta->nalloc;
     psVector *Params = psVectorAlloc(params->n, PS_TYPE_F64);
-    Params->n = Params->nalloc;
     psVector *dy     = NULL;
     psBool rc = true;
@@ -175,5 +173,4 @@
     } else {
         dy = psVectorAlloc(y->n, PS_TYPE_F32);
-        dy->n = dy->nalloc;
         psVectorInit(dy, 1.0);
     }
@@ -246,5 +243,4 @@
     psF64 ymodel;
     psVector *deriv = psVectorAlloc(params->n, PS_TYPE_F32);
-    deriv->n = deriv->nalloc;
 
     // zero alpha and beta for summing below
@@ -380,9 +376,6 @@
     psImage *Alpha   = psImageAlloc(params->n, params->n, PS_TYPE_F64);
     psVector *beta   = psVectorAlloc(params->n, PS_TYPE_F64);
-    beta->n = beta->nalloc;
     psVector *Beta   = psVectorAlloc(params->n, PS_TYPE_F64);
-    beta->n = beta->nalloc;
     psVector *Params = psVectorAlloc(params->n, PS_TYPE_F32);
-    Params->n = Params->nalloc;
     psVector *dy     = NULL;
     psF64 Chisq = 0.0;
@@ -398,5 +391,4 @@
     } else {
         dy = psVectorAlloc(y->n, PS_TYPE_F32);
-        dy->n = dy->nalloc;
         psVectorInit(dy, 1.0);
     }
Index: trunk/psLib/src/math/psMinimizePolyFit.c
===================================================================
--- trunk/psLib/src/math/psMinimizePolyFit.c	(revision 9720)
+++ trunk/psLib/src/math/psMinimizePolyFit.c	(revision 9730)
@@ -10,6 +10,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-19 02:57:18 $
+ *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -46,5 +46,4 @@
 #define PS_VECTOR_GEN_CHEBY_INDEX(VEC, SIZE, TYPE) \
 VEC = psVectorAlloc(SIZE, TYPE); \
-VEC->n = VEC->nalloc; \
 if (TYPE == PS_TYPE_F64) { \
     for (psS32 i = 0 ; i < SIZE ; i++) { \
@@ -93,8 +92,7 @@
     if (sums == NULL) {
         sums = psVectorAlloc(nSum, PS_TYPE_F64);
-        sums->n = sums->nalloc;
     } else if (nSum > sums->n) {
         sums = psVectorRealloc(sums, nSum);
-        sums->n = sums->nalloc;
+        sums->n = nSum;
     }
 
@@ -333,5 +331,4 @@
     psImage *A = psImageAlloc(numTerms, numTerms, PS_TYPE_F64); // Least-squares matrix
     psVector *B = psVectorAlloc(numTerms, PS_TYPE_F64); // Least-squares vector
-    B->n = numTerms;
     psImageInit(A, 0.0);
     psVectorInit(B, 0.0);
@@ -509,5 +506,4 @@
     psImage *A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); // Least-squares matrix
     psVector *B = psVectorAlloc(nTerm, PS_TYPE_F64); // Least-squares vector
-    B->n = B->nalloc;
 
     // Initialize data structures.
@@ -805,5 +801,4 @@
     psVector *fit   = NULL;
     psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64);
-    resid->n = resid->nalloc;
 
     // eventual expansion: user supplies one of various stats option pairs,
@@ -976,5 +971,4 @@
     psImage *A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); // Least-squares matrix
     psVector *B = psVectorAlloc(nTerm, PS_TYPE_F64); // Least-squares vector
-    B->n = B->nalloc;
 
     // Initialize data structures.
@@ -1256,5 +1250,4 @@
     }
     psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64);
-    resid->n = resid->nalloc;
 
     // eventual expansion: user supplies one of various stats option pairs,
@@ -1434,5 +1427,4 @@
     psImage    *A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); // Least-squares matrix
     psVector   *B = psVectorAlloc(nTerm, PS_TYPE_F64); // Least-squares vector
-    B->n = B->nalloc;
 
     // Initialize data structures.
@@ -1790,5 +1782,4 @@
     psVector *fit   = NULL;
     psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64);
-    resid->n = resid->nalloc;
 
     // eventual expansion: user supplies one of various stats option pairs,
@@ -1967,5 +1958,4 @@
     psImage    *A = psImageAlloc(nTerm, nTerm, PS_TYPE_F64); // Least-squares matrix
     psVector   *B = psVectorAlloc(nTerm, PS_TYPE_F64); // Least-squares vector
-    B->n = B->nalloc;
 
     // Initialize data structures.
@@ -2368,5 +2358,4 @@
     psVector *fit   = NULL;
     psVector *resid = psVectorAlloc(f->n, PS_TYPE_F64);
-    resid->n = resid->nalloc;
 
     // eventual expansion: user supplies one of various stats option pairs,
Index: trunk/psLib/src/math/psMinimizePowell.c
===================================================================
--- trunk/psLib/src/math/psMinimizePowell.c	(revision 9720)
+++ trunk/psLib/src/math/psMinimizePowell.c	(revision 9730)
@@ -11,6 +11,6 @@
  *  NOTE: XXX: The SDR is silent about data types.  F32 is implemented here.
  *
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 22:04:58 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -549,7 +549,5 @@
                 ((psVector *) (v->data[i]))->data.F32[j] = 0.0;
             }
-            ((psVector *)(v->data[i]))->n++;
-        }
-        v->n++;
+        }
     }
 
Index: trunk/psLib/src/math/psPolynomial.c
===================================================================
--- trunk/psLib/src/math/psPolynomial.c	(revision 9720)
+++ trunk/psLib/src/math/psPolynomial.c	(revision 9730)
@@ -7,6 +7,6 @@
 *  polynomials.  It also contains a Gaussian functions.
 *
-*  @version $Revision: 1.151 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-13 22:04:58 $
+*  @version $Revision: 1.152 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-24 22:52:56 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -266,5 +266,4 @@
         // General case where the Chebyshev poly has 2 or more terms.
         d = psVectorAlloc(nTerms, PS_TYPE_F64);
-        d->n = d->nalloc;
         if(poly->mask[nTerms-1] == 0) {
             d->data.F64[nTerms-1] = poly->coeff[nTerms-1];
@@ -571,32 +570,4 @@
     psTrace("psLib.math", 4, "---- %s() end ----\n", __func__);
     return(tmp * exp(-((x - mean) * (x - mean)) / (2.0 * sigma * sigma)));
-}
-
-/*****************************************************************************
-    p_psGaussianDev()
- This private routine (formerly a psLib API routine) creates a psVector of the
- specified size and type F32 and fills it with a random Gaussian distribution
- of numbers with the specified mean and sigma.
- 
-XXX: It's possible to have a different seed everytime.  However, for now,
-for testability, we use a common seed.
- *****************************************************************************/
-#define PS_XXX_GAUSSIAN_SEED 1995
-psVector* p_psGaussianDev(psF32 mean,
-                          psF32 sigma,
-                          unsigned int Npts)
-{
-    PS_ASSERT_INT_NONNEGATIVE(Npts, NULL);
-
-    //    psRandom *r = psRandomAlloc(PS_RANDOM_TAUS, p_psRandomGetSystemSeed());
-    psRandom *r = psRandomAlloc(PS_RANDOM_TAUS, PS_XXX_GAUSSIAN_SEED);
-    psVector* gauss = psVectorAlloc(Npts, PS_TYPE_F32);
-    for (unsigned int i = 0; i < Npts; i++) {
-        gauss->data.F32[i] = mean + p_psRandomGaussian(r, sigma);
-        gauss->n++;
-    }
-    psFree(r);
-
-    return(gauss);
 }
 
@@ -808,5 +779,4 @@
         for (unsigned int i=0;i<x->n;i++) {
             tmp->data.F64[i] = psPolynomial1DEval(poly, x->data.F64[i]);
-            tmp->n++;
         }
         break;
@@ -815,5 +785,4 @@
         for (unsigned int i=0;i<x->n;i++) {
             tmp->data.F32[i] = psPolynomial1DEval(poly, x->data.F32[i]);
-            tmp->n++;
         }
         break;
@@ -877,5 +846,4 @@
         for (unsigned int i=0; i<vecLen; i++) {
             tmp->data.F32[i] = psPolynomial2DEval(poly,x->data.F32[i],y->data.F32[i]);
-            tmp->n++;
         }
         break;
@@ -892,5 +860,4 @@
         for (unsigned int i=0; i<vecLen; i++) {
             tmp->data.F64[i] = psPolynomial2DEval(poly,x->data.F64[i],y->data.F64[i]);
-            tmp->n++;
         }
         break;
@@ -959,5 +926,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F32[i],
                                                   y->data.F32[i], z->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F32)
@@ -966,5 +932,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F32[i],
                                                   y->data.F32[i], z->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F64)
@@ -973,5 +938,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F32[i],
                                                   y->data.F64[i], z->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F64)
@@ -980,5 +944,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F32[i],
                                                   y->data.F64[i], z->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F32)
@@ -987,5 +950,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F64[i],
                                                   y->data.F32[i], z->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F32)
@@ -994,5 +956,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F64[i],
                                                   y->data.F32[i], z->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F64)
@@ -1001,5 +962,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F64[i],
                                                   y->data.F64[i], z->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F64)
@@ -1008,5 +968,4 @@
             tmp->data.F64[i] = psPolynomial3DEval(poly, x->data.F64[i],
                                                   y->data.F64[i], z->data.F64[i]);
-            tmp->n++;
         }
     }
@@ -1079,5 +1038,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F32[i], z->data.F32[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F32)
@@ -1086,5 +1044,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F32[i], z->data.F32[i], t->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F32)
@@ -1093,5 +1050,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F32[i], z->data.F64[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F32)
@@ -1100,5 +1056,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F32[i], z->data.F64[i], t->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F64)
@@ -1107,5 +1062,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F64[i], z->data.F32[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F64)
@@ -1114,5 +1068,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F64[i], z->data.F32[i], t->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F64)
@@ -1121,5 +1074,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F64[i], z->data.F64[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F32) && (y->type.type == PS_TYPE_F64)
@@ -1128,5 +1080,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F32[i],
                                                   y->data.F64[i], z->data.F64[i], t->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F32)
@@ -1135,5 +1086,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F64[i],
                                                   y->data.F32[i], z->data.F32[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F32)
@@ -1142,5 +1092,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F64[i],
                                                   y->data.F32[i], z->data.F32[i], t->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F32)
@@ -1149,5 +1098,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F64[i],
                                                   y->data.F32[i], z->data.F64[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F32)
@@ -1156,5 +1104,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F64[i],
                                                   y->data.F32[i], z->data.F64[i], t->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F64)
@@ -1163,5 +1110,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F64[i],
                                                   y->data.F64[i], z->data.F32[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F64)
@@ -1170,5 +1116,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F64[i],
                                                   y->data.F64[i], z->data.F32[i], t->data.F64[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F64)
@@ -1177,5 +1122,4 @@
             tmp->data.F64[i] = psPolynomial4DEval(poly, x->data.F64[i],
                                                   y->data.F64[i], z->data.F64[i], t->data.F32[i]);
-            tmp->n++;
         }
     } else if ((x->type.type == PS_TYPE_F64) && (y->type.type == PS_TYPE_F64)
@@ -1185,5 +1129,4 @@
                                                   y->data.F64[i], z->data.F64[i],
                                                   t->data.F64[i]);
-            tmp->n++;
         }
     }
Index: trunk/psLib/src/math/psPolynomial.h
===================================================================
--- trunk/psLib/src/math/psPolynomial.h	(revision 9720)
+++ trunk/psLib/src/math/psPolynomial.h	(revision 9730)
@@ -11,6 +11,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.63 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-30 02:20:06 $
+ *  @version $Revision: 1.64 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -45,16 +45,4 @@
     float sigma,                       ///< Standard deviation for the Gaussian
     bool normal                        ///< Indicates whether result should be normalized
-);
-
-/** Produce a vector of random numbers from a Gaussian distribution with
- *  the specified mean and sigma
- *
- *  @return psVector*    vector of random numbers
- *
- */
-psVector* p_psGaussianDev(
-    psF32 mean,                        ///< The mean of the Gaussian
-    psF32 sigma,                       ///< The sigma of the Gaussian
-    unsigned int Npts                  ///< The size of the vector
 );
 
Index: trunk/psLib/src/math/psSparse.c
===================================================================
--- trunk/psLib/src/math/psSparse.c	(revision 9720)
+++ trunk/psLib/src/math/psSparse.c	(revision 9730)
@@ -35,17 +35,12 @@
     psMemSetDeallocator(sparse, (psFreeFunc)sparseFree);
 
-    sparse->Aij = psVectorAlloc(Nelem, PS_DATA_F32);
-    sparse->Si  = psVectorAlloc(Nelem, PS_DATA_S32);
-    sparse->Sj  = psVectorAlloc(Nelem, PS_DATA_S32);
-
-    sparse->Aij->n = 0;
-    sparse->Si->n  = 0;
-    sparse->Sj->n  = 0;
+    sparse->Aij = psVectorAllocEmpty(Nelem, PS_DATA_F32);
+    sparse->Si  = psVectorAllocEmpty(Nelem, PS_DATA_S32);
+    sparse->Sj  = psVectorAllocEmpty(Nelem, PS_DATA_S32);
+
     sparse->Nelem = 0;
 
     sparse->Bfj = psVectorAlloc(Nrows, PS_DATA_F32);
     sparse->Qii = psVectorAlloc(Nrows, PS_DATA_F32);
-    sparse->Bfj->n = Nrows;
-    sparse->Qii->n = Nrows;
 
     sparse->Nrows = Nrows;
@@ -157,5 +152,4 @@
     // temporary storage for intermediate results
     psVector *dQ = psVectorAlloc(output->n, PS_DATA_F32);
-    dQ->n = output->n;
 
     for (int j = 0; j < Niter; j++) {
@@ -197,5 +191,4 @@
     psVector *tSi  = psVectorAlloc(Nelem, PS_DATA_S32);
     psVector *tSj  = psVectorAlloc(Nelem, PS_DATA_S32);
-    tAij->n = tSi->n = tSj->n = Nelem;
 
     for (int i = 0; i < Nelem; i++) {
Index: trunk/psLib/src/math/psSpline.c
===================================================================
--- trunk/psLib/src/math/psSpline.c	(revision 9720)
+++ trunk/psLib/src/math/psSpline.c	(revision 9730)
@@ -6,6 +6,6 @@
 *  This file contains the routines that allocate, free, and evaluate splines.
 *
-*  @version $Revision: 1.155 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-13 22:04:58 $
+*  @version $Revision: 1.156 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-24 22:52:56 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -239,10 +239,8 @@
             for (psS32 i = 0 ; i < x->n ; i++) {
                 spline->knots->data.F32[i] = x->data.F32[i];
-                spline->knots->n++;
             }
         } else if (x->type.type == PS_TYPE_F64) {
             for (psS32 i = 0 ; i < x->n ; i++) {
                 spline->knots->data.F32[i] = (psF32) x->data.F64[i];
-                spline->knots->n++;
             }
         }
@@ -250,5 +248,4 @@
         for (psS32 i = 0 ; i < y->n ; i++) {
             spline->knots->data.F32[i] = (psF32) i;
-            spline->knots->n++;
         }
     }
@@ -415,10 +412,8 @@
         for (psS32 i=0;i<x->n;i++) {
             tmpVector->data.F32[i] = psSpline1DEval(spline, x->data.F32[i]);
-            tmpVector->n++;
         }
     } else if (x->type.type == PS_TYPE_F64) {
         for (psS32 i=0;i<x->n;i++) {
             tmpVector->data.F32[i] = psSpline1DEval(spline, (psF32) x->data.F64[i]);
-            tmpVector->n++;
         }
     }
Index: trunk/psLib/src/math/psStats.c
===================================================================
--- trunk/psLib/src/math/psStats.c	(revision 9720)
+++ trunk/psLib/src/math/psStats.c	(revision 9730)
@@ -16,6 +16,6 @@
  * use ->min and ->max (PS_STAT_USE_RANGE)
  *
- *  @version $Revision: 1.187 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 22:04:58 $
+ *  @version $Revision: 1.188 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -388,5 +388,5 @@
 
     // Allocate temporary vectors for the data.
-    psVector* vector = psVectorAlloc(myVector->n, PS_TYPE_F32); // Vector containing the unmasked values
+    psVector* vector = psVectorAllocEmpty(myVector->n, PS_TYPE_F32); // Vector containing the unmasked values
     long count = 0;                     // Number of valid entries
 
@@ -486,5 +486,4 @@
     long numBins = histogram->nums->n;  // Number of histogram bins
     psVector *smooth = psVectorAlloc(numBins, PS_TYPE_F32); // Smoothed version of histogram bins
-    smooth->n = smooth->nalloc;
     const psVector *bounds = histogram->bounds; // The bounds for the histogram bins
 
@@ -723,5 +722,4 @@
     // We copy the mask vector, to preserve the original
     psVector *tmpMask = psVectorAlloc(myVector->n, PS_TYPE_U8);
-    tmpMask->n = tmpMask->nalloc;
     psVectorInit(tmpMask, 0);
     if (maskVector) {
@@ -901,6 +899,4 @@
     psVector *x = psVectorAlloc(3, PS_TYPE_F64);
     psVector *y = psVectorAlloc(3, PS_TYPE_F64);
-    x->n = 3;
-    y->n = 3;
     psF32 tmpFloat = 0.0f;
 
@@ -1066,5 +1062,4 @@
 
     psVector *mask = psVectorAlloc(myVector->n, PS_TYPE_MASK); // The actual mask we will use
-    mask->n = myVector->n;
     psVectorInit(mask, 0);
     if (maskVector) {
@@ -1487,10 +1482,7 @@
         psVector *y = psVectorAlloc((1 + (binMax - binMin)), PS_TYPE_F32); // Vector of coordinates
         psArray *x = psArrayAlloc((1 + (binMax - binMin))); // Array of ordinates
-        y->n = y->nalloc;
-        x->n = x->nalloc;
         for (long i = binMin, j = 0; i <= binMax ; i++, j++) {
             y->data.F32[j] = smoothed->data.F32[i];
             psVector *ordinate = psVectorAlloc(1, PS_TYPE_F32); // The ordinate value
-            ordinate->n = 1;
             ordinate->data.F32[0] = PS_BIN_MIDPOINT(histogram, i);
             x->data[j] = ordinate;
@@ -1521,5 +1513,4 @@
         psMinimization *minimizer = psMinimizationAlloc(100, 0.01); // The minimizer information
         psVector *params = psVectorAlloc(2, PS_TYPE_F32); // Parameters for the Gaussian
-        params->n = params->nalloc;
         // Initial guess for the mean (index 0) and standard dev (index 1).
         params->data.F32[0] = stats->robustMedian;
@@ -1654,5 +1645,4 @@
     psVector* newBounds = psVectorAlloc(n + 1, PS_TYPE_F32);
     newHist->bounds = newBounds;
-    newBounds->n = newHist->bounds->nalloc;
 
     // Calculate the bounds for each bin.
@@ -1666,8 +1656,5 @@
     // Allocate the bins, and initialize them to zero.
     newHist->nums = psVectorAlloc(n, PS_TYPE_F32);
-    for (long i = 0; i < newHist->nums->nalloc; i++) {
-        newHist->nums->data.F32[i] = 0.0;
-        newHist->nums->n++;
-    }
+    psVectorInit(newHist->nums, 0.0);
 
     // Initialize the other members.
@@ -1699,18 +1686,11 @@
     psHistogram *newHist = (psHistogram* ) psAlloc(sizeof(psHistogram)); // The new histogram structure
     psMemSetDeallocator(newHist, (psFreeFunc) histogramFree);
-    psVector* newBounds = psVectorAlloc(bounds->n, PS_TYPE_F32);
+    psVector* newBounds = psVectorCopy(NULL, bounds, PS_TYPE_F32);
     newHist->bounds = newBounds;
-    newBounds->n = newHist->bounds->nalloc;
-    for (long i = 0; i < bounds->n; i++) {
-        newBounds->data.F32[i] = bounds->data.F32[i];
-    }
 
     // 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_F32);
-    for (long i = 0; i < newHist->nums->nalloc; i++) {
-        newHist->nums->data.F32[i] = 0.0;
-        newHist->nums->n++;
-    }
+    psVectorInit(newHist->nums, 0.0);
 
     // Initialize the other members.
Index: trunk/psLib/src/mathtypes/psVector.c
===================================================================
--- trunk/psLib/src/mathtypes/psVector.c	(revision 9720)
+++ trunk/psLib/src/mathtypes/psVector.c	(revision 9730)
@@ -9,6 +9,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.86 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-14 00:12:39 $
+*  @version $Revision: 1.87 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-24 22:52:56 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -68,11 +68,10 @@
 
 
-psVector* psVectorAlloc(long nalloc,
-                        psElemType type)
-{
-    psVector* psVec = NULL;
-    psS32 elementSize = 0;
-
-    elementSize = PSELEMTYPE_SIZEOF(type);
+// Allocate a psVector; does not set vector->n (left to the caller)
+static psVector *vectorAlloc(long nalloc, // Number of elements to allocate
+                             psElemType type // Type of elements
+                            )
+{
+    int elementSize = PSELEMTYPE_SIZEOF(type); // Size, in bytes, of element
     if (elementSize < 1) {
         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
@@ -81,19 +80,38 @@
     }
 
-
     // Create vector struct
-    psVec = (psVector* ) psAlloc(sizeof(psVector));
-    psMemSetDeallocator(psVec, (psFreeFunc) vectorFree);
-
-    psVec->type.dimen = PS_DIMEN_VECTOR;
-    psVec->type.type = type;
-    P_PSVECTOR_SET_NALLOC(psVec,nalloc);
-    //    psVec->n = nalloc;
-    psVec->n = 0;
+    psVector *vector = (psVector*) psAlloc(sizeof(psVector));
+    psMemSetDeallocator(vector, (psFreeFunc) vectorFree);
+
+    vector->type.dimen = PS_DIMEN_VECTOR;
+    vector->type.type = type;
+    P_PSVECTOR_SET_NALLOC(vector, nalloc);
 
     // Create vector data array
-    psVec->data.U8 = psAlloc(nalloc * elementSize);
-
-    return psVec;
+    vector->data.U8 = psAlloc(nalloc * elementSize);
+
+    return vector;
+}
+
+psVector* psVectorAlloc(long nalloc,
+                        psElemType type)
+{
+    psVector *vector = vectorAlloc(nalloc, type);
+    if (!vector) {
+        return NULL;
+    }
+    vector->n = nalloc;
+    return vector;
+}
+
+psVector* psVectorAllocEmpty(long nalloc,
+                             psElemType type)
+{
+    psVector *vector = vectorAlloc(nalloc, type);
+    if (!vector) {
+        return NULL;
+    }
+    vector->n = 0;
+    return vector;
 }
 
Index: trunk/psLib/src/mathtypes/psVector.h
===================================================================
--- trunk/psLib/src/mathtypes/psVector.h	(revision 9720)
+++ trunk/psLib/src/mathtypes/psVector.h	(revision 9730)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-14 00:07:13 $
+ *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -74,5 +74,5 @@
         ;
 
-/** Allocate a vector.
+/** Allocate a vector, with length set to number allocated
  *
  *  Uses psLib memory allocation functions to create a vector collection of
@@ -82,4 +82,16 @@
  */
 psVector* psVectorAlloc(
+    long nalloc,                       ///< Total number of elements to make available.
+    psElemType type                    ///< Type of data to be held by vector.
+);
+
+/** Allocate a vector, with length set to zero
+ *
+ *  Uses psLib memory allocation functions to create a vector collection of
+ *  data as defined by the psType type.
+ *
+ * @return psVector*    Pointer to psVector.
+ */
+psVector* psVectorAllocEmpty(
     long nalloc,                       ///< Total number of elements to make available.
     psElemType type                    ///< Type of data to be held by vector.
Index: trunk/psLib/src/sys/psError.c
===================================================================
--- trunk/psLib/src/sys/psError.c	(revision 9720)
+++ trunk/psLib/src/sys/psError.c	(revision 9730)
@@ -11,6 +11,6 @@
  *  @author Eric Van Alst, MHPCC
  *
- *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-18 15:26:33 $
+ *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -84,5 +84,5 @@
     if ((errorStack = pthread_getspecific(errorStack_key)) == NULL) {
         // allocate the error stack
-        errorStack = psArrayAlloc(MAX_ERROR_STACK_SIZE);
+        errorStack = psArrayAllocEmpty(MAX_ERROR_STACK_SIZE);
         p_psMemSetPersistent(errorStack, true);
         p_psMemSetPersistent(errorStack->data, true);
Index: trunk/psLib/src/types/psArray.c
===================================================================
--- trunk/psLib/src/types/psArray.c	(revision 9720)
+++ trunk/psLib/src/types/psArray.c	(revision 9730)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 22:24:29 $
+ *  @version $Revision: 1.57 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -49,4 +49,24 @@
 }
 
+// Allocate an array, deliberately leave size unset.
+static psArray *arrayAlloc(long nalloc)
+{
+    if (nalloc < 0) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "Can't allocate a psArray of negative size.");
+        return NULL;
+    }
+
+    // Create vector struct
+    psArray *array = (psArray*)psAlloc(sizeof(psArray));
+    psMemSetDeallocator(array, (psFreeFunc)arrayFree);
+
+    P_PSARRAY_SET_NALLOC(array, nalloc);
+    // Create vector data array
+    array->data = psAlloc(nalloc * sizeof(psPtr));
+    memset(array->data, 0, sizeof(void*) * nalloc);  //set the initial values of data to NULL
+
+    return array;
+}
 
 /*****************************************************************************
@@ -55,22 +75,20 @@
 psArray* psArrayAlloc(long nalloc)
 {
-    if (nalloc < 0) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                "Can't allocate a psArray of negative size.");
-        return NULL;
-    }
-    psArray* psArr = NULL;
-
-    // Create vector struct
-    psArr = (psArray* ) psAlloc(sizeof(psArray));
-    psMemSetDeallocator(psArr, (psFreeFunc) arrayFree);
-
-    P_PSARRAY_SET_NALLOC(psArr,nalloc);
-    psArr->n = 0;  //set the initial number of elements in use to 0
-    // Create vector data array
-    psArr->data = psAlloc(nalloc * sizeof(psPtr));
-    memset(psArr->data, 0, sizeof(void*) * nalloc);  //set the initial values of data to NULL
-
-    return psArr;
+    psArray *array = arrayAlloc(nalloc);
+    if (!array) {
+        return NULL;
+    }
+    array->n = nalloc;
+    return array;
+}
+
+psArray* psArrayAllocEmpty(long nalloc)
+{
+    psArray *array = arrayAlloc(nalloc);
+    if (!array) {
+        return NULL;
+    }
+    array->n = 0;
+    return array;
 }
 
Index: trunk/psLib/src/types/psArray.h
===================================================================
--- trunk/psLib/src/types/psArray.h	(revision 9720)
+++ trunk/psLib/src/types/psArray.h	(revision 9730)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 22:24:29 $
+ *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -60,5 +60,5 @@
 
 
-/** Allocate an array.
+/** Allocate an array, set the length to the number of allocated elements
  *
  * Uses psLib memory allocation functions to create an array collection of
@@ -69,4 +69,16 @@
  */
 psArray* psArrayAlloc(
+    long nalloc                        ///< Total number of elements to make available.
+);
+
+/** Allocate an array, set the length to zero.
+ *
+ * Uses psLib memory allocation functions to create an array collection of
+ * data
+ *
+ * @return psArray* : Pointer to psArray.
+ *
+ */
+psArray* psArrayAllocEmpty(
     long nalloc                        ///< Total number of elements to make available.
 );
Index: trunk/psLib/src/types/psHash.c
===================================================================
--- trunk/psLib/src/types/psHash.c	(revision 9720)
+++ trunk/psLib/src/types/psHash.c	(revision 9730)
@@ -12,6 +12,6 @@
 *  @author GLG, MHPCC
 *
-*  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-13 21:13:48 $
+*  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-24 22:52:56 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -433,5 +433,4 @@
 
     psArray* result = psArrayAlloc(nElements);
-    result->n = nElements;
 
     // now fill in the array with the hash hash's data
Index: trunk/psLib/src/types/psList.c
===================================================================
--- trunk/psLib/src/types/psList.c	(revision 9720)
+++ trunk/psLib/src/types/psList.c	(revision 9730)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.55 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 21:13:48 $
+ *  @version $Revision: 1.56 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -25,4 +25,6 @@
 #define ITER_INIT_HEAD ((psPtr )1)         // next iteration should return head
 #define ITER_INIT_TAIL ((psPtr )2)         // next iteration should return tail
+
+#define INITIAL_NUM_ITERATORS 16        // Initial number of iterators to create
 
 // private functions.
@@ -125,6 +127,5 @@
     list->n = 0;
     list->head = list->tail = NULL;
-    list->iterators = psArrayAlloc(16);
-    list->iterators->n = 0;
+    list->iterators = psArrayAllocEmpty(INITIAL_NUM_ITERATORS);
 
     // create a default iterator
@@ -564,24 +565,10 @@
 psArray* psListToArray(const psList* list)
 {
-    psListElem* ptr;
-    psU32 n;
-    psArray* arr;
-
-    if (list == NULL) {
-        return NULL;
-    }
-
-    //XXX: Following is unnecessary as a list->n = 0 should do ArrayAlloc(0) I believe.
-    /*    if (list->n > 0) {
-            arr = psArrayAlloc(list->n);
-        } else {
-            arr = psArrayAlloc(1);
-        }
-    */
-    arr = psArrayAlloc(list->n);
-    arr->n = list->n;
-
-    ptr = list->head;
-    n = list->n;
+    PS_ASSERT_PTR_NON_NULL(list, NULL);
+
+    long n = list->n;
+    psArray *arr = psArrayAlloc(n);
+
+    psListElem *ptr = list->head;
     for (psS32 i = 0; i < n; i++) {
         arr->data[i] = psMemIncrRefCounter(ptr->data);
Index: trunk/psLib/src/types/psLookupTable.c
===================================================================
--- trunk/psLib/src/types/psLookupTable.c	(revision 9720)
+++ trunk/psLib/src/types/psLookupTable.c	(revision 9730)
@@ -7,6 +7,6 @@
 *  @author Ross Harman, MHPCC
 *
-*  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-22 00:51:05 $
+*  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-24 22:52:56 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
@@ -36,5 +36,5 @@
 #define MAX_STRING_LENGTH   256
 #define ARRAY_STRIDE        16
-
+#define INITIAL_NUM         10          // Initial number of elements
 /******************************************************************************/
 /*  TYPE DEFINITIONS                                                          */
@@ -449,6 +449,5 @@
 
     // Create output array and set array elements to zero
-    outputArray = psArrayAlloc(10);
-    outputArray->n = 0;
+    outputArray = psArrayAllocEmpty(INITIAL_NUM);
 
     // Parse the format string to determine how many vectors
@@ -629,5 +628,4 @@
     // Check if array is sorted on the index column
     psVector* sortedIndex = psVectorAlloc(numRows,PS_TYPE_U32);
-    sortedIndex->n = numRows;
     sortedIndex = psVectorSortIndex(sortedIndex,indexColumnVector);
     for(psS32 i = 0; i < numRows; i++ ) {
@@ -645,6 +643,4 @@
             psS32 type = ((psVector*)(vectors->data[j]))->type.type;
             newValueArray->data[j] = psVectorAlloc(numRows,type);
-            ((psVector*)(newValueArray->data[j]))->n = numRows;
-            newValueArray->n++;
         }
 
Index: trunk/psLib/src/types/psMetadataConfig.c
===================================================================
--- trunk/psLib/src/types/psMetadataConfig.c	(revision 9720)
+++ trunk/psLib/src/types/psMetadataConfig.c	(revision 9730)
@@ -10,6 +10,6 @@
 *  @author Eric Van Alst, MHPCC
 *
-*  @version $Revision: 1.95 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2006-10-24 01:15:47 $
+*  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2006-10-24 22:52:56 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -47,4 +47,5 @@
 /** Maximum size of a string */
 #define MAX_STRING_LENGTH 1024
+#define INITIAL_LENGTH 10               // Initial length for arrays
 
 /******************************************************************************/
@@ -73,9 +74,24 @@
 static psMetadata* setMetadataItem(psMetadata* template, char* linePtr)
 ;
-static void parseLevelInfoFree(p_psParseLevelInfo* info);
-static psBool parseLine(psS32* level,   psArray* levelArray, char*  linePtr, psS32 lineCount, psBool overwrite);
-static psBool parseMetadataItem(char* keyName, psS32* level, psArray* levelArray, char* linePtr, psS32 lineCount, psMetadataFlags flags);
+static psBool parseLine(psS32* level,   psArray* levelArray, char*  linePtr,
+                        psS32 lineCount, psBool overwrite);
+static psBool parseMetadataItem(char* keyName, psS32* level, psArray* levelArray,
+                                char* linePtr, psS32 lineCount, psMetadataFlags flags);
 static psString formatMetadataItem(psMetadataItem *item);
 static psArray *p_psMetadataKeyArray(psMetadata *md);
+
+
+// A metadata data structure used in parsing arrays.
+// Contains array information and the metadata storage location.
+typedef struct
+{
+    psArray*    nonUniqueKeyArray;     ///< non-unique key names
+    psArray*    typeArray;             ///< array of user defined types
+    psArray*    templateArray;         ///< array of user type templates
+    psMetadata* metadata;              ///< metadata container
+    char*       name;                  ///< name of key
+}
+p_psParseLevelInfo;
+
 static void parseLevelInfoFree(p_psParseLevelInfo* info)
 {
@@ -85,4 +101,19 @@
     psFree(info->name);
     psFree(info->metadata);
+}
+
+static p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)
+{
+    // Allocate memory for parse level info
+    p_psParseLevelInfo *info = (p_psParseLevelInfo*)psAlloc(sizeof(p_psParseLevelInfo));
+    psMemSetDeallocator(info,(psFreeFunc)parseLevelInfoFree);
+
+    info->nonUniqueKeyArray = psArrayAllocEmpty(INITIAL_LENGTH);
+    info->typeArray = psArrayAllocEmpty(INITIAL_LENGTH);
+    info->templateArray = psArrayAllocEmpty(INITIAL_LENGTH);
+    info->metadata = NULL;
+    info->name = NULL;
+
+    return info;
 }
 
@@ -350,5 +381,5 @@
         inString = saveValue;
         end = NULL;
-        vec = psVectorAlloc(numValues, elemType);
+        vec = psVectorAllocEmpty(numValues, elemType);
 
         while(*inString!='\0') {
@@ -406,33 +437,8 @@
 }
 
+
 /*****************************************************************************/
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
 /*****************************************************************************/
-
-p_psParseLevelInfo* p_psParseLevelInfoAlloc(void)
-{
-
-    p_psParseLevelInfo* info = NULL;
-
-    // Allocate memory for parse level info
-    info = (p_psParseLevelInfo*)psAlloc(sizeof(p_psParseLevelInfo));
-
-    // If allocation successful then initialize members
-    if(info != NULL) {
-
-        info->nonUniqueKeyArray = psArrayAlloc(10);
-
-        info->typeArray = psArrayAlloc(10);
-
-        info->templateArray = psArrayAlloc(10);
-
-        info->metadata = NULL;
-        info->name = NULL;
-
-        // Set memory deallocator
-        psMemSetDeallocator(info,(psFreeFunc)parseLevelInfoFree);
-    }
-    return info;
-}
 
 bool psMetadataItemPrint(FILE * fd,
@@ -1220,5 +1226,5 @@
 
     // Allocate array to store parse level information
-    parseLevelInfoArray = psArrayAlloc(10);
+    parseLevelInfoArray = psArrayAllocEmpty(INITIAL_LENGTH);
 
     // Set parse level info for the top level
@@ -1522,5 +1528,5 @@
     PS_ASSERT_PTR_NON_NULL(md, NULL);
 
-    psArray *keys = psArrayAlloc(psListLength(md->list));
+    psArray *keys = psArrayAllocEmpty(psListLength(md->list));
 
     // since we want to preserve the order of the keys in the metadata we can't
Index: trunk/psLib/src/types/psMetadataConfig.h
===================================================================
--- trunk/psLib/src/types/psMetadataConfig.h	(revision 9720)
+++ trunk/psLib/src/types/psMetadataConfig.h	(revision 9730)
@@ -10,6 +10,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-24 01:15:47 $
+ *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-10-24 22:52:56 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -22,24 +22,4 @@
 /// @addtogroup Metadata
 /// @{
-
-/** A metadata data structure used in parsing arrays.
- *
- *  Contains array information and the metadata storage location.
-*/
-typedef struct
-{
-    psArray*    nonUniqueKeyArray;     ///< non-unique key names
-    psArray*    typeArray;             ///< array of user defined types
-    psArray*    templateArray;         ///< array of user type templates
-    psMetadata* metadata;              ///< metadata container
-    char*       name;                  ///< name of key
-}
-p_psParseLevelInfo;
-
-/** Allocates a p_psParseLevelInfo structure
- *
- *  @return p_psParseLevelInfo* :   new p_psParseLevelInfo struct
- */
-p_psParseLevelInfo* p_psParseLevelInfoAlloc(void);
 
 /** Print metadata item to file.
