Index: trunk/Ohana/src/libohana/Makefile
===================================================================
--- trunk/Ohana/src/libohana/Makefile	(revision 38458)
+++ trunk/Ohana/src/libohana/Makefile	(revision 38459)
@@ -34,4 +34,5 @@
 $(SRC)/ohana_allocate.$(ARCH).o  \
 $(SRC)/sorts.$(ARCH).o		 \
+$(SRC)/bisection.$(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 38458)
+++ trunk/Ohana/src/libohana/include/ohana.h	(revision 38459)
@@ -479,3 +479,6 @@
 void VSHtermsForLM (VSHterms *terms, double R, double D, int l, int m);
 
-# endif
+/* in bisection.c */
+int ohana_bisection_double (double *values, int Nvalues, double threshold);
+
+# endif
Index: trunk/Ohana/src/libohana/src/bisection.c
===================================================================
--- trunk/Ohana/src/libohana/src/bisection.c	(revision 38459)
+++ trunk/Ohana/src/libohana/src/bisection.c	(revision 38459)
@@ -0,0 +1,33 @@
+# include <ohana.h>
+
+// return the index of the last value < threshold 
+int ohana_bisection_double (double *values, int Nvalues, double threshold) {
+
+  int Nlo = 0; 
+  int Nhi = Nvalues - 1;
+
+  if (Nvalues < 1) return (-1);
+  if (values[Nlo] > threshold) return (-1);
+
+  if (Nvalues < 2) return (0);
+  if (values[Nhi] < threshold) return (Nhi);
+
+  int N;
+  while (Nhi - Nlo > 4) {
+    N = 0.5*(Nlo + Nhi);
+    if (values[N] < threshold) {
+      Nlo = MAX(N, 0);
+    } else {
+      Nhi = MIN(N + 1, Nvalues - 1);
+    }
+  }
+  // values[Nlo] < threshold 
+  // values[Nhi] >= threshold 
+
+  for (N = Nlo; N < Nhi; N++) {
+    if (values[N] >= threshold) {
+      return (N-1);
+    }
+  }
+  return (N);
+}
Index: trunk/Ohana/src/libohana/src/config.c
===================================================================
--- trunk/Ohana/src/libohana/src/config.c	(revision 38458)
+++ trunk/Ohana/src/libohana/src/config.c	(revision 38459)
@@ -395,6 +395,6 @@
   Nbytes = 0;
   NBYTES = D_NBYTES;
-  ALLOCATE (ibuffer, char, NBYTES + 2);
-    
+  ALLOCATE_ZERO (ibuffer, char, NBYTES + 2);
+
   /* load data from file */
   while ((nbytes = fread (&ibuffer[Nbytes], sizeof(char), D_NBYTES, f)) == D_NBYTES) {
@@ -402,4 +402,5 @@
     NBYTES += D_NBYTES;
     REALLOCATE (ibuffer, char, NBYTES + 2);
+    memset (&ibuffer[NBYTES - D_NBYTES], 0, NBYTES - D_NBYTES + 2);
   }
   Nbytes += nbytes;
@@ -419,6 +420,8 @@
       Ncpy = strlen (line);
       if (Nbytes + Ncpy >= NBYTES) {
+	int Nbytes_old = NBYTES;
 	NBYTES = Nbytes + Ncpy + D_NBYTES;
 	REALLOCATE (ibuffer, char, NBYTES + 2);
+	memset (&ibuffer[Nbytes_old], 0, NBYTES + 2 - Nbytes_old);
       }    
       memcpy (&ibuffer[Nbytes], line, Ncpy);
@@ -430,6 +433,8 @@
       Ncpy = strlen (line);
       if (Nbytes + Ncpy >= NBYTES) {
+	int Nbytes_old = NBYTES;
 	NBYTES = Nbytes + Ncpy + D_NBYTES;
 	REALLOCATE (ibuffer, char, NBYTES + 2);
+	memset (&ibuffer[Nbytes_old], 0, NBYTES + 2 - Nbytes_old);
       }    
       memcpy (&ibuffer[Nbytes], line, Ncpy);
