Index: trunk/psLib/src/collections/Makefile
===================================================================
--- trunk/psLib/src/collections/Makefile	(revision 1231)
+++ trunk/psLib/src/collections/Makefile	(revision 1233)
@@ -3,6 +3,6 @@
 ##  Makefile:   collections
 ##
-##  $Revision: 1.24 $  $Name: not supported by cvs2svn $
-##  $Date: 2004-07-15 22:18:02 $
+##  $Revision: 1.25 $  $Name: not supported by cvs2svn $
+##  $Date: 2004-07-15 23:52:33 $
 ##
 ##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -32,5 +32,4 @@
 SRC_OBJS = psBitSet.o \
            psVector.o \
-           psSort.o \
            psImage.o \
            psList.o \
Index: trunk/psLib/src/collections/psSort.c
===================================================================
--- trunk/psLib/src/collections/psSort.c	(revision 1231)
+++ 	(revision )
@@ -1,248 +1,0 @@
-/** @file  psSort.c
- *
- *  @brief Sorts vectors
- *
- *  The psSort functions use the qsort() stdlib function with a user-defined callback to sort an vector of
- *  floats. The qsort function requires the starting point of the vector, number of elements in the vector, size
- *  of each element, and a pointer to a callback comparison function. Once called, qsort() will sort the vector
- *  contents in ascending order according to the comparison function. The comparison function is called with
- *  two arguments that point to the objects being compared - in this case two floats. The comparison function
- *  must return an integer less than, equal to, or greater than zero if the first argument is considered to be
- *  respectively less than, equal to, or greater than the second. If two members compare as equal, their order
- *  in the sorted vector is undefined.
- *
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-23 23:00:15 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
-
-/******************************************************************************/
-/*  INCLUDE FILES                                                             */
-/******************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <float.h>
-
-#include "psVector.h"
-#include "psSort.h"
-#include "psError.h"
-#include "psMemory.h"
-
-/******************************************************************************/
-/*  DEFINE STATEMENTS                                                         */
-/******************************************************************************/
-
-// None
-
-/******************************************************************************/
-/*  TYPE DEFINITIONS                                                          */
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  GLOBAL VARIABLES                                                         */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FILE STATIC VARIABLES                                                    */
-/*****************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/*  FUNCTION IMPLEMENTATION - LOCAL                                          */
-/*****************************************************************************/
-
-/** Private callback comparison function to compare two floats.
- *
- *  The comparison function is called by qsort() with two arguments that point to the objects being
- *  compared. The comparison function must return an integer less than, equal to, or greater than zero if
- *  the first argument is considered to be respectively less than, equal to, or greater than the second.
- *
- *  @return  int: Result of comparsion (-1, 0, or 1).
- */
-#define PS_COMPARE(TYPE)                                                                                     \
-static int psCompare##TYPE(const void *x, const void *y)                                                     \
-{                                                                                                            \
-    ps##TYPE *item1 = NULL;                                                                                  \
-    ps##TYPE *item2 = NULL;                                                                                  \
-    \
-    if(x == NULL || y == NULL) {                                                                             \
-        psError(__func__, " : Line %d - Null input argument: x=%d y=%d\n", __LINE__, x, y);                  \
-    }                                                                                                        \
-    \
-    item1 = (ps##TYPE *)x;                                                                                   \
-    item2 = (ps##TYPE *)y;                                                                                   \
-    \
-    if(item1 == NULL || item2 == NULL) {                                                                     \
-        psError(__func__, " : Line %d - Improper cast to float: item1=%d item2=%d\n", __LINE__, item1,       \
-                item2);                                                                                      \
-    }                                                                                                        \
-    \
-    if(*item1 < *item2) {                                                                                    \
-        return -1;                                                                                           \
-    } else if(*item1 > *item2) {                                                                             \
-        return 1;                                                                                            \
-    } else {                                                                                                 \
-        return 0;                                                                                            \
-    }                                                                                                        \
-}
-
-PS_COMPARE(U8)
-PS_COMPARE(U16)
-PS_COMPARE(F32)
-PS_COMPARE(F64)
-
-/*****************************************************************************/
-/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
-/*****************************************************************************/
-
-psVector *psSort(psVector *restrict outVector, const psVector *restrict inVector)
-{
-    int inN = 0;
-    int outN = 0;
-    int elSize = 0;
-    void *inVec = NULL;
-    void *outVec = NULL;
-    psElemType inType = 0;
-
-    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;
-    }
-
-    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(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);
-
-    // 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_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;
-}
-
-#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 *psSortIndex(psVector *restrict outVector, const psVector *restrict inVector)
-{
-    int inN = 0;
-    int outN = 0;
-    int i = 0;
-    int j = 0;
-    float *inVec = NULL;
-    int *outVec = NULL;
-    double diff = 0.0f;
-    psVector *tmpVector = NULL;
-    psElemType inType = 0;
-
-    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;
-    }
-
-    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;
-    }
-
-    tmpVector = psVectorAlloc(inN, inType);
-    tmpVector->n = inN;
-    tmpVector = psSort(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_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);
-
-    return outVector;
-}
Index: trunk/psLib/src/collections/psSort.d
===================================================================
--- trunk/psLib/src/collections/psSort.d	(revision 1231)
+++ 	(revision )
@@ -1,2 +1,0 @@
-psSort.o psSort.d : psSort.c psVector.h psType.h psSort.h ../sysUtils/psError.h \
-  ../sysUtils/psMemory.h
Index: trunk/psLib/src/collections/psSort.h
===================================================================
--- trunk/psLib/src/collections/psSort.h	(revision 1231)
+++ 	(revision )
@@ -1,67 +1,0 @@
-/** @file  psSort.h
- *
- *  @brief Sorts vectors
- *
- *  The psSort functions use the qsort() stdlib function with a user-defined callback to sort an array of
- *  floats. The qsort function requires the starting point of the array, number of elements in the array, size
- *  of each element, and a pointer to a callback comparison function. Once called, qsort() will sort the array
- *  contents in ascending order according to the comparison function. The comparison function is called with
- *  two arguments that point to the objects being compared - in this case two floats. The comparison function
- *  must return an integer less than, equal to, or greater than zero if the first argument is considered to be
- *  respectively less than, equal to, or greater than the second. If two members compare as equal, their order
- *  in the sorted array is undefined.
- *
- *  @ingroup Sort
- *
- *  @author Ross Harman, MHPCC
- *
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-10 01:58:06 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
-
-#ifndef PSSORT_H
-#define PSSORT_H
-
-/// @addtogroup Sort
-/// @{
-
-/******************************************************************************/
-/*  DEFINE STATEMENTS                                                         */
-/******************************************************************************/
-
-// None
-
-/******************************************************************************/
-/*  TYPE DEFINITIONS                                                          */
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/* FUNCTION PROTOTYPES                                                       */
-/*****************************************************************************/
-
-/** Sort an array of floats.
- *
- *  Sorts an array of floats in ascendin order with the qsort() stdlib function.
- *
- *  @return  psFloatArray*: Pointer to sorted psFloatArray.
- */
-
-psVector *psSort(psVector *restrict outVector, const psVector *restrict inVector);
-
-/** Creates an array of indices based on sort odred of float array.
- *
- *  Sorts an array of floats and creates an integer array holding indices of sorted float values based on
- *  pre-sort index positions.
- *
- *  @return  psIntArray*: Pointer to psIntArray of sorted indices.
- */
-
-psVector *psSortIndex(psVector *restrict outVector, const psVector *restrict inVector);
-
-/// @}
-
-#endif
Index: trunk/psLib/src/collections/psVector.c
===================================================================
--- trunk/psLib/src/collections/psVector.c	(revision 1231)
+++ trunk/psLib/src/collections/psVector.c	(revision 1233)
@@ -8,6 +8,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-15 22:18:02 $
+ *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-15 23:52:33 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -17,8 +17,13 @@
 /*  INCLUDE FILES                                                             */
 /******************************************************************************/
