2 SUBROUTINE DQAWOE
(F
, A
, B
, OMEGA
, INTEGR
, EPSABS
, EPSREL
, LIMIT
,
3 + ICALL
, MAXP1
, RESULT
, ABSERR
, NEVAL
, IER
, LAST
, ALIST
, BLIST
,
4 + RLIST
, ELIST
, IORD
, NNLOG
, MOMCOM
, CHEBMO
)
5 C***BEGIN PROLOGUE DQAWOE
6 C***PURPOSE Calculate an approximation to a given definite integral
7 C I = Integral of F(X)*W(X) over (A,B), where
9 C or W(X)=SIN(OMEGA*X),
10 C hopefully satisfying the following claim for accuracy
11 C ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I)).
12 C***LIBRARY SLATEC (QUADPACK)
14 C***TYPE DOUBLE PRECISION (QAWOE-S, DQAWOE-D)
15 C***KEYWORDS AUTOMATIC INTEGRATOR, CLENSHAW-CURTIS METHOD,
16 C EXTRAPOLATION, GLOBALLY ADAPTIVE,
17 C INTEGRAND WITH OSCILLATORY COS OR SIN FACTOR, QUADPACK,
18 C QUADRATURE, SPECIAL-PURPOSE
19 C***AUTHOR Piessens, Robert
20 C Applied Mathematics and Programming Division
23 C Applied Mathematics and Programming Division
27 C Computation of Oscillatory integrals
28 C Standard fortran subroutine
29 C Double precision version
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.
38 C A - Double precision
39 C Lower limit of integration
41 C B - Double precision
42 C Upper limit of integration
44 C OMEGA - Double precision
45 C Parameter in the integrand weight function
48 C Indicates which of the WEIGHT functions is to be
50 C INTEGR = 1 W(X) = COS(OMEGA*X)
51 C INTEGR = 2 W(X) = SIN(OMEGA*X)
52 C If INTEGR.NE.1 and INTEGR.NE.2, the routine
53 C will end with IER = 6.
55 C EPSABS - Double precision
56 C Absolute accuracy requested
57 C EPSREL - Double precision
58 C Relative accuracy requested
60 C and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
61 C the routine will end with IER = 6.
64 C Gives an upper bound on the number of subdivisions
65 C in the partition of (A,B), LIMIT.GE.1.
68 C If DQAWOE is to be used only once, ICALL must
69 C be set to 1. Assume that during this call, the
70 C Chebyshev moments (for CLENSHAW-CURTIS integration
71 C of degree 24) have been computed for intervals of
72 C lengths (ABS(B-A))*2**(-L), L=0,1,2,...MOMCOM-1.
73 C If ICALL.GT.1 this means that DQAWOE has been
74 C called twice or more on intervals of the same
75 C length ABS(B-A). The Chebyshev moments already
76 C computed are then re-used in subsequent calls.
77 C If ICALL.LT.1, the routine will end with IER = 6.
80 C Gives an upper bound on the number of Chebyshev
81 C moments which can be stored, i.e. for the
82 C intervals of lengths ABS(B-A)*2**(-L),
83 C L=0,1, ..., MAXP1-2, MAXP1.GE.1.
84 C If MAXP1.LT.1, the routine will end with IER = 6.
87 C RESULT - Double precision
88 C Approximation to the integral
90 C ABSERR - Double precision
91 C Estimate of the modulus of the absolute error,
92 C which should equal or exceed ABS(I-RESULT)
95 C Number of integrand evaluations
98 C IER = 0 Normal and reliable termination of the
99 C routine. It is assumed that the
100 C requested accuracy has been achieved.
101 C - IER.GT.0 Abnormal termination of the routine.
102 C The estimates for integral and error are
103 C less reliable. It is assumed that the
104 C requested accuracy has not been achieved.
106 C IER = 1 Maximum number of subdivisions allowed
107 C has been achieved. One can allow more
108 C subdivisions by increasing the value of
109 C LIMIT (and taking according dimension
110 C adjustments into account). However, if
111 C this yields no improvement it is advised
112 C to analyze the integrand, in order to
113 C determine the integration difficulties.
114 C If the position of a local difficulty can
115 C be determined (e.g. SINGULARITY,
116 C DISCONTINUITY within the interval) one
117 C will probably gain from splitting up the
118 C interval at this point and calling the
119 C integrator on the subranges. If possible,
120 C an appropriate special-purpose integrator
121 C should be used which is designed for
122 C handling the type of difficulty involved.
123 C = 2 The occurrence of roundoff error is
124 C detected, which prevents the requested
125 C tolerance from being achieved.
126 C The error may be under-estimated.
127 C = 3 Extremely bad integrand behaviour occurs
128 C at some points of the integration
130 C = 4 The algorithm does not converge.
131 C Roundoff error is detected in the
132 C extrapolation table.
133 C It is presumed that the requested
134 C tolerance cannot be achieved due to
135 C roundoff in the extrapolation table,
136 C and that the returned result is the
137 C best which can be obtained.
138 C = 5 The integral is probably divergent, or
139 C slowly convergent. It must be noted that
140 C divergence can occur with any other value
142 C = 6 The input is invalid, because
144 C EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28))
145 C or (INTEGR.NE.1 and INTEGR.NE.2) or
146 C ICALL.LT.1 or MAXP1.LT.1.
147 C RESULT, ABSERR, NEVAL, LAST, RLIST(1),
148 C ELIST(1), IORD(1) and NNLOG(1) are set
149 C to ZERO. ALIST(1) and BLIST(1) are set
150 C to A and B respectively.
153 C On return, LAST equals the number of
154 C subintervals produces in the subdivision
155 C process, which determines the number of
156 C significant elements actually in the
158 C ALIST - Double precision
159 C Vector of dimension at least LIMIT, the first
160 C LAST elements of which are the left
161 C end points of the subintervals in the partition
162 C of the given integration range (A,B)
164 C BLIST - Double precision
165 C Vector of dimension at least LIMIT, the first
166 C LAST elements of which are the right
167 C end points of the subintervals in the partition
168 C of the given integration range (A,B)
170 C RLIST - Double precision
171 C Vector of dimension at least LIMIT, the first
172 C LAST elements of which are the integral
173 C approximations on the subintervals
175 C ELIST - Double precision
176 C Vector of dimension at least LIMIT, the first
177 C LAST elements of which are the moduli of the
178 C absolute error estimates on the subintervals
181 C Vector of dimension at least LIMIT, the first K
182 C elements of which are pointers to the error
183 C estimates over the subintervals,
184 C such that ELIST(IORD(1)), ...,
185 C ELIST(IORD(K)) form a decreasing sequence, with
186 C K = LAST if LAST.LE.(LIMIT/2+2), and
187 C K = LIMIT+1-LAST otherwise.
190 C Vector of dimension at least LIMIT, containing the
191 C subdivision levels of the subintervals, i.e.
192 C IWORK(I) = L means that the subinterval
193 C numbered I is of length ABS(B-A)*2**(1-L)
195 C ON ENTRY AND RETURN
197 C Indicating that the Chebyshev moments
198 C have been computed for intervals of lengths
199 C (ABS(B-A))*2**(-L), L=0,1,2, ..., MOMCOM-1,
202 C CHEBMO - Double precision
203 C Array of dimension (MAXP1,25) containing the
206 C***REFERENCES (NONE)
207 C***ROUTINES CALLED D1MACH, DQC25F, DQELG, DQPSRT
208 C***REVISION HISTORY (YYMMDD)
209 C 800101 DATE WRITTEN
210 C 890531 Changed all specific intrinsics to generic. (WRB)
211 C 890831 Modified array declarations. (WRB)
212 C 890831 REVISION DATE from Version 3.2
213 C 891214 Prologue converted to Version 4.0 format. (BAB)
214 C***END PROLOGUE DQAWOE
216 DOUBLE PRECISION A
,ABSEPS
,ABSERR
,ALIST
,AREA
,AREA1
,AREA12
,AREA2
,A1
,
217 1 A2
,B
,BLIST
,B1
,B2
,CHEBMO
,CORREC
,DEFAB1
,DEFAB2
,DEFABS
,
218 2 DOMEGA
,D1MACH
,DRES
,ELIST
,EPMACH
,EPSABS
,EPSREL
,ERLARG
,ERLAST
,
219 3 ERRBND
,ERRMAX
,ERROR1
,ERRO12
,ERROR2
,ERRSUM
,ERTEST
,F
,OFLOW
,
220 4 OMEGA
,RESABS
,RESEPS
,RESULT
,RES3LA
,RLIST
,RLIST2
,SMALL
,UFLOW
,WIDTH
221 INTEGER ICALL
,ID
,IER
,IERRO
,INTEGR
,IORD
,IROFF1
,IROFF2
,IROFF3
,
222 1 JUPBND
,K
,KSGN
,KTMIN
,LAST
,LIMIT
,MAXERR
,MAXP1
,MOMCOM
,NEV
,NEVAL
,
223 2 NNLOG
,NRES
,NRMAX
,NRMOM
,NUMRL2
224 LOGICAL EXTRAP
,NOEXT
,EXTALL
226 DIMENSION ALIST
(*),BLIST
(*),RLIST
(*),ELIST
(*),
227 1 IORD
(*),RLIST2
(52),RES3LA
(3),CHEBMO
(MAXP1
,25),NNLOG
(*)
231 C THE DIMENSION OF RLIST2 IS DETERMINED BY THE VALUE OF
232 C LIMEXP IN SUBROUTINE DQELG (RLIST2 SHOULD BE OF
233 C DIMENSION (LIMEXP+2) AT LEAST).
235 C LIST OF MAJOR VARIABLES
236 C -----------------------
238 C ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
239 C CONSIDERED UP TO NOW
240 C BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
241 C CONSIDERED UP TO NOW
242 C RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER
243 C (ALIST(I),BLIST(I))
244 C RLIST2 - ARRAY OF DIMENSION AT LEAST LIMEXP+2
245 C CONTAINING THE PART OF THE EPSILON TABLE
246 C WHICH IS STILL NEEDED FOR FURTHER COMPUTATIONS
247 C ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)
248 C MAXERR - POINTER TO THE INTERVAL WITH LARGEST
250 C ERRMAX - ELIST(MAXERR)
251 C ERLAST - ERROR ON THE INTERVAL CURRENTLY SUBDIVIDED
252 C AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
253 C ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS
254 C ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
256 C *****1 - VARIABLE FOR THE LEFT SUBINTERVAL
257 C *****2 - VARIABLE FOR THE RIGHT SUBINTERVAL
258 C LAST - INDEX FOR SUBDIVISION
259 C NRES - NUMBER OF CALLS TO THE EXTRAPOLATION ROUTINE
260 C NUMRL2 - NUMBER OF ELEMENTS IN RLIST2. IF AN APPROPRIATE
261 C APPROXIMATION TO THE COMPOUNDED INTEGRAL HAS
262 C BEEN OBTAINED IT IS PUT IN RLIST2(NUMRL2) AFTER
263 C NUMRL2 HAS BEEN INCREASED BY ONE
264 C SMALL - LENGTH OF THE SMALLEST INTERVAL CONSIDERED
265 C UP TO NOW, MULTIPLIED BY 1.5
266 C ERLARG - SUM OF THE ERRORS OVER THE INTERVALS LARGER
267 C THAN THE SMALLEST INTERVAL CONSIDERED UP TO NOW
268 C EXTRAP - LOGICAL VARIABLE DENOTING THAT THE ROUTINE IS
269 C ATTEMPTING TO PERFORM EXTRAPOLATION, I.E. BEFORE
270 C SUBDIVIDING THE SMALLEST INTERVAL WE TRY TO
271 C DECREASE THE VALUE OF ERLARG
272 C NOEXT - LOGICAL VARIABLE DENOTING THAT EXTRAPOLATION
273 C IS NO LONGER ALLOWED (TRUE VALUE)
275 C MACHINE DEPENDENT CONSTANTS
276 C ---------------------------
278 C EPMACH IS THE LARGEST RELATIVE SPACING.
279 C UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
280 C OFLOW IS THE LARGEST POSITIVE MAGNITUDE.
282 C***FIRST EXECUTABLE STATEMENT DQAWOE
285 C TEST ON VALIDITY OF PARAMETERS
286 C ------------------------------
299 IF((INTEGR
.NE
.1.AND
.INTEGR
.NE
.2).OR
.(EPSABS
.LE
.0.0D
+00.AND
.
300 1 EPSREL
.LT
.MAX
(0.5D
+02*EPMACH
,0.5D
-28)).OR
.ICALL
.LT
.1.OR
.
301 2 MAXP1
.LT
.1) IER
= 6
302 IF(IER
.EQ
.6) GO TO 999
304 C FIRST APPROXIMATION TO THE INTEGRAL
305 C -----------------------------------
309 IF (ICALL
.GT
.1) GO TO 5
311 5 CALL DQC25F
(F
,A
,B
,DOMEGA
,INTEGR
,NRMOM
,MAXP1
,0,RESULT
,ABSERR
,
312 1 NEVAL
,DEFABS
,RESABS
,MOMCOM
,CHEBMO
)
317 ERRBND
= MAX
(EPSABS
,EPSREL*DRES
)
321 IF(ABSERR
.LE
.0.1D
+03*EPMACH*DEFABS
.AND
.ABSERR
.GT
.ERRBND
) IER
= 2
322 IF(LIMIT
.EQ
.1) IER
= 1
323 IF(IER
.NE
.0.OR
.ABSERR
.LE
.ERRBND
) GO TO 200
343 SMALL
= ABS
(B
-A
)*0.75D
+00
347 IF(0.5D
+00*ABS
(B
-A
)*DOMEGA
.GT
.0.2D
+01) GO TO 10
351 10 IF(0.25D
+00*ABS
(B
-A
)*DOMEGA
.LE
.0.2D
+01) EXTALL
= .TRUE
.
353 IF(DRES
.GE
.(0.1D
+01-0.5D
+02*EPMACH
)*DEFABS
) KSGN
= 1
358 DO 140 LAST
= 2,LIMIT
360 C BISECT THE SUBINTERVAL WITH THE NRMAX-TH LARGEST
363 NRMOM
= NNLOG
(MAXERR
)+1
365 B1
= 0.5D
+00*(ALIST
(MAXERR
)+BLIST
(MAXERR
))
369 CALL DQC25F
(F
,A1
,B1
,DOMEGA
,INTEGR
,NRMOM
,MAXP1
,0,
370 1 AREA1
,ERROR1
,NEV
,RESABS
,DEFAB1
,MOMCOM
,CHEBMO
)
372 CALL DQC25F
(F
,A2
,B2
,DOMEGA
,INTEGR
,NRMOM
,MAXP1
,1,
373 1 AREA2
,ERROR2
,NEV
,RESABS
,DEFAB2
,MOMCOM
,CHEBMO
)
376 C IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL
377 C AND ERROR AND TEST FOR ACCURACY.
380 ERRO12
= ERROR1
+ERROR2
381 ERRSUM
= ERRSUM
+ERRO12
-ERRMAX
382 AREA
= AREA
+AREA12
-RLIST
(MAXERR
)
383 IF(DEFAB1
.EQ
.ERROR1
.OR
.DEFAB2
.EQ
.ERROR2
) GO TO 25
384 IF(ABS
(RLIST
(MAXERR
)-AREA12
).GT
.0.1D
-04*ABS
(AREA12
)
385 1 .OR
.ERRO12
.LT
.0.99D
+00*ERRMAX
) GO TO 20
386 IF(EXTRAP
) IROFF2
= IROFF2
+1
387 IF(.NOT
.EXTRAP
) IROFF1
= IROFF1
+1
388 20 IF(LAST
.GT
.10.AND
.ERRO12
.GT
.ERRMAX
) IROFF3
= IROFF3
+1
389 25 RLIST
(MAXERR
) = AREA1
391 NNLOG
(MAXERR
) = NRMOM
393 ERRBND
= MAX
(EPSABS
,EPSREL*ABS
(AREA
))
395 C TEST FOR ROUNDOFF ERROR AND EVENTUALLY SET ERROR FLAG.
397 IF(IROFF1
+IROFF2
.GE
.10.OR
.IROFF3
.GE
.20) IER
= 2
398 IF(IROFF2
.GE
.5) IERRO
= 3
400 C SET ERROR FLAG IN THE CASE THAT THE NUMBER OF
401 C SUBINTERVALS EQUALS LIMIT.
403 IF(LAST
.EQ
.LIMIT
) IER
= 1
405 C SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
406 C AT A POINT OF THE INTEGRATION RANGE.
408 IF(MAX
(ABS
(A1
),ABS
(B2
)).LE
.(0.1D
+01+0.1D
+03*EPMACH
)
409 1 *(ABS
(A2
)+0.1D
+04*UFLOW
)) IER
= 4
411 C APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
413 IF(ERROR2
.GT
.ERROR1
) GO TO 30
417 ELIST
(MAXERR
) = ERROR1
420 30 ALIST
(MAXERR
) = A2
423 RLIST
(MAXERR
) = AREA2
425 ELIST
(MAXERR
) = ERROR2
428 C CALL SUBROUTINE DQPSRT TO MAINTAIN THE DESCENDING ORDERING
429 C IN THE LIST OF ERROR ESTIMATES AND SELECT THE SUBINTERVAL
430 C WITH NRMAX-TH LARGEST ERROR ESTIMATE (TO BISECTED NEXT).
432 40 CALL DQPSRT
(LIMIT
,LAST
,MAXERR
,ERRMAX
,ELIST
,IORD
,NRMAX
)
433 C ***JUMP OUT OF DO-LOOP
434 IF(ERRSUM
.LE
.ERRBND
) GO TO 170
435 IF(IER
.NE
.0) GO TO 150
436 IF(LAST
.EQ
.2.AND
.EXTALL
) GO TO 120
438 IF(.NOT
.EXTALL
) GO TO 50
439 ERLARG
= ERLARG
-ERLAST
440 IF(ABS
(B1
-A1
).GT
.SMALL
) ERLARG
= ERLARG
+ERRO12
443 C TEST WHETHER THE INTERVAL TO BE BISECTED NEXT IS THE
446 50 WIDTH
= ABS
(BLIST
(MAXERR
)-ALIST
(MAXERR
))
447 IF(WIDTH
.GT
.SMALL
) GO TO 140
450 C TEST WHETHER WE CAN START WITH THE EXTRAPOLATION PROCEDURE
451 C (WE DO THIS IF WE INTEGRATE OVER THE NEXT INTERVAL WITH
452 C USE OF A GAUSS-KRONROD RULE - SEE SUBROUTINE DQC25F).
454 SMALL
= SMALL*0
.5D
+00
455 IF(0.25D
+00*WIDTH*DOMEGA
.GT
.0.2D
+01) GO TO 140
460 70 IF(IERRO
.EQ
.3.OR
.ERLARG
.LE
.ERTEST
) GO TO 90
462 C THE SMALLEST INTERVAL HAS THE LARGEST ERROR.
463 C BEFORE BISECTING DECREASE THE SUM OF THE ERRORS OVER
464 C THE LARGER INTERVALS (ERLARG) AND PERFORM EXTRAPOLATION.
467 IF (LAST
.GT
.(LIMIT
/2+2)) JUPBND
= LIMIT
+3-LAST
471 ERRMAX
= ELIST
(MAXERR
)
472 IF(ABS
(BLIST
(MAXERR
)-ALIST
(MAXERR
)).GT
.SMALL
) GO TO 140
476 C PERFORM EXTRAPOLATION.
479 RLIST2
(NUMRL2
) = AREA
480 IF(NUMRL2
.LT
.3) GO TO 110
481 CALL DQELG
(NUMRL2
,RLIST2
,RESEPS
,ABSEPS
,RES3LA
,NRES
)
483 IF(KTMIN
.GT
.5.AND
.ABSERR
.LT
.0.1D
-02*ERRSUM
) IER
= 5
484 IF(ABSEPS
.GE
.ABSERR
) GO TO 100
489 ERTEST
= MAX
(EPSABS
,EPSREL*ABS
(RESEPS
))
490 C ***JUMP OUT OF DO-LOOP
491 IF(ABSERR
.LE
.ERTEST
) GO TO 150
493 C PREPARE BISECTION OF THE SMALLEST INTERVAL.
495 100 IF(NUMRL2
.EQ
.1) NOEXT
= .TRUE
.
496 IF(IER
.EQ
.5) GO TO 150
498 ERRMAX
= ELIST
(MAXERR
)
501 SMALL
= SMALL*0
.5D
+00
504 120 SMALL
= SMALL*0
.5D
+00
506 RLIST2
(NUMRL2
) = AREA
511 C SET THE FINAL RESULT.
512 C ---------------------
514 150 IF(ABSERR
.EQ
.OFLOW
.OR
.NRES
.EQ
.0) GO TO 170
515 IF(IER
+IERRO
.EQ
.0) GO TO 165
516 IF(IERRO
.EQ
.3) ABSERR
= ABSERR
+CORREC
518 IF(RESULT
.NE
.0.0D
+00.AND
.AREA
.NE
.0.0D
+00) GO TO 160
519 IF(ABSERR
.GT
.ERRSUM
) GO TO 170
520 IF(AREA
.EQ
.0.0D
+00) GO TO 190
522 160 IF(ABSERR
/ABS
(RESULT
).GT
.ERRSUM
/ABS
(AREA
)) GO TO 170
524 C TEST ON DIVERGENCE.
526 165 IF(KSGN
.EQ
.(-1).AND
.MAX
(ABS
(RESULT
),ABS
(AREA
)).LE
.
527 1 DEFABS*0
.1D
-01) GO TO 190
528 IF(0.1D
-01.GT
.(RESULT
/AREA
).OR
.(RESULT
/AREA
).GT
.0.1D
+03
529 1 .OR
.ERRSUM
.GE
.ABS
(AREA
)) IER
= 6
532 C COMPUTE GLOBAL INTEGRAL SUM.
536 RESULT
= RESULT
+RLIST
(K
)
539 190 IF (IER
.GT
.2) IER
=IER
-1
540 200 IF (INTEGR
.EQ
.2.AND
.OMEGA
.LT
.0.0D
+00) RESULT
=-RESULT