to_logical Subroutine

private pure elemental subroutine to_logical(str, val, status_ok)

Convert a string to a logical

  • Evaluates to .true. for strings ['t','true','.true.']
  • Evaluates to .false. for strings ['f','false','.false.']

The string match is not case sensitive.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str
logical, intent(out) :: val
logical, intent(out) :: status_ok

Calls

proc~~to_logical~~CallsGraph proc~to_logical namelist_parser_module::to_logical proc~lowercase_string namelist_parser_module::lowercase_string proc~to_logical->proc~lowercase_string

Called by

proc~~to_logical~~CalledByGraph proc~to_logical namelist_parser_module::to_logical proc~add_variable namelist_parser_module::add_variable proc~add_variable->proc~to_logical proc~parse_namelist namelist_parser_module::parse_namelist proc~parse_namelist->proc~add_variable

Source Code

    pure elemental subroutine to_logical(str,val,status_ok)

    implicit none

    character(len=*),intent(in) :: str
    logical,intent(out) :: val
    logical,intent(out) :: status_ok

    character(len=:),allocatable :: tmp

    ! True and False options (all lowercase):
    character(len=*),dimension(3),parameter :: true_str  = ['t     ',&
                                                            'true  ',&
                                                            '.true.']
    character(len=*),dimension(3),parameter :: false_str = ['f      ',&
                                                            'false  ',&
                                                            '.false.']

    tmp = lowercase_string(str)
    if ( any(tmp==true_str) ) then
        val = .true.
        status_ok = .true.
    else if ( any(tmp==false_str) ) then
        val = .false.
        status_ok = .true.
    else
        val = .false.
        status_ok = .false.
    end if

    end subroutine to_logical