What are common errors when compiling a simple Fortran code?

In summary, the conversation discusses an issue with compiling a simple Fortran code on an Ubuntu machine. The user had saved the code as a .f file instead of .f90, causing errors to occur during compilation. After changing the file extension, the code compiled successfully.
  • #1
MathematicalPhysicist
Gold Member
4,699
371
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
  • #2
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.
 
  • #3
Works fine now.
 

1. What is gfortran and why should I learn it?

Gfortran, also known as the GNU Fortran compiler, is a free and open source compiler for the Fortran programming language. It is widely used in scientific computing and offers a wide range of features and optimizations. Learning gfortran can enhance your ability to write efficient and high-performance code for scientific applications.

2. How can I get started with learning gfortran?

The first step to teaching yourself gfortran is to download and install the compiler on your computer. This can be done for free from the official gfortran website. Once installed, you can find tutorials, documentation, and other learning resources online to help you get started.

3. Do I need any prior programming experience to learn gfortran?

While prior programming experience is not required, it can be helpful in understanding the basic concepts of programming. However, if you are new to programming, it is recommended to start with learning the fundamentals of programming before diving into gfortran.

4. Are there any specific skills or knowledge that I should have in order to learn gfortran?

It is helpful to have a basic understanding of mathematics and scientific concepts, as gfortran is commonly used for scientific computing. Knowledge of other programming languages, such as C or Python, can also be beneficial in learning gfortran.

5. Can I use gfortran on any operating system?

Yes, gfortran is a cross-platform compiler and can be used on various operating systems such as Windows, Mac, and Linux. However, the installation process may differ slightly depending on your operating system.

Similar threads

  • Programming and Computer Science
Replies
15
Views
218
  • Programming and Computer Science
Replies
4
Views
619
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
2
Views
315
  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
2
Views
7K
Back
Top