NLSL
plgndr.f90
Go to the documentation of this file.
1 c Version 1.4 10/10/94
2 c*********************************************************************
3 c
4 c ASSOCIATED LEGENDRE FUNCTIONS
5 c -----------------------------
6 c
7 c This double precision function subroutine calculates the
8 c value of the associated Legendre function via an upward
9 c recurrence scheme taken from "Numerical Recipes", W. H. Press,
10 c B. P. Flannery, S. A. Teulosky and W. T. Vetterling,1st ed.,
11 c Cambridge Univ. Press, 1986.
12 c
13 c written by DJS 10-SEP-87
14 c
15 c Includes:
16 c
17 c Uses:
18 c
19 c*********************************************************************
20 c
21  function plgndr(l,m,z)
22  implicit none
23 c
24  integer l,m
25  double precision plgndr,z
26 c
27  integer i
28  double precision pmm,temp1,temp2,pmmp1,pmmp2
29 c
30  intrinsic abs,sqrt
31 c
32 c#####################################################################
33 c
34  if ((m.lt.0).or.(m.gt.l).or.(abs(z).gt.1.0d0)) then
35  go to 9999
36  end if
37 c
38  pmm=1.0d0
39 c
40 c---------------------------------------------------------------------
41 c
42 c calculate the starting point for the upward recurrence
43 c on l using the formula :
44 c
45 c m m 2 m/2
46 c P (z)=(-1) (2m-1)!! (1-z )
47 c m
48 c
49 c---------------------------------------------------------------------
50 c
51  if (m.gt.0) then
52  temp1=sqrt((1.0d0-z)*(1.0d0+z))
53  temp2=1.0d0
54  do 10 i=1,m
55  pmm=-pmm*temp1*temp2
56  10 temp2=temp2+2.0d0
57  end if
58 c
59 c---------------------------------------------------------------------
60 c
61 c do upward recursion on l using the formulae :
62 c
63 c m m m
64 c (l-m)P (z)= z(2l-1)P (z) - (l+m-1)P (z)
65 c l l-1 l-2
66 c
67 c or
68 c m m
69 c P (z) = z(2m+1) P (z) if l=m+1
70 c m+1 m
71 c
72 c---------------------------------------------------------------------
73 c
74  if (l.eq.m) then
75  plgndr=pmm
76  else
77  pmmp1=z*(2*m+1)*pmm
78  if (l.eq.m+1) then
79  plgndr=pmmp1
80  else
81  do 20 i=m+2,l
82  pmmp2=(z*(2*i-1)*pmmp1-(i+m-1)*pmm)/(i-m)
83  pmm=pmmp1
84  20 pmmp1=pmmp2
85  plgndr=pmmp2
86  end if
87  end if
88 c
89 c---------------------------------------------------------------------
90 c return to calling program
91 c---------------------------------------------------------------------
92 c
93  return
94 c
95 c---------------------------------------------------------------------
96 c exit from program if improper arguments detected
97 c---------------------------------------------------------------------
98 c
99  9999 write (*,1000) l,m,z
100  1000 format('Improper arguments for PLGNDR: ',
101  # i3,',',i3,',',g13.6)
102  stop
103  end
double precision function plgndr(l, m, z)
Definition: plgndr.f90:22