Next: Declaration of Variables
Up: A quick tour of
Previous: Program Form
  Contents
In Fortran 95 the code layout is obeys
the following rules, which describe the ``free source form''.
- statements can begin in any column;
- multiple statements on a line are allowed; they have to be separated
by semicolon ``;''
- an exclamation mark ``!'' in any column is the
beginning of a comment;
the rest of the line is ignored by the compiler;
- a statement can be continued on the following line by
appending a ``&'' sign on the current line.
For example, the above code fragment could be
written in free source form as
language=[95]Fortran
visiblespaces=true
! This is free-form
temp = x; x = y; y = temp ! Swap x and y
write(6,*) 'x and y are =', &
x,y ! Print x and y
visiblespaces=false
For back-compatibility with Fortran 77,
Fortran 90 accepts a ``fixed source form''.
In short, the fixed source form requirements are:
- all lines of code start in the (or higher) column;
the first
6 columns are reserved for labels, continuation characters, etc.
- each statement is written on a separate line (i.e., statements are
separated by newlines); a statement can be continued on the next line
by writing (any) character in the column of the new line;
- comment lines start with a C in the first column.
Fixed format was born in 1950's, when each line of code
was punched on a paper card (``punched card''). For debugging
and maintaining the code it was clearly easier to have one statement per card.
When running, a
punched card had to be aligned, checked if it is a new statement or
a continuation of the last, if it is a comment, etc. - lots of
information stored in the first 6 columns.
(A million-line code,
quite common today, on punched cards, needed a truck to
be carried from one computer to another).
For example, a fragment of a Fortran 90 program in fixed source form
(in fact, Fortran 77 program)
can be:
C---This-is-fixed-form
C---Swap x and y
temp = x
x = y
y = temp
C---Print x and y
write(6,*) 'x and y are =',
* x,y
Our compiler (f90) will consider the program
to be in fixed source format if the source file has the extension `` .f''
(for example, my_program.f).
The compiler will consider the program
to be in free source format if the source file has the extension `` .f90''
(for example, my_program.f90).
Note that a free format source in a .f file may result in compilation
errors.
Next: Declaration of Variables
Up: A quick tour of
Previous: Program Form
  Contents
Adrian Sandu
2001-08-26