Skip to content

Commit 63abab4

Browse files
committed
updates for new multiple-file version.
1 parent 81a3452 commit 63abab4

18 files changed

+109
-86
lines changed

src/json_file_module.F90

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

99
use,intrinsic :: iso_fortran_env
10-
use json_value_module
1110
use json_kinds
1211
use json_string_utilities
12+
use json_value_module
1313

1414
implicit none
1515

@@ -179,7 +179,7 @@ subroutine json_file_destroy(me)
179179

180180
class(json_file),intent(inout) :: me
181181

182-
if (associated(me%p)) call json_value_destroy(me%p)
182+
if (associated(me%p)) call json_destroy(me%p)
183183

184184
end subroutine json_file_destroy
185185
!*****************************************************************************************
@@ -298,9 +298,10 @@ subroutine json_file_print_to_console(me)
298298

299299
class(json_file),intent(inout) :: me
300300

301-
character(kind=CK,len=:),allocatable :: dummy
301+
!character(kind=CK,len=:),allocatable :: dummy
302302

303-
call json_value_print(me%p,iunit=output_unit,str=dummy,indent=1,colon=.true.)
303+
!call json_value_print(me%p,iunit=output_unit,str=dummy,indent=1,colon=.true.)
304+
call json_print(me%p,iunit=output_unit)
304305

305306
end subroutine json_file_print_to_console
306307
!*****************************************************************************************
@@ -318,12 +319,13 @@ subroutine json_file_print_1(me, iunit)
318319
class(json_file),intent(inout) :: me
319320
integer(IK),intent(in) :: iunit !! file unit number (must not be -1)
320321

321-
integer(IK) :: i
322-
character(kind=CK,len=:),allocatable :: dummy
322+
!integer(IK) :: i
323+
!character(kind=CK,len=:),allocatable :: dummy
323324

324325
if (iunit/=unit2str) then
325-
i = iunit
326-
call json_value_print(me%p,iunit=i,str=dummy,indent=1,colon=.true.)
326+
!i = iunit
327+
!call json_value_print(me%p,iunit=i,str=dummy,indent=1,colon=.true.)
328+
call json_print(me%p,iunit=iunit)
327329
else
328330
call throw_exception('Error in json_file_print_1: iunit must not be -1.')
329331
end if
@@ -358,6 +360,8 @@ subroutine json_file_print_2(me,filename)
358360

359361
integer(IK) :: iunit,istat
360362

363+
!...note: why not just call [[json_print_2]] here?
364+
361365
open(newunit=iunit,file=filename,status='REPLACE',iostat=istat FILE_ENCODING )
362366
if (istat==0) then
363367
call me%print_file(iunit) !call the other routine
@@ -393,7 +397,7 @@ subroutine json_file_print_to_string(me,str)
393397
class(json_file),intent(inout) :: me
394398
character(kind=CK,len=:),allocatable,intent(out) :: str !! string to print JSON data to
395399

396-
call json_value_to_string(me%p,str)
400+
call json_print_to_string(me%p,str)
397401

398402
end subroutine json_file_print_to_string
399403
!*****************************************************************************************

src/json_kinds.F90

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
!*****************************************************************************************
2-
!>
2+
!> author: Jacob Williams
3+
! license: BSD
4+
!
35
! JSON-Fortran kind definitions.
46
!
57
!@note ```-DUSE_UCS4``` is an optional preprocessor flag.

src/json_string_utilities.F90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
!*****************************************************************************************
2-
!>
2+
!> author: Jacob Williams
3+
! license: BSD
4+
!
35
! JSON-Fortran support module for string manipulation.
6+
! This is a low-level module not meant to be used by a JSON-Fortran user.
47

58
module json_string_utilities
69

src/json_value_module.F90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ end subroutine traverse_callback_func
579579
public :: json_print_error_message !
580580

581581
!... so it can be used in json_file_module ...
582-
public :: json_value_print
582+
!public :: json_value_print
583+
public :: throw_exception
583584

584585
character(kind=CDK,len=*),parameter,public :: json_ext = '.json' !! JSON file extension
585586

