Index: trunk/psLib/src/collections/psVector.c
===================================================================
--- trunk/psLib/src/collections/psVector.c	(revision 1305)
+++ 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 );
+}
