For Programmers: Free Programming Magazines  


Home > Archive > Fortran > May 2006 > Common statement does not work with gfortran, but g95 gives the correct answer









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Common statement does not work with gfortran, but g95 gives the correct answer
gabsata

2006-05-26, 7:04 pm

When I give a vector size of 2 for "x", with values x(1)=3D1 y x(2)=3D1,
the result with an executable from gfrotran gives x(1)+x(2)=3D3.00000000,
but with g95, it gives x(1)+x(2)=3D3.00000000. Maybe I am doing something
wrong, but lahey gives the correct answer as g95. =BFgfortran does not
parse correctly my function?


My code (in 1 file) is:

IMPLICIT NONE
REAL(8),allocatable:: X(:)
REAL(8) fun
INTEGER n
COMMON n
READ*,n
ALLOCATE (x(n))
READ*,x
PRINT*,fun(x)
end


function fun(x)
implicit REAL(8) (a-z)
DIMENSION x(n)
INTEGER n
COMMON n
fun=3Dx( 1 )+x( 2 )
END function fun

The correct code is:

IMPLICIT NONE
REAL(8),allocatable:: X(:)
REAL(8) fun
INTEGER n
READ*,n
ALLOCATE (x(n))
READ*,x
PRINT*,fun(n,x)
end


function fun(n,x)
implicit REAL(8) (a-z)
DIMENSION x(n)
INTEGER n
fun=3Dx( 1 )+x( 2 )
END function fun

Steven G. Kargl

2006-05-26, 7:04 pm

In article <1148679429.660261.252150@g10g2000cwb.googlegroups.com>,
"gabsata" <gabsata@gmail.com> writes:
> When I give a vector size of 2 for "x", with values x(1)=1 y x(2)=1,
> the result with an executable from gfrotran gives x(1)+x(2)=3.00000000,
> but with g95, it gives x(1)+x(2)=3.00000000. Maybe I am doing something
> wrong, but lahey gives the correct answer as g95. ¿gfortran does not
> parse correctly my function?
> My code (in 1 file) is:
> IMPLICIT NONE
> REAL(8),allocatable:: X(:)
> REAL(8) fun
> INTEGER n
> COMMON n
> READ*,n
> ALLOCATE (x(n))
> READ*,x
> PRINT*,fun(x)
> end
> function fun(x)
> implicit REAL(8) (a-z)
> DIMENSION x(n)
> INTEGER n
> COMMON n
> fun=x( 1 )+x( 2 )
> END function fun


You failed to mention the version of gfortran that you used.
If you have 4.0.x, then upgrade to at least 4.1.1 (which was
released yesterday :-).

troutmask:kargl[205] gfortran -o z a.f90
troutmask:kargl[206] ./z
2
1
1
2.00000000000000

--
Steve
http://troutmask.apl.washington.edu/~kargl/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com