@@ -770,11 +771,10 @@ recursive subroutine json_value_clone_func(from,to,parent,previous,next,children
770771
end subroutine json_value_clone_func
771772
!*****************************************************************************************
772773

773-
774774
!*****************************************************************************************
775775
!> author: Jacob Williams
776776
!
777-
! Destroy the data within a [[json_value]], and rest type to `json_unknown`.
777+
! Destroy the data within a [[json_value]], and reset type to `json_unknown`.
778778

779779
subroutine destroy_json_data(d)
780780

src/tests/jf_test_1.f90

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

88
module jf_test_1_mod
99

10+
use json_kinds
1011
use json_module
1112
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1213

@@ -249,13 +250,13 @@ end module jf_test_1_mod
249250
program jf_test_1
250251

251252
!! First unit test.
252-
253+
253254
use jf_test_1_mod , only: test_1
254255
implicit none
255256
integer :: n_errors
256257
n_errors = 0
257258
call test_1(n_errors)
258259
if (n_errors /= 0) stop 1
259-
260+
260261
end program jf_test_1
261-
!*****************************************************************************************
262+
!*****************************************************************************************

src/tests/jf_test_10.f90

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
module jf_test_10_mod
88

9+
use json_kinds
910
use json_module
1011
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1112

src/tests/jf_test_11.F90

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

77
module jf_test_11_mod
88

9+
use json_kinds
910
use json_module
1011
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1112

@@ -283,12 +284,12 @@ end module jf_test_11_mod
283284
program jf_test_11
284285

285286
!! 11th unit test.
286-
287+
287288
use jf_test_11_mod , only: test_11
288289
implicit none
289290
integer :: n_errors
290291
n_errors = 0
291292
call test_11(n_errors)
292293
if (n_errors /= 0) stop 1
293294
end program jf_test_11
294-
!*****************************************************************************************
295+
!*****************************************************************************************

src/tests/jf_test_12.f90

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

77
module jf_test_12_mod
88

9+
use json_kinds
910
use json_module
1011
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit, wp => real64
1112

@@ -18,13 +19,13 @@ module jf_test_12_mod
1819
contains
1920

2021
subroutine test_12(error_cnt)
21-
22+
2223
implicit none
2324

2425
integer,intent(out) :: error_cnt !! report number of errors to caller
2526

2627
integer,parameter :: imx = 5, jmx = 3, kmx = 4 !! dimensions for raw work array of primitive type
27-
28+
2829
integer,dimension(3) :: shape !! shape of work array
2930
integer, dimension(:), allocatable :: fetched_shape !! retrieved shape
3031
type(json_value), pointer :: root, meta_array !! json nodes to work with
@@ -171,7 +172,7 @@ subroutine test_12(error_cnt)
171172
close(lun)
172173

173174
contains
174-
175+
175176
subroutine check_errors(assertion)
176177
logical, optional, intent(in) :: assertion
177178
if (json_failed()) then
@@ -206,13 +207,13 @@ end module jf_test_12_mod
206207
program jf_test_12
207208

208209
!! 12th unit test.
209-
210+
210211
use jf_test_12_mod, only: test_12
211212
implicit none
212213
integer :: n_errors
213214
n_errors = 0
214215
call test_12(n_errors)
215216
if ( n_errors /= 0) stop 1
216-
217+
217218
end program jf_test_12
218219
!*****************************************************************************************

src/tests/jf_test_13.f90

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
module jf_test_13_mod
88

9+
use json_kinds
910
use json_module
1011
use, intrinsic :: iso_fortran_env , only: error_unit, output_unit
1112

@@ -14,17 +15,17 @@ module jf_test_13_mod
1415
contains
1516

1617
subroutine test_13(error_cnt)
17-
18+
1819
!! Tests different real format strings using repeated calls to [[json_initialize]].
19-
20+
2021
implicit none
2122

2223
integer,intent(out) :: error_cnt !! report number of errors to caller
23-
24+
2425
type(json_file) :: my_file
2526
character(kind=CK,len=:),allocatable :: str
2627
integer :: i
27-
28+
2829
character(len=2),dimension(5),parameter :: fmts=['g ','e ','en','es','* ']
2930
!! format statements to test
3031

@@ -35,11 +36,11 @@ subroutine test_13(error_cnt)
3536
write(error_unit,'(A)') ''
3637

3738
error_cnt = 0
38-
39+
3940
do i=1,size(fmts)
40-
41+
4142
call json_initialize(real_format=trim(fmts(i)))
42-
43+
4344
call my_file%load_from_string('{ "value": 1234.56789 }')
4445
if (json_failed()) then
4546
call json_print_error_message(error_unit)
@@ -52,11 +53,11 @@ subroutine test_13(error_cnt)
5253
else
5354
write(output_unit,'(A)') str
5455
end if
55-
56+
5657
call my_file%destroy()
57-
58+
5859
end do
59-
60+
6061
end subroutine test_13
6162

6263
end module jf_test_13_mod
@@ -66,12 +67,12 @@ end module jf_test_13_mod
6667
program jf_test_13
6768

6869
!! 13th unit test.
69-
70+
7071
use jf_test_13_mod, only: test_13
7172
implicit none
7273
integer :: n_errors
7374
call test_13(n_errors)
7475
if ( n_errors /= 0) stop 1
75-
76+
7677
end program jf_test_13
7778
!*****************************************************************************************

0 commit comments

Comments
 (0)