quadpack_module.f90
Go to the documentation of this file.
1 #include "../macros.h"
2 !> Further information:
3 !! http://netlib.org/quadpack/index.html
4 !! https://orion.math.iastate.edu/burkardt/f_src/quadpack/quadpack.html
5 !
6 !******************************************************************************
7 !
8 ! 1. introduction
9 !
10 ! quadpack is a fortran subroutine package for the numerical
11 ! computation of definite ond-dimensional integrals. it originated
12 ! from a joint project of r. piessens and e. de doncker (appl.
13 ! math. and progr. div.- k.u.leuven, belgium), c. ueberhuber (inst.
14 ! fuer math.- techn.u.wien, austria), and d. kahaner (nation. bur.
15 ! of standards- washington d.c., u.s.a.).
16 !
17 ! 2. survey
18 !
19 ! - qags : is an integrator based on globally adaptive interval
20 ! subdivision in connection with extrapolation (de doncker,
21 ! 1978) by the epsilon algorithm (wynn, 1956).
22 !
23 ! - qagp : serves the same purposes as qags, but also allows
24 ! for eventual user-supplied information, i.e. the
25 ! abscissae of internal singularities, discontinuities
26 ! and other difficulties of the integrand function.
27 ! the algorithm is a modification of that in qags.
28 !
29 ! - qagi : handles integration over infinite intervals. the
30 ! infinite range is mapped onto a finite interval and
31 ! then the same strategy as in qags is applied.
32 !
33 ! - qawo : is a routine for the integration of cos(omega*x)*f(x)
34 ! or sin(omega*x)*f(x) over a finite interval (a,b).
35 ! omega is is specified by the user
36 ! the rule evaluation component is based on the
37 ! modified clenshaw-curtis technique.
38 ! an adaptive subdivision scheme is used connected with
39 ! an extrapolation procedure, which is a modification
40 ! of that in qags and provides the possibility to deal
41 ! even with singularities in f.
42 !
43 ! - qawf : calculates the fourier cosine or fourier sine
44 ! transform of f(x), for user-supplied interval (a,
45 ! infinity), omega, and f. the procedure of qawo is
46 ! used on successive finite intervals, and convergence
47 ! acceleration by means of the epsilon algorithm (wynn,
48 ! 1956) is applied to the series of the integral
49 ! contributions.
50 !
51 ! - qaws : integrates w(x)*f(x) over (a,b) with a < b finite,
52 ! and w(x) = ((x-a)**alfa)*((b-x)**beta)*v(x)
53 ! where v(x) = 1 or log(x-a) or log(b-x)
54 ! or log(x-a)*log(b-x)
55 ! and alfa > (-1), beta > (-1).
56 ! the user specifies a, b, alfa, beta and the type of
57 ! the function v.
58 ! a globally adaptive subdivision strategy is applied,
59 ! with modified clenshaw-curtis integration on the
60 ! subintervals which contain a or b.
61 !
62 ! - qawc : computes the cauchy principal value of f(x)/(x-c)
63 ! over a finite interval (a,b) and for
64 ! user-determined c.
65 ! the strategy is globally adaptive, and modified
66 ! clenshaw-curtis integration is used on the subranges
67 ! which contain the point x = c.
68 !
69 ! each of the routines above also has a "more detailed" version
70 ! with a name ending in e, as qage. these provide more
71 ! information and control than the easier versions.
72 !
73 !
74 ! the preceeding routines are all automatic. that is, the user
75 ! inputs his problem and an error tolerance. the routine
76 ! attempts to perform the integration to within the requested
77 ! absolute or relative error.
78 ! there are, in addition, a number of non-automatic integrators.
79 ! these are most useful when the problem is such that the
80 ! user knows that a fixed rule will provide the accuracy
81 ! required. typically they return an error estimate but make
82 ! no attempt to satisfy any particular input error request.
83 !
84 ! qk15
85 ! qk21
86 ! qk31
87 ! qk41
88 ! qk51
89 ! qk61
90 ! estimate the integral on [a,b] using 15, 21,..., 61
91 ! point rule and return an error estimate.
92 ! qk15i 15 point rule for (semi)infinite interval.
93 ! qk15w 15 point rule for special singular weight functions.
94 ! qc25c 25 point rule for cauchy principal values
95 ! qc25o 25 point rule for sin/cos integrand.
96 ! qmomo integrates k-th degree chebychev polynomial times
97 ! function with various explicit singularities.
98 !
99 ! 3. guidelines for the use of quadpack
100 !
101 ! here it is not our purpose to investigate the question when
102 ! automatic quadrature should be used. we shall rather attempt
103 ! to help the user who already made the decision to use quadpack,
104 ! with selecting an appropriate routine or a combination of
105 ! several routines for handling his problem.
106 !
107 ! for both quadrature over finite and over infinite intervals,
108 ! one of the first questions to be answered by the user is
109 ! related to the amount of computer time he wants to spend,
110 ! versus his -own- time which would be needed, for example, for
111 ! manual subdivision of the interval or other analytic
112 ! manipulations.
113 !
114 ! (1) the user may not care about computer time, or not be
115 ! willing to do any analysis of the problem. especially when
116 ! only one or a few integrals must be calculated, this attitude
117 ! can be perfectly reasonable. in this case it is clear that
118 ! either the most sophisticated of the routines for finite
119 ! intervals, qags, must be used, or its analogue for infinite
120 ! intervals, qagi. these routines are able to cope with
121 ! rather difficult, even with improper integrals.
122 ! this way of proceeding may be expensive. but the integrator
123 ! is supposed to give you an answer in return, with additional
124 ! information in the case of a failure, through its error
125 ! estimate and flag. yet it must be stressed that the programs
126 ! cannot be totally reliable.
127 !
128 ! (2) the user may want to examine the integrand function.
129 ! if bad local difficulties occur, such as a discontinuity, a
130 ! singularity, derivative singularity or high peak at one or
131 ! more points within the interval, the first advice is to
132 ! split up the interval at these points. the integrand must
133 ! then be examinated over each of the subintervals separately,
134 ! so that a suitable integrator can be selected for each of
135 ! them. if this yields problems involving relative accuracies
136 ! to be imposed on -finitd- subintervals, one can make use of
137 ! qagp, which must be provided with the positions of the local
138 ! difficulties. however, if strong singularities are present
139 ! and a high accuracy is requested, application of qags on the
140 ! subintervals may yield a better result.
141 !
142 ! for quadrature over finite intervals we thus dispose of qags
143 ! and
144 ! - qng for well-behaved integrands,
145 ! - qag for functions with an oscillating behavior of a non
146 ! specific type,
147 ! - qawo for functions, eventually singular, containing a
148 ! factor cos(omega*x) or sin(omega*x) where omega is known,
149 ! - qaws for integrands with algebraico-logarithmic end point
150 ! singularities of known type,
151 ! - qawc for cauchy principal values.
152 !
153 ! remark
154 !
155 ! on return, the work arrays in the argument lists of the
156 ! adaptive integrators contain information about the interval
157 ! subdivision process and hence about the integrand behavior:
158 ! the end points of the subintervals, the local integral
159 ! contributions and error estimates, and eventually other
160 ! characteristics. for this reason, and because of its simple
161 ! globally adaptive nature, the routine qag in particular is
162 ! well-suited for integrand examination. difficult spots can
163 ! be located by investigating the error estimates on the
164 ! subintervals.
165 !
166 ! for infinite intervals we provide only one general-purpose
167 ! routine, qagi. it is based on the qags algorithm applied
168 ! after a transformation of the original interval into (0,1).
169 ! yet it may eventuate that another type of transformation is
170 ! more appropriate, or one might prefer to break up the
171 ! original interval and use qagi only on the infinite part
172 ! and so on. these kinds of actions suggest a combined use of
173 ! different quadpack integrators. note that, when the only
174 ! difficulty is an integrand singularity at the finite
175 ! integration limit, it will in general not be necessary to
176 ! break up the interval, as qagi deals with several types of
177 ! singularity at the boundary point of the integration range.
178 ! it also handles slowly convergent improper integrals, on
179 ! the condition that the integrand does not oscillate over
180 ! the entire infinite interval. if it does we would advise
181 ! to sum succeeding positive and negative contributions to
182 ! the integral -e.g. integrate between the zeros- with one
183 ! or more of the finitd-range integrators, and apply
184 ! convergence acceleration eventually by means of quadpack
185 ! subroutine qelg which implements the epsilon algorithm.
186 ! such quadrature problems include the fourier transform as
187 ! a special case. yet for the latter we have an automatic
188 ! integrator available, qawf.
189 !
190 
191 
192 function pi ( )
193 !
194 !*******************************************************************************
195 !
196 !! PI returns the value of pi.
197 !
198 !
199 ! Modified:
200 !
201 ! 04 December 1998
202 !
203 ! Author:
204 !
205 ! John Burkardt
206 !
207 ! Parameters:
208 !
209 ! Output, real(r_kind) PI, the value of pi.
210 !
211  implicit none
212 !
213  real(r_kind) pi
214 !
215  pi = 3.14159265358979323846264338327950288419716939937510d+00
216 
217  return
218 end function
219 subroutine qag ( f, a, b, epsabs, epsrel, key, result, abserr, neval, ier )
220 !
221 !******************************************************************************
222 !
223 !! QAG approximates an integral over a finite interval.
224 !
225 !
226 ! Discussion:
227 !
228 ! The routine calculates an approximation RESULT to a definite integral
229 ! I = integral of F over (A,B),
230 ! hopefully satisfying
231 ! || I - RESULT || <= max ( EPSABS, EPSREL * ||I|| ).
232 !
233 ! QAG is a simple globally adaptive integrator using the strategy of
234 ! Aind (Piessens, 1973). It is possible to choose between 6 pairs of
235 ! Gauss-Kronrod quadrature formulae for the rule evaluation component.
236 ! The pairs of high degree of precision are suitable for handling
237 ! integration difficulties due to a strongly oscillating integrand.
238 !
239 ! Reference:
240 !
241 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
242 ! QUADPACK, a Subroutine Package for Automatic Integration,
243 ! Springer Verlag, 1983
244 !
245 ! Parameters:
246 !
247 ! Input, external real(r_kind) F, the name of the function routine, of the form
248 ! function f ( x )
249 ! real(r_kind) f
250 ! real(r_kind) x
251 ! which evaluates the integrand function.
252 !
253 ! Input, real(r_kind) A, B, the limits of integration.
254 !
255 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
256 !
257 ! Input, integer KEY, chooses the order of the local integration rule:
258 ! 1, 7 Gauss points, 15 Gauss-Kronrod points,
259 ! 2, 10 Gauss points, 21 Gauss-Kronrod points,
260 ! 3, 15 Gauss points, 31 Gauss-Kronrod points,
261 ! 4, 20 Gauss points, 41 Gauss-Kronrod points,
262 ! 5, 25 Gauss points, 51 Gauss-Kronrod points,
263 ! 6, 30 Gauss points, 61 Gauss-Kronrod points.
264 !
265 ! Output, real(r_kind) RESULT, the estimated value of the integral.
266 !
267 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
268 !
269 ! Output, integer NEVAL, the number of times the integral was evaluated.
270 !
271 ! Output, integer IER, return code.
272 ! 0, normal and reliable termination of the routine. It is assumed that the
273 ! requested accuracy has been achieved.
274 ! 1, maximum number of subdivisions allowed has been achieved. One can
275 ! allow more subdivisions by increasing the value of LIMIT in QAG.
276 ! However, if this yields no improvement it is advised to analyze the
277 ! integrand to determine the integration difficulties. If the position
278 ! of a local difficulty can be determined, such as a singularity or
279 ! discontinuity within the interval) one will probably gain from
280 ! splitting up the interval at this point and calling the integrator
281 ! on the subranges. If possible, an appropriate special-purpose
282 ! integrator should be used which is designed for handling the type
283 ! of difficulty involved.
284 ! 2, the occurrence of roundoff error is detected, which prevents the
285 ! requested tolerance from being achieved.
286 ! 3, extremely bad integrand behavior occurs at some points of the
287 ! integration interval.
288 ! 6, the input is invalid, because EPSABS < 0 and EPSREL < 0.
289 !
290 ! Local parameters:
291 !
292 ! LIMIT is the maximum number of subintervals allowed in
293 ! the subdivision process of QAGE.
294 !
295  implicit none
296 !
297  integer, parameter :: limit = 500
298 !
299  real(r_kind) a
300  real(r_kind) abserr
301  real(r_kind) alist(limit)
302  real(r_kind) b
303  real(r_kind) blist(limit)
304  real(r_kind) elist(limit)
305  real(r_kind) epsabs
306  real(r_kind) epsrel
307  real(r_kind), external :: f
308  integer ier
309  integer iord(limit)
310  integer key
311  integer last
312  integer neval
313  real(r_kind) result
314  real(r_kind) rlist(limit)
315 !
316  call qage ( f, a, b, epsabs, epsrel, key, limit, result, abserr, neval, &
317  ier, alist, blist, rlist, elist, iord, last )
318 
319  return
320 end subroutine
321 subroutine qage ( f, a, b, epsabs, epsrel, key, limit, result, abserr, neval, &
322  ier, alist, blist, rlist, elist, iord, last )
323 !
324 !******************************************************************************
325 !
326 !! QAGE estimates a definite integral.
327 !
328 !
329 ! Discussion:
330 !
331 ! The routine calculates an approximation RESULT to a definite integral
332 ! I = integral of F over (A,B),
333 ! hopefully satisfying
334 ! || I - RESULT || <= max ( EPSABS, EPSREL * ||I|| ).
335 !
336 ! Reference:
337 !
338 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
339 ! QUADPACK, a Subroutine Package for Automatic Integration,
340 ! Springer Verlag, 1983
341 !
342 ! Parameters:
343 !
344 ! Input, external real(r_kind) F, the name of the function routine, of the form
345 ! function f ( x )
346 ! real(r_kind) f
347 ! real(r_kind) x
348 ! which evaluates the integrand function.
349 !
350 ! Input, real(r_kind) A, B, the limits of integration.
351 !
352 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
353 !
354 ! Input, integer KEY, chooses the order of the local integration rule:
355 ! 1, 7 Gauss points, 15 Gauss-Kronrod points,
356 ! 2, 10 Gauss points, 21 Gauss-Kronrod points,
357 ! 3, 15 Gauss points, 31 Gauss-Kronrod points,
358 ! 4, 20 Gauss points, 41 Gauss-Kronrod points,
359 ! 5, 25 Gauss points, 51 Gauss-Kronrod points,
360 ! 6, 30 Gauss points, 61 Gauss-Kronrod points.
361 !
362 ! Input, integer LIMIT, the maximum number of subintervals that
363 ! can be used.
364 !
365 ! Output, real(r_kind) RESULT, the estimated value of the integral.
366 !
367 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
368 !
369 ! Output, integer NEVAL, the number of times the integral was evaluated.
370 !
371 ! Output, integer IER, return code.
372 ! 0, normal and reliable termination of the routine. It is assumed that the
373 ! requested accuracy has been achieved.
374 ! 1, maximum number of subdivisions allowed has been achieved. One can
375 ! allow more subdivisions by increasing the value of LIMIT in QAG.
376 ! However, if this yields no improvement it is advised to analyze the
377 ! integrand to determine the integration difficulties. If the position
378 ! of a local difficulty can be determined, such as a singularity or
379 ! discontinuity within the interval) one will probably gain from
380 ! splitting up the interval at this point and calling the integrator
381 ! on the subranges. If possible, an appropriate special-purpose
382 ! integrator should be used which is designed for handling the type
383 ! of difficulty involved.
384 ! 2, the occurrence of roundoff error is detected, which prevents the
385 ! requested tolerance from being achieved.
386 ! 3, extremely bad integrand behavior occurs at some points of the
387 ! integration interval.
388 ! 6, the input is invalid, because EPSABS < 0 and EPSREL < 0.
389 !
390 ! Workspace, real(r_kind) ALIST(LIMIT), BLIST(LIMIT), contains in entries 1
391 ! through LAST the left and right ends of the partition subintervals.
392 !
393 ! Workspace, real(r_kind) RLIST(LIMIT), contains in entries 1 through LAST
394 ! the integral approximations on the subintervals.
395 !
396 ! Workspace, real(r_kind) ELIST(LIMIT), contains in entries 1 through LAST
397 ! the absolute error estimates on the subintervals.
398 !
399 ! Output, integer IORD(LIMIT), the first K elements of which are pointers
400 ! to the error estimates over the subintervals, such that
401 ! elist(iord(1)), ..., elist(iord(k)) form a decreasing sequence, with
402 ! k = last if last <= (limit/2+2), and k = limit+1-last otherwise.
403 !
404 ! Output, integer LAST, the number of subintervals actually produced
405 ! in the subdivision process.
406 !
407 ! Local parameters:
408 !
409 ! alist - list of left end points of all subintervals
410 ! considered up to now
411 ! blist - list of right end points of all subintervals
412 ! considered up to now
413 ! elist(i) - error estimate applying to rlist(i)
414 ! maxerr - pointer to the interval with largest error estimate
415 ! errmax - elist(maxerr)
416 ! area - sum of the integrals over the subintervals
417 ! errsum - sum of the errors over the subintervals
418 ! errbnd - requested accuracy max(epsabs,epsrel*abs(result))
419 ! *****1 - variable for the left subinterval
420 ! *****2 - variable for the right subinterval
421 ! last - index for subdivision
422 !
423  implicit none
424 !
425  integer limit
426 !
427  real(r_kind) a
428  real(r_kind) abserr
429  real(r_kind) alist(limit)
430  real(r_kind) area
431  real(r_kind) area1
432  real(r_kind) area12
433  real(r_kind) area2
434  real(r_kind) a1
435  real(r_kind) a2
436  real(r_kind) b
437  real(r_kind) blist(limit)
438  real(r_kind) b1
439  real(r_kind) b2
440  real(r_kind) c
441  real(r_kind) defabs
442  real(r_kind) defab1
443  real(r_kind) defab2
444  real(r_kind) elist(limit)
445  real(r_kind) epsabs
446  real(r_kind) epsrel
447  real(r_kind) errbnd
448  real(r_kind) errmax
449  real(r_kind) error1
450  real(r_kind) error2
451  real(r_kind) erro12
452  real(r_kind) errsum
453  real(r_kind), external :: f
454  integer ier
455  integer iord(limit)
456  integer iroff1
457  integer iroff2
458  integer key
459  integer keyf
460  integer last
461  integer maxerr
462  integer neval
463  integer nrmax
464  real(r_kind) resabs
465  real(r_kind) result
466  real(r_kind) rlist(limit)
467 !
468 ! Test on validity of parameters.
469 !
470  ier = 0
471  neval = 0
472  last = 0
473  result = 0.0d+00
474  abserr = 0.0d+00
475  alist(1) = a
476  blist(1) = b
477  rlist(1) = 0.0d+00
478  elist(1) = 0.0d+00
479  iord(1) = 0
480 
481  if ( epsabs < 0.0d+00 .and. epsrel < 0.0d+00 ) then
482  ier = 6
483  return
484  end if
485 !
486 ! First approximation to the integral.
487 !
488  keyf = key
489  keyf = max( keyf, 1 )
490  keyf = min( keyf, 6 )
491 
492  c = keyf
493  neval = 0
494 
495  if ( keyf == 1 ) then
496  call qk15 ( f, a, b, result, abserr, defabs, resabs )
497  else if ( keyf == 2 ) then
498  call qk21 ( f, a, b, result, abserr, defabs, resabs )
499  else if ( keyf == 3 ) then
500  call qk31 ( f, a, b, result, abserr, defabs, resabs )
501  else if ( keyf == 4 ) then
502  call qk41 ( f, a, b, result, abserr, defabs, resabs )
503  else if ( keyf == 5 ) then
504  call qk51 ( f, a, b, result, abserr, defabs, resabs )
505  else if ( keyf == 6 ) then
506  call qk61 ( f, a, b, result, abserr, defabs, resabs )
507  end if
508 
509  last = 1
510  rlist(1) = result
511  elist(1) = abserr
512  iord(1) = 1
513 !
514 ! Test on accuracy.
515 !
516  errbnd = max( epsabs, epsrel * abs( result ) )
517 
518  if ( abserr <= 5.0d+01 * epsilon( defabs ) * defabs .and. &
519  abserr > errbnd ) then
520  ier = 2
521  end if
522 
523  if ( limit == 1 ) then
524  ier = 1
525  end if
526 
527  if ( ier /= 0 .or. &
528  ( abserr <= errbnd .and. abserr /= resabs ) .or. &
529  abserr == 0.0d+00 ) then
530 
531  if ( keyf /= 1 ) then
532  neval = (10*keyf+1) * (2*neval+1)
533  else
534  neval = 30 * neval + 15
535  end if
536 
537  return
538 
539  end if
540 !
541 ! Initialization.
542 !
543  errmax = abserr
544  maxerr = 1
545  area = result
546  errsum = abserr
547  nrmax = 1
548  iroff1 = 0
549  iroff2 = 0
550 
551  do last = 2, limit
552 !
553 ! Bisect the subinterval with the largest error estimate.
554 !
555  a1 = alist(maxerr)
556  b1 = 0.5d+00 * ( alist(maxerr) + blist(maxerr) )
557  a2 = b1
558  b2 = blist(maxerr)
559 
560  if ( keyf == 1 ) then
561  call qk15 ( f, a1, b1, area1, error1, resabs, defab1 )
562  else if ( keyf == 2 ) then
563  call qk21 ( f, a1, b1, area1, error1, resabs, defab1 )
564  else if ( keyf == 3 ) then
565  call qk31 ( f, a1, b1, area1, error1, resabs, defab1 )
566  else if ( keyf == 4 ) then
567  call qk41 ( f, a1, b1, area1, error1, resabs, defab1)
568  else if ( keyf == 5 ) then
569  call qk51 ( f, a1, b1, area1, error1, resabs, defab1 )
570  else if ( keyf == 6 ) then
571  call qk61 ( f, a1, b1, area1, error1, resabs, defab1 )
572  end if
573 
574  if ( keyf == 1 ) then
575  call qk15 ( f, a2, b2, area2, error2, resabs, defab2 )
576  else if ( keyf == 2 ) then
577  call qk21 ( f, a2, b2, area2, error2, resabs, defab2 )
578  else if ( keyf == 3 ) then
579  call qk31 ( f, a2, b2, area2, error2, resabs, defab2 )
580  else if ( keyf == 4 ) then
581  call qk41 ( f, a2, b2, area2, error2, resabs, defab2 )
582  else if ( keyf == 5 ) then
583  call qk51 ( f, a2, b2, area2, error2, resabs, defab2 )
584  else if ( keyf == 6 ) then
585  call qk61 ( f, a2, b2, area2, error2, resabs, defab2 )
586  end if
587 !
588 ! Improve previous approximations to integral and error and
589 ! test for accuracy.
590 !
591  neval = neval + 1
592  area12 = area1 + area2
593  erro12 = error1 + error2
594  errsum = errsum + erro12 - errmax
595  area = area + area12 - rlist(maxerr)
596 
597  if ( defab1 /= error1 .and. defab2 /= error2 ) then
598 
599  if ( abs( rlist(maxerr) - area12 ) <= 1.0d-05 * abs( area12 ) &
600  .and. erro12 >= 9.9d-01 * errmax ) then
601  iroff1 = iroff1 + 1
602  end if
603 
604  if ( last > 10 .and. erro12 > errmax ) then
605  iroff2 = iroff2 + 1
606  end if
607 
608  end if
609 
610  rlist(maxerr) = area1
611  rlist(last) = area2
612  errbnd = max( epsabs, epsrel * abs( area ) )
613 !
614 ! Test for roundoff error and eventually set error flag.
615 !
616  if ( errsum > errbnd ) then
617 
618  if ( iroff1 >= 6 .or. iroff2 >= 20 ) then
619  ier = 2
620  end if
621 !
622 ! Set error flag in the case that the number of subintervals
623 ! equals limit.
624 !
625  if ( last == limit ) then
626  ier = 1
627  end if
628 !
629 ! Set error flag in the case of bad integrand behavior
630 ! at a point of the integration range.
631 !
632  if ( max( abs( a1 ), abs( b2 ) ) <= ( 1.0d+00 + c * 1.0d+03 * &
633  epsilon( a1 ) ) * ( abs( a2 ) + 1.0d+04 * tiny( a2 ) ) ) then
634  ier = 3
635  end if
636 
637  end if
638 !
639 ! Append the newly-created intervals to the list.
640 !
641  if ( error2 <= error1 ) then
642  alist(last) = a2
643  blist(maxerr) = b1
644  blist(last) = b2
645  elist(maxerr) = error1
646  elist(last) = error2
647  else
648  alist(maxerr) = a2
649  alist(last) = a1
650  blist(last) = b1
651  rlist(maxerr) = area2
652  rlist(last) = area1
653  elist(maxerr) = error2
654  elist(last) = error1
655  end if
656 !
657 ! Call QSORT to maintain the descending ordering
658 ! in the list of error estimates and select the subinterval
659 ! with the largest error estimate (to be bisected next).
660 !
661  call qsort ( limit, last, maxerr, errmax, elist, iord, nrmax )
662 
663  if ( ier /= 0 .or. errsum <= errbnd ) then
664  exit
665  end if
666 
667  end do
668 !
669 ! Compute final result.
670 !
671  result = sum( rlist(1:last) )
672 
673  abserr = errsum
674 
675  if ( keyf /= 1 ) then
676  neval = ( 10 * keyf + 1 ) * ( 2 * neval + 1 )
677  else
678  neval = 30 * neval + 15
679  end if
680 
681  return
682 end subroutine
683 subroutine qagi ( f, bound, inf, epsabs, epsrel, result, abserr, neval, ier )
684 !
685 !******************************************************************************
686 !
687 !! QAGI estimates an integral over a semi-infinite or infinite interval.
688 !
689 !
690 ! Discussion:
691 !
692 ! The routine calculates an approximation RESULT to a definite integral
693 ! I = integral of F over (A, +Infinity),
694 ! or
695 ! I = integral of F over (-Infinity,A)
696 ! or
697 ! I = integral of F over (-Infinity,+Infinity),
698 ! hopefully satisfying
699 ! || I - RESULT || <= max ( EPSABS, EPSREL * ||I|| ).
700 !
701 ! Reference:
702 !
703 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
704 ! QUADPACK, a Subroutine Package for Automatic Integration,
705 ! Springer Verlag, 1983
706 !
707 ! Parameters:
708 !
709 ! Input, external real(r_kind) F, the name of the function routine, of the form
710 ! function f ( x )
711 ! real(r_kind) f
712 ! real(r_kind) x
713 ! which evaluates the integrand function.
714 !
715 ! Input, real(r_kind) BOUND, the value of the finite endpoint of the integration
716 ! range, if any, that is, if INF is 1 or -1.
717 !
718 ! Input, integer INF, indicates the type of integration range.
719 ! 1: ( BOUND, +Infinity),
720 ! -1: ( -Infinity, BOUND),
721 ! 2: ( -Infinity, +Infinity).
722 !
723 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
724 !
725 ! Output, real(r_kind) RESULT, the estimated value of the integral.
726 !
727 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
728 !
729 ! Output, integer NEVAL, the number of times the integral was evaluated.
730 !
731 ! Output, integer IER, error indicator.
732 ! 0, normal and reliable termination of the routine. It is assumed that
733 ! the requested accuracy has been achieved.
734 ! > 0, abnormal termination of the routine. The estimates for result
735 ! and error are less reliable. It is assumed that the requested
736 ! accuracy has not been achieved.
737 ! 1, maximum number of subdivisions allowed has been achieved. One can
738 ! allow more subdivisions by increasing the data value of LIMIT in QAGI
739 ! (and taking the according dimension adjustments into account).
740 ! However, if this yields no improvement it is advised to analyze the
741 ! integrand in order to determine the integration difficulties. If the
742 ! position of a local difficulty can be determined (e.g. singularity,
743 ! discontinuity within the interval) one will probably gain from
744 ! splitting up the interval at this point and calling the integrator
745 ! on the subranges. If possible, an appropriate special-purpose
746 ! integrator should be used, which is designed for handling the type
747 ! of difficulty involved.
748 ! 2, the occurrence of roundoff error is detected, which prevents the
749 ! requested tolerance from being achieved. The error may be
750 ! under-estimated.
751 ! 3, extremely bad integrand behavior occurs at some points of the
752 ! integration interval.
753 ! 4, the algorithm does not converge. Roundoff error is detected in the
754 ! extrapolation table. It is assumed that the requested tolerance
755 ! cannot be achieved, and that the returned result is the best which
756 ! can be obtained.
757 ! 5, the integral is probably divergent, or slowly convergent. It must
758 ! be noted that divergence can occur with any other value of IER.
759 ! 6, the input is invalid, because INF /= 1 and INF /= -1 and INF /= 2, or
760 ! epsabs < 0 and epsrel < 0. result, abserr, neval are set to zero.
761 !
762 ! Local parameters:
763 !
764 ! the dimension of rlist2 is determined by the value of
765 ! limexp in QEXTR.
766 !
767 ! alist - list of left end points of all subintervals
768 ! considered up to now
769 ! blist - list of right end points of all subintervals
770 ! considered up to now
771 ! rlist(i) - approximation to the integral over
772 ! (alist(i),blist(i))
773 ! rlist2 - array of dimension at least (limexp+2),
774 ! containing the part of the epsilon table
775 ! which is still needed for further computations
776 ! elist(i) - error estimate applying to rlist(i)
777 ! maxerr - pointer to the interval with largest error
778 ! estimate
779 ! errmax - elist(maxerr)
780 ! erlast - error on the interval currently subdivided
781 ! (before that subdivision has taken place)
782 ! area - sum of the integrals over the subintervals
783 ! errsum - sum of the errors over the subintervals
784 ! errbnd - requested accuracy max(epsabs,epsrel*
785 ! abs(result))
786 ! *****1 - variable for the left subinterval
787 ! *****2 - variable for the right subinterval
788 ! last - index for subdivision
789 ! nres - number of calls to the extrapolation routine
790 ! numrl2 - number of elements currently in rlist2. if an
791 ! appropriate approximation to the compounded
792 ! integral has been obtained, it is put in
793 ! rlist2(numrl2) after numrl2 has been increased
794 ! by one.
795 ! small - length of the smallest interval considered up
796 ! to now, multiplied by 1.5
797 ! erlarg - sum of the errors over the intervals larger
798 ! than the smallest interval considered up to now
799 ! extrap - logical variable denoting that the routine
800 ! is attempting to perform extrapolation. i.e.
801 ! before subdividing the smallest interval we
802 ! try to decrease the value of erlarg.
803 ! noext - logical variable denoting that extrapolation
804 ! is no longer allowed (trud-value)
805 !
806  implicit none
807 !
808  integer, parameter :: limit = 500
809 !
810  real(r_kind) abseps
811  real(r_kind) abserr
812  real(r_kind) alist(limit)
813  real(r_kind) area
814  real(r_kind) area1
815  real(r_kind) area12
816  real(r_kind) area2
817  real(r_kind) a1
818  real(r_kind) a2
819  real(r_kind) blist(limit)
820  real(r_kind) boun
821  real(r_kind) bound
822  real(r_kind) b1
823  real(r_kind) b2
824  real(r_kind) correc
825  real(r_kind) defabs
826  real(r_kind) defab1
827  real(r_kind) defab2
828  real(r_kind) dres
829  real(r_kind) elist(limit)
830  real(r_kind) epsabs
831  real(r_kind) epsrel
832  real(r_kind) erlarg
833  real(r_kind) erlast
834  real(r_kind) errbnd
835  real(r_kind) errmax
836  real(r_kind) error1
837  real(r_kind) error2
838  real(r_kind) erro12
839  real(r_kind) errsum
840  real(r_kind) ertest
841  logical extrap
842  real(r_kind), external :: f
843  integer id
844  integer ier
845  integer ierro
846  integer inf
847  integer iord(limit)
848  integer iroff1
849  integer iroff2
850  integer iroff3
851  integer jupbnd
852  integer k
853  integer ksgn
854  integer ktmin
855  integer last
856  integer maxerr
857  integer neval
858  logical noext
859  integer nres
860  integer nrmax
861  integer numrl2
862  real(r_kind) resabs
863  real(r_kind) reseps
864  real(r_kind) result
865  real(r_kind) res3la(3)
866  real(r_kind) rlist(limit)
867  real(r_kind) rlist2(52)
868  real(r_kind) small
869 !
870 ! Test on validity of parameters.
871 !
872  ier = 0
873  neval = 0
874  last = 0
875  result = 0.0d+00
876  abserr = 0.0d+00
877  alist(1) = 0.0d+00
878  blist(1) = 1.0d+00
879  rlist(1) = 0.0d+00
880  elist(1) = 0.0d+00
881  iord(1) = 0
882 
883  if ( epsabs < 0.0d+00 .and. epsrel < 0.0d+00 ) then
884  ier = 6
885  return
886  end if
887 !
888 ! First approximation to the integral.
889 !
890 ! Determine the interval to be mapped onto (0,1).
891 ! If INF = 2 the integral is computed as i = i1+i2, where
892 ! i1 = integral of f over (-infinity,0),
893 ! i2 = integral of f over (0,+infinity).
894 !
895  if ( inf == 2 ) then
896  boun = 0.0d+00
897  else
898  boun = bound
899  end if
900 
901  call qk15i ( f, boun, inf, 0.0d+00, 1.0d+00, result, abserr, defabs, resabs )
902 !
903 ! Test on accuracy.
904 !
905  last = 1
906  rlist(1) = result
907  elist(1) = abserr
908  iord(1) = 1
909  dres = abs( result )
910  errbnd = max( epsabs, epsrel * dres )
911 
912  if ( abserr <= 100.0d+00 * epsilon( defabs ) * defabs .and. &
913  abserr > errbnd ) then
914  ier = 2
915  end if
916 
917  if ( limit == 1 ) then
918  ier = 1
919  end if
920 
921  if ( ier /= 0 .or. (abserr <= errbnd .and. abserr /= resabs ) .or. &
922  abserr == 0.0d+00 ) go to 130
923 !
924 ! Initialization.
925 !
926  rlist2(1) = result
927  errmax = abserr
928  maxerr = 1
929  area = result
930  errsum = abserr
931  abserr = huge( abserr )
932  nrmax = 1
933  nres = 0
934  ktmin = 0
935  numrl2 = 2
936  extrap = .false.
937  noext = .false.
938  ierro = 0
939  iroff1 = 0
940  iroff2 = 0
941  iroff3 = 0
942 
943  if ( dres >= ( 1.0d+00 - 5.0d+01 * epsilon( defabs ) ) * defabs ) then
944  ksgn = 1
945  else
946  ksgn = -1
947  end if
948 
949  do last = 2, limit
950 !
951 ! Bisect the subinterval with nrmax-th largest error estimate.
952 !
953  a1 = alist(maxerr)
954  b1 = 5.0d-01 * ( alist(maxerr) + blist(maxerr) )
955  a2 = b1
956  b2 = blist(maxerr)
957  erlast = errmax
958  call qk15i ( f, boun, inf, a1, b1, area1, error1, resabs, defab1 )
959  call qk15i ( f, boun, inf, a2, b2, area2, error2, resabs, defab2 )
960 !
961 ! Improve previous approximations to integral and error
962 ! and test for accuracy.
963 !
964  area12 = area1 + area2
965  erro12 = error1 + error2
966  errsum = errsum + erro12 - errmax
967  area = area + area12 - rlist(maxerr)
968 
969  if ( defab1 /= error1 .and. defab2 /= error2 ) then
970 
971  if ( abs( rlist(maxerr) - area12 ) <= 1.0d-05 * abs( area12 ) &
972  .and. erro12 >= 9.9d-01 * errmax ) then
973 
974  if ( extrap ) then
975  iroff2 = iroff2 + 1
976  end if
977 
978  if ( .not. extrap ) then
979  iroff1 = iroff1 + 1
980  end if
981 
982  end if
983 
984  if ( last > 10 .and. erro12 > errmax ) then
985  iroff3 = iroff3 + 1
986  end if
987 
988  end if
989 
990  rlist(maxerr) = area1
991  rlist(last) = area2
992  errbnd = max( epsabs, epsrel * abs( area ) )
993 !
994 ! Test for roundoff error and eventually set error flag.
995 !
996  if ( iroff1 + iroff2 >= 10 .or. iroff3 >= 20 ) then
997  ier = 2
998  end if
999 
1000  if ( iroff2 >= 5 ) then
1001  ierro = 3
1002  end if
1003 !
1004 ! Set error flag in the case that the number of subintervals equals LIMIT.
1005 !
1006  if ( last == limit ) then
1007  ier = 1
1008  end if
1009 !
1010 ! Set error flag in the case of bad integrand behavior
1011 ! at some points of the integration range.
1012 !
1013  if ( max( abs(a1), abs(b2) ) <= (1.0d+00 + 1.0d+03 * epsilon( a1 ) ) * &
1014  ( abs(a2) + 1.0d+03 * tiny( a2 ) )) then
1015  ier = 4
1016  end if
1017 !
1018 ! Append the newly-created intervals to the list.
1019 !
1020  if ( error2 <= error1 ) then
1021  alist(last) = a2
1022  blist(maxerr) = b1
1023  blist(last) = b2
1024  elist(maxerr) = error1
1025  elist(last) = error2
1026  else
1027  alist(maxerr) = a2
1028  alist(last) = a1
1029  blist(last) = b1
1030  rlist(maxerr) = area2
1031  rlist(last) = area1
1032  elist(maxerr) = error2
1033  elist(last) = error1
1034  end if
1035 !
1036 ! Call QSORT to maintain the descending ordering
1037 ! in the list of error estimates and select the subinterval
1038 ! with NRMAX-th largest error estimate (to be bisected next).
1039 !
1040  call qsort ( limit, last, maxerr, errmax, elist, iord, nrmax )
1041 
1042  if ( errsum <= errbnd ) go to 115
1043 
1044  if ( ier /= 0 ) then
1045  exit
1046  end if
1047 
1048  if ( last == 2 ) then
1049  small = 3.75d-01
1050  erlarg = errsum
1051  ertest = errbnd
1052  rlist2(2) = area
1053  cycle
1054  end if
1055 
1056  if ( noext ) then
1057  cycle
1058  end if
1059 
1060  erlarg = erlarg-erlast
1061 
1062  if ( abs(b1-a1) > small ) then
1063  erlarg = erlarg+erro12
1064  end if
1065 !
1066 ! Test whether the interval to be bisected next is the
1067 ! smallest interval.
1068 !
1069  if ( .not. extrap ) then
1070 
1071  if ( abs(blist(maxerr)-alist(maxerr)) > small ) then
1072  cycle
1073  end if
1074 
1075  extrap = .true.
1076  nrmax = 2
1077 
1078  end if
1079 
1080  if ( ierro == 3 .or. erlarg <= ertest ) go to 60
1081 !
1082 ! The smallest interval has the largest error.
1083 ! before bisecting decrease the sum of the errors over the
1084 ! larger intervals (erlarg) and perform extrapolation.
1085 !
1086  id = nrmax
1087  jupbnd = last
1088 
1089  if ( last > (2+limit/2) ) then
1090  jupbnd = limit + 3 - last
1091  end if
1092 
1093  do k = id, jupbnd
1094  maxerr = iord(nrmax)
1095  errmax = elist(maxerr)
1096  if ( abs( blist(maxerr) - alist(maxerr) ) > small ) then
1097  go to 90
1098  end if
1099  nrmax = nrmax + 1
1100  end do
1101 !
1102 ! Extrapolate.
1103 !
1104 60 continue
1105 
1106  numrl2 = numrl2 + 1
1107  rlist2(numrl2) = area
1108  call qextr ( numrl2, rlist2, reseps, abseps, res3la, nres )
1109  ktmin = ktmin+1
1110 
1111  if ( ktmin > 5.and.abserr < 1.0d-03*errsum ) then
1112  ier = 5
1113  end if
1114 
1115  if ( abseps < abserr ) then
1116 
1117  ktmin = 0
1118  abserr = abseps
1119  result = reseps
1120  correc = erlarg
1121  ertest = max( epsabs, epsrel*abs(reseps) )
1122 
1123  if ( abserr <= ertest ) then
1124  exit
1125  end if
1126 
1127  end if
1128 !
1129 ! Prepare bisection of the smallest interval.
1130 !
1131  if ( numrl2 == 1 ) then
1132  noext = .true.
1133  end if
1134 
1135  if ( ier == 5 ) then
1136  exit
1137  end if
1138 
1139  maxerr = iord(1)
1140  errmax = elist(maxerr)
1141  nrmax = 1
1142  extrap = .false.
1143  small = small*5.0d-01
1144  erlarg = errsum
1145 
1146 90 continue
1147 
1148  end do
1149 !
1150 ! Set final result and error estimate.
1151 !
1152  if ( abserr == huge( abserr ) ) go to 115
1153 
1154  if ( (ier+ierro) == 0 ) go to 110
1155 
1156  if ( ierro == 3 ) then
1157  abserr = abserr+correc
1158  end if
1159 
1160  if ( ier == 0 ) then
1161  ier = 3
1162  end if
1163 
1164  if ( result /= 0.0d+00 .and. area /= 0.0d+00) go to 105
1165  if ( abserr > errsum)go to 115
1166  if ( area == 0.0d+00) go to 130
1167 
1168  go to 110
1169 
1170 105 continue
1171  if ( abserr / abs(result) > errsum / abs(area) ) go to 115
1172 !
1173 ! Test on divergence
1174 !
1175 110 continue
1176 
1177  if ( ksgn == (-1) .and. &
1178  max( abs(result), abs(area) ) <= defabs * 1.0d-02) go to 130
1179 
1180  if ( 1.0d-02 > (result/area) .or. &
1181  (result/area) > 1.0d+02 .or. &
1182  errsum > abs(area)) then
1183  ier = 6
1184  end if
1185 
1186  go to 130
1187 !
1188 ! Compute global integral sum.
1189 !
1190  115 continue
1191 
1192  result = sum( rlist(1:last) )
1193 
1194  abserr = errsum
1195  130 continue
1196 
1197  neval = 30*last-15
1198  if ( inf == 2 ) then
1199  neval = 2*neval
1200  end if
1201 
1202  if ( ier > 2 ) then
1203  ier = ier - 1
1204  end if
1205 
1206  return
1207 end subroutine
1208 subroutine qagp ( f, a, b, npts2, points, epsabs, epsrel, result, abserr, &
1209  neval, ier )
1210 !
1211 !******************************************************************************
1212 !
1213 !! QAGP computes a definite integral.
1214 !
1215 !
1216 ! Discussion:
1217 !
1218 ! The routine calculates an approximation RESULT to a definite integral
1219 ! I = integral of F over (A,B),
1220 ! hopefully satisfying
1221 ! || I - RESULT || <= max ( EPSABS, EPSREL * ||I|| ).
1222 !
1223 ! Interior break points of the integration interval,
1224 ! where local difficulties of the integrand may occur, such as
1225 ! singularities or discontinuities, are provided by the user.
1226 !
1227 ! Reference:
1228 !
1229 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
1230 ! QUADPACK, a Subroutine Package for Automatic Integration,
1231 ! Springer Verlag, 1983
1232 !
1233 ! Parameters:
1234 !
1235 ! Input, external real(r_kind) F, the name of the function routine, of the form
1236 ! function f ( x )
1237 ! real(r_kind) f
1238 ! real(r_kind) x
1239 ! which evaluates the integrand function.
1240 !
1241 ! Input, real(r_kind) A, B, the limits of integration.
1242 !
1243 ! Input, integer NPTS2, the number of user-supplied break points within
1244 ! the integration range, plus 2. NPTS2 must be at least 2.
1245 !
1246 ! Input/output, real(r_kind) POINTS(NPTS2), contains the user provided interior
1247 ! breakpoints in entries 1 through NPTS2-2. If these points are not
1248 ! in ascending order on input, they will be sorted.
1249 !
1250 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
1251 !
1252 ! Output, real(r_kind) RESULT, the estimated value of the integral.
1253 !
1254 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
1255 !
1256 ! Output, integer NEVAL, the number of times the integral was evaluated.
1257 !
1258 ! ier - integer
1259 ! ier = 0 normal and reliable termination of the
1260 ! routine. it is assumed that the requested
1261 ! accuracy has been achieved.
1262 ! ier > 0 abnormal termination of the routine.
1263 ! the estimates for integral and error are
1264 ! less reliable. it is assumed that the
1265 ! requested accuracy has not been achieved.
1266 ! ier = 1 maximum number of subdivisions allowed
1267 ! has been achieved. one can allow more
1268 ! subdivisions by increasing the data value
1269 ! of limit in qagp(and taking the according
1270 ! dimension adjustments into account).
1271 ! however, if this yields no improvement
1272 ! it is advised to analyze the integrand
1273 ! in order to determine the integration
1274 ! difficulties. if the position of a local
1275 ! difficulty can be determined (i.e.
1276 ! singularity, discontinuity within the
1277 ! interval), it should be supplied to the
1278 ! routine as an element of the vector
1279 ! points. if necessary, an appropriate
1280 ! special-purpose integrator must be used,
1281 ! which is designed for handling the type
1282 ! of difficulty involved.
1283 ! = 2 the occurrence of roundoff error is
1284 ! detected, which prevents the requested
1285 ! tolerance from being achieved.
1286 ! the error may be under-estimated.
1287 ! = 3 extremely bad integrand behavior occurs
1288 ! at some points of the integration
1289 ! interval.
1290 ! = 4 the algorithm does not converge. roundoff
1291 ! error is detected in the extrapolation
1292 ! table. it is presumed that the requested
1293 ! tolerance cannot be achieved, and that
1294 ! the returned result is the best which
1295 ! can be obtained.
1296 ! = 5 the integral is probably divergent, or
1297 ! slowly convergent. it must be noted that
1298 ! divergence can occur with any other value
1299 ! of ier > 0.
1300 ! = 6 the input is invalid because
1301 ! npts2 < 2 or
1302 ! break points are specified outside
1303 ! the integration range or
1304 ! epsabs < 0 and epsrel < 0,
1305 ! or limit < npts2.
1306 ! result, abserr, neval are set to zero.
1307 !
1308 ! Local parameters:
1309 !
1310 ! the dimension of rlist2 is determined by the value of
1311 ! limexp in QEXTR (rlist2 should be of dimension
1312 ! (limexp+2) at least).
1313 !
1314 ! alist - list of left end points of all subintervals
1315 ! considered up to now
1316 ! blist - list of right end points of all subintervals
1317 ! considered up to now
1318 ! rlist(i) - approximation to the integral over
1319 ! (alist(i),blist(i))
1320 ! rlist2 - array of dimension at least limexp+2
1321 ! containing the part of the epsilon table which
1322 ! is still needed for further computations
1323 ! elist(i) - error estimate applying to rlist(i)
1324 ! maxerr - pointer to the interval with largest error
1325 ! estimate
1326 ! errmax - elist(maxerr)
1327 ! erlast - error on the interval currently subdivided
1328 ! (before that subdivision has taken place)
1329 ! area - sum of the integrals over the subintervals
1330 ! errsum - sum of the errors over the subintervals
1331 ! errbnd - requested accuracy max(epsabs,epsrel*
1332 ! abs(result))
1333 ! *****1 - variable for the left subinterval
1334 ! *****2 - variable for the right subinterval
1335 ! last - index for subdivision
1336 ! nres - number of calls to the extrapolation routine
1337 ! numrl2 - number of elements in rlist2. if an appropriate
1338 ! approximation to the compounded integral has
1339 ! obtained, it is put in rlist2(numrl2) after
1340 ! numrl2 has been increased by one.
1341 ! erlarg - sum of the errors over the intervals larger
1342 ! than the smallest interval considered up to now
1343 ! extrap - logical variable denoting that the routine
1344 ! is attempting to perform extrapolation. i.e.
1345 ! before subdividing the smallest interval we
1346 ! try to decrease the value of erlarg.
1347 ! noext - logical variable denoting that extrapolation is
1348 ! no longer allowed (trud-value)
1349 !
1350  implicit none
1351 !
1352  integer, parameter :: limit = 500
1353 !
1354  real(r_kind) a
1355  real(r_kind) abseps
1356  real(r_kind) abserr
1357  real(r_kind) alist(limit)
1358  real(r_kind) area
1359  real(r_kind) area1
1360  real(r_kind) area12
1361  real(r_kind) area2
1362  real(r_kind) a1
1363  real(r_kind) a2
1364  real(r_kind) b
1365  real(r_kind) blist(limit)
1366  real(r_kind) b1
1367  real(r_kind) b2
1368  real(r_kind) correc
1369  real(r_kind) defabs
1370  real(r_kind) defab1
1371  real(r_kind) defab2
1372  real(r_kind) dres
1373  real(r_kind) elist(limit)
1374  real(r_kind) epsabs
1375  real(r_kind) epsrel
1376  real(r_kind) erlarg
1377  real(r_kind) erlast
1378  real(r_kind) errbnd
1379  real(r_kind) errmax
1380  real(r_kind) error1
1381  real(r_kind) erro12
1382  real(r_kind) error2
1383  real(r_kind) errsum
1384  real(r_kind) ertest
1385  logical extrap
1386  real(r_kind), external :: f
1387  integer i
1388  integer id
1389  integer ier
1390  integer ierro
1391  integer ind1
1392  integer ind2
1393  integer iord(limit)
1394  integer ip1
1395  integer iroff1
1396  integer iroff2
1397  integer iroff3
1398  integer j
1399  integer jlow
1400  integer jupbnd
1401  integer k
1402  integer ksgn
1403  integer ktmin
1404  integer last
1405  integer levcur
1406  integer level(limit)
1407  integer levmax
1408  integer maxerr
1409  integer ndin(40)
1410  integer neval
1411  integer nint
1412  logical noext
1413  integer npts
1414  integer npts2
1415  integer nres
1416  integer nrmax
1417  integer numrl2
1418  real(r_kind) points(40)
1419  real(r_kind) pts(40)
1420  real(r_kind) resa
1421  real(r_kind) resabs
1422  real(r_kind) reseps
1423  real(r_kind) result
1424  real(r_kind) res3la(3)
1425  real(r_kind) rlist(limit)
1426  real(r_kind) rlist2(52)
1427  real(r_kind) sign
1428 !
1429 ! Test on validity of parameters.
1430 !
1431  ier = 0
1432  neval = 0
1433  last = 0
1434  result = 0.0d+00
1435  abserr = 0.0d+00
1436  alist(1) = a
1437  blist(1) = b
1438  rlist(1) = 0.0d+00
1439  elist(1) = 0.0d+00
1440  iord(1) = 0
1441  level(1) = 0
1442  npts = npts2-2
1443 
1444  if ( npts2 < 2 ) then
1445  ier = 6
1446  return
1447  else if ( limit <= npts .or. (epsabs < 0.0d+00.and. &
1448  epsrel < 0.0d+00) ) then
1449  ier = 6
1450  return
1451  end if
1452 !
1453 ! If any break points are provided, sort them into an
1454 ! ascending sequence.
1455 !
1456  if ( a > b ) then
1457  sign = -1.0d+00
1458  else
1459  sign = +1.0d+00
1460  end if
1461 
1462  pts(1) = min( a,b)
1463 
1464  do i = 1, npts
1465  pts(i+1) = points(i)
1466  end do
1467 
1468  pts(npts+2) = max( a,b)
1469  nint = npts+1
1470  a1 = pts(1)
1471 
1472  if ( npts /= 0 ) then
1473 
1474  do i = 1, nint
1475  ip1 = i+1
1476  do j = ip1, nint+1
1477  if ( pts(i) > pts(j) ) then
1478  call r_swap ( pts(i), pts(j) )
1479  end if
1480  end do
1481  end do
1482 
1483  if ( pts(1) /= min( a, b ) .or. pts(nint+1) /= max( a,b) ) then
1484  ier = 6
1485  return
1486  end if
1487 
1488  end if
1489 !
1490 ! Compute first integral and error approximations.
1491 !
1492  resabs = 0.0d+00
1493 
1494  do i = 1, nint
1495 
1496  b1 = pts(i+1)
1497  call qk21 ( f, a1, b1, area1, error1, defabs, resa )
1498  abserr = abserr+error1
1499  result = result+area1
1500  ndin(i) = 0
1501 
1502  if ( error1 == resa .and. error1 /= 0.0d+00 ) then
1503  ndin(i) = 1
1504  end if
1505 
1506  resabs = resabs + defabs
1507  level(i) = 0
1508  elist(i) = error1
1509  alist(i) = a1
1510  blist(i) = b1
1511  rlist(i) = area1
1512  iord(i) = i
1513  a1 = b1
1514 
1515  end do
1516 
1517  errsum = 0.0d+00
1518 
1519  do i = 1, nint
1520  if ( ndin(i) == 1 ) then
1521  elist(i) = abserr
1522  end if
1523  errsum = errsum + elist(i)
1524  end do
1525 !
1526 ! Test on accuracy.
1527 !
1528  last = nint
1529  neval = 21 * nint
1530  dres = abs( result )
1531  errbnd = max( epsabs, epsrel * dres )
1532 
1533  if ( abserr <= 1.0d+02 * epsilon( resabs ) * resabs .and. &
1534  abserr > errbnd ) then
1535  ier = 2
1536  end if
1537 
1538  if ( nint /= 1 ) then
1539 
1540  do i = 1, npts
1541 
1542  jlow = i+1
1543  ind1 = iord(i)
1544 
1545  do j = jlow, nint
1546  ind2 = iord(j)
1547  if ( elist(ind1) <= elist(ind2) ) then
1548  ind1 = ind2
1549  k = j
1550  end if
1551  end do
1552 
1553  if ( ind1 /= iord(i) ) then
1554  iord(k) = iord(i)
1555  iord(i) = ind1
1556  end if
1557 
1558  end do
1559 
1560  if ( limit < npts2 ) then
1561  ier = 1
1562  end if
1563 
1564  end if
1565 
1566  if ( ier /= 0 .or. abserr <= errbnd ) then
1567  return
1568  end if
1569 !
1570 ! Initialization
1571 !
1572  rlist2(1) = result
1573  maxerr = iord(1)
1574  errmax = elist(maxerr)
1575  area = result
1576  nrmax = 1
1577  nres = 0
1578  numrl2 = 1
1579  ktmin = 0
1580  extrap = .false.
1581  noext = .false.
1582  erlarg = errsum
1583  ertest = errbnd
1584  levmax = 1
1585  iroff1 = 0
1586  iroff2 = 0
1587  iroff3 = 0
1588  ierro = 0
1589  abserr = huge( abserr )
1590 
1591  if ( dres >= ( 1.0d+00 - 0.5d+00 * epsilon( resabs ) ) * resabs ) then
1592  ksgn = 1
1593  else
1594  ksgn = -1
1595  end if
1596 
1597  do last = npts2, limit
1598 !
1599 ! Bisect the subinterval with the nrmax-th largest error estimate.
1600 !
1601  levcur = level(maxerr)+1
1602  a1 = alist(maxerr)
1603  b1 = 0.5d+00 * ( alist(maxerr) + blist(maxerr) )
1604  a2 = b1
1605  b2 = blist(maxerr)
1606  erlast = errmax
1607  call qk21 ( f, a1, b1, area1, error1, resa, defab1 )
1608  call qk21 ( f, a2, b2, area2, error2, resa, defab2 )
1609 !
1610 ! Improve previous approximations to integral and error
1611 ! and test for accuracy.
1612 !
1613  neval = neval+42
1614  area12 = area1+area2
1615  erro12 = error1+error2
1616  errsum = errsum+erro12-errmax
1617  area = area+area12-rlist(maxerr)
1618 
1619  if ( defab1 /= error1 .and. defab2 /= error2 ) then
1620 
1621  if ( abs(rlist(maxerr)-area12) <= 1.0d-05*abs(area12) .and. &
1622  erro12 >= 9.9d-01*errmax ) then
1623 
1624  if ( extrap ) then
1625  iroff2 = iroff2+1
1626  else
1627  iroff1 = iroff1+1
1628  end if
1629 
1630  end if
1631 
1632  if ( last > 10 .and. erro12 > errmax ) then
1633  iroff3 = iroff3 + 1
1634  end if
1635 
1636  end if
1637 
1638  level(maxerr) = levcur
1639  level(last) = levcur
1640  rlist(maxerr) = area1
1641  rlist(last) = area2
1642  errbnd = max( epsabs, epsrel * abs( area ) )
1643 !
1644 ! Test for roundoff error and eventually set error flag.
1645 !
1646  if ( iroff1 + iroff2 >= 10 .or. iroff3 >= 20 ) then
1647  ier = 2
1648  end if
1649 
1650  if ( iroff2 >= 5 ) then
1651  ierro = 3
1652  end if
1653 !
1654 ! Set error flag in the case that the number of subintervals
1655 ! equals limit.
1656 !
1657  if ( last == limit ) then
1658  ier = 1
1659  end if
1660 !
1661 ! Set error flag in the case of bad integrand behavior
1662 ! at a point of the integration range
1663 !
1664  if ( max( abs(a1),abs(b2)) <= (1.0d+00+1.0d+03* epsilon( a1 ) )* &
1665  ( abs(a2) + 1.0d+03 * tiny( a2 ) ) ) then
1666  ier = 4
1667  end if
1668 !
1669 ! Append the newly-created intervals to the list.
1670 !
1671  if ( error2 <= error1 ) then
1672  alist(last) = a2
1673  blist(maxerr) = b1
1674  blist(last) = b2
1675  elist(maxerr) = error1
1676  elist(last) = error2
1677  else
1678  alist(maxerr) = a2
1679  alist(last) = a1
1680  blist(last) = b1
1681  rlist(maxerr) = area2
1682  rlist(last) = area1
1683  elist(maxerr) = error2
1684  elist(last) = error1
1685  end if
1686 !
1687 ! Call QSORT to maintain the descending ordering
1688 ! in the list of error estimates and select the subinterval
1689 ! with nrmax-th largest error estimate (to be bisected next).
1690 !
1691  call qsort ( limit, last, maxerr, errmax, elist, iord, nrmax )
1692 
1693  if ( errsum <= errbnd ) go to 190
1694 
1695  if ( ier /= 0 ) then
1696  exit
1697  end if
1698 
1699  if ( noext ) then
1700  cycle
1701  end if
1702 
1703  erlarg = erlarg - erlast
1704 
1705  if ( levcur+1 <= levmax ) then
1706  erlarg = erlarg + erro12
1707  end if
1708 !
1709 ! Test whether the interval to be bisected next is the
1710 ! smallest interval.
1711 !
1712  if ( .not. extrap ) then
1713 
1714  if ( level(maxerr)+1 <= levmax ) then
1715  cycle
1716  end if
1717 
1718  extrap = .true.
1719  nrmax = 2
1720 
1721  end if
1722 !
1723 ! The smallest interval has the largest error.
1724 ! Before bisecting decrease the sum of the errors over the
1725 ! larger intervals (erlarg) and perform extrapolation.
1726 !
1727  if ( ierro /= 3 .and. erlarg > ertest ) then
1728 
1729  id = nrmax
1730  jupbnd = last
1731  if ( last > (2+limit/2) ) then
1732  jupbnd = limit+3-last
1733  end if
1734 
1735  do k = id, jupbnd
1736  maxerr = iord(nrmax)
1737  errmax = elist(maxerr)
1738  if ( level(maxerr)+1 <= levmax ) go to 160
1739  nrmax = nrmax+1
1740  end do
1741 
1742  end if
1743 !
1744 ! Perform extrapolation.
1745 !
1746  numrl2 = numrl2+1
1747  rlist2(numrl2) = area
1748  if ( numrl2 <= 2 ) go to 155
1749  call qextr ( numrl2, rlist2, reseps, abseps, res3la, nres )
1750  ktmin = ktmin+1
1751 
1752  if ( ktmin > 5 .and. abserr < 1.0d-03*errsum ) then
1753  ier = 5
1754  end if
1755 
1756  if ( abseps < abserr ) then
1757 
1758  ktmin = 0
1759  abserr = abseps
1760  result = reseps
1761  correc = erlarg
1762  ertest = max( epsabs,epsrel*abs(reseps))
1763 
1764  if ( abserr < ertest ) then
1765  exit
1766  end if
1767 
1768  end if
1769 !
1770 ! Prepare bisection of the smallest interval.
1771 !
1772  if ( numrl2 == 1 ) then
1773  noext = .true.
1774  end if
1775 
1776  if ( ier >= 5 ) then
1777  exit
1778  end if
1779 
1780 155 continue
1781 
1782  maxerr = iord(1)
1783  errmax = elist(maxerr)
1784  nrmax = 1
1785  extrap = .false.
1786  levmax = levmax+1
1787  erlarg = errsum
1788 
1789 160 continue
1790 
1791  end do
1792 !
1793 ! Set the final result.
1794 !
1795  if ( abserr == huge( abserr ) ) go to 190
1796  if ( (ier+ierro) == 0 ) go to 180
1797 
1798  if ( ierro == 3 ) then
1799  abserr = abserr+correc
1800  end if
1801 
1802  if ( ier == 0 ) then
1803  ier = 3
1804  end if
1805 
1806  if ( result /= 0.0d+00.and.area /= 0.0d+00 ) go to 175
1807  if ( abserr > errsum ) go to 190
1808  if ( area == 0.0d+00 ) go to 210
1809  go to 180
1810 
1811 175 continue
1812 
1813  if ( abserr/abs(result) > errsum/abs(area) ) go to 190
1814 !
1815 ! Test on divergence.
1816 !
1817  180 continue
1818 
1819  if ( ksgn == (-1) .and. max( abs(result),abs(area)) <= &
1820  resabs*1.0d-02 ) go to 210
1821 
1822  if ( 1.0d-02 > (result/area) .or. (result/area) > 1.0d+02 .or. &
1823  errsum > abs(area) ) then
1824  ier = 6
1825  end if
1826 
1827  go to 210
1828 !
1829 ! Compute global integral sum.
1830 !
1831 190 continue
1832 
1833  result = sum( rlist(1:last) )
1834 
1835  abserr = errsum
1836 
1837 210 continue
1838 
1839  if ( ier > 2 ) then
1840  ier = ier - 1
1841  end if
1842 
1843  result = result * sign
1844 
1845  return
1846 end subroutine
1847 subroutine qags ( f, a, b, epsabs, epsrel, result, abserr, neval, ier )
1848 !
1849 !******************************************************************************
1850 !
1851 !! QAGS estimates the integral of a function.
1852 !
1853 !
1854 ! Discussion:
1855 !
1856 ! The routine calculates an approximation RESULT to a definite integral
1857 ! I = integral of F over (A,B),
1858 ! hopefully satisfying
1859 ! || I - RESULT || <= max ( EPSABS, EPSREL * ||I|| ).
1860 !
1861 ! Reference:
1862 !
1863 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
1864 ! QUADPACK, a Subroutine Package for Automatic Integration,
1865 ! Springer Verlag, 1983
1866 !
1867 ! Parameters:
1868 !
1869 ! Input, external real(r_kind) F, the name of the function routine, of the form
1870 ! function f ( x )
1871 ! real(r_kind) f
1872 ! real(r_kind) x
1873 ! which evaluates the integrand function.
1874 !
1875 ! Input, real(r_kind) A, B, the limits of integration.
1876 !
1877 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
1878 !
1879 ! Output, real(r_kind) RESULT, the estimated value of the integral.
1880 !
1881 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
1882 !
1883 ! Output, integer NEVAL, the number of times the integral was evaluated.
1884 !
1885 ! Output, integer IER, error flag.
1886 ! ier = 0 normal and reliable termination of the
1887 ! routine. it is assumed that the requested
1888 ! accuracy has been achieved.
1889 ! ier > 0 abnormal termination of the routine
1890 ! the estimates for integral and error are
1891 ! less reliable. it is assumed that the
1892 ! requested accuracy has not been achieved.
1893 ! = 1 maximum number of subdivisions allowed
1894 ! has been achieved. one can allow more sub-
1895 ! divisions by increasing the data value of
1896 ! limit in qags (and taking the according
1897 ! dimension adjustments into account).
1898 ! however, if this yields no improvement
1899 ! it is advised to analyze the integrand
1900 ! in order to determine the integration
1901 ! difficulties. if the position of a
1902 ! local difficulty can be determined (e.g.
1903 ! singularity, discontinuity within the
1904 ! interval) one will probably gain from
1905 ! splitting up the interval at this point
1906 ! and calling the integrator on the sub-
1907 ! ranges. if possible, an appropriate
1908 ! special-purpose integrator should be used,
1909 ! which is designed for handling the type
1910 ! of difficulty involved.
1911 ! = 2 the occurrence of roundoff error is detec-
1912 ! ted, which prevents the requested
1913 ! tolerance from being achieved.
1914 ! the error may be under-estimated.
1915 ! = 3 extremely bad integrand behavior occurs
1916 ! at some points of the integration
1917 ! interval.
1918 ! = 4 the algorithm does not converge. roundoff
1919 ! error is detected in the extrapolation
1920 ! table. it is presumed that the requested
1921 ! tolerance cannot be achieved, and that the
1922 ! returned result is the best which can be
1923 ! obtained.
1924 ! = 5 the integral is probably divergent, or
1925 ! slowly convergent. it must be noted that
1926 ! divergence can occur with any other value
1927 ! of ier.
1928 ! = 6 the input is invalid, because
1929 ! epsabs < 0 and epsrel < 0,
1930 ! result, abserr and neval are set to zero.
1931 !
1932 ! Local Parameters:
1933 !
1934 ! alist - list of left end points of all subintervals
1935 ! considered up to now
1936 ! blist - list of right end points of all subintervals
1937 ! considered up to now
1938 ! rlist(i) - approximation to the integral over
1939 ! (alist(i),blist(i))
1940 ! rlist2 - array of dimension at least limexp+2 containing
1941 ! the part of the epsilon table which is still
1942 ! needed for further computations
1943 ! elist(i) - error estimate applying to rlist(i)
1944 ! maxerr - pointer to the interval with largest error
1945 ! estimate
1946 ! errmax - elist(maxerr)
1947 ! erlast - error on the interval currently subdivided
1948 ! (before that subdivision has taken place)
1949 ! area - sum of the integrals over the subintervals
1950 ! errsum - sum of the errors over the subintervals
1951 ! errbnd - requested accuracy max(epsabs,epsrel*
1952 ! abs(result))
1953 ! *****1 - variable for the left interval
1954 ! *****2 - variable for the right interval
1955 ! last - index for subdivision
1956 ! nres - number of calls to the extrapolation routine
1957 ! numrl2 - number of elements currently in rlist2. if an
1958 ! appropriate approximation to the compounded
1959 ! integral has been obtained it is put in
1960 ! rlist2(numrl2) after numrl2 has been increased
1961 ! by one.
1962 ! small - length of the smallest interval considered
1963 ! up to now, multiplied by 1.5
1964 ! erlarg - sum of the errors over the intervals larger
1965 ! than the smallest interval considered up to now
1966 ! extrap - logical variable denoting that the routine is
1967 ! attempting to perform extrapolation i.e. before
1968 ! subdividing the smallest interval we try to
1969 ! decrease the value of erlarg.
1970 ! noext - logical variable denoting that extrapolation
1971 ! is no longer allowed (true value)
1972 !
1973  implicit none
1974 !
1975  integer, parameter :: limit = 500
1976 !
1977  real(r_kind) a
1978  real(r_kind) abseps
1979  real(r_kind) abserr
1980  real(r_kind) alist(limit)
1981  real(r_kind) area
1982  real(r_kind) area1
1983  real(r_kind) area12
1984  real(r_kind) area2
1985  real(r_kind) a1
1986  real(r_kind) a2
1987  real(r_kind) b
1988  real(r_kind) blist(limit)
1989  real(r_kind) b1
1990  real(r_kind) b2
1991  real(r_kind) correc
1992  real(r_kind) defabs
1993  real(r_kind) defab1
1994  real(r_kind) defab2
1995  real(r_kind) dres
1996  real(r_kind) elist(limit)
1997  real(r_kind) epsabs
1998  real(r_kind) epsrel
1999  real(r_kind) erlarg
2000  real(r_kind) erlast
2001  real(r_kind) errbnd
2002  real(r_kind) errmax
2003  real(r_kind) error1
2004  real(r_kind) error2
2005  real(r_kind) erro12
2006  real(r_kind) errsum
2007  real(r_kind) ertest
2008  logical extrap
2009  real(r_kind), external :: f
2010  integer id
2011  integer ier
2012  integer ierro
2013  integer iord(limit)
2014  integer iroff1
2015  integer iroff2
2016  integer iroff3
2017  integer jupbnd
2018  integer k
2019  integer ksgn
2020  integer ktmin
2021  integer last
2022  logical noext
2023  integer maxerr
2024  integer neval
2025  integer nres
2026  integer nrmax
2027  integer numrl2
2028  real(r_kind) resabs
2029  real(r_kind) reseps
2030  real(r_kind) result
2031  real(r_kind) res3la(3)
2032  real(r_kind) rlist(limit)
2033  real(r_kind) rlist2(52)
2034  real(r_kind) small
2035 !
2036 ! The dimension of rlist2 is determined by the value of
2037 ! limexp in QEXTR (rlist2 should be of dimension
2038 ! (limexp+2) at least).
2039 !
2040 ! Test on validity of parameters.
2041 !
2042  ier = 0
2043  neval = 0
2044  last = 0
2045  result = 0.0d+00
2046  abserr = 0.0d+00
2047  alist(1) = a
2048  blist(1) = b
2049  rlist(1) = 0.0d+00
2050  elist(1) = 0.0d+00
2051 
2052  if ( epsabs < 0.0d+00 .and. epsrel < 0.0d+00 ) then
2053  ier = 6
2054  return
2055  end if
2056 !
2057 ! First approximation to the integral.
2058 !
2059  ierro = 0
2060  call qk21 ( f, a, b, result, abserr, defabs, resabs )
2061 !
2062 ! Test on accuracy.
2063 !
2064  dres = abs( result )
2065  errbnd = max( epsabs, epsrel * dres )
2066  last = 1
2067  rlist(1) = result
2068  elist(1) = abserr
2069  iord(1) = 1
2070 
2071  if ( abserr <= 1.0d+02 * epsilon( defabs ) * defabs .and. &
2072  abserr > errbnd ) then
2073  ier = 2
2074  end if
2075 
2076  if ( limit == 1 ) then
2077  ier = 1
2078  end if
2079 
2080  if ( ier /= 0 .or. (abserr <= errbnd .and. abserr /= resabs ) .or. &
2081  abserr == 0.0d+00 ) go to 140
2082 !
2083 ! Initialization.
2084 !
2085  rlist2(1) = result
2086  errmax = abserr
2087  maxerr = 1
2088  area = result
2089  errsum = abserr
2090  abserr = huge( abserr )
2091  nrmax = 1
2092  nres = 0
2093  numrl2 = 2
2094  ktmin = 0
2095  extrap = .false.
2096  noext = .false.
2097  iroff1 = 0
2098  iroff2 = 0
2099  iroff3 = 0
2100 
2101  if ( dres >= (1.0d+00-5.0d+01* epsilon( defabs ) )*defabs ) then
2102  ksgn = 1
2103  else
2104  ksgn = -1
2105  end if
2106 
2107  do last = 2, limit
2108 !
2109 ! Bisect the subinterval with the nrmax-th largest error estimate.
2110 !
2111  a1 = alist(maxerr)
2112  b1 = 5.0d-01*(alist(maxerr)+blist(maxerr))
2113  a2 = b1
2114  b2 = blist(maxerr)
2115  erlast = errmax
2116  call qk21 ( f, a1, b1, area1, error1, resabs, defab1 )
2117  call qk21 ( f, a2, b2, area2, error2, resabs, defab2 )
2118 !
2119 ! Improve previous approximations to integral and error
2120 ! and test for accuracy.
2121 !
2122  area12 = area1+area2
2123  erro12 = error1+error2
2124  errsum = errsum+erro12-errmax
2125  area = area+area12-rlist(maxerr)
2126 
2127  if ( defab1 == error1 .or. defab2 == error2 ) go to 15
2128 
2129  if ( abs( rlist(maxerr) - area12) > 1.0d-05 * abs(area12) &
2130  .or. erro12 < 9.9d-01 * errmax ) go to 10
2131 
2132  if ( extrap ) then
2133  iroff2 = iroff2+1
2134  else
2135  iroff1 = iroff1+1
2136  end if
2137 
2138 10 continue
2139 
2140  if ( last > 10.and.erro12 > errmax ) iroff3 = iroff3+1
2141 
2142 15 continue
2143 
2144  rlist(maxerr) = area1
2145  rlist(last) = area2
2146  errbnd = max( epsabs,epsrel*abs(area))
2147 !
2148 ! Test for roundoff error and eventually set error flag.
2149 !
2150  if ( iroff1+iroff2 >= 10 .or. iroff3 >= 20 ) then
2151  ier = 2
2152  end if
2153 
2154  if ( iroff2 >= 5 ) ierro = 3
2155 !
2156 ! Set error flag in the case that the number of subintervals
2157 ! equals limit.
2158 !
2159  if ( last == limit ) then
2160  ier = 1
2161  end if
2162 !
2163 ! Set error flag in the case of bad integrand behavior
2164 ! at a point of the integration range.
2165 !
2166  if ( max( abs(a1),abs(b2)) <= (1.0d+00+1.0d+03* epsilon( a1 ) )* &
2167  (abs(a2)+1.0d+03* tiny( a2 ) ) ) then
2168  ier = 4
2169  end if
2170 !
2171 ! Append the newly-created intervals to the list.
2172 !
2173  if ( error2 <= error1 ) then
2174  alist(last) = a2
2175  blist(maxerr) = b1
2176  blist(last) = b2
2177  elist(maxerr) = error1
2178  elist(last) = error2
2179  else
2180  alist(maxerr) = a2
2181  alist(last) = a1
2182  blist(last) = b1
2183  rlist(maxerr) = area2
2184  rlist(last) = area1
2185  elist(maxerr) = error2
2186  elist(last) = error1
2187  end if
2188 !
2189 ! Call QSORT to maintain the descending ordering
2190 ! in the list of error estimates and select the subinterval
2191 ! with nrmax-th largest error estimate (to be bisected next).
2192 !
2193  call qsort ( limit, last, maxerr, errmax, elist, iord, nrmax )
2194 
2195  if ( errsum <= errbnd ) go to 115
2196 
2197  if ( ier /= 0 ) then
2198  exit
2199  end if
2200 
2201  if ( last == 2 ) go to 80
2202  if ( noext ) go to 90
2203 
2204  erlarg = erlarg-erlast
2205 
2206  if ( abs(b1-a1) > small ) then
2207  erlarg = erlarg+erro12
2208  end if
2209 
2210  if ( extrap ) go to 40
2211 !
2212 ! Test whether the interval to be bisected next is the
2213 ! smallest interval.
2214 !
2215  if ( abs(blist(maxerr)-alist(maxerr)) > small ) go to 90
2216  extrap = .true.
2217  nrmax = 2
2218 
2219 40 continue
2220 !
2221 ! The smallest interval has the largest error.
2222 ! Before bisecting decrease the sum of the errors over the
2223 ! larger intervals (erlarg) and perform extrapolation.
2224 !
2225  if ( ierro /= 3 .and. erlarg > ertest ) then
2226 
2227  id = nrmax
2228  jupbnd = last
2229 
2230  if ( last > (2+limit/2) ) then
2231  jupbnd = limit+3-last
2232  end if
2233 
2234  do k = id, jupbnd
2235  maxerr = iord(nrmax)
2236  errmax = elist(maxerr)
2237  if ( abs(blist(maxerr)-alist(maxerr)) > small ) go to 90
2238  nrmax = nrmax+1
2239  end do
2240 
2241  end if
2242 !
2243 ! Perform extrapolation.
2244 !
2245 60 continue
2246 
2247  numrl2 = numrl2+1
2248  rlist2(numrl2) = area
2249  call qextr ( numrl2, rlist2, reseps, abseps, res3la, nres )
2250  ktmin = ktmin+1
2251 
2252  if ( ktmin > 5 .and. abserr < 1.0d-03 * errsum ) then
2253  ier = 5
2254  end if
2255 
2256  if ( abseps < abserr ) then
2257 
2258  ktmin = 0
2259  abserr = abseps
2260  result = reseps
2261  correc = erlarg
2262  ertest = max( epsabs,epsrel*abs(reseps))
2263 
2264  if ( abserr <= ertest ) then
2265  exit
2266  end if
2267 
2268  end if
2269 !
2270 ! Prepare bisection of the smallest interval.
2271 !
2272  if ( numrl2 == 1 ) then
2273  noext = .true.
2274  end if
2275 
2276  if ( ier == 5 ) then
2277  exit
2278  end if
2279 
2280  maxerr = iord(1)
2281  errmax = elist(maxerr)
2282  nrmax = 1
2283  extrap = .false.
2284  small = small*5.0d-01
2285  erlarg = errsum
2286  go to 90
2287 
2288 80 continue
2289 
2290  small = abs(b-a)*3.75d-01
2291  erlarg = errsum
2292  ertest = errbnd
2293  rlist2(2) = area
2294 
2295 90 continue
2296 
2297  end do
2298 !
2299 ! Set final result and error estimate.
2300 !
2301  if ( abserr == huge( abserr ) ) go to 115
2302  if ( ier+ierro == 0 ) go to 110
2303 
2304  if ( ierro == 3 ) then
2305  abserr = abserr+correc
2306  end if
2307 
2308  if ( ier == 0 ) ier = 3
2309  if ( result /= 0.0d+00.and.area /= 0.0d+00 ) go to 105
2310  if ( abserr > errsum ) go to 115
2311  if ( area == 0.0d+00 ) go to 130
2312  go to 110
2313 
2314 105 continue
2315 
2316  if ( abserr/abs(result) > errsum/abs(area) ) go to 115
2317 !
2318 ! Test on divergence.
2319 !
2320 110 continue
2321 
2322  if ( ksgn == (-1).and.max( abs(result),abs(area)) <= &
2323  defabs*1.0d-02 ) go to 130
2324 
2325  if ( 1.0d-02 > (result/area) .or. (result/area) > 1.0d+02 &
2326  .or. errsum > abs(area) ) then
2327  ier = 6
2328  end if
2329 
2330  go to 130
2331 !
2332 ! Compute global integral sum.
2333 !
2334 115 continue
2335 
2336  result = sum( rlist(1:last) )
2337 
2338  abserr = errsum
2339 
2340 130 continue
2341 
2342  if ( ier > 2 ) ier = ier-1
2343 
2344 140 continue
2345 
2346  neval = 42*last-21
2347 
2348  return
2349 end subroutine
2350 subroutine qawc ( f, a, b, c, epsabs, epsrel, result, abserr, neval, ier )
2351 !
2352 !******************************************************************************
2353 !
2354 !! QAWC computes a Cauchy principal value.
2355 !
2356 !
2357 ! Discussion:
2358 !
2359 ! The routine calculates an approximation RESULT to a Cauchy principal
2360 ! value
2361 ! I = integral of F*W over (A,B),
2362 ! with
2363 ! W(X) = 1 / (X-C),
2364 ! with C distinct from A and B, hopefully satisfying
2365 ! || I - RESULT || <= max ( EPSABS, EPSREL * ||I|| ).
2366 !
2367 ! Reference:
2368 !
2369 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
2370 ! QUADPACK, a Subroutine Package for Automatic Integration,
2371 ! Springer Verlag, 1983
2372 !
2373 ! Parameters:
2374 !
2375 ! Input, external real(r_kind) F, the name of the function routine, of the form
2376 ! function f ( x )
2377 ! real(r_kind) f
2378 ! real(r_kind) x
2379 ! which evaluates the integrand function.
2380 !
2381 ! Input, real(r_kind) A, B, the limits of integration.
2382 !
2383 ! Input, real(r_kind) C, a parameter in the weight function, which must
2384 ! not be equal to A or B.
2385 !
2386 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
2387 !
2388 ! Output, real(r_kind) RESULT, the estimated value of the integral.
2389 !
2390 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
2391 !
2392 ! Output, integer NEVAL, the number of times the integral was evaluated.
2393 !
2394 ! ier - integer
2395 ! ier = 0 normal and reliable termination of the
2396 ! routine. it is assumed that the requested
2397 ! accuracy has been achieved.
2398 ! ier > 0 abnormal termination of the routine
2399 ! the estimates for integral and error are
2400 ! less reliable. it is assumed that the
2401 ! requested accuracy has not been achieved.
2402 ! ier = 1 maximum number of subdivisions allowed
2403 ! has been achieved. one can allow more sub-
2404 ! divisions by increasing the data value of
2405 ! limit in qawc (and taking the according
2406 ! dimension adjustments into account).
2407 ! however, if this yields no improvement it
2408 ! is advised to analyze the integrand in
2409 ! order to determine the integration
2410 ! difficulties. if the position of a local
2411 ! difficulty can be determined (e.g.
2412 ! singularity, discontinuity within the
2413 ! interval one will probably gain from
2414 ! splitting up the interval at this point
2415 ! and calling appropriate integrators on the
2416 ! subranges.
2417 ! = 2 the occurrence of roundoff error is detec-
2418 ! ted, which prevents the requested
2419 ! tolerance from being achieved.
2420 ! = 3 extremely bad integrand behavior occurs
2421 ! at some points of the integration
2422 ! interval.
2423 ! = 6 the input is invalid, because
2424 ! c = a or c = b or
2425 ! epsabs < 0 and epsrel < 0,
2426 ! result, abserr, neval are set to zero.
2427 !
2428 ! Local parameters:
2429 !
2430 ! LIMIT is the maximum number of subintervals allowed in the
2431 ! subdivision process of qawce. take care that limit >= 1.
2432 !
2433  implicit none
2434 !
2435  integer, parameter :: limit = 500
2436 !
2437  real(r_kind) a
2438  real(r_kind) abserr
2439  real(r_kind) alist(limit)
2440  real(r_kind) b
2441  real(r_kind) blist(limit)
2442  real(r_kind) elist(limit)
2443  real(r_kind) c
2444  real(r_kind) epsabs
2445  real(r_kind) epsrel
2446  real(r_kind), external :: f
2447  integer ier
2448  integer iord(limit)
2449  integer last
2450  integer neval
2451  real(r_kind) result
2452  real(r_kind) rlist(limit)
2453 !
2454  call qawce ( f, a, b, c, epsabs, epsrel, limit, result, abserr, neval, ier, &
2455  alist, blist, rlist, elist, iord, last )
2456 
2457  return
2458 end subroutine
2459 subroutine qawce ( f, a, b, c, epsabs, epsrel, limit, result, abserr, neval, &
2460  ier, alist, blist, rlist, elist, iord, last )
2461 !
2462 !******************************************************************************
2463 !
2464 !! QAWCE computes a Cauchy principal value.
2465 !
2466 !
2467 ! Discussion:
2468 !
2469 ! The routine calculates an approximation RESULT to a Cauchy principal
2470 ! value
2471 ! I = integral of F*W over (A,B),
2472 ! with
2473 ! W(X) = 1 / ( X - C ),
2474 ! with C distinct from A and B, hopefully satisfying
2475 ! | I - RESULT | <= max ( EPSABS, EPSREL * |I| ).
2476 !
2477 ! Reference:
2478 !
2479 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
2480 ! QUADPACK, a Subroutine Package for Automatic Integration,
2481 ! Springer Verlag, 1983
2482 !
2483 ! Parameters:
2484 !
2485 ! Input, external real(r_kind) F, the name of the function routine, of the form
2486 ! function f ( x )
2487 ! real(r_kind) f
2488 ! real(r_kind) x
2489 ! which evaluates the integrand function.
2490 !
2491 ! Input, real(r_kind) A, B, the limits of integration.
2492 !
2493 ! Input, real(r_kind) C, a parameter in the weight function, which cannot be
2494 ! equal to A or B.
2495 !
2496 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
2497 !
2498 ! Input, integer LIMIT, the upper bound on the number of subintervals that
2499 ! will be used in the partition of [A,B]. LIMIT is typically 500.
2500 !
2501 ! Output, real(r_kind) RESULT, the estimated value of the integral.
2502 !
2503 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
2504 !
2505 ! Output, integer NEVAL, the number of times the integral was evaluated.
2506 !
2507 ! ier - integer
2508 ! ier = 0 normal and reliable termination of the
2509 ! routine. it is assumed that the requested
2510 ! accuracy has been achieved.
2511 ! ier > 0 abnormal termination of the routine
2512 ! the estimates for integral and error are
2513 ! less reliable. it is assumed that the
2514 ! requested accuracy has not been achieved.
2515 ! ier = 1 maximum number of subdivisions allowed
2516 ! has been achieved. one can allow more sub-
2517 ! divisions by increasing the value of
2518 ! limit. however, if this yields no
2519 ! improvement it is advised to analyze the
2520 ! integrand, in order to determine the
2521 ! integration difficulties. if the position
2522 ! of a local difficulty can be determined
2523 ! (e.g. singularity, discontinuity within
2524 ! the interval) one will probably gain
2525 ! from splitting up the interval at this
2526 ! point and calling appropriate integrators
2527 ! on the subranges.
2528 ! = 2 the occurrence of roundoff error is detec-
2529 ! ted, which prevents the requested
2530 ! tolerance from being achieved.
2531 ! = 3 extremely bad integrand behavior occurs
2532 ! at some interior points of the integration
2533 ! interval.
2534 ! = 6 the input is invalid, because
2535 ! c = a or c = b or
2536 ! epsabs < 0 and epsrel < 0,
2537 ! or limit < 1.
2538 ! result, abserr, neval, rlist(1), elist(1),
2539 ! iord(1) and last are set to zero.
2540 ! alist(1) and blist(1) are set to a and b
2541 ! respectively.
2542 !
2543 ! Workspace, real(r_kind) ALIST(LIMIT), BLIST(LIMIT), contains in entries 1
2544 ! through LAST the left and right ends of the partition subintervals.
2545 !
2546 ! Workspace, real(r_kind) RLIST(LIMIT), contains in entries 1 through LAST
2547 ! the integral approximations on the subintervals.
2548 !
2549 ! Workspace, real(r_kind) ELIST(LIMIT), contains in entries 1 through LAST
2550 ! the absolute error estimates on the subintervals.
2551 !
2552 ! iord - integer
2553 ! vector of dimension at least limit, the first k
2554 ! elements of which are pointers to the error
2555 ! estimates over the subintervals, so that
2556 ! elist(iord(1)), ..., elist(iord(k)) with
2557 ! k = last if last <= (limit/2+2), and
2558 ! k = limit+1-last otherwise, form a decreasing
2559 ! sequence.
2560 !
2561 ! last - integer
2562 ! number of subintervals actually produced in
2563 ! the subdivision process
2564 !
2565 ! Local parameters:
2566 !
2567 ! alist - list of left end points of all subintervals
2568 ! considered up to now
2569 ! blist - list of right end points of all subintervals
2570 ! considered up to now
2571 ! rlist(i) - approximation to the integral over
2572 ! (alist(i),blist(i))
2573 ! elist(i) - error estimate applying to rlist(i)
2574 ! maxerr - pointer to the interval with largest error
2575 ! estimate
2576 ! errmax - elist(maxerr)
2577 ! area - sum of the integrals over the subintervals
2578 ! errsum - sum of the errors over the subintervals
2579 ! errbnd - requested accuracy max(epsabs,epsrel*
2580 ! abs(result))
2581 ! *****1 - variable for the left subinterval
2582 ! *****2 - variable for the right subinterval
2583 ! last - index for subdivision
2584 !
2585  implicit none
2586 !
2587  integer limit
2588 !
2589  real(r_kind) a
2590  real(r_kind) aa
2591  real(r_kind) abserr
2592  real(r_kind) alist(limit)
2593  real(r_kind) area
2594  real(r_kind) area1
2595  real(r_kind) area12
2596  real(r_kind) area2
2597  real(r_kind) a1
2598  real(r_kind) a2
2599  real(r_kind) b
2600  real(r_kind) bb
2601  real(r_kind) blist(limit)
2602  real(r_kind) b1
2603  real(r_kind) b2
2604  real(r_kind) c
2605  real(r_kind) elist(limit)
2606  real(r_kind) epsabs
2607  real(r_kind) epsrel
2608  real(r_kind) errbnd
2609  real(r_kind) errmax
2610  real(r_kind) error1
2611  real(r_kind) error2
2612  real(r_kind) erro12
2613  real(r_kind) errsum
2614  real(r_kind), external :: f
2615  integer ier
2616  integer iord(limit)
2617  integer iroff1
2618  integer iroff2
2619  integer krule
2620  integer last
2621  integer maxerr
2622  integer nev
2623  integer neval
2624  integer nrmax
2625  real(r_kind) result
2626  real(r_kind) rlist(limit)
2627 !
2628 ! Test on validity of parameters.
2629 !
2630  ier = 0
2631  neval = 0
2632  last = 0
2633  alist(1) = a
2634  blist(1) = b
2635  rlist(1) = 0.0d+00
2636  elist(1) = 0.0d+00
2637  iord(1) = 0
2638  result = 0.0d+00
2639  abserr = 0.0d+00
2640 
2641  if ( c == a ) then
2642  ier = 6
2643  return
2644  else if ( c == b ) then
2645  ier = 6
2646  return
2647  else if ( epsabs < 0.0d+00 .and. epsrel < 0.0d+00 ) then
2648  ier = 6
2649  return
2650  end if
2651 !
2652 ! First approximation to the integral.
2653 !
2654  if ( a <= b ) then
2655  aa = a
2656  bb = b
2657  else
2658  aa = b
2659  bb = a
2660  end if
2661 
2662  krule = 1
2663  call qc25c ( f, aa, bb, c, result, abserr, krule, neval )
2664  last = 1
2665  rlist(1) = result
2666  elist(1) = abserr
2667  iord(1) = 1
2668  alist(1) = a
2669  blist(1) = b
2670 !
2671 ! Test on accuracy.
2672 !
2673  errbnd = max( epsabs, epsrel*abs(result) )
2674 
2675  if ( limit == 1 ) then
2676  ier = 1
2677  go to 70
2678  end if
2679 
2680  if ( abserr < min( 1.0d-02*abs(result),errbnd) ) then
2681  go to 70
2682  end if
2683 !
2684 ! Initialization
2685 !
2686  alist(1) = aa
2687  blist(1) = bb
2688  rlist(1) = result
2689  errmax = abserr
2690  maxerr = 1
2691  area = result
2692  errsum = abserr
2693  nrmax = 1
2694  iroff1 = 0
2695  iroff2 = 0
2696 
2697  do last = 2, limit
2698 !
2699 ! Bisect the subinterval with nrmax-th largest error estimate.
2700 !
2701  a1 = alist(maxerr)
2702  b1 = 5.0d-01*(alist(maxerr)+blist(maxerr))
2703  b2 = blist(maxerr)
2704  if ( c <= b1 .and. c > a1 ) b1 = 5.0d-01*(c+b2)
2705  if ( c > b1 .and. c < b2 ) b1 = 5.0d-01*(a1+c)
2706  a2 = b1
2707  krule = 2
2708 
2709  call qc25c ( f, a1, b1, c, area1, error1, krule, nev )
2710  neval = neval+nev
2711 
2712  call qc25c ( f, a2, b2, c, area2, error2, krule, nev )
2713  neval = neval+nev
2714 !
2715 ! Improve previous approximations to integral and error
2716 ! and test for accuracy.
2717 !
2718  area12 = area1+area2
2719  erro12 = error1+error2
2720  errsum = errsum+erro12-errmax
2721  area = area+area12-rlist(maxerr)
2722 
2723  if ( abs(rlist(maxerr)-area12) < 1.0d-05*abs(area12) &
2724  .and.erro12 >= 9.9d-01*errmax .and. krule == 0 ) &
2725  iroff1 = iroff1+1
2726 
2727  if ( last > 10.and.erro12 > errmax .and. krule == 0 ) then
2728  iroff2 = iroff2+1
2729  end if
2730 
2731  rlist(maxerr) = area1
2732  rlist(last) = area2
2733  errbnd = max( epsabs,epsrel*abs(area))
2734 
2735  if ( errsum > errbnd ) then
2736 !
2737 ! Test for roundoff error and eventually set error flag.
2738 !
2739  if ( iroff1 >= 6 .and. iroff2 > 20 ) then
2740  ier = 2
2741  end if
2742 !
2743 ! Set error flag in the case that number of interval
2744 ! bisections exceeds limit.
2745 !
2746  if ( last == limit ) then
2747  ier = 1
2748  end if
2749 !
2750 ! Set error flag in the case of bad integrand behavior at
2751 ! a point of the integration range.
2752 !
2753  if ( max( abs(a1), abs(b2) ) <= ( 1.0d+00 + 1.0d+03 * epsilon( a1 ) ) &
2754  *(abs(a2)+1.0d+03* tiny( a2 ) )) then
2755  ier = 3
2756  end if
2757 
2758  end if
2759 !
2760 ! Append the newly-created intervals to the list.
2761 !
2762  if ( error2 <= error1 ) then
2763  alist(last) = a2
2764  blist(maxerr) = b1
2765  blist(last) = b2
2766  elist(maxerr) = error1
2767  elist(last) = error2
2768  else
2769  alist(maxerr) = a2
2770  alist(last) = a1
2771  blist(last) = b1
2772  rlist(maxerr) = area2
2773  rlist(last) = area1
2774  elist(maxerr) = error2
2775  elist(last) = error1
2776  end if
2777 !
2778 ! Call QSORT to maintain the descending ordering
2779 ! in the list of error estimates and select the subinterval
2780 ! with NRMAX-th largest error estimate (to be bisected next).
2781 !
2782  call qsort ( limit, last, maxerr, errmax, elist, iord, nrmax )
2783 
2784  if ( ier /= 0 .or. errsum <= errbnd ) then
2785  exit
2786  end if
2787 
2788  end do
2789 !
2790 ! Compute final result.
2791 !
2792  result = sum( rlist(1:last) )
2793 
2794  abserr = errsum
2795 
2796 70 continue
2797 
2798  if ( aa == b ) then
2799  result = - result
2800  end if
2801 
2802  return
2803 end subroutine
2804 subroutine qawf ( f, a, omega, integr, epsabs, result, abserr, neval, ier )
2805 !
2806 !******************************************************************************
2807 !
2808 !! QAWF computes Fourier integrals over the interval [ A, +Infinity ).
2809 !
2810 !
2811 ! Discussion:
2812 !
2813 ! The routine calculates an approximation RESULT to a definite integral
2814 !
2815 ! I = integral of F*COS(OMEGA*X)
2816 ! or
2817 ! I = integral of F*SIN(OMEGA*X)
2818 !
2819 ! over the interval [A,+Infinity), hopefully satisfying
2820 !
2821 ! || I - RESULT || <= EPSABS.
2822 !
2823 ! If OMEGA = 0 and INTEGR = 1, the integral is calculated by means
2824 ! of QAGI, and IER has the meaning as described in the comments of QAGI.
2825 !
2826 ! Reference:
2827 !
2828 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
2829 ! QUADPACK, a Subroutine Package for Automatic Integration,
2830 ! Springer Verlag, 1983
2831 !
2832 ! Parameters:
2833 !
2834 ! Input, external real(r_kind) F, the name of the function routine, of the form
2835 ! function f ( x )
2836 ! real(r_kind) f
2837 ! real(r_kind) x
2838 ! which evaluates the integrand function.
2839 !
2840 ! Input, real(r_kind) A, the lower limit of integration.
2841 !
2842 ! Input, real(r_kind) OMEGA, the parameter in the weight function.
2843 !
2844 ! Input, integer INTEGR, indicates which weight functions is used
2845 ! = 1, w(x) = cos(omega*x)
2846 ! = 2, w(x) = sin(omega*x)
2847 !
2848 ! Input, real(r_kind) EPSABS, the absolute accuracy requested.
2849 !
2850 ! Output, real(r_kind) RESULT, the estimated value of the integral.
2851 !
2852 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
2853 !
2854 ! Output, integer NEVAL, the number of times the integral was evaluated.
2855 !
2856 ! ier - integer
2857 ! ier = 0 normal and reliable termination of the
2858 ! routine. it is assumed that the
2859 ! requested accuracy has been achieved.
2860 ! ier > 0 abnormal termination of the routine.
2861 ! the estimates for integral and error are
2862 ! less reliable. it is assumed that the
2863 ! requested accuracy has not been achieved.
2864 ! if omega /= 0
2865 ! ier = 6 the input is invalid because
2866 ! (integr /= 1 and integr /= 2) or
2867 ! epsabs <= 0
2868 ! result, abserr, neval, lst are set to
2869 ! zero.
2870 ! = 7 abnormal termination of the computation
2871 ! of one or more subintegrals
2872 ! = 8 maximum number of cycles allowed
2873 ! has been achieved, i.e. of subintervals
2874 ! (a+(k-1)c,a+kc) where
2875 ! c = (2*int(abs(omega))+1)*pi/abs(omega),
2876 ! for k = 1, 2, ...
2877 ! = 9 the extrapolation table constructed for
2878 ! convergence acceleration of the series
2879 ! formed by the integral contributions
2880 ! over the cycles, does not converge to
2881 ! within the requested accuracy.
2882 !
2883 ! Local parameters:
2884 !
2885 ! Integer LIMLST, gives an upper bound on the number of cycles, LIMLST >= 3.
2886 ! if limlst < 3, the routine will end with ier = 6.
2887 !
2888 ! Integer MAXP1, an upper bound on the number of Chebyshev moments which
2889 ! can be stored, i.e. for the intervals of lengths abs(b-a)*2**(-l),
2890 ! l = 0,1, ..., maxp1-2, maxp1 >= 1. if maxp1 < 1, the routine will end
2891 ! with ier = 6.
2892 !
2893  implicit none
2894 !
2895  integer, parameter :: limit = 500
2896  integer, parameter :: limlst = 50
2897  integer, parameter :: maxp1 = 21
2898 !
2899  real(r_kind) a
2900  real(r_kind) abserr
2901  real(r_kind) alist(limit)
2902  real(r_kind) blist(limit)
2903  real(r_kind) chebmo(maxp1,25)
2904  real(r_kind) elist(limit)
2905  real(r_kind) epsabs
2906  real(r_kind) erlst(limlst)
2907  real(r_kind), external :: f
2908  integer ier
2909  integer integr
2910  integer iord(limit)
2911  integer ierlst(limlst)
2912  integer last
2913  integer lst
2914  integer neval
2915  integer nnlog(limit)
2916  real(r_kind) omega
2917  real(r_kind) result
2918  real(r_kind) rlist(limit)
2919  real(r_kind) rslst(limlst)
2920 !
2921  ier = 6
2922  neval = 0
2923  last = 0
2924  result = 0.0d+00
2925  abserr = 0.0d+00
2926 
2927  if ( limlst < 3 .or. maxp1 < 1 ) then
2928  return
2929  end if
2930 
2931  call qawfe ( f, a, omega, integr, epsabs, limlst, limit, maxp1, result, &
2932  abserr, neval, ier, rslst, erlst, ierlst, lst, alist, blist, rlist, &
2933  elist, iord, nnlog, chebmo )
2934 
2935  return
2936 end subroutine
2937 subroutine qawfe ( f, a, omega, integr, epsabs, limlst, limit, maxp1, &
2938  result, abserr, neval, ier, rslst, erlst, ierlst, lst, alist, blist, &
2939  rlist, elist, iord, nnlog, chebmo )
2940 !
2941 !******************************************************************************
2942 !
2943 !! QAWFE computes Fourier integrals.
2944 !
2945 !
2946 ! Discussion:
2947 !
2948 ! The routine calculates an approximation RESULT to a definite integral
2949 ! I = integral of F*COS(OMEGA*X) or F*SIN(OMEGA*X) over (A,+Infinity),
2950 ! hopefully satisfying
2951 ! || I - RESULT || <= EPSABS.
2952 !
2953 ! Reference:
2954 !
2955 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
2956 ! QUADPACK, a Subroutine Package for Automatic Integration,
2957 ! Springer Verlag, 1983
2958 !
2959 ! Parameters:
2960 !
2961 ! Input, external real(r_kind) F, the name of the function routine, of the form
2962 ! function f ( x )
2963 ! real(r_kind) f
2964 ! real(r_kind) x
2965 ! which evaluates the integrand function.
2966 !
2967 ! Input, real(r_kind) A, the lower limit of integration.
2968 !
2969 ! Input, real(r_kind) OMEGA, the parameter in the weight function.
2970 !
2971 ! Input, integer INTEGR, indicates which weight function is used
2972 ! = 1 w(x) = cos(omega*x)
2973 ! = 2 w(x) = sin(omega*x)
2974 !
2975 ! Input, real(r_kind) EPSABS, the absolute accuracy requested.
2976 !
2977 ! Input, integer LIMLST, an upper bound on the number of cycles.
2978 ! LIMLST must be at least 1. In fact, if LIMLST < 3, the routine
2979 ! will end with IER= 6.
2980 !
2981 ! limit - integer
2982 ! gives an upper bound on the number of
2983 ! subintervals allowed in the partition of
2984 ! each cycle, limit >= 1.
2985 !
2986 ! maxp1 - integer
2987 ! gives an upper bound on the number of
2988 ! Chebyshev moments which can be stored, i.e.
2989 ! for the intervals of lengths abs(b-a)*2**(-l),
2990 ! l=0,1, ..., maxp1-2, maxp1 >= 1
2991 !
2992 ! Output, real(r_kind) RESULT, the estimated value of the integral.
2993 !
2994 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
2995 !
2996 ! Output, integer NEVAL, the number of times the integral was evaluated.
2997 !
2998 ! ier - ier = 0 normal and reliable termination of
2999 ! the routine. it is assumed that the
3000 ! requested accuracy has been achieved.
3001 ! ier > 0 abnormal termination of the routine
3002 ! the estimates for integral and error
3003 ! are less reliable. it is assumed that
3004 ! the requested accuracy has not been
3005 ! achieved.
3006 ! if omega /= 0
3007 ! ier = 6 the input is invalid because
3008 ! (integr /= 1 and integr /= 2) or
3009 ! epsabs <= 0 or limlst < 3.
3010 ! result, abserr, neval, lst are set
3011 ! to zero.
3012 ! = 7 bad integrand behavior occurs within
3013 ! one or more of the cycles. location
3014 ! and type of the difficulty involved
3015 ! can be determined from the vector ierlst.
3016 ! here lst is the number of cycles actually
3017 ! needed (see below).
3018 ! ierlst(k) = 1 the maximum number of
3019 ! subdivisions (= limit)
3020 ! has been achieved on the
3021 ! k th cycle.
3022 ! = 2 occurence of roundoff
3023 ! error is detected and
3024 ! prevents the tolerance
3025 ! imposed on the k th cycle
3026 ! from being acheived.
3027 ! = 3 extremely bad integrand
3028 ! behavior occurs at some
3029 ! points of the k th cycle.
3030 ! = 4 the integration procedure
3031 ! over the k th cycle does
3032 ! not converge (to within the
3033 ! required accuracy) due to
3034 ! roundoff in the
3035 ! extrapolation procedure
3036 ! invoked on this cycle. it
3037 ! is assumed that the result
3038 ! on this interval is the
3039 ! best which can be obtained.
3040 ! = 5 the integral over the k th
3041 ! cycle is probably divergent
3042 ! or slowly convergent. it
3043 ! must be noted that
3044 ! divergence can occur with
3045 ! any other value of
3046 ! ierlst(k).
3047 ! = 8 maximum number of cycles allowed
3048 ! has been achieved, i.e. of subintervals
3049 ! (a+(k-1)c,a+kc) where
3050 ! c = (2*int(abs(omega))+1)*pi/abs(omega),
3051 ! for k = 1, 2, ..., lst.
3052 ! one can allow more cycles by increasing
3053 ! the value of limlst (and taking the
3054 ! according dimension adjustments into
3055 ! account).
3056 ! examine the array iwork which contains
3057 ! the error flags over the cycles, in order
3058 ! to eventual look for local integration
3059 ! difficulties.
3060 ! if the position of a local difficulty can
3061 ! be determined (e.g. singularity,
3062 ! discontinuity within the interval)
3063 ! one will probably gain from splitting
3064 ! up the interval at this point and
3065 ! calling appopriate integrators on the
3066 ! subranges.
3067 ! = 9 the extrapolation table constructed for
3068 ! convergence acceleration of the series
3069 ! formed by the integral contributions
3070 ! over the cycles, does not converge to
3071 ! within the required accuracy.
3072 ! as in the case of ier = 8, it is advised
3073 ! to examine the array iwork which contains
3074 ! the error flags on the cycles.
3075 ! if omega = 0 and integr = 1,
3076 ! the integral is calculated by means of qagi
3077 ! and ier = ierlst(1) (with meaning as described
3078 ! for ierlst(k), k = 1).
3079 !
3080 ! rslst - real
3081 ! vector of dimension at least limlst
3082 ! rslst(k) contains the integral contribution
3083 ! over the interval (a+(k-1)c,a+kc) where
3084 ! c = (2*int(abs(omega))+1)*pi/abs(omega),
3085 ! k = 1, 2, ..., lst.
3086 ! note that, if omega = 0, rslst(1) contains
3087 ! the value of the integral over (a,infinity).
3088 !
3089 ! erlst - real
3090 ! vector of dimension at least limlst
3091 ! erlst(k) contains the error estimate
3092 ! corresponding with rslst(k).
3093 !
3094 ! ierlst - integer
3095 ! vector of dimension at least limlst
3096 ! ierlst(k) contains the error flag corresponding
3097 ! with rslst(k). for the meaning of the local error
3098 ! flags see description of output parameter ier.
3099 !
3100 ! lst - integer
3101 ! number of subintervals needed for the integration
3102 ! if omega = 0 then lst is set to 1.
3103 !
3104 ! alist, blist, rlist, elist - real
3105 ! vector of dimension at least limit,
3106 !
3107 ! iord, nnlog - integer
3108 ! vector of dimension at least limit, providing
3109 ! space for the quantities needed in the
3110 ! subdivision process of each cycle
3111 !
3112 ! chebmo - real
3113 ! array of dimension at least (maxp1,25),
3114 ! providing space for the Chebyshev moments
3115 ! needed within the cycles
3116 !
3117 ! Local parameters:
3118 !
3119 ! c1, c2 - end points of subinterval (of length
3120 ! cycle)
3121 ! cycle - (2*int(abs(omega))+1)*pi/abs(omega)
3122 ! psum - vector of dimension at least (limexp+2)
3123 ! (see routine qextr)
3124 ! psum contains the part of the epsilon table
3125 ! which is still needed for further computations.
3126 ! each element of psum is a partial sum of
3127 ! the series which should sum to the value of
3128 ! the integral.
3129 ! errsum - sum of error estimates over the
3130 ! subintervals, calculated cumulatively
3131 ! epsa - absolute tolerance requested over current
3132 ! subinterval
3133 ! chebmo - array containing the modified Chebyshev
3134 ! moments (see also routine qc25o)
3135 !
3136  implicit none
3137 !
3138  integer limit
3139  integer limlst
3140  integer maxp1
3141 !
3142  real(r_kind) a
3143  real(r_kind) abseps
3144  real(r_kind) abserr
3145  real(r_kind) alist(limit)
3146  real(r_kind) blist(limit)
3147  real(r_kind) chebmo(maxp1,25)
3148  real(r_kind) correc
3149  real(r_kind) cycle
3150  real(r_kind) c1
3151  real(r_kind) c2
3152  real(r_kind) dl
3153  real(r_kind) dla
3154  real(r_kind) drl
3155  real(r_kind) elist(limit)
3156  real(r_kind) ep
3157  real(r_kind) eps
3158  real(r_kind) epsa
3159  real(r_kind) epsabs
3160  real(r_kind) erlst(limlst)
3161  real(r_kind) errsum
3162  real(r_kind), external :: f
3163  real(r_kind) fact
3164  integer ier
3165  integer ierlst(limlst)
3166  integer integr
3167  integer iord(limit)
3168  integer ktmin
3169  integer l
3170  integer ll
3171  integer lst
3172  integer momcom
3173  integer nev
3174  integer neval
3175  integer nnlog(limit)
3176  integer nres
3177  integer numrl2
3178  real(r_kind) omega
3179  real(r_kind), parameter :: p = 0.9d+00
3180  real(r_kind), parameter :: pi = 3.1415926535897932d+00
3181  real(r_kind) p1
3182  real(r_kind) psum(52)
3183  real(r_kind) reseps
3184  real(r_kind) result
3185  real(r_kind) res3la(3)
3186  real(r_kind) rlist(limit)
3187  real(r_kind) rslst(limlst)
3188 !
3189 ! The dimension of psum is determined by the value of
3190 ! limexp in QEXTR (psum must be
3191 ! of dimension (limexp+2) at least).
3192 !
3193 ! Test on validity of parameters.
3194 !
3195  result = 0.0d+00
3196  abserr = 0.0d+00
3197  neval = 0
3198  lst = 0
3199  ier = 0
3200 
3201  if ( (integr /= 1 .and. integr /= 2 ) .or. &
3202  epsabs <= 0.0d+00 .or. &
3203  limlst < 3 ) then
3204  ier = 6
3205  return
3206  end if
3207 
3208  if ( omega == 0.0d+00 ) then
3209 
3210  if ( integr == 1 ) then
3211  call qagi ( f, 0.0d+00, 1, epsabs, 0.0d+00, result, abserr, neval, ier )
3212  else
3213  result = 0.0d+00
3214  abserr = 0.0d+00
3215  neval = 0
3216  ier = 0
3217  end if
3218 
3219  rslst(1) = result
3220  erlst(1) = abserr
3221  ierlst(1) = ier
3222  lst = 1
3223 
3224  return
3225  end if
3226 !
3227 ! Initializations.
3228 !
3229  l = abs( omega )
3230  dl = 2 * l + 1
3231  cycle = dl * pi / abs( omega )
3232  ier = 0
3233  ktmin = 0
3234  neval = 0
3235  numrl2 = 0
3236  nres = 0
3237  c1 = a
3238  c2 = cycle+a
3239  p1 = 1.0d+00-p
3240  eps = epsabs
3241 
3242  if ( epsabs > tiny( epsabs ) / p1 ) then
3243  eps = epsabs * p1
3244  end if
3245 
3246  ep = eps
3247  fact = 1.0d+00
3248  correc = 0.0d+00
3249  abserr = 0.0d+00
3250  errsum = 0.0d+00
3251 
3252  do lst = 1, limlst
3253 !
3254 ! Integrate over current subinterval.
3255 !
3256  dla = lst
3257  epsa = eps*fact
3258 
3259  call qfour ( f, c1, c2, omega, integr, epsa, 0.0d+00, limit, lst, maxp1, &
3260  rslst(lst), erlst(lst), nev, ierlst(lst), alist, blist, rlist, elist, &
3261  iord, nnlog, momcom, chebmo )
3262 
3263  neval = neval + nev
3264  fact = fact * p
3265  errsum = errsum + erlst(lst)
3266  drl = 5.0d+01 * abs(rslst(lst))
3267 !
3268 ! Test on accuracy with partial sum.
3269 !
3270  if ((errsum+drl) <= epsabs.and.lst >= 6) go to 80
3271 
3272  correc = max( correc,erlst(lst))
3273 
3274  if ( ierlst(lst) /= 0 ) then
3275  eps = max( ep,correc*p1)
3276  ier = 7
3277  end if
3278 
3279  if ( ier == 7 .and. (errsum+drl) <= correc*1.0d+01.and. lst > 5) go to 80
3280 
3281  numrl2 = numrl2+1
3282 
3283  if ( lst <= 1 ) then
3284  psum(1) = rslst(1)
3285  go to 40
3286  end if
3287 
3288  psum(numrl2) = psum(ll)+rslst(lst)
3289 
3290  if ( lst == 2 ) then
3291  go to 40
3292  end if
3293 !
3294 ! Test on maximum number of subintervals
3295 !
3296  if ( lst == limlst ) then
3297  ier = 8
3298  end if
3299 !
3300 ! Perform new extrapolation
3301 !
3302  call qextr ( numrl2, psum, reseps, abseps, res3la, nres )
3303 !
3304 ! Test whether extrapolated result is influenced by roundoff
3305 !
3306  ktmin = ktmin+1
3307 
3308  if ( ktmin >= 15 .and. abserr <= 1.0d-03 * (errsum+drl) ) then
3309  ier = 9
3310  end if
3311 
3312  if ( abseps <= abserr .or. lst == 3 ) then
3313 
3314  abserr = abseps
3315  result = reseps
3316  ktmin = 0
3317 !
3318 ! If IER is not 0, check whether direct result (partial
3319 ! sum) or extrapolated result yields the best integral
3320 ! approximation
3321 !
3322  if ( ( abserr + 1.0d+01 * correc ) <= epsabs ) then
3323  exit
3324  end if
3325 
3326  if ( abserr <= epsabs .and. 1.0d+01 * correc >= epsabs ) then
3327  exit
3328  end if
3329 
3330  end if
3331 
3332  if ( ier /= 0 .and. ier /= 7 ) then
3333  exit
3334  end if
3335 
3336 40 continue
3337 
3338  ll = numrl2
3339  c1 = c2
3340  c2 = c2+cycle
3341 
3342  end do
3343 !
3344 ! Set final result and error estimate.
3345 !
3346 60 continue
3347 
3348  abserr = abserr + 1.0d+01 * correc
3349 
3350  if ( ier == 0 ) then
3351  return
3352  end if
3353 
3354  if ( result /= 0.0d+00 .and. psum(numrl2) /= 0.0d+00) go to 70
3355 
3356  if ( abserr > errsum ) go to 80
3357 
3358  if ( psum(numrl2) == 0.0d+00 ) then
3359  return
3360  end if
3361 
3362 70 continue
3363 
3364  if ( abserr / abs(result) <= (errsum+drl)/abs(psum(numrl2)) ) then
3365 
3366  if ( ier >= 1 .and. ier /= 7 ) then
3367  abserr = abserr + drl
3368  end if
3369 
3370  return
3371 
3372  end if
3373 
3374 80 continue
3375 
3376  result = psum(numrl2)
3377  abserr = errsum + drl
3378 
3379  return
3380 end subroutine
3381 subroutine qawo ( f, a, b, omega, integr, epsabs, epsrel, result, abserr, &
3382  neval, ier )
3383 !
3384 !******************************************************************************
3385 !
3386 !! QAWO computes the integrals of oscillatory integrands.
3387 !
3388 !
3389 ! Discussion:
3390 !
3391 ! The routine calculates an approximation RESULT to a given
3392 ! definite integral
3393 ! I = Integral ( A <= X <= B ) F(X) * cos ( OMEGA * X ) dx
3394 ! or
3395 ! I = Integral ( A <= X <= B ) F(X) * sin ( OMEGA * X ) dx
3396 ! hopefully satisfying following claim for accuracy
3397 ! | I - RESULT | <= max ( epsabs, epsrel * |I| ).
3398 !
3399 ! Reference:
3400 !
3401 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
3402 ! QUADPACK, a Subroutine Package for Automatic Integration,
3403 ! Springer Verlag, 1983
3404 !
3405 ! Parameters:
3406 !
3407 ! Input, external real(r_kind) F, the name of the function routine, of the form
3408 ! function f ( x )
3409 ! real(r_kind) f
3410 ! real(r_kind) x
3411 ! which evaluates the integrand function.
3412 !
3413 ! Input, real(r_kind) A, B, the limits of integration.
3414 !
3415 ! Input, real(r_kind) OMEGA, the parameter in the weight function.
3416 !
3417 ! Input, integer INTEGR, specifies the weight function:
3418 ! 1, W(X) = cos ( OMEGA * X )
3419 ! 2, W(X) = sin ( OMEGA * X )
3420 !
3421 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
3422 !
3423 ! Output, real(r_kind) RESULT, the estimated value of the integral.
3424 !
3425 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
3426 !
3427 ! Output, integer NEVAL, the number of times the integral was evaluated.
3428 !
3429 ! ier - integer
3430 ! ier = 0 normal and reliable termination of the
3431 ! routine. it is assumed that the
3432 ! requested accuracy has been achieved.
3433 ! - ier > 0 abnormal termination of the routine.
3434 ! the estimates for integral and error are
3435 ! less reliable. it is assumed that the
3436 ! requested accuracy has not been achieved.
3437 ! ier = 1 maximum number of subdivisions allowed
3438 ! (= leniw/2) has been achieved. one can
3439 ! allow more subdivisions by increasing the
3440 ! value of leniw (and taking the according
3441 ! dimension adjustments into account).
3442 ! however, if this yields no improvement it
3443 ! is advised to analyze the integrand in
3444 ! order to determine the integration
3445 ! difficulties. if the position of a local
3446 ! difficulty can be determined (e.g.
3447 ! singularity, discontinuity within the
3448 ! interval) one will probably gain from
3449 ! splitting up the interval at this point
3450 ! and calling the integrator on the
3451 ! subranges. if possible, an appropriate
3452 ! special-purpose integrator should
3453 ! be used which is designed for handling
3454 ! the type of difficulty involved.
3455 ! = 2 the occurrence of roundoff error is
3456 ! detected, which prevents the requested
3457 ! tolerance from being achieved.
3458 ! the error may be under-estimated.
3459 ! = 3 extremely bad integrand behavior occurs
3460 ! at some interior points of the integration
3461 ! interval.
3462 ! = 4 the algorithm does not converge. roundoff
3463 ! error is detected in the extrapolation
3464 ! table. it is presumed that the requested
3465 ! tolerance cannot be achieved due to
3466 ! roundoff in the extrapolation table,
3467 ! and that the returned result is the best
3468 ! which can be obtained.
3469 ! = 5 the integral is probably divergent, or
3470 ! slowly convergent. it must be noted that
3471 ! divergence can occur with any other value
3472 ! of ier.
3473 ! = 6 the input is invalid, because
3474 ! epsabs < 0 and epsrel < 0,
3475 ! result, abserr, neval are set to zero.
3476 !
3477 ! Local parameters:
3478 !
3479 ! limit is the maximum number of subintervals allowed in the
3480 ! subdivision process of QFOUR. take care that limit >= 1.
3481 !
3482 ! maxp1 gives an upper bound on the number of Chebyshev moments
3483 ! which can be stored, i.e. for the intervals of lengths
3484 ! abs(b-a)*2**(-l), l = 0, 1, ... , maxp1-2. take care that
3485 ! maxp1 >= 1.
3486 
3487  implicit none
3488 !
3489  integer, parameter :: limit = 500
3490  integer, parameter :: maxp1 = 21
3491 !
3492  real(r_kind) a
3493  real(r_kind) abserr
3494  real(r_kind) alist(limit)
3495  real(r_kind) b
3496  real(r_kind) blist(limit)
3497  real(r_kind) chebmo(maxp1,25)
3498  real(r_kind) elist(limit)
3499  real(r_kind) epsabs
3500  real(r_kind) epsrel
3501  real(r_kind), external :: f
3502  integer ier
3503  integer integr
3504  integer iord(limit)
3505  integer momcom
3506  integer neval
3507  integer nnlog(limit)
3508  real(r_kind) omega
3509  real(r_kind) result
3510  real(r_kind) rlist(limit)
3511 !
3512  call qfour ( f, a, b, omega, integr, epsabs, epsrel, limit, 1, maxp1, &
3513  result, abserr, neval, ier, alist, blist, rlist, elist, iord, nnlog, &
3514  momcom, chebmo )
3515 
3516  return
3517 end subroutine
3518 subroutine qaws ( f, a, b, alfa, beta, integr, epsabs, epsrel, result, &
3519  abserr, neval, ier )
3520 !
3521 !******************************************************************************
3522 !
3523 !! QAWS estimates integrals with algebraico-logarithmic endpoint singularities.
3524 !
3525 !
3526 ! Discussion:
3527 !
3528 ! This routine calculates an approximation RESULT to a given
3529 ! definite integral
3530 ! I = integral of f*w over (a,b)
3531 ! where w shows a singular behavior at the end points, see parameter
3532 ! integr, hopefully satisfying following claim for accuracy
3533 ! abs(i-result) <= max(epsabs,epsrel*abs(i)).
3534 !
3535 ! Reference:
3536 !
3537 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
3538 ! QUADPACK, a Subroutine Package for Automatic Integration,
3539 ! Springer Verlag, 1983
3540 !
3541 ! Parameters:
3542 !
3543 ! Input, external real(r_kind) F, the name of the function routine, of the form
3544 ! function f ( x )
3545 ! real(r_kind) f
3546 ! real(r_kind) x
3547 ! which evaluates the integrand function.
3548 !
3549 ! Input, real(r_kind) A, B, the limits of integration.
3550 !
3551 ! Input, real(r_kind) ALFA, BETA, parameters used in the weight function.
3552 ! ALFA and BETA should be greater than -1.
3553 !
3554 ! Input, integer INTEGR, indicates which weight function is to be used
3555 ! = 1 (x-a)**alfa*(b-x)**beta
3556 ! = 2 (x-a)**alfa*(b-x)**beta*log(x-a)
3557 ! = 3 (x-a)**alfa*(b-x)**beta*log(b-x)
3558 ! = 4 (x-a)**alfa*(b-x)**beta*log(x-a)*log(b-x)
3559 !
3560 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
3561 !
3562 ! Output, real(r_kind) RESULT, the estimated value of the integral.
3563 !
3564 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
3565 !
3566 ! Output, integer NEVAL, the number of times the integral was evaluated.
3567 !
3568 ! ier - integer
3569 ! ier = 0 normal and reliable termination of the
3570 ! routine. it is assumed that the requested
3571 ! accuracy has been achieved.
3572 ! ier > 0 abnormal termination of the routine
3573 ! the estimates for the integral and error
3574 ! are less reliable. it is assumed that the
3575 ! requested accuracy has not been achieved.
3576 ! ier = 1 maximum number of subdivisions allowed
3577 ! has been achieved. one can allow more
3578 ! subdivisions by increasing the data value
3579 ! of limit in qaws (and taking the according
3580 ! dimension adjustments into account).
3581 ! however, if this yields no improvement it
3582 ! is advised to analyze the integrand, in
3583 ! order to determine the integration
3584 ! difficulties which prevent the requested
3585 ! tolerance from being achieved. in case of
3586 ! a jump discontinuity or a local
3587 ! singularity of algebraico-logarithmic type
3588 ! at one or more interior points of the
3589 ! integration range, one should proceed by
3590 ! splitting up the interval at these points
3591 ! and calling the integrator on the
3592 ! subranges.
3593 ! = 2 the occurrence of roundoff error is
3594 ! detected, which prevents the requested
3595 ! tolerance from being achieved.
3596 ! = 3 extremely bad integrand behavior occurs
3597 ! at some points of the integration
3598 ! interval.
3599 ! = 6 the input is invalid, because
3600 ! b <= a or alfa <= (-1) or beta <= (-1) or
3601 ! integr < 1 or integr > 4 or
3602 ! epsabs < 0 and epsrel < 0,
3603 ! result, abserr, neval are set to zero.
3604 !
3605 ! Local parameters:
3606 !
3607 ! LIMIT is the maximum number of subintervals allowed in the
3608 ! subdivision process of qawse. take care that limit >= 2.
3609 !
3610  implicit none
3611 !
3612  integer, parameter :: limit = 500
3613 !
3614  real(r_kind) a
3615  real(r_kind) abserr
3616  real(r_kind) alfa
3617  real(r_kind) alist(limit)
3618  real(r_kind) b
3619  real(r_kind) blist(limit)
3620  real(r_kind) beta
3621  real(r_kind) elist(limit)
3622  real(r_kind) epsabs
3623  real(r_kind) epsrel
3624  real(r_kind), external :: f
3625  integer ier
3626  integer integr
3627  integer iord(limit)
3628  integer last
3629  integer neval
3630  real(r_kind) result
3631  real(r_kind) rlist(limit)
3632 !
3633  call qawse ( f, a, b, alfa, beta, integr, epsabs, epsrel, limit, result, &
3634  abserr, neval, ier, alist, blist, rlist, elist, iord, last )
3635 
3636  return
3637 end subroutine
3638 subroutine qawse ( f, a, b, alfa, beta, integr, epsabs, epsrel, limit, &
3639  result, abserr, neval, ier, alist, blist, rlist, elist, iord, last )
3640 !
3641 !******************************************************************************
3642 !
3643 !! QAWSE estimates integrals with algebraico-logarithmic endpoint singularities.
3644 !
3645 !
3646 ! Discussion:
3647 !
3648 ! This routine calculates an approximation RESULT to an integral
3649 ! I = integral of F(X) * W(X) over (a,b),
3650 ! where W(X) shows a singular behavior at the endpoints, hopefully
3651 ! satisfying:
3652 ! | I - RESULT | <= max ( epsabs, epsrel * |I| ).
3653 !
3654 ! Reference:
3655 !
3656 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
3657 ! QUADPACK, a Subroutine Package for Automatic Integration,
3658 ! Springer Verlag, 1983
3659 !
3660 ! Parameters:
3661 !
3662 ! Input, external real(r_kind) F, the name of the function routine, of the form
3663 ! function f ( x )
3664 ! real(r_kind) f
3665 ! real(r_kind) x
3666 ! which evaluates the integrand function.
3667 !
3668 ! Input, real(r_kind) A, B, the limits of integration.
3669 !
3670 ! Input, real(r_kind) ALFA, BETA, parameters used in the weight function.
3671 ! ALFA and BETA should be greater than -1.
3672 !
3673 ! Input, integer INTEGR, indicates which weight function is used:
3674 ! = 1 (x-a)**alfa*(b-x)**beta
3675 ! = 2 (x-a)**alfa*(b-x)**beta*log(x-a)
3676 ! = 3 (x-a)**alfa*(b-x)**beta*log(b-x)
3677 ! = 4 (x-a)**alfa*(b-x)**beta*log(x-a)*log(b-x)
3678 !
3679 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
3680 !
3681 ! Input, integer LIMIT, an upper bound on the number of subintervals
3682 ! in the partition of (A,B), LIMIT >= 2. If LIMIT < 2, the routine
3683 ! will end with IER = 6.
3684 !
3685 ! Output, real(r_kind) RESULT, the estimated value of the integral.
3686 !
3687 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
3688 !
3689 ! Output, integer NEVAL, the number of times the integral was evaluated.
3690 !
3691 ! ier - integer
3692 ! ier = 0 normal and reliable termination of the
3693 ! routine. it is assumed that the requested
3694 ! accuracy has been achieved.
3695 ! ier > 0 abnormal termination of the routine
3696 ! the estimates for the integral and error
3697 ! are less reliable. it is assumed that the
3698 ! requested accuracy has not been achieved.
3699 ! = 1 maximum number of subdivisions allowed
3700 ! has been achieved. one can allow more
3701 ! subdivisions by increasing the value of
3702 ! limit. however, if this yields no
3703 ! improvement it is advised to analyze the
3704 ! integrand, in order to determine the
3705 ! integration difficulties which prevent
3706 ! the requested tolerance from being
3707 ! achieved. in case of a jump discontinuity
3708 ! or a local singularity of algebraico-
3709 ! logarithmic type at one or more interior
3710 ! points of the integration range, one
3711 ! should proceed by splitting up the
3712 ! interval at these points and calling the
3713 ! integrator on the subranges.
3714 ! = 2 the occurrence of roundoff error is
3715 ! detected, which prevents the requested
3716 ! tolerance from being achieved.
3717 ! = 3 extremely bad integrand behavior occurs
3718 ! at some points of the integration
3719 ! interval.
3720 ! = 6 the input is invalid, because
3721 ! b <= a or alfa <= (-1) or beta <= (-1) or
3722 ! integr < 1 or integr > 4, or
3723 ! epsabs < 0 and epsrel < 0,
3724 ! or limit < 2.
3725 ! result, abserr, neval, rlist(1), elist(1),
3726 ! iord(1) and last are set to zero.
3727 ! alist(1) and blist(1) are set to a and b
3728 ! respectively.
3729 !
3730 ! Workspace, real(r_kind) ALIST(LIMIT), BLIST(LIMIT), contains in entries 1
3731 ! through LAST the left and right ends of the partition subintervals.
3732 !
3733 ! Workspace, real(r_kind) RLIST(LIMIT), contains in entries 1 through LAST
3734 ! the integral approximations on the subintervals.
3735 !
3736 ! Workspace, real(r_kind) ELIST(LIMIT), contains in entries 1 through LAST
3737 ! the absolute error estimates on the subintervals.
3738 !
3739 ! iord - integer
3740 ! vector of dimension at least limit, the first k
3741 ! elements of which are pointers to the error
3742 ! estimates over the subintervals, so that
3743 ! elist(iord(1)), ..., elist(iord(k)) with k = last
3744 ! if last <= (limit/2+2), and k = limit+1-last
3745 ! otherwise, form a decreasing sequence.
3746 !
3747 ! Output, integer LAST, the number of subintervals actually produced in
3748 ! the subdivision process.
3749 !
3750 ! Local parameters:
3751 !
3752 ! alist - list of left end points of all subintervals
3753 ! considered up to now
3754 ! blist - list of right end points of all subintervals
3755 ! considered up to now
3756 ! rlist(i) - approximation to the integral over
3757 ! (alist(i),blist(i))
3758 ! elist(i) - error estimate applying to rlist(i)
3759 ! maxerr - pointer to the interval with largest error
3760 ! estimate
3761 ! errmax - elist(maxerr)
3762 ! area - sum of the integrals over the subintervals
3763 ! errsum - sum of the errors over the subintervals
3764 ! errbnd - requested accuracy max(epsabs,epsrel*
3765 ! abs(result))
3766 ! *****1 - variable for the left subinterval
3767 ! *****2 - variable for the right subinterval
3768 ! last - index for subdivision
3769 !
3770  implicit none
3771 !
3772  integer limit
3773 !
3774  real(r_kind) a
3775  real(r_kind) abserr
3776  real(r_kind) alfa
3777  real(r_kind) alist(limit)
3778  real(r_kind) area
3779  real(r_kind) area1
3780  real(r_kind) area12
3781  real(r_kind) area2
3782  real(r_kind) a1
3783  real(r_kind) a2
3784  real(r_kind) b
3785  real(r_kind) beta
3786  real(r_kind) blist(limit)
3787  real(r_kind) b1
3788  real(r_kind) b2
3789  real(r_kind) centre
3790  real(r_kind) elist(limit)
3791  real(r_kind) epsabs
3792  real(r_kind) epsrel
3793  real(r_kind) errbnd
3794  real(r_kind) errmax
3795  real(r_kind) error1
3796  real(r_kind) erro12
3797  real(r_kind) error2
3798  real(r_kind) errsum
3799  real(r_kind), external :: f
3800  integer ier
3801  integer integr
3802  integer iord(limit)
3803  integer iroff1
3804  integer iroff2
3805  integer last
3806  integer maxerr
3807  integer nev
3808  integer neval
3809  integer nrmax
3810  real(r_kind) resas1
3811  real(r_kind) resas2
3812  real(r_kind) result
3813  real(r_kind) rg(25)
3814  real(r_kind) rh(25)
3815  real(r_kind) ri(25)
3816  real(r_kind) rj(25)
3817  real(r_kind) rlist(limit)
3818 !
3819 ! Test on validity of parameters.
3820 !
3821  ier = 0
3822  neval = 0
3823  last = 0
3824  rlist(1) = 0.0d+00
3825  elist(1) = 0.0d+00
3826  iord(1) = 0
3827  result = 0.0d+00
3828  abserr = 0.0d+00
3829 
3830  if ( b <= a .or. &
3831  (epsabs < 0.0d+00 .and. epsrel < 0.0d+00) .or. &
3832  alfa <= (-1.0d+00) .or. &
3833  beta <= (-1.0d+00) .or. &
3834  integr < 1 .or. &
3835  integr > 4 .or. &
3836  limit < 2) then
3837  ier = 6
3838  return
3839  end if
3840 !
3841 ! Compute the modified Chebyshev moments.
3842 !
3843  call qmomo ( alfa, beta, ri, rj, rg, rh, integr )
3844 !
3845 ! Integrate over the intervals (a,(a+b)/2) and ((a+b)/2,b).
3846 !
3847  centre = 5.0d-01 * ( b + a )
3848 
3849  call qc25s ( f, a, b, a, centre, alfa, beta, ri, rj, rg, rh, area1, &
3850  error1, resas1, integr, nev )
3851 
3852  neval = nev
3853 
3854  call qc25s ( f, a, b, centre, b, alfa, beta, ri, rj, rg, rh, area2, &
3855  error2, resas2, integr, nev )
3856 
3857  last = 2
3858  neval = neval+nev
3859  result = area1+area2
3860  abserr = error1+error2
3861 !
3862 ! Test on accuracy.
3863 !
3864  errbnd = max( epsabs, epsrel * abs( result ) )
3865 !
3866 ! Initialization.
3867 !
3868  if ( error2 <= error1 ) then
3869  alist(1) = a
3870  alist(2) = centre
3871  blist(1) = centre
3872  blist(2) = b
3873  rlist(1) = area1
3874  rlist(2) = area2
3875  elist(1) = error1
3876  elist(2) = error2
3877  else
3878  alist(1) = centre
3879  alist(2) = a
3880  blist(1) = b
3881  blist(2) = centre
3882  rlist(1) = area2
3883  rlist(2) = area1
3884  elist(1) = error2
3885  elist(2) = error1
3886  end if
3887 
3888  iord(1) = 1
3889  iord(2) = 2
3890 
3891  if ( limit == 2 ) then
3892  ier = 1
3893  return
3894  end if
3895 
3896  if ( abserr <= errbnd ) then
3897  return
3898  end if
3899 
3900  errmax = elist(1)
3901  maxerr = 1
3902  nrmax = 1
3903  area = result
3904  errsum = abserr
3905  iroff1 = 0
3906  iroff2 = 0
3907 
3908  do last = 3, limit
3909 !
3910 ! Bisect the subinterval with largest error estimate.
3911 !
3912  a1 = alist(maxerr)
3913  b1 = 5.0d-01 * (alist(maxerr)+blist(maxerr))
3914  a2 = b1
3915  b2 = blist(maxerr)
3916 
3917  call qc25s ( f, a, b, a1, b1, alfa, beta, ri, rj, rg, rh, area1, &
3918  error1, resas1, integr, nev )
3919 
3920  neval = neval + nev
3921 
3922  call qc25s ( f, a, b, a2, b2, alfa, beta, ri, rj, rg, rh, area2, &
3923  error2, resas2, integr, nev )
3924 
3925  neval = neval + nev
3926 !
3927 ! Improve previous approximations integral and error and
3928 ! test for accuracy.
3929 !
3930  area12 = area1+area2
3931  erro12 = error1+error2
3932  errsum = errsum+erro12-errmax
3933  area = area+area12-rlist(maxerr)
3934 !
3935 ! Test for roundoff error.
3936 !
3937  if ( a /= a1 .and. b /= b2 ) then
3938 
3939  if ( resas1 /= error1 .and. resas2 /= error2 ) then
3940 
3941  if ( abs(rlist(maxerr)-area12) < 1.0d-05*abs(area12) &
3942  .and.erro12 >= 9.9d-01*errmax) then
3943  iroff1 = iroff1+1
3944  end if
3945 
3946  if ( last > 10.and.erro12 > errmax ) then
3947  iroff2 = iroff2+1
3948  end if
3949 
3950  end if
3951 
3952  end if
3953 
3954  rlist(maxerr) = area1
3955  rlist(last) = area2
3956 !
3957 ! Test on accuracy.
3958 !
3959  errbnd = max( epsabs, epsrel * abs( area ) )
3960 
3961  if ( errsum > errbnd ) then
3962 !
3963 ! Set error flag in the case that the number of interval
3964 ! bisections exceeds limit.
3965 !
3966  if ( last == limit ) then
3967  ier = 1
3968  end if
3969 !
3970 ! Set error flag in the case of roundoff error.
3971 !
3972  if ( iroff1 >= 6 .or. iroff2 >= 20 ) then
3973  ier = 2
3974  end if
3975 !
3976 ! Set error flag in the case of bad integrand behavior
3977 ! at interior points of integration range.
3978 !
3979  if ( max( abs(a1),abs(b2)) <= (1.0d+00+1.0d+03* epsilon( a1 ) )* &
3980  (abs(a2)+1.0d+03* tiny( a2) )) then
3981  ier = 3
3982  end if
3983 
3984  end if
3985 !
3986 ! Append the newly-created intervals to the list.
3987 !
3988  if ( error2 <= error1 ) then
3989  alist(last) = a2
3990  blist(maxerr) = b1
3991  blist(last) = b2
3992  elist(maxerr) = error1
3993  elist(last) = error2
3994  else
3995  alist(maxerr) = a2
3996  alist(last) = a1
3997  blist(last) = b1
3998  rlist(maxerr) = area2
3999  rlist(last) = area1
4000  elist(maxerr) = error2
4001  elist(last) = error1
4002  end if
4003 !
4004 ! Call QSORT to maintain the descending ordering
4005 ! in the list of error estimates and select the subinterval
4006 ! with largest error estimate (to be bisected next).
4007 !
4008  call qsort ( limit, last, maxerr, errmax, elist, iord, nrmax )
4009 
4010  if (ier /= 0 .or. errsum <= errbnd ) then
4011  exit
4012  end if
4013 
4014  end do
4015 !
4016 ! Compute final result.
4017 !
4018  result = sum( rlist(1:last) )
4019 
4020  abserr = errsum
4021 
4022  return
4023 end subroutine
4024 subroutine qc25c ( f, a, b, c, result, abserr, krul, neval )
4025 !
4026 !******************************************************************************
4027 !
4028 !! QC25C returns integration rules for Cauchy Principal Value integrals.
4029 !
4030 !
4031 ! Discussion:
4032 !
4033 ! This routine estimates
4034 ! I = integral of F(X) * W(X) over (a,b)
4035 ! with error estimate, where
4036 ! w(x) = 1/(x-c)
4037 !
4038 ! Reference:
4039 !
4040 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
4041 ! QUADPACK, a Subroutine Package for Automatic Integration,
4042 ! Springer Verlag, 1983
4043 !
4044 ! Parameters:
4045 !
4046 ! Input, external real(r_kind) F, the name of the function routine, of the form
4047 ! function f ( x )
4048 ! real(r_kind) f
4049 ! real(r_kind) x
4050 ! which evaluates the integrand function.
4051 !
4052 ! Input, real(r_kind) A, B, the limits of integration.
4053 !
4054 ! Input, real(r_kind) C, the parameter in the weight function.
4055 !
4056 ! Output, real(r_kind) RESULT, the estimated value of the integral.
4057 ! RESULT is computed by using a generalized Clenshaw-Curtis method if
4058 ! C lies within ten percent of the integration interval. In the
4059 ! other case the 15-point Kronrod rule obtained by optimal addition
4060 ! of abscissae to the 7-point Gauss rule, is applied.
4061 !
4062 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
4063 !
4064 ! krul - integer
4065 ! key which is decreased by 1 if the 15-point
4066 ! Gauss-Kronrod scheme has been used
4067 !
4068 ! Output, integer NEVAL, the number of times the integral was evaluated.
4069 !
4070 ! Local parameters:
4071 !
4072 ! fval - value of the function f at the points
4073 ! cos(k*pi/24), k = 0, ..., 24
4074 ! cheb12 - Chebyshev series expansion coefficients, for the
4075 ! function f, of degree 12
4076 ! cheb24 - Chebyshev series expansion coefficients, for the
4077 ! function f, of degree 24
4078 ! res12 - approximation to the integral corresponding to the
4079 ! use of cheb12
4080 ! res24 - approximation to the integral corresponding to the
4081 ! use of cheb24
4082 ! qwgtc - external function subprogram defining the weight
4083 ! function
4084 ! hlgth - half-length of the interval
4085 ! centr - mid point of the interval
4086 !
4087  implicit none
4088 !
4089  real(r_kind) a
4090  real(r_kind) abserr
4091  real(r_kind) ak22
4092  real(r_kind) amom0
4093  real(r_kind) amom1
4094  real(r_kind) amom2
4095  real(r_kind) b
4096  real(r_kind) c
4097  real(r_kind) cc
4098  real(r_kind) centr
4099  real(r_kind) cheb12(13)
4100  real(r_kind) cheb24(25)
4101  real(r_kind), external :: f
4102  real(r_kind) fval(25)
4103  real(r_kind) hlgth
4104  integer i
4105  integer isym
4106  integer k
4107  integer kp
4108  integer krul
4109  integer neval
4110  real(r_kind) p2
4111  real(r_kind) p3
4112  real(r_kind) p4
4113  real(r_kind), external :: qwgtc
4114  real(r_kind) resabs
4115  real(r_kind) resasc
4116  real(r_kind) result
4117  real(r_kind) res12
4118  real(r_kind) res24
4119  real(r_kind) u
4120  real(r_kind), parameter, dimension ( 11 ) :: x = (/ &
4121  9.914448613738104d-01, 9.659258262890683d-01, &
4122  9.238795325112868d-01, 8.660254037844386d-01, &
4123  7.933533402912352d-01, 7.071067811865475d-01, &
4124  6.087614290087206d-01, 5.000000000000000d-01, &
4125  3.826834323650898d-01, 2.588190451025208d-01, &
4126  1.305261922200516d-01 /)
4127 !
4128 ! Check the position of C.
4129 !
4130  cc = ( 2.0d+00 * c - b - a ) / ( b - a )
4131 !
4132 ! Apply the 15-point Gauss-Kronrod scheme.
4133 !
4134  if ( abs( cc ) >= 1.1d+00 ) then
4135  krul = krul - 1
4136  call qk15w ( f, qwgtc, c, p2, p3, p4, kp, a, b, result, abserr, &
4137  resabs, resasc )
4138  neval = 15
4139  if ( resasc == abserr ) then
4140  krul = krul+1
4141  end if
4142  return
4143  end if
4144 !
4145 ! Use the generalized Clenshaw-Curtis method.
4146 !
4147  hlgth = 5.0d-01 * ( b - a )
4148  centr = 5.0d-01 * ( b + a )
4149  neval = 25
4150  fval(1) = 5.0d-01 * f(hlgth+centr)
4151  fval(13) = f(centr)
4152  fval(25) = 5.0d-01 * f(centr-hlgth)
4153 
4154  do i = 2, 12
4155  u = hlgth * x(i-1)
4156  isym = 26 - i
4157  fval(i) = f(u+centr)
4158  fval(isym) = f(centr-u)
4159  end do
4160 !
4161 ! Compute the Chebyshev series expansion.
4162 !
4163  call qcheb ( x, fval, cheb12, cheb24 )
4164 !
4165 ! The modified Chebyshev moments are computed by forward
4166 ! recursion, using AMOM0 and AMOM1 as starting values.
4167 !
4168  amom0 = log( abs( ( 1.0d+00 - cc ) / ( 1.0d+00 + cc ) ) )
4169  amom1 = 2.0d+00 + cc * amom0
4170  res12 = cheb12(1) * amom0 + cheb12(2) * amom1
4171  res24 = cheb24(1) * amom0 + cheb24(2) * amom1
4172 
4173  do k = 3, 13
4174  amom2 = 2.0d+00 * cc * amom1 - amom0
4175  ak22 = ( k - 2 ) * ( k - 2 )
4176  if ( ( k / 2 ) * 2 == k ) then
4177  amom2 = amom2 - 4.0d+00 / ( ak22 - 1.0d+00 )
4178  end if
4179  res12 = res12 + cheb12(k) * amom2
4180  res24 = res24 + cheb24(k) * amom2
4181  amom0 = amom1
4182  amom1 = amom2
4183  end do
4184 
4185  do k = 14, 25
4186  amom2 = 2.0d+00 * cc * amom1 - amom0
4187  ak22 = ( k - 2 ) * ( k - 2 )
4188  if ( ( k / 2 ) * 2 == k ) then
4189  amom2 = amom2 - 4.0d+00 / ( ak22 - 1.0d+00 )
4190  end if
4191  res24 = res24 + cheb24(k) * amom2
4192  amom0 = amom1
4193  amom1 = amom2
4194  end do
4195 
4196  result = res24
4197  abserr = abs( res24 - res12 )
4198 
4199  return
4200 end subroutine
4201 subroutine qc25o ( f, a, b, omega, integr, nrmom, maxp1, ksave, result, &
4202  abserr, neval, resabs, resasc, momcom, chebmo )
4203 !
4204 !******************************************************************************
4205 !
4206 !! QC25O returns integration rules for integrands with a COS or SIN factor.
4207 !
4208 !
4209 ! Discussion:
4210 !
4211 ! This routine estimates the integral
4212 ! I = integral of f(x) * w(x) over (a,b)
4213 ! where
4214 ! w(x) = cos(omega*x)
4215 ! or
4216 ! w(x) = sin(omega*x),
4217 ! and estimates
4218 ! J = integral ( A <= X <= B ) |F(X)| dx.
4219 !
4220 ! For small values of OMEGA or small intervals (a,b) the 15-point
4221 ! Gauss-Kronrod rule is used. In all other cases a generalized
4222 ! Clenshaw-Curtis method is used, that is, a truncated Chebyshev
4223 ! expansion of the function F is computed on (a,b), so that the
4224 ! integrand can be written as a sum of terms of the form W(X)*T(K,X),
4225 ! where T(K,X) is the Chebyshev polynomial of degree K. The Chebyshev
4226 ! moments are computed with use of a linear recurrence relation.
4227 !
4228 ! Reference:
4229 !
4230 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
4231 ! QUADPACK, a Subroutine Package for Automatic Integration,
4232 ! Springer Verlag, 1983
4233 !
4234 ! Parameters:
4235 !
4236 ! Input, external real(r_kind) F, the name of the function routine, of the form
4237 ! function f ( x )
4238 ! real(r_kind) f
4239 ! real(r_kind) x
4240 ! which evaluates the integrand function.
4241 !
4242 ! Input, real(r_kind) A, B, the limits of integration.
4243 !
4244 ! Input, real(r_kind) OMEGA, the parameter in the weight function.
4245 !
4246 ! Input, integer INTEGR, indicates which weight function is to be used
4247 ! = 1, w(x) = cos(omega*x)
4248 ! = 2, w(x) = sin(omega*x)
4249 !
4250 ! ?, integer NRMOM, the length of interval (a,b) is equal to the length
4251 ! of the original integration interval divided by
4252 ! 2**nrmom (we suppose that the routine is used in an
4253 ! adaptive integration process, otherwise set
4254 ! nrmom = 0). nrmom must be zero at the first call.
4255 !
4256 ! maxp1 - integer
4257 ! gives an upper bound on the number of Chebyshev
4258 ! moments which can be stored, i.e. for the intervals
4259 ! of lengths abs(bb-aa)*2**(-l), l = 0,1,2, ...,
4260 ! maxp1-2.
4261 !
4262 ! ksave - integer
4263 ! key which is one when the moments for the
4264 ! current interval have been computed
4265 !
4266 ! Output, real(r_kind) RESULT, the estimated value of the integral.
4267 !
4268 ! abserr - real
4269 ! estimate of the modulus of the absolute
4270 ! error, which should equal or exceed abs(i-result)
4271 !
4272 ! Output, integer NEVAL, the number of times the integral was evaluated.
4273 !
4274 ! Output, real(r_kind) RESABS, approximation to the integral J.
4275 !
4276 ! Output, real(r_kind) RESASC, approximation to the integral of abs(F-I/(B-A)).
4277 !
4278 ! on entry and return
4279 ! momcom - integer
4280 ! for each interval length we need to compute
4281 ! the Chebyshev moments. momcom counts the number
4282 ! of intervals for which these moments have already
4283 ! been computed. if nrmom < momcom or ksave = 1,
4284 ! the Chebyshev moments for the interval (a,b)
4285 ! have already been computed and stored, otherwise
4286 ! we compute them and we increase momcom.
4287 !
4288 ! chebmo - real
4289 ! array of dimension at least (maxp1,25) containing
4290 ! the modified Chebyshev moments for the first momcom
4291 ! interval lengths
4292 !
4293 ! Local parameters:
4294 !
4295 ! maxp1 gives an upper bound
4296 ! on the number of Chebyshev moments which can be
4297 ! computed, i.e. for the interval (bb-aa), ...,
4298 ! (bb-aa)/2**(maxp1-2).
4299 ! should this number be altered, the first dimension of
4300 ! chebmo needs to be adapted.
4301 !
4302 ! x contains the values cos(k*pi/24)
4303 ! k = 1, ...,11, to be used for the Chebyshev expansion of f
4304 !
4305 ! centr - mid point of the integration interval
4306 ! hlgth - half length of the integration interval
4307 ! fval - value of the function f at the points
4308 ! (b-a)*0.5*cos(k*pi/12) + (b+a)*0.5
4309 ! k = 0, ...,24
4310 ! cheb12 - coefficients of the Chebyshev series expansion
4311 ! of degree 12, for the function f, in the
4312 ! interval (a,b)
4313 ! cheb24 - coefficients of the Chebyshev series expansion
4314 ! of degree 24, for the function f, in the
4315 ! interval (a,b)
4316 ! resc12 - approximation to the integral of
4317 ! cos(0.5*(b-a)*omega*x)*f(0.5*(b-a)*x+0.5*(b+a))
4318 ! over (-1,+1), using the Chebyshev series
4319 ! expansion of degree 12
4320 ! resc24 - approximation to the same integral, using the
4321 ! Chebyshev series expansion of degree 24
4322 ! ress12 - the analogue of resc12 for the sine
4323 ! ress24 - the analogue of resc24 for the sine
4324 !
4325  implicit none
4326 !
4327  integer maxp1
4328 !
4329  real(r_kind) a
4330  real(r_kind) abserr
4331  real(r_kind) ac
4332  real(r_kind) an
4333  real(r_kind) an2
4334  real(r_kind) as
4335  real(r_kind) asap
4336  real(r_kind) ass
4337  real(r_kind) b
4338  real(r_kind) centr
4339  real(r_kind) chebmo(maxp1,25)
4340  real(r_kind) cheb12(13)
4341  real(r_kind) cheb24(25)
4342  real(r_kind) conc
4343  real(r_kind) cons
4344  real(r_kind) cospar
4345  real(r_kind) d(28)
4346  real(r_kind) d1(28)
4347  real(r_kind) d2(28)
4348  real(r_kind) d3(28)
4349  real(r_kind) estc
4350  real(r_kind) ests
4351  real(r_kind), external :: f
4352  real(r_kind) fval(25)
4353  real(r_kind) hlgth
4354  integer i
4355  integer integr
4356  integer isym
4357  integer j
4358  integer k
4359  integer ksave
4360  integer m
4361  integer momcom
4362  integer neval
4363  integer, parameter :: nmac = 28
4364  integer noeq1
4365  integer noequ
4366  integer nrmom
4367  real(r_kind) omega
4368  real(r_kind) parint
4369  real(r_kind) par2
4370  real(r_kind) par22
4371  real(r_kind) p2
4372  real(r_kind) p3
4373  real(r_kind) p4
4374  real(r_kind), external :: qwgto
4375  real(r_kind) resabs
4376  real(r_kind) resasc
4377  real(r_kind) resc12
4378  real(r_kind) resc24
4379  real(r_kind) ress12
4380  real(r_kind) ress24
4381  real(r_kind) result
4382  real(r_kind) sinpar
4383  real(r_kind) v(28)
4384  real(r_kind), dimension ( 11 ) :: x = (/ &
4385  9.914448613738104d-01, 9.659258262890683d-01, &
4386  9.238795325112868d-01, 8.660254037844386d-01, &
4387  7.933533402912352d-01, 7.071067811865475d-01, &
4388  6.087614290087206d-01, 5.000000000000000d-01, &
4389  3.826834323650898d-01, 2.588190451025208d-01, &
4390  1.305261922200516d-01 /)
4391 !
4392  centr = 5.0d-01*(b+a)
4393  hlgth = 5.0d-01*(b-a)
4394  parint = omega * hlgth
4395 !
4396 ! Compute the integral using the 15-point Gauss-Kronrod
4397 ! formula if the value of the parameter in the integrand
4398 ! is small or if the length of the integration interval
4399 ! is less than (bb-aa)/2**(maxp1-2), where (aa,bb) is the
4400 ! original integration interval.
4401 !
4402  if ( abs( parint ) <= 2.0d+00 ) then
4403 
4404  call qk15w ( f, qwgto, omega, p2, p3, p4, integr, a, b, result, &
4405  abserr, resabs, resasc )
4406 
4407  neval = 15
4408  return
4409 
4410  end if
4411 !
4412 ! Compute the integral using the generalized clenshaw-curtis method.
4413 !
4414  conc = hlgth * cos(centr*omega)
4415  cons = hlgth * sin(centr*omega)
4416  resasc = huge( resasc )
4417  neval = 25
4418 !
4419 ! Check whether the Chebyshev moments for this interval
4420 ! have already been computed.
4421 !
4422  if ( nrmom < momcom .or. ksave == 1 ) go to 140
4423 !
4424 ! Compute a new set of Chebyshev moments.
4425 !
4426  m = momcom+1
4427  par2 = parint*parint
4428  par22 = par2+2.0d+00
4429  sinpar = sin(parint)
4430  cospar = cos(parint)
4431 !
4432 ! Compute the Chebyshev moments with respect to cosine.
4433 !
4434  v(1) = 2.0d+00*sinpar/parint
4435  v(2) = (8.0d+00*cospar+(par2+par2-8.0d+00)*sinpar/ parint)/par2
4436  v(3) = (3.2d+01*(par2-1.2d+01)*cospar+(2.0d+00* &
4437  ((par2-8.0d+01)*par2+1.92d+02)*sinpar)/ &
4438  parint)/(par2*par2)
4439  ac = 8.0d+00*cospar
4440  as = 2.4d+01*parint*sinpar
4441 
4442  if ( abs( parint ) > 2.4d+01 ) then
4443  go to 70
4444  end if
4445 !
4446 ! Compute the Chebyshev moments as the solutions of a boundary value
4447 ! problem with one initial value (v(3)) and one end value computed
4448 ! using an asymptotic formula.
4449 !
4450  noequ = nmac-3
4451  noeq1 = noequ-1
4452  an = 6.0d+00
4453 
4454  do k = 1, noeq1
4455  an2 = an*an
4456  d(k) = -2.0d+00*(an2-4.0d+00)*(par22-an2-an2)
4457  d2(k) = (an-1.0d+00)*(an-2.0d+00)*par2
4458  d1(k) = (an+3.0d+00)*(an+4.0d+00)*par2
4459  v(k+3) = as-(an2-4.0d+00)*ac
4460  an = an+2.0d+00
4461  end do
4462 
4463  an2 = an*an
4464  d(noequ) = -2.0d+00*(an2-4.0d+00)*(par22-an2-an2)
4465  v(noequ+3) = as-(an2-4.0d+00)*ac
4466  v(4) = v(4)-5.6d+01*par2*v(3)
4467  ass = parint*sinpar
4468  asap = (((((2.10d+02*par2-1.0d+00)*cospar-(1.05d+02*par2 &
4469  -6.3d+01)*ass)/an2-(1.0d+00-1.5d+01*par2)*cospar &
4470  +1.5d+01*ass)/an2-cospar+3.0d+00*ass)/an2-cospar)/an2
4471  v(noequ+3) = v(noequ+3)-2.0d+00*asap*par2*(an-1.0d+00)* &
4472  (an-2.0d+00)
4473 !
4474 ! Solve the tridiagonal system by means of Gaussian
4475 ! elimination with partial pivoting.
4476 !
4477  d3(1:noequ) = 0.0d+00
4478 
4479  d2(noequ) = 0.0d+00
4480 
4481  do i = 1, noeq1
4482 
4483  if ( abs(d1(i)) > abs(d(i)) ) then
4484  an = d1(i)
4485  d1(i) = d(i)
4486  d(i) = an
4487  an = d2(i)
4488  d2(i) = d(i+1)
4489  d(i+1) = an
4490  d3(i) = d2(i+1)
4491  d2(i+1) = 0.0d+00
4492  an = v(i+4)
4493  v(i+4) = v(i+3)
4494  v(i+3) = an
4495  end if
4496 
4497  d(i+1) = d(i+1)-d2(i)*d1(i)/d(i)
4498  d2(i+1) = d2(i+1)-d3(i)*d1(i)/d(i)
4499  v(i+4) = v(i+4)-v(i+3)*d1(i)/d(i)
4500 
4501  end do
4502 
4503  v(noequ+3) = v(noequ+3)/d(noequ)
4504  v(noequ+2) = (v(noequ+2)-d2(noeq1)*v(noequ+3))/d(noeq1)
4505 
4506  do i = 2, noeq1
4507  k = noequ-i
4508  v(k+3) = (v(k+3)-d3(k)*v(k+5)-d2(k)*v(k+4))/d(k)
4509  end do
4510 
4511  go to 90
4512 !
4513 ! Compute the Chebyshev moments by means of forward recursion
4514 !
4515 70 continue
4516 
4517  an = 4.0d+00
4518 
4519  do i = 4, 13
4520  an2 = an*an
4521  v(i) = ((an2-4.0d+00)*(2.0d+00*(par22-an2-an2)*v(i-1)-ac) &
4522  +as-par2*(an+1.0d+00)*(an+2.0d+00)*v(i-2))/ &
4523  (par2*(an-1.0d+00)*(an-2.0d+00))
4524  an = an+2.0d+00
4525  end do
4526 
4527 90 continue
4528 
4529  do j = 1, 13
4530  chebmo(m,2*j-1) = v(j)
4531  end do
4532 !
4533 ! Compute the Chebyshev moments with respect to sine.
4534 !
4535  v(1) = 2.0d+00*(sinpar-parint*cospar)/par2
4536  v(2) = (1.8d+01-4.8d+01/par2)*sinpar/par2 &
4537  +(-2.0d+00+4.8d+01/par2)*cospar/parint
4538  ac = -2.4d+01*parint*cospar
4539  as = -8.0d+00*sinpar
4540  chebmo(m,2) = v(1)
4541  chebmo(m,4) = v(2)
4542 
4543  if ( abs(parint) <= 2.4d+01 ) then
4544 
4545  do k = 3, 12
4546  an = k
4547  chebmo(m,2*k) = -sinpar/(an*(2.0d+00*an-2.0d+00)) &
4548  -2.5d-01*parint*(v(k+1)/an-v(k)/(an-1.0d+00))
4549  end do
4550 !
4551 ! Compute the Chebyshev moments by means of forward recursion.
4552 !
4553  else
4554 
4555  an = 3.0d+00
4556 
4557  do i = 3, 12
4558  an2 = an*an
4559  v(i) = ((an2-4.0d+00)*(2.0d+00*(par22-an2-an2)*v(i-1)+as) &
4560  +ac-par2*(an+1.0d+00)*(an+2.0d+00)*v(i-2)) &
4561  /(par2*(an-1.0d+00)*(an-2.0d+00))
4562  an = an+2.0d+00
4563  chebmo(m,2*i) = v(i)
4564  end do
4565 
4566  end if
4567 
4568 140 continue
4569 
4570  if ( nrmom < momcom ) then
4571  m = nrmom + 1
4572  end if
4573 
4574  if ( momcom < maxp1 - 1 .and. nrmom >= momcom ) then
4575  momcom = momcom + 1
4576  end if
4577 !
4578 ! Compute the coefficients of the Chebyshev expansions
4579 ! of degrees 12 and 24 of the function F.
4580 !
4581  fval(1) = 5.0d-01*f(centr+hlgth)
4582  fval(13) = f(centr)
4583  fval(25) = 5.0d-01*f(centr-hlgth)
4584 
4585  do i = 2, 12
4586  isym = 26-i
4587  fval(i) = f(hlgth*x(i-1)+centr)
4588  fval(isym) = f(centr-hlgth*x(i-1))
4589  end do
4590 
4591  call qcheb ( x, fval, cheb12, cheb24 )
4592 !
4593 ! Compute the integral and error estimates.
4594 !
4595  resc12 = cheb12(13) * chebmo(m,13)
4596  ress12 = 0.0d+00
4597  estc = abs( cheb24(25)*chebmo(m,25))+abs((cheb12(13)- &
4598  cheb24(13))*chebmo(m,13) )
4599  ests = 0.0d+00
4600  k = 11
4601 
4602  do j = 1, 6
4603  resc12 = resc12+cheb12(k)*chebmo(m,k)
4604  ress12 = ress12+cheb12(k+1)*chebmo(m,k+1)
4605  estc = estc+abs((cheb12(k)-cheb24(k))*chebmo(m,k))
4606  ests = ests+abs((cheb12(k+1)-cheb24(k+1))*chebmo(m,k+1))
4607  k = k-2
4608  end do
4609 
4610  resc24 = cheb24(25)*chebmo(m,25)
4611  ress24 = 0.0d+00
4612  resabs = abs(cheb24(25))
4613  k = 23
4614 
4615  do j = 1, 12
4616 
4617  resc24 = resc24+cheb24(k)*chebmo(m,k)
4618  ress24 = ress24+cheb24(k+1)*chebmo(m,k+1)
4619  resabs = resabs+abs(cheb24(k))+abs(cheb24(k+1))
4620 
4621  if ( j <= 5 ) then
4622  estc = estc+abs(cheb24(k)*chebmo(m,k))
4623  ests = ests+abs(cheb24(k+1)*chebmo(m,k+1))
4624  end if
4625 
4626  k = k-2
4627 
4628  end do
4629 
4630  resabs = resabs * abs( hlgth )
4631 
4632  if ( integr == 1 ) then
4633  result = conc * resc24-cons*ress24
4634  abserr = abs( conc * estc ) + abs( cons * ests )
4635  else
4636  result = conc*ress24+cons*resc24
4637  abserr = abs(conc*ests)+abs(cons*estc)
4638  end if
4639 
4640  return
4641 end subroutine
4642 subroutine qc25s ( f, a, b, bl, br, alfa, beta, ri, rj, rg, rh, result, &
4643  abserr, resasc, integr, neval )
4644 !
4645 !******************************************************************************
4646 !
4647 !! QC25S returns rules for algebraico-logarithmic end point singularities.
4648 !
4649 !
4650 ! Discussion:
4651 !
4652 ! This routine computes
4653 ! i = integral of F(X) * W(X) over (bl,br),
4654 ! with error estimate, where the weight function W(X) has a singular
4655 ! behavior of algebraico-logarithmic type at the points
4656 ! a and/or b.
4657 !
4658 ! The interval (bl,br) is a subinterval of (a,b).
4659 !
4660 ! Reference:
4661 !
4662 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
4663 ! QUADPACK, a Subroutine Package for Automatic Integration,
4664 ! Springer Verlag, 1983
4665 !
4666 ! Parameters:
4667 !
4668 ! Input, external real(r_kind) F, the name of the function routine, of the form
4669 ! function f ( x )
4670 ! real(r_kind) f
4671 ! real(r_kind) x
4672 ! which evaluates the integrand function.
4673 !
4674 ! Input, real(r_kind) A, B, the limits of integration.
4675 !
4676 ! Input, real(r_kind) BL, BR, the lower and upper limits of integration.
4677 ! A <= BL < BR <= B.
4678 !
4679 ! Input, real(r_kind) ALFA, BETA, parameters in the weight function.
4680 !
4681 ! Input, real(r_kind) RI(25), RJ(25), RG(25), RH(25), modified Chebyshev moments
4682 ! for the application of the generalized Clenshaw-Curtis method,
4683 ! computed in QMOMO.
4684 !
4685 ! Output, real(r_kind) RESULT, the estimated value of the integral, computed by
4686 ! using a generalized clenshaw-curtis method if b1 = a or br = b.
4687 ! In all other cases the 15-point Kronrod rule is applied, obtained by
4688 ! optimal addition of abscissae to the 7-point Gauss rule.
4689 !
4690 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
4691 !
4692 ! Output, real(r_kind) RESASC, approximation to the integral of abs(F*W-I/(B-A)).
4693 !
4694 ! Input, integer INTEGR, determines the weight function
4695 ! 1, w(x) = (x-a)**alfa*(b-x)**beta
4696 ! 2, w(x) = (x-a)**alfa*(b-x)**beta*log(x-a)
4697 ! 3, w(x) = (x-a)**alfa*(b-x)**beta*log(b-x)
4698 ! 4, w(x) = (x-a)**alfa*(b-x)**beta*log(x-a)*log(b-x)
4699 !
4700 ! Output, integer NEVAL, the number of times the integral was evaluated.
4701 !
4702 ! Local Parameters:
4703 !
4704 ! fval - value of the function f at the points
4705 ! (br-bl)*0.5*cos(k*pi/24)+(br+bl)*0.5
4706 ! k = 0, ..., 24
4707 ! cheb12 - coefficients of the Chebyshev series expansion
4708 ! of degree 12, for the function f, in the interval
4709 ! (bl,br)
4710 ! cheb24 - coefficients of the Chebyshev series expansion
4711 ! of degree 24, for the function f, in the interval
4712 ! (bl,br)
4713 ! res12 - approximation to the integral obtained from cheb12
4714 ! res24 - approximation to the integral obtained from cheb24
4715 ! qwgts - external function subprogram defining the four
4716 ! possible weight functions
4717 ! hlgth - half-length of the interval (bl,br)
4718 ! centr - mid point of the interval (bl,br)
4719 !
4720 ! the vector x contains the values cos(k*pi/24)
4721 ! k = 1, ..., 11, to be used for the computation of the
4722 ! Chebyshev series expansion of f.
4723 !
4724  implicit none
4725 !
4726  real(r_kind) a
4727  real(r_kind) abserr
4728  real(r_kind) alfa
4729  real(r_kind) b
4730  real(r_kind) beta
4731  real(r_kind) bl
4732  real(r_kind) br
4733  real(r_kind) centr
4734  real(r_kind) cheb12(13)
4735  real(r_kind) cheb24(25)
4736  real(r_kind) dc
4737  real(r_kind), external :: f
4738  real(r_kind) factor
4739  real(r_kind) fix
4740  real(r_kind) fval(25)
4741  real(r_kind) hlgth
4742  integer i
4743  integer integr
4744  integer isym
4745  integer neval
4746  real(r_kind), external :: qwgts
4747  real(r_kind) resabs
4748  real(r_kind) resasc
4749  real(r_kind) result
4750  real(r_kind) res12
4751  real(r_kind) res24
4752  real(r_kind) rg(25)
4753  real(r_kind) rh(25)
4754  real(r_kind) ri(25)
4755  real(r_kind) rj(25)
4756  real(r_kind) u
4757  real(r_kind), dimension ( 11 ) :: x = (/ &
4758  9.914448613738104d-01, 9.659258262890683d-01, &
4759  9.238795325112868d-01, 8.660254037844386d-01, &
4760  7.933533402912352d-01, 7.071067811865475d-01, &
4761  6.087614290087206d-01, 5.000000000000000d-01, &
4762  3.826834323650898d-01, 2.588190451025208d-01, &
4763  1.305261922200516d-01 /)
4764 !
4765  neval = 25
4766 
4767  if ( bl == a .and. (alfa /= 0.0d+00 .or. integr == 2 .or. integr == 4)) &
4768  go to 10
4769 
4770  if ( br == b .and. (beta /= 0.0d+00 .or. integr == 3 .or. integr == 4)) &
4771  go to 140
4772 !
4773 ! If a > bl and b < br, apply the 15-point Gauss-Kronrod scheme.
4774 !
4775  call qk15w ( f, qwgts, a, b, alfa, beta, integr, bl, br, result, abserr, &
4776  resabs, resasc )
4777 
4778  neval = 15
4779  return
4780 !
4781 ! This part of the program is executed only if a = bl.
4782 !
4783 ! Compute the Chebyshev series expansion of the function
4784 ! f1 = (0.5*(b+b-br-a)-0.5*(br-a)*x)**beta*f(0.5*(br-a)*x+0.5*(br+a))
4785 !
4786 10 continue
4787 
4788  hlgth = 5.0d-01*(br-bl)
4789  centr = 5.0d-01*(br+bl)
4790  fix = b-centr
4791  fval(1) = 5.0d-01*f(hlgth+centr)*(fix-hlgth)**beta
4792  fval(13) = f(centr)*(fix**beta)
4793  fval(25) = 5.0d-01*f(centr-hlgth)*(fix+hlgth)**beta
4794 
4795  do i = 2, 12
4796  u = hlgth*x(i-1)
4797  isym = 26-i
4798  fval(i) = f(u+centr)*(fix-u)**beta
4799  fval(isym) = f(centr-u)*(fix+u)**beta
4800  end do
4801 
4802  factor = hlgth**(alfa+1.0d+00)
4803  result = 0.0d+00
4804  abserr = 0.0d+00
4805  res12 = 0.0d+00
4806  res24 = 0.0d+00
4807 
4808  if ( integr > 2 ) go to 70
4809 
4810  call qcheb ( x, fval, cheb12, cheb24 )
4811 !
4812 ! integr = 1 (or 2)
4813 !
4814  do i = 1, 13
4815  res12 = res12+cheb12(i)*ri(i)
4816  res24 = res24+cheb24(i)*ri(i)
4817  end do
4818 
4819  do i = 14, 25
4820  res24 = res24 + cheb24(i) * ri(i)
4821  end do
4822 
4823  if ( integr == 1 ) go to 130
4824 !
4825 ! integr = 2
4826 !
4827  dc = log( br - bl )
4828  result = res24 * dc
4829  abserr = abs((res24-res12)*dc)
4830  res12 = 0.0d+00
4831  res24 = 0.0d+00
4832 
4833  do i = 1, 13
4834  res12 = res12+cheb12(i)*rg(i)
4835  res24 = res24+cheb24(i)*rg(i)
4836  end do
4837 
4838  do i = 14, 25
4839  res24 = res24+cheb24(i)*rg(i)
4840  end do
4841 
4842  go to 130
4843 !
4844 ! Compute the Chebyshev series expansion of the function
4845 ! F4 = f1*log(0.5*(b+b-br-a)-0.5*(br-a)*x)
4846 !
4847 70 continue
4848 
4849  fval(1) = fval(1) * log( fix - hlgth )
4850  fval(13) = fval(13) * log( fix )
4851  fval(25) = fval(25) * log( fix + hlgth )
4852 
4853  do i = 2, 12
4854  u = hlgth*x(i-1)
4855  isym = 26-i
4856  fval(i) = fval(i) * log( fix - u )
4857  fval(isym) = fval(isym) * log( fix + u )
4858  end do
4859 
4860  call qcheb ( x, fval, cheb12, cheb24 )
4861 !
4862 ! integr = 3 (or 4)
4863 !
4864  do i = 1, 13
4865  res12 = res12+cheb12(i)*ri(i)
4866  res24 = res24+cheb24(i)*ri(i)
4867  end do
4868 
4869  do i = 14, 25
4870  res24 = res24+cheb24(i)*ri(i)
4871  end do
4872 
4873  if ( integr == 3 ) go to 130
4874 !
4875 ! integr = 4
4876 !
4877  dc = log( br - bl )
4878  result = res24*dc
4879  abserr = abs((res24-res12)*dc)
4880  res12 = 0.0d+00
4881  res24 = 0.0d+00
4882 
4883  do i = 1, 13
4884  res12 = res12+cheb12(i)*rg(i)
4885  res24 = res24+cheb24(i)*rg(i)
4886  end do
4887 
4888  do i = 14, 25
4889  res24 = res24+cheb24(i)*rg(i)
4890  end do
4891 
4892 130 continue
4893 
4894  result = (result+res24)*factor
4895  abserr = (abserr+abs(res24-res12))*factor
4896  go to 270
4897 !
4898 ! This part of the program is executed only if b = br.
4899 !
4900 ! Compute the Chebyshev series expansion of the function
4901 ! f2 = (0.5*(b+bl-a-a)+0.5*(b-bl)*x)**alfa*f(0.5*(b-bl)*x+0.5*(b+bl))
4902 !
4903 140 continue
4904 
4905  hlgth = 5.0d-01*(br-bl)
4906  centr = 5.0d-01*(br+bl)
4907  fix = centr-a
4908  fval(1) = 5.0d-01*f(hlgth+centr)*(fix+hlgth)**alfa
4909  fval(13) = f(centr)*(fix**alfa)
4910  fval(25) = 5.0d-01*f(centr-hlgth)*(fix-hlgth)**alfa
4911 
4912  do i = 2, 12
4913  u = hlgth*x(i-1)
4914  isym = 26-i
4915  fval(i) = f(u+centr)*(fix+u)**alfa
4916  fval(isym) = f(centr-u)*(fix-u)**alfa
4917  end do
4918 
4919  factor = hlgth**(beta+1.0d+00)
4920  result = 0.0d+00
4921  abserr = 0.0d+00
4922  res12 = 0.0d+00
4923  res24 = 0.0d+00
4924 
4925  if ( integr == 2 .or. integr == 4 ) go to 200
4926 !
4927 ! integr = 1 (or 3)
4928 !
4929  call qcheb ( x, fval, cheb12, cheb24 )
4930 
4931  do i = 1, 13
4932  res12 = res12+cheb12(i)*rj(i)
4933  res24 = res24+cheb24(i)*rj(i)
4934  end do
4935 
4936  do i = 14, 25
4937  res24 = res24+cheb24(i)*rj(i)
4938  end do
4939 
4940  if ( integr == 1 ) go to 260
4941 !
4942 ! integr = 3
4943 !
4944  dc = log( br - bl )
4945  result = res24*dc
4946  abserr = abs((res24-res12)*dc)
4947  res12 = 0.0d+00
4948  res24 = 0.0d+00
4949 
4950  do i = 1, 13
4951  res12 = res12+cheb12(i)*rh(i)
4952  res24 = res24+cheb24(i)*rh(i)
4953  end do
4954 
4955  do i = 14, 25
4956  res24 = res24+cheb24(i)*rh(i)
4957  end do
4958 
4959  go to 260
4960 !
4961 ! Compute the Chebyshev series expansion of the function
4962 ! f3 = f2*log(0.5*(b-bl)*x+0.5*(b+bl-a-a))
4963 !
4964 200 continue
4965 
4966  fval(1) = fval(1) * log( hlgth + fix )
4967  fval(13) = fval(13) * log( fix )
4968  fval(25) = fval(25) * log( fix - hlgth )
4969 
4970  do i = 2, 12
4971  u = hlgth*x(i-1)
4972  isym = 26-i
4973  fval(i) = fval(i) * log(u+fix)
4974  fval(isym) = fval(isym) * log(fix-u)
4975  end do
4976 
4977  call qcheb ( x, fval, cheb12, cheb24 )
4978 !
4979 ! integr = 2 (or 4)
4980 !
4981  do i = 1, 13
4982  res12 = res12+cheb12(i)*rj(i)
4983  res24 = res24+cheb24(i)*rj(i)
4984  end do
4985 
4986  do i = 14, 25
4987  res24 = res24+cheb24(i)*rj(i)
4988  end do
4989 
4990  if ( integr == 2 ) go to 260
4991 
4992  dc = log(br-bl)
4993  result = res24*dc
4994  abserr = abs((res24-res12)*dc)
4995  res12 = 0.0d+00
4996  res24 = 0.0d+00
4997 !
4998 ! integr = 4
4999 !
5000  do i = 1, 13
5001  res12 = res12+cheb12(i)*rh(i)
5002  res24 = res24+cheb24(i)*rh(i)
5003  end do
5004 
5005  do i = 14, 25
5006  res24 = res24+cheb24(i)*rh(i)
5007  end do
5008 
5009 260 continue
5010 
5011  result = (result+res24)*factor
5012  abserr = (abserr+abs(res24-res12))*factor
5013 
5014 270 continue
5015 
5016  return
5017 end subroutine
5018 subroutine qcheb ( x, fval, cheb12, cheb24 )
5019 !
5020 !******************************************************************************
5021 !
5022 !! QCHEB computes the Chebyshev series expansion.
5023 !
5024 !
5025 ! Discussion:
5026 !
5027 ! This routine computes the Chebyshev series expansion
5028 ! of degrees 12 and 24 of a function using a fast Fourier transform method
5029 !
5030 ! f(x) = sum(k=1, ...,13) (cheb12(k)*t(k-1,x)),
5031 ! f(x) = sum(k=1, ...,25) (cheb24(k)*t(k-1,x)),
5032 !
5033 ! where T(K,X) is the Chebyshev polynomial of degree K.
5034 !
5035 ! Reference:
5036 !
5037 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
5038 ! QUADPACK, a Subroutine Package for Automatic Integration,
5039 ! Springer Verlag, 1983
5040 !
5041 ! Parameters:
5042 !
5043 ! Input, real(r_kind) X(11), contains the values of COS(K*PI/24), for K = 1 to 11.
5044 !
5045 ! Input/output, real(r_kind) FVAL(25), the function values at the points
5046 ! (b+a+(b-a)*cos(k*pi/24))/2, k = 0, ...,24, where (a,b) is the
5047 ! approximation interval. FVAL(1) and FVAL(25) are divided by two
5048 ! These values are destroyed at output.
5049 !
5050 ! on return
5051 ! cheb12 - real
5052 ! vector of dimension 13 containing the Chebyshev
5053 ! coefficients for degree 12
5054 !
5055 ! cheb24 - real
5056 ! vector of dimension 25 containing the Chebyshev
5057 ! coefficients for degree 24
5058 !
5059  implicit none
5060 !
5061  real(r_kind) alam
5062  real(r_kind) alam1
5063  real(r_kind) alam2
5064  real(r_kind) cheb12(13)
5065  real(r_kind) cheb24(25)
5066  real(r_kind) fval(25)
5067  integer i
5068  integer j
5069  real(r_kind) part1
5070  real(r_kind) part2
5071  real(r_kind) part3
5072  real(r_kind) v(12)
5073  real(r_kind) x(11)
5074 !
5075  do i = 1, 12
5076  j = 26-i
5077  v(i) = fval(i)-fval(j)
5078  fval(i) = fval(i)+fval(j)
5079  end do
5080 
5081  alam1 = v(1)-v(9)
5082  alam2 = x(6)*(v(3)-v(7)-v(11))
5083  cheb12(4) = alam1+alam2
5084  cheb12(10) = alam1-alam2
5085  alam1 = v(2)-v(8)-v(10)
5086  alam2 = v(4)-v(6)-v(12)
5087  alam = x(3)*alam1+x(9)*alam2
5088  cheb24(4) = cheb12(4)+alam
5089  cheb24(22) = cheb12(4)-alam
5090  alam = x(9)*alam1-x(3)*alam2
5091  cheb24(10) = cheb12(10)+alam
5092  cheb24(16) = cheb12(10)-alam
5093  part1 = x(4)*v(5)
5094  part2 = x(8)*v(9)
5095  part3 = x(6)*v(7)
5096  alam1 = v(1)+part1+part2
5097  alam2 = x(2)*v(3)+part3+x(10)*v(11)
5098  cheb12(2) = alam1+alam2
5099  cheb12(12) = alam1-alam2
5100  alam = x(1)*v(2)+x(3)*v(4)+x(5)*v(6)+x(7)*v(8) &
5101  +x(9)*v(10)+x(11)*v(12)
5102  cheb24(2) = cheb12(2)+alam
5103  cheb24(24) = cheb12(2)-alam
5104  alam = x(11)*v(2)-x(9)*v(4)+x(7)*v(6)-x(5)*v(8) &
5105  +x(3)*v(10)-x(1)*v(12)
5106  cheb24(12) = cheb12(12)+alam
5107  cheb24(14) = cheb12(12)-alam
5108  alam1 = v(1)-part1+part2
5109  alam2 = x(10)*v(3)-part3+x(2)*v(11)
5110  cheb12(6) = alam1+alam2
5111  cheb12(8) = alam1-alam2
5112  alam = x(5)*v(2)-x(9)*v(4)-x(1)*v(6) &
5113  -x(11)*v(8)+x(3)*v(10)+x(7)*v(12)
5114  cheb24(6) = cheb12(6)+alam
5115  cheb24(20) = cheb12(6)-alam
5116  alam = x(7)*v(2)-x(3)*v(4)-x(11)*v(6)+x(1)*v(8) &
5117  -x(9)*v(10)-x(5)*v(12)
5118  cheb24(8) = cheb12(8)+alam
5119  cheb24(18) = cheb12(8)-alam
5120 
5121  do i = 1, 6
5122  j = 14-i
5123  v(i) = fval(i)-fval(j)
5124  fval(i) = fval(i)+fval(j)
5125  end do
5126 
5127  alam1 = v(1)+x(8)*v(5)
5128  alam2 = x(4)*v(3)
5129  cheb12(3) = alam1+alam2
5130  cheb12(11) = alam1-alam2
5131  cheb12(7) = v(1)-v(5)
5132  alam = x(2)*v(2)+x(6)*v(4)+x(10)*v(6)
5133  cheb24(3) = cheb12(3)+alam
5134  cheb24(23) = cheb12(3)-alam
5135  alam = x(6)*(v(2)-v(4)-v(6))
5136  cheb24(7) = cheb12(7)+alam
5137  cheb24(19) = cheb12(7)-alam
5138  alam = x(10)*v(2)-x(6)*v(4)+x(2)*v(6)
5139  cheb24(11) = cheb12(11)+alam
5140  cheb24(15) = cheb12(11)-alam
5141 
5142  do i = 1, 3
5143  j = 8-i
5144  v(i) = fval(i)-fval(j)
5145  fval(i) = fval(i)+fval(j)
5146  end do
5147 
5148  cheb12(5) = v(1)+x(8)*v(3)
5149  cheb12(9) = fval(1)-x(8)*fval(3)
5150  alam = x(4)*v(2)
5151  cheb24(5) = cheb12(5)+alam
5152  cheb24(21) = cheb12(5)-alam
5153  alam = x(8)*fval(2)-fval(4)
5154  cheb24(9) = cheb12(9)+alam
5155  cheb24(17) = cheb12(9)-alam
5156  cheb12(1) = fval(1)+fval(3)
5157  alam = fval(2)+fval(4)
5158  cheb24(1) = cheb12(1)+alam
5159  cheb24(25) = cheb12(1)-alam
5160  cheb12(13) = v(1)-v(3)
5161  cheb24(13) = cheb12(13)
5162  alam = 1.0d+00/6.0d+00
5163 
5164  do i = 2, 12
5165  cheb12(i) = cheb12(i)*alam
5166  end do
5167 
5168  alam = 5.0d-01*alam
5169  cheb12(1) = cheb12(1)*alam
5170  cheb12(13) = cheb12(13)*alam
5171 
5172  do i = 2, 24
5173  cheb24(i) = cheb24(i)*alam
5174  end do
5175 
5176  cheb24(1) = 0.5d+00 * alam*cheb24(1)
5177  cheb24(25) = 0.5d+00 * alam*cheb24(25)
5178 
5179  return
5180 end subroutine
5181 subroutine qextr ( n, epstab, result, abserr, res3la, nres )
5182 !
5183 !******************************************************************************
5184 !
5185 !! QEXTR carries out the Epsilon extrapolation algorithm.
5186 !
5187 !
5188 ! Discussion:
5189 !
5190 ! The routine determines the limit of a given sequence of approximations,
5191 ! by means of the epsilon algorithm of P. Wynn. An estimate of the
5192 ! absolute error is also given. The condensed epsilon table is computed.
5193 ! Only those elements needed for the computation of the next diagonal
5194 ! are preserved.
5195 !
5196 ! Reference:
5197 !
5198 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
5199 ! QUADPACK, a Subroutine Package for Automatic Integration,
5200 ! Springer Verlag, 1983
5201 !
5202 ! Parameters:
5203 !
5204 ! Input, integer N, indicates the entry of EPSTAB which contains
5205 ! the new element in the first column of the epsilon table.
5206 !
5207 ! Input/output, real(r_kind) EPSTAB(52), the two lower diagonals of the triangular
5208 ! epsilon table. The elements are numbered starting at the right-hand
5209 ! corner of the triangle.
5210 !
5211 ! Output, real(r_kind) RESULT, the estimated value of the integral.
5212 !
5213 ! Output, real(r_kind) ABSERR, estimate of the absolute error computed from
5214 ! RESULT and the 3 previous results.
5215 !
5216 ! ?, real(r_kind) RES3LA(3), the last 3 results.
5217 !
5218 ! Input/output, integer NRES, the number of calls to the routine. This
5219 ! should be zero on the first call, and is automatically updated
5220 ! before return.
5221 !
5222 ! Local Parameters:
5223 !
5224 ! e0 - the 4 elements on which the
5225 ! e1 computation of a new element in
5226 ! e2 the epsilon table is based
5227 ! e3 e0
5228 ! e3 e1 new
5229 ! e2
5230 ! newelm - number of elements to be computed in the new
5231 ! diagonal
5232 ! error - error = abs(e1-e0)+abs(e2-e1)+abs(new-e2)
5233 ! result - the element in the new diagonal with least value
5234 ! of error
5235 ! limexp is the maximum number of elements the epsilon table
5236 ! can contain. if this number is reached, the upper diagonal
5237 ! of the epsilon table is deleted.
5238 !
5239  implicit none
5240 !
5241  real(r_kind) abserr
5242  real(r_kind) delta1
5243  real(r_kind) delta2
5244  real(r_kind) delta3
5245  real(r_kind) epsinf
5246  real(r_kind) epstab(52)
5247  real(r_kind) error
5248  real(r_kind) err1
5249  real(r_kind) err2
5250  real(r_kind) err3
5251  real(r_kind) e0
5252  real(r_kind) e1
5253  real(r_kind) e1abs
5254  real(r_kind) e2
5255  real(r_kind) e3
5256  integer i
5257  integer ib
5258  integer ib2
5259  integer ie
5260  integer indx
5261  integer k1
5262  integer k2
5263  integer k3
5264  integer limexp
5265  integer n
5266  integer newelm
5267  integer nres
5268  integer num
5269  real(r_kind) res
5270  real(r_kind) result
5271  real(r_kind) res3la(3)
5272  real(r_kind) ss
5273  real(r_kind) tol1
5274  real(r_kind) tol2
5275  real(r_kind) tol3
5276 !
5277  nres = nres+1
5278  abserr = huge( abserr )
5279  result = epstab(n)
5280 
5281  if ( n < 3 ) go to 100
5282  limexp = 50
5283  epstab(n+2) = epstab(n)
5284  newelm = (n-1)/2
5285  epstab(n) = huge( epstab(n) )
5286  num = n
5287  k1 = n
5288 
5289  do i = 1, newelm
5290 
5291  k2 = k1-1
5292  k3 = k1-2
5293  res = epstab(k1+2)
5294  e0 = epstab(k3)
5295  e1 = epstab(k2)
5296  e2 = res
5297  e1abs = abs(e1)
5298  delta2 = e2-e1
5299  err2 = abs(delta2)
5300  tol2 = max( abs(e2),e1abs)* epsilon( e2 )
5301  delta3 = e1-e0
5302  err3 = abs(delta3)
5303  tol3 = max( e1abs,abs(e0))* epsilon( e0 )
5304 !
5305 ! If e0, e1 and e2 are equal to within machine accuracy, convergence
5306 ! is assumed.
5307 !
5308  if ( err2 <= tol2 .and. err3 <= tol3 ) then
5309  result = res
5310  abserr = err2+err3
5311  go to 100
5312  end if
5313 
5314  e3 = epstab(k1)
5315  epstab(k1) = e1
5316  delta1 = e1-e3
5317  err1 = abs(delta1)
5318  tol1 = max( e1abs,abs(e3))* epsilon( e3 )
5319 !
5320 ! If two elements are very close to each other, omit a part
5321 ! of the table by adjusting the value of N.
5322 !
5323  if ( err1 <= tol1 .or. err2 <= tol2 .or. err3 <= tol3 ) go to 20
5324 
5325  ss = 1.0d+00/delta1+1.0d+00/delta2-1.0d+00/delta3
5326  epsinf = abs( ss*e1 )
5327 !
5328 ! Test to detect irregular behavior in the table, and
5329 ! eventually omit a part of the table adjusting the value of N.
5330 !
5331  if ( epsinf > 1.0d-04 ) go to 30
5332 
5333 20 continue
5334 
5335  n = i+i-1
5336  exit
5337 !
5338 ! Compute a new element and eventually adjust the value of RESULT.
5339 !
5340 30 continue
5341 
5342  res = e1+1.0d+00/ss
5343  epstab(k1) = res
5344  k1 = k1-2
5345  error = err2+abs(res-e2)+err3
5346 
5347  if ( error <= abserr ) then
5348  abserr = error
5349  result = res
5350  end if
5351 
5352  end do
5353 !
5354 ! Shift the table.
5355 !
5356  if ( n == limexp ) then
5357  n = 2*(limexp/2)-1
5358  end if
5359 
5360  if ( (num/2)*2 == num ) then
5361  ib = 2
5362  else
5363  ib = 1
5364  end if
5365 
5366  ie = newelm+1
5367 
5368  do i = 1, ie
5369  ib2 = ib+2
5370  epstab(ib) = epstab(ib2)
5371  ib = ib2
5372  end do
5373 
5374  if ( num /= n ) then
5375 
5376  indx = num-n+1
5377 
5378  do i = 1, n
5379  epstab(i)= epstab(indx)
5380  indx = indx+1
5381  end do
5382 
5383  end if
5384 
5385  if ( nres < 4 ) then
5386  res3la(nres) = result
5387  abserr = huge( abserr )
5388  else
5389  abserr = abs(result-res3la(3))+abs(result-res3la(2)) &
5390  +abs(result-res3la(1))
5391  res3la(1) = res3la(2)
5392  res3la(2) = res3la(3)
5393  res3la(3) = result
5394  end if
5395 
5396 100 continue
5397 
5398  abserr = max( abserr,0.5d+00* epsilon( result ) *abs(result))
5399 
5400  return
5401 end subroutine
5402 subroutine qfour ( f, a, b, omega, integr, epsabs, epsrel, limit, icall, &
5403  maxp1, result, abserr, neval, ier, alist, blist, rlist, elist, iord, &
5404  nnlog, momcom, chebmo )
5405 !
5406 !******************************************************************************
5407 !
5408 !! QFOUR estimates the integrals of oscillatory functions.
5409 !
5410 !
5411 ! Discussion:
5412 !
5413 ! This routine calculates an approximation RESULT to a definite integral
5414 ! I = integral of F(X) * COS(OMEGA*X)
5415 ! or
5416 ! I = integral of F(X) * SIN(OMEGA*X)
5417 ! over (A,B), hopefully satisfying:
5418 ! | I - RESULT | <= max ( epsabs, epsrel * |I| ) ).
5419 !
5420 ! QFOUR is called by QAWO and QAWF. It can also be called directly in
5421 ! a user-written program. In the latter case it is possible for the
5422 ! user to determine the first dimension of array CHEBMO(MAXP1,25).
5423 ! See also parameter description of MAXP1. Additionally see
5424 ! parameter description of ICALL for eventually rd-using
5425 ! Chebyshev moments computed during former call on subinterval
5426 ! of equal length abs(B-A).
5427 !
5428 ! Reference:
5429 !
5430 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
5431 ! QUADPACK, a Subroutine Package for Automatic Integration,
5432 ! Springer Verlag, 1983
5433 !
5434 ! Parameters:
5435 !
5436 ! Input, external real(r_kind) F, the name of the function routine, of the form
5437 ! function f ( x )
5438 ! real(r_kind) f
5439 ! real(r_kind) x
5440 ! which evaluates the integrand function.
5441 !
5442 ! Input, real(r_kind) A, B, the limits of integration.
5443 !
5444 ! Input, real(r_kind) OMEGA, the multiplier of X in the weight function.
5445 !
5446 ! Input, integer INTEGR, indicates the weight functions to be used.
5447 ! = 1, w(x) = cos(omega*x)
5448 ! = 2, w(x) = sin(omega*x)
5449 !
5450 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
5451 !
5452 ! Input, integer LIMIT, the maximum number of subintervals of [A,B]
5453 ! that can be generated.
5454 !
5455 ! icall - integer
5456 ! if qfour is to be used only once, ICALL must
5457 ! be set to 1. assume that during this call, the
5458 ! Chebyshev moments (for clenshaw-curtis integration
5459 ! of degree 24) have been computed for intervals of
5460 ! lenghts (abs(b-a))*2**(-l), l=0,1,2,...momcom-1.
5461 ! the Chebyshev moments already computed can be
5462 ! rd-used in subsequent calls, if qfour must be
5463 ! called twice or more times on intervals of the
5464 ! same length abs(b-a). from the second call on, one
5465 ! has to put then ICALL > 1.
5466 ! if ICALL < 1, the routine will end with ier = 6.
5467 !
5468 ! maxp1 - integer
5469 ! gives an upper bound on the number of
5470 ! Chebyshev moments which can be stored, i.e.
5471 ! for the intervals of lenghts abs(b-a)*2**(-l),
5472 ! l=0,1, ..., maxp1-2, maxp1 >= 1.
5473 ! if maxp1 < 1, the routine will end with ier = 6.
5474 ! increasing (decreasing) the value of maxp1
5475 ! decreases (increases) the computational time but
5476 ! increases (decreases) the required memory space.
5477 !
5478 ! Output, real(r_kind) RESULT, the estimated value of the integral.
5479 !
5480 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
5481 !
5482 ! Output, integer NEVAL, the number of times the integral was evaluated.
5483 !
5484 ! ier - integer
5485 ! ier = 0 normal and reliable termination of the
5486 ! routine. it is assumed that the
5487 ! requested accuracy has been achieved.
5488 ! - ier > 0 abnormal termination of the routine.
5489 ! the estimates for integral and error are
5490 ! less reliable. it is assumed that the
5491 ! requested accuracy has not been achieved.
5492 ! ier = 1 maximum number of subdivisions allowed
5493 ! has been achieved. one can allow more
5494 ! subdivisions by increasing the value of
5495 ! limit (and taking according dimension
5496 ! adjustments into account). however, if
5497 ! this yields no improvement it is advised
5498 ! to analyze the integrand, in order to
5499 ! determine the integration difficulties.
5500 ! if the position of a local difficulty can
5501 ! be determined (e.g. singularity,
5502 ! discontinuity within the interval) one
5503 ! will probably gain from splitting up the
5504 ! interval at this point and calling the
5505 ! integrator on the subranges. if possible,
5506 ! an appropriate special-purpose integrator
5507 ! should be used which is designed for
5508 ! handling the type of difficulty involved.
5509 ! = 2 the occurrence of roundoff error is
5510 ! detected, which prevents the requested
5511 ! tolerance from being achieved.
5512 ! the error may be under-estimated.
5513 ! = 3 extremely bad integrand behavior occurs
5514 ! at some points of the integration
5515 ! interval.
5516 ! = 4 the algorithm does not converge. roundoff
5517 ! error is detected in the extrapolation
5518 ! table. it is presumed that the requested
5519 ! tolerance cannot be achieved due to
5520 ! roundoff in the extrapolation table, and
5521 ! that the returned result is the best which
5522 ! can be obtained.
5523 ! = 5 the integral is probably divergent, or
5524 ! slowly convergent. it must be noted that
5525 ! divergence can occur with any other value
5526 ! of ier > 0.
5527 ! = 6 the input is invalid, because
5528 ! epsabs < 0 and epsrel < 0,
5529 ! or (integr /= 1 and integr /= 2) or
5530 ! ICALL < 1 or maxp1 < 1.
5531 ! result, abserr, neval, last, rlist(1),
5532 ! elist(1), iord(1) and nnlog(1) are set to
5533 ! zero. alist(1) and blist(1) are set to a
5534 ! and b respectively.
5535 !
5536 ! Workspace, real(r_kind) ALIST(LIMIT), BLIST(LIMIT), contains in entries 1
5537 ! through LAST the left and right ends of the partition subintervals.
5538 !
5539 ! Workspace, real(r_kind) RLIST(LIMIT), contains in entries 1 through LAST
5540 ! the integral approximations on the subintervals.
5541 !
5542 ! Workspace, real(r_kind) ELIST(LIMIT), contains in entries 1 through LAST
5543 ! the absolute error estimates on the subintervals.
5544 !
5545 ! iord - integer
5546 ! vector of dimension at least limit, the first k
5547 ! elements of which are pointers to the error
5548 ! estimates over the subintervals, such that
5549 ! elist(iord(1)), ..., elist(iord(k)), form
5550 ! a decreasing sequence, with k = last
5551 ! if last <= (limit/2+2), and
5552 ! k = limit+1-last otherwise.
5553 !
5554 ! nnlog - integer
5555 ! vector of dimension at least limit, indicating the
5556 ! subdivision levels of the subintervals, i.e.
5557 ! iwork(i) = l means that the subinterval numbered
5558 ! i is of length abs(b-a)*2**(1-l)
5559 !
5560 ! on entry and return
5561 ! momcom - integer
5562 ! indicating that the Chebyshev moments have been
5563 ! computed for intervals of lengths
5564 ! (abs(b-a))*2**(-l), l=0,1,2, ..., momcom-1,
5565 ! momcom < maxp1
5566 !
5567 ! chebmo - real
5568 ! array of dimension (maxp1,25) containing the
5569 ! Chebyshev moments
5570 !
5571 ! Local Parameters:
5572 !
5573 ! alist - list of left end points of all subintervals
5574 ! considered up to now
5575 ! blist - list of right end points of all subintervals
5576 ! considered up to now
5577 ! rlist(i) - approximation to the integral over
5578 ! (alist(i),blist(i))
5579 ! rlist2 - array of dimension at least limexp+2 containing
5580 ! the part of the epsilon table which is still
5581 ! needed for further computations
5582 ! elist(i) - error estimate applying to rlist(i)
5583 ! maxerr - pointer to the interval with largest error
5584 ! estimate
5585 ! errmax - elist(maxerr)
5586 ! erlast - error on the interval currently subdivided
5587 ! area - sum of the integrals over the subintervals
5588 ! errsum - sum of the errors over the subintervals
5589 ! errbnd - requested accuracy max(epsabs,epsrel*
5590 ! abs(result))
5591 ! *****1 - variable for the left subinterval
5592 ! *****2 - variable for the right subinterval
5593 ! last - index for subdivision
5594 ! nres - number of calls to the extrapolation routine
5595 ! numrl2 - number of elements in rlist2. if an appropriate
5596 ! approximation to the compounded integral has
5597 ! been obtained it is put in rlist2(numrl2) after
5598 ! numrl2 has been increased by one
5599 ! small - length of the smallest interval considered
5600 ! up to now, multiplied by 1.5
5601 ! erlarg - sum of the errors over the intervals larger
5602 ! than the smallest interval considered up to now
5603 ! extrap - logical variable denoting that the routine is
5604 ! attempting to perform extrapolation, i.e. before
5605 ! subdividing the smallest interval we try to
5606 ! decrease the value of erlarg
5607 ! noext - logical variable denoting that extrapolation
5608 ! is no longer allowed (true value)
5609 !
5610  implicit none
5611 !
5612  integer limit
5613  integer maxp1
5614 !
5615  real(r_kind) a
5616  real(r_kind) abseps
5617  real(r_kind) abserr
5618  real(r_kind) alist(limit)
5619  real(r_kind) area
5620  real(r_kind) area1
5621  real(r_kind) area12
5622  real(r_kind) area2
5623  real(r_kind) a1
5624  real(r_kind) a2
5625  real(r_kind) b
5626  real(r_kind) blist(limit)
5627  real(r_kind) b1
5628  real(r_kind) b2
5629  real(r_kind) chebmo(maxp1,25)
5630  real(r_kind) correc
5631  real(r_kind) defab1
5632  real(r_kind) defab2
5633  real(r_kind) defabs
5634  real(r_kind) domega
5635  real(r_kind) dres
5636  real(r_kind) elist(limit)
5637  real(r_kind) epsabs
5638  real(r_kind) epsrel
5639  real(r_kind) erlarg
5640  real(r_kind) erlast
5641  real(r_kind) errbnd
5642  real(r_kind) errmax
5643  real(r_kind) error1
5644  real(r_kind) erro12
5645  real(r_kind) error2
5646  real(r_kind) errsum
5647  real(r_kind) ertest
5648  logical extall
5649  logical extrap
5650  real(r_kind), external :: f
5651  integer icall
5652  integer id
5653  integer ier
5654  integer ierro
5655  integer integr
5656  integer iord(limit)
5657  integer iroff1
5658  integer iroff2
5659  integer iroff3
5660  integer jupbnd
5661  integer k
5662  integer ksgn
5663  integer ktmin
5664  integer last
5665  integer maxerr
5666  integer momcom
5667  integer nev
5668  integer neval
5669  integer nnlog(limit)
5670  logical noext
5671  integer nres
5672  integer nrmax
5673  integer nrmom
5674  integer numrl2
5675  real(r_kind) omega
5676  real(r_kind) resabs
5677  real(r_kind) reseps
5678  real(r_kind) result
5679  real(r_kind) res3la(3)
5680  real(r_kind) rlist(limit)
5681  real(r_kind) rlist2(52)
5682  real(r_kind) small
5683  real(r_kind) width
5684 !
5685 ! the dimension of rlist2 is determined by the value of
5686 ! limexp in QEXTR (rlist2 should be of dimension
5687 ! (limexp+2) at least).
5688 !
5689 ! Test on validity of parameters.
5690 !
5691  ier = 0
5692  neval = 0
5693  last = 0
5694  result = 0.0d+00
5695  abserr = 0.0d+00
5696  alist(1) = a
5697  blist(1) = b
5698  rlist(1) = 0.0d+00
5699  elist(1) = 0.0d+00
5700  iord(1) = 0
5701  nnlog(1) = 0
5702 
5703  if ( (integr /= 1.and.integr /= 2) .or. (epsabs < 0.0d+00.and. &
5704  epsrel < 0.0d+00) .or. icall < 1 .or. maxp1 < 1 ) then
5705  ier = 6
5706  return
5707  end if
5708 !
5709 ! First approximation to the integral.
5710 !
5711  domega = abs( omega )
5712  nrmom = 0
5713 
5714  if ( icall <= 1 ) then
5715  momcom = 0
5716  end if
5717 
5718  call qc25o ( f, a, b, domega, integr, nrmom, maxp1, 0, result, abserr, &
5719  neval, defabs, resabs, momcom, chebmo )
5720 !
5721 ! Test on accuracy.
5722 !
5723  dres = abs(result)
5724  errbnd = max( epsabs,epsrel*dres)
5725  rlist(1) = result
5726  elist(1) = abserr
5727  iord(1) = 1
5728  if ( abserr <= 1.0d+02* epsilon( defabs ) *defabs .and. &
5729  abserr > errbnd ) ier = 2
5730 
5731  if ( limit == 1 ) then
5732  ier = 1
5733  end if
5734 
5735  if ( ier /= 0 .or. abserr <= errbnd ) go to 200
5736 !
5737 ! Initializations
5738 !
5739  errmax = abserr
5740  maxerr = 1
5741  area = result
5742  errsum = abserr
5743  abserr = huge( abserr )
5744  nrmax = 1
5745  extrap = .false.
5746  noext = .false.
5747  ierro = 0
5748  iroff1 = 0
5749  iroff2 = 0
5750  iroff3 = 0
5751  ktmin = 0
5752  small = abs(b-a)*7.5d-01
5753  nres = 0
5754  numrl2 = 0
5755  extall = .false.
5756 
5757  if ( 5.0d-01*abs(b-a)*domega <= 2.0d+00) then
5758  numrl2 = 1
5759  extall = .true.
5760  rlist2(1) = result
5761  end if
5762 
5763  if ( 2.5d-01 * abs(b-a) * domega <= 2.0d+00 ) then
5764  extall = .true.
5765  end if
5766 
5767  if ( dres >= (1.0d+00-5.0d+01* epsilon( defabs ) )*defabs ) then
5768  ksgn = 1
5769  else
5770  ksgn = -1
5771  end if
5772 !
5773 ! main do-loop
5774 !
5775  do 140 last = 2, limit
5776 !
5777 ! Bisect the subinterval with the nrmax-th largest error estimate.
5778 !
5779  nrmom = nnlog(maxerr)+1
5780  a1 = alist(maxerr)
5781  b1 = 5.0d-01*(alist(maxerr)+blist(maxerr))
5782  a2 = b1
5783  b2 = blist(maxerr)
5784  erlast = errmax
5785 
5786  call qc25o ( f, a1, b1, domega, integr, nrmom, maxp1, 0, area1, &
5787  error1, nev, resabs, defab1, momcom, chebmo )
5788 
5789  neval = neval+nev
5790 
5791  call qc25o ( f, a2, b2, domega, integr, nrmom, maxp1, 1, area2, &
5792  error2, nev, resabs, defab2, momcom, chebmo )
5793 
5794  neval = neval+nev
5795 !
5796 ! Improve previous approximations to integral and error and
5797 ! test for accuracy.
5798 !
5799  area12 = area1+area2
5800  erro12 = error1+error2
5801  errsum = errsum+erro12-errmax
5802  area = area+area12-rlist(maxerr)
5803  if ( defab1 == error1 .or. defab2 == error2 ) go to 25
5804  if ( abs(rlist(maxerr)-area12) > 1.0d-05*abs(area12) &
5805  .or. erro12 < 9.9d-01*errmax ) go to 20
5806  if ( extrap ) iroff2 = iroff2+1
5807 
5808  if ( .not.extrap ) then
5809  iroff1 = iroff1+1
5810  end if
5811 
5812 20 continue
5813 
5814  if ( last > 10.and.erro12 > errmax ) iroff3 = iroff3+1
5815 
5816 25 continue
5817 
5818  rlist(maxerr) = area1
5819  rlist(last) = area2
5820  nnlog(maxerr) = nrmom
5821  nnlog(last) = nrmom
5822  errbnd = max( epsabs,epsrel*abs(area))
5823 !
5824 ! Test for roundoff error and eventually set error flag
5825 !
5826  if ( iroff1+iroff2 >= 10 .or. iroff3 >= 20 ) ier = 2
5827 
5828  if ( iroff2 >= 5) ierro = 3
5829 !
5830 ! Set error flag in the case that the number of subintervals
5831 ! equals limit.
5832 !
5833  if ( last == limit ) then
5834  ier = 1
5835  end if
5836 !
5837 ! Set error flag in the case of bad integrand behavior at
5838 ! a point of the integration range.
5839 !
5840  if ( max( abs(a1),abs(b2)) <= (1.0d+00+1.0d+03* epsilon( a1 ) ) &
5841  *(abs(a2)+1.0d+03* tiny( a2 ) )) then
5842  ier = 4
5843  end if
5844 !
5845 ! Append the newly-created intervals to the list.
5846 !
5847  if ( error2 <= error1 ) then
5848  alist(last) = a2
5849  blist(maxerr) = b1
5850  blist(last) = b2
5851  elist(maxerr) = error1
5852  elist(last) = error2
5853  else
5854  alist(maxerr) = a2
5855  alist(last) = a1
5856  blist(last) = b1
5857  rlist(maxerr) = area2
5858  rlist(last) = area1
5859  elist(maxerr) = error2
5860  elist(last) = error1
5861  end if
5862 !
5863 ! Call QSORT to maintain the descending ordering
5864 ! in the list of error estimates and select the subinterval
5865 ! with nrmax-th largest error estimate (to be bisected next).
5866 !
5867 40 continue
5868 
5869  call qsort ( limit, last, maxerr, errmax, elist, iord, nrmax )
5870 
5871  if ( errsum <= errbnd ) then
5872  go to 170
5873  end if
5874 
5875  if ( ier /= 0 ) go to 150
5876  if ( last == 2 .and. extall ) go to 120
5877  if ( noext ) go to 140
5878  if ( .not. extall ) go to 50
5879  erlarg = erlarg-erlast
5880  if ( abs(b1-a1) > small ) erlarg = erlarg+erro12
5881  if ( extrap ) go to 70
5882 !
5883 ! Test whether the interval to be bisected next is the
5884 ! smallest interval.
5885 !
5886 50 continue
5887 
5888  width = abs(blist(maxerr)-alist(maxerr))
5889  if ( width > small ) go to 140
5890  if ( extall ) go to 60
5891 !
5892 ! Test whether we can start with the extrapolation procedure
5893 ! (we do this if we integrate over the next interval with
5894 ! use of a Gauss-Kronrod rule - see QC25O).
5895 !
5896  small = small*5.0d-01
5897  if ( 2.5d-01*width*domega > 2.0d+00 ) go to 140
5898  extall = .true.
5899  go to 130
5900 
5901 60 continue
5902 
5903  extrap = .true.
5904  nrmax = 2
5905 
5906 70 continue
5907 
5908  if ( ierro == 3 .or. erlarg <= ertest ) go to 90
5909 !
5910 ! The smallest interval has the largest error.
5911 ! Before bisecting decrease the sum of the errors over the
5912 ! larger intervals (ERLARG) and perform extrapolation.
5913 !
5914  jupbnd = last
5915 
5916  if ( last > (limit/2+2) ) then
5917  jupbnd = limit+3-last
5918  end if
5919 
5920  id = nrmax
5921 
5922  do k = id, jupbnd
5923  maxerr = iord(nrmax)
5924  errmax = elist(maxerr)
5925  if ( abs(blist(maxerr)-alist(maxerr)) > small ) go to 140
5926  nrmax = nrmax+1
5927  end do
5928 !
5929 ! Perform extrapolation.
5930 !
5931 90 continue
5932 
5933  numrl2 = numrl2+1
5934  rlist2(numrl2) = area
5935  if ( numrl2 < 3 ) go to 110
5936  call qextr ( numrl2, rlist2, reseps, abseps, res3la, nres )
5937  ktmin = ktmin+1
5938 
5939  if ( ktmin > 5.and.abserr < 1.0d-03*errsum ) then
5940  ier = 5
5941  end if
5942 
5943  if ( abseps >= abserr ) go to 100
5944  ktmin = 0
5945  abserr = abseps
5946  result = reseps
5947  correc = erlarg
5948  ertest = max( epsabs, epsrel*abs(reseps))
5949  if ( abserr <= ertest ) go to 150
5950 !
5951 ! Prepare bisection of the smallest interval.
5952 !
5953 100 continue
5954 
5955  if ( numrl2 == 1 ) noext = .true.
5956  if ( ier == 5 ) go to 150
5957 
5958 110 continue
5959 
5960  maxerr = iord(1)
5961  errmax = elist(maxerr)
5962  nrmax = 1
5963  extrap = .false.
5964  small = small*5.0d-01
5965  erlarg = errsum
5966  go to 140
5967 
5968 120 continue
5969 
5970  small = small * 5.0d-01
5971  numrl2 = numrl2 + 1
5972  rlist2(numrl2) = area
5973 
5974 130 continue
5975 
5976  ertest = errbnd
5977  erlarg = errsum
5978 
5979 140 continue
5980 !
5981 ! set the final result.
5982 !
5983 150 continue
5984 
5985  if ( abserr == huge( abserr ) .or. nres == 0 ) go to 170
5986  if ( ier+ierro == 0 ) go to 165
5987  if ( ierro == 3 ) abserr = abserr+correc
5988  if ( ier == 0 ) ier = 3
5989  if ( result /= 0.0d+00.and.area /= 0.0d+00 ) go to 160
5990  if ( abserr > errsum ) go to 170
5991  if ( area == 0.0d+00 ) go to 190
5992  go to 165
5993 
5994 160 continue
5995 
5996  if ( abserr/abs(result) > errsum/abs(area) ) go to 170
5997 !
5998 ! Test on divergence.
5999 !
6000  165 continue
6001 
6002  if ( ksgn == (-1) .and. max( abs(result),abs(area)) <= &
6003  defabs*1.0d-02 ) go to 190
6004 
6005  if ( 1.0d-02 > (result/area) .or. (result/area) > 1.0d+02 &
6006  .or. errsum >= abs(area) ) ier = 6
6007 
6008  go to 190
6009 !
6010 ! Compute global integral sum.
6011 !
6012 170 continue
6013 
6014  result = sum( rlist(1:last) )
6015 
6016  abserr = errsum
6017 
6018 190 continue
6019 
6020  if (ier > 2) ier=ier-1
6021 
6022 200 continue
6023 
6024  if ( integr == 2 .and. omega < 0.0d+00 ) then
6025  result = -result
6026  end if
6027 
6028  return
6029 end subroutine
6030 subroutine qk15 ( f, a, b, result, abserr, resabs, resasc )
6031 !
6032 !******************************************************************************
6033 !
6034 !! QK15 carries out a 15 point Gauss-Kronrod quadrature rule.
6035 !
6036 !
6037 ! Discussion:
6038 !
6039 ! This routine approximates
6040 ! I = integral ( A <= X <= B ) F(X) dx
6041 ! with an error estimate, and
6042 ! J = integral ( A <= X <= B ) | F(X) | dx
6043 !
6044 ! Reference:
6045 !
6046 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
6047 ! QUADPACK, a Subroutine Package for Automatic Integration,
6048 ! Springer Verlag, 1983
6049 !
6050 ! Parameters:
6051 !
6052 ! Input, external real(r_kind) F, the name of the function routine, of the form
6053 ! function f ( x )
6054 ! real(r_kind) f
6055 ! real(r_kind) x
6056 ! which evaluates the integrand function.
6057 !
6058 ! Input, real(r_kind) A, B, the limits of integration.
6059 !
6060 ! Output, real(r_kind) RESULT, the estimated value of the integral.
6061 ! RESULT is computed by applying the 15-point Kronrod rule (RESK)
6062 ! obtained by optimal addition of abscissae to the 7-point Gauss rule
6063 ! (RESG).
6064 !
6065 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
6066 !
6067 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
6068 ! value of F.
6069 !
6070 ! Output, real(r_kind) RESASC, approximation to the integral | F-I/(B-A) |
6071 ! over [A,B].
6072 !
6073 ! Local Parameters:
6074 !
6075 ! the abscissae and weights are given for the interval (-1,1).
6076 ! because of symmetry only the positive abscissae and their
6077 ! corresponding weights are given.
6078 !
6079 ! xgk - abscissae of the 15-point Kronrod rule
6080 ! xgk(2), xgk(4), ... abscissae of the 7-point
6081 ! Gauss rule
6082 ! xgk(1), xgk(3), ... abscissae which are optimally
6083 ! added to the 7-point Gauss rule
6084 !
6085 ! wgk - weights of the 15-point Kronrod rule
6086 !
6087 ! wg - weights of the 7-point Gauss rule
6088 !
6089 ! centr - mid point of the interval
6090 ! hlgth - half-length of the interval
6091 ! absc - abscissa
6092 ! fval* - function value
6093 ! resg - result of the 7-point Gauss formula
6094 ! resk - result of the 15-point Kronrod formula
6095 ! reskh - approximation to the mean value of f over (a,b),
6096 ! i.e. to i/(b-a)
6097 !
6098  implicit none
6099 !
6100  real(r_kind) a
6101  real(r_kind) absc
6102  real(r_kind) abserr
6103  real(r_kind) b
6104  real(r_kind) centr
6105  real(r_kind) dhlgth
6106  real(r_kind), external :: f
6107  real(r_kind) fc
6108  real(r_kind) fsum
6109  real(r_kind) fval1
6110  real(r_kind) fval2
6111  real(r_kind) fv1(7)
6112  real(r_kind) fv2(7)
6113  real(r_kind) hlgth
6114  integer j
6115  integer jtw
6116  integer jtwm1
6117  real(r_kind) resabs
6118  real(r_kind) resasc
6119  real(r_kind) resg
6120  real(r_kind) resk
6121  real(r_kind) reskh
6122  real(r_kind) result
6123  real(r_kind) wg(4)
6124  real(r_kind) wgk(8)
6125  real(r_kind) xgk(8)
6126 !
6127  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8)/ &
6128  9.914553711208126d-01, 9.491079123427585d-01, &
6129  8.648644233597691d-01, 7.415311855993944d-01, &
6130  5.860872354676911d-01, 4.058451513773972d-01, &
6131  2.077849550078985d-01, 0.0d+00 /
6132  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8)/ &
6133  2.293532201052922d-02, 6.309209262997855d-02, &
6134  1.047900103222502d-01, 1.406532597155259d-01, &
6135  1.690047266392679d-01, 1.903505780647854d-01, &
6136  2.044329400752989d-01, 2.094821410847278d-01/
6137  data wg(1),wg(2),wg(3),wg(4)/ &
6138  1.294849661688697d-01, 2.797053914892767d-01, &
6139  3.818300505051189d-01, 4.179591836734694d-01/
6140 !
6141  centr = 5.0d-01*(a+b)
6142  hlgth = 5.0d-01*(b-a)
6143  dhlgth = abs(hlgth)
6144 !
6145 ! Compute the 15-point Kronrod approximation to the integral,
6146 ! and estimate the absolute error.
6147 !
6148  fc = f(centr)
6149  resg = fc*wg(4)
6150  resk = fc*wgk(8)
6151  resabs = abs(resk)
6152 
6153  do j = 1, 3
6154  jtw = j*2
6155  absc = hlgth*xgk(jtw)
6156  fval1 = f(centr-absc)
6157  fval2 = f(centr+absc)
6158  fv1(jtw) = fval1
6159  fv2(jtw) = fval2
6160  fsum = fval1+fval2
6161  resg = resg+wg(j)*fsum
6162  resk = resk+wgk(jtw)*fsum
6163  resabs = resabs+wgk(jtw)*(abs(fval1)+abs(fval2))
6164  end do
6165 
6166  do j = 1, 4
6167  jtwm1 = j*2-1
6168  absc = hlgth*xgk(jtwm1)
6169  fval1 = f(centr-absc)
6170  fval2 = f(centr+absc)
6171  fv1(jtwm1) = fval1
6172  fv2(jtwm1) = fval2
6173  fsum = fval1+fval2
6174  resk = resk+wgk(jtwm1)*fsum
6175  resabs = resabs+wgk(jtwm1)*(abs(fval1)+abs(fval2))
6176  end do
6177 
6178  reskh = resk * 5.0d-01
6179  resasc = wgk(8)*abs(fc-reskh)
6180 
6181  do j = 1, 7
6182  resasc = resasc+wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
6183  end do
6184 
6185  result = resk*hlgth
6186  resabs = resabs*dhlgth
6187  resasc = resasc*dhlgth
6188  abserr = abs((resk-resg)*hlgth)
6189 
6190  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00 ) then
6191  abserr = resasc*min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
6192  end if
6193 
6194  if ( resabs > tiny( resabs ) / (5.0d+01* epsilon( resabs ) ) ) then
6195  abserr = max(( epsilon( resabs ) *5.0d+01)*resabs,abserr)
6196  end if
6197 
6198  return
6199 end subroutine
6200 subroutine qk15i ( f, boun, inf, a, b, result, abserr, resabs, resasc )
6201 !
6202 !******************************************************************************
6203 !
6204 !! QK15I applies a 15 point Gauss-Kronrod quadrature on an infinite interval.
6205 !
6206 !
6207 ! Discussion:
6208 !
6209 ! The original infinite integration range is mapped onto the interval
6210 ! (0,1) and (a,b) is a part of (0,1). The routine then computes:
6211 !
6212 ! i = integral of transformed integrand over (a,b),
6213 ! j = integral of abs(transformed integrand) over (a,b).
6214 !
6215 ! Reference:
6216 !
6217 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
6218 ! QUADPACK, a Subroutine Package for Automatic Integration,
6219 ! Springer Verlag, 1983
6220 !
6221 ! Parameters:
6222 !
6223 ! Input, external real(r_kind) F, the name of the function routine, of the form
6224 ! function f ( x )
6225 ! real(r_kind) f
6226 ! real(r_kind) x
6227 ! which evaluates the integrand function.
6228 !
6229 ! Input, real(r_kind) BOUN, the finite bound of the original integration range,
6230 ! or zero if INF is 2.
6231 !
6232 ! inf - integer
6233 ! if inf = -1, the original interval is
6234 ! (-infinity,BOUN),
6235 ! if inf = +1, the original interval is
6236 ! (BOUN,+infinity),
6237 ! if inf = +2, the original interval is
6238 ! (-infinity,+infinity) and
6239 ! The integral is computed as the sum of two
6240 ! integrals, one over (-infinity,0) and one
6241 ! over (0,+infinity).
6242 !
6243 ! Input, real(r_kind) A, B, the limits of integration, over a subrange of [0,1].
6244 !
6245 ! Output, real(r_kind) RESULT, the estimated value of the integral.
6246 ! RESULT is computed by applying the 15-point Kronrod rule (RESK) obtained
6247 ! by optimal addition of abscissae to the 7-point Gauss rule (RESG).
6248 !
6249 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
6250 !
6251 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
6252 ! value of F.
6253 !
6254 ! Output, real(r_kind) RESASC, approximation to the integral of the
6255 ! transformated integrand | F-I/(B-A) | over [A,B].
6256 !
6257 ! Local Parameters:
6258 !
6259 ! centr - mid point of the interval
6260 ! hlgth - half-length of the interval
6261 ! absc* - abscissa
6262 ! tabsc* - transformed abscissa
6263 ! fval* - function value
6264 ! resg - result of the 7-point Gauss formula
6265 ! resk - result of the 15-point Kronrod formula
6266 ! reskh - approximation to the mean value of the transformed
6267 ! integrand over (a,b), i.e. to i/(b-a)
6268 !
6269  implicit none
6270 !
6271  real(r_kind) a
6272  real(r_kind) absc
6273  real(r_kind) absc1
6274  real(r_kind) absc2
6275  real(r_kind) abserr
6276  real(r_kind) b
6277  real(r_kind) boun
6278  real(r_kind) centr
6279  real(r_kind) dinf
6280  real(r_kind), external :: f
6281  real(r_kind) fc
6282  real(r_kind) fsum
6283  real(r_kind) fval1
6284  real(r_kind) fval2
6285  real(r_kind) fv1(7)
6286  real(r_kind) fv2(7)
6287  real(r_kind) hlgth
6288  integer inf
6289  integer j
6290  real(r_kind) resabs
6291  real(r_kind) resasc
6292  real(r_kind) resg
6293  real(r_kind) resk
6294  real(r_kind) reskh
6295  real(r_kind) result
6296  real(r_kind) tabsc1
6297  real(r_kind) tabsc2
6298  real(r_kind) wg(8)
6299  real(r_kind) wgk(8)
6300  real(r_kind) xgk(8)
6301 !
6302 ! the abscissae and weights are supplied for the interval
6303 ! (-1,1). because of symmetry only the positive abscissae and
6304 ! their corresponding weights are given.
6305 !
6306 ! xgk - abscissae of the 15-point Kronrod rule
6307 ! xgk(2), xgk(4), ... abscissae of the 7-point Gauss
6308 ! rule
6309 ! xgk(1), xgk(3), ... abscissae which are optimally
6310 ! added to the 7-point Gauss rule
6311 !
6312 ! wgk - weights of the 15-point Kronrod rule
6313 !
6314 ! wg - weights of the 7-point Gauss rule, corresponding
6315 ! to the abscissae xgk(2), xgk(4), ...
6316 ! wg(1), wg(3), ... are set to zero.
6317 !
6318  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8)/ &
6319  9.914553711208126d-01, 9.491079123427585d-01, &
6320  8.648644233597691d-01, 7.415311855993944d-01, &
6321  5.860872354676911d-01, 4.058451513773972d-01, &
6322  2.077849550078985d-01, 0.0000000000000000d+00/
6323 !
6324  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8)/ &
6325  2.293532201052922d-02, 6.309209262997855d-02, &
6326  1.047900103222502d-01, 1.406532597155259d-01, &
6327  1.690047266392679d-01, 1.903505780647854d-01, &
6328  2.044329400752989d-01, 2.094821410847278d-01/
6329 !
6330  data wg(1),wg(2),wg(3),wg(4),wg(5),wg(6),wg(7),wg(8)/ &
6331  0.0000000000000000d+00, 1.294849661688697d-01, &
6332  0.0000000000000000d+00, 2.797053914892767d-01, &
6333  0.0000000000000000d+00, 3.818300505051189d-01, &
6334  0.0000000000000000d+00, 4.179591836734694d-01/
6335 !
6336  dinf = min( 1, inf )
6337 
6338  centr = 5.0d-01*(a+b)
6339  hlgth = 5.0d-01*(b-a)
6340  tabsc1 = boun+dinf*(1.0d+00-centr)/centr
6341  fval1 = f(tabsc1)
6342  if ( inf == 2 ) fval1 = fval1+f(-tabsc1)
6343  fc = (fval1/centr)/centr
6344 !
6345 ! Compute the 15-point Kronrod approximation to the integral,
6346 ! and estimate the error.
6347 !
6348  resg = wg(8)*fc
6349  resk = wgk(8)*fc
6350  resabs = abs(resk)
6351 
6352  do j = 1, 7
6353 
6354  absc = hlgth*xgk(j)
6355  absc1 = centr-absc
6356  absc2 = centr+absc
6357  tabsc1 = boun+dinf*(1.0d+00-absc1)/absc1
6358  tabsc2 = boun+dinf*(1.0d+00-absc2)/absc2
6359  fval1 = f(tabsc1)
6360  fval2 = f(tabsc2)
6361 
6362  if ( inf == 2 ) then
6363  fval1 = fval1+f(-tabsc1)
6364  fval2 = fval2+f(-tabsc2)
6365  end if
6366 
6367  fval1 = (fval1/absc1)/absc1
6368  fval2 = (fval2/absc2)/absc2
6369  fv1(j) = fval1
6370  fv2(j) = fval2
6371  fsum = fval1+fval2
6372  resg = resg+wg(j)*fsum
6373  resk = resk+wgk(j)*fsum
6374  resabs = resabs+wgk(j)*(abs(fval1)+abs(fval2))
6375  end do
6376 
6377  reskh = resk * 5.0d-01
6378  resasc = wgk(8) * abs(fc-reskh)
6379 
6380  do j = 1, 7
6381  resasc = resasc + wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
6382  end do
6383 
6384  result = resk * hlgth
6385  resasc = resasc * hlgth
6386  resabs = resabs * hlgth
6387  abserr = abs( ( resk - resg ) * hlgth )
6388 
6389  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00) then
6390  abserr = resasc* min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
6391  end if
6392 
6393  if ( resabs > tiny( resabs ) / ( 5.0d+01 * epsilon( resabs ) ) ) then
6394  abserr = max(( epsilon( resabs ) *5.0d+01)*resabs,abserr)
6395  end if
6396 
6397  return
6398 end subroutine
6399 subroutine qk15w ( f, w, p1, p2, p3, p4, kp, a, b, result, abserr, resabs, &
6400  resasc )
6401 !
6402 !******************************************************************************
6403 !
6404 !! QK15W applies a 15 point Gauss-Kronrod rule for a weighted integrand.
6405 !
6406 !
6407 ! Discussion:
6408 !
6409 ! This routine approximates
6410 ! i = integral of f*w over (a,b),
6411 ! with error estimate, and
6412 ! j = integral of abs(f*w) over (a,b)
6413 !
6414 ! Reference:
6415 !
6416 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
6417 ! QUADPACK, a Subroutine Package for Automatic Integration,
6418 ! Springer Verlag, 1983
6419 !
6420 ! Parameters:
6421 !
6422 ! Input, external real(r_kind) F, the name of the function routine, of the form
6423 ! function f ( x )
6424 ! real(r_kind) f
6425 ! real(r_kind) x
6426 ! which evaluates the integrand function.
6427 !
6428 ! w - real
6429 ! function subprogram defining the integrand
6430 ! weight function w(x). the actual name for w
6431 ! needs to be declared e x t e r n a l in the
6432 ! calling program.
6433 !
6434 ! ?, real(r_kind) P1, P2, P3, P4, parameters in the weight function
6435 !
6436 ! kp - integer
6437 ! key for indicating the type of weight function
6438 !
6439 ! Input, real(r_kind) A, B, the limits of integration.
6440 !
6441 ! Output, real(r_kind) RESULT, the estimated value of the integral.
6442 ! RESULT is computed by applying the 15-point Kronrod rule (RESK) obtained by
6443 ! optimal addition of abscissae to the 7-point Gauss rule (RESG).
6444 !
6445 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
6446 !
6447 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
6448 ! value of F.
6449 !
6450 ! Output, real(r_kind) RESASC, approximation to the integral | F-I/(B-A) |
6451 ! over [A,B].
6452 !
6453 ! Local Parameters:
6454 !
6455 ! centr - mid point of the interval
6456 ! hlgth - half-length of the interval
6457 ! absc* - abscissa
6458 ! fval* - function value
6459 ! resg - result of the 7-point Gauss formula
6460 ! resk - result of the 15-point Kronrod formula
6461 ! reskh - approximation to the mean value of f*w over (a,b),
6462 ! i.e. to i/(b-a)
6463 !
6464  implicit none
6465 !
6466  real(r_kind) a
6467  real(r_kind) absc
6468  real(r_kind) absc1
6469  real(r_kind) absc2
6470  real(r_kind) abserr
6471  real(r_kind) b
6472  real(r_kind) centr
6473  real(r_kind) dhlgth
6474  real(r_kind), external :: f
6475  real(r_kind) fc
6476  real(r_kind) fsum
6477  real(r_kind) fval1
6478  real(r_kind) fval2
6479  real(r_kind) fv1(7)
6480  real(r_kind) fv2(7)
6481  real(r_kind) hlgth
6482  integer j
6483  integer jtw
6484  integer jtwm1
6485  integer kp
6486  real(r_kind) p1
6487  real(r_kind) p2
6488  real(r_kind) p3
6489  real(r_kind) p4
6490  real(r_kind) resabs
6491  real(r_kind) resasc
6492  real(r_kind) resg
6493  real(r_kind) resk
6494  real(r_kind) reskh
6495  real(r_kind) result
6496  real(r_kind), external :: w
6497  real(r_kind), dimension ( 4 ) :: wg = (/ &
6498  1.294849661688697d-01, 2.797053914892767d-01, &
6499  3.818300505051889d-01, 4.179591836734694d-01 /)
6500  real(r_kind) wgk(8)
6501  real(r_kind) xgk(8)
6502 !
6503 ! the abscissae and weights are given for the interval (-1,1).
6504 ! because of symmetry only the positive abscissae and their
6505 ! corresponding weights are given.
6506 !
6507 ! xgk - abscissae of the 15-point Gauss-Kronrod rule
6508 ! xgk(2), xgk(4), ... abscissae of the 7-point Gauss
6509 ! rule
6510 ! xgk(1), xgk(3), ... abscissae which are optimally
6511 ! added to the 7-point Gauss rule
6512 !
6513 ! wgk - weights of the 15-point Gauss-Kronrod rule
6514 !
6515 ! wg - weights of the 7-point Gauss rule
6516 !
6517  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8)/ &
6518  9.914553711208126d-01, 9.491079123427585d-01, &
6519  8.648644233597691d-01, 7.415311855993944d-01, &
6520  5.860872354676911d-01, 4.058451513773972d-01, &
6521  2.077849550789850d-01, 0.000000000000000d+00/
6522 !
6523  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8)/ &
6524  2.293532201052922d-02, 6.309209262997855d-02, &
6525  1.047900103222502d-01, 1.406532597155259d-01, &
6526  1.690047266392679d-01, 1.903505780647854d-01, &
6527  2.044329400752989d-01, 2.094821410847278d-01/
6528 !
6529  centr = 5.0d-01*(a+b)
6530  hlgth = 5.0d-01*(b-a)
6531  dhlgth = abs(hlgth)
6532 !
6533 ! Compute the 15-point Kronrod approximation to the integral,
6534 ! and estimate the error.
6535 !
6536  fc = f(centr)*w(centr,p1,p2,p3,p4,kp)
6537  resg = wg(4)*fc
6538  resk = wgk(8)*fc
6539  resabs = abs(resk)
6540 
6541  do j = 1, 3
6542  jtw = j*2
6543  absc = hlgth*xgk(jtw)
6544  absc1 = centr-absc
6545  absc2 = centr+absc
6546  fval1 = f(absc1)*w(absc1,p1,p2,p3,p4,kp)
6547  fval2 = f(absc2)*w(absc2,p1,p2,p3,p4,kp)
6548  fv1(jtw) = fval1
6549  fv2(jtw) = fval2
6550  fsum = fval1+fval2
6551  resg = resg+wg(j)*fsum
6552  resk = resk+wgk(jtw)*fsum
6553  resabs = resabs+wgk(jtw)*(abs(fval1)+abs(fval2))
6554  end do
6555 
6556  do j = 1, 4
6557  jtwm1 = j*2-1
6558  absc = hlgth*xgk(jtwm1)
6559  absc1 = centr-absc
6560  absc2 = centr+absc
6561  fval1 = f(absc1)*w(absc1,p1,p2,p3,p4,kp)
6562  fval2 = f(absc2)*w(absc2,p1,p2,p3,p4,kp)
6563  fv1(jtwm1) = fval1
6564  fv2(jtwm1) = fval2
6565  fsum = fval1+fval2
6566  resk = resk+wgk(jtwm1)*fsum
6567  resabs = resabs+wgk(jtwm1)*(abs(fval1)+abs(fval2))
6568  end do
6569 
6570  reskh = resk*5.0d-01
6571  resasc = wgk(8)*abs(fc-reskh)
6572 
6573  do j = 1, 7
6574  resasc = resasc+wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
6575  end do
6576 
6577  result = resk*hlgth
6578  resabs = resabs*dhlgth
6579  resasc = resasc*dhlgth
6580  abserr = abs((resk-resg)*hlgth)
6581 
6582  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00) then
6583  abserr = resasc*min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
6584  end if
6585 
6586  if ( resabs > tiny( resabs ) /(5.0d+01* epsilon( resabs ) ) ) then
6587  abserr = max( ( epsilon( resabs ) * 5.0d+01)*resabs,abserr)
6588  end if
6589 
6590  return
6591 end subroutine
6592 subroutine qk21 ( f, a, b, result, abserr, resabs, resasc )
6593 !
6594 !******************************************************************************
6595 !
6596 !! QK21 carries out a 21 point Gauss-Kronrod quadrature rule.
6597 !
6598 !
6599 ! Discussion:
6600 !
6601 ! This routine approximates
6602 ! I = integral ( A <= X <= B ) F(X) dx
6603 ! with an error estimate, and
6604 ! J = integral ( A <= X <= B ) | F(X) | dx
6605 !
6606 ! Reference:
6607 !
6608 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
6609 ! QUADPACK, a Subroutine Package for Automatic Integration,
6610 ! Springer Verlag, 1983
6611 !
6612 ! Parameters:
6613 !
6614 ! Input, external real(r_kind) F, the name of the function routine, of the form
6615 ! function f ( x )
6616 ! real(r_kind) f
6617 ! real(r_kind) x
6618 ! which evaluates the integrand function.
6619 !
6620 ! Input, real(r_kind) A, B, the limits of integration.
6621 !
6622 ! Output, real(r_kind) RESULT, the estimated value of the integral.
6623 ! result is computed by applying the 21-point
6624 ! Kronrod rule (resk) obtained by optimal addition
6625 ! of abscissae to the 10-point Gauss rule (resg).
6626 !
6627 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
6628 !
6629 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
6630 ! value of F.
6631 !
6632 ! Output, real(r_kind) RESASC, approximation to the integral | F-I/(B-A) |
6633 ! over [A,B].
6634 !
6635  implicit none
6636 !
6637  real(r_kind) a
6638  real(r_kind) absc
6639  real(r_kind) abserr
6640  real(r_kind) b
6641  real(r_kind) centr
6642  real(r_kind) dhlgth
6643  real(r_kind), external :: f
6644  real(r_kind) fc
6645  real(r_kind) fsum
6646  real(r_kind) fval1
6647  real(r_kind) fval2
6648  real(r_kind) fv1(10)
6649  real(r_kind) fv2(10)
6650  real(r_kind) hlgth
6651  integer j
6652  integer jtw
6653  integer jtwm1
6654  real(r_kind) resabs
6655  real(r_kind) resasc
6656  real(r_kind) resg
6657  real(r_kind) resk
6658  real(r_kind) reskh
6659  real(r_kind) result
6660  real(r_kind) wg(5)
6661  real(r_kind) wgk(11)
6662  real(r_kind) xgk(11)
6663 !
6664 ! the abscissae and weights are given for the interval (-1,1).
6665 ! because of symmetry only the positive abscissae and their
6666 ! corresponding weights are given.
6667 !
6668 ! xgk - abscissae of the 21-point Kronrod rule
6669 ! xgk(2), xgk(4), ... abscissae of the 10-point
6670 ! Gauss rule
6671 ! xgk(1), xgk(3), ... abscissae which are optimally
6672 ! added to the 10-point Gauss rule
6673 !
6674 ! wgk - weights of the 21-point Kronrod rule
6675 !
6676 ! wg - weights of the 10-point Gauss rule
6677 !
6678  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8), &
6679  xgk(9),xgk(10),xgk(11)/ &
6680  9.956571630258081d-01, 9.739065285171717d-01, &
6681  9.301574913557082d-01, 8.650633666889845d-01, &
6682  7.808177265864169d-01, 6.794095682990244d-01, &
6683  5.627571346686047d-01, 4.333953941292472d-01, &
6684  2.943928627014602d-01, 1.488743389816312d-01, &
6685  0.000000000000000d+00/
6686 !
6687  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8), &
6688  wgk(9),wgk(10),wgk(11)/ &
6689  1.169463886737187d-02, 3.255816230796473d-02, &
6690  5.475589657435200d-02, 7.503967481091995d-02, &
6691  9.312545458369761d-02, 1.093871588022976d-01, &
6692  1.234919762620659d-01, 1.347092173114733d-01, &
6693  1.427759385770601d-01, 1.477391049013385d-01, &
6694  1.494455540029169d-01/
6695 !
6696  data wg(1),wg(2),wg(3),wg(4),wg(5)/ &
6697  6.667134430868814d-02, 1.494513491505806d-01, &
6698  2.190863625159820d-01, 2.692667193099964d-01, &
6699  2.955242247147529d-01/
6700 !
6701 !
6702 ! list of major variables
6703 !
6704 ! centr - mid point of the interval
6705 ! hlgth - half-length of the interval
6706 ! absc - abscissa
6707 ! fval* - function value
6708 ! resg - result of the 10-point Gauss formula
6709 ! resk - result of the 21-point Kronrod formula
6710 ! reskh - approximation to the mean value of f over (a,b),
6711 ! i.e. to i/(b-a)
6712 !
6713  centr = 5.0d-01*(a+b)
6714  hlgth = 5.0d-01*(b-a)
6715  dhlgth = abs(hlgth)
6716 !
6717 ! Compute the 21-point Kronrod approximation to the
6718 ! integral, and estimate the absolute error.
6719 !
6720  resg = 0.0d+00
6721  fc = f(centr)
6722  resk = wgk(11)*fc
6723  resabs = abs(resk)
6724 
6725  do j = 1, 5
6726  jtw = 2*j
6727  absc = hlgth*xgk(jtw)
6728  fval1 = f(centr-absc)
6729  fval2 = f(centr+absc)
6730  fv1(jtw) = fval1
6731  fv2(jtw) = fval2
6732  fsum = fval1+fval2
6733  resg = resg+wg(j)*fsum
6734  resk = resk+wgk(jtw)*fsum
6735  resabs = resabs+wgk(jtw)*(abs(fval1)+abs(fval2))
6736  end do
6737 
6738  do j = 1, 5
6739  jtwm1 = 2*j-1
6740  absc = hlgth*xgk(jtwm1)
6741  fval1 = f(centr-absc)
6742  fval2 = f(centr+absc)
6743  fv1(jtwm1) = fval1
6744  fv2(jtwm1) = fval2
6745  fsum = fval1+fval2
6746  resk = resk+wgk(jtwm1)*fsum
6747  resabs = resabs+wgk(jtwm1)*(abs(fval1)+abs(fval2))
6748  end do
6749 
6750  reskh = resk*5.0d-01
6751  resasc = wgk(11)*abs(fc-reskh)
6752 
6753  do j = 1, 10
6754  resasc = resasc+wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
6755  end do
6756 
6757  result = resk*hlgth
6758  resabs = resabs*dhlgth
6759  resasc = resasc*dhlgth
6760  abserr = abs((resk-resg)*hlgth)
6761 
6762  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00) then
6763  abserr = resasc*min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
6764  end if
6765 
6766  if ( resabs > tiny( resabs ) /(5.0d+01* epsilon( resabs ) )) then
6767  abserr = max(( epsilon( resabs ) *5.0d+01)*resabs,abserr)
6768  end if
6769 
6770  return
6771 end subroutine
6772 subroutine qk31 ( f, a, b, result, abserr, resabs, resasc )
6773 !
6774 !******************************************************************************
6775 !
6776 !! QK31 carries out a 31 point Gauss-Kronrod quadrature rule.
6777 !
6778 !
6779 ! Discussion:
6780 !
6781 ! This routine approximates
6782 ! I = integral ( A <= X <= B ) F(X) dx
6783 ! with an error estimate, and
6784 ! J = integral ( A <= X <= B ) | F(X) | dx
6785 !
6786 ! Reference:
6787 !
6788 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
6789 ! QUADPACK, a Subroutine Package for Automatic Integration,
6790 ! Springer Verlag, 1983
6791 !
6792 ! Parameters:
6793 !
6794 ! Input, external real(r_kind) F, the name of the function routine, of the form
6795 ! function f ( x )
6796 ! real(r_kind) f
6797 ! real(r_kind) x
6798 ! which evaluates the integrand function.
6799 !
6800 ! Input, real(r_kind) A, B, the limits of integration.
6801 !
6802 ! Output, real(r_kind) RESULT, the estimated value of the integral.
6803 ! result is computed by applying the 31-point
6804 ! Gauss-Kronrod rule (resk), obtained by optimal
6805 ! addition of abscissae to the 15-point Gauss
6806 ! rule (resg).
6807 !
6808 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
6809 !
6810 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
6811 ! value of F.
6812 !
6813 ! Output, real(r_kind) RESASC, approximation to the integral | F-I/(B-A) |
6814 ! over [A,B].
6815 !
6816  implicit none
6817 !
6818  real(r_kind) a
6819  real(r_kind) absc
6820  real(r_kind) abserr
6821  real(r_kind) b
6822  real(r_kind) centr
6823  real(r_kind) dhlgth
6824  real(r_kind), external :: f
6825  real(r_kind) fc
6826  real(r_kind) fsum
6827  real(r_kind) fval1
6828  real(r_kind) fval2
6829  real(r_kind) fv1(15)
6830  real(r_kind) fv2(15)
6831  real(r_kind) hlgth
6832  integer j
6833  integer jtw
6834  integer jtwm1
6835  real(r_kind) resabs
6836  real(r_kind) resasc
6837  real(r_kind) resg
6838  real(r_kind) resk
6839  real(r_kind) reskh
6840  real(r_kind) result
6841  real(r_kind) wg(8)
6842  real(r_kind) wgk(16)
6843  real(r_kind) xgk(16)
6844 !
6845 ! the abscissae and weights are given for the interval (-1,1).
6846 ! because of symmetry only the positive abscissae and their
6847 ! corresponding weights are given.
6848 !
6849 ! xgk - abscissae of the 31-point Kronrod rule
6850 ! xgk(2), xgk(4), ... abscissae of the 15-point
6851 ! Gauss rule
6852 ! xgk(1), xgk(3), ... abscissae which are optimally
6853 ! added to the 15-point Gauss rule
6854 !
6855 ! wgk - weights of the 31-point Kronrod rule
6856 !
6857 ! wg - weights of the 15-point Gauss rule
6858 !
6859  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8), &
6860  xgk(9),xgk(10),xgk(11),xgk(12),xgk(13),xgk(14),xgk(15),xgk(16)/ &
6861  9.980022986933971d-01, 9.879925180204854d-01, &
6862  9.677390756791391d-01, 9.372733924007059d-01, &
6863  8.972645323440819d-01, 8.482065834104272d-01, &
6864  7.904185014424659d-01, 7.244177313601700d-01, &
6865  6.509967412974170d-01, 5.709721726085388d-01, &
6866  4.850818636402397d-01, 3.941513470775634d-01, &
6867  2.991800071531688d-01, 2.011940939974345d-01, &
6868  1.011420669187175d-01, 0.0d+00 /
6869  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8), &
6870  wgk(9),wgk(10),wgk(11),wgk(12),wgk(13),wgk(14),wgk(15),wgk(16)/ &
6871  5.377479872923349d-03, 1.500794732931612d-02, &
6872  2.546084732671532d-02, 3.534636079137585d-02, &
6873  4.458975132476488d-02, 5.348152469092809d-02, &
6874  6.200956780067064d-02, 6.985412131872826d-02, &
6875  7.684968075772038d-02, 8.308050282313302d-02, &
6876  8.856444305621177d-02, 9.312659817082532d-02, &
6877  9.664272698362368d-02, 9.917359872179196d-02, &
6878  1.007698455238756d-01, 1.013300070147915d-01/
6879  data wg(1),wg(2),wg(3),wg(4),wg(5),wg(6),wg(7),wg(8)/ &
6880  3.075324199611727d-02, 7.036604748810812d-02, &
6881  1.071592204671719d-01, 1.395706779261543d-01, &
6882  1.662692058169939d-01, 1.861610000155622d-01, &
6883  1.984314853271116d-01, 2.025782419255613d-01/
6884 !
6885 !
6886 ! list of major variables
6887 !
6888 ! centr - mid point of the interval
6889 ! hlgth - half-length of the interval
6890 ! absc - abscissa
6891 ! fval* - function value
6892 ! resg - result of the 15-point Gauss formula
6893 ! resk - result of the 31-point Kronrod formula
6894 ! reskh - approximation to the mean value of f over (a,b),
6895 ! i.e. to i/(b-a)
6896 !
6897  centr = 5.0d-01*(a+b)
6898  hlgth = 5.0d-01*(b-a)
6899  dhlgth = abs(hlgth)
6900 !
6901 ! Compute the 31-point Kronrod approximation to the integral,
6902 ! and estimate the absolute error.
6903 !
6904  fc = f(centr)
6905  resg = wg(8)*fc
6906  resk = wgk(16)*fc
6907  resabs = abs(resk)
6908 
6909  do j = 1, 7
6910  jtw = j*2
6911  absc = hlgth*xgk(jtw)
6912  fval1 = f(centr-absc)
6913  fval2 = f(centr+absc)
6914  fv1(jtw) = fval1
6915  fv2(jtw) = fval2
6916  fsum = fval1+fval2
6917  resg = resg+wg(j)*fsum
6918  resk = resk+wgk(jtw)*fsum
6919  resabs = resabs+wgk(jtw)*(abs(fval1)+abs(fval2))
6920  end do
6921 
6922  do j = 1, 8
6923  jtwm1 = j*2-1
6924  absc = hlgth*xgk(jtwm1)
6925  fval1 = f(centr-absc)
6926  fval2 = f(centr+absc)
6927  fv1(jtwm1) = fval1
6928  fv2(jtwm1) = fval2
6929  fsum = fval1+fval2
6930  resk = resk+wgk(jtwm1)*fsum
6931  resabs = resabs+wgk(jtwm1)*(abs(fval1)+abs(fval2))
6932  end do
6933 
6934  reskh = resk*5.0d-01
6935  resasc = wgk(16)*abs(fc-reskh)
6936 
6937  do j = 1, 15
6938  resasc = resasc+wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
6939  end do
6940 
6941  result = resk*hlgth
6942  resabs = resabs*dhlgth
6943  resasc = resasc*dhlgth
6944  abserr = abs((resk-resg)*hlgth)
6945 
6946  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00) &
6947  abserr = resasc*min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
6948 
6949  if ( resabs > tiny( resabs ) /(5.0d+01* epsilon( resabs ) )) then
6950  abserr = max(( epsilon( resabs ) *5.0d+01)*resabs,abserr)
6951  end if
6952 
6953  return
6954 end subroutine
6955 subroutine qk41 ( f, a, b, result, abserr, resabs, resasc )
6956 !
6957 !******************************************************************************
6958 !
6959 !! QK41 carries out a 41 point Gauss-Kronrod quadrature rule.
6960 !
6961 !
6962 ! Discussion:
6963 !
6964 ! This routine approximates
6965 ! I = integral ( A <= X <= B ) F(X) dx
6966 ! with an error estimate, and
6967 ! J = integral ( A <= X <= B ) | F(X) | dx
6968 !
6969 ! Reference:
6970 !
6971 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
6972 ! QUADPACK, a Subroutine Package for Automatic Integration,
6973 ! Springer Verlag, 1983
6974 !
6975 ! Parameters:
6976 !
6977 ! Input, external real(r_kind) F, the name of the function routine, of the form
6978 ! function f ( x )
6979 ! real(r_kind) f
6980 ! real(r_kind) x
6981 ! which evaluates the integrand function.
6982 !
6983 ! Input, real(r_kind) A, B, the limits of integration.
6984 !
6985 ! Output, real(r_kind) RESULT, the estimated value of the integral.
6986 ! result is computed by applying the 41-point
6987 ! Gauss-Kronrod rule (resk) obtained by optimal
6988 ! addition of abscissae to the 20-point Gauss
6989 ! rule (resg).
6990 !
6991 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
6992 !
6993 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
6994 ! value of F.
6995 !
6996 ! Output, real(r_kind) RESASC, approximation to the integral | F-I/(B-A) |
6997 ! over [A,B].
6998 !
6999 ! Local Parameters:
7000 !
7001 ! centr - mid point of the interval
7002 ! hlgth - half-length of the interval
7003 ! absc - abscissa
7004 ! fval* - function value
7005 ! resg - result of the 20-point Gauss formula
7006 ! resk - result of the 41-point Kronrod formula
7007 ! reskh - approximation to mean value of f over (a,b), i.e.
7008 ! to i/(b-a)
7009 !
7010  implicit none
7011 !
7012  real(r_kind) a
7013  real(r_kind) absc
7014  real(r_kind) abserr
7015  real(r_kind) b
7016  real(r_kind) centr
7017  real(r_kind) dhlgth
7018  real(r_kind), external :: f
7019  real(r_kind) fc
7020  real(r_kind) fsum
7021  real(r_kind) fval1
7022  real(r_kind) fval2
7023  real(r_kind) fv1(20)
7024  real(r_kind) fv2(20)
7025  real(r_kind) hlgth
7026  integer j
7027  integer jtw
7028  integer jtwm1
7029  real(r_kind) resabs
7030  real(r_kind) resasc
7031  real(r_kind) resg
7032  real(r_kind) resk
7033  real(r_kind) reskh
7034  real(r_kind) result
7035  real(r_kind) wg(10)
7036  real(r_kind) wgk(21)
7037  real(r_kind) xgk(21)
7038 !
7039 ! the abscissae and weights are given for the interval (-1,1).
7040 ! because of symmetry only the positive abscissae and their
7041 ! corresponding weights are given.
7042 !
7043 ! xgk - abscissae of the 41-point Gauss-Kronrod rule
7044 ! xgk(2), xgk(4), ... abscissae of the 20-point
7045 ! Gauss rule
7046 ! xgk(1), xgk(3), ... abscissae which are optimally
7047 ! added to the 20-point Gauss rule
7048 !
7049 ! wgk - weights of the 41-point Gauss-Kronrod rule
7050 !
7051 ! wg - weights of the 20-point Gauss rule
7052 !
7053  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8), &
7054  xgk(9),xgk(10),xgk(11),xgk(12),xgk(13),xgk(14),xgk(15),xgk(16), &
7055  xgk(17),xgk(18),xgk(19),xgk(20),xgk(21)/ &
7056  9.988590315882777d-01, 9.931285991850949d-01, &
7057  9.815078774502503d-01, 9.639719272779138d-01, &
7058  9.408226338317548d-01, 9.122344282513259d-01, &
7059  8.782768112522820d-01, 8.391169718222188d-01, &
7060  7.950414288375512d-01, 7.463319064601508d-01, &
7061  6.932376563347514d-01, 6.360536807265150d-01, &
7062  5.751404468197103d-01, 5.108670019508271d-01, &
7063  4.435931752387251d-01, 3.737060887154196d-01, &
7064  3.016278681149130d-01, 2.277858511416451d-01, &
7065  1.526054652409227d-01, 7.652652113349733d-02, &
7066  0.0d+00 /
7067  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8), &
7068  wgk(9),wgk(10),wgk(11),wgk(12),wgk(13),wgk(14),wgk(15),wgk(16), &
7069  wgk(17),wgk(18),wgk(19),wgk(20),wgk(21)/ &
7070  3.073583718520532d-03, 8.600269855642942d-03, &
7071  1.462616925697125d-02, 2.038837346126652d-02, &
7072  2.588213360495116d-02, 3.128730677703280d-02, &
7073  3.660016975820080d-02, 4.166887332797369d-02, &
7074  4.643482186749767d-02, 5.094457392372869d-02, &
7075  5.519510534828599d-02, 5.911140088063957d-02, &
7076  6.265323755478117d-02, 6.583459713361842d-02, &
7077  6.864867292852162d-02, 7.105442355344407d-02, &
7078  7.303069033278667d-02, 7.458287540049919d-02, &
7079  7.570449768455667d-02, 7.637786767208074d-02, &
7080  7.660071191799966d-02/
7081  data wg(1),wg(2),wg(3),wg(4),wg(5),wg(6),wg(7),wg(8),wg(9),wg(10)/ &
7082  1.761400713915212d-02, 4.060142980038694d-02, &
7083  6.267204833410906d-02, 8.327674157670475d-02, &
7084  1.019301198172404d-01, 1.181945319615184d-01, &
7085  1.316886384491766d-01, 1.420961093183821d-01, &
7086  1.491729864726037d-01, 1.527533871307259d-01/
7087 !
7088  centr = 5.0d-01*(a+b)
7089  hlgth = 5.0d-01*(b-a)
7090  dhlgth = abs(hlgth)
7091 !
7092 ! Compute 41-point Gauss-Kronrod approximation to the
7093 ! the integral, and estimate the absolute error.
7094 !
7095  resg = 0.0d+00
7096  fc = f(centr)
7097  resk = wgk(21)*fc
7098  resabs = abs(resk)
7099 
7100  do j = 1, 10
7101  jtw = j*2
7102  absc = hlgth*xgk(jtw)
7103  fval1 = f(centr-absc)
7104  fval2 = f(centr+absc)
7105  fv1(jtw) = fval1
7106  fv2(jtw) = fval2
7107  fsum = fval1+fval2
7108  resg = resg+wg(j)*fsum
7109  resk = resk+wgk(jtw)*fsum
7110  resabs = resabs+wgk(jtw)*(abs(fval1)+abs(fval2))
7111  end do
7112 
7113  do j = 1, 10
7114  jtwm1 = j*2-1
7115  absc = hlgth*xgk(jtwm1)
7116  fval1 = f(centr-absc)
7117  fval2 = f(centr+absc)
7118  fv1(jtwm1) = fval1
7119  fv2(jtwm1) = fval2
7120  fsum = fval1+fval2
7121  resk = resk+wgk(jtwm1)*fsum
7122  resabs = resabs+wgk(jtwm1)*(abs(fval1)+abs(fval2))
7123  end do
7124 
7125  reskh = resk*5.0d-01
7126  resasc = wgk(21)*abs(fc-reskh)
7127 
7128  do j = 1, 20
7129  resasc = resasc+wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
7130  end do
7131 
7132  result = resk*hlgth
7133  resabs = resabs*dhlgth
7134  resasc = resasc*dhlgth
7135  abserr = abs((resk-resg)*hlgth)
7136 
7137  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00) &
7138  abserr = resasc*min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
7139 
7140  if ( resabs > tiny( resabs ) /(5.0d+01* epsilon( resabs ) )) then
7141  abserr = max(( epsilon( resabs ) *5.0d+01)*resabs,abserr)
7142  end if
7143 
7144  return
7145 end subroutine
7146 subroutine qk51 ( f, a, b, result, abserr, resabs, resasc )
7147 !
7148 !******************************************************************************
7149 !
7150 !! QK51 carries out a 51 point Gauss-Kronrod quadrature rule.
7151 !
7152 !
7153 ! Discussion:
7154 !
7155 ! This routine approximates
7156 ! I = integral ( A <= X <= B ) F(X) dx
7157 ! with an error estimate, and
7158 ! J = integral ( A <= X <= B ) | F(X) | dx
7159 !
7160 ! Reference:
7161 !
7162 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
7163 ! QUADPACK, a Subroutine Package for Automatic Integration,
7164 ! Springer Verlag, 1983
7165 !
7166 ! Parameters:
7167 !
7168 ! Input, external real(r_kind) F, the name of the function routine, of the form
7169 ! function f ( x )
7170 ! real(r_kind) f
7171 ! real(r_kind) x
7172 ! which evaluates the integrand function.
7173 !
7174 ! Input, real(r_kind) A, B, the limits of integration.
7175 !
7176 ! Output, real(r_kind) RESULT, the estimated value of the integral.
7177 ! result is computed by applying the 51-point
7178 ! Kronrod rule (resk) obtained by optimal addition
7179 ! of abscissae to the 25-point Gauss rule (resg).
7180 !
7181 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
7182 !
7183 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
7184 ! value of F.
7185 !
7186 ! Output, real(r_kind) RESASC, approximation to the integral | F-I/(B-A) |
7187 ! over [A,B].
7188 !
7189 ! Local Parameters:
7190 !
7191 ! centr - mid point of the interval
7192 ! hlgth - half-length of the interval
7193 ! absc - abscissa
7194 ! fval* - function value
7195 ! resg - result of the 25-point Gauss formula
7196 ! resk - result of the 51-point Kronrod formula
7197 ! reskh - approximation to the mean value of f over (a,b),
7198 ! i.e. to i/(b-a)
7199 !
7200  implicit none
7201 !
7202  real(r_kind) a
7203  real(r_kind) absc
7204  real(r_kind) abserr
7205  real(r_kind) b
7206  real(r_kind) centr
7207  real(r_kind) dhlgth
7208  real(r_kind), external :: f
7209  real(r_kind) fc
7210  real(r_kind) fsum
7211  real(r_kind) fval1
7212  real(r_kind) fval2
7213  real(r_kind) fv1(25)
7214  real(r_kind) fv2(25)
7215  real(r_kind) hlgth
7216  integer j
7217  integer jtw
7218  integer jtwm1
7219  real(r_kind) resabs
7220  real(r_kind) resasc
7221  real(r_kind) resg
7222  real(r_kind) resk
7223  real(r_kind) reskh
7224  real(r_kind) result
7225  real(r_kind) wg(13)
7226  real(r_kind) wgk(26)
7227  real(r_kind) xgk(26)
7228 !
7229 ! the abscissae and weights are given for the interval (-1,1).
7230 ! because of symmetry only the positive abscissae and their
7231 ! corresponding weights are given.
7232 !
7233 ! xgk - abscissae of the 51-point Kronrod rule
7234 ! xgk(2), xgk(4), ... abscissae of the 25-point
7235 ! Gauss rule
7236 ! xgk(1), xgk(3), ... abscissae which are optimally
7237 ! added to the 25-point Gauss rule
7238 !
7239 ! wgk - weights of the 51-point Kronrod rule
7240 !
7241 ! wg - weights of the 25-point Gauss rule
7242 !
7243  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8), &
7244  xgk(9),xgk(10),xgk(11),xgk(12),xgk(13),xgk(14)/ &
7245  9.992621049926098d-01, 9.955569697904981d-01, &
7246  9.880357945340772d-01, 9.766639214595175d-01, &
7247  9.616149864258425d-01, 9.429745712289743d-01, &
7248  9.207471152817016d-01, 8.949919978782754d-01, &
7249  8.658470652932756d-01, 8.334426287608340d-01, &
7250  7.978737979985001d-01, 7.592592630373576d-01, &
7251  7.177664068130844d-01, 6.735663684734684d-01/
7252  data xgk(15),xgk(16),xgk(17),xgk(18),xgk(19),xgk(20),xgk(21), &
7253  xgk(22),xgk(23),xgk(24),xgk(25),xgk(26)/ &
7254  6.268100990103174d-01, 5.776629302412230d-01, &
7255  5.263252843347192d-01, 4.730027314457150d-01, &
7256  4.178853821930377d-01, 3.611723058093878d-01, &
7257  3.030895389311078d-01, 2.438668837209884d-01, &
7258  1.837189394210489d-01, 1.228646926107104d-01, &
7259  6.154448300568508d-02, 0.0d+00 /
7260  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8), &
7261  wgk(9),wgk(10),wgk(11),wgk(12),wgk(13),wgk(14)/ &
7262  1.987383892330316d-03, 5.561932135356714d-03, &
7263  9.473973386174152d-03, 1.323622919557167d-02, &
7264  1.684781770912830d-02, 2.043537114588284d-02, &
7265  2.400994560695322d-02, 2.747531758785174d-02, &
7266  3.079230016738749d-02, 3.400213027432934d-02, &
7267  3.711627148341554d-02, 4.008382550403238d-02, &
7268  4.287284502017005d-02, 4.550291304992179d-02/
7269  data wgk(15),wgk(16),wgk(17),wgk(18),wgk(19),wgk(20),wgk(21), &
7270  wgk(22),wgk(23),wgk(24),wgk(25),wgk(26)/ &
7271  4.798253713883671d-02, 5.027767908071567d-02, &
7272  5.236288580640748d-02, 5.425112988854549d-02, &
7273  5.595081122041232d-02, 5.743711636156783d-02, &
7274  5.868968002239421d-02, 5.972034032417406d-02, &
7275  6.053945537604586d-02, 6.112850971705305d-02, &
7276  6.147118987142532d-02, 6.158081806783294d-02/
7277  data wg(1),wg(2),wg(3),wg(4),wg(5),wg(6),wg(7),wg(8),wg(9),wg(10), &
7278  wg(11),wg(12),wg(13)/ &
7279  1.139379850102629d-02, 2.635498661503214d-02, &
7280  4.093915670130631d-02, 5.490469597583519d-02, &
7281  6.803833381235692d-02, 8.014070033500102d-02, &
7282  9.102826198296365d-02, 1.005359490670506d-01, &
7283  1.085196244742637d-01, 1.148582591457116d-01, &
7284  1.194557635357848d-01, 1.222424429903100d-01, &
7285  1.231760537267155d-01/
7286 !
7287  centr = 5.0d-01*(a+b)
7288  hlgth = 5.0d-01*(b-a)
7289  dhlgth = abs(hlgth)
7290 !
7291 ! Compute the 51-point Kronrod approximation to the integral,
7292 ! and estimate the absolute error.
7293 !
7294  fc = f(centr)
7295  resg = wg(13)*fc
7296  resk = wgk(26)*fc
7297  resabs = abs(resk)
7298 
7299  do j = 1, 12
7300  jtw = j*2
7301  absc = hlgth*xgk(jtw)
7302  fval1 = f(centr-absc)
7303  fval2 = f(centr+absc)
7304  fv1(jtw) = fval1
7305  fv2(jtw) = fval2
7306  fsum = fval1+fval2
7307  resg = resg+wg(j)*fsum
7308  resk = resk+wgk(jtw)*fsum
7309  resabs = resabs+wgk(jtw)*(abs(fval1)+abs(fval2))
7310  end do
7311 
7312  do j = 1, 13
7313  jtwm1 = j*2-1
7314  absc = hlgth*xgk(jtwm1)
7315  fval1 = f(centr-absc)
7316  fval2 = f(centr+absc)
7317  fv1(jtwm1) = fval1
7318  fv2(jtwm1) = fval2
7319  fsum = fval1+fval2
7320  resk = resk+wgk(jtwm1)*fsum
7321  resabs = resabs+wgk(jtwm1)*(abs(fval1)+abs(fval2))
7322  end do
7323 
7324  reskh = resk*5.0d-01
7325  resasc = wgk(26)*abs(fc-reskh)
7326 
7327  do j = 1, 25
7328  resasc = resasc+wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
7329  end do
7330 
7331  result = resk*hlgth
7332  resabs = resabs*dhlgth
7333  resasc = resasc*dhlgth
7334  abserr = abs((resk-resg)*hlgth)
7335 
7336  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00) then
7337  abserr = resasc*min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
7338  end if
7339 
7340  if ( resabs > tiny( resabs ) / (5.0d+01* epsilon( resabs ) ) ) then
7341  abserr = max(( epsilon( resabs ) *5.0d+01)*resabs,abserr)
7342  end if
7343 
7344  return
7345 end subroutine
7346 subroutine qk61 ( f, a, b, result, abserr, resabs, resasc )
7347 !
7348 !******************************************************************************
7349 !
7350 !! QK61 carries out a 61 point Gauss-Kronrod quadrature rule.
7351 !
7352 !
7353 ! Discussion:
7354 !
7355 ! This routine approximates
7356 ! I = integral ( A <= X <= B ) F(X) dx
7357 ! with an error estimate, and
7358 ! J = integral ( A <= X <= B ) | F(X) | dx
7359 !
7360 ! Reference:
7361 !
7362 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
7363 ! QUADPACK, a Subroutine Package for Automatic Integration,
7364 ! Springer Verlag, 1983
7365 !
7366 ! Parameters:
7367 !
7368 ! Input, external real(r_kind) F, the name of the function routine, of the form
7369 ! function f ( x )
7370 ! real(r_kind) f
7371 ! real(r_kind) x
7372 ! which evaluates the integrand function.
7373 !
7374 ! Input, real(r_kind) A, B, the limits of integration.
7375 !
7376 ! Output, real(r_kind) RESULT, the estimated value of the integral.
7377 ! result is computed by applying the 61-point
7378 ! Kronrod rule (resk) obtained by optimal addition of
7379 ! abscissae to the 30-point Gauss rule (resg).
7380 !
7381 ! Output, real(r_kind) ABSERR, an estimate of | I - RESULT |.
7382 !
7383 ! Output, real(r_kind) RESABS, approximation to the integral of the absolute
7384 ! value of F.
7385 !
7386 ! Output, real(r_kind) RESASC, approximation to the integral | F-I/(B-A) |
7387 ! over [A,B].
7388 !
7389 ! Local Parameters:
7390 !
7391 ! centr - mid point of the interval
7392 ! hlgth - half-length of the interval
7393 ! absc - abscissa
7394 ! fval* - function value
7395 ! resg - result of the 30-point Gauss rule
7396 ! resk - result of the 61-point Kronrod rule
7397 ! reskh - approximation to the mean value of f
7398 ! over (a,b), i.e. to i/(b-a)
7399 !
7400  implicit none
7401 !
7402  real(r_kind) a
7403  real(r_kind) absc
7404  real(r_kind) abserr
7405  real(r_kind) b
7406  real(r_kind) centr
7407  real(r_kind) dhlgth
7408  real(r_kind), external :: f
7409  real(r_kind) fc
7410  real(r_kind) fsum
7411  real(r_kind) fval1
7412  real(r_kind) fval2
7413  real(r_kind) fv1(30)
7414  real(r_kind) fv2(30)
7415  real(r_kind) hlgth
7416  integer j
7417  integer jtw
7418  integer jtwm1
7419  real(r_kind) resabs
7420  real(r_kind) resasc
7421  real(r_kind) resg
7422  real(r_kind) resk
7423  real(r_kind) reskh
7424  real(r_kind) result
7425  real(r_kind) wg(15)
7426  real(r_kind) wgk(31)
7427  real(r_kind) xgk(31)
7428 !
7429 ! the abscissae and weights are given for the
7430 ! interval (-1,1). because of symmetry only the positive
7431 ! abscissae and their corresponding weights are given.
7432 !
7433 ! xgk - abscissae of the 61-point Kronrod rule
7434 ! xgk(2), xgk(4) ... abscissae of the 30-point
7435 ! Gauss rule
7436 ! xgk(1), xgk(3) ... optimally added abscissae
7437 ! to the 30-point Gauss rule
7438 !
7439 ! wgk - weights of the 61-point Kronrod rule
7440 !
7441 ! wg - weigths of the 30-point Gauss rule
7442 !
7443  data xgk(1),xgk(2),xgk(3),xgk(4),xgk(5),xgk(6),xgk(7),xgk(8), &
7444  xgk(9),xgk(10)/ &
7445  9.994844100504906d-01, 9.968934840746495d-01, &
7446  9.916309968704046d-01, 9.836681232797472d-01, &
7447  9.731163225011263d-01, 9.600218649683075d-01, &
7448  9.443744447485600d-01, 9.262000474292743d-01, &
7449  9.055733076999078d-01, 8.825605357920527d-01/
7450  data xgk(11),xgk(12),xgk(13),xgk(14),xgk(15),xgk(16),xgk(17), &
7451  xgk(18),xgk(19),xgk(20)/ &
7452  8.572052335460611d-01, 8.295657623827684d-01, &
7453  7.997278358218391d-01, 7.677774321048262d-01, &
7454  7.337900624532268d-01, 6.978504947933158d-01, &
7455  6.600610641266270d-01, 6.205261829892429d-01, &
7456  5.793452358263617d-01, 5.366241481420199d-01/
7457  data xgk(21),xgk(22),xgk(23),xgk(24),xgk(25),xgk(26),xgk(27), &
7458  xgk(28),xgk(29),xgk(30),xgk(31)/ &
7459  4.924804678617786d-01, 4.470337695380892d-01, &
7460  4.004012548303944d-01, 3.527047255308781d-01, &
7461  3.040732022736251d-01, 2.546369261678898d-01, &
7462  2.045251166823099d-01, 1.538699136085835d-01, &
7463  1.028069379667370d-01, 5.147184255531770d-02, &
7464  0.0d+00 /
7465  data wgk(1),wgk(2),wgk(3),wgk(4),wgk(5),wgk(6),wgk(7),wgk(8), &
7466  wgk(9),wgk(10)/ &
7467  1.389013698677008d-03, 3.890461127099884d-03, &
7468  6.630703915931292d-03, 9.273279659517763d-03, &
7469  1.182301525349634d-02, 1.436972950704580d-02, &
7470  1.692088918905327d-02, 1.941414119394238d-02, &
7471  2.182803582160919d-02, 2.419116207808060d-02/
7472  data wgk(11),wgk(12),wgk(13),wgk(14),wgk(15),wgk(16),wgk(17), &
7473  wgk(18),wgk(19),wgk(20)/ &
7474  2.650995488233310d-02, 2.875404876504129d-02, &
7475  3.090725756238776d-02, 3.298144705748373d-02, &
7476  3.497933802806002d-02, 3.688236465182123d-02, &
7477  3.867894562472759d-02, 4.037453895153596d-02, &
7478  4.196981021516425d-02, 4.345253970135607d-02/
7479  data wgk(21),wgk(22),wgk(23),wgk(24),wgk(25),wgk(26),wgk(27), &
7480  wgk(28),wgk(29),wgk(30),wgk(31)/ &
7481  4.481480013316266d-02, 4.605923827100699d-02, &
7482  4.718554656929915d-02, 4.818586175708713d-02, &
7483  4.905543455502978d-02, 4.979568342707421d-02, &
7484  5.040592140278235d-02, 5.088179589874961d-02, &
7485  5.122154784925877d-02, 5.142612853745903d-02, &
7486  5.149472942945157d-02/
7487  data wg(1),wg(2),wg(3),wg(4),wg(5),wg(6),wg(7),wg(8)/ &
7488  7.968192496166606d-03, 1.846646831109096d-02, &
7489  2.878470788332337d-02, 3.879919256962705d-02, &
7490  4.840267283059405d-02, 5.749315621761907d-02, &
7491  6.597422988218050d-02, 7.375597473770521d-02/
7492  data wg(9),wg(10),wg(11),wg(12),wg(13),wg(14),wg(15)/ &
7493  8.075589522942022d-02, 8.689978720108298d-02, &
7494  9.212252223778613d-02, 9.636873717464426d-02, &
7495  9.959342058679527d-02, 1.017623897484055d-01, &
7496  1.028526528935588d-01/
7497 !
7498  centr = 5.0d-01*(b+a)
7499  hlgth = 5.0d-01*(b-a)
7500  dhlgth = abs(hlgth)
7501 !
7502 ! Compute the 61-point Kronrod approximation to the integral,
7503 ! and estimate the absolute error.
7504 !
7505  resg = 0.0d+00
7506  fc = f(centr)
7507  resk = wgk(31)*fc
7508  resabs = abs(resk)
7509 
7510  do j = 1, 15
7511  jtw = j*2
7512  absc = hlgth*xgk(jtw)
7513  fval1 = f(centr-absc)
7514  fval2 = f(centr+absc)
7515  fv1(jtw) = fval1
7516  fv2(jtw) = fval2
7517  fsum = fval1+fval2
7518  resg = resg+wg(j)*fsum
7519  resk = resk+wgk(jtw)*fsum
7520  resabs = resabs+wgk(jtw)*(abs(fval1)+abs(fval2))
7521  end do
7522 
7523  do j = 1, 15
7524  jtwm1 = j*2-1
7525  absc = hlgth*xgk(jtwm1)
7526  fval1 = f(centr-absc)
7527  fval2 = f(centr+absc)
7528  fv1(jtwm1) = fval1
7529  fv2(jtwm1) = fval2
7530  fsum = fval1+fval2
7531  resk = resk+wgk(jtwm1)*fsum
7532  resabs = resabs+wgk(jtwm1)*(abs(fval1)+abs(fval2))
7533  end do
7534 
7535  reskh = resk * 5.0d-01
7536  resasc = wgk(31)*abs(fc-reskh)
7537 
7538  do j = 1, 30
7539  resasc = resasc+wgk(j)*(abs(fv1(j)-reskh)+abs(fv2(j)-reskh))
7540  end do
7541 
7542  result = resk*hlgth
7543  resabs = resabs*dhlgth
7544  resasc = resasc*dhlgth
7545  abserr = abs((resk-resg)*hlgth)
7546 
7547  if ( resasc /= 0.0d+00 .and. abserr /= 0.0d+00) then
7548  abserr = resasc*min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
7549  end if
7550 
7551  if ( resabs > tiny( resabs ) / (5.0d+01* epsilon( resabs ) )) then
7552  abserr = max( ( epsilon( resabs ) *5.0d+01)*resabs, abserr )
7553  end if
7554 
7555 
7556  return
7557 end subroutine
7558 subroutine qmomo ( alfa, beta, ri, rj, rg, rh, integr )
7559 !
7560 !******************************************************************************
7561 !
7562 !! QMOMO computes modified Chebyshev moments.
7563 !
7564 !
7565 ! Discussion:
7566 !
7567 ! This routine computes modified Chebyshev moments.
7568 ! The K-th modified Chebyshev moment is defined as the
7569 ! integral over (-1,1) of W(X)*T(K,X), where T(K,X) is the
7570 ! Chebyshev polynomial of degree K.
7571 !
7572 ! Reference:
7573 !
7574 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
7575 ! QUADPACK, a Subroutine Package for Automatic Integration,
7576 ! Springer Verlag, 1983
7577 !
7578 ! Parameters:
7579 !
7580 ! Input, real(r_kind) ALFA, a parameter in the weight function w(x), ALFA > -1.
7581 !
7582 ! Input, real(r_kind) BETA, a parameter in the weight function w(x), BETA > -1.
7583 !
7584 ! ri - real
7585 ! vector of dimension 25
7586 ! ri(k) is the integral over (-1,1) of
7587 ! (1+x)**alfa*t(k-1,x), k = 1, ..., 25.
7588 !
7589 ! rj - real
7590 ! vector of dimension 25
7591 ! rj(k) is the integral over (-1,1) of
7592 ! (1-x)**beta*t(k-1,x), k = 1, ..., 25.
7593 !
7594 ! rg - real
7595 ! vector of dimension 25
7596 ! rg(k) is the integral over (-1,1) of
7597 ! (1+x)**alfa*log((1+x)/2)*t(k-1,x), k = 1, ...,25.
7598 !
7599 ! rh - real
7600 ! vector of dimension 25
7601 ! rh(k) is the integral over (-1,1) of
7602 ! (1-x)**beta*log((1-x)/2)*t(k-1,x), k = 1, ..., 25.
7603 !
7604 ! integr - integer
7605 ! input parameter indicating the modified moments
7606 ! to be computed
7607 ! integr = 1 compute ri, rj
7608 ! = 2 compute ri, rj, rg
7609 ! = 3 compute ri, rj, rh
7610 ! = 4 compute ri, rj, rg, rh
7611 !
7612  implicit none
7613 !
7614  real(r_kind) alfa
7615  real(r_kind) alfp1
7616  real(r_kind) alfp2
7617  real(r_kind) an
7618  real(r_kind) anm1
7619  real(r_kind) beta
7620  real(r_kind) betp1
7621  real(r_kind) betp2
7622  integer i
7623  integer im1
7624  integer integr
7625  real(r_kind) ralf
7626  real(r_kind) rbet
7627  real(r_kind) rg(25)
7628  real(r_kind) rh(25)
7629  real(r_kind) ri(25)
7630  real(r_kind) rj(25)
7631 !
7632  alfp1 = alfa+1.0d+00
7633  betp1 = beta+1.0d+00
7634  alfp2 = alfa+2.0d+00
7635  betp2 = beta+2.0d+00
7636  ralf = 2.0d+00**alfp1
7637  rbet = 2.0d+00**betp1
7638 !
7639 ! Compute RI, RJ using a forward recurrence relation.
7640 !
7641  ri(1) = ralf/alfp1
7642  rj(1) = rbet/betp1
7643  ri(2) = ri(1)*alfa/alfp2
7644  rj(2) = rj(1)*beta/betp2
7645  an = 2.0d+00
7646  anm1 = 1.0d+00
7647 
7648  do i = 3, 25
7649  ri(i) = -(ralf+an*(an-alfp2)*ri(i-1))/(anm1*(an+alfp1))
7650  rj(i) = -(rbet+an*(an-betp2)*rj(i-1))/(anm1*(an+betp1))
7651  anm1 = an
7652  an = an+1.0d+00
7653  end do
7654 
7655  if ( integr == 1 ) go to 70
7656  if ( integr == 3 ) go to 40
7657 !
7658 ! Compute RG using a forward recurrence relation.
7659 !
7660  rg(1) = -ri(1)/alfp1
7661  rg(2) = -(ralf+ralf)/(alfp2*alfp2)-rg(1)
7662  an = 2.0d+00
7663  anm1 = 1.0d+00
7664  im1 = 2
7665 
7666  do i = 3, 25
7667  rg(i) = -(an*(an-alfp2)*rg(im1)-an*ri(im1)+anm1*ri(i))/ &
7668  (anm1*(an+alfp1))
7669  anm1 = an
7670  an = an+1.0d+00
7671  im1 = i
7672  end do
7673 
7674  if ( integr == 2 ) go to 70
7675 !
7676 ! Compute RH using a forward recurrence relation.
7677 !
7678 40 continue
7679 
7680  rh(1) = -rj(1) / betp1
7681  rh(2) = -(rbet+rbet)/(betp2*betp2)-rh(1)
7682  an = 2.0d+00
7683  anm1 = 1.0d+00
7684  im1 = 2
7685 
7686  do i = 3, 25
7687  rh(i) = -(an*(an-betp2)*rh(im1)-an*rj(im1)+ &
7688  anm1*rj(i))/(anm1*(an+betp1))
7689  anm1 = an
7690  an = an+1.0d+00
7691  im1 = i
7692  end do
7693 
7694  do i = 2, 25, 2
7695  rh(i) = -rh(i)
7696  end do
7697 
7698  70 continue
7699 
7700  do i = 2, 25, 2
7701  rj(i) = -rj(i)
7702  end do
7703 
7704  90 continue
7705 
7706  return
7707 end subroutine
7708 subroutine qng ( f, a, b, epsabs, epsrel, result, abserr, neval, ier )
7709 !
7710 !******************************************************************************
7711 !
7712 !! QNG estimates an integral, using non-adaptive integration.
7713 !
7714 !
7715 ! Discussion:
7716 !
7717 ! The routine calculates an approximation RESULT to a definite integral
7718 ! I = integral of F over (A,B),
7719 ! hopefully satisfying
7720 ! || I - RESULT || <= max ( EPSABS, EPSREL * ||I|| ).
7721 !
7722 ! The routine is a simple non-adaptive automatic integrator, based on
7723 ! a sequence of rules with increasing degree of algebraic
7724 ! precision (Patterson, 1968).
7725 !
7726 ! Reference:
7727 !
7728 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
7729 ! QUADPACK, a Subroutine Package for Automatic Integration,
7730 ! Springer Verlag, 1983
7731 !
7732 ! Parameters:
7733 !
7734 ! Input, external real(r_kind) F, the name of the function routine, of the form
7735 ! function f ( x )
7736 ! real(r_kind) f
7737 ! real(r_kind) x
7738 ! which evaluates the integrand function.
7739 !
7740 ! Input, real(r_kind) A, B, the limits of integration.
7741 !
7742 ! Input, real(r_kind) EPSABS, EPSREL, the absolute and relative accuracy requested.
7743 !
7744 ! Output, real(r_kind) RESULT, the estimated value of the integral.
7745 ! RESULT is obtained by applying the 21-point Gauss-Kronrod rule (RES21)
7746 ! obtained by optimal addition of abscissae to the 10-point Gauss rule
7747 ! (RES10), or by applying the 43-point rule (RES43) obtained by optimal
7748 ! addition of abscissae to the 21-point Gauss-Kronrod rule, or by
7749 ! applying the 87-point rule (RES87) obtained by optimal addition of
7750 ! abscissae to the 43-point rule.
7751 !
7752 ! Output, real(r_kind) ABSERR, an estimate of || I - RESULT ||.
7753 !
7754 ! Output, integer NEVAL, the number of times the integral was evaluated.
7755 !
7756 ! ier - ier = 0 normal and reliable termination of the
7757 ! routine. it is assumed that the requested
7758 ! accuracy has been achieved.
7759 ! ier > 0 abnormal termination of the routine. it is
7760 ! assumed that the requested accuracy has
7761 ! not been achieved.
7762 ! ier = 1 the maximum number of steps has been
7763 ! executed. the integral is probably too
7764 ! difficult to be calculated by qng.
7765 ! = 6 the input is invalid, because
7766 ! epsabs < 0 and epsrel < 0,
7767 ! result, abserr and neval are set to zero.
7768 !
7769 ! Local Parameters:
7770 !
7771 ! centr - mid point of the integration interval
7772 ! hlgth - half-length of the integration interval
7773 ! fcentr - function value at mid point
7774 ! absc - abscissa
7775 ! fval - function value
7776 ! savfun - array of function values which have already
7777 ! been computed
7778 ! res10 - 10-point Gauss result
7779 ! res21 - 21-point Kronrod result
7780 ! res43 - 43-point result
7781 ! res87 - 87-point result
7782 ! resabs - approximation to the integral of abs(f)
7783 ! resasc - approximation to the integral of abs(f-i/(b-a))
7784 !
7785  implicit none
7786 !
7787  real(r_kind) a
7788  real(r_kind) absc
7789  real(r_kind) abserr
7790  real(r_kind) b
7791  real(r_kind) centr
7792  real(r_kind) dhlgth
7793  real(r_kind) epsabs
7794  real(r_kind) epsrel
7795  real(r_kind), external :: f
7796  real(r_kind) fcentr
7797  real(r_kind) fval
7798  real(r_kind) fval1
7799  real(r_kind) fval2
7800  real(r_kind) fv1(5)
7801  real(r_kind) fv2(5)
7802  real(r_kind) fv3(5)
7803  real(r_kind) fv4(5)
7804  real(r_kind) hlgth
7805  integer ier
7806  integer ipx
7807  integer k
7808  integer l
7809  integer neval
7810  real(r_kind) result
7811  real(r_kind) res10
7812  real(r_kind) res21
7813  real(r_kind) res43
7814  real(r_kind) res87
7815  real(r_kind) resabs
7816  real(r_kind) resasc
7817  real(r_kind) reskh
7818  real(r_kind) savfun(21)
7819  real(r_kind) w10(5)
7820  real(r_kind) w21a(5)
7821  real(r_kind) w21b(6)
7822  real(r_kind) w43a(10)
7823  real(r_kind) w43b(12)
7824  real(r_kind) w87a(21)
7825  real(r_kind) w87b(23)
7826  real(r_kind) x1(5)
7827  real(r_kind) x2(5)
7828  real(r_kind) x3(11)
7829  real(r_kind) x4(22)
7830 !
7831 ! the following data statements contain the abscissae
7832 ! and weights of the integration rules used.
7833 !
7834 ! x1 abscissae common to the 10-, 21-, 43- and 87-point
7835 ! rule
7836 ! x2 abscissae common to the 21-, 43- and 87-point rule
7837 ! x3 abscissae common to the 43- and 87-point rule
7838 ! x4 abscissae of the 87-point rule
7839 ! w10 weights of the 10-point formula
7840 ! w21a weights of the 21-point formula for abscissae x1
7841 ! w21b weights of the 21-point formula for abscissae x2
7842 ! w43a weights of the 43-point formula for absissae x1, x3
7843 ! w43b weights of the 43-point formula for abscissae x3
7844 ! w87a weights of the 87-point formula for abscissae x1,
7845 ! x2 and x3
7846 ! w87b weights of the 87-point formula for abscissae x4
7847 !
7848  data x1(1),x1(2),x1(3),x1(4),x1(5)/ &
7849  9.739065285171717d-01, 8.650633666889845d-01, &
7850  6.794095682990244d-01, 4.333953941292472d-01, &
7851  1.488743389816312d-01/
7852  data x2(1),x2(2),x2(3),x2(4),x2(5)/ &
7853  9.956571630258081d-01, 9.301574913557082d-01, &
7854  7.808177265864169d-01, 5.627571346686047d-01, &
7855  2.943928627014602d-01/
7856  data x3(1),x3(2),x3(3),x3(4),x3(5),x3(6),x3(7),x3(8),x3(9),x3(10), &
7857  x3(11)/ &
7858  9.993333609019321d-01, 9.874334029080889d-01, &
7859  9.548079348142663d-01, 9.001486957483283d-01, &
7860  8.251983149831142d-01, 7.321483889893050d-01, &
7861  6.228479705377252d-01, 4.994795740710565d-01, &
7862  3.649016613465808d-01, 2.222549197766013d-01, &
7863  7.465061746138332d-02/
7864  data x4(1),x4(2),x4(3),x4(4),x4(5),x4(6),x4(7),x4(8),x4(9),x4(10), &
7865  x4(11),x4(12),x4(13),x4(14),x4(15),x4(16),x4(17),x4(18),x4(19), &
7866  x4(20),x4(21),x4(22)/ 9.999029772627292d-01, &
7867  9.979898959866787d-01, 9.921754978606872d-01, &
7868  9.813581635727128d-01, 9.650576238583846d-01, &
7869  9.431676131336706d-01, 9.158064146855072d-01, &
7870  8.832216577713165d-01, 8.457107484624157d-01, &
7871  8.035576580352310d-01, 7.570057306854956d-01, &
7872  7.062732097873218d-01, 6.515894665011779d-01, &
7873  5.932233740579611d-01, 5.314936059708319d-01, &
7874  4.667636230420228d-01, 3.994248478592188d-01, &
7875  3.298748771061883d-01, 2.585035592021616d-01, &
7876  1.856953965683467d-01, 1.118422131799075d-01, &
7877  3.735212339461987d-02/
7878  data w10(1),w10(2),w10(3),w10(4),w10(5)/ &
7879  6.667134430868814d-02, 1.494513491505806d-01, &
7880  2.190863625159820d-01, 2.692667193099964d-01, &
7881  2.955242247147529d-01/
7882  data w21a(1),w21a(2),w21a(3),w21a(4),w21a(5)/ &
7883  3.255816230796473d-02, 7.503967481091995d-02, &
7884  1.093871588022976d-01, 1.347092173114733d-01, &
7885  1.477391049013385d-01/
7886  data w21b(1),w21b(2),w21b(3),w21b(4),w21b(5),w21b(6)/ &
7887  1.169463886737187d-02, 5.475589657435200d-02, &
7888  9.312545458369761d-02, 1.234919762620659d-01, &
7889  1.427759385770601d-01, 1.494455540029169d-01/
7890  data w43a(1),w43a(2),w43a(3),w43a(4),w43a(5),w43a(6),w43a(7), &
7891  w43a(8),w43a(9),w43a(10)/ 1.629673428966656d-02, &
7892  3.752287612086950d-02, 5.469490205825544d-02, &
7893  6.735541460947809d-02, 7.387019963239395d-02, &
7894  5.768556059769796d-03, 2.737189059324884d-02, &
7895  4.656082691042883d-02, 6.174499520144256d-02, &
7896  7.138726726869340d-02/
7897  data w43b(1),w43b(2),w43b(3),w43b(4),w43b(5),w43b(6),w43b(7), &
7898  w43b(8),w43b(9),w43b(10),w43b(11),w43b(12)/ &
7899  1.844477640212414d-03, 1.079868958589165d-02, &
7900  2.189536386779543d-02, 3.259746397534569d-02, &
7901  4.216313793519181d-02, 5.074193960018458d-02, &
7902  5.837939554261925d-02, 6.474640495144589d-02, &
7903  6.956619791235648d-02, 7.282444147183321d-02, &
7904  7.450775101417512d-02, 7.472214751740301d-02/
7905  data w87a(1),w87a(2),w87a(3),w87a(4),w87a(5),w87a(6),w87a(7), &
7906  w87a(8),w87a(9),w87a(10),w87a(11),w87a(12),w87a(13),w87a(14), &
7907  w87a(15),w87a(16),w87a(17),w87a(18),w87a(19),w87a(20),w87a(21)/ &
7908  8.148377384149173d-03, 1.876143820156282d-02, &
7909  2.734745105005229d-02, 3.367770731163793d-02, &
7910  3.693509982042791d-02, 2.884872430211531d-03, &
7911  1.368594602271270d-02, 2.328041350288831d-02, &
7912  3.087249761171336d-02, 3.569363363941877d-02, &
7913  9.152833452022414d-04, 5.399280219300471d-03, &
7914  1.094767960111893d-02, 1.629873169678734d-02, &
7915  2.108156888920384d-02, 2.537096976925383d-02, &
7916  2.918969775647575d-02, 3.237320246720279d-02, &
7917  3.478309895036514d-02, 3.641222073135179d-02, &
7918  3.725387550304771d-02/
7919  data w87b(1),w87b(2),w87b(3),w87b(4),w87b(5),w87b(6),w87b(7), &
7920  w87b(8),w87b(9),w87b(10),w87b(11),w87b(12),w87b(13),w87b(14), &
7921  w87b(15),w87b(16),w87b(17),w87b(18),w87b(19),w87b(20),w87b(21), &
7922  w87b(22),w87b(23)/ 2.741455637620724d-04, &
7923  1.807124155057943d-03, 4.096869282759165d-03, &
7924  6.758290051847379d-03, 9.549957672201647d-03, &
7925  1.232944765224485d-02, 1.501044734638895d-02, &
7926  1.754896798624319d-02, 1.993803778644089d-02, &
7927  2.219493596101229d-02, 2.433914712600081d-02, &
7928  2.637450541483921d-02, 2.828691078877120d-02, &
7929  3.005258112809270d-02, 3.164675137143993d-02, &
7930  3.305041341997850d-02, 3.425509970422606d-02, &
7931  3.526241266015668d-02, 3.607698962288870d-02, &
7932  3.669860449845609d-02, 3.712054926983258d-02, &
7933  3.733422875193504d-02, 3.736107376267902d-02/
7934 !
7935 ! Test on validity of parameters.
7936 !
7937  result = 0.0d+00
7938  abserr = 0.0d+00
7939  neval = 0
7940 
7941  if ( epsabs < 0.0d+00 .and. epsrel < 0.0d+00 ) then
7942  ier = 6
7943  return
7944  end if
7945 
7946  hlgth = 5.0d-01*(b-a)
7947  dhlgth = abs(hlgth)
7948  centr = 5.0d-01*(b+a)
7949  fcentr = f(centr)
7950  neval = 21
7951  ier = 1
7952 !
7953 ! Compute the integral using the 10- and 21-point formula.
7954 !
7955  do l = 1, 3
7956 
7957  if ( l == 1 ) then
7958 
7959  res10 = 0.0d+00
7960  res21 = w21b(6) * fcentr
7961  resabs = w21b(6) * abs(fcentr)
7962 
7963  do k = 1, 5
7964  absc = hlgth*x1(k)
7965  fval1 = f(centr+absc)
7966  fval2 = f(centr-absc)
7967  fval = fval1+fval2
7968  res10 = res10+w10(k)*fval
7969  res21 = res21+w21a(k)*fval
7970  resabs = resabs+w21a(k)*(abs(fval1)+abs(fval2))
7971  savfun(k) = fval
7972  fv1(k) = fval1
7973  fv2(k) = fval2
7974  end do
7975 
7976  ipx = 5
7977 
7978  do k = 1, 5
7979  ipx = ipx+1
7980  absc = hlgth*x2(k)
7981  fval1 = f(centr+absc)
7982  fval2 = f(centr-absc)
7983  fval = fval1 + fval2
7984  res21 = res21 + w21b(k) * fval
7985  resabs = resabs + w21b(k) * (abs(fval1)+abs(fval2))
7986  savfun(ipx) = fval
7987  fv3(k) = fval1
7988  fv4(k) = fval2
7989  end do
7990 !
7991 ! Test for convergence.
7992 !
7993  result = res21*hlgth
7994  resabs = resabs*dhlgth
7995  reskh = 5.0d-01*res21
7996  resasc = w21b(6)*abs(fcentr-reskh)
7997 
7998  do k = 1, 5
7999  resasc = resasc+w21a(k)*(abs(fv1(k)-reskh)+abs(fv2(k)-reskh)) &
8000  +w21b(k)*(abs(fv3(k)-reskh)+abs(fv4(k)-reskh))
8001  end do
8002 
8003  abserr = abs((res21-res10)*hlgth)
8004  resasc = resasc*dhlgth
8005 !
8006 ! Compute the integral using the 43-point formula.
8007 !
8008  else if ( l == 2 ) then
8009 
8010  res43 = w43b(12)*fcentr
8011  neval = 43
8012 
8013  do k = 1, 10
8014  res43 = res43+savfun(k) * w43a(k)
8015  end do
8016 
8017  do k = 1, 11
8018  ipx = ipx+1
8019  absc = hlgth*x3(k)
8020  fval = f(absc+centr)+f(centr-absc)
8021  res43 = res43+fval*w43b(k)
8022  savfun(ipx) = fval
8023  end do
8024 !
8025 ! Test for convergence.
8026 !
8027  result = res43 * hlgth
8028  abserr = abs((res43-res21)*hlgth)
8029 !
8030 ! Compute the integral using the 87-point formula.
8031 !
8032  else if ( l == 3 ) then
8033 
8034  res87 = w87b(23) * fcentr
8035  neval = 87
8036 
8037  do k = 1, 21
8038  res87 = res87 + savfun(k) * w87a(k)
8039  end do
8040 
8041  do k = 1, 22
8042  absc = hlgth * x4(k)
8043  res87 = res87+w87b(k)*(f(absc+centr)+f(centr-absc))
8044  end do
8045 
8046  result = res87 * hlgth
8047  abserr = abs( ( res87-res43) * hlgth )
8048 
8049  end if
8050 
8051  if ( resasc /= 0.0d+00.and.abserr /= 0.0d+00 ) then
8052  abserr = resasc * min( 1.0d+00,(2.0d+02*abserr/resasc)**1.5d+00)
8053  end if
8054 
8055  if ( resabs > tiny( resabs ) / ( 5.0d+01 * epsilon( resabs ) ) ) then
8056  abserr = max(( epsilon( resabs ) *5.0d+01) * resabs, abserr )
8057  end if
8058 
8059  if ( abserr <= max( epsabs, epsrel*abs(result))) then
8060  ier = 0
8061  end if
8062 
8063  if ( ier == 0 ) then
8064  exit
8065  end if
8066 
8067  end do
8068 
8069  return
8070 end subroutine
8071 subroutine qsort ( limit, last, maxerr, ermax, elist, iord, nrmax )
8072 !
8073 !******************************************************************************
8074 !
8075 !! QSORT maintains the order of a list of local error estimates.
8076 !
8077 !
8078 ! Discussion:
8079 !
8080 ! This routine maintains the descending ordering in the list of the
8081 ! local error estimates resulting from the interval subdivision process.
8082 ! At each call two error estimates are inserted using the sequential
8083 ! search top-down for the largest error estimate and bottom-up for the
8084 ! smallest error estimate.
8085 !
8086 ! Reference:
8087 !
8088 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
8089 ! QUADPACK, a Subroutine Package for Automatic Integration,
8090 ! Springer Verlag, 1983
8091 !
8092 ! Parameters:
8093 !
8094 ! Input, integer LIMIT, the maximum number of error estimates the list can
8095 ! contain.
8096 !
8097 ! Input, integer LAST, the current number of error estimates.
8098 !
8099 ! Input/output, integer MAXERR, the index in the list of the NRMAX-th
8100 ! largest error.
8101 !
8102 ! Output, real(r_kind) ERMAX, the NRMAX-th largest error = ELIST(MAXERR).
8103 !
8104 ! Input, real(r_kind) ELIST(LIMIT), contains the error estimates.
8105 !
8106 ! Input/output, integer IORD(LAST). The first K elements contain
8107 ! pointers to the error estimates such that ELIST(IORD(1)) through
8108 ! ELIST(IORD(K)) form a decreasing sequence, with
8109 ! K = LAST
8110 ! if
8111 ! LAST <= (LIMIT/2+2),
8112 ! and otherwise
8113 ! K = LIMIT+1-LAST.
8114 !
8115 ! Input/output, integer NRMAX.
8116 !
8117  implicit none
8118 !
8119  integer last
8120 !
8121  real(r_kind) elist(last)
8122  real(r_kind) ermax
8123  real(r_kind) errmax
8124  real(r_kind) errmin
8125  integer i
8126  integer ibeg
8127  integer iord(last)
8128  integer isucc
8129  integer j
8130  integer jbnd
8131  integer jupbn
8132  integer k
8133  integer limit
8134  integer maxerr
8135  integer nrmax
8136 !
8137 ! Check whether the list contains more than two error estimates.
8138 !
8139  if ( last <= 2 ) then
8140  iord(1) = 1
8141  iord(2) = 2
8142  go to 90
8143  end if
8144 !
8145 ! This part of the routine is only executed if, due to a
8146 ! difficult integrand, subdivision increased the error
8147 ! estimate. in the normal case the insert procedure should
8148 ! start after the nrmax-th largest error estimate.
8149 !
8150  errmax = elist(maxerr)
8151 
8152  do i = 1, nrmax-1
8153 
8154  isucc = iord(nrmax-1)
8155 
8156  if ( errmax <= elist(isucc) ) then
8157  exit
8158  end if
8159 
8160  iord(nrmax) = isucc
8161  nrmax = nrmax-1
8162 
8163  end do
8164 !
8165 ! Compute the number of elements in the list to be maintained
8166 ! in descending order. This number depends on the number of
8167 ! subdivisions still allowed.
8168 !
8169  jupbn = last
8170 
8171  if ( last > (limit/2+2) ) then
8172  jupbn = limit+3-last
8173  end if
8174 
8175  errmin = elist(last)
8176 !
8177 ! Insert errmax by traversing the list top-down, starting
8178 ! comparison from the element elist(iord(nrmax+1)).
8179 !
8180  jbnd = jupbn-1
8181  ibeg = nrmax+1
8182 
8183  do i = ibeg, jbnd
8184  isucc = iord(i)
8185  if ( errmax >= elist(isucc) ) go to 60
8186  iord(i-1) = isucc
8187  end do
8188 
8189  iord(jbnd) = maxerr
8190  iord(jupbn) = last
8191  go to 90
8192 !
8193 ! Insert errmin by traversing the list bottom-up.
8194 !
8195 60 continue
8196 
8197  iord(i-1) = maxerr
8198  k = jbnd
8199 
8200  do j = i, jbnd
8201  isucc = iord(k)
8202  if ( errmin < elist(isucc) ) go to 80
8203  iord(k+1) = isucc
8204  k = k-1
8205  end do
8206 
8207  iord(i) = last
8208  go to 90
8209 
8210 80 continue
8211 
8212  iord(k+1) = last
8213 !
8214 ! Set maxerr and ermax.
8215 !
8216 90 continue
8217 
8218  maxerr = iord(nrmax)
8219  ermax = elist(maxerr)
8220 
8221  return
8222 end subroutine
8223 subroutine r_swap ( x, y )
8224 !
8225 !*******************************************************************************
8226 !
8227 !! R_SWAP swaps two real(r_kind) values.
8228 !
8229 !
8230 ! Modified:
8231 !
8232 ! 01 May 2000
8233 !
8234 ! Author:
8235 !
8236 ! John Burkardt
8237 !
8238 ! Parameters:
8239 !
8240 ! Input/output, real(r_kind) X, Y. On output, the values of X and
8241 ! Y have been interchanged.
8242 !
8243  implicit none
8244 !
8245  real(r_kind) x
8246  real(r_kind) y
8247  real(r_kind) z
8248 !
8249  z = x
8250  x = y
8251  y = z
8252 
8253  return
8254 end subroutine
8255 
8256 
8257 real(r_kind) function qwgtc ( x, c ) !( x, c, p2, p3, p4, kp )
8258 !
8259 !******************************************************************************
8260 !
8261 !! QWGTC defines the weight function used by QC25C.
8262 !
8263 !
8264 ! Discussion:
8265 !
8266 ! The weight function has the form 1 / ( X - C ).
8267 !
8268 ! Reference:
8269 !
8270 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
8271 ! QUADPACK, a Subroutine Package for Automatic Integration,
8272 ! Springer Verlag, 1983
8273 !
8274 ! Parameters:
8275 !
8276 ! Input, real(r_kind) X, the point at which the weight function is evaluated.
8277 !
8278 ! Input, real(r_kind) C, the location of the singularity.
8279 !
8280 ! Input, real(r_kind) P2, P3, P4, parameters that are not used.
8281 !
8282 ! Input, integer KP, a parameter that is not used.
8283 !
8284 ! Output, real(r_kind) QWGTC, the value of the weight function at X.
8285 !
8286  implicit none
8287 !
8288  real(r_kind) c
8289  !integer kp
8290  !real(r_kind) p2
8291  !real(r_kind) p3
8292  !real(r_kind) p4
8293  real(r_kind) x
8294 !
8295  qwgtc = 1.0d+00 / ( x - c )
8296 
8297  return
8298 end function
8299 real(r_kind) function qwgto ( x, omega, integr ) !( x, omega, p2, p3, p4, integr )
8300 !
8301 !******************************************************************************
8302 !
8303 !! QWGTO defines the weight functions used by QC25O.
8304 !
8305 !
8306 ! Reference:
8307 !
8308 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
8309 ! QUADPACK, a Subroutine Package for Automatic Integration,
8310 ! Springer Verlag, 1983
8311 !
8312 ! Parameters:
8313 !
8314 ! Input, real(r_kind) X, the point at which the weight function is evaluated.
8315 !
8316 ! Input, real(r_kind) OMEGA, the factor multiplying X.
8317 !
8318 ! Input, real(r_kind) P2, P3, P4, parameters that are not used.
8319 !
8320 ! Input, integer INTEGR, specifies which weight function is used:
8321 ! 1. W(X) = cos ( OMEGA * X )
8322 ! 2, W(X) = sin ( OMEGA * X )
8323 !
8324 ! Output, real(r_kind) QWGTO, the value of the weight function at X.
8325 !
8326  implicit none
8327 !
8328  integer integr
8329  real(r_kind) omega
8330  !real(r_kind) p2
8331  !real(r_kind) p3
8332  !real(r_kind) p4
8333  real(r_kind) x
8334 !
8335  if ( integr == 1 ) then
8336  qwgto = cos( omega * x )
8337  else if ( integr == 2 ) then
8338  qwgto = sin( omega * x )
8339  end if
8340 
8341  return
8342 end function
8343 real(r_kind) function qwgts ( x, a, b, alfa, beta, integr )
8344 !
8345 !******************************************************************************
8346 !
8347 !! QWGTS defines the weight functions used by QC25S.
8348 !
8349 !
8350 ! Reference:
8351 !
8352 ! R Piessens, E de Doncker-Kapenger, C W Ueberhuber, D K Kahaner,
8353 ! QUADPACK, a Subroutine Package for Automatic Integration,
8354 ! Springer Verlag, 1983
8355 !
8356 ! Parameters:
8357 !
8358 ! Input, real(r_kind) X, the point at which the weight function is evaluated.
8359 !
8360 ! Input, real(r_kind) A, B, the endpoints of the integration interval.
8361 !
8362 ! Input, real(r_kind) ALFA, BETA, exponents that occur in the weight function.
8363 !
8364 ! Input, integer INTEGR, specifies which weight function is used:
8365 ! 1. W(X) = (X-A)**ALFA * (B-X)**BETA
8366 ! 2, W(X) = (X-A)**ALFA * (B-X)**BETA * log (X-A)
8367 ! 3, W(X) = (X-A)**ALFA * (B-X)**BETA * log (B-X)
8368 ! 4, W(X) = (X-A)**ALFA * (B-X)**BETA * log (X-A) * log(B-X)
8369 !
8370 ! Output, real(r_kind) QWGTS, the value of the weight function at X.
8371 !
8372  implicit none
8373 !
8374  real(r_kind) a
8375  real(r_kind) alfa
8376  real(r_kind) b
8377  real(r_kind) beta
8378  integer integr
8379  real(r_kind) x
8380 !
8381  if ( integr == 1 ) then
8382  qwgts = ( x - a )**alfa * ( b - x )**beta
8383  else if ( integr == 2 ) then
8384  qwgts = ( x - a )**alfa * ( b - x )**beta * log( x - a )
8385  else if ( integr == 3 ) then
8386  qwgts = ( x - a )**alfa * ( b - x )**beta * log( b - x )
8387  else if ( integr == 4 ) then
8388  qwgts = ( x - a )**alfa * ( b - x )**beta * log( x - a ) * log( b - x )
8389  end if
8390 
8391  return
8392 end function
qawce
subroutine qawce(f, a, b, c, epsabs, epsrel, limit, result, abserr, neval, ier, alist, blist, rlist, elist, iord, last)
Definition: quadpack_module.f90:2461
qk15
subroutine qk15(f, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:6031
qng
subroutine qng(f, a, b, epsabs, epsrel, result, abserr, neval, ier)
Definition: quadpack_module.f90:7709
qawc
subroutine qawc(f, a, b, c, epsabs, epsrel, result, abserr, neval, ier)
Definition: quadpack_module.f90:2351
qawf
subroutine qawf(f, a, omega, integr, epsabs, result, abserr, neval, ier)
Definition: quadpack_module.f90:2805
qsort
subroutine qsort(limit, last, maxerr, ermax, elist, iord, nrmax)
Definition: quadpack_module.f90:8072
qk31
subroutine qk31(f, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:6773
qawfe
subroutine qawfe(f, a, omega, integr, epsabs, limlst, limit, maxp1, result, abserr, neval, ier, rslst, erlst, ierlst, lst, alist, blist, rlist, elist, iord, nnlog, chebmo)
Definition: quadpack_module.f90:2940
qk15i
subroutine qk15i(f, boun, inf, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:6201
qk41
subroutine qk41(f, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:6956
qcheb
subroutine qcheb(x, fval, cheb12, cheb24)
Definition: quadpack_module.f90:5019
qc25s
subroutine qc25s(f, a, b, bl, br, alfa, beta, ri, rj, rg, rh, result, abserr, resasc, integr, neval)
Definition: quadpack_module.f90:4644
r_swap
subroutine r_swap(x, y)
Definition: quadpack_module.f90:8224
qextr
subroutine qextr(n, epstab, result, abserr, res3la, nres)
Definition: quadpack_module.f90:5182
qc25o
subroutine qc25o(f, a, b, omega, integr, nrmom, maxp1, ksave, result, abserr, neval, resabs, resasc, momcom, chebmo)
Definition: quadpack_module.f90:4203
qagi
subroutine qagi(f, bound, inf, epsabs, epsrel, result, abserr, neval, ier)
Definition: quadpack_module.f90:684
qk51
subroutine qk51(f, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:7147
qk15w
subroutine qk15w(f, w, p1, p2, p3, p4, kp, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:6401
qaws
subroutine qaws(f, a, b, alfa, beta, integr, epsabs, epsrel, result, abserr, neval, ier)
Definition: quadpack_module.f90:3520
qage
subroutine qage(f, a, b, epsabs, epsrel, key, limit, result, abserr, neval, ier, alist, blist, rlist, elist, iord, last)
Definition: quadpack_module.f90:323
qk61
subroutine qk61(f, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:7347
r_kind
#define r_kind
Definition: macros.h:46
qfour
subroutine qfour(f, a, b, omega, integr, epsabs, epsrel, limit, icall, maxp1, result, abserr, neval, ier, alist, blist, rlist, elist, iord, nnlog, momcom, chebmo)
Definition: quadpack_module.f90:5405
qags
subroutine qags(f, a, b, epsabs, epsrel, result, abserr, neval, ier)
Definition: quadpack_module.f90:1848
qawse
subroutine qawse(f, a, b, alfa, beta, integr, epsabs, epsrel, limit, result, abserr, neval, ier, alist, blist, rlist, elist, iord, last)
Definition: quadpack_module.f90:3640
qagp
subroutine qagp(f, a, b, npts2, points, epsabs, epsrel, result, abserr, neval, ier)
Definition: quadpack_module.f90:1210
qwgtc
real(r_kind) function qwgtc(x, c)
Definition: quadpack_module.f90:8258
qawo
subroutine qawo(f, a, b, omega, integr, epsabs, epsrel, result, abserr, neval, ier)
Definition: quadpack_module.f90:3383
qk21
subroutine qk21(f, a, b, result, abserr, resabs, resasc)
Definition: quadpack_module.f90:6593
qc25c
subroutine qc25c(f, a, b, c, result, abserr, krul, neval)
Definition: quadpack_module.f90:4025
qmomo
subroutine qmomo(alfa, beta, ri, rj, rg, rh, integr)
Definition: quadpack_module.f90:7559
pi
real(r_kind) function pi()
Further information: http://netlib.org/quadpack/index.html https://orion.math.iastate....
Definition: quadpack_module.f90:193
qag
subroutine qag(f, a, b, epsabs, epsrel, key, result, abserr, neval, ier)
Definition: quadpack_module.f90:220
qwgts
real(r_kind) function qwgts(x, a, b, alfa, beta, integr)
Definition: quadpack_module.f90:8344
qwgto
real(r_kind) function qwgto(x, omega, integr)
Definition: quadpack_module.f90:8300