OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
legend.f
Go to the documentation of this file.
1  SUBROUTINE legend(N,M,X,P)
2 C VERSION OF 2/9/87
3 C PURPOSE
4 C COMPUTES LEGENDRE AND ASSOCIATED LEGENDRE FUNCTIONS UP TO
5 C DEGREE N AND ORDER M, N.GE.M
6 C INPUT
7 C N = DEGREE OF SPHERICAL HARMONICS
8 C M = ORDER OF SPHERICAL HARMONICS
9 C X = SIN (LATITUDE)
10 C OUTPUT
11 C P = 2-D LEGENDRE FUNCTIONS
12 C CALLED BY SUBROUTINES
13 C DER
14 C CALL SUBROUTINES
15 C NONE
16 C REFERENCES
17 C JPL EM 312/87-153, 20 APRIL 1987
18 C ANALYSIS
19 C J. H. KWOK - JPL
20 C PROGRAMMER
21 C J. H. KWOK - JPL
22 C PROGRAM MODIFICATION
23 C NONE
24 C COMMENTS
25 C THIS PROGRAM HAS BEEN DIMENSION FOR MAXIMUM OF 40X40 HARMONICS.
26 C FOR HIGHER ORDER OR DEGREE, REDIMENSION P( , ). THE FUNCTIONS
27 C ARE STORED AS PIJ=P(I+1,J+1). INPUT N CAN BE .GE. M.
28 C
29  IMPLICIT DOUBLE PRECISION (a-h,o-z)
30  dimension p(41,41)
31  DATA one/1.d0/
32  p(1,1)=one
33  p(2,1)=x
34 C *** COMPUTE LEGENDRE FUNCTIONS UP TO DEGREE N
35  DO 100 i=2,n
36  100 p(i+1,1)=((2*i-1)*x*p(i,1)-(i-1)*p(i-1,1))/i
37  IF (m.EQ.0) RETURN
38 C *** COMPUTE ASSOCIATED LEGENDRE FUNCTIONS UP TO ORDER M
39  y=dsqrt(one-x*x)
40  p(2,2)=y
41  IF (m.EQ.1) GO TO 400
42 C *** THIS IS THE SECTORIAL PART OF THE ASSOCIATED FUNCTIONS
43  DO 200 i=2,m
44  200 p(i+1,i+1)=(2*i-1)*y*p(i,i)
45  400 CONTINUE
46 C *** THIS THE TESSERAL PART OF THE ASSOCIATED FUNCTIONS
47  DO 500 i=2,n
48  i1=i-1
49  DO 300 j=1,i1
50  IF (j.GT.m) GO TO 500
51  p(i+1,j+1)=(2*i-1)*y*p(i,j)
52  IF (i-2.GE.j) p(i+1,j+1)=p(i+1,j+1)+p(i-1,j+1)
53  300 CONTINUE
54  500 CONTINUE
55  RETURN
56  END
subroutine legend(N, M, X, P)
Definition: legend.f:2