Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fortran natural logarithm error

New to Fortran (just started today), having trouble with the natural logarithm:

PROGRAM log
IMPLICIT NONE
REAL :: x

PRINT *, "Enter a number:"
READ *, x

x = log (x)

PRINT *, "The natural log of x is:", x

END PROGRAM log

The compiler keeps throwing up the error:

x = log (x)
       1
Error: Symbol at (1) is not appropriate for an expression

Other intrinsic functions work fine. What am I doing wrong?

like image 304
James Jenkinson Avatar asked Oct 27 '12 21:10

James Jenkinson


1 Answers

The problem is that you've shadowed (overridden) the definition of the symbol log - which would normally refer to the standard library mathematical function - with the name of your program, which is also log. If you change the name of the program to, say, logtest:

PROGRAM logtest
...
END PROGRAM logtest

You'll find that the program works as expected.

like image 136
Jonathan Dursi Avatar answered Dec 31 '22 02:12

Jonathan Dursi