Source code can be in free, fixed, or tab format. Fixed or tab forms must not be mixed with free form in the same source program, but different source forms can be used in different source programs. All source forms allow lowercase characters to be used as an alternative to uppercase characters. More than one statement (or partial statement) can appear on a single source line if a statement separator is placed between the statements. The statement separator is a semicolon character (;). Consecutive semicolons (with or without intervening blanks) are considered to be one semicolon. If a semicolon is the last character on a line, or the last character before a comment, it is ignored.
1 – Free Form
In free source form, statements are not limited to specific
positions on a source line, and a line can contain from 0 to 132
characters.
Blank characters are significant in free source form. The
following are rules for blank characters:
o Blank characters must not appear in lexical tokens, except
within a character context. For example, there can be no
blanks between the exponentiation operator **. Blank
characters can be used freely between lexical tokens to improve
legibility.
o Blank characters must be used to separate names, constants, or
labels from adjacent keywords, names, constants, or labels.
For example, consider the following statements:
INTEGER NUM
GO TO 40
20 DO K=1,8
The blanks are required after INTEGER, TO, 20, and DO.
o Some adjacent keywords must have one or more blank characters
between them. Others do not require any; for example, BLOCK
DATA can also be spelled BLOCKDATA. The following list shows
which keywords have optional or required blanks.
Optional Blanks Required Blanks
---------------- ----------------
BLOCK DATA CASE DEFAULT
DOUBLE COMPLEX DO WHILE
DOUBLE PRECISION IMPLICIT type
ELSE IF IMPLICIT NONE
END BLOCK DATA INTERFACE ASSIGNMENT
END DO INTERFACE OPERATOR
END FILE MODULE PROCEDURE
END FORALL RECURSIVE FUNCTION
END FUNCTION RECURSIVE SUBROUTINE
END IF RECURSIVE type FUNCTION
END INTERFACE type FUNCTION
END MODULE type RECURSIVE FUNCTION
END PROGRAM
END SELECT
END SUBROUTINE
END TYPE
END WHERE
GO TO
IN OUT
SELECT CASE
The exclamation point character (!) indicates a comment if it is
within a source line, or a comment line if it is the first
character in a source line.
The ampersand character (&) indicates a continuation line (unless
it appears in a Hollerith or character constant, or within a
comment). The continuation line is the first noncomment line
following the ampersand. Although Fortran 95/90 permits up to 39
continuation lines in free-form programs, VSI Fortran allows up
to 511 continuation lines.
The following shows a continued statement:
TCOSH(Y) = EXP(Y) + & ! The initial statement line
EXP(-Y) ! A continuation line
If the first nonblank character on the next noncomment line is an
ampersand, the statement continues at the character following the
ampersand. For example, the preceding example can be written as
follows:
TCOSH(Y) = EXP(Y) + &
& EXP(-Y)
If a lexical token must be continued, the first nonblank character
on the next noncomment line must be an ampersand followed
immediately by the rest of the token. For example:
TCOSH(Y) = EXP(Y) + EX&
&P(-Y)
If you continue a character constant, an ampersand must be the
first non-blank character of the continued line; the statement
continues with the next character following the ampersand. For
example:
ADVERTISER = "Davis, O'Brien, Chalmers & Peter&
&son"
ARCHITECT = "O'Connor, Emerson, and Davis&
& Associates"
In VSI Fortran, if the ampersand is omitted on the continued
line, the statement continues with the first non-blank character in
the continued line. So, in the preceding example, the whitespace
before "Associates" would be ignored.
The ampersand cannot be the only nonblank character in a line, or
the only nonblank character before a comment; an ampersand in a
comment is ignored.
2 – Fixed and Tab Format
Each Fortran line has the following four fields:
Statement label field Columns 1-5
Continuation indicator field Column 6
Statement field Columns 7-72 (if you specify
the EXTEND_SOURCE compiler
option or OPTIONS/EXTEND_SOURCE,
statements extend to column 132)
Sequence number field Columns 73-80
Note: If you use the sequence number field, do not use tabs
anywhere in the source line, or the compiler may interpret the
sequence numbers as part of the statement field in your program.
2.1 – Fixed
A Fortran line is divided into fields for the required information.
Each column represents a single character.
COLUMN FIELD
------ -----
1 Indicator: Comment(C,c,*,!,blank) or Debug(D,d)
1-5 Label (any decimal integer except zero)
6 Indicator: Continuation of statement (any character
except zero or space)
7-72 Statement Field (up to column 72)
73-80 Sequence Number (optionally to column 132 -- ignored)
NOTE
This source format is obsolescent in Fortran 95.
HP Fortran flags obsolescent features, but
fully supports them.
2.2 – Tab
A Fortran line is divided into fields for the required information.
Each column represents a single character. You cannot specify a
sequence number field using this method of coding.
COLUMN FIELD
------ -----
(before tab)
1 Indicator: Comment(C,c,*,!,blank) or Debug(D,d)
1-5 Label (any decimal integer except zero)
(after first tab)
6 Indicator: Continuation of statement (any digit 1-9)
(after second tab)
Statement Field (up to column 72)
Tabs are treated as single characters.
3 – Example
The following example is valid for all source forms:
Column:
12345678... 73
_________________________________________________________________________
! Define the user function MY_SIN
DOUBLE PRECISION FUNCTION MY_SIN(X)
MY_SIN = X - X**3/FACTOR(3) + X**5/FACTOR(5) &
& - X**7/FACTOR(7)
CONTAINS
INTEGER FUNCTION FACTOR(N)
FACTOR = 1
DO 10 I = N, 1, -1
10 FACTOR = FACTOR * I
END FUNCTION FACTOR
END FUNCTION MY_SIN