index_option Function

private elemental function index_option(self, option_name, back) result(ind)

Return the index of the option matching the name passed.

Arguments

TypeIntentOptionalAttributesName
class(section), intent(in) :: self

Section data.

character, intent(in) :: option_name

Option name.

logical, intent(in), optional :: back

If back appears with the value true, the last matching index is returned.

Return Value integer(kind=I4P)

Index of searched section.


Contents

Source Code


Source Code

  elemental function index_option(self, option_name, back) result(ind)
  !< Return the index of the option matching the name passed.
  !<
  !< @note The matching index returned is the first found if *back* is not passed or if *back=.false.*. On the contrary the last
  !< found is returned if *back=.true.*.
  class(section), intent(in)           :: self        !< Section data.
  character(*),   intent(in)           :: option_name !< Option name.
  logical,        intent(in), optional :: back        !< If back appears with the value true, the last matching index is returned.
  integer(I4P)                         :: ind         !< Index of searched section.
  logical                              :: backd       !< Dummy back flag.
  integer(I4P)                         :: o           !< Counter.

  ind = 0
  if (allocated(self%options)) then
    backd = .false. ; if (present(back)) backd = back
    if (backd) then
      do o=size(self%options, dim=1), 1,-1
        if (self%options(o) == trim(adjustl(option_name))) then
          ind = o
          exit
        endif
      enddo
    else
      do o=1, size(self%options, dim=1)
        if (self%options(o) == trim(adjustl(option_name))) then
          ind = o
          exit
        endif
      enddo
    endif
  endif
  endfunction index_option