Getting an unclassifiable statement error in Fortran 95

  • Context: Fortran 
  • Thread starter Thread starter ngendler
  • Start date Start date
  • Tags Tags
    Error Fortran
Click For Summary

Discussion Overview

The discussion revolves around a Fortran 95 programming issue related to an "unclassifiable statement" error encountered while attempting to integrate the function x from 0 to 1. Participants are exploring the code structure, variable and function naming conflicts, and the implications of implicit typing in Fortran.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant shares their Fortran code and describes the error messages they are receiving.
  • Another participant suggests that the error arises from having a variable and a function both named 'f' within the same program unit, recommending a rename of either.
  • A later reply indicates that renaming 'f' did not resolve the issue, as it led to a new error regarding implicit typing, suggesting that 'f' needs to be declared as a real type.
  • Another participant reiterates that the conflict between the variable and function named 'f' is the core issue, emphasizing that the statement 'f = f(x)' is nonsensical due to this naming conflict.
  • One participant provides a modified version of the code that they claim will compile and run, introducing a new variable 'fx' to avoid the naming conflict.
  • A final comment points out the distinction between 'rename' and 'remove' in the context of the previous suggestions, implying a misunderstanding in terminology.

Areas of Agreement / Disagreement

Participants generally agree that the naming conflict between the variable and function 'f' is causing the error, but there is some disagreement on the best approach to resolve the issue, particularly regarding implicit typing and variable declarations.

Contextual Notes

The discussion highlights limitations related to implicit typing in Fortran and the potential for confusion when using the same identifier for different purposes. There are unresolved aspects regarding the implications of the suggested code changes.

Who May Find This Useful

Programmers working with Fortran, particularly those encountering similar issues with variable and function naming conflicts, as well as those interested in understanding implicit typing in Fortran 95.

ngendler
Messages
20
Reaction score
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
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.
 
@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.
 
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
 
'Rename' and 'remove' mean different things, in English at least.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 8 ·
Replies
8
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
Replies
13
Views
8K
  • · Replies 5 ·
Replies
5
Views
5K