json_get_logical Subroutine

private subroutine json_get_logical(json, me, value)

Get a logical value from a json_value.

Note

If strict_type_checking is False, then the following assumptions are made:

  • For integers: a value > 0 is True
  • For reals: a value > 0 is True
  • For strings: ‘true’ is True, and everything else is false. [case sensitive match]

Arguments

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

Contents

Source Code


Source Code

    subroutine json_get_logical(json, me, value)

    implicit none

    class(json_core),intent(inout)      :: json
    type(json_value),pointer,intent(in) :: me
    logical(LK),intent(out)             :: value

    value = .false.
    if ( json%exception_thrown ) return

    if (me%var_type == json_logical) then
        value = me%log_value
    else
        if (json%strict_type_checking) then
            call json%throw_exception('Error in json_get_logical: '//&
                                      'Unable to resolve value to logical: '//&
                                      me%name)
        else
            !type conversions
            select case (me%var_type)
            case (json_integer)
                value = (me%int_value > 0_IK)
            case (json_real)
                value = (me%dbl_value > 0.0_RK)
            case (json_string)
                value = (me%str_value == true_str)
            case default
                call json%throw_exception('Error in json_get_logical: '//&
                                          'Unable to resolve value to logical: '//&
                                          me%name)
            end select
        end if
    end if

    end subroutine json_get_logical