Fortran (Formula Translation) is one of the oldest programming languages and has been widely used in scientific and engineering applications.
Despite its age, Fortran remains a robust and efficient language for numerical computations.
Here, we will explore how to write a classic “Hello World” program in Fortran. By following these simple steps, you’ll gain a foundational understanding of Fortran’s syntax and structure, setting you on a path to becoming a proficient Fortran programmer.
Step 1: Installing a Fortran Compiler
Before we dive into writing our first Fortran program, we need to ensure that we have a Fortran compiler installed on our system. One popular choice is the GNU Fortran compiler, commonly known as gfortran. You can download and install gfortran by following the instructions provided on the GNU website.
Step 2: Setting up the Development Environment
Once you have installed the Fortran compiler, you’ll need a text editor or an Integrated Development Environment (IDE) to write your code.
Popular choices include Visual Studio Code with the Fortran extension or dedicated Fortran IDEs like Geany, Intel Fortran Compiler, or Silverfrost FTN95.
Step 3: Writing the “Hello World” Program:
Now that we have our development environment set up let’s write our first Fortran program, the classic “Hello World” example. Open your chosen text editor or IDE and create a new file with a .f90 extension (e.g., hello_world.f90).
program hello_world
implicit none
write(*, *) "Hello, World!"
end program hello_world
Let’s break down the code:
- program hello_world: This line declares the start of our program and assigns it the name “hello_world.”
- implicit none: This line ensures that all variables must be explicitly declared, promoting good programming practices.
- write(*, *) “Hello, World!”: This line prints the string “Hello, World!” to the standard output, denoted by the asterisks (*).