Index: /trunk/psLib/src/collections/psVector.c
===================================================================
--- /trunk/psLib/src/collections/psVector.c	(revision 1359)
+++ /trunk/psLib/src/collections/psVector.c	(revision 1360)
@@ -1,16 +1,16 @@
 /** @file  psVector.c
- *
- *  @brief Contains support for basic vector types
- *
- *  This file defines the basic type for a vector struct and functions useful
- *  in manupulating vectors.
- *
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-28 00:06:13 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
+*
+*  @brief Contains support for basic vector types
+*
+*  This file defines the basic type for a vector struct and functions useful
+*  in manupulating vectors.
+*
+*  @author Ross Harman, MHPCC
+*
+*  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-07-31 02:28:10 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
 
 /******************************************************************************/
@@ -54,99 +54,99 @@
 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
 /*****************************************************************************/
-static void vectorFree(psVector *restrict psVec);
+static void vectorFree( psVector *restrict psVec );
 
 /*****************************************************************************/
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
 /*****************************************************************************/
-psVector* psVectorAlloc(unsigned int nalloc, psElemType elemType)
-{
-    psVector *psVec = NULL;
+psVector* psVectorAlloc( unsigned int nalloc, psElemType elemType )
+{
+    psVector * psVec = NULL;
     int elementSize = 0;
-
+    
     // Invalid nalloc
-    if(nalloc < 1) {
-        psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);
-        return NULL;
-    }
-
-    elementSize = PSELEMTYPE_SIZEOF(elemType);
-
+    if ( nalloc < 1 ) {
+            psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
+            return NULL;
+        }
+        
+    elementSize = PSELEMTYPE_SIZEOF( elemType );
+    
     // Create vector struct
-    psVec = (psVector *)psAlloc(sizeof(psVector));
-    p_psMemSetDeallocator(psVec,(psFreeFcn)vectorFree);
-
+    psVec = ( psVector * ) psAlloc( sizeof( psVector ) );
+    p_psMemSetDeallocator( psVec, ( psFreeFcn ) vectorFree );
+    
     psVec->type.dimen = PS_DIMEN_VECTOR;
     psVec->type.type = elemType;
     psVec->nalloc = nalloc;
     psVec->n = nalloc;
-
+    
     // Create vector data array
-    psVec->data.V = psAlloc(nalloc*elementSize);
-
+    psVec->data.V = psAlloc( nalloc * elementSize );
+    
     return psVec;
 }
 
-psVector *psVectorRealloc(unsigned int nalloc, psVector *restrict in)
+psVector *psVectorRealloc( unsigned int nalloc, psVector *restrict in )
 {
     int elementSize = 0;
     psElemType elemType;
-
+    
     // Invalid nalloc
-    if(nalloc < 1) {
-        psError(__func__, "Invalid value for realloc (%d)\n", nalloc);
-        return NULL;
-    }
-
-    if(in == NULL) {
-        psError(__func__, "Null input vector\n");
-        return NULL;
-    } else if(in->nalloc != nalloc) {                    // No need to realloc to same size
-        elemType = in->type.type;
-        elementSize = PSELEMTYPE_SIZEOF(elemType);
-        if(nalloc < in->n) {
-            in->n = nalloc;
-        }
-
-        // Realloc after decrementation to avoid accessing freed array elements
-        in->data.V = psRealloc(in->data.V,nalloc*elementSize);
-        in->nalloc = nalloc;
-    }
-
+    if ( nalloc < 1 ) {
+            psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
+            return NULL;
+        }
+        
+    if ( in == NULL ) {
+            psError( __func__, "Null input vector\n" );
+            return NULL;
+        } else if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
+            elemType = in->type.type;
+            elementSize = PSELEMTYPE_SIZEOF( elemType );
+            if ( nalloc < in->n ) {
+                    in->n = nalloc;
+                }
+                
+            // Realloc after decrementation to avoid accessing freed array elements
+            in->data.V = psRealloc( in->data.V, nalloc * elementSize );
+            in->nalloc = nalloc;
+        }
+        
     return in;
 }
 
-psVector *psVectorRecycle(psVector *restrict in, psElemType type, unsigned int nalloc)
+psVector *psVectorRecycle( psVector *restrict in, psElemType type, unsigned int nalloc )
 {
     psElemType elemType;
-
-    if (in == NULL) {
-        return psVectorAlloc(nalloc, type);
-    }
-
+    
+    if ( in == NULL ) {
+            return psVectorAlloc( nalloc, type );
+        }
+        
     elemType = in->type.type;
-
-    if (in->nalloc == nalloc && elemType == type) {
-        // it is proper size/type already
-        return in;
-    }
-
+    
+    if ( in->nalloc == nalloc && elemType == type ) {
+            // it is proper size/type already
+            return in;
+        }
+        
     // Invalid nalloc
-    if(nalloc < 1) {
-        psError(__func__, "Invalid value for nalloc (%d)\n", nalloc);
-        psFree(in);
-        return NULL;
-    }
-
-
-    in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(type));
-
-    in->n = 0;
+    if ( nalloc < 1 ) {
+            psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
+            psFree( in );
+            return NULL;
+        }
+        
+        
+    in->data.V = psRealloc( in->data.V, nalloc * PSELEMTYPE_SIZEOF( type ) );
+    
     in->type.type = type;
     in->nalloc = nalloc;
-
+    in->n = nalloc;
+    
     return in;
 }
 
-psVector *psVectorSort(psVector *restrict outVector, const psVector *restrict inVector)
+psVector *psVectorSort( psVector *restrict outVector, const psVector *restrict inVector )
 {
     int inN = 0;
@@ -156,84 +156,84 @@
     void *outVec = NULL;
     psElemType inType = 0;
-
-    if(inVector == NULL) {
-        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
-        return outVector;
-    }
-
+    
+    if ( inVector == NULL ) {
+            psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
+            return outVector;
+        }
+        
     inType = inVector->type.type;
     inN = inVector->n;
     inVec = inVector->data.V;
-    elSize = PSELEMTYPE_SIZEOF(inType);
-
-    if(outVector == NULL) {
-        outVector = psVectorAlloc(inN, inType);
-        outVector->n = inVector->n;
-    }
-
+    elSize = PSELEMTYPE_SIZEOF( inType );
+    
+    if ( outVector == NULL ) {
+            outVector = psVectorAlloc( inN, inType );
+            outVector->n = inVector->n;
+        }
+        
     outN = outVector->n;
     outVec = outVector->data.V;
-
-    if(inN != outN) {
-        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
-                inN, outN);
-        return outVector;
-    }
-
-    if(inType != outVector->type.type) {
-        psError(__func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
-                inType, outVector->type.type);
-        return outVector;
-    }
-
-    if(inN == 0) {
-        psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__);
-        return outVector;
-    }
-
-    if(outN == 0) {
-        psError(__func__, " : Line %d - No elements in use for output vector\n", __LINE__);
-        return outVector;
-    }
-
+    
+    if ( inN != outN ) {
+            psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
+                     inN, outN );
+            return outVector;
+        }
+        
+    if ( inType != outVector->type.type ) {
+            psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
+                     inType, outVector->type.type );
+            return outVector;
+        }
+        
+    if ( inN == 0 ) {
+            psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
+            return outVector;
+        }
+        
+    if ( outN == 0 ) {
+            psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
+            return outVector;
+        }
+        
     // Copy input vector values into output vector
-    memcpy(outVec, inVec, elSize*outN);
-
+    memcpy( outVec, inVec, elSize * outN );
+    
     // Sort output vector
-    switch(inType) {
-    case PS_TYPE_U8:
-        qsort(outVec, inN, elSize, psCompareU8);
-        break;
-    case PS_TYPE_U16:
-        qsort(outVec, inN, elSize, psCompareU16);
-        break;
-    case PS_TYPE_U32:
-        qsort(outVec, inN, elSize, psCompareU32);
-        break;
-    case PS_TYPE_U64:
-        qsort(outVec, inN, elSize, psCompareU64);
-        break;
-    case PS_TYPE_S8:
-        qsort(outVec, inN, elSize, psCompareS8);
-        break;
-    case PS_TYPE_S16:
-        qsort(outVec, inN, elSize, psCompareS16);
-        break;
-    case PS_TYPE_S32:
-        qsort(outVec, inN, elSize, psCompareS32);
-        break;
-    case PS_TYPE_S64:
-        qsort(outVec, inN, elSize, psCompareS64);
-        break;
-    case PS_TYPE_F32:
-        qsort(outVec, inN, elSize, psCompareF32);
-        break;
-    case PS_TYPE_F64:
-        qsort(outVec, inN, elSize, psCompareF64);
-        break;
-    default:
-        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
-    }
-
+    switch ( inType ) {
+            case PS_TYPE_U8:
+            qsort( outVec, inN, elSize, psCompareU8 );
+            break;
+            case PS_TYPE_U16:
+            qsort( outVec, inN, elSize, psCompareU16 );
+            break;
+            case PS_TYPE_U32:
+            qsort( outVec, inN, elSize, psCompareU32 );
+            break;
+            case PS_TYPE_U64:
+            qsort( outVec, inN, elSize, psCompareU64 );
+            break;
+            case PS_TYPE_S8:
+            qsort( outVec, inN, elSize, psCompareS8 );
+            break;
+            case PS_TYPE_S16:
+            qsort( outVec, inN, elSize, psCompareS16 );
+            break;
+            case PS_TYPE_S32:
+            qsort( outVec, inN, elSize, psCompareS32 );
+            break;
+            case PS_TYPE_S64:
+            qsort( outVec, inN, elSize, psCompareS64 );
+            break;
+            case PS_TYPE_F32:
+            qsort( outVec, inN, elSize, psCompareF32 );
+            break;
+            case PS_TYPE_F64:
+            qsort( outVec, inN, elSize, psCompareF64 );
+            break;
+            default:
+            psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
+        }
+        
     return outVector;
 }
@@ -241,14 +241,14 @@
 #define SORT_INDICES(TYPE)                                                                                   \
 for(i=0; i<inN; i++) {                                                                                       \
-    for(j=0; j<inN; j++) {                                                                                   \
-        diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
-        if(diff < FLT_EPSILON) {                                                                             \
-            outVec[i] = j;                                                                                   \
-            break;                                                                                           \
-        }                                                                                                    \
-    }                                                                                                        \
-}
-
-psVector *psVectorSortIndex(psVector *restrict outVector, const psVector *restrict inVector)
+        for(j=0; j<inN; j++) {                                                                                   \
+                diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
+                if(diff < FLT_EPSILON) {                                                                             \
+                        outVec[i] = j;                                                                                   \
+                        break;                                                                                           \
+                    }                                                                                                    \
+            }                                                                                                        \
+    }
+    
+psVector *psVectorSortIndex( psVector *restrict outVector, const psVector *restrict inVector )
 {
     int inN = 0;
@@ -261,86 +261,86 @@
     psVector *tmpVector = NULL;
     psElemType inType = 0;
-
-    if(inVector == NULL) {
-        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
-        return outVector;
-    }
-
+    
+    if ( inVector == NULL ) {
+            psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
+            return outVector;
+        }
+        
     inN = inVector->n;
     inVec = inVector->data.V;
     inType = inVector->type.type;
-
-    if(outVector == NULL) {
-        outVector = psVectorAlloc(inN, PS_TYPE_U32);
-        outVector->n = inN;
-    }
-
+    
+    if ( outVector == NULL ) {
+            outVector = psVectorAlloc( inN, PS_TYPE_U32 );
+            outVector->n = inN;
+        }
+        
     outN = outVector->n;
     outVec = outVector->data.V;
-
-    if(inN != outN) {
-        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
-                __LINE__, inN, outN);
-        return outVector;
-    }
-
-    if(outVector->type.type != PS_TYPE_U32) {
-        psError(__func__, " : Line %d - Output vector is not of type U32: out=%d\n",
-                __LINE__, outVector->type.type);
-        return outVector;
-    }
-
-    tmpVector = psVectorAlloc(inN, inType);
+    
+    if ( inN != outN ) {
+            psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
+                     __LINE__, inN, outN );
+            return outVector;
+        }
+        
+    if ( outVector->type.type != PS_TYPE_U32 ) {
+            psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",
+                     __LINE__, outVector->type.type );
+            return outVector;
+        }
+        
+    tmpVector = psVectorAlloc( inN, inType );
     tmpVector->n = inN;
-    tmpVector = psVectorSort(tmpVector, inVector);
-
+    tmpVector = psVectorSort( tmpVector, inVector );
+    
     // Sort output vector
-    switch(inType) {
-    case PS_TYPE_U8:
-        SORT_INDICES(U8);
-        break;
-    case PS_TYPE_U16:
-        SORT_INDICES(U16);
-        break;
-    case PS_TYPE_U32:
-        SORT_INDICES(U32);
-        break;
-    case PS_TYPE_U64:
-        SORT_INDICES(U64);
-        break;
-    case PS_TYPE_S8:
-        SORT_INDICES(S8);
-        break;
-    case PS_TYPE_S16:
-        SORT_INDICES(S16);
-        break;
-    case PS_TYPE_S32:
-        SORT_INDICES(S32);
-        break;
-    case PS_TYPE_S64:
-        SORT_INDICES(S64);
-        break;
-    case PS_TYPE_F32:
-        SORT_INDICES(F32);
-        break;
-    case PS_TYPE_F64:
-        SORT_INDICES(F64);
-        break;
-    default:
-        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
-    }
-
+    switch ( inType ) {
+            case PS_TYPE_U8:
+            SORT_INDICES( U8 );
+            break;
+            case PS_TYPE_U16:
+            SORT_INDICES( U16 );
+            break;
+            case PS_TYPE_U32:
+            SORT_INDICES( U32 );
+            break;
+            case PS_TYPE_U64:
+            SORT_INDICES( U64 );
+            break;
+            case PS_TYPE_S8:
+            SORT_INDICES( S8 );
+            break;
+            case PS_TYPE_S16:
+            SORT_INDICES( S16 );
+            break;
+            case PS_TYPE_S32:
+            SORT_INDICES( S32 );
+            break;
+            case PS_TYPE_S64:
+            SORT_INDICES( S64 );
+            break;
+            case PS_TYPE_F32:
+            SORT_INDICES( F32 );
+            break;
+            case PS_TYPE_F64:
+            SORT_INDICES( F64 );
+            break;
+            default:
+            psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
+        }
+        
     // Free temp memory
-    psFree(tmpVector);
-
+    psFree( tmpVector );
+    
     return outVector;
 }
 
-static void vectorFree(psVector *restrict psVec)
-{
-    if (psVec == NULL) {
-        return;
-    }
-
-    psFree(psVec->data.V);
-}
+static void vectorFree( psVector *restrict psVec )
+{
+    if ( psVec == NULL ) {
+            return ;
+        }
+        
+    psFree( psVec->data.V );
+}
Index: /trunk/psLib/src/mathtypes/psVector.c
===================================================================
--- /trunk/psLib/src/mathtypes/psVector.c	(revision 1359)
+++ /trunk/psLib/src/mathtypes/psVector.c	(revision 1360)
@@ -1,16 +1,16 @@
 /** @file  psVector.c
- *
- *  @brief Contains support for basic vector types
- *
- *  This file defines the basic type for a vector struct and functions useful
- *  in manupulating vectors.
- *
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-28 00:06:13 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
+*
+*  @brief Contains support for basic vector types
+*
+*  This file defines the basic type for a vector struct and functions useful
+*  in manupulating vectors.
+*
+*  @author Ross Harman, MHPCC
+*
+*  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-07-31 02:28:10 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
 
 /******************************************************************************/
