Return the index of the option matching the name passed.
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..
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
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. |
Index of searched section.
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