• Keine Ergebnisse gefunden

FORTRAN IV

N/A
N/A
Protected

Academic year: 2022

Aktie "FORTRAN IV "

Copied!
125
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Digital EquipmenfCorporation Maynard,· Massachusetts

Programmers' Reference Manual

PDP-15 FORTRAN IV

(2)

PDP-15

FORTRAN IV

PROGRAMMERS'

REFERENCE MANUAL

Order No. DEC-15-KF ZB-D from Program Library, Maynard, Mass. Pri ce: $2.50 Direct comments concerning this manual to Software Information Service, Maynard.

DIGITAL EQUIPMENT CORPORATION • MAYNARD, MASSACHUSETTS

(3)

1st Prinf'ing July 1969 2nd Printing (Rev) June 1970

Your attention is invited to the last two pages of this manual. The Reader's Comments page, when filled in and returned, is beneficia I to both you and DEC. All comments received are considered when documenting subsequent manuals, and when assistance is required, a knowledgeable DEC representative will contact you. The Software Information page offers you a means of keeping up-to-date with DEC's software.

Copyright © 1968, 1969, 1970 by Digita I Equipment Corporation

'The material in this handbook, including but not limited to instruction times and operating speeds, is for infor- mation purposes and is subject to change without notice.

The following are trademarks of Digita I Equipment Corporation, Maynard, Massachusetts:

DEC FLIP CHIP DIGITAL

PDP FOCAL

COMPUTE R LAB

(4)

CONTENTS

PART 1 LANGUAGE

CHAPTER 1 INTRODUCTION

1.1 1.2

1 .2. 1

1.2.2

FORTRAN

Source Program Format

Card Format (IBM Model 029 Keypunch Codes) Paper Tape Format

CHAPTER 2 ELEMENTS OF THE FORTRAN LANGUAGE

2. 1

Constants

2.1.1

Integer Constants

2.1.2

Real Constants {Six-decimal-digit accuracy}

2.1.3

Double-Precision Constants {nine-decimal-digit accuracy}

2.1.4

Logical Constants

2.1.5

Hollerith Constants

2.2

Variables

2.2.1

Variable Types

2.2.2

Integer Variables

2.2.3

Real Variab les

2.2.4

Double-Precision and Logical Variables

2.3

Arrays and Subscripts

2.3.1

Arrangement of Arrays in Storage

2.3.2

Subscript Expressions

2.3.3

Subscripted Variables

2.4

Expressions

2.4.1

Arithmetic Expressions

2.4.2

Relational Expressions

2.4.3

Logical Expressions

2.5

Statements

iii

Page

1-1 1-1

1-2 1-2

2-1

2-1

2-1

2-2

2-3

2-3

2-3

2-3

2-4

2-4

2-4

2-4

2-5

2-5

2-6

2-6

2-6

2-8

2-8

2-10

(5)

CONTENTS (Cont)

PClge CHAPTER

3

ARITHMETIC STATEMENTS

CHAPTER

4

CONTROL STATEMENTS

4.1

Unconditional GO TO Statements

4-1

4.2

ASSIGN Statement

4-1

4.3

Assigned GO TO Statement

4-1

4.4

Computed GO TO Statement

4-2

4.5

Arithmetic IF Statement

4-2

4.6

Logical IF Statement

4-2

4.7

DO Statement

4-3

4.8

CONTINUE Statement

4-5

4.9

PAUSE Statement

4-5

4.10

STOP Statement

4-5

4.11 END Statement

4-6

CHAPTER

5

INPUT/OUTPUT STATEMENTS

5.1

General I/O Statements

5-2

5. 1 . 1

Input/Output Argument Lists

5-2

5.1.2

READ S ta temen t

5-3

5.1.3

WRITE Statement

5,-3

5.2

FORMA T Statements

5--4

5.2.1

Specifying FORMAT

5,-4

5.2.2

Conversion of Numeric Data

5,-6

5.2.3

P-Scale Factor - Field descriptor: nP or -nP

5,-9

5.2.4

Conversion of Alphanumeric Data

5,-9

5.2.5

Logical Fields, L Conversion - Field descriptor: Lw or nLw

5,-10 5.2.6

Blank Fields, X Conversion - Field descriptor: nX

5,-10

5.2.7

FORTRAN Statements Read in at Object Time

5,·10

5.2.8

Output of a Formatted Record

5·-11

5.3

Auxiliary I/O Statements

5·-12

5.3.1

BACKSPACE Statement

5·-12

5.3.2

REWIND Statement

5·-12

5.3.3

ENDFILE Statement

5·-12

(6)

CONTENTS (Cont)

CHAPTER 6 SPECIFICATION STATEMENTS 6. 1

6.1.1

6.2 6.3 6.4

6.4.1

6.5

6.6

TY PE Statements

Typing Double-Precision Functions DIMENSION Statement

COMMON Statement EQUIVALENC E Statement

Equivalencing COMMON Variables EXTERNAL Statement

DATA Statement CHAPTER 7 SUBPROGRAMS 7. 1

7.2 7.3 7.4

7.5 7.5.1

Statement Functions

Intrinsic or Library Functions External Functions

Su bro ut i nes

BLOCK DATA Subprogram

Example of BLOCK DATA Subprogram PART 2

FORTRAN IV OBJECT - TIME SYSTEM CHAPTER 8 OBJECT -TIME SYSTEM DESCRIPTIO N

8. 1

8.2

8.3

8.4 8.5

8.6

8.7

8.8

8.9

8. 10 8.11

OTS Binary Coded Input/Output (BCDIO) OTS Binary Input/Output (BINIO) OTS Auxiliary Input/Output (AUXIO) OTS lOPS Communication (FlOPS)

OTS Calcu late Array Element Address (. SS) OTS Computed GO TO (GO TO (.GO)) OTS STOP (STOP (. ST))

OTS PAUSE (PAUSE (.PA)) OTS Octal Print (SPMSG (. SP)) OTS Errors (OTSER (.ER))

Additions to the FORTRAN IV Subroutine Library v

Page 6-1 6-1

6-2 6-3 6-3 6-4 6-5 6-5

6-6

7-1 7-1 7-2 7-4 7-6 7-7 7-8

8-1

8-2

8-4

8-6

8-7

8-9

8-10 8-11 8-11 8-12 8-12 8-13

(7)

8.11.1 8.11.2 8. 11.3 8.11.4 8. 11.5 8. 11.6

CONTENTS (Cont)

Fi Ie Commands (FILE) Clock Handling (TIME) Clock Handling (TIME10) Adjustable Dimensioning (ADJ 1) Adjustable Dimensioning (ADJ2) Adjustable Dimensioning (ADJ3)

PART III

THE SCIENCE LIBRARY CHAPTER 9 SCIENCE LIBRARY DESCRIPTION

9. 1 9.2 9.3 9.4 9.5 9.5.1 9.5.2 9.5.3 9.6 9.7 9.7.1 9.7.2 9.7.3 9.7.4 9.7.5 9.7.6 9.7.7 9.7.8

Intrinsic Functions External Functions Sub-Functions

The Arithmetic Package Accumu lators

A-Register

Floating Accumulator Held Accumulator Calling Sequences

Science Library Algorithm Descriptions Square Root (SQRT, DSQRT)

Exponential (EXP, DEXP, . EF, • DF)

