quantil2.pro
1.85 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
FUNCTION quantil2,input,npercent,noplot=noplot,above=above
;+
; NAME:
; quantil2
; PURPOSE:
; Given an input array, computes the value val so that npercent
; of the input values are below val.
; if above is set, npercent of the input values are above val
; CATEGORY:
; General
; CALLING SEQUENCE:
; val=quantil2(input,npercent)
; INPUTS:
; input = array (any dim) for which mean profile is to be calculated
; npercent = percentage value
; OPTIONAL INPUT PARAMETERS:
; OUTPUTS:
; val = value so that npercent % of the values are below val
; OPTIONAL OUTPUT PARAMETERS:
; COMMON BLOCKS:
; SIDE EFFECTS:
;
; RESTRICTIONS:
; PROCEDURE:
; Uses sort instead of histogram (more efficient than quantil)
; interpol
; MODIFICATION HISTORY:
; 18-Oct-1993, Written by Jean-Philippe Bernard, IPAC.
;-
IF N_PARAMS(0) LT 2 THEN BEGIN
PRINT,'Calling sequence: val=quantil(input,npercent)'
PRINT,'accepted Key-words: /noplot,/above'
GOTO, sortie
ENDIF
si=size(npercent)
IF si(0) NE 0 and si(0) NE 1 THEN BEGIN
print,'nperc should be a single value or 1D array'
goto,sortie
ENDIF
single=0
IF si(0) EQ 0 THEN single=1
IF single EQ 1 THEN BEGIN
IF npercent LT 0 OR npercent GT 100. THEN BEGIN
print,'we should have 0<npercent<100 !'
goto,sortie
ENDIF
ENDIF ELSE BEGIN
ind=where(npercent LT 0. OR npercent GT 100.,count)
IF count NE 0 THEN BEGIN
print,'we should have 0<npercent<100 !'
goto,sortie
ENDIF
ENDELSE
indef=-32768.
ind=where(input ne indef,count)
inp=input(ind)
ma=max(inp) & mi=min(inp)
IF ma NE mi THEN BEGIN
si=size(inp) & Ninp=si(1)
nv=(1.*lindgen(Ninp))/(1.*Ninp)*100.
ord=sort(inp)
inpord=inp(ord)
value=interpol(inpord,nv,npercent)
IF not keyword_set(noplot) THEN BEGIN
plot,nv,inpord
ENDIF
IF single EQ 1 THEN value=value(0)
ENDIF ELSE BEGIN
value=indef
ENDELSE
RETURN,value
sortie:
END