# Numerical Modelling in Fortran day 8

Document Sample

```					Numerical Modelling in
Fortran: day 8
Paul Tackley, 2009
Today’s Goals
1.  Fortran: Learn new things: generic
intrinsic functions.
2.  Programming: Get timestepping,
poisson solver and convection program
working.
Generic procedures
(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
next slide).
•  Easiest way: in a module
generic
interface
apbxc

to functions
rapbxc and
iapbxc

Program
using this
generic
function
procedure name is used to refer to several
procedures: which one is used depends on
the variable types.
•  Examples
–  apbxc is overloaded with rapbxc and iapbxc
–  *,+,-,/ are overloaded with integer,real,complex
versions in different precisions
•  You can overload existing operators, or
procedures
Useful for
defined types
Defining
new
operator
.distance.
Useful for
conversion
between different
types: in this case
point to real.

Must use
subroutine with
1st argument
intent(out) and
2nd argument
intent(in).
Intrinsic functions
•  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
•  http://www.nsc.liu.se/~boein/f77to90/
a5.html
•  This doesn’t list cpu_time(), which is
useful for checking how long parts of the
code take
Now work on programs
tested using given solution (slide 4 of
Class6.pdf)
•  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
Class7.pdf)

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 13 posted: 5/1/2010 language: English pages: 10