Natural and Common Logarithms (ALOG, ALOG 10, DLOG, DLOG 10) Sine and Cosine (SIN ,COS ,DSIN ,DCOS, . EB, . DB)

Arctangent (ATAN, DATAN, ATAN2, DATAN2, .ED, .DD) Hyperbolic Tangent (TANH)

Logarithm, Base 2 (. EE, . DE) Polynomial Evaluator (. EC, • DC)

APPENDICES APPENDIX A FORTRAN IV, ADDITIONAL INFORMATION

Page 8-13 8-15 8-16 8-17 8-18 8-18

9-1 9-1 9-1 9-1 9-2 9-2 9-2 9-2 9-3 9-3 9-9 9-9 9-9 9-10 9-10 9-11 9-12 9-13 9-13

A-l

(8)

APPENDICES (Cont)

APPENDIX B FORTRAN IV AND MACRO LINKAGE B. 1

B.2 B.3 B.4 B.4.1 B.4.2 B.4.3 B.4.4

Linking FORTRAN IV Programs with MACRO Subprograms Linking MACRO Programs with FORTRAN IV Subprograms Linking MACRO Programs with FORTRAN IV Library Routines More Illustrative Examples

A New Dimension Adjustment Routine A Function to Read the AC Switches A Routine to Read an Array in Octal

A FORTRAN Program Using the Foregoing Programs APPENDIX C CHAINING FORTRAN IV PROGRAMS APPENDIX D FORTRAN IV ERROR LIST

D.1 D.2 D.3 D.4

Techniques for Avoiding F Errors Techniques for Avoiding TErrors Techniques for Avoiding M Errors Technique for Avoiding an E Error APPENDIX E SYMBOL TABLE SIZES (F4 V5A)

ILLUSTRATIONS 1-1 FORTRAN Coding Form

TABLES 3-1 Assignment Ru I es

5-1 Physical Record Definitions 7-1 Intrinsic Functions

7-2 External Functions 8-1 OTS Error Messages 9-1 The Science Library D-1 Compilation Errors

vii

Page B-1 B-1 B-3 B-4 B-4 B-4

B-6 B-6 B-8

C-1 D-1 D-2 D-3 D-4 D-5 E-1

1-3

3-1 5-1 7-3 7-5

8-2

9-4

D-1

(9)
(10)

PREFACE

This manual describes the FORTRAN IV language and compiler system for either the PDP-15 or PDP-9 Computer; it provides the user with the information needed to write, compi Ie and execute FORTRAN programs on either of these computers.

The manual consists of three major parts:

Part 1, Basic FORTRAN IV Language

Part 1 is intended to familiarize the user with the FORTRAN IV coding procedures in the PDP-15 and -9 environment.

Part 2, FORTRAN IV Object Time System

Part 2 describes the group of subprograms which process compiled FORTRAN statements, particularly I/O statements, at the time of execution.

Part 3, FORTRAN Science Library

Part 3 provides detailed descriptions of the intrinsic functions, external functions, subfunctions, and arithmetic routines contained in the system Science Library.

FORTRAN IV (as described in this manual) is essentially the language specified by the United States of America Standards Institute (X3. 9 - 1966) with the exceptions noted in Appendix A of this manual {located at the end of Chapter 9).

(11)
(12)

1.1 FORTRAN

CHAPTER 1 INTRODUCTION

PART 1 LANGUAGE

FORTRAN makes it unnecessary for the scientisf' or engineer to learn the machine language for specific com- puters. With FORTRAN, the user can write programs in a simple language that adapts easily to scientific usage.

The FORTRAN language is composed of statements constructed in mathematical form in accordance with precise- ly formulated rules. A FORTRAN program consists of meaningful sequences of FORTRAN statements that direct the computer to perform specific operations and calculations; such a program is called a source program. The source program must be translated by the FORTRAN compiler program before execution; the translated version of the program is referred to as an object program. The object program is in binary code that the machine can understand.

1.2 SOURCE PROGRAM FORMAT

The FORTRAN character set consists of the 26 letters (A through Z); 10 digits (0 through 10); and 11 special characters:

Blank Equals Plus Minus Asterisk Slash

Left Parenthesis Right Parenthesis Comma

Decimal Point Dollar Sign

+

*

/

$

1-1

(13)

1 .2. 1 Card Format (IBM Model 029 Keypunch Codes)

The FORTRAN source program is written on a s1'andard FORTRAN coding sheet (see Figure 1-1), which consists of the following fields:

a. statement number field b. line continuation field c. statement field

d. identification field.

The FORTRAN statement is written in columns 7 through 72. If the statement is too long for one line, it can be continued in the statement field of as many lines as necessary if column 6 of each continuation line contains clny numeric character other than blank or zero. There are two exceptions to this rule:

a . the DO statement must be on one line

b. the equal sign (=) of an assignment statement must appear on the first line.

For one statement to be referenced by another, a statement number must be placed in columns 1 through 5 of the first line of the referenced statement. This number is made up of digits only, and can contain from one 1'0 five digits. Leading zeros and all blanks in this field are ignored. Because statement numbers are used only for identification, they can be assigned in any order.

The FORTRAN compiler ignores the last eight columns (columns 73 through 80), which can be used for program identification, sequencing, or arlY other purpose desired by the user. Comments can be included in the progmm by putting the letter C in column 1 of each line containing a comment (or continuation of a comment). The compiler ignores these comments except for printing them.

Blanks can be used to aid readability of a FORTRAN statement, except where otherwise indicated in thhi manual.

1 .2" 2 Paper Tape Format

When FORTRAN source program statements are prepared on paper tape, the sequence of characters is ex(]ctly the same as for card input, and each line is terminated with a carriage return-line feed sequence.

A statement number (all digits) can be written as the first five characters, or the letter C can appear as f'he first character to indicate a comment I ine or a continuation of a comment line. For statement continuation lines, any numeric character other than blank or zero is written as the sixth character or as the first character (lfter (]

TAB. The seventh character, which begins the statement, must be alphabetic. Each I ine is terminated with CI

carriage return-line feed.

1-2

(14)

The TAB key can increase the speed of writing FORTRAN statements on paper tape. A TAB followed by an alphabetic character begins the statement in column 7. A TAB followed by a digit causes the digit to be placed in column 6, indicating a statement continuation line. A statement number of less than five digits, followed by a TAB, causes the next character to be placed in column 6 if it is a digit, or in column 7 if it is a letter.

If a title is desired at the beginning of the tape for a listing, it must be entered as a comment line.

FORTRAN CODER DATE PAGE

CODING FORM PROBLEM

rrC~-C~o-nH-~-en~IT8---,--- S-$ymbol ic

B - Boolean STATEMENT NUMBER 1 2 3 4 5

FORTRAN STATEMENT IDENTIFICATION

7 8 9 1011 1213141516171819202122 23 24 25262728293031323334353637383940414243444546474849 50 5152 535455565758596061626364 65 66676869707172 7374757677 787980

I-+---+-+-i--+-+-+----+-+-+-+-+-+-+ I I I I I I I I I I +_+_+_+__+_+--+-+---+ I I I I I I I I I I I I I I I I I I I I I 1 1 I I I I ++-+-+-++-+-+++ +++ I 1--+1 t-+--t-t-t-++-I--+--+-++-- I I I I I I I I I I I I I I I I I I I 1 1 I I I 1 I I I I 1 I I 1 1 1 1 1 +t--+--+-

