qagpe.f 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. *DECK QAGPE
  2. SUBROUTINE QAGPE (F, A, B, NPTS2, POINTS, EPSABS, EPSREL, LIMIT,
  3. + RESULT, ABSERR, NEVAL, IER, ALIST, BLIST, RLIST, ELIST, PTS,
  4. + IORD, LEVEL, NDIN, LAST)
  5. C***BEGIN PROLOGUE QAGPE
  6. C***PURPOSE Approximate a given definite integral I = Integral of F
  7. C over (A,B), hopefully satisfying the accuracy claim:
  8. C ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I)).
  9. C Break points of the integration interval, where local
  10. C difficulties of the integrand may occur (e.g. singularities
  11. C or discontinuities) are provided by the user.
  12. C***LIBRARY SLATEC (QUADPACK)
  13. C***CATEGORY H2A2A1
  14. C***TYPE SINGLE PRECISION (QAGPE-S, DQAGPE-D)
  15. C***KEYWORDS AUTOMATIC INTEGRATOR, EXTRAPOLATION, GENERAL-PURPOSE,
  16. C GLOBALLY ADAPTIVE, QUADPACK, QUADRATURE,
  17. C SINGULARITIES AT USER SPECIFIED POINTS
  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 Computation of a definite integral
  27. C Standard fortran subroutine
  28. C Real version
  29. C
  30. C PARAMETERS
  31. C ON ENTRY
  32. C F - Real
  33. C Function subprogram defining the integrand
  34. C function F(X). The actual name for F needs to be
  35. C declared E X T E R N A L in the driver program.
  36. C
  37. C A - Real
  38. C Lower limit of integration
  39. C
  40. C B - Real
  41. C Upper limit of integration
  42. C
  43. C NPTS2 - Integer
  44. C Number equal to two more than the number of
  45. C user-supplied break points within the integration
  46. C range, NPTS2.GE.2.
  47. C If NPTS2.LT.2, the routine will end with IER = 6.
  48. C
  49. C POINTS - Real
  50. C Vector of dimension NPTS2, the first (NPTS2-2)
  51. C elements of which are the user provided break
  52. C POINTS. If these POINTS do not constitute an
  53. C ascending sequence there will be an automatic
  54. C sorting.
  55. C
  56. C EPSABS - Real
  57. C Absolute accuracy requested
  58. C EPSREL - Real
  59. C Relative accuracy requested
  60. C If EPSABS.LE.0
  61. C and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
  62. C the routine will end with IER = 6.
  63. C
  64. C LIMIT - Integer
  65. C Gives an upper bound on the number of subintervals
  66. C in the partition of (A,B), LIMIT.GE.NPTS2
  67. C If LIMIT.LT.NPTS2, the routine will end with
  68. C IER = 6.
  69. C
  70. C ON RETURN
  71. C RESULT - Real
  72. C Approximation to the integral
  73. C
  74. C ABSERR - Real
  75. C Estimate of the modulus of the absolute error,
  76. C which should equal or exceed ABS(I-RESULT)
  77. C
  78. C NEVAL - Integer
  79. C Number of integrand evaluations
  80. C
  81. C IER - Integer
  82. C IER = 0 Normal and reliable termination of the
  83. C routine. It is assumed that the requested
  84. C accuracy has been achieved.
  85. C IER.GT.0 Abnormal termination of the routine.
  86. C The estimates for integral and error are
  87. C less reliable. It is assumed that the
  88. C requested accuracy has not been achieved.
  89. C ERROR MESSAGES
  90. C IER = 1 Maximum number of subdivisions allowed
  91. C has been achieved. One can allow more
  92. C subdivisions by increasing the value of
  93. C LIMIT (and taking the according dimension
  94. C adjustments into account). However, if
  95. C this yields no improvement it is advised
  96. C to analyze the integrand in order to
  97. C determine the integration difficulties. If
  98. C the position of a local difficulty can be
  99. C determined (i.e. SINGULARITY,
  100. C DISCONTINUITY within the interval), it
  101. C should be supplied to the routine as an
  102. C element of the vector points. If necessary
  103. C an appropriate special-purpose integrator
  104. C must be used, which is designed for
  105. C handling the type of difficulty involved.
  106. C = 2 The occurrence of roundoff error is
  107. C detected, which prevents the requested
  108. C tolerance from being achieved.
  109. C The error may be under-estimated.
  110. C = 3 Extremely bad integrand behaviour occurs
  111. C At some points of the integration
  112. C interval.
  113. C = 4 The algorithm does not converge.
  114. C Roundoff error is detected in the
  115. C extrapolation table. It is presumed that
  116. C the requested tolerance cannot be
  117. C achieved, and that the returned result is
  118. C the best which can be obtained.
  119. C = 5 The integral is probably divergent, or
  120. C slowly convergent. It must be noted that
  121. C divergence can occur with any other value
  122. C of IER.GT.0.
  123. C = 6 The input is invalid because
  124. C NPTS2.LT.2 or
  125. C Break points are specified outside
  126. C the integration range or
  127. C (EPSABS.LE.0 and
  128. C EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28))
  129. C or LIMIT.LT.NPTS2.
  130. C RESULT, ABSERR, NEVAL, LAST, RLIST(1),
  131. C and ELIST(1) are set to zero. ALIST(1) and
  132. C BLIST(1) are set to A and B respectively.
  133. C
  134. C ALIST - Real
  135. C Vector of dimension at least LIMIT, the first
  136. C LAST elements of which are the left end points
  137. C of the subintervals in the partition of the given
  138. C integration range (A,B)
  139. C
  140. C BLIST - Real
  141. C Vector of dimension at least LIMIT, the first
  142. C LAST elements of which are the right end points
  143. C of the subintervals in the partition of the given
  144. C integration range (A,B)
  145. C
  146. C RLIST - Real
  147. C Vector of dimension at least LIMIT, the first
  148. C LAST elements of which are the integral
  149. C approximations on the subintervals
  150. C
  151. C ELIST - Real
  152. C Vector of dimension at least LIMIT, the first
  153. C LAST elements of which are the moduli of the
  154. C absolute error estimates on the subintervals
  155. C
  156. C PTS - Real
  157. C Vector of dimension at least NPTS2, containing the
  158. C integration limits and the break points of the
  159. C interval in ascending sequence.
  160. C
  161. C LEVEL - Integer
  162. C Vector of dimension at least LIMIT, containing the
  163. C subdivision levels of the subinterval, i.e. if
  164. C (AA,BB) is a subinterval of (P1,P2) where P1 as
  165. C well as P2 is a user-provided break point or
  166. C integration limit, then (AA,BB) has level L if
  167. C ABS(BB-AA) = ABS(P2-P1)*2**(-L).
  168. C
  169. C NDIN - Integer
  170. C Vector of dimension at least NPTS2, after first
  171. C integration over the intervals (PTS(I)),PTS(I+1),
  172. C I = 0,1, ..., NPTS2-2, the error estimates over
  173. C some of the intervals may have been increased
  174. C artificially, in order to put their subdivision
  175. C forward. If this happens for the subinterval
  176. C numbered K, NDIN(K) is put to 1, otherwise
  177. C NDIN(K) = 0.
  178. C
  179. C IORD - Integer
  180. C Vector of dimension at least LIMIT, the first K
  181. C elements of which are pointers to the
  182. C error estimates over the subintervals,
  183. C such that ELIST(IORD(1)), ..., ELIST(IORD(K))
  184. C form a decreasing sequence, with K = LAST
  185. C If LAST.LE.(LIMIT/2+2), and K = LIMIT+1-LAST
  186. C otherwise
  187. C
  188. C LAST - Integer
  189. C Number of subintervals actually produced in the
  190. C subdivisions process
  191. C
  192. C***REFERENCES (NONE)
  193. C***ROUTINES CALLED QELG, QK21, QPSRT, R1MACH
  194. C***REVISION HISTORY (YYMMDD)
  195. C 800101 DATE WRITTEN
  196. C 890531 Changed all specific intrinsics to generic. (WRB)
  197. C 890831 Modified array declarations. (WRB)
  198. C 890831 REVISION DATE from Version 3.2
  199. C 891214 Prologue converted to Version 4.0 format. (BAB)
  200. C***END PROLOGUE QAGPE
  201. REAL A,ABSEPS,ABSERR,ALIST,AREA,AREA1,AREA12,AREA2,A1,
  202. 1 A2,B,BLIST,B1,B2,CORREC,DEFABS,DEFAB1,DEFAB2,
  203. 2 DRES,R1MACH,ELIST,EPMACH,EPSABS,EPSREL,ERLARG,ERLAST,ERRBND,
  204. 3 ERRMAX,ERROR1,ERRO12,ERROR2,ERRSUM,ERTEST,F,OFLOW,POINTS,PTS,
  205. 4 RESA,RESABS,RESEPS,RESULT,RES3LA,RLIST,RLIST2,SIGN,TEMP,
  206. 5 UFLOW
  207. INTEGER I,ID,IER,IERRO,IND1,IND2,IORD,IP1,IROFF1,IROFF2,
  208. 1 IROFF3,J,JLOW,JUPBND,K,KSGN,KTMIN,LAST,LEVCUR,LEVEL,LEVMAX,
  209. 2 LIMIT,MAXERR,NDIN,NEVAL,NINT,NINTP1,NPTS,NPTS2,NRES,
  210. 3 NRMAX,NUMRL2
  211. LOGICAL EXTRAP,NOEXT
  212. C
  213. C
  214. DIMENSION ALIST(*),BLIST(*),ELIST(*),IORD(*),
  215. 1 LEVEL(*),NDIN(*),POINTS(*),PTS(*),RES3LA(3),
  216. 2 RLIST(*),RLIST2(52)
  217. C
  218. EXTERNAL F
  219. C
  220. C THE DIMENSION OF RLIST2 IS DETERMINED BY THE VALUE OF
  221. C LIMEXP IN SUBROUTINE EPSALG (RLIST2 SHOULD BE OF DIMENSION
  222. C (LIMEXP+2) AT LEAST).
  223. C
  224. C
  225. C LIST OF MAJOR VARIABLES
  226. C -----------------------
  227. C
  228. C ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
  229. C CONSIDERED UP TO NOW
  230. C BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
  231. C CONSIDERED UP TO NOW
  232. C RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER
  233. C (ALIST(I),BLIST(I))
  234. C RLIST2 - ARRAY OF DIMENSION AT LEAST LIMEXP+2
  235. C CONTAINING THE PART OF THE EPSILON TABLE WHICH
  236. C IS STILL NEEDED FOR FURTHER COMPUTATIONS
  237. C ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)
  238. C MAXERR - POINTER TO THE INTERVAL WITH LARGEST ERROR
  239. C ESTIMATE
  240. C ERRMAX - ELIST(MAXERR)
  241. C ERLAST - ERROR ON THE INTERVAL CURRENTLY SUBDIVIDED
  242. C (BEFORE THAT SUBDIVISION HAS TAKEN PLACE)
  243. C AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
  244. C ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS
  245. C ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
  246. C ABS(RESULT))
  247. C *****1 - VARIABLE FOR THE LEFT SUBINTERVAL
  248. C *****2 - VARIABLE FOR THE RIGHT SUBINTERVAL
  249. C LAST - INDEX FOR SUBDIVISION
  250. C NRES - NUMBER OF CALLS TO THE EXTRAPOLATION ROUTINE
  251. C NUMRL2 - NUMBER OF ELEMENTS IN RLIST2. IF AN
  252. C APPROPRIATE APPROXIMATION TO THE COMPOUNDED
  253. C INTEGRAL HAS BEEN OBTAINED, IT IS PUT IN
  254. C RLIST2(NUMRL2) AFTER NUMRL2 HAS BEEN INCREASED
  255. C BY ONE.
  256. C ERLARG - SUM OF THE ERRORS OVER THE INTERVALS LARGER
  257. C THAN THE SMALLEST INTERVAL CONSIDERED UP TO NOW
  258. C EXTRAP - LOGICAL VARIABLE DENOTING THAT THE ROUTINE
  259. C IS ATTEMPTING TO PERFORM EXTRAPOLATION. I.E.
  260. C BEFORE SUBDIVIDING THE SMALLEST INTERVAL WE
  261. C TRY TO DECREASE THE VALUE OF ERLARG.
  262. C NOEXT - LOGICAL VARIABLE DENOTING THAT EXTRAPOLATION IS
  263. C NO LONGER ALLOWED (TRUE-VALUE)
  264. C
  265. C MACHINE DEPENDENT CONSTANTS
  266. C ---------------------------
  267. C
  268. C EPMACH IS THE LARGEST RELATIVE SPACING.
  269. C UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
  270. C OFLOW IS THE LARGEST POSITIVE MAGNITUDE.
  271. C
  272. C***FIRST EXECUTABLE STATEMENT QAGPE
  273. EPMACH = R1MACH(4)
  274. C
  275. C TEST ON VALIDITY OF PARAMETERS
  276. C -----------------------------
  277. C
  278. IER = 0
  279. NEVAL = 0
  280. LAST = 0
  281. RESULT = 0.0E+00
  282. ABSERR = 0.0E+00
  283. ALIST(1) = A
  284. BLIST(1) = B
  285. RLIST(1) = 0.0E+00
  286. ELIST(1) = 0.0E+00
  287. IORD(1) = 0
  288. LEVEL(1) = 0
  289. NPTS = NPTS2-2
  290. IF(NPTS2.LT.2.OR.LIMIT.LE.NPTS.OR.(EPSABS.LE.0.0E+00.AND.
  291. 1 EPSREL.LT.MAX(0.5E+02*EPMACH,0.5E-14))) IER = 6
  292. IF(IER.EQ.6) GO TO 999
  293. C
  294. C IF ANY BREAK POINTS ARE PROVIDED, SORT THEM INTO AN
  295. C ASCENDING SEQUENCE.
  296. C
  297. SIGN = 1.0E+00
  298. IF(A.GT.B) SIGN = -1.0E+00
  299. PTS(1) = MIN(A,B)
  300. IF(NPTS.EQ.0) GO TO 15
  301. DO 10 I = 1,NPTS
  302. PTS(I+1) = POINTS(I)
  303. 10 CONTINUE
  304. 15 PTS(NPTS+2) = MAX(A,B)
  305. NINT = NPTS+1
  306. A1 = PTS(1)
  307. IF(NPTS.EQ.0) GO TO 40
  308. NINTP1 = NINT+1
  309. DO 20 I = 1,NINT
  310. IP1 = I+1
  311. DO 20 J = IP1,NINTP1
  312. IF(PTS(I).LE.PTS(J)) GO TO 20
  313. TEMP = PTS(I)
  314. PTS(I) = PTS(J)
  315. PTS(J) = TEMP
  316. 20 CONTINUE
  317. IF(PTS(1).NE.MIN(A,B).OR.PTS(NINTP1).NE.
  318. 1 MAX(A,B)) IER = 6
  319. IF(IER.EQ.6) GO TO 999
  320. C
  321. C COMPUTE FIRST INTEGRAL AND ERROR APPROXIMATIONS.
  322. C ------------------------------------------------
  323. C
  324. 40 RESABS = 0.0E+00
  325. DO 50 I = 1,NINT
  326. B1 = PTS(I+1)
  327. CALL QK21(F,A1,B1,AREA1,ERROR1,DEFABS,RESA)
  328. ABSERR = ABSERR+ERROR1
  329. RESULT = RESULT+AREA1
  330. NDIN(I) = 0
  331. IF(ERROR1.EQ.RESA.AND.ERROR1.NE.0.0E+00) NDIN(I) = 1
  332. RESABS = RESABS+DEFABS
  333. LEVEL(I) = 0
  334. ELIST(I) = ERROR1
  335. ALIST(I) = A1
  336. BLIST(I) = B1
  337. RLIST(I) = AREA1
  338. IORD(I) = I
  339. A1 = B1
  340. 50 CONTINUE
  341. ERRSUM = 0.0E+00
  342. DO 55 I = 1,NINT
  343. IF(NDIN(I).EQ.1) ELIST(I) = ABSERR
  344. ERRSUM = ERRSUM+ELIST(I)
  345. 55 CONTINUE
  346. C
  347. C TEST ON ACCURACY.
  348. C
  349. LAST = NINT
  350. NEVAL = 21*NINT
  351. DRES = ABS(RESULT)
  352. ERRBND = MAX(EPSABS,EPSREL*DRES)
  353. IF(ABSERR.LE.0.1E+03*EPMACH*RESABS.AND.ABSERR.GT.
  354. 1 ERRBND) IER = 2
  355. IF(NINT.EQ.1) GO TO 80
  356. DO 70 I = 1,NPTS
  357. JLOW = I+1
  358. IND1 = IORD(I)
  359. DO 60 J = JLOW,NINT
  360. IND2 = IORD(J)
  361. IF(ELIST(IND1).GT.ELIST(IND2)) GO TO 60
  362. IND1 = IND2
  363. K = J
  364. 60 CONTINUE
  365. IF(IND1.EQ.IORD(I)) GO TO 70
  366. IORD(K) = IORD(I)
  367. IORD(I) = IND1
  368. 70 CONTINUE
  369. IF(LIMIT.LT.NPTS2) IER = 1
  370. 80 IF(IER.NE.0.OR.ABSERR.LE.ERRBND) GO TO 999
  371. C
  372. C INITIALIZATION
  373. C --------------
  374. C
  375. RLIST2(1) = RESULT
  376. MAXERR = IORD(1)
  377. ERRMAX = ELIST(MAXERR)
  378. AREA = RESULT
  379. NRMAX = 1
  380. NRES = 0
  381. NUMRL2 = 1
  382. KTMIN = 0
  383. EXTRAP = .FALSE.
  384. NOEXT = .FALSE.
  385. ERLARG = ERRSUM
  386. ERTEST = ERRBND
  387. LEVMAX = 1
  388. IROFF1 = 0
  389. IROFF2 = 0
  390. IROFF3 = 0
  391. IERRO = 0
  392. UFLOW = R1MACH(1)
  393. OFLOW = R1MACH(2)
  394. ABSERR = OFLOW
  395. KSGN = -1
  396. IF(DRES.GE.(0.1E+01-0.5E+02*EPMACH)*RESABS) KSGN = 1
  397. C
  398. C MAIN DO-LOOP
  399. C ------------
  400. C
  401. DO 160 LAST = NPTS2,LIMIT
  402. C
  403. C BISECT THE SUBINTERVAL WITH THE NRMAX-TH LARGEST
  404. C ERROR ESTIMATE.
  405. C
  406. LEVCUR = LEVEL(MAXERR)+1
  407. A1 = ALIST(MAXERR)
  408. B1 = 0.5E+00*(ALIST(MAXERR)+BLIST(MAXERR))
  409. A2 = B1
  410. B2 = BLIST(MAXERR)
  411. ERLAST = ERRMAX
  412. CALL QK21(F,A1,B1,AREA1,ERROR1,RESA,DEFAB1)
  413. CALL QK21(F,A2,B2,AREA2,ERROR2,RESA,DEFAB2)
  414. C
  415. C IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL
  416. C AND ERROR AND TEST FOR ACCURACY.
  417. C
  418. NEVAL = NEVAL+42
  419. AREA12 = AREA1+AREA2
  420. ERRO12 = ERROR1+ERROR2
  421. ERRSUM = ERRSUM+ERRO12-ERRMAX
  422. AREA = AREA+AREA12-RLIST(MAXERR)
  423. IF(DEFAB1.EQ.ERROR1.OR.DEFAB2.EQ.ERROR2) GO TO 95
  424. IF(ABS(RLIST(MAXERR)-AREA12).GT.0.1E-04*ABS(AREA12)
  425. 1 .OR.ERRO12.LT.0.99E+00*ERRMAX) GO TO 90
  426. IF(EXTRAP) IROFF2 = IROFF2+1
  427. IF(.NOT.EXTRAP) IROFF1 = IROFF1+1
  428. 90 IF(LAST.GT.10.AND.ERRO12.GT.ERRMAX) IROFF3 = IROFF3+1
  429. 95 LEVEL(MAXERR) = LEVCUR
  430. LEVEL(LAST) = LEVCUR
  431. RLIST(MAXERR) = AREA1
  432. RLIST(LAST) = AREA2
  433. ERRBND = MAX(EPSABS,EPSREL*ABS(AREA))
  434. C
  435. C TEST FOR ROUNDOFF ERROR AND EVENTUALLY
  436. C SET ERROR FLAG.
  437. C
  438. IF(IROFF1+IROFF2.GE.10.OR.IROFF3.GE.20) IER = 2
  439. IF(IROFF2.GE.5) IERRO = 3
  440. C
  441. C SET ERROR FLAG IN THE CASE THAT THE NUMBER OF
  442. C SUBINTERVALS EQUALS LIMIT.
  443. C
  444. IF(LAST.EQ.LIMIT) IER = 1
  445. C
  446. C SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
  447. C AT A POINT OF THE INTEGRATION RANGE
  448. C
  449. IF(MAX(ABS(A1),ABS(B2)).LE.(0.1E+01+0.1E+03*EPMACH)*
  450. 1 (ABS(A2)+0.1E+04*UFLOW)) IER = 4
  451. C
  452. C APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
  453. C
  454. IF(ERROR2.GT.ERROR1) GO TO 100
  455. ALIST(LAST) = A2
  456. BLIST(MAXERR) = B1
  457. BLIST(LAST) = B2
  458. ELIST(MAXERR) = ERROR1
  459. ELIST(LAST) = ERROR2
  460. GO TO 110
  461. 100 ALIST(MAXERR) = A2
  462. ALIST(LAST) = A1
  463. BLIST(LAST) = B1
  464. RLIST(MAXERR) = AREA2
  465. RLIST(LAST) = AREA1
  466. ELIST(MAXERR) = ERROR2
  467. ELIST(LAST) = ERROR1
  468. C
  469. C CALL SUBROUTINE QPSRT TO MAINTAIN THE DESCENDING ORDERING
  470. C IN THE LIST OF ERROR ESTIMATES AND SELECT THE
  471. C SUBINTERVAL WITH NRMAX-TH LARGEST ERROR ESTIMATE (TO BE
  472. C BISECTED NEXT).
  473. C
  474. 110 CALL QPSRT(LIMIT,LAST,MAXERR,ERRMAX,ELIST,IORD,NRMAX)
  475. C ***JUMP OUT OF DO-LOOP
  476. IF(ERRSUM.LE.ERRBND) GO TO 190
  477. C ***JUMP OUT OF DO-LOOP
  478. IF(IER.NE.0) GO TO 170
  479. IF(NOEXT) GO TO 160
  480. ERLARG = ERLARG-ERLAST
  481. IF(LEVCUR+1.LE.LEVMAX) ERLARG = ERLARG+ERRO12
  482. IF(EXTRAP) GO TO 120
  483. C
  484. C TEST WHETHER THE INTERVAL TO BE BISECTED NEXT IS THE
  485. C SMALLEST INTERVAL.
  486. C
  487. IF(LEVEL(MAXERR)+1.LE.LEVMAX) GO TO 160
  488. EXTRAP = .TRUE.
  489. NRMAX = 2
  490. 120 IF(IERRO.EQ.3.OR.ERLARG.LE.ERTEST) GO TO 140
  491. C
  492. C THE SMALLEST INTERVAL HAS THE LARGEST ERROR.
  493. C BEFORE BISECTING DECREASE THE SUM OF THE ERRORS
  494. C OVER THE LARGER INTERVALS (ERLARG) AND PERFORM
  495. C EXTRAPOLATION.
  496. C
  497. ID = NRMAX
  498. JUPBND = LAST
  499. IF(LAST.GT.(2+LIMIT/2)) JUPBND = LIMIT+3-LAST
  500. DO 130 K = ID,JUPBND
  501. MAXERR = IORD(NRMAX)
  502. ERRMAX = ELIST(MAXERR)
  503. C ***JUMP OUT OF DO-LOOP
  504. IF(LEVEL(MAXERR)+1.LE.LEVMAX) GO TO 160
  505. NRMAX = NRMAX+1
  506. 130 CONTINUE
  507. C
  508. C PERFORM EXTRAPOLATION.
  509. C
  510. 140 NUMRL2 = NUMRL2+1
  511. RLIST2(NUMRL2) = AREA
  512. IF(NUMRL2.LE.2) GO TO 155
  513. CALL QELG(NUMRL2,RLIST2,RESEPS,ABSEPS,RES3LA,NRES)
  514. KTMIN = KTMIN+1
  515. IF(KTMIN.GT.5.AND.ABSERR.LT.0.1E-02*ERRSUM) IER = 5
  516. IF(ABSEPS.GE.ABSERR) GO TO 150
  517. KTMIN = 0
  518. ABSERR = ABSEPS
  519. RESULT = RESEPS
  520. CORREC = ERLARG
  521. ERTEST = MAX(EPSABS,EPSREL*ABS(RESEPS))
  522. C ***JUMP OUT OF DO-LOOP
  523. IF(ABSERR.LT.ERTEST) GO TO 170
  524. C
  525. C PREPARE BISECTION OF THE SMALLEST INTERVAL.
  526. C
  527. 150 IF(NUMRL2.EQ.1) NOEXT = .TRUE.
  528. IF(IER.GE.5) GO TO 170
  529. 155 MAXERR = IORD(1)
  530. ERRMAX = ELIST(MAXERR)
  531. NRMAX = 1
  532. EXTRAP = .FALSE.
  533. LEVMAX = LEVMAX+1
  534. ERLARG = ERRSUM
  535. 160 CONTINUE
  536. C
  537. C SET THE FINAL RESULT.
  538. C ---------------------
  539. C
  540. C
  541. 170 IF(ABSERR.EQ.OFLOW) GO TO 190
  542. IF((IER+IERRO).EQ.0) GO TO 180
  543. IF(IERRO.EQ.3) ABSERR = ABSERR+CORREC
  544. IF(IER.EQ.0) IER = 3
  545. IF(RESULT.NE.0.0E+00.AND.AREA.NE.0.0E+00)GO TO 175
  546. IF(ABSERR.GT.ERRSUM)GO TO 190
  547. IF(AREA.EQ.0.0E+00) GO TO 210
  548. GO TO 180
  549. 175 IF(ABSERR/ABS(RESULT).GT.ERRSUM/ABS(AREA))GO TO 190
  550. C
  551. C TEST ON DIVERGENCE.
  552. C
  553. 180 IF(KSGN.EQ.(-1).AND.MAX(ABS(RESULT),ABS(AREA)).LE.
  554. 1 DEFABS*0.1E-01) GO TO 210
  555. IF(0.1E-01.GT.(RESULT/AREA).OR.(RESULT/AREA).GT.0.1E+03.OR.
  556. 1 ERRSUM.GT.ABS(AREA)) IER = 6
  557. GO TO 210
  558. C
  559. C COMPUTE GLOBAL INTEGRAL SUM.
  560. C
  561. 190 RESULT = 0.0E+00
  562. DO 200 K = 1,LAST
  563. RESULT = RESULT+RLIST(K)
  564. 200 CONTINUE
  565. ABSERR = ERRSUM
  566. 210 IF(IER.GT.2) IER = IER - 1
  567. RESULT = RESULT*SIGN
  568. 999 RETURN
  569. END