map_to_bin Subroutine

public subroutine map_to_bin(x, bins, N, ibin)

Arguments

Type IntentOptional Attributes Name
real(kind=rk), intent(in) :: x

Number to map to a bin

real(kind=rk), intent(in) :: bins(:)

Array containing the boundaries of each bin Should be monotonic increasing i.e. bin(0) < bin(1) < ... bin(Nbins)

integer, intent(in) :: N

Number of elements in bins array

integer, intent(out) :: ibin

so that bins(ibin) < x <= bins(ibin+1)

EXAMPLE if bins = [0.0, 0.1, 0.3, 0.7, 1.0] and x = 0.32 then this routine returns ibin = 3 since bins(ibin) = 0.3 < x <= bins(ibin+1)