xlegf.f 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. *DECK XLEGF
  2. SUBROUTINE XLEGF (DNU1, NUDIFF, MU1, MU2, THETA, ID, PQA, IPQA,
  3. 1 IERROR)
  4. C***BEGIN PROLOGUE XLEGF
  5. C***PURPOSE Compute normalized Legendre polynomials and associated
  6. C Legendre functions.
  7. C***LIBRARY SLATEC
  8. C***CATEGORY C3A2, C9
  9. C***TYPE SINGLE PRECISION (XLEGF-S, DXLEGF-D)
  10. C***KEYWORDS LEGENDRE FUNCTIONS
  11. C***AUTHOR Smith, John M., (NBS and George Mason University)
  12. C***DESCRIPTION
  13. C
  14. C XLEGF: Extended-range Single-precision Legendre Functions
  15. C
  16. C A feature of the XLEGF subroutine for Legendre functions is
  17. C the use of extended-range arithmetic, a software extension of
  18. C ordinary floating-point arithmetic that greatly increases the
  19. C exponent range of the representable numbers. This avoids the
  20. C need for scaling the solutions to lie within the exponent range
  21. C of the most restrictive manufacturer's hardware. The increased
  22. C exponent range is achieved by allocating an integer storage
  23. C location together with each floating-point storage location.
  24. C
  25. C The interpretation of the pair (X,I) where X is floating-point
  26. C and I is integer is X*(IR**I) where IR is the internal radix of
  27. C the computer arithmetic.
  28. C
  29. C This subroutine computes one of the following vectors:
  30. C
  31. C 1. Legendre function of the first kind of negative order, either
  32. C a. P(-MU1,NU,X), P(-MU1-1,NU,X), ..., P(-MU2,NU,X) or
  33. C b. P(-MU,NU1,X), P(-MU,NU1+1,X), ..., P(-MU,NU2,X)
  34. C 2. Legendre function of the second kind, either
  35. C a. Q(MU1,NU,X), Q(MU1+1,NU,X), ..., Q(MU2,NU,X) or
  36. C b. Q(MU,NU1,X), Q(MU,NU1+1,X), ..., Q(MU,NU2,X)
  37. C 3. Legendre function of the first kind of positive order, either
  38. C a. P(MU1,NU,X), P(MU1+1,NU,X), ..., P(MU2,NU,X) or
  39. C b. P(MU,NU1,X), P(MU,NU1+1,X), ..., P(MU,NU2,X)
  40. C 4. Normalized Legendre polynomials, either
  41. C a. PN(MU1,NU,X), PN(MU1+1,NU,X), ..., PN(MU2,NU,X) or
  42. C b. PN(MU,NU1,X), PN(MU,NU1+1,X), ..., PN(MU,NU2,X)
  43. C
  44. C where X = COS(THETA).
  45. C
  46. C The input values to XLEGF are DNU1, NUDIFF, MU1, MU2, THETA,
  47. C and ID. These must satisfy
  48. C
  49. C DNU1 is REAL and greater than or equal to -0.5;
  50. C NUDIFF is INTEGER and non-negative;
  51. C MU1 is INTEGER and non-negative;
  52. C MU2 is INTEGER and greater than or equal to MU1;
  53. C THETA is REAL and in the half-open interval (0,PI/2];
  54. C ID is INTEGER and equal to 1, 2, 3 or 4;
  55. C
  56. C and additionally either NUDIFF = 0 or MU2 = MU1.
  57. C
  58. C If ID=1 and NUDIFF=0, a vector of type 1a above is computed
  59. C with NU=DNU1.
  60. C
  61. C If ID=1 and MU1=MU2, a vector of type 1b above is computed
  62. C with NU1=DNU1, NU2=DNU1+NUDIFF and MU=MU1.
  63. C
  64. C If ID=2 and NUDIFF=0, a vector of type 2a above is computed
  65. C with NU=DNU1.
  66. C
  67. C If ID=2 and MU1=MU2, a vector of type 2b above is computed
  68. C with NU1=DNU1, NU2=DNU1+NUDIFF and MU=MU1.
  69. C
  70. C If ID=3 and NUDIFF=0, a vector of type 3a above is computed
  71. C with NU=DNU1.
  72. C
  73. C If ID=3 and MU1=MU2, a vector of type 3b above is computed
  74. C with NU1=DNU1, NU2=DNU1+NUDIFF and MU=MU1.
  75. C
  76. C If ID=4 and NUDIFF=0, a vector of type 4a above is computed
  77. C with NU=DNU1.
  78. C
  79. C If ID=4 and MU1=MU2, a vector of type 4b above is computed
  80. C with NU1=DNU1, NU2=DNU1+NUDIFF and MU=MU1.
  81. C
  82. C In each case the vector of computed Legendre function values
  83. C is returned in the extended-range vector (PQA(I),IPQA(I)). The
  84. C length of this vector is either MU2-MU1+1 or NUDIFF+1.
  85. C
  86. C Where possible, XLEGF returns IPQA(I) as zero. In this case the
  87. C value of the Legendre function is contained entirely in PQA(I),
  88. C so it can be used in subsequent computations without further
  89. C consideration of extended-range arithmetic. If IPQA(I) is nonzero,
  90. C then the value of the Legendre function is not representable in
  91. C floating-point because of underflow or overflow. The program that
  92. C calls XLEGF must test IPQA(I) to ensure correct usage.
  93. C
  94. C IERROR is an error indicator. If no errors are detected, IERROR=0
  95. C when control returns to the calling routine. If an error is detected,
  96. C IERROR is returned as nonzero. The calling routine must check the
  97. C value of IERROR.
  98. C
  99. C If IERROR=110 or 111, invalid input was provided to XLEGF.
  100. C If IERROR=101,102,103, or 104, invalid input was provided to XSET.
  101. C If IERROR=105 or 106, an internal consistency error occurred in
  102. C XSET (probably due to a software malfunction in the library routine
  103. C I1MACH).
  104. C If IERROR=107, an overflow or underflow of an extended-range number
  105. C was detected in XADJ.
  106. C If IERROR=108, an overflow or underflow of an extended-range number
  107. C was detected in XC210.
  108. C
  109. C***SEE ALSO XSET
  110. C***REFERENCES Olver and Smith, Associated Legendre Functions on the
  111. C Cut, J Comp Phys, v 51, n 3, Sept 1983, pp 502--518.
  112. C Smith, Olver and Lozier, Extended-Range Arithmetic and
  113. C Normalized Legendre Polynomials, ACM Trans on Math
  114. C Softw, v 7, n 1, March 1981, pp 93--105.
  115. C***ROUTINES CALLED XERMSG, XPMU, XPMUP, XPNRM, XPQNU, XQMU, XQNU,
  116. C XRED, XSET
  117. C***REVISION HISTORY (YYMMDD)
  118. C 820728 DATE WRITTEN
  119. C 890126 Revised to meet SLATEC CML recommendations. (DWL and JMS)
  120. C 901019 Revisions to prologue. (DWL and WRB)
  121. C 901106 Changed all specific intrinsics to generic. (WRB)
  122. C Corrected order of sections in prologue and added TYPE
  123. C section. (WRB)
  124. C CALLs to XERROR changed to CALLs to XERMSG. (WRB)
  125. C 920127 Revised PURPOSE section of prologue. (DWL)
  126. C***END PROLOGUE XLEGF
  127. REAL PQA,DNU1,DNU2,SX,THETA,X,PI2
  128. DIMENSION PQA(*),IPQA(*)
  129. C
  130. C***FIRST EXECUTABLE STATEMENT XLEGF
  131. IERROR=0
  132. CALL XSET (0, 0, 0.0, 0,IERROR)
  133. IF (IERROR.NE.0) RETURN
  134. PI2=2.*ATAN(1.)
  135. C
  136. C ZERO OUTPUT ARRAYS
  137. C
  138. L=(MU2-MU1)+NUDIFF+1
  139. DO 290 I=1,L
  140. PQA(I)=0.
  141. 290 IPQA(I)=0
  142. C
  143. C CHECK FOR VALID INPUT VALUES
  144. C
  145. IF(NUDIFF.LT.0) GO TO 400
  146. IF(DNU1.LT.-.5) GO TO 400
  147. IF(MU2.LT.MU1) GO TO 400
  148. IF(MU1.LT.0) GO TO 400
  149. IF(THETA.LE.0..OR.THETA.GT.PI2) GO TO 420
  150. IF(ID.LT.1.OR.ID.GT.4) GO TO 400
  151. IF((MU1.NE.MU2).AND.(NUDIFF.GT.0)) GO TO 400
  152. C
  153. C IF DNU1 IS NOT AN INTEGER, NORMALIZED P(MU,DNU,X)
  154. C CANNOT BE CALCULATED. IF DNU1 IS AN INTEGER AND
  155. C MU1.GT.DNU2 THEN ALL VALUES OF P(+MU,DNU,X) AND
  156. C NORMALIZED P(MU,NU,X) WILL BE ZERO.
  157. C
  158. DNU2=DNU1+NUDIFF
  159. IF((ID.EQ.3).AND.(MOD(DNU1,1.).NE.0.)) GO TO 295
  160. IF((ID.EQ.4).AND.(MOD(DNU1,1.).NE.0.)) GO TO 400
  161. IF((ID.EQ.3.OR.ID.EQ.4).AND.MU1.GT.DNU2) RETURN
  162. 295 CONTINUE
  163. C
  164. X=COS(THETA)
  165. SX=1./SIN(THETA)
  166. IF(ID.EQ.2) GO TO 300
  167. IF(MU2-MU1.LE.0) GO TO 360
  168. C
  169. C FIXED NU, VARIABLE MU
  170. C CALL XPMU TO CALCULATE P(-MU1,NU,X),....,P(-MU2,NU,X)
  171. C
  172. CALL XPMU(DNU1,DNU2,MU1,MU2,THETA,X,SX,ID,PQA,IPQA,IERROR)
  173. IF (IERROR.NE.0) RETURN
  174. GO TO 380
  175. C
  176. 300 IF(MU2.EQ.MU1) GO TO 320
  177. C
  178. C FIXED NU, VARIABLE MU
  179. C CALL XQMU TO CALCULATE Q(MU1,NU,X),....,Q(MU2,NU,X)
  180. C
  181. CALL XQMU(DNU1,DNU2,MU1,MU2,THETA,X,SX,ID,PQA,IPQA,IERROR)
  182. IF (IERROR.NE.0) RETURN
  183. GO TO 390
  184. C
  185. C FIXED MU, VARIABLE NU
  186. C CALL XQNU TO CALCULATE Q(MU,DNU1,X),....,Q(MU,DNU2,X)
  187. C
  188. 320 CALL XQNU(DNU1,DNU2,MU1,THETA,X,SX,ID,PQA,IPQA,IERROR)
  189. IF (IERROR.NE.0) RETURN
  190. GO TO 390
  191. C
  192. C FIXED MU, VARIABLE NU
  193. C CALL XPQNU TO CALCULATE P(-MU,DNU1,X),....,P(-MU,DNU2,X)
  194. C
  195. 360 CALL XPQNU(DNU1,DNU2,MU1,THETA,ID,PQA,IPQA,IERROR)
  196. IF (IERROR.NE.0) RETURN
  197. C
  198. C IF ID = 3, TRANSFORM P(-MU,NU,X) VECTOR INTO
  199. C P(MU,NU,X) VECTOR.
  200. C
  201. 380 IF(ID.EQ.3) CALL XPMUP(DNU1,DNU2,MU1,MU2,PQA,IPQA,IERROR)
  202. IF (IERROR.NE.0) RETURN
  203. C
  204. C IF ID = 4, TRANSFORM P(-MU,NU,X) VECTOR INTO
  205. C NORMALIZED P(MU,NU,X) VECTOR.
  206. C
  207. IF(ID.EQ.4) CALL XPNRM(DNU1,DNU2,MU1,MU2,PQA,IPQA,IERROR)
  208. IF (IERROR.NE.0) RETURN
  209. C
  210. C PLACE RESULTS IN REDUCED FORM IF POSSIBLE
  211. C AND RETURN TO MAIN PROGRAM.
  212. C
  213. 390 DO 395 I=1,L
  214. CALL XRED(PQA(I),IPQA(I),IERROR)
  215. IF (IERROR.NE.0) RETURN
  216. 395 CONTINUE
  217. RETURN
  218. C
  219. C ***** ERROR TERMINATION *****
  220. C
  221. 400 CALL XERMSG ('SLATEC', 'XLEGF',
  222. + 'DNU1, NUDIFF, MU1, MU2, or ID not valid', 110, 1)
  223. IERROR=110
  224. RETURN
  225. 420 CALL XERMSG ('SLATEC', 'XLEGF', 'THETA out of range', 111, 1)
  226. IERROR=111
  227. RETURN
  228. END