@@ -54,99 +54,99 @@
 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
 /*****************************************************************************/
-static void vectorFree(psVector *restrict psVec);
+static void vectorFree( psVector *restrict psVec );
 
 /*****************************************************************************/
 /* FUNCTION IMPLEMENTATION - PUBLIC                                          */
 /*****************************************************************************/
-psVector* psVectorAlloc(unsigned int nalloc, psElemType elemType)
-{
-    psVector *psVec = NULL;
+psVector* psVectorAlloc( unsigned int nalloc, psElemType elemType )
+{
+    psVector * psVec = NULL;
     int elementSize = 0;
-
+    
     // Invalid nalloc
-    if(nalloc < 1) {
-        psError(__func__, "Invalid value for nalloc. nalloc: %d\n", nalloc);
-        return NULL;
-    }
-
-    elementSize = PSELEMTYPE_SIZEOF(elemType);
-
+    if ( nalloc < 1 ) {
+            psError( __func__, "Invalid value for nalloc. nalloc: %d\n", nalloc );
+            return NULL;
+        }
+        
+    elementSize = PSELEMTYPE_SIZEOF( elemType );
+    
     // Create vector struct
-    psVec = (psVector *)psAlloc(sizeof(psVector));
-    p_psMemSetDeallocator(psVec,(psFreeFcn)vectorFree);
-
+    psVec = ( psVector * ) psAlloc( sizeof( psVector ) );
+    p_psMemSetDeallocator( psVec, ( psFreeFcn ) vectorFree );
+    
     psVec->type.dimen = PS_DIMEN_VECTOR;
     psVec->type.type = elemType;
     psVec->nalloc = nalloc;
     psVec->n = nalloc;
-
+    
     // Create vector data array
-    psVec->data.V = psAlloc(nalloc*elementSize);
-
+    psVec->data.V = psAlloc( nalloc * elementSize );
+    
     return psVec;
 }
 
-psVector *psVectorRealloc(unsigned int nalloc, psVector *restrict in)
+psVector *psVectorRealloc( unsigned int nalloc, psVector *restrict in )
 {
     int elementSize = 0;
     psElemType elemType;
-
+    
     // Invalid nalloc
-    if(nalloc < 1) {
-        psError(__func__, "Invalid value for realloc (%d)\n", nalloc);
-        return NULL;
-    }
-
-    if(in == NULL) {
-        psError(__func__, "Null input vector\n");
-        return NULL;
-    } else if(in->nalloc != nalloc) {                    // No need to realloc to same size
-        elemType = in->type.type;
-        elementSize = PSELEMTYPE_SIZEOF(elemType);
-        if(nalloc < in->n) {
-            in->n = nalloc;
-        }
-
-        // Realloc after decrementation to avoid accessing freed array elements
-        in->data.V = psRealloc(in->data.V,nalloc*elementSize);
-        in->nalloc = nalloc;
-    }
-
+    if ( nalloc < 1 ) {
+            psError( __func__, "Invalid value for realloc (%d)\n", nalloc );
+            return NULL;
+        }
+        
+    if ( in == NULL ) {
+            psError( __func__, "Null input vector\n" );
+            return NULL;
+        } else if ( in->nalloc != nalloc ) {                    // No need to realloc to same size
+            elemType = in->type.type;
+            elementSize = PSELEMTYPE_SIZEOF( elemType );
+            if ( nalloc < in->n ) {
+                    in->n = nalloc;
+                }
+                
+            // Realloc after decrementation to avoid accessing freed array elements
+            in->data.V = psRealloc( in->data.V, nalloc * elementSize );
+            in->nalloc = nalloc;
+        }
+        
     return in;
 }
 
-psVector *psVectorRecycle(psVector *restrict in, psElemType type, unsigned int nalloc)
+psVector *psVectorRecycle( psVector *restrict in, psElemType type, unsigned int nalloc )
 {
     psElemType elemType;
-
-    if (in == NULL) {
-        return psVectorAlloc(nalloc, type);
-    }
-
+    
+    if ( in == NULL ) {
+            return psVectorAlloc( nalloc, type );
+        }
+        
     elemType = in->type.type;
-
-    if (in->nalloc == nalloc && elemType == type) {
-        // it is proper size/type already
-        return in;
-    }
-
+    
+    if ( in->nalloc == nalloc && elemType == type ) {
+            // it is proper size/type already
+            return in;
+        }
+        
     // Invalid nalloc
-    if(nalloc < 1) {
-        psError(__func__, "Invalid value for nalloc (%d)\n", nalloc);
-        psFree(in);
-        return NULL;
-    }
-
-
-    in->data.V = psRealloc(in->data.V,nalloc*PSELEMTYPE_SIZEOF(type));
-
-    in->n = 0;
+    if ( nalloc < 1 ) {
+            psError( __func__, "Invalid value for nalloc (%d)\n", nalloc );
+            psFree( in );
+            return NULL;
+        }
+        
+        
+    in->data.V = psRealloc( in->data.V, nalloc * PSELEMTYPE_SIZEOF( type ) );
+    
     in->type.type = type;
     in->nalloc = nalloc;
-
+    in->n = nalloc;
+    
     return in;
 }
 
-psVector *psVectorSort(psVector *restrict outVector, const psVector *restrict inVector)
+psVector *psVectorSort( psVector *restrict outVector, const psVector *restrict inVector )
 {
     int inN = 0;
@@ -156,84 +156,84 @@
     void *outVec = NULL;
     psElemType inType = 0;
-
-    if(inVector == NULL) {
-        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
-        return outVector;
-    }
-
+    
+    if ( inVector == NULL ) {
+            psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
+            return outVector;
+        }
+        
     inType = inVector->type.type;
     inN = inVector->n;
     inVec = inVector->data.V;
-    elSize = PSELEMTYPE_SIZEOF(inType);
-
-    if(outVector == NULL) {
-        outVector = psVectorAlloc(inN, inType);
-        outVector->n = inVector->n;
-    }
-
+    elSize = PSELEMTYPE_SIZEOF( inType );
+    
+    if ( outVector == NULL ) {
+            outVector = psVectorAlloc( inN, inType );
+            outVector->n = inVector->n;
+        }
+        
     outN = outVector->n;
     outVec = outVector->data.V;
-
-    if(inN != outN) {
-        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
-                inN, outN);
-        return outVector;
-    }
-
-    if(inType != outVector->type.type) {
-        psError(__func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
-                inType, outVector->type.type);
-        return outVector;
-    }
-
-    if(inN == 0) {
-        psError(__func__, " : Line %d - No elements in use for input vector\n", __LINE__);
-        return outVector;
-    }
-
-    if(outN == 0) {
-        psError(__func__, " : Line %d - No elements in use for output vector\n", __LINE__);
-        return outVector;
-    }
-
+    
+    if ( inN != outN ) {
+            psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n", __LINE__,
+                     inN, outN );
+            return outVector;
+        }
+        
+    if ( inType != outVector->type.type ) {
+            psError( __func__, " : Line %d - Input and output vectors are not same type: in=%d out=%d\n", __LINE__,
+                     inType, outVector->type.type );
+            return outVector;
+        }
+        
+    if ( inN == 0 ) {
+            psError( __func__, " : Line %d - No elements in use for input vector\n", __LINE__ );
+            return outVector;
+        }
+        
+    if ( outN == 0 ) {
+            psError( __func__, " : Line %d - No elements in use for output vector\n", __LINE__ );
+            return outVector;
+        }
+        
     // Copy input vector values into output vector
-    memcpy(outVec, inVec, elSize*outN);
-
+    memcpy( outVec, inVec, elSize * outN );
+    
     // Sort output vector
-    switch(inType) {
-    case PS_TYPE_U8:
-        qsort(outVec, inN, elSize, psCompareU8);
-        break;
-    case PS_TYPE_U16:
-        qsort(outVec, inN, elSize, psCompareU16);
-        break;
-    case PS_TYPE_U32:
-        qsort(outVec, inN, elSize, psCompareU32);
-        break;
-    case PS_TYPE_U64:
-        qsort(outVec, inN, elSize, psCompareU64);
-        break;
-    case PS_TYPE_S8:
-        qsort(outVec, inN, elSize, psCompareS8);
-        break;
-    case PS_TYPE_S16:
-        qsort(outVec, inN, elSize, psCompareS16);
-        break;
-    case PS_TYPE_S32:
-        qsort(outVec, inN, elSize, psCompareS32);
-        break;
-    case PS_TYPE_S64:
-        qsort(outVec, inN, elSize, psCompareS64);
-        break;
-    case PS_TYPE_F32:
-        qsort(outVec, inN, elSize, psCompareF32);
-        break;
-    case PS_TYPE_F64:
-        qsort(outVec, inN, elSize, psCompareF64);
-        break;
-    default:
-        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
-    }
-
+    switch ( inType ) {
+            case PS_TYPE_U8:
+            qsort( outVec, inN, elSize, psCompareU8 );
+            break;
+            case PS_TYPE_U16:
+            qsort( outVec, inN, elSize, psCompareU16 );
+            break;
+            case PS_TYPE_U32:
+            qsort( outVec, inN, elSize, psCompareU32 );
+            break;
+            case PS_TYPE_U64:
+            qsort( outVec, inN, elSize, psCompareU64 );
+            break;
+            case PS_TYPE_S8:
+            qsort( outVec, inN, elSize, psCompareS8 );
+            break;
+            case PS_TYPE_S16:
+            qsort( outVec, inN, elSize, psCompareS16 );
+            break;
+            case PS_TYPE_S32:
+            qsort( outVec, inN, elSize, psCompareS32 );
+            break;
+            case PS_TYPE_S64:
+            qsort( outVec, inN, elSize, psCompareS64 );
+            break;
+            case PS_TYPE_F32:
+            qsort( outVec, inN, elSize, psCompareF32 );
+            break;
+            case PS_TYPE_F64:
+            qsort( outVec, inN, elSize, psCompareF64 );
+            break;
+            default:
+            psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
+        }
+        
     return outVector;
 }
@@ -241,14 +241,14 @@
 #define SORT_INDICES(TYPE)                                                                                   \
 for(i=0; i<inN; i++) {                                                                                       \
-    for(j=0; j<inN; j++) {                                                                                   \
-        diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
-        if(diff < FLT_EPSILON) {                                                                             \
-            outVec[i] = j;                                                                                   \
-            break;                                                                                           \
-        }                                                                                                    \
-    }                                                                                                        \
-}
-
-psVector *psVectorSortIndex(psVector *restrict outVector, const psVector *restrict inVector)
+        for(j=0; j<inN; j++) {                                                                                   \
+                diff = fabs((double)tmpVector->data.TYPE[i] - inVec[j]);                                             \
+                if(diff < FLT_EPSILON) {                                                                             \
+                        outVec[i] = j;                                                                                   \
+                        break;                                                                                           \
+                    }                                                                                                    \
+            }                                                                                                        \
+    }
+    
+psVector *psVectorSortIndex( psVector *restrict outVector, const psVector *restrict inVector )
 {
     int inN = 0;
@@ -261,86 +261,86 @@
     psVector *tmpVector = NULL;
     psElemType inType = 0;
-
-    if(inVector == NULL) {
-        psError(__func__, " : Line %d - Null input vector\n", __LINE__);
-        return outVector;
-    }
-
+    
+    if ( inVector == NULL ) {
+            psError( __func__, " : Line %d - Null input vector\n", __LINE__ );
+            return outVector;
+        }
+        
     inN = inVector->n;
     inVec = inVector->data.V;
     inType = inVector->type.type;
-
-    if(outVector == NULL) {
-        outVector = psVectorAlloc(inN, PS_TYPE_U32);
-        outVector->n = inN;
-    }
-
+    
+    if ( outVector == NULL ) {
+            outVector = psVectorAlloc( inN, PS_TYPE_U32 );
+            outVector->n = inN;
+        }
+        
     outN = outVector->n;
     outVec = outVector->data.V;
-
-    if(inN != outN) {
-        psError(__func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
-                __LINE__, inN, outN);
-        return outVector;
-    }
-
-    if(outVector->type.type != PS_TYPE_U32) {
-        psError(__func__, " : Line %d - Output vector is not of type U32: out=%d\n",
-                __LINE__, outVector->type.type);
-        return outVector;
-    }
-
-    tmpVector = psVectorAlloc(inN, inType);
+    
+    if ( inN != outN ) {
+            psError( __func__, " : Line %d - Input and output vector sizes are not equal: in=%d out=%d\n",
+                     __LINE__, inN, outN );
+            return outVector;
+        }
+        
+    if ( outVector->type.type != PS_TYPE_U32 ) {
+            psError( __func__, " : Line %d - Output vector is not of type U32: out=%d\n",
+                     __LINE__, outVector->type.type );
+            return outVector;
+        }
+        
+    tmpVector = psVectorAlloc( inN, inType );
     tmpVector->n = inN;
-    tmpVector = psVectorSort(tmpVector, inVector);
-
+    tmpVector = psVectorSort( tmpVector, inVector );
+    
     // Sort output vector
-    switch(inType) {
-    case PS_TYPE_U8:
-        SORT_INDICES(U8);
-        break;
-    case PS_TYPE_U16:
-        SORT_INDICES(U16);
-        break;
-    case PS_TYPE_U32:
-        SORT_INDICES(U32);
-        break;
-    case PS_TYPE_U64:
-        SORT_INDICES(U64);
-        break;
-    case PS_TYPE_S8:
-        SORT_INDICES(S8);
-        break;
-    case PS_TYPE_S16:
-        SORT_INDICES(S16);
-        break;
-    case PS_TYPE_S32:
-        SORT_INDICES(S32);
-        break;
-    case PS_TYPE_S64:
-        SORT_INDICES(S64);
-        break;
-    case PS_TYPE_F32:
-        SORT_INDICES(F32);
-        break;
-    case PS_TYPE_F64:
-        SORT_INDICES(F64);
-        break;
-    default:
-        psError(__func__, " : Line %d - Invalid psType\n", __LINE__);
-    }
-
+    switch ( inType ) {
+            case PS_TYPE_U8:
+            SORT_INDICES( U8 );
+            break;
+            case PS_TYPE_U16:
+            SORT_INDICES( U16 );
+            break;
+            case PS_TYPE_U32:
+            SORT_INDICES( U32 );
+            break;
+            case PS_TYPE_U64:
+            SORT_INDICES( U64 );
+            break;
+            case PS_TYPE_S8:
+            SORT_INDICES( S8 );
+            break;
+            case PS_TYPE_S16:
+            SORT_INDICES( S16 );
+            break;
+            case PS_TYPE_S32:
+            SORT_INDICES( S32 );
+            break;
+            case PS_TYPE_S64:
+            SORT_INDICES( S64 );
+            break;
+            case PS_TYPE_F32:
+            SORT_INDICES( F32 );
+            break;
+            case PS_TYPE_F64:
+            SORT_INDICES( F64 );
+            break;
+            default:
+            psError( __func__, " : Line %d - Invalid psType\n", __LINE__ );
+        }
+        
     // Free temp memory
-    psFree(tmpVector);
-
+    psFree( tmpVector );
+    
     return outVector;
 }
 
