index function problem
- From: utab <umut.tabak@xxxxxxxxx>
- Date: Thu, 27 Mar 2008 05:18:56 -0700 (PDT)
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,
.
- Follow-Ups:
- Re: index function problem
- From: relaxmike
- Re: index function problem
- From: FX
- Re: index function problem
- Prev by Date: Re: compiler switch -c
- Next by Date: Re: index function problem
- Previous by thread: what is wrong with this code?can someone walk me through this?
- Next by thread: Re: index function problem
- Index(es):
Relevant Pages
|