def _getind(x,x0):
    """Find the index of a point on a grid.
    
    Find the index k of x0 in a real array x, such that
        x[k] <= x0 < x[k+1].
    To enable usage by the interpolation routine, the edge cases are
        x0 <= x[0]: k = 0
        x0 >= x[-1]: k = len(x) - 2
    so that expressions such as (x[k+1]-x[k]) are always valid.
    
    :arg x: Grid points, monotonically increasing.
    :type x: list[float]
    :arg float x0: Value to find the index of.
    :returns: Index of x0 in the array.
    """
    if x0 <= x[0]:
        k = 0
    elif x0 >= x[-1]:
        k = len(x) - 2
    else:
        k = [(xk > x0) for xk in x].index(True) - 1
    return k