COSMOS v7.655  COSMOSv7655
(AirShowerMC)
ktrpzIntT2.f
Go to the documentation of this file.
1 !
2 ! Trapezoidal integral of a given table data.
3 ! of which x interval is not unique.
4  subroutine ktrpzintt2(t, intv, n, xt, intvx, a, b, ans)
5  implicit none
6  integer intv ! input. see below
7  integer n ! input. number of data values
8  real*8 t(intv, n) ! input. t(1, 1), t(1, 2), .. t(1, n) are used.
9  ! function values at xt(1,1), xt(1,2), ..
10  integer intvx ! see below
11  real*8 xt(intvx, n) ! input. must be xt(1,i) < xt(1,i+1)
12  real*8 a ! input. lower value of the integral region.
13  real*8 b ! input. upper value of the integral region. a<= b.
14 ! Note: table values outside of the given xt are assumed to be 0.
15  real*8 ans ! output. integral value
16 
17  integer i, i1, i2
18  real*8 aa, bb, fa, fb
19 
20 
21 
22  ans = 0.
23  aa = max(a, xt(1, 1))
24  bb = min(b, xt(1, n))
25  do i =1, n
26  if(aa .le. xt(1,i)) goto 10
27  enddo
28 ! never come here
29 
30  10 continue
31  i1 = i
32 
33  do i = n, 1, -1
34  if(bb .ge. xt(1,i)) goto 20
35  enddo
36 ! never come here
37 
38  20 continue
39  i2 = i
40 !
41  if(i1 .ne. 1) then
42  fa =
43  * (t(1,i1)- t(1,i1-1))/ (xt(1,i1) - xt(1,i1-1)) *
44  * (aa - xt(1,i1-1)) + t(1,i1-1)
45  ans = ans + (xt(1,i1)- aa) * (fa + t(1,i1))/2
46  endif
47  if(i2 .ne. n) then
48  fb = (t(1,i2+1) - t(1, i2))/ (xt(1,i2+1) - xt(1,i2)) *
49  * (bb -xt(1,i2)) + t(1,i2)
50  ans = ans+ (bb - xt(1,i2)) * (t(1,i2) + fb)/2
51  endif
52  do i = i1, i2-1
53  ans = ans + (xt(1,i+1) - xt(1, i)) * (t(1,i) + t(1,i+1))/2
54  enddo
55  end
subroutine ktrpzintt2(t, intv, n, xt, intvx, a, b, ans)
Definition: ktrpzIntT2.f:5