index function problem



Dear all,

I tried a code to find the indices of the ocurences of a pattern in a
string.

Here is the code.

program find_occurances
implicit none
integer :: real_ind,dummy,start
logical :: flag=.true.
!!!!
character,dimension(150) :: text='IF A PROGRAMMER IS FOUND TO BE
INDISPENSABLE,&
THE BEST THING TO DO IS TO GET RID OF HIM AS SOON AS POSSIBLE'
!character(80) :: text='IS A PROGRAMMER IS'
character(2) :: pattern ='IS'
! find 1st occurance
dummy=index(text,pattern)
! if found continue
if(dummy > 0) then
print*, dummy
start=dummy+len(pattern)
do while(flag)
dummy=index(text(start:),pattern) ! is for a space
if( dummy > 0) then
flag=.true.
real_ind=start+dummy-1
start=real_ind+len(pattern)
print*, real_ind
else
flag=.false.
end if
end do
end if
end program find_occurances

I have a problem with the long text I can not compile the code with
that text, errors are given by gfortran

In file ind.f90:11

dummy=index(text,pattern)
1
Error: Incompatible ranks 0 and 1 in assignment at (1)
In file ind.f90:17

dummy=index(text(start:),pattern) ! is for a space
1
Error: Incompatible ranks 0 and 1 in assignment at (1)


However if I comment out this and use the smaller one on the below
line. I results in what I want.
../a.out
1
17

What is wrong with the string separation?
Rgs,
.



Relevant Pages

  • Re: Design: Custom Exception Usage
    ... It'd be silly to call a method that basically has to do the work of parsing the string, but which only returns a flag telling me if actually parsing the string will work. ... Beyond that, however, since sometimes performance _is_ an issue, it's not like TryParse() could have been left out of the API. ... That provides the exact assignment pattern you're asking for. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [KSH] Assign a matched pattern to a shell variable
    ... > portion of the string that the pattern matched. ... but matched against the string: ... > the assignment to extract a substring from $. ...
    (comp.unix.shell)
  • Problem mit XML Serialisierung
    ... public sealed partial class Assignment { ... XmlSerializer serializer = new XmlSerializer); ... private string david; ... private Listdatabases; ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: OpenForm vs. Form menu double click.
    ... was a string and the data type of the where variable matched the syntax... ... In my situatiation the SSN on the input is text as well as the SSN field in ... A command button to add an assignment ... Private Sub Form_Open ...
    (microsoft.public.access.formscoding)
  • Re: Java or C++?
    ... Plus there are several toolkits and existing libraries available for Python. ... Take a string object for example. ... a copy constructor or assignment operator can be implemented when using C++. ... And if you want more control you can implement the default and copy constructors, destructor, and assignment operator, and tell them to do what you want. ...
    (comp.lang.python)