COSMOS v7.655  COSMOSv7655
(AirShowerMC)
kpolintp.f
Go to the documentation of this file.
1 ! test kpolintp, kpolintpFE
2 !
3 ! implicit none
4 ! integer n
5 ! parameter (n = 20)
6 ! real*8 xa(n), ya(n), x, y, error
7 ! integer i, m
8 !
9 ! do i = 1, n
10 ! xa(i) = i/3.d0
11 ! ya(i) = exp(xa(i))
12 ! enddo
13 ! m = 5 ! use m points around x.
14 ! do i =1, n
15 ! x = xa(i) - 0.2
16 ! call kpolintpFE(xa, 1, ya, 1, n, m, x, y, error)
17 ! write(*, *) x, exp(x), y, error
18 ! enddo
19 ! end
20  subroutine kpolintplogxyfe(xa, xstep, ya, ystep, nt, m,
21  * logxy, x, y, error)
22  implicit none
23 ! This is a front end for kpolintp for which we must give
24 ! some few to several points around x. This manages such
25 ! business automatically. This version takes log of x and or y before
26 ! kpolintp is called.
27 !
28  integer xstep ! input. see below
29  integer nt ! input. total number of points
30  integer m ! input. the number of points to be used
31  ! for interpolation. must be <=10.
32  real*8 xa(xstep, nt) ! input. values of x-coordinate at xa(1, i)
33  ! (i=1, nt) are valid x data.
34  integer ystep ! input. see below
35  real*8 ya(ystep, nt) ! input. values of y-coordinate at ya(1, i)
36  ! (i=1, nt) are valid y data.
37  integer logxy ! input. 1-->log(x) 2-->log(y) 3-->log(x),log(y)
38  real*8 x ! input. x-value where an interpolated y
39  ! value is wanted
40  real*8 y ! output. see above
41 
42  real*8 error ! output. estimated error
43 ! -----------------------------------------------
44 
45  real*8 logx(10), logy(10) ! working array.
46  real*8 xx, yy
47 
48  integer loc, k, i
49  logical kbitest
50 ! find location of x in xa
51  call kdwhereis(x, nt, xa, xstep, loc)
52  k = min(max(loc - (m-1)/2,1), nt+1-m) ! max of m points from k
53 
54  do i = k, m+k-1
55  if( kbitest(logxy, 1)) then
56  if( xa(1, i) .gt. 0.) then
57  logx(i-k+1) = log(xa(1,i))
58  xx = log(x)
59  else
60 ! if some of x is <= 0; we don't use log
61  call kpolintpfe(xa, xstep, ya, ystep, nt, m,
62  * x, y, error)
63  return ! **************
64  endif
65  else
66  logx(i-k+1) = xa(1,i)
67  xx = x
68  endif
69  if( kbitest(logxy, 2)) then
70  if( ya(1, i) .gt. 0.) then
71  logy(i-k+1) = log(ya(1,i))
72  else
73 ! if some of y is <= 0; we don't use log
74  call kpolintpfe(xa, xstep, ya, ystep, nt, m,
75  * x, y, error)
76  return ! **************
77  endif
78  else
79  logy(i-k+1) = ya(1,i)
80  endif
81  enddo
82  call kpolintp(logx, 1, logy, 1, m, xx, yy, error)
83  if( kbitest(logxy, 2) ) then
84  y = exp(yy)
85  else
86  y = yy
87  endif
88  end
89  subroutine kpolintplogfe(xa, xstep, ya, ystep, nt, m,
90  * x, y, error)
91  implicit none
92 ! This is a front end for kpolintp for which we must give
93 ! some few to several points around x. This manages such
94 ! business automatically. This version takes log of y before
95 ! kpolintp is called.
96 !
97  integer xstep ! input. see below
98  integer nt ! input. total number of points
99  integer m ! input. the number of points to be used
100  ! for interpolation. must be <=10.
101  real*8 xa(xstep, nt) ! input. values of x-coordinate at xa(1, i)
102  ! (i=1, nt) are valid x data.
103  integer ystep ! input. see below
104  real*8 ya(ystep, nt) ! input. values of y-coordinate at ya(1, i)
105  ! (i=1, nt) are valid y data.
106  real*8 x ! input. x-value where an interpolated y
107  ! value is wanted
108  real*8 y ! output. see above
109  real*8 error ! output. estimated error
110 ! -----------------------------------------------
111 
112  real*8 logy(10) ! working array.
113  real*8 yy
114 
115  integer loc, k, i
116 ! find location of x in xa
117  call kdwhereis(x, nt, xa, xstep, loc)
118  k = min(max(loc - (m-1)/2,1), nt+1-m) ! max of m points from k
119 
120  do i = k, m+k-1
121  if(ya(1,i) .gt. 0.) then
122  logy(i-k+1) = log(ya(1,i))
123  else
124 ! if some of y is <= 0; we don't use log
125  call kpolintpfe(xa, xstep, ya, ystep, nt, m,
126  * x, y, error)
127  return ! **************
128  endif
129  enddo
130  call kpolintp(xa(1, k), xstep, logy, 1, m, x, yy, error)
131  y = exp(yy)
132  end
133  subroutine kpolintpfe(xa, xstep, ya, ystep, nt, m, x, y, error)
134  implicit none
135 ! This is a front end for kpolintp for which we must give
136 ! some few to several points around x. This manages such
137 ! business automatically.
138 !
139  integer xstep ! input. see below
140  integer nt ! input. total number of points
141  integer m ! input. the number of points to be used
142  ! for interpolation. must be <=10.
143  real*8 xa(xstep, nt) ! input. values of x-coordinate at xa(1, i)
144  ! (i=1, nt) are valid x data.
145  integer ystep ! input. see below
146  real*8 ya(ystep, nt) ! input. values of y-coordinate at ya(1, i)
147  ! (i=1, nt) are valid y data.
148  real*8 x ! input. x-value where an interpolated y
149  ! value is wanted
150  real*8 y ! output. see above
151  real*8 error ! output. estimated error
152 
153 
154  integer loc, k
155 ! find location of x in xa
156  call kdwhereis(x, nt, xa, xstep, loc)
157  k = min(max(loc - (m-1)/2,1), nt+1-m) ! max of m points from k
158  call kpolintp(xa(1, k), xstep, ya(1, k), ystep, m, x, y, error)
159  end
160 
161 
162  subroutine kpolintp(xa, xstep, ya, ystep, n, x, y, error)
163 !
164 ! integer n. input. number of points.
165 ! real*8 xa(xstep, n). input.
166 ! real*8 ya(ystep, n). input. function values at xa.
167 ! real*8 x. input.
168 ! real*8 y. output. interepolated functon value at x.
169 ! real*8 error. output. estiamted rough error.
170 !
171  implicit none
172  integer n, xstep, ystep
173  real*8 xa(xstep, n), ya(ystep, n), x, y, error
174 
175  integer i, maxm, j
176  parameter(maxm = 10)
177  real*8 c(maxm), d(maxm), diff, difft
178 
179  integer ns, m
180  real*8 h0, hp, w, den
181 
182  if(n .gt. maxm) then
183  write(*, *) ' kpolintp: use lesser number of points'
184  stop
185  endif
186  ns = 1
187  diff = abs(x - xa(1, 1))
188  do i = 1, n
189  difft= abs(x - xa(1, i))
190  if(difft .le. diff) then
191  ns = i
192  diff = difft
193  endif
194  c(i) = ya(1, i)
195  d(i) = ya(1, i)
196  enddo
197  y = ya(1, ns)
198  ns = ns-1
199  do m = 1, n-1
200  do i=1, n-m
201  h0 = xa(1,i) -x
202  hp = xa(1, i+m) - x
203  w = c(i+1) - d(i)
204  den = h0- hp
205  if(den .ne. 0.) then
206  den = w/den
207  d(i) = hp*den
208  c(i) = h0*den
209  else
210  write(0,*) ' error in kpolintp; den= ',den
211  write(0,*) 'x=',x
212  write(0,'(10G12.4)' ) ' xa=', (xa(1,j), j=1, n)
213  write(0,'(10G12.4)' ) ' ya=', (ya(1,j), j=1, n)
214  stop
215  endif
216  enddo
217  if(2*ns .le. n-m) then
218  error = c(ns+1)
219  else
220  error = d(ns)
221  ns = ns-1
222  endif
223  y = y + error
224  enddo
225  end
226 
227  subroutine kpolintpeqs(x0, dx, ya, ystep, n, x, y, error)
228 !
229 ! integer n. input. number of points.
230 ! real*8 x0. input. x0, x0+dx, x0+2dx, ...x0+(n-1)dx
231 ! are given data points
232 ! real*8 ya(ystep,n) input. function values at x0,..
233 ! real*8 x. input.
234 ! real*8 y. output. interepolated functon value at x.
235 ! real*8 error. output. estiamted rough error.
236 !
237  implicit none
238  integer n, ystep
239  real*8 x0, ya(ystep, n), x, y, error, dx
240 
241  integer i, maxm
242  parameter(maxm = 10)
243  real*8 c(maxm), d(maxm), diff, difft
244 
245  integer ns, m
246  real*8 h0, hp, w, den
247  integer p, q
248  real*8 xa
249  xa(p, q) = (q-1)*dx + x0
250 
251  if(n .gt. maxm) then
252  write(*, *)
253  * ' kpolintpeqs: use lesser number of points'
254  stop
255  endif
256  ns = 1
257  diff = abs(x - xa(1, 1))
258  do i = 1, n
259  difft= abs(x - xa(1, i))
260  if(difft .le. diff) then
261  ns = i
262  diff = difft
263  endif
264  c(i) = ya(1, i)
265  d(i) = ya(1, i)
266  enddo
267  y = ya(1, ns)
268  ns = ns-1
269  do m = 1, n-1
270  do i=1, n-m
271  h0 = xa(1,i) -x
272  hp = xa(1, i+m) - x
273  w = c(i+1) - d(i)
274  den = h0- hp
275  if(den .eq. 0.) then
276  write(0,*) ' error in kpolintpeqs'
277  stop
278  endif
279  den = w/den
280  d(i) = hp*den
281  c(i) = h0*den
282  enddo
283  if(2*ns .le. n-m) then
284  error = c(ns+1)
285  else
286  error = d(ns)
287  ns = ns-1
288  endif
289  y = y + error
290  enddo
291  end
integer npitbl real *nx parameter(n=101, npitbl=46, nx=n-1) real *8 uconst
subroutine kpolintp(xa, xstep, ya, ystep, n, x, y, error)
Definition: kpolintp.f:163
subroutine kdwhereis(x, in, a, step, loc)
Definition: kdwhereis.f:27
subroutine kpolintplogxyfe(xa, xstep, ya, ystep, nt, m, logxy, x, y, error)
Definition: kpolintp.f:22
subroutine kpolintplogfe(xa, xstep, ya, ystep, nt, m, x, y, error)
Definition: kpolintp.f:91
subroutine kpolintpeqs(x0, dx, ya, ystep, n, x, y, error)
Definition: kpolintp.f:228
subroutine kpolintpfe(xa, xstep, ya, ystep, nt, m, x, y, error)
Definition: kpolintp.f:134