rIndex <- function(xs,x){
### xs: evenly spaced increasing sequence

### return i such that xs[i] is nearest to x

  nx=length(xs)
  dx=(xs[nx]-xs[1])/(nx-1)

  i=(x-((min(xs)-dx/2)))/dx

  return(1+floor(i))
}
