glob_character Subroutine

private subroutine glob_character(self, pattern, list)

Type Bound

string

Arguments

Type IntentOptional Attributes Name
class(string), intent(in) :: self
character(len=*), intent(in) :: pattern
character(len=:), intent(out), allocatable :: list(:)

Calls

proc~~glob_character~~CallsGraph proc~glob_character string%glob_character none~glob string%glob proc~glob_character->none~glob proc~chars string%chars proc~glob_character->proc~chars none~glob->proc~glob_character proc~glob_string string%glob_string none~glob->proc~glob_string proc~read_file string%read_file proc~glob_string->proc~read_file proc~split string%split proc~glob_string->proc~split proc~tempname string%tempname proc~glob_string->proc~tempname proc~read_file->proc~chars proc~read_lines string%read_lines proc~read_file->proc~read_lines proc~upper~2 string%upper proc~read_file->proc~upper~2 proc~partition string%partition proc~split->proc~partition proc~unique string%unique proc~split->proc~unique proc~read_line string%read_line proc~read_lines->proc~read_line proc~replace string%replace proc~unique->proc~replace proc~read_line->proc~chars proc~read_line->proc~upper~2 proc~replace_one_occurrence string%replace_one_occurrence proc~replace->proc~replace_one_occurrence

Called by

proc~~glob_character~~CalledByGraph proc~glob_character string%glob_character none~glob string%glob proc~glob_character->none~glob interface~glob glob interface~glob->proc~glob_character none~glob->proc~glob_character program~volatile_doctest~1058 volatile_doctest program~volatile_doctest~1058->none~glob program~volatile_doctest~334 volatile_doctest program~volatile_doctest~334->none~glob program~volatile_doctest~426 volatile_doctest program~volatile_doctest~426->none~glob program~volatile_doctest~468 volatile_doctest program~volatile_doctest~468->interface~glob program~volatile_doctest~498 volatile_doctest program~volatile_doctest~498->interface~glob program~volatile_doctest~511 volatile_doctest program~volatile_doctest~511->none~glob

Source Code

   subroutine glob_character(self, pattern, list)
   !< Glob search (character output), finds all the pathnames matching a given pattern according to the rules used by the Unix shell.
   !<
   !< @note Method not portable: works only on Unix/GNU Linux OS.
   !<
   !<```fortran
   !< type(string)                  :: astring
   !< character(len=:), allocatable :: alist_chr(:)
   !< integer, parameter            :: Nf=5
   !< character(14)                 :: files(1:Nf)
   !< integer                       :: file_unit
   !< integer                       :: f
   !< integer                       :: ff
   !< logical                       :: test_passed
   !< do f=1, Nf
   !<    files(f) = astring%tempname(prefix='foo-')
   !<    open(newunit=file_unit, file=files(f))
   !<    write(file_unit, *)f
   !<    close(unit=file_unit)
   !< enddo
   !< call astring%glob(pattern='foo-*', list=alist_chr)
   !< do f=1, Nf
   !<    open(newunit=file_unit, file=files(f))
   !<    close(unit=file_unit, status='delete')
   !< enddo
   !< test_passed = .false.
   !< outer_chr: do f=1, size(alist_chr, dim=1)
   !<    do ff=1, Nf
   !<       test_passed = alist_chr(f) == files(ff)
   !<       if (test_passed) cycle outer_chr
   !<    enddo
   !< enddo outer_chr
   !< print '(L1)', test_passed
   !<```
   !=> T <<<
   class(string),                 intent(in)  :: self           !< The string.
   character(*),                  intent(in)  :: pattern        !< Given pattern.
   character(len=:), allocatable, intent(out) :: list(:)        !< List of matching pathnames.
   type(string), allocatable                  :: list_(:)       !< List of matching pathnames.
   integer(I4P)                               :: max_len        !< Maximum length.
   integer(I4P)                               :: matches_number !< Matches number.
   integer(I4P)                               :: m              !< Counter.

   call self%glob(pattern=pattern, list=list_)
   if (allocated(list_)) then
      matches_number = size(list_, dim=1)
      max_len = 0
      do m=1, matches_number
         max_len = max(max_len, list_(m)%len())
      enddo
      allocate(character(max_len) :: list(1:matches_number))
      do m=1, matches_number
         list(m) = list_(m)%chars()
      enddo
   endif
   endsubroutine glob_character