Intel fortran-80 User Manual

FORTRAN-SO
PROGRAMMING
MANUAL
Manual
Order
Number: 9800481 A
Copyright
Intel
I
Corporation,
3065 Bowers Avenue, Santa Clara,
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'
FORTRAN-80
By
'array
element
name'
we
mean
an
theses as shown in the example above. identifies the entire array, with array
name
not
qualified by a subscript identifies the first element
An
array
name
is
local
to
the
program
one
exception. In
3.2.1 DIMENSION Statement
The
format
of
the
DIMENSION
01
M ENSION ary(d) [,ary(d)].
statement is:
..
Defining Variables, Arrays, And Memory
array
name qualified by a subscript in paren-
An
array
name
not
qualified by a sUbscript
an
EQUIVALENCE
of
the array.
unit in which it
is
declared.
statement, an
where each
ary(d
'ary(d)'
[,d]
....
)
is
an
array
declarator
of
the form
and
ary
d
is
the symbolic
is
a dimension declarator
name
of
the
array
Dimension declarators are discussed in more detail below (section 3.2.3). In general, they indicate the upper
bound)
number
of
each dimension. The maximum
of
dimensions in the
array
number
and
the
number
of
dimensions
of
elements (or
is
seven.
Examples:
LOGICAL INTEGER ARRAY DIMENSION TABLE(2,3), ARRAY(3,3,3)
TABLE
3.2.2 Kinds of Array Declarators
An
array
declarator
justable,
or
In a constant
justable
array
assumed-size
array
('ary(d)'
array
in the
declarator.
declarator, each
declarator contains one
DIMENSION
of
the dimension bounds
or
more variables as bounds:
format)
is
either a constant, ad-
is
a constant.
An
ad-
ARRAY(3,MI00LE,THIRD)
An
assumed-size
bound
An
of
the last dimension
ARRA Y(3,3, *)
array SUBROUTINE and
dummy
declarator, whereas assumed size. Like actual DIMENSION MON
statements. A variable appear program.
in the
The latter requirements can be avoided using the asterisk feature for the
array
declarator
is
an
asterisk.
name
may be used as a
subprogram.
array
declarators.
dummy
or
type statements, but unlike actuals, they
subprogram's
Thus, a program
An
array
array
declarators,
name
used as a dimension
dummy
last dimension, thereby gaining some
is
either constant
dummy
actual
array
or
adjustable,
argument
in a
can have actual
but
the upper
FUNCTION
array
declarators
declarator must be a constant
declarators may be constant, adjustable,
argument
program
dummy
list
efficiency.
declarators are permitted in
or
bound
in a
cannot
common
appear
of
an
array
block in the sub-
in COM-
must also
or
array
or
3-5
Defining Variables, Arrays,
3.2.3 Properties of Arrays
The
examples following the description
types
of
the array names
rays. They also specify (by default) the
And
Memory
of
the
and,
by implication, the types
lengths
DIMENSION
of
the elements.
statement specify the
of
the elements in the ar-
FORTRAN-SO
The remaining properties
of
the array are determined from the dimension
declarator. These are:
The
number
The size
The total number The
number
of
dimensions in the array
of
each dimension
of
array elements
of
dimensions equals the
number
of
declarator. Thus, the array
TABLE(4,4)
has two dimensions. The size
is assumed an
The size
of
a dimension
also the same as the
to
have the value one.
is
the same as the value
'upper
assumed-size array declarator.
of
an
array can generally be
dimension
The
upper
computed
'd'
bound.'
bound
dimensions specified by the array declarator. Thus
ARRA
Y(3,3,3)
would have
27
elements. The number
of
elements in
can be determined as follows:
dimension declarators in the array
in the array declarator format; it
The lower dimension
may be
as the
an
product
an
assumed-size
asterisk in the case
of
bound
the sizes
dummy
of
the
array
is
of
If
the actual
is
size
If
the actual argument
an
array
Array
elements are stored sequentially.
DIMENSION TABLE(3,1) TABLE(2,3)
'2.9'
would be assigned to the
is
'TABLE,'
(1,1
)(2,1
The
total number
multiplied by the
that
of
argument
of
the actual array;
size
'n,'
TABLE(3,3)
corresponding
is
an
array element name with a subscript value
the size
of
the
= 2.9 = 7.3
third
and
'7.3'
would be assigned to the eighth location.
)2.9(1,2)(2,2)(3,2)(1,3)7.3(3,3)
of
bytes in an array
number
of
bytes occupied by each element.
to
dummy
For
example, in the following sequence
storage location in the block whose low address
is
3.2.4 Referencing Array Elements
Array
elements are referenced by qualifying
form
ary
(s [,s]
...
)
the
dummy
array
the
number
an
array name with a subscript in the
is
n + l-p.
array
is
an array name, the
of
elements in the array
of
'p'
in
3-6
FORTRAN-80
where
'ary'
is
equal the
number
Each subscript dimension
bound
subscript must
Examples:
ARRA
Y(2,6) = A
ARRAY(I + ARRAY(M,M
an
array
name
and's'
of
dimensions in the
is
an integer expression in the range 1
of a dummy
not
exceed the size
J,
3)
= 8
is
a subscript. The
array
declarator.
array
is
an
asterisk, the value
of
the corresponding actual array.
+ N,M-N) = A + SQRT(8)
Defining Variables, Arrays,
number
:5
s:5 upper-bound.
of
of
the corresponding
subscripts must
If
the
upper
And
Memory
Figure elements
(1
:5
n:5 7),
3-1
can
is
'd'
pression.
Dimension
n Declarator
(d1)
1
(d
2
3
n (d1, ... ,dn)
1 ,d2)
(d1,d2,d3)
be used
to
calculate which element in the storage sequence
being referenced. In this figure,
is
the value
of
the upper dimension
Subscript Referenced
(s1
)
(s1,s2) 1 + (81-1)
(s1,s2,s3) 1 + (s2-1)
(s1, ... ,sn) 1
'n'
is
bound,
the
number
and's'
Element
s1
+ (s2-1)*d1
+ (s2-1 + (s3-1) *
+(s1-1) +(s2-1)*d1 + (s3-1)*d1 +
...
+(sn-1)*dn-1
+
dn-2*
of
of
dimensions
is
the subscript ex-
)*d2
d2
* d 1
*d2
...
d1
array
Fig. 3-1 Subscript Reference
3.3 Assignment Statements
The
type statements correlate a type
statements described in this section assign values elements.
Assignment statements are used variables
The
and
ASSIGN
array
elements. These statements have
statement
is
used
to
to
variable symbol name.
The
DATA
statement
is
used
to
initialize variables, arrays,
specific values.
and
length with a symbolic name.
assign arithmetic, logical,
assign a numerical statement label
to
variables, arrays,
or
character values
no
keyword.
and
to
array
The
or
array
to
an
integer-
elements to
3-7
Defining Variables,
Arrays,
And
Memory
FORTRAN-80
3.3.1
The formula.
Arithmetic Assignment Statement
arithmetic assignment
Its
v =
format
exp
is:
where
The'
v
exp
='
in
is
the
I
is
an
FORTRAN
name
arithmetic expression
has the sense 'is assigned the value'
Thus
I =
1+1
is
a perfectly correct
of
Execution 'exp'
according
of
'exp'
an
to the type
FORTRAN
arithmetic assignment
to
the rules listed in
of
'v,'
and value, as shown in Figure 3-2. for converting a real
number
tively.
statement
of
a variable
statement.
Chapter
definition
IFIX
and
to
an
integer
closely resembles a conventional arithmetic
or
array
statement
2 (see Figures 2-2
and
assignment
FLOAT
and
an
element
causes evaluation
in this figure are intrinsic functons
integer
of
type integer
rather
and
of
'v'
to
a real
or
real
than
'is equal
of
the expression
to.'
2-3), conversion
with the resulting
number,
respec-
TYPE
OF
'v'
INTEGER REAL INTEGER REAL
Example:
1=3
C = I + SQRT(25.0) C =
AS A RESULT OF THESE
C
If
the value
may
happen
of
tion
If
the length
of
'exp'
when the length
the integer value (see section
of
'v'
preserving its value.
Example:
TYPE
INTEGER REAL REAL INTEGER
f'i~.
C**2
is
too
large to be assigned
of
'v'
is
longer, the length
OF
'exp'
3-2 Result
is
of
CALCULATIONS
too
short
F.l).
of
'exp'
RESULT
exp exp IFIX (exp) FLOAT
'v
= exp'
to
'v'
the result
to
contain the processor representa-
is
converted to the length
(exp)
C = 64.0
is
undefined. This
of
'v'
while
3-8
INTEGER* 1 M(1000) INTEGER*4 N M(200) = N
C LENGTH
= 65
OF
N
IN'
IS CONVERTED TO
ONE
BYTE
FORTRAN-SO
Defining Variables, Arrays,
And
Memory
3.3.2 Logical
The logical assignment statement assigns the
or
v =
v
array
exp
variable
where
exp
Examples:
C FLAG C OTH ERWISE
3.3.3 Character
The character assignment statement assigns a character constant, variable name, array
element
Assignment
element. It has the
is
the
name
is
a logical expression
LOGICAL FLAG, TABLE(3,3) FLAG
TABLE(1,3) TABLE(1,2)
= (INT1 .NE. 1 .AND. INT2 .EQ.
IS
.TRUE.IF BOTH CONDITIONS ARE TRUE
IS
.FALSE.
Assignment
name
to a character variable
Statement
format
of
a logical variable
= .FALSE. = FLAG
Statement
or
value.
or
array
TRUE.
logical
element. Its
or
array
1)
.FALSE.
element
AND
format
to
is:
a logical
or
v =
char
where
v
char
None
of
the character positions being defined in two sides than
'char,'
'char'
is
truncated
Examples:
CHARACTER*10 NAMES(4), MGR MGR
NAMES(1)
NAMES(2) = 'OTT' NAMES(3) = 'RUTH' NAMES(4)
3.3.4 ASSIG N
The
ASSIGN name. The symbolic mat
identifier in context, it must first be redefined as statement.
is
the
name
is a character element name.
of
the assignment
the latter
= 'STENGEL'
is
on
the right until it fits into
= 'GEHRIG'
= MGR
Statement
statement
name
an
input/output
of
a character variable
constant, character variable name,
may
have different lengths, however.
padded
is
on the right with blank characters.
the only way
can then be referenced in a
statement.
or
character
'v'
can
be referenced in
'v.'
to
assign a statement label to a symbolic
GO
To
use the symbolic
an
integer value in
array
element
or
character
If
If
TO
statement
name
an
arithmetic assignment
'char.'
'v'
'v'
is
or
in any
array
The
is
longer
shorter,
as a for-
other
3-9
Defining Variables, Arrays,
The
ASSIGN
And
Memory
statement
has
the
FORTRAN-80
format:
ASSIGN
where
stl
name
The
statement statement must
not
An integer variable defined with a same
or a different
Examples:
stlTO
in the
be
declared as length
name
is a statement
is
an
integer variable
label
must
same
program
statement
label (1-5 digits)
be the label
unit
INTEGER * 1.
label value, as well as with
ASSIGN 1010 TO LOOP1 GOTO
LOOP1
GO TO LOOP1(1000, 1010, 1020) IF(.NOT.DONE)
THEN ASSIGN 20 TO WRFORM ELSE ASSIGN 25 TO WRFORM ENDIF WRITE (6,WRFORM) PNAME, AVG
20 FORMAT 25 FORMAT
..
.
..
.
name
of
an
as the
ASSIGN
statement
executable
statement.
label value
statement
The
may
be redefined with
an
integer value.
or
a
FORMA
variable
T
'name'
the
3.3.5 DATA Statement
The
DATA clements. or
'common,'
statements
The
DATA statements
The
DATA
DATA
where 'clist'
has
[r*]c[,[r*]c] ...
where
c
r
Dummy
'nlist'
the
statement
arguments
memory
are
part
statement
and
before
statement
nlist
felistl [[,]
is
a list
form:
is a constant
is a 'repeat'
'r*c'
gives the initial values
can be initialized by
of
a
BLOCK
must
any
statement
has the
nlist
of
variable
is
equivalent
and
functions
DATA
appear
format:
felistl] ...
(including a
character
function
names,
to
Or'
in a
and
of
variables, arrays,
cannot
subprogram
array
Hollerith
is a nonzero,
successive repetitions
be initialized by
DATA
(section 3.4.3).
program
or
executable
names,
constant)
statements
unit
and
array
unsigned, integer
DATA.
after
the specification
statements.
element
of
the
constant
if
and
Shared,
the
DATA
names,
constant;
'c.'
array
and
3-10
FORTRAN-80
Defining Variables, Arrays,
And
Memory
Items in 'Nlist'
to-one.
constant for each element
is specified must be
The constant in 'elist,' except
and
type
DATA
If
lists must agree in
'elist'
must
have the same
'nlist'
contains
of
a name specified in 'nlist' must agree with the type
an
array
of
that
an
integer constant.
that
an
constant. Given a length
corresponding initial Hollerith
'n'
is
less are equal. Note itializes
that
A variable
'g'
than'
g,'
that
entire item.
or
array element
of
a variable
the constant
initialization
cannot
constant
two symbols are associated, only Examples:
DATA
I,J,K/10,20,301
CHARACTER*10
DATA
NAMES/'GEHRIG',
number,
type,
number
and
length.
of
items, as the lists correspond one-
name without a subscript, 'elist' must have one
array
(but
see section F.2.9.2). Any subscript
of
the corresponding
item
of
any type can be initialized
or
array
element in
in 'elist' must be less
is
padded on the right with blanks until the lengths of
a character in a variable
be initialized
one
may be initialized.
'nlist,'
more
then the length In'
than
than
once in a
or
to
or
equal to
array
a Hollerith
element in-
program.
NAMES(3)
'OTT', 'RUTH'I
of
'g.'
that
its
If
If
INTEGER*1 ZEROS
DATA ZEROS 110*0/1,J,K
(10)
110,20,301
&NAMES(2) I'OTT'I
C AMPERSAND USED TO CONTINUE STATEMENT
LOGICAL TABLE(3) DATA
TABLE
I.TRUE., .TRUE., .FALSE.!
3.4 Memory Definition
The
DATA also ineludes three statements for establishing memory areas areas. These are the
EQUIVALENCE associating a variable which it appears. The
ferent
program BLOCK memory.
3.4.1 EQUIVALENCE Statement
The
EQUIVALENCE All entities listed in the memory (even
and
assignment statements assign values to specific items.
program
units, allowing
(for example, a
DATA
subprogram,
if
they are
EQUIVALENCE,
is
used
to
associate two
name
with
COMMON
COMMON,
an
array element. Its scope
statement can be used
common
common
data
which can assign initial values to items in
statement allows items in a
EQUIVALENCE
of
unequal lengths).
and
BLOCK
or
more
items in memory, such as
to
use
of
data
and
memory
base
or
table). BLOCK
program
statement share the same start address in
FORTRAN
and
initializing these
is
DATA
the
statements.
program
associate items in
through
DATA
an
defines a
common
unit
to
share memory.
unit in
dif-
entire
format
The
EQUIVALENCE
of
the
EQUIVALENCE
(nlist)
statement is:
[,(nlist)] ...
3-11
Defining Variables, Arrays,
where
'nlist'
may
ter
only be subscripted by integer qualified by a subscript Function
Equivalenced items ed.
The
EQUIV
Example:
And
is
names
Memory
a list
of
and
the names
may
ALENCE
variable names,
is
the same as a reference
of
have different
statement
array
dummy
data
does
names
or
constants.
The
to
arguments
types,
although
no
type conversion.
array
element names.
use
of
an
the first element
may
not
be listed.
this
is
not
array
name
of
the
recommend-
The
array.
FORTRAN-80
lat­un-
INTEGER* REAL
1,
ARRAY(3), LlST(6)
FPNUMB
EQUIVALENCE (ARRAY,LlST), (LlST(4),FPNUMB)
The
The than
resulting
ARRAY LIST FPNUMB
EQUIV
once in a
memory
ALENCE
memory
allocation would be:
I A(1) I A(2) I A(3) I
L(1) I L(2) I L(3) I L(4) I
I LOW I I HIGH I
statement
sequence,
must not cause the same storage item
nor
can
it
L(S)
result
quence.
Examples:
C
THE
FOLLOWING
EXAMPLES ARE
INVALID DIMENSION ARRAY(3) EQUIVALENCE (ARRAY(1),FPNUM B),(ARRAY(2),FPNUMB)
C
FPNUMB
OCCURS MORE
THAN
ONCE REAL TABLE(2), ROOTS(3) EQU IV
ALENCE
(T
ABLE(1), ROOTS(1 )),(TABLE(2),
&ROOTS(3))
C MEMORY SEQUENCE IS SPLIT
I L(6) I
in
the splitting
IN
MEMORY
to
occur
more
of a memory
SEQUENCE
se-
3-12
3.4.2 COMMON Statement
Common program. named
The
where
memory
The
or
unnamed
format
of
COMMON
cb
nlist
blocks allow
COMMON
(that
the
COMMON
[/[eb]!]
is
the
name
is
a list Function listed.
data
statement
is,
'blank').
statement
nlist
[[,]/ [eb]!
of a common
of
variable names,
names
and
and
defines
is:
nlist]
the
memory
common
...
block.
array
names
to be shared
blocks
names,
of
dummy
throughout
that
may
or
array
arguments
an
entire
be either
declarators.
cannot
be
FORTRAN-80
Defining Variables, Arrays,
And
Memory
The items in 'nlist' following a to be in statement refers to the blank omitted in the above present, however, block.
The statements, either in the same items in different ing the same name also have the same starting address in memory. The same of linked
3.4.2.1
A COMMON within the
An done by adding EQUIV same block are considered
that
block (or in blank common).
same
common
all declarations
program.
Common
common
EQUIVALENCE
block memory sequence consists
statement(s) for
COMMON
memory
ALENCE
program
unit
format,
if
blank
block
program
of
blank
Block Memory Sequence.
statement(s).
statement may cause a
statement must
to
be associated. Names associated with a
to
be
common
common
the slashes may be omitted also. The slashes must be
common
name
program
units are associated in memory. All
common.
that
beyond the highest location in the
part
of
block name (or omitted name) are declared
If
a
block.
is
specified as other
(or blank) can
unit
or
Only one blank
of
common
not
that
block, in the
common
cause two different
common
common
If
in
the
block.
the first
appear
other
program
common
memory
block
block name
common
than
the first
in
other
units. This
common
can exist in the final
of
all items listed in the
order
of
their appearance
to
be extended. This
common
common
name
is
omitted, the
block name
COMMON
blocks hav-
block. blocks in the in a
common
common
is
is
is
how
true
is
An
3.4.2.2 Named
Named and blank
Within a same size. Blank
Executing a common
DA
TA
named
Examples:
C PREVIOUS STATEMENT EXTENDS C
'BLOCK1'
C
BLANK ARRAY ELEMENTS
C
3.4.3 BLOCK DATA
BLOCK
named
DATA The in a SA VE,
DATA
common
statement, which
last statement must be the
BLOCK
EQUIVALENCE,
and
Blank
common
program,
common
RETURN
blocks
to
statements in a BLOCK
common
blocks.
COMMON
LOGICAL LOGICS(3,3),Z
COMMON COMMON
IS
EQUIVALENCE (Z,LOGICS(1,
COMMON
Common
blocks are treated differently in several respects.
all
common
block-s
or
END
become undefined. This
IBLOCK1/A,B,ROOTS X,Y,Z IBLOCK1/C
NOW
EXTENDED BY LENGTH EXTENDED
Subprograms
subprograms
blocks. The first statement
DATA
are used
mayor
subprogram
DATA,
may
END
and
Blocks.
blocks having the same
may
be different sizes.
statement sometimes causes items in named
cannot
DATA
statement. The only
are
subprogram
/I
BLANK
1))
AGAIN-BY
to
initialize variables
of
such a
not
name the BLOCK
IMPLICIT,
the type statements.
name
must also be
occur with blank
can
only initialize items in
TABLES(3,3)
COMMON OF
'C'
8 LOGICAL
and
array
subprogram
other
DIMENSION,
is DATA statements permitted
common.
elements in
the BLOCK
subprogram.
COMMON,
the
3-13
Defining Variables, Arrays,
3.4.4 BLOCK DATA Statement
The
format
BLOCK DATA [name]
where
'name'
Since
'name'
main
program,
unnamed
Only an item in a or
type
statement
mon
BLOCK
If
a
named
they
are
not itialized in a single block not
be specified in
Examples:
And
Memory
of
the
BLOCK
is
the
is
global,
common
BLOCK
DATA
J
common
in a
can
be initialized in a
common
all initialized.
more
symbolic
it
must
block,
subprogram
BLOCK
block
data
than
DATA
block
name
not
or
may
statement
of
be
another
DATA
BLOCK
is
initialized, all items in
More
than
subprogram,
one
block
BLOCK DATA BLK1 LOGICAL
FLAGS(3) INTEGER ZEROS(10),RESULTS COMMON
/BLOCK1/ FLAGS,ZEROS,RESULT
DATA FLAGS/.TRUE., .TRUE., .FALSE.!
&ZEROS/1 0* 0/
END
is:
the
BLOCK
the
same
BLOCK
is
permitted
appear
in a
subprogram.
DATA
one
named
but
data
subprogram.
DATA
as
the
name
DATA
per
executable
DIMENSION,
Only
subprogram.
the
common
the
same
subprogram.
of
an
external
subprogram.
an
item in a named
block
must
block
named
common
procedure,
Only
one
program.
EQUIVALENCE,
com-
be listed, even
may
have items in-
block
may
FORTRAN-SO
if
3-14
CHAPTER 4
PROGRAM
FORTRAN execution. These are statements tions), regulate execution loops tion
(PAUSE,
4.1
The
statements in this cases only when a stated condition as conditional native set
The
statements
4.1.1
includes
STOP,
16
statements,
END).
or
that
transfer control (GO
(DO,
Transferring Program Oontrol
group
pass
control
is
meL
and
unconditional branching. Some statements also allow
of
operations
that
Unconditional Computed Assigned Arithmetic Logical
GO
GO
IF
Unconditional GO
transfer
GO
TO
TO
IF
to
TO
be
performed
program
TO
Statement
control are:
EXECUTION CONTROLS
statement variations, for controlling
TO,
IF,
and
CONTINUE),
to
another
These alternatives are usually referred
if.the stated conditions are not met.
and
part
Block
ELSE ELSE END
terminate
of
the
program,
IF
IF
IF
program
program
their varia-
execu-
in some
to
an
alter-
The
unconditional
ecuted.
where as the
Example:
It
GO TO
'stl'
GO
GO TO 1010
has the
is
TO
GO
TO
statement transfers control
format
stl
the statement label
statement.
to
the next statement
of
an
executable statement in the same
4.1.2 Computed GO TO Statement
The
computed
based on the value
GOTO
is
GO TO
where
exp
stl
The same statement label may expression has a value in the range labels in the list), control passes to the statement pointed side this range, execution continues with the statement following the
GO
TO
statement branches
of
a controlling integer expression. The
(stl
[,stl] ... )[,]exp
is
an
integer expression
is
the statement label
program
unit as the
appear
of
computed
more
1::5
exp::5
to
one
of
several executable statements
format
an
executable statement in the same
GO
TO.
than
once in the statement.
n (where
'n'
is
to
the
by
number 'exp.'
program
of
the
If
If
GO
to
be ex-
computed
the integer
of
statement
'exp'
is
TO.
unit
out-
4-1
Program Execution Controls
Examples:
C IF K = C 1020
C NOTE
4.1.3 Assigned GO TO Statement
GO TO (1010,1020,1030) K
2,
FOR EXAMPLE, CONTROL PASSES TO STATEMENT
INTEGER*1 SWITCH SWITCH GO TO
THAT
GO TO
= K/J
(10,500,500,10,10)
'J' MUST BE .LE.
(10,
500, 600, 500) K * L + 1
'K'
SWITCH
IN THIS EXAMPLE
FORTRAN-SO
The assigned GO
TO variable name. Before the assigned defined with the value gram
unit.
The
format
GO TO name
where
name
stl
The
same statement label may thesized list must be one
Examples:
GO
TO
is
similar
to
of
the assigned
is
an
is
the statement label
program
of
statement labels
of
the labels in the list.
ASSIGN
GOTOSTART
ASSIGN 999 TO DONE
GO TO DON
statement
the
computed
of
a statement label by an ASSIGN statement in the same pro-
n,]
(stl
integer variable name
is
GO
TO
[,stl]
...
)]
unit as the assigned
appear
is
10TO
START
E (500, 600, 999)
used with the ASSIGN statement. The assigned GO
TO,
but in this case the control
GO
TO
is
executed, the variable name must be
statement
more
present, the statement label assigned
of
is
an
executable statement
GO
TO.
than
once in the statement.
is
an integer
III
the same
If
the paren-.
to
'name'
4-2
4.1.4 Arithmetic I F Statement
The
arithmetic IF statement behaves similarly transferred expression. The
to
one
format
of
three possible statements based on the value
of
the arithmetic IF
IF(exp)s1,s2,s3
where
exp
s
The
same statement label may
If
the value equals zero, control passes trol passes to the third statement.
of
is
an
integer
is
the statement label
program
'exp'
unit as the arithmetic IF.
is
less
than
to
or
real expression
appear
the second statement;
more
zero, control passes to the first statement listed;
of
to
a computed
is
an
executable statement in the same
than
once in the statement.
if
'exp'
is
greater
GO
TO.
of
than
a controlling
Control
if
zero, con-
is
it
FORTRAN-SO
Examples:
IF(A + 8)1010,1020,1030
Program
Execution Controls
SWITCH = IF (SWITCH) 100,200,300
A**2 -8**2
4.1.5 Logical I F Statement
We have given several examples effect, if the logical expression evaluated next.
If
the
logical expression
following the logical The
format
where
of
IF (exp)
exp
stmt
A function reference in the controlling logical expression parameters in the statement
Examples:
IF
statement.
the logical
stmt
is
is ELSE,
IF (SWITCH .EO. IF (SWITCH
IF
a logical expression
any executable statement except DO, a block IF,
END
of
logical
is
FALSE, execution continues with the statement
statement
IF,
END,
'stmt.'
1)
.NE.
1)
IF
statements already in this manual. In
is
TRUE,
is
or
other
GO TO FINISH WRITE (6,20) TOTALS
a specified statement
logical
IF
is
permitted
is
executed
ELSE
to
affect
IF,
LOGICAL DONE DONE IF (DONE) PAUSE IF (.NOT. DONE) GO TO START
=
(A * *2
.GT.
8**2)
4.1.6 IF, ELSE IF, and ELSE Blocks
The block IF statement
ELSE
IF
and
ELSE
Together with
'ELSE IF,
These blocks may be block, which may contain For
ment
An to, but nesting level as the block
An ment
has the same nesting level as the
IF
or
ELSE, respectively.
example, there may be no executable statements at all between a block
and
IF block consists
not
ELSE
up to,
other
blocks,'
its corresponding
including, the next ELSE IF, ELSE,
IF
block consists
but
not
is
used with the
statements
executable
or
'ELSE
'nested.'
of
all the executable statements
including, the nest
to
control
FORTRAN
blocks,'
another
END
IF
statement. of
the first statements
For
example,
IF
block, etc. These blocks may also be empty.
IF
statement.
all the executable statements
ELSE
ELSE
IF
END
IF
statement
program
statement.
execution.
statements, they can form
of
which must be IF, ELSE
an
IF block may contain
after
the block
or
END
IF
statement on the same
after
IF,
ELSE,
or
END
and,
optionally, the
'IF
another
IF
statement up
the
ELSE
IF
statement
blocks,'
IF
IF
state-
IF
state-
that
4-3
Program Execution Controls
An
ELSE
up
to,
but
ELSE
as the
For
each block IF statement, there must be a corresponding
same
program
block consists
not
including, the next
statement.
unit.
IF
...
ELSE
IF
...
IF
...
:
END
IF
_______________
ELSE
IF
...
END
IF
of
all the executable statements after the
END
IF statement
that
has the same nesting level
END
IIF
BLOCK
=:J
ELSE IF BLOCK
--,
IF
BLOCK ELSE BLOCK
_
IF.
. . ]
ENDIF
________
IF
BLOCK
IF
BLOCK
ELSE
statement
IF
statement in the
FORTRAN-SO
END
IF
______________
4.1.7 Block I F Statement
The
format
where
If
the value
block.
END FALSE, level as the block
Control section F.2.9.3).
If
the last statement in the IF block does statement, control passes level as the block
An
example
of
the block IF
IF
(exp)
THEN
'exp'
is
a logical expression.
of
'exp'
If
the
IF
IF statement
control passes
cannot
if
shown following the description
is
is
TRUE,
happens
on
the. same nesting level as the block
IF
statement.
execution continues with the first statement
to
be empty
to
the next
be transferred into
to
the next
IF
statement.
and
'exp'
is
TRUE,
ELSE
IF, ELSE,
an
IF block from outside the
not
END
IF statement
or
END
transfer control
of
the
END
_
of
the
control passes to the next
IF
statement.
IF
on the same nesting
IF
to
another
that
has the same nesting
If
'exp'
block (but see
executable
IF statement.
IF
is
4-4
4.1.8 ELSE I F Statement
The ELSE
where
IF
ELSE IF
'exp'
is
statement has the
(exp)
THEN
format
a logical expression.
FORTRAN-80
If
'exp'
is
IF
block.
TRUE,
If
normal execution continues with the first statement
'exp'
is
FALSE,
control passes
statement having the same level as the
ELSE
to
the
IF
statement.
next
ELSE
IF, ELSE,
Program Execution Controls
of
the
ELSE
or
END
IF
Control section F.2.9.3). The statement label, referenced by
If
cannot
'be transferred into
another
statement.
the last statement in the ELSE
an
ELSE
if
IF
block does
IF
any,
ecutable statement, control passes to the next nesting level as the
An
example
ELSE
IF
statement.
is
shown following the description
4.1.9 ELSE Statement
Executing the is
ELSE
The
ELSE block ELSE statement. This ELSE
IF
Control section F.2.9.3). The statement label, referenced by
or
another
cannot
another
ELSE
statement has
is
terminated by
END
IF
ELSE
statement
be transferred into
statement.
no
effect; execution simply continues. Its
an
END
statement must
of
the same nesting level.
an
ELSE block from outside the block
if
any,
block from outside the block (but see
of
the
ELSE
IF
END
of
the
statement
not
pass control
IF
statement having the same
END
IF
statement.
to
another
cannot
format
IF
statement
appear
of
the same level as the
before the appearance
of
(but
of
the ELSE statement
cannot
be
ex-
an
see
be
An
example
is
shown following the description
4.1.10 END IF Statement
Executing the END
IF
block
IF
IF
statement
The
format
ENDIF
Example:
END
IF statement has no effect; normal execution continues. The
statement acts as a
terminator
statement must have a corresponding
of
the same nesting level as the block
of
the
END
IF statement
IF (FLAG .EO.
3)
WRITE (6,20) NAME(3), PAY(3)
20
FORMAT
ELSE IF (FLAG .EO.
WRITE (6,40) FEDTAX
40
FORMAT
ELSE
WRITE(6,60) FICA
60 FORMAT
ENDIF
for IF, ELSE IF,
is
THEN
...
2)
THEN
...
...
of
the
END
END
IF
IF
statement.
IF
statement.
and
ELSE blocks. Each
statement,
that
is, an
END
4-5
Program Execution Controls
4.2 Loop Control Statements
FORTRAN-80
Frequently, a series reading a series
ly). Rather
one
can create a loop until all entries have been read ment.
The
CONTINUE
statement, though it
than
of
operations must be repeated several times (for example,
of
entries from
repeat the statements
that
statement described in this section
is
not
an
input device
to
perform
causes the same statements
and
processed. This
limited
to
this use.
4.2.1 Operation of a DO Loop
The first statement labeled statement whose label define the range are executed a specific
The
DO
statement includes three values: an initial loop index value, a loop termina­tion value, and decremented. Each time the loop ed to the initial index value, value until the loop termination value with the statement following the last statement
This sequence describes the most also terminate operation as the result loop, a transfer program,
or
program termination for any other reason.
of a DO
of
the
an
amount
of
control outside the loop, execution
loop
is
the
DO
statement itself. The last statement
is
specified in the DO statement. These two statements
DO
loop. The statements making up the body
number
of
times, as defined in the DO statement.
by which the initial value
is
performed, a
is
increased
common
or
is
reached.
operation
of a RETURN
and
extracting
these operations for each entry,
to
is
the function
is
'DO
variable,' previously initializ-
decreased by the incrementl decrement
Program
of
the DO loop.
of a DO
statement executed within the
information
be performed over
of
ordinarily used with the DO
is
to
be incremented or
execution then continues
loop. A DO loop can
of a STOP
statement in the
selective-
and
the DO state-
of
the
DO
over
is
loop
a
Program
control
cannot
be transferred into a
DO
4.2.2 DO Statement
The
format
where
In this format, and
'e3' ment iterations are performed (but see the discussion trols in section F.2.5).
The last statement TO, RETURN, logical ELSE
of
the
DO
statement
DO
sfl
[,] var = e1,
stl
var
e
is
of
one
assigned
IF
IF, ELSE,
is
the last statement in the is is
'eI'
the loop incrementl decrement
is
assumed. The values
GO
STOP,
statement, it can contain any executable statement except a
e2
the statement label
the name an
integer expression.
is
the initial loop index value,
of
a DO loop, statement
TO,
END,
or
END
IF,
is
[,e3]
of
an
executable statement and
DO
loop.
of
an integer variable, called the
amount.
of
'eI'
and
'stl,'
arithmetic IF, block IF, ELSE IF, ELSE,
DO
END,
statement.
or
another
If
the last statement
logical
loop.
'DO
'e2'
is
the loop termination value,
If
'e3'
is
not
'e2'
can be specified such
of
the
0077/0066
must
not
be
an
IF
statement.
is
the label
variable.'
specified,
unconditional
of
the
an
compiler con-
END
DO
loop
DO,
block IF,
incre-
that
of
no
GO
IF,
is
a
4-6
FORTRAN-80
DO
loops
may
be nested,
DO
statement the second can
share the same last statement.
I f a
DO
of
the
DO
appears
DO
statement
statement lies within
loop
must
within the range
be entirely within
that
is, a
DO
must
be within the range
an
IF
block,
loop
of
that
can
another
ELSE
block.
contain
DO
of
the
IF
block,
another
loop,
outer
or
ELSE
Program Execution Controls
DO
loop, etc.
the
loop
specified by
DO
loop.
block, the range
DO
If
loops
a
I f a block
statement must also be within the range Examples:
The
IF
statement
first example demonstrates the looping process.
is
within the range
of
N=O
DO 100 I
J = I
DO L=K
100 N = N + 1 110 CONTINUE
When
looping
of
blanks
use
The following example players (one team).
C LOOP C
is
completed~
to
isolate the nested
Compare
CHARACTER*12 PNAME DO READ 10, PNAME, AB, HITS
10 FORMAT
AVG = HITS/AB PRINT 20,
20
FORMAT (A12,
30 CONTINUE
CAN NOT TERM I NATE WITH STATEM ENT 20
BECAUSE
'FORMAT'
==
1,10
100 K = 1,5
I = 11, J = 10, K = 6, L = 5,
is
another
this
30
1=1,25
(A12, 2(2X, F3.0))
PNAME, AVG
IS
DO
loop
program
program
5X,
F4.3)
NONEXECUTABLE
of a DO
the
in this example.
to Figure 1-1...
loop, its corresponding
DO
loop.
to
compute
END
and
N = 50.
batting averages for
Note
IF
the
25
4.2.3 CONTINUE Statement
The
format
of
the
CONTINUE
statement
is
CONTINUE
as shown in the preceding example.
statement
This next executable statement.
has
no
effect
on
program
execution, which simply continues with the
4.3 Program Termination Statements
FORTRAN The
PAUSE statement program program.
provides three statements for halting
statement
terminates
unit. It terminates a
halts execution,
program
execution.
main
but
program
or
terminating
allows execution
The
END
statement
and
acts as a
program
to
resume.
marks
RETURN
execution.
The
STOP
the end
from
a sub-
of
a
4-7
Program Execution Controls
FORTRAN-SO
4.3.1
The
where time the console terminal.
Program program control, however, and might be initiated, for example, by rupt quence
Examples:
PAUSE Statement
format
such as a key being pressed.
of
the
PAUSE
PAUSE [msg]
'msg'
is
a string
PAUSE
execution must be resumable following the pause. Resumption
is
continued with the statement following the
PAUSE PAUSE PAUSE
is
executed
1234 'BREAK
statement
of
not
12'
is
more
than
five digits,
and
program execution ceases,
If
execution
is
or
is
a character constant.
'msg'
resumed, the normal execution
PAUSE
statement.
4.3.2 STOP Statement
The
format
of
the
STOP [msg]
STOP
statement
is
At
is
displayed on the
is
not
under
an
external inter-
the
se-
where
'msg'
is
a string
STOP
terminates execution
displayed on the console terminal. Examples:
STOP STOP
22
STOP
'CHECK
4.3.3
The
The gram, it terminates the program.
RETURN
gram unit
An must that
EN
0 Statement
format
END
of
the
END
statement
statement and returns
must
END
statement
not
be continued. No other statement in a
appears
to
be
be
of
not
more
of
the executable program. When this happens
SUM'
END
statement
marks
the end
an
END
statement.
is
written only in columns 7
an
END
statement.
than
five digits,
is
of
a program unit.
If
executed in a
to
the main program. The last line
or
is
a character constant.
If
subprogram,
through
program
unit can have an initial line
executed in a main pro-
72
'msg'
it has the effect
of
every pro-
of
an initial line and
of
is
a
4-8
CHAPTER 5
FUNCTIONS AND SUBROUTINES
Functions logical structures, conserve storage, avoid the tedium error functions.
The term is
referenced. A subroutine
alter the values All functions
Intrinsic,
Single-statement, user-defined functions (statement functions);
User-defined function by their initial
Subroutine subprograms identified by their initial
External functions cedures.' These may be the assembly language procedures)
When a procedure the place called. The use of
this chapter.
and
subroutines reduce coding, break programs into readily-visible
in repetitive coding, and eliminate the coding
'function'
program,
of
'actual
refers
to
a statement
is a subprogram
of
variables outside itself.
and
subroutines are called
or
predefined,
FUNCTION
and
or
they may be procedures created elsewhere (e.g.,
is arguments' to be substituted when the procedure
of
dummy
FORTRAN
subprograms
statement;
subroutines are referred to collectively as 'external pro-
FUNCTION
and
defined, it usually includes
and
actual arguments will become clearer in the remainder
or
subprogram
that
'procedures.'
functions;
(external functions), which are identified
or
SUBROUTINE
linked to the
and
increased probability
of
commonly-used mathematical
that
returns a value when it
does not return a value, but may
These include:
SUBROUTINE
subprograms
program
'dummy
where
appropriate.
arguments'
statement.
defined within
PL/M
used to hold
is
referenced
and
of
or
5.1
Intrinsic and Statement Functions
5.1.1
FORTRAN operations such as square tions, etc. The complete list dix tion definitions, type that PLICIT
An
The reference (for example, the actual value arguments with the specifications in Appendix B and may be any expression type.
Arguments for which the result numerical range tions on the range notes in Appendix
Intrinsic Functions
provides a
B.
This appendix shows the names
have
more
than
statement has no effect
intrinsic function
A = 33 + SQRT(8)
resulting value depends on the value
that
constitute the
of
number
of
arguments,
one argument, all arguments must be
is
referenced by specifying it in an expression.
the processor cause results
of
arguments
B.
of
predefined functions for performing
root
calculation, type conversion, trigonometric calcula-
of
available intrinsic functions can be
of
and
on
the types
argument
is
not mathematically defined
and
results for intrinsic functions are listed in the
the various intrinsic functions, their func-
type
of
results.
of
intrinsic functions.
of
the actual argument(s) used in the
of
'B'
in the expression above). The actual
list must agree in type, number,
not
For
those intrinsic functions
of
the same type. The IM-
or
defined in this manual. Restric-
common
found
in Appen-
and
order
of
the specified
which exceed the
5-1
Functions
And
Subroutines
I f
the
name
of
an
intrinsic
TION
or
SUBROUTINE the intrinsic its intrinsic quality. normal
If
the
procedure
function
(by
default
name
of
reference, the
an
intrinsic
or
function
subprogram,
within the scope
The
data
by a type
function
name
5.1.2 I NTRI NSIC Statement
The
INTRINSIC function pearance unit an
The
and of
is
allowed. A symbolic
EXTERNAL
format
statement
allows
a symbolic
statement
of
the
INTRINSIC
that
name
name
appears
type associated with the symbolic
statement).
is
must
first be specified in
confirms
to
be used as
in all
of
name
may
in the
same
statement
in the
the
name
of
the
program
to be used as
that
a symbolic
an
the
INTRINSIC
not
appear
program
unit.
is
dummy
is
considered
unit
an
actual
an
name
actual
statements
in
an
argument
to
have
and
the
name
argument
INTRINSIC
represents
argument.
in a given
INTRINSIC
list
of a FUNC-
no
name
is
specified as
in
an
statement.
an
Only
statement
relation itself loses
to
external
intrinsic
one
ap-
program
and
FORTRAN-SO
INTRINSIC
where
'func'
The
names therefore, type conversion ing a largest AMINO,
Examples:
cannot
MINI).
INTRINSIC INTRINSIC
tunc
[,tunc]
is
an
intrinsic function
of
certain
or
smallest value (MAXO,
intrinsic
appear
(lNT,
SQRT
EXP, LOG, LOG10
in
IFIX,
INTRINSIC
FLOAT,
...
functions
5.1.3 Statement Functions
Straightforward
= ax
f(x)
are
defined
keyword;
tunc
where
mathematical
2
+
bx
in
FORTRAN
the
format
is
([dum [,dum]
+ c
...
])
functions
using
= exp
name.
cannot
statements.
REAL,
AMAXI,
like
statement
be used as
ICHAR)
AMAXO,
functions.
actual These and
the functions for choos-
MAXI,
These
arguments
are
the functions for
MINO,
functions
and,
AMINI,
have
no
5-2
June
dum
exp
As
an
example,
F(X) =
Substituting would
result in the value
is
the symbolic
is a dummy the
function
is
an
expression
the
mathematical
A*(X**2)+
the
actual
argument is
referenced
8*X
+ C
argument
'9A
+ 3B +
name
function
'3'
of
the
statement
to
be replaced by
above
for
the
C.'
would
dummy
function
an
actual
be
written
argument
'X'
argument
in this
function
when
FORTRAN-80
The
statement
The
type
The
dummy
statement function.
function only,
The
type
used outside the The
name
the same type in
identify a variable
unit, but they have no
function
of
the value
argument
and
each
of a dummy
statement
of a dummy
other
of
name
and
returned
is
as shown in Figure 3-2.
list indicates the
The
names
of
dummy
name
may
argument
name
function.
argument
can
statement-function the same type other
relationship.
the expression
order,
arguments have a scope
appear
only once in the
is
the same as it would be
be used
statements.
or a common
5.1.3.1 Referencing Statement Functions
A statement function quired actual arguments).
is
referenced by specifying its symbolic
'exp'
may
number
to
and
identify
other
The
type
name
block within the same
Functions And Subroutines
be
of
different types.
of
arguments for the
of
the statement
dummy
dummy
argument
if
the
arguments
name
can also be used to
name
(with any re-
list.
were
of
program
DATA A,
FSUM(X) = A *(X* *2) + TOTAL
This
operation
function
B,
C
110.0,
= 33 + FSUM(3.0)
substitutes
definition.
At
10.0,
the
3.81
B*X
the
value '3.0'
end
+ C
of
the
operation,
for
every
occurrence
the
value
'156.8.'
5.1.3.2 Statement Function Limitations
All statement functions must follow all specification statements executable statements.
name
of
The symbolic in
any
specification statement, except in a type statement
mon
block in the same
an
EXTERNAL
A statement function
a statement function
program
statement
or
cannot
as
be
unit.
an
of
The
actual
type type character, the length specification tant.
Each
operand
in the statement function expression
ing:
A
constant:
FPROD(C) = C*3.1412
A variable reference:
FPROD(C)
An
array
element reference:
FSUM(C) = C +
An
intrinsic function reference:
FHVP(A,B)
A reference
An
external function reference:
FSU.B(C) = 3*C
A
dummy
FSUB(C) =
to a statement
FTOTAL(C)
procedure
=
C*3.1412+
2ITABLE(1,3)
= SQRT(A * *2 +
function:
=
C/3 + FUNC(3.8)
- EXFUN(3.
reference:
3*C
- EXFUN(X, Y,Z)
is
local
name
is
argument.
character.
of
that
argument
AV12
B*
*2)
0,
3.
and
cannot
or
as the
also prohibited from being used in
If
it has a
must
'exp'
must
0,2. 5)
of
'X' in the
of
'TOTAL' is
and
must precede all
be a symbolic
name
of
dummy
be one
be
an
argument
integer cons-
of
the follow-
name
a com-
of
5-3
Functions And Subroutines
A
statement
The
statement function FUNCTION reference
cause a ed.
is
dummy
5.2 External Procedures
This
section desi:ribes external
FUNCTION
to
external
function
defined later in the
subprogram
to
an
and
procedures:
may
function
external
argument
may
function
of
SUBROUTINE
RETURN,
be referenced only in
not
program
must
the
statement
reference
not
in
the
procedures,
subprograms.
SAVE,
another
unit.
Furthermore, a statement
reference
expression
function
EXTERNAL,
the
program
statement
the
name
of a statement
to
become
specifically
It
also describes
and
unit
where it
function
of
the
subprogram.
function
undefined
procedures
statements
the
subroutine
is
defined.
if
that
other
function
must
or
redefin-
defined by
related
CALL.
FORTRAN-80
in a
A
not
5.2.1
The TION
program
The
where
FUNCTION Statement
FUNCTION
statement
must be
format
of
the
[typ] FUNCTION tunc
typ
June
dum
The
FUNCTION
must
become defined
of
this variable when a
An
external
addition
If
'typ'
conventions
function
to the
function
is
not
specified, the type
described in sections 2.2.2.1
statement
must always be the first
terminated
FUNCTION
is
either
1,2,
or
is
the symbolic
name.
is a dummy procedure
subprogram
or
in a
introduces a FUNCTION
with
an
END
statement
([dum
[,dum]
INTEGER
[*Ien],
4.
name
of
argument
name.
name,
appearing
redefined each time the
RETURN
subprogram
value
or
returned.
and
length
END may use
statement
statement.
is
...
])
REAL,
the
subprogram
and
is
either a variable,
as a variable within the
is
executed
dummy
of
'func'
and
2.2.2.2.
subprogram.
of
the
subprogram
or
LOGICAL
and
subprogram
is
the value
arguments
are
determined
[*lenJ, len being
is
an
external
array,
is
executed.
of
to
return
by the
The
FUNC-
and
the sub-
function
or
dummy
subprogram,
The
value
the
function.
values in
default
5-4
5.2.1.1
An with all necessary
The with their subroutine type.
A
Referencing External Functions.
external
actual
Actual
An An An An
function
arguments
corresponding
name
arguments
expression array
name intrinsic function external
dummy
procedure
is
referenced by specifying its
actual
arguments).
in the reference
as
an
actual
must
procedure
dummy
argument; also be
name
name
name
must
agree in
arguments.
subroutine
one
of
the following:
order,
One
names
name
in
number,
exception
do
an
not
have
expression
type,
and
is
the use
an
associated
(along
length
of
a
FORTRAN-SO Functions And Subroutines
An actual a
dummy
reference.
5.2.1.2
A
FUNCTION subprogram. SUBROUTINE,
The other
program. name may
specified in the
be type character. The symbolic
program DATA,
A function specified by a subprogram procedure however, either directly
compiler control in section F.2.3).
When program.
gram before it TRAN
argument
argument list within the subprogram containing the external function
FUNCTION
name
of
name in the
Within the
appear
unit
or
COMMON
or
in the main
an
external function reference
External functions created outside the
compiler
may also be a
dummy
Subprogram
statement
The
subprogram
BLOCK
the
FUNCTION
subprogram,
is
FUNCTION
name
and
cannot
is
executed. External procedure linkage
operator's
may
be used only as the first statement
itself can consist
DATA,
subprogram,
a type statement,
of a dummy
statement (except as a
program.
or
or
PROGRAM
subprogram
except for its use as a variable in the
the only nonexecutable statement in which the
statement. A
argument
be used in an
A function
indirectly (but see the description
manual.
argument as long as the
Limitations
of
any
other
statement except a
statement.
is
global
and
even this
FUNCTION
in a function
EQUIVALENCE,
common
can
be referenced within any
is
executed, the function must be
and
is
not
subprogram
subprogram
block name).
subprogram
program
cannot
be the same as
permitted
SAVE,
must.not reference itself,
of
the
must be linked is
described in the
dummy
of a FUNCTION
body
is
part
of
any
of
the sub-
if
the type
name
is
local to the
INTRINSIC,
other
REENTRANT
part
to
may
not
external
of
the
the pro-
FOR-
is
Example:
C THE FOLLOWING EXAMPLE TOTALS THE C VALUES IN AN ARRAY
FUNCTION
DIMENSION ARRAY(I)
TOTAL
DO
100 CONTINUE
RETURN
END
OF
LENGTH I
TOTAL(ARRAY,
= 0.0
100 K =
TOTAL
1,
I
= TOTAL + ARRAY(K)
5.2.2 Subroutines
A subroutine
be called from anywhere in a
dummy
its operations, then returns control
SUBROUTINE
The program.
statement
or a FUNCTION,
subprogram,
return
control
is
used primarily
arguments specified in the subroutine definition. The subroutine performs
statement
The
subprogram
and
can contain any statement except
BLOCK
the
RETURN
to
the point
to
avoid
redundant
program,
must
(being a DATA,
statement can be specified
of
call.
with actual arguments substituted for the
to
the point
be the fitst statement program
or
PROGRAM
I)
blocks
of
call.
unit) must be terminated by
anotqer
of
code. A subroutine can
of a SUBROUTINE
SUBROUTINE
statement.
to
At
some point in the
tell the subroutine when
sub-
an
END
statement,
to
5-5
Functions
And
Subroutines
The
subroutine
is
called by
the
CALL
PROGRAM
FORTRAN-SO
statement.
CALL
.~RETURN
CA.~END
END
Subroutines, time a subroutine program described in the
5.2.3 SUBROUTINE Statement
The
SUBROUTINE
SUBROUTINE
SU
where
sub
being external
program
definition
containing a CALL
must be
FORTRAN
subprogram.
BROUTI N E
is
procedures,
part
of
the
or
by being linked
compiler
statement
Its
sub[([dum[,dum
the symbolic
name
to
calling
to
operator's
is
used only as the first
format
] ... ])]
of
..
SUBROUTINE
can be defined
the
subroutine
program,
the
program.
is
the
subroutine.
either by
manual.
outside
External
the
program.
is
executed, however, the
SUBROUTINE
procedure
statement
By
sub-
linkage
of
the
is
a
dum
If
no
dummy
'SUBROUTINE
The
symbolic
any
other
name
The
symbolic used in ment,
An
example
except as a
name
an
EQUIVALENCE,
is
5.2.4 RETU
The
RETURN
only in a
have statement
The
FUNCTION
one
or
terminating
format
RETURN
more
of
is a dummy procedure
arguments
subO'
name
of
in the
of a dummy
common
shown following
RN
Statement
statement
RETURN
the
RETURN
name.
are
is
acceptable.
the
subroutine
program
block
returns
or
SUBROUTINE
such a
statement
argument
specified, either
unit.
argument
SAVE,
name.
the
control
statements,
program
and
is
a global
is
INTRINSIC,
RETURN
to
or
unit has the
is
simply
is
either a variable,
of
the
forms
name
and
local to the
statement.
the
calling
subprogram.
they
DATA,
may
same
program
program
have
effect as a
array,
'SUBROUTINE
must
not
be the
unit
and
or
COMMON
unit. It
These
none
may
subprograms
at all.
RETURN.
or
dummy
sub'
same
cannot
appear
The
or
as
be
state-
may
END
5-6
FORTRAN-SO Functions
And
Subroutines
When a
RETURN
is
executed in a
FUNCTION
tion must be available to the referencing
Whenever
an
external procedure
RETURN
is
executed, the association between the
and
the current actual arguments
tion 5.2.5, the SA VE statement). Example:
C TH
REE N UM
C TO 11F THEIR
BERS ARE ADDED AN D TH E FLAG
TOTAL
IS
POSITIVE
SUBROUTINE POSTOT(A,B,C)
IF
((A
+ B +
C) POSTOT = 1 ELSE POSTOT
= 0
ENDIF
RETURN END
5.2.5 SAVE Statement
The SAVE statement can be used to FUNCTION RETURN
The
format
or
SUBROUTINE
or
END
is
executed.
of
the SAVE statement
subprogram
is
program
.GE.
make
subprogram,
the value
of
the func-
unit.
0)
THEN
sure
that
dummy
is
terminated (but see sec-
'POSTor
common
arguments
SET TO
variables within a
do not become undefined when a
of
SAVE
where that
block. A specific SA VE statement. Entities in blank executing
'cb'
is
RETURN
lebl
[,Iebl] ...
a named
common
common
or
END.
block. Naming the
bloj:k
cannot
common
be listed
never become undefined as the result
common
Example:
SAVE IBLOCK1/,/BLOCK21
5.2.6 EXTERNAL Statement
The
EXTERNAL
dummy The
procedure
format
EXTERNAL
where
'proc'
If
an intrinsic function can no longer be used stead becomes the
A symbolic name can be specified only once in all the program
unit.
statement confirms
and
allows
of
the
EXTERNAL
proe
is
the
name
to
name
that
name
statement
[,proe]
name of
...
of
an
external
is
specified in
specify
an
an
external procedure.
that
a symbolic
to
be used as
is
or
dummy
procedure.
an
EXTERNAL
intrinsic function in the
block saves all items in
more
than
name
represents
an
actual
argument.
statement,
program
EXTERNAL
once in a single
of
an
external
that
or
name
unit, but in-
statements in a
Example:
EXTERNAL HYP,
POSTOT, SIN
5-7
Functions
And
Subroutines
5.2.7 CALL Statement
The
CALL enced within must REENTRANT
The
format
where
statement
any
other
not
reference itself either directly
compiler
of
the
CALL
CALL
sub
[([arg [,arg].
is
used
external
control
statement
to
reference a procedure
or
in section F.2.3).
is
..
])]
subroutine. A subroutine
or
in the
main
program. A subprogram
indirectly
(but
see the description
can be refer-
of
the
FORTRAN-SO
sub
arg
The
actual and
(if applicable) length with the
referenced
ment, the type
is
the symbolic
is
an
arguments
subroutine.
conformity
actual
in the
If
associated type.
Each actual
An
An
argument
expression array
name
must
An intrinsic function
An external
A
dummy
An
actual
name
appears
procedure
procedure
argument
in a dummy
in a
CALL.
Examples:
THE
C
C C
FOLLOWING
THE
SUBROUTINE
EXAMPLE
(SECTION
name
argument.
CALL
the
name
rule does
be
one
of
name
name
name
CALL
statement
argument
STATEMENTS
DEFINED
5.2.5)
of a subroutine
or
dummy
statement must agree in
corresponding
of a subroutine
not
apply since subroutines
dummy
is
specified as an actual argu-
the following:
may
be a
dummy
list within the
COULD
IN
THE
subprogram
BE
'RETURN
procedure.
order,
number,
argument
do
argument
containing the
USED
TO
CALL
STATEMENT'
list
not
name
type,
of
have
if
the
an
that
5-8
CALL CALL
POSTOT(3.2,-2.7,0.08) POSTOT(X,5.2**I,-Y)
5.3 Arguments And Common Blocks Revisited
Arguments cedures ment
external procedures common
FORTRAN
and
argument subroutine of
others
and
and
function
common
statements referencing the procedures.
or
intrinsic function by
and
blocks
other
are
program
the means
an
argument
units by
of
communicating
Data
can be passed
list.
Data
argument
can be passed between
lists
blocks.
has a
number
lists. We
of
very specific rules governing the use
touched
on
the most
important
references were discussed. This section repeats those rules plus a
related
to
arguments
and
common
blocks.
between pro-
or
can be shared in
of
common
when function
to
a state-
number
blocks
and
FORTRAN-80
Functions And Subroutines
5.3.1 Common Blocks
Common to share the same referencing
The
subprograms memory given data the same type.
An gram
blocks reduce storage requirements by allowing two
memory.
data.
variables
common
referenced
integer variable
unit containing its
and
that
location
block
rather
and
arrays in a
contain
ASSIGNed
This sharing
common
a declaration
than
by
may
be different in the different
the
common
a statement label
ASSIGN
may
block
name,
statement.
so the names
block name used to reference the
be limited by the rules for defining
can
of
that
5.3.2 Dummy And Actual Arguments
A
dummy tual referenced.
Dummy SUBROUTINE
argument
the tion, the
argument
argument
arguments
dummy
is
used in the
is
used in the corresponding
are used by statement functions,
subprograms
is
a single value,
argument
must be a variable.
argument
to
specify the types
array,
or
list when defining a procedure.
argument
procedure.
or
more
subprograms
be defined
common
of
subprograms.
can
only be referenced in the pro-
FUNCTION
of
actual arguments
In
the case
and
referenced in all
block. 'Association
variables
list when the procedure
and
arrays
However, the
data
must be
subprograms,
and
of
a statement func-
and
is
by
of
of
An
ac-
is
and
whether
a
Dummy
(that
prohibited.
SA VE,
dummy ment function
Actual
arguments
function sions (if the associated ternal procedure). defined later in the
argument
is, variable,
Dummy
INTRINSIC,
name
also
name
arguments
for a
or
subroutine
names
can
be used anywhere
array,
or
dummy
argument
or
COMMON
cannot
particular
An
program
be the same as a
declared in the same
list the entities to be associated with corresponding
procedure
references,
dummy
actual
procedure)
names
argument
unit containing the reference.
cannot
statements (except as
program
reference. Actual arguments
or
expressions, including parenthesized expres-
argument
cannot
5.3.3 Association Of Arguments
When a procedure associated; the first actual argument, when the actual
If
an sion, the actual is
referenced.
actual
etc.
argument
reference
Therefore,
argument
is
associated with a
argument
is
executed, the actual
argument
the
arguments
is a subroutine
must be defined with
replaces all occurrences
must agree in
name),
dummy
an
actual
name
of
and
type can be used, unless explicitly
appear
FUNCTION,
is
not defined during execution
in
EQUIVALENCE,
common
SUBROUTINE,
unit.
be the
name
of
a statement function
and
dummy
of
order,
number,
and
length (where applicable).
appearing in
an
integer value when the
an
adjustable
may
the first
the same 'class'
DATA,
block names). A
or
state-
dummy
be constants,
of
the ex-
arguments
type (except
are
dummy
dimen-
procedure
If
an tion. tion.
actual
If
the actual
argument
is
an
is
an
expression, the expression
array
element name, its subscript
is
evaluated before associa-
is
evaluated before associa-
5-9
Functions
And
Subroutines
NOTE
The subscript value remains constant as long as the arguments are associated, even
if
the subscript contains variables redefined during the
association.
FORTRAN-80
Argument association can be carried
through
more
than
one level
of
procedure reference. A valid association exists at the last level, however, only if the association is
maintained when a cedure reference
5.3.3.1 Agreement
If
a
dummy
and
length.
through
RETURN
argument
If
the
all intermediate levels. The association normally terminates
or
END
is
to
the next.
Of
dummy
executed. The association
Argument Lengths
is
type character, its actual argument must be the same type
is
an
array name, the length requirement applies
is
not retained from one pro-
to
each
element in the array.
If
the dllmmy
lepgth~lfaninteger
as
shq""n
integer
c~ssordetermines
argumentis
c()nstant
in~ection
variable
2.2.Z.2.That
length;if
its length implicitly.
type integer. the arguments must again
is
used as
the base
is,
an
of
the integer
an
actual
integer
argument, its length is deterInined
without
abas~suffix
constantisstated
agreeiu
type
and
has the default
explicitly, tbe pro-
5.3.3.2 Variables As Dummy Arguments
A variable ment, name, its Otherwise, if the actual argument dummy
dummy
or
expression.
dummy
argument
argument can be associated with an actual variable, array ele-
If
the actual
argument can be defined
must
not be redefined within the subprogram.
argument
is a constant,
is
a variable name
or
redefined within the subprogram.
function reference,
or
array
or
expression, its
element
5-10
5.3.3.3 Arrays As Dummy Arguments
An array ment name. The declarator can be declarator.
If
not
If
ray element with a subscript with the subscript value (p than ment.
dummy
argument
number
differept from the dimensions in its associated
the actual argument
be greater
than
the size
the actual argument
the size
of
the actual array plus one minus the subscript value
can be associated with an actual and
size
of
dimensions in an actual
is
an array name, the size
of
the actual argument array.
is
an array element name with a subscript
'q'
becomes associated with the actual array element
+
q-l).
The size
of
5.3.3.4 Procedures As Dummy Arguments
I f a
dummy argument a
dummy actual argument subroutine referenced as a function.
argument
is
used as if it were an external function, the associated actual
must be an intrinsic function, external function, argument appears in a type statement
argument
must be the
is
referenced as a subroutine, the actual argument must be the
or
dummy procedure
name
of
a function
and
must
not
of
the
dummy
the
dummy
array
or
and
an
EXTERNAL
or
dummy procedure.
appear
in a type statement
array
name
or
array ele-
argument
dummy
argument array must
'p,'
the
dummy
must not be greater
of
the array ele-
dummy
procedure.
statement, the
If
the
dummy
name
array array
ar-
If
of
or
be
a
FORTRAN-SO
NOTE
Functions
And
Subroutines
In a given associated cedure statement, enough with a
A
dummy association. the
result
of
dummy
as a the
subprogram. A dummy
procedure
as a number
5.3.3.5
If reference the
and
Argument Association Limitations
dummy
to
subprogram.
program
with a
name
and
to
determine
subroutine
argument
Therefore,
all
actual
external
name
type
with
arguments
that
subprogram, For
FUNCTION F(A,B,C)
could
not
be
referenced
F(X,
Y,
X)
function
appears
an
actual
or a function.
associated
the
arguments
function
in a
those
in
the
example,
by
unit,
det~rmining
or a subroutine
only
in a
dummy
argument
whether
type
argument function
specified
with
of
the
associated
name
same
neither
an
external
the
an dummy
loses its
associated
reference
for
subprogram
dummy
whether a dummy
may
not
argument
list,
examining
symbolic
intrinsic
the
function
name
argument
with it.
property
with
must
intrinsic
are
can
function
An
have function.
be
beginning with
be possible.
list,
an
the
subprogram
should
has
must
agree
intrinsic
as
an
intrinsic
an
intrinsic
arguments
associated
redefined
procedure
If a pro-
EXTERNAL
is
be
associated
no
automatic
with
the
function
function
as
during
name
function
that
the
result
execution
is
not
type
type
used
within
and
used
agree in
of
of
a
of
because'
If a subprogram item in a
mon
item
A'
and
common
can
be
'C'
would
reference
block
redefined
become
causes a
in
the
within
associated.
dummy
same
subprogram,
the
subprogram.
argument
neither
to
become
the
associated
dummy
nor
with
the
an
com-
5-11
The
FORTRAN
and
external units
ternal units
the
format
input/output
or
within the processor itself. These statements can specify the ex-
to
be used, the variables whose values are being entered
of
I/O
data.
(I/O)
statements transfer
data
CHAPTER
INPUT/OUTPUT
between a processor
or
output,
and
61
The first
BACKSPACE, used for connecting of
The external unit
by the output
group
of
I/O
statements are the file-handling statements
REWIND,
and
a file.
to
be used
READ,
is
WRITE,
formatted, these statements are used with the
ENDFILE).
disconnecting files, positioning files,
and
and
the list
PRINT
of
data-transfer
(OPEN,
As their names imply, these statements are
and
marking the end
variables to be
input
or
output
statements. When the input
FORMAT
statement.
CLOSE,
is
supplied
or
~~f:~~~~t~~~~~r.~~~~I~~.9:~~~~.~I~Btg1~<l~~t~.*P~~~2t:E~?P:S>~~i~~Intetf:9RjR~N
?~~~;~~~f~rp/~Ptq~$gt;l~~!pp.qr~lif:.~~~'~~Jl9.~~ffJf!J;Jff
s.ectionF.2,2. . .
Before any units are reviewed. They can be described only in general here, however, since many of
the specifics related to them are dependent on the processor
ment.
6.1
6.1.1
A record generally the same as the sum (in bytes) is
stated specifically in a record length specifier (section 6.2.1.8). Records are
classified as formatted
of
these statements are discussed, the properties
Records, Files, And Units
Record Properties
is
simply a sequence
or
of
values
unformatted.
or
of
the items written into the record, unless it
characters. The length
••
jq~ril1s~<:.
of
su
broutine~
records, files,
or
operating environ-
of
a record
·in
and
is
A formatted record can be any sequence cessor (except escape, carriage record can be a sequence
data.
These two kinds
formatted
I/O
statements, respectively.
of
return,
of
values containing
records can only be read
or
6.1.2 File Properties
The main properties
That
is
may exist;
That
it may have a name;
That
it has a position;
That
it
may be external
That
it may be accessed sequentially
That
it may have records
That
it
may have formatted
of
a file are:
or
internal
of
specific length or
unformatted
to
the processor;
or
of
characters representable in the pro-
line feed characters). An
both
character
or
written by formatted
directly;
(for
direct access files);
contents.
unformatted
and
non character
and
un-
6-1
Input/Output
6.1.2.1 File Existence
At
the time an executable program files are said to operating system
A file may exist without containing any data; an example would be a newly-created file having only a name.
exist,
and
or
environment in which the
is
running, a certain set
the particular files
program
of
files
is
available. These
that
exist are determined by the
is
running.
FORTRAN-SO
FORTRAN
All CLOSE, ist
and
are in the process
6.1.2.2
FORTRAN dependent. names:
File Name
MYFILE MYFILE.SRC :LP: :F1:PROG.OBJ
I/O
WRITE,
has no
For
example,
statements can refer
PRINT,
standard
and
ENDFILE)
of
being created.
file-naming convention. Such conventions are system
in
the ISIS-II environment all
1-6
character file name
file name plus device name, in this case line printer device name plus file name plus extension
to
existing files. Some statements
can also refer
1-3
character extension
to
files
that
of
the following are valid file
6.1.2.3 File Position
Once a file has been connected to a unit, it has a position. The 'initial is
the position preceding the first record. Its 'terminal the last record. record.'
Executing certain can cause the file position to become indeterminate.
If
the file
I/O
is
positioned within a record,
statements affects the position
point'
is
the position
that
record
of
the file. Some circumstances
do
not
point' is
the
(OPEN,
yet ex-
of
a file
just
after
'current
6-2
6.1.2.4 External
An
external file character variable, character array, you to transfer
An internal file CLOSE, BACKSPACE, sequential- access, formatted matting.'
An
internal file has the following properties:
Each record
The length
array element, it
array element. I f the file
an
array element in the array
A record may be read only if it has been defined. A variable
record
ment statement).
the record, the characters are left-adjusted in the record the record
An
is
internal file
And
Internal Files
is
a file
that
can be connected to an external unit.
or
character array element. Internal files allow
data
within processor memory.
cannot
is
of
defined by writing the record (or by making it the target in
is
filled with blanks.
be specified by one
REWIND,
I/O
statements
a character array element. the file depends on its kind.
is
a single record whose length
is
a character array, every record has the same length as
and
If
the number
is
always positioned
of
of
ENDFILE).
the file has as many records as array elements.
characters written
at
its initial point before a
the file-handling statements
It
can only be read
that
do not specify 'list-directed for-
If
the file
is
is
the length
is
a character variable
less
and
An
internal file
(OPEN,
or
written by
of
the variable
or
array element
an
than
the length
the remainder
data
transfer.
is
or or
assign-
of of
a
FORTRAN-SO
6.1.2.5 File Access
An
external file can be accessed sequentially
be accessed sequentially.
Some external files
operating to
a unit.
environment.
may
be allowed The
access
more
method
or
directly.
than
one access
is
determined when the file
An
method,
internal file can only
depending on the
is
connected
Input/Output
6.1.2.5.1
Sequential Access File. A file connected for sequential access has the
following characteristics:
The
records are a totally ordered set, having the
written.
The
records
If
the file
the same as the
6.1.2.5.2
are
either all
may
also be connected for direct access, the
order
of
the sequential write.
Direct Access Files. A file connected for direct access has the following
characteristics:
The
Its records are either all
read
order
or
written in
of
its records
any
order.
formatted
Its records can be read List-directed
All records
Each record
written. A record
formatting
of
the file
of
are
the file has a unique record
cannot
ten.
6.1.3 U nit Properties
A
'unit'
is
a logical way executable CLOSE
program.
statement
A unit has the refers
to
a file. All
connected to a file.
property
of
referring
All
FORTRAN
can
also refer to nonexistent units.
of
110
statements except
formatted
is
the
or
cannot
or
all
unformatted.
order
of
their record numbers. Its records can be
or
all
unformatted.
written only by direct-access
be used.
the same length.
number,
be deleted
being connected
or
its
number
to
a file. Like files, units can exist
110
statements can refer to existing units. The
or
OPEN
and
order
in which they were
order
of
a direct-access read
110
specified when the record
changed,
but
is
can be rewrit-
or
disconnected.
CLOSE
If
connected,
must
reference a unit
is
statements.
is
not for
an
it
is
Typically, a file CLOSE be
statement. Depending
preconnected, meaning they
connected by the
having to be connected by the nected the first time it
environment the console
nected. See the discussion A unit
may, the same
must
not be connected to
of
course, be disconnected by the
or
a different unit by the
The
only way
is
referenced by
output
of
to
refer
to
statement. Consequently,
it
nected once
has been disconnected.
OPEN
on
the
operating
can
be referenced by
OPEN
the
statement. A preconnected file becomes con-
an
110
device
and
UNIT
run-time
more
than
CLOSE
OPEN
statement.
NOTE
a disconnected file
an
unnamed
statement
and
disconnected by the
environment, some units may also
110
statements without first
statement.
console
control
one file
statement
file
may
For
example, in the ISIS-II
input
device
in section F.3.
at
a time,
and
is
by naming it in
not
be able
are
always precon-
and
vice versa. A file
then reconnected
an
OPEN
to
be recon-
to
6-3
Input/Output
6.2 File-Handling Statements
6.2.1 OPEN Statement
The
OPEN preconnected file, create a file the
file/unit
The
format
OPEN (open-list)
statement can be used to connect
and
connection.
of
the
OPEN
statement
connect it
is
to
an
existing file to a unit, create a
a unit,
or
change certain specifiers in
FORTRAN-SO
where 'open-list'
[UNIT IOSTAT = ERR = FilE STATUS = ACCESS = aee FORM = RECl BLANK = b/nk CARRIAGE::::;
The unit specifier specifiers are
is
being connected for direct access. Some specifiers have default values.
file
The following sections 6.2.1.1 through 6.2.1.10 describe each
specifiers in detail.
6.2.1.1
The
Unit
format
[UNIT
is
a list
=]
unit
stname
st/
= fname
stat
fmat
= ree/en
car
'unit'
optional
Specifier
of
the unit specifier
=]
unit
except
of
specifiers separated by commas.
U nit specifier
II
0 status speci fier
Error
specifier
File
name
specifier
File status specifier
must be present
that
the record length
is
Access
Formatting Record length specifier Blank specifier
Carriage
method
specifier
control specifier
and
the unit specified
(REeL)
The
specifier
must
must
list
of
specifiers is:
exist. All
be specified
of
the 'open-list'
other if
the
6-4
where
'unit'
identifies
specifier must be the first item in
An external unit identifier
0:$unit:$255.
Examples:
OPEN OPEN
6.2.1.2
The
format
IOSTAT =
where
(UNIT=3) (4)
1/0
Status
of
'stname'
the
an
Specifier
input/
output
stname
is
an
integer variable
external unit.
must
If
the
optional
'open-list.'
be
an
integer expression whose value
status specifier
or
integer
is
array
'UNIT
element
='
is
omitted, the unit
name.
is
in the range
FORTRAN-80
Input/Output
Executing defined with a zero value positive integer value
Example:
6.2.1.3
The
where 'st!' OPEN
If
the processor discovers
the following steps occur:
1.
2.
3.
4. Execution continues with the statement named by the
OPEN
Error
format
ERR =
statement.
The
OPEN
The
position
If
the
error
condition;
an
OPEN
(4,
statement containing this specifier causes
if
if
an
error
IOSTAT = ERRFLG)
Specifier
of
the
error
specifier
stl
is
the label
operation terminates;
OPEN
of
an
an
of
the file specified by
statement has an
no
error
condition exists,
condition does exist.
is
executable statement in the same
error
condition while executing the
OPEN
IOSTAT
specifier,
or
becomes indeterminate;
'stname'
'stname'
with a processor-dependent
program
OPEN
is
ERR
specifier.
set
to
to
become
unit as the
statement,
reflect the
Example:
OPEN
6.2.1.4
The
format
FILE = {name
where constant
program
the processor-determined file.
Example:
OPEN(UNIT=3,
6.2.1.5
The
format
STATUS = stat
(4,
IOSTAT=
File
Name
of
the file name specifier
'fname'
is
or
variable. The file
is
executing.
File
Status
of
the file status specifier
Specifier
the
name
Specifier
FILE=
ERRFLG,ERR= 1010)
is
of
the file
name
If
'MVPROG.SRC')
to
be connected, expressed as a character-type
must be valid for the particular system in which
FILE
is
omitted, the unit becomes connected to a
is
where
'stat'
is 'UNKNOWN'. 'UNKNOWN'.
a character expression evaluating
If
the STATUS specifier
to
'OLD',
is
omitted, the default value
'NEW',
'SCRATCH',
or
is
6-5
Input/Output
If
'OLD'
file
The specified with duration unit.
If
'UNKNOWN'
Example:
or
must
exist already; a
'SCRATCH'
of
OPEN
(3,
'NEW'
option
an
unnamed
program
is
specified, the file
FllE=
is
specified, the
'NEW'
must
file, the file
execution
FILE
specifier
file
not
or
cannot
until a
exist already.
be specified with a
is
connected
CLOSE
status
is
processor dependent.
must
statement
'MYPROG.SRC', STATUS = 'NEW')
be present also.
named
to
the specified
is
issued for the same
file.
An
When
unit
'OLD'
it
is
for the
FORTRAN-SO
6.2.1.6
The
Access
format
Method
of
the access
Specifier
method
specifier
is
ACCESS = ace
where
'acc'
is a character (see section 6.1.2.5). TIAL'.
If
the file already exists, the specified access
For
a new file, the processor creates the file with the specified access
access
method
sent in Example:
'open-list.'
OPEN
& ACCESS = 'SEQUENTIAL')
6.2.1.7
The
formatting
formatted
FORM =
where
FORMATTED'.
FORMATTED' TED'
'fmat'
when the file
is
'DIRECT',
(3,
FllE='MYPROG',
Formatting
specifier states whether a file
input/
output.
(mat
is a character
If
when the file
is
expression evaulating
If
the
ACCESS
the record length specifier (6.2.1.8)
specifier
to
is
omitted,
method
'SEQUENTIAL'
must
STATUS='NEW',
Specifier
is
being connected for
Its
format
the
FORM
being connected for sequential access.
is
expression evaluating
specifier
is
being connected for direct access,
is
omitted,
to
the
'FORMATTED'
or
'DIRECT'
the
default
be allowable for
default
is
'SEQUEN-
method.
must
also be pre-
formatted
value is
and
'FORMAT-
that
or
If
or
'UN­'UN-
file.
the
un-
6-6
If
the file already exists, the specified
new file, the processor creates the file with the specified
Example:
OPEN
& ACCESS = 'SEQUENTIAL', FORM = 'FORMATTED')
6.2.1.8
The
record
nected for direct access. Its
RECl
where
(3,
FllE='MYPROG',
Record
Length
length specifier identifies the length
Specifier
format
= ree/en
'reelen'
is
a positive integer expression.
formatting
must be legal for
STATUS='NEW',
of
is
each
formatting.
record
in a file being con-
that
file.
For
a
FORTRAN-80
If
the file
If
the file
If
created. In the case
is
being connected for formatted
is
being connected for
unformatted
110,
110,
the file already exists, the length specified must be
of
a new file, the processor creates a file with the specified length
for each record. The
REeL
specifier must be included in the
OPEN
connected for direct access.
Example:
'reclen'
is
the
the length
that
number
is
used when the file was
statement when a file
of
characters.
measured in bytes.
is
being
Input/Output
OPEN
& FORM = 'FORMATTED',
6.2.1.9
The
format
BLANK
where specifier
If
'NULL'
cept
that
(3,
FILE='CARDS',
Blank Specifier
of
the blank specifier
=
blnk
'blnk'
is
one
of
the character constants
is
omitted, the default value
is
specified, all blanks in numeric
a field
of
all blanks has the value zero.
STATUS='NEW',
RECL=80)
is
is
cept leading blanks have the value zero. The
specifier
is
permitted only for files being connected for formatted
Example:
OPEN
&
FORM='FORMATTED',
(UNIT=3,
FILE='TOTALS',
BLANK='ZERO')
ACCESS='DIREcr,
'NULL'
'NULL'.
formatted
If
'ZERO'
STATUS='NEW',
or
'ZERO'.
input
is
specified, all blanks ex-
If
the BLANK
fields are ignored, ex-
input/output.
6-7
Input/Output
FORTRAN-SO
6.2.1.11 Opening A Connected
The
OPEN
file.
That
not
included in the
I f the file to be connected depends
nected,
statement can be specified for a unit already connected to
existing file
is
OPEN
assumed
'open-list.'
is
on
whether
or
if
it was preconnected
or
not the file was preconnected.
Unit
to
be the value
the same as the connected file, the effect
and
ment, only the BLANK specifier (and
If
existing attributes.
the file was preconnected,
the file, the propetties specified in the
connection. Subsequent
OPEN
statements can change only the BLANKS
attributes as described above.
I f the file connected file deleted status
I f a file
if
it was previously opened with status
is
'OLD',
is
already connected to a unit, no
different unit
be connected
is
closed 'NEW',
can
be executed.
is
not the same as the file already connected, the currently
and
the new file
or
'UNKNOWN'.
to
6.2.2 CLOSE Statement
The
CLOSE
IS
statement
is
used
to
disconnect a particular file
of
'fname'
if
the
FILE
If
the file was not precon-
has already been referenced by
RECL
is
for sequential files) may differ from
but
no
I/O
has been
OPEN
statement become the properties
opened with this unit.
'SCRATCH',
OPEN
statement connecting
The
but
from
is
a unit. Its
connected file
not
an
existing
specifier
of
OPEN
an
I/O
state-
performed
and
RECL
deleted
that
file
format
if
to
is
on
of
is
its
a
CLOSE (close-list)
where 'close-list'
[UNIT IOSTAT = ERR = STATUS =
The
unit specifier must be present; all
=]
stl
is
a list
unit
stname
stat
of
specifiers separated by commas.
U nit specifier I/O
status specifier
Error
specifier
File disposition specifier
other
specifiers are
The
optional
list
specified only once.
The
IOSTAT
and
6.2.1. 3, respectively.
and
ERR
specifiers have the same interpretation as in sections 6.2.1.2
The
UNIT
and
STATUS
specifiers are described in the
following sections.
6.2.2.1 Unit Specifier
The
unit specifier has the same interpretation as in section 6.2.1.1. Execution CLOSE as its corresponding CLOSE
Once a unit has been disconnected by the to been disconnected, it the file still exists.
statement containing this specifier need
OPEN
statement, however.
has no effect.
the same file
or
a different file within the same
may
be reconnected
CLOSE
to
the same
not
occur in the same
If
the specified file does not exist,
statement,
program.
or
it
may
Similarly, once a file
a different unit, so long as
of
specifiers is:
and
can be
of
program
unit
be reconnected
the
has
6-8
Example:
CLOSE
(3,
IOSTAT=
ERRFLG,
ERR=
1020)
FORTRAN-80
Input/Output
6.2.2.2
The
where specifier status be specified for a file opened with
If statement
If
File Disposition Specifier
format
STATUS =
'KEEP'
'DELETE'
of
the file disposition specifier
stat
'stat'
is
a character expression evaluating
is
omitted, the default value
of
'SCRATCH',
is
specified for
is
executed. Otherwise,
is
specified, the file ceases to exist
is
to
'KEEP'
is
'DELETE'
and
'KEEP'
otherwise. Under no circumstances can
'SCRATCH'
an
existing file, the file continues to exist
'KEEP'
has no effect.
for a file
status.
after
the
CLOSE
ecuted. Following
normal
are deleted; all others
program
termination, all connected units are closed. Scratch units
are
closed with disposition
'KEEP'.
Example:
CLOSE
(3,
ERR = 1020, STATUS
='
KEEP')
6.2.3 BACKSPACE Statement
The
BACKSPACE
positioned before the preceding record. Its possible formats are
statement causes the file connected to the specified unit to be
or
'DELETE'.
that
previously
after
statement
the
If
this
had
'KEEP'
CLOSE
is
ex-
a
BACKSPACE BACKSPACE (arg-list)
where
'unit'
is
by commas. The list
[UNIT
IOSTAT = ERR =
=]
unit
an external unit specifier
of
arguments is:
unit
stname
stl
and
'arg-list'
is
a list
External unit specifier
110
status specifier
Error
specifier
of
arguments separated
The argument list must include an external unit specifier (section 6.2.1.1) contain
an
110
status specifier (section 6.2.1.2)
and
an
error
specifier (section
6.2.1.3). The file being backspaced must be connected for sequential access.
If
the file has no preceding record, the
end-of-file condition has occurred, the file
BACKSPACE
is
positioned such
statement has no effect.
that
the last record
the file becomes the preceding record.
Backspacing over a record written using list-directed formatting Backspacing a nonexistent file
or
unit
is
prohibited also.
is
not
Examples:
BACKSPACE 3
(3,
BACKSPACE
ERR = 1020)
6.2.4 REWI N D Statement
The
REWIND
tioned
at
possible formats for the
statement causes the file connected
to
the specified unit
to
its initial point. The file must be connected for sequential access. The
REWIND
statement are
and
may
If
the
of
allowed.
be reposi-
REWIND REWI N D(arg-list)
unit
6-9
Input/Output
FORTRAN-80
where described
but has
Examples:
'unit'
for
If
the specified file
does
not
occurred,
is
an
external
the
BACKSPACE
is
already
exist,
the
the
file
can
unit
positioned
REWIND
still be
statement
statement
rewound.
REWIND 3 REWIND
(3,
IOSTAT=
ERRFLG,
6.2.5 ENDFILE Statement
When
the
ENDFILE
becomes
on
must
The
the
the file
be
connected
possible
last
without
formats
ENDFILE ENDFILE (arg-list)
where described
before
f the file
I
'unit'
for
can
the
end-of-file
is
the
be
statement
record
of
the
first issuing a
for
sequential
of
the
unit
an
external
BACKSPACE
connected
record
is
file.
access
ENDFILE
unit specifier
statement
for direct access
can
be
specifier
and
(section
at
its initial
has
ERR=
executed,
No
data-transfer
BACKSPACE
when
statment
and
(6.2.3).
read
during
'arg-list'
6.2.3).
point,
no
effect.
1030)
the
record
I/O
or
REWIND
ENDFILE
are
'arg-list'
also,
only
subsequent
is
a list
or
if
the
If
an
end-of-file
preceding
statement
statement.
is
issued.
is
a list
those direct access
of
arguments
file is
the
can
of
arguments
records
connected
condition
ENDFILE
be
executed
The
file
appearing
operations.
as
as
I f a file
ENDFI Examples:
is
preconnected
LE
statement
to
causes
a unit
the
ENDFILE 3 ENDFILE
6.3 Data-Transfer
Once
a file
statement, statements. connected
has
or
Note
to
(3,
ERR = 1040)
been
data
that
a line
printer,
1/0
connected
can
be
the
keyword
nor
6.3.1 READ Statement
The
READ
where
statement
READ
(ctl-list)
[in-list]
READ f [,in-list]
etl-Iist
in-list
reads
data
is a list
is
but
does
file
to
be
created.
Statements
to a unit,
written
does
from
a list
data
into 'PRINT' the
keyword
a specified
of
control
of
the
data
not
yet exist, specifying
in
the
file
can
the file using
does
not
imply
'WRITE'
unit.
Its
information
to
be
read
be
read
the
WRITE
that
imply
possible
specifiers
the
using
an
that
it is
formats
unit
the
or
output
not.
are
in
an
READ
PRINT
file
is
6-10
is a
f
format
specifier in
identifier,
'ctl-list.'
and
is
the
same
as
the
'FMT
=
f'
FORTRAN-SO
Input/Output
The list
of
control
[UNIT [FMT REC
=]
=]
= recno
IOSTAT =
information
unit
f
stname
specifiers is:
ERR = stl END =
6.3.1.1
The control READ
stl
Control
Information
information
list must contain a unit specifier.
statement shown above
List
is
used (that is,
the default unit.
The
'ctl-list'
The following sections 6.3.1.1.1
may
contain, at most, one
through
detail.
6.3.1.1.1
OPEN 'unit'
Unit Specifier.
The
unit specifier has the same interpretation as for the
statement (section 6.2.1.1). In addition, for
may be
an
asterisk.
If
this
processor-determined external unit. The unit specifier may also point
of
a character variable, character array, case, 'ctl-list' must contain a contain a record
number
format
specifier.
U nit specifier Format
Record I/O
Error
specifier
number
specifier
status specifier
specifier
End-of-file specifier
If
the second form
if
of
each
no unit
of
the
is
specified), the unit read
other
specifiers.
6.3.1.1.6 describe control list specifiers in
data-transfer
is
the case, the specifier identifies a particular
to
an
internal file (that is,
or
character
identifier (other
'unit'
array
than
I/O
statements,
may be the name
element name). In this
asterisk)
and
of
may
the
is
not
If
the optional
'UNIT
list.'
Example:
READ
(2)
PNAME, AB, HITS
6.3.1.1.2
ment The
where
The label
Format
is
aformatted
format
[FMT
'f'
is
of
this specifier
=]f
one
of a FORMAT
An
integer variable ASSIGNed the label
A character
containing a
An
asterisk (*) specifying list-directed formatting (section 6.4.4);
An
integer, real,
data.
If
the optional 'ctl-list' 'UNIT
=.'
'FMT
and
the first item must be the unit specifier without the optional characters
='
Specifier.
I/O
statement; otherwise, it
of
the following:
array
name, character variable name,
format
specification;
or
logical
='
is
omitted, the unit specifier must be the first item in 'ctl-
If
'ctl-list' contains a
format
is
an
unformatted
specifier, the
I/O
READ
statement.
is
statement in the same
array
containing a
is
omitted, the
format
program
of a FORMAT
format
unit as the READ;
statement;
or
character expression
specification as Hollerith
specifier must be the second item in
state-
6-11
Input/Output
FORTRAN-SO
I f the asterisk
If
the unit specifier
not
be
an
asterisk.
Examples:
25 FORMAT
25
25
6.3.1.1.3 list' if
Record
and
only if the file to be read
REC = recno
'recno'
where pression
is
the
option
is
selected, 'ctl-list'
is
an
internal file, the
READ (2,25) PNAME,
...
READ 25, PNAM FpRMAT
...
ASSIGN 25 TO
E,
AS, HITS
INFMT READ (2,INFMT) PNAME FORMAT
READ
Number
is
an
integer expression whose value
number
...
(2,
*) PNAM E
Specifier.
of
the record to be read.
The
is
connected for direct access.
must
not
format
AS, HITS
record
number
include a record
number
specifier must be present,
is
positive.
specifier
is
included in 'ctl-
It
has the
The
value
specifier.
but
can-
format
of
this ex-
Examples:
READ READ READ
6.3.1.1.4 essentially interpreted as of
data-transfer
negative value
6.3.1.1.5 OPEN
6.3.1.1.6
END =
where
(2,
REC =
(2,
REC =
(2,
REC = K +
Input/Output
at
Error
20) K)
1)
Status
it
was for the
110
statements, however, the variable
end-oF-file.
Specifier.
The
error
statement (section 6.2.1.3).
End-Of-File Specifier.
stl
'stl'
is
the label
of
an
executable statement in the same
Specifier.
The
OPEN
specifier has the same interpretation as for the
The
format
statement containing this specifier.
When
the end-of-file
statement
terminates,
is
detected during a read
'stname'
is
assigned a negative value (6.3.1.1.4),
tion continues with the statement specified by
110
status specifier,
10STAT,
statement (section 6.2.1.2). In the case
'stname'
of
the end-of-file specifier
operation,
is
program
execution
also assigned a
is
unit as the
of
the
READ
and
execu-
END.
is
6-12
If
END
is
Example:
READ
specified, the file must be connected for sequential access.
(2,25,IOSTAT=STFLG,ERR=
1200,END=860)
A,S,C
FORTRAN-SO
Input/Output
6.3.1.2
The read. name. ordering sequence. The the input list.
Input
List
list 'in-list' in the
An
item in
If
an
an
array
input
name
READ
statement identifies the items whose values are
list must be a variable name,
is
listed, the entire
name
of
an
assumed-size
6.3.1.3 Implied-DO List
An
implied-DO list embedded in the be used for input list read without specifying each individual implied-DO list
(in-list, var =
where
'var,
el, (section 4.2.2) may also contain additional
For
READ
Example:
statements, the
CREAD
20
array
elements.
is
el,
e2, e3)
e2, and e3' have the same interpretation as for the
and
'in-list'
ONLY
DIMENSION TABLE(60) READ FORMAT
is
a list
implied-DO lists.
DO
THE ODD ELEMENTS IN ARRAY 'TABLE'
(2,
20) ...
READ
For
of
input
variable
(TABLE(N), N =
array
name,
or
array
element
array
is
read in
dummy
statement allows a range
example,
array
items as described above. The list 'in-list'
'var'
half
element to be read. The
must not
appear
1,59,2)
normal
array
must
the items in
as
an
array
element
not
appear
of
subscripts
an
array
format
DO
statement
item in 'in-list.'
to
be
in
to
can be
of
the
6.3.2 WRITE
The
WRITE
statement
where
The control and 'out-list' ment, including the
Like input list items, ray element name. An pression involving
Examples:
is
WRITE
ctl-list
out-list
following subsections) except
is
120 FORMAT
120 FORMAT
C WRITE DOUBLE COLUMN PRINTOUT
C EACH ARRAY
120 FORMAT
Statement
statement
(ctl-list)
is
information
defined in the same
WRITE (6,120) PNAME, AVG
WRITE (6,120,IOSTAT= ERRFLG, ERR=2000)
&PNAME +
DIMENSION PNAME(25), AVG(25)
WRITE (6,120)(PNAME(K), AVG(K),
outputs
[out-list]
a list
of
is
a list
of
implied-DO
an
output
output
operators
data
control the
list
...
...
(1X,
information
data
to be written
is
the
same as for the that
manner
option
list item
list item
or
enclosed in parentheses.
I,
AVG + I
A,
5X, F4.3)
to
a specified unit.
specifiers
no
END
specifer
as the 'in-list'
(sections 6.3.1.2
may
be a variable name,
may
also be
The
format
READ
OF
statement (section 6.3.1.1
is
allowed. The
portion
and
an
expression, including
FIRST ITEMS
K=1,
of
6.3.1.3).
10)
of
the
array
the
output
READ
name,
OF
WRITE
list
state-
or
ar-
an
ex-
6-13
Input/Output
6.3.3 PRINT Statement
The
PRINT
format
PRI
where
NT f
statement
[,out-list]
outputs
formatted
data
to
the default write unit.
It
has the
FORTRAN-SO
f
out-list
that
Note printer
The
6.3.1.1.2). The list 'out-list'
6.3.2).
Examples:
or
format
120 FORMAT
120 FORMAT
is a format
is
a list
the keyword other
print device.
specifier
PRINT 120, PNAME, AVG
ASSIG N 120 TO OUTFMT
PRINT OUTFMT,
identifier
of
the
data
to be written
'PRINT'
'f'
has the same meaning as for the
does not necessarily imply the default unit
is
defined for
...
...
PRINT
PNAME, AVG
exactly as it
READ
is
statement (section
for
WRITE
6.4 Formatted And Unformatted Data Transfer
In the description formatted specifier are MATTED' perty
or
is
confirmed by the presence
of
the
OPEN
unformatted
'UNFORMATTED'
if the access method
I/O
statement
(section 6.2.1.7). The defaults for the formatting
if
the file
is
sequential. The formatted
or
is
absence
we
saw
that
a file can be connected for
connected for direct access
or
unformatted
of
the
format
specifier
is
(section
and
a line
'FOR-
pro-
6-14
[FMT
=]
f
in READ, statement
WRITE,
is
normally used with a
or
PRINT
statements. in the case
FORMAT
6.4.1 Unformatted Data Transfer
The unit specified in a an
external unit.
the connected file and items in the
The
number record. The type responding
On
output,
do
not
of
input
if the file
fill the record, the remainder
data-transfer
Data
is
transferred without editing between the current record
items in an input list must
of
each value in the record must agree with the type
list item. The item
is
connected for direct access
statement involving
110
list. Exactly one record
and
its value must also agree in length.
of
the record
of
statement.
unformatted
not
exceed the number
and
the values in the
is
undefined.
formatted
is
read
of
110,
the
data
must be
or
written.
values in the
of
the cor-
output
I/O
of
list
FORTRAN-80
Input/Output
6.4.2 Formatted Data Transfer
During the specifications can be given:
As values
As Hollerith values assigned I f the
array referenced tions. may the or
6.4.2.1
If
the record ing
When
formatted
110
list.
In
FORMAT
expressions;
format
name,
must
The
follow the right parenthesis
format
logical
specification itself.
array.
data
transfer,
The
editing
statements;
of
specifier (section 6.3.1.1.2) in a
character
contain
format
is
character
variable
a valid
specification
Printing Formatted Records
a
formatted
characters
this convention
is
not
record
printed.
of
the record
is
printed
It
is
specified,
directed by some kind
The
is
used instead to indicate vertical spacing.
are
data
is
transferred
arrays,
to
format is that
on
then printed beginning
character
integer,
name,
described below (section 6.4.3).
same applies
some external listing device, the first
the
real,
or
other
specification in its leftmost
ends the
first
character
with editing between the file
of
variables,
or
logical
formatted
character
format
specification with no effect
to
Hollerith
is
format
at
interpreted
specification.
arrays.
110
statement
expression, the value
data
the left margin.
Format
or
other
in an integer, real,
as follows:
character
is a character
character
Character
character
The
remain-
and
posi-
data
on
of
Character
Blank
o
I
+
This-interpretation is requested by (section 6.2.1.10).
preted
as vertical spacing
6.4.2.2
The classified as either repeatable
Both the
right.
is control repeated, say five times, it
If
the left parenthesis tion ing the first pass time
Format Control
edit descriptors
format
One
item in the
no
corresponding
communicates
a
format
contains
specification list ends
format
If
'car'
is specified as
information
that
make
up
or
nonrepeatable.
specification list
110
list
corresponds
110
list item for
directly with the
corresponds
matching
nested parentheses). Repeat specifications have the same effect as
through
reversion occurs.
the
the
format
Vertical Spacing
One
line
Two
lines
Ski p
to
next page
No
advance
the
CARRIAGE
'FORTRAN"
and
is
not
the
format
and
its
corresponding
to
nonrepeatable
110
record.
to
five consecutive
before
rightmost
the
I/O
right parenthesis
specification list. A new
specifier
printed.
specification list (section 6.4.3)
each
repeatable
list, it reverts to its beginning
of
the
OPEN
the
first
character
110
list
are
edit descriptor.
edit descriptors,
If
a repeatable edit descriptor
I/O
list items.
if
the
format
record
statement
scanned
and
specifica-
is
begun each
is
inter-
left
There
format
(or
dur-
are
to
is
to
6-15
Input/Output
6.4.3 FORMAT Statement
The
form
of
the
where
FORMAT
stl
FORMAT ([flist])
statement
FORTRAN-SO
is
stl
JUst
Each
item in
descriptor,
nonzero,
with a 'flist'
can
F5.3 5F5.3
X
3(2X,I5)
Note
that used only must
have
is a 1-5
digit
is a format
'flist'
must
or a parenthesized
unsigned integer
also be prefixed by a
Repeatable Repeatable Nonrepeatable Entire
the
FORMAT
if
the
at
least
110
one
statement
list
is
repeatable
6.4.3. t Edit Descriptors
6.4.3.1.1
of
a letter indicating the type
the
data
lw
Fw.d
Ew.d
Ew.dEe
Lw
A
Aw
Bw
Zw
Repeatable
field
and
Edit
how
it
is
Integer Real Real Real
Logical Variable-length Fixed-length
Binary
Hexadecimal
statement
label
specification list whose items
be a
repeatable
'flist.'
constant
repeat
An
specification.
edit
edit
descriptor
called a
descriptor, a nonrepeatable
'repeat
descriptor descriptor
prefixed with
descriptor
'flist'
prefixed with
with
also
empty.
edit
Descriptors.
of
data
to
be divided.
no
Conversely,
descriptor.
Repeatable
involved
The
repeat
'flist'
specified,
if
and a number
repeatable
descriptor number number number
descriptor descriptor descriptor
descriptor
alphanumeric
alphanumeric
descriptor
descriptor
descriptor
are
separated
by
commas
edit
is
repeated
specification.'
repeat
specification
'FORMAT ( ),'
the
110
list
by prefixing it
The
specification'
'3'
is
not
empty,
entire
5'
can be
'flist'
edit descriptors generally consist
indicating
the
size
of
edit descriptors are:
descriptor
6-16
where
I, F,
LandA
BandZ
w
d
e
The
I,
F,
and
E serve the
notation.
E,
and
E edit descriptors
same
function
indicate
indicate
the
the
is a nonzero, of
the
entire edited field
is
an
unsigned integer
digits
that
should
is a nonzero,
of
the
exponent
are
on
input;
type
of
data
being edited
number
base
of
unsigned integer
constant
follow
the
unsigned integer
field.
used
to
specify
E allows
data
constant
decimal
constant
110
output
being
edited
representing the width
representing
the
point.
representing
of
of
integer
real
and
numbers
number
the
real
of
width
data.
in scientific
F
FORTRAN-80
Input/Output
Certain
A decimal
The B and Z cdit respectively.
'-1' is
general
On
input, to the setting BLANK
an
For
for the processor
On
output, left.
On
output,
exponent
remarks
leading
sp~cifier
point
E descriptor.
values
has
The
'Ff').
Integer Editing
An
I/O
list item
input
list item ed with integer one
digit.
Examples:
is
data.
20 FORMAT
apply
to
all
blanks
of
the
in the
in
to
are
if
the
more descriptors
internal
matched
defined with integer
The
are
not
non
repeatable
OPEN
input
data
The
input
approximate
right-justified.
number
than
representation
integer
of
'e'
digits, the entire field
specify
with
an
constant
overrides the decimal
'Iw'
PRINT 20, INTNUM
(15)
three
of
these numeric editing descriptors.
significant.
descriptors BN
statement
field
may
the
data's
If
necessary,
characters
data
110
of
the
edit descriptor
data;
the
read
Other
blanks
and
(section 6.2.1.9).
also have
value.
the
exceeds the field width
is
filled with asterisks.
in
binary
data
is
output
must
output
list item
or
written always consists
BZ
point
more
field
and
hexadecimal
(e.g.,
be
must
are
and
location specified by
digits
is
blank-filled
of
treated
the
type integer.
already be defin-
according
the value
than
are
'w,'
notation,
'Z'
format
of
of
the
needed
on
the
or
The
at least
an
of
READ (2,20) INTNM1, INTNM2,
20 FORMAT (215,14)
<F'
Descriptor Editing
An
I/O
list item
put
to
this descriptor
are
interpreted as the fractional
On
input, nent consisting ly signed integer
Output modified edit descriptor, section 6.4.3.1.2). Leading zeros field would be
Examples:
edited by the
matched
a string
of
a signed integer
constant.
by
an
established scale
blank
with
an
contains
of
digits by the basic
'F'
otherwise.
no
part
descriptor
factor
'Fw.d'
decimal
descriptor
point,
of
the
input
'F'
descriptor
constant
or
is
rounded
(see the description
the letter
READ (2,20) REALN M
20
FORMAT (F5.3) DIMENSION TABLE
PRINT
20,
TABLE
(10)
20 FORMAT 5(F5.3, 2X, F5.3)
CTHE
TABLE
WILL
BE PRINTED OUT IN TWO
INTNM3
must
the
rightmost
value.
can
'E'
to
'd'
fractional digits,
are
not
generated unless the
have a real value.
'd'
digits
of
be followed by
followed by
of
the
an
and
'P'
nonrepeatable
COLUMNS
If
the in-
the string
an
expo-
optional-
may
be
output
6-17
Input/Output
'E'
Descriptor Editing
An
I/O
list item matched with an
variable. The exponent On
output,
the
format
zero is:
'Ew.d'
'e'
has no effect on input
of
the
output
field for a scale factor (section 6.4.3.1.2)
or
'Ew.dEe'
data.
FORTRAN-SO
descriptor must be a real
of
[±]
[0].x1
where
± signifies a plus
exp
Edit Descriptor Absolute value of
Ew.d
Ew.dEe
The sign in the exponent plus. The
'Ew.d'
Decimal normalization
-d<k:$O,
the number
xdex
x2···
P
are the after
rounding
is
a decimal exponent having one
('y'
is
lexpl:$
99<
lexpl:$(10**e)-1
is
always present.
descriptor should
is
controlled by the scale factor
output
will have exactly
or
'd'
most significant digits
a digit):
99
lexpl:$
999
If
not
be used if exp exceeds 999.
significant digits following the decimal point. exactly cant digits
k significant digits
to
the right
of
to
the left
of
the decimal point
the decimal point.
Other
minus
'exp'
the exponent
Iklleading
If
0<
k<
d + 2, the
values
of
of
the
data's
of
the following forms
Form of
± ±
E ±
is
zero, it
'k'
'exp'
OY1
Y2
Y1
Y2 Y3
Y1
Y2··
is
prefixed by a
(section 6.4.3.1.2).
zeros and
number
and
'd
- k +
k are not legal.
value
·Ye
'd
- Ikl'
will have
1,
signifi-
If
Examples:
30
110
READ (2,30) FORMAT
WRITE (6,110) RLOUT FORMAT
RLNUMB
(E4.2)
(E6.5E6)
Logical Editing
An
I/O
item matched with
The input field includes
an
'Lw'
descriptor must be
an
optional period followed by a
of
type logical.
'T'
(for
TRUE) FALSE). These characters may be followed by additional characters. the logical
The value
constants'
output
of
the internal
.TRUE.'
field consists
data.
and'
of
the letters
.FALSE.'
'T'
or
are acceptable inputs.
'F,'
based on the
TRUE
Examples:
50
80
DIMENSION
READ
WRITE (6,80) TRUTH(1) FORMAT
(3,50) TRUTH(1), TRUTH(4)
FORMAT
TRUTH(4)
(2L6)
(L
1)
or
For
or
'F'
(for
example,
FALSE
6-18
FORTRAN-80
A /phanumeric Editing
An
110
item
matched defined with Hollerith 'w'
characters. Otherwise, the
110
list item.
On
input,
if
the
character
cated
on the string filling
is
the right.
is
blank-filled
done
on
If
the left.
with
an
'A'
or
'Aw'
descriptor
data.
If
the field width
number
string
is
the specified width exceeds the length
on
the right.
of
longer
The
characters
than
same
must
'w'
is
specified, the field consists
in
the
the specified width, the string
is
true
on
output,
have type
field
is
of
the
except
character
the length
character
that
or
of
the
is
trun-
string,
blank
Input/Output
be of
NumlJt!f Bast!
A:nil1~lltit7ttiirp~t¢~~9~H~
()rht:x~d~cirnaldjg~ts;re~.l)ectiv7~Y'
either a sjgu
I··f··.O.n~."
•.
()(
number~~se tobe~ur7
exampletif~Fisa,~ingle-byteinn~ger
Editing
.~.
'Bw'
or':fw~?~~pr~~~Rt~tis~cpn~~sts
..
·10
,.p~rticula~,$tlpljaninput
ora
letter indicatingthebas¢.
••.•
tne~~
.•..•
4~s;ct.iptors
in~ic~ted.Leadiflk1Ter()$ar7
th~rear~asrn~ny.
•..
·i$
•.•••
sP~.~i.fi.eq.·
digit~·pres~:n!~~~t7n.~~pedto
.·fo~
....
9.HtJrM.t#
sup~Jie~~~9:utptltaI1Qacceptedon
••. • ••
;.~.'.·'·~nat~Pt¢rs.·
represent'
wn¢se
valuei~'4,'
itisOlltput
onlyofbi~ary
·fi~ld
cannot contain
•••
are
out
the
as
'bbb04
a 'Z5'editdesctiptor.
The
flum ber· hase
6.4.3.1.2
'hlh2···hn'
nHhl
nX
/
Nonrepeatable Edit Descriptors.
h2
...
kP
edit
descriptors
h
n
can
be
specif\edfof tlataof any type.
The
nonrepeatable
Literal string descriptor
Hollerith string descriptor
Record position
Record
Scale
termination
factor
control
descriptor
descriptor
descriptor
edit descriptors are:
pu
•.
io
·t~e
input,
data . For
'under
BN
BZ
$
where
apostrophe
of
kind
Apostrophe
The enclosed in the
editing
h
n
k
apostrophe
character
Blank descriptor
Blank descriptor
Alternate
C),
H,
X,
slash
(I),
P,
and
is
any
character
is a nonzero, is
an
optionally-signed integer
Editing
edit descriptor
apostrophes
field, show it as two consecutive
to
representable
unsigned, integer
can
be used only for
be written
out
record
BN, BZ,
on
constant
constant
literally.
apostrophes.
termination
and
the
the processor
output.
To
indicate
desc:riptor
dollar
sign ($) indicate the
representing a scale factor
It
causes the
an
apostrophe
characters
within
6-19
Input/Output
The
width
of
the field
is
the length
of
the character string.
Example:
WRITE (7,100) ITSTNO
100
'H'
Descriptor Editing
The
Hollerith field descriptor
apostrophe
FORMAT
editing. Like
('THIS IS THE TEST NUMBER', 2X,
is
an
alternate
apostrophe
editing, it
way
is descriptor causes the In' characters following the embedded blanks).
on is
an
likely
Because the Hollerith field descriptor relies duce the correct
output,
apostrophe
editing
method. Example:
WRITE (7,100) ITSTNO
100
FORMAT
(1
H1, 19HTHIS IS TEST NUMBER, 2X,
C FIRST H DESCRIPTOR CAUSES SKIP TO NEW PAGE
12)
to
perform
used only for
'H'
to
be written
the same
output.
accurate character
to
be less
error
operation
out
(including
count
prone
12)
The
to pro-
than
FORTRAN-SO
as
'nH'
this
'X'
Descriptor Editing
The'
nX'
descriptor indicates
is
the
character
is
to insert In' blanks
"n' positions from the
Example:
WRITE (7,100) ITSTNO
100
FORMAT
C FIRST X DESCRIPTOR CAUSES SINGLE SPACING BY
C INSERTING A CTHE
RECORD
Slash Editing
The
slash
(I)
edit descriptor acts as
mainder
of
On edit descriptor to provide
The before
of
the
current
a record, the entire record
output,·
comma
the current record
may
blank
lines
that
normally separates
or
after
a slash.
also be used
that
into
the
the next
output
current
record.
character
record position. On
(1X, 'THIS IS TEST NUMBER',
record
on
printed
BLANK
AS THE FIRST CHARACTER
an
end-of-record indicator.
is
skipped
is
skipped.
is
terminated
to
write
or,
if
the file
and
an
empty record, which
output.
format
specification list items
transferred
2X,12)
is
positioned
a new record
to
or
from a record
output,
the effect
OF
On
input, the re-
at
the beginning
is
begun.
is
a convenient way
is
The
not
required
slash
6-20
Example:
WRITE (7,100)
100
CTHIS
FORMAT
SLASH CAUSES
WRITE (7,150)
150 FORMAT
(1
H1, ' PLAYER AVERAGE'!)
BLANK
LINE
FOLLOWING
PNAME, AVG
(1X,
A12,
4X,
F4.3)
HEADING
FORTRAN-80
Input/Output
Scale Factor (P)
A scale factor factor. needed between the
A scale factor been changed by the'
On input, the scale factor has no effect field. number true part reduced by
As multiplier printed in scientific Changing the scale factor to one changes the multiplier range the scale factor generally not desirable for scale factor, the scale factor should probably be respecified as occurrence
The following table and the use the field descriptor used
It
1 PE8.6E2
kP'
descriptor
Otherwise, the effect
equals the internally represented
of
output
of
the quantity
we
saw in the description
Editing
is
established by
is
used with the
'P'
descriptor and
of
zero
is
the'
kP'
is
issued again
with
'F'
to
'k.'
is
useful for very large
of
'F'
editing.
of
number
of
the scale factor would be most applicable. The column headings show
the'
kP'
edit descriptor,
'F'
and
'E'
descriptors
an
immediately following
assumed at the beginning
edit descriptor, the new scale factor remains in effect until
or
until the end
if
there
is
of
the scale factor
number
editing. On
be produced
'F'
to
produce each representation.
output
of
'E'
notation
edited numbers. Following specification
representations illustrates instances where
with
is
multiplied by
descriptor editing, the
with a scale factor
or
very small
where'
to
edit real numbers. No
of
an
110
of
the
110
statement.
an exponent in the
is
that
the externally-represented
multiplied by
'E'
editing, the basic real
'10**k'
to
'E'
edited numbers,
k'
represents the scale
comma
'F'
or
'E.'
statement. Once it has
'F'
or
'E'
'10**k.'
and
output
of
zero
1.0 - 10.0. Changing
'OP' before the next
The same
constant
the exponent
range
is
0.1 to 1.0.
of
a nonzero
'E'
edited
is
is
of
but
is
editing
is
a
Real
Number
4.32
7255000.0
0.0065
Clearly, clearly,
'7255000'
'BN'
These two edit descriptors are used for They can be used
If
zero. Until the
specifier in the blanks.
Example:
Dollyt
'F'
'F'
or
and
'BZ'
'BN'
is
specified, blanks are ignored except
If
'BZ'
'BZ'
50
Sigfjl$ijitrrrg·
descriptor editing
descriptor editing
'0.0065.'
Editing
is
specified, blanks are regarded as zeros.
or
FS.2
4.32
******
0.01
is
preferable for simple numbers like
is
inadequate for very large
to
specify the interpretation
'BN'
descriptor
OPEN
statement (section 6.2.1.9) determines the interpretation
READ (2,50) INTNUM, FPNUM FORMAT
(BN,
is
specified (or,
15,
5X, F7.4)
E10.5
0.43200E +
O.
72550E + 07
0.65000E-02
input
only
of
blanks,
that
if
1 PE10.4
01
and
a field
neither
4.3200E+00
7.2550E+06
6.5000E-03
'4.32.'
or
very small numbers like
affect only numeric editing.
other
than
leading blanks.
of
all blanks
is
specified), the BLANK
is
Just
as
treated as
of
Th¢
..•
~oll.~f
•••.
$~~·~
••••••
~.~.).···.·e~l~
c()nsoletYFl1l~l\l~LJtlea~~s.~·~l\tYF~inalfnlrs~r~tr~~~~§~~~~n~m,tn~~i~tel~fCl)~19\Ving
the
I/Odataju~t
.••.••
(J~~pti~t?f
pr()ces$ed;·rathe:rthant>egil1nill,gan1tw~ine~Ifthe·f{)r.i)lat·c()l1tTlpl
.. · •••
~.s·
....
·.~.~~~.
·.p~i~~t~l,~
•••.
f~r~~~~r~~ti,~~
.•
ilq
...
t~r?Mgp.·L.a
6-21
Input/Output
FORTRAN-SO
scanner
trol
donar
encounters a dollarsign
terminates
sign .edit
without
descriptor
at
positioning
has
no
effect
the
the
end
on
Example:
PAINT 25, PNAME
25 FORMAT (A20, $)
6.4.4 List·Directed Formatting
List-directed
specifier
free terminal. No
the
A list-formatted file consists
either a
of a data-transfer
form
input
programmer.
constant,
I
formatting
and
output,
FORMAT
statement
a null value, or a
is
indicated by specifying
110
statement's
which
is
especially helpful
is
required as all necessary
of
a string
constant
specification in the form:
r*c r*
The
first form
cond
is characters separator
is
equivalent
equivalent
between value
in a record.
to
'r'
successive
to
'r'
null values. A null value
The
separators
null value
or
is
not
of a format
file
to
the beginning
direct~accessfil¢s.
control
specification list,
of
the
next
an
asterisk (*) in the
list (section 6.3.1.1.2).
if
the
110
device
formatting
of
values
and
value
separators.
or null value prefixed by a repeat
appearances
no
characters
produced
of
the
constant
can
also be specified as
preceding the first value
by list-directed
output.
format record.
It
is
a console
is
done
Each
'c;'
con;.
The
format
allows
for
value
the se-
no
is
Value
separators following the last put.
When
put
statement
tional items, they
Any sequence character
constant.
6.4.4.1 List-Directed
Input
forms acceptable list-directed may not be
An input list item unless a decimal
can
be a
constant
encountered
after
assignment
are
effectively assigned null values.
of
blanks
An
formatting
embedded
of
type real
point
comma,
in a record.
during list-directed
is
treated as a single
end-of-record
Input
to
format
with a few exceptions. Blanks
in
constants
appears
must not include either slashes An
input
list item
of
characters enclosed in
the end
of
one mally has the effect the
character
and
are
truncated
A null value has
previous value
was
encountered.
of
record
of a blank
constant
on
no
effect
or
remains
type
character apostrophes.
to
the beginning
in this case.
the right
on a corresponding
undefined,
slash,
or
one
or
more
blanks
The
slash
separator
input,
it terminates execution
of
the previous value.
blank
If
except when
has the same effect as a
specifications for a given type
are
(except
is
assumed
within the field. An
or
commas
in list-directed
Character
if
their length exceeds the width
character
to
have
in its input
consists, in its
Character
of
the next.
formatting, a blank
constants
input
depending
constants).
no
fractional
input
form.
input constants
Though
are
list item.
on
its
is
not
the
110
blank.
never
list item
form,
can be
the
transferred
of
status
between
constants
produced
of
list
contains
it
appears
are
acceptable for
treated
part
as zeros,
in
its
input
of
type logical
of a nonempty
continued
end
of
a record nor-
is
not inserted
left-justified
the
input
list item.
The
item retains its
before
the null value
or
on
out-
the in-
addi-
within a
and
form
string
from
into
6-22
FORTRAN-80
Input/Output
6.4.4.2
The responding as the end and
Integer reasonable value editing, depending of constants
Output
List-Directed Output
form
of
the values
output
of
a record does not fall within a
blanks are not embedded within constants.
'1
P'
output
is
constants
used. Logical
are
output
records are single spaced.
produced
by list-directed
list items. The processor separates records as necessary, so long
are
produced
of
'w.'
Real constants are
on
the
magnitude
constants
simply as
are
character
output
constant
with the effect
produced
of
the value.
'T'
for
TRUE
strings without
agrees in type with their cor-
(except a
of
with the effect
Where
and
'F'
surrounding
character
'Iw'
formatting,
of
reasonable, a scale factor
for
FALSE.
apostrophes.
constant)
for
some
'F'
or
'E'
Character
6-23
CHAPTER 7
PROGRAMMING GUIDELINES
This chapter techniques. mer.
For
ming, a
The first section ming in any language. The second section lists suggestions for programming in FORTRAN
7.1
Program Development
The
recommended method. initially,
final code.
going
to
The
first step in this
7.1.1
Before considering any actual programming, pletely the problems involved.
plugs
on the new plugs by the possibility put
a trace
easier,
is
by
no
means intended as an exhaustive discussion
It
is
intended simply as a guideline, primarily for the novice program-
those who wish
number
the next level
of
of
specifically.
Essentially, this means defining a and
then working down
At
each level, debugging
to
go
more
deeply into the science
references are listed in the bibliography
this chapter deals with general guidelines applicable to program-
approach
of
approach
to
program
through
refinement.
is a thorough
is
Problem Definition
For
example, a person
his car. This
of
of
and
limit the chance
is
fine,
but
hand
first
and
stripping threads.
'anti-seize'
compound of
breaking a plug.
he will be better
using a plug wrench only for final tightening reduces
And
of
FORTRAN
at
the end
development
program
a series
performed
definition
one
prepared
he will be better advised still
on
the threads first
is
the so-called
in the broadest possible terms
of
increasingly detailed steps
to
whatever extent possible before
of
the programming task.
must
understand
may
have
if
he knows
to
of
programming
program-
of
the chapter.
'top-down'
clearly
to
change the spark
make
and
that
inserting
if
he
is
later removal
com-
told
to
to
Similarly, knowing
it to print out only employee names (federal, social security, state, city,
for the
show the hours worked, splitting
tion pay? Should it show accrued sick used to display all this
While the he at least needs what form,
company's
progammer
and
that a program
stock plan, pension plan, credit union,
information?
need
not
to
know in detail
exactly what
must print
ad
infinitum)? Should it show
out
overtime, shift differential, holiday,
or
state the specific algorithms
what
output
the
out
payroll statistics
and
net pay? Is it
vacation leave?
input
the
program
is expected to produce.
to
And
program
7.1.2 Program Documentation
Every
program
At
the earliest stage preliminary functional specification should be reviewed by will gaps be filled in, of
programming, for coworkers to familiarize themselves with each
and
for developing a feeling
should have
of
program
one's
but
this review creates
good
documentionfrom
development,
of
programming
of
teamwork within a
the beginning!
documentation
the
program.
peers for constructive criticism. Not only
an
environment for exchanging theories
programming
Ideally, this specification
is
insufficient.
show taxes withheld
other
deductions
or
whatever? Should it
or
what
format
to
be used
will be receiving
would normally be a
group.
at
other's
should be
this stage,
and
projects,
Is
vaca-
in
7-1
Programming Guidelines
FORTRAN-80
As the development become correspondingly detailed.
program
final
ingful mnemonic names for symbols, lines to improve cessor
memory
These comments could include
of a program
becomes
The
ultimate
more
detailed, the
documentation
code, which should include numerous useful
and
make
good use
program
size, each
readability.
program
more
If
the
program
is
not
unit could be prefaced with a
than
a description
of
documentation
comments, of
severely limited by pro-
the tion; for example, it might say who coded this unit originally latest changes.
7.1.3 Refining The Problem Definition
Once the problem level in the series being increasingly detailed.
For
the sake
defined as follows:
The
input employee. This record contains all rates, deductions, etc.
The
program field), the hours worked (HRS), the gross pay PAY).
After the last record has been printed, the
• showing the total (gross) pay disbursed.
is
defined in detail, a series
of
example, let's assume the payroll statistics
will be a
formatted
file on diskette containing a record for each
of
refinements
information
is
to
print
out
(on the line printer) only the employee's
(GRPA
program
number
of
employees, the total hours worked,
printout
related to hours worked, pay
Y),
is
should
is,
of
course, the
have mean-
blanks in statement
comment
program
and
who
is
begun, with each
unit's
made
block.
func-
task has been
name
(EMP
and
net pay (NET-
to
print a summary
and
the
total
the
The
first two levels
Print
out payroll statistics
Initialize variables.
Open
files.
Read
input
record.
If
(last record) then
Print
totals
Close files
Else
Print
individual statistics Update Go
Note
in level two words here beginning
totals
to
'read
and
there
to
take shape,
FORTRAN.code.
of
program
development might look like:
Level One
on
line printer.
Level
Two
record'
that
statement
we are still using essentially English sentences with a few
that
begin
to
but
at
look like
this
point
FORTRAN.
we're
more
The
program
concerned with logic
structure
than
is
7-2
FORTRAN-SO
Programming Guidelines
The next pass statements for English sentences.
C INITIALIZE VARIABLES NEEDED FOR TOTALS
C OPEN INPUT/OUTPUT FILES,
C PRINT TOTALS IF NO MORE RECORDS
C OTHERWISE PRINT
is a more
DATA TOTEMP, TOTHRS, TOTPAY / 3*0.0/
OPEN
OPEN 10 20
40
60 FORMAT (flist)
READ (unit, FORMAT
I
F (no
WRITE (unit,
FORMAT (flist) CLOSE CLOSE
ELSE WRITE
TOTEMP TOTH TOTPAY = TOTPAY
formal description
(input (output
more
file)
20)
(flist)
records) TH
40)
(input (output
EMPLOYEE DATA
(unit, 60) EMP, HRS, GRPAY, NETPAY
= TOTEMP + 1
RS
= TOTH
of
Level Three
READ EMPLOYEE RECORD
file)
EMP, HRS, GRPAY, NETPAY
EN
TOTEM
file)
file)
RS
+ H
+GRPAY
P,
TOTH
RS
level two, introducing
RS,
TOTPA Y
AND
UPDATE TOTALS
FORTRAN
C READ NEXT EMPLOYEE RECORD
number
A
complete the
accuracy
only
at
GOTO ENDIF END
of
details remain to be specified,
and
can be debugged to the extent
of
the
the
end
concern ourselves with such details as
10
program's
logic, then
7.1.4 Final Coding
At
the level debugging the program
Take programming can execution paths. These
Avoid tricky programming.
Concentrate produced as a last step.
Concentrate Syntax details initial
Again, use
blanks
of
detailed code, a
program,
later.
advantage
be interspersed
effort
to
improve
of
language.
initially
especially
can
in this
area
comment
program
number
or
to
simplify the task
the built-in debugging aids available in the particular
For
example,
throughout
can
be removed in the final version
Code
on
making the
on
getting the statement syntax correct the first time.
be particularly annoying
can save a lot
lines frequently. Use meaningful labels for variables. Use
listing readability.
but
each
that
it
is
110
interfaces
of
steps can be
of
another
PAUSE,
initial
conservatively!
FORTRAN
program
of
work. Beautiful
to
grief in the long
of
these levels
complete. Thus
and
basic calculations,
format
STOP,
FORTRAN
specification.
taken
to
programmer
and
code to trace
of
run.
simplify writing
WRITE
the
programmers,
is
in some sense
we
can confirm
updating the
statements
program
program.
printouts
and
and
can be
but
7-3
Programming Guidelines
This
is
checklist. Rereading such a list frequently, like rereading
good
way to refresh
7.2 FORTRAN Coding
just a 'starter'
list. Certainly, any experienced
or
reconfirm
programming
knowledge.
programmer
programming
could
manuals,
add
to
FORTRAN-SO
this
is
a
Section 7.1 lists some general TRAN
specifically,
other
programming
points should be kept in mind.
7.2.1 Functions And Subroutines
The
first point has already been
functions all, they reduce the chance And, grammed
understand.
and
of
error.
most
importantly,
and
subroutines in a
amount
They also save processor
debugged
they break a
and
made
in
program
of
coding
that
also clarify its logical structure, making it easier to
wherever it makes sense
to
program
7.2.2 GO TO Statement
The
GO
TO
statement should be used only when necessary. around ning. No painter would worry by simply shouting whether gram
at
will within a
an
alternative solution
has been overlooked.
program
'go
to
can be a strong
about
painting himself
exit.' When the
that
would improve the logical structure
considerations. When coding in
Chapter
be done, saving time
memory
GO
5,
but
is
worth repeating. Use
to
do
and
by allowing
into
units
that
temptation
into
a corner
TO
seems necessary, consider first
shorter
can
be separately pro-
The
ability to
to
neglect logical plan-
if
he could escape
so. First
reducing the
FOR-
of
programs.
jump
of
the pro-
7-4
7.2.3 Crossing Unit Lines
The
ability
to
divide a
It
also has some potential pitfalls. procedures, gram aware memory!
and
unit!
Take
of
the interaction
program
variables whose values have been
advantage
into
subprograms
Be
careful when using global variables, external
of
the capability provided by
among
all the
program
is a major
computed
common
units
benefit
outside the
memory,
that
reference
of
7.2.4 Computing Variables And Constants
Complex calculations can frequently be simplified by breaking them steps
and
computing
variables are used several times
can
tion time
ly
more
variables
be reduced by using intermediate variables
readable. Like most
can
be abused
intermediate variables. This
after
their value has been
programming
and
requires good judgement.
tools, however, the use
is
particularly
computed.
and
the
Program
program
of
FORTRAN.
current
into
true
intermediate
but
common
several
if
such
execu-
is
general-
pro-
be
FORTRAN-SO Programming Guidelines
When calculating a value for use in a the loop iteration
is
entered. Otherwise, the
of
the loop. Consider the following
C EXAMPLE
OF
RECOMPUTED CONSTANT INTEGER*1 DO
25
R =
R
1,60
X = (2217)*(r* *2)
WRITE (4)
25
C SAME
25
In the first case, the value
CONTINUE
EXAMPLE WITH PRECOMPUTED
INTEGER*1 R PI
=
DO
X = WRITE CONTINUE
X,
2217
25 R = PI*(R**2)
'22/7'
1,60
(4)
X,
would have to be
R
R
7.2.5 Reminders
We've
already mentioned the use to improve debugging aids available in the and
WRITE
other
debugging tools DEBUG cludes
command
ICE-80
program
or
and
readability
PRINT
statements). In addition, the
that
in Intel's ISIS-II
ICE-85 for the 8080
might be available in his system environment, such as the
of
FORTRAN
DO
loop, be sure the value
program
comments,
and
or
could
compute
short
Examples:
CONSTANT
computed
good
mnemonic names,
understandability. We've also mentioned
language (such as the
programmer
Intel's in-circuit
and
8085 microprocessors.
emulator
is
computed
the
value again for each
60 times!
PAUSE,
should explore
family, which in-
and
before
blanks
STOP,
7.3 References
The
following list suggests material for further reading. Some the books by Ledgard Bear in mind and
FORTRAN
in the new version. Dahl,
Academic Press, New York, 1972. Dijkstra,
0.1.,
Edgar
that
Dijkstra,
the A CM, Vol. 15, No.
Henderson,
BIT
12, 1972. Hilburn,
Software,
Knuth,
P.,
1.L.,
and
Applications, Prentice-Hall, Inc., 1976.
Donald
Algorithms, Addison-Wesley, Reading, Mass., 1968.
Ledgard, Rochelle
Henry
Park,
N.l.,
and
McCracken
all
of
this material was written before
'limitations'
W.,
'GO
and
Snowdon,
and
lulich,
E.,
The
F.,
Programming Pro verbs
1975. .
discussed in these works may
E.W.
10,
and
TO
Statement Considered
Oct. 1972.
R.,
P.M.,
Art
of
Computer
or
the article by Ogdin,
Hoare,
'An
C.A.R.,
Experiment in Structured
Microcomputers/Microprocessors: Hardware,
Programming, Vol.
for
FORTRAN
of
the material, like
is
essentially tutorial.
FORTRAN
no
77
~as
longer be a problem
Structured Programming,
Harmful,'
Communications
Programming,'
1,
Fundamental
Programmers, Hayden,
specified
of
7-5
Programming Guidelines
FORTRAN-SO
McCracken, Daniel
A.,
A Simplified Guide to
Wiley & Sons, New York, 1974.
Mills,
Technical Report,
Harlan
B., Mathematical Foundations
FSC
72-6012, IBM Federal Systems Division, Gaithersburg,
1972.
Ogdin, Carol Wirth,
of
the
ACM,
A.,
Niklaus,
Vol. 14,
'Software
'Program
No.4,
Design
Development by Stepwise Refinement,' Communications
April 1971.
Course,'
EDN,
FORTRAN
for
June
Programming,
Structured Programming,
5, 1977.
John
Md.,
7-6
FORTRAN-80 STATEMENT SUMMARY
A.1
Statement Sequence
The
following
FORTRAN
1.
Comment
after
2.
The program.
SUBROUTINE,
Within a program
FORMAT
3.
4.
IMPLICIT
5. All specification statements must precede all precede
statements.
6.
The
last line
These rules
order
program.
lines can
an
END
statement.
PROGRAM
The
unit
statements
statements
statement
of a program
are
summarized
of
statements
appear
statement,
first
statement
or
BLOCK
that
permits the following statements:
can
appear
must
function statements, which
unit
in Figure 1-2.
and
lines
before
DATA
precede all
or
between statements,
if
used,
must
of a subprogram
statement.
before
the
other
must
be
an
must
END
END
APPENDIX A
be observed when coding a
but
cannot
be the first
statement.
specification statements.
DATA
must
statement.
statement
must
be a
FUNCTION,
statements, which
precede all executable
appear
of a main
must
A.2 Statement Summary
In the following Ellipses indicate the preceding item can be repeated indefinitely (within length limits).
Category: Executable
Text Reference: Section
ASSIGN
Category: Executable
Types:
Text Reference: Sections
Arithmetic,
Format
stl
Format
summary,
3.3.4
TO
name
Character,
3.3.1,3.3.2,3.3.3
any
format
ASSIGN
Assignment
Logical
item enclosed in
Statement
Assign statement label ' stl' integer variable
Statement
square
Function
'name.'
Function
brackets
is
optional.
statement
to
v = e
Assign value
type
is character.
integer, real,
of
'e'
to
'v,'
logical,
where
'v'
or
A-l
FORTRAN-80
Statement
Summary
FORTRAN-SO
Category: Executable
Text Reference: Section 6.2.3
Formats
BACKSPACE
BACKSPACE
unit (arg-list)
Notes: 'unit'
is
unit specifier
is
'arg-list'
following argument list:
[UNIT IOSTAT =
ERR
=
=]
stl
unit
stname
Category: Nonexecutable Text Reference: Sections
3.4.3,3.4.4
BACKSP
ACE
Statement
Position file connected before preceding record.
unit specifier
110
status specifier
error specifier
BLOCK DATA Statement
Function
to
'unit'
Format
BLOCK
DATA
[name] Identify start
subprogram; program
CALL
Statement Category: Executable
Text Reference: Section 5.2.7
}'ormat
CALL
sub [([a[,a]
...
])]
Call argument(s)
CHARACTER Category: Nonexecutable, specification, type Text Reference: Section 3.1.4
'name.'
subroutine
Statement
Function
of
BLOCK
DATA
optionally name sub-
Function
'sub'
with actual
'a.'
A-2
CHARACTER
Format
[*len['llname[,name]
Specify
...
character type variable
Function
name
and
length
or
array.
for
FORTRAN-SO
FORTRAN-80 Statement Summary
Category:
Text
Notes: 'close-list'
Category:
Text Reference: Section 1.1.1
Executable
Reference:' Section
Format
CLOSE
(close-list)
can
be following fields:
[UNIT
=]
IOSTAT =
ERR
=
stl
STATUS =
Nonexecutable
Format
6.2.2
unit
stname
stat
CLOSE
Comment
Statement
Function
file
Close described by 'close-list.'
unit
specifier
110
status
error
specifier
file disposition specifier
Line
(disconnect
specifier
Function
unit)
'c'
or
'*'
in
column
character
Category:
Text Reference: Section
COMMON
Category:
Text Reference: 4.2.3
in
columns
Nonexecutable,
Format
[/[cbJ!]
Executable
Format
1;
any
ASCII
2-72
COMMON
specification
3.4.2
nlist[[,]/[cbJ!nlist]
CONTINUE
Program
Statement
Name
common
Statement
documentation
Function
and
define
block(s)
Function
'cb.'
contents
of
CONTINUE
No
effect unless this statement depends
of a DO
on
DO
loop;
variable.
terminal
is
then
action
A-3
f'ORTRAN-80
Statement
Summary
FORTRAN-SO
DATA
Category: Nonexecutable
Text Reference: Section 3.3.5
Format
DATA
nlist/
clist/[[,)
nlist/
elist/) ...
DIMENSION
Category: Nonexecutable, specification
Text Reference: Section 3.2.1
Format
DIMENSION
a(d) [,a(d))
...
DO
Statement
Assign 'nlist.'
Statement
Name dimension(s)
Statement
Function
values in 'elist'
Function
array(s)
'a'
'd.'
to items
and
in
define
Category: Executable Text Reference: Section 4.2.2
Format
DO stl [,) var =
el,
e2 [,e3)
Notes:
stl label var el
of
last (executable) statement in
DO
variable
initial loop index value e2 loop termination value e3
loop
increment/
Category: Executable, block
Text Reference: Section 4.1.9
Format
decrement
ELSE
IF
Define set
up
loop counters.
amount
Statement
Function
beginning
DO
loop
Function
of
DO
loop
and
A-4
ELSE
Continue
execution; alternate execution ELSE
IF.
path
provides
from
IF
or
FORTRAN-80
ELSE
IF
Statement
FORTRAN-80 Statement Summary
Category: Executable, Block
Text Reference: 'Section 4.1.8
Format
ELSE
IF
(exp)
THEN
Category: Executable
Text Reference: 4.3.1
Format
END
IF
END
END
Continue 'exp'
Statement
Terminate from
subprogram;
gram
unit.
IF
Statement
is
TRUE
main
Function
execution
Function
program;
mark
if
end
of
expression
return
pro-
Category: Executable, block IF
Text Reference: Section
Format
ENDIF
Category: Executable
Text Reference: Section 6.2.5
Formats
ENDFILE ENDFILE
Notes:
'unit'
is
unit specifier
'arg-list'
is
following
4.1.10
unit (arg-list)
argument
Mark execution.
ENDFILE
list:
Function
end
of
IF
block;
Statement
Function
Write end-of-file connected
to
'unit.'
continue
record
on
file
[UNIT lOST ERR
=]
A T =
= stl
unit
stname
unit specifier
110
status
specifier
error
specifier
A-5
FORTRAN-80
Statement
Summary
FORTRAN-80
EQUIVALENCE
Category: Nonexecutable, specification
Text Reference: Section 3.4.1
Format
EQUIV
ALENCE
(nlist) [,(nlist)]
...
EXTERNAL
Category: Nonexecutable, specification
Text
Reference: Section 5.2.6
Format
EXTERNAL
proc
[,proc
] ...
Statement
Allow entities in same storage area.
Statement
Function
Allows name
procedure
to
be used as an
argument.
Function
'nlist'
of
external!
to
share
dummy
the
actual
Category: Nonexecutable
Text Reference: Section 6.4.3
Format
stl
FORMAT
([flist])
Notes:
'flist'
includes the following repeatable
Repeatable
Iw Fw.d Ew.d Ew.dEe
Lw A Aw
Bw Zw
integer real no. real no. real &
exponent logical alphanumeric alphanumeric binary hexadecimal
FORMAT
and
Statement
Specify
format
data.
nonrepeatable
'string' nHstring nX
/
kP BN BZ
$
Function
of
formatted
edit descriptors.
Nonrepeatable
literal Hollerith record position record
termination
scale
factor blank blank alternate
termination
110
record
A-6
FORTRAN-80
FORTRAN-80
Statement
Summary
Category: Nonexecutable
Text Reference: Section 5.2.1
Format
[type]
FUNCTION
func ([d[,d]
Category: Executable
Text Reference: Section
4.1.1,4.1.2,4.1.3
Formats
GOTOs GO
TO
(s[,s]
...
)[,]exp labeled
GO
TO
i [[,](s[,s]
...
)]
Notes:
FUNCTION
...
J)
GO
TO
Statements
Transfer
variable
Statement
Name
the
'func,'
define its type
parameter(s)
control
's'
name
Function
FUNCTION
'd.'
Function
to
ASSIGNED
or 'i'.
subprogram
and
dummy
statement
to
format
First Second Third
branches unconditionally.
format
format
branches based
branches
must be included in list.
Cagetory: Executable
Text Reference: Sections
Formats
IF
(e)
sl,
s2,
s3
IF
(e) st
IF
(e)
THEN
Notes:
In first
format
'e'
is
an
trol passes to:
sl
ife<O
s2
if
e = 0
s3ife>O
on
value
of
integer expression
unconditionally,
but
IF
Statements
4.1.4,4.1.5,4.1.6,4.1.7
Transfer statement tion(s) based sion
arithmetic
expression
statement
control or
'e'.
and s 1,
label
Function
to
perform
on
the value
s2,
s3
are
'exp.'
corresponding
specified
a
specified ac-
of
expres-
standard
to
'i'
labels; con-
In second format
introduces
expression
format,
'e'
is
TRUE.
statement
IF
block;
'st'
is
executed
statements
if
logical expression
following
IF-THEN
'e'
are
is
TRUE.
executed
if
logical
Third
A-7
FORTRAN-80
Statement
Summary
FORTRAN-SO
Category:
Nonexecutable,
Text Reference: Section
Format
IMPLICIT
Category:
Text
Reference: Section
type
(1[,
1]
Nonexecutable,
Format
INTEGER
[*
len [,]]
IMPLICIT
specification
3.1.5
...
)[,type(1[,I]
INTEGER
specification, type
3.1.2
name
[,name]
...
)]
...
Statement
...
Define names
range
Statement
Define
with length
Function
implicit typing
whose
first letter
'1,1.'
Function
'name'
to
be
'len.'
for
is
of
type integer
variable
'1'
or
in
Category:
Nonexecutable,
Text Reference: Section
.
Format
INTRINSIC
Category:
Text
Nonexecutable,
Reference: Section
fune
Format
LOGICAL
[*
len [,]]
INTRINSIC
specification
5.1.2
[,func]
...
LOGICAL
specification, type
3.1.3
name
[,name]
Statement
Function
Allow intrinsic function(s) be used as
actual
Statement
,.'
Function
...
Define
with length
'name'
'len.'
argument(s).
to
be
of
type logical
'fune'
to
A-8
FORTRAN-80
F'ORTRAN-80
Statement
Summary
Category:
Executable
Text Reference: Section 6.2.1
Format
OPEN
(open-list)
Notes:
'open-list'
consists
[UNIT
of
the
following specifiers:
=]
unit IOSTAT = stname ERR
= stl
FILE = fname STATUS = stat ACCESS
= acc
FORM = fmat RECL = reden BLANK = blnk CARRIAGE = car
OPEN
Statement
Open
the
to
unit).
unit
specifier
I/O
status
error
specifier
name
file
status
file
method
access
formatting record blank
specifier
carriage
Function
specified file
specifier
specifier
specifier
specifier
specifier
length specifier
control
specifier
(connect
file
Category:
Executable
Text Reference: Section 4.3.1
Format
PAUSE
Category:
Text Reference: Section
[msg]
Executable
6.3.3
Format
PRINT
f [,o'utlist]
PAUSE
PRINT
. -
Statement
Halt
program under 'msg'
control
1-5 digits
is
constant.
Statement
Output
preconnected
specified by
Function
of
Function
items
'f.'
execution;
external
or a character
'outlist'
in
unit
in
resume
signal;
format
to
...
-
..
-.-.--
A-9
f'ORTRAN-80
Statement
Summary
FORTRAN-SO
Category:
Text
Nonexecutable
Reference: Section
Format
PROGRAM
Category:
Text
Executable
Reference: Section 6.3.1
Formats
READ READ
(ctl-list) [in list]
f [,inlist]
Notes:
'ctl-list'
includes the following specifiers:
name
2.1.2
PROGRAM
Name be
READ
Statement
Statement
main
first
statement
Input
items in
specified
Function
program
Function
'inlist'
controls.
if
'name;'
used.
as
must
directed
by
Second
format
Category:
Text
Reference:
REAL
Category:
Text
Reference:
[UNIT [FMT
=]
= ] f
REC = recno lOST
A T =
ERR
= stl
END
= stl
is
for
preconnected
Nonexecutablc,
Section
Format
name
[,name]
Executable
Section
unit
stname
specification,
3.1.1
...
RETURN
5.2.4
units;
REAL
unit specifier format record 110 error
specifier
number
status
specificr
end-of-file
'f'
is
the
format
Statement
type
Define
'name'
Statement
specifier
specifier
specifier
specifier.
Function
to
be
of
type
real.
A-tO
Format
RETURN
Function
Return
from
SUBROUTINE
FUNCTION
subprogram.
or
Loading...