cdm/src/main/java/ucar/nc2/ft2/coverage/CoordAxisHelper.java
private int findCoordElementContiguous(double target, boolean bounded) {
    int n = axis.getNcoords();
    //double resolution = (values[n-1] - values[0]) / (n - 1);
    //int startGuess = (int) Math.round((target - values[0]) / resolution);

    int low = 0;
    int high = n - 1;
    if (axis.isAscending()) {
      // Check that the point is within range
      if (target < axis.getCoordEdge1(0))
        return bounded ? 0 : -1;
      else if (target > axis.getCoordEdgeLast())
        return bounded ? n - 1 : n;

      // do a binary search to find the nearest index
      int mid;
      while (high > low + 1) {
        mid = (low + high) / 2;                           // binary search
        if (contains(target, mid, true)) return mid;
        else if (axis.getCoordEdge2(mid) < target) low = mid;
        else high = mid;
      }
      return contains(target, low, true) ? low : high;

    } else {  // descending

      // Check that the point is within range
      if (target > axis.getCoordEdge1(0))
        return bounded ? 0 : -1;
      else if (target < axis.getCoordEdgeLast())
        return bounded ? n - 1 : n;

      // do a binary search to find the nearest index
      int mid;
      while (high > low + 1) {
        mid = (low + high) / 2;         // binary search
        if (contains(target, mid, false)) return mid;
        else if (axis.getCoordEdge2(mid) < target) high = mid;
        else low = mid;
      }
      return contains(target, low, false) ? low : high;
    }
  }
private int findCoordElementContiguous(double target, boolean bounded) {
    int n = axis.getNcoords();
    //double resolution = (values[n-1] - values[0]) / (n - 1);
    //int startGuess = (int) Math.round((target - values[0]) / resolution);

    int low = 0;
    int high = n - 1;
    if (axis.isAscending()) {
      // Check that the point is within range
      if (target < axis.getCoordEdge1(0))
        return bounded ? 0 : -1;
      else if (target > axis.getCoordEdgeLast())
        return bounded ? n - 1 : n;

      // do a binary search to find the nearest index
      int mid;
      while (high > low + 1) {
        mid = (low + high) / 2;                           // binary search
        if (contains(target, mid, true)) return mid;
        else if (axis.getCoordEdge2(mid) < target) low = mid;
        else high = mid;
      }
      return contains(target, low, true) ? low : high;

    } else {  // descending

      // Check that the point is within range
      if (target > axis.getCoordEdge1(0))
        return bounded ? 0 : -1;
      else if (target < axis.getCoordEdgeLast())
        return bounded ? n - 1 : n;

      // do a binary search to find the nearest index
      int mid;
      while (high > low + 1) {
        mid = (low + high) / 2;         // binary search
        if (contains(target, mid, false)) return mid;
        else if (axis.getCoordEdge2(mid) < target) high = mid;
        else low = mid;
      }
      return contains(target, low, false) ? low : high;
    }
  }
Performs a binary search to find the index of the element of the array whose value is contained in the contiguous intervals.
irregularPoint,    // irregular spaced points (values, npts), edges halfway between coords
contiguousInterval, // irregular contiguous spaced intervals (values, npts), values are the edges, and there are npts+1, coord halfway between edges
<p>
same contract as findCoordElement()