@@ -7,6 +7,7 @@ module jf_test_12_mod
7
7
8
8
character (len=* ),parameter :: dir = ' ../files/outputs/' ! ! Path to write JSON file to
9
9
character (len=* ),parameter :: file = ' array.json' ! ! Filename to write
10
+ real (wp), parameter :: TOL = 100 * epsilon (1.0_wp ) ! ! Tolerance for real comparisons
10
11
11
12
contains
12
13
@@ -81,7 +82,7 @@ subroutine test_12(error_cnt)
81
82
call check_errors()
82
83
83
84
call json_get(root,' $.array data.data(1)' ,array_element)
84
- call check_errors(array_element == 1.0_wp )
85
+ call check_errors(abs ( array_element - 1.0_wp ) < = TOL )
85
86
86
87
call json_get(root,' @.array data.shape' ,fetched_shape)
87
88
call check_errors(all (fetched_shape == shape))
@@ -129,14 +130,14 @@ subroutine test_12(error_cnt)
129
130
call check_errors()
130
131
131
132
call json_get(tmp_json_ptr,fetched_array)
132
- call check_errors(all (fetched_array == reshape (raw_array,[size (raw_array)])))
133
+ call check_errors(all (abs ( fetched_array - reshape (raw_array,[size (raw_array)])) < = TOL ))
133
134
134
135
call json_get(root,' array data.data' ,fetched_array)
135
- call check_errors(all (fetched_array == reshape (raw_array,[size (raw_array)])))
136
+ call check_errors(all (abs ( fetched_array - reshape (raw_array,[size (raw_array)])) < = TOL ))
136
137
137
138
raw_array = 0
138
139
call json_get(me= root,path= ' array data.data' ,array_callback= get_3D_from_array)
139
- call check_errors(all (fetched_array == reshape (raw_array,[size (raw_array)])))
140
+ call check_errors(all (abs ( fetched_array - reshape (raw_array,[size (raw_array)])) < = TOL ))
140
141
141
142
my_file = json_file(root)
142
143
@@ -150,7 +151,7 @@ subroutine test_12(error_cnt)
150
151
call check_errors()
151
152
152
153
call my_file% get(' $array data.data' ,fetched_array)
153
- call check_errors(all (fetched_array == reshape (raw_array,[size (raw_array)])))
154
+ call check_errors(all (abs ( fetched_array - reshape (raw_array,[size (raw_array)])) < = TOL ))
154
155
155
156
call my_file% get(tmp_json_ptr)
156
157
call check_errors(associated (tmp_json_ptr,root))
@@ -169,14 +170,16 @@ subroutine check_errors(assertion)
169
170
170
171
subroutine get_3D_from_array (element , i , count )
171
172
type (json_value), pointer , intent (in ) :: element
172
- integer , intent (in ) :: i ! index
173
- integer , intent (in ) :: count ! size of array
173
+ integer , intent (in ) :: i ! !index
174
+ integer , intent (in ) :: count ! !size of array
175
+ integer :: useless ! ! assign count to this to silence warnings
174
176
175
177
! let's pretend we're c programmers!
176
178
call json_get( element, raw_array( &
177
179
mod (i-1 ,imx) + 1 , & ! i index
178
180
mod ((i-1 )/ imx,jmx) + 1 , & ! j index
179
181
mod ((i-1 )/ imx/ jmx,kmx) + 1 ) ) ! k inded
182
+ useless = count
180
183
end subroutine
181
184
182
185
end subroutine
0 commit comments