-static void vectorFree(psVector *restrict psVec)
-{
-    if (psVec == NULL) {
-        return;
-    }
-
-    psFree(psVec->data.V);
-}
+static void vectorFree( psVector *restrict psVec )
+{
+    if ( psVec == NULL ) {
+            return ;
+        }
+        
+    psFree( psVec->data.V );
+}
Index: /trunk/psLib/src/sys/psMemory.c
===================================================================
--- /trunk/psLib/src/sys/psMemory.c	(revision 1359)
+++ /trunk/psLib/src/sys/psMemory.c	(revision 1360)
@@ -1,16 +1,16 @@
 /** @file  psMemory.c
- *
- *  @brief Contains the definitions for the memory management system
- *
- *  psMemory.h has additional information and documentation of the routines found in this file.
- *
- *  @author Robert DeSonia, MHPCC
- *  @author Robert Lupton, Princeton University
- *
- *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-19 20:45:53 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
+*
+*  @brief Contains the definitions for the memory management system
+*
+*  psMemory.h has additional information and documentation of the routines found in this file.
+*
+*  @author Robert DeSonia, MHPCC
+*  @author Robert Lupton, Princeton University
+*
+*  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-07-31 02:28:10 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
 
 #define PS_ALLOW_MALLOC                 // we're allowed to call malloc()
@@ -30,5 +30,5 @@
 #define P_PS_LARGE_BLOCK_SIZE 65536    // size where under, we try to recycle
 
-static int checkMemBlock(const psMemBlock *m, const char* funcName);
+static int checkMemBlock( const psMemBlock *m, const char* funcName );
 static psMemBlock *lastMemBlockAllocated = NULL;
 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
@@ -38,8 +38,14 @@
 
 static int recycleBins = 13;
-static int recycleBinSize[14] = {8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,P_PS_LARGE_BLOCK_SIZE};
+static int recycleBinSize[ 14 ] =
+    {
+        8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE
+    };
 // N.B. recycleBinSize should be terminated by P_PS_LARGE_BLOCK_SIZE (simplifies search loops)
-static psMemBlock* recycleMemBlockList[13] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
-
+static psMemBlock* recycleMemBlockList[ 13 ] =
+    {
+        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+    };
+    
 #ifdef PS_MEM_DEBUG
 static psMemBlock* deadBlockList;    // a place to put dead memBlocks in debug mode.
@@ -53,21 +59,21 @@
  *  Default memExhausted callback.
  */
-static void *memExhaustedCallbackDefault(size_t size)
-{
-    void* ptr = NULL;
-
-    pthread_mutex_lock(&recycleMemBlockListMutex);
-    int level=recycleBins-1;
-    while (level >= 0 && ptr == NULL) {
-        while (recycleMemBlockList[level] != NULL && ptr == NULL) {
-            psMemBlock* old = recycleMemBlockList[level];
-            recycleMemBlockList[level] = recycleMemBlockList[level]->nextBlock;
-            free(old);
-            ptr = malloc(size);
-        }
-        level--;
-    }
-    pthread_mutex_unlock(&recycleMemBlockListMutex);
-
+static void *memExhaustedCallbackDefault( size_t size )
+{
+    void * ptr = NULL;
+    
+    pthread_mutex_lock( &recycleMemBlockListMutex );
+    int level = recycleBins - 1;
+    while ( level >= 0 && ptr == NULL ) {
+            while ( recycleMemBlockList[ level ] != NULL && ptr == NULL ) {
+                    psMemBlock * old = recycleMemBlockList[ level ];
+                    recycleMemBlockList[ level ] = recycleMemBlockList[ level ] ->nextBlock;
+                    free( old );
+                    ptr = malloc( size );
+                }
+            level--;
+        }
+    pthread_mutex_unlock( &recycleMemBlockListMutex );
+    
     return ptr;
 }
@@ -75,42 +81,42 @@
 static psMemExhaustedCallback memExhaustedCallback = memExhaustedCallbackDefault;
 
-psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func)
+psMemExhaustedCallback psMemExhaustedCallbackSet( psMemExhaustedCallback func )
 {
     psMemExhaustedCallback old = memExhaustedCallback;
-
-    if (func != NULL) {
-        memExhaustedCallback = func;
-    } else {
-        memExhaustedCallback = memExhaustedCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memExhaustedCallback = func;
+        } else {
+            memExhaustedCallback = memExhaustedCallbackDefault;
+        }
+        
     return old;
 }
 
-static void memProblemCallbackDefault(const psMemBlock *ptr,
-                                      const char *file, int lineno)
-{
-    if (ptr->refCounter < 1) {
-        psError(__func__,
-                "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
-                ptr->id, ptr->file, ptr->lineno, file, lineno);
-    }
-
-    if (lineno > 0) {
-        psAbort(__func__, "Detected a problem in the memory system at %s:%d", file, lineno);
-    }
+static void memProblemCallbackDefault( const psMemBlock *ptr,
+                                       const char *file, int lineno )
+{
+    if ( ptr->refCounter < 1 ) {
+            psError( __func__,
+                     "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
+                     ptr->id, ptr->file, ptr->lineno, file, lineno );
+        }
+        
+    if ( lineno > 0 ) {
+            psAbort( __func__, "Detected a problem in the memory system at %s:%d", file, lineno );
+        }
 }
 static psMemProblemCallback memProblemCallback = memProblemCallbackDefault;
 
-psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func)
+psMemProblemCallback psMemProblemCallbackSet( psMemProblemCallback func )
 {
     psMemProblemCallback old = memProblemCallback;
-
-    if (func != NULL) {
-        memProblemCallback = func;
-    } else {
-        memProblemCallback = memProblemCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memProblemCallback = func;
+        } else {
+            memProblemCallback = memProblemCallbackDefault;
+        }
+        
     return old;
 }
@@ -123,17 +129,17 @@
 psMemoryId p_psMemFreeID = 0;   // notify user this block is freed
 
-psMemoryId psMemAllocateCallbackSetID(psMemoryId id)
+psMemoryId psMemAllocateCallbackSetID( psMemoryId id )
 {
     psMemoryId old = p_psMemAllocateID;
     p_psMemAllocateID = id;
-
+    
     return old;
 }
 
-psMemoryId psMemFreeCallbackSetID(psMemoryId id)
+psMemoryId psMemFreeCallbackSetID( psMemoryId id )
 {
     psMemoryId old = p_psMemFreeID;
     p_psMemFreeID = id;
-
+    
     return old;
 }
@@ -145,15 +151,15 @@
  * isn't resignalled)
  */
-static psMemoryId memAllocateCallbackDefault(const psMemBlock *ptr)
+static psMemoryId memAllocateCallbackDefault( const psMemBlock *ptr )
 {
     static psMemoryId incr = 0;  // "p_psMemAllocateID += incr"
-
+    
     return incr;
 }
 
-static psMemoryId memFreeCallbackDefault(const psMemBlock *ptr)
+static psMemoryId memFreeCallbackDefault( const psMemBlock *ptr )
 {
     static psMemoryId incr = 0;  // "p_psMemFreeID += incr"
-
+    
     return incr;
 }
@@ -165,27 +171,27 @@
 static psMemFreeCallback memFreeCallback = memFreeCallbackDefault;
 
-psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func)
+psMemAllocateCallback psMemAllocateCallbackSet( psMemAllocateCallback func )
 {
     psMemFreeCallback old = memAllocateCallback;
-
-    if (func != NULL) {
-        memAllocateCallback =  func;
-    } else {
-        memAllocateCallback = memAllocateCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memAllocateCallback = func;
+        } else {
+            memAllocateCallback = memAllocateCallbackDefault;
+        }
+        
     return old;
 }
 
-psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func)
+psMemFreeCallback psMemFreeCallbackSet( psMemFreeCallback func )
 {
     psMemFreeCallback old = memFreeCallback;
-
-    if (func != NULL) {
-        memFreeCallback = func;
-    } else {
-        memFreeCallback = memFreeCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memFreeCallback = func;
+        } else {
+            memFreeCallback = memFreeCallbackDefault;
+        }
+        
     return old;
 }
@@ -194,11 +200,11 @@
  * Return memory ID counter for next block to be allocated
  */
-psMemoryId psMemGetId(void)
+psMemoryId psMemGetId( void )
 {
     psMemoryId id;
-    pthread_mutex_lock(&memIdMutex);
+    pthread_mutex_lock( &memIdMutex );
     id = memid + 1;
-    pthread_mutex_unlock(&memIdMutex);
-
+    pthread_mutex_unlock( &memIdMutex );
+    
     return id;
 }
@@ -210,199 +216,199 @@
  */
 
-static int checkMemBlock(const psMemBlock *m, const char* funcName)
+static int checkMemBlock( const psMemBlock *m, const char* funcName )
 {
     // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
     // we shouldn't call such things as p_psAlloc/p_psFree here.
-
-    if (m == NULL) {
-        psError(funcName,"Memory Corruption: NULL memory block found.");
-        return 1;
-    }
-
-    if (m->refCounter == 0) {
-        // using an unreferenced block of memory, are you?
-        psError(__func__,"Memory Corruption: memory block %ld was freed but still used.",
-                m->id);
-        return 1;
-    }
-
-    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
-        psError(funcName, "Memory Corruption: memory block %ld is corrupted (buffer underflow)",
-                m->id);
-        return 1;
-    }
-    if (*(void**)((int8_t*)(m+1)+m->userMemorySize) != P_PS_MEMMAGIC) {
-        psError(funcName, "Memory Corruption: memory block %ld is corrupted (buffer overflow)",
-                m->id);
-        return 1;
-    }
-
+    
+    if ( m == NULL ) {
+            psError( funcName, "Memory Corruption: NULL memory block found." );
+            return 1;
+        }
+        
+    if ( m->refCounter == 0 ) {
+            // using an unreferenced block of memory, are you?
+            psError( __func__, "Memory Corruption: memory block %ld was freed but still used.",
+                     m->id );
+            return 1;
+        }
+        
+    if ( m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC ) {
+            psError( funcName, "Memory Corruption: memory block %ld is corrupted (buffer underflow)",
+                     m->id );
+            return 1;
+        }
+    if ( *( void** ) ( ( int8_t* ) ( m + 1 ) + m->userMemorySize ) != P_PS_MEMMAGIC ) {
+            psError( funcName, "Memory Corruption: memory block %ld is corrupted (buffer overflow)",
+                     m->id );
+            return 1;
+        }
+        
     return 0;
 }
 
-int psMemCheckCorruption(bool abort_on_error)
+int psMemCheckCorruption( bool abort_on_error )
 {
     int nbad = 0;                       // number of bad blocks
-
+    
     // get exclusive access to the memBlock list to avoid it changing on us while we use it.
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter=lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock) {
-        if (checkMemBlock(iter, __func__)) {
-            nbad++;
-
-            memProblemCallback(iter, __func__, __LINE__);
-
-            if (abort_on_error) {
-                // release the lock on the memblock list
-                pthread_mutex_unlock(&memBlockListMutex);
-                psAbort(__func__, "Detected memory corruption");
-                return nbad;
-            }
-        }
-    }
-
+    pthread_mutex_lock( &memBlockListMutex );
+    
+    for ( psMemBlock * iter = lastMemBlockAllocated; iter != NULL; iter = iter->nextBlock ) {
+            if ( checkMemBlock( iter, __func__ ) ) {
+                    nbad++;
+                    
+                    memProblemCallback( iter, __func__, __LINE__ );
+                    
+                    if ( abort_on_error ) {
+                            // release the lock on the memblock list
+                            pthread_mutex_unlock( &memBlockListMutex );
+                            psAbort( __func__, "Detected memory corruption" );
+                            return nbad;
+                        }
+                }
+        }
+        
     // release the lock on the memblock list
-    pthread_mutex_unlock(&memBlockListMutex);
+    pthread_mutex_unlock( &memBlockListMutex );
     return nbad;
 }
 