I-++-I---t---+-I--+---+-+-+---t-+-I-+-+--+-+--+--+ I I I I I I I I I +-+++--+ I I 1 I I I 1 I I I 1-+-+-1 I I I I 1 1 1 I-t-- 1 1 I 1 1 1 +-+-+-+-+-+ +-++-+-1--+ + 1-+--1- r+---+-+-i-+--t-+----+-+-+-+-~1-+141-+1+1-+1 +I-II--+I~II-+I~II--+I-II--+I~I'-+I~I--+-I~I-+I~I~+I~I-+I~I-+I+I-+I +1-+1 +1-+1 +I-I~I--I--+-I--+-I--+-I--+-I--~-+--t-~-+-+-~-+--t-+-i-+--t-+----+--++ 1--+-+-

I I I I 1 I I I 1++-+-+ I I I 1 1 I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I + 1-+--+-

~-+---+-l-+-+--t-I'-I---+--t-I'-I---+-+-+-+-+-+---+---t-+---+- I I I I I I 1 1 I 1 I I I I 1 I I I I I I I ~ I I I I I I 1 +-+--+-+--+-+-t-+-+--+-+---+-+-+--+-+-+- +-1--+-+ j-+--t- r+---+-+-t-+'+--t-I'-I---+-+-i'-l---+-+-i-+-+---+-+--+--+---+-+--+--+-t-+-+---+-t-+--+-+I-It-+I -111--+-1 -11'-1--1 -11'-1--1 -+1'-1--1 -+1-+-1 +1--+-1 +1 -+-1 -+1--+-1 +1 -+-1 +1 --+-1 +1 --+-1 +1 -It-+I -111---t--1 -I1f-+1 -It-+I -11-+-+-+---1-+-+-+ t-I---+-I- 1-+-+--+-1--+-+-+----+-+ 1 1 1 1 1 I 1 \ 1 1 1 1 I I 1 I I I I I I 1 \ -+-+-+--1 1 I I I I I I I I I I I 1 I I I I I I I I 1 t-+--+--I-+-+-+-+~-+-+--+---+-+-+--1-+-+ -

t-+---t--+-l---++-t-lc---+----+--t-1I--+--+-+-i-+--+---+-+--+--+-+-+-+--+-t-+-+---+-t-+--+--+-t-+-+--+-tc---+--+-+-ic---+--+---+--+-+--+---+--I--+--+---+---+--+--+-+-+--+--+-t-+-+---+-+-+--+-+-It-++-+-+---+-+ -t--t-+

~-I--+-I-_+--t--t-I'-I---+--+-i-+-+--+----+-+-+-+----+--+--+-+----+-+--+-t-+-+---+-t-+-+-+-++I-+I +1 ~I-+I ~I-+I ~I-+I -ll-+I -ll-+I -ll-+I ~I-+I -ll-+I -ll-+I +1-+1 +1-+1 +1-+1 +1-+1 +1-+1 +1-+1 +I--+-~ -+-+++ 1-+-1 I-+---+-+-i-_+-+--~-+-+--+-+-1 I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I 1 I I I I I I I I I I I I I 1 I I 1 I +-+-+-+--t-~-+-+-+-+--+-+-+ 1-+-+

I-+---+-+-i-+--t-+-tc---+----+-+-t--+---+-+--I--+--+-+-+--+--+-+-+--+-+-It-+---+-+-t-+-+ I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I -+-t---t---+---t--+--+-+-i-+-+ ---t--t

r+-+-+-i-t4--t-I-Ilc---+-I-IIc---+-I-II--+--I-+I-+I+I--+-1 +1--+-1 +1--+-1 +1--+-1 +1--+-1 +1-I1t-+1-I1t-+1~1t-+1-+--1 --t--It-+---+-+-i-+-+-+--t-+-+-+--t--+--+-t-t--+--+-+-+--+--+-t-+--+-+-It-+---t--+-t-+-+---+-l'-l--~+-i-+4 +--+-4 1 I I I I I I I I I I I I I I I I I I I I I 1 I I I I --t--I-+--+-+--+-+-t-+-+-+-+-+--+-+-+-+--+-4

I--+---+-+-l--+--+--~-+-+-+----+-+-+-+----+-++-I--+-++-I--+-+~I--+-I--+-I--+-+-il-+I~I-+I~I-+I+I~I+I~I+I-+I +1-+1 +1-+1 +1-+1+1-+1 +1-+1 +1~11--+1~1-+1~1-+1~1-+1~11--+1411--+1~1~+~~+-+-+

~-+--+-I-+-I---+-ll--+-+---+-l-+---t-+-i--+---+-+--+I-+-I +1-+-1 +1-+1 +1-+-1 +1-+-1 t---++-+ I 1 1 1 1 I 1 1 I I 1 1 I 1 I 1 1 I 1 I I I I I 1 1 I I I 1 I I I +-+-+-+-+-II--+-+-+--+--t-+-+- t-+-t-1t-+---t----1-+---t----1-f--t--l-+--t--l-+--+-+-+-+-+-+-+-+-+-+-++-+-+-t-+-+--1--1 +1 -+-11--+1 -+-11-+--+1 ~I-+I +1 -+-t--++-H--hH--+I~IH--+I-111-+-1 +1 +-H--fl ++-++++ ++t+-++-t

I I I 1 1 I I 1 I 1 1 1 1 , , 1 ++--+-+-+++-H---+-+--lH--+-+-t--+++-f-+-I--++-+--+-+

I--+---+-+-i-+-I--~-+-+--+-i-+-+-++__+-+-+-+__+-+-+----+__+-+-I--+--+-_+_I--+-+--I , • , , 1 , I I I , I I 1 -+-+

. .

1 2 3 4 5 6 7 8 9 10 11 121314151617181920212223242526272829303132'333 .. 353637.39 .. 0 .. 14243" .... $46 .. 7 .... '50515253545556575859606162636 .. 656667686117071 12 737 .. 757&77117980

PG-3 DIGITAL EQUIPMENT CGRfDOIRA:t"to-N • ~ARO.MA8S"'CHUSETTS ~ -12-1-6l1

Figure 1-1 FORTRAN Coding Form

1-3

(15)
(16)

CHAPTER 2

ELEMENTS OF THE FORTRAN LANGUAGE

2. 1 CONSTANTS

There are five types of constants allowed in the FORTRAN source program: integer, real, double-precision, logical, and Hollerith.

2. 1 • 1 Integer Constants

An integer constant consists of one to six decimal digits written without a decimal point. A + or - sign preced- ing the number is optional. The magnitude of the constant must be less than or equal to 131071 (217

_1).

Examples:

+97

o

-2176 576 If the magnitude>217

-1, an error message will be output. Negative numbers are represented in 21s complement notation.

2. 1.2 Real Constants (Six-decimal-digit accuracy)

A real constant is an integer, fraction, or mixed format number written in the following forms:

a. A constant consisting of one to six significant decimal digits with a decimal point included within the constant. A + or - sign can precede the cotstant; the + sign is optional.

b. A constant followed by the letter E, indicating a decimal exponent, and a one or two digit expo- nent with magnitude less than 76* indicating the appropriate power of 10. A + or - sign can precede the exponent. The decimal point is not necessary in real constants having a decimal exponent.

