Convert a string to a logical
.true.
for strings ['1','t','true','.true.'].false.
for strings ['0','f','false','.false.']The string match is not case sensitive.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | str | |||
logical, | intent(out) | :: | val | |||
logical, | intent(out) | :: | status_ok |
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(4),parameter :: true_str = ['1 ',& 't ',& 'true ',& '.true.'] character(len=*),dimension(4),parameter :: false_str = ['0 ',& '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