Skip to content

Commit dd3c2f5

Browse files
committed
Fixed some issues where default integers were being used, which prevented the integer kind from being changed. Fixes #365
1 parent 36b16d2 commit dd3c2f5

31 files changed

+177
-177
lines changed

src/json_file_module.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ subroutine json_file_print_to_console(me)
843843

844844
class(json_file),intent(inout) :: me
845845

846-
call me%core%print(me%p,iunit=output_unit)
846+
call me%core%print(me%p,iunit=int(output_unit,IK))
847847

848848
end subroutine json_file_print_to_console
849849
!*****************************************************************************************

src/json_value_module.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,8 @@ subroutine json_matrix_info(json,p,is_matrix,var_type,n_sets,set_size,name)
15791579
integer(IK) :: nr !! number of children of `p`
15801580
integer(IK) :: nc !! number of elements in first child of `p`
15811581
integer(IK) :: icount !! number of elements in a set
1582-
integer :: i !! counter
1583-
integer :: j !! counter
1582+
integer(IK) :: i !! counter
1583+
integer(IK) :: j !! counter
15841584
#if defined __GFORTRAN__
15851585
character(kind=CK,len=:),allocatable :: p_name !! temporary variable for getting name
15861586
#endif

src/tests/jf_test_01.F90

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module jf_test_1_mod
99

10-
use json_module, wp => json_RK
10+
use json_module, wp => json_RK, IK => json_IK, LK => json_LK
1111
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1212

1313
implicit none
@@ -31,17 +31,17 @@ subroutine test_1(error_cnt)
3131
type(json_value),pointer :: p !! a pointer for low-level manipulations
3232
type(json_core) :: core !! factory for manipulating `json_value` pointers
3333
integer,intent(out) :: error_cnt
34-
integer :: ival
34+
integer(IK) :: ival
3535
character(kind=json_CK,len=:),allocatable :: cval
3636
real(wp) :: rval
37-
logical :: found
38-
logical :: lval
39-
integer,dimension(:),allocatable :: ivec
40-
integer,dimension(:),allocatable :: ilen
37+
logical(LK) :: found
38+
logical(LK) :: lval
39+
integer(IK),dimension(:),allocatable :: ivec
40+
integer(IK),dimension(:),allocatable :: ilen
4141
real(wp),dimension(:),allocatable :: rvec
4242
character(kind=json_CK,len=1),dimension(:),allocatable :: cvec
4343
character(kind=json_CK,len=:),dimension(:),allocatable :: acvec
44-
logical,dimension(:),allocatable :: lvec
44+
logical(LK),dimension(:),allocatable :: lvec
4545

4646
error_cnt = 0
4747
call json%initialize()
@@ -72,7 +72,7 @@ subroutine test_1(error_cnt)
7272
! print the parsed data to the console
7373
write(error_unit,'(A)') ''
7474
write(error_unit,'(A)') 'printing the file...'
75-
call json%print_file(error_unit)
75+
call json%print_file(int(error_unit,IK))
7676
if (json%failed()) then
7777
call json%print_error_message(error_unit)
7878
error_cnt = error_cnt + 1
@@ -102,7 +102,7 @@ subroutine test_1(error_cnt)
102102
write(error_unit,'(A)') ''
103103
write(error_unit,'(A)') 'printing each variable [JSONPath style]'
104104
write(error_unit,'(A)') ''
105-
call core%initialize(path_mode=3,unescape_strings=.false.)
105+
call core%initialize(path_mode=3_IK,unescape_strings=.false.)
106106
call core%traverse(p,print_json_variable)
107107

108108
call core%destroy()
@@ -113,7 +113,7 @@ subroutine test_1(error_cnt)
113113
write(error_unit,'(A)') ''
114114
write(error_unit,'(A)') 'get some data from the file...'
115115

116-
call json%initialize(path_mode=1,path_separator=json_CK_'%') ! use fortran-style paths
116+
call json%initialize(path_mode=1_IK,path_separator=json_CK_'%') ! use fortran-style paths
117117

118118
call json%get('version%svn', ival)
119119
if (json%failed()) then
@@ -336,7 +336,7 @@ subroutine test_1(error_cnt)
336336

