Skip to content

Commit 7d7669a

Browse files
committed
fixed a unit test and minor documentation updates.
1 parent 1d87463 commit 7d7669a

File tree

2 files changed

+63
-59
lines changed

2 files changed

+63
-59
lines changed

src/json_value_module.F90

Lines changed: 58 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ module json_value_module
9292
!>
9393
! Type used to construct the linked-list JSON structure.
9494
! Normally, this should always be a pointer variable.
95+
! This type should only be used by an instance of [[json_core]].
9596
!
9697
!# Example
9798
!
@@ -178,27 +179,34 @@ module json_value_module
178179

179180
integer(IK) :: spaces_per_tab = 2 !! number of spaces for indenting
180181

181-
logical(LK) :: compact_real = .true. !! to use the "compact" form of real numbers for output
182-
character(kind=CDK,len=:),allocatable :: real_fmt !! the format string to use for real numbers
183-
!! it is set in [[json_initialize]]
184-
185-
logical(LK) :: is_verbose = .false. !! if true, all exceptions are immediately printed to console
186-
logical(LK) :: exception_thrown = .true. !! the error flag (by default, this is true to
187-
!! make sure that [[json_initialize]] is called.
182+
logical(LK) :: compact_real = .true. !! to use the "compact" form of real
183+
!! numbers for output
184+
character(kind=CDK,len=:),allocatable :: real_fmt !! the format string to use
185+
!! for real numbers. it is
186+
!! set in [[json_initialize]]
187+
188+
logical(LK) :: is_verbose = .false. !! if true, all exceptions are
189+
!! immediately printed to console
190+
logical(LK) :: exception_thrown = .true. !! the error flag (by default,
191+
!! this is true to make sure that
192+
!! [[json_initialize]] is called so
193+
!! that the `real_fmt` can be set.
188194
character(kind=CK,len=:),allocatable :: err_message !! the error message
189195

190196
integer(IK) :: char_count = 0 !! character position in the current line
191197
integer(IK) :: line_count = 1 !! lines read counter
192198
integer(IK) :: pushed_index = 0 !! used when parsing lines in file
193-
character(kind=CK,len=pushed_char_size) :: pushed_char = '' !! used when parsing lines in file
199+
character(kind=CK,len=pushed_char_size) :: pushed_char = '' !! used when parsing
200+
!! lines in file
194201

195202
integer(IK) :: ipos = 1 !! for allocatable strings: next character to read
196203

197204
contains
198205

199206
private
200207

201-
generic,public :: get_child => json_value_get_by_index, MAYBEWRAP(json_value_get_by_name_chars)
208+
generic,public :: get_child => json_value_get_by_index, &
209+
MAYBEWRAP(json_value_get_by_name_chars)
202210
procedure,private :: json_value_get_by_index
203211
procedure,private :: MAYBEWRAP(json_value_get_by_name_chars)
204212

@@ -214,10 +222,10 @@ module json_value_module
214222
MAYBEWRAP(json_value_add_string), &
215223
MAYBEWRAP(json_value_add_string_vec)
216224
#ifdef USE_UCS4
217-
generic,public :: add => json_value_add_string_name_ascii, &
218-
json_value_add_string_val_ascii, &
219-
json_value_add_string_vec_name_ascii, &
220-
json_value_add_string_vec_val_ascii
225+
generic,public :: add => json_value_add_string_name_ascii, &
226+
json_value_add_string_val_ascii, &
227+
json_value_add_string_vec_name_ascii, &
228+
json_value_add_string_vec_val_ascii
221229
#endif
222230

223231
procedure,private :: json_value_add_member
@@ -237,8 +245,8 @@ module json_value_module
237245
#endif
238246

239247
!>
240-
! These are like [[json_add]], except if a child with the same name is
241-
! already present, then its value is simply updated.
248+
! These are like the `add` methods, except if a child with the
249+
! same name is already present, then its value is simply updated.
242250
! Note that currently, these only work for scalar variables.
243251
! These routines can also change the variable's type (but an error will be
244252
! thrown if the existing variable is not a scalar).
@@ -251,8 +259,8 @@ module json_value_module
251259
MAYBEWRAP(json_update_integer),&
252260
MAYBEWRAP(json_update_string)
253261
#ifdef USE_UCS4
254-
generic,public :: update => json_update_string_name_ascii,&
255-
json_update_string_val_ascii
262+
generic,public :: update => json_update_string_name_ascii,&
263+
json_update_string_val_ascii
256264
#endif
257265
procedure,private :: MAYBEWRAP(json_update_logical)
258266
procedure,private :: MAYBEWRAP(json_update_double)
@@ -306,8 +314,8 @@ module json_value_module
306314
! !...
307315
! call json%print(p,'test.json') !this is [[json_print_2]]
308316
!````
309-
generic,public :: print => json_value_print,json_print_1,json_print_2
310-
procedure :: json_value_print,json_print_1,json_print_2
317+
generic,public :: print => json_print_1,json_print_2
318+
procedure :: json_print_1,json_print_2
311319

312320
!>
313321
! Destructor routine for a [[json_value]] pointer.
@@ -497,6 +505,7 @@ module json_value_module
497505
procedure,public :: print_error_message => json_print_error_message !! simply routine to print error messages
498506

499507
!other private routines:
508+
procedure :: json_value_print
500509
procedure :: string_to_integer
501510
procedure :: string_to_double
502511
procedure :: unescape_string
@@ -907,7 +916,7 @@ end subroutine wrap_json_throw_exception
907916
! date: 12/4/2013
908917
!
909918
! Retrieve error code from the [[json_core]].
910-
! This should be called after [[json_parse]] to check for errors.
919+
! This should be called after `parse` to check for errors.
911920
! If an error is thrown, before using the class again, [[json_initialize]]
912921
! should be called to clean up before it is used again.
913922
!
@@ -2322,7 +2331,7 @@ subroutine json_value_to_string(json,me,str)
23222331
character(kind=CK,len=:),intent(out),allocatable :: str !! prints structure to this string
23232332

23242333
str = ''
2325-
call json%print(me, iunit=unit2str, str=str, indent=1, colon=.true.)
2334+
call json%json_value_print(me, iunit=unit2str, str=str, indent=1, colon=.true.)
23262335

23272336
end subroutine json_value_to_string
23282337
!*****************************************************************************************
@@ -2344,7 +2353,7 @@ subroutine json_print_1(json,me,iunit)
23442353
character(kind=CK,len=:),allocatable :: dummy
23452354

23462355
if (iunit/=unit2str) then
2347-
call json%print(me,iunit,str=dummy, indent=1, colon=.true.)
2356+
call json%json_value_print(me,iunit,str=dummy, indent=1, colon=.true.)
23482357
else
23492358
call json%throw_exception('Error in json_print_1: iunit must not be -1.')
23502359
end if
@@ -2385,8 +2394,7 @@ end subroutine json_print_2
23852394
! Print the JSON structure to a string or a file.
23862395
!
23872396
!# Notes
2388-
! * This is an internal routine called by the wrapper routines
2389-
! [[json_print]] and [[json_value_to_string]].
2397+
! * This is an internal routine called by the various wrapper routines.
23902398
! * The reason the str argument is non-optional is because of a
23912399
! bug in v4.9 of the gfortran compiler.
23922400

@@ -2489,7 +2497,7 @@ recursive subroutine json_value_print(json,me,iunit,str,indent,need_comma,colon,
24892497
end if
24902498

24912499
! recursive print of the element
2492-
call json%print(element, iunit=iunit, indent=tab + 1, &
2500+
call json%json_value_print(element, iunit=iunit, indent=tab + 1, &
24932501
need_comma=i<count, colon=.true., str=str)
24942502

24952503
! get the next child the list:
@@ -2521,7 +2529,7 @@ recursive subroutine json_value_print(json,me,iunit,str,indent,need_comma,colon,
25212529
do i = 1, count
25222530

25232531
! recursive print of the element
2524-
call json%print(element, iunit=iunit, indent=tab,&
2532+
call json%json_value_print(element, iunit=iunit, indent=tab,&
25252533
need_comma=i<count, is_array_element=.true., str=str)
25262534

25272535
! get the next child the list:
@@ -2662,7 +2670,7 @@ end subroutine json_value_print
26622670
!
26632671
! Thus, if any of these characters are present in the name key,
26642672
! this routine cannot be used to get the value.
2665-
! In that case, the [[json_get_child]] routines would need to be used.
2673+
! In that case, the `get_child` methods would need to be used.
26662674

26672675
subroutine json_get_by_path(json, me, path, p, found)
26682676

@@ -3945,7 +3953,7 @@ end subroutine wrap_json_get_string_vec_with_path
39453953
! for each element in the array.
39463954
!
39473955
!@note For integer, double, logical, and character arrays,
3948-
! higher-level routines are provided (see [[json_get]]), so
3956+
! higher-level routines are provided (see `get` methods), so
39493957
! this routine does not have to be used for those cases.
39503958

39513959
subroutine json_get_array(json, me, array_callback)
@@ -4109,8 +4117,9 @@ end subroutine wrap_json_get_array_with_path
41094117
!# Example
41104118
!
41114119
!````fortran
4120+
! type(json_core) :: json
41124121
! type(json_value),pointer :: p
4113-
! call json_parse(file='myfile.json', p=p)
4122+
! call json%parse(file='myfile.json', p=p)
41144123
!````
41154124
!
41164125
!# History
@@ -4241,7 +4250,7 @@ end subroutine json_parse_string
42414250

42424251
!*****************************************************************************************
42434252
!>
4244-
! Alternate version of [[json_parse_string]], where "str" is kind=CDK.
4253+
! Alternate version of [[json_parse_string]], where `str` is kind=CDK.
42454254

42464255
subroutine wrap_json_parse_string(json, p, str)
42474256

@@ -4547,7 +4556,7 @@ end subroutine json_value_create_logical
45474556
!*****************************************************************************************
45484557
!> author: Izaak Beekman
45494558
!
4550-
! Wrapper for [[json_value_create_logical]] so [[json_create_logical]] can
4559+
! Wrapper for [[json_value_create_logical]] so `create_logical` method can
45514560
! be called with name of character kind 'DEFAULT' or 'ISO_10646'
45524561

45534562
subroutine wrap_json_value_create_logical(json,me,val,name)
@@ -4594,9 +4603,9 @@ end subroutine json_value_create_integer
45944603
!*****************************************************************************************
45954604
!> author: Izaak Beekman
45964605
!
4597-
! A wrapper procedure for [[json_value_create_integer]] so that [[json_create_integer]]
4598-
! may be called with either a 'DEFAULT' or 'ISO_10646' character kind 'name'
4599-
! actual argument.
4606+
! A wrapper procedure for [[json_value_create_integer]] so that `create_integer`
4607+
! method may be called with either a 'DEFAULT' or 'ISO_10646' character kind
4608+
! `name` actual argument.
46004609

46014610
subroutine wrap_json_value_create_integer(json,me,val,name)
46024611

@@ -4642,9 +4651,9 @@ end subroutine json_value_create_double
46424651
!*****************************************************************************************
46434652
!> author: Izaak Beekman
46444653
!
4645-
! A wrapper for [[json_value_create_double]] so that [[json_create_double]] may be
4646-
! called with an actual argument corresponding to the dummy argument, 'name'
4647-
! that may be of 'DEFAULT' or 'ISO_10646' character kind.
4654+
! A wrapper for [[json_value_create_double]] so that `create_double` method
4655+
! may be called with an actual argument corresponding to the dummy argument,
4656+
! `name` that may be of 'DEFAULT' or 'ISO_10646' character kind.
46484657

46494658
subroutine wrap_json_value_create_double(json,me,val,name)
46504659

@@ -4690,9 +4699,9 @@ end subroutine json_value_create_string
46904699
!*****************************************************************************************
46914700
!> author: Izaak Beekman
46924701
!
4693-
! Wrap [[json_value_create_string]] so that [[json_create_string]] may be called with actual
4694-
! character string arguments for 'name' and 'val' that are BOTH of 'DEFAULT' or
4695-
! 'ISO_10646' character kind.
4702+
! Wrap [[json_value_create_string]] so that `create_string` method may be called
4703+
! with actual character string arguments for `name` and `val` that are BOTH of
4704+
! 'DEFAULT' or 'ISO_10646' character kind.
46964705

46974706
subroutine wrap_json_value_create_string(json,me,val,name)
46984707

@@ -4737,9 +4746,9 @@ end subroutine json_value_create_null
47374746
!*****************************************************************************************
47384747
!> author: Izaak Beekman
47394748
!
4740-
! Wrap [[json_value_create_null]] so that [[json_create_null]] may be called with an actual
4741-
! argument corresponding to the dummy argument 'name' that is either of 'DEFAULT' or
4742-
! 'ISO_10646' character kind.
4749+
! Wrap [[json_value_create_null]] so that `create_null` method may be called with
4750+
! an actual argument corresponding to the dummy argument `name` that is either
4751+
! of 'DEFAULT' or 'ISO_10646' character kind.
47434752

47444753
subroutine wrap_json_value_create_null(json,me,name)
47454754

@@ -4786,9 +4795,9 @@ end subroutine json_value_create_object
47864795
!*****************************************************************************************
47874796
!> author: Izaak Beekman
47884797
!
4789-
! Wrap [[json_value_create_object]] so that [[json_create_object]] may be called with an actual
4790-
! argument corresponding to the dummy argument 'name' that is of either 'DEFAULT' or
4791-
! 'ISO_10646' character kind.
4798+
! Wrap [[json_value_create_object]] so that `create_object` method may be called
4799+
! with an actual argument corresponding to the dummy argument `name` that is of
4800+
! either 'DEFAULT' or 'ISO_10646' character kind.
47924801

47934802
subroutine wrap_json_value_create_object(json,me,name)
47944803

@@ -4832,9 +4841,9 @@ end subroutine json_value_create_array
48324841
!*****************************************************************************************
48334842
!> author: Izaak Beekman
48344843
!
4835-
! A wrapper for [[json_value_create_array]] so that [[json_create_array]] may be called with
4836-
! an actual argument, corresponding to the dummy argument 'name', that is either of
4837-
! 'DEFAULT' or 'ISO_10646' character kind.
4844+
! A wrapper for [[json_value_create_array]] so that `create_array` method may be
4845+
! called with an actual argument, corresponding to the dummy argument `name`,
4846+
! that is either of 'DEFAULT' or 'ISO_10646' character kind.
48384847

48394848
subroutine wrap_json_value_create_array(json,me,name)
48404849

src/tests/jf_test_11.F90

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ subroutine test_11(error_cnt)
3434
# endif
3535

3636
error_cnt = 0
37-
!call json_initialize()
38-
!if (json_failed()) then
39-
! call json_print_error_message(error_unit)
40-
! error_cnt = error_cnt + 1
41-
!end if
4237

4338
write(error_unit,'(A)') ''
4439
write(error_unit,'(A)') '================================='
@@ -156,13 +151,13 @@ subroutine test_11(error_cnt)
156151
write(error_unit,'(A)') ''
157152
write(error_unit,'(A)') 'destroy...'
158153
call json%destroy()
159-
if (json_failed()) then
160-
call json_print_error_message(error_unit)
154+
if (json%failed()) then
155+
call json%print_error_message(error_unit)
161156
error_cnt = error_cnt + 1
162157
end if
163158
call clone%destroy()
164-
if (json_failed()) then
165-
call json_print_error_message(error_unit)
159+
if (clone%failed()) then
160+
call clone%print_error_message(error_unit)
166161
error_cnt = error_cnt + 1
167162
end if
168163

@@ -291,6 +286,6 @@ program jf_test_11
291286
n_errors = 0
292287
call test_11(n_errors)
293288
if (n_errors /= 0) stop 1
294-
289+
295290
end program jf_test_11
296291
!*****************************************************************************************

0 commit comments

Comments
 (0)