Getting an "unclassifiable statement" error in Fortran 95


by ngendler
Tags: f95, fortran, language, programming
ngendler
ngendler is offline
#1
Jun9-13, 04:15 PM
P: 14
I am trying to integrate the function x from 0 to 1. Here is my code:

program myownmonte
!This program will integrate the function x from 0 to 1
implicit none
real :: ans0,y,f,x,xmax
integer :: icount,nmax,i,iseed
iseed = 89237
call srand(iseed)

nmax = 100000

icount = 0
xmax = 1
ans0 = 0
do i=1,nmax
x = rand()
y = rand()
f = f(x)
if (y.le.f) then
icount = icount + 1
end if
ans0 = ans0 + f(x)
end do
print *, icount/nmax,ans0/nmax
end program myownmonte



function f(x)
implicit none
real :: x,f
f = x
end function f


And here are the errors I'm getting:

f = f(x)
1
Error: Unclassifiable statement at (1)
mymonte.f95:21:

ans0 = ans0 + f(x)
1
Error: Unclassifiable statement at (1)


Could someone help me fix this, and kindly let me know what the phrase "unclassifiable statement" means? Thanks in advance!
Phys.Org News Partner Science news on Phys.org
Better thermal-imaging lens from waste sulfur
Hackathon team's GoogolPlex gives Siri extra powers
Bright points in Sun's atmosphere mark patterns deep in its interior
SteamKing
SteamKing is offline
#2
Jun9-13, 04:53 PM
HW Helper
Thanks
P: 5,542
In your main program, you have a variable 'f' and also a function 'f'. You can't have both in the same program unit. Rename either the variable or the function.
ngendler
ngendler is offline
#3
Jun9-13, 06:48 PM
P: 14
@SteamKing, that didn't work. When I remove f from my list of reals, I get another error saying that f has no implicit type, which makes me think that I need it to be declared as real.

phyzguy
phyzguy is offline
#4
Jun9-13, 07:21 PM
P: 2,068

Getting an "unclassifiable statement" error in Fortran 95


SteamKing is still right that using f as both a function and a variable is the problem. The statement:

f = f(x)

really makes no sense, since you are trying to use the same symbol as a variable and a function. Your attempt to fix it wasn't correct, since you need to tell the compiler what kind of datatype f is. You need to do something like this. This will compile and run.


program myownmonte
!This program will integrate the function x from 0 to 1
implicit none
real :: ans0,y,f,fx,x,xmax
integer :: icount,nmax,i,iseed
iseed = 89237
call srand(iseed)

nmax = 100000

icount = 0
xmax = 1
ans0 = 0
do i=1,nmax
x = rand()
y = rand()
fx = f(x)
if (y.le.fx) then
icount = icount + 1
end if
ans0 = ans0 + fx
end do
print *, icount/nmax,ans0/nmax
end program myownmonte



function f(x)
implicit none
real :: x,f
f = x
end function f
SteamKing
SteamKing is offline
#5
Jun9-13, 08:54 PM
HW Helper
Thanks
P: 5,542
'Rename' and 'remove' mean different things, in English at least.


Register to reply

Related Discussions
Fortran, File Read Error("Tried to read past...") Programming & Computer Science 4
I can not read character "0A" in a bmp file with "Compaq Visual Fortran 6.6C" Programming & Computer Science 11
Unclassifiable Statement error in fortran 90 Programming & Computer Science 3
Unclassifiable statement,, Unexpected data declaration statement Programming & Computer Science 3
Checking Chadwick's statement about the mysterious "neutral radiation"? Advanced Physics Homework 4