Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compiling

Status
Not open for further replies.

Nusc

Programmer
May 9, 2015
11
CA
Hi all, it's been a long time since I touched Fortran.

I am trying to compile old Fortran (.f) files.

I am using Gygwin executing the following command:

gfortran -ffree-form -o filename.exe filename.f

I get the following error over 25 times:

Error: Unclassifiable statement at (1)

I'm not sure what's wrong. If you can help me out that would be great.

Thank you!

 
Can you show us a bit of code? Maybe the first 10 lines where the error is happening

Have you got tabs or spaces in the code?

Are you sure you want to use -ffree-form? That is for F90 type programs.
 
I believe the issue comes with the existing comments:

c ---

c --- blah

c --- blah

c --- blah

c --- blah

c ---


Do you know if the original files were compiled in F77 F90 or F95?

I'm using gfortran.

 
Looks like F77. In that case remove -ffree-form and you should be OK.

In F90, the comment character is !. In F77, a comment is any character in column 1. So you could have
Code:
One day this will work
as a comment, as long as it starts in column 1.
 
Hi xwb,

thanks for your help.

That seems to have resolved some of the errors, now I receive the following messages:

filename.f:42.72:

pause
1
Warning: Deleted feature: PAUSE statement at (1)


What does this warning show?


Another error apepras
filename.f:427.19:

subroutine function(x,y)
2
Error: COMMON block 'function' at (1) uses the same global identifier as entity at (2)


Thanks
 
The two message are quite explicit :

- PAUSE is an old statement which does not belong to the language anymore. But this is just a warning...

- you cannot have simultaneously a subroutine and a common block having the same name. This is really an error. Fix it please...

François Jacq
 
Hi FJacq,

from the above posts, this is a F77 program. I'm sure it worked at some point without error.

filename.f:427.19:

subroutine myownfxn(x,y)
2
Error: COMMON block 'myownfxn' at (1) uses the same global identifier as entity at (2)
---------------------------------------------------
Do I declare it as a subroutine or a function?

function myownfxn(variable1,variable2)
or
SUBROUTINE myownfxn(variable1,variable2)

What I am trying to do is integrate a function.
 
What it is telling you is that you have a function and a common block with the same name. It is possible that the original compiler was not as strict.
 
Could you please show us an exact piece of your source file including spaces : you have an icon enabling to display the source code correctly.

François Jacq
 
gfortran testcode.exe testcode.f

program HelloWorld
write (*,*) 'Hello, world!' ! This is an inline comment
end program HelloWorld

I get the following:

testcode.f:1.2:

program HelloWorld
1
Error: Non-numeric character in statement label at (1)
testcode.f:1.2:

program HelloWorld
1
Error: Unclassifiable statement at (1)
testcode.f:2.4:

write (*,*) 'Hello, world!' ! This is an inline comment
1
Error: Non-numeric character in statement label at (1)
testcode.f:2.4:

write (*,*) 'Hello, world!' ! This is an inline comment
1
Error: Unclassifiable statement at (1)
testcode.f:3.2:

end program HelloWorld
1
Error: Non-numeric character in statement label at (1)
testcode.f:3.2:

end program HelloWorld
1
Error: Unclassifiable statement at (1)
 
Do they start in column 7? In F77 the first 5 columns are for a statement label like a format statement the 6th column indicates a continuation and 7 and above is where the code goes.

Bill
Lead Application Developer
New York State, USA
 
Does what start in column 7?

I am using Gedit, at the bottom right hand side it says Fortran 95.

There is no option for Fortran 77.

Do you advise indenting my code?
 
You used bad file extension for your program - see for example this:

if your program name is testcode.f then the compiler expects fixed form style, but your source is written in free form. Rename the source file to testcode.f95 and try to compile with the command
Code:
gfortran testcode.f95 -o testcode
 
So back to the other posts:

I should remove all the 'pause' statements and recompile without free form.

And back to the other error:
filename.f:395.16:

common/op/help,constant1,constant2,a1,b1,a2,b2,n2
1

I will paste part of the source code as expected:


subroutine function(id)

implicit real*8(a-h,o-z)

dimension help(900),xvariable(900),yvariable(900),constant1(900),constant2(900)

dimension fxn1(900),fxn2(900)

common/op/help,constant1,constant2,a1,b1,a2,b2,n2


The second error is:

filename.f:427.19:

subroutine function(k,conc1)
2
Error: COMMON block 'function' at (1) uses the same global identifier as entity at (2)

Source code:


subroutine function(k,conc1)

implicit real*8(a-h,o-k)

dimension help(600),c1(600),c2(600)

common/op/help,constant1,constant2,a1,b1,a2,b2,n2

Thirdly, I don't understand the line:

implicit real*8(a-h,o-k)

What is a-h and o-k?




 
Code:
subroutine function(id)

implicit real*8(a-h,o-z)

dimension alt(900),xvariable(900),yvariable(900),constant1(900),constant2(900)

dimension fxn1(900),fxn2(900)

common/op/alt,constant1,constant2,a1,b1,a2,b2,n2

gives:
filename.f:395.16:

common/op/alt,constant1,constant2,a1,b1,a2,b2,n2
1


Code:
subroutine function(k,conc1)

implicit real*8(a-h,o-k)

dimension alt(900),constant1(900),constant2(900)

common/op/alt,constant1,constant2,a1,b1,a2,b2,n2

filename.f:427.19:

subroutine function(k,conc1)
2
Error: COMMON block 'function' at (1) uses the same global identifier as entity at (2)

xwb said the original compiler was not as strict. What must I do to remove these messages?
 
CHANGE THE NAME OF THE BLOCK OR THE FUNCTION. Your choice.

Bill
Lead Application Developer
New York State, USA
 
I have removed all lines containing common and the code compiles.

#1. Is common a redundant feature?

#2. I get results but with error:

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
Backtrace for this error:


#3.

write(6,*) '======================='
1
Error: Syntax error in WRITE statement at (1)

What's wrong with this statement? I have another line of code with the same syntax which does not produce an error.
 
You can't get rid of the common statements. They indicate a common variable memory location for the various routines. Just change one of the invalid block or function names to something else.

Bill
Lead Application Developer
New York State, USA
 
If I want to pause the running code, what is the command to do this? They took out the PAUSE function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top