percentile.pro
1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
FUNCTION percentile,array,perc,low=low,values=values,Nvalues=Nvalues,indexes=indexes, lac = lac
;+
; NAME:
; percentile
; CALLING SEQUENCE:
; result=percentile(array,perc,low=low)
; PURPOSE:
; Makes a binned correlation plot
; INPUTS:
; array = input array
; perc =percentile
; OPTIONAL INPUT:
; low = If set compute lower percentile
; lac = if set, exclude la_undef values
; OUTPUTS:
; result= percentile value
; values= values of the upper/lower percentile
; Nvalues= # of elements of values
; indexes= indexes of above in original array
; OPTIONAL OUTPUT:
; None
; PROCEDURE AND SUBROUTINE USED
; None
; SIDE EFFECTS:
; None
; EXAMPLE:
;
; MODIFICATION HISTORY:
; written by Jean-Philippe Bernard
;-
IF N_PARAMS(0) LT 1 THEN begin
print,'result=percentile(array,perc,low=low)'
print,'perc in %'
sarray=[0] & x=0L
GOTO,sortie
ENDIF
sarray=array
ind=where(finite(sarray) EQ 1,count)
sarray=sarray[ind]
if keyword_set(lac) then begin
ind=where(sarray NE la_undef(),count)
sarray=sarray[ind]
endif
N=n_elements(sarray)
order=sort(sarray)
sarray=sarray(order) ;sorted array
IF keyword_set(low) THEN BEGIN
x=long(N*(perc/100.))>0<(N-1)
values=sarray(0:x)
indexes=order(0:x)
ENDIF ELSE BEGIN
x=N-long(N*(perc/100.))>0<(N-1)
values=sarray(x:N-1)
indexes=order(x:N-1)
ENDELSE
Nvalues=n_elements(values)
sortie:
RETURN,sarray(x)
END