[fortran90] have problem in real array index

  • Fortran
  • Thread starter s_hy
  • Start date
  • #1
61
0
hi all...i have problem in understanding in array index. my codes are as below

Code:
subroutine  tmz2d
implicit none


double precision                   :: phi
double precision                   :: cosphi,sinphi
double precision                   :: d,dp,dpp,d1,d2
integer                            :: i,j,m,h
integer                            :: minit,mlast
integer                            :: l,p
integer                            :: iinit,ilast,hlast,pinit,plast
integer                            :: n
integer                            :: linit,llast
integer                            :: jinit,jlast
double precision,dimension(200)    :: Hm,Em
double precision                   :: Einc,Hinc
double precision,dimension(200,200):: Ezinc,Hxinc,Hyinc
double precision, parameter        :: pi = 3.14159265
character(len=20)                  :: filename
 

 minit = 1
 mlast = 100
 linit = 1
 llast = 100
 pinit = 1
 plast = 100

 iinit = 1 
 ilast = 100
 jinit = 1
 jlast = 100


 phi = pi/4.0
 cosphi = cos(phi)
 sinphi = sin(phi)
 print *, 'cosphi=',cosphi,'sinphi=',sinphi


do n = 1,100
   
  write (filename, "('data',I3.3,'.dat')") n
  open (unit=130,file=filename)


 call bg1d
 !print *, 'see me2'

  do m = 2,2*ilast-1
    do p = 2,2*jlast-1
      if (Mod(m,2)/=0) then
	if (Mod(p,2)/=0) then
         d = cosphi*(m - minit) + sinphi*(p - pinit)
         dp = d - int(d)
         Einc = (1-dp)*Em(int(d))+dp*(Em(int(d)+1))
         Ezinc(m,p+2) = Einc
         write(130,*) Ezinc(m,p+2)
        end if
      end if
    end do
  end do

  do m = 2,2*ilast-1
    do p = 2,2*jlast-1
      if (Mod(m,2) == 0) then
	if (Mod(p,2) == 0) then
         d = cosphi*(m - minit) + sinphi*(p - pinit)
         dpp = d+1
         dp = dpp-int(d)
           Hinc = (1-dp)*Hm(int(dpp)-0.5)+dp*Hm(0.5+int(dpp))
           Hxinc(m,p+1) = sinphi*Hinc
           Hyinc(m-1,p+2) = -cosphi*Hinc
        end if
      end if
    end do
  end do

end do !n
print *, 'see me3'


end subroutine tmz2d
and i got this warning when execute

subroutines.f90:167.48:

Hinc = (1-dp)*Hm(int(dpp)-0.5)+dp*Hm(0.5+int(dpp))
1
Warning: Extension: REAL array index at (1)
subroutines.f90:167.28:

Hinc = (1-dp)*Hm(int(dpp)-0.5)+dp*Hm(0.5+int(dpp))
1
Warning: Extension: REAL array index at (1)


###########################################

the problem come from line 167 and i found out that fortran do not allow real index...(int(dpp) -0.5)..can anyone give me an advice how to solve this problem.

thank you in advance
 

Answers and Replies

  • #2
Borek
Mentor
28,511
2,940
The obvious answer (which should remove the warning, but doesn't have to be correct for your problem) is to use int(dpp-0.5) - right now you are converting dpp to an int, then subtracting (or adding) 0.5 converting it back to a real. Do the subtraction first, conversion to an int later.
 
  • #3
1,065
53
O.k., you found out that Fortran does not allow "real" index; more precisely, it allows a "real argument" but the final index needs to be integer...to that end, it allows a "real argument" which gets automatically typecast into an integer. If "real argument" wasn't allowed, you would get a compiler "error" instead of a "warning".

Say, is there a chest of drawers in your room? Does it have drawer 1.37?...It's the same with arrays.
 
  • #4
61
0
thanks Borek, its worked and removed the warning

thanks gsal for the explanation..i am really new in fortran90
 

Related Threads on [fortran90] have problem in real array index

Replies
21
Views
1K
  • Last Post
Replies
1
Views
603
Replies
8
Views
2K
Replies
9
Views
892
  • Last Post
Replies
9
Views
2K
Replies
3
Views
2K
Replies
20
Views
1K
Replies
8
Views
2K
Replies
1
Views
2K
Top