Viewing contents of file '../idllib/contrib/tappin/graffer/fractile.pro'
function Fractile, x, frac

;+
; FRACTILE
;	Return the requested fractile of the input data.
;
; Usage:
;	fr = fractile(x, frac)
;
; Return:
;	fr	<input>	The requested fractile.
;
; Arguments:
;	x	most	input	The array whose fractile(s) are to be
;				returned 
;	frac	float	input	The fractile(s) to return.
;
; Restrictions:
;	The input data must be a SORTable array (i.e. not complex,
;	string or structure).
;
; Example:
;	To find the interquartile range of a data set, try:
;	q = fractile(data, [.25,.75])
;	iqr = q(1)-q(0)
;	
; History:
;	Original: 26/9/95; SJT
;	Modify to interpolate: 4/2/97; SJT
;-

if (n_params() ne 2) then message, 'Incorrect number of arguments'

n = n_elements(x)-1
i = sort(x)

f0 = floor(frac*n)
w1 = frac*n - f0
f1 = floor(frac*n+1)
w0 = f1 - frac*n

return, x(i(f0))*w0 + x(i(f1))*w1

end