Getting an unclassifiable statement error in Fortran 95

In summary: Rename' means to change the name of a variable, while 'remove' means to delete a variable. If you want to change the name of a variable, use the command:rename x oldname
  • #1
ngendler
20
0
Getting an "unclassifiable statement" error in Fortran 95

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!
 
Technology news on Phys.org
  • #2
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.
 
  • #3
@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.
 
  • #4
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
 
  • #5
'Rename' and 'remove' mean different things, in English at least.
 

1. What does it mean to get an unclassifiable statement error in Fortran 95?

An unclassifiable statement error in Fortran 95 means that the compiler was unable to understand or classify a particular statement in the code. This could be due to a syntax error, missing or incorrect punctuation, or a mismatch between the code and the intended formatting rules.

2. How can I fix an unclassifiable statement error in Fortran 95?

The first step in fixing an unclassifiable statement error is to carefully review the code and check for any syntax errors or incorrect formatting. This includes making sure that all statements are properly terminated and that any variables being used are declared and initialized correctly. If the error persists, it may be helpful to consult the Fortran 95 language documentation or seek assistance from a more experienced programmer.

3. Can an unclassifiable statement error be caused by a missing or incorrect data type declaration?

Yes, an unclassifiable statement error can be caused by a missing or incorrect data type declaration. Fortran 95 is a strongly typed language, meaning that all variables must be declared with a specific data type before they can be used. If a variable is not declared or is declared with the wrong data type, it can result in an unclassifiable statement error.

4. Are there any common mistakes that can lead to an unclassifiable statement error in Fortran 95?

Yes, there are a few common mistakes that can lead to an unclassifiable statement error in Fortran 95. These include forgetting to terminate a statement with a semicolon, using incorrect keywords or syntax, and mismatching parentheses or quotation marks. It is important to be diligent and thorough when writing Fortran 95 code to avoid these types of errors.

5. Is it possible for an unclassifiable statement error to be caused by a problem with the compiler?

While it is possible for an unclassifiable statement error to be caused by a problem with the compiler, it is more likely that the error is due to an issue with the code itself. However, if the code seems to be correct and the error persists, it may be worth checking for any updates or known issues with the compiler and considering trying a different compiler to see if the error persists.

Similar threads

  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
498
  • Programming and Computer Science
Replies
8
Views
3K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
4K
Back
Top