Skip to main content Skip to navigation

Fortran for Researchers

Aims

While it has a long history, Fortran is by no means a dead language and modern Fortran is a thoroughly modern language. While still the preeminent language of high performance computing in the exascale era, it is also a more forgiving and quicker to learn alternative to C or C++. Fortran has many helpful features that make it a good language for people who need higher performance to learn when moving from interpreted languages like Python or Matlab. This course assumes that you are familiar with the basic concepts of computer programming but have no knowledge or Fortran or compiled languages in general. It introduces how to implement basic elements like loops, conditionals and functions in Fortran, introduces Fortran's extremely powerful arrays and also briefly describes Fortran's more powerful features such as optional arguments and object oriented programming.

Sign up

This course is being run again on the 25th of September 2023.

If you want to attend this course for SkillsForge credit then please sign up for course RSE/7 on SkillsForge. Otherwise, please fill in this form.

Session Details for 25th September 2023

If you are signed up you should have now (19/9/23) received an email with details of when and where this course will run. Please contact us if you have not.

If you are attending remotely, or want to review the live stream, here is the link again: https://youtube.com/live/GXRmEnbiafcLink opens in a new window

Slides

Part 1 - Fortran BasicsLink opens in a new window

Part 2 - ArraysLink opens in a new window

Part 3 - Last EssentialsLink opens in a new window

Part 4 - Other Parts of FortranLink opens in a new window This briefly covers almost all the rest of Fortran you might want to use. We don't talk through this, but we do demonstrate it all in the Model codes linked below.

Example Code

All of the example code from the slides, and suggestions and model solutions for programs from Hello World up to almost useful codes are available on Github here.

Other Useful Links and Material

Documentation Tools

HereLink opens in a new window is our Github repo demonstrating how to use the Doxygen documentation tool to make good Fortran docs.

Books Etc

Some "cheatsheet" summaries of the fiddlier parts of Fortran are here along with a description of "Old" (pre 90) Fortran, which you might still come across "in the wild".

Our recommended book for Fortran is Introduction to programming with Fortran : with coverage of Fortran 90, 95, 2003, 2008 and 77 by Ian D. Chivers, Jane Sleightholme. You can find the Springer e-Book in the library (ISBN 9783319177014).

This is a really nice "self-study" guide to Fortran 95 (reproduced w. thanks to Dr Padman)

Online Resources

Doctor Fortran - Steve Lionel worked on Intel's Fortran compiler team for years, and knows Fortran as well as anybody possibly can. He has a series of blog posts, and pops up on Stack Overflow, Intel's developer zone and elsewhere.

Learn X in Y minutes is a handy site for just the syntax and ideas of a new language. Written like a program listing, these go through the basics. They can be a bit intense in a language you've never seen before though.

Rosetta Code is an attempt to compile lots of people's approaches in lots of languages. BEWARE though - nobody reviews these for style. They mostly work as expected, but can suffer from being too clever by half, especially in Fortran, in which you also have to watch out for FORTRAN77 and what are now "bad habits" engrained by it.

The Computer Language Benchmark game has some good examples of how the Fortran you would write as your first solution can actually be almost optimally performant already. In particular, the Fortran examples tend to be much simpler than the hand-optimised C, while getting 90% or more of the performance in the numerical problems. The String problems do not suit Fortran and for some reason the Binary Trees problem also works poorly (possibly the recursion is troublesome?).

Videos

We have some videos on a few of the fiddlier bits of Fortran:

Creating a module, step by step

The Application Binary Interface. Can compilers talk to each other? What about languages? How?

What interfaces are and why they're used

Reading the Fortran Standard document - what does x = func1() * func2() do?