Index: /trunk/psLib/src/dataManip/Makefile
===================================================================
--- /trunk/psLib/src/dataManip/Makefile	(revision 434)
+++ /trunk/psLib/src/dataManip/Makefile	(revision 435)
@@ -9,7 +9,9 @@
 include ../Makefile.Globals
 
-SRC_OBJS = \
-    psBitMask.o \
-    psSort.o
+SRC_OBJS = psSort.o 
+
+%.o: %.c
+	@echo "    Compiling $<. "
+	$(CC) $(CFLAGS) -I$(includedir) -c $< -o $@
 
 libpsDataManip.a: $(SRC_OBJS)
Index: /trunk/psLib/src/dataManip/psSort.c
===================================================================
--- /trunk/psLib/src/dataManip/psSort.c	(revision 435)
+++ /trunk/psLib/src/dataManip/psSort.c	(revision 435)
@@ -0,0 +1,145 @@
+#include "psArray.h"
+#include "psSort.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <float.h>
+/*       qsort - sorts an array */
+/*       The  qsort()  function sorts an array with nmemb elements of size size.
+       The base argument points to the start of the array.
+
+       The contents of the array are sorted in ascending order according to  a
+       comparison  function  pointed  to  by  compar, which is called 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 respec-
+       tively less than, equal to, or greater than the second.  If two members
+       compare as equal, their order in the sorted array is undefined.
+*/
+static int psCompare(const void *x, const void *y);
+
+
+psFloatArray *psSort(psFloatArray *restrict outArray, const psFloatArray *restrict inArray)
+{
+    int inN = 0;
+    int outN = 0;
+    int i = 0;
+    int elSize = 0;
+    float *inArr = NULL;
+    float *outArr = NULL;
+
+    if(outArray == NULL) {
+        printf("NULL output array n");
+        return outArray;
+    }
+    
+    if(inArray == NULL) {
+        printf("NULL input array\n");
+        return outArray;
+    }
+        
+    // Initialize values
+    inN = inArray->n;
+    outN = outArray->n;
+    inArr = inArray->arr;
+    outArr = outArray->arr;
+    elSize = sizeof(float);
+    
+    if(inN != outN) {
+        printf("Input and output array sizes are not equal");
+        return outArray;
+    }
+    
+    // Copy input array values into output array
+    for(i=0; i<inN; i++) {
+        outArr[i] = inArr[i];
+    }
+    
+    // Sort output array
+    qsort((void*)outArr, inN, elSize, psCompare);
+    
+    return outArray;
+}
+
+psIntArray *psSortIndex(psIntArray *restrict outArray, const psFloatArray *restrict inArray)
+{
+    int inN = 0;
+    int outN = 0;
+    int i = 0;
+    int j = 0;
+    float tempVal = 0.0f;
+    float *inArr = NULL;
+    int *outArr = NULL;
+    float diff = 0.0f;
+    psFloatArray *tmpFloatArray = NULL;
+    
+    if(outArray == NULL) {
+        printf("NULL output array n");
+        return outArray;
+    }
+    
+    if(inArray == NULL) {
+        printf("NULL input array\n");
+        return outArray;
+    }
+
+    // Initialize values
+    inN = inArray->n;
+    outN = outArray->n;
+    inArr = inArray->arr;
+    outArr = outArray->arr;
+
+    if(inN != outN) {
+        printf("Input and output array sizes are not equal");
+        return outArray;
+    }
+
+    tmpFloatArray = psFloatArrayAlloc(inN);
+    tmpFloatArray = psSort(tmpFloatArray, inArray);
+    
+    for(i=0; i<inN; i++) {
+        tempVal = tmpFloatArray->arr[i];
+        for(j=0; j<inN; j++) {
+            diff = fabsf(tempVal - inArr[j]);
+            if(diff < FLT_EPSILON) {
+                outArr[i] = j;
+                break;
+            }
+        } 
+    }
+    
+    // Free temp memory
+    psFreeFloatArray(tmpFloatArray);
+    
+    return outArray;    
+}
+
+static int psCompare(const void *x, const void *y)
+{
+    float *item1 = NULL;
+    float *item2 = NULL;
+    
+    if(x == NULL || y == NULL) {
+        printf("Null input argument\n");
+    }
+    
+    item1 = (float*)x;
+    item2 = (float*)y;
+    
+    if(item1 == NULL || item2 == NULL) {
+        printf("Improper cast to float\n");
+    }
+    
+    if(*item1 < *item2) {
+        return -1;
+    }
+    else if(*item1 > *item2) {
+        return 1;
+    }
+    else {
+        return 0;
+    }
+}
Index: /trunk/psLib/src/dataManip/psSort.h
===================================================================
--- /trunk/psLib/src/dataManip/psSort.h	(revision 435)
+++ /trunk/psLib/src/dataManip/psSort.h	(revision 435)
@@ -0,0 +1,2 @@
+psFloatArray *psSort(psFloatArray *restrict out, const psFloatArray *restrict inArray);
+psIntArray *psSortIndex(psIntArray *restrict out, const psFloatArray *restrict inArray);
