which_nearest function

Find the index of value nearest to a target value