check_choices Subroutine

private 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.

Type Bound

command_line_argument

Arguments

Type IntentOptional 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.


Calls

proc~~check_choices~~CallsGraph proc~check_choices flap_command_line_argument_t::command_line_argument%check_choices cton cton proc~check_choices->cton proc~errored~2 flap_command_line_argument_t::command_line_argument%errored proc~check_choices->proc~errored~2 proc~tokenize flap_utils_m::tokenize proc~check_choices->proc~tokenize str str proc~check_choices->str proc~errored~2->str interface~colorize face::colorize proc~errored~2->interface~colorize proc~print_error_message flap_object_t::object%print_error_message proc~errored~2->proc~print_error_message proc~colorize_default face::colorize_default interface~colorize->proc~colorize_default proc~color_index face::color_index proc~colorize_default->proc~color_index proc~style_index face::style_index proc~colorize_default->proc~style_index proc~upper face::upper proc~colorize_default->proc~upper

Called by

proc~~check_choices~~CalledByGraph proc~check_choices flap_command_line_argument_t::command_line_argument%check_choices proc~get_cla flap_command_line_argument_t::command_line_argument%get_cla proc~get_cla->proc~check_choices proc~get_cla_list_from_buffer flap_command_line_argument_t::command_line_argument%get_cla_list_from_buffer proc~get_cla_list_from_buffer->proc~check_choices none~get flap_command_line_argument_t::command_line_argument%get none~get->proc~get_cla proc~get_cla_list flap_command_line_argument_t::command_line_argument%get_cla_list none~get->proc~get_cla_list proc~get_cla_list->proc~get_cla_list_from_buffer proc~get_cla_list~2 flap_command_line_interface_t::command_line_interface%get_cla_list proc~get_cla_list~2->none~get proc~get_cla~2 flap_command_line_interface_t::command_line_interface%get_cla proc~get_cla~2->none~get none~get~2 flap_command_line_interface_t::command_line_interface%get none~get~2->proc~get_cla_list~2 none~get~2->proc~get_cla~2 proc~fake_call flap_test_group::fake_call proc~fake_call->none~get~2 program~flap_save_man_page flap_save_man_page program~flap_save_man_page->none~get~2 program~flap_save_usage_to_markdown flap_save_usage_to_markdown program~flap_save_usage_to_markdown->none~get~2 program~flap_test_action_store flap_test_action_store program~flap_test_action_store->none~get~2 program~flap_test_ansi_color_style flap_test_ansi_color_style program~flap_test_ansi_color_style->none~get~2 program~flap_test_basic flap_test_basic program~flap_test_basic->none~get~2 program~flap_test_choices_logical flap_test_choices_logical program~flap_test_choices_logical->none~get~2 program~flap_test_duplicated_clas flap_test_duplicated_clas program~flap_test_duplicated_clas->none~get~2 program~flap_test_group_examples flap_test_group_examples program~flap_test_group_examples->none~get~2 program~flap_test_hidden flap_test_hidden program~flap_test_hidden->none~get~2 program~flap_test_ignore_unknown_clas flap_test_ignore_unknown_clas program~flap_test_ignore_unknown_clas->none~get~2 program~flap_test_minimal flap_test_minimal program~flap_test_minimal->none~get~2 program~flap_test_nargs_insufficient flap_test_nargs_insufficient program~flap_test_nargs_insufficient->none~get~2 program~flap_test_nargs_insufficient~2 flap_test_nargs_insufficient program~flap_test_nargs_insufficient~2->none~get~2 program~flap_test_nested flap_test_nested program~flap_test_nested->none~get~2 program~flap_test_string flap_test_string program~flap_test_string->none~get~2 program~flap_test_group flap_test_group program~flap_test_group->proc~fake_call

Source Code

  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