Examples:

352.

+12.03 -.0054 5.E-3 +5E7

*If the adjusted magnitude exceeds 75, an error results. The constant .999999E75 is legal, but 999. 999E73 is illegal.

2-1

(17)

Real constants are stored in two words in the following format:

LOW ORDER MANTISSA (2'S COMP.) EXPONENT

=:=J

' - - - _ _ - - - J I - - - ,

o 89 17

SIGN OF

+

MANTISSA L.._-'--_ _ _ _ _ _ _ _

HIGH ORDER MANTISSA

~

, _ _ _ _ ---.J

o 17

NOTE

Negative mantissae are indicated with a change of sign.

2.1.3 Double-Precision Constants (nine-decimal-digit accuracy)

A double-precision constant is written as a real number with a decimal exponent I followed by the letter 0 and the one- or two-digit exponent with magnitude not greater than 76. A + or - sign can precede the constant clnd also the exponent. A decimal point within the constant is optional. A double-precision constant is int4~rpreted

the same as a real constant I except that the degree of accuracy is greater.

Examples:

-3.000 987.6542015 32.1230+7

Double-precision constants are stored in three words:

EXPONENT (2'S COMP,)

o

SIGN OF

+

MANTISSA L _ - L -_ _ _ _ _ _ _ _

HIGH ORDER MANTISSA

o

LOW ORDER MANTISSA

o

2-2

-.J

17

NEGATIVE MANTISSAE

~

INDICATED WITH A CHANGE ARE.

17 OF SIGN

-.J

17

(18)

2.1.4 Logical Constants

The two logical constants are the words TRUE and FALSE, each enclosed by periods, with values as indicated below.

.TRUE.

.FALSE.

2.1.5 Hollerith Constants

777777

o

A Hollerith constant is written as an unsigned integer constant, the value of which (n) must be

2:

1 and'=:; 5, followed by the letter H, followed by exactly n characters, which are the Hollerith data. Any FORTRAN character, including blank, is acceptable. The Hollerith constants are used only in CALL and DATA statements and must be associated with real variable names. (For examples, refer to Paragraph 8. 11 • 1 .) ihe Hollerith constants are packed in 7-bit ASCII, five per 1wo words of storage with the rightmost bit always zero.

Examples:

2.2 VARIABLES 1HA 4HA$CD

A variable is a representation of a numeric quantity, the value of which can change by assignment or computa- tion during the execution of a program. The representation, or name, consists of from one to six alphanumeric characters, the first of which must be alphabetic.

Example:

X=Y+10. Both X and Yare variables; X by computation, and Y by assignment in some previous statement.

TEST GAMMA X12345

2.2. 1 Variable Types

NOTE

If three characters or less are used for each symbol, considerable core space can be saved during com- pi lation.

Variables in FORTRAN can represent one of the followi ng types of quantities: integer, real, double-precision, or logical.

2-3

(19)

2.2.2 Integer Variables

Variable names beginning with the letters I, J, K, L, M, or N are considered to be integer variables. If the first letter is not one of the above letters, it 'is an integer variable only if it was named in a previous il1tegel~

type specification statement.

2.2.3 Real Variables

Variable names beginning with letters other than I, J, K, L, M, or N are considered real variables. If the first character is one of the foregoing letters, it is a real variable only if it was named in a previous real type specification statement.

Example:

REAL ITIN

C ITI N WILL BE TREATED AS A REAL VARIABLE SUM=ITIN+ 1

2.:2.4 Double-Precision and Logical Variab~es

A 'type specification statement is the only way to assign a variable value to one of these two types. This is done with either a double precision statement or a logical statement.

2.:3 ARRAYS AND SUBSCRIPTS

An array is an ordered set of data identified by a symbolic name. Each individual quantity in this set of data is referred to in terms of its position within the array. This identifier is called a subscript. For example,

A (3)

represents the third element of a 1-dimension array named A. To generalize further, in an array A witlh n elements, A (I) represents the Ith element of the array A where I = 1, 2, ••• ,n.

FORTRAN allows for 1-, 2-, and 3-dimension arrays; thus, there can be up to three subscripts for the (Irray, each subscript separated from the next by a comma. For example,

B (1, 3)

represents the value located in the first row and the third column of a 2-dimension array named B. A dimens;ion statement defining the size of the array (i .e. I the maximum values each of its subscrip,ts can attain) must pre- cede the array in the source program. (A COMMON statement can also be used for dimensioning.)

2-4

(20)

FORTRAN IV does not check constant subscripts to ascertain that they are positive and nonzero. For example, the following statements are not flagged, although they are illegal.

N(O)=l N(-l)= 1

(These statements are illegal because the array N cannot have a 0 or -1 member.)

2.3. 1 Arrangement of Arrays in Storage

Arrays are stored in column order in ascending absolute storage locations. The array is stored with the first of its subscripts varying most rapidly and the last varying least rapidly. For example, a 3-dimension array A, de- fined in a DIMENSION statement as A (2,2,2), is stored sequentially in this order:

A(l,l,l) A{2,1 ,1) A(1,2,1) A(2,2,1) A(l ,1,2) A(2,1,2) A(1,2,2) A(2,2,2)

2.3.2 Subscript Expressions

ascending absolute storage locations

Subscripts can be written in any of the following forms:

V C V + k V-k C*V C

*

V + k C

*

V - k

where C and k represent unsigned integer constants and V represents an unsigned integer variable.

Example:

I 13

IMOST + 3 ILAST - 1 5

*

IFIRST 2*J+9

4 * Ml - 7

2-5

(21)

2.:3.3 Subscripted Variables

A subscripted variable is a variable followed by a pair of parentheses enclosing one to three subscripts !)eparcJted by commas.

Example:

A

(I) B (I, J - 3)

BETA {5 * J + 9, K + 7, 6 * JOB}

2.4 EXPRESSIONS

An expression is a combination of elements {constants, subscripted or nonsubscripted variables, and fun,etiomi}, each of whi ch is related to another by operators and parentheses. An expression represents one single value that is the result of calculations specified by the values and operators that make up the expression. The FORTRAN language provides two kinds of expressions: arithmetic and logical.

2.4. 1 Arithmetic Expressions

An arithmetic expression consists of arithmetic elements joined by the arithmetic opera~ors +, -, *, /, and '1<'*, which denote addition, subtraction, multiplication, division, and exponentiation, respectively. An expression may consist of a single element {meaning a constant, a variable, or a function name}. An expression enclosled in parentheses is considered a single element. Compound expressions use arithmetic operators to combine single ele!ments.

Examples:

2.71828

Z{N)

TAN{THETA}

{X Y}/2

{X+Y)-{ALPHA *BETA}

(single element: a constant) {single element: a variable}

(single element: a function name)

(single element: because it is enclosed in parentheses)

(compound expression: arithmetic operators combining single elem4~nts)

2.4. 1 • 1 Mode of an Expression - The type of quantities making up an expression determines its mode; e.g. , a simple expression consisting of an integer constant or an integer variable is said to be in the integer mode.

Simi larly, real constants or variables produce a real mode of expression, and double-precision constant!) or variables produce a double-precision mode. The mode of an arithmetic expression is important because it de~er­

mines the accuracy of the expression.

In !~eneral, variables or constants of one mode cannot be combined with variables or constants of anothE~r mode in the same expression. There are, however, exceptions to this rule.

2-6

(22)

a. The following examples show the modes of the valid arithmetic expressions involving the use of the arithmetic operators (+, -, *, and /). I, R, and D indicate integer, real, and double-precision variables or constants. A plus sign (+) is used to indicate anyone of the four operators:

I + I R+R

R+~

D+R D+D

Integer resu It Real result

Double-precision result

b. When raising a value to a power, the mode of the power can be different than that of the value being raised. The following examples show the modes of the valid arithmetic expressions using the arithmetic operator (**). As above, I, R, and D indicate integer, real, and double-precision.

1**1 R**I R**R

Integer result Real resu It

Double-precision result

The subscript of a subscripted variable, which is always an integer quantity, does not affect the mode of the express ion.

2.4.1.2 Hierarchy of Operations - The order in which the operations of an arithmetic expression are to be computed is based on a priority rating. The operator with the highest priority takes precedence over other operators in the expression. Parentheses can be used to determine the order of computation. If no parentheses are used, the order is understood to be as follows:

1. Function reference 2. **(Exponentiation) 3. Unary minus evaluation 4. *(multipl ication), /(division) 5. +(addition), -(subtraction)

Within the same priority, operations are computed from left to right.

Example:

FUNC + A*B/C-D(I,J) + E**F*G-H interpreted as,

FUNC + ((A *B)/C) - D(I, J) +(EF

* G) - H

2.4.1.3 Construction 'of Arithmetic Expressions - The following rules apply to constructing arithmetic expres- sions:

a. Any expression can be enclosed in parentheses.

2-7

(23)

b. Expressions can be preceded by a + or - sign.

c. Simple expressions may be connected to other simple expressions to form a compound expres!;ion, provided that:

(1 ) No two operators appear together.

(2) No operator is assumed to be present.

d. Only val id mode combinations can be used in an expression (Refer to Section 2.4. 1 . 1).

e. The expression must be constructed so that the priority scheme determines the order of operation de- sired (Refer to Section 2.4. 1 .2).

Arithmetic expression examples:

3 A(I) B + 7.3 C*D

A + (B*C) - D**2 + E/F

2.4.2 Relational Expressions

A relational expression is formed with the arithmetic expressions separated by a relational operator. The result value is either TRUE or FALSE depending on whether the condition expressed by the relational operator is met or not met. The arithmetic expressions can both be integer mode expressions or a combina1rion of real/doub le- precision. No other mode combinations are legal. The relational operators must be enclosed by periods. They are:

Examples:

.LT. Less than

«)

