A brief introduction to Fortran –
To help the transition from MATLAB to Fortran
What is Fortran?
Tip: Skim through the wikipedia article !
Historically it is the language of choice for scientific
computing. That is, if you want to use, modify and
develop scientific code you better know a little bit
For floating point operations it is extremely fast*.
Approximately C = 2 fortran, C++ = 4 fortran**.
Matlab is generally much much much worse.
* = If you use the best compilers, else it is just very fast.
Unfortunately the best are all commercial, but they are usually for
free when used for non-comercial purposes ( e.g. by students
and for science). The open scource compilers still make fortran
at least as fast as C for floating point operations.
**= For a long list of “fortran over C”-advantages see:
Run own code that does this (and some more):
● Reads about 700 MB of input
● Computes 80200 double integrals of the form
numerically exact and stores the information in a
● All this is done in double precision
Which version of fortran should I use?
A lot (!) of usable code is written in fortran77 so it is good to
know the syntax.
However, fortran 90, 95 and 2003 have a lot of pros if you
are about to write new code.
Some examples of pros for fortran 90/95 and 2003 compared
to fortran 77 are:
● free format
● dynamic allocation
● array programing (compare matlab)
● object based/object oriented programming
A small warning:
The different variants of Fortran are
open standards and therefore one code might
be functioning with one compiler but not with
If you stick as close to the standard as
possible this problem is minimized.
When do I use MATLAB
(or similar e.g. python with pylab)
and when do I use Fortran?
This is how I do it:
● Start out with MATLAB (it is generally faster to code
or at least easier to play around with)
● If I notice that computations take to long time, I
translate the code to Fortran.
● Write results to file
● Use MATLAB to analyze, interpret and plot the
● For larger codes, I manage input and output with
python, do the computationally heavy stuff in
fortran, and plot in python/MATLAB
Some useful (?) links
● You will find everything in this lecture here:
● Free books on fortran:
● Learning Fortran 90 by examples
● For those who which to take a glance at python: