Remove commented out operators property
[maxima.git] / src / numerical / slatec / fortran / dqagse.f
blobbd1244fc1513cd24550615869dd2f89910220796
1 *DECK DQAGSE
2 SUBROUTINE DQAGSE (F, A, B, EPSABS, EPSREL, LIMIT, RESULT, ABSERR,
3 + NEVAL, IER, ALIST, BLIST, RLIST, ELIST, IORD, LAST)
4 C***BEGIN PROLOGUE DQAGSE
5 C***PURPOSE The routine calculates an approximation result to a given
6 C definite integral I = Integral of F over (A,B),
7 C hopefully satisfying following claim for accuracy
8 C ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I)).
9 C***LIBRARY SLATEC (QUADPACK)
10 C***CATEGORY H2A1A1
11 C***TYPE DOUBLE PRECISION (QAGSE-S, DQAGSE-D)
12 C***KEYWORDS AUTOMATIC INTEGRATOR, END POINT SINGULARITIES,
13 C EXTRAPOLATION, GENERAL-PURPOSE, GLOBALLY ADAPTIVE,
14 C QUADPACK, QUADRATURE
15 C***AUTHOR Piessens, Robert
16 C Applied Mathematics and Programming Division
17 C K. U. Leuven
18 C de Doncker, Elise
19 C Applied Mathematics and Programming Division
20 C K. U. Leuven
21 C***DESCRIPTION
23 C Computation of a definite integral
24 C Standard fortran subroutine
25 C Double precision version
27 C PARAMETERS
28 C ON ENTRY
29 C F - Double precision
30 C Function subprogram defining the integrand
31 C function F(X). The actual name for F needs to be
32 C declared E X T E R N A L in the driver program.
34 C A - Double precision
35 C Lower limit of integration
37 C B - Double precision
38 C Upper limit of integration
40 C EPSABS - Double precision
41 C Absolute accuracy requested
42 C EPSREL - Double precision
43 C Relative accuracy requested
44 C If EPSABS.LE.0
45 C and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
46 C the routine will end with IER = 6.
48 C LIMIT - Integer
49 C Gives an upper bound on the number of subintervals
50 C in the partition of (A,B)
52 C ON RETURN
53 C RESULT - Double precision
54 C Approximation to the integral
56 C ABSERR - Double precision
57 C Estimate of the modulus of the absolute error,
58 C which should equal or exceed ABS(I-RESULT)
60 C NEVAL - Integer
61 C Number of integrand evaluations
63 C IER - Integer
64 C IER = 0 Normal and reliable termination of the
65 C routine. It is assumed that the requested
66 C accuracy has been achieved.
67 C IER.GT.0 Abnormal termination of the routine
68 C the estimates for integral and error are
69 C less reliable. It is assumed that the
70 C requested accuracy has not been achieved.
71 C ERROR MESSAGES
72 C = 1 Maximum number of subdivisions allowed
73 C has been achieved. One can allow more sub-
74 C divisions by increasing the value of LIMIT
75 C (and taking the according dimension
76 C adjustments into account). However, if
77 C this yields no improvement it is advised
78 C to analyze the integrand in order to
79 C determine the integration difficulties. If
80 C the position of a local difficulty can be
81 C determined (e.g. singularity,
82 C discontinuity within the interval) one
83 C will probably gain from splitting up the
84 C interval at this point and calling the
85 C integrator on the subranges. If possible,
86 C an appropriate special-purpose integrator
87 C should be used, which is designed for
88 C handling the type of difficulty involved.
89 C = 2 The occurrence of roundoff error is detec-
90 C ted, which prevents the requested
91 C tolerance from being achieved.
92 C The error may be under-estimated.
93 C = 3 Extremely bad integrand behaviour
94 C occurs at some points of the integration
95 C interval.
96 C = 4 The algorithm does not converge.
97 C Roundoff error is detected in the
98 C extrapolation table.
99 C It is presumed that the requested
100 C tolerance cannot be achieved, and that the
101 C returned result is the best which can be
102 C obtained.
103 C = 5 The integral is probably divergent, or
104 C slowly convergent. It must be noted that
105 C divergence can occur with any other value
106 C of IER.
107 C = 6 The input is invalid, because
108 C EPSABS.LE.0 and
109 C EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28).
110 C RESULT, ABSERR, NEVAL, LAST, RLIST(1),
111 C IORD(1) and ELIST(1) are set to zero.
112 C ALIST(1) and BLIST(1) are set to A and B
113 C respectively.
115 C ALIST - Double precision
116 C Vector of dimension at least LIMIT, the first
117 C LAST elements of which are the left end points
118 C of the subintervals in the partition of the
119 C given integration range (A,B)
121 C BLIST - Double precision
122 C Vector of dimension at least LIMIT, the first
123 C LAST elements of which are the right end points
124 C of the subintervals in the partition of the given
125 C integration range (A,B)
127 C RLIST - Double precision
128 C Vector of dimension at least LIMIT, the first
129 C LAST elements of which are the integral
130 C approximations on the subintervals
132 C ELIST - Double precision
133 C Vector of dimension at least LIMIT, the first
134 C LAST elements of which are the moduli of the
135 C absolute error estimates on the subintervals
137 C IORD - Integer
138 C Vector of dimension at least LIMIT, the first K
139 C elements of which are pointers to the
140 C error estimates over the subintervals,
141 C such that ELIST(IORD(1)), ..., ELIST(IORD(K))
142 C form a decreasing sequence, with K = LAST
143 C If LAST.LE.(LIMIT/2+2), and K = LIMIT+1-LAST
144 C otherwise
146 C LAST - Integer
147 C Number of subintervals actually produced in the
148 C subdivision process
150 C***REFERENCES (NONE)
151 C***ROUTINES CALLED D1MACH, DQELG, DQK21, DQPSRT
152 C***REVISION HISTORY (YYMMDD)
153 C 800101 DATE WRITTEN
154 C 890531 Changed all specific intrinsics to generic. (WRB)
155 C 890831 Modified array declarations. (WRB)
156 C 890831 REVISION DATE from Version 3.2
157 C 891214 Prologue converted to Version 4.0 format. (BAB)
158 C***END PROLOGUE DQAGSE
160 DOUBLE PRECISION A,ABSEPS,ABSERR,ALIST,AREA,AREA1,AREA12,AREA2,A1,
161 1 A2,B,BLIST,B1,B2,CORREC,DEFABS,DEFAB1,DEFAB2,D1MACH,
162 2 DRES,ELIST,EPMACH,EPSABS,EPSREL,ERLARG,ERLAST,ERRBND,ERRMAX,
163 3 ERROR1,ERROR2,ERRO12,ERRSUM,ERTEST,F,OFLOW,RESABS,RESEPS,RESULT,
164 4 RES3LA,RLIST,RLIST2,SMALL,UFLOW
165 INTEGER ID,IER,IERRO,IORD,IROFF1,IROFF2,IROFF3,JUPBND,K,KSGN,
166 1 KTMIN,LAST,LIMIT,MAXERR,NEVAL,NRES,NRMAX,NUMRL2
167 LOGICAL EXTRAP,NOEXT
169 DIMENSION ALIST(*),BLIST(*),ELIST(*),IORD(*),
170 1 RES3LA(3),RLIST(*),RLIST2(52)
172 EXTERNAL F
174 C THE DIMENSION OF RLIST2 IS DETERMINED BY THE VALUE OF
175 C LIMEXP IN SUBROUTINE DQELG (RLIST2 SHOULD BE OF DIMENSION
176 C (LIMEXP+2) AT LEAST).
178 C LIST OF MAJOR VARIABLES
179 C -----------------------
181 C ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
182 C CONSIDERED UP TO NOW
183 C BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
184 C CONSIDERED UP TO NOW
185 C RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER
186 C (ALIST(I),BLIST(I))
187 C RLIST2 - ARRAY OF DIMENSION AT LEAST LIMEXP+2 CONTAINING
188 C THE PART OF THE EPSILON TABLE WHICH IS STILL
189 C NEEDED FOR FURTHER COMPUTATIONS
190 C ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)
191 C MAXERR - POINTER TO THE INTERVAL WITH LARGEST ERROR
192 C ESTIMATE
193 C ERRMAX - ELIST(MAXERR)
194 C ERLAST - ERROR ON THE INTERVAL CURRENTLY SUBDIVIDED
195 C (BEFORE THAT SUBDIVISION HAS TAKEN PLACE)
196 C AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
197 C ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS
198 C ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
199 C ABS(RESULT))
200 C *****1 - VARIABLE FOR THE LEFT INTERVAL
201 C *****2 - VARIABLE FOR THE RIGHT INTERVAL
202 C LAST - INDEX FOR SUBDIVISION
203 C NRES - NUMBER OF CALLS TO THE EXTRAPOLATION ROUTINE
204 C NUMRL2 - NUMBER OF ELEMENTS CURRENTLY IN RLIST2. IF AN
205 C APPROPRIATE APPROXIMATION TO THE COMPOUNDED
206 C INTEGRAL HAS BEEN OBTAINED IT IS PUT IN
207 C RLIST2(NUMRL2) AFTER NUMRL2 HAS BEEN INCREASED
208 C BY ONE.
209 C SMALL - LENGTH OF THE SMALLEST INTERVAL CONSIDERED UP
210 C TO NOW, MULTIPLIED BY 1.5
211 C ERLARG - SUM OF THE ERRORS OVER THE INTERVALS LARGER
212 C THAN THE SMALLEST INTERVAL CONSIDERED UP TO NOW
213 C EXTRAP - LOGICAL VARIABLE DENOTING THAT THE ROUTINE IS
214 C ATTEMPTING TO PERFORM EXTRAPOLATION I.E. BEFORE
215 C SUBDIVIDING THE SMALLEST INTERVAL WE TRY TO
216 C DECREASE THE VALUE OF ERLARG.
217 C NOEXT - LOGICAL VARIABLE DENOTING THAT EXTRAPOLATION
218 C IS NO LONGER ALLOWED (TRUE VALUE)
220 C MACHINE DEPENDENT CONSTANTS
221 C ---------------------------
223 C EPMACH IS THE LARGEST RELATIVE SPACING.
224 C UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
225 C OFLOW IS THE LARGEST POSITIVE MAGNITUDE.
227 C***FIRST EXECUTABLE STATEMENT DQAGSE
228 EPMACH = D1MACH(4)
230 C TEST ON VALIDITY OF PARAMETERS
231 C ------------------------------
232 IER = 0
233 NEVAL = 0
234 LAST = 0
235 RESULT = 0.0D+00
236 ABSERR = 0.0D+00
237 ALIST(1) = A
238 BLIST(1) = B
239 RLIST(1) = 0.0D+00
240 ELIST(1) = 0.0D+00
241 IF(EPSABS.LE.0.0D+00.AND.EPSREL.LT.MAX(0.5D+02*EPMACH,0.5D-28))
242 1 IER = 6
243 IF(IER.EQ.6) GO TO 999
245 C FIRST APPROXIMATION TO THE INTEGRAL
246 C -----------------------------------
248 UFLOW = D1MACH(1)
249 OFLOW = D1MACH(2)
250 IERRO = 0
251 CALL DQK21(F,A,B,RESULT,ABSERR,DEFABS,RESABS)
253 C TEST ON ACCURACY.
255 DRES = ABS(RESULT)
256 ERRBND = MAX(EPSABS,EPSREL*DRES)
257 LAST = 1
258 RLIST(1) = RESULT
259 ELIST(1) = ABSERR
260 IORD(1) = 1
261 IF(ABSERR.LE.1.0D+02*EPMACH*DEFABS.AND.ABSERR.GT.ERRBND) IER = 2
262 IF(LIMIT.EQ.1) IER = 1
263 IF(IER.NE.0.OR.(ABSERR.LE.ERRBND.AND.ABSERR.NE.RESABS).OR.
264 1 ABSERR.EQ.0.0D+00) GO TO 140
266 C INITIALIZATION
267 C --------------
269 RLIST2(1) = RESULT
270 ERRMAX = ABSERR
271 MAXERR = 1
272 AREA = RESULT
273 ERRSUM = ABSERR
274 ABSERR = OFLOW
275 NRMAX = 1
276 NRES = 0
277 NUMRL2 = 2
278 KTMIN = 0
279 EXTRAP = .FALSE.
280 NOEXT = .FALSE.
281 IROFF1 = 0
282 IROFF2 = 0
283 IROFF3 = 0
284 KSGN = -1
285 IF(DRES.GE.(0.1D+01-0.5D+02*EPMACH)*DEFABS) KSGN = 1
287 C MAIN DO-LOOP
288 C ------------
290 DO 90 LAST = 2,LIMIT
292 C BISECT THE SUBINTERVAL WITH THE NRMAX-TH LARGEST ERROR
293 C ESTIMATE.
295 A1 = ALIST(MAXERR)
296 B1 = 0.5D+00*(ALIST(MAXERR)+BLIST(MAXERR))
297 A2 = B1
298 B2 = BLIST(MAXERR)
299 ERLAST = ERRMAX
300 CALL DQK21(F,A1,B1,AREA1,ERROR1,RESABS,DEFAB1)
301 CALL DQK21(F,A2,B2,AREA2,ERROR2,RESABS,DEFAB2)
303 C IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL
304 C AND ERROR AND TEST FOR ACCURACY.
306 AREA12 = AREA1+AREA2
307 ERRO12 = ERROR1+ERROR2
308 ERRSUM = ERRSUM+ERRO12-ERRMAX
309 AREA = AREA+AREA12-RLIST(MAXERR)
310 IF(DEFAB1.EQ.ERROR1.OR.DEFAB2.EQ.ERROR2) GO TO 15
311 IF(ABS(RLIST(MAXERR)-AREA12).GT.0.1D-04*ABS(AREA12)
312 1 .OR.ERRO12.LT.0.99D+00*ERRMAX) GO TO 10
313 IF(EXTRAP) IROFF2 = IROFF2+1
314 IF(.NOT.EXTRAP) IROFF1 = IROFF1+1
315 10 IF(LAST.GT.10.AND.ERRO12.GT.ERRMAX) IROFF3 = IROFF3+1
316 15 RLIST(MAXERR) = AREA1
317 RLIST(LAST) = AREA2
318 ERRBND = MAX(EPSABS,EPSREL*ABS(AREA))
320 C TEST FOR ROUNDOFF ERROR AND EVENTUALLY SET ERROR FLAG.
322 IF(IROFF1+IROFF2.GE.10.OR.IROFF3.GE.20) IER = 2
323 IF(IROFF2.GE.5) IERRO = 3
325 C SET ERROR FLAG IN THE CASE THAT THE NUMBER OF SUBINTERVALS
326 C EQUALS LIMIT.
328 IF(LAST.EQ.LIMIT) IER = 1
330 C SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
331 C AT A POINT OF THE INTEGRATION RANGE.
333 IF(MAX(ABS(A1),ABS(B2)).LE.(0.1D+01+0.1D+03*EPMACH)*
334 1 (ABS(A2)+0.1D+04*UFLOW)) IER = 4
336 C APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
338 IF(ERROR2.GT.ERROR1) GO TO 20
339 ALIST(LAST) = A2
340 BLIST(MAXERR) = B1
341 BLIST(LAST) = B2
342 ELIST(MAXERR) = ERROR1
343 ELIST(LAST) = ERROR2
344 GO TO 30
345 20 ALIST(MAXERR) = A2
346 ALIST(LAST) = A1
347 BLIST(LAST) = B1
348 RLIST(MAXERR) = AREA2
349 RLIST(LAST) = AREA1
350 ELIST(MAXERR) = ERROR2
351 ELIST(LAST) = ERROR1
353 C CALL SUBROUTINE DQPSRT TO MAINTAIN THE DESCENDING ORDERING
354 C IN THE LIST OF ERROR ESTIMATES AND SELECT THE SUBINTERVAL
355 C WITH NRMAX-TH LARGEST ERROR ESTIMATE (TO BE BISECTED NEXT).
357 30 CALL DQPSRT(LIMIT,LAST,MAXERR,ERRMAX,ELIST,IORD,NRMAX)
358 C ***JUMP OUT OF DO-LOOP
359 IF(ERRSUM.LE.ERRBND) GO TO 115
360 C ***JUMP OUT OF DO-LOOP
361 IF(IER.NE.0) GO TO 100
362 IF(LAST.EQ.2) GO TO 80
363 IF(NOEXT) GO TO 90
364 ERLARG = ERLARG-ERLAST
365 IF(ABS(B1-A1).GT.SMALL) ERLARG = ERLARG+ERRO12
366 IF(EXTRAP) GO TO 40
368 C TEST WHETHER THE INTERVAL TO BE BISECTED NEXT IS THE
369 C SMALLEST INTERVAL.
371 IF(ABS(BLIST(MAXERR)-ALIST(MAXERR)).GT.SMALL) GO TO 90
372 EXTRAP = .TRUE.
373 NRMAX = 2
374 40 IF(IERRO.EQ.3.OR.ERLARG.LE.ERTEST) GO TO 60
376 C THE SMALLEST INTERVAL HAS THE LARGEST ERROR.
377 C BEFORE BISECTING DECREASE THE SUM OF THE ERRORS OVER THE
378 C LARGER INTERVALS (ERLARG) AND PERFORM EXTRAPOLATION.
380 ID = NRMAX
381 JUPBND = LAST
382 IF(LAST.GT.(2+LIMIT/2)) JUPBND = LIMIT+3-LAST
383 DO 50 K = ID,JUPBND
384 MAXERR = IORD(NRMAX)
385 ERRMAX = ELIST(MAXERR)
386 C ***JUMP OUT OF DO-LOOP
387 IF(ABS(BLIST(MAXERR)-ALIST(MAXERR)).GT.SMALL) GO TO 90
388 NRMAX = NRMAX+1
389 50 CONTINUE
391 C PERFORM EXTRAPOLATION.
393 60 NUMRL2 = NUMRL2+1
394 RLIST2(NUMRL2) = AREA
395 CALL DQELG(NUMRL2,RLIST2,RESEPS,ABSEPS,RES3LA,NRES)
396 KTMIN = KTMIN+1
397 IF(KTMIN.GT.5.AND.ABSERR.LT.0.1D-02*ERRSUM) IER = 5
398 IF(ABSEPS.GE.ABSERR) GO TO 70
399 KTMIN = 0
400 ABSERR = ABSEPS
401 RESULT = RESEPS
402 CORREC = ERLARG
403 ERTEST = MAX(EPSABS,EPSREL*ABS(RESEPS))
404 C ***JUMP OUT OF DO-LOOP
405 IF(ABSERR.LE.ERTEST) GO TO 100
407 C PREPARE BISECTION OF THE SMALLEST INTERVAL.
409 70 IF(NUMRL2.EQ.1) NOEXT = .TRUE.
410 IF(IER.EQ.5) GO TO 100
411 MAXERR = IORD(1)
412 ERRMAX = ELIST(MAXERR)
413 NRMAX = 1
414 EXTRAP = .FALSE.
415 SMALL = SMALL*0.5D+00
416 ERLARG = ERRSUM
417 GO TO 90
418 80 SMALL = ABS(B-A)*0.375D+00
419 ERLARG = ERRSUM
420 ERTEST = ERRBND
421 RLIST2(2) = AREA
422 90 CONTINUE
424 C SET FINAL RESULT AND ERROR ESTIMATE.
425 C ------------------------------------
427 100 IF(ABSERR.EQ.OFLOW) GO TO 115
428 IF(IER+IERRO.EQ.0) GO TO 110
429 IF(IERRO.EQ.3) ABSERR = ABSERR+CORREC
430 IF(IER.EQ.0) IER = 3
431 IF(RESULT.NE.0.0D+00.AND.AREA.NE.0.0D+00) GO TO 105
432 IF(ABSERR.GT.ERRSUM) GO TO 115
433 IF(AREA.EQ.0.0D+00) GO TO 130
434 GO TO 110
435 105 IF(ABSERR/ABS(RESULT).GT.ERRSUM/ABS(AREA)) GO TO 115
437 C TEST ON DIVERGENCE.
439 110 IF(KSGN.EQ.(-1).AND.MAX(ABS(RESULT),ABS(AREA)).LE.
440 1 DEFABS*0.1D-01) GO TO 130
441 IF(0.1D-01.GT.(RESULT/AREA).OR.(RESULT/AREA).GT.0.1D+03
442 1 .OR.ERRSUM.GT.ABS(AREA)) IER = 6
443 GO TO 130
445 C COMPUTE GLOBAL INTEGRAL SUM.
447 115 RESULT = 0.0D+00
448 DO 120 K = 1,LAST
449 RESULT = RESULT+RLIST(K)
450 120 CONTINUE
451 ABSERR = ERRSUM
452 130 IF(IER.GT.2) IER = IER-1
453 140 NEVAL = 42*LAST-21
454 999 RETURN