• LE. Less than or equal to (~)

• EQ. Equal to (=) .NE. Not equal to (IJ

• GT • Greater than (»

· G E. Greater than or equa I to ~)

N .LT.5

DELTA + 7.3 .LE. B/3E7 (KAPPA + 7)/5 .NE.IOTA 1.736D-4.GT .BETA X.GE. Y*Z**2

2.4.3 Logical Expressions

A logical expression consists of logi cal elements joined by logical operators. The value is either TRUE ()r FALSE. The logical operator symbols must be enclosed by periods.

2-8

(24)

The logical operator symbols are:

• NOT. Logical negation. Reverses the state of the logical quantity that follows •

.AND. Logical AND generates a logical result (TRUE or FALSE) determined by two logical elements as follows:

T .AND. T generates T T .AND. F generates F F .AND. T generates F F .AND. F generates F

.OR. Logical OR generates a logical result determined by two logical elements as follows:

T .OR. T generates T T .OR. F generates T F .OR. T generates T F • OR. F generates F

2.4.3.1 Construction of Logical Expression - The following rules apply to constructing logical expressions:

a. A logical expression can consist of a logical constant, a logical variable, a reference to a logical function, a relational expression, or a complex logical expression enclosed in parentheses.

b. The logi cal operator • NOT. must be followed only by a logi cal expression, whi Ie the logical operators .AND. and • OR. must both be preceded by and followed by a logical expression for more complex logical expressions.

c. Any logi cal expression can be enclosed in parentheses. The logical expression following the logical operator. NOT. must be enclosed in parentheses if it contains more than one quantity.

d. When two logical operators appear in sequence, they must be separated by a comma or parenthesis, unless the second operator is . NOT. In addition, when two decimal points appear together I they must be separated by a comma or parenthesis, unless one belongs to a constant and the other to a relational operator.

2.4.3.2 Hierarchy of Operations - Parentheses can be used as in normal mathematical notation to specify the order of operations. Within the parentheses, or where there are no parentheses, the order in which the opera- tions are performed is as follows:

a. Evaluation of functions b. **(Exponentiation)

c. Evaluation of unary minus quantities d. * and/ (multiplication and division) e. + and - (addition and subtraction) f. • LT., • L E ., • EQ ., • N E ., • G T ., . G E • g. .NOT.

h. .AND. and .OR.

i • = Rep I acement operator

2-9

(25)

Since .AND. and .OR. are of equal priority and are evaluated from left to right, the FORTRAN user must insert his own parentheses when necessary. The following example illustrates equivalent logical expressions according to FORTRAN (Ll, L2, ••• are defined as LOGICAL).

Example:

L 1.AND.L2.0R •• NOT .L3.AND.L4.0R.L5 is equivalent to

«(L1.AND.L2).OR •• NOT.L3) .AND.L4) .OR.L5

To present the foregoing expression as if it were meant to be a sum of products (instead of what FORTRAN inte!rprets it to be) requires enclosing the product terms in parentheses.

Example:

(Ll.AND.L2) .OR.(.NOT .L3.AND.L4) .OR.L5

To express the original example as if it were a product of sums requires enclosing the sum terms in parentheses;.

Example:

Ll.AND.(L2.0R •• NOT .L3) .AND. (L4.0R.L5)

2.5 STATEMENTS

Stat'ements specify the computations required to carry out the processes of the FORTRAN program. Theria are four categories of statements provided for by the FORTRAN language:

a. Arithmetic statements define a numerical calculation.

b. Control statements determine the sequence of operation in the program.

c. Input/output statements are used to transmit information between the computer and related input/

output dev ices.

d. Specification statements define the properties of variables, functions, and arrays appearing in th.e source program. They also enable the user to control the allocation of storage.

2-10

(26)

CHAPTER 3

ARITHMETIC STATEMENTS

An arithmetic statement is a FORTRAN mathematical equation that defines a numerical or logical calculation.

It directs the assignment of a calculated quantity to a given variable. An arithmetic statement has the form

v =

E

where V is a variable (integer, real, double-precision, or logi cal, subscripted or nonsubscripted) or any array element name; = means replacement rather than equivalence, as opposed to the conventional mathematical notation; and E is an expression.

In some cases, the mode of the variable is different from that of the expression. In such cases, an automatic conversion takes place. The fules for the assignment of an expression, E, to a variable, V, are given in Table 3-1 .

V Mode

Integer Integer Integer Real Real Real

Double-precision Double-precision Double-precision Logical

Table 3-1 Assignment Rules

E Mode Assignment Rule

Integer Assign

Real Fix and assign

Doub I e-prec is i on Fix and assign

Integer Float and assign

Real Assign

Double-precision Double-precision evaluate and real assign Integer Double-precision float and assign

