Intermediate Modern Fortran

Key Points

Connecting to ARCHER2 and transferring data
  • We should all understand and follow the [ARCHER2 Code of Conduct][archer2-tcoc] to ensure this course is conducted in the best teaching environment.

  • The course will be flexible to best meet the learning needs of the attendees.

  • Feedback is an essential part of our training to allow us to continue to improve and make sure the course is as useful as possible to attendees.

  • ARCHER2’s login address is login.archer2.ac.uk.

  • You have to change the default text password the first time you log in

  • MFA is mandatory in ARCHER2

Arrays
  • Fortran supports both static- and dynamic-sized arrays

  • Fortran arrays are objects, allowing out of bounds accesses to be checked

  • The bounds of an array can be set by the programmer

Arrays as arguments
  • Arrays passed as arguments retain their size, not their bounds

  • Array arguments behave as though passed by reference, however array sections may require copy-in, copy-out

More on pointers
  • Fortran pointers describe what they are pointing to, not only its address.

  • We must take care when programming with pointers to avoid aliasing.

  • Procedure pointers create a binding between a variable and a procedure.

Derived types
  • Derived types enable creating custom data structures in Fortran.

  • Access to components of derived types can be controlled via the private attribute.

Interfaces and overloading
  • Interfaces allow us to write generic, high-level code.

  • Designing a generic interface requires care, particularly for generic operators.

Type extension and polymorphism
  • Fortran supports polymorphism through the class pointers and allocatable objects.

  • Types can be selected dynamically to support type-specific behaviours

Type-bound procedures
  • Type-bound procedures allow Fortran objects to implement behaviour

  • Redefining type-bound procedures allows behaviour to be specialised

  • Types can prevent extended types from redefining type-bound procedures

  • Generic type-bound procedures enable generic methods on types

Generic input/output for derived types
  • Defined types can control how they are printed using type-bound procedures

Abstract types
  • Abstract types allow Fortran programs to specify and use interfaces that are then provided by concrete implementations.

Modules again
  • Submodules provide the mechanism to separate interface and implementation in Fortran

Unlimited polymorphic entities
  • Unlimited polymorphic entities provide a void *-like type in Fortran

  • Without determining the unlimite polymorphic entity’s dynamic type, it cannot be used

Type parameters
  • The kind of a user-defined type must be known at compile time (as for intrinsic types)

Intrinsic modules
  • The iso_fortran_env intrinsic module provides constants and functions that enable code portability

  • The IEEE intrinsic modules allow programs to check the conformance with IEEE features

Interoperability with C
  • The iso_c_binding module allows a programmer to write Fortran that is interoperable with C.

  • Care must be taken with pointers and arrays, and with variables which are to be passed to C by value.