COSMOS v7.655  COSMOSv7655
(AirShowerMC)
kpmnx.f
Go to the documentation of this file.
1 ! test kpmnx
2 !
3 ! include "kgamma.f"
4 ! real*4 x, y, sint
5 ! integer m, n
6 ! real*4 kpmnxn
7 !c
8 ! read(*,*) m, n
9 !
10 ! do x=-1.d0, 1.0000001d0, 0.01d0
11 ! y = min(x, 1.d0)
12 ! sint =sqrt(1.d0- y**2)
13 ! write(*,*) m, n, y, kpmnxn(m, n, sint, y)
14 ! enddo
15 ! end
16 !
17 ! kpmnx: P(n, m, x) = m-th derivative
18 ! of Legendre Pn(x) times
19 ! (1-x**2)**(m/2)
20 !
21 ! Use recurrence relation:
22 ! (n-m) P(n, m, x) = (2n-1)xP(n-1,m, x) - (n-1+m)P(n-2, m, x)
23 !
24 ! P(0, 0, x) = 1, P(n, m, x) = 0 (m> n)
25 ! P(1, 0, x) = 2x
26 ! P(1, 1, x) = 2(1-x**2)**(1/2)
27 ! P(1, m, x) = 0 ( m>=2 )
28 !
29  real*4 function krmnx(m, n, x)
30  implicit none
31  integer m ! input >=0
32  integer n ! input. >=0
33  real*4 x ! input. argument |x| <= 1
34 
35 
36 ! m-th derivative of Pn(x)
37 ! where Pn(x) = 1/(2^2 n!) (x^2-1)^n
38 !
39  real*4 r0m, r1m, rn, rn1, rn2, krnnx
40  real*4 kpnx
41 
42  integer i
43 
44  if(n .lt. 0 .or. m .lt. 0) then
45  write(0, *) ' error input to krmnx; n, m=', n, m
46  stop 9999
47  endif
48  if(m .eq. 0) then
49 ! m=0
50  krmnx = kpnx(n, x)
51  elseif(m .gt. n) then
52 ! krmnx = 0.d0
53  krmnx = 0.
54  elseif(n .ge. 1) then
55  if(m .eq. 1) then
56 ! r1m = 1.d0
57  r1m = 1.0
58  r0m = 0.
59  else
60 ! m > 1
61  r1m = 0.
62  r0m = 0.
63  endif
64 
65  if( n .ge. 2) then
66  rn2 = r0m
67  rn1 = r1m
68  do i = 2, n
69  if(i .eq. m) then
70  rn = krnnx(i, x)
71  else
72 ! (n-m) r(n, m, x) = (2n-1)xr(n-1,m, x) - (n-1+m)r(n-2, m, x)
73  rn = ( (2*i-1)*x*rn1 - (i-1+m)*rn2 ) /(i-m)
74  endif
75  rn2 = rn1
76  rn1 = rn
77  enddo
78  krmnx = rn
79  else
80  krmnx = r1m
81  endif
82  else
83 ! n=0, m=0
84  krmnx = 1
85  endif
86  end
87 ! **********************************************
88  real*4 function krnnx(n, x)
89  implicit none
90 ! kpmnx for n=m case.
91  integer n ! input
92  real*4 x ! input.
93 !
94 ! r(n,m) = r(n-2,m) + (2n-1)*r(n-1, m-1)
95 ! since n=m, r(n-2,m) is always 0.
96 ! So r(n) = (2n-1)*r(n-1)
97 ! r(0) = 1.
98 !
99  real*4 r
100  integer i
101 
102 
103  if(n .lt. 0) then
104  write(0,*) 'error input to krnnx; n=',n
105  stop 999
106  else
107 ! r = 1.d0
108  r = 1.0
109  do i = 1, n
110  r = (2*i-1)*r
111  enddo
112  krnnx = r
113  endif
114  end
115 !-------------------------------------------------------
116 !c testing kpnx, kpmnx, kdpmnx, kdpnx, kdpmnxn, kpmnxn
117 !c kpnx: Legendre polynomial
118 !c kpmnx: Legendre polynomial p(m, n, x)
119 !c kdpmnx: d p(m, n, x)/dx
120 !c kdpnx: m-th derivative of legendre function, kpnx
121 !c = p(m,n,x)/(1-x**2)**(m/2)
122 !c kdpmnxn: sqrt( em* (n-m)!/ (n+m)! ) * kdpmnx
123 !c kpmnxn: sqrt( em* (n-m)!/(n+m)! ) * kpmnx
124 ! implicit none
125 ! integer m, n
126 ! real*4 x, y, y1, y2, z, kpmnx
127 ! real*8 kgamma
128 ! real*4 kpnx, kdpmnx, kdpmnxn
129 ! integer mv
130 ! read(*, *) mv
131 ! do m=mv, mv
132 !c
133 ! do n=1, 8
134 ! do x=-.996, 1., .004
135 !c y = kpmnx(m, n, x)
136 !c y1 = kgamma(dble(n-m)+1.d0)
137 !c y2 = kgamma(dble(n+m)+1.d0)
138 !c z =sqrt((2*n+1)/2.d0*y1/y2)*y
139 !c z = kpnx(n, x)
140 !c z = kdpmnx(m, n, x)
141 ! z = kdpmnxn(m, n, x)
142 ! write(*, *) sngl(x), sngl(z)
143 ! enddo
144 ! write(*,*)
145 ! enddo
146 ! enddo
147 ! end
148 !*********************************************************************
149  real*4 function kpnx(n, x)
150  implicit none
151  real*4 x
152  integer n
153 ! Legendre polinomial (n>=0)
154  real*4 pim, pimm, pi
155  integer nc/0/, i
156 !
157  if(n .eq. 0) then
158 ! kpnx=1.d0
159  kpnx=1.0
160  elseif(n .eq. 1) then
161  kpnx=x
162  elseif(n .ge. 2) then
163  pim=x
164 ! pimm=1.d0
165  pimm=1.0
166  do i=2, n
167  pi=( (2*i-1)*x *pim - (i-1)*pimm )/i
168  pimm=pim
169  pim=pi
170  enddo
171  kpnx=pi
172  else
173  if(nc .lt. 20) then
174  write(*,*) ' n=',n,' invalid for kpnx'
175  nc=nc+1
176  endif
177 ! kpnx=1.d50
178  kpnx=1.e35
179  endif
180  end
181 ! **************************************
182  real*4 function kpmnx(m, n, sint, x)
183  implicit none
184  real*4 x, sint
185  integer m, n
186 !
187  real*4 krmnx, sintm
188  if(m .eq. 0) then
189  sintm = 1.
190  else
191  sintm = sint**m
192  endif
193  kpmnx = sintm * krmnx(m, n, x)
194  end
195 ! ********************************
196  real*4 function kpmnxn(m, n, sint, x)
197  implicit none
198  real*4 x, sint
199  integer m, n
200 ! sqrt(em*(n-m)!/(n+m)!)* kpmnx(m, n, x )
201  real*4 kpnorm, kpmnx
202  kpmnxn=kpnorm(m, n)* kpmnx(m, n, sint, x)
203  end
204 ! *********************
205  real*4 function kpmnxisin(m, n, sint, x)
206  implicit none
207  integer m, n ! m >= 1
208  real*4 x
209  real*4 sint ! sqrt(1.-x**2)
210 !
211  real*4 krmnx, sintm
212 
213  if(m .eq. 1) then
214  sintm = 1.
215  else
216  sintm = sint**(m-1)
217  endif
218  kpmnxisin = sintm * krmnx(m, n, x)
219  end
220 ! ********************
221  real*4 function kpmnxisinn(m, n, sint, x)
222  implicit none
223  integer m, n ! m >=1
224  real*4 x
225  real*4 sint ! sint = sqrt(1-x**2)
226  real*4 kpmnxisin, kpnorm
227  kpmnxisinn = kpnorm(m, n)*kpmnxisin(m, n, sint, x)
228  end
229 ! **********************
230  real*4 function kdpmnxsin(m, n, sint, x)
231  implicit none
232  real*4 x
233  real*4 sint
234  integer m, n
235 
236  real*4 krmnx, sintm
237  if(m .gt. 0) then
238  if(m .eq. 1) then
239  sintm = 1.
240  else
241  sintm = sint**(m-1)
242  endif
243  kdpmnxsin= (-m*x*krmnx(m, n, x) + sint*sint*krmnx(m+1, n, x))
244  * *sintm
245  else
246  kdpmnxsin= sint*krmnx(1, n, x)
247  endif
248  end
249  real*4 function kdpmnxsinn(m, n, sint, x)
250  implicit none
251  real*4 x
252  real*4 sint
253  integer m, n
254 !
255  real*4 kpnorm, kdpmnxsin
256  kdpmnxsinn = kpnorm(m, n)* kdpmnxsin(m, n, sint, x)
257  end
258 ! *************
259  real*4 function kpnorm(m, n)
260  implicit none
261  integer m, n
262  real*4 pnorms, em
263  real*8 kgamma
264  save pnorms
265 !
266  integer ms/-1/, ns/-1/
267  logical first
268 
269 
270  integer nn, i
271  parameter(nn=30)
272  real*4 fact(0:nn), dv, dn
273  save first, fact, ms, ns
274  data first /.true./
275 
276  if(first) then
277  fact(0) = 1.
278  do i= 1, nn
279  fact(i) = i* fact(i-1)
280  enddo
281  first = .false.
282  endif
283  if(m .eq. ms .and. n .eq. ns)then
284  elseif(m .gt. n) then
285  pnorms=0.0
286  else
287  ms = m
288  ns = n
289  if(m .eq. 0)then
290  em=1.0
291  else
292  em=2.0
293  endif
294  if(n-m .le. nn) then
295  dn = fact(n-m)
296  else
297  dn = kgamma(dble(n-m+1))
298  endif
299  if(n+m .le. nn) then
300  dv = fact(n+m)
301  else
302  dv = kgamma(dble(n+m+1))
303  endif
304  pnorms=sqrt(em* dn /dv)
305  endif
306  kpnorm=pnorms
307  end
308 
309 
310 
integer npitbl real *nx parameter(n=101, npitbl=46, nx=n-1) real *8 uconst
real *4 function kpmnxisin(m, n, sint, x)
Definition: kpmnx.f:206
real *4 function kdpmnxsinn(m, n, sint, x)
Definition: kpmnx.f:250
real *4 function kdpmnxsin(m, n, sint, x)
Definition: kpmnx.f:231
real *4 function kpmnx(m, n, sint, x)
Definition: kpmnx.f:183
real *4 function kpnorm(m, n)
Definition: kpmnx.f:260
block data cblkElemag data *AnihiE ! Eposi< 1 TeV, anihilation considered *X0/365.667/, ! radiation length of air in kg/m2 *Ecrit/81.e-3/, ! critical energy of air in GeV *MaxComptonE/1./, ! compton is considered below 1 GeV *MaxPhotoE/1.e-3/, ! above this, PhotoElectric effect neg. *MinPhotoProdE/153.e-3/, ! below 153 MeV, no gp --> hadrons ! scattering const not MeV *Knockon true
Definition: cblkElemag.h:7
real *4 function kpmnxn(m, n, sint, x)
Definition: kpmnx.f:197
real *4 function kpnx(n, x)
Definition: kpmnx.f:150
real *4 function krmnx(m, n, x)
Definition: kpmnx.f:30
block data cblkElemag data *AnihiE ! Eposi< 1 TeV, anihilation considered *X0/365.667/, ! radiation length of air in kg/m2 *Ecrit/81.e-3/, ! critical energy of air in GeV *MaxComptonE/1./, ! compton is considered below 1 GeV *MaxPhotoE/1.e-3/, ! above this, PhotoElectric effect neg. *MinPhotoProdE/153.e-3/, ! below 153 MeV, no gp --> hadrons ! scattering const not MeV *Knockon ! knockon is considered Obsolete *PhotoProd false
Definition: cblkElemag.h:7
real *4 function kpmnxisinn(m, n, sint, x)
Definition: kpmnx.f:222
real *4 function krnnx(n, x)
Definition: kpmnx.f:89