Real Double-precision evaluate and assign Double-precision Assign

Logical Assign

3-1

(27)

Mode conversions involving logical quantities are illegal unless the mode of both V and E is logical. Examples of an assignment statement:

ITEM

=

ITEM + 1

A(I)

=

B(I) + ASSIN (C (I) ) V

=

.FALSE.

X

=

A.GT .B.AND.C .LE. G A = B

3-2

(28)

CHAPTER 4 CONTROL STATEMENTS

The statements of a FORTRAN program are normally executed as written. It is frequently desirable, however, to alter the normal order of execution. Control statements give the FORTRAN user this capability. This section discusses the reasons for control statements and their use.

4.1 UNCONDITIONAL GO TO STATEMENTS The form of the unconditional GO TO statement is

GO TO n

where n is a statement number. On execution of this statement, control is transferred to the statement identified by the statement number, n, which is the next statement to be executed.

Example:

GO TO 17

4.2 ASSIGN STATEMENT

The general form of an ASSIGN statement is ASSIGN n TO i

where n is a statement number and i is a nonsubscripted integer variable name that appears in a subsequently executed assigned GO TO statement. The stai"ement number, n, is the statement to which control will be transferred after the execution of the assigned GO TO statement.

Example:

ASSIGN 27 TO ITEST

4.3 ASSIGNED GO TO STATEMENT Assigned GO TO statements have the form

GO TO i I (n 1, n

2, •••• , n m)

4-1

(29)

where i is a nonsubscripted integer variable reference appearing in a previously executed ASSIGN statement, and n

1, n

2, .••• , nm are the statement numbers which the ASSIGN statement may legally assign to i.

Examples:

ASSIGN 13 TO KAPPA

GO TO KAPPA, (1, 13, 72, 100, 35)

There is no object time checking to ensure that the assignment is a legal statement number.

4.4 COMPUTED GO TO STATEMENT The format of a computed GO TO statement is

GO TO (n l' n

2, •... , n m)' i wher,e n l' n

2, .... , nm are statement numbers and i is an integer variable reference the value of which is greater than or equal to 1 and less than or equal to the number of statement numbers enclosed in parentheses.

If the value of i is out of this range, the statement is effectively a CONTINUE statement, however an OTS error statement is also generated.

Example:

GO TO (3, 17, 25,50, 66), HEM

If the value of ITEM is 2 at the time this GO TO statement is executed, the statement to which control is;

transferred is the second statement number in the series, i. e. , statement 17.

4.5 ARITHMETIC IF STATEMENT The form of the arithmeti c IF statement is

IF (e) n1, n2, n3 where e is an arithmetic expression and n

1, n2, n3 are statement numbers. The IF statement evaluates the expression in parentheses and transfers control to one of the referenced statements. If the value of the expres- sion (e) is less than, equal to, or greater than zero, control is transferred to n

1, n2, or n

3, respectively.

Example:

IF (AUB (I) - B*D) 10, 7, 23

4.6 LOGICAL IF STATEMENT

The general format of a logical IF statement is IF (e) s

where e is a logical expression and s is any executable statement other than a DO statement or another logical IF statement. The logi cal expression is evaluated, and different statements are executed depending on w!hethelr the expression is TRUE or FALSE. If the logical expression e is TRUE, statement s is executed and control is thl3n

(30)

transferred to the statement following the IF statement (unless the statement is a GO TO statement or an arith- metic IF statement, in which cases control is transferred as indicated; or the statement s is a CALL statement, in which case control is transferred to the next statement after return from the subprogram). If the logical expres- sion e is false, statement s is ignored and control is transferred to the statement following the IF statement.

Example:

IF (L 1) I

=

I + I

IF (L.LE.k) GO TO 17

IF (LOG.AND. (.NOT.LOG1)) IF (X) 3,5,5

4.7

DO STATEMENT

The DO statement is a command to execute repeatedly a specified series of statements. The general format of the DO statement is

DO n i

=

m1, m2' m3 or

DO n i

=

m 1, m

2

where n is a statement number representing the terminal statement or end of the range; i is a nonsubscripted integer variable known as the index; and m

1, rn

2, and m3 are unsigned nonzero integer constants or nonsub- scripted integer variables, which represent the initial, final and increment values of the index.

NOTE The quantities m

1, m

2,

and m3 must be assigned only positive values.

The range of a DO statement is the series of statements to be executed. It consists of all statements immediately following the DO, up to and including statement n. Any number of statements can appear between the DO and statement n. The terminal statement (statement n) cannot be a GO TO (of any form), an arithmetic IF, a RETURN, a STOP, a PAUSE, or a DO statement, or a logical IF statement containing any of these forms.

The index of a DO is the integer variable i which is controlled by the DO statement in such a way that its initial value is set to m l' and is increased by rn3 each time the range of statements is executed, unti I a further incrementation would cause the value of m

2 to be exceeded. When i is greater than m

2, control passes to the statement following statement n. Throughout the range of the DO, the index is available for computation either as an ordinary integer variable or as the variable of a subscript. The index cannot be changed by any statement within the DO range.

4-3

(31)

The initial value is the value of the index when the range is executed for the first time.,

The final value is the value which the index must not exceed. When this value is reached, the DO is complE!ted and control passes to the first executable statement following statement n.

The increment is the amount by which the index is to be increased after each execution of the range. If the increment is omitted, as in the second form of the DO statement above, its value is assumed to be 1.

Example:

DO 72 I

=

1, 1 0, 2 DO 15 K = 1, 5 DO 23 I = 1, 11, 4

Any FORTRAN statement can appear within the range of a DO statement, including another DO statemElnt.

When such is the case, the range of the second DO must be contained entirely within the range of the fi'rst;

i.e", it is not permissible for the ranges of DOs to overlap. A set of DOs satisfying this rule is called CI nest of DOs. DOs can be nested to a depth of ten. It is possible for a terminal statement to be the terminal state- ment for more than one DO statement. The following configuration, where brackets are used to represent the range of the DOs, indicates the permissible and illegal nesting procedures.

PERMISSIBLE DO

r r = - D O

LL-

DO

ILLEGAL . . . - - - DO

. . . - - - DO

Transfer of control from within the range of a DO statement to outside its range is permitted at any time. ThE~

reverse is not true, however; i.e., control cannot be transferr:ed from outside the range of a DO statemEmt to inside its range. The following examples show both valid and invalid transfers.

VALID

...---~V

INVALID

...---3

C 3

,---5)

---

(32)

4.8 CONTINUE STATEMENT

The CONTINUE statement causes no action and generates no machine coding. It is a dummy statement used for terminating DO loops when the last statement would otherwise be an illegal terminal statement (viz., GO TO, arithmetic IF, RETURN, STOP, PAUSE, or DO I or d logical IF containing any of these forms). The form con- sists of the single word

CONTINUE Example:

D07K START ,END

If(X(K))22, 13,7

7 CONTINUE

4.9

PAUSE STATEMENT

A PAUSE statement is a temporary halt of the program during run time. The PAUSE statement is in one of two forms:

PAUSE or PAUSE n

where n is an octal integer the value of which is less than 777777

8. The integer n is typed out on the console teletype for the purpose of determining which of several PAUSE statements was encountered. Program execution is resumed, by typing control P (tP), starting with the first statement following the PAUSE statement.

