DEV Community

Cover image for February of Fortran
Lautaro Lobo
Lautaro Lobo

Posted on • Originally published at on

February of Fortran

What is Fortran?

Fortran is a 63 y.o. programming language developed by IBM for scientific and engineering applications. Its name is an acronym from FORmula TRANslation , and still being in use for that purpose.

It’s a general-purpose programming language, but best suited for computationally intensive areas like computational physics, computational chemistry, high-performance computing and so.

Many programming languages were based on or influenced by, Fortran. And it has received many updates among the years, last one in 2018.

It was originally conceived as FORTRAN, all uppercase, in 1956. 5 updates later, in the 90s, it became Fortran. The update also added many other changes like free-form source, inline comments, modules, recursive procedures, dynamic memory allocation and many other changes that make the language modern-er.

How to Compile and Run a Fortran Program

Let’s say you want to compile and run your first Fortran program, like this one:

program HelloWorld
  implicit none
  print*, "hello world"
  write(*,*) "hello world"
end program

! it should return:
! hello world
! hello world

Well, you should make a series of things:

  • Install gfortran, which is a Fortran compiler.
  • Save your code with .f90 extension (even if you are writing in Fortran 2015, .f90 it’s the standard file extension).
  • Compile with gfortran.
  • Run your program as you would run any C program.

And that’s how you do it!

What is Fortran Used For

Fortran is still in use in HPC (High Performace Computing). All that is mathematical chunk is probably done with Fortran. It’s widely used in scientific computing from Chemistry and Physics to Astronomy and Mathematics.

I can almost hear the masses… why not Python?

In fact, you can use Python in those areas. But even if Python is a better choice in many cases, you wouldn’t use it in HPC, since Fortran is performant-er. It may take more time to write, but sometimes code performance means everything.

You know, even that Python has evolved, wasn’t born exclusively for Physicists and Mathematicians.

As I’ve read somewhere:

At the end of the day, Physicists are writing very different programs than Computer Scientists with very different goals and concerns.

You may say that Physicists are not willing to change, or that there’s a lot of Fortran legacy code out there, but even then, Fortran keeps being the best choice for some HPC projects, or Physics calculations.

But that doesn’t mean that you can only use Fortran. Other programming languages used in HPC are C and C++, both being faster than Fortran in many cases, or the somehow-new Julia that is slowly entering the market, is also faster than Fortran and it was developed by MIT exclusively for HPC and all scientific computing.

If you want to see a detailed comparison between Python, C++, and Fortran on scientific computing, check out this amazing paper.

Top comments (0)