dqawse.f 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. *DECK DQAWSE
  2. SUBROUTINE DQAWSE (F, A, B, ALFA, BETA, INTEGR, EPSABS, EPSREL,
  3. + LIMIT, RESULT, ABSERR, NEVAL, IER, ALIST, BLIST, RLIST, ELIST,
  4. + IORD, LAST)
  5. C***BEGIN PROLOGUE DQAWSE
  6. C***PURPOSE The routine calculates an approximation result to a given
  7. C definite integral I = Integral of F*W over (A,B),
  8. C (where W shows a singular behaviour at the end points,
  9. C see parameter INTEGR).
  10. C Hopefully satisfying following claim for accuracy
  11. C ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I)).
  12. C***LIBRARY SLATEC (QUADPACK)
  13. C***CATEGORY H2A2A1
  14. C***TYPE DOUBLE PRECISION (QAWSE-S, DQAWSE-D)
  15. C***KEYWORDS ALGEBRAIC-LOGARITHMIC END POINT SINGULARITIES,
  16. C AUTOMATIC INTEGRATOR, CLENSHAW-CURTIS METHOD, QUADPACK,
  17. C QUADRATURE, SPECIAL-PURPOSE
  18. C***AUTHOR Piessens, Robert
  19. C Applied Mathematics and Programming Division
  20. C K. U. Leuven
  21. C de Doncker, Elise
  22. C Applied Mathematics and Programming Division
  23. C K. U. Leuven
  24. C***DESCRIPTION
  25. C
  26. C Integration of functions having algebraico-logarithmic
  27. C end point singularities
  28. C Standard fortran subroutine
  29. C Double precision version
  30. C
  31. C PARAMETERS
  32. C ON ENTRY
  33. C F - Double precision
  34. C Function subprogram defining the integrand
  35. C function F(X). The actual name for F needs to be
  36. C declared E X T E R N A L in the driver program.
  37. C
  38. C A - Double precision
  39. C Lower limit of integration
  40. C
  41. C B - Double precision
  42. C Upper limit of integration, B.GT.A
  43. C If B.LE.A, the routine will end with IER = 6.
  44. C
  45. C ALFA - Double precision
  46. C Parameter in the WEIGHT function, ALFA.GT.(-1)
  47. C If ALFA.LE.(-1), the routine will end with
  48. C IER = 6.
  49. C
  50. C BETA - Double precision
  51. C Parameter in the WEIGHT function, BETA.GT.(-1)
  52. C If BETA.LE.(-1), the routine will end with
  53. C IER = 6.
  54. C
  55. C INTEGR - Integer
  56. C Indicates which WEIGHT function is to be used
  57. C = 1 (X-A)**ALFA*(B-X)**BETA
  58. C = 2 (X-A)**ALFA*(B-X)**BETA*LOG(X-A)
  59. C = 3 (X-A)**ALFA*(B-X)**BETA*LOG(B-X)
  60. C = 4 (X-A)**ALFA*(B-X)**BETA*LOG(X-A)*LOG(B-X)
  61. C If INTEGR.LT.1 or INTEGR.GT.4, the routine
  62. C will end with IER = 6.
  63. C
  64. C EPSABS - Double precision
  65. C Absolute accuracy requested
  66. C EPSREL - Double precision
  67. C Relative accuracy requested
  68. C If EPSABS.LE.0
  69. C and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
  70. C the routine will end with IER = 6.
  71. C
  72. C LIMIT - Integer
  73. C Gives an upper bound on the number of subintervals
  74. C in the partition of (A,B), LIMIT.GE.2
  75. C If LIMIT.LT.2, the routine will end with IER = 6.
  76. C
  77. C ON RETURN
  78. C RESULT - Double precision
  79. C Approximation to the integral
  80. C
  81. C ABSERR - Double precision
  82. C Estimate of the modulus of the absolute error,
  83. C which should equal or exceed ABS(I-RESULT)
  84. C
  85. C NEVAL - Integer
  86. C Number of integrand evaluations
  87. C
  88. C IER - Integer
  89. C IER = 0 Normal and reliable termination of the
  90. C routine. It is assumed that the requested
  91. C accuracy has been achieved.
  92. C IER.GT.0 Abnormal termination of the routine
  93. C the estimates for the integral and error
  94. C are less reliable. It is assumed that the
  95. C requested accuracy has not been achieved.
  96. C ERROR MESSAGES
  97. C = 1 Maximum number of subdivisions allowed
  98. C has been achieved. One can allow more
  99. C subdivisions by increasing the value of
  100. C LIMIT. However, if this yields no
  101. C improvement, it is advised to analyze the
  102. C integrand in order to determine the
  103. C integration difficulties which prevent the
  104. C requested tolerance from being achieved.
  105. C In case of a jump DISCONTINUITY or a local
  106. C SINGULARITY of algebraico-logarithmic type
  107. C at one or more interior points of the
  108. C integration range, one should proceed by
  109. C splitting up the interval at these
  110. C points and calling the integrator on the
  111. C subranges.
  112. C = 2 The occurrence of roundoff error is
  113. C detected, which prevents the requested
  114. C tolerance from being achieved.
  115. C = 3 Extremely bad integrand behaviour occurs
  116. C at some points of the integration
  117. C interval.
  118. C = 6 The input is invalid, because
  119. C B.LE.A or ALFA.LE.(-1) or BETA.LE.(-1), or
  120. C INTEGR.LT.1 or INTEGR.GT.4, or
  121. C (EPSABS.LE.0 and
  122. C EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
  123. C or LIMIT.LT.2.
  124. C RESULT, ABSERR, NEVAL, RLIST(1), ELIST(1),
  125. C IORD(1) and LAST are set to zero. ALIST(1)
  126. C and BLIST(1) are set to A and B
  127. C respectively.
  128. C
  129. C ALIST - Double precision
  130. C Vector of dimension at least LIMIT, the first
  131. C LAST elements of which are the left
  132. C end points of the subintervals in the partition
  133. C of the given integration range (A,B)
  134. C
  135. C BLIST - Double precision
  136. C Vector of dimension at least LIMIT, the first
  137. C LAST elements of which are the right
  138. C end points of the subintervals in the partition
  139. C of the given integration range (A,B)
  140. C
  141. C RLIST - Double precision
  142. C Vector of dimension at least LIMIT, the first
  143. C LAST elements of which are the integral
  144. C approximations on the subintervals
  145. C
  146. C ELIST - Double precision
  147. C Vector of dimension at least LIMIT, the first
  148. C LAST elements of which are the moduli of the
  149. C absolute error estimates on the subintervals
  150. C
  151. C IORD - Integer
  152. C Vector of dimension at least LIMIT, the first K
  153. C of which are pointers to the error
  154. C estimates over the subintervals, so that
  155. C ELIST(IORD(1)), ..., ELIST(IORD(K)) with K = LAST
  156. C If LAST.LE.(LIMIT/2+2), and K = LIMIT+1-LAST
  157. C otherwise form a decreasing sequence
  158. C
  159. C LAST - Integer
  160. C Number of subintervals actually produced in
  161. C the subdivision process
  162. C
  163. C***REFERENCES (NONE)
  164. C***ROUTINES CALLED D1MACH, DQC25S, DQMOMO, DQPSRT
  165. C***REVISION HISTORY (YYMMDD)
  166. C 800101 DATE WRITTEN
  167. C 890531 Changed all specific intrinsics to generic. (WRB)
  168. C 890831 Modified array declarations. (WRB)
  169. C 890831 REVISION DATE from Version 3.2
  170. C 891214 Prologue converted to Version 4.0 format. (BAB)
  171. C***END PROLOGUE DQAWSE
  172. C
  173. DOUBLE PRECISION A,ABSERR,ALFA,ALIST,AREA,AREA1,AREA12,AREA2,A1,
  174. 1 A2,B,BETA,BLIST,B1,B2,CENTRE,D1MACH,ELIST,EPMACH,
  175. 2 EPSABS,EPSREL,ERRBND,ERRMAX,ERROR1,ERRO12,ERROR2,ERRSUM,F,
  176. 3 RESAS1,RESAS2,RESULT,RG,RH,RI,RJ,RLIST,UFLOW
  177. INTEGER IER,INTEGR,IORD,IROFF1,IROFF2,K,LAST,LIMIT,MAXERR,NEV,
  178. 1 NEVAL,NRMAX
  179. C
  180. EXTERNAL F
  181. C
  182. DIMENSION ALIST(*),BLIST(*),RLIST(*),ELIST(*),
  183. 1 IORD(*),RI(25),RJ(25),RH(25),RG(25)
  184. C
  185. C LIST OF MAJOR VARIABLES
  186. C -----------------------
  187. C
  188. C ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
  189. C CONSIDERED UP TO NOW
  190. C BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
  191. C CONSIDERED UP TO NOW
  192. C RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER
  193. C (ALIST(I),BLIST(I))
  194. C ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)
  195. C MAXERR - POINTER TO THE INTERVAL WITH LARGEST
  196. C ERROR ESTIMATE
  197. C ERRMAX - ELIST(MAXERR)
  198. C AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
  199. C ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS
  200. C ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
  201. C ABS(RESULT))
  202. C *****1 - VARIABLE FOR THE LEFT SUBINTERVAL
  203. C *****2 - VARIABLE FOR THE RIGHT SUBINTERVAL
  204. C LAST - INDEX FOR SUBDIVISION
  205. C
  206. C
  207. C MACHINE DEPENDENT CONSTANTS
  208. C ---------------------------
  209. C
  210. C EPMACH IS THE LARGEST RELATIVE SPACING.
  211. C UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
  212. C
  213. C***FIRST EXECUTABLE STATEMENT DQAWSE
  214. EPMACH = D1MACH(4)
  215. UFLOW = D1MACH(1)
  216. C
  217. C TEST ON VALIDITY OF PARAMETERS
  218. C ------------------------------
  219. C
  220. IER = 6
  221. NEVAL = 0
  222. LAST = 0
  223. RLIST(1) = 0.0D+00
  224. ELIST(1) = 0.0D+00
  225. IORD(1) = 0
  226. RESULT = 0.0D+00
  227. ABSERR = 0.0D+00
  228. IF (B.LE.A.OR.(EPSABS.EQ.0.0D+00.AND.
  229. 1 EPSREL.LT.MAX(0.5D+02*EPMACH,0.5D-28)).OR.ALFA.LE.(-0.1D+01)
  230. 2 .OR.BETA.LE.(-0.1D+01).OR.INTEGR.LT.1.OR.INTEGR.GT.4.OR.
  231. 3 LIMIT.LT.2) GO TO 999
  232. IER = 0
  233. C
  234. C COMPUTE THE MODIFIED CHEBYSHEV MOMENTS.
  235. C
  236. CALL DQMOMO(ALFA,BETA,RI,RJ,RG,RH,INTEGR)
  237. C
  238. C INTEGRATE OVER THE INTERVALS (A,(A+B)/2) AND ((A+B)/2,B).
  239. C
  240. CENTRE = 0.5D+00*(B+A)
  241. CALL DQC25S(F,A,B,A,CENTRE,ALFA,BETA,RI,RJ,RG,RH,AREA1,
  242. 1 ERROR1,RESAS1,INTEGR,NEV)
  243. NEVAL = NEV
  244. CALL DQC25S(F,A,B,CENTRE,B,ALFA,BETA,RI,RJ,RG,RH,AREA2,
  245. 1 ERROR2,RESAS2,INTEGR,NEV)
  246. LAST = 2
  247. NEVAL = NEVAL+NEV
  248. RESULT = AREA1+AREA2
  249. ABSERR = ERROR1+ERROR2
  250. C
  251. C TEST ON ACCURACY.
  252. C
  253. ERRBND = MAX(EPSABS,EPSREL*ABS(RESULT))
  254. C
  255. C INITIALIZATION
  256. C --------------
  257. C
  258. IF(ERROR2.GT.ERROR1) GO TO 10
  259. ALIST(1) = A
  260. ALIST(2) = CENTRE
  261. BLIST(1) = CENTRE
  262. BLIST(2) = B
  263. RLIST(1) = AREA1
  264. RLIST(2) = AREA2
  265. ELIST(1) = ERROR1
  266. ELIST(2) = ERROR2
  267. GO TO 20
  268. 10 ALIST(1) = CENTRE
  269. ALIST(2) = A
  270. BLIST(1) = B
  271. BLIST(2) = CENTRE
  272. RLIST(1) = AREA2
  273. RLIST(2) = AREA1
  274. ELIST(1) = ERROR2
  275. ELIST(2) = ERROR1
  276. 20 IORD(1) = 1
  277. IORD(2) = 2
  278. IF(LIMIT.EQ.2) IER = 1
  279. IF(ABSERR.LE.ERRBND.OR.IER.EQ.1) GO TO 999
  280. ERRMAX = ELIST(1)
  281. MAXERR = 1
  282. NRMAX = 1
  283. AREA = RESULT
  284. ERRSUM = ABSERR
  285. IROFF1 = 0
  286. IROFF2 = 0
  287. C
  288. C MAIN DO-LOOP
  289. C ------------
  290. C
  291. DO 60 LAST = 3,LIMIT
  292. C
  293. C BISECT THE SUBINTERVAL WITH LARGEST ERROR ESTIMATE.
  294. C
  295. A1 = ALIST(MAXERR)
  296. B1 = 0.5D+00*(ALIST(MAXERR)+BLIST(MAXERR))
  297. A2 = B1
  298. B2 = BLIST(MAXERR)
  299. C
  300. CALL DQC25S(F,A,B,A1,B1,ALFA,BETA,RI,RJ,RG,RH,AREA1,
  301. 1 ERROR1,RESAS1,INTEGR,NEV)
  302. NEVAL = NEVAL+NEV
  303. CALL DQC25S(F,A,B,A2,B2,ALFA,BETA,RI,RJ,RG,RH,AREA2,
  304. 1 ERROR2,RESAS2,INTEGR,NEV)
  305. NEVAL = NEVAL+NEV
  306. C
  307. C IMPROVE PREVIOUS APPROXIMATIONS INTEGRAL AND ERROR
  308. C AND TEST FOR ACCURACY.
  309. C
  310. AREA12 = AREA1+AREA2
  311. ERRO12 = ERROR1+ERROR2
  312. ERRSUM = ERRSUM+ERRO12-ERRMAX
  313. AREA = AREA+AREA12-RLIST(MAXERR)
  314. IF(A.EQ.A1.OR.B.EQ.B2) GO TO 30
  315. IF(RESAS1.EQ.ERROR1.OR.RESAS2.EQ.ERROR2) GO TO 30
  316. C
  317. C TEST FOR ROUNDOFF ERROR.
  318. C
  319. IF(ABS(RLIST(MAXERR)-AREA12).LT.0.1D-04*ABS(AREA12)
  320. 1 .AND.ERRO12.GE.0.99D+00*ERRMAX) IROFF1 = IROFF1+1
  321. IF(LAST.GT.10.AND.ERRO12.GT.ERRMAX) IROFF2 = IROFF2+1
  322. 30 RLIST(MAXERR) = AREA1
  323. RLIST(LAST) = AREA2
  324. C
  325. C TEST ON ACCURACY.
  326. C
  327. ERRBND = MAX(EPSABS,EPSREL*ABS(AREA))
  328. IF(ERRSUM.LE.ERRBND) GO TO 35
  329. C
  330. C SET ERROR FLAG IN THE CASE THAT THE NUMBER OF INTERVAL
  331. C BISECTIONS EXCEEDS LIMIT.
  332. C
  333. IF(LAST.EQ.LIMIT) IER = 1
  334. C
  335. C
  336. C SET ERROR FLAG IN THE CASE OF ROUNDOFF ERROR.
  337. C
  338. IF(IROFF1.GE.6.OR.IROFF2.GE.20) IER = 2
  339. C
  340. C SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
  341. C AT INTERIOR POINTS OF INTEGRATION RANGE.
  342. C
  343. IF(MAX(ABS(A1),ABS(B2)).LE.(0.1D+01+0.1D+03*EPMACH)*
  344. 1 (ABS(A2)+0.1D+04*UFLOW)) IER = 3
  345. C
  346. C APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
  347. C
  348. 35 IF(ERROR2.GT.ERROR1) GO TO 40
  349. ALIST(LAST) = A2
  350. BLIST(MAXERR) = B1
  351. BLIST(LAST) = B2
  352. ELIST(MAXERR) = ERROR1
  353. ELIST(LAST) = ERROR2
  354. GO TO 50
  355. 40 ALIST(MAXERR) = A2
  356. ALIST(LAST) = A1
  357. BLIST(LAST) = B1
  358. RLIST(MAXERR) = AREA2
  359. RLIST(LAST) = AREA1
  360. ELIST(MAXERR) = ERROR2
  361. ELIST(LAST) = ERROR1
  362. C
  363. C CALL SUBROUTINE DQPSRT TO MAINTAIN THE DESCENDING ORDERING
  364. C IN THE LIST OF ERROR ESTIMATES AND SELECT THE SUBINTERVAL
  365. C WITH LARGEST ERROR ESTIMATE (TO BE BISECTED NEXT).
  366. C
  367. 50 CALL DQPSRT(LIMIT,LAST,MAXERR,ERRMAX,ELIST,IORD,NRMAX)
  368. C ***JUMP OUT OF DO-LOOP
  369. IF (IER.NE.0.OR.ERRSUM.LE.ERRBND) GO TO 70
  370. 60 CONTINUE
  371. C
  372. C COMPUTE FINAL RESULT.
  373. C ---------------------
  374. C
  375. 70 RESULT = 0.0D+00
  376. DO 80 K=1,LAST
  377. RESULT = RESULT+RLIST(K)
  378. 80 CONTINUE
  379. ABSERR = ERRSUM
  380. 999 RETURN
  381. END