COSMOS v7.655  COSMOSv7655
(AirShowerMC)
kpolygC.f
Go to the documentation of this file.
1 ! this is copy of kpolyg.f from Epics. C is added in the last part of
2 ! eahc name.
3 !c to test kpolygC
4 ! implicit none
5 ! real*8 x,y, kpolygC
6 ! integer i, n
7 ! do n=0, 0
8 ! do i=1, 2500
9 ! x =-0.10 + (i-1)* 0.01
10 ! y = kpolygC(n, x)
11 ! write(*,*) x, y
12 ! enddo
13 ! write(*, *)
14 ! enddo
15 ! end
16 !
17 ! *******************************************
18 ! * *
19 ! * kpolygC: n-th logarithmic derivative *
20 ! * of gamma function. *
21 ! * *
22 ! *******************************************
23 !
24 ! usage:
25 ! y= kpolygC(n,x)
26 !
27 ! n: 0,1,2... specifies n-th derivative
28 ! x: argument. may be negative.
29 ! kpolygC(0,x) = psi(x) = d ln(Gamma(x))/dx
30 ! d (G'/G ) /dx
31 ! kpolygC(1, x) =d psi(x)/dx etc
32 ! Note psi(x) != dln(Gamma(x+1))/dx
33 !
34 !
35  real*8 function kpolygc(n,x)
36  implicit none
37  real*8 x
38  integer n
39 !
40 !
41 !
42 !
43 ! Computes n-th derivative of psi function with 7-8 significant dig
44 ! ts. psi(x) is logarithmic derivative of gamma function. psi(1)=-g
45 ! where g=0.57721566---Euler const. in Rossi notation, psi(s+1)=
46 ! dlog(s!)/ds=polyg(0,s+1.), where s! means factorial of s. x must
47 ! not be 0,-1,-2,---, and for practical reason must be > -20, n<
48 ! nmax, (of course must be >= 0). if so message printed, and polyg=
49 ! 1.0e35.
50 !
51 !
52  integer,parameter::nmax=50
53  real*8 f(nmax)
54  real*8 b(6)/8.333333e-2, -1.388889e-3, 3.3068783e-5,
55  1 -8.267196e-7, 2.087676e-8, -52.841901e-11/
56  logical first/.true./
57  integer i, nt, j, m
58  real*8 z, s, znt, z2, sn, sum, zn
59  save first
60 
61  if(first) then
62 ! compute factorial up to nmax
63  first=.false.
64  f(1)=1.
65  do i=2,nmax
66  f(i)=float(i-1)*f(i-1)
67  enddo
68  endif
69 !
70  z=x
71  if(z .gt. 0. .or. z - aint(z) .ne. 0. .and.
72  * (n .ge. 0 .and. n .lt. nmax) ) then
73  s=0.
74  nt=n+1
75  do while (z .lt. 4.)
76  znt=1.
77  do i=1,nt
78  znt=znt*z
79  enddo
80  s=s+1./znt
81  z=z+1.
82  enddo
83  s=f(nt)*s
84  z2=z*z
85  zn=1.
86  do while (nt .gt. 1)
87  nt=nt-1
88  zn=zn*z
89  enddo
90  sn=-1.
91  if(mod(n,2).ne.0) sn=1.
92  sum=0.
93  do i=1,6
94  j=7-i
95  m=j+j+n
96  sum=(sum+f(m)*b(j))/z2
97  enddo
98  sum=((sum+0.5*f(n+1)/z)/zn+s)*sn
99  if(n .eq. 0) then
100  kpolygc=log(z)+sum
101  else
102  kpolygc=sum+f(n)/zn*sn
103  endif
104  else
105  write(*,
106  * '( ''***error input to kpolygC: (z,n)='',e18.8,i10)') z,n
107  kpolygc=1.e36
108  endif
109  end
real *8 function kpolygc(n, x)
Definition: kpolygC.f:36
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