6
6
; ToDo: testing /NaN ?!
8
; Since 16 June 2012, we also have DIMENSION for MOMENT() (Mathieu Pinter)
9
; Since 14 July 2012, we also have DIMENSION for related codes:
10
; MEAN(), STDDEV(), VARIANCE(), SKEWNESS(), KURTOSIS()
12
; -------------------------------------------------------------
8
14
function ERREUR, x1, x2
9
15
return, SQRT(TOTAL((x1-x2)^2))
12
pro TEST_MOMENT, test=test
18
; -------------------------------------------------------------
20
function CHECK_DIMENSION_CAPABILITY, verbose=verbose
22
; IDL before version 8 cannot manage DIMENSION keyword
24
; Since 16 June 2012, we also have DIMENSION for MOMENT()
25
; Since 14 July 2012, we also have DIMENSION for related codes:
26
; MEAN(), STDDEV(), VARIANCE(), SKEWNESS(), KURTOSIS()
28
if KEYWORD_SET(verbose) then begin
29
txt1='dimension keyword is available in MOMENT() and related codes:'
30
txt2='MEAN(), STDDEV(), VARIANCE(), SKEWNESS(), KURTOSIS()'
33
DEFSYSV, '!gdl', exists=isGDL
39
if KEYWORD_SET(verbose) then begin
40
MESSAGE,/cont, 'in GDL, '+txt1
44
;; when IDL, which major version ? we assume "." is the separator !
45
version=!version.release
46
if (FIX(STRMID(version,0, STRPOS(version,'.'))) GE 8) then check_dim=1
47
if KEYWORD_SET(verbose) then begin
48
if (check_dim EQ 0) then begin
49
MESSAGE,/cont, 'in IDL, before 8.0, dimension keyword not available !'
51
MESSAGE,/cont, 'in IDL, since 8.0, '+txt1
61
; -------------------------------------------------------------
63
pro CHECK_VISUAL_MOMENT, data, force_dim=force_dim, no_exit=no_exit, $
64
help=help, test=test, verbose=verbose
66
if KEYWORD_SET(help) then begin
67
print, 'pro CHECK_VISUAL_MOMENT, data, force_dim=force_dim, no_exit=no_exit, $'
68
print, ' help=help, test=test, verbose=verbose'
72
; do we have the dimension keyword capability ?
74
if ~KEYWORD_SET(force_dim) then begin
75
check_dim=CHECK_DIMENSION_CAPABILITY()
76
endif else check_dim=1
78
if (check_dim EQ 0) then begin
79
MESSAGE, 'this test requires Dimension keyword capability'
82
if N_PARAMS() EQ 0 then data=DIST(115, 128)
84
nb_nan=N_ELEMENTS(data)/10
85
pos=FIX(RANDOMU(seed,nb_nan)*N_ELEMENTS(data))
87
data_NaN[pos]=!values.f_nan
97
WINDOW, ii, xsize=400, ysize=750, title=title
100
plot, MEAN(tmp, dim=1,/nan), title='MEAN, dim=1'
101
plot, MEAN(tmp, dim=2,/nan), title='MEAN, dim=1'
102
plot, STDDEV(tmp, dim=1,/nan), title='STDDEV, dim=1'
103
plot, STDDEV(tmp, dim=2,/nan), title='STDDEV, dim=2'
104
plot, SKEWNESS(tmp, dim=1,/nan), title='SKEWNESS, dim=1'
105
plot, SKEWNESS(tmp, dim=2,/nan), title='SKEWNESS, dim=2'
106
plot, KURTOSIS(tmp, dim=1,/nan), title='KURTOSIS, dim=1'
107
plot, KURTOSIS(tmp, dim=2,/nan), title='KURTOSIS, dim=2'
114
pro TEST_NUMERICAL_MOMENT, force_dim=force_dim, no_exit=no_exit, $
115
help=help, test=test, verbose=verbose
117
if KEYWORD_SET(help) then begin
118
print, 'pro TEST_NUMERICAL_MOMENT, force_dim=force_dim, no_exit=no_exit, $'
119
print, ' help=help, test=test, verbose=verbose'
123
; do we have the dimension keyword capability ?
125
if ~KEYWORD_SET(force_dim) then begin
126
check_dim=CHECK_DIMENSION_CAPABILITY(/verbose)
127
endif else check_dim=1
27
142
e2=ERREUR(expected_resu2, resu2)
28
143
if (e2 GT 1e-5) then nb_pb=nb_pb+1
30
if KEYWORD_SET(test) then STOP
148
expected_resu3=[[[60.0000, 73.0000, 88.0000], $
149
[105.000, 124.000, 145.000]], $
150
[[5616.00, 7488.00, 9648.00], $
151
[12096.0, 14832.0, 17856.0]], $
152
[[0.287409, 0.256015, 0.229751], $
153
[0.207827, 0.189413, 0.173812]], $
154
[[-2.33333, -2.33333, -2.33333], $
155
[-2.33333, -2.33333, -2.33333]]]
156
if (check_dim) then begin
157
resu3=MOMENT(a, DIMENSION=3)
158
e3=ERREUR(expected_resu3, resu3)
159
if (e3 GT 1e-5) then nb_pb=nb_pb+1
160
endif else MESSAGE, /continue, 'skipping /DIM test'
164
a=[1,4,5,!VALUES.F_NAN]
165
expected_resu4=[3.33333, 4.33333, -0.28741, -2.33333]
166
resu4=MOMENT(a, /NAN)
167
e4=ERREUR(expected_resu4, resu4)
168
if (e4 GT 1e-5) then nb_pb=nb_pb+1
172
a=[[1,4,5,!VALUES.F_NAN],[6,8,!VALUES.F_NAN, 9]]
173
expected_resu5=[[3.33333,7.66667], $
174
[4.33333,2.33333],[-0.28741,-0.20783], $
176
if (check_dim) then begin
177
resu5=MOMENT(a, DIMENSION=1, /NAN)
178
e5=ERREUR(expected_resu5, resu5)
179
if (e5 GT 1e-5) then nb_pb=nb_pb+1
180
endif else MESSAGE, /continue, 'skipping /DIM test'
32
184
if (nb_pb EQ 0) then begin
33
185
MESSAGE, 'No problem found in TEST_MOMENT', /continue
35
187
MESSAGE, STRING(nb_pb)+' problem(s) found in TEST_MOMENT', /continue
190
if KEYWORD_SET(test) then STOP
192
if (nb_pb GT 0) AND ~KEYWORD_SET(no_exit) then EXIT, status=1
196
; ------------------------------------
198
pro TEST_MOMENT, force_dim=force_dim, $
199
help=help, test=test, no_exit=no_exit, verbose=verbose
201
TEST_NUMERICAL_MOMENT, force_dim=force_dim, help=help, $
202
test=test, no_exit=no_exit, verbose=verbose
204
CHECK_VISUAL_MOMENT, force_dim=force_dim, help=help, $
205
test=test, no_exit=no_exit, verbose=verbose