Skip to content

Commit efac226

Browse files
Merge pull request #232 from jacobwilliams/real-format
Real format fix
2 parents ee40873 + a404828 commit efac226

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

src/json_parameters.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module json_parameters
9393
!find out the precision of the floating point number system
9494
!and set safety factors
9595
integer(IK),parameter :: rp_safety_factor = 1_IK
96-
integer(IK),parameter :: rp_addl_safety = 1_IK
96+
integer(IK),parameter :: rp_addl_safety = 2_IK
9797
integer(IK),parameter :: real_precision = rp_safety_factor*precision(1.0_RK) + &
9898
rp_addl_safety
9999

src/tests/jf_test_21.f90

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
!*****************************************************************************************
2+
!> author: Jacob Williams
3+
! date: 10/20/2016
4+
!
5+
! Module for the 21st unit test.
6+
! This one is testing the real format options.
7+
8+
module jf_test_21_mod
9+
10+
use json_module, RK => json_RK
11+
use, intrinsic :: iso_fortran_env , only: error_unit,output_unit
12+
13+
implicit none
14+
15+
character(len=*),parameter :: dir = '../files/' !! working directory
16+
17+
contains
18+
19+
subroutine test_21(error_cnt)
20+
21+
!! Test some of the edge cases, and incorrect usages.
22+
23+
implicit none
24+
25+
integer,intent(out) :: error_cnt !! report number of errors to caller
26+
27+
type(json_core) :: json
28+
type(json_file) :: jfile
29+
type(json_value),pointer :: ptr
30+
31+
logical :: found
32+
real(kind=RK),dimension(:),allocatable :: array1,array2
33+
34+
write(error_unit,'(A)') ''
35+
write(error_unit,'(A)') '================================='
36+
write(error_unit,'(A)') ' TEST 21'
37+
write(error_unit,'(A)') '================================='
38+
write(error_unit,'(A)') ''
39+
40+
error_cnt = 0
41+
42+
array1 = [sqrt(2.0_RK),sqrt(3.0_RK),sqrt(7.0_RK),&
43+
sqrt(2.0e4_RK),sqrt(3.0e5_RK),sqrt(7.0e6_RK),&
44+
huge(1.0_RK),tiny(1.0_RK),epsilon(1.0_RK)]
45+
46+
! write array1 into file
47+
call json % initialize(real_format='E')
48+
call json % create_object(ptr,'')
49+
call json % add(ptr,'value',array1)
50+
call json % print(ptr,dir//'test21.json')
51+
call json % destroy(ptr)
52+
53+
! read array2 from file
54+
call jfile % initialize(real_format='E')
55+
call jfile % load_file(dir//'test21.json')
56+
call jfile % get('value',array2,found)
57+
call jfile % destroy()
58+
59+
! Compare
60+
write(*,*) ''
61+
if (any(array1 /= array2)) then
62+
error_cnt = error_cnt + 1
63+
write(*,*) 'Test failed'
64+
write(*,*) array1 == array2
65+
else
66+
write(*,*) 'Test passed'
67+
end if
68+
write(*,'(A,1X,*(E30.18E3))') 'original array :',array1
69+
write(*,'(A,1X,*(E30.18E3))') 'read from file :',array2
70+
write(*,*) ''
71+
72+
end subroutine test_21
73+
74+
end module jf_test_21_mod
75+
!*****************************************************************************************
76+
77+
!*****************************************************************************************
78+
program jf_test_21
79+
80+
!! 21st unit test.
81+
82+
use jf_test_21_mod, only: test_21
83+
implicit none
84+
integer :: n_errors
85+
call test_21(n_errors)
86+
if ( n_errors /= 0) stop 1
87+
88+
end program jf_test_21
89+
!*****************************************************************************************

0 commit comments

Comments
 (0)