Class Information: 2024
- Instructor: Prof. Paul Tackley, room NO H9.1, ptackley@ethz.ch, 044 633-2758
- Schedule:
16:15-18:00 Mondays from 23.09-16.12.2024 (13 lectures)
- Grading: 3 KP on weekly assignments (hand in to ETHFortran@gmail.com); 1 KP (optional) on a semester project - writing a program for a scientific application to be agreed upon individually.
- Project: Some instructions on the optional 1 KP project are here.
- Description: FORTRAN
(95/2003/2008/2013/2018) is a modern programming language
that is specifically designed for scientific and
engineering applications. This course gives an
introduction to programming in this language, and is
suitable for students who have only minimal
programming experience, for example with MATLAB
scripts. The focus will be on Fortran 95 and its more
recent extensions (2003/2008/2013/2018), but differences to
Fortran 77 will also be briefly covered for those working with already-existing codes. A hands-on approach will be emphasised rather than abstract concepts, using example scientific problems relevant to Earth science.
- Computing requirements: A computer is needed during lectures. Please bring your own laptop with a suitable Fortran95 compiler installed (see below; installation help will be available in the first class). A computer is also needed to finish the weekly assignments.
- Books etc.: There is no
required book, but a book might be useful. Class notes
(posted here each week) + free online tutorials listed
below + a free reference manual (such as the one
listed below downloadable as PDF from Intel) might be
sufficient. If you would like a book, two that get
good reviews are: "Fortran for Scientists and Engineers" by Stephen J. Chapman, or "Modern Fortran Explained" by Michael Metcalf, John Reid, and Malcolm Cohen. Alternatively, look in a good technical bookstore for something that seems well written and easy to follow.
Fortran compilers
The most convenient way to do the exercises is on your own computer after installing a
compiler. The main choices are listed
below. gfortran is the most
universal/popular, is completely free and can be used
on Windows, MacOSX or Linux. The
Intel compiler is probably the best
compiler, is available free to individuals, and also works on Windows, MacOSX and Linux.
gfortran: Developed by the GNU,
the free software foundation. See http://gcc.gnu.org/wiki/GFortran.
- Linux: One of the optional packages to install.
- MacOSX: Install (i) Xcode (from App Store), (ii)
XCode command line tools, (iii) gfortran from http://hpc.sourceforge.net
or https://brew.sh. A good guide to this process is here.
- Windows: There are 3 main possibilities:
(i) Install MinGW, which allows you to use gfortran
inside a Command Prompt window. Follow these
instructions, being sure to edit your path.
(ii) Install Cygwin, which provides a unix-like
environment in which you can use gfortran
(www.cygwin.com - make sure to select fortran during
the installation process; your files can be found in
C:\cygwin64\home\yourname).
(iii) Install Microsoft's Windows Subsystem for
Linux (WSL), which allows you to run a full Linux
installation at the same time as Windows, as discussed
here
and here.
Intel Fortran Compiler: This is
available either (i) free to everyone directly from
Intel as part of the oneAPI HPC Toolkit (here),
which can optionally use an Application Programming
Interface such as
Visual
Studio 2019 (make sure to install "Desktop
development with C++") or Visual
Studio Code (ii) free to ETH
employees (e.g. doctoral students) from
the
IT shop.
A good editor that highlights Fortran syntax is also very
useful. Emacs is a good one: for Mac the Aquamacs
version is nice, for Windows download the emacs-w64
version. Another suitable one for Windows is Kate.
Free resources on the internet
1. A manual. A good one is the Intel Fortan Language Reference Manual.
2. Tutorials
3. General information and/or pages of links to relevant sites
4. Unix tutorials (if using MacOS,
Linux or Windows+Cygwin)
Provisional schedule (including exercises)
|
Fortran Topics |
Numerical Topics |
1 (23.09) |
History, basics, simple programs |
|
2 (30.09) |
More basics, interactive I/O, do loops, functions&subroutines |
Finite differences |
3 (07.10) |
Modules, ascii file I/O, Array functions, assumed size arrays. |
1-D & 2-D diffusion equations |
4 (14.10) |
Precision, formatted I/O. |
Streamfunction. Upwind advection. 2-D advection-diffusion. |
5 (21.10) |
Derived types. Keyword&optional arguments. Character string manipulation. Recursive functions. |
Iterative & multigrid solvers. Jacobi & Gauss-Seidel iterations. Program 2D Poisson solver. |
6 (28.10) |
Binary I/O. |
Convection (2-D, infinite-Prandtl). |
7 (04.11) |
Makefiles. Intrinsic functions. Pointers. Writing fast code (optimisation). |
|
8 (11.11) |
Pure procedures, elemental
procedures, generic procedures, operators and overloading. |
Finite (low) Prandtl number convection. |
9 (18.11) |
Parallel computing (MPI & Co-array) |
|
10 (25.11) |
Object-oriented programming |
OOP exercises |
11 (02.12) |
Other new features |
Restructure convection using OOP |
12 (09.12) |
Useful libraries. Summary and review. |
Implicit time-stepping |
13 (16.12) |
Finalisation of exercises. |
|