Skip to main content

Full text of "microsoft :: cpm :: Microsoft FORTRAN-80 3.0 Reference Manual 1977"

See other formats


MICROSOFT FORTRAN-80 Reference Manual 

Version 3. 

Copyright 1977 <€> by Microsoft 



MICROSOFT FORTRAN-80 
Reference Manual 
Contents 
Section 

1 Introduction 

2 Fortran Program Form 

2. 1 Fortran Character Set 
2. 1. 1 Letters 
2.1.2 Digits 

2. 1. 3 Alphanumeric* 

2. 1.4 Special Characters 

2. 2 FORTRAN Line Format 

2. 3 Statements 

3 Data Representation/Storage Format 
3. 1 Data Names and Types 

3. .1. 1 Names 

3. 1. 2 Types 
3. 2 Constants 

3. 3 Variab les 

3. 4 Arrays and Array Elements 

3. 5 Subscripts 

3.6 Data Storage Allocation 

4 FORTRAN Expressions 

4. 1 Arithmetic Expressions 

4.2 Expression Evaluation 

4.3 Logical Expressions 

4. 3. 1 Relational Expressions 
4.3.2 Logical Operators 

4.4 Hollerith* Literal* and Hexadecimal 
Constants in Expressions 

5 Replacement Statements 

6 Specification Statements 

A. 1 Specification Statements 

6.2 Array Declarators 

6. 3 Type Statements 

6. 4 EXTERNAL Statements 
6. 5 DIMENSION Statements 



7. 


2 


7. 


3 


7. 


4 


7. 


5 


7. 


6 


7. 


7 


7. 


S 


7. 


9 


7. 


1' 



6. 6 COMMON Statements 

6. 7 EQUIVALENCE Statements 

6.8 DATA Initialization Statement 
FORTRAN Control Statements 

7. i GOTO Statements 
7. 1. 1 Unconditional GOTO 
7. 1. 2 Computed GOTO 
7. 1.3 Assigned GOTO 
ASSIGN Statement 
IF Statement 
7. 3. 1 Arithmetic IF 

7. 3. 2 Log ical IF 
DO Statement 
CONTINUE Statement 
STOP Statement 
PAUSE Statement 
CALL Statement 
RETURN Statement 
END Statement 

8 Input/Output 

8. 1 Formatted READ/WRITE 

8. 1. 1 Formatted READ 
8. 1.2 Formatted WRITE 
Unformatted READ/WRITE 
Disk File I/O 
8. 3. 1 Random Disk I/O 
8. 3. 2 OPEN Subroutine 
Auxiliary I/O Statements 
ENCODE/DECODE 

Input/Output List Specifications 
8. 6. 1 List Item Types 
8. 6. 2 Special Notes on List 

Spec if ications 
8. 7 FORMAT Statements 

Field Descriptors 

Numeric Conversions 

Hollerith Conversions 

Logical Conversion 

X Descriptor 

P Descriptor 

Special Control Features 

of FORMAT Statements 
7. % Repeat Specifications 
7. 2 Field Separators 

FORMAT Control* List Specifications. 

and Record Demarcation 

FORMAT Carriage Control 
FORMAT Specifications in Arrays 



8. 


2 


8. 


3 


8. 


4 


8. 


5 


8. 


6 



FC 


3Ri* 


1AT 


8. 


7. 


i 


8. 


7. 


2 


8. 


7. 


3 


8. 


7. 


4 


8. 


7. 


5 


8. 


7. 


6 


8. 


7. 


7 




CJ. 






8. 




8. 


7. 


8 


8. 


7. 


9 


8. 


7. 


10 



Functions and Subprograms 

9. 1 PROGRAM Statement 

9. 2 Statement Functions 

9. 3 Library Functions 

9. 4 Function Subprograms 

9.5 Construction of Function Subprograms 

9.6 Referencing a Function Subprogram 

9. 7 Subroutine Subprograms 

9.8 Construction of Subroutine Subprograms 

9.9 Referencing a Subroutine Subprogram 

9. 10 Return From Function and Subroutine 
Subprograms 

9. 11 Processing Arrays in Subprograms 
9. 12 BLOCK DATA Subroutine 

Language Extensions and Restrictions 

I/O Interface 

Subprogram Linkages 

ASCII Character Codes 

Referencing FORTRAN-80 Library Subroutines 



APPENDIX 


A 


APPENDIX 


B 


APPENDIX 


C 


APPENDIX 


D 


APPENDIX 


E 



FORTRAN-BO Reference Manual Page 6 

SECTION i 
INTRODUCTION 
FORTRAN is a universal* problem oriented programming 
language designed to simplify the preparation and check-out 
of computer programs. The name of the language ••- FORTRAN 
is an acronym for FORmula TRANslator. 

The syntactical rules for using the language are rigorous 
and require the programmer to define fully the 
characteristics of a problem in a series of precise 
statements. These statements* called the source program* 
are translated by a system program called the FORTRAN 
processor into an object program in the machine language of 

the computer on which the program is to be executed. 
This manual defines the FORTRAN source language for the 8080 
and 2-80 microcomputers. This language includes the 
American National Standard FORTRAN language as described in 
ANSI document X3. 9-1966* approved on March 7* 1966* plus a 
number of language extensions and some restrictions. These 
language extensions and restrictions are described in the 
text of this document and are listed in Appendix A. 

NOTE 

This FORTRAN differs from the 

Standard in that it does not 

include the COMPLEX data type. 
Examples btb included throughout the manual to illustrate 
the construction and use of the language elements. The 
programmer should be familiar with all aspects of the 
language to take full advantage of its capabilities. 
Section 2 describes the form and components of ar) 8080 
FORTRAN source program. Sections 3 and 4 define data types 
and their expressional relationships. Sections 5 through 9 
describe the proper construction and usage of the various 
statement classes. 



F0RTRAN--80 Reference Manual Page 7 

SECTION 2 
FORTRAN PROGRAM FORM 
8080 FORTRAN source programs consist of one program unit 
called the Main program and any number of program units 

called subprograms. A discussion of subprogram types and 

methods of writing and using them is in Section 9 of this 
manual. 

Programs and program units are constructed of an ordered set 
of statements which precisely describe procedures for 
solving problems &nd which also define information to be 
used by the FORTRAN processor during compilation of the 
object program. Each statement is written using the FORTRAN 
character set and following a prescribed line format. 
2. 1 FORTRAN CHARACTER SET 

To simplify reference and explanation* the FORTRAN 
character set is divided into four subsets and a 
name is given to each. 
2. :l. 1 LETTERS 

aTbTcTd, E> F* G, H> I, J* K» L* M* N* 0, P> Q, R, S* T, U 
V, y, X, Y* .2, * 

NOTE 
No distinction is made between upper and 
lower case letters. However, for clarity 
and legibility* exclusive use of upper case 
letters is recommended. 
2. I. 2 DIGITS 

5777273* 4, 5, 6, 7* 8, 9 

NOTE 
Strings of digits representing numeric 
quantities are normally interpreted as 
decimal numbers. However* in certain 
statements* the interpretation is in the 



FORTRAN-80 Reference Manual Page 8 

Hexadecimal number system in which case the 
letters A> B> C* D> E> F may also be used 
as Hexadecimal digits. Hexadecimal usage 
is defined in the descriptions of 
statements in which such notation is 
al lowed. 

2. 1. 3 ALPHANUMERIC5 

A sub-set of characters made up of all letters and 
all digits. 
2. 1.4 SPECIAL. CHARACTERS 





Blank 


as 


Equality Sign 


+ 


Plus Sign 


- 


Minus Sign 


# 


Asterisk 


/ 


Slash 


( 


Left Parenthesis 


) 


Right Parenthesis 


> 


Comma 




Decimal Point 


NOTES: 





1. FORTRAN program lines consist of SO character 
positions or columns* numbered 1 through 80. 
They are divided into four fields. 

2. The following special characters are classified 
as Arithmetic Operators and are significant in 
the unambiguous statement of arithmetic 
expressions. 

+ Addition or Positive Value 

- Subtraction or Negative Value 

* Multiplication 

/ Division 

*# Exponentiation 

3. The other special characters have specific 
application in the syntactical expression of 
the FORTRAN language and in the construction of 
FORTRAN statements. 



FORTRAN-BO Reference Manual Page 7 

4. Any printable character may appear in a 
Hollerith or Literal field. 
2. 2 FORTRAN LINE FORMAT 

The sample FORTRAN coding form (Figure 2. 1) shows 
the format of FORTRAN program lines. The lines of 
the form consist of SO character positions or 
columns* numbered 1 through SO» and are divided 
into four fields. 

1. Statement Label (or Number) field- Columns 1 
through 5 (See definition of statement labels). 

2. Continuation character field- 
Column 6 

3. Statement field- 
Columns 7 through 72 

4. Indentifi cation field- 
Columns 73 through SO 

The identification field is available for any 

purpose the FORTRAN programmer may desire and is 

ignored by the FORTRAN processor. 

The lines of a FORTRAN statement are placed in 

Columns 1 through 72 formatted according to line 

types. The four line types* their definitions, and 

column formats are: 

1. Comment line — used for source program 

annotation at the convenience of the 

programmer. 

1. Column 1 contains the letter C. 

t 

2. Columns 2-72 btq used in any desired 
format to express the comment or they may 
be left blank. 

3. A comment line may be followed only by an 
initial line. an END line. or another 
comment line. 

4. Comment lines have no effect on the object 
program and are ignored by the FORTRAN 
processor except for display purposes in 
the listing of the program. 



: 0RTRAN~80 Reference Manual Page 11 

Example: 

C _ COMMENT LINES ARE INDICATED BY THE 
C CHARACTER C IN COLUMN 1. 
C THESE ARE COMMENT LINES 

2. END line — the last line of a program unit. 

1. Columns 1-5 may contain a statement label. 

2. Column 6 must contain a zero or blank. 

3. Columns 7-72 contain one of the characters 
Ej N or Dt in that order* preceded by* 
separated by or followed by blank 
characters. 

4. Each FORTRAN program unit must have an END 
line as its last line to inform the 
Processor that it is at the physical end of 
the program unit. 

5. An END line may follow any other type line. 
Ex amp le: 

END 

3. Initial Line — the first or only line of each 
statement. 

i. Columns 1~5 may contain a statement label 
to identify the statement. 

2. Column 6 must contain a zero or blank. 

3. Columns 7-72 contain all or part of the 
statement. 

4. An initial line may begin anywhere within 
the statement field. 

Example: 



C THE STATEMENT BELOW CONSISTS 

C OF AN INITIAL LINE 

C 

A~ . 5*SGRT<3~-2. *C ) 



FQRTRAN-80 Reference Manual Page 12 

4. Continuation Line — used when additional lines 
of coding are required to complete a statement 
originating with an initial line. 

1. Columns 1-5 are ignored/ unless Column 1 
contains a C. 

2. If Column 1 contains a C, it is a comment 
line. 

3. Column 6 must contain a character other 



than zero or blank. 

4. Columns 7-72 contain the continuation of 
the statement. 

5. There may be as many continuation lines as 
needed to complete the statement. 
Example: 



C THE STATEMENTS BELOW ARE AW INITIAL LINE 

C AND 2 CONTINUATION LINES 

C 

63 BETA (1,2) « 

1 A6BAR**7-(BETA<2, 2>~A3BAR#5Q 

2 +SQRT (BETA (2, 1))> 

A statement label may be placed in columns 1—5 of a 
FORTRAN statement initial line and is used for 
reference purposes in other statements. 
The following considerations govern the use of 
statement labels: 

1. The label is an integer from 1 to 99999. 

2. The numeric value of the label, leading zeros 
and blanks are not significant. 

3. A label must be unique within a program unit. 

4. A label on a continuation line is ignored by 
the FORTRAN Processor. 



FORTRAN-80 Reference Manual , Page 13 

Example: 

C SAMPLES OF STATEMENT LABELS 
C 
.1 

101 
99999 
763 
2. 3 STATEMENTS 

Individual statements deal with specific aspects of 
a procedure described in a program unit and are 
classified as either executable or non-executable. 

Executable statements specify actions and cause the 

FORTRAN Processor to generate object program 
instructions. There are three types of executable 

statements: 

1. Replacement statements. 

2. Control statements. 

3. Input/Output statements. 

Non-executable statements describe to the processor 

the nature and arrangement of data and provide 
information about input/output formats and data 
initialization to the object program during program 
loading and execution. There are five types of 
non-executable statements: 

1. Specification statements. 

2. DATA Initialization statements. 

3. FORMAT statements. 

4. FUNCTION defining statements. 

5. Subprogram statements. 

The proper usage and construction of the various 
types of statements are described in Sections 5 
through 9. 



FORTRAN— 80 Reference Manual Page. 14 

SECTION 3 
DATA REPRESENTATION / STORAGE FORMAT 
The FORTRAN Language prescribes a definitive method for 
identifying data used in FORTRAN programs by name and type. 

3. 1 DATA NAMES AND TYPES _ 

3. :i . 1 NAMES 



1. Constant - An explicitly stated datum. 

2. Variable - A symbolically identified datum. 

3. Array -~ An ordered set of data in t> 2 or 3 
dimensions. 

4. Array Element - One member of the set of data 
of an array. 



3. 1. 2 TYPES 



1. Integer — Precise representation of integral 
numbers (positive* negative or zero) having 
precision to 5 digits in the range -32768 to +32767 
inclusive ( ~2## 1 5 t o 2**1 5- 1 ) . 

2. Real — Approximations of real numbers (positive* 
negative or zero) represented in computer storage 
in 4-byte* floating-point form. Real data are 
precise to 7+ significant digits and their 
magnitude may lie between the approximate limits of 
10#*-38 and 10**38 <2**~I27 and 2**127). 

3. Double Precision'— Approximations of real numbers 
(positivei negative or zero) represented in 
computer storage in 8~byte> floating-point form. 
Double Precision data arts precise to 16+ 
significant digits in the same magnitude range as 
real data. 

4. Logical - — One byte representations of the truth 
values "TRUE" or "FALSE" with "FALSE defined to 
have an internal representation of zero. The 
constant .TRUE. has the value . —1» however any 
non-zero value will be treated as .TRUE. in a 
Logical IF statement. In addition* Logical types 
may be used as on© byte signed integers in the 



ORTRAN-80 Reference Manual Page 15 
range -128 to +127* inclusive. 

S. Hollerith — A string of any number of characters 

from the computer's character set. All characters 

including blanks qt& significant. Hollerith data 
require one byte for storage of each character in 
the string. 
I. 2 CONSTANTS 

FORTRAN constants are identified explicitly by 
stating their actual value. The plus (+) character 
need not precede positive valued constants. 
Formats for writing constants are shown in Table 
3-1. 



FORTRAN-BO Reference Manual 

Table 3-1. CONSTANT FORMAT: 
TYPE FORMATS AND RULES OF USE 



INTEGER 



REAL 



1. 1 to 5 decimal digits 
interpreted as a deci- 
mal number. 

2. A preceding plus ( + > or 
minus < -- ) sign is op- 

t ional. 

3. No decimal point <. ) or 
comma ( .• > is allowed. 

4. Value range: -32768 
through +32767 <. :L e. > 
-2**15 through 2**15-1). 

1. A decimal number with 
precision to 7 digits 
and represented in one 
of the following forms: 

a. + or -. f + or -i. f 

b. + or ~:i. E+ or -e 
+ or -. PE+ or — e 
+ or ™i. fE+ or -e 

where i, f, and e are 
each strings rep7*esent- 
ing integer, fraction* 
and exponent respective- 
ly. 

2. Plus < + ) and minus (-) 
characters ar& optional. 

3. In the form shown in 1 b 
above* if r represents any 
of the forms preceding 

E+ or -e (i. e. > rE+ or -e)» 
the value of the constant 
is interpreted as r times 
10*#e» where ~33<=e038. 

4. If the constant preceding 
E+ or -e contains more 
significant digits than 



Page 16 

EXAMPLES 

-763 
1 

+00672 
-32768 

+32767 



345. 

-. 345678 

+345. 678 

+ . 3E3 
-73E4 



FORTRAN-80 Reference Manual 

the pre 
data al 
occurs, 
most si 
in the 
resent© 
DOUBLE A decimal n 

PRECISION precision t 

formats and 
c: a 1 to t h o s 
stants* exc 
place of E. 
constant is 
cision unle 
"D" exponen 
LOGICAL .TRUE, gene 

byte < h e x a d 
. FALSE, gen 
which all b 



Page 17 



cision for real 
lows* truncation 

and only the 
gnificant digits 
range will be rep- 
el. 

umber with 
o 16 d igi ts. Al 1 

rules are identi-- 
e for REAL con~ 
ept D is used in 
Note that a real 

assumed single pre- 
ss it contains a 
t. 

rates a n on- zero 
ecimal FF) and 
erates a byte in 
its are 0. 



+345. 678 
+ . 3D3 
-73D4 



TRUE. 
FALSE. 



LITERAL 



HEXADECIMAL 



If logical values btb 

used as one -byte integei^s* the 

rules for use ar& the same as 

for type INTEGER* except that 

the range allowed is -128 to 

+127* inclusive. 

In the literal farm* any 

number of characters may be 

enclosed by single quotation 

marks. The form is as follows; 

