Advertisement
KDOXG

Untitled

Apr 4th, 2021
2,179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. subroutine findsubstring (lineToSearch,line)
  2.     character line(256), lineToSearch(20)   !# line precisa ser ponteiro
  3.                                             !# precisa descobrir o tamanho de line e lineToSearch;
  4.                                             !  função do fortran ou receber de argumento?
  5.     logical found, loop
  6.     integer i1, i2, i3
  7.     common/args/ count
  8.     count = 0
  9.     i1 = 0
  10.     found = .false.
  11.     loop = .true.
  12.     !i = index(line,lineToSearch)           !#OLD# Procura se lineToSearch é uma substring de line, se não for, i recebe 0
  13.  
  14.     do while (i1.LT.len(line) .and. loop.EQV..true.)               ! Implementação da função index
  15.         i2 = 0
  16.         if (line(i1).EQ.lineToSearch(i2)) then      ! Comparação de inteiros;
  17.                                                     ! Testa se o caractere atual de line é igual ao primeiro de lineToSearch
  18.             found = .true.
  19.             i3 = i1
  20.             do while (found.EQV..true. .and. i2.LT.len(lineToSearch) .and. i3.LE.len(line))
  21.                 if (i3.EQ.len(line) .or. lineToSearch(i2).NE.line(i3)) then     ! Se a string não existe, nao encontrou
  22.                     found = .false.
  23.                 end if
  24.                 i2 = i2 + 1
  25.                 i3 = i3 + 1
  26.             end do
  27.         end if
  28.         if (found.EQV..true.) then                   ! Se a string existe
  29.             loop = .false.                           ! Para sair do loop principal
  30.             i1 = i3
  31.         end if
  32.         i1 = i1 + 1
  33.     end do
  34.     if (i1.EQ.len(line)) then
  35.         i1 = 0
  36.     end if
  37.  
  38.     if (i.NE.0) then                        ! se i é diferente de 0, ou seja, lineToSearch é uma substring de line
  39.         count = count + 1          
  40.         !line = line + i + 1                !# Corrigir esta aritmética de ponteiros; line no momento é character
  41.         do while (i.NE.0)
  42.             !i = index(line,lineToSearch)
  43.             if (i.NE.0) then
  44.                 count = count + 1
  45.                 !line = line + i + 1        !# Corrigir esta aritmética de ponteiros; line no momento é character
  46.             end if
  47.         end do
  48.     end if
  49.  
  50.     return
  51. end subroutine findsubstring
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement