Documente Academic
Documente Profesional
Documente Cultură
Lecture I
Thomas Kalscheuer
Introduction
If builders built buildings the way programmers wrote programs,
then the first woodpecker that came along would destroy civilization.
- Weinberg’s second law -
References
[metc04] M. Metcalf, J. Reid and M. Cohen: fortran95/2003 explained,
Oxford University Press, Oxford, 2004
[hahn94] B.D. Hahn: Fortran 90 for Scientists and Engineers, Arnold,
London, 1994
[intel] Intel: Intel Fortran Language Reference,
http://developer.intel.com, 2005-
• gfortran:
As part of gcc it comes with GPL. Due to gcc backend, almost all
current hardware/OS platforms supported. Forked from g95.
Unfortunately, still in a relatively premature status.
Link: http://gcc.gnu.org/fortran/
Links
• Michael Metcalf’s Fortran 90 CNL Articles:
http://wwwasdoc.web.cern.ch/wwwasdoc/f90.html
• Blanks:
Blanks generally ignored by compiler, i.e. use them to make your
code more legible. Be aware: blanks not allowed within tokens
like keywords (e.g. end, program, print, etc.), variable names,
labels, constants, operators and separators.
Blanks are also used for indentation of program lines.
• Comments:
Any characters appearing after exclamation marks (!) are
comments and ignored by the compiler. Use them to explain
your code!
• Continuation lines:
If a line becomes too long it can be continued on the next line by
using an ampersand (&) as the last non-blank character:
print *, "This is a very long line and it does", &
" not just print: Hello, world!"
• Case:
FORTRAN is not case sensitive, e.g. end is the same as END
• Non-numeric:
1. character defines strings, e.g. ’John Smith’, "Course duration"
Type declaration with:
character :: name
2. logical has one of two values, i.e. either .true. or .false.
Type declaration with:
logical :: test_finished
Definition of constants:
through the parameter attribute, e.g.
real, parameter :: pi = 3.1415926
Implicit typing:
is a relic of the old days. If implicit typing is switched on (which is
the default!), variables that are not explicitly declared and start with
i-n or I-N are assumed to be integers and all others are assumed to be
real. Typing errors in variable names may lead to unexpected
program behaviour.
You should always switch off implicit typing at the start of your
programs with implicit none. As a consequence you have to
declare all variables explicitly.
operator action
** exponentiation
*, / multiplication, division
+, - addition, subtraction
Numeric expressions:
• integer: truncated towards zero
10/3 evaluates to 3
• Example:
real :: alpha ! angle in degrees
real, parameter :: pi = 3.1415926
alpha = 90.0
print *, "cos of alpha is ", cos(alpha*pi/180.0)
real :: a
a = 0.05
print *, "value of a:", a
implicit none
! constant pi
real, parameter :: pi = 3.141592687
! radius and surface area of sphere
real :: radius, surface_area