get_logical Subroutine

private subroutine get_logical(this, path, value)

Arguments

Type IntentOptional AttributesName
type(fson_value), pointer:: this
character(len=*), optional :: path
logical :: value

Contents

Source Code


Source Code

  subroutine get_logical(this, path, value)
    use fson_value_m, only: type_integer, type_logical, fson_value
    implicit none

    type(fson_value), pointer :: this, p
    character(len=*), optional :: path
    logical :: value

    nullify(p)

    if (present(path)) then
       call get_by_path(this=this, path=path, p=p)
    else
       p => this
    end if

    if (.not.associated(p)) then
       print *, "Unable to resolve path: ", path
       call exit(1)
    end if

    if (p % value_type == TYPE_INTEGER) then
       value = (p % value_integer > 0)
    else if (p % value_type == TYPE_LOGICAL) then
       value = p % value_logical
    else
       print *, "Unable to resolve value to logical: ", path
       call exit(1)
    end if

  end subroutine get_logical