This lesson is in the early stages of development (Alpha version)

Intermediate Modern Fortran

Description

Fortran (a contraction of Formula Translation) was the first programming language to have a standard (in 1954), but has changed significantly over the years. More recent standards (the latest being Fortran 2023) come under the umbrella term “Modern Fortran”. Fortran retains very great significance in many areas of scientific and numerical computing, particularly for applications such as quantum chemistry, plasmas, engineering and fluid dynamics, and in numerical weather prediction and climate models.

This intermediate course concentrates on some of the more recent features which are central to Modern Fortran. Attendees should be familiar with the basics of Fortran programming which might be covered in an introductory course, e.g., the one at,

https://epcced.github.io/2025-05-19-MO-Fortran-intro/

So, attendees should be comfortable writing structured Fortran programs based on modules and procedures, and have a sound grounding in variables, logic, flow-of-control, and so on. Some knowledge of Fortran I/O is assumed.

There are two main topics in this intermediate course: the facilities in Fortran for abstraction and polymorphism provided by classes and interfaces, and the facilities for formal interoperability with ANSI C. The course will cover type extension (“classes” and “inheritance”), type-bound procedures (“methods”), generic procedures (“polymorphism”), and so on. The standard iso_c_binding module provides facilities for interoperability with C; this allow the communication of Fortran entities with direct analogues C, and also Fortran objects (particularly arrays) which have no direct analogue in C.

Further language features concerning arrays, pointers, and facilities for structured programming using submodules will also be covered along the way.

Knowledge of the object-oriented paradigm would be useful, but is not essential. Knowledge of C is required for the material on C/Fortran interoperation. The course will allow programmers interested in working on larger, structured, software projects to make use of (almost) a full complement of Modern Fortran features.

The course requires a Fortran compiler, for which a local machine or laptop may be appropriate [1]. If you do not have access to a Fortran compiler, course training accounts on ARCHER2 will be available which provide access to various compilers. Use of a text editor will be required (some may prefer an IDE, but we do not intend to consider or support IDEs).

[1] This may typically be gfortran, freely available as part of the GNU Compiler Collection (GCC). See e.g., https://gcc.gnu.org/wiki/GFortranBinaries


General Information

Requirements: Participants must have a working laptop or desktop computer with a Mac, Linux, or Windows operating system (not a tablet, Chromebook, etc.) that they have administrative privileges on. They should have access to a terminal (Mac and Linux users should have a terminal installed by default; Windows users should get either MobaXterm or PuTTY. They are also required to abide by the ARCHER2 Training Code of Conduct.

Accessibility: We are committed to making this workshop accessible to everybody. Materials will be provided in advance of the lesson and large-print handouts are available if needed by notifying the organizers in advance. If we can help making learning easier for you (e.g. sign-language interpreters, lactation facilities) please get in touch (using contact details below) and we will attempt to provide them.

Contact: Please email for more information.


Prerequisites

You should have used remote HPC facilities before. In particular, you should be happy with connecting using SSH, know what a batch scheduling system is and be familiar with using the Linux command line. You should also be happy editing plain text files in a remote terminal (or, alternatively, editing them on your local system and copying them to the remote HPC system using scp).


Schedule

Setup Download files required for the lesson
Day 1 10:00 1. Connecting to ARCHER2 and transferring data What can I expect from this course?
How will the course work and how will I get help?
How can I give feedback to improve the course?
How can I access ARCHER2 interactively?
10:40 2. Arrays How are arrays declared?
How can array sizes be determined at runtime?
11:00 3. Break Break
11:30 4. Arrays as arguments How are arrays passed as arguments?
How are array slices passed as arguments?
How do allocatable array arguments interact with argument intent attributes?
12:00 5. More on pointers How are pointers associated with data?
How can pointers be used to access arrays?
How can pointers be associated with procedures
12:30 6. Lunch Break
13:30 7. Derived types How are data structures (derived types) defined in Fortran?
How can we control access to components of data structures in Fortran?
How does assignment between derived types work?
14:00 8. Interfaces and overloading How are interfaces used for generic programming?
14:45 9. Break Break
15:00 10. Type extension and polymorphism
15:30 11. Type-bound procedures
16:00 Finish
Day 2 10:00 12. Generic input/output for derived types
10:20 13. Abstract types
10:40 14. Modules again
11:00 15. Unlimited polymorphic entities
11:20 16. Type parameters
11:40 17. Intrinsic modules
12:00 18. Interoperability with C
12:20 Finish

The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.