public subroutine test_6(error_cnt)
Arguments
Type |
Intent | Optional |
Attributes | | Name | |
integer, |
intent(out) |
|
| :: |
error_cnt | |
Description
This example tries to read an invalid JSON file.
Variables
Type | Visibility |
Attributes | | Name | | Initial | |
type(json_file), |
public |
| :: |
json | | | |
integer, |
public |
| :: |
i | | | |
character(len=*), |
public, |
parameter, dimension(2) | :: |
files | = | ['invalid.json ','invalid.json '] | |
Source Code
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