-void *p_psAlloc(size_t size, const char *file, int lineno)
-{
-
-    psMemBlock *ptr = NULL;
-
+void *p_psAlloc( size_t size, const char *file, int lineno )
+{
+
+    psMemBlock * ptr = NULL;
+    
     // memory is of the size I want to bother recycling?
-    if (size < P_PS_LARGE_BLOCK_SIZE) {
-        // find the bin we need.
-        int level = 0;
-        while (size > recycleBinSize[level]) {
-            level++;
-        }
-        // Are we in one of the bins
-        if (level<recycleBins) {
-
-            size = recycleBinSize[level];  // round-up size to next sized bin.
-
-            pthread_mutex_lock(&recycleMemBlockListMutex);
-
-            if (recycleMemBlockList[level] != NULL) {
-                ptr = recycleMemBlockList[level];
-                recycleMemBlockList[level] = ptr->nextBlock;
-                if (recycleMemBlockList[level] != NULL) {
-                    recycleMemBlockList[level]->previousBlock = NULL;
-                }
-                size = ptr->userMemorySize;
-            }
-
-            pthread_mutex_unlock(&recycleMemBlockListMutex);
-        }
-    }
-
-    if (ptr == NULL) {
-        ptr = malloc(sizeof(psMemBlock) + size + sizeof(void*));
-
-        if (ptr == NULL) {
-            ptr = memExhaustedCallback(size);
-            if (ptr == NULL) {
-                psAbort(__func__, "Failed to allocate %u bytes at %s:%d",
-                        size, file, lineno);
-            }
-        }
-
-        ptr->startblock = P_PS_MEMMAGIC;
-        ptr->endblock = P_PS_MEMMAGIC;
-        ptr->userMemorySize = size;
-        pthread_mutex_init(&ptr->refCounterMutex, NULL);
-    }
-
+    if ( size < P_PS_LARGE_BLOCK_SIZE ) {
+            // find the bin we need.
+            int level = 0;
+            while ( size > recycleBinSize[ level ] ) {
+                    level++;
+                }
+            // Are we in one of the bins
+            if ( level < recycleBins ) {
+            
+                    size = recycleBinSize[ level ];  // round-up size to next sized bin.
+                    
+                    pthread_mutex_lock( &recycleMemBlockListMutex );
+                    
+                    if ( recycleMemBlockList[ level ] != NULL ) {
+                            ptr = recycleMemBlockList[ level ];
+                            recycleMemBlockList[ level ] = ptr->nextBlock;
+                            if ( recycleMemBlockList[ level ] != NULL ) {
+                                    recycleMemBlockList[ level ] ->previousBlock = NULL;
+                                }
+                            size = ptr->userMemorySize;
+                        }
+                        
+                    pthread_mutex_unlock( &recycleMemBlockListMutex );
+                }
+        }
+        
+    if ( ptr == NULL ) {
+            ptr = malloc( sizeof( psMemBlock ) + size + sizeof( void* ) );
+            
+            if ( ptr == NULL ) {
+                    ptr = memExhaustedCallback( size );
+                    if ( ptr == NULL ) {
+                            psAbort( __func__, "Failed to allocate %u bytes at %s:%d",
+                                     size, file, lineno );
+                        }
+                }
+                
+            ptr->startblock = P_PS_MEMMAGIC;
+            ptr->endblock = P_PS_MEMMAGIC;
+            ptr->userMemorySize = size;
+            pthread_mutex_init( &ptr->refCounterMutex, NULL );
+        }
+        
     // increment the memory id safely.
-    pthread_mutex_lock(&memBlockListMutex);
-    *(psMemoryId*)&ptr->id = ++memid;
-    pthread_mutex_unlock(&memBlockListMutex);
-
+    pthread_mutex_lock( &memBlockListMutex );
+    *( psMemoryId* ) & ptr->id = ++memid;
+    pthread_mutex_unlock( &memBlockListMutex );
+    
     ptr->file = file;
     ptr->freeFcn = NULL;
-    *(unsigned int*)&ptr->lineno = lineno;
-    *(void**)((int8_t*)(ptr+1)+size) = P_PS_MEMMAGIC;
+    *( unsigned int* ) & ptr->lineno = lineno;
+    *( void** ) ( ( int8_t* ) ( ptr + 1 ) + size ) = P_PS_MEMMAGIC;
     ptr->previousBlock = NULL;
-
+    
     ptr->refCounter = 1;                // one user so far
-
+    
     // need exclusive access of the memory block list now...
-    pthread_mutex_lock(&memBlockListMutex);
-
+    pthread_mutex_lock( &memBlockListMutex );
+    
     // insert the new block to the front of the memBlock linked-list
     ptr->nextBlock = lastMemBlockAllocated;
-    if (ptr->nextBlock != NULL) {
-        ptr->nextBlock->previousBlock = ptr;
-    }
+    if ( ptr->nextBlock != NULL ) {
+            ptr->nextBlock->previousBlock = ptr;
+        }
     lastMemBlockAllocated = ptr;
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
+    
+    pthread_mutex_unlock( &memBlockListMutex );
+    
     //  Did the user ask to be informed about this allocation?
-    if (ptr->id == p_psMemAllocateID) {
-        p_psMemAllocateID += memAllocateCallback(ptr);
-    }
-
+    if ( ptr->id == p_psMemAllocateID ) {
+            p_psMemAllocateID += memAllocateCallback( ptr );
+        }
+        
     // And return the user the memory that they allocated
     return ptr + 1;   // user memory
 }
 
-void *p_psRealloc(void *vptr, size_t size, const char *file, int lineno)
-{
-    if (vptr == NULL) {
-        return p_psAlloc(size, file, lineno);
-    } else {
-        psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-        bool isBlockLast = false;
-
-        if (checkMemBlock(ptr, __func__) != 0) {
-            memProblemCallback(ptr, file, lineno);
-            psAbort(file,"Realloc detected a memory corruption (id %ld @ %s:%d).",
-                    ptr->id,ptr->file,ptr->lineno);
-        }
-
-        pthread_mutex_lock(&memBlockListMutex);
-
-        isBlockLast = (ptr == lastMemBlockAllocated);
-
-        ptr = (psMemBlock*)realloc(ptr, sizeof(psMemBlock) + size + sizeof(void*));
-
-        if (ptr == NULL) {
-            psAbort(__func__, "Failed to reallocate %ld bytes at %s:%d",
-                    size, file, lineno);
-        }
-
-        ptr->userMemorySize = size;
-        *(void**)((int8_t*)(ptr+1)+size) = P_PS_MEMMAGIC;
-
-        if (isBlockLast) {
-            lastMemBlockAllocated = ptr;
-        }
-
-        // the block location may have changed, so fix the linked list addresses.
-        if (ptr->nextBlock != NULL) {
-            ptr->nextBlock->previousBlock = ptr;
-        }
-        if (ptr->previousBlock != NULL) {
-            ptr->previousBlock->nextBlock = ptr;
-        }
-
-        pthread_mutex_unlock(&memBlockListMutex);
-
-        //  Did the user ask to be informed about this allocation?
-        if (ptr->id == p_psMemAllocateID) {
-            p_psMemAllocateID += memAllocateCallback(ptr);
-        }
-
-        return ptr + 1;   // usr memory
-    }
-}
-
-void p_psFree(void *vptr, const char *file, int lineno)
-{
-    (void)p_psMemDecrRefCounter(vptr,file,lineno);   // this handles the free, if required.
+void *p_psRealloc( void *vptr, size_t size, const char *file, int lineno )
+{
+    if ( vptr == NULL ) {
+            return p_psAlloc( size, file, lineno );
+        } else {
+            psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+            bool isBlockLast = false;
+            
+            if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+                    memProblemCallback( ptr, file, lineno );
+                    psAbort( file, "Realloc detected a memory corruption (id %ld @ %s:%d).",
+                             ptr->id, ptr->file, ptr->lineno );
+                }
+                
+            pthread_mutex_lock( &memBlockListMutex );
+            
+            isBlockLast = ( ptr == lastMemBlockAllocated );
+            
+            ptr = ( psMemBlock* ) realloc( ptr, sizeof( psMemBlock ) + size + sizeof( void* ) );
+            
+            if ( ptr == NULL ) {
+                    psAbort( __func__, "Failed to reallocate %ld bytes at %s:%d",
+                             size, file, lineno );
+                }
+                
+            ptr->userMemorySize = size;
+            *( void** ) ( ( int8_t* ) ( ptr + 1 ) + size ) = P_PS_MEMMAGIC;
+            
+            if ( isBlockLast ) {
+                    lastMemBlockAllocated = ptr;
+                }
+                
+            // the block location may have changed, so fix the linked list addresses.
+            if ( ptr->nextBlock != NULL ) {
+                    ptr->nextBlock->previousBlock = ptr;
+                }
+            if ( ptr->previousBlock != NULL ) {
+                    ptr->previousBlock->nextBlock = ptr;
+                }
+                
+            pthread_mutex_unlock( &memBlockListMutex );
+            
+            //  Did the user ask to be informed about this allocation?
+            if ( ptr->id == p_psMemAllocateID ) {
+                    p_psMemAllocateID += memAllocateCallback( ptr );
+                }
+                
+            return ptr + 1;   // usr memory
+        }
+}
+
+void p_psFree( void *vptr, const char *file, int lineno )
+{
+    ( void ) p_psMemDecrRefCounter( vptr, file, lineno );   // this handles the free, if required.
 }
 
@@ -410,46 +416,46 @@
  * Check for memory leaks.
  */
-int psMemCheckLeaks(psMemoryId id0,psMemBlock ***arr,FILE *fd)
+int psMemCheckLeaks( psMemoryId id0, psMemBlock ***arr, FILE *fd )
 {
     int nleak = 0;
     int j = 0;
     psMemBlock* topBlock = lastMemBlockAllocated;
-
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = topBlock; iter != NULL; iter=iter->nextBlock) {
-        if ( (psMemGetRefCounter(iter+1) > 0) && (iter->id >= id0) ) {
-            nleak++;
-
-            if (fd != NULL) {
-                if (nleak == 1) {
-                    fprintf(fd, "   %20s:line ID\n", "file");
-                }
-
-                fprintf(fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id);
-            }
-        }
-    }
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
-    if (nleak == 0 || arr == NULL) {
-        return nleak;
-    }
-
-    *arr = p_psAlloc(nleak*sizeof(psMemBlock), __FILE__, __LINE__);
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = topBlock; iter != NULL; iter=iter->nextBlock) {
-        if ( (psMemGetRefCounter(iter+1) > 0) && (iter->id >= id0) ) {
-            (*arr)[j++] = iter;
-            if (j == nleak) { // found them all
-                break;
-            }
-        }
-    }
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
+    
+    pthread_mutex_lock( &memBlockListMutex );
+    
+    for ( psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock ) {
+            if ( ( psMemGetRefCounter( iter + 1 ) > 0 ) && ( iter->id >= id0 ) ) {
+                    nleak++;
+                    
+                    if ( fd != NULL ) {
+                            if ( nleak == 1 ) {
+                                    fprintf( fd, "   %20s:line ID\n", "file" );
+                                }
+                                
+                            fprintf( fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id );
+                        }
+                }
+        }
+        
+    pthread_mutex_unlock( &memBlockListMutex );
+    
+    if ( nleak == 0 || arr == NULL ) {
+            return nleak;
+        }
+        
+    *arr = p_psAlloc( nleak * sizeof( psMemBlock ), __FILE__, __LINE__ );
+    pthread_mutex_lock( &memBlockListMutex );
+    
+    for ( psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock ) {
+            if ( ( psMemGetRefCounter( iter + 1 ) > 0 ) && ( iter->id >= id0 ) ) {
+                    ( *arr ) [ j++ ] = iter;
+                    if ( j == nleak ) { // found them all
+                            break;
+                        }
+                }
+        }
+        
+    pthread_mutex_unlock( &memBlockListMutex );
+    
     return nleak;
 }
@@ -457,173 +463,169 @@
 /*
  * Reference counting APIs
- */
+ */ 
 // return refCounter
-psReferenceCount psMemGetRefCounter(void *vptr)
-{
-    psMemBlock *ptr;
+psReferenceCount psMemGetRefCounter( void *vptr )
+{
+    psMemBlock * ptr;
     unsigned int refCount;
-
-    if (vptr == NULL) {
-        return 0;
-    }
-
-    ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-    pthread_mutex_lock(&ptr->refCounterMutex);
+    
+    if ( vptr == NULL ) {
+            return 0;
+        }
+        
+    ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, __func__, __LINE__ );
+        }
+        
+    pthread_mutex_lock( &ptr->refCounterMutex );
     refCount = ptr->refCounter;
-    pthread_mutex_unlock(&ptr->refCounterMutex);
-
+    pthread_mutex_unlock( &ptr->refCounterMutex );
+    
     return refCount;
 }
 // increment and return refCounter
-void* p_psMemIncrRefCounter(void *vptr, const char *file, int lineno)
-{
-    psMemBlock *ptr;
-
-    if (vptr == NULL) {
-        return vptr;
-    }
-
-    ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__)) {
-        memProblemCallback(ptr, file,lineno);
-    }
-
-    pthread_mutex_lock(&ptr->refCounterMutex);
+void* p_psMemIncrRefCounter( void *vptr, const char *file, int lineno )
+{
+    psMemBlock * ptr;
+    
+    if ( vptr == NULL ) {
+            return vptr;
+        }
+        
+    ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) ) {
+            memProblemCallback( ptr, file, lineno );
+        }
+        
+    pthread_mutex_lock( &ptr->refCounterMutex );
     ptr->refCounter++;
-    pthread_mutex_unlock(&ptr->refCounterMutex);
-
+    pthread_mutex_unlock( &ptr->refCounterMutex );
+    
     return vptr;
 }
 
 // decrement and return refCounter
-void* p_psMemDecrRefCounter(void *vptr,const char *file, int lineno)
-{
-    if (vptr == NULL) {
-        return NULL;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, file, lineno);
-        return NULL;
-    }
-
-    pthread_mutex_lock(&ptr->refCounterMutex);
-
-    if (ptr->refCounter > 1) {
-        /// XXX - Probably should have another mutex here.
-        ptr->refCounter--;          // multiple references, just decrement the count.
-        pthread_mutex_unlock(&ptr->refCounterMutex);
-
-    } else {
-        pthread_mutex_unlock(&ptr->refCounterMutex);
-
-        // Did the user ask to be informed about this deallocation?
-        if (ptr->id == p_psMemFreeID) {
-            p_psMemFreeID += memFreeCallback(ptr);
-        }
-
-        if (ptr->freeFcn != NULL) {
-            ptr->freeFcn(vptr);
-        }
-
-        pthread_mutex_lock(&memBlockListMutex);
-
-        // cut the memBlock out of the memBlock list
-        if (ptr->nextBlock != NULL) {
-            ptr->nextBlock->previousBlock = ptr->previousBlock;
-        }
-        if (ptr->previousBlock != NULL) {
-            ptr->previousBlock->nextBlock = ptr->nextBlock;
-        }
-        if (lastMemBlockAllocated == ptr) {
-            lastMemBlockAllocated = ptr->nextBlock;
-        }
-
-        pthread_mutex_unlock(&memBlockListMutex);
-
-
-        // do we need to recycle?
-        if (ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE) {
-
-            int level = 1;
-            while (ptr->userMemorySize >= recycleBinSize[level]) {
-                level++;
-            }
-            level--;
-
-            ptr->refCounter = 0;
-            ptr->previousBlock = NULL;
-
-            pthread_mutex_lock(&recycleMemBlockListMutex);
-            ptr->nextBlock = recycleMemBlockList[level];
-            if (recycleMemBlockList[level] != NULL) {
-                recycleMemBlockList[level]->previousBlock = ptr;
-            }
-            recycleMemBlockList[level] = ptr;
-            pthread_mutex_unlock(&recycleMemBlockListMutex);
-
+void* p_psMemDecrRefCounter( void *vptr, const char *file, int lineno )
+{
+    if ( vptr == NULL ) {
+            return NULL;
+        }
+        
+    psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, file, lineno );
+            return NULL;
+        }
+        
+    pthread_mutex_lock( &ptr->refCounterMutex );
+    
+    if ( ptr->refCounter > 1 ) {
+            /// XXX - Probably should have another mutex here.
+            ptr->refCounter--;          // multiple references, just decrement the count.
+            pthread_mutex_unlock( &ptr->refCounterMutex );
+            
         } else {
-            // memory is larger than I want to recycle.
-            #ifdef PS_MEM_DEBUG
-            (void)p_psRealloc(vptr,0,file,lineno);
-            ptr->previousBlock = NULL;
-            ptr->nextBlock = deadBlockList;
-            if (deadBlockList != NULL) {
-                deadBlockList->previous = ptr;
-            }
-            deadBlockList = ptr;
-            #else
-
-            pthread_mutex_destroy(&ptr->refCounterMutex);
-            free(ptr);
-            #endif
-
-        }
-
-
-        pthread_mutex_destroy(&ptr->refCounterMutex);
-
-
-        vptr = NULL;    // since we freed it, make sure we return NULL.
-    }
-
+            pthread_mutex_unlock( &ptr->refCounterMutex );
+            
+            // Did the user ask to be informed about this deallocation?
+            if ( ptr->id == p_psMemFreeID ) {
+                    p_psMemFreeID += memFreeCallback( ptr );
+                }
+                
+            if ( ptr->freeFcn != NULL ) {
+                    ptr->freeFcn( vptr );
+                }
+                
+            pthread_mutex_lock( &memBlockListMutex );
+            
+            // cut the memBlock out of the memBlock list
+            if ( ptr->nextBlock != NULL ) {
+                    ptr->nextBlock->previousBlock = ptr->previousBlock;
+                }
+            if ( ptr->previousBlock != NULL ) {
+                    ptr->previousBlock->nextBlock = ptr->nextBlock;
+                }
+            if ( lastMemBlockAllocated == ptr ) {
+                    lastMemBlockAllocated = ptr->nextBlock;
+                }
+                
+            pthread_mutex_unlock( &memBlockListMutex );
+            
+            
+            // do we need to recycle?
+            if ( ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE ) {
+            
+                    int level = 1;
+                    while ( ptr->userMemorySize >= recycleBinSize[ level ] ) {
+                            level++;
+                        }
+                    level--;
+                    
+                    ptr->refCounter = 0;
+                    ptr->previousBlock = NULL;
+                    
+                    pthread_mutex_lock( &recycleMemBlockListMutex );
+                    ptr->nextBlock = recycleMemBlockList[ level ];
+                    if ( recycleMemBlockList[ level ] != NULL ) {
+                            recycleMemBlockList[ level ] ->previousBlock = ptr;
+                        }
+                    recycleMemBlockList[ level ] = ptr;
+                    pthread_mutex_unlock( &recycleMemBlockListMutex );
+                    
+                } else {
+                    // memory is larger than I want to recycle.
+                    #ifdef PS_MEM_DEBUG
+                    ( void ) p_psRealloc( vptr, 0, file, lineno );
+                    ptr->previousBlock = NULL;
+                    ptr->nextBlock = deadBlockList;
+                    if ( deadBlockList != NULL ) {
+                            deadBlockList->previous = ptr;
+                        }
+                    deadBlockList = ptr;
+                    #else
+                    
+                    pthread_mutex_destroy( &ptr->refCounterMutex );
+                    free( ptr );
+                    #endif
+                    
+                }
+                
+            vptr = NULL;    // since we freed it, make sure we return NULL.
+        }
+        
     return vptr;
 }
 
