This example tries to read an invalid JSON file.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer, | intent(out) | :: | error_cnt |
Nodes of different colours represent the following:
Solid arrows point from a procedure to one which it calls. Dashed arrows point from an interface to procedures which implement that interface. This could include the module procedures in a generic interface or the implementation in a submodule of an interface in a parent module. Where possible, edges connecting nodes are given different colours to make them easier to distinguish in large graphs.
subroutine test_6(error_cnt)
!! This example tries to read an invalid JSON file.
implicit none
integer,intent(out) :: error_cnt
type(json_file) :: json
integer :: i
character(len=*),dimension(2),parameter :: files = ['invalid.json ',&
'invalid2.json']
error_cnt = 0
call json%initialize()
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
end if
write(error_unit,'(A)') ''
write(error_unit,'(A)') '================================='
write(error_unit,'(A)') ' EXAMPLE 6 : invalid JSON files'
write(error_unit,'(A)') '================================='
write(error_unit,'(A)') ''
do i=1,2
! parse the json file:
write(error_unit,'(A)') ''
write(error_unit,'(A)') 'load file: '//trim(files(i))
write(error_unit,'(A)') ''
call json%load_file(filename = dir//trim(files(i)))
if (json%failed()) then
call json%print_error_message(error_unit)
else
write(error_unit,'(A)') 'An error should have been raised!'
error_cnt = error_cnt + 1
end if
! clean up
call json%destroy()
if (json%failed()) then
call json%print_error_message(error_unit)
error_cnt = error_cnt + 1
end if
end do
end subroutine test_6