json_get_integer Subroutine

private subroutine json_get_integer(json, me, value)

Get an integer value from a json_value.

Arguments

Type IntentOptional AttributesName
class(json_core), intent(inout) :: json
type(json_value), intent(in), pointer:: me
integer(kind=IK), intent(out) :: value

the integer value


Calls

proc~~json_get_integer~~CallsGraph proc~json_get_integer json_get_integer proc~string_to_integer string_to_integer proc~json_get_integer->proc~string_to_integer

Contents

Source Code


Source Code

    subroutine json_get_integer(json, me, value)

    implicit none

    class(json_core),intent(inout)      :: json
    type(json_value),pointer,intent(in) :: me
    integer(IK),intent(out)             :: value  !! the integer value

    logical(LK) :: status_ok !! for [[string_to_integer]]

    value = 0_IK
    if ( json%exception_thrown ) return

    if (me%var_type == json_integer) then
        value = me%int_value
    else
        if (json%strict_type_checking) then
            if (allocated(me%name)) then
                call json%throw_exception('Error in json_get_integer:'//&
                    ' Unable to resolve value to integer: '//me%name)
            else
                call json%throw_exception('Error in json_get_integer:'//&
                    ' Unable to resolve value to integer')
            end if
        else
            !type conversions
            select case(me%var_type)
            case (json_real)
                value = int(me%dbl_value, IK)
            case (json_logical)
                if (me%log_value) then
                    value = 1_IK
                else
                    value = 0_IK
                end if
            case (json_string)
                call string_to_integer(me%str_value,value,status_ok)
                if (.not. status_ok) then
                    value = 0_IK
                    if (allocated(me%name)) then
                        call json%throw_exception('Error in json_get_integer:'//&
                            ' Unable to convert string value to integer: '//&
                            me%name//' = '//trim(me%str_value))
                    else
                        call json%throw_exception('Error in json_get_integer:'//&
                            ' Unable to convert string value to integer: '//&
                            trim(me%str_value))
                    end if
                end if
            case default
                if (allocated(me%name)) then
                    call json%throw_exception('Error in json_get_integer:'//&
                        ' Unable to resolve value to integer: '//me%name)
                else
                    call json%throw_exception('Error in json_get_integer:'//&
                        ' Unable to resolve value to integer')
                end if
            end select
        end if
    end if

    end subroutine json_get_integer