-void p_psMemSetDeallocator(void* vptr, psFreeFcn freeFcn)
-{
-    if (vptr == NULL) {
-        return;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
+void p_psMemSetDeallocator( void* vptr, psFreeFcn freeFcn )
+{
+    if ( vptr == NULL ) {
+            return ;
+        }
+        
+    psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, __func__, __LINE__ );
+        }
+        
     ptr->freeFcn = freeFcn;
-
-}
-psFreeFcn p_psMemGetDeallocator(void* vptr)
-{
-    if (vptr == NULL) {
-        return NULL;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
+    
+}
+psFreeFcn p_psMemGetDeallocator( void* vptr )
+{
+    if ( vptr == NULL ) {
+            return NULL;
+        }
+        
+    psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, __func__, __LINE__ );
+        }
+        
     return ptr->freeFcn;
 }
Index: /trunk/psLib/src/sys/psType.h
===================================================================
--- /trunk/psLib/src/sys/psType.h	(revision 1359)
+++ /trunk/psLib/src/sys/psType.h	(revision 1360)
@@ -1,18 +1,18 @@
 /** @file  psType.h
- *
- *  @brief Contains support for basic types
- *
- *  This file defines common datatypes used throughout psLib.
- *
- *  @ingroup DataContainer
- *
- *  @author Robert DeSonia, MHPCC
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-24 02:00:21 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
+*
+*  @brief Contains support for basic types
+*
+*  This file defines common datatypes used throughout psLib.
+*
+*  @ingroup DataContainer
+*
+*  @author Robert DeSonia, MHPCC
+*  @author Ross Harman, MHPCC
+*
+*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-07-31 02:28:10 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
 
 #ifndef PS_TYPE_H
@@ -37,36 +37,37 @@
  */
 
-typedef uint8_t         psU8;           ///< 8-bit unsigned int
-typedef uint16_t        psU16;          ///< 16-bit unsigned int
-typedef uint32_t        psU32;          ///< 32-bit unsigned int
-typedef uint64_t        psU64;          ///< 64-bit unsigned int
-typedef int8_t          psS8;           ///< 8-bit signed int
-typedef int16_t         psS16;          ///< 16-bit signed int
-typedef int32_t         psS32;          ///< 32-bit signed int
-typedef int64_t         psS64;          ///< 64-bit signed int
-typedef float           psF32;          ///< 32-bit floating point
-typedef double          psF64;          ///< 64-bit floating point
-typedef complex float   psC32;          ///< complex with 32-bit floating point Real and Imagary numbers
-typedef complex double  psC64;          ///< complex with 64-bit floating point Real and Imagary numbers
-typedef void*           psPTR;           ///< void pointer
+typedef uint8_t psU8;           ///< 8-bit unsigned int
+typedef uint16_t psU16;          ///< 16-bit unsigned int
+typedef uint32_t psU32;          ///< 32-bit unsigned int
+typedef uint64_t psU64;          ///< 64-bit unsigned int
+typedef int8_t psS8;           ///< 8-bit signed int
+typedef int16_t psS16;          ///< 16-bit signed int
+typedef int32_t psS32;          ///< 32-bit signed int
+typedef int64_t psS64;          ///< 64-bit signed int
+typedef float psF32;          ///< 32-bit floating point
+typedef double psF64;          ///< 64-bit floating point
+typedef complex float psC32;          ///< complex with 32-bit floating point Real and Imagary numbers
+typedef complex double psC64;          ///< complex with 64-bit floating point Real and Imagary numbers
+typedef void* psPTR;           ///< void pointer
 
 
 typedef enum {
-    PS_TYPE_S8               = 0x0101,  ///< Character.
-    PS_TYPE_S16              = 0x0102,  ///< Short integer.
-    PS_TYPE_S32              = 0x0104,  ///< Integer.
-    PS_TYPE_S64              = 0x0108,  ///< Long integer.
-    PS_TYPE_U8               = 0x0301,  ///< Unsigned character.
-    PS_TYPE_U16              = 0x0302,  ///< Unsigned short integer.
-    PS_TYPE_U32              = 0x0304,  ///< Unsigned integer.
-    PS_TYPE_U64              = 0x0308,  ///< Unsigned long integer.
-    PS_TYPE_F32              = 0x0404,  ///< Single-precision Floating point.
-    PS_TYPE_F64              = 0x0408,  ///< Double-precision floating point.
-    PS_TYPE_C32              = 0x0808,  ///< Complex numbers consisting of single-precision floating point.
-    PS_TYPE_C64              = 0x0810,  ///< Complex numbers consisting of double-precision floating point.
-    PS_TYPE_PTR              = 0x0000   ///< Something else that's not supported for arithmetic.
+    PS_TYPE_S8 = 0x0101,   ///< Character.
+    PS_TYPE_S16 = 0x0102,   ///< Short integer.
+    PS_TYPE_S32 = 0x0104,   ///< Integer.
+    PS_TYPE_S64 = 0x0108,   ///< Long integer.
+    PS_TYPE_U8 = 0x0301,   ///< Unsigned character.
+    PS_TYPE_U16 = 0x0302,   ///< Unsigned short integer.
+    PS_TYPE_U32 = 0x0304,   ///< Unsigned integer.
+    PS_TYPE_U64 = 0x0308,   ///< Unsigned long integer.
+    PS_TYPE_F32 = 0x0404,   ///< Single-precision Floating point.
+    PS_TYPE_F64 = 0x0408,   ///< Double-precision floating point.
+    PS_TYPE_C32 = 0x0808,   ///< Complex numbers consisting of single-precision floating point.
+    PS_TYPE_C64 = 0x0810,   ///< Complex numbers consisting of double-precision floating point.
+    PS_TYPE_PTR = 0x0000   ///< Something else that's not supported for arithmetic.
 } psElemType;
 
 #define PS_TYPE_MASK PS_TYPE_U8         ///< the psElemType to use for mask image
+#define PS_TYPE_MASK_DATA U8            ///< the data member to use for mask image
 #define PS_TYPE_MASK_NAME "psU8"
 typedef psU8 psMaskType;                ///< the C datatype for a mask image
@@ -127,8 +128,8 @@
  */
 typedef enum {
-    PS_DIMEN_SCALAR,    ///< Scalar.
-    PS_DIMEN_VECTOR,    ///< Vector.
-    PS_DIMEN_TRANSV,    ///< Transposed vector.
-    PS_DIMEN_IMAGE,     ///< Image.
+    PS_DIMEN_SCALAR,     ///< Scalar.
+    PS_DIMEN_VECTOR,     ///< Vector.
+    PS_DIMEN_TRANSV,     ///< Transposed vector.
+    PS_DIMEN_IMAGE,      ///< Image.
     PS_DIMEN_OTHER      ///< Something else that's not supported for arithmetic.
 } psDimen;
@@ -141,8 +142,8 @@
  */
 typedef struct
-{
-    psElemType type;    ///< Primitive type.
-    psDimen dimen;      ///< Dimensionality.
-}
+    {
+        psElemType type;    ///< Primitive type.
+        psDimen dimen;      ///< Dimensionality.
+    }
 psType;
 
Index: /trunk/psLib/src/sysUtils/psMemory.c
===================================================================
--- /trunk/psLib/src/sysUtils/psMemory.c	(revision 1359)
+++ /trunk/psLib/src/sysUtils/psMemory.c	(revision 1360)
@@ -1,16 +1,16 @@
 /** @file  psMemory.c
- *
- *  @brief Contains the definitions for the memory management system
- *
- *  psMemory.h has additional information and documentation of the routines found in this file.
- *
- *  @author Robert DeSonia, MHPCC
- *  @author Robert Lupton, Princeton University
- *
- *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-19 20:45:53 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
+*
+*  @brief Contains the definitions for the memory management system
+*
+*  psMemory.h has additional information and documentation of the routines found in this file.
+*
+*  @author Robert DeSonia, MHPCC
+*  @author Robert Lupton, Princeton University
+*
+*  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-07-31 02:28:10 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
 
 #define PS_ALLOW_MALLOC                 // we're allowed to call malloc()
@@ -30,5 +30,5 @@
 #define P_PS_LARGE_BLOCK_SIZE 65536    // size where under, we try to recycle
 
-static int checkMemBlock(const psMemBlock *m, const char* funcName);
+static int checkMemBlock( const psMemBlock *m, const char* funcName );
 static psMemBlock *lastMemBlockAllocated = NULL;
 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
@@ -38,8 +38,14 @@
 
 static int recycleBins = 13;
-static int recycleBinSize[14] = {8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,P_PS_LARGE_BLOCK_SIZE};
+static int recycleBinSize[ 14 ] =
+    {
+        8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, P_PS_LARGE_BLOCK_SIZE
+    };
 // N.B. recycleBinSize should be terminated by P_PS_LARGE_BLOCK_SIZE (simplifies search loops)
-static psMemBlock* recycleMemBlockList[13] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
-
+static psMemBlock* recycleMemBlockList[ 13 ] =
+    {
+        NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
+    };
+    
 #ifdef PS_MEM_DEBUG
 static psMemBlock* deadBlockList;    // a place to put dead memBlocks in debug mode.
@@ -53,21 +59,21 @@
  *  Default memExhausted callback.
  */