4.10 STOP STATEMENT

The STOP statement is of one of two forms:

STOP or STOP n

where n is an octal integer whose value is less than 777777

8• The STOP statement is placed at the logical end of a program and causes the computer to type the integer n on the console teletype, and then to exit back to the

Monitor. There must be at least one STOP statement per main program, but none are allowed in subprograms.

4-5

(33)

4.11 END STATEMENT

The END statement is placed at the physical end of a program or subprogram. The form consists of the single word

END

The END statement is used by the compiler and generates no code. It signals the compiler that the processing of the source program is complete. The compiler assumes the presence of an END statement if it fails to find cine.

A control transfer type statement, a STOP statement, or a RETURN statement must immediately precede END.

This will be checked by the compiler.

4-6

(34)

CHAPTER 5

I NPUT/OUTPUT STATEMENTS

The input/output (I/O) statements direct the transfer of data between the computer and I/O devices. The information thus transmitted is defined as a logical record, which can be formatted or unformatted. A logi cal record, or records, can be written on a devi ce as one or more physical records. This is a function of the size of the logical record and the physical device used.

The definition of the data which comprise a physical record varies with each I/O device (Refer to Table 5-1) .

Unit/Devi ce

Typewriter (i nput and output)

Line printer Cards

(i nput and output) Paper tape (i nput and output) Magnetic tape Disc/drum/Dectape

Table 5-1

Physical Record Definitions

Formatted P hys i ca I Record Definition

One line of type is terminated by a carriage return. Maximum of 72 printing characters per line

One line of printing. Maximum of 120 characters per line

One card. Maximum of 80 characters One line image of 72 printing characters One line image of 630 characters One line image of 630 characters

Unformatted (Binary) Physical Record Definition

Undefined

Undefined 50 words 50 words 252 words :2.5'~

252 words ~5l

Each I/O device is identified by an integer constant which is associated with a device assignment table in the Monitor. This table may be modified at system generation time, or just before run time. For example, the statement

READ (u,f) list

requests one logical record from the device associated with slot u in the device assignment table.

5-1

(35)

The statement descriptions in this section use u to identify a specific I/O unit, f as ,the statement number of the FORMAT statement describing the type of data conversion, and list as a list of argumen1's to be input or output.

5. 1 GENERAL I/O STATEMENTS

These statements cause the transfer of data between the computer and I/O devices.

5. 1 • 1 Input/Output Argument Lists

An I/O statement which calls for the transmission of information includes a list of the quantities to be trans- mitted. In an input statement, this list consists of the variables to which the incoming data is to be assi<gned; in an output statement, the I ist consists of the variables the values of which are to be transmitted to the given I/O deviice. The order of the I ist must be that in which the data words exist (input) or are to exist (output) on the I/O device. Any number of items can appear in a single list. The same statement can transmit integer .::md mal quantities. If the data to be transmitted exce€ids the items in the list, only the number of quantiti es equal to the number of items in the I ist are transmitted. The remaining data is ignored. Conversely, if the items in 'the list exceed the data to be transmitted, succeeding superfluous records are transmitted until all items specified in t'he I ist have been transmitted.

5. 1 • 1 • 1 Simple Lists - The list uses the form C1,C

2, .... ,C n

where each C. is a variable, a subscripted variable, or an array identifier. Constants Clre not allowed as list

I

items. The list reads from left to right. When an array identifier appears in the list, the entire array is to be·

transmitted before the next item in the list.

Examples:

Y,Y,Z

A, B (3), C, D (I + 1, 4)

5. 1. 1.2 DO-Implied Lists - Indexing similar to that of the DO statement can be used to control the number of

timE~s a group of simple lists is to be repeated. The list elements, thus controlled, as well as the index contro·1 itsellf, are enclosed in parentheses, and the entire enclosure is regarded as a single item of the I/O list.

Example:

W, X (3), (Y (I), Z (I,K), I == 1, 10)

5-2

(36)

5. 1 .2 READ Statement

The READ statement is used to transfer data from any input device to the computer. The general READ statement can be used to read either BCD or binary information. The form of the statement determines what kind of input is performed.

5. 1 .2. 1 Formatted READ - T he formatted READ statement has the genera I form READ (u,f) list

or READ (u,f)

Execution of this statement causes input from device u to be converted as specified by format statement f, and the resulting values to be assigned to the items specified by list, if any.

Examples:

READ (3, 13) A,B,C

READ (2, 10) A, (B (I), I

=

1,5) READ (1,3)

5. 1 .2.2 Unformatted READ - An unformatted READ statement has the general form READ (u) list

or READ (u)

Execution of this statement causes input from device u, in binary format, to be assigned to the items specified by list. If no I ist is given, one record is read, but ignored. If the record contains more information words than the list requires, that part of the record is lost. If more elements are in the list than are in one record, additional records are read until the list is satisfied.

Examples:

READ (5) I,J,K READ (8)

5. 1 .3 WRITE Statement

The WRITE statement is used to transmit information from the computer to any I/O device. The WRITE statement closely parallels the READ statement in both format and operation.

5-3

(37)

5. 1 .3.1 Formatted WRITE - The formatted WRITE statement has the general form WRITE (u,f) list

or WRITE (u ,f)

Execution of this statement causes the I ist elements, if any, to be converted according to format statement f, and output onto device u.

5.1.3.2 Unformatted WRITE - The unformatted WRITE statement has the general form WRITE (u) list

Execution of this statement causes output onto device u, in binary format, of all words specified by the liist. If the list elements do not fill the record, the remaining part of the record is filled with blanks. If the list elemEmts more than fill one record, successive records are written until all elements of the list are satisfied, and the last record is padded, with blanks if necessary.

Examples:

WRITE (1, 10) A, (B (I), (C (I,J), J=2, 10,2), 1=1,5) WRITE (2,7) A,B,C

WRITE (5) W,X(3), Y(I + 1,4),Z

5.2 FORMAT STATEMENTS

These statements are used in conjunction with the general I/O statements. They specify the type of conversior.1 which is to be performed between the internal machine language and the external notation. FORMAT statements are not executed; their function is to supply information to the object program.

5.2." Specifying FORMAT

The general form of the FORMAT statement is FORMAT (Sl' S2' .••. , Sn)

where Sl •..• Sn are data field descriptors. Breaking this format down further, the basic data field descriptor i~;

written in the form nkw.d

where n is a posit'ive unsigned integer indicating the number of successive fields for which the data conversion is to Ibe performed according to the same specification. This is also known as the repeat count. If n is eClual M 1, it can be omitted. The control character, k, indicates which type of conversion is to be performed. This character can be I,E,F,G,D,P,L,A,H, or X. The nonzero integer constant, w, specifies the width of the field. The integer constant, d, indicates the number of digits to the right of the decimal point.

(38)

Six of the nine control characters listed above provide for data conversion between internal machine language and external notation.

Internal Integer variable Real variable Real variable Real variable Double-precision variable

Logical variable Alphanumeric

E F G D L A

External Dec i ma I integer Floating-point, scaled Floating-point, mixed Floating-point, mixed/scaled Floating-point, scaled Letter T or F

Alphanumeric (BCD) characters

The other three control types are special purpose control characters:

P Used to set a scale factor for use with E, F, and D conversions.

