-
Notifications
You must be signed in to change notification settings - Fork 9
/
adgaquad_mod.F90
3573 lines (3454 loc) · 140 KB
/
adgaquad_mod.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!! ******************************************************************
!! The routines listed in this file "adgaquad_mod.F90" are performing
!! Numerical Integrations using some kind of
!! adaptive Gauss quadrature.
!! They are taken from the Internet (http://www.netlib.org)
!! and parts of different software packages / libraries.
!! ******************************************************************
!! For any restrictions on the use of the routines, please see
!! the original web site.
!! ******************************************************************
!! Changes: calls to error handler 'xerror()' replaced by
!! WRITE(7,*) - statements.
!! ******************************************************************
!! list of routines and the libraries they are taken from:
!! dqag calling routine, bounded integration interval
!! QUADPACK; calls: dqage
!! dqage the integration routine, bounded interval
!! QUADPACK; calls: sd1mach,dqk15,dqk21,dqk31,
!! dqk41,dqk51,dqk61,dqpsrt
!! dqagi calling routine, unbounded (semi-infinite or
!! infinite) integration interval
!! QUADPACK; calls: dqagie
!! dqagie the integration routine, unbounded interval
!! QUADPACK; calls: sd1mach,dqelg,dqk15i,dqpsrt
!! ------------------------------------------------------------------
!! dqk15 QUADPACK; calls: sd1mach
!! dqk21 QUADPACK; calls: sd1mach
!! dqk31 QUADPACK; calls: sd1mach
!! dqk41 QUADPACK; calls: sd1mach
!! dqk51 QUADPACK; calls: sd1mach
!! dqk61 QUADPACK; calls: sd1mach
!! dqpsrt QUADPACK; calls: none
!! dqk15i QUADPACK; calls: sd1mach
!! dqelg QUADPACK; calls: sd1mach
!! ------------------------------------------------------------------
!! xerror Error handling routine
!! ALLIANT (/quad); calls: xerrwv
!! xerrwv Error handling routine
!! SODEPACK; calls: none
!! d1mach determine machine parameters (accuracies)
!! BLAS; calls: none
!! ------------------------------------------------------------------
module adgaquad_mod
use carma_precision_mod
use adgaquad_types_mod
implicit none
private
public :: dqag
public :: dqage
public :: dqagi
public :: dqagie
contains
!!***begin prologue dqag
!!***date written 800101 (yymmdd)
!!***revision date 130319 (yymmdd)
!!***category no. h2a1a1
!!***keywords automatic integrator, general-purpose,
!! integrand examinator, globally adaptive,
!! gauss-kronrod
!!***author piessens,robert,appl. math. & progr. div - k.u.leuven
!! de doncker,elise,appl. math. & progr. div. - k.u.leuven
!!***purpose the routine calculates an approximation result to a given
!! definite integral i = integral of f over (a,b),
!! hopefully satisfying following claim for accuracy
!! abs(i-result)le.max(epsabs,epsrel*abs(i)).
!!***description
!!
!! computation of a definite integral
!! standard fortran subroutine
!! double precision version
!!
!! fx - double precision
!! function subprogam defining the integrand
!! function f(x). the actual name for f needs to be
!! declared e x t e r n a l in the driver program.
!!
!! fx_vars- structure containing variables need for integration
!! specific to fractal meanfield scattering code
!!
!! a - double precision
!! lower limit of integration
!!
!! b - double precision
!! upper limit of integration
!!
!! epsabs - double precision
!! absolute accoracy requested
!! epsrel - double precision
!! relative accuracy requested
!! if epsabs.le.0
!! and epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
!! the routine will end with ier = 6.
!!
!! key - integer
!! key for choice of local integration rule
!! a gauss-kronrod pair is used with
!! 7 - 15 points if key.lt.2,
!! 10 - 21 points if key = 2,
!! 15 - 31 points if key = 3,
!! 20 - 41 points if key = 4,
!! 25 - 51 points if key = 5,
!! 30 - 61 points if key.gt.5.
!!
!! on return
!! result - double precision
!! approximation to the integral
!!
!! abserr - double precision
!! estimate of the modulus of the absolute error,
!! which should equal or exceed abs(i-result)
!!
!! neval - integer
!! number of integrand evaluations
!!
!! ier - integer
!! ier = 0 normal and reliable termination of the
!! routine. it is assumed that the requested
!! accuracy has been achieved.
!! ier.gt.0 abnormal termination of the routine
!! the estimates for result and error are
!! less reliable. it is assumed that the
!! requested accuracy has not been achieved.
!! error messages
!! ier = 1 maximum number of subdivisions allowed
!! has been achieved. one can allow more
!! subdivisions by increasing the value of
!! limit (and taking the according dimension
!! adjustments into account). however, if
!! this yield no improvement it is advised
!! to analyze the integrand in order to
!! determine the integration difficulaties.
!! if the position of a local difficulty can
!! be determined (i.e.singularity,
!! discontinuity within the interval) one
!! will probably gain from splitting up the
!! interval at this point and calling the
!! integrator on the subranges. if possible,
!! an appropriate special-purpose integrator
!! should be used which is designed for
!! handling the type of difficulty involved.
!! = 2 the occurrence of roundoff error is
!! detected, which prevents the requested
!! tolerance from being achieved.
!! = 3 extremely bad integrand behaviour occurs
!! at some points of the integration
!! interval.
!! = 6 the input is invalid, because
!! (epsabs.le.0 and
!! epsrel.lt.max(50*rel.mach.acc.,0.5d-28))
!! or limit.lt.1 or lenw.lt.limit*4.
!! result, abserr, neval, last are set
!! to zero.
!! except when lenw is invalid, iwork(1),
!! work(limit*2+1) and work(limit*3+1) are
!! set to zero, work(1) is set to a and
!! work(limit+1) to b.
!! = 9 failure in sd1mach determining machine parameters
!!
!! dimensioning parameters
!! limit - integer
!! dimensioning parameter for iwork
!! limit determines the maximum number of subintervals
!! in the partition of the given integration interval
!! (a,b), limit.ge.1.
!! if limit.lt.1, the routine will end with ier = 6.
!!
!! lenw - integer
!! dimensioning parameter for work
!! lenw must be at least limit*4.
!! if lenw.lt.limit*4, the routine will end with
!! ier = 6.
!!
!! last - integer
!! on return, last equals the number of subintervals
!! produced in the subdiviosion process, which
!! determines the number of significant elements
!! actually in the work arrays.
!!
!! work arrays
!! iwork - integer
!! vector of dimension at least limit, the first k
!! elements of which contain pointers to the error
!! estimates over the subintervals, such that
!! work(limit*3+iwork(1)),... , work(limit*3+iwork(k))
!! form a decreasing sequence with k = last if
!! last.le.(limit/2+2), and k = limit+1-last otherwise
!!
!! work - double precision
!! vector of dimension at least lenw
!! on return
!! work(1), ..., work(last) contain the left end
!! points of the subintervals in the partition of
!! (a,b),
!! work(limit+1), ..., work(limit+last) contain the
!! right end points,
!! work(limit*2+1), ..., work(limit*2+last) contain
!! the integral approximations over the subintervals,
!! work(limit*3+1), ..., work(limit*3+last) contain
!! the error estimates.
!!
!!***references (none)
!!***routines called dqage,xerror
!!***end prologue dqag
subroutine dqag(fx,fx_vars,a,b,epsabs,epsrel,key,result,abserr,neval,ier, &
limit,lenw,last,iwork,work)
! Arguments
interface
function fx(centr, vars)
use carma_precision_mod, only : f
use adgaquad_types_mod
real(kind=f), intent(in) :: centr
type(adgaquad_vars_type), intent(inout) :: vars
real(kind=f) :: fx
end function fx
end interface
type(adgaquad_vars_type) :: fx_vars
real(kind=f) :: a
real(kind=f) :: b
real(kind=f) :: epsabs
real(kind=f) :: epsrel
integer :: key
real(kind=f) :: result
real(kind=f) :: abserr
integer :: neval
integer :: ier
integer :: limit
integer :: lenw
integer :: last
integer :: iwork(limit)
real(kind=f) :: work(lenw)
! Local declarations
integer :: lvl,l1,l2,l3
! check validity of lenw.
!
!***first executable statement dqag
ier = 6
neval = 0
last = 0
result = 0.0_f
abserr = 0.0_f
if(limit.lt.1.or.lenw.lt.limit*4) go to 10
! prepare call for dqage.
l1 = limit+1
l2 = limit+l1
l3 = limit+l2
call dqage(fx,fx_vars,a,b,epsabs,epsrel,key,limit,result,abserr,neval, &
ier,work(1),work(l1),work(l2),work(l3),iwork,last)
! call error handler if necessary.
lvl = 0
10 if(ier.eq.6) lvl = 1
if(ier.ne.0) then
write(*,*) "ERROR: abnormal return from dqag"
write(*,*) " ifail=",ier," level=",lvl
endif
return
end subroutine dqag
!!***begin prologue dqage
!!***date written 800101 (yymmdd)
!!***revision date 130319 (yymmdd)
!!***category no. h2a1a1
!!***keywords automatic integrator, general-purpose,
!! integrand examinator, globally adaptive,
!! gauss-kronrod
!!***author piessens,robert,appl. math. & progr. div. - k.u.leuven
!! de doncker,elise,appl. math. & progr. div. - k.u.leuven
!!***purpose the routine calculates an approximation result to a given
!! definite integral i = integral of f over (a,b),
!! hopefully satisfying following claim for accuracy
!! abs(i-reslt).le.max(epsabs,epsrel*abs(i)).
!!***description
!!
!! computation of a definite integral
!! standard fortran subroutine
!! double precision version
!!
!! parameters
!! on entry
!! fx - double precision
!! function subprogram defining the integrand
!! function f(x). the actual name for f needs to be
!! declared e x t e r n a l in the driver program.
!!
!! fx_vars- structure containing variables need for integration
!! specific to fractal meanfield scattering code
!!
!! a - double precision
!! lower limit of integration
!!
!! b - double precision
!! upper limit of integration
!!
!! epsabs - double precision
!! absolute accuracy requested
!! epsrel - double precision
!! relative accuracy requested
!! if epsabs.le.0
!! and epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
!! the routine will end with ier = 6.
!!
!! key - integer
!! key for choice of local integration rule
!! a gauss-kronrod pair is used with
!! 7 - 15 points if key.lt.2,
!! 10 - 21 points if key = 2,
!! 15 - 31 points if key = 3,
!! 20 - 41 points if key = 4,
!! 25 - 51 points if key = 5,
!! 30 - 61 points if key.gt.5.
!!
!! limit - integer
!! gives an upperbound on the number of subintervals
!! in the partition of (a,b), limit.ge.1.
!!
!! on return
!! result - double precision
!! approximation to the integral
!!
!! abserr - double precision
!! estimate of the modulus of the absolute error,
!! which should equal or exceed abs(i-result)
!!
!! neval - integer
!! number of integrand evaluations
!!
!! ier - integer
!! ier = 0 normal and reliable termination of the
!! routine. it is assumed that the requested
!! accuracy has been achieved.
!! ier.gt.0 abnormal termination of the routine
!! the estimates for result and error are
!! less reliable. it is assumed that the
!! requested accuracy has not been achieved.
!! error messages
!! ier = 1 maximum number of subdivisions allowed
!! has been achieved. one can allow more
!! subdivisions by increasing the value
!! of limit.
!! however, if this yields no improvement it
!! is rather advised to analyze the integrand
!! in order to determine the integration
!! difficulties. if the position of a local
!! difficulty can be determined(e.g.
!! singularity, discontinuity within the
!! interval) one will probably gain from
!! splitting up the interval at this point
!! and calling the integrator on the
!! subranges. if possible, an appropriate
!! special-purpose integrator should be used
!! which is designed for handling the type of
!! difficulty involved.
!! = 2 the occurrence of roundoff error is
!! detected, which prevents the requested
!! tolerance from being achieved.
!! = 3 extremely bad integrand behaviour occurs
!! at some points of the integration
!! interval.
!! = 6 the input is invalid, because
!! (epsabs.le.0 and
!! epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
!! result, abserr, neval, last, rlist(1) ,
!! elist(1) and iord(1) are set to zero.
!! alist(1) and blist(1) are set to a and b
!! respectively.
!! = 9 failure in sd1mach determining machine parameters
!!
!! alist - double precision
!! vector of dimension at least limit, the first
!! last elements of which are the left
!! end points of the subintervals in the partition
!! of the given integration range (a,b)
!!
!! blist - double precision
!! vector of dimension at least limit, the first
!! last elements of which are the right
!! end points of the subintervals in the partition
!! of the given integration range (a,b)
!!
!! rlist - double precision
!! vector of dimension at least limit, the first
!! last elements of which are the
!! integral approximations on the subintervals
!!
!! elist - double precision
!! vector of dimension at least limit, the first
!! last elements of which are the moduli of the
!! absolute error estimates on the subintervals
!!
!! iord - integer
!! vector of dimension at least limit, the first k
!! elements of which are pointers to the
!! error estimates over the subintervals,
!! such that elist(iord(1)), ...,
!! elist(iord(k)) form a decreasing sequence,
!! with k = last if last.le.(limit/2+2), and
!! k = limit+1-last otherwise
!!
!! last - integer
!! number of subintervals actually produced in the
!! subdivision process
!!
!!***references (none)
!!***routines called sd1mach,dqk15,dqk21,dqk31,
!! dqk41,dqk51,dqk61,dqpsrt
!!***end prologue dqage
subroutine dqage(fx,fx_vars,a,b,epsabs,epsrel,key,limit,result,abserr, &
neval,ier,alist,blist,rlist,elist,iord,last)
! Arguments
interface
function fx(centr, vars)
use carma_precision_mod, only : f
use adgaquad_types_mod
real(kind=f), intent(in) :: centr
type(adgaquad_vars_type), intent(inout) :: vars
real(kind=f) :: fx
end function fx
end interface
type(adgaquad_vars_type) :: fx_vars
real(kind=f) :: a
real(kind=f) :: b
real(kind=f) :: epsabs
real(kind=f) :: epsrel
integer :: limit
integer :: key
real(kind=f) :: result
real(kind=f) :: abserr
integer :: neval
integer :: ier
real(kind=f) :: alist(limit)
real(kind=f) :: blist(limit)
real(kind=f) :: rlist(limit)
real(kind=f) :: elist(limit)
integer :: iord(limit)
integer :: last
! Local declarations
real(kind=f) :: area, area1, area12, area2, a1, a2
real(kind=f) :: b1, b2, dabs, defabs, defab1, defab2, dmax1, epmach
real(kind=f) :: errbnd,errmax,error1,error2,erro12,errsum,resabs,uflow
integer :: iroff1,iroff2,k,keyf,maxerr,nrmax
! list of major variables
! -----------------------
!
! alist - list of left end points of all subintervals
! considered up to now
! blist - list of right end points of all subintervals
! considered up to now
! rlist(i) - approximation to the integral over
! (alist(i),blist(i))
! elist(i) - error estimate applying to rlist(i)
! maxerr - pointer to the interval with largest
! error estimate
! errmax - elist(maxerr)
! area - sum of the integrals over the subintervals
! errsum - sum of the errors over the subintervals
! errbnd - requested accuracy max(epsabs,epsrel*
! abs(result))
! *****1 - variable for the left subinterval
! *****2 - variable for the right subinterval
! last - index for subdivision
!
!
! machine dependent constants
! ---------------------------
!
! epmach is the largest relative spacing.
! uflow is the smallest positive magnitude.
!
!***first executable statement dqage
call sd1mach(4,epmach,ier)
if(ier.eq.9) return
call sd1mach(1,uflow,ier)
if(ier.eq.9) return
!epmach = d1mach(4)
!uflow = d1mach(1)
! test on validity of parameters
! ------------------------------
!
ier = 0
neval = 0
last = 0
result = 0.0_f
abserr = 0.0_f
alist(1) = a
blist(1) = b
rlist(1) = 0.0_f
elist(1) = 0.0_f
iord(1) = 0
if(epsabs.le.0.0_f.and.epsrel.lt.dmax1(0.5e2_f*epmach,0.5e-28_f)) ier = 6
if(ier.eq.6) go to 999
! first approximation to the integral
! -----------------------------------
!
keyf = key
if(key.le.0) keyf = 1
if(key.ge.7) keyf = 6
neval = 0
if(keyf.eq.1) call dqk15(fx,fx_vars,a,b,result,abserr,defabs,resabs,ier)
if(ier.eq.9) return
if(keyf.eq.2) call dqk21(fx,fx_vars,a,b,result,abserr,defabs,resabs,ier)
if(ier.eq.9) return
if(keyf.eq.3) call dqk31(fx,fx_vars,a,b,result,abserr,defabs,resabs,ier)
if(ier.eq.9) return
if(keyf.eq.4) call dqk41(fx,fx_vars,a,b,result,abserr,defabs,resabs,ier)
if(ier.eq.9) return
if(keyf.eq.5) call dqk51(fx,fx_vars,a,b,result,abserr,defabs,resabs,ier)
if(ier.eq.9) return
if(keyf.eq.6) call dqk61(fx,fx_vars,a,b,result,abserr,defabs,resabs,ier)
if(ier.eq.9) return
last = 1
rlist(1) = result
elist(1) = abserr
iord(1) = 1
!
! test on accuracy.
!
errbnd = dmax1(epsabs,epsrel*dabs(result))
if(abserr.le.0.5e2_f*epmach*defabs.and.abserr.gt.errbnd) ier = 2
if(limit.eq.1) ier = 1
if(ier.ne.0.or.(abserr.le.errbnd.and.abserr.ne.resabs).or.abserr.eq.0.0_f) go to 60
!
! initialization
! --------------
!
errmax = abserr
maxerr = 1
area = result
errsum = abserr
nrmax = 1
iroff1 = 0
iroff2 = 0
!
! main do-loop
! ------------
!
do last = 2,limit
!
! bisect the subinterval with the largest error estimate.
!
a1 = alist(maxerr)
b1 = 0.5_f*(alist(maxerr)+blist(maxerr))
a2 = b1
b2 = blist(maxerr)
if(keyf.eq.1) call dqk15(fx,fx_vars,a1,b1,area1,error1,resabs,defab1,ier)
if(ier.eq.9) return
if(keyf.eq.2) call dqk21(fx,fx_vars,a1,b1,area1,error1,resabs,defab1,ier)
if(ier.eq.9) return
if(keyf.eq.3) call dqk31(fx,fx_vars,a1,b1,area1,error1,resabs,defab1,ier)
if(ier.eq.9) return
if(keyf.eq.4) call dqk41(fx,fx_vars,a1,b1,area1,error1,resabs,defab1,ier)
if(ier.eq.9) return
if(keyf.eq.5) call dqk51(fx,fx_vars,a1,b1,area1,error1,resabs,defab1,ier)
if(ier.eq.9) return
if(keyf.eq.6) call dqk61(fx,fx_vars,a1,b1,area1,error1,resabs,defab1,ier)
if(ier.eq.9) return
if(keyf.eq.1) call dqk15(fx,fx_vars,a2,b2,area2,error2,resabs,defab2,ier)
if(ier.eq.9) return
if(keyf.eq.2) call dqk21(fx,fx_vars,a2,b2,area2,error2,resabs,defab2,ier)
if(ier.eq.9) return
if(keyf.eq.3) call dqk31(fx,fx_vars,a2,b2,area2,error2,resabs,defab2,ier)
if(ier.eq.9) return
if(keyf.eq.4) call dqk41(fx,fx_vars,a2,b2,area2,error2,resabs,defab2,ier)
if(ier.eq.9) return
if(keyf.eq.5) call dqk51(fx,fx_vars,a2,b2,area2,error2,resabs,defab2,ier)
if(ier.eq.9) return
if(keyf.eq.6) call dqk61(fx,fx_vars,a2,b2,area2,error2,resabs,defab2,ier)
if(ier.eq.9) return
! improve previous approximations to integral
! and error and test for accuracy.
!
! neval = neval+1
area12 = area1+area2
erro12 = error1+error2
errsum = errsum+erro12-errmax
area = area+area12-rlist(maxerr)
if(defab1.eq.error1.or.defab2.eq.error2) go to 5
if(dabs(rlist(maxerr)-area12).le.0.1e-4_f*dabs(area12).and.erro12.ge.0.99_f*errmax) iroff1 = iroff1+1
if(last.gt.10.and.erro12.gt.errmax) iroff2 = iroff2+1
5 rlist(maxerr) = area1
rlist(last) = area2
errbnd = dmax1(epsabs,epsrel*dabs(area))
if(errsum.le.errbnd) go to 8
!
! test for roundoff error and eventually set error flag.
!
if(iroff1.ge.6.or.iroff2.ge.20) ier = 2
!
! set error flag in the case that the number of subintervals
! equals limit.
!
if(last.eq.limit) ier = 1
!
! set error flag in the case of bad integrand behaviour
! at a point of the integration range.
!
if(dmax1(dabs(a1),dabs(b2)).le.(0.1e1_f+0.1e3_f*epmach)*(dabs(a2)+0.1e4_f*uflow)) ier = 3
!
! append the newly-created intervals to the list.
!
8 if(error2.gt.error1) go to 10
alist(last) = a2
blist(maxerr) = b1
blist(last) = b2
elist(maxerr) = error1
elist(last) = error2
go to 20
10 alist(maxerr) = a2
alist(last) = a1
blist(last) = b1
rlist(maxerr) = area2
rlist(last) = area1
elist(maxerr) = error2
elist(last) = error1
!
! call subroutine dqpsrt to maintain the descending ordering
! in the list of error estimates and select the subinterval
! with the largest error estimate (to be bisected next).
!
20 call dqpsrt(limit,last,maxerr,errmax,elist,iord,nrmax)
! ***jump out of do-loop
if(ier.ne.0.or.errsum.le.errbnd) go to 40
end do
!
! compute final result.
! ---------------------
!
40 result = 0.0_f
do k=1,last
result = result+rlist(k)
end do
abserr = errsum
60 if(keyf.ne.1) neval = (10*keyf+1)*(2*neval+1)
if(keyf.eq.1) neval = 30*neval+15
999 return
end subroutine dqage
!!***begin prologue dqagi
!!***date written 800101 (yymmdd)
!!***revision date 130319 (yymmdd)
!!***category no. h2a3a1,h2a4a1
!!***keywords automatic integrator, infinite intervals,
!! general-purpose, transformation, extrapolation,
!! globally adaptive
!!***author piessens,robert,appl. math. & progr. div. - k.u.leuven
!! de doncker,elise,appl. math. & progr. div. -k.u.leuven
!!***purpose the routine calculates an approximation result to a given
!! integral i = integral of f over (bound,+infinity)
!! or i = integral of f over (-infinity,bound)
!! or i = integral of f over (-infinity,+infinity)
!! hopefully satisfying following claim for accuracy
!! abs(i-result).le.max(epsabs,epsrel*abs(i)).
!!***description
!!
!! integration over infinite intervals
!! standard fortran subroutine
!!
!! parameters
!! on entry
!! fx - double precision
!! function subprogram defining the integrand
!! function f(x). the actual name for f needs to be
!! declared e x t e r n a l in the driver program.
!!
!! fx_vars- structure containing variables need for integration
!! specific to fractal meanfield scattering code
!!
!! bound - double precision
!! finite bound of integration range
!! (has no meaning if interval is doubly-infinite)
!!
!! inf - integer
!! indicating the kind of integration range involved
!! inf = 1 corresponds to (bound,+infinity),
!! inf = -1 to (-infinity,bound),
!! inf = 2 to (-infinity,+infinity).
!!
!! epsabs - double precision
!! absolute accuracy requested
!! epsrel - double precision
!! relative accuracy requested
!! if epsabs.le.0
!! and epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
!! the routine will end with ier = 6.
!!
!!
!! on return
!! result - double precision
!! approximation to the integral
!!
!! abserr - double precision
!! estimate of the modulus of the absolute error,
!! which should equal or exceed abs(i-result)
!!
!! neval - integer
!! number of integrand evaluations
!!
!! ier - integer
!! ier = 0 normal and reliable termination of the
!! routine. it is assumed that the requested
!! accuracy has been achieved.
!! - ier.gt.0 abnormal termination of the routine. the
!! estimates for result and error are less
!! reliable. it is assumed that the requested
!! accuracy has not been achieved.
!! error messages
!! ier = 1 maximum number of subdivisions allowed
!! has been achieved. one can allow more
!! subdivisions by increasing the value of
!! limit (and taking the according dimension
!! adjustments into account). however, if
!! this yields no improvement it is advised
!! to analyze the integrand in order to
!! determine the integration difficulties. if
!! the position of a local difficulty can be
!! determined (e.g. singularity,
!! discontinuity within the interval) one
!! will probably gain from splitting up the
!! interval at this point and calling the
!! integrator on the subranges. if possible,
!! an appropriate special-purpose integrator
!! should be used, which is designed for
!! handling the type of difficulty involved.
!! = 2 the occurrence of roundoff error is
!! detected, which prevents the requested
!! tolerance from being achieved.
!! the error may be under-estimated.
!! = 3 extremely bad integrand behaviour occurs
!! at some points of the integration
!! interval.
!! = 4 the algorithm does not converge.
!! roundoff error is detected in the
!! extrapolation table.
!! it is assumed that the requested tolerance
!! cannot be achieved, and that the returned
!! result is the best which can be obtained.
!! = 5 the integral is probably divergent, or
!! slowly convergent. it must be noted that
!! divergence can occur with any other value
!! of ier.
!! = 6 the input is invalid, because
!! (epsabs.le.0 and
!! epsrel.lt.max(50*rel.mach.acc.,0.5d-28))
!! or limit.lt.1 or leniw.lt.limit*4.
!! result, abserr, neval, last are set to
!! zero. exept when limit or leniw is
!! invalid, iwork(1), work(limit*2+1) and
!! work(limit*3+1) are set to zero, work(1)
!! is set to a and work(limit+1) to b.
!! = 9 failure in sd1mach determining machine parameters
!!
!! dimensioning parameters
!! limit - integer
!! dimensioning parameter for iwork
!! limit determines the maximum number of subintervals
!! in the partition of the given integration interval
!! (a,b), limit.ge.1.
!! if limit.lt.1, the routine will end with ier = 6.
!!
!! lenw - integer
!! dimensioning parameter for work
!! lenw must be at least limit*4.
!! if lenw.lt.limit*4, the routine will end
!! with ier = 6.
!!
!! last - integer
!! on return, last equals the number of subintervals
!! produced in the subdivision process, which
!! determines the number of significant elements
!! actually in the work arrays.
!!
!! work arrays
!! iwork - integer
!! vector of dimension at least limit, the first
!! k elements of which contain pointers
!! to the error estimates over the subintervals,
!! such that work(limit*3+iwork(1)),... ,
!! work(limit*3+iwork(k)) form a decreasing
!! sequence, with k = last if last.le.(limit/2+2), and
!! k = limit+1-last otherwise
!!
!! work - double precision
!! vector of dimension at least lenw
!! on return
!! work(1), ..., work(last) contain the left
!! end points of the subintervals in the
!! partition of (a,b),
!! work(limit+1), ..., work(limit+last) contain
!! the right end points,
!! work(limit*2+1), ...,work(limit*2+last) contain the
!! integral approximations over the subintervals,
!! work(limit*3+1), ..., work(limit*3)
!! contain the error estimates.
!!***references (none)
!!***routines called dqagie,xerror
!!***end prologue dqagi
!!
subroutine dqagi(fx,fx_vars,bound,inf,epsabs,epsrel,result,abserr,neval, &
ier,limit,lenw,last,iwork,work)
! Arguments
interface
function fx(centr, vars)
use carma_precision_mod, only : f
use adgaquad_types_mod
real(kind=f), intent(in) :: centr
type(adgaquad_vars_type), intent(inout) :: vars
real(kind=f) :: fx
end function fx
end interface
type(adgaquad_vars_type) :: fx_vars
real(kind=f) :: bound
integer :: inf
real(kind=f) :: epsabs
real(kind=f) :: epsrel
real(kind=f) :: result
real(kind=f) :: abserr
integer :: neval
integer :: ier
integer :: limit
integer :: lenw
integer :: last
integer :: iwork(limit)
real(kind=f) :: work(lenw)
! Local declarations
integer lvl,l1,l2,l3
!
! check validity of limit and lenw.
!
!***first executable statement dqagi
ier = 6
neval = 0
last = 0
result = 0.0_f
abserr = 0.0_f
if(limit.lt.1.or.lenw.lt.limit*4) go to 10
!
! prepare call for dqagie.
!
l1 = limit+1
l2 = limit+l1
l3 = limit+l2
call dqagie(fx,fx_vars,bound,inf,epsabs,epsrel,limit,result,abserr, &
neval,ier,work(1),work(l1),work(l2),work(l3),iwork,last)
!
! call error handler if necessary.
!
lvl = 0
10 if(ier.eq.6) lvl = 1
if(ier.ne.0) then
write(*,*) "ERROR: abnormal return from dqagi"
write(*,*) " ifail=",ier," level=",lvl
endif
return
end subroutine dqagi
!!***begin prologue dqagie
!!***date written 800101 (yymmdd)
!!***revision date 130319 (yymmdd)
!!***category no. h2a3a1,h2a4a1
!!***keywords automatic integrator, infinite intervals,
!! general-purpose, transformation, extrapolation,
!! globally adaptive
!!***author piessens,robert,appl. math & progr. div - k.u.leuven
!! de doncker,elise,appl. math & progr. div - k.u.leuven
!!***purpose the routine calculates an approximation result to a given
!! integral i = integral of f over (bound,+infinity)
!! or i = integral of f over (-infinity,bound)
!! or i = integral of f over (-infinity,+infinity),
!! hopefully satisfying following claim for accuracy
!! abs(i-result).le.max(epsabs,epsrel*abs(i))
!!***description
!!
!! integration over infinite intervals
!! standard fortran subroutine
!!
!! fx - double precision
!! function subprogram defining the integrand
!! function f(x). the actual name for f needs to be
!! declared e x t e r n a l in the driver program.
!!
!! fx_vars- structure containing variables need for integration
!! specific to fractal meanfield scattering code
!!
!! bound - double precision
!! finite bound of integration range
!! (has no meaning if interval is doubly-infinite)
!!
!! inf - double precision
!! indicating the kind of integration range involved
!! inf = 1 corresponds to (bound,+infinity),
!! inf = -1 to (-infinity,bound),
!! inf = 2 to (-infinity,+infinity).
!!
!! epsabs - double precision
!! absolute accuracy requested
!! epsrel - double precision
!! relative accuracy requested
!! if epsabs.le.0
!! and epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
!! the routine will end with ier = 6.
!!
!! limit - integer
!! gives an upper bound on the number of subintervals
!! in the partition of (a,b), limit.ge.1
!!
!! on return
!! result - double precision
!! approximation to the integral
!!
!! abserr - double precision
!! estimate of the modulus of the absolute error,
!! which should equal or exceed abs(i-result)
!!
!! neval - integer
!! number of integrand evaluations
!!
!! ier - integer
!! ier = 0 normal and reliable termination of the
!! routine. it is assumed that the requested
!! accuracy has been achieved.
!! - ier.gt.0 abnormal termination of the routine. the
!! estimates for result and error are less
!! reliable. it is assumed that the requested
!! accuracy has not been achieved.
!! error messages
!! ier = 1 maximum number of subdivisions allowed
!! has been achieved. one can allow more
!! subdivisions by increasing the value of
!! limit (and taking the according dimension
!! adjustments into account). however,if
!! this yields no improvement it is advised
!! to analyze the integrand in order to
!! determine the integration difficulties.
!! if the position of a local difficulty can
!! be determined (e.g. singularity,
!! discontinuity within the interval) one
!! will probably gain from splitting up the
!! interval at this point and calling the
!! integrator on the subranges. if possible,
!! an appropriate special-purpose integrator
!! should be used, which is designed for
!! handling the type of difficulty involved.
!! = 2 the occurrence of roundoff error is
!! detected, which prevents the requested
!! tolerance from being achieved.
!! the error may be under-estimated.
!! = 3 extremely bad integrand behaviour occurs
!! at some points of the integration
!! interval.
!! = 4 the algorithm does not converge.
!! roundoff error is detected in the
!! extrapolation table.
!! it is assumed that the requested tolerance
!! cannot be achieved, and that the returned
!! result is the best which can be obtained.
!! = 5 the integral is probably divergent, or
!! slowly convergent. it must be noted that
!! divergence can occur with any other value
!! of ier.
!! = 6 the input is invalid, because
!! (epsabs.le.0 and
!! epsrel.lt.max(50*rel.mach.acc.,0.5d-28),
!! result, abserr, neval, last, rlist(1),
!! elist(1) and iord(1) are set to zero.
!! alist(1) and blist(1) are set to 0
!! and 1 respectively.
!! = 9 failure in sd1mach determining machine parameters
!!
!! alist - double precision
!! vector of dimension at least limit, the first
!! last elements of which are the left
!! end points of the subintervals in the partition