Index: trunk/psModules/src/objects/psVectorBracket.c
===================================================================
--- trunk/psModules/src/objects/psVectorBracket.c	(revision 8885)
+++ trunk/psModules/src/objects/psVectorBracket.c	(revision 8927)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-09-22 21:35:10 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-09-25 01:06:51 $
  *
  *  Copyright 2006 Institute for Astronomy, University of Hawaii
@@ -59,4 +59,44 @@
 }
 
+// return the last entry below or first entry above key value (reverse sorted input)
+int psVectorBracketDescend (psVector *index, psF32 key, bool above)
+{
+
+    int N;
+    int Nhi = 0;
+    int Nlo = index->n;
+
+    if (above) {
+        while (Nlo - Nhi > 10) {
+            N = 0.5*(Nhi + Nlo);
+            if (index->data.F32[N] < key) {
+                Nlo = N;
+            } else {
+                Nhi = N - 1;
+            }
+        }
+        // at this point, index[Nhi] >= key > index[Nlo]
+        N = Nhi;
+        while ((index->data.F32[N] >= key) && (N < Nlo)) {
+            N++;
+        }
+        return (N);
+    }
+    while (Nlo - Nhi > 10) {
+        N = 0.5*(Nhi + Nlo);
+        if (index->data.F32[N] > key) {
+            Nhi = N;
+        } else {
+            Nlo = N + 1;
+        }
+    }
+    // at this point, index[Nhi] > key >= index[Nlo]
+    N = Nlo;
+    while ((index->data.F32[N] <= key) && (N > Nhi)) {
+        N--;
+    }
+    return (N);
+}
+
 // search for the bins bounding key in index, interpolate the corresponding values
 psF32 psVectorInterpolate (psVector *index, psVector *value, psF32 key)