-static void *memExhaustedCallbackDefault(size_t size)
-{
-    void* ptr = NULL;
-
-    pthread_mutex_lock(&recycleMemBlockListMutex);
-    int level=recycleBins-1;
-    while (level >= 0 && ptr == NULL) {
-        while (recycleMemBlockList[level] != NULL && ptr == NULL) {
-            psMemBlock* old = recycleMemBlockList[level];
-            recycleMemBlockList[level] = recycleMemBlockList[level]->nextBlock;
-            free(old);
-            ptr = malloc(size);
-        }
-        level--;
-    }
-    pthread_mutex_unlock(&recycleMemBlockListMutex);
-
+static void *memExhaustedCallbackDefault( size_t size )
+{
+    void * ptr = NULL;
+    
+    pthread_mutex_lock( &recycleMemBlockListMutex );
+    int level = recycleBins - 1;
+    while ( level >= 0 && ptr == NULL ) {
+            while ( recycleMemBlockList[ level ] != NULL && ptr == NULL ) {
+                    psMemBlock * old = recycleMemBlockList[ level ];
+                    recycleMemBlockList[ level ] = recycleMemBlockList[ level ] ->nextBlock;
+                    free( old );
+                    ptr = malloc( size );
+                }
+            level--;
+        }
+    pthread_mutex_unlock( &recycleMemBlockListMutex );
+    
     return ptr;
 }
@@ -75,42 +81,42 @@
 static psMemExhaustedCallback memExhaustedCallback = memExhaustedCallbackDefault;
 
-psMemExhaustedCallback psMemExhaustedCallbackSet(psMemExhaustedCallback func)
+psMemExhaustedCallback psMemExhaustedCallbackSet( psMemExhaustedCallback func )
 {
     psMemExhaustedCallback old = memExhaustedCallback;
-
-    if (func != NULL) {
-        memExhaustedCallback = func;
-    } else {
-        memExhaustedCallback = memExhaustedCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memExhaustedCallback = func;
+        } else {
+            memExhaustedCallback = memExhaustedCallbackDefault;
+        }
+        
     return old;
 }
 
-static void memProblemCallbackDefault(const psMemBlock *ptr,
-                                      const char *file, int lineno)
-{
-    if (ptr->refCounter < 1) {
-        psError(__func__,
-                "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
-                ptr->id, ptr->file, ptr->lineno, file, lineno);
-    }
-
-    if (lineno > 0) {
-        psAbort(__func__, "Detected a problem in the memory system at %s:%d", file, lineno);
-    }
+static void memProblemCallbackDefault( const psMemBlock *ptr,
+                                       const char *file, int lineno )
+{
+    if ( ptr->refCounter < 1 ) {
+            psError( __func__,
+                     "Block %ld allocated at %s:%d freed more than once at %s:%d\n",
+                     ptr->id, ptr->file, ptr->lineno, file, lineno );
+        }
+        
+    if ( lineno > 0 ) {
+            psAbort( __func__, "Detected a problem in the memory system at %s:%d", file, lineno );
+        }
 }
 static psMemProblemCallback memProblemCallback = memProblemCallbackDefault;
 
-psMemProblemCallback psMemProblemCallbackSet(psMemProblemCallback func)
+psMemProblemCallback psMemProblemCallbackSet( psMemProblemCallback func )
 {
     psMemProblemCallback old = memProblemCallback;
-
-    if (func != NULL) {
-        memProblemCallback = func;
-    } else {
-        memProblemCallback = memProblemCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memProblemCallback = func;
+        } else {
+            memProblemCallback = memProblemCallbackDefault;
+        }
+        
     return old;
 }
@@ -123,17 +129,17 @@
 psMemoryId p_psMemFreeID = 0;   // notify user this block is freed
 
-psMemoryId psMemAllocateCallbackSetID(psMemoryId id)
+psMemoryId psMemAllocateCallbackSetID( psMemoryId id )
 {
     psMemoryId old = p_psMemAllocateID;
     p_psMemAllocateID = id;
-
+    
     return old;
 }
 
-psMemoryId psMemFreeCallbackSetID(psMemoryId id)
+psMemoryId psMemFreeCallbackSetID( psMemoryId id )
 {
     psMemoryId old = p_psMemFreeID;
     p_psMemFreeID = id;
-
+    
     return old;
 }
@@ -145,15 +151,15 @@
  * isn't resignalled)
  */
-static psMemoryId memAllocateCallbackDefault(const psMemBlock *ptr)
+static psMemoryId memAllocateCallbackDefault( const psMemBlock *ptr )
 {
     static psMemoryId incr = 0;  // "p_psMemAllocateID += incr"
-
+    
     return incr;
 }
 
-static psMemoryId memFreeCallbackDefault(const psMemBlock *ptr)
+static psMemoryId memFreeCallbackDefault( const psMemBlock *ptr )
 {
     static psMemoryId incr = 0;  // "p_psMemFreeID += incr"
-
+    
     return incr;
 }
@@ -165,27 +171,27 @@
 static psMemFreeCallback memFreeCallback = memFreeCallbackDefault;
 
-psMemAllocateCallback psMemAllocateCallbackSet(psMemAllocateCallback func)
+psMemAllocateCallback psMemAllocateCallbackSet( psMemAllocateCallback func )
 {
     psMemFreeCallback old = memAllocateCallback;
-
-    if (func != NULL) {
-        memAllocateCallback =  func;
-    } else {
-        memAllocateCallback = memAllocateCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memAllocateCallback = func;
+        } else {
+            memAllocateCallback = memAllocateCallbackDefault;
+        }
+        
     return old;
 }
 
-psMemFreeCallback psMemFreeCallbackSet(psMemFreeCallback func)
+psMemFreeCallback psMemFreeCallbackSet( psMemFreeCallback func )
 {
     psMemFreeCallback old = memFreeCallback;
-
-    if (func != NULL) {
-        memFreeCallback = func;
-    } else {
-        memFreeCallback = memFreeCallbackDefault;
-    }
-
+    
+    if ( func != NULL ) {
+            memFreeCallback = func;
+        } else {
+            memFreeCallback = memFreeCallbackDefault;
+        }
+        
     return old;
 }
@@ -194,11 +200,11 @@
  * Return memory ID counter for next block to be allocated
  */
-psMemoryId psMemGetId(void)
+psMemoryId psMemGetId( void )
 {
     psMemoryId id;
-    pthread_mutex_lock(&memIdMutex);
+    pthread_mutex_lock( &memIdMutex );
     id = memid + 1;
-    pthread_mutex_unlock(&memIdMutex);
-
+    pthread_mutex_unlock( &memIdMutex );
+    
     return id;
 }
@@ -210,199 +216,199 @@
  */
 
-static int checkMemBlock(const psMemBlock *m, const char* funcName)
+static int checkMemBlock( const psMemBlock *m, const char* funcName )
 {
     // n.b. since this is called by psMemCheckCorruption while the memblock list is mutex locked,
     // we shouldn't call such things as p_psAlloc/p_psFree here.
-
-    if (m == NULL) {
-        psError(funcName,"Memory Corruption: NULL memory block found.");
-        return 1;
-    }
-
-    if (m->refCounter == 0) {
-        // using an unreferenced block of memory, are you?
-        psError(__func__,"Memory Corruption: memory block %ld was freed but still used.",
-                m->id);
-        return 1;
-    }
-
-    if (m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC) {
-        psError(funcName, "Memory Corruption: memory block %ld is corrupted (buffer underflow)",
-                m->id);
-        return 1;
-    }
-    if (*(void**)((int8_t*)(m+1)+m->userMemorySize) != P_PS_MEMMAGIC) {
-        psError(funcName, "Memory Corruption: memory block %ld is corrupted (buffer overflow)",
-                m->id);
-        return 1;
-    }
-
+    
+    if ( m == NULL ) {
+            psError( funcName, "Memory Corruption: NULL memory block found." );
+            return 1;
+        }
+        
+    if ( m->refCounter == 0 ) {
+            // using an unreferenced block of memory, are you?
+            psError( __func__, "Memory Corruption: memory block %ld was freed but still used.",
+                     m->id );
+            return 1;
+        }
+        
+    if ( m->startblock != P_PS_MEMMAGIC || m->endblock != P_PS_MEMMAGIC ) {
+            psError( funcName, "Memory Corruption: memory block %ld is corrupted (buffer underflow)",
+                     m->id );
+            return 1;
+        }
+    if ( *( void** ) ( ( int8_t* ) ( m + 1 ) + m->userMemorySize ) != P_PS_MEMMAGIC ) {
+            psError( funcName, "Memory Corruption: memory block %ld is corrupted (buffer overflow)",
+                     m->id );
+            return 1;
+        }
+        
     return 0;
 }
 
-int psMemCheckCorruption(bool abort_on_error)
+int psMemCheckCorruption( bool abort_on_error )
 {
     int nbad = 0;                       // number of bad blocks
-
+    
     // get exclusive access to the memBlock list to avoid it changing on us while we use it.
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter=lastMemBlockAllocated; iter != NULL; iter=iter->nextBlock) {
-        if (checkMemBlock(iter, __func__)) {
-            nbad++;
-
-            memProblemCallback(iter, __func__, __LINE__);
-
-            if (abort_on_error) {
-                // release the lock on the memblock list
-                pthread_mutex_unlock(&memBlockListMutex);
-                psAbort(__func__, "Detected memory corruption");
-                return nbad;
-            }
-        }
-    }
-
+    pthread_mutex_lock( &memBlockListMutex );
+    
+    for ( psMemBlock * iter = lastMemBlockAllocated; iter != NULL; iter = iter->nextBlock ) {
+            if ( checkMemBlock( iter, __func__ ) ) {
+                    nbad++;
+                    
+                    memProblemCallback( iter, __func__, __LINE__ );
+                    
+                    if ( abort_on_error ) {
+                            // release the lock on the memblock list
+                            pthread_mutex_unlock( &memBlockListMutex );
+                            psAbort( __func__, "Detected memory corruption" );
+                            return nbad;
+                        }
+                }
+        }
+        
     // release the lock on the memblock list
-    pthread_mutex_unlock(&memBlockListMutex);
+    pthread_mutex_unlock( &memBlockListMutex );
     return nbad;
 }
 
-void *p_psAlloc(size_t size, const char *file, int lineno)
-{
-
-    psMemBlock *ptr = NULL;
-
+void *p_psAlloc( size_t size, const char *file, int lineno )
+{
+
+    psMemBlock * ptr = NULL;
+    
     // memory is of the size I want to bother recycling?
-    if (size < P_PS_LARGE_BLOCK_SIZE) {
-        // find the bin we need.
-        int level = 0;
-        while (size > recycleBinSize[level]) {
-            level++;
-        }
-        // Are we in one of the bins
-        if (level<recycleBins) {
-
-            size = recycleBinSize[level];  // round-up size to next sized bin.
-
-            pthread_mutex_lock(&recycleMemBlockListMutex);
-
-            if (recycleMemBlockList[level] != NULL) {
-                ptr = recycleMemBlockList[level];
-                recycleMemBlockList[level] = ptr->nextBlock;
-                if (recycleMemBlockList[level] != NULL) {
-                    recycleMemBlockList[level]->previousBlock = NULL;
-                }
-                size = ptr->userMemorySize;
-            }
-
-            pthread_mutex_unlock(&recycleMemBlockListMutex);
-        }
-    }
-
-    if (ptr == NULL) {
-        ptr = malloc(sizeof(psMemBlock) + size + sizeof(void*));
-
-        if (ptr == NULL) {
-            ptr = memExhaustedCallback(size);
-            if (ptr == NULL) {
-                psAbort(__func__, "Failed to allocate %u bytes at %s:%d",
-                        size, file, lineno);
-            }
-        }
-
-        ptr->startblock = P_PS_MEMMAGIC;
-        ptr->endblock = P_PS_MEMMAGIC;
-        ptr->userMemorySize = size;
-        pthread_mutex_init(&ptr->refCounterMutex, NULL);
-    }
-
+    if ( size < P_PS_LARGE_BLOCK_SIZE ) {
+            // find the bin we need.
+            int level = 0;
+            while ( size > recycleBinSize[ level ] ) {
+                    level++;
+                }
+            // Are we in one of the bins
+            if ( level < recycleBins ) {
+            
+                    size = recycleBinSize[ level ];  // round-up size to next sized bin.
+                    
+                    pthread_mutex_lock( &recycleMemBlockListMutex );
+                    
+                    if ( recycleMemBlockList[ level ] != NULL ) {
+                            ptr = recycleMemBlockList[ level ];
+                            recycleMemBlockList[ level ] = ptr->nextBlock;
+                            if ( recycleMemBlockList[ level ] != NULL ) {
+                                    recycleMemBlockList[ level ] ->previousBlock = NULL;
+                                }
+                            size = ptr->userMemorySize;
+                        }
+                        
+                    pthread_mutex_unlock( &recycleMemBlockListMutex );
+                }
+        }
+        
+    if ( ptr == NULL ) {
+            ptr = malloc( sizeof( psMemBlock ) + size + sizeof( void* ) );
+            
+            if ( ptr == NULL ) {
+                    ptr = memExhaustedCallback( size );
+                    if ( ptr == NULL ) {
+                            psAbort( __func__, "Failed to allocate %u bytes at %s:%d",
+                                     size, file, lineno );
+                        }
+                }
+                
+            ptr->startblock = P_PS_MEMMAGIC;
+            ptr->endblock = P_PS_MEMMAGIC;
+            ptr->userMemorySize = size;
+            pthread_mutex_init( &ptr->refCounterMutex, NULL );
+        }
+        
     // increment the memory id safely.
-    pthread_mutex_lock(&memBlockListMutex);
-    *(psMemoryId*)&ptr->id = ++memid;
-    pthread_mutex_unlock(&memBlockListMutex);
-
+    pthread_mutex_lock( &memBlockListMutex );
+    *( psMemoryId* ) & ptr->id = ++memid;
+    pthread_mutex_unlock( &memBlockListMutex );
+    
     ptr->file = file;
     ptr->freeFcn = NULL;
-    *(unsigned int*)&ptr->lineno = lineno;
-    *(void**)((int8_t*)(ptr+1)+size) = P_PS_MEMMAGIC;
+    *( unsigned int* ) & ptr->lineno = lineno;
+    *( void** ) ( ( int8_t* ) ( ptr + 1 ) + size ) = P_PS_MEMMAGIC;
     ptr->previousBlock = NULL;
-
+    
     ptr->refCounter = 1;                // one user so far
-
+    
     // need exclusive access of the memory block list now...
-    pthread_mutex_lock(&memBlockListMutex);
-
+    pthread_mutex_lock( &memBlockListMutex );
+    
     // insert the new block to the front of the memBlock linked-list
     ptr->nextBlock = lastMemBlockAllocated;
-    if (ptr->nextBlock != NULL) {
-        ptr->nextBlock->previousBlock = ptr;
-    }
+    if ( ptr->nextBlock != NULL ) {
+            ptr->nextBlock->previousBlock = ptr;
+        }
     lastMemBlockAllocated = ptr;
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
+    
+    pthread_mutex_unlock( &memBlockListMutex );
+    
     //  Did the user ask to be informed about this allocation?
-    if (ptr->id == p_psMemAllocateID) {
-        p_psMemAllocateID += memAllocateCallback(ptr);
-    }
-
+    if ( ptr->id == p_psMemAllocateID ) {
+            p_psMemAllocateID += memAllocateCallback( ptr );
+        }
+        
     // And return the user the memory that they allocated
     return ptr + 1;   // user memory
 }
 
-void *p_psRealloc(void *vptr, size_t size, const char *file, int lineno)
-{
-    if (vptr == NULL) {
-        return p_psAlloc(size, file, lineno);
-    } else {
-        psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-        bool isBlockLast = false;
-
-        if (checkMemBlock(ptr, __func__) != 0) {
-            memProblemCallback(ptr, file, lineno);
-            psAbort(file,"Realloc detected a memory corruption (id %ld @ %s:%d).",
-                    ptr->id,ptr->file,ptr->lineno);
-        }
-
-        pthread_mutex_lock(&memBlockListMutex);
-
-        isBlockLast = (ptr == lastMemBlockAllocated);
-
-        ptr = (psMemBlock*)realloc(ptr, sizeof(psMemBlock) + size + sizeof(void*));
-
-        if (ptr == NULL) {
-            psAbort(__func__, "Failed to reallocate %ld bytes at %s:%d",
-                    size, file, lineno);
-        }
-
-        ptr->userMemorySize = size;
-        *(void**)((int8_t*)(ptr+1)+size) = P_PS_MEMMAGIC;
-
-        if (isBlockLast) {
-            lastMemBlockAllocated = ptr;
-        }
-
-        // the block location may have changed, so fix the linked list addresses.
-        if (ptr->nextBlock != NULL) {
-            ptr->nextBlock->previousBlock = ptr;
-        }
-        if (ptr->previousBlock != NULL) {
-            ptr->previousBlock->nextBlock = ptr;
-        }
-
-        pthread_mutex_unlock(&memBlockListMutex);
-
-        //  Did the user ask to be informed about this allocation?
-        if (ptr->id == p_psMemAllocateID) {
-            p_psMemAllocateID += memAllocateCallback(ptr);
-        }
-
-        return ptr + 1;   // usr memory
-    }
-}
-
-void p_psFree(void *vptr, const char *file, int lineno)
-{
-    (void)p_psMemDecrRefCounter(vptr,file,lineno);   // this handles the free, if required.
+void *p_psRealloc( void *vptr, size_t size, const char *file, int lineno )
+{
+    if ( vptr == NULL ) {
+            return p_psAlloc( size, file, lineno );
+        } else {
+            psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+            bool isBlockLast = false;
+            
+            if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+                    memProblemCallback( ptr, file, lineno );
+                    psAbort( file, "Realloc detected a memory corruption (id %ld @ %s:%d).",
+                             ptr->id, ptr->file, ptr->lineno );
+                }
+                
+            pthread_mutex_lock( &memBlockListMutex );
+            
+            isBlockLast = ( ptr == lastMemBlockAllocated );
+            
+            ptr = ( psMemBlock* ) realloc( ptr, sizeof( psMemBlock ) + size + sizeof( void* ) );
+            
+            if ( ptr == NULL ) {
+                    psAbort( __func__, "Failed to reallocate %ld bytes at %s:%d",
+                             size, file, lineno );
+                }
+                
+            ptr->userMemorySize = size;
+            *( void** ) ( ( int8_t* ) ( ptr + 1 ) + size ) = P_PS_MEMMAGIC;
+            
+            if ( isBlockLast ) {
+                    lastMemBlockAllocated = ptr;
+                }
+                
+            // the block location may have changed, so fix the linked list addresses.
+            if ( ptr->nextBlock != NULL ) {
+                    ptr->nextBlock->previousBlock = ptr;
+                }
+            if ( ptr->previousBlock != NULL ) {
+                    ptr->previousBlock->nextBlock = ptr;
+                }
+                
+            pthread_mutex_unlock( &memBlockListMutex );
+            
+            //  Did the user ask to be informed about this allocation?
+            if ( ptr->id == p_psMemAllocateID ) {
+                    p_psMemAllocateID += memAllocateCallback( ptr );
+                }
+                
+            return ptr + 1;   // usr memory
+        }
+}
+
+void p_psFree( void *vptr, const char *file, int lineno )
+{
+    ( void ) p_psMemDecrRefCounter( vptr, file, lineno );   // this handles the free, if required.
 }
 
@@ -410,46 +416,46 @@
  * Check for memory leaks.
  */
-int psMemCheckLeaks(psMemoryId id0,psMemBlock ***arr,FILE *fd)
+int psMemCheckLeaks( psMemoryId id0, psMemBlock ***arr, FILE *fd )
 {
     int nleak = 0;
     int j = 0;
     psMemBlock* topBlock = lastMemBlockAllocated;
-
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = topBlock; iter != NULL; iter=iter->nextBlock) {
-        if ( (psMemGetRefCounter(iter+1) > 0) && (iter->id >= id0) ) {
-            nleak++;
-
-            if (fd != NULL) {
-                if (nleak == 1) {
-                    fprintf(fd, "   %20s:line ID\n", "file");
-                }
-
-                fprintf(fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id);
-            }
-        }
-    }
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
-    if (nleak == 0 || arr == NULL) {
-        return nleak;
-    }
-
-    *arr = p_psAlloc(nleak*sizeof(psMemBlock), __FILE__, __LINE__);
-    pthread_mutex_lock(&memBlockListMutex);
-
-    for (psMemBlock* iter = topBlock; iter != NULL; iter=iter->nextBlock) {
-        if ( (psMemGetRefCounter(iter+1) > 0) && (iter->id >= id0) ) {
-            (*arr)[j++] = iter;
-            if (j == nleak) { // found them all
-                break;
-            }
-        }
-    }
-
-    pthread_mutex_unlock(&memBlockListMutex);
-
+    
+    pthread_mutex_lock( &memBlockListMutex );
+    
+    for ( psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock ) {
+            if ( ( psMemGetRefCounter( iter + 1 ) > 0 ) && ( iter->id >= id0 ) ) {
+                    nleak++;
+                    
+                    if ( fd != NULL ) {
+                            if ( nleak == 1 ) {
+                                    fprintf( fd, "   %20s:line ID\n", "file" );
+                                }
+                                
+                            fprintf( fd, "   %20s:%-4d %ld\n", iter->file, iter->lineno, iter->id );
+                        }
+                }
+        }
+        
+    pthread_mutex_unlock( &memBlockListMutex );
+    
+    if ( nleak == 0 || arr == NULL ) {
+            return nleak;
+        }
+        
+    *arr = p_psAlloc( nleak * sizeof( psMemBlock ), __FILE__, __LINE__ );
+    pthread_mutex_lock( &memBlockListMutex );
+    
+    for ( psMemBlock * iter = topBlock; iter != NULL; iter = iter->nextBlock ) {
+            if ( ( psMemGetRefCounter( iter + 1 ) > 0 ) && ( iter->id >= id0 ) ) {
+                    ( *arr ) [ j++ ] = iter;
+                    if ( j == nleak ) { // found them all
+                            break;
+                        }
+                }
+        }
+        
+    pthread_mutex_unlock( &memBlockListMutex );
+    
     return nleak;
 }
@@ -457,173 +463,169 @@
 /*
  * Reference counting APIs
- */
+ */ 
 // return refCounter
-psReferenceCount psMemGetRefCounter(void *vptr)
-{
-    psMemBlock *ptr;
+psReferenceCount psMemGetRefCounter( void *vptr )
+{
+    psMemBlock * ptr;
     unsigned int refCount;
-
-    if (vptr == NULL) {
-        return 0;
-    }
-
-    ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
-    pthread_mutex_lock(&ptr->refCounterMutex);
+    
+    if ( vptr == NULL ) {
+            return 0;
+        }
+        
+    ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, __func__, __LINE__ );
+        }
+        
+    pthread_mutex_lock( &ptr->refCounterMutex );
     refCount = ptr->refCounter;
-    pthread_mutex_unlock(&ptr->refCounterMutex);
-
+    pthread_mutex_unlock( &ptr->refCounterMutex );
+    
     return refCount;
 }
 // increment and return refCounter