+#include <string.h>        // for memcpy
+#include <stdlib.h>
+#include <math.h>
+
 #include "psMemory.h"
 #include "psError.h"
 #include "psVector.h"
 #include "psLogMsg.h"
+#include "psCompare.h"
 
 /******************************************************************************/
@@ -143,4 +148,181 @@
 }
 
+psVector *psVectorSort(psVector *restrict outVector, const psVector *restrict inVector)
+{
+    int inN = 0;
+    int outN = 0;
+    int elSize = 0;
+    void *inVec = NULL;
+    void *outVec = NULL;
+    psElemType inType = 0;
+
+    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;
+    }
+
+    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(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);
+
+    // 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__);
+    }
+
+    return outVector;
+}
+
+#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)
+{
+    int inN = 0;
+    int outN = 0;
+    int i = 0;
+    int j = 0;
+    float *inVec = NULL;
+    int *outVec = NULL;
+    double diff = 0.0f;
+    psVector *tmpVector = NULL;
+    psElemType inType = 0;
+
+    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;
+    }
+
+    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;
+    }
+
+    tmpVector = psVectorAlloc(inN, inType);
+    tmpVector->n = inN;
+    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__);
+    }
+
+    // Free temp memory
+    psFree(tmpVector);
+
+    return outVector;
+}
+
 static void vectorFree(psVector *restrict psVec)
 {
Index: trunk/psLib/src/collections/psVector.d
===================================================================
--- trunk/psLib/src/collections/psVector.d	(revision 1231)
+++ trunk/psLib/src/collections/psVector.d	(revision 1233)
@@ -1,2 +1,2 @@
 psVector.o psVector.d : psVector.c ../sysUtils/psMemory.h ../sysUtils/psError.h \
-  psVector.h psType.h ../sysUtils/psLogMsg.h
+  psVector.h psType.h ../sysUtils/psLogMsg.h psCompare.h
Index: trunk/psLib/src/collections/psVector.h
===================================================================
--- trunk/psLib/src/collections/psVector.h	(revision 1231)
+++ trunk/psLib/src/collections/psVector.h	(revision 1233)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-15 22:18:02 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-15 23:52:33 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -99,4 +99,31 @@
 );
 
+/** Sort an array of floats.
+ *
+ *  Sorts an array of floats in ascending order.  This function is valid for
+ *  all non-complex data types.
+ *
+ *  @return  psFloatArray*: Pointer to sorted psFloatArray.
+ */
+
+psVector *psVectorSort(
+    psVector *restrict outVector,  ///< the output vector to recycle, or NULL if new vector desired.
+    const psVector *restrict inVector ///< the vector to sort.
+);
+
+/** Creates an array of indices based on sort odred of float array.
+ *
+ *  Sorts an array of floats and creates an integer array holding indices of 
+ *  sorted float values based on pre-sort index positions.  
+ *
+ *  @return  psIntArray*: Pointer to psIntArray of sorted indices.
+ */
+
+psVector *psVectorSortIndex(
+    psVector *restrict outVector,
+    const psVector *restrict inVector
+);
+
+
 /// @}
 