'X1X2X3. . . Xn' 
where each Xi is any charac- 
ter other than '. Two 
quotation marks in succession 
may be used to represent the 
quotation mark character 
within the string* i.e.* 
if X2 is to be the quotation 
mark character.* the string 
appears as the following: 

'XI ' 'X3. . . Xn' 
1. The letter Z or X 
followed by a single quote* 
up to 4 hexadecimal 



Z'12' 
X'ABIF 



FORTRAN— 80 Reference Manual Fage 

digits (0-9 and A--F) and a Z'FFFF' 
single quote is recognized 
as a hexadecimal value. X'lF' 

2. A hexadecimal constant is 
right justified in its storage 
value. 



IS 



FORTRAN—BO Reference Manual 
3.3 VARIABLES 



Page 19 



Variable data are identified in FORTRAN statements 
by symbolic names. The names ar^ unique strings of 

from 1 to 6 alphanumeric characters of which the 

first is a letter. 

NOTE 
System variable names and runtime 
subprogram names are distinguished from 
other variable names in that they begin 
with the dollar sign character ($). It is 
therefore strongly recommended that in 
order to avoid conflicts., symbolic names in 
FORTRAN source programs begin with some 
letter other than "*". 

Examp les: 



15, TEAR, B23, ARRAY, XFM79, 
Variable data are classif 
INTEGER, REAL, DOUBLE PREC 
specification of type is ace 
foil owing ways: 
1. Implicit typing in which 
the symbolic name spe 
type. Unless explicit! 
symbolic names beg inn in 
N represent Integer va 
names beginning with 1 
K, L, M or N represent R 
Integer Variables 



MAX, A1$C 
ied into four types: 
ISION and LOGICAL. The 
omplished in one of the 

the first letter of 
cifies Integer or Real 
y typed (2., below), 
g with I, J, K, L, M or 
riables, and symbolic 
etters other than I, J, 
eal variables. 



ITEM 

Ji 

MODE 

K123 

N2 



FORTRAN-80 Reference Manual Page 20 

Real Variables 
__ 

H2 

ZAP 

AMAT 

XID 
2. Variables may be typed explicitly. That is, 

they may be given a particular type without 

reference to the first letters of their names. 

Variables may be explicitly typed as INTEGER* 

REAL, DOUBLE PRECISION or LOGICAL. The 

specific statements used in explicitly typing 

data are described in Section 6. 
Variable data receive their numeric value assignments during 
program execution or, initially, in a DATA statement 
(Section 6). 

Hollerith or Literal data may be assigned to any type 
variable. Sub-paragraph 3.6 contains a discussion of 
Hollerith data storage. 
3. 4 ARRAYS AND ARRAY ELEMENTS 



An array is an ordered set of data characterized by 
the property of dimension. An array may have 1> 2 



or 3 dimensions and is identified and typed by a 
symbolic name in the same manner as a variable 
except that an arra^ name must be so declared by an 
"away declarator." Complete discussions of the 
arva{^ declarators appear in Section 6 of this 
manual. An arra\^ declarator also indicates the 
dimensionality and size of the arrav^. An array 

element is one member of the data set that makes up 

an arra\^. Reference to an arrays element in a 
FORTRAN statement is made by appending a subscript 
to the arra\} name. The term arrav^ element is 
synonymous u/ith the term subscripted variable used 
in some FORTRAN texts and reference manuals. 
An initial value may be assigned to any arrays 
element by a DATA statement or its value may be 
derived and defined during program execution. 
SUBSCRIPTS 

A subscript follows an array name to uniquely 



FORTRAN-80 Reference Manual Page 21 

identify an array element. In use* a subscript in 
a FORTRAN statement takes on the same 
representational meaning as a subscript in familiar 
algebraic, notation. 

Rules that govern the use of subscripts aris as 
f ol lows: 

1. A subscript contains 1* 2 or 3 subscript 
expressions (see 4 below) enclosed in 
parentheses. 

2. If there are two or three subscript expressions 
within the parentheses* they must be separated 
by commas. 

3. The number of subscript expressions must be the 
same as the specified dimensionality of the 
Array Declarator except in EQUIVALENCE 
statements (Section 6). 

4. A subscript expression is written in one of the 
following forms: 

K OV V-K 

V CttV+K C*V-K 

V+K 

where C and K ar& integer constants and V is an 

integer variable name (see Section 4 for a 

discussion of expression evaluation). 

5. Subscripts themselves may not be subscripted. 

Examples: 

X<2*J--3, 7) A<I»J,K) 1(20) C(L-2) Y(I) 
3. 6 DATA STORAGE ALLOCATION 

Allocation of storage for FORTRAN data is made in 
numbers of storage units. A storage unit is the 



memory space required to store one real data value 

(4 bytes). 

Table 3-2 defines the word formats of the three 

data types. 

Hexadecimal data may be associated (via a DATA 

statement) with any type data. Its storage 

allocation is the same as the associated datum. 

Hollerith or literal data may be associated with 

any data type by use of DATA initial i zaton 



FORTRAN— SO Reference Manual Page 22 

statements (Section 6). 

Up to eight Hollerith characters may be associated 
with Double Precision type storage* up to four with 
Real* up to two with Integer and one with Logical 
type storage. 



FORTRAN-80 Reference Manual Page 23 

TABLE 3-2. STORAGE ALLOCATION BY DATA TYPES 
TYPE ALLOCATION 

INTEGER 2 bytes/ 1/2 storage unit 
S Binary Value 

Negative numbers are the 2's complement of 
positive representations. 

LOGICAL 1 byte/ 1/4 storage unit 

Zero (false) or non-zero (true) 

A non-zero valued byte indicates true (the 

logical constant .TRUE. is represented by 

the hexadecimal value FF). A zero valued 

byte indicates false. 

When used as an arithmetic value* a Logical 

datum is treated as an Integer in the range 

-128 to +127. 

REAL 4 bytes/ 1 storage unit 

Characteristic: S Mantissa 
Mantissa (continued) 

The first byte is the characteristic 
expressed in excess 200 (octal) notation; 
i. e. * a value of 200 (octal) corresponds to a 
binary exponent of 0. Values less than 200 
(octal) correspond to negative exponents* and 
values greater than 200 correspond to 
positive exponents. By definition* if the 
characteristic is zero* the entire number is 
zero. 

The next three bytes constitute the mantissa. 
The mantissa is always normalized such that 
the high order bit is one* eliminating the 
need to actually save that bit. The high bit 
is used instead to indicate the sign of the 
number. A one indicates a negative number* 
and zero indicates a positive number. The 
mantissa is assumed to be a binary fraction 
whose binary point is to the left of the 
mantissa. 



FORTRAN-80 Reference Manual Page 24 

DOUBLE 8 bytes/ 2 storage units 

PRECISION 

The internal form of Double Precision data is 
identical with that of Real data except 
Double Precision uses 4 extra bytes for the 
matissa. 



FORTRAN-80 Reference Manual Page 25 

SECTION 4 
FORTRAN EXPRESSIONS 
A FORTRAN expression is composed of a single operand or a 
string of operands connected by operators. Two expression 
types —Arithmetic and Logical — are provided by FORTRAN. 
The operands* operators and rules of use for both types are 
described in the following paraqraphs. 
4. 1 ARITHMETIC EXPRESSIONS" 



The following rules define all permissible 

arithmetic expression forms: 

1. A constant) variable name.. arrays element 

reference or FUNCTION reference (Section 9) 

standing alone is an expression. 

Examp les: 



S<I) JOBNO 217 17.26 SQRT<A+B> 

2. If E is an expression whose first character is 
not an operator* then +E and -~E are called 
signed expressions. 

Examples 

HeT + JOBNO -217 -4-17.26 -SGR T < A+B > 

3. If E is an expression* then (E) means the 
quantity resulting when E is evaluated. 
Examples: 



<~A) -(JOBNO) ~(X+1) <A-SQRT<A+B>) 
If E is an unsigned expression and F is any 
expression* then: F+E* F--E* F#E* F/E and F*#E 
are all expressions. 
Examp les: 

•~TB"rfTj7+SGRT ( A+B ( K* L) ) ) 
1. 7E-2**<X+5. 0) 
~<B<I+3* 3#J+5>+A) 



FORTRAN-80 Reference Manual Page 26 

5. An evaluated expression may be Integer* Real* 
Double Precision* or Logical. The type is 
determined by the data types of the elements of 
the expression. If the elements of the 
expression are not all of the same type* the 
type of the expression is determined by the 
element having the highest type. The type 
hierarchy <hiqhest to lowest) is as follows: 
DOUBLE PRECISION, REAL* INTEGER* LOGICAL. 

6. Expressions may contain nested parenthesized 
elements as in the following: 

A#<Z~< <Y+X)/T))##U 

where Y+X is the innermost element* (Y+X)/T is 

the next innermost* Z-<(Y+X)/T) the next. In 

such expressions* care should be taken to see 

that the number of left parentheses and the 
number of right parentheses are equal. 
4. 2 EXPRESSION EVALUATION 

Arithmetic expressions are evaluated according to 
the following rules: 

1. Parenthesized expression elements are evaluated 
first. If parenthesized elements are nested* 
the innermost elements are evaluated* then the 
next innermost until the entire expression has 
been evaluated. 

2. Within parentheses and/or wherever parentheses 
do not govern the order or evaluation* the 
hierarchy of operations in order of precedence 
is as follows: 

a. FUNCTION evaluation 

b. Exponentiation 

c. Multiplication and Division 

d. Addition and Subtraction 
Examp le: 



The expression 

A* < Z- < < Y+R ) /T ) ) **J+VAL 
is evaluated in the following sequence: 



FORTRAN-BO Reference Manual Page 27 

Y+R zz e.t 
<el)/T = e2 
Z~e2 = e3 
e3#*J = e4 
A#e4 « g5 
e5+VAL ~ e6 

3. The expression X**Y**Z is not allowed. It 
should be written as follows: 

<X**Y)**Z or X**<Y*#Z) 

4. Use of an arra^ element reference requires the 
evaluation of its subscript. Subscript 
expressions arB evaluated under the same rules 
as other expressions. 

4. 3 LOGICAL EXPRESSIONS 

A Logical Expression may be any of the following: 

1. A single Logical Constant (i.e.* .TRUE. or 
.FALSE. >* a Logical variable* Logical Array 
Element or Logical FUNCTION reference (see 
FUNCTION* Section 9). 

2. Two arithmetic expressions separated by a 
relational operator (i.e.* a relational 



expression). 

3. Logical operators acting upon logical 
constants, logical variables* logical arra^ 
elements* logical FUNCTIONS* relational 
expressions or other logical expressions. 

The value of a logical expression is always either 

. TRUE. or . FALSE." 
4. 3. t RELATIONAL EXPRESSIONS 

The general form of a relational expression is as 
follows: 

e.t r e2 
where el and e2 are arithmetic expressions and r is 
a relational operator. The six relational 



operators av& as follows: 



FORTRAN-80 



Reference 


Manual 


Page 2S 


. LT. 






Less Than 




. LE. 






Less than or 


equal to 


. EQ. 






Equal to 




. NE. 






Not equal to 




. GT. 






Greater than 




. GE. 






Greater than 


or equal to 


The value 





f the relational 


expression is . TRUE. 


if the i 


:ondi 


tion defined 


bij the operator is met. 


Otherwise^ 




the 


value is . FAL 


.SE. 


Examp les: 










~— ~ 


B 








< A** J ) 


. GT. 


. <ZAP*(RHO#TAL 


f-ALPH)) 



4.3.2 LOGICAL OPERATORS 



Table 4-1 lists the logical operations. U and 
denote logical expressions. 



FORTRAN-80 Reference Manual Page 29 

Table 4-1. Logical Operations 

. NOT. U The value of this expression is the 

logical complement of U (i. e. , 1 
bits become and bits become 1). 

U. AND. V The value of this expression is the 

logical product of U and V (i.e.* 
there is a .1 bit in the result only 
where the corresponding bits in both 
U and V are 1. 

U. OR. V The value of this expression is the 

logical sum of U and V (i.e.* there 
is a 1 in the result if the 
corresponding bit in U or V is 1 or 
if the corresponding bits in both U 
and V are 1. 

U. XOR. V The value of this expression is the 

exclusive OR of U and V (i. e. * there 
is a one in the result if the 
corresponding bits in U and V are 1 
and O or O and 1 respectively. 

Examples: 



If U = 01 101 100 and V = 11001001 > then 

. NOT. U = 10010011 
U. AND. V « 01001O0O 
U. OR. V « 11101101 
U. XOR. V « 10100101 



FORTRAN-80 Reference Manual Page 30 

The following are additional considerations for 
construction of Logical expressions: 

1. Any Logical expression may be enclosed in 
parentheses. However* a Logical expression to 
which the .NOT. operator is applied must be 
enclosed in parentheses if it contains two or 
more elements. 

2. In the hierarchy of operations* parentheses may 
be used to specify the ordering of the 
expression evaluation. Within parentheses* and 
where parentheses do not dictate evaluation 
order* the order is understood to be as 
f ol lows: 

a. FUNCTION Reference 

b. Exponentiation (##) 

c. Multiplication and Division (•* and /> 

d. Addition and Subtraction (+ and -) 

e. . LT. * . LE. > . EQ. > . NE. * . GT. * . GE. 

f . . NOT. 

g. ■ AND. 

h. . OR. * . XOR. 
Examples: 



The expression 

X . AND. Y . OR. B<3, 2) . GT. Z 
is evaluated as 



The 



is 



el = B<3>2>. 
e2 = X . AND. 
e3 ~ e2 . OR. 


GT. Z 
Y 
el 


expression 
X . AND. (Y . 


OR. B(3*2) 


evaluated as 
el » B<3* 2) 


. GT. Z 



GT. Z> 



e2 = Y .OR. el 
e3 = X . AND. e2 
3. It is invalid to have two contiguous logical 
operators except when the second operator is 

. NOT". 



FORTRAN-SO Reference Manual Page 31 

That is, 

. AND. . NOT. 

and 

. OR. . NOT. 

are permitted. 
Example: 

A. AND. . NOT. B is permitted 

A. AND. . OR. B is not permitted 
4. 4 HOLLERITH, LITERAL, AND HEXADECIMAL CONSTANTS IN 



EXPRESSIONS 

Hollerith, Literal, and Hexadecimal constants are 
allowed in expressions in place of Integer 
constants. These special constants always evaluate 
to an Integer value and are therefore limited to a 
length of two bytes. The only exceptions to this 
are: 

1. Long Hollerith or Literal constants may be used 
as subprogram parameters. 

2. Hollerith, Literal, or Hexadecimal constants 
may be up to four bytes long in DATA statements 
when associated with Real variables, or up to 
eight bytes long when associated with Double 
Precision variables. 



FORTRAN-80 Reference Manual Page 32 

SECTION 5 
REPLACEMENT STATEMENTS 
Replacement statements define computations and are used 
similarly to equations in normal mathematical notation. 
They are of the following form: 

v = e 
where v is any variable or array element and e is an 
expression. 

FORTRAN semantics defines the equality sign {-) as meaning 
to be replaced by rather than the normal is equivalent to. 



Thus* the object program instructions generated by a 
replacement statement will* when executed) evaluate the 
expression on the right of the equality sign and place that 
result in the storage space allocated to the variable or 
arra\i element on the left of the equality sign. 
The following conditions apply to replacement statements: 

1. Both v and the equality sign must appear on the 
same line. This holds even when the statement is 
part of a logical IP" statement <section 7). 
Example: 

C IN A REPLACEMENT STATEMENT THE '=' 
C MUST BE IN THE INITIAL LINE. 
A (5, 3) - 
1 B<7* 2) + SIN<C) 

The line containing v= must be the initial line of 
the statement unless the statement is part of a 
logical IF statement. In that case the v« must 
occur no later than the end of the first line after 
the end of the IF. 

2. If the data types of the variable* v* and the 
expression* e* are different* then the value 
determined by the expression will be converted* if 
possible* to conform to the typing of the variable. 
Table 5-1 shows which type expressions may be 
equated to which type of variable. Y indicates a 
valid replacement and N indicates an invalid 
replacement. Footnotes to Y indicate conversion 
considerations. 



FORTRAN-60 Reference Manual 

Table 5-1. Replacement By Type 
Expression Types <e) 



t e3 CJ €? ww 



Variab 

Types 

I n t e g e 

Real 

Logica 

Double 

a. The 
truncat 
Integer 

b . The 

c. The 
the Int 

d. The 
Integer 
regardl 

e. The 
Real ex 



le 



Real 
Ya 
Y 

Ya 
Y 



Logical 

Yb 

Yc 

Y 

Yc 
is converted 
conform to 



Double 
Ya 
Ye 
Ya 
Y 

to 
the 



Integer 
r Y 

Yc 
1 Yd 
Yc 
Real expression value 
ed if necessary to 
data. 

sign is extended through the second byte, 
variable is assigned the Real approximation 
eger value of the expression, 
variable is assigned the truncated value of the 
expression (the low-order byte is used* 
ess of sign). 

variable is assigned the rounded value of the 
pression. 



Integer* 
range of 



of 



FORTRAN-80 Reference Manual Page 34 

SECTION 6 
SPECIFICATION STATEMENTS 
Specification statements are non-executable* non-generative 
statements which define data types of variables and arrays* 
specify arrai^ dimensionality and size* allocate data storage 
or otherwise supply determinative information to the FORTRAN 
processor. DATA intial i zation statements are 
non-executable* but generate object program data and 
establish initial values for variable data. 
6. 1 SPECIFICATION STATEMENTS 

