function percentile(d, n, x) ! Given a sorted x(n), calculate the percentile of observation d integer n = size(x) real x(n), d, percentile end function percentile