COPYRIGHT © 1981 by Technical Systems Consultants, Inc. 111 Providence Road Chapel Hill, North Carolina 27514 All Rights Reserved ™ UniFLEX is a trademark of Technical Systems Consultants, Inc. ™ FLEX is a trademark of Technical Systems Consultants, Inc. COPYRIGHT NOTICE This entire manual and documentation is provided for personal use and enjoyment by the purchaser. The entire contents have been copyrighted by Technical Systems Consultants, Inc., and reproduction by any means is prohibited. Use of this manual, or any part thereof, for any purpose other than single end use is strictly prohibited. Fortran 77 Table of Contents Page I. Introduction 1 II-A. Running the Fortran Compiler Under UniFLEX 3 II-B. Running the Fortran Compiler Under FLEX 7 III. Language Constructs 9 IV. Data Types and Constants 13 V. Arrays 15 VI. Expressions 17 VII. Specification Statements 21 VIII. DATA Statement 25 IX. Assignment Statements 27 X. Control Statements 29 XI. Input/Output Statements 33 XII. FORMAT Specification 39 XIII. Main Program 43 XIV. Functions and Subroutines 45 Appendixes A. Compilation Error Messages 49 B. Run-time Error Messages 55 C. Interfacing with External Routines 59 D. Standard Functions 61 E. Reserved Words 63 -i Fortran 77 -ii Fortran 77 1. INTRODUCTION This manual describes the use and operation of the FORTRAN compilers which run under the UniFLEX™ and FLEX™ operating systems (UniFLEX and FLEX are trademarks of Technical Systems Consultants, Inc.). FORTRAN is a high-level computer programming language. This particular system runs on the Motorola 6809 series of microcomputers. This manual describes the FORTRAN programming language features and its usage with the UniFLEX and FLEX operating systems. No attempt is made in this manual to teach programming in FORTRAN; rather, the manual describes in detail the FORTRAN language and any details specific to its use with the operating system. Fortran 77 requires the relocating assembler and linkage editor package in order to compile and execute Fortran programs. The user should obtain and be familiar with these products before using the Fortran system. Technical Systems Consultants' Fortran conforms to ANSI FORTRAN-77 (ANSI X3.9-1978) subset of the FORTRAN language, with the following exceptions: The INTRINSIC and SAVE statements are ignored. The EQUIVALENCE statement is not implemented. The BACKSPACE statement is only allowed an direct access The ENDFILE statement performs no useful function. Statement functions are not supported. Variable names may be of any length with 7 characters significant. All keywords (see appendix E) are reserved in all contexts and must not be used as identifiers. Direct access files are not available under FLEX. In addition, Technical Systems Consultants' Fortran contains some features of the full FORTRAN language, most notably list-directed I/O and expanded form of the OPEN statement. Some notation is used throughout this document which should be explained here. Uppercase words are keywords and must be used exactly as they appear, although they may be spelled in either case. Lowercase words stand for some object defined by the user, either an identifier or expression, etc. Items enclosed within the characters "<" and ">" stand for some concept described in the surrounding text. Items enclosed within square brackets, "[" and "]", indicate an optional item which may or may not be present, depending on the user's wishes. The ellipsis, "...", is used to indicate that a given item may be repeated and when it follows an optional item; that item may occur zero or more times. E.g. the description: SUBROUTINE sub [(parm [, parm]... )] allows any of the following statements: SUBROUTINE sub1 SUBROUTINE sub2(parm1) SUBROUTINE sub3(parm2, parm3) SUBROUTINE sub4(parm4, parm5, parm6) -1 Fortran 77 -2 Fortran 77 11-A. Running the Fortran Compiler Under UniFLEX The purpose of running the Fortran compiler is to take a program which is written in the FORTRAN programming language and produce a program which can be executed by the 6809 processor. This process involves many steps, most of which are automatic. The steps involved are: 1. Scan the FORTRAN source program and produce an assembly language file which corresponds to that program. 2. Assemble this file, creating a relocatable binary program. 3. Use the linkage editor to link this program with the FORTRAN run-time library, creating an executable program. Steps 2 and 3 are optional and in no case will they be executed if your program contains errors. The Command Line The syntax of the command to execute the Fortran compiler is: ++ f77 file ... [+options] The plus signs are UniFLEX's prompt, "f77' is the name of the Fortran compiler. One or more input files may be specified, given by "file...".. If more than one file is specified, the result is the same as if all the files were appended in the order given. The options may appear anywhere on the command line and are any combination of the following: a - Save the assembly language output file. This option will inhibit the compiler from automatically calling the assembler and linkage editor. b - Suppress the creation of an assembly file. If this option is specified, the compiler will go through all the actions necessary to compile the given programs, but will produce no executable output. c - Suppress calling the linkage editor. The compiler will create and assemble an assembly file and the resulting relocatable output file will be preserved. This is useful if the source files do not comprise a complete program and the linking process should be postponed. d - Instructs the compiler to place additional code in the assembly language output file for debugging purposes. Primarily, this information will provide a post-mortem dump of all active variables in the program if it aborts for any reason. This option also implies the +t and +n options. l - List the source program. If not specified, only those lines which are in error will be listed. -3 Fortran 77 n - Keep track of the exact execution line number. This option will make the compiled program somewhat larger, but if a fatal error occurs, the systen will be able to indicate exactly the last line executed in the program. This option automatically implies the +t option. o - Specify the final output file. Normally, the Fortran compiler will create the final (executable program with a name which is derived from the first source file name (see below). If this is undesirable, the user may specify the output name directly by using +o=XXX, where XXX is the desired output file name. s - Print smumary information at the end of each module compiled. This option lists such information as thie time and size of each variable in the program, external programs which were called by this program segment, etc. t - Keep information about the execution of the program and print an execution trace-back if a fatal error occurs. If the +n option (above) is not on, this will simply print the subroutines and functions which are active in the current program in reverse order. If the +n option is also on, the current line being executed in each program unit will be listed. x - Generate shared text output from the linkage editor. Normally, Fortran will generate a "no-text" output file but this option allows those users who wish to do so to generate shared text Source file names for Fortran programs must be of the form: XXXX.f The ".f" is REQUIRED! This file name is used to create all internal files used by the compiler system as follows Source file: XXXX.f Assembly file: XXXX.a Relocatable object: XXXX.r Executable output: XXXX Literals: XXXX.s The "Literals" file is a temporary file used by the Fortran compiler. It is automatically deleted by the compiler when the compilation is complete and as such, users should refrain from naming files "XXXY.s". If more than one input file is specified, the first file name given is used to form these file names. The user has the ability, via the +c option, to specify the file name of the executable output file, but all others are given implicitly as above. -4 Fortran 77 Examples: The simplest example is one which compiles a Fortran program which is complete in one file, producing an executable file. An example of this would be: ++ f77 main.f This command instructs the Fortran compiler to compile the program "main.f", then call the assembler and linkage editor to produce an executable program. Nothing except error messages will be printed on the standard output. The command line: ++ f77 main.f +ls would be the same as the previous one, except that a listing of the program along with some summary information about each module within the program would be printed. Again, this command would create an executable program called "main". Suppose you had a program which was contained in the files "program1.f", "program2.f", "program3.f" and "program4.f". The command line: ++ f77 program[1-4].f +o=program would compile the files "program1.f", "program2.f", "program3.f" and "program4.f" in that order and create an executable program called "program". Programs may be broken into modules and compiled together as in the example above, or they may be compiled separately, each creating its own binary file. In this case, the linkage editor must be invoked by the user to create an executable program from the pieces. An example of this would be: ++ f77 program1.f +c ++ f77 program2.f +c ++ f77 program3.f +c ++ f77 program4.f +c ++ link-edit program[1-4l.r +l=F77.runlib +no=progran This sequence of commands would compile each of the modules separately and create a binary file for each one. This set of binary files would then be combined using the linkage editor to create an executable program. This example produces a program which is identical to the one produced by the example above. Fortran programs may call external routines which have been written in another language, such as assembly language. The details of this mechanism are explained fully in Appendix C. Whenever this is done, the user is responsible for linking the modules together to create the executable program. An example of this might be when the user wishes to write his own random number function. Let us assume that he has done so and that the object file for this function is in the file "rnd.r". Now assume that the user's program is the same as above except that we wish to include this random number function instead of the library function. This could be accomplished by the commands: ++ f77 program[1-4].f +c ++ link-edit program[1-4].r rnd.r +l=F77.runlib +to=program -5 Fortran 77 -6 Fortran 77 11-B. RUNNING THE COMPILER UNDER FLEX In order to execute the Fortran compiler under the FLEX operating system, a source file must exist on a disk. This file may then be compiled, using the Fortran compiler, into an assembly language program. This assembly language program must then be assembled and linked with the Fortran runtime library, using the relocating assembler and linkage editor, respectively. The command used to invoke the Fortran compiler is: +++ F77 [+options] The is the name of the Fortran program which is to be compiled. It is assumed that this file ends with the extension ".TXT", but this may be overidden by specifying any other extension. The Fortran compiler uses several files based on the source file name, as follows: XXXX.TXT - Source file XXXX.LIT - Temporary file XXXX.ASM - Assembly language output file The file "XXXX.LIT" is used Internally by the Fortran compiler and will be deleted after the program has been compiled. Because of this, it is advised that the user refrain from naming programs "XXXX.LIT". The options mentioned above are the same as the options available under UniFLEX, as described in the previous section. The options "a", "c" and "x" are not available under FLEX. Installation Procedure The following files must be on the "system" disk when the Fortran 77 compiler is executed. These files may be copied from the master disk to your normal system disk, or alternatively, they may be copied to a separate disk used only for the Fortran system. Needed at Compile Time Needed at Assembly/Link Edit Time ====================== ================================= F77.CMD RELASMB.CMD LLOAD.CMD SYMBOLS.F77 F77.LIB (*) ERRORS.F77 RUNLIS.F77 (*) The files marked with an asterisk (*) must reside on the "work" disk, not on the 'system" disk. In order to run a Fortran program, a mutli-step process must take place. First, the program must be compiled. This step takes a Fortran source program and produces a relocatable assembly language source file as output. The second step is to use the relocating assembler to assemble this file. This produces a relocatable object module. The last step is to use the linkage-editor to link all the desired object modules together, along with the Fortran runtime package, and produce an executable program. The following statements give a schema for this process: -7 Fortran 77 +++ F77 file +++ RELASMB file.ASM +sluy +++ LLOAD file.REL +l.RUNLIB.F77 +o=file.CMD +a=0 In the schema above, "file" represents the name of the Fortran program being compiled. This schema assures that the entire Fortran program is composed of a single source file. If this is not the case, the first two steps may be repeated as many times as necessary to compile and assemble each of the modules of the program. The last line would then be extended to: +++ LLOAD file-1.REL ... file-n.REL +l=RUNLIB.F77 +o-file.REL +a=0 In this schema, "file-1.REL" stands for the first object module of the program, 'file-2.REL" would be the second, and so on until "file-n.REL" which would be the last module of the program. Refer to the Relocating Assembler and Linkage Editor manual for more details on how to run these programs. One thing to note is that in order to obtain an executable Fortran program, the "+a" option must be used with the link editor. Also, Fortran programs must be assembled using the "+u" option of RELASMB. We have provided a test program on the Fortran master disk. The following are the commands necessary to compile and execute this test program. +++ F77 svtest +l +++ RELASMB svtest.ASM +sluy +++ LLOAD svtest.REL +l=RUNLIB.F77 +o=svtest.CMD +a=0 +++ svtest -8 Fortran 77 111. LANGUAGE CONSTRUCTS This chapter describes the basic components of a FORTRAN program. A FORTRAN program is composed of one or more program units. Each of these units may be compiled separately, using the +c option, or they may all be compiled together at one time. The advantage of separate compilation is that if only a subset of the total modules (or units the terms are interchangable) changes, only those modules which have changed need be re-compiled. However, for simple programs, the advantage of single compilation is that the entire program can be compiled and loaded in one single command, producing an executable program. (Under FLEX, the user is responsible for assembling and linking the resulting modules together to form an executable program). A program unit is either a MAIN program, a SUBROUTINE or a FUNCTION. The details of each of these units are described in later chapters. Note that a program must contain exactly one MAIN program and may contain one or more SUBROUTINEs or FUNCTIONs. Each program unit is composed of records. A record In this case may be one or more lines. A line is a sequence of characters, terminated by a carriage return. If the information for a given record will not fit on one line, the record may be continued to another line. A single record may contain up to 10 lines. Each line has fields which have special meanings. Columns 1 through 5 comprise the label field. Column 6 is the continuation-marker field. Columns 7-72 are the text field. For any given record, the first line may contain a value in the label field. This value must be a non-zero, unsigned integer. If the label field does not contain a label, this field must be completely blank. If a record is to contain more than one line, all lines except the first must be marked as "Continuation" lines. This is done by placing a non-blank character in column 6. Any line which contains a non-blank character in column 6 is assumed to be a continuation of the previous line. Columns 7 through 72 of all lines in every record comprise the text portion of the record and contain all program elements except record labels, as described above. For the user's convenience, the horizontal tab character may be used to simplify the typing of FORTRAN programs. If a tab character appears, in any column of a line before column 7, the tab character is replaced by sufficient spaces so that the following character is in column 7. If the tab character appears after column 7, it is replaced by a blank. There is one exception to this rule: If the character immediately following the tab is the asterisk character '*', then the tab is really a tab to column 6 and the asterisk is placed in the continuation field of the line. The tab feature is not available under FLEX. -9 Fortran 77 Any line which begins with any of the characters 'c', 'C', or '*' in column 1 is a comment line. Comment lines are totally ignored by the compiler and are only for use by humans. Also, comment lines are never part of a record and may not appear between continuation lines. A line with no characters other than the carriage return is also considered a comment line. Programs are made up of symbols, some of which are: Keywords and identifiers Special symbols Character strings Numbers Each of these symbols has specific syntax or construction rules. They will be explained in the sections below: Keywords and Identifiers These symbols are the words which are used to write a Fortran program. They must begin with a letter and may contain any number of letters or digits following the initial letter. Both upper and lower case letters are acceptable, but upper case will be implicitly mapped to lower case by the compiler. Thus the identifier "IDENT" is the same identifier is "ident". Although identifiers may be of any length in the program, only the first 7 characters are significant. Keywords must be spelled completely, with all characters significant. Special symbols There are some special symbols in a Fortran program. These are used in arithmetic expressions and as punctuation. They will be described in more detail in the sections which deal with these subjects. Notice that they must always be written exactly as they appear in this document. E.g. the symbol "**" is not the same as "* *". Character strings A character string is any sequence of characters, enclosed in single quotes. If a character string extends past column 72, then it is assumed that the line is continued and the first character of the next line in the record follows the character in column 72. It is not advisable to continue character strings in this fashion unless absolutely necessary. If it is desired to have the character string contain the single quote character itself, the quote must appear twice consecutively. Thus the string 'ab''cd' stands for the string "ab'cd". Numbers A number is a symbol which represents some numeric quantity. These quantities come in two varieties, integer numbers and real numbers. An integer is what is normally called a "whole" number. The numbers 1, 23, -256, are all integers. A real number is a number which may contain a fractional part. Real numbers are not the same as integers, even if they contain the same value. Some real numbers would be 3.14159. 6.02e+23 and 0.0. Notice that 0.0 is a real number but 0 is an integer. A number is an optional sign character ('-' or '+'), followed by a string of digits, optionally -10 Fortran 77 followed by a decimal point followed by another string of digits, optionally followed by an exponent which is written as the letter 'e' followed by a signed integer. Any number which contains a fractional part or an exponent is considered to be a real number. The Fortran standard defines that a FORTRAN program which has had all blanks removed (except from character strings and FORMAT statements) is equivalent to the same program with the blanks in it. This implementation uses blanks as separators and thus differs from the standard in this point. This is only significant in the fact that basic symbols (as described in the section above) may not contain blanks as would be allowed by the standard. Where there are keyword sequences which may include blanks, this implementation allows either spelling. E.g. "GO TO" is the same as "GOTO", but "ID ENT" is not the same as 'IDENT". -11 Fortran 77 -12 Fortran 77 IV. DATA TYPES AND CONSTANTS There are four types of data in FORTRAN programs. These are: Integer Real Logical Character Each type is different and is used to represent different types of data. Integers are whole numbers; 0, 1, 2, ... Reals are numbers which may or may not contain fractional parts; 0.0, 3.14, -2.65, ... Logical values are the values .TRUE. or .FALSE. These values indicate a "truth" value of either true or false. Character data are strings of characters, built from the ASCII character set. Any printable character is allowed as an element of a character string. Symbolic names (or identifiers) in a FORTRAN program have an implicit type associated with them. This type is based on the first character of the identifier. It may be overidden by the use of a "type" declaration as discussed in chapter VII. If not overidden, any identifier which begins with the character 'I' through the character 'N' is considered to be an integer. All other identifiers are considered to be reals. These implicit type definitions way also be changed by using the IMPLICIT statement as discussed in chapter VII. FORTRAN programs may contain explicit constant values of the various types. These constants are written using the rules described in the previous chapter. The logical constants are written as ".TRUE." and ".FALSE.". -13 Fortran 77 -14 Fortran 77 V. ARRAYS An array is a nonempty sequence of data. An array element is one member of this sequence. An array name is the symbolic name of the entire array. An array element name is an array name qualified by a subscript. Arrays are used to organize related data into an easily managed form. Any particular item from the set of data may be changed or used by simply indicating which item within the set it is. An array is declared using an array declarator most any place a normal variable may be declared. For more information, see chapter VII on declarations. The form of an array declarator is: a(d [.d]...) where: a is the array name. d is a dimension declarator which is of the form [b1:]b2 where b1 and b2 are integer expressions. If b1 is not present, the array will have elements which are numbered from 1 to b2, inclusive. If b1 is present, it must be less than b2 and the array will have elements which are numbered from bl up to b2, inclusive. An array declarator may contain one, two or three dimensions. If the array is being declared as a dummy array used as a parameter in a subprogram, then the array bounds may be declared using an '*' in place of a constant expression. This is because the actual bounds are not needed in the declaration of an array passed as a parameter. An array declarator declares a collection of data items which are accessed by a common mechanism. This mechanism is known as array indexing. The general form of an array index expression (also refered to as an array subscripting expression) is: a(e [. e]...) where: a is the array name. e is an Integer expression. The effect of array indexing is to select a particular element of the array for use. An array element, given by a subscripted expression, is equivalent to a single simple variable. Arrays are represented in the computer memory in an organized fashion, with the separate array elements in a specific order. For one dimensional arrays, this ordering is simple. Array element i "follows" element i-1 and "precedes" element i+l. For multiple dimensional arrays, the first dimension "varies most rapidly". That is, element (i, j) "follows" element (i-1, j) and "precedes" element (i+1, j). Array element (n, j) is "followed" by element (m, j+1), if "n" and "m" are the upper and lower bounds for the first dimension, respectively. For a three dimensional array, the process is similar. -15 Fortran 77 -16 Fortran 77 VI. EXPRESSIONS This chapter describes the formation, interpretation and evaluation rules for expressions. An expression may be any one of arithmetic, relational or logical expressions. Expressions are formed from operands, operators and parentheses. Arithmetic Expressions An arithnetic expression is made up of combinations of the following: Arithmetic Primary Arithmetic Factor Arithmetic Term Arithmetic Expression Each of these components will be described below: Arithmetic Primary A primary is one of: Unsigned numeric constant Arithmetic variable reference Arithmetic array element reference Arithmetic function reference Arithmetic expression enclosed in parentheses Arithmetic Factor A factor is formed as: Primary Primary ** Factor Arithmetic Term A term is formed as: Factor Term / Factor Term * Factor Arithmetic Expression An arithmetic expression is formed as: Term + Term -Term Arithmetic expression + Term Arithmetic expression - Term For arithmetic expressions, the operands must always be either of integer or real type. The operators described above are not defined on any other types. -17 Fortran 77 The operators mentioned above have the following meanings: Operation Meaning + y x + y - y x - y x * y x / y x** y Same as y Add x to y Negate y Subtract y from x Multiply x by y Divide x by y Exponentiate x to the power y where: x denotes the operand to the left of the operator y denotes the operand to the right of the operator Evaluation of a given operator is described in the tables below: Type and Interpretation of x + y xy Integer Real Integer i = x + y r = float(x) + y Real r = x + float(y) r = x + y Type and Interpretation for x ** y x y Integer Real Integer i = x ** y r = float(x) ** y Real r = x ** y r = x ** y In the tables above, 'i =' indicates that the result is of type integer and 'r =' indicates that the type is real. Logical Expressions A logical expression is one which yields a truth value, either .TRUE. or .FALSE. A logical expression may be made up of relational expressions or logical variables or constants, or combinations of logical expressions. Logical expressions are combined using the logical operators: .AND. Logical conjunction .OR. Logical disjunction .NOT. Logical negation Thus a logical expression has the fortn: [ ]... The logical operators have the following interpretation: .NOT. This is a unary operator. The value of .NOT. is the inverse of the value of . Thus .NOT. .FALSE. is .TRUE. and .NOT. .TRUE. is .FALSE. The operator .NOT. has the highest precedence of the logical operators. .AND. This is a binary operator between two logical expressions. Its meaning is: if both expressions have the value .TRUE., the expression has the value .TRUE. If either expression has the value -18 Fortran 77 .FALSE., the expression has the value .FALSE. The logical operator .AND. is higher in priority than the operator .OR. .OR. This is a binary operator between two logical expressions. Its meaning is: if both expressions have the value .FALSE., then the expression is .FALSE. If either expression has the value .TRUE., then the expression has the value .TRUE. Relational Expressions Relational expressions are used to compare two expressions and determine a logical value based on their relation. The two expressions must be of the same type, or be coercible to the same type. The result of a relational expression is always a logical value. Relational expressions use the relational operators: .EQ. Equal to .LT. Less than .GT. Greater than .NE. Not equal to .LE. Less than or equal to .GE. Greater than or equal to A relational expression is then: The meaning of this expression is: if the is in the given relation to the then the relational expression has the value .TRUE., otherwise it will have the value .FALSE. A relational expression may be used any place a logical value is permissible, except in a DATA statement. Precedence of Operators and Order of Evalutation In the sections above, the various operators within the given types of expressions were discussed. The following section describes the precedence relations between different types of expressions. These precedence relations are based on the following rules, in order. Parenthesized expressions Precedence of operators Right-to-left interpretation of exponentiations in a factor. Left-to-right interpretation of multiplications and divisions in a term. left-to-right interpretation of additions and subtractions in an arithmetic expression. Left-to-right interpretation of conjunctions in a logical term. Left-to-right interpretation of disjunctions in a logical expression. As indicated above, parentheses may be used to alter this evaluation ordering since they are of the absolute highest precedence. For example, using the rules above, the expression: a + b * c - d is interpreted as: (a + (b * c)) -d -19 Fortran 77 -20 Fortran 77 VII. SPECIFICATION STATEMENTS There are five kinds of specification statements: DIMENSION COMMON INTEGER, REAL, LOGICAL, and CHARACTER type statements IMPLICIT EXTERNAL Additionally, the specification statements:. INTRINSIC SAVE are allowed, but are ignored. Currently, the EQUIVALENCE statement is not supported. All specification statements are non-executable and must appear before any executable statements or DATA statements within a program unit. DIMENSION Statement A DIMENSION statement is used to specify the symbolic names and dimension specifications of arrays. The form of a DIMENSION statement is: DIMENSION a(d) [, a(d)]... where each "a(d)" is an array declarator of the form: a([l]:u [,[l:]u]... ) where "l" specifies the lower bound for a given dimension and "u" is the upper bound for that dimension. If "l" is not present, "l" is assumed. Refer to chapter V for a complete discussion of arrays. Each symbolic name appearing in a DIMENSION statement declares "a" to be an array in that program unit. Note that array declarators may appear in COMMON statements and type-statements as well. Only one appearance of a name in an array declarator is permitted in a given program unit. Examples: DIMENSION a(100), b(0:99) COMMON Statement The COMMON statement provides a means of associating entitles in different program units. This allows different program units to share the same data without using parameters. The form of a COMMON statement is: COMMON [/[cb]/] nlist [[,]/[cb]/nlist]... where: cb is a common block name. This name has no meaning within a program unit other than to name the common block and cannot be used in any other fashion. Common block names are significant to only 6 characters. nlist is a list of variable names, array names, and array declarators. Only one appearance of a given name may appear within all the common lists within a program unit. Variable names which are also parameters or function names must not appear within the list. -21 Fortran 77 If "cb" is not present, the common block is part of the "blank common" block. For each COMMON statement, the variables in the list "nlist" are declared to be part of the common block "cb". The common block "cb" may be referenced by more than one COMMON statement, in which case, the list of variables is simply appended to the list of variables already associated with that common block. When two separate program units contain a COMMON statement with the same common block name, "cb", the variables in each program unit defined within that common block will share the same address space. This is not true of variables not in common, as each variable in each program unit has its own address space, regardless of its name. Examples: COMMON /com1/ a, b(10), c COMMON // d INTEGER, REAL, LOGICAL and CHARACTER Type Statements These statements are used to declare variables and associate a "type" with them. The form of the type-statement is: v [, v]... where: is one of INTEGER, REAL, LOGICAL or CHARACTER. v is a variable name, array name, array declarator, function name or dummy procedure name. Examples: INTEGER x1, abcdef, x2. REAL zz, iz CHARACTER*10 name LOGICAL flags(0:8190) IMPLICIT Statement The IMPLICIT statement allows the programmer to override the default implied types for variables. Normally, all variables which begin with the letters I-N are considered to be of type Integer and all other variables are considered to be of type Real. If it is desired to have these implied types be something else, the IMPLICIT statement allows the programmer to specify this. The form of the IMPLICIT statement is: IMPLICIT type (a [, a]... ) [type(a C, a]... )]... where: type is one of INTEGER, REAL, LOGICAL, or CHARACTER[*len]. a is either a single letter or a range of single letters in alphabetical order. A range is indicated by the first and last letter of the range, separated by a minus sign. This is equivalent to writing every character within the range separately. -22 Fortran 77 WARNING! The IMPLICIT statement will cause all identifiers which are not explicitly declared to be implicitly declared as specified in the IMPLICIT statement. This includes built-in functions such as SQRT, ATAN, etc. The user is advised to take care when using built-in functions in programs which make use of the IMPLICIT statement. len is the [optional] length specification for entities of type CHARACTER. If 'len' is not specified, the length is one. The IMPLICIT statement affects all variable declarations which do not explicitly declare a type for a given item. An IMPLICIT statement only applies to the program unit which contains it. Examples: IMPLICIT INTEGER(a-z) IMPLICIT CHARACTER*4 (c, f-i, z) EXTERNAL Statement The EXTERNAL statement is used to identify a symbolic name as the name of an external procedure or dummy procedure, and to permit such a name as an argument. The form of an EXTERNAL statement is: EXTERNAL proc [, proc]... -23 Fortran 77 -24 Fortran 77 VIII. DATA STATEMENT The DATA statement is used to specify initial values for variables at compilation time. A DATA statement is not executable and must appear after any specification statements and before any executable statements in a given program unit. The form of a DATA statement is: DATA nlist /clist/ [[,] nlist /clist/]... where: nlist is a list of variable names, array names, and array element names. clist is a list of the form: a [, a]... where "a" is one of the forms: c r*c c is a constant r is an unsigned integer constant. The "r*c' form is equivalent to "r" successive appearances of the constant "c". Names of parameters, functions and entities in COMMON must not be specified in the variable list. There must be the same number of items specified in the data list "clist" as in the variable list "nlist". There is a one-to-one correspondence between elements of "nlist" and elements of the "clist". Specifying the name of an array in the list is equivalent to specifying each element of the array, with the first dimension being varied most rapidly. Also, if any elements of an array are specified. they must be given in ascending order. That is, the array element A(10) must not appear before the array element A(1). The type of the element in the nlist and the corresponding element in the clist must be the same. A variable or array element must not appear more than once in a DATA statement in a given program unit. Character constants need not have the same length as the element they are meant to initialize. In this case, they will be padded or truncated on the right as needed. Examples: INTEGER a(10) DATA a/1, 2, 8*0/ CHARACTER*10 lines(5) DATA lines(1)/'line 1'/, line(5)/'*Full line'/ -25 Fortran 77 -26 Fortran 77 IX. ASSIGNMENT STATEMENTS There are four distinct forms of assignment in FORTRAN: Arithmetic Assignment Logical Assignment Statement label Assignment Character Assignment Arithmetic Assignment This statement assigns the value of an arithmetic expression to a given variable. The format of this statement is: = This statement is executed by first evaluating the expression and then assigning the result value to the variable which appears to the left of the "-". If the expression and variable have different types, the expression is automatically converted to the same type as the variable before the assignment takes place. The following table outlines legal combinations of variables and expressions and the conversions which take place. The rows in the table correspond to the type of the in the assignment and the columns correspond to the . Integer RealRealInteger FLOAT(e) Assign AssignIFIX(e) Any other combination of types is illegal. Logical Assignment This statement assigns the value of a logical expression to a given variable. It has the same syntax as the arithmetic assignment, except that the variable must be of type logical. Character Assignment This statement assigns the value of a character expression (character variable or literal string) to a given variable. The syntax of the statement is the same as the arithmetic assignment statement. If the variable and the expression have the same length, then this statement simply assigns the expression to the variable. If the variable is shorter than the given expression, the expression is truncated on the right before assignment. That is, only the leftmost "w" characters from the expression are copied into a variable which is of length "w". If the variable is longer than the expression, the expression will be padded on the right with spaces to the length of the variable. ASSIGN Statement and GOTOs: The fourth form of assignment is the operation of assigning a label to a variable. This variable may then be used in a GOTO statement. This statement has the form: ASSIGN