337337
write(error_unit,'(A)') ''
338338
write(error_unit,'(A)') 'printing the modified structure...'
339-
call json%print_file(error_unit)
339+
call json%print_file(int(error_unit,IK))
340340
if (json%failed()) then
341341
call json%print_error_message(error_unit)
342342
error_cnt = error_cnt + 1
@@ -362,15 +362,15 @@ subroutine test_1(error_cnt)
362362
!call json%update(p,'real',[1.0_wp, 2.0_wp, 3.0_wp],found) !don't have one like this yet...
363363

364364
!use the json_file procedure to update a variable:
365-
call json%update('version.svn',999,found)
365+
call json%update('version.svn',999_IK,found)
366366
if (json%failed()) then
367367
call json%print_error_message(error_unit)
368368
error_cnt = error_cnt + 1
369369
end if
370370

371371
write(error_unit,'(A)') ''
372372
write(error_unit,'(A)') 'printing the modified structure...'
373-
call json%print_file(error_unit)
373+
call json%print_file(int(error_unit,IK))
374374
if (json%failed()) then
375375
call json%print_error_message(error_unit)
376376
error_cnt = error_cnt + 1
@@ -379,7 +379,7 @@ subroutine test_1(error_cnt)
379379
write(error_unit,'(A)') ''
380380
write(error_unit,'(A)') 'printing the modified structure (compact mode)...'
381381
call json%initialize(no_whitespace=.true.)
382-
call json%print_file(error_unit)
382+
call json%print_file(int(error_unit,IK))
383383
if (json%failed()) then
384384
call json%print_error_message(error_unit)
385385
error_cnt = error_cnt + 1
@@ -389,7 +389,7 @@ subroutine test_1(error_cnt)
389389
write(error_unit,'(A)') ''
390390
write(error_unit,'(A)') 'get some data from the file (bracket notation)...'
391391

392-
call json%initialize(path_mode=3)
392+
call json%initialize(path_mode=3_IK)
393393

394394
! get an integer value:
395395
write(error_unit,'(A)') ''
@@ -445,13 +445,13 @@ subroutine print_json_variable(json,p,finished)
445445

446446
class(json_core),intent(inout) :: json
447447
type(json_value),pointer,intent(in) :: p
448-
logical(json_LK),intent(out) :: finished !! set true to stop traversing
448+
logical(LK),intent(out) :: finished !! set true to stop traversing
449449

450450
character(kind=json_CK,len=:),allocatable :: path !! path to the variable
451-
logical(json_LK) :: found !! error flag
451+
logical(LK) :: found !! error flag
452452
type(json_value),pointer :: child !! variable's first child
453453
character(kind=json_CK,len=:),allocatable :: value !! variable value as a string
454-
integer(json_IK) :: var_type !! JSON variable type
454+
integer(IK) :: var_type !! JSON variable type
455455

456456
call json%get_child(p,child)
457457
finished = .false.

src/tests/jf_test_02.F90

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module jf_test_2_mod
99

10-
use json_module, wp => json_RK
10+
use json_module, wp => json_RK, IK => json_IK, LK => json_LK
1111
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1212

1313
implicit none
@@ -31,11 +31,11 @@ subroutine test_2(error_cnt)
3131
type(json_value),pointer :: p, inp, traj, tmp1, tmp2, p_tmp, p_integer_array, p_clone
3232
type(json_core) :: json !! factory for manipulating `json_value` pointers
3333

34-
integer :: iunit
34+
integer(IK) :: iunit
3535
character(kind=json_CK,len=:),allocatable :: name
36-
integer :: ival,ival_clone
37-
logical :: found
38-
logical :: is_valid
36+
integer(IK) :: ival,ival_clone
37+
logical(LK) :: found
38+
logical(LK) :: is_valid
3939
character(kind=json_CK,len=:),allocatable :: error_msg
4040

4141
write(error_unit,'(A)') ''
@@ -54,7 +54,7 @@ subroutine test_2(error_cnt)
5454
! first we test an incorrect usage case:
5555
! [trying to print a null json_value pointer]
5656
nullify(p)
57-
call json%print(p,error_unit)
57+
call json%print(p,int(error_unit,IK))
5858
if (.not. json%failed()) then
5959
write(error_unit,'(A)') 'Error: printing a null pointer should have raised an exception.'
6060
error_cnt = error_cnt + 1
@@ -121,12 +121,12 @@ subroutine test_2(error_cnt)
121121
call json%print_error_message(error_unit)
122122
error_cnt = error_cnt + 1
123123
end if
124-
call json%add(inp, 'integer_scalar', 1)
124+
call json%add(inp, 'integer_scalar', 1_IK)
125125
if (json%failed()) then
126126
call json%print_error_message(error_unit)
127127
error_cnt = error_cnt + 1
128128
end if
129-
call json%add(inp, 'integer_array', [2,4,99])
129+
call json%add(inp, 'integer_array', [2_IK,4_IK,99_IK])
130130
if (json%failed()) then
131131
call json%print_error_message(error_unit)
132132
error_cnt = error_cnt + 1
@@ -228,7 +228,7 @@ subroutine test_2(error_cnt)
228228
write(error_unit,'(A)') '============='
229229
write(error_unit,'(A)') ' p_clone'
230230
write(error_unit,'(A)') '============='
231-
call json%print(p_clone,error_unit)
231+
call json%print(p_clone,int(error_unit,IK))
232232
write(error_unit,'(A)') '============='
233233
write(error_unit,'(A)') ''
234234

