Fixed form is the layout of the punched card. FORTRAN 66 and FORTRAN 77 had only this form;
Fortran 90 added free form and kept fixed form, which the standard has
called obsolescent since Fortran 95 and which every compiler still reads. It is the form of
.f, .for, .ftn and .f77 files. The rules below are from the FORTRAN 77 standard
(ANSI X3.9-1978, section 3) and the later standards, which kept them and added to them.
The columns
| Columns | Use |
|---|---|
| 1 | A C or * makes the whole line a comment. Fortran 90 also allows !, and compilers allow a lower-case c |
| 1 to 5 | An optional statement label: one to five digits, from 1 to 99999. Labels need not be in order, and a label may be used once in a program unit. Blanks inside the label are ignored |
| 6 | Blank or 0 on the first line of a statement (the initial line). Any other character on a continuation line |
| 7 to 72 | The statement |
| 73 to 80 | Ignored by the compiler. The standard has lines of 72 characters; these columns held the card’s sequence number or an identification, so that a dropped deck could be sorted again |
C COMPUTE THE MEAN OF N VALUES
SUBROUTINE MEAN(X, N, XBAR)
INTEGER N, I
REAL X(N), XBAR, S
S = 0.0
DO 10 I = 1, N
S = S + X(I)
10 CONTINUE
XBAR = S / REAL(N)
WRITE (*, 100) 'MEAN =',
& XBAR
100 FORMAT (1X, A, F10.4)
RETURN
END
&) in column 6.Comment lines
C,cor*in column 1: the rest of the line is a comment (FORTRAN 77, section 3.2.1: aCor an asterisk in column 1)- a line with only blanks in columns 1 to 72 is a comment line, so a blank line is allowed anywhere
!in column 1, or in any other column except 6, outside a character literal, starts a comment that runs to the end of the line (Fortran 90 and later; many FORTRAN 77 compilers allowed it as an extension)Dordin column 1 is a debugging line in the DEC family of compilers: a comment unless the compiler is told to compile debug lines (GNU Fortran:-fd-lines-as-code; the default is comment). It is not in any standard- Comment lines may come between an initial line and its first continuation line, or between two continuation lines (3.2.1)
- a
Cin column 1 followed by a name is still a comment:CALLin column 1 is not a statement. Tools put markers there (cf2py,CDEC$,C$OMP); see Directives and preprocessor
Continuation
A continuation line has a character other than a blank or 0 in column 6, and blanks in columns 1 to 5. The
statement goes on from column 7. Any character may be the mark; &, +, *, $
and the digits 1 to 9 are the usual ones. The limits:
| Standard | Continuation lines per statement |
|---|---|
| FORTRAN 77 | 19 (3.2.3), with at most 1320 characters in a statement (3.3) |
| Fortran 90 and 95 | 19 in fixed form |
| Fortran 2003 and later | 255 |
An END statement is written on one initial line and is never continued, and no other statement may start with
something that looks like END on its initial line (3.3). A character literal can run over a line break: it goes
on at column 7 of the continuation line, and a short first line counts as padded with blanks to column 72.
Blanks mean nothing
Outside character literals, Hollerith constants and the H and apostrophe edit descriptors, a blank has no meaning at all
(3.1.6). The same statement can be written in several ways, and a compiler tells which keyword it has by the statement as a whole:
GO TO 10
GOTO 10
DOUBLE PRECISION X
DOUBLEPRECISIONX
DO 10 I = 1, 10
DO10I=1,10
DO10I=1.10
DO10I: a comma, not a period, makes a DO.This is why Fortran has no reserved words, and why highlighters of fixed form must read the statement before colouring its first word.
The viewer takes the blank-free text of a statement’s first line, decides whether it is an assignment (a name, subscripts and an =), and if not
colours the leading keywords: GO TO, DOUBLE PRECISION, END IF, ELSE IF and the rest, each as one span even when there are blanks inside.
Tab format (DEC)
The DEC compilers of VAX and Alpha, and Intel Fortran, GNU Fortran and others after them, accept a form that makes a terminal easier to type on:
- a tab in the first six columns ends the label field. The label is what comes before it, and the statement starts after it
- if the character after the tab is a digit from
1to9, the line is a continuation line and the digit is the mark, and the statement goes on after the digit - otherwise the line is an initial line whose statement starts straight after the tab
Compilers differ in how they count columns for the 72-column cut after a tab; the viewer does not cut tab-format lines.
Text after column 72
The standard says text after column 72 is not part of the line. GNU Fortran drops it (its default
-ffixed-line-length-n is 72 and the other documented values are 80, 132 and none); Intel Fortran and others have an option for 80 or
132. Many modern fixed-form files hold code beyond column 72, for compilers set up that way. The viewer follows the standard with one guess:
- a line of 80 characters or fewer that has text after column 72 shows that text as a comment (it is a sequence number, or a mistake that a standard compiler would also ignore)
- a line longer than 80 characters is read as code in full
What changed with the standards
- FORTRAN 66 (ANSI X3.9-1966) used the same card columns.
Cin column 1 was the only comment mark. - FORTRAN 77 described the layout in section 3 of the standard; the details are above. A blank line was a comment line.
- Fortran 90 added
!comments and the;statement separator. It also added the new free form, and described fixed form as one of two source forms. - Fortran 95 declared fixed form obsolescent. The standard keeps the form and every compiler reads it. Fortran 2018 and 2023 still describe it.
- Fortran 2003 allowed 255 continuation lines in fixed form.
What the viewer colours
- comment lines and sequence-number text as comments;
!comments after code - the label in columns 1 to 5 as a number; the column-6 mark is left plain
- sentinel comments (
C$OMP,*$ACC,CDIR$,CDEC$,!$OMP) as directives; aC$line as a directive mark followed by code #lines of the preprocessor and$metacommand lines ($DEFINE) as directives- strings that go on over a continuation line