PHY201 - Worksheet 1, F00

Due Friday Sept. 8th 5pm

Physics 201 home

Background

FORTRAN (FORmula TRANslation) remains the workhorse of scientific computing. The majority of existing codes for scientific simulation are in fortran, many still in the old Fortran 77 standard. Fortran 90 contains many important improvements over Fortran 77. Fortran is a continuously evolving language, and a great deal of ``backward compatability'' is maintained. Only the most odeous of old constructs are explicitly removed in the recent versions of Fortran.

Here is a brief history of Fortran: 1954, Fortran I; 1958, Fortran II; 1958, Fortran IV; 1966, Fortran 66 standard; 1978, Fortran 77 standard; 1991, Fortran 90(and HP) standard; 1996, Fortran 95 standard; 2001, Fortran 2000(expected). You need to understand the main features of Fortran 77 through Fortran 95, as in looking at existing codes, you will find a variety of different constructs drawn from these standards. The Fortran 77 and Fortran 90 standards contain the majority of constructs and so the handout covers these two standards quite extensively, as well as referring to a few features of Fortran 95 and High Performance Fortran (HPF). HPF is a superset of Fortran 90 and is designed to take full advantage of parallel computing architectures. The first thing to do however is to learn Fortan 90, which provides many of the contstructs which modern compilers can automatically optimize for parallel platforms. We shall thus concentrate on Fortran 90.

Although Fortran is often criticized and is sometimes referred to as the ``programming language of the past'', it remains the most efficient language for large-scale scientific computing. The ``Object-Oriented-Programming'' (OOP) revolution (e.g. C++ and more recently Java) have not superceded Fortran, as the modern Fortran standards incorporate many of the most useful features of OOP. OOP attempts to enable maximum transferability of code, so that in C++, subunits are placed in ``CLASSES'' which can be included in a variety of larger programming units. In the Fortran 77 standard FUNCTIONS and SUBROUTINES do some of this, but their transferability is limited. Fortran has responded by introducing MODULES which do provide many of the features of CLASSES. You should also note that the performance of C++ and Java in large scale computing is also continuously improving as the compilers for these programming languages are being optimized for scientific computing.

Though the above list of programming languages seems overwhelming at first, learning a new programming language in not a difficult task, once you have learned one of them well. In fact Mathematica is in many ways a programming language and many of the contructs used there appear in Fortran and/or C,C++, Java. For example the ``DO'' and ``IF'' statements appear in Fortran, though in somewhat different forms. In general Mathematica is less efficient for large-scale calculations, but is very useful for smaller calculations.

To get started, read the first 10 pages(up to the discussion of the WRITE statement) of the fortran manual (a hardcopy is available in rm346G). Also look at the files:

1. sample file 1 which prints out ``Hello World'' three different ways.

2. sample file 2 which finds the sum of the first 100 integers.

First set of coding tasks (due Friday 8th Sept. at 5pm)

1. Write a Fortran code which prints out your name.

2. Write a Fortran code which calculates and prints out the sum of Sin^2(i), for three cases: Where i runs over the first 3 integers; where i runs over the first 10 integers; where i runs over the first 100 integers.
(Check your answers by doing the same sums using Mathematica - also hand in the Mathematica code.)

Other things you need to know

(0) yppasswd - change your password (and remember it!!!)

(i) gEdit - You can use this to edit files

(ii) g77 - Use this to compile your fortran program e.g. g77 -o test.exe test.f
This generates the executable and writes it onto test.exe.
If you do not specify a destination file e.g. g77 test.f
The executable is written onto the file a.out.

(iii) How to run an executable - Type ./test.exe (or ./a.out)
The ./ specifies the PATH to the fortran directory. On many computers it is not necessary to specify the path, but with the current setup in rm346G you need to specify the path.