Read a value as logical.
Accepts true, false, yes, no, on, off, 1 and 0 in any
mixture of cases. A flag always reads back cleanly, since its stored
value is one of the first two.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(cli_t), | intent(in) | :: | this | |||
| character(len=*), | intent(in) | :: | name |
Long name of a declared entry. |
||
| logical, | intent(out) | :: | value |
Parsed value; false when the conversion failed. |
||
| type(error_t), | intent(inout), | optional | :: | err |
Set on an undeclared name or an unrecognised spelling. |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private | :: | i | ||||
| character(len=:), | private, | allocatable | :: | lowered | |||
| type(string_type), | private | :: | text |
subroutine cli_get_logical(this, name, value, err) !! Read a value as `logical`. !! !! Accepts `true`, `false`, `yes`, `no`, `on`, `off`, `1` and `0` in any !! mixture of cases. A flag always reads back cleanly, since its stored !! value is one of the first two. class(cli_t), intent(in) :: this character(len=*), intent(in) :: name !! Long name of a declared entry. logical, intent(out) :: value !! Parsed value; false when the conversion failed. type(error_t), intent(inout), optional :: err !! Set on an undeclared name or an unrecognised spelling. type(string_type) :: text character(len=:), allocatable :: lowered integer(default_int) :: i value = .false. call this%get_string(name, text, err) if (present(err)) then if (err%has_error()) return else if (this%find(name) == 0_default_int) return end if lowered = char(text) do i = 1_default_int, len(lowered, kind=default_int) if (lowered(i:i) >= "A" .and. lowered(i:i) <= "Z") then lowered(i:i) = achar(iachar(lowered(i:i)) + 32) end if end do select case (lowered) case ("true", "yes", "on", "1") value = .true. case ("false", "no", "off", "0", "") value = .false. case default call fail(err, ERROR_PARSE, "pic_cli: "//name//" is not a logical: "//lowered) end select end subroutine cli_get_logical