test_5 Subroutine

public subroutine test_5(error_cnt)

Arguments

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

Description

Github issue example: https://github.com/josephalevin/fson/issues/12

Read an existing file and extract some variables.

Calls

proc~~test_5~~CallsGraph proc~test_5 test_5 proc~json_initialize json_initialize proc~test_5->proc~json_initialize proc~json_failed json_failed proc~test_5->proc~json_failed proc~json_print_error_message json_print_error_message proc~test_5->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_5~~CalledByGraph proc~test_5 test_5 program~jf_test_5 jf_test_5 program~jf_test_5->proc~test_5
Help

Variables

TypeVisibility AttributesNameInitial
integer, public :: vv
integer, public, dimension(:), allocatable:: vvv
real(kind=wp), public :: d
type(json_file), public :: json
logical, public :: found

Source Code

    subroutine test_5(error_cnt)

    !! Github issue example: https://github.com/josephalevin/fson/issues/12
    !!
    !! Read an existing file and extract some variables.

    implicit none

    integer,intent(out) :: error_cnt
    integer :: vv
    integer,dimension(:),allocatable :: vvv
    real(wp) :: d
    type(json_file) :: json
    logical :: found

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

    ! parse the json file:
    write(error_unit,'(A)') 'load file...'
    call json%load_file(filename = dir//filename5)
    if (json_failed()) then

        call json_print_error_message(error_unit)
        error_cnt = error_cnt + 1

    else

        ! print the parsed data to the console:
        write(error_unit,'(A)') 'print file...'
        call json%print_file()
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        end if

        ! extract data from the parsed value:
        write(error_unit,'(A)') ''
        write(error_unit,'(A)') 'extract data...'

        write(error_unit,'(A)') '--------------------------'
        call json%get('Correl.ID2', vv, found)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        end if
        if (found) write(error_unit,'(A,I5)') 'vv = ',vv

        call json%get('Correl.ID1', vvv, found)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        end if
        if (found) write(error_unit,'(A,*(I5,1X))') 'vvv= ',vvv

        call json%get('Prior[3].mode', d, found)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        end if
        if (found) write(error_unit,'(A,E30.16)') 'd  = ',d

        write(error_unit,'(A)') ''

    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 subroutine test_5