Introduction to Fortran#

ADD MORE HELPFULL LINKS TO THIS PAGE
ADD MASTER TOC OR WEB TREE THING
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-literalinclude
BLOCK construct not inlcuded in Basic Program section yet
MASTER EX LIST? - like sphinx-lesson?

This book is designed to introduce you to the basics of modern Fortran and good software engineering practices. It is heavily inspired by the work of Katherine Holcomb [Holcomb, 2008].

Fortran was created in 1957 by a team at IBM and excels with numerically intensive science code. Far from the punchcards, and fixed-form formatting of Fortrans early days, modern Fortran is fast, and since the Fortran 2018 update natively parallel. It is often used to write numerical code for High Performance Computing (HPC).

Getting Started#

This book includes practice exercises and solutions for you to work on in each chapter. You can download a zip file containing instructions and skeleton files for the exercises here. The first few lessons can be explored using the built in interactives and on your local machine. The next sections explain how to use the interactivity and work locally.

Interactives#

The first few lessons in this book contain interactive elements which don’t require you to have a fortran compiler installed locally, although the first exercises will require a local fortran compiler. Through the power of the open-source projects Jupyter and LFortran you can compile and run Fortran code in the browser.

Try it out:

Interactive

This card marks an interactive section. To activate interactivity for the page:

  • click on the top right icon
  • then click on Live Code

You should now see a run button. Click on it!

print *, 'I <3 Fortran'

If you receive an error message trying to run a cell click on restart & run all to restart the interactive Fortran kernel. Later lessons in this book aren’t interactive so you wont see the rocket icon. You will need to ensure you have a Fortran compiler installed, see Working Locally below.

Working Locally#

The exercises in this book were tested on Linux and compiled with both the gfortran5 and ifort compilers. We recommend you create a conda environment with:

  • fortls, the Fortran language server
  • gfortran, the GNU Fortran compiler

You can also use our fortran.yml file to create the same environment we used to test this book. Our test environment also includes python packages for visualising some exercise solutions and doxygen, a document generation package. If you’d like to use Intels ifort compiler you can download ifort from their website.

We hope you enjoy learning Fortran using these resources. If you spot any errors or have ideas to improve the book please contact dt @ dt.com.