Skip to content

Commit 1ce9ffc

Browse files
committed
table cleanups
1 parent bf0dcf4 commit 1ce9ffc

File tree

1 file changed

+72
-43
lines changed

1 file changed

+72
-43
lines changed

test/root_tests.f90

Lines changed: 72 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ program root_tests
1717

1818
implicit none
1919

20+
character(len=:),allocatable :: kind_str !! real kind string
21+
2022
integer :: nprob
2123
integer :: n
2224
integer :: imeth !! method counter
@@ -30,6 +32,9 @@ program root_tests
3032
integer,dimension(:),allocatable :: cases_to_run
3133
type(pyplot) :: stats_plot !! pyplot handler
3234
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
3338

3439
character(len=*),parameter :: fmt = '( A20,1X,A3,1X,A4,1X,A16, 1X,A25, 1X,A16, 1X,A5,1X,A5,1X,A8 )' !! format for header
3540
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
5964

6065
integer,dimension(number_of_methods) :: number_of_wins, ivec, number_of_failures, ivec2
6166

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+
6290
write(*,*) ''
6391
write(*,*) '-------------------------------------------------'
6492
write(*,*) 'root_tests'
@@ -71,13 +99,13 @@ program root_tests
7199
! open output files:
72100
open(newunit=iunit, file='root_report_best.txt', status='REPLACE', iostat=istat)
73101
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)
75103

76104
! output file headers:
77105
write(iunit, '(A5,1X,A5,1X,A5,1X,A)') 'nprob', 'n', 'evals', 'Best Methods'
78106
write(iunit_failed, '(A5,1X,A5,1X,A)') 'nprob', 'n', 'Failed Methods'
79107

80-
write(iunit_results,'(a)') '% !TeX root = table.tex'
108+
write(iunit_results,'(a)') '% !TeX root = '//'table_'//kind_str//'.tex'
81109

82110
write(iunit_results,'(a)') '\documentclass{article}'
83111
write(iunit_results,'(a)') '\usepackage[utf8]{inputenc}'
@@ -97,12 +125,20 @@ program root_tests
97125
write(iunit_results,'(a)') '\begin{landscape}'
98126

99127
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}'
101136
write(iunit_results,'(a)') ''
102137

138+
103139
! 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}$ &'
106142
do imeth = 1, number_of_methods
107143
if (imeth==number_of_methods) then
108144
write(iunit_results,'(a)') '\verb|' // trim(methods(imeth))//'|' // '\\'
@@ -143,7 +179,7 @@ program root_tests
143179
close(iunit_failed)
144180
close(iunit_results)
145181

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')
147183

148184
! another summary:
149185
ivec = [(i, i = 1, number_of_methods)]
@@ -184,35 +220,14 @@ subroutine test()
184220
real(wp) :: tstart, tfinish !! for `cpu_time`
185221
integer :: irepeat !! test repeat counter
186222
integer :: i
187-
real(wp) :: atol, rtol, ftol
188-
real(wp) :: tol_for_check !! for pass/fail check
189223
character(len=:),allocatable :: latex, tmp, latex_line, bounds, fevals_line, eqn
190224
character(len=10) :: itmp, nstr
191225
integer :: n_bounds_cases, bounds_cases_first
226+
character(len=30) :: root_str
192227

193228
integer,parameter :: n_repeat = 1 !! number of times to repeat each test for timing purposes
194229
integer,parameter :: maxiter = 1000 !! maximum number of iterations
195230

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-
216231
write(output_unit,fmt) &
217232
repeat('-',20),repeat('-',3),repeat('-',4),repeat('-',16),&
218233
repeat('-',25),repeat('-',16),repeat('-',5),repeat('-',5),repeat('-',8)
@@ -348,8 +363,12 @@ subroutine test()
348363
eqn = '$'//trim(latex) // '$'
349364
end if
350365

366+
! root string:
367+
write(root_str, '(1p,e30.15)') root; root_str = trim(adjustl(root_str))
368+
351369
! 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
353372
latex_line = trim(latex_line)
354373
latex_line(len(latex_line):len(latex_line)) = ' '
355374
latex_line = trim(latex_line) // '\\'
@@ -673,9 +692,19 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
673692
if (present(x)) f = x**(1.0_wp/dn) - dn**(1.0_wp/dn)
674693
if (present(latex)) latex = 'x^{1/n} - n^{1/n}'
675694
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
679708
root = 0.0_wp ! this is just almost impossible to get
680709
if (present(x)) then
681710
if (x == 0.0_wp) then
@@ -686,8 +715,8 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
686715
end if
687716
if (present(latex)) latex = '\left\{ \begin{array}{cl} 0 & \mathrm{if~}x=0 \\'//&
688717
' 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)
691720
a = -10000.0_wp
692721
b = pi/2.0_wp
693722
root = 6.2380651896161232E-01_wp
@@ -703,7 +732,7 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
703732
if (present(latex)) latex = '\left\{ \begin{array}{cl} (x/1.5 + \sin(x) - 1) n/20 & \mathrm{if~}x \ge 0 \\'//&
704733
' -n/20 & \mathrm{otherwise} \end{array} \right.'
705734
if (present(bounds)) bounds = '-10000,\pi/2'
706-
case (28)
735+
case (29)
707736
a = -10000.0_wp
708737
b = 1.0e-4_wp
709738
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,
759788
' \mathrm{e}^{500 (n + 1) x} - 1.859 & x \ge 0\\'//&
760789
' -0.859 & \mathrm{otherwise}'//&
761790
' \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'
770791

771792
! 30-36 : Gottlieb's paper [table 1 & 2]
772793
case (30)
@@ -1710,6 +1731,14 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
17101731
if (present(x)) f = x**5
17111732
if (present(latex)) latex = 'x^5'
17121733
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'
17131742

17141743

17151744
case default

0 commit comments

Comments
 (0)