index_section Function

private elemental function index_section(self, back, section_name) result(ind)

Return the index of the section matching the name passed.

Arguments

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

File data.

logical, intent(in), optional :: back

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

character, intent(in) :: section_name

Section name.

Return Value integer(kind=I4P)

Index of searched section.


Contents

Source Code


Source Code

  elemental function index_section(self, back, section_name) result(ind)
  !< Return the index of the section 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(file_ini),   intent(IN) :: self         !< File data.
  logical, optional, intent(IN) :: back         !< If back appears with the value true, the last matching index is returned.
  character(*),      intent(IN) :: section_name !< Section name.
  integer(I4P)                  :: ind          !< Index of searched section.
  logical                       :: backd        !< Dummy back flag.
  integer(I4P)                  :: s            !< Counter.

  ind = 0
  if (allocated(self%sections)) then
    backd = .false. ; if (present(back)) backd = back
    if (backd) then
      do s=size(self%sections, dim=1), 1,-1
        if (self%sections(s) == trim(adjustl(section_name))) then
          ind = s
          exit
        endif
      enddo
    else
      do s=1, size(self%sections, dim=1)
        if (self%sections(s) == trim(adjustl(section_name))) then
          ind = s
          exit
        endif
      enddo
    endif
  endif
  endfunction index_section