# Full text of "cdc :: cyber :: lang :: fortran :: 60101500B 6600 Programming System Vol3 FORTRAN66 1965"

## See other formats

CONTROL DATA® 6600 Computer System Programming System/ Reference Manual n ^viSSCiSstftir* 1 PIT SECOND EDITION! • m i €) PREFACE The FORTRAN*-66 language contains most of the features of FORTRAN-63. The FORTRAN-66 compiler adapts current techniques to the particular capabilities of the Control Data® 6600 Computer System. Emphasis has been placed on producing highly efficient object programs while maintaining the efficiency of compilation. This reference manual was written as a text for advanced FORTRAN-66 classes and as a reference manual for programmers using the FORTRAN-66 system. The manual assumes a basic knowledge of the FORTRAN language. • * FORTRAN is an abbreviation for FORmula TRANslation and was originally developed for International Business Machine equipment. ^^. • TABLE OF CONTENTS 1. ELEMENTS OF FORTRAN 66 1.1 CONSTANTS 1-1 1.2 VARIABLES 1-2 1.3 STATEMENTS 1-4 1.4 EXPRESSIONS 1-4 2. ARITHMETIC EXPRESSIONS AND REPLACEMENT STATEMENTS 2.1 ARITHMETIC REPLACEMENT STATEMENTS 2-1 2.2 ARITHMETIC EXPRESSIONS 2-1 2.3 MIXED MODE ARITHMETIC EXPRESSIONS 2-2 2.4 MIXED MODE REPLACEMENT STATEMENT 2-3 3. LOGICAL/RELATIONAL AND MASKING EXPRESSIONS AND REPLACEMENT STATEMENTS 3.1 LOGICAL EXPRESSION 3-1 3.2 RELATIONAL EXPRESSION 3-2 3.3 MASKING REPLACEMENT STATEMENT 3-3 3.4 MASKING EXPRESSIONS 3-3 3.5 MULTIPLE REPLACEMENT STATEMENTS 3-4 4. TYPE DECLARATIONS AND STORAGE ALLOCATIONS 4.1 TYPE DECLARATIONS 4-1 4.2 DIMENSION 4-2 4.3 COMMON 4-2 4.4 COMMON BLOCKS 4-2 4.5 EQUIVALENCE 4-3 4.6 DATA 4-4 4.7 BANK 4-5 5. CONTROL STATEMENTS 5.1 STATEMENT IDENTIFIERS 5-1 5.2 GO TO STATEMENTS 5-1 5.3 IF STATEMENTS 5-1 5.4 FAULT CONDITION STATEMENTS 5-2 5.5 DO STATEMENT 5-3 5.6 CONTINUE 5-5 5.7 PAUSE 5-5 5.8 STOP 5-5 5.9 END 5-5 6. FUNCTIONS AND SUBPROGRAMS 6.1 MAIN PROGRAM AND SUBPROGRAMS 6-1 6.2 FUNCTION SUBPROGRAM 6-1 m 6.3 LIBRARY FUNCTIONS 6-2 6.4 EXTERNAL STATEMENTS 6-2 6.5 STATEMENT FUNCTIONS 6-3 6.6 SUBROUTINE SUBPROGRAM 6-4 6.7 CALL 6-4 6.8 PROGRAM ARRANGEMENT 6-6 6.9 RETURN AND END 6-6 6.10 ENTRY 6-6 6.11 VARIABLE DIMENSIONS IN SUBPROGRAMS 6-7 7. FORMAT SPECIFICATIONS 7.1 THE I/O LIST 7-1 7.2 FORMAT STATEMENT 7-2 7.3 FORMAT SPECIFICATIONS 7-2 7.4 CONVERSION SPECIFICATIONS 7-2 7.5 EDITING SPECIFICATIONS 7-8 7.6 nP SCALE FACTOR 7-10 7.7 REPEATED FORMAT SPECIFICATIONS 7-11 7.8 VARIABLE FORMAT 7-11 8. INPUT/OUTPUT STATEMENTS 8.1 WRITE STATEMENTS 8-1 8.2 READ STATEMENTS 8-1 8.3 BUFFER STATEMENTS 8-2 8.4 TAPE HANDLING STATEMENTS 8-2 8.5 STATUS CHECKING STATEMENTS , 8-3 8.6 ENCODE/DECODE STATEMENTS , 8-3 APPENDIX A CODING PROCEDURES A-l APPENDIX B CHARACTER CODES 6600 COMPUTER B-l APPENDIX C STATEMENTS OF FORTRAN-66 C-l APPENDIX D LIBRARY FUNCTIONS D-l APPENDIX E QUANTITIES AND WORD STRUCTURE E-l APPENDIX F PROGRAM SEGMENTATION F-l APPENDIX G FORTRAN ERROR PRINTOUTS G-l # H) IV €) 6600 COMPUTING SYSTEM Main frame (center) — contains 10 peripheral and control processors, central processor, central memory, some I/O synchronizers. Display console (foreground) — includes a keyboard for manual input and operator control, and two 1 0-inch display tubes for display of problem status and operator directives. CONTROL DATA 607 tapes (left front)— V2 inch magnetic tape units for supplementary storage; binary or BCD data handled at 200, 556, or 800 bpi. CONTROL DATA 626 tapes (left rear)— 1 -inch magnetic tape units for supplementary storage; binary data handled at 800 bpi. Disc file (right rear) — Supplementary mass storage device holds 500 million bits of information. CONTROL DATA 405 card reader (right front)— reads binary or BCD cards at 1200 card per minute rate. l 9 # • SYSTEM ORGANIZATION The CONTROL DATA® 6600 is a large-scale, solid- state, general-purpose digital computing system. The advanced design techniques incorporated in the system provide for extremely fast solutions to data processing, scientific and control center prob- lems. Within the 6600 are eleven independent computers (Fig. 1). Ten of these are constructed with the pe- ripheral and operating system in mind. These ten have separate memory and can execute programs independently of each other or the central processor. The eleventh computer, the central processor, is a very high-speed arithmetic device. The common element between these computers is the large central memory. 4096 WORD CORE MEMORY 1 ' 4096 WORD 1 CORE MEMORY 1 PERIPHERAL a CONTROL PROCESSOR PERIPHERAL a CONTROL PROCESSOR 4096 WORD CORE MEMORY 4096 WORD CORE MEMORY PERIPHERAL a CONTROL PROCESSOR i > PERIPHERAL a CONTROL PROCESSOR 6600 CENTRAL MEMORY ■ >■ (E O ■ 2 UJ 2 -l < K 1- Z 111 o o o 8. 6600 CENTRAL PROCESSOR at 8 o m z -I TO > ' r Z m 2 O 3) -C 4096 WORD CORE MEMORY 4096 WORD CORE MEMORY PERIPHERAL a CONTROL PROCESSOR PERIPHERAL a CONTROL PROCESSOR 6600 CENTRAL MEMORY 4096 WORD CORE MEMORY 4096 WORD CORE MEMORY t 1 i L PERIPHERAL a CONTROL PROCESSOR PERIPHERAL a CONTROL PROCESSOR 1 4096 WORD 1 CORE MEMORY 4096 WORD ' 1 CORE MEMORY 1 PERIPHERAL a CONTROL PROCESSOR PERIPHERAL a CONTROL PROCESSOR Figure 1 CONTROL DATA 6600 vn 12 INPUT OUTPUT CHANNELS ADD | MULTIPLY | UPPER BOUNDARY CENTRAL MEMORY MULTIPLY DIVIDE 24 OPERATING REGISTERS >] LONG ADD~ LOWER BOUNDARY SHIFT BOOLEAN INCREMENT BRANCH PERIPHERAL & CONTROL PROCESSORS CENTRAL PROCESSOR % CENTRAL MEMORY - 131,072 words — 60-bit words — Memory organized in 32 logically independent banks of 4096 words with corresponding multi- phasing of banks — Random access, coincident-current, magnetic core — One major cycle for read-write — Maximum memory reference rate to all banks — one address/minor cycle — Maximum rate of data flow to/from memory — one word/minor cycle DISPLAY CONSOLE — Two display tubes — Modes Character Dot — Character size Large — 16 characters /line Medium — 32 characters/line Small — 64 characters/line — Characters 26 alphabetic 10 numeric 11 special Figure 2 BLOCK DIAGRAM OF 6600 VI 11 I 1. ELEMENTS OF FORTRAN-66 1.1 CONSTANTS Four basic types of constants are used in FORTRAN-66: integer, octal, floating point and Hollerith. Complex and double precision constants can be formed from floating point constants. The type of a constant is determined by its form. The computer word structure for each type is given in Appendix E. 1.1.1 INTEGER Integer constants may consist of up to 18 decimal digits, in the range from — (2 s " — 1) to (2 S!I — 1). Integer multiply and divide are executed in floating point modules. No double precision is performed on integer values; if multiply and divide a re specified, operands and result will be taken modular 2 4T . Examples: 63 -247 314159265 3647631 464646464 1.1.2 OCTAL Octal constants may consist of up to 20 octal digits. The form is: n x — n,B Examples: 77777777000000000000B 7777700077777B 23232323232323232323B 77B 7777777777777700B 1.1.3 FLOATING POINT Real constants are represented by a string of up to 15 digits. A real constant may be expressed with a decimal point or with a fraction and an exponent representing a power of ten. The forms of real con- stants are: nE n.n n. ,n nE±s n.nEzbs n.E±s .nE±s n is the coefficient; s is the exponent to the base 10. The plus sign may be omitted for positive s. The range of s is through 308. Examples: 3.1415768 314. .0749162 314159E-05 31.41592E-01 .31415E01 .31415E + 01 Double precision constants are represented by a string of up to 29 digits. The forms are: nD±s ,nD±s nD n.nD n.D .nD n.nD±s n.Dzts n is the coefficient; s is the exponent to the base 10. The D must always appear. The plus sign may be omitted for positive s; the range of s is through 308. Examples: 3. 1415926535897932384626D 3.1415D 3.1415D0 3141.598D-03 31415.D-04 379867524430111D + 01 Complex constants are represented by pairs of real constants separated by a comma and enclosed in parentheses (R T , R 2 ). The real part of a complex number is represented by R 1( the imaginary part by R 2 . Either constant may be preceded by a — sign. Examples: FORTRAN-66 Representation (1., 6.55) (15., 16.7) (-14.09, 1.654E-04) (0., -1.) Complex Number l. + 6.55i 15. + 16.7i - 14.09 +.0001654i 1.1.4 HOLLERITH A Hollerith constant is a string of alphanumeric 1-1 characters of the form hHf; h is an unsigned deci- mal integer representing the length of the field f and must be 10 or less characters except when used in a format statement. Spaces are significant in the field f . When h is not a multiple of 10, the last computer word is left-justified with BCD spaces filling the remainder of the word. An alternate form of a Hollerith constant is hRf. When h is less than or equal to 10, the computer word is right-justified with zero fill. When h is greater than 10 only the first 10 characters are retained and the excess characters are discarded. Examples: 6HCOGITO 4HERGO 3HSUM 8RCDC 6600 8R ** 1R) 1.2 VARIABLES FORTRAN-66 recognizes simple and subscripted variables. A simple variable represents a single quantity; a subscripted variable represents a single quantity within an array of quantities. The variable is either defined in a TYPE declaration or determined by the first letter of the variable name. A first letter of I, J, K, L, M, or N indicates a fixed point (integer) variable; any other first letter indicates a floating point variable. However, a TYPE declaration over- rides any other naming convention. (See Section 4-1.) 1.2.1 SIMPLE A simple variable is the name of a storage area in which values can be stored. The variable is refer- enced by the location name; the value specified by the name is always the current value stored in that location. Simple integer variables are identified by at least one or up to 8 alphabetic or numeric characters; the first must be I, J, K, L, M, or N. Any integer value in the range from -(2 5B -1) to 2 59 -1 may be as- signed to a simple integer variable. Examples: N NOODGE K2S04 M58 LOX M58 Since spaces are ignored in variable names, M58 and M 58 are identical. Simple -floating point variables are identified by at least one or up to 8 alphabetic or numeric charac- ters; the first must be alphabetic and not I, J, K, L, M, or N. Any value from 10" 308 to 10 308 and zero can be assigned to a simple floating point variable. A TYPE declaration overrides any other naming con- vention. Examples: VECTOR BAGELS A65302 BATMAN 1.2.2 SUBSCRIPTED VARIABLE ARRAYS A subscripted variable represents an element of an array. An array is a block of successive memory locations which is divided into areas for storage of variables. Each element of the array is referenced by the array name plus a subscript. The type of an array is determined by the array name or TYPE declaration. Arrays may have one, two, or three dimensions and the maximum number of elements is the product of the dimensions. A subscript can be an integer constant, an integer variable, or any integer expression. Any other constant, variable, or expression will be reduced to an integer value. The array name and its dimensions must be declared at the beginning of the program in a DIMENSION statement (section 4.2). Array structure. Elements of arrays are stored by columns in ascending order of storage location. In the array declared as A(3,3,3): Am A121 A131 A211 A221 A23I A311 A321 A3SI A112 A 12 2 A132 A 212 A 2 22 A232 A3 12 A322 A332 A113 A123 A133 A213 A223 A233 A313 A323 A333 % 1-2 The planes are stored in order, starting with the first, as follows: A m -^L A 121 -*L+3 ... A 133 ->L+24 A 211 -^L+1 A 221 ->L+4 . . . A 233 -h>L+25 A 311 -»L+2 A 321 -^L+5 . . . A 333 -^L+26 Program errors may result if subscripts are larger than the dimensions initially declared for the array. A single subscript notation may be used for a two or three dimensional array if it does not exceed the product of the declared dimensions. 1.2.3 SUBSCRIPT FORMS Subscripted integer variables, the elements of an integer array, may be assigned the same values as simple integer values. An integer array is named by an integer variable name (1 to 8 alphabetic or numeric characters, the first of which is I, J, K, L, M, or N), or is designated integer by a TYPE INTEGER statement. NEURON (6, 8, 6) MORPH (20,20) L6034 (J, 3) N3 (1) ^^ Subscripted floating point variables, the elements of a floating point array, may be assigned the same values as simple floating point variables. A floating point variable array is named with a floating point variable name (1 to 8 alphabetic or numeric charac- ters, the first of which is alphabetic and not I, J, K, L, M, or N), or is designated floating point by a TYPE REAL statement. TMESIS (6, 4, 7) YCLEPT (46) PST (6, 8) SVELTE (37, 24, 35) Any computable arithmetic expression may be used as a subscript. A (I, J) A(MAXF(I, J, M) ) B (I + 2,J + 3,2*K+1) B(J, ATANF(J) ) Q (14) C(I+K) P(KLIM, JLIM + 5) MOTZO (3*K*ILIM + 3.5) SAM (J -6) WOW(I(J(K) ) ) The location of an array element with respect to the first element is a function of the maximum array dimensions and the type of the array. Given DI- MENSION A(L, M, N) the location of A (i, j, k), with respect to the first element A of the array, is given by A+{i-l+L(j-l+M(k-l))}*E The quantity in braces is the subscript expression. If it is not an integer value, it is truncated after evaluation. E is the element length, that is, the number of stor- age words required for each element of the array; for real and integer arrays, E = 1. (See Appendix E) 1. Referring to the matrix in 1.2.2, the location of A (2,2,3) with respect to A (1,1,1) is: Locn (A(2,2,3)} = Locn {A(l,l,l) } + {2-1+3(1 + 3(2))} = L+22 2. Given DIMENSION Z (5,5,5) and 1 = 1, K= 2, X=45°, A=7.29, B = 1.62. The location, z, of Z (I*K, TANF(X), A-B) with resrject to Z U.1,1) is: z = Locn (Z(l,l,l)) + (2-1 + 5 ([TANF(X)] -l + 5[4.67])) = Locn (Z(l,l,l)) + (2-1 + 5 (1-1 + 5*4)) = Locn (Z(l,l,l))+ 101 FORTRAN-66 permits the following relaxation of the representation of subscripted variables: Given A(D 1; D 2 ,D 3 ): where the Di are integer constants, then A(I,J,K) implies A(IJ,K) A(IJ) implies A(I,J,1) A(I) implies A(I,1,1) A implies A(l,l,l) similarly, for A(D 1: D 2 ) A(I,J) implies A(I,J) A(I) implies A(I,1) A implies A(l,l) and for A(D a ) A implies A(l) However, the elements of a single-dimension array 1-3 A(DO may not be referred to as A(IJ,K) or A(IJ). Array allocation is discussed under Storage Alloca- tion in Section 4. 1.3 STATEMENTS The FORTRAN-66 elements are combined to form statements. An executable statement performs a cal- culation or directs control of the program; a non- executable statement provides the compiler with information regarding variable structure, array allo- cation, storage sharing requirements. 1.4 EXPRESSIONS An expression is a constant, variable (simple or sub- scripted), function (section 7.2) or any combination of these separated by operators and parentheses, written to comply with the rules given for con- structing a particular type of expression. There are four kinds of expressions in FORTRAN- 66: arithmetic and masking (Roolean) expressions which have numerical values, and logical and rela- tional expressions which have truth values. For each type of expression, there is an associated group of operators and operands. • ♦ 1-4 fj 2. ARITHMETIC EXPRESSION AND REPLACEMENT STATEMENTS 2.1 ARITHMETIC REPLACEMENT STATEMENTS The general form of the arithmetic replacement statement (arithmetic statement) is A^E, where E is an arithmetic expression and A is any variable name, simple or subscripted. The operator = means that A is replaced by the value of the evaluated ex- pression, E, with conversion for mode if necessary. 2.2 ARITHMETIC EXPRESSIONS An arithmetic expression can contain the following operators : OPERATOR MEANING + addition — subtraction * multiplication / division * * exponentiation Operands are: Constants Variables (simple or subscripted) Functions (see Chapter 7) Examples: A 3.141592 B + 16.8946 (A-B(IJ+K) ) G*C(J)+4.1/(Z(I+J,3*K))*SINF(V) (Q+V(M,MAXF(A,B) )*Y**2)/(G*H-F(K+3) ) -C + D(IJ)*13.627 Any variable (with or without subscripts), constant, or function is an arithmetic expression. These enti- ties may be combined by using the arithmetic op- erators to form algebraic expressions. Rules: 1. An arithmetic expression may not contain adja- cent arithmetic operators: X op op Y 2. If X is an expression, then (X), ( (X) ), et cetera, are expressions. 3. If X, Y are expressions, then the following are expressions: X+Y X/Y X-Y X*Y 4. Expressions of the form X**Y and X**( — Y) are legitimate, subject to the restrictions in sec- tion 2.3. 5. The following forms of implied multiplication are permitted: constant (...) implies constant* (...) (...)(...) implies (.. .)*(...) (...) constant implies ( . . . )* constant (...) variable implies ( . . . )*variable 2.2.1 ORDER OF EVALUATION The hierarchy of arithmetic operation is: ** exponentiation class 1 / division class 2 * multiplication + addition class 3 — subtraction In an expression with no parentheses or within a pair of parentheses, in which unlike classes of op- erators appear, evaluation proceeds in the above order. In those expressions where operators of like classes appear, evaluation proceeds from left to right. For example, A**B**C is evaluated as (A**B)**C. In parenthetical expressions within parenthetical expressions, evaluation begins with the innermost expression. Parenthetical expressions are evaluated as they are encountered in the left to right scanning process. When writing an integer expression, it is important to remember not only the left to right scanning process, but also that dividing an integer quantity by an integer quantity always yields a truncated 2-1 result; thus 11/3 = 3. The expression I*J/K may yield a different result than the expression J/K*I. For example, 4*3/2 = 6 but 3/2*4=4. Examples: In the following examples, R indicates an inter- mediate result in evaluation: A**B/C + D*E*F — G is evaluated: ->Ri -^R 2 -*R 3 ^R 4 ^R 5 -» R 6 Evaluation completed A**B/(C + D)*(E*F-G) is evaluated: A**B Rx/C D*E R 3 *F R 4 + R 2 R s -G A**B C+D E*F-G R1/R2 R 4 *R 3 ->Ri ^■R 2 -*R 3 Evaluation completed If the expression contains a function, the function is evaluated first. H(13) + C(IJ + 2)*(COSF(Z))**2 is evaluated: COSF(Z) ->Rx Ri ** 2 ^r 2 R 2 *C(IJ+2)-+R 3 R 3 + H(13) ->R 4 Evaluation completed The following is an example of an expression with embedded parentheses. A*(B + ((C/D)-E)) is evaluated: C/D ^R t R t -E -^R 2 R,+B -h>R 3 R 3 *A -»R, Evaluation completed A*(SINF(X) + 1.)-Z/(C*(D-(E + F) ) ) is evaluated: SINF(X) ->Ri Rx + 1 ^R 2 E + F -^R 3 D-R 3 ->IU C*R. t ^R 5 Z/R 5 ^Re A * R 2 ^•R T r 7 -r 5 -»R 8 • Evaluation completed 2.3 MIXED MODE ARITHMETIC EXPRESSIONS FORTRAN-66 permits full mixed mode arithmetic. Mixed mode arithmetic is accomplished through the special library subroutines. In the 6600 com- puter system, these routines include complex arith- metic. The five standard operand types are com- plex, double, real, integer, and logical. Mixed mode arithmetic is completely general; how- ever, most applications will probably mix operand types, real and integer, real and double, or real and complex. The following rules establish the relation- ship between the mode of an evaluated expression and the types of the operands it contains. Rules: 1. The order of dominance of the standard oper- and types within an expression from highest to lowest is: COMPLEX DOUBLE REAL INTEGER LOGICAL 2. The mode of an evaluated arithmetic expres- sion is referred to by the name of the dominant operand type. 3. In expressions of the form A**B, the following rules apply: • B may be negative in which case the form is : A**(-B). • For the standard types (except logical) the mode/type relationships are: •> 2-2 m • T y p e Type B I R D C I I R D C R R R D C D D D D C C C C C C mode of A**B For example, if A is complex and B is real, the mode of A**B is complex. 2.3.1 EVALUATION 1. Given A, B type real; I, J type integer. The mode of expression A*B — I + J will be real be- cause the dominant operand is type real. It is evaluated: Convert I to real Convert J to real A^^-^Rj real Rx-I^R;. real R = + J-^R 3 real Evaluation completed 2. The use of parentheses may change the eval- uation. A,B,IJ are defined as above. A*B — (I — J) is evaluated: I — J-»Ri integer Convert Rj to real -> R 2 A*B-»R 3 real R 3 — R 2 -> R.j real Evaluation completed 3. Given C1,C2 type complex; A1,A2 type real. The mode of expression A1*(C1/C2) + A2 is complex because its dominant operand is type complex. It is evaluated: C1/C2->R 1 complex Convert Al to complex Convert A2 to complex A1*R X -»R 2 complex R 2 + A2-> R 3 complex Evaluation completed 4. Consider the expression C1/C2+(A1 — A2) where the operands are defined as in 3 above. It is evaluated: Al-A2^Ri real Convert R x to complex -» R 2 C1/C2-^R 3 complex R 3 + R 2 -» Rj complex Evaluation completed 5. Mixed mode arithmetic with all standard types is illustrated by this example. Given: C complex D double R real I integer L logical and the expression C :|: D + R/I — L The dominant operand type in this expression is type complex; therefore, the evaluated expression is of mode complex. It is evaluated: Convert D,R,I, and L to complex R/I—» Rj complex C * Dh> R 2 complex Ri — L-> R 3 complex R, + R 3 -»R 4 complex Evaluation completed If the same expression is rewritten with parentheses as C*D + (R/I — L) the evaluation proceeds: Convert I to real Convert L to real R/I-^Ri real Rj — L— > R 2 real Convert D to complex Convert R 2 to complex-* R 3 C * D-» R 4 complex R.i + R 3 ^R 5 complex Evaluation completed 2.4 MIXED MODE REPLACEMENT STATEMENT The mode of an evaluated expression is determined by the type of the dominant operand. This, how- ever, does not restrict the types that identifier A may assume. An expression of complex mode may replace A even if A is type real. The following chart shows the A, E relationship for all the standard modes. 2-3 ARITHMETIC REPLACEMENT STATEMENT A = E A is an Identifier E is an Arithmetic Expression 0(f) is the Evaluated Arithmetic Expression <i \v Mode of Complex Double Real Integer of A \. Store real & Round 0(f) to Store 0(f) in real Convert 0(f) to real & imaginary parts real. Store in real part of A. Store store in real part of A. Complex of 0(f) in real & part of A. Store zero in imaginary Store zero in imaginary imaginary parts zero in imaginary part of A. part of A. of A. part of A. Discard imaginary Store 0(f) (most If 0(f) is ± affix Convert 0(f) to real. part of 0(f) & re- & least significant ±0 as least sig- Fill out least significant Double place it with ±0 parts) in A (most nificant part. half with binary zeros according to real & least signifi- Store in A, most or ones accordingly as part of 0(f). cant parts). & least signifi- cant parts. sign of 0(f) is plus or minus. Store in A, most and least significant parts. Store real part of Round 0(f) to real Store 0(f) in A. Convert 0(f) to real. Real 0(f) in A. Imagi- nary part is lost. & store in A. Least significant part of 0(f) is lost. Store in A. Truncate real Truncate 0(f) to Truncate 0(f) to Store 0(f) in A. part of 0(f) to INTEGER & INTEGER. Integer INTEGER. Store in A. Imaginary part is lost. store in A. Store in A. If real part of If 0(f)^O ; 1->A. Same as for Same as for double at Logical 0(f)^O, 1-*A. If real part of 0(f) = 0, 0-»A. If 0(f) = 0,0-* A. double at left. left. When all of the operands in the expression E are of type logical, the expression is evaluated as though all the logical operands were integers. For example, if L 1; L,, L 3 , L 4 are logical variables, R is a real variable, and I is an integer variable, then I = L 1 *L 2 + L 3 -L. 1 will be evaluated as though the L[ were all integers (0 or 1) and the resulting value will be stored, as an integer, in I. R = L 1 *L 2 + L 3 -L 4 is evaluated as stated above, but the result is con- verted to a real (a floating point quantity) before it is stored in R. t. 2-4 Examples: Given: d , A t complex Di , A 2 double Ri , A 3 real I, , A 4 integer Li , A 5 logical A^c^Ca-c/a (.905,15.393) = (4.4,2.1)*(3.0,2.0)-(3.3,6.8)/(l.l,3.4) The mode of the expression is complex. Therefore, the result of the expression is a two-word, floating point quantity. A t is type complex and the result replaces A a . A^d 4.4000 +000 = (4.4,2.1) The mode of the expression is complex. The type of A a is real; therefore, the real part of C t replaces A 3 . A a = C 1 *(0.,-2) 4.2000+000 = (4.4,2.1)*(0.,-2) The mode of the expression is complex. The type of A 3 is real. A^ = R 1 /R 2 *(R 8 -IU)+Ii-(l2*R«) 3=8.4/4.2*(3.1-2.1) + 14-(l*2.3) The mode of the expression is real. The type of A 4 is integer; the result of the expression evaluation, a real, will be converted to an integer replacing A 4 . A 2 =D 1 **2*(D 2 + (D 3 *D 4 )) + (D 2 *D 1 *D 2 ) 4.96800000000000000000000 + 001 = 2( )D**2*(3.2D + (4.1D*1.0D)) + (3.2D*2.0D*3.2D) The mode of the expression is double. The type of A 2 is double; the result of the expression evalua- tion, a double precision floating quantity, replaces A 2 . A 5 = C 1 *R 1 -R 2 + Ii 1 = (4.4,2.1) *8.4- 4.2 + 14 The mode of the expression is complex. Since A 5 is type logical, an integer 1 will replace A 5 if the real part of the evaluated expression is not zero. If the real part is zero, zero replaces A 5 . ^F 2-5 « ♦> t 3. LOGICAL/RELATIONAL AND MASKING EXPRESSIONS AND REPLACEMENT STATEMENTS The general form of the logical/relational replace- ment statement is L = E, where L is a variable of type logical and E may be a logical, relational, or arithmetic expression. 3.1 LOGICAL EXPRESSION A logical expression has the general form O t op Oo op O a . . . The terms Oj are logical variables, arithmetic ex- pressions or relational expressions, and op is the logical operator .AND. indicating conjunction or .OR. indicating disjunction. The logical operator .NOT. indicating negation ap- pears in the form: .NOT. O t The value of a logical expression is either true or false. When an arithmetic expression appears as a term of a logical replacement statement, the value of the expression is examined. If the value is non-zero, the term has the value TRUE. If the value is equal to zero, the term has the value FALSE. Logical expressions are generally used in logical IF- statements. (See section 5.3) Rules: 1. The hierarchy of logical operations is: First .NOT. then AND. then .OR. 2. A logical variable or a relational expression is, in itself, a logical expression. If Lj, L, are logical expressions, then .NOT. L x U .AND. L, U .OR. L 2 are logical expressions. If L is a logical expres- sion, (L), ( (L) ) are logical expressions. 3. If L,, L 2 are logical expressions and op is AND. or .OR. then, L, op op L 2 is never legiti- mate. 4. .NOT. may appear in combination with AND. or .OR. only as follows : AND. .NOT. .OR. .NOT. AND. (.NOT. . . .) .OR. (.NOT. . . .) .NOT. may appear with itself only in the form .NOT. (.NOT.(.NOT. . . . 5. If Li, L 2 are logical expressions, the logical operators are defined as follows: .NOT. U U AND. L 2 U .OR. L 2 is false only if L t is true is true only if L l5 L 2 are both true is false only if L 1; L 2 are both false Incorrect usages such as the following are not per- mitted: Q.NOT. .OR.R CAND. .NOT. .NOT.B The last expression is permissible in the form CAND. .NOT.(.NOT.B) Examples: Logical Expressions {The product A*B greater than 16.} AND. {C equals 3.141519} A*B .GT. 16. AND. C .EQ. 3.141519 3-1 (begin) AXB-16.-»L t C Is L t >0? ) -/fALSEJ {A(I) greater than 0} .OR. {B(J) less than 0} a(i).gt.o.or.b(j).lt.o (begin) (" Is A(i)>0? ^^-(tRUEJ NO ( IsB(j)<0? ) YES In the two examples below, all L, are of TYPE LOGICAL (L2.0R...NOT.L3) BEGIN ( IsL ^ 0? y^-* ( IsL=0? ) YES «• YES (true) L2.0R..N0T.L3 .AND.(.NOT.L6,OR.L5) (trueY— (begin) YES /• " \ i — C IsL ^ 0? ) NO Is L 3 = 0? YES ) NO YES FALSE C Is L 6 = 0? ) YES NO (^ Is L 5 ^0? ^ NO % ♦) 3.2 RELATIONAL EXPRESSION A relational expression has the form: qi op q 2 The q's are arithmetic expressions; op is an operator belonging to the set: Operator Meaning .EQ. Equal to .NE. Not equal to .GT. Greater than .GE. Greater than or equal to XT. Less than .LE. Less than or equal to A relation is true if q 1 and q 2 satisfy the relation specified by op. A relation is false if q x and q, do not satisfy the relation specified by op. Relations are evaluated as illustrated in the rela- tion, p .EQ. q. This is equivalent to the question, does p — q = 0? The difference is computed and tested for zero. If the difference is zero, the relation is true. If the dif- ference is not zero, the relation is false. Relational expressions are converted internally to arithmetic expressions according to the rules of mixed mode arithmetic. These expressions are evaluated and compared with zero to determine the truth value of the corresponding relational expression. When ex- pressions of mode complex are tested for zero, only 3-2 the real part is used in the comparison. Rules: 1. The permissible forms of a relation are: q (where a non-zero value is true and a zero value is false) qi op q 2 q t op q, .AND. q, op q 3 2. The evaluation of a relation of the form q 1 op q- 2 is from left to right. The relations q t op q 2 , q t op (q,), (q t ) op q 2 , (q t ) op (q 2 ) are equivalent. Examples: A.GT. 16. R(I) .GE. R(I-l) R-Q(I)*Z.LE. 3.141592 K XT. 16 B-C.NE. D + E I.EQ.J(K) 3.3 MASKING REPLACEMENT STATEMENT The general form of the masking replacement state- ment is M = E. The masking statement is distin- quished from the logical statement in the following ways. 1. The type of M must be real or integer. 2. All operands in the expression E must be type real or integer. E may contain functions as well as variable or constant operands. Examples: Given: All variables of type real or integer. A(I) = B .OR. .NOT. C(I) B = D .AND. Q C(IJ) = .NOT. Z(K) .AND. (Ql .OR. .NOT. Q2) TEST = CELESTE .AND. 7HECLIPSE AB = D .OR. FUNC (X,T) *ilP 3.4 MASKING EXPRESSIONS In a FORTRAN-66 masking expression 60-bit arithmetic is performed bit-by-bit on the operands within the expression. Although the masking operators are identical in appearance to the logical operators, their meanings are different. They are listed accordingly to hier- archy, and the following definitions apply: .NOT. complement the operand .AND. form the bit-by-bit logical product of two operands .OR. form the bit-by-bit logical sum of two operands The operations are described below. p V p .AND. v p .OR.v .NOT.p 1 1 1 1 1 1 1 1 1 1 Rules: 1. Let Bi be masking expressions, variables or con- stants whose types are real or integer. Then the following are masking expressions. .NOT. B, B, .AND. B 2 B a .OR. B 2 2. If B is a masking expression, then (B), ((B)) are masking expressions. 3. .NOT. may appear with AND. or .OR. only as follows : .AND. .NOT. .OR. .NOT. .AND. (.NOT. . . .) .OR. (.NOT. . . .) 4. Masking expressions of the following forms are evaluated from left to right. 2 A. .AND. B .AND. C . . . A .OR. B. OR. C . . . 5. Masking expressions may contain logical oper- ands, parenthetical arithmetic expressions and statement functions. Examples: A 1 77770000000000000000 octal constant A, 00000000000077777777 octal constant 3-3 B 00000000000000001763 octal form of integer constant C 20045000000000000000 octal form of real constant .NOT. A, is 00007777777777777777 Ai AND. C is 20040000000000000000 A 1 .AND. .NOT. C is 57730000000000000000 B .OR. .NOT. A 2 is 77777777777700001763 3.5 MULTIPLE REPLACEMENT STATEMENTS The multiple replacement statement is a general- ization of the replacement statements discussed earlier in this and the previous chapter, and its form is: fa, = fa^-i — • ■ ■ — fa- = ^i = expression The expression may be arithmetic, logical or mask- ing. The fa are variables subject to the following restrictions : Arithmetic or Logical Statement: fa = ZAP If ZAP is logical or arithmetic and: If the variable fa is type complex, double, real, or integer, then fa = ZAP is an arithmetic state- ment. If the variable fa is type logical, then fa = ZAP is a logical statement. Masking Statement: fa = ZAP If ZAP is a masking expression, fa must be a type real or integer variable only. The remaining n — l*i may be variables of any type and the multiple replacement statement replaces each of the variables *i ( 2 ^ i ^ n ) in turn with the value of *i — 1 in a manner analogous to that em- ployed in mixed mode arithmetic statements. Examples: A real E,F complex G double I integer K logical The numbers in the examples represent the evalua- tions of expressions. A = G = 3.1415926535897932384626D 3.1415926535897932384626D-> G % 3.141592654 I = A = 4.6 A = I = 4.6 I = A = E = (10.2,3.0) ->A 4.6^ A 4 -*I 4 ^1 4.0-^ A 10.2-> E real 3.0-> E imaginary 10.2->A 10 -*I F = A = I = E = (13.4, 16.2) 13.4^ E real 16.2->E imaginary 13 ^1 13.0-* A 13.0-> F real 0.0 ^F imaginary f K> I = -14.6 I = K= -14.6 14 ->I 1 -*K 1 ^K 1 ^1 V 3-4 4. TYPE DECLARATIONS AND STORAGE ALLOCATIONS • 4 ^^f 4.1 TYPE DECLARATIONS The TYPE declaration provides the compiler with information on the structure of variable and func- tion identifiers. There are five standard variable types which are declared by one of the following statements : Statement Characteristics TYPE COMPLEX List 2 words/element Floating point TYPE DOUBLE List 2 words/element Floating point TYPE REAL List 1 word/element Floating point TYPE INTEGER List 1 word/element Integer TYPE LOGICAL List 1 word/element Logical (non- dimensioned ) 1 bit/ element, 32 bits/word Logical ( dimensioned ) A list is a string of identifiers separated by commas; subscripts are not permitted. An example of a list is : A, Bl, CAT, D36F, EUPHORIA Rides: 1. The TYPE declaration is non-executable and must precede the first executable statement in a given program. 2. An identifier may not be declared in two or more TYPE declarations. 3. An identifier not declared in a TYPE statement is an integer if the first letter of the identifier is I, J, K, L, M, N; for any other letter, it will be real. 4. If TYPE, DIMENSION or COMMON appear together, the order is immaterial. Examples: TYPE COMPLEX A147, RIGGISH, AT1LL2 TYPE DOUBLE TEEPEE, B2BAZ TYPE REAL EL, CAMINO, REAL, IDE63 TYPE INTEGER QUID, PRO, QUO TYPE LOGICAL GEORGE6 4.2 DIMENSION A subscripted variable represents an element of an array of variables. Storage may be reserved for arrays by the non-executable statements DIMEN- SION or COMMON. The standard form of the DIMENSION statement is DIMENSION Vi, V 2 , . . . , V„ The variable names, Vi, may have 1, 2, or 3 integer constant subscripts separated by commas, as in SPACE (5, 5, 5,). Under certain conditions within subprograms only, the subscripts may be integer variables. This is explained in section 6.11. The number of computer words reserved for a given array is determined by the product of the subscripts in the subscript string, and the type of the variable. In the statements TYPE COMPLEX HERCULES DIMENSION HERCULES (10, 20) the number of elements in the array HERCULES is 200. Two words are used to store a complex ele- ment; therefore, the number of computer words reserved is 400. The argument is the same for double precision. For reals and integers the number of words in an array equals the number of elements in the array. Rules: 1. The DIMENSION statement is non-executable and must precede the first executable statement in a given program. 2. An identifier may not be declared in two or more DIMENSION statements. 3. If TYPE, DIMENSION or COMMON appear to- gether, the order is immaterial. 4. For any given dimensional variable, the dimen- sions may be declared either in a COMMON statement or in a DIMENSION statement. If de- clared in both, those of the DIMENSION state- ment override those declared in the COMMON statement. 5. Any number of DIMENSION statements may appear in a program section. 6. A zero subscript is treated as a one. 4-1 4.2.1 VARIABLE DIMENSIONS When an array identifier and its dimensions appear as formal parameters in a function or subroutine, the dimensions may be assigned through the actual parameter list accompanying the function reference or subroutine call. The dimensions must not exceed the maximum array size specified by the DIMEN- SION statement in the calling program. See section 6.11 for details and examples. 4.3 COMMON A program may contain or call subprograms. Areas of common information may be specified by the statement: COMMON/L/List/L/List . . . I is a common block identifier. It may be blank; or consist of up to 8 characters. If the first character is a number, then all characters in the identifier must be numbers. The following are common identifiers: /AZ13/ /35£ /CAVEAT/ // /O/ /x/ List is composed of simple variable identifiers and array identifiers (subscripted or non-subscripted). If a non-subscripted array name appears in the list, the dimensions are defined by the DIMENSION statement in that program. Dimensions for arrays may also be given in the COMMON statement when a subscript string ap- pears with the identifier. If dimensions are given in both, those in the DIMENSION statement are used. Examples: COMMON A, B, C COMMON/ / A, B, C, D COMMON/BLOCK1/A, B/1234/C(10), D(10,10),E(10,10,10) COMMON/BLOCKA/D(15), F(3,3), GOSH(2, 3, 4), Ql If a subprogram does not use all of the locations reserved in a common block, unused variables may be necessary in the COMMON statement to insure proper correspondence of common areas. | MAIN PROG SUB PROG COMMON/SUM/A, B, C COMMON/SUM/E, F, G In the above example, assume only the variables E and G are used in the subprogram. The unused vari- able F is necessary to space over the area reserved by B. Rules: 1. COMMON is non-executable and must precede the first executable statement in the program. Any number of COMMON statements may appear in a program section. 2. If TYPE, DIMENSION or COMMON appear together, the order is immaterial. 3. A variable in COMMON may not be equated to any other variable in COMMON. 4. Common block identifiers are used only for block identification within the compiler; they may be used elsewhere in the program as other kinds of identifiers. 5. An identifier in one common block may not appear in another common block. 6. For any given dimensional variable, the dimen- sions may be declared either in a COMMON statement or in a DIMENSION statement. If de- clared in both, those of the DIMENSION state- ment override those declared in the COMMON statement. 7. At the beginning of program execution, the con- tents of the common area are undefined unless specified by a DATA statement. «■ 4.4 COMMON BLOCKS The COMMON statement provides the program- mer with a means of reserving blocks of storage area that are referenced by more than one sub- program. Data may be stored in common blocks by the DATA statement and are made available to any subprogram using the appropriate block. 4-2 4.4.1 BLOCK LENGTH The length of a common block in computer words is determined from the number and type of the list identifiers. In the following statement, the length of the common block A is 12 computer words. The origin of the common block is Q(l). Q and R are real variables and S is complex. • COMMON/A/Q(4), R(4), S(2) b ock A origin Qd) Q(2) Q(3) Q(4) R(l) R(2) R(3) R(4) S(l) real part S(l) imaginary part S(2) real part S(2) imaginary part Example: MAIN PROG COMPLEX C COMMON/TES17C(20)/36/A,B,Z The length of TEST is 40 computer words. The subprogram may rearrange the allocation of words as in: SUB PROG 1 COMMON/TEST/A(10),G(10),K(10) TYPE COMPLEX A The following arrangements are equivalent: TYPE DOUBLE A \ ( COMMON A(10) DIMENSION A(10) | j TYPE DOUBLE A COMMON A The label of a COMMON block is used only for block identification. The following is permissible: COMMON /A/A(10)/B/B(5,5) /C/C (5,5,5) 4.5 EQUIVALENCE The EQUIVALENCE statement permits variables to share locations in storage. The general form is: EQUIVALENCE (A,B, . . .), (A1,B1, ...),... (A,B, . . .) is an equivalence group of two or more simple or singly subscripted variable identifiers. A multiply subscripted variable can be represented only by a singly subscripted variable. The corre- spondence is: A(i,j,k)=A(i+(j-l)I+(k-l)IJ) where i,j,k are integer constants: I and J are the integer constants appearing in DIMENSION A (IJ.K). For example, in DIMENSION A(2,3,4), the element A(l,l,2) is represented by A(7). Examples: EQUIVALENCE is most commonly used when two or more arrays can share the same storage locations. The lengths may be different or equal. DIMENSION A(10,10), 1(100) EQUIVALENCE (A,I) The length of TEST is 40 words. The first 10 ele- ments (20 words) of the block, represented by A, are complex elements. Array G is the next 10 words, and array K is the last 10 words. -Within the sub- program, elements of G will be treated as floating point quantities; elements of K will be treated as integer quantities. The length of a COMMON block must not be changed by the subprograms using the block. The identifiers used within the block may differ as shown above. 5 READ 10, A 6 READ 20, 1 The EQUIVALENCE statement assigns the first element of array A and array I to the same storage location. The READ statement 5 stores the A array in consecutive locations. Before statement 6 is exe- 4-3 cuted all operations using A must be completed as the values of array I are read into the storage loca- tions previously occupied by A. Rules: 1. EQUIVALENCE is non-executable and must precede the first executable statement in the program or subprogram. 2. If TYPE, DIMENSION, COMMON, or EQUIV- ALENCE appear together, the order is imma- terial. 3. Any variable or array may be made equivalent to any other variable or array. The variable or array may or may not be subscripted in the EQUIV- ALENCE statement. A given identifier may be repeated in more than one equivalence group, but caution must be observed to avoid circular references. A zero or one subscript is treated as though the subscript were not present. 4. The EQUIVALENCE statement does not re- arrange common, but arrays may be defined as equivalent so that the length of the common block is changed. The origin of the common block must not be changed by the EQUIVALENCE statement. The following simple examples illus- trate changes in block lengths caused by the EQUIVALENCE statement. Given: Arrays A and B Sa = subscript of A Sb = subscript of B Examples: 1. A in COMMON, B not in COMMON Sb ^ Sa is a permissible subscript Sb > Sa is not COMMON/l/A(4) DIMENSION B(5) EQUIVALENCE (A(3), B(2)) origin A(l) A(2) B(l) A(3) B(2) A(4) B(3) B(4) B(5) 2. B in COMMON, A not in COMMON Sa ^ Sb is a permissible subscript 4-4 length of block 1 (now 6 elements) Sa > Sb is not COMMON/2/B(3) DIMENSION A(2) EQUIVALENCE (B(l), A(l)) origin B(l) A(l) \ B(2) A(2) > length of block 2 B(3) J (not increased) 3. A, B not in COMMON No restrictions on subscript arrangement. 4. A, B both in COMMON No subscript arrangement is legal. 4.6 DATA The programmer may assign constant values to variables in the source program by using the DATA statement either by itself or with a DIMENSION statement. It may be used to store constant values in variables contained in a common block. DATA(L = List), (I, = List), . . . I is an identifier representing a simple variable, array name, or a variable with integer constant sub- scripts or integer variable subscripts. List contains constants only and has the form a 1 ,a 2 , . . . , k(b!,b,, . . . ), c„c u . . . k is an integer constant repetition factor that causes the parenthetical list following it to be repeated k times. Rules: 1. DATA is non-executable and must precede the first executable statement in any program or sub- program in which it appears. 2. When DATA appears with TYPE, DIMENSION, COMMON or EQUIVALENCE statements, the order is immaterial. 3. DO loop-implying notation is permissible. This notation may be used for storing constant values in arrays. DIMENSION X( 10,10) DATA ( ( (X(IJ)I = 1,10,2), J = 6,9,3) = 2(5(3.1))) DIMENSION GIB (10) DATA ( (GIB(I),I = 1,10) = 1. ,2. ,3. ,7(4.32) ) ARRAY GIB 1. 2. 3. 4.32 4.32 4.32 4.32 4.32 4.32 4.32 Examples: 1. DATA (LEDA=15), (CASTOR =16.0), (POLLUX =84.0) LEDA CASTOR POLLUX 15 16.0 84.0 4. Variables in variable dimensioned arrays may not be preset in a DATA statement. 5. Either unsigned constants or constants preceded by a minus sign may be used. Negative octal con- stants are prefixed with minus signs. 6. There must be a one-to-one correspondence be- tween the identifiers and the list. COMMON / TUP / C(3) DATA (C = l. ,2,3) 2. DATA (A(l,3) = 16.239) ARRAY A A(l,3) 16.239 3. DIMENSION B(10) DATA (B = 77B, - 77B, 4(776B, - 774B) ) ARRAY B 77B -77B 776B -774B 776B -774B 776B -774B 776B -774B 4.7 BANK In FORTRAN-66 the BANK statement acts as a do-nothing statement. * 4-5 * •> % 5. CONTROL STATEMENTS Program execution normally proceeds from one statement to the statement immediately following it in the program. Control statements can be used to alter this sequence or cause a number of itera- tions of a program section. Control may be transferred to an executable state- ment only; a transfer to a non-executable statement results in a program error. Iteration control provided by the DO statement causes a predetermined sequence of instructions to be repeated any number of times with the stepping of a simple integer variable after each iteration. 5.1 STATEMENT IDENTIFIERS Statements are identified by numbers which can be referred to from other sections of the program. A statement number used as a label or tag appears in columns 1 through 5 on the same line as the state- ment on the coding form. The statement number N may lie in the range 1==N^99999. An identifier up to 5 digits long may occupy any of the first five col- umns; blanks are squeezed out and leading zeros are ignored. 1, 01, 001, 0001, are identical, (Appen- dix A). 5.2 GO TO STATEMENTS Transfer of control is provided by GO TO state- ments. 5.2.1 UNCONDITIONAL GO TO GO TO N This statement causes an unconditional transfer to the statement labeled N; N is a statement identifier. 5.2.3 ASSIGN STATEMENTS ASSIGN N TO m This statement is used with the assigned GO TO statement. N is a statement number, m is a simple integer variable. ASSIGN 10 TO LSWTCH GO TO LSWTCH,(5,10,15,20) Control will transfer to statement 10. 5.2.4 computed GO TO GO TO (n 1; n 2 , . . . ,n m )i GO TO (n l5 n 2 . . . ,n m ), i This statement acts as a many-branch GO TO, where i is preset or computed prior to its use in the GO TO. The rii are statement numbers and i is a simple integer variable. If i— 1, a transfer to n a occurs; if i— m, a transfer to n m occurs. Otherwise, transfer is to nj. For proper operations, i must not be specified by an ASSIGN statement. ISWITCH = 1 GO TO (10,20,30),ISWITCH "slP 5.2.2 assigned GO TO GO TO m, (n 1; n 2 . . . ,n m ) This statement acts as a many-branch GO TO. m is an integer variable assigned an integer value iij in a preceeding ASSIGN statement. The ni are state- ment numbers. A parenthetical list need not be present. The comma after m is optional when the list is omitted, m cannot be the result of a computation. If m is computed, the object code is incorrect. 10 JSWITCH = ISWITCH + 1 GO TO (11,21,31)JSWITCH Control will transfer to statement 21. 5.3 IF STATEMENTS Conditional transfer of control is provided by the one-, two-, and three-branch IF statements, the status of sense lights or switches. 5-1 5.3.1 THREE BRANCH IF (ARITHMETIC) IF (A) n^nojii., A is an arithmetic expression and the ni are state- ment numbers. This statement tests the evaluated quantity A and jumps accordingly. A < jump to statement iu A = jump to statement n 2 A > jump to statement n 3 In the test for zero, +0= -0. When the mode of the evaluated expression is complex, only the real part is tested for zero. IF(A*B-C*SINF(X) )10,10,20 IF(I)5,6,7 IF(A/B**2)3,6,6 5.3.2 TWO BRANCH IF (LOGICAL) IF(L) ni ,n 2 L is a logical expression. The n, are statement numbers. The evaluated expression is tested for true (non- zero) or false (zero). If L is true, jump to statement rij. If L is false, jump to statement n 2 . IF(A .GT. 16. .OR. I .EQ.O)5,10 IF(L)1,2 (L is TYPE LOGICAL) IF(A*B-C)1,2 (A*B-C is arithmetic) IF(A*B/C .LE. 14.32)4,6 5.3.3 ONE BRANCH IF (LOGICAL) IF (L)s L is a logical expression and s is a statement. If L is true (non-zero), execute statement s. If L is false (zero), continue in sequence to the statement following the IF logical. IF (L) GO TO 3 (L is logical) IF(L)Y=SINF(X)/2 5.3.4 SENSE LIGHT SENSE LIGHT i The statement turns on the sense light i. SENSE LIGHT turns off all sense lights, i may be a simple integer variable or constant (1 to 60). IF(SENSE LIGHT i) n 1: n 2 The statement test sense light i. If it is on, it is turned off and a jump occurs to statement n t . If it 5-2 is off, a jump occurs to statement n 2 . i is a sense light and the n, are statement numbers, i may be a simple integer variable or constant (1 to 60). IF(SENSE LIGHT 4)10,20 5.3.5 SENSE SWITCH IF(SENSE SWITCH i) n„n 2 If sense switch i is set (on), a jump occurs to state- ment rii. If it is not set (off), a jump occurs to state- ment n 2 ; i may be a simple integer variable or constant. In the 6600, 1 ^ i ^ 6 N=5 IF(SENSE SWITCH N) 5,10 5.4 FAULT CONDITION STATEMENTS At execute time, the computer is set to interrupt on operand out of range. A program may be exe- cuted with an exit on any fault condition or by optional exits or tests provided by the program (SIPROS parameter). IF DIVIDE CHECK n l5 n 2 IF DIVIDE FAULT n l5 n 2 The above statements are equivalent. A divide fault occurs following division by zero. The state- ment checks for this fault; if it has occurred, the indicator is turned off and a jump to statement n x takes place. If no fault exists, a jump to statement n 2 takes place. IF EXPONENT FAULT n 1; n 2 An exponent fault occurs when the result of a real or complex arithmetic operation exceeds the upper limits specified for these types. Results that are less than the lower limits are set to zero without indica- tion. This statement is therefore a test for floating- point overflow only. If the fault occurs, the indicator is turned off, and a jump to statement n, takes place. If no fault exists, a jump to statement n 2 takes place. IF OVERFLOW FAULT n 1; n 2 No overflow condition is provided on 60-bit sums and differences. A jump to statement n, is gener- ated for the statement. i> \j) 5.5 DO STATEMENTS DO n i=m 1 ,m 2 ,m3 This statement makes it possible to repeat groups of statements and to change the value of a fixed point variable during the repetition, n is the number of the statement ending the DO loop, i is the index variable (simple integer). The mi are the indexing parameters; they may be any computable arithmetic expression. The initial value assigned to i is im, m 2 is the largest value assigned to i, and m 3 is the amount added to i after each DO loop is executed. If m a does not appear, it is assigned the value 1. The values of m 2 and m 3 may be changed at any time. The DO statement, the statement labeled n, and any intermediate statements constitute a DO loop. Statement n may not be an IF or GO TO statement or another DO statement. See Transmission of Ar- rays section 7.1.1 and DATA Statement section 4.6 for usage of implied DO loops. 5.5.1 DO LOOP EXECUTION The initial value of i, m 1; is compared with m 2 before executing the DO loop and, if it does not exceed m 2 , the loop is executed. After this step, i is increased by m 3 . i is again compared with m 2 ; this process continues until i exceeds m 2 as shown below. Control then passes to the statement im- mediately following n, and the DO loop is satisfied. If m x exceeds m 2 on the initial entry to the loop, the loop is not executed and control passes to the next statement after statement n. When the DO loop is satisfied, the index variable i is no longer well defined. If a transfer out of the DO loop occurs before the DO is satisfied, the value of i is preserved and may be used in subse- quent statements. 5.5.2 DO nests When a DO loop contains another DO loop, the grouping is called a DO nest. The last statement of a nested DO loop must either be the same as the last statement of the outer DO loop or occur before it. If Dj,D 2 , . . . D m represent DO statements, where the subscripts indicate that Di appears before D 2 appears before D 3 , and n 1; n,, . . . ,n m represent the corresponding limits of the D 1; then n m must appear before n m _! . . . n 2 must appear before m. I-Di Do ■D„ • (start) mi->i EXECUTE STATE- MENTS IN LOOP INCLUDING STATEMENT N. i.+m 3 -»i 5-3 Examples: DO loops may be nested in common with other DO loops : D, D- n 2 D, DO 1 I = 1,10,2 D 3 Bi Do n 2 D„ ni DO 100 L = 2,LIMIT 1 — D1 *->2 1 n - -n. = n 3 DO 5 I = 1,5 DO 5 J = 1,10 DO 5 K = J,15 D 3 DO 2 J = 1,5 DO 10 I = 1,10 DO 10 J = 1,10 5 CONTINUE D0 3K- 2,8 3 CONTINUE 2 CONTINUE DO 4 L = 1,3 4 CONTINUE 1 CONTINUE 10 CONTINUE DO 20 K = K1,K2 20 CONTINUE 100 CONTINUE f 5-4 d •5.5.3 DO LOOP TRANSFER In a DO nest, a transfer may be made from one DO loop into a DO loop that contains it; and a transfer out of a DO nest is permissible. The special case is transferring out of a nested DO loop and then transferring back to the nest. In a DO nest, if the range of i includes the range of j and a transfer out of the range of j occurs, then a transfer into the range of i or i is permissible. A transfer from the outer DO loop to the last state- ment should not be made when that statement is also the last statement of an inner DO loop. If such a transfer is made, control will transfer to the inner DO loop. Example : DO10I = J,K,L 5 GO to 10 DO10II = JJ,KK,LL 10 CONTINUE This will cause control to pass the inner DO loop. In the following diagram, EXTR represents a por- tion of the program outside of the DO nest. 5.5.4 DO PROPERTIES 1. The indexing parameters mi,mo,m 3 may be any executable arithmetic expression. 2. The indexing parameters m x and m 2 , if variable, may assume positive or negative values, or zero. 3. The values of m 2 and m 3 may be changed during the execution of the DO loop. 4. i is initially m^ As soon as i exceeds m», the loop is terminated. 5. DO loops may be nested 50 deep. 5.6 CONTINUE CONTINUE The CONTINUE statement is most frequently used as the last statement of a DO loop to provide a transfer address for IF and GO TO instructions that are intended to begin another repetition of the loop. If CONTINUE is used elsewhere in the source pro- gram, it acts as a do-nothing instruction; and control passes to the next sequential program statement. 5.7 PAUSE PAUSE PAUSE n PAUSE or PAUSE n act as do-nothing instructions. 5.8 STOP STOP STOP n STOP or STOP n cause immediate exit to the monitor, n is an arbitrary number, not more than 5 digits in length. 5.9 END END END marks the physical end of a program or sub- program. It is executable in the sense that it effects return from a subprogram in the absence of a RETURN. The END statement may include the name of the program or subprogram which it terminates. This name, however, is ignored . The END statement is not connected widi the dollar sign, which is used as a separator, nor does it make use of the continuation. When punched into a card, it must be the only entry in the card and must be punched within columns 7 through 72. 5-5 i i) ( • 6. FUNCTIONS AND SUBPROGRAMS 5 ^y Sets of instructions may be written as independent subroutines or function subprograms which can be referred to by the main program. The mode of a function subprogram is determined by the name of the subroutine in the same manner as variable modes are determined. Subroutine subprogram names are not classified by mode. The program or function name must be unique within that sub- program. 6.1 MAIN PROGRAMS AND SUBPROGRAMS A main program may be written with or without references to subprograms. In all cases, the first statement must be of the following form where name is an alphanumeric identifier, 1-8 characters. The first character must be alphabetic; the remain- ing characters may be alphabetic or numeric. PROGRAM name A main program may refer to both subroutines and functions which are compiled independently of the main program. A calling program is a main pro- gram or subprogram that refers to subroutines and functions. 6.2 FUNCTIONAL SUBPROGRAM The first statement of function subprograms must have the form: FUNCTION F ( Pl , p 2 , . . . Pn ) F is the function name and the ps are formal parameters. A function name is constructed and its type determined in the same way as a variable identifier. The parameters may be array names, non-subscripted variables, or names of other func- tion or subroutine subprograms. A function, together with its arguments, may be used any place in an expression that a variable identifier may be used. A function reference is a call upon a computational procedure for the return of a single value associated with the function identifier. This procedure may be defined by a single statement in the program (arithmetic statement function), in the compiler (library function), or in a multi-statement sub- program compiled independently of a main pro- gram (function subprogram). The name of a function subprogram may occur as an operand in an arithmetic statement. The function reference must supply the function with at least one argument and it may contain up to 63. The form of the function reference is: F (p l5 p,, . . . p n ) F is the function name and pj are function argu- ments or actual parameters. The corresponding arguments appearing with the function name in a function definition are called formal parameters. Because formal parameters are local to the sub- program in which they appear, they may or may not correspond to the actual parameters in the calling subprogram. Type-FUNCTION statements are permitted in ad- dition to the FUNCTION F (p 1; p., . . . p n ) state- ment where mode is determined by the first character or a TYPE declaration. The alternate forms are : REAL FUNCTION F( Pl ,p 2 , . . . p n ) INTEGER FUNCTION F( Pl ,p = , . . . Pn ) DOUBLE PRECISION FUNCTION F (p^po, . . . p n ) COMPLEX FUNCTION F (p Xj p 2) . . . p n ) LOGICAL FUNCTION F ( Pl ,p,, . . . p n ) F is the function name, and p* are formal param- eters. The type-FUNCTION statement declares the type of the result returned by the function. Rules: 1. The type of the function is determined from the naming conventions specified for variables in section 4.1 or from the type-FUNCTION state- ment. 2. The name of a function must not appear in a DIMENSION statement. The name must appear, however, at least once as any of the following: the left-hand identifier of a replacement state- ment an element of an input list an actual parameter of a subprogram call 3. No element of a formal parameter list may ap- pear in a COMMON, EQUIVALENCE, DATA, or EXTERNAL statement within the function subprogram. 6-1 4. When a formal parameter represents an array, it must be declared in a DIMENSION statement within the function subprogram. If it is not de- clared, only the first element of the array is avail- able to the function subprogram. 5. In referring to a function subprogram the fol- lowing forms of the actual parameters are per- missible: arithmetic expression constant or variable, simple or subscripted array name function reference subroutine When the name of a function subprogram appears as an actual parameter, that name must also appear in an EXTERNAL statement in the calling program. When the name of a function subprogram is used as an actual parameter, it may be in either of two forms : a. FUNCTION PUSH (ARG1) b. FUNCTION PUSH (FUNCT,ARG2) To call these functions, then, the calling program uses, respectively, the forms: a. A = PUSH (CALC(X) ) b. A = PUSH (CALC, X) When a subroutine appears as an actual parameter, the subroutine name may appear alone or with a parameter list. When a subroutine appears with a parameter list, the subroutine name and its param- eters must appear as separate actual parameters: Level I— Calling program PUSH = - - END At some other level of the program, subroutines DAB and DABL are defined. a 6. Logical expressions may be actual parameters. 7. Actual and formal parameters must agree in order, number (see rule 5, section 6.7) and type. 8. Functions must have at least one parameter. 6.3 LIBRARY FUNCTIONS Function subprograms which are used frequently have been written and stored in a reference library and are available to the programmer through the compiler. FORTRAN-66 contains the standard library func- tions available in earlier versions of FORTRAN. A list of these functions is in Appendix D. When one appears in the source program, the compiler identifies it as a library function and generates a calling sequence within the object program. In the absence of a TYPE declaration, the type of the function identifier is determined by its first letter or by the type-FUNCTION statement. How- ever, for standard library functions the modes of the results have been established through usage. The compiler recognizes the standard library functions and associates the established types with the results. For example, in the function identifier LOGF, the first letter, L, would normally cause that function to return an integer result. This is contrary to estab- lished FORTRAN usage. The compiler recognizes LOGF as a standard library function and permits the return of a real result. A = PUSH (DAB,W,X) B = PUSH (DABL,Y,Z) Level II— Function statement and subroutine call FUNCTION PUSH (SUB, ARG1, ARG2) CALL SUB (ARG1, ARG2) 6.4 EXTERNAL STATEMENT When the actual parameter list of a function or sub- routine reference contains a function or subroutine name, that name must be declared in an EX- TERNAL statement. Its form is: EXTERNAL identifier!, identifier 2 , . . . Identifier! is the name of a function or subroutine. The EXTERNAL statement must precede the first executable statement of any program in which it appears. When it is used, EXTERNAL always ap- pears in the calling program; it must not be used with arithmetic statement functions. 6-2 % Examples: 1. Function Subprogram FUNCTION GREATER (A,B) IF (A.GT.B) 10,20 10 GREATER = A -B RETURN 20 GREATER = A + B END Calling Program Reference Z(I,J) = F1 + F2-GREATER(C-D,3.*I/J) 2. Function Subprogram FUNCTION PHI(ALFA, PHI2) PHI = PHI2(ALFA) END Calling Program Reference EXTERNAL SINF 4. Function Subprogram FUNCTION AL(W,X,Y,Z) CALL w(x;y,z) AL = Z**4 RETURN END Function Subprogram Reference EXTERNAL SUM G = AL(SUM,E,V,H) In the function subprogram the name of the sub- routine (SUM) and its parameters (E,V,H) replace W and X,Y,Z. SUM appears in the EXTERNAL statement so that the compiler treats it as a sub- routine name rather than a variable identifier. C = D-PHI(Q(K),SINF) From its call in the main program, the formal parameter ALFA is replaced by Q(K), and the formal parameter PHI2 is replaced by SINF. PHI will be replaced by the sine of Q(K). 3. Function Subprogram FUNCTION PSYCHE (A,B,X) CALL X PSYCHE = A/B *2. * ( A - B) END Function Sumprogram Reference EXTERNAL EROS R = S- PSYCHE (TLIM, ULIM, EROS) In the function subprogram, TLIM, ULIM replaces A,B. The CALL X is a call to a subroutine named EROS. EROS appears in an EXTERNAL statement so that the compiler recognizes it as a subroutine name rather than a variable identifier. 6.5 STATEMENT FUNCTIONS Statement functions are defined when used as an operand in a single arithmetic or logical statement in the source program and apply only to the par- ticular program or subprogram in which the defini- tion appears. They have the form F (p ljP o, . . . p n ) E l^n^63 F is the function name, p, are the formal param- eters, and E is an expression. Rules: 1. The function name must not appear in a DIMENSION, EQUIVALENCE, COMMON or EXTERNAL statement. 2. The formal parameters usually appear in the expression E. When the statement function is executed, formal parameters are replaced by the corresponding actual parameters of the function reference. Each of the formal parameters may be TYPE REAL or INTEGER only, but they may not be declared in a TYPE statement. Each of the actual parameters may be any computable arithmetic expression, but there must be agree- ment in order, number and type between the actual and formal parameters. Formal parameters must be simple variables. 6-3 3. E may be an arithmetic or logical expression. 4. E may contain subscripted variables. 5. The expression E may refer to library functions, previously defined statement function and func- tion subprograms. 6. All statement functions must precede the first executable statement of the program or subpro- gram, but they must follow all declarative state- ments (DIMENSION, TYPE, et cetera). Examples: TYPE COMPLEX Z Z ( X ,Y) = (1. ,0.)*EXPF(X)*COSF(Y) + (0.,1.)*EXPF(X)*SINF(Y) This arithmetic statement function computes the complex exponential Z(x,y) = e x+,y . 6.6 SUBROUTINE PROGRAM A reference to a subroutine is a call upon a com- putational procedure. This procedure may return none, one or more values. No value is associated with the name of the subroutine, and the subroutine must be called by a CALL statement. The first statement of subroutine subprograms must have the form: l^n^63 SUBROUTINE S or SUBROUTINE S (p l5 p„ . . . p„) S is the subroutine name which follows the rules for variable identifiers, and p, are the formal param- eters which may be array names, non-subscripted variables, or names of other function or subroutine subprograms. Rules: 1 The name of the subroutine may not appear in any declarative statement (TYPE, DIMENSION) in the subroutine. 2. No element of a formal parameter list may ap- pear in a COMMON, EQUIVALENCE, DATA, or EXTERNAL statement within the subroutine subprogram. 4. When a formal parameter represents an array, it must be declared in a DIMENSION statement within the subroutine. If it is not declared, only the first element of the array is available to the subroutine. 6.7 CALL The executable statement in the calling program for referring to a subroutine subprogram is of the form: CALL S or CALL S (p„p„...p„) l^n^63 S is the subroutine name, and pi are the actual parameters. The CALL statement transfers control to the subroutine. When a RETURN or END state- ment is encountered in the subroutine, control is returned to the next executable statement following the CALL in the calling program. If the CALL statement is the last statement in a DO, looping con- tinues until satisfied. Subprograms may be called from a main program or from other subprograms. Any subprogram called, however, may not call the calling program. That is, if program A calls sub- program B, subprogram B may not call program A. Furthermore, a program or subprogram may not call itself. Rules: 1. The subroutine returns values through formal parameters which are substituted for actual parameters or through common variables. 2. The subroutine name may not appear in any declarative statement (TYPE, DIMENSION, et cetera). No value is associated with its name. 3. In the subroutine call, the following forms of actual parameters are permissible: arithmetic expression constant or variable, simple or subscripted array name function reference subroutine or function name logical expression When the name of a function subprogram appears as an actual parameter, that name must also appear in an EXTERNAL statement in the calling program. When the name of a function subprogram is used as an actual parameter, it may be in either of two forms: a. FUNCTION POSH (ARG3) b. FUNCTION POSH (FUNCT, ARG4) 6 6-4 • To call these functions, then, the calling program uses, respectively, the forms: a. B = POSH (CALC(X) ) b. B = POSH (CALC,X) When a subroutine appears as an actual param- eter, the subroutine name may appear alone or with a parameter list. When a subroutine appears with a parameter list, the subroutine name and its parameters must ap- pear as separate actual parameters. Level I— Calling program 6. Logical expressions may be actual parameters. Examples: 1. Subroutine Subprogram SUBROUTINE BLVDLDR (A,B,W) W = 2.*B/A END Calling Program References CALL BLVDLDR (X(I),Y(I),W) A = PULL (DIS,A,B) CALL BLVDLDR (X(I) + H/2. ,Y(I) + C(1)/2.,W) B = PULL (DISP,C,D) Level II— Function statement and subroutine call FUNCTION PULL (SUB,ARG1,ARG2) CALL SUB (ARG1, ARG2) PULL = - - END Level III— Subroutine definition SUBROUTINE DIS (DUMMY 1, DUMMY 2) END SUBROUTINE DISP (DUMMY 3, DUMMY 4) CALL BLVDLDR (X(I) + H,Y(I) + C(3),Z) Subroutine Subprogram (Matrix Multiply) SUBROUTINE MATMULT COMMON/BLK1/X(20,20),Y(20,20), Z(20,20) 1 = 1,20 J = 1,20 DO 10 DO 10 Z(IJ)=0 DO 10 K = l,20 10 Z(IJ) = (IJ) + X(LK)*Y(K,J) RETURN END Calling Program Reference COMMON/BLK1/A(20,20),B(20,20), C(20,20) END 4. Because formal parameters are local to the sub- routine in which they appear, they may be the same as names appearing outside the subroutine. 5. Actual and formal parameters must agree in order, type and, for the first call of the sub- program, in number (example 4). CALL MATMULT 6-5 3. Subroutine Subprogram SUBROUTINE ISHTAR (Y,Z) COMMON/1/X(100) Z = 0. DO 5 1 = 1,100 5 Z=Z+X(I) CALL Y RETURN END Calling Program Reference COMMON/1/A(100) EXTERNAL PRNTIT CALL ISHTAR (PRNTIT,SUM) 6.8 PROGRAM ARRANGEMENT FORTRAN-66 assumes that all statements and comments appearing between a PROGRAM, SUB- ROUTINE or FUNCTION statement and an END statement belong to one program. A typical arrange- ment of a set of main program and subprograms follows. /PROGRAM SOMTHING ^END -SUBROUTINE SI iEND -SUBROUTINE S2 *END 6-6 -FUNCTION Fl (. ..) \END /FUNCTION F2 (. . .) ^END 6.9 RETURN AND END A subprogram normally contains one or several RETURN statements that indicate the end of logic flow within the subprogram and return control to the calling program. The form is: RETURN In function references, control returns to the state- ment containing the function. In subroutine subpro- grams, control returns to the calling program. The END statement marks the physical end of a program, subroutine subprogram or function sub- program. If the RETURN statement is omitted, END acts as a return to the calling program. A RETURN statement in the main program causes an exit to the monitor. 6.10 ENTRY This statement provides alternate entry points to a function or subroutine subprogram. Its form is: ENTRY name Name is an alphanumeric identifier, and may ap- pear within the subprogram only in the ENTRY statement. Each entry identifier must appear in a separate ENTRY statement. The maximum number of entry points, including the subprogram name, is 20. The formal parameters, if any, appearing with the FUNCTION or SUBROUTINE statement do not appear with the ENTRY statement. ENTRY may appear anywhere within the subprogram ex- cept it must not appear within a DO; it can not be labeled. In the calling program, the reference to the entry name is made just as though reference were being made to the FUNCTION or SUBROUTINE in which the ENTRY is imbedded. Rules 5 and 6 of 6.2 apply. ENTRY names must agree in type with the func- tion or subroutine name. < Examples: FUNCTION JOE (X,Y) 10 JOE=X+Y RETURN ENTRY JAM IF(X.GT.Y)10,20 20 JOE=X-Y END This could be called from the main programi as follows: Z=A + B-JOE(3.*P,Q-l) ^P R=S+JAM(Q,2.*P) 6.11 VARIABLE DIMENSIONS IN SUBPROGRAMS In many subprograms, especially those performing matrix manipulation, the programmer may wish to vary the dimension of the arrays each time the sub- program is called. This is accomplished by specifying the array identi- fier and its dimensions as formal parameters in the FUNCTION or SUBROUTINE statement head- ing a subprogram. In the subroutine call from the calling program, the corresponding actual param- eters specified are used by the called subprogram. The maximum dimension which any given array may assume is determined by a DIMENSION state- ment in the main program at compile time. Rules: 1. The rules of 6.2, 6.5, and 6.7 apply. 2. The formal parameters representing the array dimensions must be simple integer variables. The array identifier must also be a formal parameter. 3. The actual parameters representing the array dimensions may be integer constants or integer variables. 4. If the total number of elements of a given array in the calling program is N, then the total num- ber of elements of the corresponding array in the subprogram may not exceed N. Examples: 1. Consider a simple matrix add routine written as a subroutine: SUBROUTINE MATADD(X,Y,Z,M,N) DIMENSION X (M,N),Y(M,N),Z(M,N) DO 10 I=1,M DO 10 J=1,N 10 Z(IJ)=X(I,J)+Y(I,J) RETURN END The arrays X,Y,Z and the variable dimensions M,N must all appear as formal parameters in the SUBROUTINE statement and also appear in the DIMENSION statement as shown. If the calling program contains the array allocation declaration DIMENSION A(10,10), B(10,10), C(10,10) DIMENSION D(4, 8), E(4, 8), F(4, 8) DIMENSION P(3, 12), Q(3, 12), R(3, 12) the program may call the subroutine MATADD from several places within the main program, varying the array dimension within MATADD each time as follows: CALL MATADD (A,B,C,10,10) CALL MATADD (D,E,F,4,i CALL MATADD (P,Q,R,3,12) The compiler does not check to see if the limits of the array established by the DIMENSION state- ment in the main program are exceeded. 6-7 yn-- Y-21-- y a i • • y« • • Its transposed Y' is Yin y= n y 3n y*n Y' = Yii y2i y 3 i y« y ln y=n y 3n y4n The following 6600 FORTRAN program permits variation of N from call to call : SUBROUTINE MATRAN (Y, YPRIME, N) DIMENSION Y(4,N), YPRIME (N, 4) DO 7 I = 1,N DO 7 J = l,4 7 YPRIME (IJ) = Y(J,I) END 6-8 (.. • 7. FORMAT SPECIFICATIONS Data transmission between storage and an external unit requires the FORMAT statement and the I/O control statement (Chapter 9). The I/O statement specifies the input/output device and process— READ, WRITE, and so forth, and a list of data to be moved. The FORMAT statement specifies the manner in which the data are to be moved. In binary tape statements no FORMAT statement is used. 7.1 THE I/O LIST The list portion of an I/O control statement indi- cates the data elements and the order, from left to right, of transmission. Elements may be simple variables or array names (subscripted or non-sub- scripted). They may be constants on output only. List elements are separated by commas, and the order must correspond to the order of the FOR- MAT specifications. 7.1.1 TRANSMISSION OF ARRAYS Part or all of an array can be represented as a list item. Multi-dimensioned arrays may appear in the list, with values specified for the range of the sub- scripts in an implied DO loop. The general forms are: ( a ) transmission by columns ( ( ( A ( I, J,K ),I = m l! m 2 ,m 3 )J = n^n^n,, ) , K=p l5 p 2 ,p 3 ) (b) transmission by rows ( ( ( A ( I, J,K ) ,K = pi,p 2 ,p 3 ) , J = rix.na.ng ) , I = m^mo.mg ) mi,ni,pi are any computable arithmetic expres- sion. If m 3 , n 3 or p 3 is omitted, it is construed as being 1. I,J,K are subscripts of A. If a subscript is omitted when transmitting an array, a DO statement is generated for the missing subscript using the entire range of values. The I/O list may contain nested DO loops to any depth within the overall DO nest limit of 50 (in- cluding the nest depth in which the I/O statement resides ) . Example: DO loops nested 5 deep: ( ( ( ( (A(IJ,K),B(M), C(N), N = ni ,n 2 ,n 3 ), M=mi,m,,m 3 ), K=k 1 ,k 2 ,k 3 ), J = Ji>J2,j 3 ), I=ii,i 2 ,is) During execution, each subscript (index variable) is set to the initial index value: I = i x , J=ji, K=k 1; M = m 1 , N=n x . The first index variable defined in the list is incre- mented first. Data named in the implied DO loops are transmitted in increments according to the third DO loop parameter until the second DO loop parameter is exceeded. If the third parameter is omitted, the increment value is 1. When the first index variable reaches the maximum value, it is reset; the next index variable to the right is incre- mented; and the process is repeated until the last index variable has been incremented. An implied DO loop may also be used to transmit a simple variable more than one time. In (A,K = 1,10), A will be transmitted 10 times. Example: As an element in an input/output list, the expression ( ( (A(IJ,K),I = m 1 ,m 2 ,m 3 ), J = n 1; n 2 ,n 3 ), K = pi,p 2 ,p 3 ) implies a nest of DO loops of the form DO 10 K=p 1: p 2 ,p., DO 10 J=n 1; n 2 ,n 3 DO 10 I^m^m,,!!!,, Transmit A(I,J,K) 10 CONTINUE To transmit the elements of a 3 by 3 matrix by columns : ((A(I,J),I = 1,3),J=1,3) To transmit the elements of a 3 by 3 matrix by rows: ((A(I,J),J=1,3),I=1,3) If a multi-dimensioned array name appears in a list without subscripts, the entire array is transmitted. For example, a multi-dimensioned, non-subscripted list element, SPECS, with an associated DIMEN- SION SPECS (7,5,3) statement is transmitted as though under control of the nested DO loops. DO 10 K=l,3 DO 10 J = 1,5 7-1 DO 10 1 = 1,7 Transmit SPECS(IJ,K) 10 CONTINUE or as though under control of an implied DO loop, ..,(((SPECS(IJ,K),I = 1,7),J=1,5), K = l,3),... I/O Lists: ( (BUZ(K,2*L),K = 1,5), L = l, 13,2) Q(3), Z(2,2), (TUP(3*I-4), 1=2,10) (RAZ(K), K=l, LIM1, LIM2) 7.2 FORMAT STATEMENT The BCD I/O control statements require a FOR- MAT statement which contains the specifications relating to the internal- external structure of the corresponding I/O list elements. FORMAT (spec,, . . . ,k(spec m , . . . ),spec n , . . . ) Speci is a format specification and k is an optional repetition factor which must be an unsigned integer constant. The FORMAT statement is non-execut- able, and may appear anywhere in the program. 7.3 FORMAT SPECIFICATIONS The data elements in I/O lists are converted from external to internal or from internal to external representation according to FORMAT conversion specifications. FORMAT specifications may also contain editing codes. FORTRAN-66 conversion specifications Ew.d Single precision floating point with exponent Fw.d Single precision floating point without exponent Dw.d Double precision floating point with exponent C(Zw.d,Zw.d) Complex conversion; Z may be E or F conversion Iw Decimal integer conversion Ow Octal integer conversion Aw Alphanumeric conversion R w Alphanumeric conversion Lw Logical conversion n P Scaling factor FORTRAN-66 editing specifications W X Intra-line spacing wH 7-2 ;'} Heading and labeling / Begin new record n/ Create n-1 blank records. Both w and d are unsigned integer constants, w specifies the field width, the number of character positions in the record; and d specifies the number of digits to the right of the decimal within the field. 7.4 CONVERSION SPECIFICATIONS 7.4.1 EW.D OUTPUT E conversion is used to convert floating point num- bers in storage to the BCD character form for out- put. The field occupies w positions in the output record; the corresponding floating point number will appear right justified in the field as I Aa.a aE±eee -307^eee^307 «•« a are the most significant digits of the integer and fractional part and eee are the digits in the exponent. If d is zero or blank, the decimal point and digits to the right of the decimal do not appear as shown above. Field w must be wide enough to contain the significant digits, signs, deci- mal point, E, and the exponent. Generally, w is greater than or equal to d + 7. If the field is not wide enough to contain the output value, asterisks are inserted for the entire field. If the field is longer than the output value, the quan- tity is right justified with blanks in the excess posi- tions to the left. For P-scaling on output, see section 7.6.2. Examples: A contains — 67.32 or +67.32 PRINT 10, A 10 FORMAT (E11.3) Result: -6.732E + 001or6.732E + 001 PRINT 20, A 20 FORMAT (E14.3) Result: aaa -6.732E + 001 or aaaa 6.732E + 001 A contains — 67.32 PRINT 30, A 30 FORMAT (E 10.3) Result: ********** p rov ision not made for sign PRINT 40, A 40 FORMAT (E 11.4) Result: *********** Same as above # 9 7.4.2 EW.D INPUT The E specification converts the number in the in- put field (specified by w) to a real and stores it in the appropriate location in memory. Subfield structure of the input field: input field , A „ integer fraction exponent The total number of characters in the input field is specified by w; this field is scanned from left to right; blanks within the field are interpreted as zeros. The coefficient subfield, composed of an integer and/or a fraction, begins with a sign ( + or — ) or a digit and contains a string of digits (a sequence of consecutive numbers). The fraction portion which begins with a decimal point contains a string of digits. The subfield is terminated by a D, E, a + or — , or the end of the input field. An exponent subfield begins with a D, E, a + or a — . When it begins with E or D, the + or — appears between the E or D and the string of digits in the subfield. The value of this string of digits must be less than 310. Permissible subfield combinations: + 1.6327E -04 -32.7216 +328+5 .629E -1 + 136 .07628431 E -06 (interpreted as zero) Rules: integer fraction exponent integer fraction integer exponent fraction exponent integer only fraction only exponent only In the Ew.d input specification, d acts as a nega- tive power of ten scaling factor when the decimal point is not present. The internal representation of the input quantity will be: (integer subfield) xl0- d X10 (expanent s "" tieId > For example, if the specification is E7.8, the input quantity 3267 + 05 is converted and stored as: 3267 X10- 8 X10 5 = 3.267. 2. If E conversion is specified, but a decimal point occurs in the input constants, the decimal point will override d. The input quantity 3.67294 + 5 may be read by any specification but is always stored as 3.67294 X10 5 . 3. When d does not appear, it is assumed to be zero. 4. The field length specified by w in Ew.d must always be the same as the length of the input field containing the input number. When it is not, incorrect numbers may be read, converted and stored as shown below. The field w includes the significant digits, signs, decimal point, E, and exponent. READ 20,A,B,C 20 FORMAT (E9.3,E7.2,E10.3) The input quantities appear on a card in three con- tiguous field columns 1 through 24: L — 9 „_L-5-J» io «4 + 6.47E-01-2.36 + 5.321E + 02 The second specification (E7.2) exceeds the physical field width of the second value by two characters. Reading proceeds as follows: — 7- -10 "I I + 6.47E-0U -2.36 + 5.321E + 02 + 6.47E - 01 1-2.36 + 51 321E + 02 + 6.47E-01-2.36 + 5 |.321E + 02 aa| First +6.47E — 01 is read, converted and placed in location A. 7-3 Next, —2.36 + 5 is read, converted and placed in location B. The number actually desired was —2.36, but the specification error (E7.2 instead of E5 2) caused the two extra characters to be read. The number read ( — 2.36 + 5) is a legitimate input repre- sentation under the definitions and restrictions. Finally .321E + 02 AA is read, converted and placed in location C. Here again, the input number is legiti- mate; and it is converted and stored, even though it is not the number desired. The above example illustrates a situation where numbers are incorrectly read, converted, and stored, and yet there is no immediate indication that an error has occurred. Examples: Ew.d Input Input Field Specifi- cation + 143.26E-03 E11.2 -12.437629E + 1 E13.6 8936E + 004 E9.10 327.625 E7.3 4.376 E5 -.0003627 + 5 E11.7 -.0003627E5 E11.7 blanks 1E1 E + 06 E 1 Ew.d E3.0 E6.3 Converted Value .14326 -124.37629 .008936 327.625 4.376 -36.27 -36.27 -0. 10. E10.6 0. 10. Remarks All subfields present All subfields present No fraction subfield. In- put number converted as 8936. X io- Mt4 No exponent subfield No d in spec- ification Integer sub- field contains — only Integer sub- field contains — only All subfields empty No fraction subfield. In- put number converted as 1. X 10 1 No integer or fraction sub- field. Zero stored regard- less of expo- nent field contents Blanks are interpreted as zeros 7.4.3 FW.D OUTPUT The field occupies w positions in the output record; the corresponding list element must be a floating point quantity, and it will appear as a decimal num- ber; right justified in the field w, as: ± 8 ... 8 .8 ... S 8 represents the most significant digits of the num- ber. The number of places to the right of the deci- mal point is specified by d. If d is zero or omitted, the fractional digits do not appear. If the number is positive, the + sign is suppressed. If the field is too short to accommodate the num- ber, asterisks will appear in the output field. If the field w is longer than required to accommo- date the number, it is right justified with blanks occupying the excess field positions to the left. Examples: A contains +32.694 PRINT 10,A 10 FORMAT(F7.3) Result: a 32.694 PRINT 11,A 11 FORMAT(F10.3) Result: aaaa 32.694 A contains -32.694 PRINT 12,A 12 FORMAT(F6.3) Result: ****** no provision for — sign 7.4.4 FW.D INPUT This specification is a modification of Ew.d. The input field consists of an integer and a fraction sub- field. An omitted subfield is assumed to be zero. All rules listed under Ew.d input apply. P-scaling is permissible. 7-4 # # Examples: Fw.d Input Specifi- Converted Input Field cation Value Remarks 367.2593 F8.4 367.2593 Integer and fraction field 37925 F5.7 .0037925 No fraction subfield. In- put number converted as 37925 X 10" T -4.7366 F7 -4.7366 No d in spec- ification .62543 F6.5 .62543 No integer subfield .62543 F6.d .62543 Decimal point over- rides d of specification + 144.15E-03 F11.2 .14415 Exponents are legitimate in F input and may have P-scaling 7.4.5 DW.D OUTPUT The field occupies w positions of the output record; the corresponding list element which must be a double precision quantity appears as a decimal number, right justified in the field w: Aa.a . . . a E ± eee -307^eee^307 D conversion corresponds to Ew.d output except that 29 is the maximum number of significant digits in the fraction. 7.4.6 DW.D INPUT D conversion corresponds to Ew.d input except that 29 is the maximum number of significant digits permitted in the combined integer-fraction field. P-scaling is not applicable. D is acceptable in place of E as the beginning of an exponent field. Example: TYPE DOUBLE Z,Y READ1, Z,Y 1 FORMAT (D24.17,D15) Input card: .col. 1, ' -6.31675298443769217E-03 f 24 * 2.718926453147' i 15 ■ 7.4.7 C (Z1W1.Di.Z2W2.D2) OUTPUT Z is either E or F. The field occupies Wi + w a posi- tions in the output record, and the corresponding list element must be complex. w t + w. are two real values; w t represents the real part of the complex number and \v-, represents the imaginary part. The value may be one of the following forms : A8.8 ... 8 Exp.AS.8 . . . S Exp. (Ew.d.Ew.d) AS. 8 . . . 8 Exp.AS . . . S.8 . . . 8 (Ew.d.Fw.d) .8. 8 . . . 8A8.8 ... 8 Exp. . 8.8 . . .8A8 ... 8.8 .. .8 (Fw.d.Ew.d) (Fw.d.Fw.d) AS .. A8 . Exp is ± e^ej. The restrictions for Ew.d and Fw.d apply. If spaces are desired between the two output num- bers, the second specification should indicate a field (w 2 ) larger than required. Example: TYPE COMPLEX A PRINT 10,A 10 FORMAT (C(F7.2,F9.2) ) real part of A is 362.92 imaginary part of A is —46.73 Result: A 362.92 AAA - 46.73 7.4.8 C (Z1Wj.D1.Z2W2.D2) INPUT Z is either E or F and the input quantity occupies Wi +w 2 character positions. The first w t characters are the representation of the real part of the com- plex number, and the remaining w. characters are the representation of the imaginary part of the com- plex number. The restrictions for Ew.d and Fw.d apply. 7-5 Example: TYPE COMPLEX A,B READ 10,A,B 10 FORMAT (C(F6.2,F6.2), C(E10.3,E10.3) ) Input card: The input field w which consists of an integer sub- field may contain only the characters +, — , the digits through 9, or blank. When a sign appears, it must precede the first digit in the field. Blanks are interpreted as zeros. The value is stored right justified in the specified variable. col. 1 -42.13 + 13.91 + 1.456E + 03-1.216E-01 U— 6-1—6- -10 10- 7.4.9 1W OUTPUT I specification is used to output decimal integer values. The output quantity occupies w output rec- ord positions; it will appear right justified in the field w, as: AS ... S 8 is the most significant decimal digits (maximum 18) of the integer. If the integer is positive, the + sign is suppressed. If the field w is larger than required, the output quantity is right justified with blanks occupying excess positions to the left. If the field is too short, characters are discarded from the left. Example: PRINT 10,IJ,K 10 FORMAT (18,110,15) Result: I contains -3762 J contains +4762937 K contains +13 AAA -3762 AAA 4762937 AAA 13 ■10- »5-~ 7.4. lO IW INPUT The field is w characters in length and the corre- sponding list element must be a decimal integer quantity. 7-6 Example: READ 10,I,J,K,L,M,N 10 FORMAT (13,17,12,13,12,14) Input card: col. 1 139AA-15AA18 AA7A3A1A4 \ —I 3 U 7 — -U l—3»| 2 [—4—1 In memory: I contains 139 J -1500 K 18 L 7 M 3 N 104 7.4.11 OW OUTPUT O specification is used to output octal integer values. The output quantity occupies w output record posi- tions, and it will appear right justified in the field as: S S ... 8. The 8 are octal digits. If w is 20 or less, the right- most w digits appear. If w is greater than 20, the number is right justified in the field with blanks to the left of the output quantity. A negative number is output in its machine form (one's complement). 7.4.12 ow INPUT Octal integer values are converted under O specifi- cation. The field is w octal integer characters in length and the corresponding list element must be an integer quantity. The input field w consists of an integer subfield only (maximum of 20 octal digits). The only char- acters that may appear in the field are +, or — , blank and through 7. Only one sign is permitted; it must precede the first digit in the field. Blanks are interpreted as zeros. Example: TYPE INTEGER P,Q,R READ 10,P,Q,R 10 FORMAT (010,012,02) w^lO output w>10 input ■w field 10 Input Card: i " 3737373737666 A 6644 A 444-0 \ L, 10 -»-i-« 12 ■- 2 L»- In memory: P: Q: R: 00000000003737373737 00000000666066440444 77777777777777777777 A negative number is represented in complement form. A negative octal number is represented internally in 20-digit seven's complement form obtained by subtracting each digit of an octal number from seven. For example, if —703 is an input quantity, its internal representation is 77777777777777777074. That is, 77777777777777777777 - 00000000000000000703 77777777777777777074 7.4.13 AW OUTPUT A conversion is used to output alphanumeric char- acters. If w is 10 or more, the output quantity ap- pears right justified in the output field, blanks fill to left. If w is less than 10 the output quantity repre- sents the leftmost w characters, left justified in the field. 7.4.14 AW INPUT This specification will accept as list elements any set of six bit characters including blanks. The in- ternal representation is BCD; the field width is w characters. If w exceeds 10, the input quantity will be the right- most characters. If w is 10 or less, the input quantity goes to the designated storage locations as a left justified BCD word, the remaining spaces are blank- filled. memory 10 BCD characters w<10 output w==10 input 10 field memory w BCD char. suppressed char, or blanks Example: (Compare with next example) READ 10,Q,P,O 10 FORMAT (A10,A10,A4) Input card : col. 1 LUX MENTIS LUX ORBIS LUX \ II I -«■ 10 — » ■ « 4 ♦! In memory: Q p o LUXbMENTIS bLUXbORBIS bLUXbbbbbb 7.4.15 RW OUTPUT This specification is the same as the Aw specifica- tion with the following exception. If w is less than 10 the output quantity represents the rightmost characters. 7-7 7.4.16 RW INPUT If w is less than 10, the input quantity goes to the designated storage location as a right justified bi- nary zero filled word. w=^10 output w>10 input field 10 memory 10 BCD char. w<10 output w^lO input 10 field ■w- memory zeros w BCD char. Example: (Compare with previous example) READ 10,Q,P,O 10 FORMAT (R10,R10,R4) Input card: col. 1 ''lux mentis lux orbis lux X H 10 -4- 10 — "4-4-H 7.4.17 LW OUTPUT L specification is used to output logical values. The input/output field is w characters long and the cor- responding list element must be a logical element. If w is greater than 1, 1 or is printed right justified in the field w with blank fill to the left. Example: TYPE LOGICAL IJ,K,L PRINT 5,IJ,K,L 5 FORMAT (4L3) I contains 1 J contains K contains 1 L contains 1 Result: AA^AA^ AA 1 AA 1 7.4.18 LW INPUT This specification will accept logical quantities as list elements. A zero or a blank in the field w is stored as zero. A one in the field w is stored as one. Only one such character (0 to 1) may appear in any input field. Any character other than 0, 1, or blank is incorrect. 7.5 EDITING SPECIFICATIONS 7.5.1 wx This specification may be used to include w blanks in an output record or to skip w characters on input to permit spacing of input/output quantities. Examples: PRINT 10,A,B,C A contains 7 10 FORMAT B contains 13.6 ( I2,6X,F6.2,6X,E13.5 ) C contains 1462.37 Result ^7^6-^ ft 13.60<-6-* A 1.46237E + 003 READ 11,R,S,T 11 FORMAT(F5.2,3X, F5.2,6X,F5.2) or FORMAT (F5.2,3XF5.2,6XF5.2) Input card: col. 1 14.62 AA $13.78 A COST A 15.97 'l T = 15. In memory: R = 14.62 S = 13.78 97 In memory: Q p o LUXbMENTIS bLUXbORBIS OOOOOObLUX In the specification list, the comma following X is optional. 7-8 7.5.2 WH OUTPUT This specification provides for the output of any set of six-bit characters, including blanks, in the form of comments, titles, and headings, w is an unsigned, integer specifying the number of characters to the right of the H that will be transmitted to the output record. H denotes a Hollerith field. The comma fol- lowing the H specification is optional. Examples: Source program: PRINT 20 20 FORMAT(28H BLANKS COUNT IN AN H FIELD.) produces output record: a BLANKS COUNT IN AN H FIELD. Source program: PRINT 30,A A contains 1.5 30 FORMAT(6H LMAX=,F5.2) comma is optional produces output record: a LMAX = A 1.50 7.5.3 WH INPUT The H field may be used to read a new heading into an existing H field. Example: Source program: READ 10 10 FORMAT (27H AAAAAAAAAAAAAAAAAAAAAAAAAAA ) A THIS IS A VARIABLE HEADING 27 cols After die READ, die FORMAT statement labeled 10 will contain the alphanumeric information read from the input card; a subsequent reference to statement 10 in an output control statement would act as follows: PRINT 10 produces die printer line: a THIS IS A VARIABLE HEADING 7.5.4 *N CHAR.* OUTPUT This specification can be used as an alternate form of wH to output headings, titles, and comments. Any 6-bit character (except asterisk) between the asterisks will be output. Tile first asterisk denotes the beginning of the Hollerith field; the second asterisk terminates the field. Examples: 1. Source program: PRINT 10 10 FORMAT (*a SUBTOTALS*) produces the output records: SUBTOTALS 2. If an asterisk accidentally occurs in the char- acters to be output, it will terminate the field and the characters following die asterisk will be inter- preted as incorrect format specifications. Source program: PRINT 10 10 FORMAT (*ABC*BE*) produces the output record: ABC The conver- sion routine will attempt to interpret BE as a format specification. 7.5.5 , * INPUT This specification is used in place of wH to read a new heading into an existing Hollerith field. Char- acters are stored in the heading until an asterisk is encountered in the input field or until all the spaces in the format specification are filled. If the format specification contains n spaces and the mth charac- tem (m<n) in the input field is an asterisk, all char- acters to the left of the asterisk will be stored in the heading and the remaining character positions in the heading will be filled with blanks. Examples: 1. Source program: READ 10 10 FORMAT (*aaaaaaaaaaaaaaaaaaaa*) Input card: [FORTRAN FOR THE 6600 A subsequent reference to statement 10 in an output control statement: PRINT 10 produces: FORTRAN FOR THE 6600 7-9 2. Source program: READ 10 10 FORMAT (*AAAAAAA : : ) Input card: f / HEAD*LINE PRINT 10 produces: HEADaaa 7.5.6 NEW RECORD The slash, /, which signals the end of a BCD record may occur anywhere in the specifications list. It need not be separated from the other list elements by commas; consecutive slashes may appear in a list. During output, it is used to skip lines, cards, or tape records. During input, it specifies that control passes to the next record or card, k + 1 consecutive slashes produce k blank lines, or n/ produces n-1 blank lines during output and skips n-1 records or cards during input. Examples: PRINT 10 10 FORMAT (20X,7HHEADING///6X, 5HINPUT,19X,6HOUTPUT) Print-out: HEADING me 2 line 2 line 3 INPUT OUTPUT line 4 Statement 10 in the example may also be written: 10 FORMAT (20X, 7HHEADING3/6X, 5HINPUT, 19X,6HOUTPUT) Each line corresponds to a BCD record. The second and third records are null and produce the line spacing illustrated. Internally: A =-11.6 C= 46.327 B= .325 D= -14.261 PRINT 11,A,B,C,D 11 FORMAT (2E12.2/2F7.3) Result: aa -1.16E + 001aaa3.25E-001 a 46.327 -14.261 PRINT 11,A,B,C,D 11 FORMAT (2E12.2/ /2F7.3) Result: aa -1.16E + 001aaa3.25E-001 a 46.327 -14.261 PRINT 15, (A(I), = 1,9) 15 FORMAT (8HRESULTS2/(3F8.2)) ) Result: RESULTS 7-10 3.62 -4.03 -9.78 -6.33 7.12 3.49 6.21 -6.74 -1.18 7.6 NP SCALE FACTOR A scale factor may precede the F conversion and E conversion. The scale factor is: External number = Internal number X10 Bcale faGtor . The scale factor applies to Fw.d on both input and output and to Ew.d and Dw.d on output only. A scaled specifica- tion is written as: y nP w.d n is a signed integer constant. The nP specifi- cation may appear with complex conversion, C(Zw.d,Zw.d); each word is scaled separately according to Fw.d or Ew.d scaling. 7.6.1 FW.D SCALING Input The number in the input field is divided by 10 n and stored. For example, if the input quantity 314.1592 is read under the specification 2PF8.4, the internal number is 314.1592X10" 2 = 3.141592. Output The number in the output field is the internal num- ber multiplied by 10". In the output representation, the decimal point is fixed; the number moves to the left or right depending on whether the scale factor is plus or minus. For example, the internal number 3.1415926536 may be represented on output under scaled F specifications as follows: Specification Output Representation F13.6 3.141593 1PF13.6 31.415927 3PF13.6 3141.592654 -1PF13.6 .314159 7.6.2 EW.D SCALING Output The scale factor has the effect of shifting the output number left n places while reducing the exponent by n. Using 3.1415926538 some output representa- tions corresponding to scaled E-specifications are: Specification Output Representation E20.2 3.14E+000 1PE20.2 31.42E-001 2PE20.2 314.16E-002 3PE20.2 3141.59E-003 4PE20.2 31415.93E-004 5PE20.2 314159.27E-005 -1PE20.2 0.31E + 001 * 7.6.3 SCALING RESTRICTIONS The scale factor is assumed to be zero if no other value has been given; however, once a value has been given, it will hold for all D,E and F specifi- cations following the scale factor within the same FORMAT statement. To nullify this effect in sub- sequent D,E and F specifications, a zero scale factor, P, must precede a D,E, or F specification. Scale factors on D or E input specifications are ignored. The scaling specification nP may appear independ- ently of an E or F specification, but it will hold for all E and F specifications that follow within the same FORMAT statement unless changed by an- other nP. (3P, 319, F10.2) same as (319, 3PF10.2) 7.7.1 UNLIMITED GROUPS FORMAT specifications may be repeated without the use of a repetition factor. The innermost paren- thetical group that has no repetition factor is un- limited and will be used repeatedly until the I/O list is exhausted. Parentheses are the controlling factors in repetition. The right parenthesis of an unlimited group is equivalent to a slash. Specifica- tions to the right of an unlimited group can never be reached. The following are format specifications for output data: (E16.3,F20.7,(2I4,2(I3,F7.1)),F8.2) Print fields according to E16.3 and F20.7. Since 2(I3,F7.1) is a repeated parenthetical group, print fields according to (2I4,2)I3,F7.1) ), which does not have repetition operator, until the list elements are exhausted. F8.2 will never be reached. # 7.7 REPEATED FORMAT SPECIFICATIONS Any FORMAT specification may be repeated by using an unsigned integer constant repetition fac- tor, k, as follows: k(spec), spec is any conversion specification except nP. For example, to print two quantities K,L: PRINT 10 K,L 10 FORMAT (12,12) Specifications for K,L are identical; the FORMAT statement may be: 10 FORMAT (212). When a group of FORMAT specifications repeats itself, as in: FORMAT (E15.3,F6.1,I4,I4,E15.3,F6.1, 14,14), the use of k produces: FORMAT (2(E15.3, F6.1,2I4) ). The parenthetical grouping of FORMAT specifica- tions is called a repeated group. Repeated groups may be nested to 10 levels. FORMAT ( ni (-n 2 ( n 10 ) ))))))))) Therefore, FORMAT statements like the following example are legal. FORMAT (1H1,5(25X,13(5X,F6.2) ) ) 7.8 VARIABLE FORMAT FORMAT lists may be specified at the time of execution. The specification list including left and right parentheses, but not the statement number or the word FORMAT, is read under A conversion or in a DATA statement and stored in an integer array. The name of the array containing the speci- fications may be used in place of the FORMAT statement number in the associated input/ output operation. The array name that appears with or without subscript specifies the location of the first word of the FORMAT information. Examples: 1. Assume the following FORMAT specifications: (E12.2,F8.2,I7,2E20.3,F9.3,I4) This information could be punched in an input card and read by a program such as : DIMENSION IVAR(4) READ 1, (IVAR(I),I = 1,4) 1 FORMAT(3A8,A6) The elements of the input card will be placed in storage as follows: IVAR : (E12.2.F IVAR + 1 : 8.2,17,2 IVAR + 2 : E20.3,F9 IVAR +3 : .3,I4)bb 7-11 A subsequent output statement in the same pro- gram could refer to these FORMAT specifications as: PRINT IVAR(1),A,B,I,C,D,EJ or PRINT IVAR,A,B,I,C,D,EJ This would produce exactly the same result as the program: -PRINT 10AAI,CAEJ ._ -— . 10 FORMAT (E12.2,F8.2,I7,2E20.3,F9.3,I4) 2. DIMENSION LAIS(4) DATA (LAIS = 8H(E12.2,F8H8.2,2I7), 8H(F8.2,E1,8H2.2,2I7) ) Output statements: When 1 = 1 PRINT LAIS (I),A,B,IJ or PRINT LAIS,A,B,IJ This is also the same as: PRINT 1,A,B,I,J 1 FORMAT (E12.2,F8.2,2I7) When 1-3 PRINT LAIS (I),C,D,IJ This is the same as : PRINT 2,0,0,1,1 2 FORMAT (F8.2,E12.2,2I7) ♦ 7-12 f 8. INPUT-OUTPUT STATEMENTS Input-output statements transfer information be- tween the memory unit and one of the following external devices : An 80 column card reader An SO column card punch A 136 column printer A magnetic tape unit The external unit, i, may be specified by an integer variable or a constant, 1 ^ i ^ 49. Logical values are established for physical units by SIPROS. The FORMAT statement number for RCD data transmission is represented by n; and may be the statement number, a variable identifier or a formal parameter. Binary data transmission does not re- quire a FORMAT statement. The input-output list is specified by L. Binary in- formation is transmitted with odd parity checking bits. BCD information is transmitted with even parity checking bits. 8.1 WRITE STATEMENTS PRINT n,L Transfers information from the memory locations given by the list (L) identifiers to the standard output medium. This information is transferred as line printer images in accordance with the FOR- MAT specification n. PUNCH n,L transfers information from the memory locations given by the list (L) identifiers to the standard punch medium. This information is transferred as card images in accordance with the FORMAT speci- fication n. WRITE (i,n)L and WRITE OUTPUT TAPE i,n,L are equivalent forms which transfer information from memory to a specified unit (i) using the number of list (L) elements and the FORMAT specification (n) to de- termine the number of records that will be written on that unit. Each logical record is one physical record containing up to 136 characters; the infor- mation is recorded in even parity (BCD mode). WRITE(i)L and WRITE TAPE i,L are equivalent forms which transfer information from memory to a specified unit (i) using the number of list elements (L) to determine the number of logical records that will be written on that unit. If there is only one physical record in the logical record, the first word contains the integer 1. If there are n physical records in the logical record, the first word of the first n — 1 physical records con- tain zero; the first word of the nth physical record contains the integer n. This first word indicates how many physical records exist in a logical record, and it is used in the BACKSPACE Statement. The information is recorded in odd parity (binary mode). If the LIST is omitted, the WRITE(i) statement acts as a do-nothing. Examples: WRITE OUTPUT TAPE 10,20,A,B,C 20 FORMAT (3F10.6) WRITE (10,20) Q1,Q2,Q3 DIMENSION A(260), B(4) WRITE (10) A,B DO 5 1=1, 10 5 WRITE TAPE 6,AMAX(I), (M(IJ)J = 1,5) WRITE OUTPUT TAPE 4,21 21 FORMAT (33H THIS STATEMENT HAS NO DATA LIST.) 8.2 READ STATEMENTS READ n,L reads one or more card images, converting the in- formation from left to right, in accordance with the FORMAT specification (n), and stores the con- verted data in the memory locations named by the list (L) identifiers. The images read may come from 80-column Hollerith cards, or from magnetic tapes, prepared off-line, containing 80-character records in BCD mode. READ(i,n)L and READ INPUT TAPE i,n,L are equivalent forms which transfer information from a specified logical unit (i) to memory locations named by the list (L) identifiers. The number of list elements and the FORMAT specifications must conform to the rec- ord structure on the logical unit (up to 136 char- acters in the BCD mode). READ(i)L and READ TAPE i,L are equivalent forms which transfer information from a specified logical unit (i) to memory. The number of words in the list must be equal to or less than the number of words in the record on the logical unit. A record read by READ (i)L should be the result of a binary mode WRITE statement. If the statement occurs without a list, READ(i), the tape on unit i moves forward one logical record. Examples: READ 10,A,B,C 10 FORMAT (3F10.4) READ (2,13) (Z(K),K = 1,8) 13 FORMAT (F10.4) READ INPUT TAPE 6,20, Q1,Q2,Q3,Q4 20 FORMAT (4E11.3) READ (6) ( (A(IJ),I = 1,100)J=1,50) READ TAPE 6, ( (A(IJ),I = 1,100)J = 1,50) READ (5) (skip one logical record on unit 5) 8.3 BUFFER STATEMENTS There are three primary differences between the buffer I/O control statements and the read/write I/O control statements. 1. The mode of transmission (BCD or binary) is tacitly implied by the form of the read/write con- trol statement. In a buffer control statement, parity must be specified by a parity indicator. 2. The read/write control statements are associated with a list, and in BCD transmission with a FOR- MAT statement. The buffer control statements are not. 3. A buffer control statement initiates data trans- mission, and then returns control to the program, 8-2 permitting the program to perform other tasks while data transmission is in progress. In the descriptions that follow, these definitions hold: i logical unit number: integer constant or vari- able. p parity indicator: for even parity (BCD); 1 for odd parity (binary). A variable identifier: first word of data block to be transmitted. B variable identifier: last word of data block to be transmitted. The location represented by A must be equal to or less than the loca- tion represented by B. BUFFER IN (i,p) (A,B) transmits information from unit i in mode p to memory locations A through B. If a magnetic tape containing BCD records written by WRITE(i,n) is used by BUFFER IN, only one physical record will be read. If a magnetic tape written by WRITE(i) is read by BUFFER IN, only one physical record is read. BUFFER OUT (i,p) (A,B) transmits information from memory locations A through B, to unit i in mode p. The physical rec- ord written contains B— A + l words, or a maximum of 512 words. 8.4 TAPE HANDLING STATEMENTS The logical unit number, i, may be an integer vari- able or constant. REWIND i rewinds the magnetic tape mounted on unit i. If tape is already rewound, the statement acts as a do-nothing. BACKSPACE i backspaces the magnetic tape mounted on unit i one logical record. (A logical record is a physical record; except for tapes written by a WRITE(i)L statement). If tape is at load point (rewound) this statement acts as a do-nothing. END FILE i writes an end-of-file on the magnetic tape mounted on unit i. <t The tape handling statements cannot be used on the standard input, standard output, or standard punch media. 8.5 STATUS CHECKING STATEMENTS IF(EOF,i)n 1: n 2 checks the previous read (write) operation to de- termine if an end-of-file (end-of-tape) has been en- countered on unit i. If it has, control is transferred to statement n^ if not, control is transferred to statement n 2 . IF(IOCHECK,i)n 1 ,n 2 checks the previous read (write) operation to de- termine if a parity error has occurred on unit i. If it has, control is transferred to statement n^ if not, control is transferred to statement n 2 . IF(UNIT,i)n 1 ,n 2 ,n.„n 4 is the status checking statement used with buffer control. It should always appear before the first statement that uses any of the variables transferred in the buffer mode to avoid loss of information. The n,- are statement numbers and the following criteria apply: Check the status of the last buffering operation on unit i and transfer control to statement n x if buffer operation is not complete n, if buffer operation is complete and NO error oc- curred n 3 if buffer operation is complete and an EOF or EOT occurred rii if buffer operation is complete and parity or buf- fer length errors occurred. A buffer length error occurs on read only to indi- cate that a record of length k words has been read into a buffer area where word length is greater than k. Program 5 GO TO (50,4)J Example: Program 1 = 1 BUFFER IN (10,0) (A,Z) 4 IF(UNIT,10)5,6,7,8 Remarks Set flag = 1 Initiate buffered read in even (BCD) parity. Check status of buffered transfer. Remarks Not finished. Do calcula- tions at 50. 50 {Some computation ^ not involving infor- \ mation in locations ( A-Z ' J = J + 1 GO TO 4 7 PRINT 70 70 FORMAT(12H EOF UNIT 10) GO TO 200 8 PRINT 80 80 FORMAT(35H PARITY OR BUF LENGTH ERROR UNIT 10) 200 REWIND 10 STOP 6 CONTINUE Calculations complete; increase flag by 1. Go to 4. End-of-file error. Rewind tape and stop. Stop. Buffer transmission complete. Continue program. 8.6 ENCODE/DECODE STATEMENTS The ENCODE/DECODE statements are compa- rable to the WRITE/READ statements, the essential difference being that no peripheral equipment is used in the data transfer. Information is transferred under FORMAT specifications from one area of memory to another. In the following descriptions, n and L have the same meanings as were defined for input-output statements. c is an integer constant or integer variable spec- ifying the record length (characters). V is a variable identifier or an array identifier. ENCODE (c,n,V)L The information of the list variables (L) is converted according to the n FORMAT statement and stored in the locations identified by V. DECODE (c,n,V)L 8-3 The information in the locations identified by V is converted according to the n FORMAT statement and stored in the list variables (L). Example: 1. The following is one method of packing the partial contents of two words into one word. In- formation is stored in core as follows: LOC(l)SSSSSxxxxx LOC(6)xxxxxaaaaa 10 BCD ch/wd. To form SSSSSaaaao: in storage location NAME: DECODE(10,1,LOC(6) )TEMP 1 FORMAT(5X,A5) ENCODE(10,2,NAME) LOC(l),TEMP 2 FORMAT(2A5) The DECODE statement places the last 5 BCD characters of LOC(6) into the first 5 characters of TEMP. The ENCODE statement packs the first 5 characters of LOC(l) and TEMP into NAME. A more straightforward way of accomplishing this is with masking statements. Using the R specifica- tion, the program may be shortened to: ENCODE (10,1,NAME) LOC(l),LOC(6) 1 FORMAT (A5.R5) I. DECODE may be used to calculate a field defini- tion in a FORMAT specification at object time. Assume that in the statement FORMAT (2A10, Im) the programmer wishes to specify m at some point in the program, subject to the restriction 2 ^= m — 9. The following program permits m to vary. IF(M .LT. 10 AND. M .GT. 1)1,2 1 ENCODE (10,100,SPECMAT) M 100 FORMAT (7H(2A10,I,I1,1H) ) PRINT SPECMAT,A,B,J M is tested to insure it is within limits. If not, control goes to statement 2 which could be an error routine. If M is within limits, ENCODE packs the integer value of M with the characters: (2A10,I). This packed FORMAT is stored in SPECMAT. SPECMAT contains (2A10,Im). The print statement will print A and B under speci- fication A10, and the quantity J under specification 12 ,or 13 or ... or 19 according to the value of m. f 8-4 # APPENDIX A. CODING PROCEDURES CODING FORM FORTRAN-66 forms contain 80 columns in which the characters of the language are written, one character per column. All comment cards belonging to a specific pro- gram, or subprogram, should appear between the PROGRAM, SUBROUTINE, or FUNCTION state- ment and the END statement. STATEMENTS The statements of FORTRAN-66 are written in columns 7 through 72. Statements longer than 66 columns may be carried to the next line by using a continuation designator. More than one state- ment may be written on a line. Blanks may be used freely in FORTRAN statements to provide readi- bility. Blanks are significant, however, in H fields. STATEMENT SEPARATOR $ The special character $ may be used to write more than one statement on a line. Statements so written may also use the continuation feature. A $ symbol may not be used as a statement separator with FORMAT statements or continuations of FORMAT statements. These statements are equivalent: 1 = 10 JLIM = 1 K = K + 1 GO TO 10 I=10$JLIM = 1$ K=K+l$GOTO10 DOlI = l,10$A(I) =B(I)+C(I) 1 CONTINUE $1=3 Also: DO 11 = 1, 10 A(I) = B(I) + C(I) 1 CONTINUE 1=3 COMMENT CARD Comment information is designated by a C in col- umn 1 of a statement. Comment information will appear in the source program, but it is not trans- lated into object code. Columns 2 through 80 may be used. Continuation is not permitted; that is, each line of comments must be preceded by the C designator in column 1. STATEMENT IDENTIFIERS Any statement may have an identifier but only statements referred to elsewhere in the program require identifiers. A statement identifier is a string of 1 to 5 digits occupying any column positions 1 through 5. If I is an identifier, 1^1^ 99999; leading zeros are ignored; 1, 01, 001, 0001 are equivalent forms. Zero is not a statement identifier. In any given pro- gram or subprogram each statement identifier must be unique. If the statement identifier is followed by a character other than blank in column 6, the statement identifier is ignored. Statement identifiers of Declarative statements (ex- cepting FORMAT) are ignored by the compiler, except for diagnostic purposes. CONTINUATION The first fine of every statement must have a blank in column 6. If statements occupy more than one fine, all subsequent lines must have a FORTRAN character other than blank or zero in column 6. A FORTRAN-66 statement may have up to 660 opera- tors, delimiters (commas or parentheses) and identi- fiers within it. The compiler will accept up to nine continuation cards. IDENTIFICATION FIELD Columns 73 through 80 are always ignored in the translation process. These columns, therefore, may be used for identification when the program is to be punched on cards. Usually these columns con- tain sequencing information provided by the pro- grammer. PUNCHED CARDS Each line of the coding form corresponds to one 80-column card; the terms line and card are often used interchangeably. Source programs and data A-l can be read into the computer from cards; a relo- catable binary deck or data, can be punched di- rectly onto cards. Blank cards appearing within the input card deck are ignored. When cards are being used for data input, all 80 columns may be used. CARRIAGE CONTROL When printing on-line, the first character of a rec- ord transmitted by a PRINT statement is a carriage control character for spacing on the printer. The carriage control characters are: Action Single space after printing Double space before printing Eject page before printing Suppress spacing after print- ing, causing two successive records to be printed on the same line. The characters, 1 -f, are not printed; any other causes single spacing and is not printed. When printing off-line, the printer control is deter- mined by a printer routine for a particular installa- tion. Character Blank or any character other than die follow- ing 1 + « A-2 9 B. CENTRAL PROCESSOR OPERATION CODES • » Octal Opcode Mnemonic Address Comments . BRANCH UNIT 00 PS . Program stop 01 RJ K . Return jump to K 02 JP Bi + K . Jump to Bi + K 030 ZR Xj K . Jump to K if Xj = 031 NZ Xj K . Jump to K if Xj ^ 032 PL Xj K . Jump to K if Xj = plus (positive) 033 NG Xj K . Jump to K if Xj = negative 034 IR Xj K . Jump to K if Xj is in range 035 OR Xj K . Jump to K if Xj is out of range 036 DF Xj K . Jump to K if Xj is definite 037 ID Xj K . Jump to K if Xj is indefinite 04 EQ Bi Bj K . Jump to K if Bi = Bj 04 ZR Bi K . Jump to K if Bi = B0 05 NE Bi Bj K . Jump to K if Bi =£ Bj 05 NZ Bi K . Jump to K if Bi ^ B0 06 GE Bi Bj K . Jump to K if Bi ^ Bj 06 PL Bi K . Jump to K if Bi ^ B0 07 LT Bi Bj K . Jump to K if Bi < Bj 07 NG Bi K . Jump to K if Bi < B0 . BOOLEAN UNIT 10 BXi Xj . Transmit Xj to Xi 11 BXi Xj* Xk . Logical Product of Xj & Xk to Xi 12 BXi Xj + Xk . Logical sum of Xj & Xk to Xi 13 BXi Xj - Xk . Logical difference of Xj & Xk to Xi 14 BXi - : Kk . Transmit the comp. of Xk to Xi 15 BXi -: >Ck*Xj . Logical product of Xj & Xk comp. to Xi 16 BXi -: 5Ck + Xj . Logical sum of Xj & Xk comp. to Xi 17 BXi " : Kk - Xj . Logical difference of Xj & Xk comp. to Xi . SHIFT UNIT 20 LXi jk . Left shift Xi, jk places 21 AXi jk . Arithmetic right shift Xi, jk places 22 LXi Bj Xk . Left shift Xk nominally Bj places to Xi 23 AXi Bj Xk . Arithmetic right shift Xk nominally Bj places to Xi 24 NXi Bj Xk . Normalize Xk in Xi and Bj 25 ZXi Bj Xk . Round and normalize Xk in Xi and Bj 26 UXi Bj Xk . Unpack Xk to Xi and Bj 27 PXi Bj Xk . Pack Xi from Xk and Bj 43 MXi jk . Form mask in Xi, jk bits B-l Octal Opcode Mnemonic Address Comments . ADD UNIT 30 FXi Xj + Xk . Floating sum of Xj and Xk to Xi 31 FXi Xj - Xk . Floating difference Xj and Xk to Xi 32 DXi Xj + Xk . Floating DP sum of Xj and Xk to Xi 33 DXi Xj - Xk . Floating DP difference of Xj and Xk to Xi 34 RXi Xj + Xk . Round floating sum of Xj and Xk to Xi 35 RXi Xj - Xk . Round floating difference of Xj and Xk to Xi . LONG ADD UNIT 36 IXi Xj + Xk . Integer sum of Xj and Xk to Xi 37 IXi Xj - Xk . Integer difference of Xj and Xk to Xi . MULTIPLY UNIT 40 FXi Xj * Xk . Floating product of Xj and Xk to Xi 41 RXi Xj * Xk . Round floating product of Xj & Xk to Xi 42 DXi Xj * Xk . Floating DP product of Xj & Xk to Xi . DIVIDE UNIT 44 FXi Xj / Xk . Floating divide Xj by Xk to Xi 45 RXi Xj / Xk . Round floating divide Xj by Xk to Xi 46 NO . No operation 47 CXi Xk . Count the number of l's in Xk to Xi . INCREMENT UNIT 50 SAi Aj + K . Set Ai to Aj + K 50 SAi Aj - K . Set Ai to Aj + comp. of K 51 SAi Bj + K . Set Ai to Bj + K 51 SAi Bj - K . Set Ai to Bj + comp. of K 52 SAi Xj + K . SetAitoXj + K 52 SAi Xj - K . Set Ai to Xj + comp. of K 53 SAi Xj + Bk . Set Ai to Xj + Bk 54 SAi Aj + Bk . Set Ai to Aj + Bk 55 SAi Aj - Bk . Set Ai to Aj — Bk 56 SAi Bj + Bk . Set Ai to Bj + Bk 57 SAi Bj - Bk . Set Ai to Bj - Bk 60 SBi Aj + K . Set Bi to Aj + K 60 SBi Aj - K . Set Bi to Aj + comp. of K 61 SBi Bj + K . Set Bi to Bj + K 61 SBi Bj - K . Set Bi to Bj + comp. of K 62 SBi Xj + K . Set Bi to Xj + K 62 SBi Xj - K . Set Bi to Xj + comp. of K 63 SBi Xj + Bk . Set Bi to Xj + Bk 64 SBi Aj + Bk . Set Bi to Aj + Bk 65 SBi Aj - Bk . Set Bi to Aj - Bk 66 SBi Bj + Bk . Set Bi to Bj + Bk 67 SBi Bj - Bk . Set Bi to Bj - Bk • 1 B-2 t Octal Opcode Mnemonic 70 SXi 70 SXi 71 SXi 71 SXi 72 SXi 72 SXi 73 SXi 74 SXi 75 SXi 76 SXi 77 SXi Address Comments AJ + K Aj -K Bj +K Bj -K Xj +K Xj -K Xj +Bk Aj + Bk -Bk + Bk Aj Bj Bj - Bk Set Xi to A Set Xi to A Set Xi to B SetXitoB Set Xi to X Set Xi to X; Set Xi to X- Set Xi to A Set Xi to A Set Xi to B Set Xi to B + + K comp. of K + K + comp. of K + K + comp. of K + Bk + Bk - Bk + Bk - Bk t B-3 % • # 9 it C. STATEMENTS OF FORTRAN-66 Subprogram Statements Entry Points Inter-subroutine Transfer Statements PROGRAM name SUBROUTINE name SUBROUTINE name (p x ,p 2) . . . ) FUNCTION name ( Pl ,p 2 , . . . ) REAL FUNCTION name ( Pl p 2 , . . . ) INTEGER FUNCTION name ( PlJ p 2j . . . ) DOUBLE PRECISION FUNCTION name ( Pl ,p, COMPLEX FUNCTION name (p 1; p 2 , . . . ) LOGICAL FUNCTION name ( Pl ,p 2 , . . . ) ENTRY name EXTERNAL name^name,, . . . CALL name CALL name (p 1; . . . ,p n ) RETURN Data Declaration and Storage Allocation Type Declaration TYPE COMPLEX List TYPE DOUBLE List TYPE REAL List TYPE INTEGER List TYPE LOGICAL List COMPLEX List DOUBLE PRECISION List REAL List INTEGER LIST LOGICAL List DIMENSION V 1; V 2) . . .,V n COMMON/I i /List EQUIVALENCE (A,B, • ■ • ), (A1,B1, ...)■•• DATA (L = List), (L = List), . . . BANK, (bj), name!, . . . , (b 2 ), name,, . . . Arithmetic Statement Function Function (pi.p^, • • • p.i) — Expression Symbol Manipulation, Control and I/O Storage Allocations Replacement A = E Arithmetic L = E Logical/Relational M = E Masking A m = . . . = A x = E Multiple N — Non-executable E — Executable N* N N N N N N N N N N E E E N N N N N N N N N N N N N N N E E E E C-l Infra-program Transfers GOTOn GO TO m, (n, . . . n,„) GO TO (n 1; . . . ,n m )i GO TO (n 1: . . . ,n n ,),i IF (A) n 1; n 2 ,n :l IF (L) n x n 2 IF (L)s IF (SENSE LIGHT i) ni ,n 2 IF (SENSE SWITCH i) ni ,n 2 IF DIVIDE { Loop Control Miscellaneous Program Controls FAULT } CHECK/ ni ' n2 IF EXPONENT FAULT n l5 n 2 IF OVERFLOW FAULT n 1>n , IF (EOF,i) ni ,n 2 IF (IOCHECK), i) n x ,n 2 IF (UNIT,i) n^n^n* IF (UNIT,i) n^n^n., IF (UNIT,i) n x ,n 2 DOn 1 =m 1 ,m 2 ,m 3 I/O Format I/O Control Statements I/O Tape Handling Internal Data Manipulation ASSIGN s TO m SENSE LIGHT i CONTINUE PAUSE; PAUSE n STOP; STOP n FORMAT (spec 1; spec,, . . . ) READ n,L PRINT n,L PUNCH n,L READ (i,n) L READ INPUT TAPE WRITE (i,n) L WRITE OUTPUT TAPE 1 READ (i) L \ READ TAPE i,L / WRITE (i) L WRITE TAPE i,L BUFFER IN (i,p) (A : B) BUFFER OUT (i,p) (A,B) END FILE i REWIND! BACKSPACE i ENCODE (c 3 n ; V) L DECODE (c,n,V) L i,n,L j i,n,L j Program and Subroutine Termination END C-2 E E E E E E E E N E E E E E E E E E E E E E E N E E E E E E E E E E E E n ♦ N/E ^ D. LIBRARY FUNCTIONS It Form ABSF(X) XABSF(i) INTF(X) XINTF(X) MODF(X 1J X 2 ) XMODF (i x ,i 2 ) MAX0F(i 1; i2, . . .) MAX1F(X 1I X 2 , . . .) XMAX0F(i 1: i 2) . . .) XMAXlF(X 1J X a , . . .) MIN0F(i 1 ,i 2 , • • ■) MIN1F(X 1 ,X 2J ...). XMIN0F(i,i 3 , . . .) XMIN1F(X 1; X 2 , . . .) SINF(X) COSF(X) TANF(X) ASINF(X) ACOSF(X) ATANF(X) TANHF(X) SQRTF(X) LOGF(X) EXPF(X) SIGNF(X 1) X 2 ) XSIGNF(i 1; i 2 ) DIMF(X 1; X 2 ) XDIMF(i 1; i 2 ) Definition Absolute Value Truncation, integer Xi modulo X 2 ii modulo i 2 > Determine maximum argument 1 Determine minimum argument Sine X radians Cosine X radians Tangent X radians Arcsine X radians Arccos X radians Arctangent X radians Hyperbolic tangent X radians Square root of X Natural log of X e to Xth power Sign of X 2 times |Xi I Sign of i 2 times lij fIFX 1 >X 2 :X 1 -X 2 flf ii>i 2 : ii-i 2 llfi^i,: Actual Param- Mode of eter Type Result Real Real Integer Integer Real Real Real Integer Real Real Integer Integer Integer Real Real Real Integer Integer Real Integer Integer Real Real Real Integer Integer Real Integer Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Real Integer Integer Real Integer Real Integer D-l Actual Param- Mode of Form Definition Cube root of X eter Type Real Result CUBERTF(X) Real FLOATF(I) Integer to Real Conversion Integer Real RANF(N)* Generate Random Number -Real | — Integer ( Real (Repeated Executions give uniformly distributed numbers) + Real \ + Integer | Integer XFIXF Real to Integer Conversion Real Integer POWER(X 1 X 2 ) X^ 2 Real, Real Real ITOJ(IJ) F Integer, Integer Integer XTOI(X,I) X 1 Real, Integer Real ITOX(I,X) F Integer, Real Real LENGTHF(i) Number of words read on unit i Integer Integer *Any compiled calls to RANF(N), used as a func- tion, treat the resulting value as real. D-2 w_ i E. QUANTITIES AND WORD STRUCTURE FORTRAN-66 manipulates floating point and inte- ger quantities. Floating point quantities have an exponent and a fractional part. The following classes of numbers are floating point quantities. REAL Exponent and sign 11 bits; fraction and sign 49 bits; range of number, (in magnitude) 10- 308 ^N^ 10 308 and zero; precision approximately 14Vi deci- mal digits. DOUBLE Each half is independendy packed. COMPLEX Two reals as defined above. Integer quantities do not have a fractional part. The following classes of numbers are integer quan- tities: INTEGER Represented by 60 bits, first bit is the sign; range of number (in magnitude) O^N— 2 00 — 1; precision is up to nVz decimal digits. LOGICAL 1 bit represents the value TRUE. bit represents the value FALSE. HOLLERITH Binary coded decimal (BCD) representation treated as an integer number. A FORTRAN-66 program may contain any or all of these classes of numbers in the forms of constants, variables, elements of arrays, evaluated functions and so forth. Variables, arrays and functions are associated with types assigned by the programmer. The type of a constant is determined by its form. • WORD STRUCTURE The word structure of the quantities in FORTRAN- 66 is shown below: FLOATING POINT QUANTITIES SIGNS 2 10 48 SIGNS EXP FRACT. SIGNS 48 REAL 2 10 48 REAL COMPLEX SIGNS SIGNS IMAGINARY 2 10 48 2 10 48 DOUBLE MOST SIGNIFICANT INTEGER QUANTITIES LEAST SIGNIFICANT 59 -SIGN ^UNUSED %31| 6 6 6 6 6 6 6 6 6 6 INTEGER LOGICAL HOLLERITH TYPE REMARKS COMPLEX DOUBLE REAL INTEGER HOLLERITH LOGICAL 2 WORDS 2 WORDS 1 WORD 1 WORD 1 WORD 1 BIT CONSECUTIVE MEMORY LOCATIONS CONSECUTIVE MEMORY LOCATIONS 6 BITS/CHARACTER •ELEMENT LENGTH E-l <fe • • # F. PROGRAM SEGMENTATION • '® In general, the complex for a central processor pro- gram is assumed to be made up of control programs, subroutines, and common data blocks. The initiating control program, any common subroutines and data blocks comprise a permanent segment in core. Any subsequent control programs, subroutines and then- data blocks are arranged dynamically in core in seg- ments according to requests encountered during execution, and as defined by segmentation control cards. The compiling process handles all programs and subroutines individually. The routines are compiled separately and, in binary form, are put together with segmentation specifications at execute time. Linkage betwen segments and between routines is handled at load time. Although a routine may ap- pear in any number of segments, only one copy need be compiled and placed with the job. Definition of Terms Basic Segment — a fixed arrangement of a con- trol program, subroutines, and common data blocks. Normal Segment — an arrangement of a control program, subroutines, and common data read into central memory dynamically as required. It is defined by a segment control card and loaded by means of the LOAD statement. Nor- mal segments may be overlayed. Control Program — defined with a PROGRAM card and is the only executable program widiin a basic segment or a normal segment. Subroutine — a routine defined by a SUB- ROUTINE card and executed by means of a CALL statement. LOAD — is a macro defined as the overlay segment request. The contents of a segment are provided by seg- mentation control cards at load time and are speci- fied as a combination of control programs, sub- routines, and other segments. The overlay operation when executed does not disturb die contents of the basic segment. However, it does destroy all other requested segments operated prior to the loading of the overlay. Overlay requests may occur without restriction in any segment and are coded in line where the decision is reached that an overlay is required. Two independent segmentation concepts are pro- vided under a single programming mechanism. The first method allows a basic segment, which resides permanently, in core, to initiate loading, and to con- trol routing to the various subroutines in the job. Under this concept, control flows back and forth between the basic segment and any routine in the other segments, but always returns to the basic segment prior to the initiation of an overlay. When an overlay is initiated, control continues to the next instruction in line (no control transfer occurs). The second method provides a program chaining operation. Under this method each successive over- lay has its own control program and provides con- trol routing dirough the various routines in that overlay. Each new overlay destroys the preceding one. Since loading is initiated by the overlay, it is necessary that a control transfer be made in con- junction with the load request. An overlay request may occur in any segment. How- ever, a transfer address must be provided if the request is made from other than the basic segment. The transfer address, if required, is taken to be that of the control program which has a trace of asterisks all the way through to the LOAD statement. An example of a segmented program and the tracing of control through the segments with asterisks follows : EXAMPLE: (Control in Normal Segments) Assume the basic segment is loaded consisting of non-executable statements defining common data and storage areas and a load request: LOAD * SEG1 * SEG1 is defined as: SEG1 = ^PROGRAM A*, SUBROUTINE Al, SUBROUTINE A2 After die load is accomplished, control is shifted to Program A as a result of asterisks around SEG1 and Program A in die definition of SEG1. F-l Assume a load request is given in SEG1: LOAD * SEG2 * SEG2 = *PROGRAM B*, SUBROUTINE Bl, SUBROUTINE B2 The load is then performed and control turned over to Program B. Suppose an overlay request exists within SEG2 which includes both segments SEG1 and SEG2, plus Program C. In addition, suppose control is to be shifted back to Program A after SEG3. has been loaded. The specification of the third segment may take one of several forms: 1. SEG3 = *PROGRAM A*, SUB- ROUTINE Al, SUB- ROUTINEA2, PROGRAM B, SUBROUTINE Bl, SUBROUTINE B2, PROGRAM C 2. SEG3 = /*SEG1V, PROGRAM B, SUBROUTINE Bl, SUBROUTINE B2, PROGRAM C 3. SEG3 = /*SEG1V, /SEG2/, PROGRAM C where slashes indicate the enclosed is a segment name. Upon a LOAD *SEG3* statement, each of these three forms will produce the same core arrangement and transfer control to Program A since it is the only routine in this segment specification which has an asterisk trace through the segment definitions to the LOAD statement. Program A is asterisked (definition 1 above contains asterisks around Program A, defini- tions 2 and 3 above have asterisks around SEG1, which contains Program A enclosed with asterisks), SEG3 is asterisked in the LOAD statement. However, if control is desired for Program C, SEG3 may then be defined as : SEG3 = /SEG1/, /SEG2/, ♦PROGRAM C* or either of the other two forms may be used with Program C enclosed with the asterisks. A transfer address is not necessary when the basic segment maintains control throughout the execution of the object program. In this instance, segments consist of subroutines which are executed by means of a CALL statement. An example of a segmented program with control residing in the basic segment follows: EXAMPLE: (Control in Basic Segment) Assume the basic segment is loaded and execut- ing. At some point within the basic segment, a load request is coded: LOAD SEG4 SEG4 is defined as: SEG4 = SUBROUTINE A, SUBROUTINE Al, SUBROUTINE A2 After the load is accomplished, all program- ming conventions relative to subroutine calls and communications may be followed. How- ever, when the tasks of the routines in the normal segment are completed, control always reverts to the calling program in the basic seg- ment which may then request the loading of another segment. With reference to these examples, general charac- teristics of segment specifications are stated as follows : 1. Segments may be defined as a combination of routines and other segments. There is no limit on the depth used in the specification. Segment hierarchies may be conveniently defined as speci- fying large and highly overlapping segments. 2. There is no requirement that a one-to-one cor- respondence exist between segment definitions and segments referenced in LOAD statements. Extra segments may be defined which contain common groupings of routines and these seg- ments may then be used to define the larger segments. Each segment referenced by a LOAD statement must be defined by a segmentation card; if not, the entire job is aborted. 3. With the chaining method, control is passed to a program in the loaded segment by an unbroken chain of asterisks from the LOAD statement through the segment specifications to the pro- gram name. This provides the necessary control routine capability. F-2 4. There is no requirement that program or sub- routine names appear uniquely in the combina- tion of segments that define a segment. The union of the segments designates the routines to be loaded. This assures that there is no loss in core utilization due to name redundancies. 5. Segment identifiers used in the definition of other segments are surrounded by slash marks (/) to distinguish them from program and subroutine names. If a segment name is enclosed in asterisks, the asterisks are placed inside the slash marks. The following restrictions are made: 1. If the LOAD statement specifies a transfer of control, one and only one program in the loaded segment must be designated as recipient of the control by meeting characteristic number 3. 2. No mixing of the two methods is permissible although a one-time switch may be made from the basic segment concept to the chaining con- cept. Once the chaining process is used, there is no way to return control to the PROGRAM in the basic segment. A core map taken at the completion of the loading of the basic segment would show the control pro- grams, the programmer subroutines in the basic segment, one copy of common data blocks, and one copy of library subroutines and functions referenced by these basic segment routines. The block of memory required for this segment is permanently reserved. The next location after this block is the initial address for all normal segments called by a LOAD statement. If there are additional segments specified to ac- company the basic segment in the initial load or when an overlay request occurs, these segments are brought in from the disk and relocated at the initial overlay address. Addresses for common blocks refer- enced in the segments are determined from their location within the basic segment, or they are as- signed and inserted where appropriate. Also one copy of any library subroutine, not previously required or loaded, is added to the program and linkages for all routines are then made. When a transfer is indicated by the segment speci- fication (asterisks around NAME), a similar name form is sought from the segment name list and control is routed to its single entry point. F-3 # # • # • G. FORTRAN ERROR PRINTOUTS Listed below are the diagnostic error printouts currently available with FORTRAN-66. A one (1) before the statement indicates that no further compilation takes place. However, the subsequent FORTRAN statements are diagnosed for errors. A zero (0) before the statement indicates that the program will be compiled, but execution is likely to be subject to error. I""" 8 " UNRECOGNIZABLE STATEMENT l'FUNCTION STATEMENT FORMAT ERROR l a SUBROUTINE STATEMENT FORMAT ERROR 1"" "SUBROUTINE OR VARIABLE NAME TOO LONG l"MORE THAN 20 ENTRIES l"°ERROR IN CALL STATEMENT** 00 1° "ILLEGAL CHARACTER l°°MORE THAN 63 PARAMETERS IN LIST 0000 1° DUPLICATION IN PARAMETER LIST 000 0°"NO HEADER CARD FOUND ASSUME FORTRAN MODE 00 l°°MORE THAN ONE HEADER CARD 00 1° DECLARATIVE STATEMENT OUT OF ORDER 000 0* 'NON-EXECUTABLE PROGRAM 00000 l"MORE THAN 9 CONTINUATIONS 1 RETURN STATEMENT USED IN PROGRAM MODE l 000000 'UNCLOSED DO LOOP DO [N] I = ETC. 000000 1°°DUPLICATE ENTRY NAME 00 1° DIMENSION NOT FOUND, VARIABLE 00000000 l°DIMENSION EXCEEDED, VARIABLE 00000000 1°SUBSCRIPT NOT FOUND, VARIABLE 00000000 1 000000 ARITHMETIC STATEMENT FORMAT ERROR l°NO EQUAL SIGN FOUND IN ARITHMETIC STATEMENT 1"LEFT SIDE ERROR 1 "ELEMENT NOT AN ARRAY l°FUNCTION NOT ON LEFT 1""" "ILLEGAL ALPHA-CHARACTER APPEARING IN NUMBER FIELD 1 "ILLEGAL PERIOD (.) OCCURRING 1 000 "*°"UNBALANCED PARENTHESIS 1"°»«ILLEGAL CHARACTER IN OCTAL NUMBER FIELD 1" ""ERROR IN GO TO STATEMENT"" 1 "ASSIGN STATEMENT FORMAT ERROR 1""IF STATEMENT FORMAT ERROR l"ERROR IN SENSE LIGHT STATEMENT" l 0000 ERROR IN DO STATEMENT 1"" "INDEX USED BY ANOTHER DO l'DO STATEMENT ENDED BY •«•»«•«», ILLEGALLY NESTED "" l"*DO STATEMENT NEXT CONTAINS MORE THAN 50 oooo ° 0°DO STATEMENT ENDED BY A TRANSFER STATEMENT 1" "ERROR IN I/O STATEMENT"" "" 1ARRAY XXXX IS NOT A SUBROUTINE FORMAL PARAMETER 1SUBSCRIPT XXXX IS NOT A SUBROUTINE FORMAL PARAMETER 1COMMON/EQUIVALENCE CONFLICT, VARIABLES . . . XXXX AND . . . YYYY 1LITERAL TABLE OVERFLOW lOCTAL TO DISPLAY CONVERSION ERROR G-l 1EQUIVALENCE STATEMENT REFERENCE CONFLICT, VARIABLE XXXX REFERENCES c VARIABLE YYYY IN MORE THAN ONE WAY. FIRST REFERENCE PREVAILS ™ 1EQUIVALENCE STATEMENT REFERENCE CONFLICT, VARIABLE XXXX REFERENCES ITSELF 1FORMAL PARAMETER XXXX APPEARS IN A COMMON STATEMENT OOBSERVE EQUIVALENCE STATEMENT SUBSCRIPT RULES 1FORMAT ERROR OCOMMA AT END OF STATEMENT 1TYPE STATEMENT CONFLICT, VARIABLE XXXX ODUPLICATE TYPE STAEMENT, VARIABLE XXXX UNCOMPLETE STATEMENT 1TOO MANY SUBSCRIPTS, VARIABLE XXXX 1COMMON STATEMENT CONFLICT, VARIABLE XXXX 1PRIOR SUBSCRIPTS WILL BE USED 1DIMENSION STATEMENT CONFLICT, VARIABLE XXXX 1COMMON STATEMENT/DIMENSION STATEMENT CONFLICT, VARIABLE XXXX ODIMENSION STATEMENT SUBSCRIPTS WILL BE USED ODUPLICATE SUBSCRIPT SET ASSIGNED TO VARIABLE XXXX 1SUBSCRIPT, VARIABLE XXXX IS TOO BIG 1SUBSCRIPT CONFLICT OR DUPLICATE, VARIABLE XXXX 1FORMAL PARAMETER XXXX APPEARS IN AN EQUIVALENCE STATEMENT OA MINIMUM OF TWO VARIABLES MUST OCCUR IN EACH EQUIVALENCE GROUP 1FUNCTION CALLING SEQUENCE ERROR. FUNCTION XXXXX 1LEFT SIDE NOT TYPE LOGICAL, WITH RIGHT SIDE RELATIONALS. 1FAILURE OF E Q B6 B7 K , TO JUMP ON EQUALITY. 1STATEMENT FUNCTION TABLE FULL. 1NUMBER OF PARAMETERS DOES NOT AGREE WITH STATEMENT FUNCTION DEFINITION A IUNIARY SIGN FORMAT ERROR. W 1RIGHT SIDE RESULTS MASSING. $$$$$$$$$$$$$$$$$$$$$$$ 1MULTIPLE RIGHT SIDE RESULTS. $$$$$$$$$$$$$$$$$$$$$$ 1UNKNOWN ELEMENT AS AN OPERAND = $$$$$$$$$$$$$$ XXXXX 1ARITHMETIC OPERANDS ARE NOT SAME TYPE. !$$$$$$$ 10PERANDS HAVE ILLEGAL TYPE 6. $$$$$$$$$$$$$$$$$$$$$ IOPERANDS HAVE ILLEGAL TYPE 7. $$$$$$$$$$$$$$$$$$$$$ HLLEGAL TYPE 6, FOR CONVERSION. $$$$$$$$$$$$$$$$$$$ HLLEGAL TYPE 7, FOR CONVERSION. $$$$$$$$$$$$$$$$$$$$ HLLEGAL TYPE 6, FOR CONVERSION. TO OCTAL. $$$$$$$$$ HLLEGAL TYPE 7, FOR CONVERSION. TO OCTAL. $$$$$$$$$ HLLEGAL TYPE 6, FOR CONVERSION. TO LOGICAL. $$$$$$ HLLEGAL TYPE 7, FOR CONVERSION. TO LOGICAL. $$$$$$ HLLEGAL TYPE 6, FOR CONVERSION. TO INTEGER. $$$$$$ HLLEGAL TYPE 7, FOR CONVERSION. TO INTEGER. $$$$$$ HLLEGAL TYPE 6, FOR CONVERSION. TO REAL. $$$$$$$$$$$ HLLEGAL TYPE 7, FOR CONVERSION. TO REAL. $$$$$$$$$$$ HLLEGAL TYPE 6, FOR CONVERSION. TO DOUBLE. $$$$$$$ HLLEGAL TYPE 7, FOR CONVERSION. TO DOUBLE. $$$$$$$ HLLEGAL TYPE 6, FOR CONVERSION. TO COMPLEX. $$$$$ HLLEGAL TYPE 7, FOR CONVERSION. TO COMPLEX. $$$$$ 1DUPLICATE STATEMENT FUNCTION = XXXXX OZERO SUBSCRIPT CHANGED TO ONE FOR VARIABLE XXXXX G-2 ^P*' o o u CONTROL DATA SALES OFFICES ALAMOGORDO • ALBUQUERQUE • ATLANTA • BILLINGS • BOSTON • CAPE CANAVERAL • CHICAGO • CINCINNATI • CLEVELAND • COLORADO SPRINGS DALLAS • DAYTON . DENVER • DETROIT • DOWNEY, CALIFORNIA • HONOLULU HOUSTON • HUNTSVILLE • ITHACA . KANSAS CITY, KANSAS . LOS ANGELES MADISON, WISCONSIN • MINNEAPOLIS • NEWARK • NEW ORLEANS • NEW YORK CITY • OAKLAND • OMAHA • PALO ALTO • PHILADELPHIA • PHOENIX PITTSBURGH • SACRAMENTO • SALT LAKE CITY • SAN BERNARDINO • SAN DIEGO • SEATTLE . ST. LOUIS . WASHINGTON, D.C. ATHENS • CANBERRA ■ DUSSELDORF . FRANKFURT . THE HAGUE • HAMBURG JOHANNESBURG • LONDON • MELBOURNE ■ MEXICO CITY (REGAL ELEC- TRONICADE MEXICO, S.A.)- MILAN • MONTREAL • MUNICH • OSLO . OTTAWA PARIS • SAVYON • STOCKHOLM • STUTTGART • SYDNEY • TOKYO (C.ITOH ELECTRONIC COMPUTING SERVICE CO., LTD.) • TORONTO • ZURICH 8100 34th AVE. SO., MINNEAPOLIS, MINN. 55440 CONTROL Dr , CORPORATION © 1965, Control Data Corporation Pub. No. 60101500 B Litho in U.S.A.