FORTRAN-SO
PROGRAMMING
MANUAL
Manual
Order
Number: 9800481 A
Copyright
Intel
I
Corporation,
3065 Bowers Avenue, Santa Clara,
© 1978 Intel
Corporation
California
95051
. I
The information in this
document
is
subject to change without notice.
Corporation
Intel
to, the implied warranties
makes
no
warranty
of
merchantability
of
assumes no responsibility for any errors
commitment to
part
No
written consent
The following are
and the combination
Additional copies
Literature
Intel
update
of
this
document
of
ICE
iCS
In
site
Intel
Intellec
Department
Corporation
nor
to keep current the
may be copied
Intel
Corporation.
trademarks
of
of
of
Intel
ICE, iCS, iSBC, MCS,
this
manual
Corporation
or
other
3065 Bowers A venue
Santa Clara,
CA
95051
any kind with regard to this material, including,
and
that
or
fitness for a particular purpose. Intel
may
appear
information
reproduced in any form
iSBC
Library
MCS
Megachassis
Micromap
Multibus
or
in this document. Intel
contained in this document.
or
by any means without the prior
and
may be used only
Manager
to
RMX and a numerical suffix.
describe
PROMPT
Promware
RMX
UPI
",Scope
Corporation
Interproducts:
Intel literature may be obtained from:
but
not
limited
Corporation
makes no
ii
PRINTED
IN
U.S.A./A151/1279/5K
CP
This
manual
for
programming
ANSI
FORTRAN
FORTRAN
sions
of
FORTRAN
describes the Intel-developed
the 8080
77
77
full language;
and
8085 microcomputers.
subset. In some instances, it
FORTRAN-80
77.
FORTRAN
also has features
language (FORTRAN-80)
FORTRAN-80
incorporates
is
based
features from the
that
exceed
both
PREFACE
on
the
ver-
Appendix
found
features
features are clearly
not
tability
The
or
extensions related to a
for
operator's
system environments (such as ISIS-II
The experienced
reviewing the summaries in the appendixes
should
programming
a
Chapter
Chapter
statements in detail. These statements
lustrative examples.
programming
ing
as
TRAN
bibliography
D lists
in the
that
be used
among
FORTRAN-80
that
compiler. They are summarized in Appendix F
read it
1 has a
2 introduces
a science. We also suggest
tutorials. Some recommended
FORTRAN-80
FORTRAN
go
beyond
if
you
processors.
manual
through
reference, it does contain some instructional material.
short
techniques
at
the end
both
marked
want
to preserve total compatibility with
language
particular
also includes considerations when running in different
FORTRAN
from the beginning. While the
program
FORTRAN
Chapter
and
of
extensions to the
77
full set;
versions
in the text
is
described in its entirety in this
programmer
designed
7 suggests some guidelines for improving
recommends sources for further study
that
Chapter
it
of
FORTRAN
of
this
compiler
and
RMX-80).
to
provide
concepts.
are
grouped
the beginning
introductory
7.
FORTRAN
also lists those
77. In
manual
are
can
of
Chapters
(shadowed in grey)
described in the
possibly begin
this
manual.
manual
an
intuitive feel for the language.
3-6 describe
functionally
programmer
texts
77 subset
FORTRAN-80
addition,
FORTRAN
manual.
operator's
of
this
programming
The
is
primarily written as
and
read
are
that
these superset
and
77
Limitations
manual.
new
programmer
FORTRAN-80
include
FORTRAN
of
programm-
one
included in the
can be
superset
should
and
por-
manual
The
operating
after
brief
two
FOR-
il-
Finally, all users
necessary:
ISIS-II
ISIS-II
X3.9-1977
The latter
The
1430 Broadway
New
10018
FORTRAN-80
System
American National
York, New York
User's
FORTRAN
document
of
this
Compiler
Guide
can
manual
Operator's
be
ordered
Standards
should refer to the following
Manual
from:
Institute, Inc.
documents
9800480
9800306
as
iii
PREF'ACE
GLOSSARY
CHAPTER 1
INTRODUCTION TO FORTRAN
1.1
An
Introductory
1.1.1
Comment
1.1.2 Type Statement
1.1.3
Input
1.1.4 Value Assignment
Output
1.1.5
L 1.6
Program
1.2
Summary
1.2.1 Executable
1.2.2 Nonexecutable
1.2.3
Order
CHAPTER
2
Example
Lines
Statement
Statements. . . . . . . . . . . . . . . .
Termination.
Of
FORTRAN-SO
Statements.
of
Statements . . . . . . . . . . . . . .
................
....................
...................
...................
..................
. . . . . . . . . . . .
Statements.
. . . . . . . . . . . .
Statements.
. . . . . . . . .
. . .
..
..
..
..
..
..
FORTRAN CONCEPTS
2.1
FORTRAN
2.1.1
2.1.2
2.1.3 Statements
2.2
FORTRAN
2.2.1
2.2.2
2.2.3
2.2.4 Expressions
2.2.5 Scope
Notational
2.3
CHAPTER
Program
Program
The
PROGRAM
Statement
Character
Constants
Arrays
....................
of
Conventions . . . . . . . . . . . . . . .
Structure
units
and
Procedures
Statement
and
Lines. . . . . . . . . . . . . .
Elements.
Set.
.....................
and
Variables
and
Operators
Symbols
.................
.............
............
3
.........
..........
. . . . . . . . .
, . . . .
..........
..
..
..
..
DEFINING VARIABLES, ARRA YS,AND
MEMORY
3.1
TypeStatements
3.1.1
REAL
3.1.2
INTEGER
3.1.3
LOGICAL
3.1.4
CHARACTER
3.1.5
IMPLICIT
3.2
Array
Definition.
3.2.1
DIMENSION
3.2.2 Kinds
3.2.3 Properties
3.2.4 Referencing
3.3 Assignment Statements
3.3.1 Arithmetic Assignmnt
3,,3.2 Logical Assignment Statement.
3.3.3
Character
3.3.4
ASSIGN
3.3
.5
DATA
........................
Type
Statement
Type Statement . . . . . . . . .
Type Statement
Type
Statement
. . . . . . . . . . . . . . . . . . . . .
Statement
of
Array
Declarators
of
Arrays
Array
Assignment
Statement.
Statement.
........
Statement.
..............
............
................
Elements . . . . . . . .
..................
Statement.
Statement.
. . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
,.....
..... , .....
. . . . .
..........
......
........
. . . .
..
..
..
..
..
..
..
,
1-1
1-1
,
1-2
,
1-2
1-2
1-2
1-3
1-3
1-3
1-3
1-4
2-1
2-1
, 2-2
2-2
2-3
'2-3
, 2-4
2-6
, 2-7
2-12
2-13
3-1
3-1
3-1
3-2
3-3
, 3-3
3-4
, 3-5
, 3-5
3-6
3-6
, 3-7
3-S
3-9
3-9
3-9
3-10
CONTENTS I
3.4
Memory
3.4.1
3.4.2
3.4.3
3.4.4
CHAPTER
PROGRAM EXECUTION CONTROLS
4.1
Transferring
4.1.1 Unconditional
4.1.2
4.1.3 Assigned
4.1.4 Arithmetic
4.1.5 Logical
4.1.6
4.1.7 Block
4.1.S ELSE
4.1.9
4.1.10
4.2
Loop
4.2.1
4.2.2
4.2.3
Program
4.3
4.3.1
4.3.2
4.3.3
CHAPTERS
FUNCTIONS
5.1 Intrinsic
5.1.1 Intrinsic Functions
5.1.2
5.1.3 Statement Functions
5.2 External Procedures
5.2.1
5.2.2 Subroutines
5.2.3
5.2.4
5 .2.5 SAVE
5.2.6
5.2.7
5.3 Arguments
5.3.1
5.3.2
5.3.3 Association
CHAPTER
INPUT/OUTPUT
6.1 Records, Files,
6.1.1 Record Properties
6.1.2 File Properties
6.1.3
Definition.
EQUIVALENCE
COMMON
BLOCK
BLOCK
. . . . . . . . . . . . . . . . . .
Statement
Statement
DATA
DATA
..............
Subprograms
Statement
4
Program
Computer
IF
IF,
ELSE
IF
IF
ELSE
Statement . . . . . . . . . . . . . . . . .
END
IF
Control
Operation
DO
CONTINUE
PAUSE
STOP
END
Statements . . . . . . . . . . . . . . .
Statement.
Termination
Statement.
Statement . . . . . . . . . . . . . . . . .
Statement
AND
And
Statement Functions . . . . . . . .
INTRINSIC
FUNCTION
SUBROUTINE
RETURN
Statement.
EXTERNAL
CALL
Statement.
And
Common
Dummy
and
Control
GO
TO
Statement
GO
TO
Statement.
GO
TO
Statement.
IF
Statement . . . . . . . . . . .
Statement.
IF,
and
Statement
Statement
Statement.
of a DO
Statement.
. . . . . . . . . . . . .
ELSE
.................
................
. . . . . . . . . . . . . .
Loop.
. . . . . . . . . . . . . . . . . .
Statements.
................
...................
SUBROUTINES
.................
Statement
...............
....................
Statement
......................
Statement.
Statement
Common
Blocks
Actual
of
...............
. . . . . . . . . . . . . . . .
Statement.
. . . . . . . . . . . . . . . .
Blocks Revisited
...................
Arguments.
Arguments
6
And
Units
.................
..................
....................
Unit
Properties.
. . . . . . . . . . . . . . . . .
.........
........
...........
.............
......
. . . . . . .
. . . . . . . .
Blocks
.......
. . . . . . . . . .
. . . . . . . . . . .
. . . . . . . .
.............
..............
...........
.............
. . . . .
............
..
3-11
3-11
3-12
3-13
3-14
4-1
4-1
..
4-1
..
4-2
..
4-2
..
4-3
, 4-3
4-4
, 4-4
..
4-5
..
4-5
..
4-6
..
4-6
..
4-6
..
4-7
..
4-7
,
4-S
..
4-S
,
4-S
..
5-1
5-1
, 5-2
, 5-2
, 5-4
5-4
, 5-5
5-6
, 5-6
..
5-7
5-7
..
5-S
... , 5-S
5-9
..
5-9
5-9
6-1
6-1
,
6-1
..
6-3
v
6.2 File-Handling
6.2.1
OPEN
CLOSE
6.2.2
6.2.3
BACKSPACE
6.2.4
REWIND
6.2.S
ENDFILE
6.3
Data-Transfer
6.3.1
READ
6.3.2
WRITEStatement
PRINT
6.3.3
Formatted
6.4
6.4.1
Unformatted
6.4.2
Formatted
6.4.3
FORMAT
6.4.4 List-Directed
CHAPTER
Statement.
Statement.
And
7
Statements.
Statement.
110
Statement
Unformatted
PROGRAMMING
7.1
Program
7.1.1
7.1.2
7.1.3 Refining the
7.1.4 Final Coding
7.2
FORTRAN
7.2.1 Functions
7.2.2
7.2.3 Crossing
7.2.4
7.2.S
7.3
References....
APPENDIX
FORTRAN-80
A.I
Statement Sequence
A.2 Statement
Development
Problem
Program
GO
Computing
Reminders........................
Coding.
TO
Statement
Definition.
Unit Lines
A
STATEMENT
Summary.
APPENDIXB
INTRINSIC
B.l
Intrinsic Function
B.2 Notes On Intrinsic
FUNCTIONS
. . . . . . . . . . . . . .
. . . . . . . . . . . . . . . .
...............
Statement. . . . . . . . . . .
Statement
Statement.
Statements
Data
Statement
Formatting
.................
.................
.................
Data
Transfer.
Transfer.
...............
. . . . . . . . . . . .
.............
Data
Transfer..
.........
..........
...............
...........
GUIDELINES
.................
. . . . . . . . . . . . . .
Documentation.
Problem
....................
. . . . . . . . . . . . . . . . . . .
and
Subroutines . . . . . . . . .
..................
Variables
. . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . .
Definition.
...............
and
Constants. . ..
. . . .
SUMMARY
....................
. . . . . . . . . . . . . . . . . .
Summary.
Functions.
. . . . . . . . . . . .
. . . . . . . . . . .
..
..
" 6-8
..
6-10
..
6-10
6-10
6-10
6-13
6-14
6-14
6-14
, 6-1S
6-16
, 6-22
"
..
..
..
"
..
..
" 7-4
..
, A-I
..
..
..
6-4
6-4
6-9
7-1
7-1
7-1
7-2
7-3
7-4
7-4
7-4
7-4
7-S
7-S
A-I
B-1
B-3
APPENDIX
HOLLERITH
C.l
Hollerith As A
C.2
The Hollerith
C.2.1 Hollerith
C.2.2
C.3 Hollerith
C.4
'A'
APPENDIX
EXTENSIONS
D.l
Standard
D.2
Nonstandard
D.3 More Specific Semantics
D.4 Differences
APPENDIX
ASCII
CODES
APPENDIX
8080/8085
F.l
Processor Limitations
F.2
Compiler Extensions
F .2.1 Lowercase Letters
F .2.2
F .2.3 Reentrant Procedures
F .2.4 Free-form Line
F.2.S
F .2.6 Default
F .2.7 Including Source Files
F .2.8
F.2.9 Flexibility In
F.3
Unit Preconnection
C
DATA
Statements
Hollerith
Statements
Format
Editing
Of
TYPE
Data
Type. . . . . . . . . . . . . . .
Constant
Constants
......................
Constants
........................
Specification. . . . . . . . . . .
Hollerith
D
TO
ANSI
Extensions
Subset.
FORTRAN
FORTRAN.
FORTRAN.
. . . . . . . . . . . . . . . . . . . . . . . . .
From
To
Extensions
......................
. . . . . . . . . . . . . . . . . . . . .
1966
. . . . . . . . . . . . . . . . . . . . .
E
F
PROCESSOR
...................
Port
Input/Output.
Format.
Interpretation
RECL
Files. . . . . . . . . . . . . . . . . . . . . . . . . . . .
F.2.9.1 Association
Locations.
F.2.9.2 Partially Initialized Arrays
F.2.9.3 Transfers
of
Data
Lengths.
Specification
Standard
. . . . . . . . . . . . . . . . . . .
....................
INDEX
..................
In
DATA
In
CALL
Data.
. . . . . . . . . . .
FORTRAN
1977
To
1977
Than
1977
DEPENDENCIES
On
Language
................
. . . . . . . . . . . . . .
DO Statements
For
of
Memory
Into
An
.......
.............
. . . . . . . . . . .
.....
. . . . . . . . . . . .
.............
Sequential
Restrictions
....
IF Block
....
...
..
C-I
C-l
"
C-l
C-l
..
C-2.
..
C-2
..
D-l
" D-l
..
0-2
..
0-2
" F-l
"
F-l
" F-2
..
F-2
" F-2
..
F-2
" F-3
..
F-3
" F-3
..
F-4
" F-4
..
F-4
" F-4
" F-4
" F-4
1-1
1-2
2-1
2-2 Type, Length,
vi
Batting Average
Order
of
FORTRAN
Program
Units
(OPI +OP2)
Program
.......................
and
......................
...............
Statements
Interpretation
.........
of
1-1
1-4
2-1
2-8
ILLUSTRATIONS I
2-3 Type, Length,
(OPI **OP2)
2-4
3-1
3-2
Length
Subscript
Result
of(OPI . OR.
of
Value.
'v = e'
and
Interpretation
....................
OP2)
. . . . . . . . . . . . . . . . . . .
......................
of
.............
" 2-8
2-11
..
3-7
3-8
GLOSSARY
Argument(s) - A collection
formed.
are
Array
selectively (by
Array
Association -
symbols.
tuals
of
are
Common
units.
Compiler -
executable
Equivalenced
Expression - A
arithmetic,
File - A collection
ternal
quentially
Functions
replaced
with actual values
-
An
ordered
array
Element -
May
Association
when a procedure
memory
also said
by
to
two
be
Memory
The
software
form.
Memory
character,
(a
character
or
directly.
and
subroutines
set
of
element
An
individual
refer
to
of
arguments
is
referenced.
or
more
associated.
-
Memory
tool
-
Memory
combination
relational,
of
data
variable
of
values
when
data
that
name).
item within
association
items.
shared
for
of
logical,
records.
or
character
and
are
usually
the
functions
can
be
of
is
the
replacement
Association
The
symbol
by items in
translating
shared
by items in
operands,
or
May
be
array
variables
defined
or
referenced
an
array.
arguments,
of
names
FORTRAN
operators,
Boolean.
external
element).
on
which a
with
subroutines
collectively (by
of
of
dummy
memory
of
the
same
the
same
(any
Records
computation
dummy
memory
arguments
locations
the
items
or
source
and
ISIS-recognized file)
code
program
parentheses.
can
arguments
are
referenced.
array
locations,
is
the
sharing
different
into
units.
be accessed se-
is
per-
that
name)
or
or
of
with ac-
sharing
memory
program
machine-
May
be
or
in-
Function - A
Functions
ed.
defined,
program).
Length
two,
or
Character
routine
single-statement
of
Data -
four
bytes
data
Main Program -
gram
to
be
invoked.
DATA
first
Number
decimal,
Procedure -
SUBROUTINE
Program -
programs
trollines,
statement
statement.
Base -
or
hexadecimal.
The
(FUNCTION,
library
Another
that
are
called
The
number
for
integer
occupies
The
subprograms
entire
procedures,
one
The
main
It
may
as its first
representation
term
executable
SUBROUTINE,
returns
a value
'intrinsic'
function),
of
bytes
and
byte
per
program
not
have a FUNCTION,
statement.
for a function
are
called
program
and
included
to
the
(FORTRAN
or
'external'
occupied
logical items
character.
is
the
first
It
may
used
for
numeric
'external'
includes
BLOCK
files.
calling
have a PROGRAM
statement
predefined),
(user-defined
by a
data
and
four
part
of
an
SUBROUTINE,
data.
or
subroutine.
procedures.
the
DATA)
when
item.
bytes
entire
May
main
plus
it
is
referenc'statement'
FUNCTION
This
can
for
real items.
FORTRAN
or
statement
be
binary,
FUNCTION
program,
any
compiler
(user-
sub-
be
one,
pro-
BLOCK
as its
octal,
and
all sub-
con-
vii
Glossary
FORTRAN-SO
Program Unit -
unit
must
Record
- A
Statement - A
pressions,
Statement
be
given a
Another
be
terminated
sequence
sequence
etc. A
statement
Label-
symbolic
of
A 1-5 digit
name
Subprogram - A tJlock
DA
T A
statement
Subroutine - A
SUBROUTINE
the
last.
Unit - A logical
as its first
group
statement
way
of
name
by
an
values
of
syntactic
has
by
of
code
of
statements
mllst
referring
for a main
END
or
characters.
an
'initial'
integer
the
ASSIGN
having a FUNCTION,
statement
be
to
program
statement.
items:
statement
line
in
columns
statement.
and
the
for
performing a frequently-used
the
first
a file.
Once
or a subprogram.
label,
and
up
1-5
of a statement's
END
statement
statement;
connected,
keyword,
to
nine
'continuation'
SUBROUTINE,
as
its
the
END
statement
it
is
the
Every
arguments,
initial line.
last
statement.
operation.
same
as a file.
program
lines.
or
BLOCK
must
ex-
Can
The
be
viii
This
chapter
TRAN
also includes a
quence.
1.1
An Introductory Example
A
FORTRAN
processing the
drawn
statements
The
example calculates a baseball
opens
with a
a feel
for
the language.
summary
program
data
received,
from the statistical world
for doing these
short
The
of
FORTRAN-80
generally
and
operations.
CHAPTER
11
INTRODUCTION TO FORTRAN
example intended
example
performs
returning
of
the
player's
is
statements
three basic
output.
sports
batting
to
give the newcomer
discussed in some d.etail.
and
their
proper
operations:
The
following
fan(atic), shows typical
average using the
receiving
short
equation:
to
FOR-
The
chapter
coding se-
input,
program,
FORTRAN
AVERAGE =
The
baseball statistician, sitting
how
often
the
is
done
he has
player's
only once.
name
batted,
and
and
batting
TIMES AT BAT
at
his console terminal, enters the
his
total
average.
1.1.1 Comment Lines
The
first seven lines
document a program.
A
comment
any
characters
blank line
sent in line 7
line
is
considered a
of
C CALCULATE BATTING AVERAGES
C VARIABLES
C PNAME = PLAYER'S
C AB = TIMES AT BAT
CHITS
C AVG
C
CHARACTER*12 PNAME
10
20
of
the
example
must
have the letter
accepted by
the example.
FORTRAN
comment
Comment
USED-
= TOTAL BASE HITS
= BATTING AVERAGE
READ
FORMAT
AVG
PRINT 20,
FORMAT (A, 5X, F4.3)
END
10, PNAME, AB, HITS
(A,
2(2X, F3.0))
= HITS/AB
PNAME, AVG
HITS
hits.
To
are
comment
.
'C'
or
in the
line also.
lines have
NAME
name
of
a player,
The
program
keep this example simple, the calculation
lines.
an
asterisk (*) in
remainder
For
example, the
no
Comment
effect
returns
of
on
a listing showing
lines
are
used
column
the line. A completely
program
'C'
need
1 followed by
not
execution.
to
be pre-
Fig. 1-1 Batting Average
Program
1-1
Introduction
To
FORTRAN
1.1.2 Type Statement
FORTRAN-SO
Every variable used in a
character,
PNAME
No type statement
FORTRAN
be used
or
Hollerith. The
represents character
variable-naming convention tells us implicitly
to
name real data. This convention
FORTRAN
CHARACTER
data
is
needed for the other variables listed (AB, HITS, AVO). The
program has a type - integer, real, logical,
and
may have up to
is
type statement says
12
characters.
that
described later in section 2.2.2.1.
that
these variables are to
1.1.3 Input Statements
Following the
The first tells the program to read input data; the second describes the
input
data.
The
number
found in statement 10. The rest
be specified by the person
CHARACTER
10
in the
READ
statement in the example are two input statements.
statement tells the
of
the statement lists the variables whose values will
at
the console.
By
program
that
the input format
default,thein,pu(is reaclfrOl11tbecori-
soleierlllinaL
The
FORMAT
to
expect.
having the length
2X, F3.0, 2X, F3.0
and
refers
followed by a 3-digit floating-point (F) number whose decimal
digits. Clearly, no
statement (labeled statement
'A'
indicates the first field
of
to
the AB and
batter
PNAME,
the player's name. '2(2X, F3.0)'
HIT
comes to the plate 79.3 times
fields.
of
10)
tells the program what kind
data
is
a string
'2X'
indicates two blanks will be entered
of
alphanumeric characters
is
equivalent to
portion
or
has 22.8 hits.
the variable
format
of
of
contains
data
the
is
'0'
One might ask
that
is,
2(2X,13}
The
reason
by another. Since AB
batting
1.000.
is
at
that
this point why
FORTRAN
~
truncates the remainder when one integer
HITS,
we
didn't
specify these fields
all averages would be
'0'
except for the rare player
1.1.4 Value Assignment Statement
The actual batting average calculation
AVG = HITS/AB
This
is
one form
ed the value
of
assignment statement, in which the
of
the expression
'HITS/
is
done by the next statement:
variable'
AB.'
1.1.5 Output Statements
Following the calculation are two
output
In the
~t~teI11e~t?O:'.flN~¥.E'~nd'AV9'
Qefa;tllt~.theoutpqtis~xi~t~n.
data; the next describes the
PRINT
statement, the
output
format
number
~qtheconsoJe.
lines. The first tells the
of
the
output.
20 indicates
are the items whose values are
that
the
output
to
be 'integer' data;
is
divided
AVO'
is
assign-
program
format
to
to
is
found in
be printed.
write
lly
1-2
FORTRAN-SO
Introduction
To
FORTRAN
Statement
of
characters
will be followed by five
'A
VG'
decimal
20,
the
FORMAT
of
variable
field consists
digits.
statement,
length, as in
blanks
(5X)
of
four
floating-point
1.1.6 Program Termination
The
final
statement
the
FORTRAN
unit
must
be
terminated
1.2 Summary Of
The
statements
classifications.
and
some
from
statements
chapter
Statements
do
calculations,
ecutable
units.
are
references
are
statements
terminates
compiler
by
that
an
the
it
hasTeached
END
FORTRAN·SO
available
These
the
listed in
are
classified as executable
read
in
FORTRAN-80
include all
FORTRAN
the
same
to
this
or
write
define
the
statements
sequence
manual,
110
characteristics
indicates
the
FORMAT
and
then
program.
statement.
are
77
full language.
as in Section 7
however,
or
data,
and
the
'PNAME'
statement
the
digits --
The
the
end
batting
average will be
one
END
statement
of
the
Statements
listed below
available in
not
nonexecutable.
control
or
value
to
To
the
the
simplify
of
ANSI
program
of
field will be a
labeled 10.
integer
program.
according
FORTRAN
the
ANSI
standard.
Executable
execution.
data
and
The
printed.
digit
and
is
an
indicator
Every
program
to
their
77 subset
comparison,
standard.
statements
Nonex-
define
program
string
name
The
three
to
main
the
All
1.2.1 Executable Statements
1.
Arithmetic,
(Chapter
2.
Unconditional,
3.
Arithmetic
4. Block
5.
CONTINUE
6.
STOP
7.
DO
statement
8.
READ,
9.
REWIND,
(Chapter
10.
CALL
11.
END
statement
logical,
3);
and
IF,
ELSE
statement
and
PAUSE
WRITE,
BACKSPACE,
6);
and
RETURN
and
assigned,
logical
IF,
ELSE,
statements
(Chapter
and
(Chapter
character
and
computed
IF
statements
and
(Chapter
(Chapter
4);
PRINT
statements
statements
ENDFILE,
4).
assignment
(Chapter
END
4);
(Chapter
IF
1.2.2 Nonexecutable Statements
1.
PROGRAM
SUBROUTINE
2.
DIMENSION,
EXTERNAL,
3.
INTEGER,
4.
DATA
5.
FORMAT
6.
Statement
(Chapter
INTRINSIC,
REAL,
statement
statement
function
2),
(Chapter
COMMON,
LOGICAL,
(Chapter
(Chapter
statement
BLOCK
5)
statements;
EQUIVALENCE,
and
SAVE
CHARACTER
3);
6);
(Chapter
DATA
GO
TO
4);
statements
4);
(Chapter
OPEN,
5);
(Chapter
(Chapter
5).
statements;
statements
(Chapter
6);
and
3),
IMPLICIT
5)
statements;
type
statements
ASSIGN
(Chapter
4);
CLOSE
FUNCTION,
(Chapter
(Chapter
statement
4);
statements
and
3),
3);
1-3
Introduction
To
FORTRAN
1.2.3 Order of Statements
The
following
1.
Comment
after
The
2.
program.
as the first statement
FORMAT
3.
IMPLICIT
4.
5. All specification statements (lists 1
DATA
must
6.
The
The
rules for ordering
order
must
be observed in coding
lines can
the
END
PROGRAM
FUNCTION,
appear
statement.
statement can
before
SUBROUTINE,
of a subprogram
statements
can
appear
statements must precede all
statements, which
must
precede all executable statements.
last line
of a program
FORTRAN
unit must be the
statements are summarized in Figure 1-2.
FORTRAN
or
between statements. They
appear
only as the first statement
and
BLOCK
statements lines:
cannot
of
DATA
can
appear
appear
a main
only
(Section 2.1.1).
anywhere before the
other
specification statements.
and
2 in section 1.2.2) must precede all
END
statement.
precede all statement function statements, which
END
statement.
FORTRAN-SO
PROGRAM,
Comment
FORMAT
Lines Statements
Figure 1-2.
FUNCTION,
END
Statement
Order
of
FORTRAN
SUBROUTINE,
or
Statement
IMPLICIT
Other
Statements
Specification
Statements
DA
T A Statements
Statement
Function
Statements
Executable Statements
Statements
BLOCK
DATA
1-4
CHAPTER 2
The
chapter discusses the concepts
and
elements
2.1
FORTRAN Program Structure
of a FORTRAN
and
program.
terminology used to describe the structure
2.1.1 Program U nits and Procedures
The
scope
of
many
FORTRAN
gram
unit
is
either a main program
A main program can start with a
programs start with either a
ment. A
have any
Subroutines
tions are further defined to be
created outside a
call
library. Procedures are discussed in detail in
FORTRAN
number
and
an
external procedure written in
program
of
subprograms
functions are called procedures. Subroutines
FORTRAN
operations
or
PROGRAM
FUNCTION,
must have one
(Figure 2-1).
external procedures. External procedures can be
program also; for example, a
is
defined to be a program unit. A pro-
a subprogram.
SUBROUTINE,
and
PL/M-80
Chapter
FORTRAN
statement, though it need not. Sub-
or
BLOCK
only one main program
and
FORTRAN
and
stored in
5.
an
CONCEPTS
DATA
'external'
program can
ISIS-II system
and
state-
may
func-
MAIN
PROGRAM
[PROGRAM]
•
•
•
•
END
SUBPROGRAMS
SUBROUTINE
•
•
FEN:
FUNCTION
•
•
Fig.
..
END
BLOCK
~
END
f'
'-----"
MISC.
EXTERNAL
PRO-
CEDURES
~
2-1
Program Units
•
DATA
•
•
• • •
-
~
..
1-
• • •
•
•
•
•
J
P-'S~UB=R=OU=T=IN=E
END
J
FUNCTION
END
J
BLOCK
END
,...
DATA
2-1
FORTRAN
Concepts
2.1.2 The PROG RAM Statement
The
PROGRAM
but
when present must be the first statement
PROGRAM name
where
'name'
is
allowed per program.
FUNCTION,
statement
is
the symbolic name
SUBROUTINE,
is
The
used
to
of
main program can contain any other statement except
BLOCK
name a program. This statement
of
a main program.
the program. Only one
DATA,
SAVE,
or
It
has the
PROGRAM
RETURN.
is
optional,
format
statement
FORTRAN-SO
The scope
moment, suffice it
program.
DATA
of
symbolic names
It
cannot
subprogram,
is
discussed later in this chapter (section 2.5.5).
to
say
that
the program name
be the same as the name
common
block,
or
'local' symbol name in the main program.
is
of
'global'
an
to the entire executable
external procedure, BLOCK
For
the
2.1.3 Statements and Lines
A FORTRAN-SO source program
statements.
Compiler controls direct the operation
it
what
kind
of
output
ed in detail in the compiler
manual where relevant. In general, controls can be embedded in
code
and
are identified by a
All
but
two types
by
that
keyword.
the keyword
do
not
example
'PROGRAM.'
begin with keywords. The
of
an arithmetic assignment statement.
to
of
FORTRAN
For
example, the
produce, the form
is
made up
operator's
'$'
in the first character position
Only 'assignment'
manual,
statement begin with a keyword
PROGRAM
'AVG = HITS/AB'
of
of
a particular
of
list
compiler controls
output,
and
a few will be mentioned in this
statement
and
'statement
and
FORTRAN
FORTRAN
etc. Controls are discuss-
('column'
just
statement in Figure
compiler, telling
FORTRAN
1).
and
are identified
described begins with
function' statements
source
1-1
is
an
2.1.3.1 Statement Labels. Any statement can be labeled; any statement to be
referenced from elsewhere in the
unsigned, nonzero, integer
ment's
gram
initial line. No two statements may have the same label within the same pro-
unit.
constant
program
must be labeled. The label
written anywhere in columns
is a 1-5
1-5
of
digit,
a state-
2-2
2.1.3.2 Line
first line
ment are called
FORTRAN
A
(referred to as
statement begins in column 7. A statement can extend over nine continuation lines
(columns 7-72) for a total
An
integer anywhere in columns
tains a
is
Specific Intel
mat.
'0,'
a continuation line. Columns
See Section
Format.
of
a statement
continuation lines.
line
can
'columns'
the line
is
FORTRAN
F.2.4
A
FORTRAN
is
called the initial line; subsequent lines in the same state-
have up to 72 characters. The first six character positions
1-6) contain
of
660 characters.
an
initial line;
1-5
compilers may allow exceptions to the
of
Appendix F for details.
statement consists
information
1-5
is
a statement label.
if
column 6 contains any
of
a continuation line must be blank.
characterizing the line.
of
If
column 6
one
or
more lines. The
is
blank
other
character, the line
standard
The
line for-
actual
or
con-
FORTRAN-80
2.2 FORTRAN Statement Elements
A
FORTRAN
• Statement identifier (keyword), such as
• Function identifiers, such as SQRT(A)
• Constants, such as 3.142857
• Variables, such as A
• Operators, such as *
•
Combinations
mathematical expressions, such as A
Statement
variables,
and
in
Chapter
2.2.1 Character Set
statement can include the following elements:
PROGRAM
or
FLOA
or
'STRING'
or
AB
or
.AND.
of
the above into value assignments, such as X =
*B
+ SQRT(C)
and
function identifiers are the subjects
operators,
3.
and
expressions are described in the remainder
T(I)
or
of
Chapters
INTEGER
3-6.
y*Z,
Constants,
of
this
FORTRAN
or
into
chapter
Concepts
The FORTRAN-80 character set consists
0-9,
and
the special characters listed below.
pr~5~ss~~1~9ItliJ~~t~~p:r~rl~iqg·
l~t~ng.sequ¢nce()fthe¢h~(actersisthat
SPECIAL
= Equal Sign
CHRACTERS
Blank
•• ~ ..
~~
of
the alphabetic characters A-Z, the digits
The
set
ofcnar&ctetsreptesentable
••
~I.gr~l?hi¢s~A9th~blan~cryar~cter
of~he
·AS~TTqhaT(\cter$et(Appendix·
'.
+ Plus
Minus
* Asterisk
/ Slash
( Left Parenthesis
) Right Parenthesis
Comma
Period
Single
Quote
$ Dollar Sign
#Pol.1ndSign
Generally, blanks have no meaning in a
improve program readability.
For
FORTRAN
example,
statement
and
should be used
in
The·.
E).
the
col*
to
A =
8*C
+ (D* *2/E)
and
A
are equivalent statements.
Blanks are counted in the total characters allowed in a
however. They are also significant in character strings
dard
line format. They
8*C
+ (D* *2/E)
and
are
not counted in the memory space occupied by a
FORTRAN
in column 6
statement,
of
the stan-
program.
2-3
:FORTRAN
Concepts
2.2.2 Constants and Variables
FORTRAN-SO
The value
next.
gram execution
The
of
a constant does not change from one execution
value
of
a variable, on the other hand,
or
between runnings
of
the program.
is
subject to change during pro-
For
of a program
example, in the statement
C=A**2+B
the
'2'
is
constant, whereas A,
an
earlier calculation
or
A constant appears as its actual value. A variable has a
B,
and
C are variable
value assignment.
and
may change as the result
symbolic name
that
1-6 alphanumeric characters. The first character must be alphabetic. Thus, all
following are valid variable names:
K
XYZ
B52
ERROR8
STEP3
Every constant
Arithmetic constants
2.2.2.1 Data Types. Arithmetic constants and variables are
real (sometimes called 'fixed
and
variable has a data type
and
variables also have an associated
point'
and
'floating
and
point').
length associated with it.
number
base.
of
type integer
to the
of
can be
of
the
or
An
integer
or
'-'
include a decimal point
preceded by
ne.ed
The internal representation, the precision,
constant
sign (0, 123, - 34, + 5). A
an
not
have a decimal point (4E3). Again, the exponent may be signed.
4.2E3
4.2E+3
4.2E-3
is
written without a decimal point
'+'
is
assumed if no sign
and
optional sign (5.,
'E'
may follow a real constant
X
103 .or 4200)
(4.2
(same as above)
(4.2 x
10-3 or
.0042)
and
and
can be preceded by a
is
present. Real constants
.5,0.5,
the range
.0005).
and,
in this case, the real constant
of
real values
An
integer exponent
conforms
'+'
to
the floating-point conventions established for the particular processor being used.
See section
An
integer variable name begins with one
'N.'
are assumed
using
Constants
Logical
logical
F.l.
of
the alphabetic
Variables beginning with an alphabetic character
to
be type real. This implicit naming convention can be circumvented
Type
statements, however (see section 3.1).
and
data
constant
.TRUE
variables can also be
may have only the values
are:
.
of
type logical
'true'
or
or
'false.'
characters'!'
other
than
I,
type character.
The possible forms
J,
K,
through
L,
M,
or
of
N
. FALSE.
a
2-4
FORTRAN-80
FORTRAN Concepts
Character
character
the form
the string
data
is
a string
is
valid
and
of
a string
is
represented by a double
of
any characters representable in the processor. The blank
significant in a character constant. A character
of
characters
surrounded
apostrophe.
by apostrophes.
An
apostrophe
A character constant can have
constant
1-255 characters.
'ARITHMETIC
'MURPHY'S
For
the sake
of
also supports Hollerith type
Hollerith type
2.~~~.2~~t3Lellgth.ATeal
hitS).
Atlintegtrm~~pc¢upY?l1e,>~W9,.()rfout
spe~ifiedw~eT\th,e"ariably,
Jf~ou~rnberpas~jS'specified
deciO}alaT\<lits'l~ngthist~e
base
.,is
speci~ied.
~~n~t~js~~t~rmJned
OVERFLOW
LAW'
compatibility with earlier versions
is
summarized in Appendix C.
type is
s~Ille;asthe
for,an.i~teger,,~onstant
implicitly
ERROR'
data
under the guise
v~lu~
defined
[or
an
integer constant, the ,constant
by
the
processor from the base
of
FORTRAN,
of
arithmetic/logical types. The
alwij.yso¢cupies four
bytes.F?ran
(section 3.1)
integervariahle, the length is
Or
by
jntegervaria,bIedefault length.,
(a$,des~rib:d
j~
the, next ,'.subsection).
FORTRAN-80
hytesof
default (section F
is
assumed to he
and
number
pftlJeirrteger.
within
memory
If
a
number
of
digits
has
(32
.2~6).
the
~~~.4.~~~~~e~.~~~~
th~~(#!il11ql~t),Illp:erb(l$.ei$assll~ed
can;bebinary,()etal~"
.•
,<~()r
.~ritliineti9·.·
or hexadecimal
••
(irlte~~r~r/~~~~)c()nst~~tS'.and
with.thefollQwi'Q8.e~(;eption~',
as
well.
·,luteger
',variables,
••
constants
2-5
FORTRAN
Concepts
The
or
where:
possibleJorms
[s]d"
.
[sl#d
... b
s
is
an
of
aninteger
optional
constant are:
+ or
-.
FORTRAN-SO
sign
d
is
a digitor.one
of
the letters
b designates the number base
lfthe
numher base specjfier
can
contain
specifier
is interpreted
can·contain
spe¢ifiedas
only
'8'
is
present,
asa
only the digits· 0-7 and is
the
the
digitsO~9artdjsinterpretedas
binary number.
base, the number
the
character
is
absent or is the letter
leo'
can
interpreted as a hexadecimal number.
The
following
are valid
integer
constants:
o
23
+64101
-#14010
#100010108
-#100010108
-#4567Q
+#AF2CH
2.2.3 Arrays
Frequently,
still be
is called
able
an
the
programmer
to
refer
array.
will
individually
want
to
elements
A~F
and
is
one
of
>'D/thecharacler
a
decimal
stringm
ust contain only the digits o and 1
or
'Q'
is specified as
interpreted
as
an
contain the digits 0-9
to
refer
to a group
in
the
group
the letters
number
thebase,
octal number
or
the
of
data
as
necessary.
D,B,O;
string
..
If
Q,
the
or
'd
... '
base
H
and
the
numper
..
If
'H'
is
lettersA~Fand
by
one
name
Such a group
is
and
2-6
An
array name is
DIMENSION
array element is
ray
name
qualified
The
following
generate
and
PNAME(3),
four
batting
averages.
AB(3),
PNAME
GEHRIG
OTT
RUTH
We
can
refer
to
hits
for
'OTT'
AVG(3).
the
symbolic
statement,
one
table
1
~dimensional
member
by
a subscript
could
Thus
HITS(3),
type
be
arrays.
the
statement,
in
produced
and
AB
49
60
54
any
can
element
be
in
referenced
name
the
group
enclosed
The
array
A VG(3).
HITS
14
21
18
these
arrays
as
HITS(2)
assigned
or
COMMON
of
data.
in
parentheses.
by
rewriting
table
lists
definitions
AVG
.286
.350
.333
by
using a
and
the
array
when
statement
An
array element name is
the
program
three
players,
for
these
four
subscript.
the
batting
average
it
is
defined
(Chapter
in
Figure
times
arrays
For
example,
for
at
bat,
could
RUTH
3).
an
1 ~ 1
in a
An
ar~
to
hits,
be
the
as
FORTRAN-80
2.2.4 Expressions and Operators
An
expression
parentheses
appear
cessing statements (e.g., IF
(CALLSUB(X+l,
in assignment statements (e.g., A = B + C) as controls in certain
is
a combination
and
may also include functions (discussed in
Y).
of
numbers, symbols,
FLAG
.NE.
3
GO
TO
and
250),
operators.
Chapter
and
It
5). Expressions
in subroutine calls
may
data
FORTRAN
include
pro-
Concepts
FORTRAN
2.2.4.1 Character Expressions. A
character
reference. The expression
2.2.4.2 Arithmetic Expressions.
computation.
values representable in the processor (see section
tion produces values outside this range, the results are undefined.
Arithmetic operands must identify values
2.2.4.2.1 Arithmetic
has four kinds
constant,
This
computation
Operator
**
/
*
+
of
character
a character variable reference,
may
be enclosed in parentheses.
An
arithmetic expression performs a numeric
is
limited by the range
of
Operators.
Meaning
Exponentiation
Division
Multiplication
U
nary
Unary
The
arithmetic
or
binary addition
or
binary subtraction
expression consists
F.l).
type integer
operators
or
a character
and
If
any
or
real.
are:
precision
part
of
either a
array
of
numeric
of
the computa-
element
The following expressions calculate the perimeter,
square with side
SPERIM =
SQAREA =
SQDIAG = SQRT (2*(S* *2))
length'S.'
4*S
S**2
area,
and
diagonal length
of
a
2-7
FORTRAN Concepts
FORTRAN-80
Fig.
2w$
·.type,. Length,
andJnterpretatbin
As these figures indicate, mixed-mode arithmetic
operands
This conversion
In the case
If
the magnitude
the
to the same type (the type
is
unnecessary when a real
of
an
integer divided by
The
value
of
1/3
is
The
value
of
8/3
is
The
value
of
-8/3
of
an
number
of
bytes shown
of
another
0
2
is
-2
arithmetic result
in
these figures, the result
the result) before performing the
number
is
integer, the remainder
is
too
large for the processor
2.2.4.3 Relational Expressions
Relational expressions
return a
TRUE
or
2.2.4.3.1 Relational
compare
FALSE
Operators.
two arithmetic
result
of
The relational
or
type logical.
operators
o~(O~1**QP2)
is
done
by converting
raised to
an
integer power.
is
truncated.
to
is
undefined. See section
two
character
expressions
are:
both
operation.
represent in
F.I.
and
2-8
Operator
.LT.
.LE.
.EQ.
.NE.
.GT.
.GE.
Meaning
Less
than
Less
than
Equal
Not
equal
Greater
Greater
or
than
than
equal
or
equal
FORTRAN-SO
f'ORTRAN
Concepts
Relational expressions
IF (NUMB .GT.
IF
(PNAME .EO. 'GEHRIG') PRINT 20, PNAME, AVG
2.2.4.3.2
tional
tion
If
the
expressions.
is evaluated as
where
operator
2.2.4.3.3
tional expression
tion
If
two
length
character
precedes
dix E).
Interpretation
expression
set
up
by
the
operands
EXP1
(EXP1
'0'
set
up
character
of
are
The
operator
if
- EXP2)
is the same type as
in
both
Interpretation
by the
the
longer by
expression
the
value
is
TRUE
operator,
of
relational expression
it were written
operator
expressions.
is
TRUE
operator,
operands
of
are
commonly
99)
STOP
of
if
and
different
EXP2
of
if
and
adding
EXP 1 is
EXP2
used in
Arithmetic
the values
is
FALSE
types, type conversion
the
Relational Expressions.
of
the
otherwise.
0
(EXPI -EXP2)
Character
the values
is
have
different
considered
in
the
Relational Expressions. A
of
the
FALSE
blanks
ASCII
otherwise.
lengths, the
on
the right
to
be less
collating sequence,
IF
statement
operands
and
'operator'
operands
than
(Chapter
satisfy the relational condi-
is
similar
satisfy the relational condi-
shorter
of
EXP2
to
is the same relational
is
the
character
if
and
4).
An
arithmetic
that
of
arithmetic
character
'extended'
the value
vice versa (Appen-
string.
of
to
EXP
rela-
rela-
the
The
1
2.2.4.4 Logical Expressions. A logical expression
tion
and
returns a TRUE
single logical
ment
reference, logical
tion
of
2.2.4.4.1
2.2.4.4.2
involving
The
logical expression has
logical
Logical
Operator
.NOT.
.AND.
.OR.
.EQV.
.NEQV.
Value
.NOT.
operand
operands
Operators.
and
is
or
FALSE
(logical
function
joined
Meaning
Logical
Logical
Logical inclusive
Logical equivalence
Logical nonequivalence
Length
as follows:
of
OP1
TRUE
result
constant,
reference,
by logical
The
logical
negation
conjunction
Logical Expressions.
.NOT.OP1
FALSE
FALSE TRUE
the
opposite
of
type logical. This expression can be a
logical variable reference, logical
or
relational expression)
operators
operators
disjunction
value as its
and
are:
operand.
performs
parentheses.
The
value
a logical
or a combina-
of
a logical
computa-
array
ele-
operand
2-9
FORTRAN Concepts
The
true. Otherwise, execution stops.
10
following example passes
FLAG = FLAG
+ 1
control
to
line
10
if
the logical variable
DONE
is
not
FORTRAN-SO
DONE = (FLAG
IF
(.NOT.
GOTO
DONE)
10
.GT.
99)
THEN
ELSE
STOP
ENDIF
The
value when two logical
OP1
TRUE TRUE
TRUE
FALSE
FALSE
If
both
operands
This example achieves the same effect as the last example.
IF
(FLAG
are
.GT. 0 .AND.
operands
OP2
are
combined
OP1
TRUE
FALSE
TRUE
FALSE
true, the logical expression
FLAG
.LE.
FALSE
FALSE
FALSE
99)
GO
by
.AND.
.AND. OP2
is
true.
TO
10
STOP
The
value when two logical
operands
are
combined
by . OR.
is
as follows:
is
as follows:
2-10
If
either
operand
The
following
IF
The
value when two logical
If
both
statement
(FLAG
operands
.EO.
OP1
TRUE
TRUE
FALSE
FALSE
is
true,
50
OP1
OP2
TRUE
FALSE
TRUE
FALSE
the logical expression
branches
.OR.
on
FLAG
operands
OP2
either
.LE.
are
10)
combined
OP1.0R.OP2
TRUE
TRUE
TRUE
FALSE
is
true.
of
two conditions.
GO
TO
OP1
.EQV. OP2
TRUE TRUE TRUE
TRUE
FALSE
FALSE
are
logically the same, the logical expression
FALSE
TRUE
FALSE
FALSE
FALSE
TRUE
250
by .EQV.
is
as follows:
is
true.
FORTRAN-80
FORTRAN Concepts
The following statement returns whenever the two logical operands are logically
equivalent.
IF
(FLAG1
The
value when two logical
.EQV.
FLAG2)
operands
RETURN
are combined by
.NEQV.
is
as follows:
OP1
TRUE
TRUE
FALSE
FALSE
If
both
operands are logically different, the logical expression
The
following statement continues execution
IF
(FLAG1
.NEQV.
OP2
TRUE
FALSE
TRUE
FALSE FALSE
FLAG2)
OP1
FALSE
TRUE
TRUE
if
the two operands are
CONTINUE
.NEQV. OP2
is
true.
not
equivalent.
2.2.4.6
Expressions are generally evaluated left
are evaluated before
When
Precedence
two operators have equal precedence, the leftmost
of
Operators.
other
operators
to
that
right.
Operators
immediately precede
with higher precedence
is
evaluated first.
or
follow them.
2-11
.FORTRAN
Concepts
FORTRAN-SO
Parentheses can be used to override
pression enclosed in parentheses
nermost are evaluated first.
15/3 + 18/9 = 5 + 2 = 7
15/(3 + 18/9) = 15/(3 + 2) = 15/5 = 3
The
following lists the precedence
• Parenthesized expressions
• Exponentiation: **
• Multiplication/Division: *, /
•
Addition/Subtraction:
• Relational
•
Logical/Boolean
•
Logical/Boolean
• Logical/
•
Logical/Boolean
Thus,
the expression
Operators:
Boolean.
.NOT.
.AND.
0 R.
.EQV.,
is
of
+, - (unary
.LT.,.LE.,.EQ.,.NE.,
.NEQV.
o .OR. A + 8 .GE. C
is
interpreted as
though
it
were written
normal
evaluated first.
operators
rules
in descending order:
and
binary)
of
precedence. The
If
parentheses are nested, the in-
.GT.,.GE.
part
of
an
ex-
o .OR. ((A +
One
exception to the left-to-right rule
occur together.
A**8**C
In this case, the exponentiation
A *
*(8
* *C)
8)
.GE. C)
is
the case where two
is
interpreted right-to-Ieft as
2.2.5 Scope of Symbols
A symbolic
must be alphabetic. Symbolic names may be
the entire
local symbol
units
The following symbolic names are global to
in a local context.
• Main
•
Subroutine
• External function names
• BLOCK
name
consists
program)
name
can, therefore, represent different entities in different
or
in different statement functions.
program
name
names
DATA
of
one
or
they may be local to a
subprogram
names
to
six alphanumeric characters, the first
global
(that
program
the entire
or
more
exponentiations
though
is, they may have a scope
unit
or
program
it were written
of
statement function. A
program
and
cannot
be used
which
of
2-12
The
following symbolic names are local to the
•
Array
names
• Variable names
program
unit in which they appear:
FORTRAN-80
•
Statement
function names
• Intrinsic function names
•
Dummy
Variables
that
statement
procedure
appearing
only.
names
as
dummy
arguments
FORTRAN
in a statement function have a scope
Concepts
of
Common
block
intrinsic function in a function
as a
function.
pearance
block names
name
in a
program
are
generally global,
unit
may
also be the
subprogram.
common
block
If a name
name,
is
used for
however,
both a common
identifies only the local entity except in
if
the
2.3 Notational Conventions
This
manual
statements
• Special characters from the
uppercase words (keywords)
noted.
• Lowercase letters
items must be substituted in actual statements.
• Brackets [ ]
• Ellipses (
.times in succession.
• Blanks are used to improve readability,
an
example
As
CALL
uses the following
and
concepts:
and
are
used to indicate
...
) indicate
of
the
notation
sub
[ ([arg[,arg]
notational
FORTRAN
are
to
be
words indicate nonspecific arguments for which specific
optional
that
the preceding
used, the description
...
] ) ]
but
do
admit
exceptions. A
name
of
any local entity
An
intrinsic function
program
unit does not reference
block
and
COMMON
name
a local entity, its ap-
and
SAVE statements.
conventions to describe
character
set, uppercase letters,
common
other
than
an
may
be used
that
FORTRAN-80
and
written as shown, except where otherwise
items.
optional
but
items can
appear
have no significance.
one
or
more
means the following forms
CALL
sub
CALL
sub
( )
CALL
sub
(arg)
CALL
sub
(arg, arg)
CALL
sub
(arg, arg, arg)
etc.
When
for
the actual
'sub'
and
CALL
CALL
each
statement
'arg.'
ROUT1(A, 3.72, 4.12)
of
the
CALL
statement
is
written, specific entities would be substituted
are
permissible:
2-13
CHAPTER 3
DEFINING VARIABLES,
ARRAYS,
This chapter describes the statements used to specify the types
with symbolic names, how to assign values
memory,
are:
• Type statements:
•
• Assignment statements: arithmetic, logical,
•
3.1
The type statements REAL,
confirm
names beginning with the letters I-N refer
tion itself can be confirmed
Type statements can also specify
and
how
to
assign values
REAL,
Array
definition statement:
ASSIGN,
Memory
DATA
definition statements:
Type Statements
or
override the type implied by a symbolic name (i.e., the convention
to
a block
INTEGER,
DIMENSION
COMMON , EQUIVALENCE,
INTEGER,
or
changed by the
data
length
to
these symbols, .how to structure
of
memory. The statements described
LOGICAL,
LOGICAL,
to
integers-Section
IMPLICIT
pr
array dimension
CHARACTER,
and
and
CHARACTER
statement.
AND
and
lengths associated
character assignment,
BLOCK
2.2.2.1). The conven-
information.
MEMORY
IMPLICIT
DATA
are used to
that
Specifying the symbolic
function in a type statement establishes the type
the program unit. The type
in a
program
statement.
unit.
name
Program
of
a variable, array, external function,
of a name
names
cannot
and
be specified explicitly
subroutine names
3.1.1 REAL Type Statement
The
REAL
type statement has the format:
name
REAL
where
'name'
tion,
or
dummy
Examples:
[,name]
is
the symbolic name
procedure.
REAL TEMP
REAL NUMB1, NUMB2, NUMB3
C REAL OVERRIDES
...
of
a real variable, array, array declarator, func-
IMPLICITTYPING
3.1.2 INTEGER Type Statement
of
that
name
for all appearances in
cannot
OF
NUMB=INTEGER
or
more
appear
statement
than once
in a type
The
INTEGER
INTEG
type statement has the format:
ER.fm!@ti£;l)
name
[,name]
...
3-1
Defining Variables, Arrays, And Memory
FORTRAN-80
where 'name'
is
one
of
the forms
v[*/en}
ary[(d)][* len]
and
v
ary
ary(
d)
lenj.i~~~~l~9:!~~i*~~f¢~;0;(<trl·.ii)t~g~rV(l~i&l?1~·9t
is
an integer variable, function, or dummy procedure name
is
an array name
is
an array declarator
.·~rp~y¢l~w~#t,
••••.
~t$
• va,luernustuei{A, Qp4. .
•.•.•......•....•...............
:
.•••••....••..••.•.•...•....••....
..•.•..•..•.••
.•......•••....•...•...•..•••••.....••
..•.•
..
•...•
..•
..•.•
••.•.....•..•..
.
••...•.••....•...•..••.....•..•••.••......••..••.•.•.....••....•.•..••.•....••...•...•.
:
...•..•........•..•
'.. . •..••.•.•...
:
•..•...........•..•..•......•..•.•
~
.•. ~ .. : ...•..•.
~.;.::
:
•...•........
:
.•..•...•....•.•...•....•
~
... ! ..•..•.•.•.
::
....•.•• : ...••.••..
:
..•...
:.~
.••...
:::
.... : •...•.
:~
•......•.••.••.
;:.~
•...
:"
..
" . :
.•.
:...............
..••.
......
...•.•.•..•......•.....•..........•........•.
.
.....••.•.•.•..............•.••.......
::
••..•.•......•..........•
:
...•........•...•.....................•.•.•
:. " •.......•.
::......
.'
.. ' ..••.........
:..............
.•.•.
.•...•.....•.•••.••.••..••....•..•..........
....•..•...
. .
..•............•.•.....•.........•.
.•.•...........
... . ..•..•.•
.•... . .....
:.:.
•......
.....•.•..
.......•
..•....
........ • .'. : ..• : ....................•..
:". • .......
":
"'
•....
X~~~~P~f.~·
~.~~.~
•.• · ••.
sp~cifi9~tiqp;.·i~~;:~i~t.7~¥X~11Q~.i119·
:~l'r~~i/t~~
def:~1l111efl.gthqf··(l~··.int~$~rvad~l?1~Ofar.r;:\y
Examples:
•••
~p~~~
••
ite~.·i~···
..
·~J.1estttJe~.el1ttlp~n~yil1~
.•
J~l1~tl)·~~p~j~~
f~E~.~~.~~
•.
··.·.~.~ffi~.~~~~rl~.fP~~~~~.n~··.·~e~~e~~?rf;l.·.·~·fir~~B:.~
.•
~2·itGB'li§!er
•.
·.tQ
•.
·•
~~p~~~rfty.·.~1~mel1t?J:f119.1e~~te:i~~R~fi~i~~~~9T$.~~rent
INTEGER TOTALS
•••
..
i~s
•.
8'Y11\1~~~~~~pe9ifi~~tio~.~
1711gt~f:()~it~~t·i~~rn
..
e1~rqentis.a;~SUlTIeg(s~ySeC!~Pfl.f,4~~).
··~BRl~~~i~?
•...
·.~
.. · ••
·ltl1gt~
.?111~\
••
~A~/.~~
INTEGER*1 DIGITS(10}
INTEGER*4
TOTALS, SUBS*2, DIGITS(10}*1
3.1.3 LOGICAL Type Statement
The LOGICAL type statement has the format:
LOGICAL [*len[,]) name [,name]
where 'name' is
one
of
the forms
v[*/en]
a
ry[
(d)][
* len]
and
v is a logical variable, function, or dummy procedure name
ary
ary(d)
leit
".:
,"
.:
...•.
:::",
,"
.. " ..... ; ......
is
an array name
is an array declarator
~~~~~l~~~~~~ij~~~¢sgf#lg$!~#~y~~~~~~$qp~!t~y.~~~m*p.~.lt$¥~h!~
mu&tgf;lJ~,-·911::h
~.::.
'.:~
...
<.,
...
-.:.:'
:".".:
:::
:::,-.::".:,.\:.::.
:.:
..
:.::
.•.. ~ ..
:.:.:.::.:::
..
::
.....•• : ..•.•...... : ..•.......•............•...•...•.....•
'
•..........•...•.
::
.•.•........•..•......•..•.•.......
:
•.•. : .•..............•......................
...
..
:
•..•.•.....•.....................••.••.........•.
::
...•.....................•..•.•..•...•............•..•...............•....•....••......................................•....•.•............
::
............•..............•.
. . .
:
....
;:
......
::
•...•.•..•........
:
...........•..............•....
:
..••....•..
::
..
:::
..... : ..
::
•.... : ......••....•.•.••.....
:.:::.:
..•...
:.: ...
:.
..
>:.:
..
: .
"."
.....•... - '
..
3-2
~~~~<itel'tli~l
s~:vifi~~t19rr.iPlnae~j~t~ly()n9W:il1g~n
ao'a~;
.the,l~ngthi~ppHe$
default.· length . ofalOgical
.••.•
tb!~'~f~~~nt[lQ~.··
..
t().·.eacl1··a,rray.el~~ent
v~riable
•.
~~~i!!$i~s.~~P
.
i~enJ.i~t~el~ng~~fQ~~'a~r~t~tni~I1~>'.~9r~rt
Of
arrayelenlent
..
I~pj~~~~~~~~lR~~~~~;~.~~~w~~
...••
If
~.~.
·~~ll~t~issp~~~f~e~yttl~current
..
is
!l$$91l1eO,f$ee$ectiPfl.ll,2.(j).
FORTRAN-SO
Examples:
LOGICAL *2 FLAG
LOGICAL* 1 FLAGS(10)
Defining Variablest Arrayst
And
Memory
LOGICAL
*4 FLAG1, FLAG2, SWITCH(5)*1
3.1.4 CHARACTER Type
The
CHARACTER
CHARACTER [* len[,]] name [,name]
where
'name'
v[* len]
ary[(d)][* len]
and
v
ary
ary(d)
len
type statement has the format:
is
one
of
the forms:
is
a variable name
is
an
array
name
is
an
array
declarator
is
the length
character
(number
array
Statement
of
element.
...
characters)
of
a character variable
or
The length specification immediately following the keyword
to
each item in the statement not having its own length specification. A length
specification immediately following an item
array, the length applies
length
of
a character (one byte)
Examples:
CHARACTER*15
CHARACTER*12 NAMES(50), CITIES(50), STATES(50)*5
CHARACTER LETTER
3.1.5 IMPLICIT
An
IMPLICIT
trinsic function names)
PLICIT
specification in a
statement can also be overridden by
statement containing the same symbolic name.
statement defines the type and length for symbolic names (except in-
types can be overridden, however, by type statements
to
each array element.
STRING
Statement
that
begin with the letter(s) specified by
FUNCTION
is
assumed.
statement. The length specified in
an
is
the length for
If
no
INTEGER,
length
LOGICAL,
CHARACTER
that
item only.
is
specified, the
IMPLICIT.
or
by
an
an
or
CHARACTER
standard
explicit type
IMPLICIT
applies
For
an
IM-
3-3
Defining Variables, Arrays,
The
IMPLICIT
And
Memory
statement has the format:
FORTRAN-SO
IMPLICIT
typ
(let
[,/et] ... ) [,typ
(let
[,let].
..
)].
..
where
typ
let
is
INTEGERf*bml ,
CHARACTER[*
is
a single letter
REAL,
len]
or
LOGICALt~lejz],
a range
of
letters in alphabetical
or
order
(e.g., C, I-M, N-Z)
The
IMPLICIT
must
precede all other specification statements in that program unit. The
unit can have more
specified
more
statement applies only to the program unit in which it appears
than
one
than
IMPLICIT
once.
statement,
but
the same letter
cannot
and
program
be
Example:
IMPLICIT REAL(A-B, D-H), CHARACTER
IMPLICIT INTEGER (I-N), LOGICAL
(C)
(O-l)
Unless these implicit definitions are overridden, the following symbols would have
the types indicated.
AVG
CNAME
FPNUM
INUM
PFLAG
(REAL)
(CHARACTER)
(REAL)
(INTEGER)
(LOGICAL)
3.2 Array Definition
An
array
is
defined by assigning a symbolic name to the array
dimensions.
CHARACTER
LOGICAL
Arrays can also be defined by the
DIMENSION
In any case, a symbol can be used only once in a
array declarator
not
be defined in a
statement. The
name
One
statement.
elsewhere:
way to
do
this
is
with type statements:
TICTAC(3,3)
TABLE(2,3,3)
COMMON
(section 3.2.1). The symbol
DIMENSION
array
name could,
statement as well as in the
of
course,
'TICTAC'
appear
and
specifying its
statement (section 3.4.2)
program
unit as
an
array name
in the example above could
CHARACTER
as a reference
or
array element
and
by the
in
an
type
3-4
TICTAC(3,2) = 'X'