-void* p_psMemIncrRefCounter(void *vptr, const char *file, int lineno)
-{
-    psMemBlock *ptr;
-
-    if (vptr == NULL) {
-        return vptr;
-    }
-
-    ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__)) {
-        memProblemCallback(ptr, file,lineno);
-    }
-
-    pthread_mutex_lock(&ptr->refCounterMutex);
+void* p_psMemIncrRefCounter( void *vptr, const char *file, int lineno )
+{
+    psMemBlock * ptr;
+    
+    if ( vptr == NULL ) {
+            return vptr;
+        }
+        
+    ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) ) {
+            memProblemCallback( ptr, file, lineno );
+        }
+        
+    pthread_mutex_lock( &ptr->refCounterMutex );
     ptr->refCounter++;
-    pthread_mutex_unlock(&ptr->refCounterMutex);
-
+    pthread_mutex_unlock( &ptr->refCounterMutex );
+    
     return vptr;
 }
 
 // decrement and return refCounter
-void* p_psMemDecrRefCounter(void *vptr,const char *file, int lineno)
-{
-    if (vptr == NULL) {
-        return NULL;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, file, lineno);
-        return NULL;
-    }
-
-    pthread_mutex_lock(&ptr->refCounterMutex);
-
-    if (ptr->refCounter > 1) {
-        /// XXX - Probably should have another mutex here.
-        ptr->refCounter--;          // multiple references, just decrement the count.
-        pthread_mutex_unlock(&ptr->refCounterMutex);
-
-    } else {
-        pthread_mutex_unlock(&ptr->refCounterMutex);
-
-        // Did the user ask to be informed about this deallocation?
-        if (ptr->id == p_psMemFreeID) {
-            p_psMemFreeID += memFreeCallback(ptr);
-        }
-
-        if (ptr->freeFcn != NULL) {
-            ptr->freeFcn(vptr);
-        }
-
-        pthread_mutex_lock(&memBlockListMutex);
-
-        // cut the memBlock out of the memBlock list
-        if (ptr->nextBlock != NULL) {
-            ptr->nextBlock->previousBlock = ptr->previousBlock;
-        }
-        if (ptr->previousBlock != NULL) {
-            ptr->previousBlock->nextBlock = ptr->nextBlock;
-        }
-        if (lastMemBlockAllocated == ptr) {
-            lastMemBlockAllocated = ptr->nextBlock;
-        }
-
-        pthread_mutex_unlock(&memBlockListMutex);
-
-
-        // do we need to recycle?
-        if (ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE) {
-
-            int level = 1;
-            while (ptr->userMemorySize >= recycleBinSize[level]) {
-                level++;
-            }
-            level--;
-
-            ptr->refCounter = 0;
-            ptr->previousBlock = NULL;
-
-            pthread_mutex_lock(&recycleMemBlockListMutex);
-            ptr->nextBlock = recycleMemBlockList[level];
-            if (recycleMemBlockList[level] != NULL) {
-                recycleMemBlockList[level]->previousBlock = ptr;
-            }
-            recycleMemBlockList[level] = ptr;
-            pthread_mutex_unlock(&recycleMemBlockListMutex);
-
+void* p_psMemDecrRefCounter( void *vptr, const char *file, int lineno )
+{
+    if ( vptr == NULL ) {
+            return NULL;
+        }
+        
+    psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, file, lineno );
+            return NULL;
+        }
+        
+    pthread_mutex_lock( &ptr->refCounterMutex );
+    
+    if ( ptr->refCounter > 1 ) {
+            /// XXX - Probably should have another mutex here.
+            ptr->refCounter--;          // multiple references, just decrement the count.
+            pthread_mutex_unlock( &ptr->refCounterMutex );
+            
         } else {
-            // memory is larger than I want to recycle.
-            #ifdef PS_MEM_DEBUG
-            (void)p_psRealloc(vptr,0,file,lineno);
-            ptr->previousBlock = NULL;
-            ptr->nextBlock = deadBlockList;
-            if (deadBlockList != NULL) {
-                deadBlockList->previous = ptr;
-            }
-            deadBlockList = ptr;
-            #else
-
-            pthread_mutex_destroy(&ptr->refCounterMutex);
-            free(ptr);
-            #endif
-
-        }
-
-
-        pthread_mutex_destroy(&ptr->refCounterMutex);
-
-
-        vptr = NULL;    // since we freed it, make sure we return NULL.
-    }
-
+            pthread_mutex_unlock( &ptr->refCounterMutex );
+            
+            // Did the user ask to be informed about this deallocation?
+            if ( ptr->id == p_psMemFreeID ) {
+                    p_psMemFreeID += memFreeCallback( ptr );
+                }
+                
+            if ( ptr->freeFcn != NULL ) {
+                    ptr->freeFcn( vptr );
+                }
+                
+            pthread_mutex_lock( &memBlockListMutex );
+            
+            // cut the memBlock out of the memBlock list
+            if ( ptr->nextBlock != NULL ) {
+                    ptr->nextBlock->previousBlock = ptr->previousBlock;
+                }
+            if ( ptr->previousBlock != NULL ) {
+                    ptr->previousBlock->nextBlock = ptr->nextBlock;
+                }
+            if ( lastMemBlockAllocated == ptr ) {
+                    lastMemBlockAllocated = ptr->nextBlock;
+                }
+                
+            pthread_mutex_unlock( &memBlockListMutex );
+            
+            
+            // do we need to recycle?
+            if ( ptr->userMemorySize < P_PS_LARGE_BLOCK_SIZE ) {
+            
+                    int level = 1;
+                    while ( ptr->userMemorySize >= recycleBinSize[ level ] ) {
+                            level++;
+                        }
+                    level--;
+                    
+                    ptr->refCounter = 0;
+                    ptr->previousBlock = NULL;
+                    
+                    pthread_mutex_lock( &recycleMemBlockListMutex );
+                    ptr->nextBlock = recycleMemBlockList[ level ];
+                    if ( recycleMemBlockList[ level ] != NULL ) {
+                            recycleMemBlockList[ level ] ->previousBlock = ptr;
+                        }
+                    recycleMemBlockList[ level ] = ptr;
+                    pthread_mutex_unlock( &recycleMemBlockListMutex );
+                    
+                } else {
+                    // memory is larger than I want to recycle.
+                    #ifdef PS_MEM_DEBUG
+                    ( void ) p_psRealloc( vptr, 0, file, lineno );
+                    ptr->previousBlock = NULL;
+                    ptr->nextBlock = deadBlockList;
+                    if ( deadBlockList != NULL ) {
+                            deadBlockList->previous = ptr;
+                        }
+                    deadBlockList = ptr;
+                    #else
+                    
+                    pthread_mutex_destroy( &ptr->refCounterMutex );
+                    free( ptr );
+                    #endif
+                    
+                }
+                
+            vptr = NULL;    // since we freed it, make sure we return NULL.
+        }
+        
     return vptr;
 }
 
-void p_psMemSetDeallocator(void* vptr, psFreeFcn freeFcn)
-{
-    if (vptr == NULL) {
-        return;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
+void p_psMemSetDeallocator( void* vptr, psFreeFcn freeFcn )
+{
+    if ( vptr == NULL ) {
+            return ;
+        }
+        
+    psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, __func__, __LINE__ );
+        }
+        
     ptr->freeFcn = freeFcn;
-
-}
-psFreeFcn p_psMemGetDeallocator(void* vptr)
-{
-    if (vptr == NULL) {
-        return NULL;
-    }
-
-    psMemBlock *ptr = ((psMemBlock *)vptr) - 1;
-
-    if (checkMemBlock(ptr, __func__) != 0) {
-        memProblemCallback(ptr, __func__, __LINE__);
-    }
-
+    
+}
+psFreeFcn p_psMemGetDeallocator( void* vptr )
+{
+    if ( vptr == NULL ) {
+            return NULL;
+        }
+        
+    psMemBlock *ptr = ( ( psMemBlock * ) vptr ) - 1;
+    
+    if ( checkMemBlock( ptr, __func__ ) != 0 ) {
+            memProblemCallback( ptr, __func__, __LINE__ );
+        }
+        
     return ptr->freeFcn;
 }
Index: /trunk/psLib/src/sysUtils/psType.h
===================================================================
--- /trunk/psLib/src/sysUtils/psType.h	(revision 1359)
+++ /trunk/psLib/src/sysUtils/psType.h	(revision 1360)
@@ -1,18 +1,18 @@
 /** @file  psType.h
- *
- *  @brief Contains support for basic types
- *
- *  This file defines common datatypes used throughout psLib.
- *
- *  @ingroup DataContainer
- *
- *  @author Robert DeSonia, MHPCC
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-24 02:00:21 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
+*
+*  @brief Contains support for basic types
+*
+*  This file defines common datatypes used throughout psLib.
+*
+*  @ingroup DataContainer
+*
+*  @author Robert DeSonia, MHPCC
+*  @author Ross Harman, MHPCC
+*
+*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-07-31 02:28:10 $
+*
+*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
+*/
 
 #ifndef PS_TYPE_H
@@ -37,36 +37,37 @@
  */
 
-typedef uint8_t         psU8;           ///< 8-bit unsigned int
-typedef uint16_t        psU16;          ///< 16-bit unsigned int
-typedef uint32_t        psU32;          ///< 32-bit unsigned int
-typedef uint64_t        psU64;          ///< 64-bit unsigned int
-typedef int8_t          psS8;           ///< 8-bit signed int
-typedef int16_t         psS16;          ///< 16-bit signed int
-typedef int32_t         psS32;          ///< 32-bit signed int
-typedef int64_t         psS64;          ///< 64-bit signed int
-typedef float           psF32;          ///< 32-bit floating point
-typedef double          psF64;          ///< 64-bit floating point
-typedef complex float   psC32;          ///< complex with 32-bit floating point Real and Imagary numbers
-typedef complex double  psC64;          ///< complex with 64-bit floating point Real and Imagary numbers
-typedef void*           psPTR;           ///< void pointer
+typedef uint8_t psU8;           ///< 8-bit unsigned int
+typedef uint16_t psU16;          ///< 16-bit unsigned int
+typedef uint32_t psU32;          ///< 32-bit unsigned int
+typedef uint64_t psU64;          ///< 64-bit unsigned int
+typedef int8_t psS8;           ///< 8-bit signed int
+typedef int16_t psS16;          ///< 16-bit signed int
+typedef int32_t psS32;          ///< 32-bit signed int
+typedef int64_t psS64;          ///< 64-bit signed int
+typedef float psF32;          ///< 32-bit floating point
+typedef double psF64;          ///< 64-bit floating point
+typedef complex float psC32;          ///< complex with 32-bit floating point Real and Imagary numbers
+typedef complex double psC64;          ///< complex with 64-bit floating point Real and Imagary numbers
+typedef void* psPTR;           ///< void pointer
 
 
 typedef enum {
-    PS_TYPE_S8               = 0x0101,  ///< Character.
-    PS_TYPE_S16              = 0x0102,  ///< Short integer.
-    PS_TYPE_S32              = 0x0104,  ///< Integer.
-    PS_TYPE_S64              = 0x0108,  ///< Long integer.
-    PS_TYPE_U8               = 0x0301,  ///< Unsigned character.
-    PS_TYPE_U16              = 0x0302,  ///< Unsigned short integer.
-    PS_TYPE_U32              = 0x0304,  ///< Unsigned integer.
-    PS_TYPE_U64              = 0x0308,  ///< Unsigned long integer.
-    PS_TYPE_F32              = 0x0404,  ///< Single-precision Floating point.
-    PS_TYPE_F64              = 0x0408,  ///< Double-precision floating point.
-    PS_TYPE_C32              = 0x0808,  ///< Complex numbers consisting of single-precision floating point.
-    PS_TYPE_C64              = 0x0810,  ///< Complex numbers consisting of double-precision floating point.
-    PS_TYPE_PTR              = 0x0000   ///< Something else that's not supported for arithmetic.
+    PS_TYPE_S8 = 0x0101,   ///< Character.
+    PS_TYPE_S16 = 0x0102,   ///< Short integer.
+    PS_TYPE_S32 = 0x0104,   ///< Integer.
+    PS_TYPE_S64 = 0x0108,   ///< Long integer.
+    PS_TYPE_U8 = 0x0301,   ///< Unsigned character.
+    PS_TYPE_U16 = 0x0302,   ///< Unsigned short integer.
+    PS_TYPE_U32 = 0x0304,   ///< Unsigned integer.
+    PS_TYPE_U64 = 0x0308,   ///< Unsigned long integer.
+    PS_TYPE_F32 = 0x0404,   ///< Single-precision Floating point.
+    PS_TYPE_F64 = 0x0408,   ///< Double-precision floating point.
+    PS_TYPE_C32 = 0x0808,   ///< Complex numbers consisting of single-precision floating point.
+    PS_TYPE_C64 = 0x0810,   ///< Complex numbers consisting of double-precision floating point.
+    PS_TYPE_PTR = 0x0000   ///< Something else that's not supported for arithmetic.
 } psElemType;
 
 #define PS_TYPE_MASK PS_TYPE_U8         ///< the psElemType to use for mask image
+#define PS_TYPE_MASK_DATA U8            ///< the data member to use for mask image
 #define PS_TYPE_MASK_NAME "psU8"
 typedef psU8 psMaskType;                ///< the C datatype for a mask image
@@ -127,8 +128,8 @@
  */
 typedef enum {
-    PS_DIMEN_SCALAR,    ///< Scalar.
-    PS_DIMEN_VECTOR,    ///< Vector.
-    PS_DIMEN_TRANSV,    ///< Transposed vector.
-    PS_DIMEN_IMAGE,     ///< Image.
+    PS_DIMEN_SCALAR,     ///< Scalar.
+    PS_DIMEN_VECTOR,     ///< Vector.
+    PS_DIMEN_TRANSV,     ///< Transposed vector.
+    PS_DIMEN_IMAGE,      ///< Image.
     PS_DIMEN_OTHER      ///< Something else that's not supported for arithmetic.
 } psDimen;
