Skip to content

Commit 2046f29

Browse files
committed
Some API cleanup for consistency.
-added new APIs to replace json_value_create (i.e., json_create_object, etc.). -renamed son_value_get to json_value_get_child. Added additional error checking. -renamed some of the internal routines. In json_value_print, names are not trimmed if they end with spaces (which is allowed in JSON).
1 parent 02851da commit 2046f29

File tree

4 files changed

+382
-148
lines changed

4 files changed

+382
-148
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,17 @@ of pointers. See the json_example.f90 file for more examples.
105105
106106
use json_module
107107
108-
type(json_value),pointer :: p, inp
108+
type(json_value),pointer :: p, inp
109109
logical :: found
110110
111111
! initialize the module
112112
call json_initialize()
113113
114114
! initialize the structure:
115-
call json_value_create(p)
116-
call to_object(p)
115+
call json_create_object(p)
117116
118117
! add an "inputs" object to the structure:
119-
call json_value_create(inp)
120-
call to_object(inp,'inputs')
118+
call json_create_object(inp,'inputs')
121119
call json_value_add(p, inp) !add it to the root
122120
123121
! add some data to inputs:

build.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ else
3939

4040
FCOMPILER='gnu'
4141
FCOMPILERFLAGS='-c -O2 -fbacktrace -Wall -Wextra -Wno-maybe-uninitialized -pedantic -std=f2008'
42+
#FCOMPILERFLAGS='-c -O2 -fbacktrace -fall-intrinsics -Wall -Wextra -Wno-maybe-uninitialized -pedantic -std=f2008'
43+
4244
fi
4345

4446
#build the stand-alone library:

src/json_example.f90

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -252,12 +252,11 @@ subroutine test_4()
252252
write(*,'(A)') ''
253253
write(*,'(A)') 'creating structure'
254254

255-
call json_value_create(p) !create the value and associate the pointer
256-
call to_object(p,dir//filename4) !add the file name as the name of the overall structure
255+
call json_create_object(p,dir//filename4) !create the value and associate the pointer
256+
!add the file name as the name of the overall structure
257257

258258
!config structure:
259-
call json_value_create(inp) !an object
260-
call to_object(inp,'INPUTS')
259+
call json_create_object(inp,'INPUTS') !an object
261260
!add just integers:
262261
do i=1,100
263262
write(istr,fmt='(I10)') i
@@ -320,20 +319,18 @@ subroutine test_2()
320319
write(*,'(A)') ''
321320

322321
!root:
323-
call json_value_create(p) ! create the value and associate the pointer
324-
call to_object(p,dir//filename2) ! add the file name as the name of the overall structure
322+
call json_create_object(p,dir//filename2) ! create the value and associate the pointer
323+
! add the file name as the name of the overall structure
325324

326325
write(*,'(A)') ''
327326
write(*,'(A)') 'initialize the structure...'
328327

329328
!config structure:
330-
call json_value_create(inp) !an object
331-
call to_object(inp,'inputs')
329+
call json_create_object(inp,'inputs') !an object
332330
call json_value_add(p, inp)
333331

334332
!trajectory structure:
335-
call json_value_create(traj) !an array
336-
call to_array(traj,'trajectory')
333+
call json_create_array(traj,'trajectory') !an array
337334
call json_value_add(p, traj)
338335

339336
write(*,'(A)') ''
@@ -395,8 +392,7 @@ subroutine add_variables_to_input(me, variable, units, frame, center, rdata)
395392
nullify(var)
396393

397394
!create the object before data can be added:
398-
call json_value_create(var)
399-
call to_object(var,'') !name does not matter
395+
call json_create_object(var,'') !name does not matter
400396

401397
!variable info:
402398
call json_value_add(var, 'VARIABLE',trim(variable))

0 commit comments

Comments
 (0)