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