Index: trunk/Ohana/src/libohana/include/ohana_allocate.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana_allocate.h	(revision 41153)
+++ trunk/Ohana/src/libohana/include/ohana_allocate.h	(revision 41154)
@@ -44,4 +44,7 @@
 void ohana_memcheck_block_func (const char *myFile, int myLine, const char *myFunc, void *in);
 void  real_free (void *in);
+
+void ohana_memdump_strings_file (FILE *f, int VERBOSE);
+void ohana_memdump_set_maxlines (int N);
 
 # define ohana_memcheck(X) ohana_memcheck_func (__FILE__, __LINE__, __func__, X)
Index: trunk/Ohana/src/libohana/include/ohana_sort.h
===================================================================
--- trunk/Ohana/src/libohana/include/ohana_sort.h	(revision 41153)
+++ trunk/Ohana/src/libohana/include/ohana_sort.h	(revision 41154)
@@ -83,3 +83,6 @@
 void isortfour (int *X, int *Y, int *Z, int *W, int N);
 
+void dsort_indexonly (double *X, off_t *S, off_t N);
+void dsort_int_indexonly (double *X, int *S, int N);
+
 #endif
Index: trunk/Ohana/src/libohana/src/ohana_allocate.c
===================================================================
--- trunk/Ohana/src/libohana/src/ohana_allocate.c	(revision 41153)
+++ trunk/Ohana/src/libohana/src/ohana_allocate.c	(revision 41154)
@@ -45,4 +45,6 @@
 
 static pthread_mutex_t memBlockListMutex = PTHREAD_MUTEX_INITIALIZER;
+
+static int NblockMaxDump = 100;
 
 void ohana_meminit () {
@@ -435,5 +437,5 @@
 	fprintf (stderr, "memory corruption\n");
       }
-      if (Nbad < 100) {
+      if (Nbad < NblockMaxDump) {
 	fprintf (stderr, "  file: %s, line: %d, func: %s\n", thisBlock->file, thisBlock->line, thisBlock->func);
       }
@@ -613,5 +615,5 @@
     Nbytes += thisBlock->size;
 
-    if (Ntotal < 100) {
+    if (Ntotal < NblockMaxDump) {
       if (good) {
 	fprintf (f, "  %zd  %zd  %zd  GOOD  %s %d, func: %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->file, thisBlock->line, thisBlock->func);
@@ -677,2 +679,49 @@
   return memstats;
 }
+
+void ohana_memdump_strings_file (FILE *f, int VERBOSE) {
+
+  if (!lastBlock) {
+    if (VERBOSE) fprintf (f, "no memory allocated\n");
+    return;
+  }
+
+  OhanaMemblock *thisBlock = lastBlock;
+
+  size_t Ntotal = 0;
+  size_t Nbytes = 0;
+  size_t Nstring = 0;
+
+  fprintf (f, "    entry |    bytes | cumulative : line : string\n");
+
+  while (thisBlock) {
+
+    // pointer to the start of the user memory
+    char *ptr = (char *)(thisBlock + 1);
+
+    Ntotal ++;
+    Nbytes += thisBlock->size;
+
+    int N = strlen(thisBlock->file);
+    if (N > 22) {
+      int found = !strcmp("libohana/src/string.c", &thisBlock->file[N - 21]);
+      if (found) {
+	if (Nstring < NblockMaxDump) {
+	  fprintf (f, " %8zd | %8zd | %10zd : %4d : %s\n", Ntotal, thisBlock->size, Nbytes, thisBlock->line, ptr);
+	}
+	Nstring ++;
+      }
+      thisBlock = thisBlock->prevBlock;
+    }
+  }
+
+  if (Nstring || VERBOSE) {
+    fprintf (f, "%zd strings allocated\n", Nstring);
+  }
+
+  return;
+}
+
+void ohana_memdump_set_maxlines (int N) {
+  NblockMaxDump = N;
+}
Index: trunk/Ohana/src/libohana/src/sorts.c
===================================================================
--- trunk/Ohana/src/libohana/src/sorts.c	(revision 41153)
+++ trunk/Ohana/src/libohana/src/sorts.c	(revision 41154)
@@ -196,2 +196,33 @@
 }
 
+/* sort the index of a vector (vector stays unsorted) */
+void dsort_indexonly (double *X, off_t *S, off_t N) {
+  
+# define SWAPFUNC(A,B){ off_t itmp; \
+  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
+}
+# define COMPARE(A,B)((!isfinite(X[S[A]]) && isfinite(X[S[B]])) || (X[S[A]] < X[S[B]]))
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+/* sort the index of a vector (vector stays unsorted) */
+void dsort_int_indexonly (double *X, int *S, int N) {
+  
+# define SWAPFUNC(A,B){ int itmp; \
+  itmp = S[A]; S[A] = S[B]; S[B] = itmp; \
+}
+# define COMPARE(A,B)((!isfinite(X[S[A]]) && isfinite(X[S[B]])) || (X[S[A]] < X[S[B]]))
+
+  OHANA_SORT (N, COMPARE, SWAPFUNC);
+
+# undef SWAPFUNC
+# undef COMPARE
+
+}
+
+
