Index: trunk/Ohana/src/libohana/Makefile
===================================================================
--- trunk/Ohana/src/libohana/Makefile	(revision 15851)
+++ trunk/Ohana/src/libohana/Makefile	(revision 16040)
@@ -27,10 +27,11 @@
 
 INCS = \
-$(DESTINC)/Xohana.h  \
 $(DESTINC)/ohana_allocate.h \
+$(DESTINC)/ohana_sort.h \
 $(DESTINC)/ohana.h
 
 OBJS = \
 $(SRC)/ohana_allocate.$(ARCH).o  \
+$(SRC)/sorts.$(ARCH).o		 \
 $(SRC)/string.$(ARCH).o		 \
 $(SRC)/findexec.$(ARCH).o	 \
Index: trunk/Ohana/src/libohana/include/ohana.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana.h	(revision 15851)
+++ trunk/Ohana/src/libohana/include/ohana.h	(revision 16040)
@@ -128,4 +128,7 @@
 # define OHANA_WHITESPACE(c)(((c) == 0x09) || ((c) == 0x0a) || ((c) == 0x0b) || ((c) == 0x0b) || ((c) == 0x0c) || ((c) == 0x0d) || ((c) == 0x20))
 
+// sorting is now defined as a macro call
+# include <ohana_sort.h>
+
 /* socket / pipe communication buffer */
 typedef struct {
Index: trunk/Ohana/src/libohana/include/ohana_sort.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana_sort.h	(revision 16040)
+++ trunk/Ohana/src/libohana/include/ohana_sort.h	(revision 16040)
@@ -0,0 +1,75 @@
+// Heap sort based on descriptions in Sedgewick "Algorithms in C"
+//
+// Copyright (C) 1999  Thomas Walter
+// Copyright (C) 2007  Paul Price, Institute for Astronomy, University of Hawaii
+// Copyright (C) 2008  Eugene Magnier, Institute for Astronomy, University of Hawaii
+//
+// 18 February 2000: Modified for GSL by Brian Gough
+// 29 November 2007: Modified for psLib by Paul Price
+// 07 January 2008: Modified for ohana by Eugene Magnier
+//
+//
+// This is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 2, or (at your option) any
+// later version.
+//
+// This source is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+//
+
+#ifndef OHANA_SORT_H
+#define OHANA_SORT_H
+
+// The following sort code is based on gsl_heapsort from GSL-1.8 (www.gnu.org/software/gsl), file
+// gsl-1.8/sort/sort.c, which is distributed under the GNU General Public License, version 2.
+
+// Use of the PSSORT() macro requires additional macros defined:
+// COMPAREEXPR(A,B): expression to compare element A with element B; true if element A is smaller than B.
+// SWAPFUNC(A,B): swap element A with element B
+
+# define OHANA_DOWNHEAP(COMPARE, SWAPFUNC, K) { \
+  unsigned long k = K; /* Local version of i in main loop */ \
+  while (k <= last / 2) {  \
+    unsigned long j = 2 * k;  \
+    if ((j < last) && COMPARE(j, j + 1)) {  \
+      j++;  \
+    }  \
+    if (COMPARE(k, j)) {  \
+      SWAPFUNC(j, k);  \
+    } else {  \
+      break;  \
+    }  \
+    k = j;  \
+  } \
+}
+
+# define OHANA_SORT(NVALUE, COMPARE, SWAPFUNC) { \
+  unsigned long last = NVALUE - 1; \
+  unsigned long i = last / 2 + 1; \
+  if (NVALUE > 1) { \
+    do { \
+      i--;  \
+      OHANA_DOWNHEAP (COMPARE, SWAPFUNC, i); \
+    } while (i > 0); \
+    while (last > 0) { \
+      SWAPFUNC(0, last); /* Swap elements */ \
+      /* Process the heap */ \
+      last--; \
+      OHANA_DOWNHEAP (COMPARE, SWAPFUNC, 0); \
+    } \
+  } \
+}
+
+// pre-defined function versions
+void dsort (double *value, int N);
+void fsort (float *value, int N);
+void fsortpair (float *X, float *Y, int N);
+void dsortpair (double *X, double *Y, int N);
+void isortpair (int *X, int *Y, int N);
+void fsortthree (float *X, float *Y, float *Z, int N);
+void dsortthree (double *X, double *Y, double *Z, int N);
+
+#endif
Index: trunk/Ohana/src/libohana/src/sorts.c
===================================================================
--- trunk/Ohana/src/libohana/src/sorts.c	(revision 16040)
+++ trunk/Ohana/src/libohana/src/sorts.c	(revision 16040)
@@ -0,0 +1,105 @@
+# include <ohana.h>
+
+/* various widely-used sort functions for specific sets of types */
+
+void dsort (double *value, int N) {
+
+# define SWAPFUNC(A,B){ double tmp = value[A]; value[A] = value[B]; value[B] = tmp; }
+# define COMPARE(A,B)(value[A] < value[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+void fsort (float *value, int N) {
+
+# define SWAPFUNC(A,B){ float tmp = value[A]; value[A] = value[B]; value[B] = tmp; }
+# define COMPARE(A,B)(value[A] < value[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+void fsortpair (float *X, float *Y, int N) {
+
+# define SWAPFUNC(A,B){ float tmp; \
+  tmp = X[A]; X[A] = X[B]; X[B] = tmp; \
+  tmp = Y[A]; Y[A] = Y[B]; Y[B] = tmp; \
+}
+# define COMPARE(A,B)(X[A] < X[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+void dsortpair (double *X, double *Y, int N) {
+
+# define SWAPFUNC(A,B){ double tmp; \
+  tmp = X[A]; X[A] = X[B]; X[B] = tmp; \
+  tmp = Y[A]; Y[A] = Y[B]; Y[B] = tmp; \
+}
+# define COMPARE(A,B)(X[A] < X[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+// sort two int vectors by first vector
+void isortpair (int *X, int *Y, int N) {
+
+# define SWAPFUNC(A,B){ int tmp; \
+  tmp = X[A]; X[A] = X[B]; X[B] = tmp; \
+  tmp = Y[A]; Y[A] = Y[B]; Y[B] = tmp; \
+}
+# define COMPARE(A,B)(X[A] < X[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+void fsortthree (float *X, float *Y, float *Z, int N) {
+
+# define SWAPFUNC(A,B){ float tmp; \
+  tmp = X[A]; X[A] = X[B]; X[B] = tmp; \
+  tmp = Y[A]; Y[A] = Y[B]; Y[B] = tmp; \
+  tmp = Z[A]; Z[A] = Z[B]; Z[B] = tmp; \
+}
+# define COMPARE(A,B)(X[A] < X[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+void dsortthree (double *X, double *Y, double *Z, int N) {
+
+# define SWAPFUNC(A,B){ double tmp; \
+  tmp = X[A]; X[A] = X[B]; X[B] = tmp; \
+  tmp = Y[A]; Y[A] = Y[B]; Y[B] = tmp; \
+  tmp = Z[A]; Z[A] = Z[B]; Z[B] = tmp; \
+}
+# define COMPARE(A,B)(X[A] < X[B])
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
