@@ -17,6 +17,8 @@ program root_tests
17
17
18
18
implicit none
19
19
20
+ character (len= :),allocatable :: kind_str ! ! real kind string
21
+
20
22
integer :: nprob
21
23
integer :: n
22
24
integer :: imeth ! ! method counter
@@ -30,6 +32,9 @@ program root_tests
30
32
integer ,dimension (:),allocatable :: cases_to_run
31
33
type (pyplot) :: stats_plot ! ! pyplot handler
32
34
integer ,dimension (2 ),parameter :: figsize= [10 ,5 ] ! ! figure size for plogs
35
+ character (len= 30 ) :: r_str
36
+ real (wp) :: atol, rtol, ftol
37
+ real (wp) :: tol_for_check ! ! for pass/fail check
33
38
34
39
character (len=* ),parameter :: fmt = ' ( A20,1X,A3,1X,A4,1X,A16, 1X,A25, 1X,A16, 1X,A5,1X,A5,1X,A8 )' ! ! format for header
35
40
character (len=* ),parameter :: dfmt = ' (1P,A20,1X,I3,1X,I4,1X,E16.6,1X,E25.16,1X,E16.6,1X,I5,1X,I5,1X,E8.1,1x,a)' ! ! format for results
@@ -59,6 +64,29 @@ program root_tests
59
64
60
65
integer ,dimension (number_of_methods) :: number_of_wins, ivec, number_of_failures, ivec2
61
66
67
+ select case (wp)
68
+ case (real32)
69
+ atol = 1.0e-5_wp
70
+ rtol = 1.0e-5_wp
71
+ ftol = 1.0e-5_wp
72
+ tol_for_check = 1.0e-4_wp
73
+ kind_str = ' real32'
74
+ case (real64)
75
+ atol = 1.0e-15_wp
76
+ rtol = 1.0e-13_wp
77
+ ftol = 1.0e-15_wp
78
+ tol_for_check = 1.0e-7_wp
79
+ kind_str = ' real64'
80
+ case (real128)
81
+ atol = 1.0e-25_wp
82
+ rtol = 1.0e-23_wp
83
+ ftol = 1.0e-25_wp
84
+ tol_for_check = 1.0e-16_wp
85
+ kind_str = ' real128'
86
+ case default
87
+ error stop ' unknown real kind'
88
+ end select
89
+
62
90
write (* ,* ) ' '
63
91
write (* ,* ) ' -------------------------------------------------'
64
92
write (* ,* ) ' root_tests'
@@ -71,13 +99,13 @@ program root_tests
71
99
! open output files:
72
100
open (newunit= iunit, file= ' root_report_best.txt' , status= ' REPLACE' , iostat= istat)
73
101
open (newunit= iunit_failed, file= ' root_report_failures.txt' , status= ' REPLACE' , iostat= istat)
74
- open (newunit= iunit_results, file= ' table .tex' , status= ' REPLACE' , iostat= istat)
102
+ open (newunit= iunit_results, file= ' table_ ' // kind_str // ' .tex' , status= ' REPLACE' , iostat= istat)
75
103
76
104
! output file headers:
77
105
write (iunit, ' (A5,1X,A5,1X,A5,1X,A)' ) ' nprob' , ' n' , ' evals' , ' Best Methods'
78
106
write (iunit_failed, ' (A5,1X,A5,1X,A)' ) ' nprob' , ' n' , ' Failed Methods'
79
107
80
- write (iunit_results,' (a)' ) ' % !TeX root = table .tex'
108
+ write (iunit_results,' (a)' ) ' % !TeX root = ' // ' table_ ' // kind_str // ' .tex'
81
109
82
110
write (iunit_results,' (a)' ) ' \documentclass{article}'
83
111
write (iunit_results,' (a)' ) ' \usepackage[utf8]{inputenc}'
@@ -97,12 +125,20 @@ program root_tests
97
125
write (iunit_results,' (a)' ) ' \begin{landscape}'
98
126
99
127
write (iunit_results,' (a)' ) ' '
100
- write (iunit_results,' (a)' ) ' \section{Function Evaluations}'
128
+ write (iunit_results,' (a)' ) ' \section{Function Evaluations (' // kind_str// ' )}'
129
+ write (iunit_results,' (a)' ) ' '
130
+
131
+ ! write(iunit_results,'(a)') '\begin{align}'
132
+ write (r_str, ' (1p,E10.1)' ) atol; write (iunit_results,' (a)' ) ' $\epsilon_{abs} = ' // trim (adjustl (r_str)// ' $\\' )
133
+ write (r_str, ' (1p,E10.1)' ) rtol; write (iunit_results,' (a)' ) ' $\epsilon_{rel} = ' // trim (adjustl (r_str)// ' $\\' )
134
+ write (r_str, ' (1p,E10.1)' ) ftol; write (iunit_results,' (a)' ) ' $\epsilon_{func} = ' // trim (adjustl (r_str)// ' $\\' )
135
+ ! write(iunit_results,'(a)') '\end{align}'
101
136
write (iunit_results,' (a)' ) ' '
102
137
138
+
103
139
! cols are num, func, bounds, [methods]
104
- write (iunit_results,' (a)' ) ' \begin{longtable}{' // repeat (' c' ,number_of_methods+4 )// ' }'
105
- write (iunit_results,' (a)' ,advance= ' NO' ) ' No. & $f(x)$ & n & $[x_a, x_b]$ & '
140
+ write (iunit_results,' (a)' ) ' \begin{longtable}{' // repeat (' c' ,number_of_methods+5 )// ' }'
141
+ write (iunit_results,' (a)' ,advance= ' NO' ) ' No. & $f(x)$ & n & $[x_a, x_b]$ & $x_{root}$ & '
106
142
do imeth = 1 , number_of_methods
107
143
if (imeth== number_of_methods) then
108
144
write (iunit_results,' (a)' ) ' \verb|' // trim (methods(imeth))// ' |' // ' \\'
@@ -143,7 +179,7 @@ program root_tests
143
179
close (iunit_failed)
144
180
close (iunit_results)
145
181
146
- call stats_plot% savefig(' stats_plot .pdf' ,istat= istat,pyfile= ' stats_plot.py' )
182
+ call stats_plot% savefig(' stats_plot_ ' // kind_str // ' .pdf' ,istat= istat,pyfile= ' stats_plot.py' )
147
183
148
184
! another summary:
149
185
ivec = [(i, i = 1 , number_of_methods)]
@@ -184,35 +220,14 @@ subroutine test()
184
220
real (wp) :: tstart, tfinish ! ! for `cpu_time`
185
221
integer :: irepeat ! ! test repeat counter
186
222
integer :: i
187
- real (wp) :: atol, rtol, ftol
188
- real (wp) :: tol_for_check ! ! for pass/fail check
189
223
character (len= :),allocatable :: latex, tmp, latex_line, bounds, fevals_line, eqn
190
224
character (len= 10 ) :: itmp, nstr
191
225
integer :: n_bounds_cases, bounds_cases_first
226
+ character (len= 30 ) :: root_str
192
227
193
228
integer ,parameter :: n_repeat = 1 ! ! number of times to repeat each test for timing purposes
194
229
integer ,parameter :: maxiter = 1000 ! ! maximum number of iterations
195
230
196
- select case (wp)
197
- case (real32)
198
- atol = 1.0e-5_wp
199
- rtol = 1.0e-5_wp
200
- ftol = 1.0e-5_wp
201
- tol_for_check = 1.0e-4_wp
202
- case (real64)
203
- atol = 1.0e-15_wp
204
- rtol = 1.0e-13_wp
205
- ftol = 1.0e-15_wp
206
- tol_for_check = 1.0e-7_wp
207
- case (real128)
208
- atol = 1.0e-25_wp
209
- rtol = 1.0e-23_wp
210
- ftol = 1.0e-25_wp
211
- tol_for_check = 1.0e-16_wp
212
- case default
213
- error stop ' unknown real kind'
214
- end select
215
-
216
231
write (output_unit,fmt) &
217
232
repeat (' -' ,20 ),repeat (' -' ,3 ),repeat (' -' ,4 ),repeat (' -' ,16 ),&
218
233
repeat (' -' ,25 ),repeat (' -' ,16 ),repeat (' -' ,5 ),repeat (' -' ,5 ),repeat (' -' ,8 )
@@ -348,8 +363,12 @@ subroutine test()
348
363
eqn = ' $' // trim (latex) // ' $'
349
364
end if
350
365
366
+ ! root string:
367
+ write (root_str, ' (1p,e30.15)' ) root; root_str = trim (adjustl (root_str))
368
+
351
369
! write the row of the latex table:
352
- write (latex_line,' (i4,a)' ) nprob, ' & ' // eqn// ' & ' // nstr// ' & ' // ' $[' // bounds// ' ]$ & ' // fevals_line
370
+ write (latex_line,' (i4,a)' ) nprob, ' & ' // eqn// ' & ' // nstr// ' & ' // ' $[' // &
371
+ bounds// ' ]$ & ' // trim (root_str)// ' & ' // fevals_line
353
372
latex_line = trim (latex_line)
354
373
latex_line(len (latex_line):len (latex_line)) = ' '
355
374
latex_line = trim (latex_line) // ' \\'
@@ -673,9 +692,19 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
673
692
if (present (x)) f = x** (1.0_wp / dn) - dn** (1.0_wp / dn)
674
693
if (present (latex)) latex = ' x^{1/n} - n^{1/n}'
675
694
if (present (bounds)) bounds = ' 1,100'
676
- case (26 )
677
- a = - 1.0_wp
678
- b = 4.0_wp
695
+ case (26 :27 )
696
+ if (present (n_bounds_cases)) n_bounds_cases = 2
697
+ if (present (bounds_cases_first)) bounds_cases_first = 26
698
+ select case (nprob)
699
+ case (26 )
700
+ a = - 1.0_wp
701
+ b = 4.0_wp
702
+ if (present (bounds)) bounds = ' -1,4'
703
+ case (27 )
704
+ a = - 1.1234_wp
705
+ b = 4.4567_wp
706
+ if (present (bounds)) bounds = ' -1.1234,4.4567'
707
+ end select
679
708
root = 0.0_wp ! this is just almost impossible to get
680
709
if (present (x)) then
681
710
if (x == 0.0_wp ) then
@@ -686,8 +715,8 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
686
715
end if
687
716
if (present (latex)) latex = ' \left\{ \begin{array}{cl} 0 & \mathrm{if~}x=0 \\' // &
688
717
' x \mathrm{e}^{-1/x^2} & \mathrm{otherwise} \end{array} \right.'
689
- if ( present (bounds)) bounds = ' -1,4 '
690
- case (27 )
718
+
719
+ case (28 )
691
720
a = - 10000.0_wp
692
721
b = pi/ 2.0_wp
693
722
root = 6.2380651896161232E-01_wp
@@ -703,7 +732,7 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
703
732
if (present (latex)) latex = ' \left\{ \begin{array}{cl} (x/1.5 + \sin(x) - 1) n/20 & \mathrm{if~}x \ge 0 \\' // &
704
733
' -n/20 & \mathrm{otherwise} \end{array} \right.'
705
734
if (present (bounds)) bounds = ' -10000,\pi/2'
706
- case (28 )
735
+ case (29 )
707
736
a = - 10000.0_wp
708
737
b = 1.0e-4_wp
709
738
if (present (bounds)) bounds = ' -10000,1 \times 10^{-4}'
@@ -759,14 +788,6 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
759
788
' \mathrm{e}^{500 (n + 1) x} - 1.859 & x \ge 0\\' // &
760
789
' -0.859 & \mathrm{otherwise}' // &
761
790
' \end{array} \right.'
762
- case (29 )
763
- ! Zhang test case
764
- a = 0.0_wp
765
- b = 4.0_wp
766
- root = 8.6547403310161445E-01_wp
767
- if (present (x)) f = cos (x) - x** 3
768
- if (present (latex)) latex = ' \cos x - x^3'
769
- if (present (bounds)) bounds = ' 0,4'
770
791
771
792
! 30-36 : Gottlieb's paper [table 1 & 2]
772
793
case (30 )
@@ -1710,6 +1731,14 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
1710
1731
if (present (x)) f = x** 5
1711
1732
if (present (latex)) latex = ' x^5'
1712
1733
if (present (bounds)) bounds = ' -0.5,1/3'
1734
+ case (145 )
1735
+ ! Zhang test case
1736
+ a = 0.0_wp
1737
+ b = 4.0_wp
1738
+ root = 8.6547403310161445E-01_wp
1739
+ if (present (x)) f = cos (x) - x** 3
1740
+ if (present (latex)) latex = ' \cos x - x^3'
1741
+ if (present (bounds)) bounds = ' 0,4'
1713
1742
1714
1743
1715
1744
case default
0 commit comments