This function parses a string containing the type of smearing and returns the correct index for the smearing_index variable
If the string is not valid, an io_error is issued
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | string | The string read from input |
||
character(len=*), | intent(in) | :: | keyword | The keyword that was read (e.g., smr_type), so that we can print a more useful error message |
function get_smearing_index(string, keyword)
!! This function parses a string containing the type of
!! smearing and returns the correct index for the smearing_index variable
!
!! If the string is not valid, an io_error is issued
use w90_io, only: io_error
character(len=*), intent(in) :: string
!! The string read from input
character(len=*), intent(in) :: keyword
!! The keyword that was read (e.g., smr_type), so that we can print a more useful error message
integer :: get_smearing_index
integer :: pos
get_smearing_index = 0 ! To avoid warnings of unset variables
if (index(string, 'm-v') > 0) then
get_smearing_index = -1
elseif (index(string, 'm-p') > 0) then
pos = index(string, 'm-p')
if (len(trim(string(pos + 3:))) .eq. 0) then
! If the string is only 'm-p', we assume that 'm-p1' was intended
get_smearing_index = 1
else
read (string(pos + 3:), *, err=337) get_smearing_index
if (get_smearing_index < 0) &
call io_error('Wrong m-p smearing order in keyword '//trim(keyword))
end if
elseif (index(string, 'f-d') > 0) then
get_smearing_index = -99
! Some aliases
elseif (index(string, 'cold') > 0) then
get_smearing_index = -1
elseif (index(string, 'gauss') > 0) then
get_smearing_index = 0
! Unrecognised keyword
else
call io_error('Unrecognised value for keyword '//trim(keyword))
end if
return
337 call io_error('Wrong m-p smearing order in keyword '//trim(keyword))
end function get_smearing_index