Check if CLA value is in allowed choices.
Note
This procedure can be called if and only if cla%choices has been allocated.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(command_line_argument), | intent(inout) | :: | self |
CLA data. |
||
class(*), | intent(in) | :: | val |
CLA value. |
||
character(len=*), | intent(in), | optional | :: | pref |
Prefixing string. |
subroutine check_choices(self, val, pref) !< Check if CLA value is in allowed choices. !< !< @note This procedure can be called if and only if cla%choices has been allocated. class(command_line_argument), intent(inout) :: self !< CLA data. class(*), intent(in) :: val !< CLA value. character(*), optional, intent(in) :: pref !< Prefixing string. character(len(self%choices)), allocatable :: toks(:) !< Tokens for parsing choices list. integer(I4P) :: Nc !< Number of choices. logical :: val_in !< Flag for checking if val is in the choosen range. character(len=:), allocatable :: val_str !< Value in string form. character(len=:), allocatable :: tmp !< Temporary string for avoiding GNU gfrotran bug. integer(I4P) :: c !< Counter. val_in = .false. val_str = '' tmp = self%choices call tokenize(strin=tmp, delimiter=',', toks=toks, Nt=Nc) select type(val) #if defined _R16P type is(real(R16P)) val_str = str(n=val) do c=1, Nc if (val==cton(str=trim(adjustl(toks(c))), knd=1._R16P)) val_in = .true. enddo #endif type is(real(R8P)) val_str = str(n=val) do c=1, Nc if (val==cton(str=trim(adjustl(toks(c))), knd=1._R8P)) val_in = .true. enddo type is(real(R4P)) val_str = str(n=val) do c=1, Nc if (val==cton(str=trim(adjustl(toks(c))), knd=1._R4P)) val_in = .true. enddo type is(integer(I8P)) val_str = str(n=val) do c=1, Nc if (val==cton(str=trim(adjustl(toks(c))), knd=1_I8P)) val_in = .true. enddo type is(integer(I4P)) val_str = str(n=val) do c=1, Nc if (val==cton(str=trim(adjustl(toks(c))), knd=1_I4P)) val_in = .true. enddo type is(integer(I2P)) val_str = str(n=val) do c=1, Nc if (val==cton(str=trim(adjustl(toks(c))), knd=1_I2P)) val_in = .true. enddo type is(integer(I1P)) val_str = str(n=val) do c=1, Nc if (val==cton(str=trim(adjustl(toks(c))), knd=1_I1P)) val_in = .true. enddo type is(character(*)) val_str = val do c=1, Nc if (val==toks(c)) val_in = .true. enddo type is(logical) call self%errored(pref=pref, error=ERROR_CHOICES_LOGICAL) endselect if (.not.val_in.and.(self%error==0)) then call self%errored(pref=pref, error=ERROR_NOT_IN_CHOICES, val_str=val_str) endif endsubroutine check_choices