There are six kinds of specification statements. 
They avB as follows: 

Type* EXTERNAL* and DIMENSION statements 

COMMON statements 

EQUIVALENCE statements 

DATA initialization statements 
All specification statements are grouped at the 
beginning of a program unit and must be ordered as 
they appear above. Specification statements may be 
preceded only by a FUNCTION* SUBROUTINE, PROGRAM or 
BLOCK DATA statement. All specification statements 
must precede statement functions and the first 
executable statement. 
6. 2 ARRAY DECLARATORS 

Three kinds of specification statements may specify 
array declarators. These statements are the 
following: 

Type statements 

DIMENSION statements 

COMMON statements 
Of these* DIMENSION statements have the declaration 
of arrays as their sole function. The other two 
serve dual purposes. These statements ans defined 
in subparagraphs 6.3* 6. 5 and 6.6. 

Array declarators arts used to specify the name* 
dimensionality and sizes of arrays. An array may 
be declared only once in a program unit. 
An array declarator has one of the following forms: 



FORTRAN-80 Reference Manual Page 35 

ui <k> 

ui < kl* k2> 

ui (ki* k2* k3) 
where ui is the name of the array * called the 
declarator name* and the k's are integer constants. 
Array storage allocation is established upon 
appearance of the array declarator. Such storage 
is allocated linearly by the FORTRAN processor 
where the order of ascendancy is determined by the 
first subscript varying most rapidly and the last 
subscript varying least rapidly. 

For example* if the array declarator AMAT<3>2*2) 
appears* storage is allocated for the 12 elements 
in the following order: 

AMATU* 1.. 1), AMAT(2*1*1>* AMAT(3* 1 * 1 ) * AMAT (1*2*1)* 
AMATC2* 2* 1)* AMAT<3*2* 1)* AMATd, 1*2)* AMAT(2* 1*2>* 
AMATO, 1,2), AMAT<1,2*2)> AMAT<2, 2*2)* AMAT(3, 2*2) 
6. 3 TYPE STATEMENTS 

Variable* array and FUNCTION names am 

automatically typed Integer or Real by the 

'predefined' convention unless they are changed by 

Type statements. For example* the type is Integer 

if the first letter of an item is I* J* K* L* M or 

N. Otherwise* the type is Real. 

Type statements provide for overriding or 

confirming the pre— defined convention by specifying 

the type of an item. In addition* these statements 

may be used to declare arrays. 

Type statements have the following general form: 

t vl* v2* . . . vn 
where t represents one of the terms INTEGER* 
INTEGER*!* INTEGER*2* REAL* REAL*4* REALMS* DOUBLE 
PRECISION* LOGICAL* LOGICAL*!* L0GICAL*2* or BYTE. 
Each v is an array declarator or a variable* array 
or FUNCTION name. The INTEGER*!* INTEGER*2* 
REAL*4* REAL*S* LOGICAL*!* and L0GICAL*2 types are 
allowed for readability and compatibility with 
other FORTRANs. BYTE* INTEGER*1* LOGICAL*!* and 
LOGICAL are all equivalent* INTEGER*2* L0GICAL*2* 
and INTEGER are equivalent* REAL and REAL*4 are 
equivalent* DOUBLE PRECISION and REAL*S are 
equivalent. 



FOR TR AN— SO Reference Manual Page 36 

Example: 

REAL AMAT<3, 3, 5), BX, IETA, KLPH 

NOTE 

1. AMAT and BX are redundantly typed. 

2. IETA and KLPH are unconditionally 
declared Real. 

3. AMAT(3, 3, 5) is a constant arra\Ji 
declarator specifying an arra^ of 45 
elements. 

Example: 

INTEGER Ml, HT, JMPU5), FL 

NOTE 
Ml is redundantly typed here. Typing of HT 
and FL by the pre-defined convention is 
overridden by their appearance in the 
INTEGER statement. JMP(15) is a constant 
arra^ declarator. It T^edundantly types the 
arrays elements as Integer and communicates 
to the processor the storage requirements 
and dimensionality of the arvavi. 
Ex amp le: 

LOGICAL LI, TEMP 

NOTE 
All variables, arrays or FUNCTIONS required 
to be typed Logical must appear in a 

LOGICAL statement, since no starting letter 
indicates these types by the default 
convention. 



FQRTRAN-80 Reference Manual Page 37 

6. 4 EXTERNAL STATEMENTS 

EXTERNAL statements have the following form: 

EXTERNAL ui, u2, . . . , un 
where each ui is a SUBROUTINE.. BLOCK DATA or 
FUNCTION name. When the name of a subprogram is 
used as an argument in a subprogram reference* it 
must have appeared in a preceding EXTERNAL 
statement. 

When a BLOCK DATA subprogram is to be included in a 
program load* its name must have appeared in an 
EXTERNAL statement within the main program unit. 
For example, if SUM and AFUNC are subprogram names 
to be used as arguments in the subroutine SUBR, the 
following statements would appear in the calling 
program unit: 



EXTERNAL SUM, AFUNC 



CALL SUBR (SUM, AFUNC, X, Y> 
6. 5 DIMENSION STATEMENTS 

A DIMENSION statement has the following form: 

DIMENSION u2, u2, u3, ...,un 
where each ui is an array declarator. 
Example: 

DIMENSION RAT<5, 5>,BAR<20> 
This statement declares two arrays - the 25 element 
array RAT and the 20 element array BAR. 
6. 6 COMMON STATEMENTS 

COMMON statements are non-executable, storage 
allocating statements which assign variables and 
arrays to a storage area called COMMON storage and 
provide the facility for various program units to 
share the use of the same storage area. 



FORTR AIM-SO Reference Manual Page 38 

COMMON statements are expressed in the following 
f OT*m: 

COMMON /yl/ai/y2/a2/. . . /yn/an 
where each yi is a COMMON block storage name and 



each ai is a sequence of variable names* arra\^ 
names or constant arraii declarators* separated by 
commas. The elements in ai make up the COMMON 

block storage area specified by the name yi. If 

any yi is omitted leaving two consecutive slash 
characters <//)* the block of storage so indicated 
is called blank COMMON. If the first block name 
<yl) is omitted* the two slashes may be omitted. 
Ex amp le: 

COMMON /AREA/A, B* C/BDATA/X* Y* Z* 
X FL*ZAP<30) 

In this example* two blocks of COMMON storage are 
allocated ~ AREA with space for three variables and 
BDATA* with space for four variables and the 30 
element array* ZAP. 
Examp le: 