@@ -240,7 +240,7 @@ subroutine test_2(error_cnt)
240240
error_cnt = error_cnt + 1
241241
else
242242
!now, change one and verify that they are independent:
243-
call json%update(p_clone,'inputs.integer_scalar',100,found)
243+
call json%update(p_clone,'inputs.integer_scalar',100_IK,found)
244244
if (json%failed()) write(error_unit,'(A)') 'json%update Error for p_clone'
245245
call json%get(p,'inputs.integer_scalar',ival)
246246
if (json%failed()) write(error_unit,'(A)') 'json%get Error for p'
@@ -250,7 +250,7 @@ subroutine test_2(error_cnt)
250250
call json%print_error_message(error_unit)
251251
error_cnt = error_cnt + 1
252252
else
253-
if (ival==1 .and. ival_clone==100) then
253+
if (ival==1_IK .and. ival_clone==100_IK) then
254254
write(error_unit,'(A)') 'json%clone ... passed'
255255
else
256256
write(error_unit,'(A)') 'Error: ival /= ival_clone'

src/tests/jf_test_03.F90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module jf_test_3_mod
99

10-
use json_module, wp => json_RK
10+
use json_module, wp => json_RK, IK => json_IK
1111
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1212

1313
implicit none
@@ -27,7 +27,7 @@ subroutine test_3(error_cnt)
2727
implicit none
2828

2929
integer,intent(out) :: error_cnt
30-
integer :: ival
30+
integer(IK) :: ival
3131
character(kind=json_CK,len=:),allocatable :: cval
3232
real(wp) :: rval
3333
type(json_file) :: json !the JSON structure read from the file:

src/tests/jf_test_04.F90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ subroutine test_4(error_cnt)
3535
type(json_file) :: json
3636
type(json_core) :: core !! factory for manipulating `json_value` pointers
3737

38-
integer :: i
38+
integer(json_IK) :: i
3939
character(kind=json_CK,len=10) :: istr
4040
character(kind=json_CK,len=:),allocatable :: string,name
4141
logical(json_LK) :: found

src/tests/jf_test_05.F90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module jf_test_5_mod
99

10-
use json_module, wp => json_RK
10+
use json_module, wp => json_RK, IK => json_IK, LK => json_LK
1111
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1212

1313
implicit none
@@ -29,11 +29,11 @@ subroutine test_5(error_cnt)
2929
implicit none
3030

3131
integer,intent(out) :: error_cnt
32-
integer :: vv
33-
integer,dimension(:),allocatable :: vvv
32+
integer(IK) :: vv
33+
integer(IK),dimension(:),allocatable :: vvv
3434
real(wp) :: d
3535
type(json_file) :: json
36-
logical :: found
36+
logical(LK) :: found
3737

3838
error_cnt = 0
3939
call json%initialize()
@@ -60,7 +60,7 @@ subroutine test_5(error_cnt)
6060

6161
! print the parsed data to the console:
6262
write(error_unit,'(A)') 'print file...'
63-
call json%print_file(error_unit)
63+
call json%print_file(int(error_unit,IK))
6464
if (json%failed()) then
6565
call json%print_error_message(error_unit)
6666
error_cnt = error_cnt + 1

src/tests/jf_test_07.F90

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module jf_test_7_mod
99

10-
use json_module
10+
use json_module, IK => json_IK
1111
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1212

