2 SUBROUTINE DQAWCE
(F
, A
, B
, C
, EPSABS
, EPSREL
, LIMIT
, RESULT
,
3 + ABSERR
, NEVAL
, IER
, ALIST
, BLIST
, RLIST
, ELIST
, IORD
, LAST
)
4 C***BEGIN PROLOGUE DQAWCE
5 C***PURPOSE The routine calculates an approximation result to a
6 C CAUCHY PRINCIPAL VALUE I = Integral of F*W over (A,B)
7 C (W(X) = 1/(X-C), (C.NE.A, C.NE.B), hopefully satisfying
8 C following claim for accuracy
9 C ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I))
10 C***LIBRARY SLATEC (QUADPACK)
11 C***CATEGORY H2A2A1, J4
12 C***TYPE DOUBLE PRECISION (QAWCE-S, DQAWCE-D)
13 C***KEYWORDS AUTOMATIC INTEGRATOR, CAUCHY PRINCIPAL VALUE,
14 C CLENSHAW-CURTIS METHOD, QUADPACK, QUADRATURE,
16 C***AUTHOR Piessens, Robert
17 C Applied Mathematics and Programming Division
20 C Applied Mathematics and Programming Division
24 C Computation of a CAUCHY PRINCIPAL VALUE
25 C Standard fortran subroutine
26 C Double precision version
30 C F - Double precision
31 C Function subprogram defining the integrand
32 C function F(X). The actual name for F needs to be
33 C declared E X T E R N A L in the driver program.
35 C A - Double precision
36 C Lower limit of integration
38 C B - Double precision
39 C Upper limit of integration
41 C C - Double precision
42 C Parameter in the WEIGHT function, C.NE.A, C.NE.B
43 C If C = A OR C = B, the routine will end with
46 C EPSABS - Double precision
47 C Absolute accuracy requested
48 C EPSREL - Double precision
49 C Relative accuracy requested
51 C and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
52 C the routine will end with IER = 6.
55 C Gives an upper bound on the number of subintervals
56 C in the partition of (A,B), LIMIT.GE.1
59 C RESULT - Double precision
60 C Approximation to the integral
62 C ABSERR - Double precision
63 C Estimate of the modulus of the absolute error,
64 C which should equal or exceed ABS(I-RESULT)
67 C Number of integrand evaluations
70 C IER = 0 Normal and reliable termination of the
71 C routine. It is assumed that the requested
72 C accuracy has been achieved.
73 C IER.GT.0 Abnormal termination of the routine
74 C the estimates for integral and error are
75 C less reliable. It is assumed that the
76 C requested accuracy has not been achieved.
78 C IER = 1 Maximum number of subdivisions allowed
79 C has been achieved. One can allow more sub-
80 C divisions by increasing the value of
81 C LIMIT. However, if this yields no
82 C improvement it is advised to analyze the
83 C the integrand, in order to determine the
84 C the integration difficulties. If the
85 C position of a local difficulty can be
86 C determined (e.g. SINGULARITY,
87 C DISCONTINUITY within the interval) one
88 C will probably gain from splitting up the
89 C interval at this point and calling
90 C appropriate integrators on the subranges.
91 C = 2 The occurrence of roundoff error is detec-
92 C ted, which prevents the requested
93 C tolerance from being achieved.
94 C = 3 Extremely bad integrand behaviour
95 C occurs at some interior points of
96 C the integration interval.
97 C = 6 The input is invalid, because
100 C EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28))
102 C RESULT, ABSERR, NEVAL, RLIST(1), ELIST(1),
103 C IORD(1) and LAST are set to zero. ALIST(1)
104 C and BLIST(1) are set to A and B
107 C ALIST - Double precision
108 C Vector of dimension at least LIMIT, the first
109 C LAST elements of which are the left
110 C end points of the subintervals in the partition
111 C of the given integration range (A,B)
113 C BLIST - Double precision
114 C Vector of dimension at least LIMIT, the first
115 C LAST elements of which are the right
116 C end points of the subintervals in the partition
117 C of the given integration range (A,B)
119 C RLIST - Double precision
120 C Vector of dimension at least LIMIT, the first
121 C LAST elements of which are the integral
122 C approximations on the subintervals
124 C ELIST - Double precision
125 C Vector of dimension LIMIT, the first LAST
126 C elements of which are the moduli of the absolute
127 C error estimates on the subintervals
130 C Vector of dimension at least LIMIT, the first K
131 C elements of which are pointers to the error
132 C estimates over the subintervals, so that
133 C ELIST(IORD(1)), ..., ELIST(IORD(K)) with K = LAST
134 C If LAST.LE.(LIMIT/2+2), and K = LIMIT+1-LAST
135 C otherwise, form a decreasing sequence
138 C Number of subintervals actually produced in
139 C the subdivision process
141 C***REFERENCES (NONE)
142 C***ROUTINES CALLED D1MACH, DQC25C, DQPSRT
143 C***REVISION HISTORY (YYMMDD)
144 C 800101 DATE WRITTEN
145 C 890531 Changed all specific intrinsics to generic. (WRB)
146 C 890831 Modified array declarations. (WRB)
147 C 890831 REVISION DATE from Version 3.2
148 C 891214 Prologue converted to Version 4.0 format. (BAB)
149 C***END PROLOGUE DQAWCE
151 DOUBLE PRECISION A
,AA
,ABSERR
,ALIST
,AREA
,AREA1
,AREA12
,AREA2
,A1
,A2
,
152 1 B
,BB
,BLIST
,B1
,B2
,C
,D1MACH
,ELIST
,EPMACH
,EPSABS
,EPSREL
,
153 2 ERRBND
,ERRMAX
,ERROR1
,ERRO12
,ERROR2
,ERRSUM
,F
,RESULT
,RLIST
,UFLOW
154 INTEGER IER
,IORD
,IROFF1
,IROFF2
,K
,KRULE
,LAST
,LIMIT
,MAXERR
,NEV
,
157 DIMENSION ALIST
(*),BLIST
(*),RLIST
(*),ELIST
(*),
162 C LIST OF MAJOR VARIABLES
163 C -----------------------
165 C ALIST - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
166 C CONSIDERED UP TO NOW
167 C BLIST - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
168 C CONSIDERED UP TO NOW
169 C RLIST(I) - APPROXIMATION TO THE INTEGRAL OVER
170 C (ALIST(I),BLIST(I))
171 C ELIST(I) - ERROR ESTIMATE APPLYING TO RLIST(I)
172 C MAXERR - POINTER TO THE INTERVAL WITH LARGEST
174 C ERRMAX - ELIST(MAXERR)
175 C AREA - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
176 C ERRSUM - SUM OF THE ERRORS OVER THE SUBINTERVALS
177 C ERRBND - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
179 C *****1 - VARIABLE FOR THE LEFT SUBINTERVAL
180 C *****2 - VARIABLE FOR THE RIGHT SUBINTERVAL
181 C LAST - INDEX FOR SUBDIVISION
184 C MACHINE DEPENDENT CONSTANTS
185 C ---------------------------
187 C EPMACH IS THE LARGEST RELATIVE SPACING.
188 C UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
190 C***FIRST EXECUTABLE STATEMENT DQAWCE
195 C TEST ON VALIDITY OF PARAMETERS
196 C ------------------------------
208 IF (C
.EQ
.A
.OR
.C
.EQ
.B
.OR
.(EPSABS
.LE
.0.0D
+00.AND
.
209 1 EPSREL
.LT
.MAX
(0.5D
+02*EPMACH
,0.5D
-28))) GO TO 999
211 C FIRST APPROXIMATION TO THE INTEGRAL
212 C -----------------------------------
221 CALL DQC25C
(F
,AA
,BB
,C
,RESULT
,ABSERR
,KRULE
,NEVAL
)
231 ERRBND
= MAX
(EPSABS
,EPSREL*ABS
(RESULT
))
232 IF(LIMIT
.EQ
.1) IER
= 1
233 IF(ABSERR
.LT
.MIN
(0.1D
-01*ABS
(RESULT
),ERRBND
)
234 1 .OR
.IER
.EQ
.1) GO TO 70
255 C BISECT THE SUBINTERVAL WITH NRMAX-TH LARGEST
259 B1
= 0.5D
+00*(ALIST
(MAXERR
)+BLIST
(MAXERR
))
261 IF(C
.LE
.B1
.AND
.C
.GT
.A1
) B1
= 0.5D
+00*(C
+B2
)
262 IF(C
.GT
.B1
.AND
.C
.LT
.B2
) B1
= 0.5D
+00*(A1
+C
)
265 CALL DQC25C
(F
,A1
,B1
,C
,AREA1
,ERROR1
,KRULE
,NEV
)
267 CALL DQC25C
(F
,A2
,B2
,C
,AREA2
,ERROR2
,KRULE
,NEV
)
270 C IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL
271 C AND ERROR AND TEST FOR ACCURACY.
274 ERRO12
= ERROR1
+ERROR2
275 ERRSUM
= ERRSUM
+ERRO12
-ERRMAX
276 AREA
= AREA
+AREA12
-RLIST
(MAXERR
)
277 IF(ABS
(RLIST
(MAXERR
)-AREA12
).LT
.0.1D
-04*ABS
(AREA12
)
278 1 .AND
.ERRO12
.GE
.0.99D
+00*ERRMAX
.AND
.KRULE
.EQ
.0)
280 IF(LAST
.GT
.10.AND
.ERRO12
.GT
.ERRMAX
.AND
.KRULE
.EQ
.0)
282 RLIST
(MAXERR
) = AREA1
284 ERRBND
= MAX
(EPSABS
,EPSREL*ABS
(AREA
))
285 IF(ERRSUM
.LE
.ERRBND
) GO TO 15
287 C TEST FOR ROUNDOFF ERROR AND EVENTUALLY SET ERROR FLAG.
289 IF(IROFF1
.GE
.6.AND
.IROFF2
.GT
.20) IER
= 2
291 C SET ERROR FLAG IN THE CASE THAT NUMBER OF INTERVAL
292 C BISECTIONS EXCEEDS LIMIT.
294 IF(LAST
.EQ
.LIMIT
) IER
= 1
296 C SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
297 C AT A POINT OF THE INTEGRATION RANGE.
299 IF(MAX
(ABS
(A1
),ABS
(B2
)).LE
.(0.1D
+01+0.1D
+03*EPMACH
)
300 1 *(ABS
(A2
)+0.1D
+04*UFLOW
)) IER
= 3
302 C APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
304 15 IF(ERROR2
.GT
.ERROR1
) GO TO 20
308 ELIST
(MAXERR
) = ERROR1
311 20 ALIST
(MAXERR
) = A2
314 RLIST
(MAXERR
) = AREA2
316 ELIST
(MAXERR
) = ERROR2
319 C CALL SUBROUTINE DQPSRT TO MAINTAIN THE DESCENDING ORDERING
320 C IN THE LIST OF ERROR ESTIMATES AND SELECT THE SUBINTERVAL
321 C WITH NRMAX-TH LARGEST ERROR ESTIMATE (TO BE BISECTED NEXT).
323 30 CALL DQPSRT
(LIMIT
,LAST
,MAXERR
,ERRMAX
,ELIST
,IORD
,NRMAX
)
324 C ***JUMP OUT OF DO-LOOP
325 IF(IER
.NE
.0.OR
.ERRSUM
.LE
.ERRBND
) GO TO 50
328 C COMPUTE FINAL RESULT.
329 C ---------------------
333 RESULT
= RESULT
+RLIST
(K
)
336 70 IF (AA
.EQ
.B
) RESULT
=-RESULT