Numerical Modelling in
Fortran: day 8
Paul Tackley, 2009
1. Fortran: Learn new things: generic
procedures, overloading, new operators,
2. Programming: Get timestepping,
poisson solver and convection program
(i.e., using a generic name to access different procedures)
• e.g., the intrinsic (built-in) sqrt function.
There are several versions: sqrt(real),
dsqrt(double precision), csqrt(complex).
Use the generic name and the correct one
will automatically be used.
• You can define the same thing. Define
similar sets of procedures then define a
generic interface to them (see example
• Easiest way: in a module
• Overloading means that one operator or
procedure name is used to refer to several
procedures: which one is used depends on
the variable types.
– apbxc is overloaded with rapbxc and iapbxc
– *,+,-,/ are overloaded with integer,real,complex
versions in different precisions
• You can overload existing operators, or
define new overloaded operators or
Overloading existing + and –
types: in this case
point to real.
• There are many more intrinsic functions
than we have used!
• It is good to browse a list so that you
know what is available, for example at
• This doesn’t list cpu_time(), which is
useful for checking how long parts of the
Now work on programs
• Advection-diffusion (ex5) working and
tested using given solution (slide 4 of
• Poisson solver (ex6) working and tested
using given solution (slide 32 of Class6.pdf)
• Convection (ex7) combining both of these,
tested using given solution (slides 16-17 of