1313
implicit none
@@ -92,7 +92,7 @@ subroutine test_7(error_cnt)
9292
call json%print_error_message(error_unit)
9393
error_cnt = error_cnt + 1
9494
end if
95-
call json%add(a,'ints', [1,2,3])
95+
call json%add(a,'ints', [1_IK,2_IK,3_IK])
9696
if (json%failed()) then
9797
call json%print_error_message(error_unit)
9898
error_cnt = error_cnt + 1
@@ -118,7 +118,7 @@ subroutine test_7(error_cnt)
118118
call json%print_error_message(error_unit)
119119
error_cnt = error_cnt + 1
120120
end if
121-
call json%add(c,'val1', 1066)
121+
call json%add(c,'val1', 1066_IK)
122122
if (json%failed()) then
123123
call json%print_error_message(error_unit)
124124
error_cnt = error_cnt + 1
@@ -128,7 +128,7 @@ subroutine test_7(error_cnt)
128128
call json%print_error_message(error_unit)
129129
error_cnt = error_cnt + 1
130130
end if
131-
call json%add(d,'val2', 1815)
131+
call json%add(d,'val2', 1815_IK)
132132
if (json%failed()) then
133133
call json%print_error_message(error_unit)
134134
error_cnt = error_cnt + 1
@@ -144,7 +144,7 @@ subroutine test_7(error_cnt)
144144
call json%print_error_message(error_unit)
145145
error_cnt = error_cnt + 1
146146
end if
147-
call json%add(e1,'int1', 1)
147+
call json%add(e1,'int1', 1_IK)
148148
if (json%failed()) then
149149
call json%print_error_message(error_unit)
150150
error_cnt = error_cnt + 1
@@ -154,12 +154,12 @@ subroutine test_7(error_cnt)
154154
call json%print_error_message(error_unit)
155155
error_cnt = error_cnt + 1
156156
end if
157-
call json%add(e2,'int1', 1)
157+
call json%add(e2,'int1', 1_IK)
158158
if (json%failed()) then
159159
call json%print_error_message(error_unit)
160160
error_cnt = error_cnt + 1
161161
end if
162-
call json%add(e2,'int2', 2)
162+
call json%add(e2,'int2', 2_IK)
163163
if (json%failed()) then
164164
call json%print_error_message(error_unit)
165165
error_cnt = error_cnt + 1
@@ -226,7 +226,7 @@ subroutine test_7(error_cnt)
226226
nullify(e2)
227227
nullify(escaped_string)
228228

229-
call json%print(root,output_unit) !print to the console
229+
call json%print(root,int(output_unit,IK)) !print to the console
230230
if (json%failed()) then
231231
call json%print_error_message(error_unit)
232232
error_cnt = error_cnt + 1
@@ -246,7 +246,7 @@ subroutine test_7(error_cnt)
246246

247247
! remove the escaped string entry
248248
if (found) call json%remove(escaped_string,destroy=.true.)
249-
call json%print(root,error_unit) !print to stderr
249+
call json%print(root,int(error_unit,IK)) !print to stderr
250250
if (json%failed()) then
251251
call json%print_error_message(error_unit)
252252
error_cnt = error_cnt + 1

src/tests/jf_test_08.F90

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
module jf_test_8_mod
99

10-
use json_module
10+
use json_module, IK => json_IK
1111
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1212

1313
implicit none
@@ -63,7 +63,7 @@ subroutine test_8(error_cnt)
6363
error_cnt = error_cnt + 1
6464
end if
6565
write(output_unit,'(A)') '{ "part a" : '
66-
call json%print(p,output_unit) ! print to console
66+
call json%print(p,int(output_unit,IK)) ! print to console
6767
write(output_unit,'(A)') ','
6868
if (json%failed()) then
6969
call json%print_error_message(error_unit)
@@ -86,7 +86,7 @@ subroutine test_8(error_cnt)
8686
error_cnt = error_cnt + 1
8787
end if
8888
write(output_unit,'(A)') '"part b" : '
89-
call json%print(p,output_unit) ! print to console
89+
call json%print(p,int(output_unit,IK)) ! print to console
9090
write(output_unit,'(A)') ','
9191
if (json%failed()) then
9292
call json%print_error_message(error_unit)
@@ -111,7 +111,7 @@ subroutine test_8(error_cnt)
111111
error_cnt = error_cnt + 1
112112
end if
113113
write(output_unit,'(A)') '"part c" : '
114-
call json%print(p,output_unit) ! print to console
114+
call json%print(p,int(output_unit,IK)) ! print to console
115115
write(output_unit,'(A)') '}'
116116
if (json%failed()) then
117117
call json%print_error_message(error_unit)

0 commit comments

Comments
 (0)