Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
30 views
54 pages
Fortran For The Ibm 704
Fortran for the Ibm 704
Uploaded by
Edison Auccapiña Perez
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save Fortran for the Ibm 704 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
0 ratings
0% found this document useful (0 votes)
30 views
54 pages
Fortran For The Ibm 704
Fortran for the Ibm 704
Uploaded by
Edison Auccapiña Perez
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save Fortran for the Ibm 704 For Later
Share
0%
0% found this document useful, undefined
0%
, undefined
Print
Embed
Report
Download
Save Fortran for the Ibm 704 For Later
You are on page 1
/ 54
Search
Fullscreen
TAMOVENSUS GUM Goh heey 20) om ay ste Dah GhO} AUST Oe eyProgrammer's Reference Manual October 15, 1956 THE FORTRAN AUTOMATIC CODING SYSTEM FOR THE IBM 704 EDPM, ®@ ‘This manual supersedes all earlier information about the FORTRAN system. It describes the system which will be made available during late 1956, and is intended to permit planning and ForTRAN coding in advance of that time. An Introductory Programmer's Manual and an Operator’s Manual will also be issued. APPLIED SCIENCE DIVISION PROGRAMMING RESEARCH DEPT. International Business Machines Corporation 590 Madison Ave., New York 22, N. ¥. R.A. NELSON nue atrerafe Con “Bot Hatord, Com: Univer of Californie ». SHER Iailton Laboratory 1, STERN ‘Tvermore, Ci 1 zuLLERSize of Machine Required Etticiency of the Object Program THE FORTRAN SYSTEM The IBM Mathematical Formula Translating System FORTRAN is an automatic ‘coding system for the IBM 704 EDPM. More precisely, it is a 704 program which accepts a source program written in a language ~ the FORTRAN language — closely resembling the ordinary language of mathematics, and which pro duces an object program in 704 machine language, ready to be run on a 704. Fortran therefore in eflect transforms the 704 into a machine with which ‘communication can be made in a language more concise and more familiar than the 704 language itself. The result should be a considerable reduction in the training required to program, as well as in the time consumed in writing pro- grams and eliminating their errors. Among the jeatures which characterize the FORTRAN system are the following. The system has been designed to operate on a “small” 704, but to write object programs for any 704. (For further details, see the section on Source and Object Machines in Chapter 7.) If an object program is produced which is too large for the machine on which it is 10 be run, the programmer must subdivide the rogram: Object programs produced by FORTRAN will be nearly as efficient as those written by good programmers. The FORTRAN language is intended 10 be capable of expressing any problem of numerical computation. In particular, it deals easily with problems containing 2Inclusion of Library Routines Provision for Input and Output Natu Fortran Arithmetic of large sets of formulae and many variables, and it permits any variable to have up to three independent subscripts. However, for problems in which machine words have a logical rather than @ numerical meaning it is less satisfactory, and it may fail entirely to express some such problems. Nevertheless, many logical operations not directly express- ible in the Fortean language can be obtained by making use of the provisions for incorporating library routines. Pre-written routines to evaluate any singie-valued functions of any number of arguments can be made available for incorporation into object programs by placing them on the master FORTRAN tape. Certain statements in the FORTRAN language cause the object program to be equipped with its necessary input and output programs. Those which deal with decimal information include conversion to or from binary, and permit con siderable freedom of format in the external medium. Arithmetic in the object program will generally be performed with single- precision 704 floating point numbers. These numbers provide 27 binary digits (about 8 decimal digits) of precision, and may have magnitudes between approxt- ‘mately 10% and 10%, and zero. Fixed point arithmetic, but for integers only, is also provided.CHAPTER 1. TABLE OF CONTENTS ‘THE FORTRAN LANQUAGE: Constants, Variables, and Subscripts ‘Functions, Expressions, and Arithmetic Formulas {THE FORTRAN LANGUAGE: Control Statements ‘Input-Output Statements MISCELLANEOUS DETAILS ABOUT FORTRAN EXAMPLES OF FORTRAN PROGRAMMING ‘TABLE OF FORTRAN STATEMENTS. pase PnCHAPTER 1. GENERAL PROPERTIES Example of a Fortran Program OF A FORTRAN SOURCE PROGRAM ‘A Forrraw source program consists of a sequence of FORTRAN statements. There are 32 different types of statement, which are described in detail in the chapters which follow. The following brief program will serve to illustrate the general appearance and some of the properties of a FORTRAN program. It is shown as coded on @ standard ForTRAN coding sheet. picks AG) 0.20 — (B1GA = ACID) 1 (CONTINUE ‘This program examines the set of n numbers ai (i=l,...., n) and sets the quantity BIGA to the largest value attained in the set, It begins (after a com- ment describing the program) by setting BIGA equal to a). Next the DO statement causes the succeeding statements to and including statement 20 to be carried out repeatedly, first with i=2, then with i=3, etc., and finally with ‘n, During each repetition of this loop the IF statement compares BIGA with ‘ajjif BIGA is less than a, statement 10, which replaces BIGA by a, is executed before continuing. Each statement is punched on a separate card. If a statement is too Tong to fit ona single card it can be continued over as many as 9 additional continuation cards. For each statement the initial card must contain either a zero or a blank in column 6; on continuation cards column 6 must not contain a zero or a blank, and it should be used to number the continuation cards consecutively from 1 t0 9, If a statement is too long to fit on a single line of the coding form, the programmer can signal to the keypuncher that he has continued on to the next by placing a mark in the column labeled CONTINUATION.Proview Fortran Statements ‘The order of the statements is governed solely by the order of the cards. However, any number less than 2! (=32768) may be associated with any statement by punching it in columns 1-5 of the initial card bearing that state- ‘ment. Thereupon this number becomes the statement number of that statement. Statement numbers, besides permitting cross-references within the source pro- gram, also help the programmer to correlate the object program with his source program, Punching the character C in column 1 will cause the card to be ignored by FORTRAN. Such cards may therefore be used to carry comments which will appear when the deck is listed Columns 73-80 are not read by FoRTRAN and may be punched with any desired identifying information. ‘The statements themselves are punched in columns 7-72, both on initial ‘and continuation cards. Thus a statement consists of not more than 10x 66=660 characters. A table of the admissible characters in FORTRAN is given in Appendix A. Blank characters, except in column 6, are simply ignored by FORTRAN, and the programmer may use blanks freely to improve the readability of his Fortean listing ‘The actual input to FortRaN is either this deck of cards or a BCD tape written from it on the 704 peripheral card-to-tape equipment with the standard SHARE 80 x 84 board. On the tape an End of File mark after the last card is required, ‘The 32 types of statement, of which every FORTRAN program is composed, may be classified as follows. 4, The arithmetic formula, which causes the object program to carry out a ‘numerical computation. Chapter 2 discusses the symbols available for refer~ ring to constants and variables, and Chapter 3 the combining of these into arithmetic formulas, 2. The 15 control statements, which govern the flow of control in the object Program. These are discussed in Chapter 4, ‘3. The 13 input-output statements, which provide the object program with its Necessary input and output routines. These are discussed in Chapter 5. ‘4, Finally, the 3 specification statements, which provide various information required or desirable to make the object program efficient, are discussed in Chapter 6. Chapters 7 and 8, which conclude the manual, give additional detail on various topics and examples of FORTRAN programming.CHAPTER 2. THE FORTRAN LANGUAGE: Constants, Variabl nd Subscripts ‘Any programming language must provide for expressing numerical constants and variable quantities. FoRtRAN also provides a subscript notation for expressing 1, 2, oF 3-dimensional arrays of variables. ‘Two types of constant are permissible: fixed point (restricted to integers) and floating point (characterized by being written with a decimal point). Fixed Point Constants. 1 to 5 decimal gts. preceding + or ~ a signs optional. The magitude of the constant must 4 be loss than 32768. 28987 ‘Any unsigned fixed point constant may be used as a statement number. Floating Point Constants. ‘ary umber of decimal digits, with v. 2 decimal pont at the beginning, atthe end, 50 ‘or between two dis 0003 A preceding + or — sign is optional. 506 (= 50x10 A decinal exponent praceded by an E 50643(= 50x10 may follow. 5067 (= 50x10-7 ‘The magnitude of the number thus expressed must be zero, or must lie between the approximate limits of 10-2 to 10%, The number will appear in the object program as a normalised single-precision floating point number.Vari ‘Subscripts and Subscripted Vari Two types of variable are also permissible: fixed point (restricted to integral values) and floating point. Fixed point variables are distinguished by the fact that their first character is I, J, K, L, M, or N. Fixed Point Variables. 1 106 alphabetic or numeri eharactes 1 (not special characters) of which the frst is we LA KLM, orn, 308N0 A fixed point variable can assume any integral value whose magnitude is less than 32768, However, see the section on Fixed Point Arithmetic in Chapter 7. WARNING. The name of a variable must not be the same as the name of any function used in the program after the terminal F of the function name has been removed. Also, if a subscripted variable has 4 or more characters in its name, the last of these must not be an F. (For the meaning of “function” and “sub- scripted” see Chapter 3 and the last section of this chapter.) Floating Point Variables. 1 to 6 alphabetic or mmaric characters A loot special characters) of which the fist is alphabetic 87 but ot, KL M, oF 8 A floating point variable can assume any value expressible as a normalised 704 floating point number; i. zero, or with magnitude between approximately 10-3 and 10°, WARNING. The restrictions on naming fixed point variables also apply to floating point variables A variable can be made to represent any member of a 1, 2, or 3-dimensional array of quantities by appending to it 1, 2, or 3 subscripts; the variable is then a subseripted variable, The subscripts are fixed point quantities whose values determine which member of the array is being referred to. 0Subscripts. a Let v represent any fed point variable 1 ‘and ¢ or any unsigned fixed point 3 anstant, Then 2 subscript fs M42 an expression of one of the forms: ¥ Mu-2 ° 5a weary S142 ew sel-2 couterarcwt! Po The symbol + denotes multiplication. The variable v must not itself be sub- scripted, Subscripted Variables. a A ised Moatng point variable a folloned by parentheses enclosing 1, 2, 0° 3 Ka) subscripts separated by commas, BETAS "1-2, K42,0 L__ For each variable that appears in subscripted form the size of the array (i.e. the maximum values which its subscripts can attain) must be stated in a DIMEN- SION statement (see Chapter 6) preceding the first appearance of the variable, ‘The minimum value which a subscript may assume in the object program is + 1 Arrangement of Arrays in Storage. ‘A 2.dimensional array A will, in the object program, be stored sequentially in the order As, Ants «++e+r Amis Atas Anas oe seyAmay oss e+++e9 Aman Thus it is stored “columnwise”, with the first of its subscripts varying most rapidly, and the last varying least rapidly. The same is true of 3-dimensional arrays. I-dimensional arrays are of course simply stored sequentially. All arrays are stored backwards in storage; i.e. the above sequence is in the order of decreas ing absolute location.CHAPTER 3. THE FORTRAN LANGUAGE: Functions Functions, Expressions, and Arithmetic Formulas Of the various FORTRAN statements it is the arithmetic formula which defines ‘a numerical calculation which the object program is to do. A Fortran arith- metic formula resembles very closely a conventional arithmetic formula; it consists of the variable to be computed, followed by an = sign, followed by an arithmetic expression. For example, the arithmetic formula Y= A-SINF(B—C) means “replace the value of y by the value of a-sin(b-c) As in the above example, a FORTRAN expression may include the name of a Junction (e.g. the sine function SINF), provided that the routine for evaluating the function is either built into FoRTRAN or is accessible to it as a pre-written subroutine in 704 language on the master FORTRAN tape, ‘The name ofthe function is 4 to 7 alphabetic or numeric SINFA4-B) characters (not special characters), of which the last must ‘SOMEFO,Y) be F andthe first must be alphabetic ls, the fst must SORTFSINFIA) be X if and ony ifthe value of the funtion i 0 be XTANE3.90) fired point. The name of the function is followed by parentheses enclosing the arguments which may be ression), separated by commas. Mode of a Function and its Arguments. Consider a function of a single argu- ment. It may be desired to state the argument either in fixed or floating point; similarly the function itself may be in either of these modes. Thus a function of a single argument has 4 possible mode configurations; in general.a function of n arguments will have 2*+1 mode configurations, 2A separate name must be given, and a separate routine must be available, for each of the mode configurations which is used. Thus a complete set of ‘names for the sine function might be SINOF Fixed argument, floating function SINIF Floating“, XSINOF = Fired «= fixed * XSINIF Floating", where the X's and F's are compulsory, but the remainder of the naming is arbitrary. Built-In Functions, The FortRan system has the routines for evaluating cer- tain functions built in, The list is as follows. Absolute value inal 1 Frosting | Floating Fixed Fined Truncation Signof Avgtimes | 1 Floating | Floating largest integer Floating | Fined ime} Remaindering ‘gy (nod We) a Floating | Floating (see note below) Fine Fited Choosing Max Wray Arg, .-)| 32 Fes Floating largest value Froating | Floating Fixed Fined Floating | Fines Choosing Min rg, Arg 1] 22 Fixed Floating smallest value Floating | Floating Fines Fined Floating | Fixed Nore. The function MODF (Arg,, Args) is defined as Arg: —{Angs/Argal ‘Arge, where [x] = integral part of x. ‘These 14 built-in subroutines are always compiled into the object program as open subroutines. Functions on the Library Tape. Besides the built-in routines, any single- valued function of any number of arguments can be made available to the programmer by placing the appropriate routine on the master FORTRAN tape. 3Expressions Any such routine will be compiled into the object program as a closed subrou- tine, In the section on Writing Subroutines for the Master Tape in Chapter 7 are given the specifications which any such routine must meet, ‘An expression is any sequence of constants, variables (subscripted or not sub- scripted), and functions, separated by operation symbols, commas, and paren- theses s0 as {0 form a meaningful mathematical expression However, one special restriction does exist. A FORTRAN expression may be either a fixed or a floating point expression, but it must not be a mixed expression. This does not mean that « floating point quantity can not appear in a fixed point expression, or vice versa, but rather that a quantity of one ‘mode can appear in an expression of the other mode only in certain ways. Briefly, a floating point quantity can appear in a fixed point expression only as an argument of a function; a fixed point quantity can appear in a floating point expression only as an argument of a function, or as a subscript, or as an exponent. Formal Rules for Forming Expressions. By repeated use of the following rules, all permissible expressions may be derived 41. Any fixed point (floating point) constant, variable, or subseripted variable is an expression of the same mode. Thus 3 and I are fixed point expressions, and ALPHA and A(1J.K) are floating point expressions. If SOMEF is some function of a variables, and if E, F, .... , Hare a set of m expressions of the correct modes for SOMEF, then SOMEF (E, F, +H) isan expression of the same mode as SOMEF. 3. ICE isan expression, and if its frst characteris not + or ~, then +E and =E are expressions of the same mode as E. Thus ~A is an expression, but +A is not. 4. If E is an expression, then (E) is an expression of the same mode as E. ‘Thus (A), ((A)), (CCA), ete, are expressions. 55. If E and F are expressions of the same mode, and ifthe fist character of F is not + or ~, then E+F E-F EF Ey F are expressions of the same mode, Thus A~+B and A/-+B are not expres: sions. The characters +, -, +, and / denote addition, subtraction, multi plication, and division. 46. If E and F are expressions, and F is not floating point unless E is too, and the first character of F is not + of ~, and neither E nor F is of the form ‘AeeB, then cer is an expression of the same mode as E. Thus A**(B++C) is an expression, but I+#(B+*C) and AveB+#C are net. The symbol +# denotes exponentia- tion; i, A**B means AB. Hierarchy of Operations. When the hierarchy of operations in an expression is not completely specified by parentheses, then it is understood to be in the following order (from innermost operations to outermost) Exponentiation Multiplication and Division Addition and Subtraction For example, the expression A+B/C+DMESFG will be taken to mean A+ (8/0) +(08°F)-6. Ordering within a Hierarchy. Parentheses which have been omitted from a sequence of consecutive multiplications and divisions (or consecutive additions and subtractions) will be understood to be grouped from the left. Thus, if. rep- resents either * or / (or either + or —), then ABODE will be taken to mean ((((AB).CVD)E Verification of Correct Use of Parentheses. The following procedure is sug- gested for checking that the parentheses in a complicated expression correctly express the desired operations. Label the first open parenthesis “I”; thereafter, working from left to right, increase the label by 1 for each open parenthesis and decrease it by 1 for each closed parenthesis. The label of the last parenthesis should be 0; the mate of an open parenthesis labeled n willbe the next parenthesis labeled n-1 15Arithmetic Formutas Optimisation of Arithmetic Expressions. The efficiency of the object program into which an arithmetic expression is translated may depend upon how the arithmetic expression is written. The section on Optimisation of Arithmetic Expressions in Chapter 7 mentions some of the consider: object program efficiency. nore ais a variable Gubsrited or a, not subscripted) and bis an expression, 800-+SINFICW)) ‘The = sign in an arithmetic formula has the meaning “is to be replaced by” ‘An arithmetic formula is therefore a command to compute the value of the right-hand side and to store that value in the storage location designated by the left-hand side. ‘The result will be stored in fixed or floating point according as the vs on the left-hand side is a fixed or floating point variable. If the variable on the left is fixed point and the expression on the right is floating point, the result will first be computed in floating point and then trun- cated and converted to a fixed point integer. Thus, if the result is 3.569 the fixed point number stored will be 3, not +4. able Examples of Arithmetic Formulas. Store the value of B in A Truncate B oan integer, convert to fixed point, and store in, Convert | to floating pont and stare in A. ‘Add 1 to and store in| This example iustrates ‘the point that an arithmetic formulas not ‘an ematon but a command to replace a valve. FISINFB), COSFIB) Replace Aby the larger ofthe quantities sinB an cos8. This example illustrates the use of fineton as an argument ofa funtion Aad 08 Replace Aby 38. Anse Not permitted, The expression is mite. Ante "Nt prmitted. The expression i mixed,CHAPTER 4. THE FORTRAN LANGUAGE: Unconditional @0 To Assigned Go To Control Statements ‘The second class of FORTRAN statements is the set of 15 control statements, which enable the programmer to state the flow of his program. "G0 TO a where n isa statement number co 103 ‘This statement causes transfer of control to the statement with statement number n, GOTO my oom" wheres 2 GO TON, 0,12, 19) ron subscript fixe pont variable appearing ina rovously executed ASSIGN statement, and hy My --osos hy ate statement aumbes, This statement causes transfer of contro! to the statement with statement num- ber equal to the value of n last assigned by an ASSIGN statement. The my, Me, sss 9 Mmare a list of the values which n may be assigned. ‘The assigned GO TO is used to obtain 2 pre-set many-way fork. Nore: When an assigned GO TO exists in the range of a DO, there is a restric tion on the ny, Ma, ..++Mm (See the section on DOs in this chapter.) “ASSIGN 1 TO n” where iis @ statement number and ASSIGN 12 TON ‘isa nonsubscriptd fied point variable. This statement causes a subsequent GOTO n, (11, «4 i, --» Mm) to transfer control to the statement whose statement number ‘The statement ASSIGN 12 TO N and the arithmetic formula N not the same. A variable which has been assigned can be used only for an assigned GO TO until it is re-established as an ordinary variable. 2 are 7Computed Go To cd SENSE LIGHT IF (SENSE LIGHT) ©. (SENSE swiTcH) {BO TO iB --+..y Mm” where 60 TO Go, 40, $0, 60,1 My coos hy af statement numbers and {isa nan-subscrptd fied point variable If at the time of execution the value of the variable i is j, then control is trans- ferred to the statement with statement number nj, Thus, in the example, if I hhas the value 3 at the time of execution, a transfer to statement 50 will occur. This statement is used to obtain a computed many-way fork. “HF La my, am" where a is any expression IF GUN —B) 10, 20, 30, and nym ae statement numbers, Control is transferred to the statement with statement number m, my, oF ns according as the value of a is less than, equal to, or greater than zero, "SENSE LIGHT i" where is, 1, 2,3, oF. SENSE LIGHT 3| It i is 0, all Sense Lights on the 704 console will be turned OFF; otherwise ‘Sense Light i will be turned ON. “AF (SENSE LIGHT 9) my, ma" where IF SENSE LIGHT 3) 30, 40 1 and ny are statement numbers and |i 2, 2 3, oF 4 Control is transferred to the statement with statement number n; or ny accord- ing as Sense Light i is ON or OFF, and the Sense Light is turned OFF IF GENSE SWITCH Dm, ay" where my and ny ate 1F (SENSE SWITCH 3) 30, 40 statement numbers and iis 1, 2, 3, 4 5 0 &If ACCUMULATOR OVERFLOW WF quoTiENT OVERFLOW IF DIVIDE CHECK PAUSE Control is transferred to the statement with statement number m, or ns accord ing as Sense Switch i on the 704 console is DOWN or UP. “IF ACCUMULATOR OVERFLOW m,n" IF ACCUMULATOR OVERFLOW 30,40 here ny and ny are statement numbers Control is transferred to the statement with statement number n, orn: accord ing as the Accumulator Overflow trigger of the 704 is ON or OFF, and the trigger is turned OFF. “IF QUOTIENT OVERFLOW m,n” IF QUOTIENT OVERFLOW 30, 40 whore ny and nae statement numbers Control is transferred to the statement with statement number n; or ns accord- ing as the Multiplier-Quotient Overflow trigger of the 704 is ON or OFF, and the trigger is turned OFF. “IF DIVIDE CHECK myn” where 1F DIVIoE CHECK 30, 40 sand ny restatement numbers. Control is transferred to the statement with statement number ny or n; accord ing as the Divide Check trigger of the 704 is ON or OFF, and the trigger is turned OFF. PAUSE” o “PAUSE n” where mf an PAUSE unsigned esta fixed point constant PRUSE 777 ‘The machine will HALT, with the octal number n displayed on the 704 con- sole in the address field of the storage register. (If n is not stated it is taken to be 0.) Pressing the START button causes the program to resume at the next FORTRAN statement.STOP “STOP” or "STOP" where nis an sroP unsigned octal fixed point constant, stop 77777 ‘This statement causes the machine to HALT in such a way that pressing the START button has no effect. Therefore, in contrast to the PAUSE, it is used where a get-off-the-machine stop, rather than a temporary stop, is desired. The octal number n is displayed on the 704 console in the address field of the storage register. (If n is not stated it is taken to be 0.) "DO i = my my" oF “DO = ym, my 0301 = 1,10 here nis a statement number, is 8 0301 = 1,3 rnon-subscripted fixed pont variable, and my, mam reach elther an unsigned Fixed pint constant or a nonsubscripted fted pont variable Him isnot stated it is taken tobe 1. The DO statement is a command to “DO the statements which follow, to and including the statement with statement namber n, repeatedly, the frst time with i =m, and with i increased by ms for each succeeding time; after they have been done with i equal to the highest of chis sequence of values which does not exceed my let control reach the statement following the statement with state- ment number n”, ‘The range of a DO is the set of statements which will be executed re- peatedly; it is the sequence of consecutive statements immediately following the DO, to and including the statement numbered n. ‘The index of a DO is the fixed point variable i, which is controlled by the DO in such a way that its value begins at m, and is increased each time by ‘ms until it is about to exceed ms. Throughout the range it is available for com- putation, either as an ordinary fixed point variable or as the variable of a subscript. During the last execution of the range, the DO is said to be satisfied. Suppose, for example, that control has reached statement 10 of the ee 10) DO MI=1, 10 A) =hN) 12 0‘The range of the DO is statement 11, and the index is I. The DO sets I to 1 and control passes into the range. N(1) is computed, converted to floating point, and stored in A(1). Now, since statement 11 is the last statement in the range of the DO and the DO is unsatisfied, I is increased to 2 and control returns to the beginning of the range, statement 11. 2N(2) is computed and stored in A(2). This continues until statement 11 has been executed with I = 10. ‘Since the DO is satisfied, control now passes to statement 12. DOs within DOs. Among the statements in the range of a DO may be other DO statements. When this is so, the following rule must be observed. Rule 4. If the range of a DO includes another DO, then all of the statements in the range of the latter must also be in the range of the former. A set of DOs satisfying this rule is called a nest of DOs. Transfer of Control and DOs. Transfers of control by IF-type or GO TO- type statements are subject to the following rule. Rule 2. No transfer is permitted into the range of any DO from outside its range. ‘Thus, in the configuration below, 1, 2, and 3 are permitted transfers, but 4, 5, and 6 are not. EXCEPTION. There is one situation in which control can be transferred into the range of a DO from outside its range. Suppose control is somewhere in the range of one or more DOs, and that it is transferred to a section of program, completely outside the nest to which those DOs belong, which makes no change in any of the indexes or indexing parameters (m’s) in the nest. Then after the execution of this section of program control can be transferred back to the same part of the nest from which it originally came. This provision makes it possible to exit temporarily from the range of a DO to execute a subroutine, An example is given in Chapter 8. atCONTINUE Restriction on Assigned GO TOs in the Range of a DO. When an assigned GO TO exists in the range of a DO, the statements to which it may transfer ‘must all lie in one single part of the nest, or must all be completely outside the nest. If this condition cannot be met, a computed GO TO may be used. Preservation of Index Values. When control leaves the range of a DO in the ordinary way (i.e. by the DO becoming satisfied and control passing on to the next statement after the range) the exit is said to be a normal exit. After a normal exit from a DO occurs, the value of the index controlled by that DO is not defined, and the index can not be used again until itis redefined. (See, however, the section on Further Details about DO Statements in Chapter 7.) However, if exit occurs by a transfer out of the range, the current value of the index remains available for any subsequent use. If exit occurs by a trans- fer which is in the ranges of several DOs, the current values of all the indexes controlled by those DOs are preserved for any subsequent use. Restriction on Calculations in the Range of a DO. Almost every’ type of calculation is permitted in the range of 1 DO. Only one type of statement is not permitted, namely any statement which redefines the value of the index or of any of the indexing parameters (m's). In other words, the indexing of a DO loop must be completely set before the range is entered. “conTinuE” CONTINUE CONTINUE is a dummy statement which gives rise to no instructions in the object program. Its most frequent use is as the last statement in the range of a DO, where it provides a statement number which can be referred to in transfers which are desired to become, in the object program, transfers to the indexing instuctions at the end of the loop. ‘As an example of a program which requires a CONTINUE, consider the table search program 10 00121 =i, 100 11 IF(ARG—VALUE()) 12, 20, 12 12 CONTINUE 13‘Summary of Fortran ‘Sequencing ‘This program will examine the 100-entry VALUE table until it finds an entry which equals ARG, whereupon it will exit to statement 20 with the successful value of I available for fixed point use; if no entry in the table equals ARG a normal exit to statement 13 will occur. The program 10 O11 =1, 100 11 IF(ARG-VALUE()) 11, 20, 1. 12 would not work since, as stated in the next section, DO-sequencing does not occur if the last statement in the range of a DO is a transfer. ‘The precise laws which govern the order in which the statements of a FORTRAN program will be executed, and which have been left unstated till now, may be stated as follows. 4. Control begins at the first executable statement. 2. If control isin a statement S, then control will next go to the statement dic- tated by the normal sequencing properties of S. (The normal sequencing for each type of FORTRAN statement is given in Appendix B.) 3. EXCEPTION. If, however, S is the last statement in the range of one or more DOs which are not yet satisfied, and if $ is not a transfer (IF-type oF GO To-type statement), then the normal sequencing of S is ignored and DO-sequencing occurs; ie, control will next go to the first statement of the range of the nearest of the unsatisfied DOs, and the index of that DO will be raised, Nore. The statements FORMAT, DIMENSION, EQUIVALENCE, and FRE- QUENCY, which are discussed in the next two chapters, are non-executable statements, and in any question of sequencing are simply to be ignored. WARNING. Every executable statement in the source program (except the first) must have some path of control leading to it; otherwise errors will occur in the compilation of the object program. 2CHAPTER 5. THE FORTRAN LANGUAGE: citying Lists of Quantities Input-Output Statements There are 13 FORTRAN statements available for specifying the transmission of information, during the running of the object program, between core storage fon the one hand and tapes, drums, and attached card reader, card punch, and printer on the other hand. These 13 statements may be grouped as follows. 4 Five statements (READ, PUNCH, PRINT, READ INPUT TAPE, and WRITE OUTPUT TAPE) call for the transmission of a list of quantities between cores and an external storage medium — cards, printed sheet, or tape — in which information is expressed in Hollerith punch, decimal print, or BCD code, respectively. 2. One statement (FORMAT) is a non-executed statement which defines the information format in the external medium for the above 5 statements. '3. Four more statements (READ TAPE, READ DRUM, WRITE TAPE, and WRITE DRUM) call for ordinary binary transmission of a list of quantities 4. Finally, there are 3 statements (END FILE, REWIND, and BACKSPACE) for manipulating tapes. This chapter will first discuss the formation of a list of quantities for trans- mission, since such a list must appear in each of the 9 statements in groups 1 and 3 above. Next the method of writing a FORMAT statement will be described, and the format which input data to the object program must have. Finally, the statements in groups 1, 3, and 4 will be discussed. Each of the 9 statements which call for the transmission of information includes a list of the quantities to be transmitted. This list is ordered, and its order must be the same as the order in which the words of information exist (for input), or will exist (for output), in the external medium, ‘The formation and meaning of a list is best described by an example. A, BG), (CU), ALK), | = 1,10), ( (EU), = 1,10,1,FU,3), J = 1K) Suppose that this list is used with an output statement. Then the information will be written in the external medium in the order 24 “‘A, BG), CI, DUA), C(2), D2), ... (10), DIO,K), EQLDD, (2,0), £(00,1), FO), EUL,2) E22) ...--, £(00,2), F2), Fk). ‘Similarly, if this list were used with an input statement, the successive words, as they were read from the external medium, would be placed into the sequence of storage locations just given. Thus the list reads from left to right and with repetition of variables en- closed within parentheses. Indeed the repetition is exactly that of DO-repetition, as if each open parenthesis (except subscripting parentheses) were a DO, with indexing given immediately before the mated closed parenthesis, and with range extending up to that indexing information. Thus the order of the above list is the same as of the “program” 1A 8G) 051 = 1,10 ew DAK) Dog) =1,K D081 =1,10,1 EW) 9 UA) Only variables, and not constants, may be listed, Notice that indexing information, as in DOs, consists of 3 constants or fixed point variables, and that the last of these may be of it is taken to be 1. For a list of the form K, A(K) or K, (A(1), I= I,K), where an index or indexing parameter itself appears earlier in the list of an input statement, the indexing will be carried out with the newly read-in value. ‘When it is desired to transmit an entire array, and in its natural order (see the section on Arrangement of Arrays in Storage in Chapter 2), then an abbre- viated notation may be used; only the name of the array need be given and the indexing information may be omitted, FoRtRAN will look to see if a DIMENSION statement (see Chapter 6) has been made about that name; it has, indexing information to transmit the entire array in natural order be supplied automatically, while if it has not, only a single variable will be transmitted, Thus,in the example, the entire A-array will be transmitted, includ~ ing the special case where the array consists of only a single quantity, sd, in which case 2sFORMAT WARNING. The information given in this section applies in its full generality only to lists which are given with the 5 decimal statements of group 1. For the binary statements WRITE DRUM and READ DRUM only the abbreviated notation mentioned immediately above is permitted; the restrictions which affect lists for WRITE TAPE and READ TAPE are discussed in the section on Lists for Binary Tape Operations in Chapter 7. “FORMAT (Specification where Specification FORMAT 12/8124, F104) {sas described below, ‘The 5 decimal input-output statements of group 1 contain, in addition to- the list of quantities to be transmitted, the statement number of a FORMAT state- ‘ment, Which describes the information format which exists, or is to be produced, in the external medium. It also specifies the type of conversion between binary and decimal which is to be performed. FORMAT statements are not executed, their function being merely to supply information in the object program. There~ fore they may be placed anywhere-in the source program. The Specification. For the sake of definiteness the details of writing a FORMAT Specification are given for use with a PRINT ttatement, However, the descrip- tion is valid for any case simply by generalizing the concept of “printed line” to that of unit record in the external medium. Thus a unit record may be 4. A printed line with a maximum of 120 characters 2. A punched card with a maximum of 72 characters. ABCD tape record with a maximum of 120 characters. Three basic types of decimal-to-binary or binary-to-decimal conversion are available: e Floating point variable Foating point decimal F Floating point variable Fited point decimal ' Fined point variable Decimal integer ‘The FORMAT specification describes the line to be printed by giving, for each ficld in the line (from left to right, beginning with the first type wheel): 26 ~4. The type of conversion (E, F, or J) to be used; 2. The width (w) of the field; and '3. For E- and F-conversion, the number of places (d) after the decimal point that are to be rounded and printed. If d is not less than 10 it is treated mod 10. ‘These basic field specifications are given in the forms lw, Ev.d, and Fw.d with the specification for successive fields separated by commas. Thus the state- ment FORMAT (12, E12.4, F10.4) might give the line 27 99321E @ 00076 ‘As in this example the field widths may be made greater than necessary, so as to ensure spacing blanks between numbers. In this case there is 1 blank follow- ing the 27, 1 blank automatically supplied after the E, and 3 blanks after the 02. Within each field the printed output is always pushed to the extreme right. Tt may be desired to print n successive fields in the same fashion. This may bbe done by giving a before the E, F, or I. Thus the statement FORMAT (12, 3E12.4) might give 27 -0S321E 02 0.758002 0.5836E 00 To permit the repetition of groups of field specifications a limited parenthetical expression is permitted, Thus FORMAT (2(F10.6, E10.2), 14) is equivalent to FORMAT (F10.6, £10.2, F10.6, E10.2, 14). No provision is made for parentheses within parentheses. To permit more general use of F-conversion, a scale factor followed by the letter P may precede the specification. The scale factor is so defined that Printed number — Internal number X 105 ator ‘Thus the statement FORMAT (12, 1P3F11.3), used with the data of the preceding example, would give 27 932096 0.076 5.836 while FORMAT (12, -1P3F11.3) would give a 9321 9.001 0.055 [A positive scale factor may also be used with E-conversion to increase the num- ber and decrease the exponent, Thus FORMAT (I2, 1P3E12.4) would give with the same data 27 932106 01 -7:5804E03 5.536101NOTE. 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 F- and E-conversions until a new one is given. The scale factor has no effect on I-conversion. Hollerith Fields, A field may be designated as a Hollerith field, in which case English text will be printed in it. The field width, followed by the desired characters, should appear in the appropriate place in the specification, For example, FORMAT (3HXY = F8.3, 4H Z=F6.2, TH W/AF = F7.3) would give with the same data XY = 93.210 0.01 W/AF= 0554 Notice that any Hollerith characters, including blanks, may be printed. This is the sole exception to the statement made in Chapter 1 that FORTRAN ignores blanks. . It is possible to print Hollerith information only, by giving no list with the input-output statement and setting up no I, E, or F fields in the FORMAT statement. ‘Consider a Hollerith field ina FORMAT statement at the time of execu- tion of the object program. If the FORMAT statement is being used with an input statement, the Hollerith text in the FORMAT statement will be replaced ‘with whatever text is read from the corresponding field in the external medium. When the FORMAT statement is used with an output statement, whatever text is currently in the FORMAT statement will be outputted, Thus text can be originated either at source time or at object time by not using, or using, the FORMAT statement with an input statement. Multi-Record Formats. To deal with a block of printing a FORMAT speci- fication may have several different line formats, separated by the slash /. Thus FORMAT (3F9.2, 2F10.4/3E14.5) would specify a block in which lines 1,3, 5, ..-- have format 3F9.2, 2F10.4 and lines 2, 4, 6, .... have format 8E14.5 If a block format is desired having the first two lines of some special formats and all the remaining lines of another format, the last line of the format should be enclosed in parentheses; e.g. FORMAT (12, 3E12.4/2F10.3, 3F9.4/ (10F12.4)). In general, if there are items in the list still remaining to be transmitted after the format specification has been completely used, the format repeats from the last open parenthesis or (if no parentheses are present) from the beginning. 28Blank lines may be introduced into a block by omitting format information; thus // and /// will give 1 and 2 blank lines respectively. Carriage Control. When WRITE OUTPUT TAPE is being used to write a BCD tape for subsequent printing, the qvestion of carriage control of the printer ‘must be considered. The peripheral printer can operate in 3 modes: single space, double space, and Program Control, of which the last gives the greatest fe Under Program Control the carriage is controlled by the first character of each BCD record, and that character is not printed. The various control characters and their effects are Blank Single space before printing 0 Double space before printing + No space before printing 19 Skip to ctannels 19 JR Short skp to channels 19 Thus a FORMAT Specification for WRITE OUTPUT TAPE for printing with Program Control will usually begin with 1H followed by the appropriate control character. The same is true of PRINT since in FortRaN printing on the attached printer simulates Program Control printing on the peripheral printer. Decimal data to be read by a READ or READ INPUT TAPE at the time of execution of the object program must be in essentially the same format as given in the examples of the preceding section. Thus a card to be read with FORMAT (12, E124, F10.4) might be punched 27 0.93216 02 0.0076 Within each field all information must be pushed to the extreme right. Positive signs may be indicated either by a blank or a +5 — signs may be punched with fn [-punch or an 8-4 punch (see Appendix A). Blanks in numeric fields are regarded as zeroes. Numbers for E- and F-conversion may contain any number of digits, but only 8 digits of accuracy will be retained, Numbers for I-conversion will be treated mod 32768. To permit economy in keypunching certain relaxations in input data format are permitted, 41, Numbers for E-conversion need not have 4 columns devoted to the ex- ponent field, The start of the exponent field must be marked by an E, or if that is omitted, by a + or — (not a blank). Thus E2, E02, +2, +02, E 02, and E+02 are all permissible exponent fields, »READ INPUT TAPE 2, Numbers for E- or F-conversion need not have the decimal point punched. IE it is not punched the FORMAT Specification sets its effective position; for example, 09321 +2 with E12.4 will be treated as if the decimal point hhad been punched 4 places before the start of the exponent field, that is between the O and the 9. If the decimal point is punched, its position over- rides the value of d given in the FORMAT Specification. “READ, List” where nis the READ 20, K, ROO ‘statement numberof a FORMAT statement, and List i a previously described, ‘The READ statement causes the object program to read cards from the attached card reader. Record after record (card after card) is read until the complete list has been brought in, converted, and stored in the locations specified by the list. The FORMAT statement describes the arrangement of information on the cards and the type of conversion to be done. If an End of File is encountered (the program attempts to read a card and finds that there is none in the card reader) the object program HALTS. Placing more cards in the card reader and pressing the START button causes the program to continue the reading from the point in the list which it had reached, ‘A pattial check is made in the object program for incorrectly punched columns. Such a column causes a HALT, Pressing the START button causes the faulty column to be treated as a zero, and the program to continue. "READ INPUT TAPE i, List” where is READ INPUT TAPE 3,30, K, AO an unsigned fixed pont constant READ INPUT TAPE I, 30, K, AND between 1 and 10 inclusive or 3 fixed point variable, nis the statement number of a FORMAT statement, and List is as previously described. ‘The READ INPUT TAPE statement causes the object program to read BCD information from tape unit i, where i= 1,2, ..., 10, Record after record is brought in, in accordance with the FORMAT statement, until the complete list has been placed in storage. 30PUNCH PRINT WRITE OUTPUT TAPE ‘An End of File causes a HALT in the object program. Pressing the START button causes the program to continue the reading from the point in the list which it had reached. ‘The object program redundancy checks the tape reading. If a record fails twice the program HALTS. Pressing the START button causes the information read on the second attempt to be accepted and the program to continue. "PUNOH n, List” where isthe statement numberof a PUNGH 30, AU, 3 FORMAT statement an List is as previously described. ‘The PUNCH statement causes the object program to punch cards on the at- tached card punch, Card after card is punched in accordance with the FORMAT statement until the complete list has been punched. No checking is done, and there are no HALTS in the object program. ‘PINT r List” where ms the statement numberof @ PRINT 30, 40), J FORMAT statement and List sas previously described 410) ‘The PRINT statement causes the object program to print on the attached printer. Line after line is printed in accordance with the FORMAT statement until the complete list has been printed. The printing is echo checked. A printing error so detected causes the object program to HALT. Pressing the START button causes the program to continue. Pressing the RESET button and then the START button causes the line to be printed again and the program to continue. WRITE OUTPUT TAPE, 30, AU, J = 1, 10) \WRITE OUTPUT TAPE 30, AU), = 1,10) “WRITE OUTPUT TAP, Ls where isan unsigned fixed pont constant betweon 1 and 10 inclusive 2 fixed pont variable, mis the statement numberof 2 FORMAT statement, and List i a previously described atREAD TAPE ‘The WRITE OUTPUT TAPE statement causes the object program to write BCD information on tape unit i, where i= 1,2, ..., 10. Record after record is written in accordance with the FORMAT statement until the complete list has been written. No End of File is written after the last record. No checking is done, and there are no HALTS in the object program. READ TAPE List” where is an READ TAPES, (AD), J = 1,10) unsigned fied point constant between READ TAPE! AU), J = 1,10) 1 and 10 inclusive o fied Point variable, and List i a described In Chapter 7 ‘The READ TAPE statement causes the object program to read binary informa- tion from tape unit i, where i= 1, 2, ...., 10. Only one record is read, and it will be completely read only if the ‘The tape, however, always moves all the way to the next record, If the list is longer than the record, the object program will stop with a Read-Write Check, and the program will not be able to continue. ‘An End of File causes a HALT in the object program. Pressing the START button causes the program to read the next record. A READ TAPE may, t contains as many words as the record. however, be given without a list, in which case it will simply skip over a record or an End of File. For reasons of timing there are limitations on the complexity of the list. See the section on Lists for Binary Tape Operations in Chapter 7. ‘The object program redundancy checks the tape reading. (The longitudinal check is applied only if the whole record is read.) If a record fails twice the program HALTS. Pressing the START button causes the information read on the second attempt to be accepted and the program to continue. “READ ORUM ij List” where READ ORUM 2, 1000, B,C, 0 and j are each either an unsigned READ DRUM, J, A,B, D fixed pont constant or 2 fixed point variable, withthe value of | between 1 and 8 inclusive, and List is as deserted below. 2WRITE TAPE WRITE DRUM ‘The READ DRUM statement causes the object program to read words of binary information from consecutive locations on drum i, where i= 1,2,» 8, beginning with the word in drum location j, where j= 0, 1, ...., 2047. (if j > 2048 it is interpreted mod 2048.) Reading continues until the complete list has been read in, For reasons of timing there are stringent limitations on the complexity of the list. In fact, the list can employ only the abbreviated notation described earlier in this chapter; it may consist only of variables without subscripts, as A,B,C, D, ... Those variables which are simple will be read into storage in the ordinary way; those which are arrays will be read with indexing obtained from their DIMENSION statements (see Chapter 6). Thus with READ DRUM the full array must be read in, and in natural order. For example, if there is a DIMENSION statement saying that A is a 2-dimensional array with maximum indexes 5, 10, but no DIMENSION statements for B, C, D, the list above will be treated as if it were written (ACJ), | = 1, 5), J = 1, 10),B, ¢,D No checking is done and there are no HALTS in the object program. “WRITE TAPE i, List where fis an WRITE TAPE3, AU), J = 1,10) ‘unsigned fixe paint constant between 1 and 10, WRITE TAPE 1 (AD, ) = 1,10 inclusive o a fied point variable, tan List is as deseribed in Chapter 7. ‘The WRITE TAPE statement causes the object program to write binary infor- mation on tape unit i, where i= 1, 2, 10, Only one record is written; its length will be that of the list. For reasons of timing, there are limitations on the complexity of the list ‘See the section on Lists for Binary Tape Operations in Chapter 7. No checking is done, and there are no HALTS in the object program. "WRITE DRUM i,j List” wher i andj (WRITE DRUM 2, 1000, A, 8, ¢, D se each ether an unsigned fied WRITE DRUM I,J, 8 B,C, 0 point constant ora fied point vi with the value of Between 1 and 8 inctusve, and Lit i a8 described for READ DRUM. 3END FILE REWIND BACKSPACE Error Halts The WRITE DRUM statement causes the object program to write words of binary information into consecutive locations on drum i, where i= 1,2, ... 5 8, beginning with drum location j, where j= 0, 1, ...., 2047. (If j > 2048 it is imterpreted mod 2048.) Writing continues until the complete list has been written, ‘The list is subject to the same restrictions as for READ DRUM. No checking is done and there are no HALTS in the object program, “END FILE" where is en unsgned fires END FILE 3 point constant between 1 and 10 inclusive END FILE | or a fixed pont variable. ‘The END FILE statement causes the object program to write End of on tape unit i, where i= 1,2, ...., 10. "REWIND i where iis an unsigned fixed REWIND 3 point constant between I ad 10 inclusive REWIND 1 ‘ora fted point variable ‘The REWIND statement causes the object program to rewind tape unit i, where §=1,2,....,10. "-BREKSPACE i" where isan unsigned fixed BACKSPACE 3 Print constant between 1 and 10 inclusive BACKSPAGE | ‘ra fixed pont variable, The BACKSPACE statement causes the object program to backspace tape unit i by one record, where i= 1, 2, ...., 10. ‘The several HALTS which can occur during input or output operation in the object program can be identified by the contents of the storage register on the 704 console. The FoRTRAN Operator's Manual contains a list of these HALTS and their identifications. 4CHAPTER 6. THE FORTRAN LANGUAGE: ‘Specification Statements The last class of FORTRAN statements is the set of 3 specification statements DIMENSION, EQUIVALENCE, and FREQUENCY. These are statements which are not executed, but which furnish information for use by FORTRAN to make the object program efficient. DIMENSION vv, .-." where ech DIMENSION AUD), BS, 151, C8, 4,5) Vis variablesubseripte with 1,2, 01 3 unsigned fired point constants ‘Any ruber of v's may be given The DIMENSION statement provides the information necessary to allocate storage in the object program for arrays of quantities. Every variable which appears in the program in subscripted form must appear in a DIMENSION statement, and the DIMENSION statement must precede the first appearance of the variable. In the DIMENSION statement are given the desired dimensions of the array; in the executed program the sub- scripts of that variable must never take on values larger than those dimensions. ‘Thus the example states that B is a 2. seripts of B will never exceed 5 and 15; it causes 75 words of storage to be jimensional array and that the sub- set aside for the B array. ‘A single DIMENSION statement may be used to dimension any number of arrays, 3s /EQUIVALENCE, EQUIVALENCE fb, 6, (df, «0, where a,b de, .. ae variables ‘ptonall followed by single unsigned ‘xed point constant in parentheses, EQUIVALENCE A, BA), 8), 1017), £1) ‘The EQUIVALENCE statement enables the programmer, if he wishes, to con- trol the allocation of data storage in the object program. In particular, it permits hhim to economise on data storage requirements by causing storage locations to be shared by two or more quantities, when the logic of his program permits. It also permits him, if he wishes, to call the same quantity by several different names, and then ensure that those names are treated as equivalent ‘An EQUIVALENCE statement may be placed anywhere in the source program. Each pair of parentheses encloses the names of two or more quanti- ties whose storage locations are to be made the same in the object program; any number of equivalences (pairs of parentheses) may be given. In an EQUIVALENCE statement the meaning of C(5), for example, is “the 4th storage location in the object program after the cell containing G. or (if C is an array) after C(1) or C141) oF C(1,1,1)”. In general A(p) defined for p > 1 and means the p—I'* location after A or the beginning of the A array; ie. the p* location in the array. If p is not given, it is taken to be 1 Thus the example statement causes A, B, and C (or the beginnings of the A, B, and C arrays) to be so placed in storage that the location containing ‘A, the location containing B, and the 4th location after that containing C, are the same location. Similarly, it causes the 16th location after D and the 2nd after E both to be another location. ‘A quantity or array which does not appear in any EQUIVALENCE state~ ment will have storage exclusively to itself Locations can be shared only among variables, not among constants. ‘The sharing of storage locations cannot be planned safely without a knowledge of which FORTRAN statements, when executed in the object pro- ‘gram, will cause a new value to be stored in a storage location, There are 7 such statements. Execution of an arithmetic formula stores a new value of the variable on its left-hand side. Execution of an ASSIGN i TO n stores a new value in n. 36FREQUENCY Execution of a DO will in general store a new value of the index. (It will not always do so, however; see the section on Further Details about DO ‘Statements in Chapter 7.) ‘4. Execution of a READ, READ INPUT TAPE, READ TAPE, or READ DRUM stores new values of the variables listed. FREQUENCY nj, 3, mh, =" FREQUENCY 300, 2,1, were n,m, ... afe statement numbers and | 40111), 500, 7,1, 1) Jhoksl -.. ae unsigned fied pont constants. ‘The FREQUENCY statement permits the programmer to give his estimate, for each branch-point of control, of the frequencies with which the several branches will actually be executed in the object program. This information is used to optimise the use of index registers in the object program. ‘A FREQUENCY statement may be placed anywhere in the source pro- ‘gram, and may be used to give the frequency information about any number of branch-points. For each branch-point the information consists of the state~ ment number of the statement causing the branch, followed by parenthesis en- closing the estimated frequencies separated by commas. Consider the example. This might be a FREQUENCY statement in a program in which statement 30 is an IF, 40 is a DO, and 50 is a computed GO TO. The programmer estimates that the argument of the IF is as likely to be zero as non-zero, and when it is non-zero it is as likely to be negative as positive. The DO statement at 40 is presumably one for which at least one of the indexing parameters (m's) is not a constant but a variable, so that the num- ber of times the loop must be executed to make a normal exit is not known in advance; the programmer here estimates that 11 is a good average for that number, The computed GO TO at 50 is estimated to transfer to its four branches with frequencies 1, 7, 1, 1. All frequency estimates, except those about DOs, are relative; thus they ‘can be multiplied by any constant. The example statement, for instance, could equally well be given as FREQUENCY 30(2,4,2), 40(11), 50(3,21,3,3). A will be taken to mean that the frequency frequency may be estimated as 0; is very small, ‘The following table lists the 8 types of statement about which frequency information may be given. 37Computed 60 TO 22 | Order of frequencies: same as order of branches 4 Ae | eer eee |F (SENSE swrToHD 2 ae c | accumutaror overrtow | 2 | © : Hw IF QUOTIENT OVERFLOW A | o J af IF DIVIDE CHECK Po PAUSE, 2 | 8% purer af times START willbe pressed, number of times it wil ot. 0 1 | To be given only when my, my orm i variable It is not necessary to give frequency information about any branch-point. If none is given, it will be taken that the probabilities of all branches are equal. A frequency estimate concerning a DO will be ignored except when at least one of the indexing parameters of that DO is variable. Moreover, the fre- quency estimate should be based only on the expected values of those para- ‘meters; in other words, even if the range of the DO contains IFs or GO TOs which may transfer outside the range, the frequency estimate should be the number of times the range must be executed to cause a normal exit. A DO for which the indexing parameters are variable and for which no FREQUENCY statement is given will be treated as if a frequency of 5 had been estimated, 38CHAPTER 7. MISCELLANEOUS DETAILS ABOUT FORTRAN ‘The source machine is the 704 on which the source program is translated into the “object program. The object machine is that on which the object program is run. The source machine must be at least as large as a “small” 704; ie. a 704 pos- sessing 4096 words of core storage, floating point instructions, CPA (copy and add logical) instruction, 1 drum unit, 4 tape units, attached card punch, attached or peripheral card reader, and attached or peripheral printer. The object machine may be of any size. Among the information produced by ForTaaw is a count of the storage locatiors required by the object program, from which it can be easily decided whether the abject program is too large for any given object machine, ‘Arrangement ‘The instructions and constants of the object program begin in lower memory and fet the extend upwards, Data and other storage locations required for the operation of the a Object Program rogram begin at location 77777, and extend downwards. Thus these latter locations are always at the top of memory, regardless of the size of the object machine. ‘The topmost section of data storage is occupied by those variables which appear in DIMENSION or EQUIVALENCE statements. The arrangement of this region is such that two programs, whose DIMENSION and EQUIVALENCE statements are identical, will have this region allocated identically. This fact makes it possible to write families of programs which deal with the same data, ‘The successively lower sections of storage are occupied by variables not mentioned in DIMENSION or EQUIVALENCE statements, then certain storage locations required for the operation of the program, and finally a section of erasable storage FFor each object program Fortran produces a printed description of the exact arrangement of storage locations. Fixed Point ‘The use of fixed point arithmetic is governed by the following considerations. Arithmetic 4. Fixed point constants specified in the source program must have magnitudes less than 215 se 2. Fixed point data readin by the object program ane-tssiodmedeass, must Ge suinller thaw 2 ‘3. Fixed point arithmetic in the object program is arithmetic mod 216. “4. Indexing in the object program is mod (size of the object machine) ® °writing. ‘Subroutines for the Master Tape Optimisation of Arithmetic Expressions Library subroutines exist on the master ForrRaN tape in relocatable binary form. Placing a new subroutine on that tape involves (1) producing the routine in the form of relocatable binary cards, and (2) transcribing those cards on to the master tape by means of a program furnished for that purpose. Further details will be found in the FoRtRAN Operator's Manual, In the object program transfer to the subroutine is by the sequence TSK Subroutine, 4 Return ‘The subroutine itself and any constants that it requires should be located in relocat- able locations 0, 1, 2, ....It may also make use of a common storage region of any desired length n, beginning with relocatable location 77777,—(a—1) and ending with relocatable location 77777 ‘At the moment of transfer to the subroutine Arg, will have been’ placed in the AC, Arg (if it exists) in the MQ, Argy (if it exists) in relocatable location 77775, of the common storage region, Argy (if it exists) in relocatable location 77774, ete. ‘The common storage region may also be used for erasable storage by the subroutine. ‘The output of the subroutine is to be left in the AC, and index registers 1 and 2 ‘must be returned with their original contents Fixed point quantities in the object program exist in the following form: in sign bit, magnitude in decrement field, remainder of word all zeroes It is suggested that error HALTS in subroutines be coded as HPR instructions, permitting the tag and address fields to contain identifying numbers which can be recognised at the console. Considerable attention is paid in FortRAN to ensure that the object program arising from an arithmetic expression shall be efficient, regardless of how the expression has been written. For example, a sequence of multiplications and divisions not grouped by parentheses will automatically be reordered if necessary to minimise the number of storage accesses in the object program, However, one important type of optimisation, concerned with common sub- ‘expressions, takes place only if the expression has been suitably written, As an ‘example, consider the arithmetic formula, y BO SINFAMB) An efficient object program would form the product A*B only once; yet if the arithmetic formula is written as above, the multiplication of A by B will occur twice The correct way to write this arithmetic formula Y (AoB)C+SINFAB) ‘The common subexpression A+B has been displayed by the extra pair of parentheses, and an object program will be formed which multiplies A by B only once. 40§ Further Detaile about DO ‘Statements In general, when common subexpressions exist in an expression, parentheses should bbe used to display them. ‘There is one case where the programmer need not write the parentheses, because FoRTRAN will understand that they are there, The parentheses discussed in the section Hierarchy of Operations in Chapter 3 are of this type, and need not be siven. Thus y +B $C SINFASB) is as suitable for optimisation as Y = U8) C-4SINFAB) However, the parentheses discussed in the section Ordering within a Hierarchy in Chapter 3 must be supplied if common subexpression optimisation is to occur. ‘This section contains further details about DOs, which may be of interest to the advanced programmer. Triangular Indexing. Indexing such as Do 1410 Do s= 110 00 |= 410 00 J=1 is permitted and simplifies work with triangular arrays. These are simply special ccases of the fact that an index under control of a DO is available for general use as 1 fixed point variable ‘The diagonal elements of an array may be picked out by the following type of indexin : do t= 110 ALL = sone expression Status of the Cell Containing I. A DO loop with index 1 does not affect the contents of the object program storage location for I except under certain circumstances, namely if 4. An IF-ype or GO TO-type transler exit occurs from the range of the DO; 2. is used as a variable in the range of the DO; or ‘3. Lis used a a subscript in combination with a relative constant whose value changes Within the range of the DO. (A relative constant is « subscript the fxed point not currently under control of a DO.) variable of whic ‘Therefore, if a normal exit occurs from a DO to which cases 2 and 3 do not apply, the I coll contains what it did before the DO was encountered. After normal exit 4“Limite on the Size of the TAPE is itself in the range of @ DO for K). However, since J, which is the index controlled by the first parenthesis, is a subscript of both A and B, this element will work if itis the first element in the lis. In performing the translation from source to object program, FortRaN forms and uses tables which summarise various aspects of the information contained in the source program. These tables are limited in size, with corresponding limitations in the amount of information which the source program may contain, If a table size is exceeded the ForrRan program will HALT at one of @ list of locations given in the FortRAn Operator's Manual In what follows, the phrase “literal appearance” means that if the same thing appears more than once it must be counted more than once, 4, (TEIFNO Table). The number of Foran statements which have statement umbers must not exceed 1500. (An input or output statement which has a statement number and whose list contains controling parentheses counts double.) 2. (FIXCON Table). The number of diferent fixed point constants must nat exceed 100. (In this count constants which differ only in sign are not considered different.) 3. (FLOCON Table). The number of diferent floating point constants must not ‘exceed 450, (In this count constants which differ only in sign are not considered diferent, nor are numbers such as 4, 40, 40.E-1, etc. which are really the same number.) 4. (TDO Table). The number of DO statements must not exceed 150 5. The number of DO statements in any one nest must not exceed 50, . (TIFGO Table). The total number of ASSIGNS plus IF-ype and GO TO-ype statements must not exceed 300. 7. (TRAD Table). The total number of statement numbers mentioned in assigned GO TO and computed GO TO statements must not exceed 250. 8. (FRET Table). ‘The total number of numbers mentioned in FREQUENCY statements must not exceed 750, (Such a statement as FREQUENCY 30(1,2.1) thas 4 numbers.) 9. (DIM Tables). The number of 1, 2, and 3.dimensional variables which appear in DIMENSION statements must not exceed 100, 100, and 90 respectively. 10. (EQUIT Table). ‘The number of literal appearances of variables in EQUIVAL- ENCE statements must not exceed 750 12. (LAMBDA Toble). This table, and the BETA Table which follows, limit the size of arithmetic expressions on the right-hand side of arithmetic formulas and as the arguments of IF statements. In any one expression let “aElements which Contain Variables with Three Subscripts. Consider a variable A Whose three subscripts 8, s2, $3 involve as variables v,, Vz, ¥s- Then the skeleton clements (yee d ee me) will work, The innermost parentheses (controlling vs, vs, vz tespectively) may contain A(si.szi3) and any number of other variables with the same subscript combination; similarly the outermost parentheses may contain variables of any one subscript combination. The middle parentheses may not contain any subscripted variables. Thus for example (CRIA, 81K), K= 110), = 1), G1, Om, 1 = 1,10) will work provided that the first two dimensions of A and B are the same. This ‘example makes use of the first of the skeleton elements just given. In the special case where the next element in the list is neither subscripted nor enclosed in controlling parentheses, the first of the above skeleton elements may also contain variables of any one subscript combination in its middle parentheses. inally, the skeleton element Wy ve Ld va= 1 =) which unlike the others indexes in the natural order, will work. Notice, however, that the indexing parameters for v, and v, must be such that the array is swept through consecutively. The innermost parameters may contain A(s)S.)) and any ‘umber of other variables with the same subscript combination. Variable Indexing Parameters and Relative Constants. Another restriction affect- ing lists for binary tape operations concerts the use of relative constants and of indexing parameters which are variables. (A relative constant is a subscript, the variable of which is not currently under the control of a DO or a controlling parenthesis.) ‘The restriction is, that variables which have a subscript involving either relative constant or an index governed by veriable indexing parameters may appear only in the first element of a list. Furthermore, all such variables must also have among their subscripts one whose index is controlled by the first parenthesis, For example, in ((A(LI), 1 = 1L), B(KJ), J ~ 14M) both the subscripts of ‘A are governed by variable indexing parameters; for B the same is true of one of its subscripts, while the other isa relative constant (unless the READ TAPE or WRITE 8
You might also like
(V. Rajaram) Computer Programming in Fortran 90 An (B-Ok - Xyz) PDF
PDF
100% (1)
(V. Rajaram) Computer Programming in Fortran 90 An (B-Ok - Xyz) PDF
363 pages
Programming With Fortran
PDF
100% (1)
Programming With Fortran
114 pages
Chapter 11 Fortran-By Om Prakash Mahato
PDF
No ratings yet
Chapter 11 Fortran-By Om Prakash Mahato
38 pages
Fortran Note
PDF
No ratings yet
Fortran Note
20 pages
Intro To Fortran
PDF
No ratings yet
Intro To Fortran
14 pages
Fortran 77 Tutorial PDF
PDF
No ratings yet
Fortran 77 Tutorial PDF
6 pages
Unit - 11 Fortran: Computer Programming
PDF
No ratings yet
Unit - 11 Fortran: Computer Programming
45 pages
Com221 L
PDF
No ratings yet
Com221 L
29 pages
Hello World in Fortran
PDF
No ratings yet
Hello World in Fortran
43 pages
Fortran Lecture
PDF
No ratings yet
Fortran Lecture
116 pages
Fortran
PDF
No ratings yet
Fortran
73 pages
Lec-04 Fortran Data Types
PDF
No ratings yet
Lec-04 Fortran Data Types
30 pages
Introduction To Fortron Programming
PDF
100% (1)
Introduction To Fortron Programming
50 pages
Programming With Fortran
PDF
0% (1)
Programming With Fortran
114 pages
Fortran Tutorials2
PDF
No ratings yet
Fortran Tutorials2
231 pages
7 - Scientiffic Computer Language (Phy 435)
PDF
No ratings yet
7 - Scientiffic Computer Language (Phy 435)
146 pages
Cosc 344
PDF
100% (1)
Cosc 344
196 pages
A User Guide For FORTRAN 90-95-0
PDF
No ratings yet
A User Guide For FORTRAN 90-95-0
19 pages
Fortran - Quick Guide Fortran - Overview
PDF
No ratings yet
Fortran - Quick Guide Fortran - Overview
61 pages
Fortran Lecture 5
PDF
No ratings yet
Fortran Lecture 5
35 pages
Fortran Primer
PDF
No ratings yet
Fortran Primer
50 pages
FORTRAN Booklet
PDF
No ratings yet
FORTRAN Booklet
38 pages
Computer Programming Using Oo-Fortran
PDF
No ratings yet
Computer Programming Using Oo-Fortran
27 pages
Fortran Notes
PDF
No ratings yet
Fortran Notes
38 pages
Basic Fortran
PDF
No ratings yet
Basic Fortran
24 pages
Fortran
PDF
No ratings yet
Fortran
13 pages
Fortran 77 Variables and Identifiers
PDF
No ratings yet
Fortran 77 Variables and Identifiers
4 pages
Basic Operation of Plato
PDF
No ratings yet
Basic Operation of Plato
34 pages
CSC 212
PDF
No ratings yet
CSC 212
10 pages
2 - Basic Fortran
PDF
No ratings yet
2 - Basic Fortran
27 pages
Fortran Programming
PDF
No ratings yet
Fortran Programming
57 pages
Home Work 1
PDF
No ratings yet
Home Work 1
56 pages
NCI Fortran Basic PDF
PDF
No ratings yet
NCI Fortran Basic PDF
56 pages
Chapter 2:basic Elements of Fortran Programming
PDF
No ratings yet
Chapter 2:basic Elements of Fortran Programming
47 pages
Fortran Tutorial
PDF
No ratings yet
Fortran Tutorial
28 pages
COM221213926315
PDF
No ratings yet
COM221213926315
7 pages
Chap 7
PDF
No ratings yet
Chap 7
16 pages
Com221 Fortran Lang
PDF
No ratings yet
Com221 Fortran Lang
61 pages
Review of Elementary Fortran: 20 Cont Inue
PDF
No ratings yet
Review of Elementary Fortran: 20 Cont Inue
14 pages
Microsoft FORTRAN-80 3.0 Reference Manual 1977
PDF
No ratings yet
Microsoft FORTRAN-80 3.0 Reference Manual 1977
109 pages
5 Fortran
PDF
No ratings yet
5 Fortran
54 pages
Fortran
PDF
No ratings yet
Fortran
150 pages
FORTRAN
PDF
No ratings yet
FORTRAN
58 pages
Introduction To Fortran: The Fortran Programming Language
PDF
No ratings yet
Introduction To Fortran: The Fortran Programming Language
16 pages
Lesson 2
PDF
No ratings yet
Lesson 2
13 pages
Programming: With Fortran by Dr. Agus Dwi Anggono
PDF
No ratings yet
Programming: With Fortran by Dr. Agus Dwi Anggono
20 pages
(NOTES) BASICS OF FORTRANwerytqertw
PDF
No ratings yet
(NOTES) BASICS OF FORTRANwerytqertw
8 pages
Fortran 77 Tutorial PDF
PDF
No ratings yet
Fortran 77 Tutorial PDF
38 pages
Com 221
PDF
No ratings yet
Com 221
18 pages