get_integer Subroutine

private subroutine get_integer(this, path, value)

Arguments

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

Contents

Source Code


Source Code

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

    type(fson_value), pointer :: this, p
    character(len=*), optional :: path
    integer :: 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
    else if (p % value_type == TYPE_REAL) then
       value = p % value_real
    else if (p % value_type == TYPE_LOGICAL) then
       if (p % value_logical) then
          value = 1
       else
          value = 0
       end if
    else
       print *, "Unable to resolve value to integer: ", path
       call exit(1)
    end if

  end subroutine get_integer