test_3 Subroutine

public subroutine test_3(error_cnt)

Arguments

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

Description

Read the file generated in test_2, and extract some data from it.

Calls

proc~~test_3~~CallsGraph proc~test_3 test_3 proc~json_initialize json_initialize proc~test_3->proc~json_initialize proc~json_failed json_failed proc~test_3->proc~json_failed proc~json_print_error_message json_print_error_message proc~test_3->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_3~~CalledByGraph proc~test_3 test_3 program~jf_test_3 jf_test_3 program~jf_test_3->proc~test_3
Help

Variables

TypeVisibility AttributesNameInitial
integer, public :: ival
character(kind=CK,len=:), public, allocatable:: cval
real(kind=wp), public :: rval
type(json_file), public :: json
integer, public :: i
character(kind=CK,len=10), public :: str
real(kind=wp), public, dimension(:), allocatable:: rvec

Source Code

    subroutine test_3(error_cnt)

    !! Read the file generated in [[test_2]], and extract some data from it.

    implicit none

    integer,intent(out) :: error_cnt
    integer :: ival
    character(kind=CK,len=:),allocatable :: cval
    real(wp) :: rval
    type(json_file) :: json    !the JSON structure read from the file:
    integer :: i
    character(kind=CK,len=10) :: str
    real(wp),dimension(:),allocatable :: rvec

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

    ! parse the json file:
    write(error_unit,'(A)') ''
    write(error_unit,'(A)') 'parsing file: '//dir//filename2

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

    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...'
        !get scalars:
        write(error_unit,'(A)') ''
        call json%get('inputs.integer_scalar', ival)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A,1X,I5)') 'inputs.integer_scalar = ',ival
        end if
        !get one element from a vector:
        write(error_unit,'(A)') ''
        call json%get('trajectory(1).DATA(2)', rval)
        if (json_failed()) then
            call json_print_error_message(error_unit)
            error_cnt = error_cnt + 1
        else
            write(error_unit,'(A,1X,F30.16)') 'trajectory(1).DATA(2) = ',rval
        end if
        !get vectors:
        do i=1,4

            write(str,fmt='(I10)') i
            str = adjustl(str)

            write(error_unit,'(A)') ''
            call json%get('trajectory('//trim(str)//').VARIABLE', cval)
            if (json_failed()) then

                call json_print_error_message(error_unit)
                error_cnt = error_cnt + 1

            else

                write(error_unit,'(A)') 'trajectory('//trim(str)//').VARIABLE = '//trim(cval)

                !...get the vector using the callback method:
                call json%get('trajectory('//trim(str)//').DATA', rvec)
                if (json_failed()) then
                    call json_print_error_message(error_unit)
                    error_cnt = error_cnt + 1
                else
                    write(error_unit,'(A,1X,*(F30.16,1X))') 'trajectory('//trim(str)//').DATA = ',rvec
                end if

            end if

        end do

    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_3