"""" COMMON //A1*B1/CDATA/Z0T<3, 3) 

X //T2, Z3 

In this example* Al» Bl* T2 and Z3 are assigned to 
blank COMMON in that order. The pair of slashes 
preceding Al could have been omitted. 
CDATA names COMMON block storage for the nine 
element array^t ZOT and thus ZOT <3*3) is an arrays 
declarator. ZOT must not have been previously 



declared. (See "Array Declarators*" Paragraph 



6. 3. ) 

Additional Considerations: 

1. The name of a COMMON block may appear more than 
once in the same COMMON statement* or in more 
than one COMMON statement. 

2. A COMMON block name is made up of from 1 to 6 
alphanumeric characters* the first of which 
must be a letter. 

3. A COMMON block name must be different from any 
subprogram names used throughout the program. 



FORTRAN-80 Reference Manual Page 39 

4. The size of a COMMON area may be increased by 
the use of EQUIVALENCE statements. See 
"EQUIVALENCE Statements* " Paragraph 6. 7. 

5. The lengths of COMMON blocks of the same name 
need not be identical in all program units 
where the name appears. However* if the 
lengths differ* the program unit specifying the 
greatest length must be loaded first (see the 
discussion of LINK-SO in the User's Guide). 
The length of a COMMON area is the number of 
storage units required to contain the variables 
and arrays declared in the COMMON statement < or 
statements) unless expanded by the use of 
EQUIVALENCE statements. 

6. 7 EQUIVALENCE STATEMENTS 



Use of EQUIVALENCE statements permits the sharing 
of the same storage unit by two or more entities. 
The general form of the statement is as follows: 

EQUIVALENCE < ul ),< u2> *...,< un ) 
where each ui represents a sequence of two or more 
variables or arra^ elements* separated by commas. 
Each element in the sequence is assigned the same 
storage unit (or portion of a storage unit) by the 
processor. The order in which the elements appear 
is not significant. 
Example: 

— QU j VALENCE ( a, B * C ) 
The variables A* B and C will share the same 
storage unit during object program execution. 
If an arra\^ element is used in an EQUIVALENCE 
statement* the number of subscripts must be the 
same as the number of dimensions established by the 
avrav^ declarator* or it must be one* where the one 
subscript specifies the arra\^ element's number 
relative to the first element of the arrai^. 
Example: 

If the dimensional iity of an arrant Z* has been 
declared as Z<3*3) then in an EQUIVALENCE statement 
Z<6) and Z<3* 2) have the same meaning. 



FORTRAN-BO Reference Manual Page 40 

Additonal Considerations: 

1. The subscripts of array elements must be 
integer constants. 

2. An element of a multi-dimensional arraxi may be 
referred to by a single subscript* if desired. 

3. Variables may be assigned to a COMMON block 
through EQUIVALENCE statements. 

Example: 

C ONMON / X / A > B , C 

EQUIVALENCE <A, D) 
In this case* the variables A and D share the 
first storage unit in COMMON block X. 

4. EQUIVALENCE statements can increase the size of 
a block indicated by a COMMON statement by 
adding more elements to the end of the block. 
Example: 

_ IHEiNjsI0W Ri2t 2) 

COMMON /Z/W, X, Y 

EQUIVALENCE (Y, R<3>) 
The resulting COMMON block will have the 
following configuration: 
Variable Storaqe Unit 



M « R<1, 1) 





X « R<2, 1) 


1 


Y « R(l, 2) 


2 


R<2, 2) 


3 


The COMMON 


bloc k 


statement 


contains 



established by the COMMON 
3 storage units. It is 
expanded to 4 storage units by the EQUIVALENCE 
statement. 

COMMON block size may be increased only from 
the last element established by the COMMON 
statement forward; not from its first element 
backward. 

Note that EQUIVALENCE <X,R<3>> would be invalid 
in the example. The COMMON statement 
established U as the first element in the 
COMMON block and an attempt to make X and R<3) 
equivalent would be an attempt to make R<1) the 
first element. 



FORTRAN-BO Reference Manual Page 41 

5. It is invalid to EQUIVALENCE two elements of 

the same array or two elements belonging to the 

same or different COMMON blocks. 
Example: 

DIMENSION XTABLE (20), D(5) 
COMMON A, B(4)/ZAP/C, X 



EQUIVALENCE (XTABLE (6).A(7), 
X B<3>, XTABLEU5)), 

Y (B<3)*D<5)) 



This EQUIVALENCE statement has the following 
errors: 

1. It attempts to EQUIVALENCE two elements of the 
same array f XTABLE<6) and XTABLE<15). 

2. It attempts to EQUIVALENCE two elements of the 
same COMMON block, A(7) and B<3). 

3. Since A is not an array* A<7) is an illegal 
reference. 

4. Making B<3) equivalent to D(5) extends COMMON 
backwards from its defined starting point. 

DATA INITIALIZATION STATEMENT 



The DATA initialization statement is a 
non-executable statement which provides a means of 
compiling d^ata values into the object program and 
assigning these data to variables and array 
elements referenced by other statements. 
The statement is of the following form: 
DATA 1 i s t / u I > u2> . . . , un / > list. . . / u k , u k + i , . . . u k +n / 
where "list" represents a list of variable* array 
or array element names, and the ui are constants 
corresponding in number to the elements in the 
list. An exception to the one-for-one 
correspondence of list items to constants is that 
an array name < unsubscripted ) may appear in the 



FORTRAN-80 Reference Manual Page 42 

list* and as many constants as necessary to fill 
the array may appear in the corresponding position 
between slashes. Instead of ui, it is permissible 
to write k#ui in order to declare the same 
constant/ ui, k times in succession. k must be a 
positive integer. Dummy arguments may not appear 
in the list. 
Example: 



DIMENSION C<7) 

DATA A, B, CU), C<3)/14. 73, 
X -8. 1> 2*7. 5/ 

This implies that 

A=14. 73, B=-8. 1, CU>=7. 5, CC3)=7. 5 

The type of each constant ui must match the type of 
the corresponding item in the list, except that a 
Hollerith or Literal constant may be paired with an 
item of any type. 

When a Hollerith or Literal constant is used, the 
number of characters in its string should be no 
greater than four times the number of storage units 
required by the corresponding item, i.e., 1 
character for a Logical variable, up to 2 
characters for an Integer variable and 4 or fewer 
characters for a Real variable. 

If fewer Hollerith or Literal characters are 
specified, trailing blanks are added to fill the 
remainder of storage. 

Hexadecimal data are stored in a similar fashion. 
If fewer Hexadecimal characters are used, 
sufficient leading zeros are added to fill the 
remainder of the storage unit. 

The examples below i 1 lustrate many of the features 
of the DATA statement. 



FORTRAN-80 Reference Manual Page 43 

DIMENSION HARY (2) 
DATA HARY, B/ 4HTHIS, 4H OK. 
1 > 7. 86/ 



REAL LIT<2) 

LOGICAL LT, L.F 

DIMENSION H4C2, 2), PI3C3) 

DATA At, Bl> Kl, LT> LF> H4 ( 1, 1 >, H4<2, 1 ), 

1 H4U, 2>,H4<2, 2), PI3/5. 9, 2. 5E-4, 

2 64, . FALSE. , . TRUE. , 1. 75E-3, 

3 0. 85E~i, 2*75. 0, 1. , 2. , 3. 14159/, 

4 LIT<1)/'N0Q0'/ 



FORTRAN-80 Reference Manual Page 44 

SECTION 7 
FORTRAN CONTROL STATEMENTS 
FORTRAN control statements are executable statements which 
affect and guide the logical flow of a FORTRAN program. The 
statements in this category are as follows: 

1. GO TO statements: 

1. Unconditional 00 TO 

2. Computed GO TO 

3. Assigned GO TO 

2. ASSIGN 

3. IF statements: 

1. Arithmetic IF 

2. Logical IF 

4. DO 

5. CONTINUE 

6. STOP 

7. PAUSE 

8. CALL 

9. RETURN 

When statement labels of other statements are a part of a 
control statement/ such statement labels must be associated 
with executable statements within the same program unit in 
which the control statement appears. 
7. 1 GO TO STATEMENTS 

7. 1. 1 UNCONDnlON^C"G"o TO 

Unconditional GO TO statements are used' whenever 
control is to be transferred unconditionally to 
some other statement within the program unit. 



FORTRAN-80 Reference Manual Page 45 

The statement is of the following form: 

GO TO k 
where k is the statement label of an executable 
statement in the same program unit. 
Exampl e: 

00 TO 376 
310 A<7> = VI ~A<3> 



376 A(2> =VECT 
GO TO 310 
In these statements* statement 376 is ahead of 
statement 310 in the logical flow of the program of 
which they are a part. 
7. 1 . 2 COMPUTED 00 TO 

Computed 00 TO statements are of the form: 

00 TO < k 1* k2* . . . * n) » j 
where the ki are statement labels* and j is an 
integer variable* 1 < j C n. 

This statement causes transfer of control to the 
statement labeled kj. If j < 1 or j > n* control 

will be passed to the next statement following the 

Computed OOTO. 

Example: 



00 T0<7* 70* 700* 7000* 70000)* J 
310 J=5 

00 TO 325 
When J = 3i the computed GO TO transfers control to 
statement 700. Changing J to equal 5 changes the 
transfer to statement 70000. Making J = or J -•= 6 
would cause control to be transferred to statement 
310. 
7. 1. 3 ASSIGNED 00 TO 

Assigned 00 TO statements are of the following 



FORTRAN-80 Reference Manual Page 46 

form: 

GO TO j, Ckl, k2, ..... kn) 

or 

GOTO J 
where J is an integer variable name* and the ki arts 
statement labels of executable statements. This 
statement causes transfer of control to the 
statement whose label is equal to the current value 
of J. 
Qual if i cat ions 

1. The ASSIGN statement must logically precede an 
assigned GO TO. 

2. The ASSIGN statement must assign a value to J 
which is a statement label included in the list 
of k ' s , if the list is specified. 

Example: 

_^ ^ LABEL> (80, 90, 100) 
Only the statement labels SO, 90 or 100 may be 
assigned to LABEL. 
7. 2 ASSIGN STATEMENT 

This statement is of the following form: 

ASSIGN j TO i 
where j is a statement label of an executable 
statement and i is an integer variable. 
The statement is used in conjunction with each 
assigned GO TO statement that contains the integer 
variable i. When the assigned GO TO is executed, 
control will be transferred to the statement 
labeled j . 



ORTRAN-80 Reference Manual Page 47 

Exampl e: 

ASSIGN 100 TO LABEL 



ASSIGN 90 TO LABEL 
GO TO LABEL, (80,90,100) 
7.3 IF STATEMENT 

IF statements transfer control to one of a series 
of statements depending upon a condition. Two 
types of IF statements are provided: 
Arithmetic IF 
Logical IF 
7. 3. 1 ARITHMETIC IF 

The arithmetic IF statement is of the form: 

IF(e > ml, m2, m3 
where e is an arithmetic expression and ml, m2 and 
m3 av& statement labels. 

Evaluation of expression e determines one of three 
transfer possibilities: 
If e is: Transfer to: 

< ml 

= m2 

> m3 

Examples: 



Statement Expression Value Transfer to 

IF (A)3, 4, 5 15 5 

IF <N~1)50, 73, 9 O 73 

IF <AMTX<2, 1, 2) )7, 2, 1 -256 7 



7. 3. 2 LOGICAL IF 



The Logical IF statement is of the form: 

IF < u ) s 
where u is a Logical expression and s is any 
executable statement except a DO statement (see 
7.4) or another Logical IF statement. The Logical 



FORTRAN-SO Reference Manual Page 48 

expression u is evaluated as . TRUE. or . FALSE. 
Section 4 contains a discussion of Logical 
expressions. 
Control Conditions: 

If u is FALSE* the statement s is ignored and 
control goes to the next statement following the 
Logical IF statement. If* however* the expression 
is TRUE* then control goes to the statement s* and 
subsequent program control follows normal 
conditions. 

If s is a replacement statement (v ~ e* Section 5)* 
the variable and equality sign (=) must be on the 
same line* either immediately following IF(u) or on 
a separate continuation line with the line spaces 
following IF(u) left blank. See example 4 below. 
Examples: 



1. IF (I. GT. 20) GO TO 115 

2. IF<Q. AND. R) ASSIGN 10 TO J 

3. IF<Z) CALL DECL(A, B*C> 

4. IF<A. OR. B. LE. P1/2)I=J 

5. IF<A. OR. B. LE. PI/2) 
X I =sJ 

7. 4 DO STATEMENT 

The DO statement* as implemented in FORTRAN* 
provides a method for repetitively executing a 
series of statements. The statement takes of one 
of the two following forms: 

1) DO k i « mi*m2*m3 

or 

2 ) DO k i = rni* m2 

where k is a statement label* i is an integer or 

logical variable* and ml* m2 and m3 are integer 

constants or integer or logical variables. 

If m3 is 1* it may be omitted as in 2> above. 

The following conditions and restrictions govern 

the use of DO statements: 



FORTRAN-BO Reference Manual Page 49 

1. The DO and the first comma must appear on the 
initial line. 

2. The statement labeled k, called the terminal 
statement, must be an executable statement. 

3. The terminal statement must physically follow 
its associated DO* and the executable 
statements following the DO* up to and 
including the terminal statement* constitute 
the range of the DO statement. 

4. The terminal statement may not be an Arithmetic 
IF* GO TO* RETURN* STOP* PAUSE or another DO. 

5. If the terminal statement is a logical IF and 
its expression is . FALSE. * then the statements 
in the DO range ar& reiterated. 

If the expression is .TRUE.* the statement of 
the logical IF is executed and then the 
statements in the DO range are reiterated. The 
statement of the logical IF may not be a GO TO* 
Arithmetic IF* RETURN, STOP or PAUSE. 

6. The controlling integer variable* i* is called 
the index of the DO range. The index must be 
positive and may not be modified by any 
statement in the range. 

7. If ml* m2* ami m3 av& Integer*! va7"iables or 
constants* the DO loop will execute faster and 
be shorter* but the range is limited to 127 
iterations. For example* the loop overhead for 
a DO loop with a constant limit and an 
increment of 1 depends upon the type of the 
index variable as follows: 

Index Variable Overhead 

Type Microseconds Bytes 

INTEGER#2 35. 5 19 

INTEGER*! 24 14 

8. During the first execution of the statements in 
the DO range, i is equal to ml* the second 
execution* i ~ ml+m3* the third* i=ml-t"2*m3* 
etc. * until i is equal to the highest value in 
this sequence less than or equal to m2» and 
then the DO is said to be satisfied. The 
statements in the DO range will always be 
executed at least once, even if ml < m2. 

When the DO has been satisfied, control passes 
to the statement following the terminal 



FORTRAN-BO Reference Manual Page 50 

statement, otherwise control transfers back to 
the first executable statement following the DO 
statement. 
EI x ample: 

The following example computes 
100 

Sigma Ai where a is a one-dimensional array 
i = l 



,00 DIMENSION A(100) 



SUM = A(l) 
DO 31 I ~ 2, 100 
31 SUM =SUM + A<I) 

END 
9. The range of a DO statement may be extended to 
include all statements which may logically be 
executed between the DO and its terminal 
statement. Thus* parts of the DO range may be 
situated such that they ar& not physically 
between the DO statement and its terminal 
statement but ar& executed logically in the DO 
range. This is called the extended range. 
Example: 

"DIMENSION A<500), B<500> 



DO 50 I = 10, 327, 3 



IF <V7 -C*C) 20, .15, 31 



30 



50 A (I) = BCD + C 



20 C ™ C - . 05 
GO TO 50 

31 C=C+ . 0125 
GO TO 30 



ORTRAN-80 Reference Manual Page 51 

10. It is invalid to transfer control into the 
range of a DO statement not itself in the range 
or extended range of the same DO statement. 

11. Within the range of a DO statement* there may 
he other DO statements* in which case the DO's 
must be nested. That is* if the range of one 
DO contains another DO* then the range of the 
inner DO must be entirely included in the range 
of the outer DO. 

The terminal statement of the inner DO may also 
be the terminal statement of the outer DO. 
For example* given a two dimensional array A of 
15 rows and 15 columns/ and a 15 element 
one-dimensional array B> the following 
statements compute the 15 elements of avra\ii C 
to the formula: 
15 
Ck -Sigma AkjBm* k = 1/2?...* 15 
J~i 

DIMENSION A U 5* 15) * B<15>* CCL5) 



DO 80 K =1, 15 
C(K) « 0. O 
DO SO J«l, 15 
BO C<K) « C(K) +A<K,J) * B<J> 



7. 5 CONTINUE STATEMENT 



CONTINUE is classified as an executable statement. 
However* its execution does nothing. The form of 
the CONTINUE statement is as follows: 

CONTINUE 
CONTINUE is frequently used as the terminal 
statement in a DO statement range when the 
statement which would normally be the terminal 
statement is one of those which ar& not allowed or 
is only executed conditionally. 



FORTRAN -80 Reference Manual Pa&® 52 

Ex amp 1 e: 



IF <C2) 5,6,6 
CONTINUE 



C2 ~ C2 +. 005 
5 CONTINUE 
7. 6 STOP STATEMENT 

A STOP statement has one of the following forms: 
STOP 

o r 

STOP c 
where c is any string of one to six characters. 
When STOP is encountered during execution of the 
object program* the characters c (if present) are 
displayed on the operator control console and 
execution of the program terminates. 

The STOP statement* therefore* constitutes the 
logical tand of the program, 
7. 7 PAUSE STATEMENT 

A PAUSE statement has one of the following forms: 

PAUSE 

or 

PAUSE c 
where c is any string of up to six characters. 
When PAUSE is encountered during execution of the 
object program* the charactei^s c (if present) are 
displayed on the operator control console and 
execution of the program ceases. 

The decision to continue execution of the program 
is not under control of the program. if execution 



FORTRAN-80 Reference Manual Page 53 

is resumed through intervention of an operator 
without otherwise changing the state of the 
processor* the normal execution sequence* following 
PAUSE* is continued. 

Execution may be terminated by typing a "T" at the 
operator console. Typing any other character will 
cause execution to resume. 

7. 8 CALL STATEMENT 

CALL statements control transfers into SUBROUTINE 
subprograms and provide parameters for use by the 
subprograms. The general forms and detailed 
discussion of CALL statements appear in Section 9* 
FUNCTIONS AND SUBPROGRAMS. 
7. 9 RETURN STATEMENT 



The form* use and interpretation of the RETURN 
statement is described in Section 9. 
7. 10 END STATEMENT 

The END statement must physically be the last 
statement of any FORTRAN program. It has the 
following form: 

end" 

The END statement is an executable statement and 
may have a statement label. It causes a transfer 
of control to be made to the system exit routine 
$EX* which returns control to the operating system. 



FORTRAN-BO Reference Manual Page 54 

SECTION 8 
INPUT / OUTPUT 
FORTRAN provides a series of statements which define the 
control and conditions of data transmission between computer 
memory and external data handling or mass storage devices 
such as magnetic tape* disk* line printer* punched card 
processors* keyboard printers* etc. 
These statements ar& grouped as follows: 

1. Formatted READ and WRITE statements which cause 

formatted information to be transmitted between the 
computer and I/O devices. 

2. Unformatted READ and WRITE statements which 



transmit unformatted binary data in a form similar 
to internal storage. 
3. Auxiliary I/O statements for positioning and 



demarcation of files. 
4. ENCODE and DECODE statements for transferring data 



between memory locations. 

FORMAT statements used in conjunction with 



formatted record transmission to provide data 
conversion and editing information between internal 
data representation and external character string 
forms, 
8. 1 FORMATTED READ/WRITE STATEMENTS 



8. 1. 1 FORMATTED READ STATEMENTS 

A formatted READ statement is used to transfer 
information from an input device to the computer. 
Two forms of the statement ar& available* as 
f ol lows: 

R E AD ( u , f * ER R =L 1 * END«L2 ) k 

or 

READ (u, f * ERR^Ll* END-L2) 
where: 
u - specifies a Physical and Logical Unit Number 

and may be either an unsigned integer or an 



FORTRAN-80 Reference Manual Page 55 

integer variable in the range 1 through 255. 
If an Integer variable is used* an Integer 
value must be assigned to it prior to execution 
of the READ statement. 

Units 1* 3* 4* and 5 are preassigned to the 
console Teletypewriter. Unit 2 is preassigned 
to the Line Printer (if one exists). Units 
6-10 ar& preassigned to Disk Files (see User's 
Manual* Section 3). These units* as well as 
units 11-255* may be re-assigned by the user 
(see Appendix B). 
f - is the statement label of the FORMAT statement 
describing the type of data conversion to be 
used within the input transmission or it may be 
an arrai^ name* in which case the formatting 
information may be input to the program at the 
execution time. (See Section 8. 7. 10) 
LI— is the FORTRAN label on the statement to which 
the I/O processor will transfer control if an 
I/O error is encountered. 
L2- is the FORTRAN label on the statement to which 
the I/O processor will transfer control if an 
End~-of~Fi le is encountered. 
If - is a list of variable names* separated by com- 
mas* specifying the input data. 
READ (u*f)k is used to input a number of items* 
corresponding to the names in the list k* from the 
file on logical unit u* and using the FORMAT 
statement f to specify the external representation 
of these items (see FORMAT statements* 8.7). The 
ERR- and END™ clauses are optional. If not- 
specified* I/O errors and End-of-Files cause fatal 
runtime errors. 

The following notes further define the function of 
the READ (u*f)k statement: 

1. Each time execution of the READ statement 
begins* a new record from the input file is 
read. 

2. The number of records to be input by a single 
READ statement is determined by the list* k* 
and format specifications. 

3. The list k specifies the number of items to be 
read from the input file and the locations into 
which they are to be stored. 



FORTRAN-80 Reference Manual Page 56 

4. Any number of items may appear in a single list 
and the items may be of different data types. 

5. If there are more quantities in an input record 
than there ar^s items in the list* only the 
number of quantities equal to the number of 
items in the list are transmitted. Remaining 
quantities avB ignored. 

6. Exact specifications for the list k are 
described in 8. 6. 

Examples: 

1. Assume that four data entries are punched in a 
card* with three blank columns separating each, 
and that the data have field widths of 3* 4* 2 
and 5 characters respectively starting in 
column 1 of the card. The statements 

READ (5* 20 )K, L* M, N 
20 F0RMAT(I3* 3X* 14* 3X* 12, 3X* 15) 
will read the card (assuming the Logical Unit 
Number 5 has been assigned to the card reader) 
and assign the input data to the variables K, 
L* M and N. The FORMAT statement could also be 

20 FORMAT (13* 17* 15* 18) 
See 8.7 for complete description of FORMAT 
statements. 

2. Input the quantities of an arrays (ARRY): 

READ (6* 21) ARRY 
Only the name of the arr&i^ needs to appear in 
the list (see 8.6). All elements of the array 
ARRY will be r^ad and stored using the 
appropriate formatting specified by the FORMAT 
statement labeled 21. 
READ(u*k) may be used in conjunction with a FORMAT 
statement to read H-type alphanumeric data into an 
existing H-type field (see Hollerith Conversions* 
8. 7. 3). " 

For example* the statements 
READd* 25) 



25 FORMAT (10HABCDEFQHIJ) 



FORTRAN-80 Reference Manual Page 57 

cause the next 10 characters of the file on input 
device I to be read and replace the characters 
ABCDEFGHIJ in the FORMAT statement. 

8. 1.2 FORMATTED WRITE STATEMENTS 

A formatted WRITE statement is used to transfer 
information from the computer to an output device. 
Two forms of the statement are available* as 
follows: 

WR I TE ( u , f , ERR=L 1 » END=L2 > k 

or 

WR I TE < u , f > ERR=L.l > END=L2 ) 
where: 

u - specifies a Logical Unit Number, 
f - is the statement label of the FORMAT statement 
describing the type of data conversion to be 
used with the output transmission. 
Li- specifies an I/O error br-anch. 
L2— specifies an EOF branch. 

k -• is a list of variable names separated by com- 
mas., specifying the output data. 
WRITE <u*f)k is used to output the data specified 
in the list k to a file on logical unit u using the 
FORMAT statement f to specify the external 
representation of the data (see FORMAT statements* 
8.7). The following notes further define the 
function of the WRITE statement: 

1. Several records may be output with a single 
WRITE statement* with the number determined by 
the list and FORMAT specifications. 

2. Successive data are output until the data 
specified in the list are exhausted. 

3. If output is to a device which specifies fixed 
length records and the data specified in the 
list do not fill the record* the remainder of 
the record is filled with blanks. 



FORTRAN-80 Reference Manual Page 58 

Example: 

WRITE (2, 10)Ai B, C, D 
The data assigned to the variables A* B* C and D 
are output to Logical Unit Number 2* formatted 
according to the FORMAT statement labeled 10. 
WRITE(u>f) may be used to write alphanumeric 
information when the characters to be written are 
specified within the FORMAT statement. In this 
case a variable list is not required. 
For example* to write the characters 'H CONVERSION-' 
on unit 1* 

WRITEd, 26) 



26 FORMAT (12HH CONVERSION) 
8.2 UNFORMATTED READ/WRITE 



Unformatted I/O (i.e. without data conversion) is 
accomplished using the statements: 

READ<u* ERR=L1» END=L2) k 

WR I TE < u , ERR--L 1 , END=L2 ) k 

where: 

u •- specifies a Logical Unit Number. 

LI— specifies an I/O error branch. 

L2- specifies an EOF branch. 

k - is a list of variable names* separated by 
commas* specifying the I/O data. 

The following notes define the functions of 
unformatted I/O statements. 

1. Unformatted READ/WRITE statements perform 
memory-image transmission of data with no data 
conversion or editing. 

2. The amount of data transmitted corresponds to 
the number of variables in the list k. 



F0RTRAN--80 Reference Manual Page 59 

3. The total length of the list of variable names 
in an unformatted READ must not be longer than 
the record length. If the logical recot'd 
length and the length of the list are the same* 
the entire record is read. If the length of 
the list is shorter than the logical record 
length the unread items in the record are 
skipped. 

4. The WRITE<a)k statement writes one logical 
record. 

5. A logical record may extend across more than 
one physical record. 

8. 3 DISK FILE I/O 



8. 3. 1 



A READ or WRITE to a di 
automatically OPENs the fi 
remains open until closed by 
(see Section 8.4) or 
termination. 

NOTE 
Exercise caution when 
output to disk files. If 
an existing file* the exi 
deleted and replaced with 
same name. 
RANDOM DISK I/O 



sk file <LUN 6-10) 

le for I/O. The file 

an ENDFILE command 

until normal program 



doing sequential 
output is done to 

sting file will be 
a new file of the 



SEE ALSO SECTION 3 OF YOUR MICROSOFT FORTRAN USER'S 

MANUAL. 

Some versions of FORTRAN-SO 

disk I/O. For random dis 

number is specified by using 

the READ or WRITE statement. 

I « 10 

WRITE (6, 20, REC=I, ERR^SO) X, Y, 



also provide random 
k access* the record 
the REC-n option in 

For example: 



This program segment writes record 10 on LUN 6. If 
a previous record 10 exists., it is written over. 
If no record 10 exists, the file is extended to 



FORTRAN-80 Reference Manual Page 60 

create one. Any attempt to read a non-existent 
record results in an I/O error. 

In random access files* the record length varies 
with different versions of FORTRAN. See Section 3 
of your Microsoft FORTRAN User's Manual. It is 
recommended that any file you wish to read randomly 
be created via FORTRAN (or Microsoft BASIC) random 
access statements. Files created this way (using 
either binary or formatted WRITE statements) will 
zero-fill each record to the proper length if the 
data does not fill the record. 

Any disk file that is OPENed by a READ or WRITE 
statement is assigned a default filename that is 
specific to the operating system. See also Section 
3 of the FORTRAN User's Manual. 

8. 3. 2 OPEN SUBROUTINE 



Alternatively* a file may be 0PEN&6 using the OPEN 
subroutine. LUNs 1—5 may also be assigned to disk 
files with OPEN. The OPEN subroutine allows the 
program to specify a filename and device to be 
associated with a LUN. 

An OPEN of a non-existent file creates a null file 
of the appropriate name. An OPEN of an existing 
file followed by sequential output deletes the 
existing file. An OPEN of an existing file 
followed by an input allows access to the current 
contents of the file. 

The form of an OPEN call varies under different 
operating systems. See your Microsoft FORTRAN 
User's Manual* Section 3. 
8.4 AUXILIARY I/O STATEMENTS 

Three auxiliary I/O statements are provided: 

BACKSPACE u 

REWIND u 

ENDFILE u 
The actions of all three statements depend on the 
LUN with which they are used (see Appendix B). 
When the LUN is for a terminal or line printer* the 
three statements ans defined as no-ops. 
When the LUN is for a disk drive* the ENDFILE and 
REWIND commands allow further program control of 
disk files. ENDFILE u closes the file associated 
with LUN u. REWIND u closes the file associated 



FORTRAN-80 Reference Manual 

with LUN u* then opens it again. 

implemented at this time* and 

error if used. 
8. 5 ENCODE/DECODE 



Page 6.1 

BACKSPACE is not 

therefore causes an 



ENCODE 
ace ord 
sec tio 
from 
change 
format 



where; 



DECODE 
causes 
ENCODE 
conver 



and DECODE statemen 
ing to format speci 
n of memory to another. 
ASCII format to the spec 
s data of the specified 
The two statements ar 
ENCODE ( a, f) k 
DECODE (a*f) k 



ts transfer data* 
fi cations.. from one 
DECODE changes data 
ified format. ENCODE 
format into ASCII 
e of the form: 



a i.s an arrays name 

f is FORMAT statement number 

k is an I/O List 

is analogous to a READ 

conversion from ASCI 

is analogous to a WRITE 

sion from internal forma 



statement* since it 
I to internal format, 
statement* causing 
ts to ASCII. 



FORTRAN-80 Reference Manual Page 62 

NOTE 
Care should be taken that the array A is 
always large enough to contain all of the 
data being processed. There is no check 



for overflow. An ENCODE operation which 



overflows the array will probably wipe out 
important data following the array. A 

DECODE operation which overflows will 
attempt to process the data following the 
array. 
8.6 INPUT/OUTPUT LIST SPECIFICATIONS 

Most forms of READ/WRITE statements may contain an 
ordered list of data names which identify the data 
to be transmitted. The order in which the list 
items appear must be the same as that in which the 
corresponding data exists (Input)/ or will exist 
(Output) in the external I/O medium. 
Lists have the following form: 

ml> m2> . . . > mn 
where the mi are list items separated by commas* as 
shown. 
8. 6. 1 LIST ITEM TYPES 



A list item may be a single datum identifier or a 

multiple data identifier. 

1. A single datum identifier item is the name of a 

variable or array element. 

Examples: 



CC26, l)> R,K, D 
B, 1(10.. iO)*S, F<1, 25) 

NOTE 
Sublists are not implemented. 



0RTRAN--80 Reference Manual Page 63 

2. Multiple data identifier items are in two 
forms: 

a. An array name appearing in a list without 
subscript(s) is considered equivalent to the 
listing of each successive element of the 
arra^. 

Example: 

If B is a two dimensional arvaq, the list item 
B is equivalent to: B < 1, 1 ) , B<2> 1 ), B (3/ 1 ). . . . > 
B<1,2>, B<2, 2>. . . ,B< J, k). 
where j and k are the subscript limits of B. 

b. DO-implied items are lists of one or more 
single datum identifiers or other DO-implied 
items followed by a comma character and an 
expression of the form: 

i = ml> m2, m3 or i -* ml* m2 
and enclosed in parentheses. 

The elements i,ml,m2, m3 have the same meaning 
as defined for the DO statement. The DO 
implication applies to all list items enclosed 
in parentheses with the implication. 
Examp les : 

DO~-Implied Lists Equivalent Lists 

< X < I > , 1 = 1 , 4 > X(i),X(2),X(3)iX(4) 

CQ<J),R{J>, J=l,2) Q<l>,R(i>,G<2>,R{2> 

<G<K)»K=1, 7, 3) G(l), G<4)>G<7> 

<<A<I, J), 1=3, 5)* J=l, 9, 4) A<3, 1>, A<4, 1), ACS, 1> 

A (3, 5), A (4, 5), A (5/ 5) 
A<3,9>, A<4, 9), A<5,9) 
<R<M),M=1, 2), I, ZAP (3) R<1>, RC2), I, ZAP (3) 
<R<3),T<I>, 1 = 1,3) R(3),TU),R<3>,TC2), 

R(3>, T(3> 
Thus, the elements of a matrix, for example, 
may be transmitted in an order different from 
the order in which they appear in storage. The 
arra^ A<3, 3) occupies storage in the order 
AC1, 1), A<2, 1), A<3, 1), A<1,2>, A<2, 2), A (3, 2), 
A<1,3)»A(2, 3), A (3, 3). By specifying the 
transmission of the array with the DO-implied 
list item < < A< I* J), J=i, 3), 1 = 1, 3>, the order of 
transmission is: 



FORTRAN-80 Reference Manual Page 64 

A ( 1 , 1 ) , A ( 1 , 2 ) , A ( 1 , 3 ) , A (2* 1 ) , A ( 2, 2 ) , 
A(2, 3), A<3, 1), A<3> 2), A<3» 3) 

8.6.2 SPECIAL NOTES ON LIST SPECIFICATIONS 

1. The ordering of a list is from left to right 
with repetition of items enclosed in 
parentheses (other than as subscripts) when 
accompanied by controlling DO-implied index 
parameters. 

2. Arrays sire transmitted by the appearance of the 
avra^ name < unsubscripted ) in an input/output 
list. 

3. Constants may appear in an input/output list 
only as subscripts or as indexing parameters. 

4. For input lists, the DQ-implying elements i, 
ml, m2 and m3 may not appear within the 
parentheses as list items. 

Examples: 



1. READ (1.20) < I* J, A( r ), 1 = 1, J, 2) is not allowed 

2. READ( 1, 20) I, J, <A( I ), 1 = 1, J, 2) is allowed 

3. WRITEM, 20X1, J, AM), 1 = 1, J,2) is allowed 
Consider the following examples: 

DIMENSION A<25) 

AM) = 2. 1 
A<3) = 2. 2 
AC5) = 2. 3 

J = 5 

WRITE (1,20) J, M, AM), 1 = 1, J, 2) 



the output of this WRITE statement is 

5 , 1, «=.. 1, 3, «l. 2, & > 2. 3 
1. Any number of items may appear in a single 
1 ist. 



FORTRAN-80 Reference Manual Page 65 

2. In a formatted transmission <READ(u>f)k* 
WRITE<u.. f ) k ) each item must have the correct 
type as specified by a FORMAT statement. 

S. 7 FORMAT STATEMENTS 



FORMAT statements are non-executable^ generative 

statements used in conjunction with formatted READ 

and WRITE statements. They specify conversion 

methods and data editing information as the data is 

transmitted between computer storage and external 

media representation. 

FORMAT statements require statement labels for 

reference (f) in the READ<u,f)k or WRITE(u*f)k 

statements. 

The general form of a FORMAT statement is as 

f ol lows: 

m FORMAT (si, s2, . . . , sn/sl ', s2' f . . . , sn '/. . . ) 
where m is the statement label and each si is a 
field descriptor. The word FORMAT and the 
parentheses must be present as shown. The slash 
</) and comma ( f ) characters are field separators 
and are described in a separate subparagraph. The 
field is defined as that part of an external record 
occupied by one transmitted item. 
S. 7. 1 FIELD DESCRIPTORS 

Field descriptors describe the sizes of data fields 
and specify the type of conversion to be exercised 
upon each transmitted datum. The FORMAT field 
descriptors may have any of the following forms: 
Descriptor Classification 

rFw. d 

rGw. d 

rEw. d Numeric Conversion 

rDw. d 

rlw 

rLw Logical Conversion 

rAw 

nHhlh2. . . hn Hollerith Conversion 

'1112. . . In' 

nX Spacing Specification 

mP Scaling Factor 



F0RTRANH30 Reference Manual P^ge 66 

where: 

1. w and n are positive integer constants defining 
the field width (including digits* decimal 
points* algebraic signs) in the external data 
representation. 

2. d is an integer specifying the number of 
fractional digits appearing in the external 
data representation. 

3. The characters F* G* E* D* I* A and L indicate 
the type of conversion to be applied to the 
items in an input/output list. 

4. r is an optional* non-zero integer indicating 
that the descriptor will be repeated r times. 

5. The hi and li are characters from the FORTRAN 
character set. 

6. m is an integer constant (positive* negative* 
or zero) indicating scaling. 

8.7.2 NUMERIC CONVERSIONS 

Input operations with any of the numeric 
conversions will allow the data to be represented 
in a "Free Format"* i.e.* commas may be used to 
separate the fields in the external representation. 
F-type conversion 

Form: Fw. d 

Real or Double Precision type data are processed 

using this conversion. w characters are processed 

of which d are considered fractional. 

F-output 

Values are converted and output as minus sign (if 

negative)* followed by the integer portion of the 

number* a decimal point and d digits of the 

fractional portion of the number. If a value does 

not fill the field* it is right justified in the 

field and enough preceding blanks to fill the field 

are inserted. If a value requires more field 

positions than allowed by w* the first w— 1 digits 

of the value are output* preceded by an asterisk. 



ORTRAN-SO Reference Manual 
F~-Output Examples: 
FORMAT Internal 

Descriptor Value 



368. 42 
-4786. 361 

S . / E '"■■«. 
4739. 76 
-~!5. 6 



Page 67 



Fit). 4 


F7. 


1 


F8. 


4 


F6. 


4 


F7. 


3 


•H- 


Not 


above. 


F~ 


Enpu 



Output 
(b-blank ) 

bb368. 4200 
-4786. 4 
bbO. 0870 
•*. 7600 
b-5. 600 



e the loss of leading digits in the 4th line 



(See the description under E-Input below. ) 
E— type Conversion 



Form: Eu.». 
Real or Do 
using thi 
of which d 
E~-Output 
Values are 
output as: 

1. a minu 

2. a zero 

3. d dec i 

4. the le 

5. the si 

6. two ex 
in that or 
justified 
fill the f 
should sat 

ui > d 
Otherwise 
E-Output e 



d 

uble Precision type data are processed 
s conversion. w characters are processed 
are considered fractional. 

converted* rounded to d digits* and 



s si 
and 
mal 
tter 
gn o 
pone 
der . 
in 
ield 
isf y 
•+• 7 
si gn 
xamp 



gn (if negative >* 

a decimal point* 
digits* 

E* 
f the exponent (minus or blank)., 
nt digits* 

The values as described are right 

the field w with preceding blanks to 

if necessary. The field width w 

the relationship: 



ificant characters may be lost, 
les follow: 



Some 



FORTRAN-80 Reference Manual Page 68 

FORMAT Internal Output 

Descriptor Value (b^blank) 

El 2. 5 76. 573 bb. 76573EbQ2 

El 4. 7 -32672. 354 ~b. 3267235Eb05 

El 3. 4 ~-0. 0012321 bb~b. 1232E-02 

EB. 2 76321.73 b. 76Eb05 

E~Input 

Data values which are to be processed under E* F* 

or Q conversion can be a relatively loose format in 

the external input medium. The format is identical 

for either conversion and is as follows: 

1. Leading spaces (ignored) 

2. A + or - sign (an unsigned input is assumed to 
be positive) 

3. A string of digits 

4. A decimal point 

5. A second string of digits 

6. The character E 

7. A + or - sign 

S. A decimal exponent 

Each item in the list above is optional; but the 

following conditions must be observed: 

1. If FORMAT items 3 and 5 (above) av& present/ 
then 4 is required. 

2. If FORMAT item 8 is present* then 6 or 7 or 
both av& required. 

3. All non-leading spaces ar& considered zeros. 
Input data can be any number of digits in length* 
and correct magnitudes will be developed* but 
precision will be maintained only to the extent 
specified in Section 3 for Real data. 



FORTRAN-80 Reference Manual Page 69 

E~ and F- and G- Input Examples: 
FORMAT Input Internal 

Descriptor (b=blank) Value 

E10. 3 +0. 237564-4 +2375. 60 

E10. 3 bbbbbl7631 +17.631 

<38. 3 b 162891. I +1628.911 

F12. 4 bbbb~6321132 -632.1132 

Note in the above examples that if no decimal point 

is given among the input characters* the d in the 

FORMAT specification establishes the decimal point 

in conjunction with an exponent* if given. If a 

decimal point is included in the input characters* 

the d specification is ignored. 

The letters Ei* F, and Q are interchangeable in the 

input format specifications. The end result is the 

same. 

D— Type Conversions 



D-Input and D-Output are identical to E-Input and 
E~-Output except the exponent may be specified with 
a "D" instead of an "E. " 
O-Type Conversions 

Form: Qw. d 

Real or Double Precision type data are processed 

using this conversion. w characters are processed 

of which d ar& considered significant. 

Q- 1 n p u t : 

<See the description under E-~Input> 

Q -Output: 

The method of output conversion is a function of 

the magnitude of the number being output. Let n be 

the magnitude of the number. The following table 

shows how the number will be output: 



FORTRAN-80 Reference Manual Page 70 

Magnitude Equivalent Conversion 



. 1 <= n < 1 F(w-4). d*4X 

1 <« n < 10 F(w~4). <d~l)*4X 



d~2 




d- 


1 






10 <« 


n < 


10 




F(w~4). 


1,4X 


d-1 




d 








10 O 


n < 


10 




F < w~4 ) . 


0, 4X 


Otherwise 








Ew. d 




I -Conversions 











Form: Iw 

Only Integer data may be converted by this form of 

conversion. w specifies field width. 

I—Output: 

Values are converted to Integer constants. 

Negative values are preceded by a minus sign. If 

the value does not fill the field* it is right 

justified in the field and enough preceding blanks 

to fill the field are inserted. If the value 

exceeds the field width* only the least significant 

w--l characters ar& output preceded by an asterisk. 

Examples: 



FORMAT 




Internal 


Output 


Descrip 


tor 


Value 


(b=blank ) 


16 




+281 


bbb281 


16 




""i&ucU •* 


-2326 1 


13 




126 


126 


14 




— .T*»A 


-226 



I - 1 n p u t : 

A field of w characters is input and converted to 

internal integer format. A minus sign may precede 

the integer digits. If a sign is not present* the 

value is considered positive. 

Integer values in the range -32768 to 32767 are 

accepted. Non-leading spaces are treated as zeros. 



FORTRAN-GO Reference Manual 
Examples: 



Page 71 



8. 7. 3 



Format 


Input 


Descriptor 


< b=blank ) 


14 


bl24 


14 


-124 


17 


bb 6732b 


14 


lb2b 


HOLLERITH 


CONVERSIONS 


A~Type Conversion 



Internal 
Value 

124 
-124 
67320 
1020 



The form of 

Aw 
This descr 
characters 
specified li 
The maximum 
be transmi 
representati 
of storage 
(i.e.* 1 cha 
for Integer 
8 characters 
A~-Output: 
If w is grea 
storage uni 
external out 
followed by 
representati 
output fie 
characters f 
Examples'. 



the A conversion is as follows: 



iptor causes u 
to be read into 
st item. 

number of actual c 

tted between in 

ons using Aw is fo 

units in the co 

racter for logical 

items/ 4 characte 

for Double Precis 

ter than 4n (where 
ts required by 
put field will con 
the 4n charact 
on. If w is less 
Id will consist 
rom the internal r 



Format 




Internal 


Type 


De script 


or 






Al 




Al 


Integer 


A2 




AB 


Integer 


A3 




ABCD 


Real 


A4 




ABCD 


Real 


A7 




ABCD 


Real 


A- Input: 









nmodified Hollerith 
or written from a 

haracters which may 
ternal and external 
ur times the number 
rresponding list item 
items* 2 characters 
rs for Real items and 
ion items). 

n is the number of 
the list item)/ the 
sist of w~4n blanks 
ers from the internal 
than 4n> the external 

of the leftmost w 
ep reservation. 



Output 
(b~blanks ) 

A 

AB 

ABC 

ABCD 

bbbABCD 



If w is greater than 4n (where n is the number of 



FORTRAN-80 Reference Manual Page 72 

storage units required by the corresponding list 
item)* the rightmost 4n characters are taken from 
the external input field. If w is less than 4n* 
the w characters appear left justified with w~4n 
trailing blanks in the internal representation. 
Examples: 



Format 


Input 


Type 


Descriptor 


Characters 




Al 


A 


Integer 


A3 


ABC 


Integer 


A4 


ABCD 


Integer 


Al 


A 


Real 


A7 


ABCDEFG 


Real 


H-Conversion 







Internal 
(b=blank ) 

Ab 

AB 

AB 

Abbb 

DEFQ 



The forms of H conversion are as follows: 
nHhlh2. . . hn 

'hlh2. . . hn' 
These descriptors process Hollerith character 
strings between the descriptor and the external 
field* where each hi represents any character from 
the ASCII character set. 

NOTE 
Special consideration is required if an 
apostrophe <') is to be used within the 
literal string in the second form. An 
apostrophe character within the string is 
represented by two successive apostrophes. 
See the examples below. 
H-Qutput: 

The n characters hi* are placed in the external 
field. In the nHhih2. . . hn form the number of 
characters in the string must be exactly as 
specified by n. Otherwise* characters from other 
descriptors will be taken as part of the string. 
In both forms* blanks are counted as characters. 



FORTRAN-BO Reference Manual 
Examples: 



Page 73 



Format 




Descriptor 


> 


1HA or 


'A' 


SHbSTRINGb or 


'bSTRINGb' 


UHX<2, 3>~12. or 


'XC2, 3> = 12. 0' 


llHIbSHOULDN'T or 


'IbSHOULDN' 'T' 


H~- Input 




The n characters c 


>f the string h 



Output 
< b=blank ) 



bSTRINGb 
X<2, 3>~12. O 
lb SHOULDN'T 



are replaced by 



the next n characters from the input record. 

results in a new string of characters in the 

descriptor. 

FORMAT Input Resultant 

Descriptor <b=blank) Descriptor 



This 
field 



8. 



4 



4H1234 or '1234' ABCD 4HABCD or 

7HbbFALSE or 'bbFALSE' bFALSEb 7HbFALSEb 

6Hbbbbbb or 'bbbbbb' MATRIX 6HMATR1X 
.OGICAL CONVERSIONS 



'ABCD' 

or 'bFALSEb 
or 'MATRIX' 



The form of the logical conversion is as follows: 

Lw 
L-Output: 

If the value of an item in an output list 
corresponding to this descriptor is d an F will be 
output; otherwise/ a T will be output. If w is 
greater than 1, w-1 leading blanks precede the 
letters. 
Examples: 



FORMAT 




Internal 


Output 


Descrip 


tor 


Value 


( b~blank ) 


LI 




■=0 


F 


LI 




00 


T 


L5 




00 


bbbbT 


L7 




«o 


bbbbbbF 



L~Input 

The external representation occupies w 
It consists of optional blanks followed 
"F" t followed by optional characters. 



positions, 
by a "T" or 



FORTRAN-SO Reference Manual 
8. 7. 5 X DESCRIPTOR 



Page 74 



The form of X conversion is as follows: 

nX 
This descriptor causes no conversion to occur* nor 
does it correspond to an item in an input/output 
list. When used for output/ it causes n blanks to 
be inserted in the output record. Under input 
circumstances., this descriptor causes the next n 
characters of the input record to be skipped. 
Output Examples: 



FORMAT Statement 



Output 
(b^blanks) 



3 FORMAT ( 1HA, 4X, 2HBC ) 
7 FORMAT (3X» 4HABCD, IX) 
Input Examples: 

FORMAT Statement 



AbbbbBC 
bbbABCDb 



Input String Resultant Input 



S. 7. & 



10 FORMAT (F4. 1, 3X,F3. 0) 12. 5ABC120 12.5,120 
5 FORMAT (7X, 13) 1234567012 012 
P DESCRIPTOR 



The P descriptor is used to specify a scaling 
factor for real conversions <F, E> D> G). The form 
is nP where n is an integer constant (positive, 
negative, or zero). 

The scaling factor is automatically set to zero at 
the beginning of each formatted I/O call (each READ 
or WRITE statement). If a P descriptor is 
encountered while scanning a FORMAT, the scale 
factor is changed to n. The scale factor remains 
changed until another P descriptor is encountered 
or the I/O terminates. 
Effects of Scale Factor on Input: 

During E, F, or O input the scale factor takes 
effect only if no exponent is present in the 
external representation. In that case, the 
internal value will be a factor of 10**n less than 
the external value (the number will be divided by 
iO-R-B-n before being stored). 



FORTRAN-80 Reference Manual Page 75 

Effect, of Scale Factor on Output: 

E~-Output, D-Output: 

The coefficient is shifted left n places relative 
to the decimal point> and the exponent is reduced 
by n (the value remains the same). 
F—Output: 

The external value will be 10#-*n times the internal 
value. 
O-Output: 

The scale factor is ignored if the internal value 
is small enough to be output using F conversion. 
Otherwise, the effect is the same as for E output. 
8. 7. 7 SPECIAL CONTROL FEATURES OF FORMAT STATEMENTS 

8.7.7.1 Repeat Specifications 

1. The E» Fi D> G, I* L and A field descriptors 
may be indicated as repetitive descriptors by 
using a repeat count r in the form rEui. d, 
rFw. d> rQm. d» rlw, rLw» rAw. The following 
pairs of FORMAT statements are equivalent: 

66 FORMAT <3F8. 3, F9. 2) 
C IS EQUIVALENT TO: 

66 FORMAT <F8. 3, F8. 3, F8. 3, F9. 2> 

14 FORMAT <2I3, 2A5, 2E10. 5) 
C IS EQUIVALENT TO: 

14 FORMAT <I3, 13, A5, A5, ElO. 5, E10. 5) 

2. Repetition of a group of field descriptors is 
accomplished by enclosing the group in 
parentheses preceded by a repeat count. 
Absence of a repeat count indicates a count of 
one. Up to two levels of parentheses, 
including the parentheses required by the 
FORMAT statement, are permitted. 

Note the following equivalent statements: 



FORTRAN-80 Reference Manual Page 76 

22 FORMAT ( 13, 4<F6. 1, 2X ) ) 
C IS EQUIVALENT TO: 

22 FORMAT ( 13, F6. 1, 2X, F6. 1, 2X, F6. 1, 2X, 
1 F6. 1 , 2X ) 
3. Repetition of FORMAT descriptors is also 
initiated when all descriptors in the FORMAT 
statement have been used but there are still 
items in the input/output list that have not 
been processed. When this occurs the FORMAT 
descriptors are re-used starting at the first 
opening parenthesis in the FORMAT statement. A 
repeat count preceding the parenthesized 
descriptor < s) to be re-used is also active in 
the re-use. This type of repetitive use of 
FORMAT descriptors terminates processing of the 
current record and initiates the processing of 
a new record each time the re-use begins. 
Record demarcation under these circumstances is 
the same as in the paragraph S. 7. 7. 2 below. 
Input Example: 

DIMENSION A(IOO) 

READ <3, 13) A 



13 FORMAT (5F7. 3) 
In this example, the first 5 quantities from each 
of 20 records are input and assigned to the arva\j 
elements of the array A. 
Output Example: 



WRITE <6, 12)E, F, K, L, M, KK, LL, MM, K3, LE, 
;l M3 



12 FORMAT <2F9. 4, <3I7) ) 
In this example, three records are written. Record 
1 contains E, F» K, L and M. Because the 
descriptor 317 is reused twice, Record 2 contains 
KK, LL and MM and Record 3 contains K3, L3 and M3. 



FORTRAN-80 Reference Manual Page 77 

S. 7. 7. 2 Field Separators 

Two adjacent descriptors must be separated in the 
FORMAT statement by either a comma or one or more 
slashes. 
Example: 

2H0K/F6T3 or 2H0K, F6. 3 

The slash not only separates field descriptors* but 

it also specifies the demarcation of formatted 

records. 

Each slash terminates a record and sets up the next 

record for processing. The remainder of an input 

record is ignored* the remainder of an output 

record is filled with blanks. Successive slashes 

<///. . . /) cause successive records to be ignored on 

input and successive blank records to be written on 

output. 

Output example: 

DIMENSION AU0Q>,J<2Q> 



WRITE <7, 8) J, A 
8 FORMAT (10I7/10I7/50F7. 3/50F7. 3) 
In this example* the data specified by the list of 
the WRITE statement are output to unit 7 according 
to the specifications of FORMAT statement 8. Four 
records are written as follows: 
Record i Record 2 Record 3 Record 4 

J<1) J<11) A<1) A<51> 

J<2> J(12) A<2) A<52> 



J<10) J(20) A<50) A(IOO) 

Input Example: 

DIMENSION B(IO) 



READ <4* 17) B 
17 FORMAKFIO. 2/F10. 2///SF10. 2) 
In this example* the two avrax^ elements B<1) and 
8(2) receive their values from the first data 



FORTRAM-80 Reference Manual Page 78 

fields of successive records (the remainders of the 
two records are ignored). The third and fourth 
records are ignored and the 7 % emaining elements of 
the arrays are filled from the fifth record. 

8.7.8 FORMAT CONTROL, LIST SPECIFICATIONS AND RECORD 

DEMARCATION " 

The following relationships and interactions 
between FORMAT control* input/output lists and 
record demarcation should be noted: 

1. Execution of a formatted READ or WRITE 
statement initiates FORMAT control. 

2. The conversion performed on data depends on 
information jointly provided by the elements in 
the input/output list and field descriptors in 
the FORMAT statement. 

3. If there is an input/output list* at least one 
descriptor of types E> F, D> G> 1, L or A must 
be present in the FORMAT statement. 

4. Each execution of a formatted READ statement 
causes a new record to be input. 

5. Each item in an input list corresponds to a 
string of characters in the record and to a 
descriptor of the types E> Ft G, I* L or A in 
the FORMAT statement. 

6. H and X descriptors communicate information 
directly between the external record and the 
field descriptors without reference to list 
items. 

7. On input/ whenever a slash is encountered in 
the FORMAT statement or the FORMAT descriptors 
have been exhausted and re-use of descriptors 
is initiated* processing of the current record 
is terminated and the following occurs: 

a. Any unprocessed characters in the record 
are ignored. 

b. If more input is necessary to satisfy 
list requirements/ the next record is 
read. 



F0RTRAN--80 Reference Manual Page 79 

8. A READ statement is terminated when all items 
in the input list have been satisfied if: 

a. The next FORMAT descriptor is E» F* G> I* 
L or A. 

b. The FORMAT control has reached the last 
outer right parenthesis of the FORMAT 
statement. 

If the input list has been satisfied* but the 
next FORMAT descriptor is H or X* more data are 
processed (with the possibility of new records 
being input) until one of the above conditions 
exists. 

9. If FORMAT control reaches the last right- 
parenthesis of the FORMAT statement but there 
am more list items to be processed* all or 
part of the descriptors are reused. (See item 
3 in the description of Repeat Specifications* 
sub-paragraph S. 7. 7. 1) 

10. When a Formatted WRITE statement is executed* 
records are written each time a slash is 
encountered in the FORMAT statement or FORMAT 
contT^o! has reached the rightmost right 
parenthesis. The FORMAT control terminates in 
one of the two methods described for READ 
termination in 8 above. Incomplete records are 
filled with blanks to maintain record lengths. 
8. 7. 9 FORMAT CARRIAGE CONTROL 

The first character of every formatted output 
record is used to convey carriage control 
information to the output device* and is therefore 
never printed. The carriage control character 
determines what action will be taken before the 
line is printed. The options are as follows: 
Control Character Action Taken Before Printing 

Skip 2 lines 

1 Insert Form Feed 
+ No advance 
Other Skip i line 

8.7.10 FORMAT SPECIFICATIONS IN ARRAYS 



The FORMAT reference* f* of a formatted READ or 
WRITE statement (See 8. 1 ) may be an array name 
instead of a statement label. If such reference is 



FORTRAN-80 Reference Manual Page SO 

made* at the time of execution of the READ/WRITE 
statement the first part of the information 
contained in the array* taken in natural order* 
must constitute a valid FORMAT specification. The 
array may contain non~FORMAT information following 
the right parenthesis that ends the FORMAT 
spec if ication. 

The FORMAT specification which is to be inserted in 
the array has the same form as defined for a FORMAT 
statement <i. e. > it begins with a left parenthesis 
and ends with a right parenthesis). 

The FORMAT specification may be inserted in the 
array by use of a DATA initialization statement* or 
by use of a READ statement together with an Aw 
FORMAT. Example: 

Assume the FORMAT specification 

<3F1Q. 3, 416) 
or a similar 12 character specification is to be 
stored into an array. The array must allow a 
minimum of 3 storage units. 

The FORTRAN coding below shows the various methods 
of establishing the FORMAT specification and then 
referencinq the array for a formatted READ or 
WRITE. 



FORTRAN-BO Reference Manual Page 81 

C DECLARE A REAL ARRAY 

DIMENSION A<3>, BO), M(4) 
C INITIALIZE FORMAT WITH DATA STATEMENT 

DATA A/'OFl ', 'O. 3, ', '416) '/ 



C READ DATA USING FORMAT SPECIFICATIONS 
C IN ARRAY A 

READ<6, A) B, M 
C DECLARE AN INTEGER ARRAY 

DIMENSION IA<4), BO), M(4) 



C READ FORMAT SPECIFICATIONS 

READ (7, 15) IA 
C FORMAT FOR INPUT OF FORMAT SPECIFICATIONS 
1'5 FORMAT <4A2) 



C READ DATA USING PREVIOUSLY INPUT 
C FORMAT SPECIFICATION 
READ (7, IA) B, M 






o 



FORTRAN -80 Reference Manual Page 82 

SECTION 7 
FUNCTIONS AND SUBPROGRAMS 
The FORTRAN language provides a means for defining and using 
often needed programming procedures such that the statement 
or statements of the procedures need appear in a program 
only once but may be referenced and brought into the logical 
execution sequence of the program whenever and as often as 
needed. 
These procedures are as follows: 

1. Statement functions. 

2. Library functions. 

3. FUNCTION subprograms. 

4. SUBROUTINE subprograms. 

Each of these procedures has its own unique requirements for 
reference and defining purposes. These requirements are 
discussed in subsequent paragraphs of this section. 
However* certain features are common to the whole group or 
to two or more of the procedures. These common features are 
as follows: 

1. Each of these procedures is referenced by its name 
which* in all cases* is one to six alphanumeric 
characters of which the first is a letter. 

2. The first three are designated as "functions" and 
are alike in that: 

1. They are always single valued (i.e.* they 
return one value to the program unit from which 
they are referenced). 

2. They are referred to by an expression 
containing a function name. 

3. They must be typed by type specification 
statements if the data type of the 
single-valued result is to be different from 
that indicated by the pre-defined convention. 

3. FUNCTION subprograms and SUBROUTINE subprograms are 
considered program units. 



FORTRAN-80 Reference Manual Page 83 

In the following descriptions of these procedures* the term 
calling program means the program unit or procedure in which 
a reference to a procedure is made, and the term "called 
program" means the procedure to which a reference is made. 
9. 1 THE PROGRAM STATEMENT 



The PROGRAM statement provides a means of 
specifying a name for a main program unit. The 
form of the statement is: 

PROGRAM name 
If present* the PROGRAM statement must appear 
before any other statement in the program unit. 
The name consists of 1-6 alphanumeric characters* 
the first of which is a letter. If no PROGRAM 
statement is present in a main program* the 
compiler assigns a name of $MAIN to that program. 
9. 2 STATEMENT FUNCTIONS 

Statement functions are defined by a single 
arithmetic or logical assignment statement and are 
relevant only to the program unit in which they 
appear. The general form of a statement function 

is as follows: 
f <al* a2* . . . an) •» e 

where f is the function name* the ai are dummy 
arguments and e is an arithmetic or logical 
expression. 

Rules for ordering* structure and use of statement- 
functions are as follows: 

1. Statement function definitions* if they exist 
in a program unit* must precede all executable 
statements in the unit and follow all 
specification statements. 

2. The ai are distinct variable names or array 
elements* but* being dummy variables* they may 
have the same names as variables of the same 
type appearing elsewhere in the program unit. 

3. The expression e is constructed according to 
the rules in SECTION 4 and may contain only 
references to the dummy arguments and 
non-Literal constants* variable and array 
element references* utility and mathematical 
function references and references to 



FORTRAN-80 Reference Manual Page 84 

previously defined statement functions. 

4. The type of any statement function name or 
argument that differs from its pre-defined 
convention type must be defined by a type 
specification statement. 

5. The relationship between f and e must conform 
to the replacement rules in Section 5. 

6. A statement function is called by its name 
followed by a parenthesized list of arguments. 
The expression is evaluated using the arguments 
specified in the call* and the reference is 
replaced by the result. 

7. The ith parameter in every argument list must 
agree in type with the ith dummy in the 
statement function. 

The example below shows a statement function and a 

statement function call. 

C STATEMENT FUNCTION DEFINITION 



C 



FUNCKA, B,C*D) = <<A+B)**C)/D 



C STATEMENT FUNCTION CALL 
C 

A12*A1-FUNC1<X, Y, Z7, C7> 
9. 3 LIBRARY FUNCTIONS 

Library functions ana a group of utility and 
mathematical functions which ar^ "built-in" to the 
FORTRAN system. Their names ar& pre-defined to the 
Processor and automatically typed. The functions 
btb listed in Tables 9-1 and 9-2. In the tables* 
arguments ax^e denoted as a.t > a2> . . . » an, if more than 
one argument is required* or as a if only one is 
required. 

A library function is called when its name is used 
in an arithmetic expression. Such a reference 
takes the following form: 
f (alt &2t . . . an ) 

where f is the name of the function and the ai are 
actual arguments. The arguments must agree in 
type* number and order with the specifications 
indicated in Tables 9-1 and 9—2. 



FDRTRAN-80 Refe7 v ence Manual Paye 85 

In addition to the functions listed in 9-1 and 9-2, 
four additional library subprograms are provided to 
enable direct access to the 8080 (or Z80) hardware. 
These art*: 

PEEK, POKE, INP, OUT 
PEEK and INP are Logical functions; POKE: and OUT 
are subroutines. PEEK and POKE allow direct access 
to any memory location. PEEK (a) returns the 
contents of the memory location specified by a. 
CALL P0KE<al>a2) causes the contents of the memory 
location specified by al to be replaced by the 
contents of a2. INP and OUT allow direct access to 
the I/O ports. INP(a) does an input from port a 
and returns the 8~bit value input. CALL 0UT<al>a2> 
outputs the value of a2 to the port specified by 
a JL. 
Examples: 

Al - B+FLOAT (17) 

MAGNI = ABS(KBAR) 

PDIF = DIM<€» D) 

S3 = SIN<T12) 

ROOT = < -B+SQRT < B**2-4. *A*C ) ) / 
1 (2. *A> 



FORTRAN-SO Reference Manual Page 86 

TABLE 9-1 
Intrinsic Functions 
Function Types 

Name Definition Argument Function 



ABS 


i a t 


Real 


Real 


I ABS 




Integer 


Integer 


DABS 




Doub le 


Double 


A I NT 


Sign of a times lar- 


Real 


Real 


INT 


gest integer <~ ! a ! 


Real 


Integer 


I DINT 




Double 


Integer 


AMOD 


al<mod a2) 


Real 


Real 


MOD 




Integer 


Integer 


AMAXO 


Max (alt a2> . . . ) 


Integer 


Real 


AMAX1 




Real 


Real 


MAXO 




Integer 


Integer 


MAX 1 




Real 


Integer 


DMA XI 




Doub le 


Doub le 


AMINO 


Min(alf a2* . . . ) 


Integer 


Real 


AMIN1 




Real 


Real 


MI NO 




Integer 


Integer 


MINI 




Real 


Integer 


DM INI 




Doub le 


Doub le 


FLOAT 


Conversion from 
Integer to Real 


Integer 


Real 


I FIX 


Conversion from 
Real to Integer 


Real 


Integer 


SI ON 


Sign of a2 times !al! 


Real 


Real 


ISIGN 




Integer 


Integer 


DS1GN 




Double 


Doubl e 


DIM 


al - Min (al> a2> 


Real 


Real 


1DIM 




Integer 


Integei 1 - 


SNOL 




Double 


Real 


DBLE 




Real 


Doub le 



FORTRAN-BO Reference Manual Page 87 

TABLE 9-2 
Basic External Functions 
Number 
of Type 

Name Arguments Definition Argument Function 



EXP 


1 


e*#s 


Real 


DEXP 


1 




Double 


ALOG 


1 


.1 n < a ) 


Real 


DL..OG 


1 




Double 


ALOQ10 


.1 


IoglO(a> 


Real 


DLOG10 


1 




Doub le 


SIN 


1 


sin < a > 


Real 


DS IN 


1 




Double 


COS 


1 


cos ( a ) 


Real 


Lf \>t K.J v3 


1 




Double 


TANH 


1 


tanh (a) 


Real 


SQRT 


1 


<a> ** 1/2 


Real 


DSQRT 


1 




Doub le 


ATAN 


1 


arc tan (a) 


Real 


DATAN 


1 




Double 


ATAN2 


2 


arc tan <al/a2) 


Real 


DATAN2 


2 




Doub le 


DMOD 


2 


aKfflod a2) 


Doub le 



Real 

Double 

Real 

Double 

Real 

Double 

Real 

Doub le 

Real 

Doub le 

Real 

Real 

Doub le 

Real 

Double 

Real 

Doub le 

Doub le 



F0RTRAN--80 Reference Manual Page S3 

9. 4 FUNCTION SUBPROGRAMS 



A program unit which begins with a FUNCTION 

statement is called a FUNCTION subprogram. 

A FUNCTION statement has one of the following 

forms: 

t FUNCTION f (al> a2, . . . an) 

or 

FUNCTION f <al, a2, . . . an) 
where: 

1. t is either INTEGER, REAL, DOUBLE PRECISION or 
LOGICAL or is empty as shown in the second 
form. 

2. f is the name of the FUNCTION subprogram. 

3. The ai are dummy arguments of which there must 
be at least one and which represent variable 
names, array names or dummy names of SUBROUTINE 
or other FUNCTION subprograms. 

CONSTRUCTION OF FUNCTION SUBPROGRAMS 



Construction of FUNCTION subprograms must comply 
with the following restrictions: 

1. The FUNCTION statement must be the first 
statement of the program unit. 

2. Within the FUNCTION subprogram, the FUNCTION 
name must appear at least once on the left side 
of the equality sign of an assignment statement 
or as an item in the input list of an input 
statement. This defines the value of the 
FUNCTION so that it may be returned to the 
calling program. 

Additional values may be returned to the 
calling program through assignment of values to 
dummy arguments. 



F0RTRAN-8G Reference Manual 
Example: 



Page 89 



FUNCTION Z7(A, B, C) 



7 ~ 5. *<A~B> + SGRT<C> 



C REDEFINE ARGUMENT 
B=~-B+Z7 



RETURN 



END 

3. The names in the dummy argument list may not appear 
in EQUIVALENCE, COMMON "or DATA statements in the 
FUNCTION subprogram. 

4. If a dummy argument is an arva\i name* then an arvmq 
declarator must appear in the subprogram with 
dimensioning information consistent with that in 
the calling program. 

5. A FUNCTION subprogram may contain any defined 
FORTRAN statements other than BLOCK DATA 
statements, SUBROUTINE statements, another FUNCTION 
statement or any statement which references either 
the FUNCTION being defined or another subprogram 
that references the FUNCTION being defined. 

6. The logical termination of a FUNCTION subprogram is 
a RETURN statement and there must be at least one 
of them. 

7. A FUNCTION subprogram must physically terminate 
with an END statement. 



FORTRAN-80 Reference Manual Page 90 

Example: 

FUNCTION SUM (BARY* I, J) 
DIMENSION BARYUO, 20) 
SUM = 0. 
DO 8 K=l* I 
DOB M = 3. > J 
8 SUM = SUM + BARYCK*M) 
RETURN 
END 
9.6 REFERENCING A FUNCTION SUBPROGRAM 



FUNCTION subprograms are called whenever the 

FUNCTION name* accompanied by an argument list; is 

used as an operand in an expression. Such 

references take the following form: 

f iait a2.« . . . > an ) 

inhere f is a FUNCTION name and the ai are actual 

arguments. Parentheses must be present in the form 

shown. 

The arguments ai must agree in type* order and 

number with the dummy arguments in the FUNCTION 

statement of the called FUNCTION subprogram. They 

may be any of the following: 

1. A variable name. 

2. An array element name. 

3. An arra^ name. 

4. An expression. 

5. A SUBROUTINE or FUNCTION subprogram name. 

6. A Hollerith or Literal constant. 

If art ai is a subprogram name; that name must have 

previously been distinguished from ordinary 

variables by appearing in an EXTERNAL statement and 

the corresponding dummy arguments in the called 

FUNCTION subprograms must be used in subprogram 

references. 

If ai is a Hollerith or Literal constant* the 

corresponding dummy variable should encompass 

enough storage units to correspond exactly to the 

amount of storage needed by the constant. 

When a FUNCTION subprogram is called* program 



FORTRAN-80 Reference Manual Page 91 

control goes to the first executable statement 
following the FUNCTION statement. 

The following examples show references to FUNCTION 
subprograms. 

ZIO = FT1+Z7(D, T3, RHO) 

DIMENSION DAKS, 5) 



9. 7 



S3. 



TOT1 + SUM (DAT, 5, 5) 



SUBROUTINE SUBPROGRAMS 



A program 
statement 
SUBROUTINE 
forms: 



unit which begins with a SUBROUTINE 

is called a SUBROUTINE subprogram. The 

statement has one of the following 



SUBROUTINE s <al, a2, . . . , an ) 



or 



9. 8 



SUBROUTINE s 

where s is the name of the SUBROUTINE subprogram 

and each ai is a dummy argument which represents a 

va?*iable or avra\^ name or another SUBROUTINE or 

FUNCTION name. 

CONSTRUCTION OF SUBROUTINE SUBPROGRAMS 



1. The SUBROUTINE statement must be the first statement 
of the subprogram. 

2. The SUBROUTINE subprogram name must not appeal* in 
any statement other than the initial SUBROUTINE 
statement. 

3. The dummy argument names must not appear in 
EQUIVALENCE, " COMMON or DATA statements in the 
subprogram. 

4. If a dummy argument is an arra\^ name then an arra\^ 
declarator must appear in the subprogram with 
dimensioning information consistent with that in the 
calling program. 

5. If any of the dummy arguments represent values that 
are to be determined by the SUBROUTINE subprogram 
and returned to the calling program, these dummy 



FORTRAN-BO Reference Manual Page 92 

arguments must appear within the subprogram on the 
left side of the equality sign in a replacement 
statement.. in the input list of an input statement 
or as a parameter within a subprogram reference. 

6. A SUBROUTINE may contain any FORTRAN statements 
other than BLOCK DATA statements* FUNCTION 
statements* another SUBROUTINE statement* a PROGRAM 
statement or any statement which references the 
SUBROUTINE subprogram being defined or another 
subprogram which references the SUBROUTINE 
subprogram being defined. 

7. A SUBROUTINE subprogram may contain any number of 
RETURN statements. It must have at least one. 

8. The RETURN statement(s) is the logical termination 
point of the subprogram. 

9. The physical termination of a SUBROUTINE subprogram 
is an END statement. 

10. If an actual argument transmitted to a SUBROUTINE 
subprogram by the calling program is the name of a 
SUBROUTINE or FUNCTION subprogram* the corresponding 
dummy argument must be used in the called SUBROUTINE 
subprogram as a subprogram reference. 
Example: 



C SUBROUTINE TO COUNT POSITIVE ELEMENTS 
C IN AN ARRAY 

SUBROUTINE COUNT P ( ARRY* I* CNT) 
DIMENSION ARRY(7) 
CNT ~ 
DO 9 J=l, I 
IF(ARRY(J))9> 5* 5 
9 CONTINUE 

RETURN 
5 CNT « CNT+1. O 
GO TO 9 
END 
9.9 REFERENCING A SUBROUTINE SUBPROGRAM 



A SUBROUTINE subprogram may be called by using a 
CALL statement. A CALL statement has one of the 
following forms: 
CALL s(al* a2* ... * an > 



or 



FORTRAN-80 Reference Manual Page 93 

CALL s 

where s is a SUBROUTINE subprogram name and the ai 

are the actual arguments to be used by the 

subprogram. The ai must qqt&b in type/ order and 

number with the corresponding dummy arguments in 

the subprogram-defining SUBROUTINE statement. 

The arguments in a CALL statement must comply with 

the following rules: 

1. FUNCTION and SUBROUTINE names appearing in the 
argument list must have previously appeared in 
an EXTERNAL statement. 

2. If the called SUBROUTINE subprogram contains a 
variable arra^ declarator, then the CALL 
statement must contain the actual name of the 
array and the actual dimension specifications 
as arguments. 

3. If an item in the SUBROUTINE subprogram dummy 
argument list is an arra\}> the corresponding 
item in the CALL statement argument list must 
be an array. 

When a SUBROUTINE subprogram is called* program 
control goes to the first executable statement 
following the SUBROUTINE statement. 
Example: 

D I MENS I ON DATA < 1 ) 



C THE STATEMENT BELOW CALLS THE 

C SUBROUTINE IN THE PREVIOUS PARAGRAPH 

C 

CALL COUNTPCDATA, 10, CPOS) 
9. 3.0 RETURN FROM FUNCTION AND SUBROUTINE SUBPROGRAMS 



The logical termination of a FUNCTION or SUBROUTINE 

subprogram is a RETURN statement which transfers 

control back to the calling program. The general 

form of the RETURN statement is simply the word 

RETURN 

The following rules govern the use of the RETURN 

statement: 



FORTRAN— SO Reference Manual Page 94 

1. There must be at least one RETURN statement in 
each SUBROUTINE or FUNCTION subprogram. 

2. RETURN from a FUNCTION subprogram is to the 
instruction sequence of the calling program 
following the FUNCTION reference. 

3. RETURN from a SUBROUTINE subprogram is to the 
next executable statement in the calling 
program which would logically follow the CALL 
statement. 

4. Upon return from a FUNCTION subprogram the 
single-valued result of the subprogram is 
available to the evaluation of the expression 
from which the FUNCTION call was made. 

5. Upon return from a SUBROUTINE subprogram the 
values assigned to the arguments in the 
SUBROUTINE are available for use by the calling 
program. 

Examp le: 



Calling Program Unit 



CALL SUBR<Z9, B7,R1) 



Ca 1 1 e cl Program Un i t 

SUBROUTINE SUBRCA, B,C> 
READC3* 7) B 
A = B##C 
RETURN 
7 FORMAT <F9. 2) 
END 
In this example* 29 and B7 are made available to 
the calling program when the RETURN occurs. 
9. 11 PROCESSING ARRAYS IN SUBPROGRAMS 

If a calling program passes an arra^ name to a 
subprogram* the subprogram must contain the 
dimension information pertinent to the array. A 
subprogram must contain arrays declarators if any of 
its dummy arguments represent arrays or arrays 



: 0RTRAN~~80 Reference Manual Page 95 

elements. 

For example* a FUNCTION subprogram designed to 
compute the average of the elements of any one 
dimension arra^ might be the folowing: 
Calling Program Unit 



DIMENSION 21(50), Z2<25) 



Al 



AVG<Z1, 50) 



A2 = A1~-AVG<Z2, 25) 



Called Program Unit 



FUNCTION AVG<ARG, I) 

DIMENSION ARG<50) 

SUM = 0. O 

DO 20 J=i, I 
20 SUM « SUM + ARG(J) 

AVG = SUM/FLOAT U) 

RETURN 

END 
Note that actual arrays to be processed by the 
FUNCTION subprogram are dimensioned in the calling 
program and the arTa\^ names and their actual 
dimensions are transmitted to the FUNCTION 
subprogram by the FUNCTION subprogram reference. 
The FUNCTION subprogram itself contains a dummy 
arrav^ and specifies a-n arra\^ declarator. 
Dimensioning information may also be passed to the 
subprogram in the paramater list. For example: 



FORTRAN-80 Reference Manual Page 96 

Calling Program Unit 

DIMENSION A<3, 4* 5) 



CALL SUBR < A, 3* 4, 5) 

END 

Called Program Unit 

SUBROUTINE SUBR ( X, I, J, K> 
DIMENSION X(I, J, K> 



RETURN 
END 

It is valid to use variable dimensions only when 

the arra\j name and all of the variable dimensions 
ar<$ dummy arguments. The variable dimensions must 
be type Integer. It is invalid to change the 
values of any of the variable dimensions within the 
called program. 
9. 3.2 BLOCK DATA SUBPROGRAMS 



A BLOCK DATA subprogram has as its only purpose the 

initialization of data in a COMMON block during 

loading of a FORTRAN object program. BLOCK DATA 

subprograms begin with a BLOCK DATA statement of 

the following form: 

BLOCK DATA Csubprogram-nameU 

and end with an END statement. Such subprograms 

may contain only Type* EQUIVALENCE* DATA* COMMON 

and DIMENSION statements and are subject to the 

following considerations: 

1. If any element in a COMMON block is to be 
initialized* all elements of the block must be 
listed in the COMMON statement even though they 
might not all be initialized. 

2. Initialization of data in more than one COMMON 
block may be accomplished in one BLOCK DATA 
subprogram. 



FOR TR AN— BO Reference Manual Page 97 

3. There may be more than one BLOCK DATA 
subprogram loaded at any given time. 

4. Any particular COMMON block item should only be 
initialized by one program unit. 

Example: 

BLOCK DATA 
LOGICAL Ai 

COMMON/BETA/B (3,3) /QAM/C ( 4 ) 
COMMON/ALPHA/A1 , F, E, D 
DATA B/l. 1, 2. 5> 3. 8,3*4. 76, 
12*0. 52, 1. l/,C/i. 2E0, 3*4. 0/ 
DATA Al/. TRUE. A E/-5. 6/ 



FORTRAN-SO Reference Manual Page 98 

APPENDIX A 
Language Extensions and Restrictions 
The FORTRAN-SO language includes the following extensions to 
ANSI Standard FORTRAN (X3. 9-1966) . 

1. If c is used in a 'STOP c ' or 'PAUSE c' statement* 
c may be any six ASCII characters. 

2. Error and End-of-File branches may be specified in 
READ and WRITE statements using the ERR= and END- 
options. 

3. The standard subprograms PEEK* POKE* INP* and OUT 
have been added to the FORTRAN library. 

4. Statement functions may use subscripted variables. 

5. Hexadecimal constants may be used wherever Integer 
constants av& normally allowed. 

6. The literal form of Hollerith data (character 
string between apostrophe characters) is permitted 
in place of the standard nH form. 

7. Holleriths and Literals ar& allowed in expressions 
in place of Integer constants. 

S. There is no restriction to the number of 

continuation lines. 
9. Mixed mode expressions and assignments are allowed* 
and conversions are done automatically. 
FORTRAN-80 places the following restrictions upon Standard 
FORTRAN. 

1. The COMPLEX data type is not implemented. It may 
be included in a future release. 

2. The specification statements must appear in the 
following order: 

.1. PROGRAM* SUBROUTINE* FUNCTION, BLOCK DATA 

2. Type* EXTERNAL* DIMENSION 

3. COMMON 

4. EQUIVALENCE 



FORTRAN-BO Reference Manual Page 99 

5. DATA 

6. Statement Functions 

3. A different amount of computer memory is allocated 
for each of the data types: Integer; Real/ Double 
Precision* Logical. 

4. The equal sign of a replacement statement and the 
first comma of a DO statement must appear on the 
initial statement line. 

5. In Input/Output list specifications* sublists 
enclosed in parentheses are not allowed. 

Descriptions of these language extensions and restrictions 
are included at the appropriate points in the text of this 
document. 



FORTRAN-80 Reference Manual Page 100 

APPENDIX B 
I/O Interface 
Input/Output operations are table-dispatched to the driver 
routine for the proper Logical Unit Number. $LUNTB is the 
dispatch table. It contains one 2-byte driver address for 
each possible LUN. It also has a one-byte entry at the 
beginning* which contains the maximum LUN plus one. The 
initial run-time package provides for 10 LUN's (1 - 10)* all 
of which correspond to the TTY. Any of these may be 
redefined by the user* or more added* simply by changing the 
appropriate entries in $LUNTB and adding more drivers. The 
runtime system uses LUN 3 for errors and other user 
communication. Therefore* LUN 3 should correspond to the 
operator console. The initial structure of $LUNTB is shown 
in the listings following this appendix. 

The device drivers also contain local dispatch tables. Note 
that $LUNTB contains one address for each device* yet there 
are really seven possible operations per device: 

1 ) Formatted Read 

2) Formatted Write 

3) Binary Read 

4) Binary Write 

5) Rewind 

6) Backspace 

7 ) En d f i I e 

Each device driver contains up to seven routines. The 
starting addresses of each of these seven routines are 
placed at the beginning of the driver* in the exact order 
listed above. The entry in $LUNTB then points to this local 
table* and the runtime system indexes into it to get the 
address of the appropriate routine to handle the requested 
1/0 operation. 

The following conventions apply to the individual 1/0 
routines: 

1. Location $BF contains the data buffer address for 
READs and WRITEs. 

2. For a WRITE* the number of bytes to write is in 
location $BL. 

3. For a READ, the number of bytes read should be 
returned in $BL. 



FORTRAN-80 Reference Manual Page 101 

4. All I/O operations set the condition codes before 
exit to indicate an error condition* end-of-file 
condition* or normal return: 

a) CY~1* Z^don't care - I/O error 

b) CY=0* Z~0 - end-of-file encountered 

c) CY-Q* Z^l - normal return 

The runtime system checks the condition codes after 
calling the driver. If they indicate a non-normal 
condition* control is passed to the label specified 
by "ERR~" or "END 5 *" or* if no label is specified* a 
fatal error results. 

5. *IOERR is a global routine which prints an "ILLEGAL 
I/O OPERATION" message (non-fatal). This routine 
may be used if there are some operations not 
allowed on a particular device <i.e. Binary I/O on 



J 



a TTY) 



NOTE 

The I/O buffer has a fixed maximum length 
of 132 bytes unless it is changed at 
installation time. If a driver allows an 
input operation to write past the end of 
the buffer* essential runtime variables may 
be affected. The consequences are 
unpredictable. 
The listings following this appendix contain an example 
driver for a TTY. REWIND* BACKSPACE* and ENDFILE ar^> 
implemented as No-Ops and Binary I/O as an error. This is 
the TTY drive?* provided with the runtime package. 



FORTRAN-80 Reference Manual Page 102 

APPENDIX C 
Subprogram Linkages 
This appendix defines a normal subprogram call as generated 
by the FORTRAN compiler. It is included to facilitate 
linkages between FORTRAN programs and those written in other 
languages* such as 8080 Assembly. 

A subprogram reference with no parameters generates a simple 
"CALL" instruction. The corresponding subprogram should 
return via a simple "RET. " (CALL and RET are 8080 opcodes - 
see the assembly manual or 8080 reference manual for 
exp lanations. ) 

A subprogram reference with parameters results in a somewhat 
more complex calling sequence. Parameters are always passed 
by reference (i.e., the thing passed is actually the address 
of the low byte of the actual argument). Therefore* 
parameters always occupy two bytes each* regardless of type. 
The method of passing the parameters depends upon the number 
of parameters to pass: 

1. If the number of parameters is less than or equal 
to 3* they are passed in the registers. Parameter 
1 will be in HL* 2 in DE (if present)* and 3 in BC 
(if present). 

2. If the number of parametei % s is greater than 3* they 
are passed as follows: 

1. Parameter 1 in HL. 

2. Parameter 2 in DE. 

3. Parameters 3 through n in a contiguous data 
block. BC will point to the low byte of this 
data block (i.e.* to the low byte of parameter 
3). 

Note that* with this scheme* the subprogram must know how 
many parameters to expect in order to find them. 
Conversely* the calling program is responsible for passing 
the correct number of parameters. Neither the compiler nor 

the runtime system checks for the correct number of 

parameters. 

If the subprogram expects more than 3 parameters* and needs 
to transfer them to a local data area> there is a system 



F0RTRAN--80 Reference 
subroutine which wil 
transfer routine i 
pointing to the loca 
parameter, and A 
transfer <i. e. , the 
subprogram is re 
parameters before ca 
expects 5 parameters 
SUBR: 



SHLD 


PI 


XCHG 




SHLD 


P2 


MVI 


A, 3 


LXI 


H, P3 


CALL 


$AT 



Manual Page 103 

1 perform this transfer. This argument 
s named $AT, and is called with HL 
1 data area* BC pointing to the third 
containing the number of arguments to 
total number of arguments minus 2). The 
sponsible for saving the first two 
lling $AT. For example* if a subprogram 
f it should look like: 
.; SAVE PARAMETER 1 



SAVE PARAMETER 2 

NO. OF PARAMETERS LEFT 

POINTER TO LOCAL AREA 

TRANSFER THE OTHER 3 PARAMETERS 



L'Body of subprogram! 



RET i RETURN TO CALLER 

PI: DS 2 , SPACE FOR PARAMETER 1 

PS: DS 2 i SPACE FOR PARAMETER 2 

P3: DS 6 ; SPACE FOR PARAMETERS 3-5 
When accessing parameters in a subprogram, don't forget that 

they av& pointers to the actual arguments passed. 

_ ^^ 

It is entirely up to the 
programmer to see to it that 
the arguments in the calling 
program match in number, type, 



and length with the parameters 



expected by the subprogram. 

This applies to FORTRAN 

subprograms, as well as those 

written in assembly language. 
FORTRAN Functions (Section 9) return their values in 
registers or memory depending upon the type. Logical 
results btb returned in <A), Integers in <HL>, Reals in 
memory at $AC» Double Precision in memory at $DAC. $AC and 
$DAC btb the add7*esses of the low bytes of the mantissas. 



FORTRAN- 


-SO Reference Manual 






Page 104 








APPENDIX D 










ASC 1 1 


CHARACTER CODES 






DECIMAL 


CHAR. 


DECIMAL 


CHAR. 


DECIMAL 


CHAR. 


4oo 


NUL 


043 




+ 


086 


V 


001 


SDH 


044 




> 


087 


w 


002 


STX 


045 




- 


088 


X 


003 


ETX 


046 






089 


Y 


004 


EOT 


047 




/ 


090 


Z 


005 


ENQ 


048 







091 


C 


006 


ACK 


04? 




1 


092 


\ 


007 


BEL 


050 




2 


093 


3 


008 


BS 


051 




3 


094 


A < or 


009 


HT 


052 




4 


095 


(or 


010 


LF 


053 




5 


096 


/ 


Oil 


VT 


054 




6 


097 


a 


012 


FF 


055 




7 


098 


b 


013 


CR 


056 




8 


099 


c 


014 


SO 


057 




9 


100 


d 


015 


O A 


058 






101 


e 


016 


DLE 


059 




/ 


102 


f 


017 


jL/Vj X 


060 




< 


103 


S 


018 


DC 2 


061 




= 


104 


h 


019 


DC3 


062 




y 


105 


i 


020 


DC 4 


063 




*> 


106 


J 


021 


NAK 


064 




e 


107 


k 


022 


SYN 


065 




A 


108 


1 


023 


ETB 


066 




B 


109 


m 


024 


CAN 


067 




c 


110 


n 


025 


EM 


068 




D 


111 


o 


026 


SUB 


069 




E 


112 


P 


027 


ESCAPE 


070 




F 


X * w 


Q 


028 


FS 


071 







114 


r 


029 


OS 


072 




H 


115 


5 


030 


RS 


073 




I 


116 


t 


031 


US 


074 




J 


117 


u 


032 


SPACE 


075 




K 


118 


V 


033 


t 


076 




L 


119 


m 


034 


ii 


077 




M 


120 


X 


035 


# 


078 




N 


121 


y 


036 


$ 


079 







122 


2 


037 


% 


080 




P 


123 


■c 


038 


& 


081 




Q 


124 


I 
1 


039 


/ 


082 




R 


125 




040 


< 


083 




S 


126 




041 


) 


084 




T 


127 


DEL 


042 


■if 


085 




U 






LF^L i n e 


reed rr- 


K Form Fi 


E-ed 


CR=Carriage 


Return 


DEL~Rubout 



FORTRAN-80 Reference Manual Page 105 

APPENDIX E 

Referencing FORTRAN-SO Library Subroutines 

The FORTRAN-SO library contains a number of subroutines that 

may be referenced by the user from FORTRAN or assembly 

programs. 

1. Referencing Arithmetic Routines 

In the following descriptions* $AC refers to the 
floating accumulator* $AC is the address of the 
low byte of the mantissa. $AC+3 is the address of 
the exponent. $DAC refers to the DOUBLE PRECISION 
accumulator; $DAC is the address of the low byte 
of the mantissa. #DAC-i~7 is the address of the 
DOUBLE PRECISION exponent. 

All arithmetic routines (addition* subtraction* 
multiplication* division* exponentiation) adhere to 
the following calling conventions. 

1. Argument 1 is passed in the registers: 
Integer in CHL.1 

Real in $AC 
Double in $DAC 

2. Argument 2 is passed either in registers* or in 
memory depending upon the type: 

a. Integers are passed in CHL3, or CDE3 if 
CHL3 contains Argument 1. 

b. Real and Double Precision values btq 
passed in memory pointed to by CHL3. 
(CHL3 points to the low byte of the 
mantissa. ) 



FORTRAN-SO Reference Manual Page 106 
The following arithmetic routines ar& contained in 
the Library: 

Function Name Argument 1 Type Argument 2 Type 

Addition $AA Real Integer 

$AB Real Real 

$AQ Double Integer 

$AR Double Real 

$AU Double Double 

Division $D9 Integer Integer 

$DA Real Integer 

$DB Real Real 

$DG Double Integer 

$DR Double Real 

*BU Double Double 

Exponentiation *E9 Integer Integer 

$EA Real Integer 

$EB Real Real 

$EG Double Integer 

*ER Double Real 

$EU Double Double 

Multiplication $M9 Integer Integer 

$MA Real Integer 

$MB Real Real 

*MQ Double Integer 

$MR Double Real 

$MU Double Double 

Subtraction $SA Real Integer 

*SB Real Real 

$SQ Double Integer 

$SR Double Real 

$SU Double Double 



FORTRAN-80 Reference Manual Page 107 

Additional Library routines are provided for converting 
between value types. Arguments are always passed to and 
returned by these conversion routines in the appropriate 
registers: 
Logical in CA3 
Integer in CHL3 
Real in $AC 
Double in $DAC 
Name Function 
$CA Integer to Real 
$CC Integer to Double 
$CH Real to Integer 
$C\) Real to Logical 

$CK Real to Double 
$CX Double to Integer 
$CY Double to Real 
$CZ Double to Logical 
2. Referencing Intrinsic Functions 



Intrinsic Functions are passed their parameters in H> L and 
D> E. If there are three arguments* E> C contains the third 
parameter. If there are more than three arguments* B> C 
contains a pointer to a block in memory that holds the 
remaining parameters. Each of these parameters is a pointer 
to an argument. (See Appendix B. ) 

For a MIN or MAX function* the number of arguments is passed 
i n A. 

NOTE 

None of the functions (except 

INP and OUT) may take a byte 

variable as an argument. Byte 

variables must first be 

converted to the type expected 

by the function. Otherwise.. 

results will be unpredictable. 
3. Formatted READ and WRITE Routines 

A READ or WRITE statement calls one of the following 
routines: 



FORTRAN-BO Reference Manual Page 108 

$W2 (2 parameters) Initialize for an I/O transfer 

$W5 <5 parameters) to a device <WRITE) 

$R2 (2 parameters) Initialize for an I/O transfer 

$R5 <5 parameters) from a device <READ) 

These routines adhere to the following calling conventions: 

1. H> L points to the LUN 

2. D» E points to the beginning of the FORMAT statement 

3. If the routine has five parameters* then B* C points 
to a block of three parameters: 

a. the address for an ERR- branch 

b. the address for an EOF- branch 

c. the address for a REC- value 

The routines that transfer values into the I/O buffer are: 

$10 transfers integers 

*I1 transfers real numbers 

$12 transfers logicals 

$13 transfers double precision numbers 

Transfer routines adhere to the following calling 

conventions: 

1. H* L points to a location that contains the number 
of dimensions for the variables in the list 

2. D,E points to the first value to be transferred 

3. B> C points to the second value to be transferred if 
there are exactly two values to be transferred by 
this call. If there are more than two values* B, C 
points to a block that contains pointers to the 
second through nth values. 

4. Register A contains the number of parameters 
(including H* L) generated by this call. 

The routine $ND terminates the I/O process. 



47 






49 






34- 


-35, 37-38, 


40-41, 


89- 


-90, 94-95 




27, 


32, 39 





FORTRAN-80 Reference Manual Page 109 

INDEX 

Arithmetic Expression .... 25-26, 

Arithmetic IF 44, 47, 

Arithmetic Operators 8 

Array 14, 20, 

56, 79, 

Array Declarator 20 

Array Element 14, 20, 

ASCII Character Codes .... 104 

ASSIGN 44, 46 

Assigned GOTO 44-45 

BACKSPACE 60 

BLOCK DATA 34, 37, 92, 96 

CALL 44, 53, 92 

Character Set 7 

Characteristic 23 

Comment Line 9 

COMMON 34, 37, 39-41, 89, 91, 96 

Computed GOTO 44-45 

Constant 14-15 

Continuation 9, 12 

CONTINUE 44, 51 

Control Statements 44 

DATA 34, 41, 89, 91, 96 

Data Representation 14 

Data Storage 21 

DECODE 61 

DIMENSION 20, 34, 37, 96 

DiskFiles 59 

DO .44, 47-49 

DO Implied List 63 

Double precision 14 

Dummy 91-93, 95 

ENCODE 61 

END 53, 89, 92, 96 

END Line 11 

ENDFILE 60 

EQUIVALENCE 34, 39-41, 89, 91, 96 

Executable 13, 34, 44 

Expression 25-26, 31-32 

Extended Range 50 

EXTERNAL . . ' 34, 37, 90, 93 

External Functions 87 

Field Descriptors 65 

FORMAT 55-57, 65, 69, 71-75, 77-80 

Formatted READ 54 



Formatted WRITE 57 

FUNCTION 34, 37, 82, 88~95 

GOTO 44, 49 

Hexadecimal 8, 21, 31, 42 

Hollerith 9, 15, 20-21, 31, 42, 56, 

71-72, 90 

I/O 54, 100 

I/O List 62 

IF .' 44, 47 

Index 49 

Initial Line 11 

INP 85 

Integer 14, 19, 23 

Intrinsic Functions 86, 107 

Label 9, 12, 44-45, 48 

Library Function 82, 84 

Library Subroutines 105 

Line Format 9 

List Item 62 

Literal 9, 20-21, 31, 42, 72, 90 

Logical 14, 19, 23, 73 

L.ogical Expression 27, 30, 48 

Logical IF 44, 47, 49 

Logical Operator 28 

Logical Unit Number 34, 58, 100 

LUN 54, 58, 100 

Mantissa 23 

Nested 51 

Non-executable 13, 34 

Numeric Conversions 66 

Operand 25 

Operator 25 

OUT 85 

PAUSE 44, 49, 52 

PEEK 85 

POKE 85 

PROGRAM 34, 83, 92 

Range 49 

READ 56, 58, 65, 74, 78-80, 107 

Real 14, 19, 23 

Relational Expression . . . . 27 

Relational Operator 27 

Replacement Statement .... 32, 48 

RETURN 44, 49, 53, 89, 92-94 

REWIND 60 

Scale Factor 74-75 

Specification Statement ... 34 

Statement Function 34, 82-83 



STOP 44, 49, 52 

Storage 35 

Storage Format 14 

Storage Unit 21* 23, 39 

Subprogram 37, 53, 82, 88-96, 102 

SUBROUTINE 34, 37, 53, 82, 89-94 

Subscript 20, 27 

Subscript Expression 21, 27 

Type . . 96 

Type Statement 35 

Unconditional GOTO 44 

Unformatted I/O 58 

Variable 14, 19, 32, 38, 90 

WRITE 57-58, 65, 74, 78-80, 107