test_11 Subroutine

public subroutine test_11(error_cnt)

Arguments

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

Description

Read the file and extract some data from it.

Calls

proc~~test_11~~CallsGraph proc~test_11 test_11 proc~json_initialize json_initialize proc~test_11->proc~json_initialize proc~json_failed json_failed proc~test_11->proc~json_failed proc~json_print_error_message json_print_error_message proc~test_11->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_11~~CalledByGraph proc~test_11 test_11 program~jf_test_11 jf_test_11 program~jf_test_11->proc~test_11
Help

Variables

TypeVisibility AttributesNameInitial
character(kind=CK,len=:), public, allocatable:: cval
type(json_file), public :: json

Source Code

    subroutine test_11(error_cnt)

    !! Read the file and extract some data from it.

    implicit none

    integer,intent(out) :: error_cnt
    character(kind=CK,len=:),allocatable :: cval
    type(json_file) :: json    !the JSON structure read from the file:
# ifdef USE_UCS4
    type(json_file) :: clone
# endif

    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 11'
    write(error_unit,'(A)') '================================='
    write(error_unit,'(A)') ''

# ifdef USE_UCS4
    ! parse the json file:
    write(error_unit,'(A)') ''
    write(error_unit,'(A)') 'parsing file: '//dir//unicode_file

    call json%load_file(filename = dir//unicode_file)

    if (json_failed()) then    !if there was an error reading the file

        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1

    else

        write(error_unit,'(A)') ''
        write(error_unit,'(A)') 'reading data from file...'

        write(error_unit,'(A)') ''
        call json%get('UCS4 support?', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'UCS4 support? '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Amharic', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Amharic : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Portuguese', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Portuguese : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Russian', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Russian : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Hebrew', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Hebrew : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Urdu', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Urdu : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%print_to_string(cval)
        if (json_failed()) then
           call json_print_error_message(error_unit)
           error_cnt = error_cnt + 1
        else
           write(error_unit,'(A)') 'The contents of the file were:'
           write(error_unit,'(A)') cval
        end if

        write(error_unit,'(A)') ''
        call clone%load_from_string(cval)
        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)') 'Printing same file, but now to stdout:'
        call clone%print_file(output_unit)
        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)') 'Writing json file object to "../files/'//unicode_file//'"'
        call clone%print_file('../files/'//unicode_file)
        if ( json_failed() ) then
           call json_print_error_message(error_unit)
           error_cnt = error_cnt + 1
        end if

    end if

    ! clean up
    write(error_unit,'(A)') ''
    write(error_unit,'(A)') 'destroy...'
    call json%destroy()
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if
    call clone%destroy()
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

# endif
    ! parse the json file:
    write(error_unit,'(A)') ''
    write(error_unit,'(A)') 'parsing file: '//dir//ascii_equivalent
    write(error_unit,'(A)') 'This is the ascii equivalent of "../files/inputs/hello-world-ucs4.json"'

    call json%load_file(filename = dir//ascii_equivalent)

    if (json_failed()) then    !if there was an error reading the file

        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1

    else

        write(error_unit,'(A)') ''
        write(error_unit,'(A)') 'reading data from file...'

        write(error_unit,'(A)') ''
        call json%get('UCS4 support?', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'UCS4 support? '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Amharic', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Amharic : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Portuguese', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Portuguese : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Russian', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Russian : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Hebrew', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Hebrew : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%get('hello world.Urdu', cval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A)') 'hello world.Urdu : '//cval
        end if

        write(error_unit,'(A)') ''
        call json%print_to_string(cval)
        if (json_failed()) then
           call json_print_error_message(error_unit)
           error_cnt = error_cnt + 1
        else
           write(error_unit,'(A)') 'The contents of the file were:'
           write(error_unit,'(A)') cval
        end if

        write(error_unit,'(A)') ''
        write(error_unit,'(A)') 'Printing same file, but now to stdout:'
        call json%print_file(output_unit)
        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)') 'Writing json file object to "../files/'//ascii_equivalent//'"'
        call json%print_file('../files/'//ascii_equivalent)
        if ( json_failed() ) then
           call json_print_error_message(error_unit)
           error_cnt = error_cnt + 1
        end if

    end if

    ! clean up
    write(error_unit,'(A)') ''
    write(error_unit,'(A)') 'destroy...'
    call json%destroy()
    if (json_failed()) then
        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1
    end if

    end subroutine test_11