FORTRAN-SO PROGRAMMING MANUAL Manual Order Number: 9800481 A I Copyright © 1978 Intel Corporation Intel Corporation, 3065 Bowers Avenue, Santa Clara, California 95051 .
The information in this document is subject to change without notice. Intel Corporation makes no warranty of any kind with regard to this material, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose. Intel Corporation assumes no responsibility for any errors that may appear in this document. Intel Corporation makes no commitment to update nor to keep current the information contained in this document.
PREFACE This manual describes the Intel-developed FORTRAN language (FORTRAN-80) for programming the 8080 and 8085 microcomputers. FORTRAN-80 is based on the ANSI FORTRAN 77 subset. In some instances, it incorporates features from the FORTRAN 77 full language; FORTRAN-80 also has features that exceed both versions of FORTRAN 77.
CONTENTS 3.4 PREF'ACE GLOSSARY CHAPTER 1 INTRODUCTION TO FORTRAN 1.1 1.2 An Introductory Example ................ , 1.1.1 Comment Lines .................... 1.1.2 Type Statement ................... , 1.1.3 Input Statement ................... , 1.1.4 Value Assignment .................. 1.1.5 Output Statements. . . . . . . . . . . . . . . . .. L 1.6 Program Termination. . . . . . . . . . . . . .. Summary Of FORTRAN-SO Statements. . . . .. 1.2.1 Executable Statements. . . . . . . . . . . . . .. 1.2.
.2 6.3 6.4 File-Handling Statements. . . . . . . . . . . . . . . .. 6-4 6.2.1 OPEN Statement. . . . . . . . . . . . . . . . . .. 6-4 6.2.2 CLOSE Statement. ............... " 6-8 6.2.3 BACKSPACE Statement. . . . . . . . . . . .. 6-9 6.2.4 REWIND Statement ............... 6-10 6.2.S ENDFILE Statement. . . . . . . . . . . . . .. 6-10 Data-Transfer 110 Statements ............. 6-10 6.3.1 READ Statement. ................. 6-10 6.3.2 WRITEStatement ................. 6-13 6.3.3 PRINT Statement ................
GLOSSARY Argument(s) - A collection of values and variables on which a computation is performed. Functions and subroutines are usually defined with dummy arguments that are replaced with actual values when the functions or subroutines are referenced. Array - An ordered set of data that can be referenced collectively (by array name) or selectively (by array element name). Array Element - An individual item within an array.
Glossary FORTRAN-SO Program Unit - Another name for a main program or a subprogram. Every program unit must be terminated by an END statement. Record - A sequence of values or characters. Statement - A sequence of syntactic items: statement label, keyword, arguments, expressions, etc. A statement has an 'initial' line and up to nine 'continuation' lines. Statement Label- A 1-5 digit integer in columns 1-5 of a statement's initial line. Can be given a symbolic name by the ASSIGN statement.
CHAPTER 11 INTRODUCTION TO FORTRAN This chapter opens with a short example intended to give the newcomer to FORTRAN a feel for the language. The example is discussed in some d.etail. The chapter also includes a summary of FORTRAN-80 statements and their proper coding sequence. 1.1 An Introductory Example A FORTRAN program generally performs three basic operations: receiving input, processing the data received, and returning output.
Introduction To FORTRAN FORTRAN-SO 1.1.2 Type Statement Every variable used in a FORTRAN program has a type - integer, real, logical, character, or Hollerith. The CHARACTER type statement says that the variable PNAME represents character data and may have up to 12 characters. No type statement is needed for the other variables listed (AB, HITS, AVO). The FORTRAN variable-naming convention tells us implicitly that these variables are to be used to name real data.
FORTRAN-SO Introduction To FORTRAN Statement 20, the FORMAT statement, indicates the 'PNAME' field will be a string of characters of variable length, as in the FORMAT statement labeled 10. The name will be followed by five blanks (5X) and then the batting average will be printed. The 'A VG' field consists of four floating-point digits -- one integer digit and three decimal digits. 1.1.6 Program Termination The final statement terminates the program.
Introduction To FORTRAN FORTRAN-SO 1.2.3 Order of Statements The following order must be observed in coding FORTRAN statements lines: 1. Comment lines can appear before or between statements. They cannot appear after the END statement. 2. The PROGRAM statement can appear only as the first statement of a main program. FUNCTION, SUBROUTINE, and BLOCK DATA can appear only as the first statement of a subprogram (Section 2.1.1). 3. FORMAT statements can appear anywhere before the END statement. 4.
CHAPTER 2 FORTRAN CONCEPTS The chapter discusses the concepts and terminology used to describe the structure and elements of a FORTRAN program. 2.1 FORTRAN Program Structure 2.1.1 Program U nits and Procedures The scope of many FORTRAN operations is defined to be a program unit. A program unit is either a main program or a subprogram. A main program can start with a PROGRAM statement, though it need not. Subprograms start with either a FUNCTION, SUBROUTINE, or BLOCK DATA statement.
FORTRAN Concepts 2.1.2 The PROG RAM Statement The PROGRAM statement is used to name a program. This statement is optional, but when present must be the first statement of a main program. It has the format PROGRAM name where 'name' is the symbolic name of the program. Only one PROGRAM statement is allowed per program. The main program can contain any other statement except FUNCTION, SUBROUTINE, BLOCK DATA, SAVE, or RETURN. The scope of symbolic names is discussed later in this chapter (section 2.5.5).
FORTRAN Concepts FORTRAN-80 2.2 FORTRAN Statement Elements A FORTRAN statement can include the following elements: • Statement identifier (keyword), such as PROGRAM or INTEGER • Function identifiers, such as SQRT(A) or FLOA T(I) • Constants, such as 3.142857 or 'STRING' • • • Variables, such as A or AB Operators, such as * or .AND.
FORTRAN-SO :FORTRAN Concepts 2.2.2 Constants and Variables The value of a constant does not change from one execution of a program to the next. The value of a variable, on the other hand, is subject to change during program execution or between runnings of the program. For example, in the statement C=A**2+B the '2' is constant, whereas A, B, and C are variable and may change as the result of an earlier calculation or value assignment. A constant appears as its actual value.
FORTRAN Concepts FORTRAN-80 Character data is a string of any characters representable in the processor. The blank character is valid and significant in a character constant. A character constant has the form of a string of characters surrounded by apostrophes. An apostrophe within the string is represented by a double apostrophe. A character constant can have 1-255 characters.
FORTRAN-SO FORTRAN Concepts The possibleJorms of aninteger constant are: [s]d" . or [sl#d ... b where: s is an optional + or -. sign d is a digitor.one of the letters A~F b designates the number base and is one of the letters D,B,O; Q, or H lfthe numher base specjfier is absent or is the letter >'D/thecharacler string 'd ... ' can contain only the digitsO~9artdjsinterpretedas a decimal number..
FORTRAN Concepts FORTRAN-80 2.2.4 Expressions and Operators An expression is a combination of numbers, symbols, and operators. It may include parentheses and may also include functions (discussed in Chapter 5). Expressions appear in assignment statements (e.g., A = B + C) as controls in certain data processing statements (e.g., IF FLAG .NE. 3 GO TO 250), and in subroutine calls (CALLSUB(X+l, Y). FORTRAN has four kinds of 2.2.4.1 Character Expressions.
FORTRAN Concepts FORTRAN-80 Fig. 2w$ ·.type,. Length, andJnterpretatbin o~(O~1**QP2) As these figures indicate, mixed-mode arithmetic is done by converting both operands to the same type (the type of the result) before performing the operation. This conversion is unnecessary when a real number is raised to an integer power. In the case of an integer divided by another integer, the remainder is truncated.
f'ORTRAN Concepts FORTRAN-SO Relational expressions are commonly used in the IF statement (Chapter 4). IF (NUMB .GT. 99) STOP IF (PNAME .EO. 'GEHRIG') PRINT 20, PNAME, AVG 2.2.4.3.2 Interpretation of Arithmetic Relational Expressions. An arithmetic relational expression is TRUE if the values of the operands satisfy the relational condition set up by the operator, and is FALSE otherwise. If the operands are of different types, type conversion is similar to that of arithmetic expressions.
FORTRAN-SO FORTRAN Concepts The following example passes control to line 10 if the logical variable DONE is not true. Otherwise, execution stops. 10 FLAG = FLAG + 1 DONE = (FLAG .GT. 99) IF (.NOT. DONE) THEN GOTO 10 ELSE STOP ENDIF The value when two logical operands are combined by .AND. is as follows: OP1 OP2 OP1 .AND. OP2 TRUE TRUE FALSE FALSE TRUE FALSE TRUE FALSE TRUE FALSE FALSE FALSE If both operands are true, the logical expression is true.
FORTRAN-80 FORTRAN Concepts The following statement returns whenever the two logical operands are logically equivalent. IF (FLAG1 .EQV. FLAG2) RETURN The value when two logical operands are combined by .NEQV. is as follows: OP1 OP2 OP1 .NEQV. OP2 TRUE TRUE FALSE FALSE TRUE FALSE TRUE FALSE FALSE TRUE TRUE FALSE If both operands are logically different, the logical expression is true. The following statement continues execution if the two operands are not equivalent. IF (FLAG1 .NEQV.
.FORTRAN Concepts FORTRAN-SO Parentheses can be used to override normal rules of precedence. The part of an expression enclosed in parentheses is evaluated first. If parentheses are nested, the innermost are evaluated first. 15/3 + 18/9 = 5 + 2 = 7 15/(3 + 18/9) = 15/(3 + 2) = 15/5 = 3 The following lists the precedence of operators in descending order: • Parenthesized expressions • Exponentiation: ** • Multiplication/Division: *, / • Addition/Subtraction: • Relational Operators: .LT.,.LE.,.EQ.
FORTRAN-80 FORTRAN Concepts • Statement function names • Intrinsic function names • Dummy procedure names Variables appearing as dummy arguments in a statement function have a scope of that statement only. Common block names are generally global, but do admit exceptions. A common block name in a program unit may also be the name of any local entity other than an intrinsic function in a function subprogram.
CHAPTER 3 DEFINING VARIABLES, ARRAYS, AND MEMORY This chapter describes the statements used to specify the types and lengths associated with symbolic names, how to assign values to these symbols, .how to structure memory, and how to assign values to a block of memory.
FORTRAN-80 Defining Variables, Arrays, And Memory where 'name' is one of the forms v[*/en} ary[(d)][* len] and v is an integer variable, function, or dummy procedure name ary is an array name ary(d) is an array declarator lenj.i~~~~l~9:!~~i*~~f¢~;0;(
FORTRAN-SO Defining Variables t Arrayst And Memory Examples: LOGICAL *2 FLAG LOGICAL* 1 FLAGS(10) LOGICAL *4 FLAG1, FLAG2, SWITCH(5)*1 3.1.4 CHARACTER Type Statement The CHARACTER type statement has the format: CHARACTER [* len[,]] name [,name] ... where 'name' is one of the forms: v[* len] ary[(d)][* len] and v is a variable name ary is an array name ary(d) is an array declarator len is the length (number of characters) of a character variable or character array element.
FORTRAN-SO Defining Variables, Arrays, And Memory The IMPLICIT statement has the format: IMPLICIT typ (let [,/et] ... ) [,typ (let [,let]. .. )]. .. where LOGICALt~lejz], typ is INTEGERf*bml , REAL, CHARACTER[* len] let is a single letter or a range of letters in alphabetical order (e.g., C, I-M, N-Z) or The IMPLICIT statement applies only to the program unit in which it appears and must precede all other specification statements in that program unit.
FORTRAN-80 Defining Variables, Arrays, And Memory By 'array element name' we mean an array name qualified by a subscript in parentheses as shown in the example above. An array name not qualified by a sUbscript identifies the entire array, with one exception. In an EQUIVALENCE statement, an array name not qualified by a subscript identifies the first element of the array. An array name is local to the program unit in which it is declared. 3.2.
Defining Variables, Arrays, And Memory 3.2.3 Properties of Arrays The examples following the description of the DIMENSION statement specify the types of the array names and, by implication, the types of the elements in the arrays. They also specify (by default) the lengths of the elements. The remaining properties of the array are determined from the dimension declarator.
FORTRAN-80 Defining Variables, Arrays, And Memory where 'ary' is an array name and's' is a subscript. The number of subscripts must equal the number of dimensions in the array declarator. Each subscript is an integer expression in the range 1 :5 s:5 upper-bound. If the upper dimension bound of a dummy array is an asterisk, the value of the corresponding subscript must not exceed the size of the corresponding actual array.
FORTRAN-80 Defining Variables, Arrays, And Memory 3.3.1 Arithmetic Assignment Statement The arithmetic assignment statement closely resembles a conventional arithmetic formula. Its format is: v = exp where v is the name of a variable or array element of type integer or real exp is an arithmetic expression I The' =' in FORTRAN has the sense 'is assigned the value' rather than 'is equal to.' Thus I = 1+1 is a perfectly correct FORTRAN statement.
FORTRAN-SO Defining Variables, Arrays, And Memory 3.3.2 Logical Assignment Statement The logical assignment statement assigns the value. TRUE. or .FALSE. to a logical variable or array element. It has the format v = exp where v is the name of a logical variable or logical array element exp is a logical expression Examples: LOGICAL FLAG, TABLE(3,3) FLAG = (INT1 .NE. 1 .AND. INT2 .EQ. 1) C FLAG IS .TRUE.IF BOTH CONDITIONS ARE TRUE AND C OTH ERWISE IS .FALSE. TABLE(1,3) = .FALSE. TABLE(1,2) = FLAG 3.3.
Defining Variables, Arrays, And Memory The ASSIGN statement has the format: ASSIGN stlTO name where stl is a statement label (1-5 digits) name is an integer variable name The statement label must be the label of an executable statement or a FORMA T statement in the same program unit as the ASSIGN statement. The variable 'name' must not be declared as length INTEGER * 1.
FORTRAN-80 Defining Variables, Arrays, And Memory Items in DATA lists must agree in number, type, and length. 'Nlist' and 'elist' must have the same number of items, as the lists correspond oneto-one. If 'nlist' contains an array name without a subscript, 'elist' must have one constant for each element of that array (but see section F.2.9.2). Any subscript that is specified must be an integer constant.
Defining Variables, Arrays, And Memory FORTRAN-80 where 'nlist' is a list of variable names, array names or array element names. The latter may only be subscripted by integer constants. The use of an array name unqualified by a subscript is the same as a reference to the first element of the array. Function names and the names of dummy arguments may not be listed. Equivalenced items may have different data types, although this is not recommended. The EQUIV ALENCE statement does no type conversion.
FORTRAN-80 Defining Variables, Arrays, And Memory The items in 'nlist' following a common block name (or omitted name) are declared to be in that block (or in blank common). If a common block name is omitted, the statement refers to the blank common block. If the first common block name is omitted in the above format, the slashes may be omitted also. The slashes must be present, however, if blank common is specified as other than the first common block.
Defining Variables, Arrays, And Memory 3.4.4 BLOCK DATA Statement The format of the BLOCK DATA statement is: BLOCK DATA [name] where 'name' is the symbolic name of the BLOCK DATA subprogram. Since 'name' is global, it must not be the same as the name of an external procedure, main program, common block, or another BLOCK DATA subprogram. Only one unnamed BLOCK DATA subprogram is permitted per executable program.
CHAPTER 4 PROGRAM EXECUTION CONTROLS FORTRAN includes 16 statements, or statement variations, for controlling program execution. These are statements that transfer control (GO TO, IF, and their variations), regulate execution loops (DO, CONTINUE), and terminate program execution (PAUSE, STOP, END). 4.
Program Execution Controls FORTRAN-SO Examples: GO TO (1010,1020,1030) K C IF K = 2, FOR EXAMPLE, CONTROL PASSES TO STATEMENT C 1020 INTEGER*1 SWITCH SWITCH = K/J GO TO (10,500,500,10,10) SWITCH C NOTE THAT 'J' MUST BE .LE. 'K' IN THIS EXAMPLE GO TO (10, 500, 600, 500) K * L + 1 4.1.3 Assigned GO TO Statement The assigned GO TO statement is used with the ASSIGN statement. The assigned GO TO is similar to the computed GO TO, but in this case the control is an integer variable name.
FORTRAN-SO Program Execution Controls Examples: IF(A + 8)1010,1020,1030 SWITCH = A**2 - 8**2 IF (SWITCH) 100,200,300 4.1.5 Logical I F Statement We have given several examples of logical IF statements already in this manual. In effect, if the logical expression evaluated is TRUE, a specified statement is executed next. If the logical expression is FALSE, execution continues with the statement following the logical IF statement.
Program Execution Controls FORTRAN-SO An ELSE block consists of all the executable statements after the ELSE statement up to, but not including, the next END IF statement that has the same nesting level as the ELSE statement. For each block IF statement, there must be a corresponding END IF statement in the same program unit. IF ... IIF BLOCK ELSE IF ... IF ... : =:J IF BLOCK ELSE IF BLOCK END IF ELSE _ _ _ _ _ _ _ _ _ _ _ _ _ _ _- - , IF ... IF. . .
FORTRAN-80 Program Execution Controls If 'exp' is TRUE, normal execution continues with the first statement of the ELSE IF block. If 'exp' is FALSE, control passes to the next ELSE IF, ELSE, or END IF statement having the same level as the ELSE IF statement. Control cannot 'be transferred into an ELSE IF block from outside the block (but see section F.2.9.3). The statement label, if any, of the ELSE IF statement cannot be referenced by another statement.
FORTRAN-80 Program Execution Controls 4.2 Loop Control Statements Frequently, a series of operations must be repeated several times (for example, reading a series of entries from an input device and extracting information selectively). Rather than repeat the statements to perform these operations for each entry, one can create a loop that causes the same statements to be performed over and over until all entries have been read and processed. This is the function of the DO statement.
FORTRAN-80 Program Execution Controls DO loops may be nested, that is, a DO loop can contain another DO loop, etc. If a DO statement appears within the range of another DO loop, the loop specified by the second DO statement must be within the range of the outer DO loop. DO loops can share the same last statement. I f a DO statement lies within an IF block, ELSE IF block, or ELSE block, the range of the DO loop must be entirely within that block.
Program Execution Controls 4.3.1 PAUSE Statement The format of the PAUSE statement is PAUSE [msg] where 'msg' is a string of not more than five digits, or is a character constant. At the time the PAUSE is executed and program execution ceases, 'msg' is displayed on the console terminal. Program execution must be resumable following the pause. Resumption is not under program control, however, and might be initiated, for example, by an external interrupt such as a key being pressed.
CHAPTER 5 FUNCTIONS AND SUBROUTINES Functions and subroutines reduce coding, break programs into readily-visible logical structures, conserve storage, avoid the tedium and increased probability of error in repetitive coding, and eliminate the coding of commonly-used mathematical functions. The term 'function' refers to a statement or subprogram that returns a value when it is referenced. A subroutine is a subprogram that does not return a value, but may alter the values of variables outside itself.
FORTRAN-SO Functions And Subroutines I f the name of an intrinsic function appears in the dummy argument list of a FUNCTION or SUBROUTINE subprogram, the name is considered to have no relation to the intrinsic function within the scope of the program unit and the name itself loses its intrinsic quality. The data type associated with the symbolic name is specified as normal (by default or by a type statement).
Functions And Subroutines FORTRAN-80 The statement function name and the expression 'exp' may be of different types. The type of the value returned is as shown in Figure 3-2. The dummy argument list indicates the order, number and type of arguments for the statement function. The names of dummy arguments have a scope of the statement function only, and each name may appear only once in the dummy argument list.
FORTRAN-80 Functions And Subroutines A statement function may be referenced only in the program unit where it is defined. The statement function may not reference another statement function if that other function is defined later in the program unit. Furthermore, a statement function in a FUNCTION subprogram must not reference the name of the subprogram.
Functions And Subroutines FORTRAN-SO An actual argument may also be a dummy argument as long as the dummy is part of a dummy argument list within the subprogram containing the external function reference. 5.2.1.2 FUNCTION Subprogram Limitations A FUNCTION statement may be used only as the first statement of a FUNCTION subprogram. The subprogram itself can consist of any other statement except a SUBROUTINE, BLOCK DATA, or PROGRAM statement.
FORTRAN-SO Functions And Subroutines The subroutine is called by the CALL statement. PROGRAM CALL .. SUBROUTINE .~RETURN CA.~END END Subroutines, being external procedures, can be defined outside the program. By the time a program containing a CALL to the subroutine is executed, however, the subroutine must be part of the calling program, either by SUBROUTINE subprogram definition or by being linked to the program. External procedure linkage is described in the FORTRAN compiler operator's manual.
Functions And Subroutines FORTRAN-SO When a RETURN is executed in a FUNCTION subprogram, the value of the function must be available to the referencing program unit. Whenever RETURN is executed, the association between the dummy arguments of an external procedure and the current actual arguments is terminated (but see section 5.2.5, the SA VE statement). Example: C TH REE N UM BERS ARE ADDED AN D TH E FLAG 'POSTor SET TO C TO 11F THEIR TOTAL IS POSITIVE SUBROUTINE POSTOT(A,B,C) IF ((A + B + C) .GE.
FORTRAN-SO Functions And Subroutines 5.2.7 CALL Statement The CALL statement is used to reference a subroutine. A subroutine can be referenced within any other external procedure or in the main program. A subprogram must not reference itself either directly or indirectly (but see the description of the REENTRANT compiler control in section F.2.3). The format of the CALL statement is CALL sub [([arg [,arg]. .. ])] where sub is the symbolic name of a subroutine or dummy procedure.
FORTRAN-80 Functions And Subroutines 5.3.1 Common Blocks Common blocks reduce storage requirements by allowing two or more subprograms to share the same memory. This sharing may be limited by the rules for defining and referencing data. The variables and arrays in a common block can be defined and referenced in all subprograms that contain a declaration of that common block.
FORTRAN-80 Functions And Subroutines NOTE The subscript value remains constant as long as the arguments are associated, even if the subscript contains variables redefined during the association. Argument association can be carried through more than one level of procedure reference. A valid association exists at the last level, however, only if the association is maintained through all intermediate levels. The association normally terminates when a RETURN or END is executed.
FORTRAN-SO Functions And Subroutines NOTE In a given program unit, det~rmining whether a dummy procedure is associated with a function or a subroutine may not be possible. If a procedure name appears only in a dummy argument list, an EXTERNAL statement, and an actual argument list, examining the subprogram is not enough to determine whether the symbolic name should be associated with a subroutine or a function. A dummy argument associated with an intrinsic function has no automatic type association.
CHAPTER INPUT/OUTPUT The FORTRAN input/output (I/O) statements transfer data between a processor and external units or within the processor itself. These statements can specify the external units to be used, the variables whose values are being entered or output, and the format of I/O data. The first group of I/O statements are the file-handling statements (OPEN, CLOSE, BACKSPACE, REWIND, ENDFILE).
Input/Output FORTRAN-SO 6.1.2.1 File Existence At the time an executable program is running, a certain set of files is available. These files are said to exist, and the particular files that exist are determined by the operating system or environment in which the program is running. A file may exist without containing any data; an example would be a newly-created file having only a name. All FORTRAN I/O statements can refer to existing files.
FORTRAN-SO Input/Output 6.1.2.5 File Access An external file can be accessed sequentially or directly. An internal file can only be accessed sequentially. Some external files may be allowed more than one access method, depending on the operating environment. The access method is determined when the file is connected to a unit. 6.1.2.5.1 Sequential Access File.
Input/Output FORTRAN-SO 6.2 File-Handling Statements 6.2.1 OPEN Statement The OPEN statement can be used to connect an existing file to a unit, create a preconnected file, create a file and connect it to a unit, or change certain specifiers in the file/unit connection. The format of the OPEN statement is OPEN (open-list) where 'open-list' is a list of specifiers separated by commas.
FORTRAN-80 Input/Output Executing an OPEN statement containing this specifier causes 'stname' to become defined with a zero value if no error condition exists, or with a processor-dependent positive integer value if an error condition does exist. Example: OPEN (4, IOSTAT = ERRFLG) 6.2.1.3 Error Specifier The format of the error specifier is ERR = stl where 'st!' is the label of an executable statement in the same program unit as the OPEN statement.
Input/Output FORTRAN-SO If 'OLD' or 'NEW' is specified, the FILE specifier must be present also. An 'OLD' file must exist already; a 'NEW' file cannot exist already. The 'SCRATCH' option must not be specified with a named file. When it is specified with an unnamed file, the file is connected to the specified unit for the duration of program execution or until a CLOSE statement is issued for the same unit. If 'UNKNOWN' is specified, the file status is processor dependent.
Input/Output FORTRAN-80 If the file is being connected for formatted 110, 'reclen' is the number of characters. If the file is being connected for unformatted 110, the length is measured in bytes. If the file already exists, the length specified must be that used when the file was created. In the case of a new file, the processor creates a file with the specified length for each record. The REeL specifier must be included in the OPEN statement when a file is being connected for direct access.
Input/Output FORTRAN-SO 6.2.1.11 Opening A Connected Unit The OPEN statement can be specified for a unit already connected to an existing file. That existing file is assumed to be the value of 'fname' if the FILE specifier is not included in the OPEN 'open-list.' I f the file to be connected is the same as the connected file, the effect of OPEN depends on whether or not the file was preconnected.
Input/Output FORTRAN-80 6.2.2.2 File Disposition Specifier The format of the file disposition specifier is STATUS = stat where 'stat' is a character expression evaluating to 'KEEP' or 'DELETE'. If this specifier is omitted, the default value is 'DELETE' for a file that previously had a status of 'SCRATCH', and 'KEEP' otherwise. Under no circumstances can 'KEEP' be specified for a file opened with 'SCRATCH' status.
FORTRAN-80 Input/Output where 'unit' is an external unit specifier and 'arg-list' is a list of arguments as described for the BACKSPACE statement (section 6.2.3). If the specified file is already positioned at its initial point, or if the file is connected but does not exist, the REWIND statement has no effect. If an end-of-file condition has occurred, the file can still be rewound. Examples: REWIND 3 REWIND (3, IOSTAT= ERRFLG, ERR= 1030) 6.2.
FORTRAN-SO Input/Output The list of control information specifiers is: [UNIT =] unit [FMT =] f REC = recno IOSTAT = stname ERR = stl END = stl U nit specifier Format specifier Record number specifier I/O status specifier Error specifier End-of-file specifier 6.3.1.1 Control Information List The control information list must contain a unit specifier. If the second form of the READ statement shown above is used (that is, if no unit is specified), the unit read is the default unit.
Input/Output FORTRAN-SO I f the asterisk option is selected, 'ctl-list' must not include a record number specifier. If the unit specifier is an internal file, the format specifier must be present, but cannot be an asterisk. Examples: 25 READ (2,25) PNAME, AS, HITS FORMAT ... 25 READ 25, PNAM E, AS, HITS FpRMAT ... 25 ASSIGN 25 TO INFMT READ (2,INFMT) PNAME FORMAT ... READ (2, *) PNAM E 6.3.1.1.3 Record Number Specifier.
Input/Output FORTRAN-SO 6.3.1.2 Input List The list 'in-list' in the READ statement identifies the items whose values are to be read. An item in an input list must be a variable name, array name, or array element name. If an array name is listed, the entire array is read in normal array element ordering sequence. The name of an assumed-size dummy array must not appear in the input list. 6.3.1.
Input/Output FORTRAN-SO 6.3.3 PRINT Statement The PRINT statement outputs formatted data to the default write unit. It has the format PRI NT f [,out-list] where f is a format identifier out-list is a list of the data to be written Note that the keyword 'PRINT' does not necessarily imply the default unit is a line printer or other print device. The format specifier 'f' has the same meaning as for the READ statement (section 6.3.1.1.2).
FORTRAN-80 Input/Output 6.4.2 Formatted Data Transfer During formatted data transfer, data is transferred with editing between the file and the 110 list. The editing is directed by some kind of format specification. Format specifications can be given: • In FORMAT statements; • As values of character arrays, character variables, or other character expressions; • As Hollerith values assigned to integer, real, or logical arrays. I f the format specifier (section 6.3.1.1.
FORTRAN-SO Input/Output 6.4.3 FORMAT Statement The form of the FORMAT statement is stl FORMAT ([flist]) where stl is a 1-5 digit statement label JUst is a format specification list whose items are separated by commas Each item in 'flist' must be a repeatable edit descriptor, a nonrepeatable edit descriptor, or a parenthesized 'flist.' An edit descriptor is repeated by prefixing it with a nonzero, unsigned integer constant called a 'repeat specification.
FORTRAN-80 Input/Output Certain general remarks apply to all three of these numeric editing descriptors. • On input, leading blanks are not significant. Other blanks are treated according to the setting of the non repeatable descriptors BN and BZ and the value of the BLANK sp~cifier in the OPEN statement (section 6.2.1.9). • A decimal point in input data overrides the decimal point location specified by an For E descriptor.
FORTRAN-SO Input/Output 'E' Descriptor Editing An I/O list item matched with an 'Ew.d' or 'Ew.dEe' descriptor must be a real variable. The exponent 'e' has no effect on input data. On output, the format of the output field for a scale factor (section 6.4.3.1.2) of zero is: [±] [0].
Input/Output FORTRAN-80 A /phanumeric Editing An 110 item matched with an 'A' or 'Aw' descriptor must have type character or be defined with Hollerith data. If the field width 'w' is specified, the field consists of 'w' characters. Otherwise, the number of characters in the field is the length of the 110 list item. On input, if the character string is longer than the specified width, the string is truncated on the right.
Input/Output FORTRAN-SO The width of the field is the length of the character string. Example: 100 WRITE (7,100) ITSTNO FORMAT ('THIS IS THE TEST NUMBER', 2X, 12) 'H' Descriptor Editing The Hollerith field descriptor is an alternate way to perform the same operation as apostrophe editing. Like apostrophe editing, it is used only for output. The 'nH' descriptor causes the In' characters following the 'H' to be written out (including embedded blanks).
Input/Output FORTRAN-80 Scale Factor (P) Editing A scale factor is established by the' kP' edit descriptor, where' k' represents the scale factor. It is used with the 'F' and 'E' descriptors to edit real numbers. No comma is needed between the 'P' descriptor and an immediately following 'F' or 'E.' 1PE8.6E2 A scale factor of zero is assumed at the beginning of an 110 statement.
FORTRAN-SO Input/Output scanner encounters a dollarsign at the end of a format specification list, format con;. trol terminates without positioning the file to the beginning of the next record. The donar sign .edit descriptor has no effect on direct~accessfil¢s. Example: 25 PAINT 25, PNAME FORMAT (A20, $) 6.4.4 List·Directed Formatting I List-directed formatting is indicated by specifying an asterisk (*) in the format specifier of a data-transfer 110 statement's control list (section 6.3.1.1.2).
Input/Output FORTRAN-80 6.4.4.2 List-Directed Output The form of the values produced by list-directed output agrees in type with their corresponding output list items. The processor separates records as necessary, so long as the end of a record does not fall within a constant (except a character constant) and blanks are not embedded within constants. Integer output constants are produced with the effect of 'Iw' formatting, for some reasonable value of 'w.
CHAPTER 7 PROGRAMMING GUIDELINES This chapter is by no means intended as an exhaustive discussion of programming techniques. It is intended simply as a guideline, primarily for the novice programmer. For those who wish to go more deeply into the science of FORTRAN programming, a number of references are listed in the bibliography at the end of the chapter. The first section of this chapter deals with general guidelines applicable to programming in any language.
Programming Guidelines FORTRAN-80 As the development of a program becomes more detailed, the documentation should become correspondingly detailed. The ultimate documentation is, of course, the final program code, which should include numerous useful comments, have meaningful mnemonic names for symbols, and make good use of blanks in statement lines to improve program readability. If the program is not severely limited by processor memory size, each program unit could be prefaced with a comment block.
FORTRAN-SO Programming Guidelines The next pass is a more formal description of level two, introducing FORTRAN statements for English sentences. Level Three C INITIALIZE VARIABLES NEEDED FOR TOTALS DATA TOTEMP, TOTHRS, TOTPAY / 3*0.
Programming Guidelines This is just a 'starter' list. Certainly, any experienced programmer could add to this checklist. Rereading such a list frequently, like rereading programming manuals, is a good way to refresh or reconfirm programming knowledge. 7.2 FORTRAN Coding Section 7.1 lists some general programming considerations. When coding in FORTRAN specifically, other points should be kept in mind. 7.2.
Programming Guidelines FORTRAN-SO When calculating a value for use in a DO loop, be sure the value is computed before the loop is entered. Otherwise, the program could compute the value again for each iteration of the loop.
Programming Guidelines McCracken, Daniel A., A Simplified Guide to FORTRAN Programming, John Wiley & Sons, New York, 1974. Mills, Harlan B., Mathematical Foundations for Structured Programming, Technical Report, FSC 72-6012, IBM Federal Systems Division, Gaithersburg, Md., 1972. Ogdin, Carol A., 'Software Design Course,' EDN, June 5, 1977. Wirth, Niklaus, 'Program Development by Stepwise Refinement,' Communications of the ACM, Vol. 14, No.4, April 1971.
APPENDIX A FORTRAN-80 STATEMENT SUMMARY A.1 Statement Sequence The following order of statements and lines must be observed when coding a FORTRAN program. 1. Comment lines can appear before or between statements, but cannot appear after an END statement. 2. The PROGRAM statement, if used, must be the first statement of a main program. The first statement of a subprogram must be a FUNCTION, SUBROUTINE, or BLOCK DATA statement. Within a program unit that permits the following statements: 3.
FORTRAN-SO FORTRAN-80 Statement Summary BACKSP ACE Statement Category: Executable Text Reference: Section 6.2.3 Function Formats Position file connected to 'unit' before preceding record. BACKSPACE unit BACKSPACE (arg-list) Notes: 'unit' is unit specifier 'arg-list' is following argument list: [UNIT =] unit IOSTAT = stname ERR = stl unit specifier 110 status specifier error specifier BLOCK DATA Statement Category: Nonexecutable Text Reference: Sections 3.4.3,3.4.
FORTRAN-SO FORTRAN-80 Statement Summary CLOSE Statement Category: Executable Text Reference:' Section 6.2.2 Format Function CLOSE (close-list) Close file (disconnect described by 'close-list.' unit) Notes: 'close-list' can be following fields: [UNIT =] unit IOSTAT = stname ERR = stl STATUS = stat unit specifier 110 status specifier error specifier file disposition specifier Comment Line Category: Nonexecutable Text Reference: Section 1.1.
FORTRAN-SO f'ORTRAN-80 Statement Summary DATA Statement Category: Nonexecutable Text Reference: Section 3.3.5 Format Function DATA nlist/ clist/[[,) nlist/ elist/) ... Assign values in 'elist' to items in 'nlist.' DIMENSION Statement Category: Nonexecutable, specification Text Reference: Section 3.2.1 Format Function DIMENSION a(d) [,a(d)) ... Name array(s) 'a' dimension(s) 'd.' and define DO Statement Category: Executable Text Reference: Section 4.2.
FORTRAN-80 FORTRAN-80 Statement Summary ELSE IF Statement Category: Executable, Block IF Text Reference: 'Section 4.1.8 Format Function ELSE IF (exp) THEN Continue execution if expression 'exp' is TRUE END Statement Category: Executable Text Reference: 4.3.1 Format Function END Terminate main program; return from subprogram; mark end of program unit. END IF Statement Category: Executable, block IF Text Reference: Section 4.1.10 Format Function ENDIF Mark end of IF block; continue execution.
FORTRAN-80 Statement Summary FORTRAN-80 EQUIVALENCE Statement Category: Nonexecutable, specification Text Reference: Section 3.4.1 Function Format EQUIV ALENCE (nlist) [,(nlist)] ... Allow entities in 'nlist' to share the same storage area. EXTERNAL Statement Category: Nonexecutable, specification Text Reference: Section 5.2.6 Format Function EXTERNAL proc [,proc ] ... Allows name of external! dummy procedure to be used as an actual argument.
FORTRAN-80 FORTRAN-80 Statement Summary FUNCTION Statement Category: Nonexecutable Text Reference: Section 5.2.1 Format Function [type] FUNCTION func ([d[,d] ... J) Name the FUNCTION subprogram 'func,' define its type and dummy parameter(s) 'd.' GO TO Statements Category: Executable Text Reference: Section 4.1.1,4.1.2,4.1.3 Formats Function GOTOs GO TO (s[,s] ... )[,]exp GO TO i [[,](s[,s] ... )] Transfer control to statement labeled 's' or ASSIGNED to variable name 'i'.
FORTRAN-SO FORTRAN-80 Statement Summary IMPLICIT Statement Category: Nonexecutable, specification Text Reference: Section 3.1.5 Format Function IMPLICIT type (1[, 1] ... )[,type(1[,I] ... )] ... Define implicit typing for variable names whose first letter is '1' or in range '1,1.' INTEGER Statement Category: Nonexecutable, specification, type Text Reference: Section 3.1.2 Format Function INTEGER [* len [,]] name [,name] ... Define 'name' to be of type integer with length 'len.
F'ORTRAN-80 Statement Summary FORTRAN-80 OPEN Statement Category: Executable Text Reference: Section 6.2.1 Format Function OPEN (open-list) Open the specified file (connect file to unit).
f'ORTRAN-80 Statement Summary FORTRAN-SO PROGRAM Statement Category: Nonexecutable Text Reference: Section 2.1.2 Format Function PROGRAM name Name main program 'name;' must be first statement if used. READ Statement Category: Executable Text Reference: Section 6.3.1 Formats Function READ (ctl-list) [in list] READ f [,inlist] Input items in 'inlist' as directed by specified controls.
FORTRAN-80 FORTRAN-SO Statement Summary REWIND Statement Category: Executable Text Reference: Section 6.2.4 Formats Function REWIND unit REWIND (arg-list) Reposition file connected to 'unit' at its initial point. Notes: 'arg-list' includes the following specifiers: [UNIT =] unit lOST A T = stname ERR = stl unit specifier 110 status specifier error specifier SA VE Statement Category: Nonexecutable, specification Text Reference: Section 5.2.5 Format Function SAVE /cb / [,/cb/] ...
FORTRAN-80 Statement Summary FORTRAN-80 SUBROUTINE Statement Category: Executable Text Reference: Section 5.2.2, 5.2.3 .~ormat Function SUBROUTINE sub [([d[,d] ... ])] Define SUBROUTINE subprogram 'sub' with dummy argument(s) 'd.' WRITE Statement Category: Executable Text Reference: Section 6.3.2 Format Function WRITE (ctl-list) [outlist] Output item in 'outlist' as directed by controls in 'ctl-list.
APPENDIX B INTRINSIC FUNCTIONS I The following table lists the intrinsic (or predefined) functions available with FORTRAN-SO. An intrinsic function is executed in an expression by referencing its name followed by some argument in parentheses. If more than one argument is needed, they are separated by commas and all arguments must be of the same type. All angles are expressed in radians. C K PAY = SQRT(A **2 + B**2) = I + MOD(M, N) = BASE*40.0 + (l.5*BASE)*(AMAXI(O.O,HOURS-40.
FORTRAN-80 Intrinsic Functions TYPE OF }<'ORM FUNCTION CATEGORY SIGN (aI, a2) (note 5) Sign transfer Transfer sign of a2 to al Real Real 101M (ai, a2) Positive difference Return al-a2 if >0; otherwise 0 Integer Integer DIM (ai, a2) Positive difference Return al-a2 if >0; otherwise 0 Real Real MAXO (al, ... ,an) Laigest value Select largest value from list Integer Integer AMAXI (al, ... ,an) Largest value Select largest value from list Real Real AMAXO (al, ...
FORTRAN-SO Intrinsic Functions B.2 Notes On Intrinsic Functions I. For an integer argument, 'int(a) = a.' For a real argument, two possibilities exist. If lal < I, int(a) = 0; if lal ~ I, 'int(a)' is the integer whose magnitude is the largest Integer that does not exceed the magnitude of 'a' and whose sign is the same as the sign of 'a.' For example, int(-12.8) = -12 For an argument of type real, 'IFIX(a)' is the same as 'INT(a).' 2. For a real argument, 'REAL(a)' is 'a.
APPENDIX C HOLLERITH DATA TYPE The Hollerith data type is a carryover from FORTRAN 66. Generally speaking, the character data type provides a superior processing capability, and Hollerith has been retained in FORTRAN-80 primarily for compatibility with the earlier standard. C.1 Hollerith As A Data Type Although Hollerith is a data type, a symbolic name cannot be of type Hollerith. Hollerith data (other than Hollerith constants) are identified under the guise of an integer, real, or logical type name.
Hollerith Data Type C.3 Hollerith Format Specification A format specification may be an array name of type integer, real, or logical. In this case, the leftmost characters of the specified entity must contain Hollerith data constituting a legal format specification. Blank characters may precede the format specification and data may follow the right parenthesis ending the specification with no effect. A Hollerith format specification must not contain an apostrophe edit descriptor or an 'H' edit descriptor.
APPENDIX D EXTENSIONS TO ANSI FORTRAN This appendix lists differences between FORTRAN-80 and ANSI FORTRAN 77. Some of these are extensions to the FORTRAN 77 subset which are included in the FORTRAN 77 full language. Other extensions go beyond both versions of the ANSI standard. In two cases, the differences merely represent a tighter definition of language semantics in FORTRAN-80 than in the ANSI standard. Differences between FORTRAN-80 and 1966 ANSI FORTRAN are summarized at the end of this appendix. 0.
Extensions To ANSI Fortran FORTRAN-SO 0.3 More Specific Semantics Than 1977 FORTRAN In the following areas, the definition of FORTRAN-80 is more explicit than the ANSI standard. 1. The character set and its collating sequence include the ASCII character set. 2. The standard length for real, integer, and logical type data is four bytes, but a particular processor can allow a different default size to be specified. 0.
FORTRAN-80 Extensions To ANSI Fortran Miscellaneous extensions: Seven-dimensional arrays Unsubscripted array names in DATA and EQUIVALENCE statements Optional commas in COMMON, DO, assigned GOTO, and computed GOTO statements Character constant in a PAUSE or STOP statement BLOCK DATA subprogram names in EXTERNAL statement Integer expressions in a computed GOTO Optional label in an assigned GOTO Integer expressions in a DO statement Asterisk in column 1 to identify a comment line D-3
APPENDIX E ASCII CODES I The following table lists the ASCII characters representable on Intel processors and their collating sequence.
APPENDIX F 8080/8085 PROCESSOR DEPENDENCIES Throughout this manual, aspects of the FORTRAN language have been said to be 'processor dependent' or 'compiler dependent.' This appendix summarizes the limitations and extensions to the FORTRAN language assumed by the 8080/8085 processors and compiler. See the ISIS-II FORTRAN-80 Compiler Operator's Manual for details. F.
FORTRAN-SO SOSO/SOS5 Processor Dependencies F.2.1 Lowercase Letters Except within Hollerith and character constants, a lowercase letter is considered to be identical to its corresponding uppercase letter. F.2.2 Port Input/Output The compiler provides two intrinsic subroutines for handling input/ output through SOSO/SOS5 110 ports. When these subroutines are called, they generate SOSO IN and OUT instructions.
FORTRAN-SO SOSO/SOS5 Processor Dependencies If the FREEFORM compiler control is set, column 1 is interpreted as follows: Column 1 Meaning Cor * 0-9 Space or TAB & $ Comment line (same as standard) Label followed by statement Unlabeled initial line of statement Continuation line of statement Compiler control line Note in this format that a statement label, if present must begin in column 1. Statements can be written in columns 2-72.
SOSO/SOS5 Processor Dependencies FORTRAN-SO The included file may itself contain INCLUDE controls, up to a total of six files. An included file cannot contain an END statement, however. An INCLUDE control must be the rightmost control when specified in a list of controls. F.2.8 REel Specification For Sequential Files To simplify terminal I/O, the FORTRAN-SO compiler allows both ACCESS = 'SEQUENTIAL' and 'RECL=reclen' to be specified in the same OPEN statement.
INDEX I The page numbers shown in italics in this index denote primary references.
FORTRAN-SO Index FREEFORM Compiler Control, F-2 Functions, 2-1, 5-1 ff FUNCTION Statement, 5-4, A-7 FUNCTION Subprograms, 5-4 GO TO Statements, Assigned, 4-2, A-7 Computed, 4-1, A-7 Unconditional, 4-1, A-7 'H' Edit Descriptor, 6-19, 6-20 Hollerith Data Type, C-1 lABS Intrinsic Function, B-1 ICHAR Intrinsic Function, B-1 IDIM Intrinsic Function, B-2 'I' Edit Descriptor, 6-16, 6-17 IF Block, 4-3 IFIX Intrinsic Function, B-1 IF Statements, Arithmetic, 4-2, A-7 Block, 4-4, A-7 Logical, 4-3, A-7 IMPLICIT State
Index FORTRAN-SO Subroutines, 2-1, 5-5 SUBROUTINE Statement, 5-6, A-12 SUBROUTINE Subprograms, 5-5 Symbols, 2-4, 2-12 UNIT Run-Time Control, F-4 Units I/O, 6-1, 6-3 Program, 2-1 TANH Intrinsic Function, B-2 TAN Intrinsic Function, B-2 Type Statements, 1-2, 3-1 Variables, Definition, 2-4 Types, 2-4, 3-1 Value Assignment, 3-7 Unformatted I/O, 6-1, 6-6, 6-14 Unit Connection/Preconnection, 6-8, F-4 UNIT I/O Specifier, Input, 6-4, 6-11 Output, 6-8, 6-13 WRITE Statement, 6-13, A-12 'X' Edit Descriptor, 6-1
NOTES
NOTES
inter SOFTWARE PROBLEM REPORT SUBMITTED BY: FOR INTERNAL USE ONLY Name Company Address No. Date Notes Phone Date CHECK ONE ITEM IN EACH CATEGORY Product o Software Manual o Fix Date Vers/System Product Type Monitor Assembler Compiler o o o Machine Line o o o 0 04004/4040 0800S 08OS0 03000 0 _ _ __ Simulator Editor Utility _ _ __ System Intellec Timeshare Co.
WE'D LIKE YOUR COMMENTS ... This document is one of a lieries describing Intel products. Your comments on the back of this form will help us produce better manuals. Each reply will be carefully reviewed by the responsible person. All comments and suggestions become the property of Intel Corporation. 111111 BUSINESS REPLY CARD FIRST CLASS PERMIT NO.
FORTRAN·80 PROGRAMMING MANUAL 9800481 A REQUEST FOR READER'S COMMENTS The Microcomputer Division Technical Publications Department attempts to provide documents that meet the needs of all Intel product users. This form lets you participate directly in the documentation process. Please restrict your comments to the usability, accuracy, readability, organization, and completeness of this document. 1. Please specify by page any errors you found in this manual. 2.
:'0 LIKE YOUR COMMENTS ... is document is one of a series describing Intel software products. Your comments on the back of this m will help us produce better software and manuals. Each reply will be carefully reviewed by the responIe person. All comments and suggestions become the property of Intel Corporation. 111111 BUSINESS REPLY CARD FIRST CLASS PERMIT NO.
inter INTEL CORPORATION, 3065 Bowers Avenue, Santa Clara, California 95051 (408) 987-8080 Printed in U.S.A.