Geology Reference
In-Depth Information
C
PROGRAMME LEGENDRE.FOR
C
C Programme to evaluate Legendre functions of the first kind.
C
IMPLICIT DOUBLE PRECISION(A-H,O-Z)
40
WRITE(6,10)
10
FORMAT(1X,'Enter m, n, z')
READ(5,*)M,N,Z
F=PMN(Z,M,N)
WRITE(6,20)M,N,Z,F
20
FORMAT(1X,'Order=',I2,5X,'Degree=',I2,5X,'Argument=',
1 F7.4,5X,'Function=',F20.15)
WRITE(6,30)
30
FORMAT(1X,'Enter 0 to end, 1 to calculate another value')
READ(5,*)IBR
IF(IBR.EQ.1) GO TO 40
END
C
DOUBLE PRECISION FUNCTION PMN(Z,M,N)
C
C PMN computes the value of the Legendre function of degree N, azimuthal
C number M, for argument Z. The procedure begins with the formula for
C the sectoral function for N=M, and then uses the recurrence relation
C across degree to arrive at the value for degree N.
C
IMPLICIT DOUBLE PRECISION(A-H,O-Z)
C Test if input arguments are out of range.
IF(M.LT.0.OR.DABS(Z).GT.1.D0) WRITE(6,10)
10 FORMAT(1X,'ONE OR MORE INPUT PARAMETERS OUT OF RANGE')
C Set Legendre function to zero if M>N and return.
PMN=0.D0
IF(M.GT.N) GO TO 11
C Begin calculation of sectoral value PMM.
C Set initial value of PMM.
PMM=1.D0
C Test if Legendre polynomial.
IF(M.EQ.0) GO TO 12
C Find square root of 1-Z*Z.
SRUMZ2=DSQRT((1.D0-Z)*(1.D0+Z))
C Complete calculation of sectoral value PMM.
FACT=1.D0
DO 13 I=1,M
PMM=-PMM*FACT*SRUMZ2
FACT=FACT+2.D0
13 CONTINUE
C Test if sectoral Legendre function.
12 IF(M.EQ.N) GO TO 14
C Convert M, N to floating point variables.
AM=DFLOAT(M)
AN=DFLOAT(N)
C Find next higher degree Legendre function.
PMMP1=(2.D0*AM+1.D0)*Z*PMM
C Test if M+1=N.
IF(M+1.EQ.N) GO TO 15
C Prepare to complete recursion.
MP2=M+2
P1=PMM
P2=PMMP1
C Complete recursion.
DO 16 I=MP2,N
AI=DFLOAT(I)
Search WWH ::




Custom Search