Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | error_cnt | report number of errors to caller |
Tests the traversal of a JSON structure
It traverses the structure, looks for all "name" variables, and changes the name.
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(json_value), | public, | pointer | :: | json |
subroutine test_14(error_cnt)
!! Tests the traversal of a JSON structure
!!
!! It traverses the structure, looks for all "name" variables, and changes the name.
implicit none
integer,intent(out) :: error_cnt !! report number of errors to caller
type(json_value),pointer :: json
write(error_unit,'(A)') ''
write(error_unit,'(A)') '================================='
write(error_unit,'(A)') ' TEST 14'
write(error_unit,'(A)') '================================='
write(error_unit,'(A)') ''
error_cnt = 0
icount = 0 !number of name changes (should be 2)
call json_initialize() !initialize the module
call json_parse(dir//filename1,json) !read the file
if (json_failed()) then
call json_print_error_message(error_unit)
error_cnt = error_cnt + 1
end if
call json_traverse(json,rename) !traverse all nodes in the structure
if (json_failed()) then
call json_print_error_message(error_unit)
error_cnt = error_cnt + 1
end if
if (icount/=2) then
write(error_unit,'(A)') 'Error: should be 2 "name" variables in this file: '//filename1
error_cnt = error_cnt + 1
end if
if (error_cnt==0) then
write(error_unit,'(A)') ''
write(error_unit,'(A)') ' All names changed to Fred:'
write(error_unit,'(A)') ''
call json_print(json,output_unit)
write(error_unit,'(A)') ''
end if
call json_destroy(json) !clean up
if (json_failed()) then
call json_print_error_message(error_unit)
error_cnt = error_cnt + 1
end if
end subroutine test_14