test_6 Subroutine

public subroutine test_6(error_cnt)

Arguments

Type IntentOptional AttributesName
integer, intent(out) :: error_cnt

Description

This example tries to read an invalid JSON file.

Calls

proc~~test_6~~CallsGraph proc~test_6 test_6 proc~json_initialize json_initialize proc~test_6->proc~json_initialize proc~json_failed json_failed proc~test_6->proc~json_failed proc~json_print_error_message json_print_error_message proc~test_6->proc~json_print_error_message proc~json_clear_exceptions json_clear_exceptions proc~json_initialize->proc~json_clear_exceptions interface~throw_exception throw_exception proc~json_initialize->interface~throw_exception proc~json_print_error_message->proc~json_clear_exceptions proc~json_check_for_errors json_check_for_errors proc~json_print_error_message->proc~json_check_for_errors proc~json_throw_exception json_throw_exception interface~throw_exception->proc~json_throw_exception
Help

Called By

proc~~test_6~~CalledByGraph proc~test_6 test_6 program~jf_test_6 jf_test_6 program~jf_test_6->proc~test_6
Help

Variables

TypeVisibility AttributesNameInitial
type(json_file), public :: json
integer, public :: i
character(len=*), public, parameter, dimension(2):: files =['invalid.json ', 'invalid2.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