X Provides for skipping characters in input or specifying blank characters in output.

H Designates Hollerith fields.

Although FORMAT statements generate code, they are not executed and therefore can be placed anywhere in the source program following all specification statements. Because FORMAT statements are referenced by READ or WRITE statements, each FORMAT statement must be given a statement number.

The comma (,) and slash (/) are used as field separators. The comma is used to separate field descriptors;

however, it need not follow a field specified by an H or X control character. The slash is used to specify the termination of formatted records. A series of slashes is also a field separator. Multiple slashes are the equiva- lent of blank records between output records, or records skipped for input records. If a seri es of n slashes occurs at the beginning or end of the FORMAT specifications, the number of input records skipped or blank lines in- serted in output is n. If the series of n slashes occurs in the middle of the FORMAT specifications, this number is n-l. A comma cannot precede/follow a slash. An integer value cannot precede a slash.

For all field descriptors (with the exception of H and X), the field width must be specified. For those descriptors of the w.d type (paragraph 5.2.2.2), the d must be specified even if it is zero. The field width must be large enough to provide for all characters (including decimal point and sign) necessary to constitute the data value as well as blank characters needed to separate it from other data values. The data value within a field is right

justified; thus, the most significant characters of the value are lost if the field specified is too small.

5-5

(39)

Successive items in the I/O list are transmitted according to successive descriptors in the FORMAT statement, untill the entire I/O list is satisfied. If the list contains more items than there are descriptors in the FORMAT state!ment, a new record must be begun. Control is transferred to the preceding left parenthesis, where the same specifications are used again until the list is complete.

Field descriptors (except H and X) are repeated by preceding the descriptor with an unsigned, nonzero integer constant (the repeat count). A group repeat count is used to enable the repetition of a group of field de!icriptlors or field separators enclosed in parentheses. The group count is placed to the left of the parenthesis. Two levlels of parentheses (not including those enclosing the FORMAT specification) are permitted.

The field descriptors in the FORMAT must be the same type as the corresponding items in the I/O list; i .'9., integer quantities require integer (I) conversion; real quantities require real (E or F) conversion, etc.

Examples:

READ (I, 100) I, A

FORMAT (I7,F10.3)

FORMAT (13, I7/E10.4,E10.4) FORMAT (214, 3(I5,D10.3) )

5.2.2 Conversion of Numeric Data

5.2.2.1 I-Type Conversion (Field descriptor: Iw or nlw) - The number of characters specified by w is c:on- verted to a decimal integer.

On input, the number specified by w in the input field is converted to a binary integer. A minus sign indicat'9s a negative number. A plus sign, indicating a positive number, is optional. The decimal point is illegal. If there are blanks, they must precede the sign or first digit. All imbedded blanks are interpreted as zero digits"

On output, the converted number is right justified. If the number is smaller than the field w allows, the left-, most spaces are fi lied with blanks. If an integer is too large the most significant digits are truncated and lost..

Negative numbers have a minus sign immediately preceding their most significant digit if sufficient SpaCE!S have been reserved. No sign indicates a positive number.

5-6

(40)

Examples (b indicates blank):

Format Descriptor

15 13 18

bbbbb -b5 bbb12345

Internal

+00000 -05 +12345

bbbbO b-5 bbb12345

5.2.2.2 E-Type Conversion (Field descriptor: Ew.d or nEw .d) - The number of characters specified by w is converted to a floating-point number with d spaces reserved for the digits to the right of the decimal point. The w inc ludes field d, spaces for a sign, the decimal point, plus four spaces for the exponent (written E ± XX) in addition to space for optional sign and one digit preceding the decimal point.

The input format of an E-type number consists of an optional sign, followed by a string of digits containing an optional decimal point, followed by an exponent. Input data can be any number of digits in length, although it must fall within the range of 0 to ± 10 ± 39.

E output consists of a minus sign if negative (blank if positive), the digit 0, a decimal point, a string of digits rounded to d significant digits, followed by an exponent of the form E ± XX.

Examples:

Format Descriptor Input Internal Output

E10.4 00.2134E03 213.4 0.2134E+03

E9.4 0.2134E02 21.34 .2134E+02

E10.3 bb-23.0321 -23.0321 -0.230E+02

5.2.2.3 F-Type Conversion (Field descriptor: Fw.d or nFw.d) - The number of characters specified by w is converted to a floating-point mixed number with d spaces reserved for the digits to the right of the decimal point.

Input for F-type conversion is basically the same as that for E-type conversion, described in paragraph 5.2.2.2.

The output consists of a minus sign if the number is negative (blank if positive), the integer portion of the num- ber, a decimal point, and the fractional part of the number rounded to d signifi cant digits.

5-7

(41)

Examples:

Format Descriptor !nput Internal Output

F6.3 b13457 13.457 13.457

F6.3 313457 313.457 13.457

F9.2 -21367. -21367. -21367.00

F7.2 -21367. -21367. 1367.00

5.2.2.4 G-Type Conversion (Field descriptor: Gw.d or nGw.d) - The external field occupies w positions with d significant digits. The value of the list item appears, or is to appear, internally as a real number.

Input for G-type conversion is basically the same as that for E-type conversion, described in paragraph 5.2.2.2.

The form of the G-type output depends on the magnitude of the internal floating-poi nt number. Comparison is made between the exponent (e) of the internal value and the number of significant digits (d) specified by the format descriptor. If e is greater than d, the E-type conversion is used. If e is less than or equal to d ,~he

F-type conversion is used, but modified by the following formula:

F (w-d). (d-e) ,4X

The 4X represents four blank spaces that are always appended to the val ue. If the value to be represented is less than. 1 , the E-type conversion is always used.

Examples:

Format Descriptor

G14.6 G14.6 G14.6 G14.6

Internal

· 12345678 x 10-1

· 12345678 x 100

• 12345678 x 104

· 12345678 x 10 8

O. 12345678E -01 bbO. 123456bbbb bbb1234.56bbbb bbO.123456E+08

5.2.2.5 D-Type Conversion (Field descriptor: Dw.d or nDw.d) - The number of characters specified by w is converted to a double-precision floating-point number with the number of digits specified by d to the right of the decimal point.

The input and output are the same as those for E-type conversion except that a D is used in place of the E in the exponent.

Referenzen

ÄHNLICHE DOKUMENTE

During the ninety (90) day period after installation, if the customer encounters a problem with the current unaltered release of the SOFTWARE which DIGITAL

Post-warranty Software Product Services for this soft- ware product are available with the prerequiSite being the purchase of the RSTS/E Self-Maintenance Service for

Upon notification by customer to the nearest DIGITAL office that the computer system, including all required prerequisite hardware and software, is ready for the

Upon notification by customer to the nearest DIGITAL office that the computer system, including all required prerequisite hardware and software, is ready for the

All source licensed software is furnished only under the terms and conditions of a separate Software Pro- gram Sources License Agreement between Purchaser and DIGITAL. Options

During the ninety (90) day period after installation, if the customer encounters a problem with the current unaltered release of the SOFTWARE which DIGITAL

Durtng the ninety (90) day period after installation, if the customer encounters a problem with the current unaltered release of the SOFTWARE which DIGITAL

When executed on remote RSX-11 M or RSX-11 S target systems, FORTRAN IV generated code can be selected to support the following arithmetic hardware options:. • KE11-A