Question: I would like to understand the basics of how to write and execute a Fortran program on Linux OS. Can you explain it with a simple example?
Answer: In this article, let us review very quickly how to write a basic Hello World Fortran program and execute *.f program on Linux or Unix OS.
1. Write a Hello World Fortran Program
Create helloworld.f program using the Vim editor as shown below.
$ vim helloworld.f program hello print *,"Hello World!" end program hello
You can also write a shorter version of the hello world Fortran program as shown below.
$ vim helloworld.f PRINT *,"Hello World!" END
2. Make sure Fortran compiler is installed on your system
Make sure Fortran compiler is installed on your system as shown below.
$ whereis gfortran gfortran: /usr/bin/gfortran /usr/share/man/man1/gfortran.1.gz $ which gfortran /usr/bin/gfortran $ dpkg -l | grep gfortran ii gfortran 4:4.3.3-1ubuntu1 The GNU Fortran 95 compiler ii gfortran-4.3 4.3.3-5ubuntu4 The GNU Fortran 95 compiler ii libgfortran3 4.3.3-5ubuntu4 Runtime library for GNU Fortran applications
Installing GNU Fortran compiler.
If you don’t have GNU Fortran compiler, install it as shown below.
$ sudo apt-get install gfortran
3. Compile the Fortran program
Compile the helloworld.f using gfortran command as shown below. This will create the a.out file.
$ gfortran -ffree-form helloworld.f $ ls -l -rw------- 1 ramesh ramesh 55 Oct 24 23:13 helloworld.f -rwx------ 1 ramesh ramesh 9545 Oct 24 23:14 a.out*
4. Execute the Fortran program (a.out)
$ ./a.out Hello World! $ mv a.out helloworld $ ./helloworld Hello World!
Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.Get the Linux Sysadmin Course Now!
If you enjoyed this article, you might also like..
|
|
|
|






My name is Ramesh Natarajan. I will be posting instruction guides, how-to, troubleshooting tips and tricks on Linux, database, hardware, security and web. My focus is to write articles that will either teach you or help you resolve a problem. Read more about
{ 4 comments… read them below or add one }
please help me..
i got a really simple question.
given natural number n (n ≤ 1000). write these number to word.( seven, eighty six, three hundred fifty five and etc)..
while compiling what does the -ffree-form stand for?
Thank you very much. A really nice kick-off for me.
Hi everybody, does any body know how to run in a release mode instead of debug?
I need it because of it’s faster speed.
Thanks