@@ -141,8 +142,8 @@
  */
 typedef struct
-{
-    psElemType type;    ///< Primitive type.
-    psDimen dimen;      ///< Dimensionality.
-}
+    {
+        psElemType type;    ///< Primitive type.
+        psDimen dimen;      ///< Dimensionality.
+    }
 psType;
 
Index: /trunk/psLib/test/psTest.c
===================================================================
--- /trunk/psLib/test/psTest.c	(revision 1359)
+++ /trunk/psLib/test/psTest.c	(revision 1360)
@@ -27,6 +27,6 @@
 #define HEADER_BOTTOM "\\**********************************************************************************/\n\n"
 
-bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName,
-                    testDescription tests[], int argc, char * const argv[])
+bool p_runTestSuite( FILE *fp, const char* testPointFile, const char* packageName,
+                     testDescription tests[], int argc, char * const argv[] )
 {
     bool success = true;
@@ -37,201 +37,206 @@
     int n;
     extern char *optarg;
-
-    if (argc > 0) {
-        while ( (c=getopt(argc,argv,"lhn:dt:")) != -1) {
-            switch (c) {
-            case 'h':
-                printf("Usage: %s [-l] [-d] [-h] [-n=Testpoint#] [-t=TestpointName]\n"
-                       "    where:\n"
-                       "           -l  : lists the testpoints contained in this test driver executable\n"
-                       "           -d  : turns on debugger-friendly mode (no forking, aborts/signals are not handled)\n"
-                       "           -h  : prints this help\n"
-                       "           -n  : specifies a particular testpoint by number to run\n"
-                       "           -t  : specifies a particular testpoint by name to run\n"
-                       "    (if no -l, -n or -t options are given, all testpoints are run)\n",
-                       argv[0]);
-                runAll = false;
-                break;
-            case 'd':
-                useFork = false;
-                break;
-            case 'l':
-                printf("Test Driver:  %s\n",testPointFile);
-                printf("Package Name: %s\n",packageName);
-                printf("Testpoints:\n");
-                runAll = false;
-                for (int index=0; tests[index].fcn != NULL; index++) {
-                    printf("    %6d - %s \n",tests[index].testPointNumber,
-                           tests[index].testPointName);
-                }
-                printf("\n");
-                break;
-            case 't':
-                runAll = false;
-                for (int index=0; tests[index].fcn != NULL; index++) {
-                    if (strcmp(optarg,tests[index].testPointName) == 0) {
-                        success = p_runTest(fp,
-                                            testPointFile,
-                                            packageName,
-                                            tests[index].testPointName,
-                                            tests[index].fcn,
-                                            tests[index].expectedReturn,
-                                            useFork) && success;
-                    }
-                }
-                break;
-            case 'n':
-                runAll = false;
-                if (sscanf(optarg,"%i",&n) != 1) {
-                    psError(__func__,"Failed to parse the testpoint number (%s).",
-                            optarg);
-                    break;
-                }
-                found = false;
-                for (int index=0; tests[index].fcn != NULL; index++) {
-                    if (n==tests[index].testPointNumber) {
-                        found = true;
-                        success = p_runTest(fp,
-                                            testPointFile,
-                                            packageName,
-                                            tests[index].testPointName,
-                                            tests[index].fcn,
-                                            tests[index].expectedReturn,
-                                            useFork) && success;
-                    }
-                }
-                if (! found) {
-                    psError(__func__,"The specified testpoint number (%d) doesn't exist in this test driver.",
-                            n);
-                    break;
-                }
-                break;
-            case '?':
-                psError(__func__,"Option %s is not recognized and is ignored.",optarg);
-                break;
-            }
-        }
-    }
-
-    if (runAll) {
-        for (int index=0; tests[index].fcn != NULL; index++) {
-            if (! tests[index].isDuplicateEntry) {
-                success = p_runTest(fp,
-                                    testPointFile,
-                                    packageName,
-                                    tests[index].testPointName,
-                                    tests[index].fcn,
-                                    tests[index].expectedReturn,
-                                    useFork) && success;
-            }
-        }
-    }
+    
+    if ( argc > 0 ) {
+            while ( ( c = getopt( argc, argv, "lhn:dt:" ) ) != -1 ) {
+                    switch ( c ) {
+                            case 'h':
+                            printf( "Usage: %s [-l] [-d] [-h] [-n=Testpoint#] [-t=TestpointName]\n"
+                                    "    where:\n"
+                                    "           -l  : lists the testpoints contained in this test driver executable\n"
+                                    "           -d  : turns on debugger-friendly mode (no forking, aborts/signals are not handled)\n"
+                                    "           -h  : prints this help\n"
+                                    "           -n  : specifies a particular testpoint by number to run\n"
+                                    "           -t  : specifies a particular testpoint by name to run\n"
+                                    "    (if no -l, -n or -t options are given, all testpoints are run)\n",
+                                    argv[ 0 ] );
+                            runAll = false;
+                            break;
+                            case 'd':
+                            useFork = false;
+                            break;
+                            case 'l':
+                            printf( "Test Driver:  %s\n", testPointFile );
+                            printf( "Package Name: %s\n", packageName );
+                            printf( "Testpoints:\n" );
+                            runAll = false;
+                            for ( int index = 0; tests[ index ].fcn != NULL; index++ ) {
+                                    printf( "    %6d - %s \n", tests[ index ].testPointNumber,
+                                            tests[ index ].testPointName );
+                                }
+                            printf( "\n" );
+                            break;
+                            case 't':
+                            runAll = false;
+                            for ( int index = 0; tests[ index ].fcn != NULL; index++ ) {
+                                    if ( strcmp( optarg, tests[ index ].testPointName ) == 0 ) {
+                                            success = p_runTest( fp,
+                                                                 testPointFile,
+                                                                 packageName,
+                                                                 tests[ index ].testPointName,
+                                                                 tests[ index ].fcn,
+                                                                 tests[ index ].expectedReturn,
+                                                                 useFork ) && success;
+                                        }
+                                }
+                            break;
+                            case 'n':
+                            runAll = false;
+                            if ( sscanf( optarg, "%i", &n ) != 1 ) {
+                                    psError( __func__, "Failed to parse the testpoint number (%s).",
+                                             optarg );
+                                    break;
+                                }
+                            found = false;
+                            for ( int index = 0; tests[ index ].fcn != NULL; index++ ) {
+                                    if ( n == tests[ index ].testPointNumber ) {
+                                            found = true;
+                                            success = p_runTest( fp,
+                                                                 testPointFile,
+                                                                 packageName,
+                                                                 tests[ index ].testPointName,
+                                                                 tests[ index ].fcn,
+                                                                 tests[ index ].expectedReturn,
+                                                                 useFork ) && success;
+                                        }
+                                }
+                            if ( ! found ) {
+                                    psError( __func__, "The specified testpoint number (%d) doesn't exist in this test driver.",
+                                             n );
+                                    break;
+                                }
+                            break;
+                            case '?':
+                            psError( __func__, "Option %s is not recognized and is ignored.", optarg );
+                            break;
+                        }
+                }
+        }
+        
+    if ( runAll ) {
+            for ( int index = 0; tests[ index ].fcn != NULL; index++ ) {
+                    if ( ! tests[ index ].isDuplicateEntry ) {
+                            success = p_runTest( fp,
+                                                 testPointFile,
+                                                 packageName,
+                                                 tests[ index ].testPointName,
+                                                 tests[ index ].fcn,
+                                                 tests[ index ].expectedReturn,
+                                                 useFork ) && success;
+                        }
+                }
+        }
+        
+    if ( ! success ) {
+            psError( testPointFile, "One or more tests failed" );
+        }
+        
     return success;
 }
 
-bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
-               testFcn fcn, int expectedReturn, bool useFork)
+bool p_runTest( FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
+                testFcn fcn, int expectedReturn, bool useFork )
 {
     int childReturn = 0;
     pid_t child;
-
-    p_printPositiveTestHeader(fp,testPointFile,packageName,testPointName);
-
-    if (useFork) {
-        child = fork();
-        if (child == 0) {                   // I am the child process, run the test
+    
+    p_printPositiveTestHeader( fp, testPointFile, packageName, testPointName );
+    
+    if ( useFork ) {
+            child = fork();
+            if ( child == 0 ) {                   // I am the child process, run the test
+                    int currentId = psMemGetId();
+                    int retVal = fcn();
+                    if ( retVal == 0 ) { // only bother checking memory if test executed to end.
+                            if ( psMemCheckLeaks( currentId, NULL, stderr ) != 0 ) {
+                                    psError( __func__, "Memory Leaks Detected" );
+                                    retVal = 64;
+                                }
+                            psMemCheckCorruption( 1 );
+                        }
+                    exit( retVal );
+                } else if ( child < 0 ) {
+                    fprintf( fp, "Couldn't fork a process to run a negative test (%s|%s)",
+                             packageName, testPointName );
+                    abort();
+                }
+                
+            waitpid( child, &childReturn, 0 );
+            if ( WIFSIGNALED( childReturn ) ) {
+                    childReturn = -WTERMSIG( childReturn );
+                } else {
+                    childReturn = WEXITSTATUS( childReturn );
+                }
+        } else {
             int currentId = psMemGetId();
-            int retVal = fcn();
-            if (retVal == 0) { // only bother checking memory if test executed to end.
-                if (psMemCheckLeaks(currentId,NULL,stderr) != 0) {
-                    psError(__func__,"Memory Leaks Detected");
-                    retVal = 64;
-                }
-                psMemCheckCorruption(1);
-            }
-            exit(retVal);
-        } else if (child < 0) {
-            fprintf(fp,"Couldn't fork a process to run a negative test (%s|%s)",
-                    packageName, testPointName);
-            abort();
-        }
-
-        waitpid(child,&childReturn,0);
-        if (WIFSIGNALED(childReturn)) {
-            childReturn =  -WTERMSIG(childReturn);
+            childReturn = fcn();
+            if ( childReturn == 0 ) { // only bother checking memory if test executed to end.
+                    if ( psMemCheckLeaks( currentId, NULL, stderr ) != 0 ) {
+                            psError( __func__, "Memory Leaks Detected" );
+                            childReturn = 64;
+                        }
+                    psMemCheckCorruption( 1 );
+                }
+        }
+        
+        
+    if ( childReturn != expectedReturn ) {
+            fprintf( fp, "Return value mismatch: expected %d, got %d",
+                     expectedReturn, childReturn );
+        }
+        
+    p_printFooter( fp, testPointFile, packageName, testPointName,
+                   ( childReturn == expectedReturn ) );
+                   
+    return ( childReturn == expectedReturn );
+}
+
+void p_printPositiveTestHeader( FILE *fp,
+                                const char* testPointFile,
+                                const char* packageName,
+                                const char* testPointName )
+{
+    char TP[ 80 ];
+    
+    snprintf( TP, 80, "%s{%s}", packageName, testPointName );
+    
+    fprintf( fp, HEADER_TOP );
+    fprintf( fp, HEADER_LINE_STRING, "TestFile", testPointFile );
+    fprintf( fp, HEADER_LINE_STRING, "TestPoint", TP );
+    fprintf( fp, HEADER_LINE_STRING, "TestType", "Positive" );
+    fprintf( fp, HEADER_BOTTOM );
+}
+
+void p_printNegativeTestHeader( FILE *fp,
+                                const char* testPointFile,
+                                const char* packageName,
+                                const char* testPointName,
+                                const char* expectedError,
+                                int exitValue )
+{
+    char TP[ 80 ];
+    
+    snprintf( TP, 80, "%s{%s}", packageName, testPointName );
+    
+    fprintf( fp, HEADER_TOP );
+    fprintf( fp, HEADER_LINE_STRING, "TestFile", testPointFile );
+    fprintf( fp, HEADER_LINE_STRING, "TestPoint", TP );
+    fprintf( fp, HEADER_LINE_STRING, "TestType", "Negative" );
+    fprintf( fp, HEADER_LINE_STRING, "ExpectedErrorText", expectedError );
+    fprintf( fp, HEADER_LINE_INT, "ExpectedStatusValue", exitValue );
+    fprintf( fp, HEADER_BOTTOM );
+}
+
+
+void p_printFooter( FILE *fp,
+                    const char* testPointFile,
+                    const char* packageName,
+                    const char* testPointName,
+                    bool success )
+{
+    if ( success ) {
+            fprintf( fp, "\n---> TESTPOINT PASSED (%s{%s} | %s)\n\n", packageName, testPointName, testPointFile );
         } else {
-            childReturn = WEXITSTATUS(childReturn);
-        }
-    } else {
-        int currentId = psMemGetId();
-        childReturn = fcn();
-        if (childReturn == 0) { // only bother checking memory if test executed to end.
-            if (psMemCheckLeaks(currentId,NULL,stderr) != 0) {
-                psError(__func__,"Memory Leaks Detected");
-                childReturn = 64;
-            }
-            psMemCheckCorruption(1);
-        }
-    }
-
-
-    if (childReturn != expectedReturn) {
-        fprintf(fp,"Return value mismatch: expected %d, got %d",
-                expectedReturn,childReturn);
-    }
-
-    p_printFooter(fp,testPointFile,packageName,testPointName,
-                  (childReturn==expectedReturn));
-
-    return (childReturn==expectedReturn);
-}
-
-void p_printPositiveTestHeader(FILE *fp,
-                               const char* testPointFile,
-                               const char* packageName,
-                               const char* testPointName)
-{
-    char TP[80];
-
-    snprintf(TP,80,"%s{%s}",packageName,testPointName);
-
-    fprintf(fp, HEADER_TOP);
-    fprintf(fp, HEADER_LINE_STRING, "TestFile", testPointFile);
-    fprintf(fp, HEADER_LINE_STRING, "TestPoint", TP);
-    fprintf(fp, HEADER_LINE_STRING, "TestType","Positive");
-    fprintf(fp, HEADER_BOTTOM);
-}
-
-void p_printNegativeTestHeader(FILE *fp,
-                               const char* testPointFile,
-                               const char* packageName,
-                               const char* testPointName,
-                               const char* expectedError,
-                               int exitValue)
-{
-    char TP[80];
-
-    snprintf(TP,80,"%s{%s}",packageName,testPointName);
-
-    fprintf(fp, HEADER_TOP);
-    fprintf(fp, HEADER_LINE_STRING, "TestFile", testPointFile);
-    fprintf(fp, HEADER_LINE_STRING, "TestPoint", TP);
-    fprintf(fp, HEADER_LINE_STRING,"TestType","Negative");
-    fprintf(fp, HEADER_LINE_STRING,"ExpectedErrorText",expectedError);
-    fprintf(fp, HEADER_LINE_INT,"ExpectedStatusValue",exitValue);
-    fprintf(fp, HEADER_BOTTOM);
-}
-
-
-void p_printFooter(FILE *fp,
-                   const char* testPointFile,
-                   const char* packageName,
-                   const char* testPointName,
-                   bool success)
-{
-    if (success) {
-        fprintf(fp, "\n---> TESTPOINT PASSED (%s{%s} | %s)\n\n", packageName,testPointName, testPointFile);
-    } else {
-        fprintf(fp, "\n---> TESTPOINT FAILED (%s{%s} | %s)\n\n", packageName,testPointName,testPointFile);
-    }
-}
+            fprintf( fp, "\n---> TESTPOINT FAILED (%s{%s} | %s)\n\n", packageName, testPointName, testPointFile );
+        }
+}
