What are common errors when compiling a simple Fortran code?

  • Context: Fortran 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Gfortran Teaching
Click For Summary
SUMMARY

The discussion centers on common errors encountered when compiling Fortran code using gfortran on an Ubuntu machine. The user faced compilation errors due to using the incorrect file extension '.f' for free form source code. The solution provided indicates that the file should be saved with the '.f90' extension to avoid errors related to unclassifiable statements and unexpected end of file. This adjustment resolves the compilation issues effectively.

PREREQUISITES
  • Understanding of Fortran programming language syntax
  • Familiarity with gfortran compiler on Ubuntu
  • Knowledge of file extensions and their significance in programming
  • Basic command line usage in Linux environments
NEXT STEPS
  • Research the differences between fixed form and free form Fortran source code
  • Learn about compiling Fortran code with gfortran options
  • Explore common Fortran compilation errors and their resolutions
  • Study best practices for organizing Fortran projects and file management
USEFUL FOR

This discussion is beneficial for Fortran programmers, students learning Fortran, and developers using gfortran on Linux who seek to understand common compilation issues and their solutions.

MathematicalPhysicist
Science Advisor
Gold Member
Messages
4,662
Reaction score
372
So I have a Ubuntu machine with gfortran installed in it.

I wrote the following simple code in fortran:
Fortran:
program calculation
   print *, 55+55
end program calculation
I saved it as 'calculation.f' file and then tried to compile it in the terminal, but got the following errors:
Code:
calculation.f:1:1:

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

 program calculation
 1
Error: Unclassifiable statement at (1)
calculation.f:3:1:

 end program calculation
 1
Error: Non-numeric character in statement label at (1)
calculation.f:3:1:

 end program calculation
 1
Error: Unclassifiable statement at (1)
f951: Error: Unexpected end of file in ‘calculation.f’
Where did I go wrong here?

Thanks.
 
Technology news on Phys.org
You didn't paste the error you got, but I suspect what it is. Since you are using free form, not the fixed column format (left over from the punch card era), the filename should end in .f90 instead of .f.
 
Works fine now.
 

Similar threads

  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 17 ·
Replies
17
Views
7K
  • · Replies 20 ·
Replies
20
Views
3K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
8K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K