-
Notifications
You must be signed in to change notification settings - Fork 8
/
tsumcumul.pro
46 lines (41 loc) · 1.09 KB
/
tsumcumul.pro
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
;+
; PURPOSE:
; This function uses the trapezoidal rule to perform a running
; integration of tabulated data. It is adapted from the tsum routine
; in the IDL astronomy user's library, but returns the integral at
; each point of x, and not just over one large region.
;
; CATEGORY:
; Numerical recipes
;
; INPUTS:
; x: Input x values
; y: Input y values
;
; OUTPUTS:
; Integral(y dx) from x[0] to x[i]. A vector of the same length as x
; and y.
;
; MODIFICATION HISTORY:
; September 2009: Lifted from IDL astronomy user's library by Chris Beaumont
;-
function tsumcumul, x, y
compile_opt idl2
On_error,2
npar = N_params()
if npar ne 2 then begin
print, 'tsumcumul calling sequence:'
print, 'result = tsumcumul(x,y)'
return, !values.f_nan
endif
if n_elements(x) ne n_elements(y) then $
message, 'X and Y must have the same number of elements'
yy = y
xx = x
npts = n_elements(x)
; Compute areas of trapezoids and sum result
xdif = xx[1:*] - xx
yavg = ( yy[0:npts-2] + yy[1:npts-1] ) / 2.
sum = total( xdif*yavg, /cumul )
return, sum
end