Digital PDFs
Documents
Guest
Register
Log In
AA-4158B-TM
May 1977
294 pages
Original
11MB
view
download
Document:
FORTRAN-20 Reference Manual Ver 5 Apr77
Order Number:
AA-4158B-TM
Revision:
0
Pages:
294
Original Filename:
AA-4158B-TM_FORTRAN-20_Reference_Manual_Ver_5_Apr77.pdf
OCR Text
FORTRAN Reference Manual Order No. AA-4158B-TM April 1977 This document describes the language elements of the FORTRAN-20 compiler for the DECSYSTEM-20. This document supersedes the document of the same name, Order No. DEC-20-LFMRA-A-D, . published January 1976. OPERATING SYSTEM AND VERSION: Any Digital-supported operating system for the DECSYSTEM-20. SOFTWARE VERSION: FORTRAN-20, Version 5 To order additional copies of this document, contact the Software Distribution Center, Digital Equipment Corporation, Maynard, Massachusetts 01754 diaital eauioment corcoration · maunard, massachusetts ......, .. . ......., First Printing, January 1976 Revised: April 1977 The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document. The software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license. Digital Equipment Corporation assumes no responsibility for the use or reliability of its software on equipment that is not supplied by DIGITAL. Copyright © 1976, 1977 by Digi tal Equipment Corporation The postage prepaid READER'S COMMENTS form on the last page of this document requests the user's critical evaluation to assist us in preparing future documentation. The following are trademarks of Digital Equipment Corporation: DIGITAL DEC PDP DECUS UNIBUS COMPUTER LABS COMTEX DDT DECCOMM DECsystem-10 DEC tape DIBOL EDUSYSTEM FLIP CHIP FOCAL INDAC LAB-8 DECsystem-20 MASSBUS OMNIBUS OS/8 PHA RSTS RSX TYPESET-8 TYPESET-10 TYPESET-II 5/77-15 CONTENTS Page CHAPTER CHAPTER 1 PROLOGUE 1-1 1.1 BACKGROUND 1-1 2 CHARACTERS AND LINES 2-1 2.1 2.2 2.2.1 CHARACTER SET STATEMENT, DEFINITION, AND FORMAT Statement Label Field and Statement Numbers Line Continuation Field Statement Field Remarks LINE TYPES Initial and Continuation Line Types Multi-Statement Lines Comment Lines and Remarks Debug Lines Blank Lines Line-Sequenced Input ORDERING OF STATEMENTS 2-1 2-2 2.2.2 2.2.3 2.2.4 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.4 CHAPTER CHAPTER 2-3 2-3 2-3 2-4 2-4 2-4 2-5 2-5 2-6 2-6 2-6 2-7 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3-1 3.1 3.2 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.3 3.4 3.5 3.5.1 3.5.2 3.5.3 DATA TYPES CONSTANTS Integer Constants Real Constants Double-Precision Constants Complex Constants Octal Constants Logical Constants Literal Constants Statement Label Constants SYMBOLIC NAMES VARIABLES ARRAYS Array Element Subscripts Dimensioning Arrays Order of Stored Array Elements 3-1 3-2 3-2 3-2 3-3 3-3 3-4 3-5 3-5 3-6 3-6 3-7 3-7 3-8 3-9 3-10 4 EXPRESSIONS 4-1 4.1 4.1.1 ARITHMETIC EXPRESSIONS Rules for Writing Arithmetic Expressions LOGICAL EXPRESSIONS Relational Expressions EVALUATION OF EXPRESSIONS Parenthesized Subexpressions 4-1 3 4.2 4.2.1 4.3 4.3.1 iii 4-2 4-4 4_-7 4-9 4-9 CONTENTS (CONT.) Page 4.3.2 4.3.3 4.3.4 CHAPTER Hierarchy of Operators Mixed Mode Expression Use of Logical Operands in Mixed Mode Expressions 4-9 4-10 5 COMPILATION CONTROL STATEMENTS 5-1 5.1 5.3 5.4 INTRODUCTION PROGRAM STATEMENT INCLUDE STATEMENT END STATEMENT 5-1 5-1 5-1 5-1 6 SPECIFICATION STATEMENTS 6-1 6.1 6-1 6-1 6.8 INTRODUCTION DIMENSION STATEMENT Adjustable Dimensions TYPE SPECIFICATION STATEMENTS IMPLICIT STATEMENTS COMMON STATEMENTS Dimensioning Arrays in COMMON Statements EQUIVALENCE STATEMENT EXTERNAL STATEMENT PARAMETER STATEMENT 7 DATA STATEMENT 7-1 7.1 INTRODUCTION 7-1 8 ASSIGNMENT STATEMENTS 8-1 8.1 INTRODUCTION ARITHMETIC ASSIGNMENT STATEMENTS LOGICAL ASSIGNMENT STATEMENTS ASSIGN (STATEMENT LABEL) ASSIGNMENT STATEMENT 8-1 8-1 8-4 9 CONTROL STATEMENTS 9-1 9.1 9.2 9.2.1 9.2.2 9.2.3 9.3 9.3.1 9.3.2 9.3.3 9.4 9.4.1 9.4.2 9.4.3 9.5 9.6 9.7 9.7.1 INTRODUCTION GO TO CONTROL STATEMENTS Unconditional GO TO Statements Computed GO TO Statements Assigned GO TO Statements IF STATEMENTS Arithmetic IF Statements Logical IF Statements Logical Two-Branch IF Statements DO STATEMENT Nested DO Statements Extended Range Permitted Transfer Operations CONTINUE STATEMENT STOP STATEMENT PAUSE STATEMENT T (TRACE) Option 9-1 9-1 9-1 9-2 9-2 9-3 9-3 9-4 9-4 9-5 9-6 9-8 9-9 9-10 9-10 9-11 9-12 5.2 CHAPTER 6.2 6.2.1 6.3 6.4 6.5 6.5.1 6.6 6.7 CHAPTER CHAPTER 8.2 8.3 8.4 CHAPTER iv 4-11 6-2 6-3 6-5 6-5 6-7 6-7 6-8 6-9 8-4 CONTENTS (CONT.) Page CHAPTER 10 I/O STATEMENTS 10-1 10.1 10.2 10.2.1 10.2.2 10.2.3 10.3 DATA TRANSFER OPERATIONS TRANSFER MODES Sequential Mode Random Access Mode Append Mode I/O STATEMENTS, BASIC FORMATS AND COMPONENTS 10.3.1 I/O Statement Keywords 10.3.2 FORTRAN Logical unit Numbers 10.3.3 FORMAT Statement References 10.3.4 I/O List 10.3.4.1 Implied DO Constructs 10.3.4.2 Formatted Record Handling 10.3.5 The Specification of Records for Random Access 10.3.6 List-Directed I/O NAMELIST I/O Lists 10.3.7 10.4 OPTIONAL READ/WRITE ERROR EXIT AND END-OF-FILE ARGUMENTS READ STATEMENTS 10.5 10.5.1 Sequential Formatted READ Transfers 10.5.2 Sequential Unformatted Binary READ Transfers 10.5.3 Sequential List-Directed READ Transfers 10.5.4 Sequential NAMELIST-Contro11ed READ Transfers 10.5.5 Random Access Formatted READ Transfers 10.5.6 Random Access Unformatted READ Transfers 10.6 SUMMARY OF READ STATEMENTS 10.7 REREAD STATEMENT WRITE STATEMENTS 10.8 10.8.1 Sequential Formatted WRITE Transfers 10.8.2 Sequential Unformatted Binary WRITE Transfer 10.8.3 Sequential List-Directed WRITE Transfers 10.8.4 Sequential NAMELIST-Contro11ed WRITE Transfers 10.8.5 Random Access Formatted WRITE Transfers 10.8.6 Random Access Unformatted WRITE Transfers 10.9 SUMMARY OF WRITE STATEMENTS 10.10 ACCEPT STATEMENT 10.10.1 Formatted ACCEPT Transfers ACCEPT Transfers Into FORMAT Statements 10.10.2 10.11 PRINT STATEMENT 10.12 TYPE STATEMENT 10.13 FIND STATEMENT 10.14 ENCODE AND DECODE STATEMENTS 10.14.1 ENCODE Statement 10.14.2 DECODE Statement 10.14.3 Example of ENCODE/DECODE Operations 10.15 SUMMARY OF I/O STATEMENTS v 10-1 10-1 10-1 10-1 10-2 10-2 10-3 10-3 10-3 10-6 10-6 10-7 10-7 10-8 10-10 10-10 10-11 10-11 10-12 10-12 10-13 10-13 10-13 10-14 10-14 10-16 10-16 10-16 10-17 10-17 10-17 10-17 10-18 10-18 10-18 10-19 10-19 10-20 10-21 10-21 10-22 10-22 10-23 10-24 CONTENTS (CONT.) Page CHAPTER CHAPTER CHAPTER 11 NAMELIST STATEMENTS 11-1 11.1 11.2 11.2.1 11.2.2 INTRODUCTION NAMELIST STATEMENT NAMELIST-Controlled Input Transfers NAMELIST-Controlled Output Transfers 11-1 11-1 11-2 11-3 12 FILE CONTROL STATEMENTS 12-1 12.1 12.2 12.2.1 12.2.2 INTRODUCTION OPEN AND CLOSE STATEMENTS Options for OPEN and CLOSE Statements Summary of OPEN/CLOSE Statement Options 12-1 12-1 12-2 12-10 13 FORMAT STATEMENT 13-1 13.1 13.1.1 13.2 13.2.1 13.2.2 INTRODUCTION FORMAT Statement, General Form FORMAT DESCRIPTORS Numeric Field Descriptors Interaction of Field Descriptors With I/O Variables G, General Numeric Conversion Code Numeric Fields with Scale Factors Logical Field Descriptors Variable Numeric Field widths Alphanumeric Field Descriptors Transferring Alphanumeric Data Mixed Numeric and Alphanumeric Fields Multiple Record Specifications Record Formatting Field Descriptors $ Format Descriptor CARRIAGE CONTROL CHARACTERS FOR PRINTING ASCII RECORDS 13-1 13-1 13-2 13-4 14 DEVICE CONTROL STATEMENTS 14-1 14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8 14.9 INTRODUCTION REWIND STATEMENT UNLOAD STATEMENT BACKSPACE STATEMENT END FILE STATEMENT SKIP RECORD STATEMENT SKIP FILE STATEMENT BACKFILE STATEMENT SUMMARY OF DEVICE CONTROL STATEMENTS 14-1 14-1 14-2 14-2 14-2 14-3 14-3 14-3 14-3 15 SUBPROGRAM STATEMENTS 15-1 15.1 15.1.1 15.2 15.3 INTRODUCTION Dummy and Actual Arguments STATEMENT FUNCTIONS INTRINSIC FUNCTIONS (FORTRAN DEFINED FUNCTIONS) EXTERNAL FUNCTIONS Basic External Functions (FORTRAN-20 Defined Functions) Generic Function Names 15-1 15-1 15-3 13.2.3 13.2.4 13.2.5 13.2.6 13.2.7 13.2.8 13.2.9 13.2.10 13.2.11 13.2.12 13.3 CHAPTER CHAPTER 15.4 15.4.1 15.4.2 vi 13-6 13-7 13-7 13-10 13-10 13-11 13-12 13-14 13-14 13-15 13-16 13-16 15-3 15-6 15-7 15-7 CONTENTS (CONT.) Page SUBROUTINE SUBPROGRAMS Referencing Subroutines (CALL Statement) FORTRAN-20 Supplied Subroutines RETURN STATEMENT AND MULTIPLE RETURNS Referencing External FUNCTION Subprograms MULTIPLE SUBPROGRAM ENTRY POINTS (ENTRY STATEMENT) 15-8 15-11 15-12 15-12 16 BLOCK DATA SUBPROGRAMS 16-1 16.1 16.2 INTRODUCTION BLOCK DATA STATEMENT 16-1 16-1 APPENDIX A ASCII-1968 CHARACTER CODE SET A-I APPENDIX B USING THE COMPILER B-1 RUNNING THE COMPILER Switches Available with FORTRAN-20 The /DEBUG Switch COMPIL-C1ass Commands READING THE LISTING Compiler-Generated Variables ERROR REPORTING Fatal Errors and Warning Messages Message Summary CREATING A REENTRAN'I' FORTRAN PROGRAH WITH LINK B-1 B-1 B-3 B-4 B-5 B-6 B-17 B-17 B-18 WRITING USER PROGRAMS C-1 GENERAL PROGRAMMING CONSIDERATIONS Accuracy and Range of Double-Precision Numbers Writing FORTRAN-20 Programs for Execution on Non-DEC Machines Using Floating-Point DO Loops Computation of DO Loop Iterations Subroutines - Programming Considerations Reordering of Computations Dimensioning of Formal Arrays FORTRAN-20 GLOBAL OPTIMIZATION Optimization Techniques Elimination of Redundant Computations Reduction of Operator Strength Removal of Constant Computation From Loops Constant Folding and Propagation Removal of Inaccessible Code Global Register Allocation I/O Optimization Uninitia1ized Variable Detection Test Replacement Improper Function References Programming 'I'echniques for Effective Optimization C-1 15.5 15.5.1 15.5.2 15.6 15.6.1 15.7 CHAPTER B.1 B.1.1 B.1.1.1 B.1.2 B.2 B.2.1 B.3 B.3.1 B.3.2 B.4 APPENDIX C C.1 C.1.1 C.1.2 C.1.3 C.1.4 C.1.5 C.1.6 C.1.7 C.2 C.2.1 C.2.1.1 C.2.1.2 C.2.1.3 C.2.1.4 C.2.1.5 C.2.1.6 C.2.1.7 C.2.1.8 C.2.1.9 C.2.2 C.2.3 vii 15-14 15-15 B-18 C-1 C-1 C-2 C-2 C-2 C-3 C-4 C-4 C-5 C-5 C-5 C-6 C-7 C-7 C-7 C-8 C-8 C-8 C-8 C-9 CONTENTS (CONT.) Page C.3 C.3.1 C.3.2 C.3.3 C.3.4 C.3.S C.3.6 C.3.7 C.3.7.1 C.3.7.2 C.3.8 C.3.8.1 APPENDIX D INTERACTING WITH NON-FORTRAN PROGRAMS AND FILES Calling Sequences Accumulator Usage Argument Lists Argument Types Description of Arguments Converting Existing MACRO Libraries for use with FORTRAN-20 Interaction with COBOL Calling FORTRAN-20 Subroutines from COBOL Programs Calling COBOL Subroutines from FORTRAN-20 Programs LINK Overlay Facilities Conventions FOROTS C-9 C-9 C-IO C-ll C-12 C-13 C-14 C-20 C-21 C-22 C-22 C-23 D-l D.l D.2 D.3 D.4 D.4.1 HAROWARE AND SOFTWARE REQUIREMENTS FEATURES OF FOROTS ERROR PROCESSING INPUT/OUTPUT FACILITIES Input/Output Channels Used Internally by FOROTS File Access Modes D.4.2 D.4.2.1 Sequential Transfer Mode D.4.2.2 Random Access Mode ACCEPTABLE TYPES OF OATA FILES ANO THEIR D.S FORMATS ASCII Data Files D.S.l D.S.2 FORTRAN Binary Oata Files D.S.2.1 Format of Binary Files D.S.3 Mixed Mode Oata Files D.S.4 Image Files D.6 USING FOROTS FOROTS Entry Points D.6.1 Calling Sequences D.6.2 MACRO Calls for FOROTS Functions D.6.3 D.6.3.1 I/O Statements, Sequential Access Calling Sequences D.6.3.2 NAMELIST I/O Sequential Access Calling Sequences D.6.3.3 Array Offsets and Factoring D.6.3.4 I/O Statements Random Access Calling Sequences D.6.3.S Calling Sequences for Statements That Use Oefault Oevices Statements to position Magnetic D.6.3.6 Tape Units D.6.3.7 List Oirected Input/Output Statements Input/Output Oata Lists D.6.3.8 OPEN and CLOSE Statements, D.6.3.9 Calling Sequences D.6.3.10 Memory Allocation Routines Software Channel Allocation and D.6.3.11 Oe-allocation Routines FUNCTIONS TO FACILITATE OVERLAYS D.7 LOGICAL/PHYSICAL OEVICE ASSIGNMENTS D.8 viii D-l 0-2 0-3 0-3 D-3 0-4 0-4 0-4 0-4 D-4 D-S O-S D-12 0-13 0-13 0-14 0-14 O-IS 0-16 0-17 D-18 0-20 0-20 0-22 0-22 0-23 0-26 0-27 0-28 0-29 0-32 CONTENTS (CONT.) Page FORDDT E-l INPUT FORMAT Variables and Arrays Numeric Conventions Statement Labels and Source Line Numbers NEW USER TUTORIAL Basic Commands FORDDT AND THE FORTRAN-20/DEBUG SWITCH LOADING AND STARTING FORDDT SCOPE OF NAME AND LABEL REFERENCES FORDDT COMMANDS ENVIRONMENT CONTROL FORTRAN-20/0PTIMIZE SWITCH FORDDT MESSAGES E-2 E-2 E-3 E-3 E-3 E-3 E-7 E-7 E-8 E-8 E-17 E-17 E-17 APPENDIX F COMPILER MESSAGES F-l APPENDIX G FOROTS ERROR MESSAGES G-l APPENDIX H DECSYSTEM-10 COMPATABILITY H-l APPENDIX E E.l E.l.l E.l.2 E.l.3 E.2 E.2.1 E.3 E.4 E.S E.6 E.7 E.8 E.9 INDEX Index-l TABLES TABLE 1-1 2-1 3-1 3-2 4-1 4-2 4-3 4-4 4-S 4-6 4-7 8-1 10-1 10-2 10-3 10-4 12-1 13-1 13-2 13-3 13-4 13-S 14-1 lS-l FORTRAN Statement Categories FORTRAN Character Set Constants Use of Symbolic Names Arithmetic Operations and Operators Type of the Result Obtained From Mixed Mode Operations Permitted Base/Exponent Type Combinations Logical Operators Logical Operations, Truth Table Relational Operators and Operations Hierarchy of FORTRAN-10 Operators Rules for Conversion in Mixed Mode Assignments FORTRAN-20 Logical Device Assignments Summary of READ Statements Summary of WRITE Statements Summary of I/O Statements OPEN/CLOSE Statement Arguments FORTRAN-20 Conversion Codes Action of Field Descriptors On Sample Data Numeric Field Codes Descriptor Conversion of Real and Double Precision Data According to Magnitude FORTRAN-20 Print Control Characters Summary of FORTRAN-20 Device Control Statements Intrinsic Functions (FORTRAN-20 Defined Functions) ix 1-2 2-1 3-1 3-6 4-1 4-3 4-4 4-S 4-6 4-7 4-10 8-2 10-4 10-lS 10-17 10-24 12-11 13-3 13-S 13-6 13-8 13-17 14-4 lS-4 CONTENTS (CaNT.) Page 15-2 15-3 B-1 B-2 C-l D-l D-2 E-l G-l G-2 Basic External Functions (FORTRAN-20 Defined Functions) FORTRAN-20 Library Subroutines FORTRAN-20 Compiler Switches Modifiers to /DEBUG Switch Argument Types and Type Codes Function Numbers and Function Codes FORTRAN Device Table Table of Commands FOROTS I/O Error Messages and ERRSNS Returned Values FOROTS Arithmetic and Library Error Messages x 15-9 15-17 B-2 B-3 C-12 D-30 D-33 E-l G-2 G-5 CHAPTER 1 PROLOGUE 1.1 BACKGROUND A FORTRAN source program consists of statements constructed using the language elements and the syntax described in this manual. A statement performs one of the following functions: 1. Causes operations such as branching to be carried out. multiplication, division, 2. Specifies the type and format of data being processed. 3. Specifies the characteristics of the source program. and FORTRAN statements are composed of keywords, i.e., words that are recognized by the compiler, used with elements of the language set: constants, variables, and expressions. There are two basic types of FORTRAN statements: executable and nonexecutable. Executable statements specify the action of the program; nonexecutable statements describe the characteristics and arrangement of data, editing information, statement functions, and the kind of subprograms that may be included in the program. The compilation of executable statements results in the creation of executable code in the object program. Nonexecutable statements provide information only to the compiler; they do not create executable code. In this manual, the FORTRAN statements are grouped into 12 categories, each of which is described in a separate chapter. The name, definition, and chapter reference for each statement category are given in Table 1-1. The basic FORTRAN language elements, (constants, variables, and expressions), the character set from which they may be formed, and the rules that govern their construction and use are described in Chapters 2 through 4. 1-1 PROLOGUE Table 1-1 FORTRAN Statement Categories Chapter Reference Category Name Function 5 Compilation Control Statements Identify programs their beginning points. 6 Specification Statements Declare the properties of variables, arrays, and functions. 7 DATA Statements Assign initial values variables and array elements. 8 Assignment Statements Assign values to named variables and array elements. 9 Control Statements Determine the order of execution of the object program and terminate its execution. 10 Input/Output Statements Transfer data between internal storage and specified input/output devices. 11 NAME LIST Statements Establish lists that are used with certain input/output statements to transfer data that appears in a special type of record. 12 File Control Statements Identify, open, and close files and set parameters for input and output operations between files and the processor. 13 FORMAT Statements Specify formats for input/output devices. 14 Device Control Statements Control the positioning of records or files on certain input/output devices. 15 Subprogram Statements Define functions and subroutines and their entry points. 16 BLOCK DATA Statements Define data specification subprograms that may initialize common storage areas. 1-2 and and indicate ending data to on PREFACE This manual describes the FORTRAN language as implemented for the DECsystem-20 FORTRAN Language Processing System. In the text, the language is called FORTRAN-20 (to distinguish it from ANSI FORTRAN), or simply FORTRAN. Since this is a reference manual, we assume that you have used FORTRAN before. If you haven't, you should read one of the many introductory FORTRAN texts. Your use of FORTRAN may also require use of other DECsystem-20 programs: the monitor, the CREF program, the debugging program, a text editor, and the BATCH program. These are described in the following manuals: User's Guide DEC-20-0UGAA-A-D Monitor Calls User's Guide DEC-20-UMUGA-A-D EDIT User's Guide DEC-20-UEUGA-A-D BATCH Reference Manual DEC-20-0BRMA-A-D The standard for FORTRAN is the American National Standards Institute (ANSI) FORTRAN, X3.9-1966. FORTRAN-20 extensions and additions to ANSI FORTRAN are gray shaded. xi CHAPTER 2 CHARACTERS AND LINES 2.1 CHARACTER SET Table 2-1 lists the digits, letters, and symbols recognized by FORTRAN. The remainder of the ASCII-1968 character set (1) , is acceptable within literal constants or comment text, but these characters cause fatal errors in other contexts. An exception is CONTROL-Z, which, when used in terminal input, means end-of-file. NOTE Lower-case alphabet characters are treated as upper-case outside the context of Hollerith constants, literal strings, and comments. Table 2-1 FORTRAN Character Set Letters A,a B,b C,c D,d E,e F,f G,g H,h I,i S,s T,t U,u V,v W,w X,x Y,y Z,z J, j K,k L,l M,m N,n 0,0 P,p Q,q R, r Digits 0 1 2 3 4 5 6 7 8 9 1. The complete ASCII-1968 character set is defined in the X3.4-l968 version of the "American National Standard for Information Interchange," and is given in Appendix A. 2-1 CHARACTERS AND LINES Table 2-1 (Cont.) FORTRAN Character Set Symbols , Comma - Hyphen (Minus) Period (Decimal Point) / Slant (slash) : Colon ; Semicolon < Less Than = Equals Greater Than > "Circumflex ! Exclamation Point Quotation Marks # Number Sign $ Dollar Sign & Ampersand I Apostrophe ( Opening Parenthesis ) Closing Parenthesis * Asterisk + Plus 1/ . Line Termination Characters Line Feed Form Feed vertical Tab Line Formatting Characters Carriage Return Horizontal Tab Blank Note that horizontal tabs normally advance the character position pointer to the next position that is an even multiple of 8. An exception to this is the initial tab, which is defined as a tab that includes or starts in character position 6. (Refer to Section 2.3.1 for a description of initial and continuation line types.) Tabs within literal specifications count as one character even though they may advance the character position as many as eight places. 2.2 STATEMENT, DEFINITION, AND FORMAT Source program statements are divided into physical lines. A line is defined as a string of adjacent character positions, terminated by the first occurrence of a line termination character regardless of context. Each line is divided into four fields: Line Character Positions ~ 234 5 6 7 -----------------+1_\ 8 70 71 72 __~~--~'~'~---------y----------J Statement Label Field Continuation Field Statement Field 2-2 73 Remarks CHARACTERS AND LINES 2.2.1 Statement Label Field and State~ent Numbers You may place a number ranging from 1 to 99999 in the statement label field of an initial line to identify the statement. Any source program statement that is referenced by another statement must have a statement number. Leading zeros and all blanks in the label field are ignored, e.g., the numbers 00105 and 105 are both accepted as statement number 105. You may assign the statement numbers in a source program in any order; however, each statement number must be unique with respect to all other statements in the program or subprogram. You cannot label non-executable statements other than FORMAT and END statements. A main program and a subroutine may contain identical statement numbers. In this case, references to these numbers are understood to mean the numbers in the same program unit in which the reference is made. An example: Assume that main module MAINMD and subprogram SUBI both A GO TO statement, for contain statement number 105. instance, in MAINMD will refer to statement 105 in MAINMD, NOT to 105 in SUBI. A GO TO in SUBI will transfer control to 105 in SUBI. When you enter source programs into the system via a standard user terminal, you may use an initial tab to skip all or part of the label field. If an initial tab is encountered during compilation, FORTRAN examines the character immediately following the tab to determine the type of line being entered. If the character following the tab is one of the digits 1 through 9, FORTRAN considers the line as a continuation line and the second character after the tab as the first character of the statement field. If the character following the tab is other than one of the digits 1 through 9, FORTRAN considers the line to be an initial line and the character following the tab is considered to be the first character of the statement field. The character following the initial tab is considered to be in character position 6 in a continuation line, and in character position 7 in an initial line. 2.2.2 Line Continuation Field Any alphanumeric character (except a blank or a zero) placed in field (position 6) identifies the line as a continuation line. Section 2.3.1 for description.) this (See Whenever you use a tab to skip all or part of the label field of a continuation line, the next character you enter must be one of the digits 1 through 9 to identify the line as a continuation line. 2.2.3 Statement Field Any FORTRAN statement may appear in this field. Blanks (spaces) and tabs do not affect compilation of the statement and may be used freely in this field for appearance purposes, with the exception of textual data given within either a literal or Hollerith specification where blanks and tabs are significant characters. 2-3 CHARACTERS AND LINES 2.2.4 Remarks In lines consisting of 73 or more character positions, only the first characters are interpreted by FORTRAN. (Note that tabs generally occupy more than one character position, usually advancing the counter to the next character position that is an even multiple of eight.) All other characters in the line (character positions 73, 74 ... etc.) are treated as remarks and do not affect compilation. 72 Note that remarks may also be added to a line in character positions 7 through 72, provided the text of the remark is preceded by the symbol "!" (Refer to Section 2.3.3.) 2.3 LINE TYPES A line in a FORTRAN source program may be: 1. An initial line, 2. A continuation line, 3. A m'u"i'tI~:";'sWtatement line, 4. A comment line, 5. A debug line, or 6. A blank line. Each of these line types is described in the following paragraphs. 2.3.1 Initial and Continuation Line Types A FORTRAN statement may occupy the statement fields of up to 20 consecutive lines. The first line in a multi-line statement group is referred to as the initial line; the succeeding lines are referred to as continuation lines. An initial line may be assigned a statement number and must have either a blank or a zero in its continuation line field, i . e • , character position 6. If you enter an initial line via a keyboard input device, you may use an initial tab to skip all or part of the label field. If you use an initial tab for this purpose, you must immediately follow it with a non-numeric character, i.e., the first character of the statement ,field must be non-numeric. Continuation lines cannot be assigned statement numbers; they are identified by any alphanumeric character (except for a blank or zero) placed in character position 6 of the line, i.e., continuation line field. The label field of a continuation line is treated as remark text. If vou are entering a continuation line via a keyboard, you may use an ;initial tab to skip all or part of the label field; however, the tab imust be followed immediately by a numeric character other than zero. lThe tab-numeric combination identifies the line as a continuation jline. 2-4 CHARACTERS AND LINES Note that blank lines, comments, and debug lines that are treated like comments, i.e., debug lines that are not compiled with the rest of the program (refer to Section 2.3.4) terminate a continuation sequence. Following is an example of a 4-1ine initial tabs: 105 FORTRAN FORMAT statement using FORMAT (lHl,17HINITIAL CHARGE = ,FIO.6,10H COULOMB,6X, 213HRESISTANCE = ,F9.3,6H OHM/ISH CAPACITANCE = ,FIO.6, 38H FARAD,11X,13HINDUCTANCE = ,F7.3,8H HENRY/// 421H TIME CURRENT/7H MS,10X.2HMA///) Continuation Line Characters, i.e., 2, 3, and 4 2.3.2 Multi-Statement Lines You may write more than one FORTRAN statement in the statement field of one line. The rules for structuring a multi-statement line are: 1. Successive statements must be separated by semicolons (;). 2. Only the first statement in the series can have number. 3. Statements following the first statement continuation of the preceding statement. 4. The last statement in a line may be continued to the line if that next line is made a continuation line. a statement cannot be a next An example of a multi-statement line is: 450 DIST=RATE * TIME ;TIME=TIME+0.05 iCALL PRIME(TIME,DIST) 2.3.3 Comment Lines and Remarks Lines that contain descriptive text only are referred to as comment lines. Comment lines are commonly used to identify and introduce a source program, to describe the purpose of a particular set of statements, and to introduce subprograms. To structure a comment line: 1. You must place one of the characters C (or c), $,/,*, or in character position 1 of the line to identify it as a comment line. 2. You may write the text into character positions 2 through the end of the line. 3. You may place comment lines anywhere in the source program, but they cannot precede a continuation line because comments terminate a continuation sequence. 4. You may write a large comment as a sequence of any number of lines; however, each line must carry the identifying character (C,$,/,*, or 1) in its first character position. 2-5 CHARACTERS AND LINES The following is an example of a comment that occupies more line. than one CSUBROUTINE - A12 CTHE PURPOSE OF THIS SUBROUTINE IS CTO FORMAT AND STORE THE RESULTS OF CTEST PROGRAM HEAT TEST-llOl Comment lines are printed on all listings, but are by the compiler. otherwise ignored You may add a remark to any statement field, in character positions 7 through 72, provided the symbol! precedes the text. For example, in the line IF(N.EQ.O)STOP! STOP IF CARD IS BLANK the character group "Stop if card is blank" is identified as a remark by the preceding! symbol. Remarks do not result in the generation of object program code, but they will appear on listings. The symbol 1, indicating a remark, must appear outside the context of a literal specification. Note that characters appearing in character positions 73 and beyond are automatically treated as remarks, so that the symbol need not be used. (Refer to Section 2.2.4.) 2.3.4 Debug Lines As an aid in program debugging, a D (or d) in character position 1 of any line causes the line to be interpreted as a comment line, i.e., not compiled with the rest of the program unless the /INCLUDE switch is present in the command string. (Refer to Appendix C for a ,description of the file switch options.) When the /INCLUDE switch is f present in the command string, the D (or d) in character position 1 is , treated as a blank so that the remainder of the line is compiled as an ordinary (noncomment) line. Note that the initial and all continuation lines of a debug statement must contain a D (or d) in character position 1. 2.3.5 Blank Lines You may insert lines consisting of only blanks, tabs, or no characters anywhere in your source program except immediately preceding a continuation line, because blank lines are by definition initial lines and as such terminate a continuation sequence. Blank lines are used for formatting purposes only; they cause blank lines to appear in their corresponding positions in source program listings; otherwise, they are ignored by the compiler. 2.3.6 Line-Sequenced Input pr\nmn7\,...,. __ ..... ..: ___ , , _ ... _____ i.._ ,..: _ _ _ _ _ ... _ _ _ _ ..:1 ..c.:, __ _ _ _ * _ _ ..:1 .... _ _ ...:1 ' - __ M1""\Trrt __ L·V~"J.J:\.r\LII V1:''-.LVllct.L.1.,Y ctl,,;l,,;t::1:''-;:' .1..Lllt::-i:)t::YUt::lll,,;t::U LJ..1.t::i:) cti:) U,Y I:.1.J.1.J. UL 1:'LVUUI,,;t::U BASIC. These sequence numbers are used in place of the listing line numbers normally generated. 2-6 CHARACTERS AND LINES 2.4 ORDERING OF STATEMENTS The order in which you place statements in a program unit is important. That is, certain types of statements have to be processed before others to guarantee that compilation takes place as you expect. The proper sequence for statements is summarized by the following diagram. PROGRAM, FUNCTION, SUBPROGRAM, or BLOCK DATA Statements IMPLICIT Statements PARAMETER Statements Comment Lines DIMENSION, COMMON, EQUIVALENCE, EXTERNAL NAMELIST, or Type Specification Statements FORMAT Statements Statement Function Definitions DATA Statements Executable Statements END Statement Horizontal lines indicate the order in which statements must appear. That is, you cannot intersperse horizontal sections. For example, all PARAMETER statements must appear after all IMPLICIT statements and before any DATA statements, i.e., PARAMETER, IMPLICIT, and DATA statements cannot be interspersed. Statement function definitions must appear after IMPLICIT statements and before executable statements. Vertical lines indicate the way in which certain types of statements may be interspersed. For example, you may intersperse DATA statements with statement function definitions and executable statements. you may intersperse FORMAT statements with IMPLICIT statements, parameter statements, other specification statements, DATA statements, statement function definitions, and executable statements. The only restriction on the placement of FORMAT statements is that they must appear after any PROGRAM, FUNCTION, subprogram, and BLOCK DATA statements, and before the END statement. 2-7 CHARACTERS AND LINES Special Cases: 1. The placement of an INCLUDE statement types of statements to be INCLUDEd. 2. The ENTRY statement is allowed only in functions or subroutines. All executable references to any of the dummy parameters must physically follow the ENTRY statement unless the references appear in the function definition statement, the subroutine, or in a preceding ENTRY statement. 3. BLOCK DATA subprograms cannot contain any executable statements, statement functions, FORMAT statements, EXTERNAL statements, or NAMELIST statements. (Refer to Section 16.1.) When statements are out of place, FORTRAN which may indicate fatal errors. 2-8 issues is dictated messages, by some the of CHAPTER 3 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3.1 DATA TYPES The data types you may use in FORTRAN source programs are: 1. integer, 2. real, 3. double-precision, 4. complex, 5. octal, 6. d~llble-oct:al, , 7. literal t 8. statement label, and 9. logical. The use and format of each of the foregoing data types are in the descriptions of the constant having the same (Sections 3.2.1 through 3.2.8). 3.2 discussed data type CONSTANTS Constants are quantities that do not change value during the execution of the object program. The constants you may use in FORTRAN are listed in Table 3-1. Table 3-1 Constants Category Constant(s) Types Numeric Integer, real, double-precision, complex, and octal Logical Literal Address of statement lap.~l Truth Values Literal Data S.tatement~. Label 3-1 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3.2.1 Integer Constants An integer constant is a string of from one to eleven digits that represents a whole decimal number (a number without a fractional part). Integer constants must be within the range of (-2**35)-1 to (+2**35)-1 (-34359738367 to +34359738367). positive integer constants may optionally be signed; negative integer constants must be signed. You cannot use decimal points, commas, or other symbols on integer constants (except for a preceding sign, + or -). Examples of valid integer constants are: 345 +345 -345 Examples of invalid integer constants are: +345. 3,450 34.5 3.2.2 (use of decimal point) (use of comma) (use of decimal point; not a whole number) Real Constants A real constant may have any of the following forms: 1. A basic real constant: a string of decimal digits followed immediately by a decimal point followed optionally by a decimal fraction, e.g., 1557.42. 2. A basic real constant followed immediately by a decimal integer exponent written in E notation (exponential notation) form, e.g., 1559.E2. 3. An integer constant (no decimal point) followed by a decimal integer exponent written in E notation, e.g., l559E2. Real constants may be of any size; however, each will be fit the precision of 27 bits (7 to 9 decimal digits). rounded to Precision for real constants is maintained to approximately eight significant digits; the absolute precision depends upon the numbers involved. The exponent field of a real constant written in E notation form cannot be empty (blank); it must be either a zero or an integer constant. The magnitude of the exponent must be greater than -38 and equal to or less than +38 (i.e., -38<n<+38). The following are examples of valid real constants. -98.765 7.0E+0 .7E-3 5E+5 50115. 50.El (7 • ) (.0007) (500000.) (500.) The following are examples of invalid real constants. 72.6E75 .375E 500 (exponent is too large) (exponent incorrectly written) (no decimal point given) 3-2 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3.2.3 Double-Precision Constants Constants of this type are similar to real constants written in E notation form; the direct differences between these two constants are: 1. Double-precision constants, depending on their magnitude, have precision of 16 to 18 places rather than the 8-digit precision obtained for real constants. 2. Each double-precision locations. 3. The letter D, instead of E, is used in constants to identify a decimal exponent. constant occupies two storage double-precision You must use both the letter D and an exponent (even of zero) in writing a double-precision constant. The exponent need only be signed if it is negative; its magnitude must be greater than -38 and equal to or less than +38 (i.e., -38<n~+38). The range of magnitude permitted a double-precision constant is 0.14 X 10**(-38) to 3.4 X 10**(+38) The following are examples of valid double-precision constants. 7.9D03 7.90+03 7.9D-3 79D03 79DO (= (= (= (= (= 7900) 7900) .0079) 79000) 79) The following are examples of invalid double-precision constants. 7.9D99 7.9ES 3.2.4 (exponent is too large) (" E" denotes a single-precision constant) Complex Constants You can represent a complex constant by an ordered pair of integer, real, or octal constants written within parentheses and separated by a comma. For example, (.70712, -.70712) and (8.763E3, 2.297) are complex constants. In a complex constant the first (leftmost) real constant of the pair represents the real part of the number; the second real constant represents the imaginary part of the number. Both the real and imaginary parts of a complex constant can be signed. The real constants that represent the real and imaginary parts of a complex constant occupy two consecutive storage locations in the object program. 3-3 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3.2.5 Octal Constants You may use octal numbers (radix 8) as constants in arithmetic, expressions, logical expressions, and data statements. Octal numbers up to 12 digits in length are considered standard octal constants; they are stored right-justified in one processor storage location. ;When necessary, standard octal constants are padded with leading zeros to fill their storage location. you specify more than 12 digits in an octal number, it is considered a double octal constant. Double octal constants occupy two storage locations and may contain up to 24 right-justified octal digits; zeros are added to fill any unused digits. ~If If you assign a single octal constant to a double precision or complex' variable, it is stored, right-justified, in the high-order word of the !variable. The low-order portion of the variable is set to zero. 'If you assign a double octal constant to a double precision or complex ,variable, it is stored right-justified starting in the low-order (rightmost) word and proceeds leftwards into the high-order word. All octal constants must: 1. be preceded by a double quote (") to identify the octal, e.g., 11777, and digits 2. be signed if negative, but optionally signed if positive. 3. contain one or more of the digits a through 7, but not 8 as or 9. The following are examples of valid octal constants: "123456700007 " 1234567000 a7 +"12345 -"7777 "-7777 The following are examples of invalid octal constants: "12368 7777 (contains an 8) (no identifying double quotes) When you use an octal constant as an operand in an expression, its form (bit pattern) is not converted to accommodate it to the type of any other operand. For example, the subexpression (A+"202 400 000 000) has as its result the sum of A with the floating point number 2.0; while the'subexpression (1+'1202 400 000 OOO) has as its result the sum of I with a large integer. iOctal constants may not be used as stand-alone arguments for library . functions that require non-octal arguments. MINO, for instance, requires INTEGER arguments and cannot accept octal arguments. When you combine a double octal constant in an expression with either: . an integer or real variable, only the contents of the high order: location (leftmost) are used. 3-4 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3.2.6 Logical Constants The Boolean values of truth and falsehood are represented in FORTRAN source programs as the logical constants .TRUE. and .FALSE .• Always write logical constants enclosed by periods as in the preceding sentence. Logical quantities may be operated on in arithmetic and logical statements. Only the sign bit of a numeric used in a logical IF statement is tested to determine if it is true (sign is negative) or false (sign is positive) . 3.2.7 Literal Constants A literal constant may be either of the following: 1. A string of alphanumeric and/or special characters within apostrophes, e.g., 'TEST#S'. contained 2. A Hollerith literal, which is written as a string of alphanumeric and/or special characters preceded by nH (e.g., nHstring). In the prefix nH, the letter n represents a number that specifies the exact number of characters (including blanks) that follow the letter Hi the letter H identifies the literal as a Hollerith literal. The following are examples of Hollerith literals: 2HAB 14HLOAD TEST #124 6H#124-A NOTE A tab (-I) in a Hollerith literal is counted character, e.g., 3H -I AB. as one You may enter literal constants into DATA statements as a string of: 1. up to ten 7-bit ASCII characters precision type variables, and 2. up to five variables. 7-bit ASCII for characters complex for all or double other type The 7-bit ASCII characters that comprise a literal constant are stored left-justified (starting in the high-order word of a 2-word precision or complex literal) with blanks placed in empty character positions. Literal constants that occupy more than one variable are stored as successive variables in the list. The following example illustrates how the string of characters A LITERAL OF MANY CHARACTERS is stored in a six-element array called A. DIMENSION A(6) DATA A/' A LITERAr. OF MANY CHARAC.TERS '/.,<. 3-5 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS A (1) A (2) A (3) A (4) A (5) A (6) 3.2.8 is is is is is is set set set set set set to to to to to to 'A LIT', 'ERAL 'OF MA' 'NY CHi 'ARACT' 'ERS Statement Label Constants Statement labels are statement numbers. numeric identifiers that represent program : You write statement label constants as strings of from one to five : decimal digits, which are preceded by either a dollar sign ($) or an ampersand (&). For example, either $11992 or &11992 may be used as a statement label constant. < You use statement label constants only in the argument list of CALL statements to identify the statement to return to in a multiple RETURN statement. (Refer to Chapter 15.) 3.3 SYMBOLIC NAMES Symbolic names may cq~sist of ~~y ~lphanumer~c .~ombin~tion of from one to six~ characters. You may use more than six characters I but FORTRAN will ignore all but .th~ first six. The first character of a symbolic name must be an alphabetic "6haiacter. The following are examples of legal symbolic names: A12345 IAMBIC ABLE The following are examples of illegal symbolic names: iAMBIC lAB (symbol used as first character) (number used as first character) You use symbolic names to identify specific items of a source program; Table 3-2 lists these items, together with an example of a symbolic name and text reference for each. Table 3-2 Use of Symbolic Names Symbolic Names Can Identify 1. 2. 3. 4. 5. 6. Variables Arrays Array elements Functions Subroutines External library functions 7. COMMON block names For Example For a Detailed Description See Section PI, CONST, LIMIT TAX TAX (NAME, INCOME) MYFUNC, VALFUN CALCSB, SUB2, LOOKUP SIN, ATAN, COSH 3.4 3.5 3.5.1 15.2 15.5 15.4 DATAR, COMDAT 6.5 3-6 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3.4 VARIABLES A variable is a datum (storage location) that is identified by a symbolic name and is not a constant, an array or an array element. Variables specify values that are assigned to them by either arithmetic statements (Chapter 8), DATA statements (Chapter 7), or at run time via I/O references (Chapter 10). Before you assign a value to a variable, it is termed an undefined variable, and you should not reference it except to assign a value to it. If you reference an undefined variable, will be obtained. an unknown value (garbage) The value you assign to a variable may be either a constant or the result of a calculation that is performed during the execution of the object program. For example, the statement IAB=5 assigns the constant 5 to the variable lAB; in the statement lAB=5+B, however, the value of lAB at a given time will depend on the value of variable B at the time the statement was last executed. The type of a variable is the type of the contents of the it identifies. Variables may be: 1. integer 2. real 3. logical 4. double-precision, or 5. complex. datum that You may declare the type of a variable by using either implicit or explicit type declaration statements (Chapter 6). However, if you do not use type declaration statements, FORTRAN assumes the following convention: 1. Variable names that begin with the letters I, J, K, L, M, N are normally integer variables. 2. Variable names that begin with any letter other than I, J, K, L, M, or N are normally real variables. Examples of determining the type of a variable according foregoing convention are given in the following table: Variable ITEMP OTEMP KA123 AABLE 3.5 Beginning Letter to or the Assumed Data Type Integer Real Integer Real I 0 K A ARRAYS An array is an ordered set of data identified by an array name. Array names are symbolic names and must conform to the rules given in Section 3.3 for writing symbolic names. 3-7 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS Each datum within an array is called an array element. As with variables, you may assign a value to an array element. Before you assign a value to an array element it is considered to be undefined; you should not reference it until you have assigned it a value. If you reference an undefined array element, the value of the element will be unpredictable. Name each element of an array by using the array name together with a subscript that describes the position of the element within the array. 3.5.1 Array Element Subscripts Give the subscript of an array element identifier within parentheses, as either one subscript quantity or a set of subscript quantities delimited by commas. write the parenthesized subscript immediately after the array name. The general form of an array element name is AN (Sl, S2, ... Sn), where AN is the array name and Sl through Sn represent nnumber of subscript quantities. 'You may use any number of subsriiip~~ : quantities in an element 'name; however, the number used must always . eq~al ~he' number of dimensions (Section 3.5.2) specified for the array. A subscript can be any compound expression (Chapter 4), for example: 1. Subscript quantities may contain arithmetic expressions that involve addition, subtraction, multiplication, division, and exponentiation. For example, (A+B,C*S,D/2) and (A**3, (B/4+C)*E,3) are valid subscripts. 2. Arithmetic expressions used in array subscripts may be of any type, but noninteger expresslons (including complex) are ~onverted to integer when the subscript is evaluated. 3. A subscript may contain function references (Chapter 14). For example: TABLE (SIN (A) *B,2,3) is a valid array element identifier. 4. Subscripts may contain array element identifiers nested to any level as subscripts. For example, in the subscript (I(J(K(L))) ,A+B,C) the first subscript quantity given is a nested 3-level subscript. Here are examples of valid array element subscripts: 1. IAB(l,S,3) 2. ABLE(A) ! 3. TABLEl(lO/C+K**2,A,B) '4. MAT(A,AB(2*L),.3*TAB(A,M+l,D) ,55) 3-8 DATA TYPES, CONSTANTS, SYMBOLIC NAMES, VARIABLES, AND ARRAYS 3.5.2 Dimensioning Arrays You must declare the size (number of elements) of an array in order to reserve the needed amount of locations in which to store the array. Arrays are stored as a series of sequential storage locations. Arrays, however, are visualized and referenced as if they were single or multi-dimensional rectilinear matrices, dimensioned on a row, column, and plane basis. For example, the following figure represents a 3-row, 3-column, 2-plane array. 3 ROWS ~~ ~C:J ~~ '/, <?" 3 COLUMNS 10-1058 You specify the size of an array by an array declarator written as a subscripted array name. In an array declarator, however, each subscript quantity is a dimension of the array and must be either an integer variable or an integer constant. For example, declarators. TABLE(I,J,K) and MATRIX (10,7,3,4) are valid array The total number of elements that comprise an array is the product of the dimension quantities given in its array declarator. For example, the array lAB dimensioned as lAB (2,3,4) has 24 elements (2 X 3 X 4 24) . Dimension arrays only in the specification statements DIMENSION, COMMON, and type declaration (Chapter 6). Subscripted array names appearing in any of the foregoing statements are array declaratorsi subscripted array names appearing in any other statements are always array element identifiers. In array declarators the position of a given subscript quantity determines the particular dimension of the array (e.g., row, column, or plane) that it represents. The first three subscript positions specify the number of rows, columns, and planes that comprise the named arraYi each following subscript given then specifies a set comprised of n-number (value of the subscript) of the previously defined sets. 3-9 For exa~ple: The Dimension Declarator Specifies the Array(s) TAB (2) TAB (2,2) TAB (2,2,2) TAB (2,2,2, 2) r-::.=-=--r----t:;-;-:;~;_:;_:;t1 NOTE FORTRAN-20 permits any number dimensions in an array declarator. 3.5.3 of Order of Stored Array Elements The elements of an array are arranged in storage in ascending order. The value of the first subscript quantity varies between its m1n1mum and maximum values most rapidly. The value of the last given subscript quantity increases to its maximum value least rapidly. For example, the elements of the array dimensioned as 1(2,3) are stored in the following order: 1(1,1) 1(2,1) 1(1,2) (2,2) (1,3) (2,3) In the following list, the elements of the three-dimensional array B(3,3,3) are stored row by row from left to right and from top to bottom. B (1,1,1) Thus B(3,1,1) B (2,1,1) B (3,1,1) - , is stored before B(1,2,1), and so forth. 3-10 CHAPTER 4 EXPRESSIONS 4.1 ARITHMETIC EXPRESSIONS Arithmetic expressions may be either simple or compound. arithmetic expressions consist of an operand that may be: Simple 1. a constant 2. a variable 3. an array element 4. a function reference (see Chapter 14 for description), or 5. an arithmetic parentheses. or logical expression written within Operands may be of integer, real, double precision, complex, ~9£!;'~:l<L .9£1 JjJ:j~ru~lj type. The following are valid examples of simple arithmetic expressions: 105 lAB TABLE(3,4,5) SIN (X) (A+B) (integer constant) (integer variable) (array element) (function reference) (a parenthetical expression) A compound arithmetic expression consists of two or more operands combined by arithmetic operators. Table 4-1 lists the arithmetic operations permitted in FORTRAN and the operator recognized for each. Table 4-1 Arithmetic Operations and Operators Operation Operator ''>'., , 1. Exponentiation 2. Multiplication 3. Division 4. Addition 5. Subtraction **~or ~ v> .~~ A * / + - 4-1 ,. Example A**B o r "~~"""_~~~_~uj A*B A/B A+B A-B EXPRESSIONS 4.1.1 Rules for Writing Arithmetic Expressions Observe the expressions: 1. following rules in structuring compound arithmetic The operands compr1s1ng a compound arithmetic expression may be of different types. Table 4-2 illustrates all permitted combinations of data types and the type assigned to the result of each. NOTE one combination of data types, double-precision complex, is prohibited in FORTRAN-20. 2. An expression cannot contain operators. For example, permitted. 3. All operators must be included; no operation is implied. For example, the expression A(B) does not specify multiplication although this is implied in standard algebraic notation. The expression A* (B) is required to obtain a multiplication of the elements. 4. When you use exponentiation, the base quantity and its exponent may be of different types. For example, the expression ABC** 13 involves a real base and an integer exponent. The permitted base/exponent type combinations and the type of the result of each combination are given in Table 4-3. 4-2 two adjacent and unseparated the expression A*/B is not Table 4-2 Type of the Result Obtained From Mixed Mode Operations Type of Argument 2 For operator; +. -. *. / I. Type of operation used 2. Type associated with result 3. Conversion on Argument I Integer Real Double Precision Double Precision Real Complex Logical Octal Double Octal 1. Integer I. Real 1. Douhle Precision I. ~'Ol1lplex Integer I. Integer 2. Integer , 2. Double Precision _. Complex Integer , 3. None 3. From Integer to 3. From Integer to 3. From lnte~er to 3. None 3. l\one Double Precision ::omplex. Value used as Real part 4. ','one ..\. None 4. t\onc 4. lIigh order word is used dirc('Uy: lov; order word is ignored. 4. !11;:h orJ ~r word is u:;ed directly; further \lords ::::.re i;nor~Ll. Real I. Real L Real 1. Real Real Real 4. Conversion on Argument 2 4. None 4, None I. Type of operation used 2. Type associated with result 3. Conversion on Argument I I. Real I. Real I. Double PreCision , , , Real J. None Real 4. None Double Precision 3. None 3. Used directly as 4. None the high order word: low order word is zero. 4. None I. Complex '1 ('ompJe~ 3. Used directly as the Real part: ,OlaVnar,. part is zero. 4. None 1. Intc~cr Integer I. Ir.:c;;:r _. Integer j. :--one Snnc 2. Real ~one J. None 3. \"onc 4. ~onc 4. \"on" ... lIi;:h order word is used directly; 10"" order word is ignored. 4. llj;~ ardor word is lli('d directly; further v.ords are 19nored. 3. 4. Conversion on Argument 2 4. From Integer to L Type of operation used 2. Type associated with result 3. Conversion on Argument 1 4. Conversion on Argument 2 I. Double Precision I. Double l'recision I. Double Precision 1. Douhle Precision I. Double PreCISion I. Double Precision I. Double I'recision ., Double Precision Double Precision 2. Double Precision 2. Double PreCISion Double Precision 2. Double Precision 2. Double !'recision I. Type of operation Complex Integer used 2. Type associated with result 3. Conversion on Argument I 4. Conversion on Argument 2 Real 3. None 3. None 3. None 3. None 3. None 3. None 3. None 4. From Integer to Double Precision 4. Used directly 'as the hit:h order ,vend ~ low order \'rard is zero. 4. None 4. Used directly as 4. Used directly as the Jllgh order v.onl: low order 4. None 4. First two words are used directly; furth':! lNords :lIe i::;ncred. I. Complex the high crder word: low order word is zero. I. Complex 1. Complex I. Complex I. Compkx I: Complex I. Complex C. Complex _. Complex 2. Complex 2. Complex _. Complex , 3. None 3. 1\one 3. None 3. t"one 3. None 3. NOM 3. None 4. From Integer to 4. Used diredly as 4. None 4. Used d [rectlr as 4. Used d itectly as the Real rart: imaginary part 4. None 4. Firsl two "iords are U"ed dir ectly. Further words are ignored. Complex. Value used as Real part. the Real part: unar-mary pari the Real port; i mag;~..!iY part I. Into~er 2. Type associated Intq~er Double Precision Complex lero Ie; 7l.'fO. I. Complex I. Integer !. Integer I. Integer I. Integor 2. Octal , , , 1") I. Type of operation used word I~: leTO. 2. Rf:tl _. [)l)uble PreciSion , 3. None Complex J. lsed directly as J. Used directly as 3. None 4. None the high order word; low order word is zero. 1'>'one the R cal part; imal'inary part is zero 4. None 4. None Octal Octal Octal with result 3. Conversion on 3. None Argument I Logical Octal 4. Conversion on Argument 2 4. None L Typ~ of operation I. Integer I. I{eal 2. Integer , 3. None J. Nont' ~. 4. None used , Type associated with result 3. Conversion on Argument I 4. Conversion on Argument 2 Non\? Real 4 .t. i\on~ 3. None 3. None 4. High order word is used directly; low order word is ignured. 4. High order word Double Precision 1. Complex I. Integer I. Integer I. Integer 1. Integer Double Precis,on , Complex , Octal _. Octal 2. Octal 2. Octal Used dire:tI>' 35 the high order word: low order word is zero. 4. l\one .~. Used directly 3' the Real part: ima,:inary part 3. None 3. None 3. None 3. None 4. None 4. :-';one 4. High order word is used directly; low order ,,"ord 4. High order word is used directly; further words are i~norcd. , tS-ll'Tu 4. NOM is ignored. I. Type of operation , Double Oclal used Type associated with result Con\"erslon on Argument I 4. Conversion on Argument 2 I. Integer I. Real I. Double Precision I. Complex I. Integer I. Integer I. Inter,er L Integer 2. Integer .., Real 2. Double Precision :!. Complex , 2. Octal 2. Octal 2. Octal lIi,h order "mel is used directly; low order word 3. :\ono 3. Sone 4. None 3. High order word is used directly; low order word is ignored. 4. None 3. High order word is used directly: low order word is ignored. 4. High order word is used directly; 3. .1i~h mUe r worol is u,cd directly: lo,w order worlh 4. None 3. lIi[t." order word is used diredly: low order word is ignored. 4. None 3. lIigh order word is used directly: low ord er word is ignored. 4. None is ignored. 4. None Octal low ordIT word is ignored. J. Type of operation Literal used , Type associated with result 3. Conversion on Argument 1 Conversion on Argument 2 ~ I w is used directly; ftuther words are ignored. He it,IHHt:U. 4. rlii'h 'order word is lIsed directly; Ill'" ,,,dcr worJ, 'fC L:llor;'?d. I. Integer I. Real I. Double Precision 1. Complex I. Integer I. Integer I. Integer 2. Integer _. Real 2. Double Precisi,'n , ~ 2. Oelal 2. Octal ~. 3. High order word 3. lIigh order word is used directly; further words are ignored. 4. None 3. First two words are used directly; further words are ignoretl. 4. None 3. First two words are used directly; further words are ignored. 4. t"one 3. High order word is used directly: further words are ignored. 4. None 3. lIigh order wortl is used directly; further words ar e ignored. 4. None 3. lIig:h order word is used Girectly; further words arc ignored. 4. High order word is used directly; further words' are ignored. Complex Octal 3. High order word is used directly; further words are ignored. 4. None is used directly: further words are ignored_ 4. lIigh order word is used directly: low order word is ignored. Octal EXPRESSIONS Table 4-3 Permitted Base/Exponent Type Combinations Base Operand Integer Real Double Precision Complex 4.2 Exponent Operand Integer Real Integer Real Double Precision Complex Double Precision Real Real Double Precision Double Double Double Precision Precision Precision Complex Complex (Prohibited) Complex Complex (Prohibited) Complex LOGICAL EXPRESSIONS Logical expressions may be either simple or compound. Simple logical expressions consist of a logical operand, which may be a logical type: 1. constant 2. variable 3. array element 4. function reference (see Chapter 15), or 5. another expression written within parentheses. Compound logical expressions consist of two or more operands by logical operators. combined Table 4-4 gives the logical operation each provides. of operators 4-4 and a description the EXPRESSIONS Table 4-4 Logical Operators Operator Description .AND. AND operator. Both of the logical operands combined this operator must be true to produce a true result . • OR. Inclusive OR operator. If either or both of the logical operands combined by .OR. are true, the result will be true. • XOR. Exclusive OR operator. If either but not both of the is true, the result logical operands combined by .XOR. will be true. .EQV. Equivalence operator. If the logical operands being combined by .EQV. are both the same (both are true or both are fa~se), the result will be true. .NOT. Complementation operator. This operator is used as a prefix that specifies complementation (inversion) of the item (operand or expression) that it modifies. The original item, if true by itself, becomes false, and vice versa. by write logical expressions in the general form P .OP. Q, where P and Q are logical operand and .OP. is any logical operator but ".NOT.II. The .NOT. operator complements the value of a logical operand; you must write it immediately before the operand that it modifies, e.g., .NOT.P. Table 4-5 is a truth table illustrating all possibie logical combinations of two logical operands (P and Q) and the resultant of each combination. When an operand of a logical expression is double-precision or complex, only the high-order word of the operand is used in the specified logical operation. The assignment of a .TRUE. or a .FALSE. value to a given operand is based only on the sign of the numeric representation of the operand. 4-5 EXPRESSIONS Table 4-5 Logical Operations, Truth Table When P is And Q is: True ----- .NOT.P False False ----- .NOT.P True True True P .AND. Q True True False P .AND. Q False False True P .AND. Q False False False P .AND. Q False True True P .OR. Q True True False P .OR. Q True False True P .OR. Q True False ,," , Then the Expression: P .OR. Q False . "" , ,. , ~ Is: ." '" , ~ '>' .. , y' ~ 'v , False y,,- '" ~ True True P .XOR. Q False True False P .XOR. Q True False True P . XOR. Q True False False P .XOR. Q False True True P .EQV. Q True True False P .EQV. Q False False True P. EQV. Q False False False P .EQV. Q True Examples Assume the following variables: variable REAL, RUN I,J,K DP,D L, A, B CPX,C Examples of valid logical variables are: Type Real Integer Double Precision Logical Complex expressions L.AND.B (RE"ACkI)"~"x6R'~"(Dp'+kf L.AND'.A.OR .. NOT. (I"":K) 4-6 consisting of the foregoing EXPRESSIONS Logical functions are performed on the full 36-bit binary processor representation of the operands involved. The result of a logical operation is found by performing the specified function, simultaneously, for each of the corresponding bits in each operand. For example, consider the expression A=C.OR.D, where C=1I456 and D=1I20l. The operation performed by the processor and the result are: Word Bits o Operand C 0 Operand D 0 Result A o 1 ---t.~ 24 o o o ... t:o t:o 25 26 o 0 0 0 o o 0 0 0 27 1 28 o 1 1 1 o 29 o o o 30 31 o o o 1 o 1 32 33 1 1 1 1 o o 34 35 1 0 o 1 1 1 Table 4-5 also illustrates all possible logical combinations of two one-bit binary operands (P and Q) and gives the result of each combination. Just read 1 for true and 0 for false. 4.2.1 Relational Expressions Relational expressions consist of two expressions combined by a relational operator. The relational operator permits the programmer to test, quantitatively, the relationship between two arithmetic expressions. The result of a relational expression is always a false value. logically true or In FORTRAN-20, you may write relational operators either as a 2-letter .mnemonic enclosed. within ,periods, e.g., .GT., or _sy~bplicallyusing; .thesymbols, ~, <, =_a~d #~ Table 4-6 lists both the mnemonic and symbolic forms of the relational operators and specifies the type of quantitative test performed by each operator. Table 4-6 Relational Operators and Operations Relation Tested Operators Mnemonic Symbolic .GT. .GE. .LT. .LE. .EQ. .NE. > >= < <= Greater than Greater than or equal to Less than Less than or equal to Equal to Not equal to -# 4-7 EXPRESSIONS Write relational expressions in the general form A(l) .OP.A(2), where A represents an arithmetic operand and .oP. is a relational operator. You may mix arithmetic operands of type precision in relational expressions. integer, real, and double You may compare complex operands using only the operators .EQ. (==) and .NE. (#) . Complex quantities are equal if the corresponding parts of both words are equal. Examples Assume the following variables: Variables Type REAL, RON I,J,K DP,D L,A,B CPX,C Real Integer Double Precision Logical Complex Examples of valid relational expressions consisting of variables are: the foregoing ( REAL) . GT . 10 I == 5 C.EQ.CPX Examples of invalid relational expressions consisting of the foregoing variables are: (REAL) .GT 10 (closing period missing from operator) C>CPX (complex operands can only be .NE. operators) combined by .EQ. Examples of valid expressions that use both logical operators to combine the foregoing variables are: and relational (I.GT.IO).AND·t(J<=K); «I*RON):;;~:(I/J» .OR*."K (I • AND. Kf#', ( (REAL) . OR. (RON) ) C:#CPX.OR.'R'ON 4-8 and EXPRESSIONS 4.3 EVALUATION OF EXPRESSIONS The following determine the order of computation of an expression: 1. the use of parentheses 2. an established hierarchy for the execution relational, and logical operations and 3. the location of operators within an expression. 4.3.1 of arithmetic, Parenthetical Subexpressions In an expression, all subexpressions written within parentheses are evaluated first. When parenthetical subexpressions are nested (one contained within another) the most deeply nested subexpression is evaluated first, the next most deeply nested subexpression is evaluated second, and so on, until the value of the. final parenthetical expression is computed. When more than one operator is contained by a parenthetical subexpression, the required computations are performed according to the hierarchy of assigned operators (Section 4.3.2). Example: The separate computations performed in evaluating the expression A+B/((A/B)+C)-C are: 1. Rl=A/B 2. 2=Rl+C 3. R3=B/R2 4. R4=R3-C S. RS=A+R4 where: Rl through RS represent the interim and final results computations performed. 4.3.2 Hierarchy of Operators The following hierarchy (order classes of FORTRAN operators: of execution) first, arithmetic operators, second, relational operators, and third, logical operators. 4-9 is assigned of the to the EXPRESSIONS Table 4-7 specifies the precedence operators of the foregoing classes. assigned to the individual With the exception of integer division and exponentiation, all operations on expressions 'or subexpressions involving operators of equal precedence are computed in any order that is algebraically correct. A sUbexpression of a given expression may be computed in any order. For example, in the expression (F(X) + A*B}, the function reference may be computed either before or after A*B. Table 4-7 Hierarchy of Operators Symbol or Mnemonic Class Level EXPONENTIAL First ** ARITHMETIC Second Third Fourth -(unary minus) and + (unary plus) *,/ +,- RELATIONAL Fifth ~~T.,~GE,.".LT~".LE., .EQ., .NE. or "> , >= , < ,~= , == , #, . LOGICAL Sixth Seventh Eighth 'Nint'h ,~, ~. ~ ~ ,."'>"' "'- .NOT. .AND. .OR . • EQV .. 1. ~X6if. Operations specifying integer division are evaluated from left to right. For example, the expression I/J*K is evaluated as if it had been written as (I/J}*K. But this left-to-right evaluation process can be overridden by parentheses. I/J*K(evaluated as(I/J) *K} does not equal I/(J*K} ,which is evaluated as written here. When a series of exponentiation operations occurs in an expression, it is evaluated in order from right to left. For example, the expression A**2**B is evaluated in the following order: first Rl = 2**B (intermediate result) second R2 = A**Rl (final result). Similarly, here too, parentheses alter the evaluation expression. (A**2}**B is evaluated in these two steps: first Rl = A**2 (intermediate result) second R2 = Rl**2 (final result) 4.3.3 of the Mixed Mode Expressions Mixed mode expressions are evaluated on a subexpression-by-subexpression basis, with the type of the results obtained converted and combined with other results or terms according : to the conversion procedures described in Table 4-2. 4-10 EXPRESSIONS Example Assume the following: Variable D X I,J Type Double-Precision Real Integer The mixed mode expression D+X* (I/J) is manner: 1.Rl I/J 2.R2 =X*Rl 3.R3 D+R2 evaluated in the following Rl is integer Rl is converted to type real and is multiplied to produce R2 by X R2 is converted to type double precision and is added to D to produce R3 where Rl and R2, and R3 represent the interim and respectively of the computations performed. 4.3.4 Use of Logical Operands in Mixed Mode Expressions final results When you use logical operands in mixed mode expressions, the value of the logical operand is not converted in any way to accommodate it to the type of the other operands in the expression. For example, in L*R, where L is type logical and R is type real, the expression is evaluated without converting L to type real. 4-11 CHAPTER 5 COMPILATION CONTROL STATEMENTS 5.1 INTRODUCTION You use compilation control statements to identify FORTRAN programs and to specify their termination. Statements of this type do not affect either the operations performed by the object program or the manner in which the object program is executed. The three compilation control statements descr ibed in this chapter are: . PROGRAM . state.ment I. ,"IN.CLUPE. statem~l'}t,: and END statement. 5.2 PROGRAM STATEMENT · This statement allows you to give the main program a name other than ,the compiler-assumed name "MAIN.". The general form of a PROGRAM statement is: PROGRAM name · where: name is a symbolic name that begins with an alphabetic character and contains a maximum of six characters. (Refer to Section 3.3 for a description of symbolic names. ) : The following rule governs the use of the PROGRAM statement: The PROGRAM statement must be the first statement in a program unit. (Refer to Section 2.4 for a discussion of the ordering of statements.) 5.3 INCLUDE STATEMENT This statement allows you to include code segments or predefined · declarations in a program unit without having them reside in the same i physical file as the primary program unit. The general form of the INCLUDE statement is i INCLUDE 'dev:filename.ext[proj,prog]/NOLIST' where: dev: is a device name. When no specified, DSK: is assumed. 5-1 device name is COMPILATION CONTROL STATEMENTS filename.ext is the filename and extension of the statements that you wish to include. The name of the file is required; the extension is optional. If you specify filename" only, .FOR is the assumed extension. If you specify the filename and period (filename.), the null extension is assumed. You may not specify wild (*) information. II [proj , pr og] is the project-programmer number. Your projectprogrammer number is assumed if none is specified. You cannot specify subdirectory information. /NOLIST is an optional switch indicating that the included statements are not to be included in the compilation listing. The following rules govern the use of the INCLUDE statement: 1. The INCLUDEd file may contain any legal statement except; another INCLUDE statement, or a statement that terminates the current program unit, such as the END, PROGRAM, FUNCTION, SUBROUTINE, or BLOCK DATA statements. 2. The proper placement of the INCLUDE statement within a program unit depends upon the types of statements to be INCLUDEd. (Refer to Section 2.4 for information on the. ordering of FORTRAN statements.) 3. The file(s) to be INCLUDEd must be on disk. Note that an asterisk (*) is appended to the line numbers of the INCLUDEd statements on the compilation listing, provided /NOLIST is. ; ~ot specified. 5.4 END STATEMENT Use this statement to show the physical end of subprogram. END is a nonexecutable statement. END statement is: a source program or The general form of an END The following rules govern the use of the END statement: 1. This statement must be the last source program or subprogram. :2. When used in a main program, the END statement implies a STOP statement operation; in a subprogram, END implies a RETURN statement operation. 3. You may label an END statement. 5-2 physical statement of a CHAPTER 6 SPECIFICATION STATEMENTS 6.1 INTRODUCTION Use specification statements to specify the type characteristics, storage allocations, and data arrangement. There are seven types of specification statements: 1. DIMENSION 2. Statements that explicitly specify INTEGER 3. IMPLICI'r 4. COMMON 5. EQUIVALENCE 6. EXTERNAL 7• PARAMETER: type, such as REAL or Specification statements are nonexecutable and conform to the ordering guidelines described in Section 2.4. 6.2 DIMENSION STATEMENT DIMENSION statements identify and allocate the space required for source program arrays. You may specify any number of subscripted array names as array declarators in a DIMENSION statement. The general form of a DIMENSION statement is DIMENSION Sl, S2, .•. ,Sn where Si is an array declarator. following form: name(max, ... ,max) or Array declarators are names of the name (min :m~x ' . ' .. ,min : max); where name is the symbolic name of the array, and each min:max represents the lower and, upper bounds of an array dimension. 6-1 value SPECIFICATION STATEMENTS min:max value for an array dimension may be either an integer constant or, if the array is a dummy argument to a subprogram, an integer variable. The value given the mlnlmum specification for a dimension must not exceed the value given the maximum specification. Minimum values of 1 with their following colon delimiters may be omitted from a dimension subscript. This is because minimum values are assumed to be ~ inth~ f~rst place. Examples DIMENSION EDGE (':"1:1,"4:8), NET (5,10,4), TABLE (567) DIMENSION TABLE (lAB:J,K,M,XO£tO) (where lAB, J, K, and M are of type integer). ~ ..O' 'h "« ' ~ Note that you may use a slash in place of a colon as the between the upper and lower bounds of an array dimension. delimiter Adjustable Dimensions When used within a subprogram, an array declarator may use type integer parameters· as dimension subscript quantities. The £ollowing rules govern the use of adjustable dimensions in a subprogram: 1. For single entry subprograms, the array name and each subscript variable must be given by the calling program as parameters when the subprogram is called. The subscript variables may also be in COMMON. 2. For multiple entry subprograms in which the array name is a parameter, any subscript variables may be passed. If all subscript variables are not passed or in COMMON, the value of the subscript as passed for a previous entry will be used. 3. The type of the arra~ dimension variables cannot within the program. 4. If the value of an array dimension variable is altered within the program, the dimensionality of the array will not be affected. 5. The original size of the array cannot exceed the array dimensions assigned within a subprogram, i.e., the size of an array is not dynamically expandable. Examples 27 SUBROUTINE SBR (ARRAY,Ml,M2,M3,M4) DIMENSION ARRAY (Ml:M2,M3:M4) DO 27 L=M3,M4 DO 27 K=Ml,M2 ARRAY (K,L)=VALUE CONTINUE END SUBROUTINE SBI (ARRl,M,N) DIMENSION ARRl(M,N) ARRl(M,N)=VALUE ENTRY SB2(ARRl,M) ENTRY SB3(ARRl,N) ENTRY SB4JARRl) > 6-2 be altered SPECIFICATION STATEMENTS In the foregoing c~~mplc, the first call made to the subroutine must be made to SBI. Assuming that the call is made at SBI with the values M=ll and N=13, any succeeding call to SB2 should give M a new value. If a succeeding call is made to SB4, the last values passed through entries SBl, SB2, or SB3 will be used for M and N. Note that for the calling program of the form: CALL SBl(A,ll,13) M=15 CALL SB3(A,13) the value of M used in the dimensionality of the execution of SB3 will be 11 (the last value passed). 6.3 array for the TYPE SPECIFICATION STATEMENTS Type specification statements declare explicitly the data type of variable, array, or function symbolic names. You may give an array name in a type statement either alone (unsubscripted) to declare the type of all its elements or in a subscripted form to specify both its type and dimensions. write type specification statements in the following form: type list where type may be anyone of the following declarators: 1. INTEGER 2. REAL 3. DOUBLE PRECISION 4. COMPLEX 5. LOGICAL NOTE In order to be compatible with the type statements used by other manufacturers, the data type size modifier, *n, is accepted by FORTRAN-20. You may append this size modifier to the declarators, causing some to elicit messages warning users of the form of the variable specified by FORTRAN-20: 6-3 SPECIFICATION STATEMENTS Declarator Form of Variable Specified INTEGER*2 Full word integer with warning message INTEGER*4 Full word integer LOGICAL*l Full word logical with warning message LOGICAL*4 Full word logical REAL*4 Full word real REAL*8 Double-precision real COMPLEX*8 Complex COMPLEX*16 Complex with warning message In addition, you may append the data type size modifier to individual variables, arrays, or function names. Its effect is to override, for the particular element, the size modifier (explicit or implicit) of the primary type. For example, REAL*4 A, B*8, C*8(10), D A and D are single-precision (one full word) real, and Band Care double-precision (two full words) real. The list consists of any number of variable, array, or function names that are to be declared the specified type. The names listed must be separated by commas and can appear in only one type statement within a program unit. Examples INTEGER A, B, TABLE, FUNC REAL R, M, ARRAY (5:10,10:20,5) NOTE Variables, arrays, and functions of a source program, which are not typed either implicitly or explicitly by a specification statement, are typed by the following conventions: 1. Variable names, array names, and function names that begin with the letters I, J, K, L, M, or N are type integer. 2. Variable names, array names, and function names that begin with any letter other than I, J, K, L, M, or N are type real. If a name that is the same as a predefined FORTRAN-20 function name appears in a conflicting type statement, it is assumed that the name refers to a user-defined routine of the given type. If you place a generic function name in an explicit type statement, it loses its generic properties. 6-4 SPECIFICATION STATEMENTS 6.4 IMPLICIT STATHMHNTS IMPLICIT statements declare the data type of variables and functions IMPLICIT according to the first letter of each variable name. statements are written in the following form: IMPLICIT type (Al,A2, ... ,An), type (Bl,B2, ... ,Bn), ... ,type ..... As shown in the foregoing form statement, an IMPLICIT statement consists of one or more type declarators separated by commas. Each type declarator has the form type (Al,A2, ... ,An) where type represents one of the declarators listed in Section 6.3, and the parenthetical list represents a list of different letters. Each letter in a type declarator list specifies that each source program variable (not declared in an explicit type specification statement) starting with that letter is assigned the data type named in the declarator. For example, the IMPLICIT type declarator REAL (R,M,N,O) declares that all names that begin with the letters R, M, N, or a are type REAL names, unless declared otherwise in an explicit type statement. NOTE Type declarations given in an explicit type specification override those also given in an IMPLICIT statement. IMPLICIT declarations do not affect the FORTRAN supplied functions. You may specify a range of letters within the alphabet by writing the first and last letters of the desired range separated by a dash, e.g., A-E for A,B,C,D,E. For example, the statement IMPLICIT INTEGER (I,L-P) declares that all variables which begin with the letters I,L,M,N,O, and P are INTEGER variables. You may use more than one IMPLICIT statement, but they must appear before any other declaration statement in the program unit. Refer to Section 2.4 for a discussion on ordering FORTRAN statements. 6.5 COMMON STATEMENT The COMMON statement enables you to establish storage that may be shared by two or more programs and/or subprograms and to name the variables and arrays that are to occupy the common storage. The use of common storage conserves storage and provides a means to implicitly transfer arguments between a calling program and a subprogram. Write COMMON statements in the following form: COMMON/Al/Vl,V2, ... ,Vn ... /An/Vl,V2, ... ,Vn where the enclosed letters /Al/, ... , /An/ represent optional constructs (referred to as common block names when used). 6-5 name SPECIFICATION STATEMENTS The list (e.g., VI,V2 ... ,Vn) appearing after each name construct lists the names of the variables and arrays that are to occupy the common area identified by the construct. The items specified for a common area are ordered within the storage area as they are listed in the COMMON statement. Either label COMMON storage areas or leave them blank (unlabeled). If the common area is to be labeled, give a symbolic name within slashes immediately before the list of items that is to occupy the names area. For example, the statement COMMON/AREAI/A,B,C/AREA2/TAB(13,3,3) establishes two labeled common areas (i.e., AREAl and AREA2). Common block names bear no relation to internal variables or arrays that have the same name. If a common area is to be declared as unlabeled, give either nothing or two sequential slashes (//) immediately before the list of items that is to occupy blank common. For example, the statement COMMON/AREAI/A,B,C//TAB(3,3,3) establishes one labeled (AREAl) and one unlabeled Unlabeled common area is also called "blank common". common area. A given labeled common name may appear more than once in the same COMMON statement and in more than one COMMON statement within the same program or subprogram. Each labeled common area is treated as a separate, specific storage area. The contents of a common area, i.e., variables and arrays, may be assigned initial values by DATA statements in BLOCK DATA subprograms. Declarations of a given common area in different subprograms must contain the same number, size, and order of variables and arrays as the reference area. Items to be placed in a blank common area may also be given in statements throughout the source program. COMMON During compilation of a source program, FORTRAN will string together all items listed for each labeled common area and for blank common areas in the order in which they appear in the source program statements. For example, the series of source program statements: COMMON/STI/A,B,C/ST2/TAB(2,2)//C,D,E COMMON/STI/TST(3,4)//M,N COMMON/ST2/X,y,Z//O,P,Q has the same effect as the single statement COMMON/STI/A,B,C,TST(3,4)/ST2/TAB(2,2) ,X,Y,Z//C,D,E,M,N,O,P,Q All items specified for blank common are placed into one area. Items within blank common are ordered as they are given throughout the source program. Common block names must be unique with respect to all subroutine, function, and entry point names. The largest definition of a given common area must be loaded first. 6-6 SPECIFICATION STATEMENTS 6.5.1 Dimensioning Arrays in COMMON Statements Subscripted array names may be given in COMMON statements as array dimension declarators. However, variables cannot be used as subscript quantities in a declarator appearing in a COMMON statement; variable dimensioning is not permitted in COMMON. Each array name given in a COMMON statement must be dimensioned either by the COMMON statement or by another dimensioning statement within the program or subprogram that contains the COMMON statement but not both. Example COMMON /A/B(lOO) , C(lO,lO) COMMON X ( 5 , 15) ,Y ( 5 ) 6.6 EQUIVALENCE STATEMENT The EQUIVALENCE statement enables you to control the allocation of shared storage within a program or subprogram. This statement causes specific storage locations to be shared by two or more variables of either the same or different types. Write the EQUIVALENCE statement in the following form: EQUIVALENCE (Vl,V2, ... ,Vn) , (Wl,W2, ... ,Wn), (Xl,X2, ... ,Xn) where each parenthetical list contains the names of variables array elements that are to share the same storage locations. example, the statements and For EQUIVALENCE (A,B,C) EQUIVALENCE (LOC,SHARE(l)) specify that the variables named A, B, and C are to share the same storage location, and that the variable LOC and array element SHARE(l) are to share the same location. The relationship of equivalence is transitive; following statements have the same effect: for example, the two EQUIVALENCE (A,B), (B,C) EQUIVALENCE (A,B,C) When you use array elements in EQUIVALENCE statements, they must have either as many subscript quantities as dimensions of the array or only one subscript quantity. In either of the foregoing cases, the subscripts must be integer constants. Note that the single case treats the array as a one-dimensional array of the given type. You may use the items given in EQUIVALENCE statement and in following rules are observed: 1. an a EQUIVALENCE list in both COMMON statement providing You cannot set two quantities declared in a COMMON to be equivalent to one another. 6-7 the the statement SPECIFICATION STATEMENTS 2. Quantities placed in a common area by means of an EQUIVALENCE statement are permitted to extend the end of the common area forwards. For example, the statements COMMON/R/X,y,Z DIMENSION A(4) EQUIVALENCE (A,y) cause the common block R to extend from Z to A(4) arranged as follows: x Y A (I) Z A (2) A (3) (shared location) (shared location) A(4) 3. You cannot use EQUIVALENCE statements that cause the start of a common block to be extended backwards. For example, the invalid sequence COMMON/R/X,y,Z DIMENSION A(4) EQUIVALENCE{X,A(3)) would require A{l) and A(2) to extend the starting location of block R in a backwards direction as illustrated by the following diagram: t A (I) A (2) X A(3) Y A (4) Z 6.7 EXTERNAL STATEMENT Any subprogram name to be used as an argument to another subprogram must appear in an EXTERNAL statement in the calling subprogram. The EXTERNAL statement declares names to be subprogram names to distinguish them from other variable or array names. Write the EXTERNAL statement in the following form: EXTERNAL namel,name2, ... ,namen where each name listed is declared to be a subprogram name. desired, these subprogram names may be FORTRAN defined functions. If You may also use FORTRAN defined function names for your subprograms by prefixing the names by an asterisk (*) or an ampersand (&) within an EXTERNAL statement. For example, EXTERNAL *SIN, &COS 6-8 SPECIFICATION STATEMENTS declares SIN and COS to be user subprograms. (If a prefixed not a FORTRAN defined function, then the prefix is ignored.) name is Note that specifying a predefined FORTRAN function in an EXTERNAL statement without a prefix, i.e., EXTERNAL SIN, has no effect upon the usage of the function name outside of actual argument lists. If the name has generic properties, they are retained outside of the actual argument list. (The name has no generic properties within an argument list.) The names declared in a program EXTERNAL statement are reserved throughout the compilation of the program and cannot be used in any other declarator statement, with the exception of a type statement. 6.8 PARAMETER STATEMENT The PARAMETER statement allows you to during compilation. define constants symbolically The general form of the PARAMETER Statement is as follows: PARAMETER PI=Cl,P2=C2, ... where pi is a standard user-defined identifier section as a parameter name) (referred to in this Ci is any type of constant (including literals) except a label or complex constant. (Refer to Chapter 3 for a description of FORTRAN constants.) During compilation, the parameter names are replaced by their associated constants, provided the following rules are observed: 1. Place parameter names only within the statement field of an initial or continuation line type, i.e., not within a comment line or literal text. 2. Place parameter names only where constants are acceptable. 3. Place parameter name references after the PARAMETER statement definition. 4. Use parameter names that are unique with respect to all other names in the program unit. 5. Do not redefine statements. 6. Do not use parameter names as part of some larger syntactical construct (such as a Hollerith constant count or a data type size modifier). parameter 6-9 names in subsequent PARAMETER CHAPTER 7 DATA STATEMENT 7.1 INTRODUCTION DATA statements are used to supply the initial values of variables, arrays, array elements, and labeled common. (1) write DATA statements as follows: DATA Listl/Datal/,List2/Data2/, ... ,Listn/Datan/ where the List portion of each List/Data/ pair identifies a set of items to be initialized and the /Data/ portion contains the list of values to be assigned the items in the List. For example, the statement DATA IA/S/,IB/IO/,IC/1S/ initializes variable IA to the value S, variable IB to the value 10, and the variable IC to the value IS. The number of storage locations you specify in the list of variables must be less than or equal to the number of storage locations you specify in its associated list of values. If the list of variables is larger (specifies more storage locations) than its associated value list, a warning message is output. When the value list specifies more storage locations than the variable list, the excess values are ignored. The List portion of each List/Data/ set may contain the names of one or more variables, array names, array elements, or labeled common variables. You may specify an entire array (unsubscripted array name) or a portion of an array in a DATA statement List as an implied DO loop construct. (See Section 10.3.4.1 for a description of implied DO loops.) For example, the statement DATA (NARY(I),I=1,S)/1,2,3,4,S/ initializes the first five elements of array . NARY(2)=2, NARY(3)=3, NARY(4)=4, NARY(S)=S. NARY as NARY(l)=l, When you use an implied DO loop in a DATA statement, the loop index variable must be of type INTEGER and the loop Initial, Terminal, and Increment parameters must also be of type INTEGER. In a DATA statement, references to an array element must be integer expressions in which all terms are either integer constants or indices of embracing implied DO loops. Integer expressions of the foregoing types cannot include the exponentiation operator. The /Data/ portion of each List/Data/ set may contain one or more numeric, logical, ,literal, or octal constants and/or alphanumeric strings. 1. Refer t6 Section 6.S for a description of labeled common. 7-1 DATA STATEMENT ~ You must identify octal constants by ; quote (n) symbol, e.g, "777. preceding them with a double You may specify literal data as either a Hollerith specification, e.g., SHABCDE, or a string enclosed in single quotes, e.g., 'ABCDE'. Each ASCII datum is stored left-justified and is padded with blanks up to the right boundary of the variable being initialized. When you assign the same value to more than one item in List, a repeat specification may be used. Write the repeat specification as N*D where N is an integer that specifies how many times the value of item D is to be used. For example, a /Data/ specification of /3*20/ specifies that the value 20 is to be assigned to the first three items named in the preceding list. The statement DATA M,N,L/3*20/ assigns the value 20 to the variables M, N, and L. ; When the specified data type is not the same as that of the variable to which it is assigned, FORTRAN-20 converts the datum to the type of the variable. The type conversion is performed using the rules given for type conversion in arithmetic assignments. (Refer to Chapter 8, Table 8-1.) Octal, logical, and literal constants are not converted. Use Sample Statement DATA PRINT,I,O/'TEST' ,30,:1177/, (TAB(J) ,J=1,30)/30*S/ The first 30 elements of array TAB are initialized to S.O. DATA((A(I,J),I=1,S),J=l,6)/30*1.0/ No conversion required. DATA((A(I,J),I=S,10),J=6,lS)/60*2.0/ No conversion required. When a literal string is specified that is longer than one variable can hold, the string will be stored left-justified across as many variables as are needed to hold it. If necessary, the last variable used will be padded with blanks up to its right boundary. Example Assuming that X, Y, and Z are single-precision, the statement DATA X,Y,Z/'ABCDEFGHIJKL'/ will cause X to be initialized to 'ABCDE' Y to be initialized to 'FGHIJ' Z to be initialized to 'KL~~~' When a literal string is to be stored in double-precision and/or complex variables and the specified string is only one word long, the second word of the variable is padded with blanks. 7-2 DATA STATEMENT Example Assuming that the variable C is complex, the statement DATA C/'ABCDE ' , 'FGHIJ'/ will cause the first word of C to be initialized to 'ABCDE ' and its second word to be initialized to I~~~~~I. The string 'FGHIJ ' is ignored. 7-3 CHAPTER 8 ASSIGNMENT STATEMENTS 8.1 INTRODUCTION Use assignment statements to assign a specific value to one or more program variables. There are three kinds of assignment statements: 8.2 1. Arithmetic assignment statements 2. Logical assignment statements 3. Statement Label assignment (ASSIGN) statements. ARITHMETIC ASSIGNMENT STATEMENT You use statements of this type to assign specific numeric variables and/or array elements. Write arithmetic statements in the form values to assignment v=e where v is the name of the variable or array element that is to receive the specified value and e is a simple or compound arithmetic expression. In assignment statements, the equal symbol (=) does not imply equality as it would in algebraic expressions; it implies replacement. For example, the expression v=e is correctly interpreted as "the current contents of the location identified as v are to be replaced by the final value of expression e; the current contents of v are lost." When the type of the specified variable or array element name differs' from that of its assigned value, FORTRAN-20 converts the value to the type of its assigned variable or array element. Table 8-1 describes 1 the type conversion operations performed by FORTRAN-20 for each possible combination of variable and value types. 8-1 Table 8-1 Rules for Conversion in Mixed Mode Assignments Variable Type (v) Expression Type (e) Real Integer Complex Double-Precision Logical REAL D C R,I H,L D INTEGER C D R,C,I H/C/L D COMPLEX R C,R D prohibited R I > I til til H Cil ex> I DOUBLEPRECISION H C,H,L prohibited D H §! tzl Z 8 til t\.) LOGICAL D D R,I H,L D,H :;; 8 tzl 3: tzl OCTAL D D R,I H,C,L D LITERAL D,H% C,H% D& D& D% DOUBLE OCTAL* H H D# D H Z 8 til Table 8-1 (Cont.) Rules for Conversion in Mixed Mode Assignments Legend D Direct replacement C = Conversion between integer and floating-point with truncation R Real part only I Set imaginary part to 0 H High-order only L Set low-order part to 0 :J:>I til til H G) Z :::: tzl z Notes (X) 1-3 I w til 1-3 * Octal numbers with 13 to 24 digits are termed double octal. Double octals require two storage locations. They are stored right-justified and are padded with zeros to fill the locations. & Use the first two words of the literal. If the literal one word long, the second word is padded with blanks. % Use the first word of the literal. # To convert double octal numbers to complex, the low-order octal digits are assumed to be the imaginary part, and the high-order digits are assumed to be the real part of the complex value. is only ~ 1-3 tzl ::: tzl z 1-3 en ASSIGNMENT STATEMENTS 8.3 LOGICAL ASSIGNMENT STATEMENTS Use this type of assignment statement to assign values to variables and array elements of type logical. Write the logical assignment statement in the form v=e where v is one or more variables and/or array element names, and e a logical expression. is Examples Assuming that the variables L, F, M, and G are of following statements are valid: type logical, the Sample Statement L=.TRUE. The contents of L is replaced by logical truth. F=.NOT.G The contents of L is replaced by the logical complement of the contents of G. M=A.GT.T or M=A)T If A is greater than T, the contents of M is replaced by logical truth: if A is less than or equal to T, the contents of M is replaced by logical false. This can also be read: If A is greater than T, then M is true, otherwise, M is false. L= ( (I. GT. H)' • AND. (J<=K) ) The contents of L are replaced by either the true or false resultant of the expression. 8.4 ASSIGN (STATEMENT LABEL) ASSIGNMENT STATEMENT Use the ASSIGN statement to assign a statement label constant, i.e., a 1- to 5-digit statement number, to a variable name. Write the ASSIGN statement in the form ASSIGN n TO I where n represents the statement number and I is a variable name. example, the statement For ASSIGN 2000 TO LABEL specifies that the variable 2000. LABEL represents the. statement with the exception of complex and double-precision, you type of variable in an ASSIGN statement. may number use any Once a variable has been assigned a statement number, FORTRAN-20 will consider it a label variable. If a label variable is used in an arithmetic statement, the result will be unpredictable. 8-4 ASSIGNMENT STATEMENTS Use the ASSIGN statement in conjunction with assigned GO TO control statements (Chapter 9). The ASSIGN verb sets up statement label variables that are then referenced in subsequent GO TO control statements. The following sequence illustrates the use of the ASSIGN statement: 555 TAX=(A+B+C) *.05 ASSIGN 555 TO LABEL GO TO LABEL 8-5 CHAPTER 9 CONTROL STATEl·tENTS 9.1 INTRODUCTION FORTRAN object programs normally execute statement-by-statement in the order in which they were presented to the compiler. The following source program control statements, however, enable you to alter the normal sequence of statement execution: 9.2 1. GO TO 2. IF 3. DO 4. CONTINUE 5. STOP 6. PAUSE GO TO CONTROL STATEMENTS There are three kinds of GO TO statements: 1. Unconditional 2. Computed 3. Assigned A GO TO control statement causes the statement that it identifies to be executed next, regardless of its position within the program. The following paragraphs describe each type of GO TO statement. 9.2.1 Unconditional GO. TO Statements write GO TO statements of this type in the form GO TO n where n is the label, i.e., statement number, of an executable statement, e.g., GO TO 555. When executed, an unconditional GO TO statement transfers control of the program to the statement that it specifies. 9-1 CONTROL STATEMENTS You may position an unconditional GO TO statement anywhere in source program except as the terminating statement of a DO loop. 9.2.2 the Computed GO TO Statements Write GO TO statements of this type in the form GO TO (Nl,N2, ••• ,Nk)E where the parenthesized list is a list of statement numbers and E is an arithmetic expression. You may include any number of statement numbers in the list of this type of GO TO statement; however, each number you give must be used as a label within the program or subprogram containing the GO TO statement. NOTE A comma may optionally parenthesized list. follow the The value of the expression E must be reducible to an integer value that is greater than 0 and less than or equal to the number of statement numbers given in the statement list. If the value of the expression E does not compute within the foregoing range, the next statement is executed. When a computed GO TO statement is executed, the value of its expreSS1on, i.e., E, is computed first. The value of E specifies the position within the given list of statement numbers of the number that identifies the statement to be executed next. For example, in the statement sequence GO TO (20, 10, 5)K CALL XRANGE(K) the variable K acts as a switch, causing a transfer to statement 20 if K=l, to statement 10 if K=2, or to statement 5 if K=3. The subprogram XRANGE is called if K is less than 1 or greater than 3. 9.2.3 Assigned GO TO Statements Write GO TO statements of this type in either of the following forms: GO TO K GO TO K, (Ll,L2, ••• Ln) where K is a variable name and the parenthesized list of the second form contains a list of statement labels, i.e., statement numbers. The statement numbers you give must be within the program or subprogram containing the GO TO statement. Assigned GO TO statements of either foregoing form must be logically preceded by an ASSIGN statement that assigns a statement label to the variable name represented by K. The value of the assigned label variable must be in the same program unit as the GO TO statement in which it is used. In statements written in the form GO TO K, (Ll,L2, ••• Ln) 9-2 CONTROL STATEMENTS if K is not assigned one of the statement numbers given statement list, the next sequential statement is executed. in the logical, and Examples GO TO STATI GO TO STATl, (177,207,777) 9.3 IF STATEMENTS There are three kinds of logical two-branch. 9.3.1 IF statements: arithmetic, Arithmetic IF Statements Write IF statements of this type in the form IF(E)Ll,L2,L3 where (E) is an expression enclosed within parentheses and Ll, L2, L3 are the labels, i.e., statement numbers, of three executable statements. This type of IF statement transfers control of the program to one of the given statements according to the computed value of the given expression. If the value of the expression is: 1. Less than 0, control identified by Ll; is transferred to the statement 2. Equal to 0, control identified by L2; is transferred to the statement 3. Greater than 0, control identified by L3. the statement is transferred to You must give all three statement numbers in arithmetic IF statements; the expression given may not compute to a complex value. Examples Sample Statement IF (E TA) 4, 7, 12 Transfers control to statement 4 if ETA is negative, to statement 7 if ETA is 0, and to statement 12 if ETA is greater than O. IF(KAPPA-L(10))20, 14, 14 Transfers control to statement 20 if KAPPA is less than the 10th element of array L and to statement 14 if KAPPA is greater than or equal to the 10th element of array L. 9-3 CONTROL STATEMENTS NOTE You must label the statement following an arithmetic IF; otherwise the statement can never be executed. 9.3.2 Logical IF Statements Write IF statements of this type in the form IF(E)S where E is any expression enclosed in parentheses and S is a executable statement. complete Logical IF statements transfer control of the program either to the next sequential executable statement or to the statement given in the IF statement, i.e., S, according to the computed logical value of the given expression. If the value of the given logical expression is true (negative), control is given to the. executable statement within the IF statement. If the value of the expression is false (positive or zero), control is transferred to the next sequential executable program statement. The statement you give in a logical IF statement may be any executable statement except a DO statement or another logical IF statement. Examples Sample Statement 9.3.3 IF (T.OR.S) X=Y+l Performs an arithmetic replacement operation if the result of IF is true. IF (Z.GT.X(K)) CALL SWITCH(S,Y) Performs a subroutine call the result of IF is true. IF (K.EQ.INDEX) GO TO 15 Performs transfer is true. if an unconditional if the result of IF Logical Two-Branch IF Statements Write IF statements of this type in the form IF (E) Nl, N2 where E is any expression, and Nl and N2 are statement labels within the program unit. defined Logical two-branch IF statements transfer control of the program to either statement Nl or N2, depending on the computed value of the given expression. If the value of the given logical expression is true (negative), control is transferred to statement Nl. If the value of the expression is false (positive or zero), control is transferred to statement N2. 9-4 CONTROL STATEMENTS Note that you must number the statement immediately following the logical two-branch IF so that control can later be transferred to the portion of code that was skipped. Examples Sample Statement 9.4 IF (LOGl) 10,20 Transfers control to statement 10 if LOGI is negative; otherwise transfers control to statement 20. IF (A.LT.B.AND.A.LT.C) 31,32 Transfers control to statement if A is less than both Band transfers control to statement if A is greater than or equal either B or C. 31 C; 32 to DO STATEMENT DO statements simplify the coding of iterative procedures; in the following form: write them Indexing Parameters DO N I ~ = Ml,M2,M3 ~fL ~~ TERMINAL STATEMENT LABEL INDEX VARIABLE PARAMETER TERMINAL PARAMETER INI-TIAL PARAMETER where 1. Terminal Statement Label N is the statement number of the last statement of the DO statement range. The range of a DO statement is defined as the series of statements that follows the DO statement up to and including its specified terminal statement. 2. Index Variable I is an unsubscripted variable whose value is defined at the start of the DO statement operations. The index variable is available for use throughout each execution of the range of the DO statement, but its value should not be altered within this range. It is also available for use in the program when: a. control is transferred outside the range of the DO loop by a GO TO, arithmetic IF or RETURN statement located within the DO range, b. a CALL is executed from within the DO statement that uses the index variable as an argument, and 9-5 range CONTROL STATEMENTS c. if an input-output statement with either or both the options END= or ERR= (Chapter 10) appears within the DO statement range. 3. Initial Parameter Ml assigns the index variable, I, its initial value. This parameter may be any variable, array element, or expression. 4. Terminal Parameter M2 provides the value that determines how many repetitions of the DO statement range are performed. 5. Increment Parameter M3 specifies the value to be added to the initial parameter (Ml) on completion of each cycle of the DO loop. If M3 and its preceding comma are omitted, M3 is assumed to be equal to 1. An indexing parameter may be any: ar ifhme'E:i.c expression resul ting in either a positive or negativ~- ~~lti~: "The values of the indexing parameters are calculated only once, at the start of each DO-loop operation. The number of times that a DO loop will execute is specified by the formula: MAX(l, ((M2-Ml)/M3)+1) Since the count is computed at the start of a DO loop operation, changing the value of the loop index variable within the loop cannot affect the number of times that the loop is executed. At the start of a DO loop operation, the index value is set to the value of the initial parameter (Ml), and a count variable (generated by the compiler) is set to the negative of the calculated count. At the end of each DO loop cycle, the value of the increment parameter (M3) is added to the index variable, and the count variable is incremented by 1. If the number of specified iterations has not been performed (i.e., if the count variable is still negative), another cycle of the loop is initiated. One execution of a DO loop range is always performed regardless of the initial values of the index variable and the indexing parameters. Exit from a DO loop operation on completion of the number of iterations specified by the loop count is referred to as a normal exit. In a normal exit, control passes to the first executable statement after the DO loop range terminal statement, and the value of the DO statement index variable is considered undefined. Exit from a DO loop may also be accomplished by a transfer of control by a statement within the DO loop range to a statement outside the range of the DO statement (Section 9.4.3). 9.4.1 Nested DO Statements One or more DO statements may be contained, i.e., nested, within the range of another DO statement. The following rules govern the nesting of DO statements. 9-6 CONTROL STATEMENTS 1. The range of each nested DO statement must be entirely within the range of the containing DO statement. Example Valid Invalid 001 DO 1 ~~ 2. The range of DO 2 is outside that of DO 1. The ranges of nested DO statements cannot overlap. Example Valid Invalid 001 DO 1 002 002 c= ~ C 003 3. The ranges of loop DO 2 and DO 3 overlap. More than one DO loop within a nest of DO loops may end on the same statement •• When this occurs, the terminal statement is considered to belong to the innermost DO statement that ends on that statement. The statement label 4 of the shared terminal statement cannot be used in any GO TO or arithmetic IF statement that occurs anywhere other than within the range of the DO statement to which it belongs. Example 004 All the DO statements share the same terminal statement, however, it belongs to the first DO 4. 004 004 9-7 CONTROL STATEMENTS 9.4.2 Extended Range The extended range of a DO statement is defined as the set of statements that execute between the transfers out of the innermost DO statement of a set of nested DOs and the transfer back into the range of this innermost DO statement. The extended range of a nested DO statement is as follows: DO 1 002 003 Extended- Range The following rules govern the use of a DO statement extended range: 1. The transfer out statement for an extended range operation must be contained by the most deeply nested DO statement that contains the location to which the return transfer is to be made. 2. A transfer into the range of a DO statement is permitted only if the transfer is made from the extended range of that DO statement. 3. The extended range of a DO statement must not contain another DO statement. CONTROL STATEr·tENTS 4. The extended range of a DO statement cannot change the variable or inde.xing parameters of the DO statement. 5. You may use and return from a subprogram within range. 9.4.3 an index extended Permitted Transfer Operations The following rules govern the transfer of program control from within a DO statement range or the ranges of nested DO statements: 1. A transfer out of the range of any DO loop is permitted at any time. When such a transfer executes, the value of the controlling DO statement's index variable is defined as the current value. 2. A transfer into the range of a DO statement is permitted it is made from the extended range of the DO statement. if 3. You may use and return from range of any: the a. b. c. a subprogram from within DO loop, nested DO loop, or extended range loop (in which you leave the loop via a GO TO, execute statements elsewhere, and return to the original loop). The following examples illustrate the transfer from within the ranges of nested DO statements: Valid Transfers Dl D2 • + extended range [ ~4-<I- - , ' Invalid Transfer Dl 9-9 operations permitted CONTROL STATEMENTS 9.5 CONTINUE STATEMENT You may place CONTINUE statements anywhere in the source program without affecting the program sequence of execution. CONTINUE statements are commonly used as the last statement of a DO statement range in order to avoid ending with a GO TO, PAUSE, STOP, RETURN, arithmetic IF, another DO statement, or a logical IF statement containing any of the foregoing statements. Write this statement as 12 CONTINUE Example In the following sequence, the labeled CONTINUE statement legal termination for the range of the DO loop. provides a DO 45 ITEM=l,lOOO STOCK=NVNTRY (ITEM) CALL UPDATE (STOCK,TALLY) IF (ITEM.EQ.LAST) GO TO 77 45 CONTINUE 77 PRINT 20, HEADING,PAGENO 9.6 STOP STATEMENT Execution of the STOP statement causes the execution of the object program to be terminated and returns control to the monitor. A descriptive message may optionally be included in the STOP statement to be output to your I/O terminal immediately before program execution is terminated. Write this statement like this: STOP :'8,'1'01',' 'N I or where 'N' is a string of ASCII characters enclosed by single quotes and n is an octal string up to 12 digits. The string N or the value n is printed at your I/O terminal when the STOP statement executes. The' string N may be of any length. (Continuation lines may be used for 1 arge messages.) 9-10 CONTROL STATEMENTS Examples STOP 'Termination of the Program' or STOP 7777 9.7 PAUSE STATEMENT Execution of a PAUSE statement suspends the execution program and gives you the option to: 1. Continue execution of the program 2. Exi t 3. Initiate a TRACE operation (Section 9.7.1). of the object The permitted forms of the PAUSE statements are: 1. PAUSE 2. PAUSE 'literal string' 3. PAUSE n, where n is an octal string up to 12 digits. Execution of a PAUSE statement of any of the the standard instruction: foregoing forms caUSes TYPE G TO CONTINUE, X TO EXIT, T TO TRACE to be printed at your terminal. If the form of the PAUSE statement contains either a literal string or an integer constant, the string or constant prints on a line preceding the standard message. For example, the statement PAUSE 'TEST POINT A' causes the following to be printed at your terminal: TEST POINT A TYPE G TO CONTINUE, X TO EXIT, T TO TRACE The statement PAUSE 1 causes the following to be printed at your terminal: PAUSE 000001 TYPE G TO CONTINUE, X TO EXIT, T TO TRACE 9-11 CONTROL STATEMENTS 9.7.1 T(TRACE) Option , The entry of the character T in response to the message output by the execution of a PAUSE statement starts a TRACE routine. This routine causes a complete history of all subroutine calls made during the execution of the program, up to the execution of the PAUSE statement to be printed at your terminal. The history printed by the TRACE routine consists of: 1. The names of all subroutines called, arranged in the order of their call; reverse 2. The absolute location (written called subroutine; of 3. The name of the calling subroutine plus an offset factor and the absolute location (written within parentheses) of the statement within the routine that initiated the calli 4. The number brackets); within angle 5. An alphabetic code (written within square brackets) specifies the types of each argument involved. alphabetic codes used and the meaning of each are: that The of arguments within involved L I F o S D C K (written the Type Specified Code Char acter. U parentheses) Undefined typei the use of the argument will determine its type. Logical INTEGER Single-precision REAL Octal Statement Number Double-precision REAL COMPLEX A literal or constant : Example ,The following printout illustrates the execution of the PAUSE : statement "PAUSE 'TEST POINT AI", the entry of a T character to initiate the TRACE routine, the resulting trace printout, and the , entry of the character G to continue the execution of the program. TEST POINT A TYPE G TO CONTINUE, X TO EXIT, T TO TRACE. *T NAME (LOC) «--- CALLER (LOC) <#ARGS> [ARG TYPES] TRACE. (414056) «--PAUSe +141 (376) <#1> [U] PAUSe (235) «--- MAIN.+4(151) <#1> [U] TYPE G TO CONTINUE, X TO EXIT, T TO TRACE. *G 9-12 CONTROL STATEMENTS In addition to its use with the PAUSE s\:.a\:.emenl:, TRACE routine directly, using the form you hlay call the CALL TRACE or as a function, using the form X=TRACE(x) Execution of the foregoing statements starts the TRACE routine, which prints the history of all subprogram calls made during the execution of the program, up to the execution of the CALL statement or up to the execution of the function, respectively. The history printed by the TRACE routine under these circumstances is as described in the preceding paragraph. 9-13 CHAPTER 10 I/O STATEMENTS 10.1 DATA TRANSFER OPERATIONS FORTRAN I/O statements permit the transfer of data between processor 'storage (memory) and peripheral devices and/or between storage locations. Data in the form of logical records may be transferred by use of an a) sequential, b) random access, c) append ,transfer mode, or d) dump mode., The areas in memory from which data is to be taken during output (write) operations and into which data is stored during input (read) operations are specified by: 1. A list in the I/O statement that initiated the transfer 2. A list defined by a NAMELIST statement, or 3. Between a specified FORMAT statement and the external medium. The type and arrangement of transferred data may be specified by format specifications located in either a FORMAT statement or an array (formatted I/O), or by the contents of an I/O list (list-directed I/O). The following sections describe the statements required to initiate I/O transfer operations. 10.2 and data format TRANSFER MODES The characteristics and requirements of the a) sequential, b) random access, and c) append data modes are described in the following paragraphs. 10.2.1 Sequential Mode Records are transferred during a sequential mode of operation in the same order they appear in the external data file. Each I/O statement executed ln a sequential mode transfers the record immediately following the last record transferred from the accessed source file. 10.2.2 Random Access Mode This mode permits access to and transfer of records from a file in any desired order. Random access transfers, however, may be made only to (or from) a device that permits random-type data addressing operations, i.e., disk, and to files that have previously been set up 10-1 I/O STATEMENTS for random access transfer operation. Files for random access must contain a specified number of identically sized records that may be · accessed, individually, by a record number. You may use the FORTRAN-20 OPEN statement - see Chapter 12 · subroutine call to DEFINE FILE to set up random access files. or a Use the OPEN statement to establish a random access mode to permit the · execution of random access data transfer operations. The OPEN statement should logically precede the first I/O statement for the 'specified logical unit in the user source program. 10.2.3 Append Mode · This mode is a special version of the sequential transfer mode: Use · it only for sequential output (write) operations. The append mode permits you to write a record immediately after the last logical · record of the accessed file. During an append transfer, the records already in the accessed file remain unchanged. The only function performed is the appending of the transferred records to the end of the file. · You must use an OPEN statement to establish · append I/O operations can be executed. 10.3 an append mode before I/O STATEMENTS, BASIC FORMATS AND COMPONENTS The majority of the I/O statements described in this chapter are written in one of the following basic forms or in some modification of these forms: Use Basic Statement Forms Keyword (u,f}list K~yw~rd (u#R,tjlist Keyword (u,*}list Keyword (u,N) Keyword (u}list : keyword (u#R)list F.orma t ted I/O Transfer... ... Random Access Formatted I/O Transfer List-Directed I/O Transfer NAMELIST-Controlled I/O Transfer Binary I/O Transf~r ~and~m_Acceis-Binary I/b fianife~ where Keyword the statement name (READ or WRITE) u logical unit number f list FORMAT statement number in the current program unit or the name of an array that contains the desired format specifications I/O list #R = the delimiter # followed by the number record in an established random-access file * = symbol specifying a list-directed I/O transfer N = the name of an I/O list statement defined by a of NAMELIST The following paragraphs provide details of the foregoing components. 10-2 a I/O STATEHENTS 10.3.1 I/O Statement Keywords The keywords (names) of the FORTRAN-IO this chapter are: 1. 2. 3. 4. 5. 10.3.2 READ REREAD ACCEPT FIND DECODE 6. 7. 8. 9. I/O statements described in WRITE PRINT TYPE ENCODE FORTRAN Logical Unit Numbers Decimal numbers identify the physical devices used for most FORTRAN I/O operations. During compilation, the compiler assigns default logical unit numbers for the REREAD, READ, ACCEPT, PRINT, and TYPE statements. Default unit numbers are negatively signed decimal numbers that you cannot access. You may make the logical device assignments at run time, or you may use the standard assignments contained by the FORTRAN-20 Object Time System (FOROTS). Table 10-1 lists the standard logical device assignments. We recommend that you specify the device explicitly in the OPEN statement. 10.1.3 FORMAT Statement References A FORMAT statement contains a set of format specifications that defines the structure of a record and the form of the data fields comprising the record. Format specifications may also be stored in an array rather than in a FORMAT statement. (Refer to Chapter 13 for a complete description of the FORMAT statement.) The execution of an I/O statement that includes either a FORMAT statement number or the name of an array that contains format specifications causes the structure and data of the transferred record to assume the form specified in the referenced format. Records transferred under the control of a format specification are referred to as "formatted" records. Conversely, records transferred by I/O statements that do not reference a format specification are referred to as "unformatted" records. During unformatted transfers, data is transferred on a one-to-one correspondence between internal (processor) and external (device) locations, with no conversion or formatting operations. Unformatted files are binary files divided into records by FORTRAN-20 embedded control words; the control words are invisible to you. You cannot prepare files of this type without using FOROTS. Unformatted files are for use only within the FORTRAN environment. 10-3 Table 10-1 FORTRAN-20 Logical Device Assignments Device/Function Default Filename FORTRAN Logical Unit Number Use Standard Devices* o DSK CDR LPT CTY TTY f-' o I ~ MTAO MTAl MTA2 FORTR DSK DSK DSK DSK DSK FORxx.DAT 00 01 02 03 04 05 06 through 15 not valid 16 ILLEGAL Disk Card Reader Line Printer Console Teletype User's Teletype *The total number of standard devices permitted is parameter. Magnetic Tape ! Assignable Device DISK j an o (J) 17 18 19 20 21 22 23 24 H ......... installation ~ J-3 ttl 3: ttl Z J-3 (J) Table 10-1 (Cont.) FORTRAN-20 Logical Device Assignments Device/Function Default Filename FORTRAN Logical Unit Number Use Standard Devices* DEVl DEV2 DEV3 DEV4 FORxx.DAT DE(S Assignable Devices 25 26 27 28 H 2( "o C/l ~ a I Ul DEV63 FOR63.DAT Disk 63 1-3 :t:t-:3 tI:l 3: tI:l Default Devices (inaccessible to the user) :z: t-:3 REREAD CDR TTY Current file FORCDR.DAT FORTTY.DAT LPT TTY FORLPT.DAT FORTTY.DAT REREAD statement READ statement ACCEPT statement Not Valid PRINT statement TYPE statement -6 -5 -4 -2 -3 -1 *The total number of standard devices permitted is parameter. an installation C/l I/O STATEMENTS 10.3.4 I/O List An I/O list specifies the names of variables, arrays, and array elements to which input data is to be assigned or from which data is to be output. Implied DO constructs (Section 10.3.4.1), which specify sets of array elements, may also be included in I/O lists. The number of items in a statement list determines the amount of data to be transferred during each execution of the statement. 10.3.4.1 Implied DO Constructs - When an array name is given in an I/O list, all elements of the array are transferred in the order described in Chapter 3 (Section 3.5.3). If only a specific set of array elements is involved, they may be specified in the I/O list either individually or in the form of an implied DO construct. Write implied DOs within parentheses in a format similar to that of DO statements. They may contain one or more variable, array, and/or array element names, delimited by commas and followed by indexing parameters that are defined as for DO statements. The general form of an implied DO is (name{SL) ,I=Ml,M2,M3) where name an array name SL the subscript list element identifier I the index control variable that may represent a subscript appearing in a preceding subscript list Ml,M2,M3 the indexing parameters that specify, respectively, the initial, terminal, and increment values that control the range of I. If M3 is omitted (with its preceding comma), a value of 1 is assumed. of an array or an array Examples S must be an integer variable (A{S) ,S=1,5) Specifies the first five elements of the one-dimension array A, i.e., A{l), A(2), A(3), A(4), A(5). (A{2,S) ,S=1,10,2) Specifies the elements A{2,l), A{2,3), A{2,5), A{2,7), A{2,9) of array A. (I, 1=1 , 5) Specifies the integers 1,2,3,4, and 5. As stated previously, implied DO constructs may also more variable names. contain one or Example (B and C must be integer variables): ({A{B,C) ,B=l,lO),C=l,lO) ,I,J Specifies a 10 X 10 set of elements of array A, the location identified by I, and the location identified oy J. 10-6 I/O STATEMENTS You may also nest implied DO constructs. one or more sets of indexing parameters. Nested implied DOs may share Example ((A(J,K),J=1,5) ,D(K) ,K=l,lO) Specifies a 5 X 10 set of elements of array A and the first 10 elements of array D. When you specify an array or set of array elements as either a storage or transmitting area for I/O purposes, the array elements involved are accessed in ascending order with the value of the first subscript quantity varying most rapidly and the value of the last given subscript increasing to its maximum value least rapidly. For example, the elements of an array dimensioned as TAB(2,3) are accessed in the order: TAB(l,l) TAB(2,l) TAB(1,2) TAB(2,2) TAB(1,3) TAB(2,3) 10.3.4.2 Formatted Record Handling - Data is processed under format control so that each item in the I/O list is matched with a field descriptor in the FORMAT statement. If the end of the FORMAT specification is reached and more items remain in the I/O list, a new line or record is established and the data processing is restarted, either: 1. at the first item in the FORMAT specification or, 2. (if parenthesized sets of FORMAT specifications exist within the FORMAT specification) with the last set within the FORMAT specification. On input, if the record is exhausted before the data transfers are completed, the remainder of the transfer is completed as if the record were extended with blanks. See Section 13.2.2 for more details. 10.3.5 Specification of Records for Random Access You must identify records to be transferred in a random access mode in an I/O statement by an integer expression or variable preceded by an apostrophe used as a delimiter, e.g., 1101. NOTE You may use a pound sign (#) in place of the apostrophe (I), e.g., both #101 and '101 are accepted by FORTRAN-20. 10-7 I/O STATEMENTS 10.3.6 List-Directed I/O 'The use of an asterisk in an I/O statement in place of a FORMAT 'statement number causes the specified transfer operation to be "list-directed". In a list-directed transfer, the data to be 'transferred and the type of each transferred datum are specified by ,the contents of the I/O list included in the I/O command used. The · transfer of data in this mode is performed without regard for column, ,card, or line boundaries. The list-directed mode is specified by the substitution of an asterisk (*) for the FORMAT statement reference, i.e., f, of an I/O statement. The general form of a list-directed I/O statement is keyword (u,*}list : Example READ (5,*)I,IAB,M,L · You may use list-directed transfers to read data from · input device, including an input keyboard terminal. any acceptable NOTE Do not use device positioning commands, such as BACKSPACE, SKIP RECORD, etc., in conjunction with list-directed I/O operations. If you do, the results are unpredictable. Data for list-directed transfers should consist of alternate constants • and delimiters. The constants used should have the following , characters: 1. Input constants must be of a type acceptable to FORTRAN-20. Octal constants, although acceptable, are not permitted in list-directed I/O operations. 2. Literal constants must be enclosed within single quotes, e.g., 'ABLE'. A quoted string which is too long to fit in one element of the input list will be placed in adjacent elements and will be padded with blanks. If a quoted string is being placed in an array and it fills more than one element of the array, the remaining elements of the array will be unchanged. In this case, it is assumed that the user meant for the long string to go into the array and for any following data to go into the rest of the input list. If the string fits into one element of the array, the array will continue to be filled. 3. Blanks are delimiters; therefore, they are not permitted any but literal constants. 4. You may omit decimal points from real constants that do not have a fractional part. FORTRAN-20 assumes that the decimal point follows the rightmost digit of a real constant. 5. Complex constants must be enclosed in parentheses. 10-8 in I/O STATEMENTS Delimiters in data following: for list-directed input must comply with the 1. Delimiters may be either commas or blanks. 2. Delimiters may be either preceded by or followed by any number of blanks, carriage return/line feed characters, tabs, or line terminators; any such combination is considered by FORTRAN-20 as being only a single delimiter. 3. Represent a null (the complete absence of a datum) by two consecutive commas that have no intervening constant(s). You may place any number of blanks, tabs, carriage return/line feed characters, or end-of-input conditions between the commas of a null. Each time you specify a null item in the input data, its corresponding list element is skipped (unchanged). The following illustrates the effect of a null input: INPUT Items 101, 'A ,tab, 'NOl', I I I I / Corresponding I/O List Items \ 'Lr'7B'NjBER Resulting Contents of List Items 101.A un- NOI changed lAB 4. Slashes (/) cause the current input operation to terminate even if all the items of the directing list are not filled. The contents of items of the directing I/O list that either are skipped (by null inputs) or have not received an input datum before the transfer is terminated remain unchanged. Once the I/O list of the controlling I/O statement is satisfied, the use of the / delimiter is optional. 5. Once the I/O list has been satisfied (values have been transferred to each item of the list), any items remaining in the input record are skipped. Constants or nulls in data for list-directed input may be repetition factor so that an item is repeated. assigned a The repetition of a constant is written as r*K where r is an integer constant that specifies the number of times . constant represented by K is to be repeated. the The repetition of a null is written asterisk. an as an integer Examples 10*5 3*'ABLE' 3* represents 5,5,5,5,5,5,5,5,5,5 represents 'ABLE', 'ABLE', 'ABLE' represents null,null,null 10-9 followed by I/O STATEMENTS 10.3.7 NAMELIST I/O Lists You may define one or more lists by a NAMELIST statement (Chapter 11). Each I/O list defined in a NAMELIST statement is identified by a unique (within the routine) 1- to 6-character name that may be referenced by one or more READ or WRITE statements. The first character of each I/O list name must be alphabetic. By using the NAMELIST statement, you eliminate the need for specifying the entire I/O list. I/O statements that reference a NAMELIST-defined I/O list cannot contain either a FORMAT statement reference or an I/O list. You canno~ use NAMELIST-controlled I/O operation to transfer octal numbers or literal strings. You may use only NAMELIST-controlled READ/WRITE statements to bring in/write out records formatted in the following manner. Format records for NAMELIST-controlled input operations as follows: $NAME Dl,D2,D3 ... Dn$ \vhere 1. $ symbols delimit the beginning and end of the record. The first $ must be in column 2 of the input record; column 1 must be blank. 2. NAME is the name of a NAMELIST-defined input list. The named list identifies the processor storage locations that are to receive the data items read from the accessed record. 3. Dl through Dn are pairs of the form "variable=value" the value is assigned to the associated variable. items cannot be octal numbers or literal strings. where These NOTE Do not use device positioning commands such as BACKSPACE, SKIP RECORD, etc., in conjunction with NAMELIST-controlled I/O operations. If you do, the results are unpredictable. See Chapter 11 for more information on NAMELIST I/O transfers. 10. 4 OPTIONAL READ/WRITE ERROR EXIT AND END-OF-FILE ARGUr.lENTS You may optionally add either or both an error exit or an end-of-file argument to the portion in parentheses of any form of the READ and WRITE statements when a unit is specified. Write the error exit argument as ERR=c where c is a statement number in the current program unit. Using this argument terminates the current I/O operation and transfers program control to the statement identified by the argument if an error is detected. For example, the detection of an error during the execution of READ(10,77,ERR=101)TABLE,I,M,J 10-10 I/O STl\TEMENTS terminates the input operation anu transfers program control to statement 101. See the Library Subroutine ERRSNS (Chapter 15) to find out how to identify the actual error that occurred. When an ERR= transfer occurs, all items on the input list and implied DO indexes on input or output lists become undefined. all Write the end-of-file argument as END=d, where d is a statement number in the current program unit. This branch, when taken, stops the current I/O operation and transfers program control to the statement identified by the argument. In the example below, the detection of an end-of-file condition during the execution of READ(10,77,END=50)TABLE,I,M,J results in the transfer of control to statement 50. When an END= transfer occurs, all items on the input list receive the value zero and all implied DO indices on input lists become undefined. If the END= argument is not present, but an ERR= argument is, an end-of-file (EOF) condition is treated as a user-trappable error. If neither the ERR= nor the END= argument is present and an end-of-file condition is detected, a message is printed, the file is closed, program execution is terminated, and control is returned to the monitor. 10.5 READ STATEMENTS READ statements transfer data from peripheral devicgs into specified processor storage locations. The permitted forms of this type of input statment permit READ statments to be used in both sequential and random access transfer modes for formatted, unformatted, list-directed, and NAMELIST-controlled data trans 10.6 SEQUENTIAL FORMATTED READ TRANSFERS Descriptions of the READ statements that sequential transfer of formatted data follow: 1. 2. may be used for the Form: READ (u,f)list Use: Input data from logical unit u, formatted according to the specification given in f, into the processor storage locations identified in input list. Example: READ (10,555)TABLE(10,20) ,ABLE, BAKER, CHARL Fo rm: READ (u, f) Use: Input the data from logical unit u directly into either a Hollerith (H) field descriptor or a literal field descriptor given within the format specifications of the referenced FORMAT statement. If the referenced FORMAT statement does not contain either of the foregoing types of format field descriptors, the input record is skipped. If a required field descriptor is present, its contents are replaced by the input data. Example: READ{15,101) 10-11 I/O STATEMENTS 3. 4. 10.6.1 Form: READ f Use: Input the data from the READ default device (card reader) directly into either a Hollerith (H) field descriptor or a literal field descriptor given within the format specifications of the referenced FORMAT statement. If the referenced FORMAT statement does not contain either of the foregoing types of format field descriptors, the input record is skipped. If a required field descriptor is present, its contents are replaced by the input data. Example: READ 66 Form: READ f,list Use: Input the data from the READ default device (card reader) into the processor storage locations identified in the input list. The input data is formatted as specified in f. Example: READ 15, ARRAY (20,30) Sequential Unformatted Binary READ Transfer You may use only the following form of the READ statement for sequential transfer of unformatted input of FORTRAN binary data: the Form: READ (u)list Use: Input one logical record of data from logical unit u into processor storage as the value of the location identified in list. You may read only binary files output by a FORTRAN-20 unformatted WRITE statement with this type of READ statement. NOTE If you use the form READ (u) , one unformatted input record will be skipped. Example: (10.6.2 READ (10) BINFIL (10,20,30) Sequential List-Directed READ Transfer ;You may use the following forms of the READ statements sequential, list-directed input transfer: 1. to control a Form: READ{u,*)list Use: Read data from logical device u into processor storage as the value of the locations identified in list. Each input datum is converted, if necessary, to the type of its assigned list variable. Example: READ(10,*)IARY(20,20},A,B,M 10-12 < < I/O STATEHENTS 2. 10.6.3 Fo rm: READ *,list Use: Read the data from the READ default device (card reader) into the processor storage locations identified in the input list. Each input datum is converted, if necessary, to the type of its assigned list variable. Example: READ *,ABEL(10,20),I,J,K Sequential NAMELIST-Controlled READ Transfers You may use only the following form of the READ statement to a sequential NAMELIST-controlled input transfer: 10.6.4 Form: READ(u,N) Use: Read data from logical unit u into processor storage as the value of the locations identified by the NAMELIST input specified by the name N. The input data is converted to the type of' assigned variable if type conflicts occur. Only input files that contain records formatted and identified for NAMELIST operations (Paragraph 10.3.7) may be read by READ statements of this form. Random Access Formatted READ Transfers You may use only the following form of the READ statement to a random access formatted input transfer: 10.6.5 initiate initiate' Form: READ (u#R,f)list Use: Input data from record R of logical unit u.: Format each input datum according to the format specifications of f and place into processor storage as values of the locations identified in. list. Only disk files that have been set up by either an OPEN or DEFINE FILE statement may be accessed by a READ statement of this form. (If record R has not been written, an error results.) Example: READ(1#20,100) I, X(J) Random Access Unformatted READ Transfers You may use only the following form of the READ statement to a random access unformatted input transfer: 10-13 initiate I/O STATEMENTS Form: READ (u#R)list Use: Input data from record R of logical unit u. Place the input data into processor storage as the value of the locations identified in list. Only binary files that have been output by an unformatted random access WRITE statement may be accessed by a READ statement ·of this form. (If record R has not been written, an error results.) Example: READ (1#20) BINFIL Read record number 20 into array BINFIL. NOTE If the form READ (u#R) is used, it will cause logical input record R to be skipped. 10.7 SUMMARY OF READ STATEMENTS Table 10-2 summarizes the various forms of the READ statements. Table 10-2 Summary of READ Statements Type of Transfer Sequential Random Access Formatted READ(u,f)list READ(u,f) READ f,list READ f READ(u#R,f)list Unformatted READ(u)list READ(u) READ(u#R)list READ(u#R) List-Directed READ(u,*)list READ *,list NAMELIST READ{U,N) Note: 10.8 Transfer Mode You may include the ERR=c and END=d arguments in any of the ,above READ statements. When included, the foregoing arguments must be last, e.g., READ (lO,20,END=lOl,ERR=500)ARRAY(50,lOO) . REREAD STATEMENT . The REREAD statement causes the last record read from the last input device to again be accessed and processed. 10-14 active I/O STl':.TEMENTS You cannot use the REREAD feature of FORrl'RAi~-20 until iill inpul (READ) transfer from a file has been accomplished. If you use REREAD prematurely, an error results. Once a record has been accessed by a formatted READ statement, the record transferred may be reread as many times as desired. In a formatted transfer, you may use the same or new format specification by each successive REREAD statement. You may use the REREAD statement only for sequential transfers. The form of the REREAD statement is: formatted data Form: REREAD f,list Use: Reread the last record read during the last initiated READ operation and input the data contained by the record into the processor storage locations specified in the input list. Format the data read according to the format specificatiOns given in statement f. Example: DIMENSION ARRAY(lO,lO) ,FORMA(lO,lO) ,FORMB(lO,lO), 1 FORMC(lO,lO) 90 READ(16,100)ARRAY 100 FORMAT (-----) 110 REREAD 100,FORMA 115 REREAD 150,FORMB 120 REREAD 160,FORMC 150 FORMAT(-----) 160 FORMAT (-----) In the above sequence, statement 90 inputs data formatted according to statement 100 into the array ARRAY. Statement 110 reads the record read by statement 90 and inputs the data formatted as in the initial READ operation into the array FORMA. Statement 115 reads the record read by statement 90 and inputs data formatted according to statement 150 into the array FORMB. the Statement 120 reads the record read by statement 90 and inputs data formatted according to statement 160 into the array FORMC. the NOTE If you try to REREAD a record input from the teletype, you will get either the current record or the last 150 characters of the current record, whichever is the lesser. 10-15 I/O STATEMENTS 10.9 WRITE STATEMENTS WRITE statements transfer data from specified processor storage locations to peripheral devices. The various forms of the WRITE statement enable it to be used in sequential, appen~, and random 'access transfer modes for formatted, unformatted, list-directed, and 'NAMELIST-controlled data transfers. 10.9.1 Sequential Formatted WRITE Transfers You may use the following forms of the sequential transfer of formatted data: 1. 2. 3. 10.9.2 WRITE statement for the Form: WRITE(u,f)list Use: Output the values of the processor storage locations identified in list into the file associated with logical unit u. Convert and arrange the output data according to the specifications given in f. Example: WRITE(06,500)OUT(10,20) ,A,B Form: WRITE f,list Use: Output the values of the processor storage locations identified in list to the default device (line printer). Convert and arrange the output data according to the specifications given in f. Example: WRITE 10,SEND(5,10) ,A,B,C Form: WRITE f Use: Output the contents of any Hollerith (H) literal (' I) field descriptor(s) contained by f the default device (line printer). If neither the foregoing types of field specifications found in f, no output transfer is performed. Example: WRITE 10 or to of is Sequential Unformatted Binary WRITE Transfer You may use the following form of the sequential transfer of unformatted data: WRITE statements for the Form: WRITE (u)list Use: Output the values of the processor storage locations identified in list into the file associated with logical unit u. No conversion or arrangement of output data is performed. Example: WRITE(12)ITAB(20,20) ,SUMS(lO,5,2) 10-16 I/O STATEMENTS 10.9.3 Sequential List-Directed WRITE Transfers You may use the following form of the WRITE statement sequential list-directed output transfer. 10.9.4 to initiate a Form: WRITE(u,*)list Use: Output the values of the processor storage locations identified in list into the file associated with logical unit u. The conversion of each datum from internal to external form is performed according to the type of the list variable from which the datum is taken. Example: WRITE(12,*)C,X,Y,ITAB(lO,10) Sequential NAMELIST-Controlled WRITE Transfers You may use only the following form of the WRITE statement to initiate a sequential NAMELIST output transfer. 10.9.5 Form: WRITE(u,N) Use: Output the values of the processor storage locations identified by the contents of the NAMELIST-defined list specified by name N into the file associated with logical unit u. Example: WRITE(12,NMLST) Random Access Formatted WRITE Transfers You may use only the following form of the WRITE statement to initiate a random access type formatted output transfer: 10.9.6 Form: WRITE(u#R,f)list Use: Output the values of the processor storage locations identified by the contents of list to record R of the file associated with logical device u. Only disk files that have been set up by either an OPEN statement or a call to the subroutine DEFINE FILE may be accessed by a WRITE transfer of this form. The data transferred will be formatted according to the specifications given in f. Only those records that have been specifically written are available to be read. Random Access Unformatted WRITE Transfers You may use only the following form of the WRITE statement to initiate a random access unformatted output transfer: Form: WRITE(u#R)list Use: Output the values of the processor storage locations identified by the contents of list to record R of the file associated with logical 10-17 I/O STATEMENTS device unit u. Only disk files that have been set· up by either an OPEN or a call to the DEFINE FILE subroutine may be accessed by a WRITE transfer of· this form. Only those records that have been specifically written are available to be read. 10.10 SUMMARY OF WRITE STATEMENTS Table 10-3 summarizes the various forms of the WRITE statements. Table 10-3 Summary of WRITE Statements Type of Transfer Transfer Mode Sequential Random Access Formatted WRITE(u,f)list WRITE f,list WRITE f WRITE(u#R,f)list Unformatted WRITE(u)list WRITE(u#R)list List-Directed HRITE(u,*)list NAMELIST-controlled WRITE(u,N) Note: 10.11 You may include the ERR=c and END=d arguments in any WRITE statement which has a unit number; however, they must be last. ACCEPT STATEMENT The ACCEPT statement enables you to input data via either a terminal keyboard or a batch control file directly into specified processor storage locations. Use this statement only in the sequential transfer mode for the formatted transfer of inputs from your terminal keyboard during program execution. The following paragraphs describe the permitted forms of the ACCEPT statement. • 10.11.1 Formatted ACCEPT Transfers : Use the following forms of the ACCEPT transfer of formatted data. 1. statement for the sequential Form: ACCEPT f,list Use: Input data character-by-character from the user's terminal into the processor storage locations identified by the contents of list. Format the input data according to the format specifications given in f. Example: ACCEPT lOl,LINE(73) 10-18 I/O STATEMENTS 2. 10.11.2 Form: ACCEPT *,list Use: Input data character-by-character from the user's terminal into the processor storage locations identified by the contents of list. Convert the input characters, where necessary, to the type of its assigned list variable. Example: ACCEPT *,IAB,ABE,KAB,MAR ACCEPT Transfers Into FORMAT Statements You may use the following form of the ACCEPT statement to input data from your terminal keyboard directly into a specified FORMAT statement if the FORMAT statement has either or both a Hollerith (H), or a literal ('s') field descriptor. If the referenced statement has neither of the foregoing descriptors, the input record is skipped. 10.12 Form: ACCEPT f Use: Replace the contents of the appropriate fields of statement f with the data entered at the user's terminal keyboard. Example: ACCEPT 101 PRINT STATEMENT The PRINT statement causes data from specified processor storage locations to be output on the standard output device (line printer). Use this statement only for sequential formatted data transfer operation; write it in either of the three following forms: 1. 2. 3. Form: PRINT f,list Use: Output the values of the processor storage locations identified by the contents of list to the line printer. The values output are to be formatted and arranged according to the format specifications given in f. Example: PRINT 55,TABLE(10,20) ,I,J,K Form: PRINT *,list Use: Output the values of the processor storage locations identified by the contents of list to the line printer. The conversion of each datum from internal to external form is performed according to the type of the list variable from which the datum is taken. Example: PRINT *,C,X,Y,ITAB(lO,lO) Form: PRINT f Use: Output the contents of the FORMAT statement Hollerith (H) or literal field descriptors to the line printer. If neither an H nor a literal field 10-19 I/O STATEMENTS descriptor is present in the referenced FORMAT statement, no operation is performed. Example: PRINT 55 The third form of the PRINT statement is particularly useful when employed with ACCEPT f statements to cause desired data (comments or headings) to be inserted into reports at program execution time. Example The sequence 55 FORMAT(' END OF ROUTINE') PRINT 55 results in the printing of the phrase printer. 10.13 "END OF .ROUTINE" on the line TYPE STATEMENT The TYPE statement causes data from specified processor storage locations to be output to your (control) terminal printing or display· device. Use this statement only for sequential formatted data transfers; write it in one of the following forms: 1. 2. 3. Form: TYPE f,list Use: Output the values of the processor storage locations identified by the contents of list to the user's terminal. The values output are to be formatted according to the format specifications given in f. Example: TYPE 101,TABLE(10,20)I,J,K Form: TYPE f Use: Output the contents of the referenced FORMAT statement Hollerith (H) or literal field descriptors to the user's terminal device. If the referenced FORMAT statement does not contain either an H or a literal field descriptor, no operation is performed. Example: TYPE 101 Form: TYPE *,list Use: Output the values of the processor storage locations identified by the contents of list to the user's terminal. The conversion of each datum from internal to external form is performed according to the type of the list variable from which the datum is taken. Example: TYPE *,IAB(l,S) ,A,B 10-20 I/O STATEMENTS 10.14 FIND STATEMENT The FIND statement does not initiate a data transfer operation; use it during random access read operations to locate the next record to be read while the current record is being input. The program does not have access to the "found" record until the next READ statement is executed. The form of the FIND statement is FIND(u#R) Example: In the sequence READ(Ol#90) FIND(Ol#lOl) READ(Ol#lOl) the FIND statement will locate record #101 on device 01 after record 90 has been retrieved. Record #101 is not processed until the second READ statement in the sequence is executed. 10.15 ENCODE AND DECODE STATEMENTS Use the ENCODE and DECODE statements to perform sequential formatted data transfer between two defined areas of processor storage, i.e., an I/O list and a user-defined buffer; no peripheral I/O device is involved in the operations performed by these statements. The ENCODE statement transfers data from the variables of a specified I/O list into a specified storage area. ENCODE operations are similar to those performed by a WRITE statement. The DECODE statement transfers data from a specified storage area into the processor storage locations identified by the variables of an I/O list. DECODE operations are similar to those performed by a READ statement. write the ENCODE and DECODE statements in the following forms: ENCODE(c,f,s)list DECODE(c,f,s)list where c specifies the number of characters to be in each internal storage area. This argument may be an integer, an integer expression, or either a real or double precision expression that is converted to an integer form. NOTE 5 characters per storage location are stored in the buffer without regard to the type of variable given as the starting location. 10-21 I/O STATEMENTS f specifies either a FORMAT statement or an array format specifications. that contains s specifies the address of the first storage location that is to be used in the transfer operations. When multiple records are specified by the format being used, the succeeding records follow each other in order of increasing storage addresses. list specifies an 10.3.4). I/O list of the standard form (Paragraph When multiple records are stored by ENCODE, each new record starts on a new storage location boundary rather than there being a CRLF inserted between records. 10.15.1 ENCODE Statement A description of the form and use of the ENCODE statement follows: Form: ENCODE(c,f,s)list Use: The values of the processor storage locations identified by the contents of list are converted to ASCII character strings according to the format specifications given in f. The converted characters are then written into the destination area starting at location s. If you try to transfer more characters than the specified area can contain, the excess characters are ignored. If you transfer fewer characters than specified for the record size, the empty character locations are filled with blanks. Example: 10.15.2 ENCODE(500,101,START)TABLE DECODE Statement A description of the form and use of the DECODE statement follows: Form: DECODE(c,f,s)list Use: The character strings are taken starting at location s, converted (decoded) according to the format specifications given in f, and stored as the values of the processor storage locations identified in list. If the format specification requires more characters from a record than are specified by c, the extra characters are assumed to be blanks. If fewer characters are required from a record than are specified by c, the extra characters are ignored. Example: DECODE(50,50,START)GET(5,10) 10-22 I/O STATEMENTS 10.15.3 Example Of ENCODE/DECODE Operations The following program illustrates the DECODE statements: use of both the ENCODE and Example Assume the contents of the variables to be as follows: A(l) A(2) J B C (1 ) ( 2) ( 3) ( 4) ( 5) ( 6) contains the floating point number 300.45 contains the floating point number 3.0 is an integer variable is a 4-word array of indeterminate contents contains the ASCII string 12345 DO 2 J=l,2 ENCODE(16,10,B)J,A(J) FORMAT(lX,2HA(,I1,4H) TYPE 11,B FORMAT (4A5) CONTINUE DECODE(5,12,C)B FORMAT(3Fl.0,lX,F1.0) TYPE 13,B FORMAT ( 4 F 5. 2) END 10 11 2 ( 7) ( 8) 12 (9) (10) 13 (11) ,FB,2) Array B can contain 20 ASCII characters. The result of statement after the first iteration of the DO loop is: B(l) 'A (1) B (2) B (3) B (4) '= the Typed at line 4 as '300.4' A (1) = 300.45 •5 The result after the second iteration is: B(l) 'A (2) Typed at line 4 as B (2) B (3) B (4) '= '3.0 A(2) = = 3.0 The DECODE statement: 1. 2. 3. 4. 5. 6. 7. Extracts the digits 1, 2, and 3 from C Converts them to floating point values Stores them in B(l), B(2), and B(3) Skips the next character (the digit 4) Extracts the digit 5 from C Converts it to a floating-point value, and, Stores it in B(4) The output from the TYPE statement at line 9 is: 1.00 2.00 3.00 5.00 10.16 SUMMARY OF I/O STATEMENTS Table 10-4 summarizes all permitted forms of the I/O statement. 10-23 ENCODE 'fable 10-4 Summary of I/O Statements I/O Statements Formatted READ Sequential Random WRITE Sequential or Append(l) f--J 0 I Transfer Format Control Unformatted Namelist READ (u,f)list READ f,list READ f READ(u)list READ (u#R,f)list READ(u#R)list WRITE (u,f)list WRITE f,list WRITE f WRITE(u)list List-Directed READ(u,N) READ(u,*)list READ *,list WRI'rE (u,N) ,\'lRITE (u, *) list m Random(2) v~RI'rE (u#R,f)list t-3 WRITE (u#R)list ~ t-3 tv .t:. H "0 trl REREAD Sequential REREAD f,list FIND Random-only FIND (u#R) ACCEPT Sequential only ~ Z t-3 m FIND ( u#R) ACCEPT f,list ACCEPT" f 1. You must use an OPEN statement to set up an append mode. 2. You must use either the OPEN statement or a call to the DEFINE FILE subroutine to set up a random 'access mode. ACCEP'f *, list Table 10-4 (Cont.) Summary of I/O Statements I/O Statements Formatted PRINT Sequential only Transfer Format Control Unformatted Namelist List-Direction PRIN1' *, list PRINT f,list PRINT f H TYPE Sequential only f-' TYPE *,list TYPE f,list TYPE f lJ1 Ul 1-3 ~ o I tv "o ENCODE Sequential only DECODE Sequential only Legend: u f list N 1-3 tlj ENCODE (c,f,s)list Ei3 z 1-3 Ul I DECODE (c,f,s)list logical unit number statement number of FORMAT statement or name of array containing format information I/O list name of specific NAMELIST I/O list * #R c s symbol used to specify list-directed I/O operator variable which specifies logical record position number of characters per internal record address of the first storage location to be used CHAPTER 11 NAMELIST STATEMENTS 11.1 INTRODUCTION Use the NAMELIST statement to define I/O lists similar to those described in Chapter 10 (Paragraph 10.3.4). Reference defined NAMELIST I/O lists in special forms of the READ and WRITE statements to provide a method of transferring and converting data without referencing format specifications or specifying an I/O list in the I/O statement. 11.2 NAMELIST STATEMENT Write NAMELIST statements in the following form: NAMELIST/Nl/Al,A2, ... ,An/N2/Bl,B2, ... ,Bn/Nn/ ... where /Nl/ through /Nn/ represents names of Always enclose the (/N/) individual lists. name with slashes Al through An and Bl through Bn are the items of the lists identified, respectively, by names Nl and N2. A list may contain one or more variable, array, or array element names. Delimit the items of a list by commas. Each list of a NAMELIST statement is identified (and referenced) by the name immediately preceding the list. Example DIMENSION C(2,4) NAMELIST/TABLE/A,B,C/SUMS/TOTAL In the foregoing example, the name TABLE identifies the list A,B,C(2,4), and the name SUMS identifies the list consisting of the array TOTAL. Once a list has been defined in a NAMELIST statement, one or more statements may reference its name. 11-1 I/O NAMELIST STATEMENTS The rules for structuring a NAMELIST statement are: 1. You may use a maximum of six characters for a NAMELIST name. 2. You must begin it with an alphabetic character. 3. You must enclose it in slashes. 4. The NAMELIST name must precede the list of entries it refers. 5. The NAMELIST name must be unique within the program. 6. You may define a NAMELIST name only once, and you must define it by a NAMELIST statement. Once defined, you may use a name only in READ or WRITE statements. 7. You must define the NAMELIST name statement in which it is used. 8. You cannot use a variable used in a NAMELIST statement dummy argument in a SUBROUTINE definition. 9. You must define any dimensioned variable contained in a NAMELIST statement in an array declaration statement preceding the NAMELIST statement. 11.2.1 in advance of to which the I/O as a NAMELIST-Controlled Input Transfers During input (READ) transfer operations in which a NAMELIST-defined name is referenced, the records are read until a record is found that begins with the sequence 1 $1 (a space followed by a dollar sign) followed by the referenced name. The dollar sign must be the second character in the record; the first character in the record must be a blank. Once the proper symbol-name combination is found, the data items following it are transferred on a one-to-one basis to the processor storage locations identified by the contents of the referenced list. The input data is always converted to the type of the list variable when there is a conflict of types. The input operation continues until another $ symbol is detected. If variables appear in the NAMELIST record that do not appear in the NAMELIST list, an error condition will occur. Data items of records to be input (read) using NAMELIST-defined lists must be separated by commas and may be of the following form: V=Kl,K2, ... ,Kn where 1. V may be a variable, array, or array element name. 2. Kl through Kn are constants of type integer, real, double precision, complex (written as (A,B) where A and B are real), or logical (written as T for true or F for false). A series of identical constants may be represented as a single constant preceded by a repetition factor (5*5 represents 5,5,5~5,5) . 11-2 NAMELIST STATEMENTS In transfers of this type, logical and complex constants must be equated to variables of their own type. Other type constants (real, double-precision, and integer) may be equated to any other type of variable (except logical or complex), and will be converted to the variable type. For example, assume A is a 2-dimensional real array, B is a I-dimensional integer array, C is an integer variable, and that the input data is as follows: $FRED A(7,2)=4, B=3,6*2.8, C=3.32$ A READ statement referring to the NAMELIST defined name FRED will result in the following: The integer 4 will be converted to floating point and placed in A(7,2). The integer 3 will be placed in B(l), and the integer 2 (converted) will be placed in B(2) ,B(3), ... ,B(7). The floating point number 3.32 will be converted to the integer 3 and placed in C. NOTE "&" may be used instead NAMELIST-controlled input. 11.2.2 of 11$" in NAMELIST-Controlled Output Transfers When a WRITE statement refers to a NAMELIST-defined name, all variables and arrays and their values belonging to the named list are written out, each according to its type. Arrays are written out by columns. Output data is written so that: 1. The fields for the data will be large enough to the significant digits. 2. The output can be read by an input NAMELIST- defined list. statement contain all referencing a For example, if JOE is a 2 X 3 real array, the statement NAMELIST/NAMl/JOE,Kl,ALPHA (u, NAMl) ~~RITE generates the following form of output: Column l $NAMEI JOE= -6.750000 , 0.2340000E-04, -1970000. Kl= , $ 3.000000 O.OOOOOOOE+OO, ALPHA= 680.0000 73.10000 NOTE Do not use device positioning commands such as BACKSPACE, SKIP, RECORD, etc., with NAMELIST-controlled I/O operations. If you do, the results are unpredictable. 11-3 -17.80000 CHAPTER 12 FILE CONTROL STATEMENTS 12.1 INTRODUCTION This chapter describes the OPEN and CLOSE statements. They are file control statements used to set up files and establish parameters for I/O operations and to terminate I/O operations. 12.2 OPEN AND CLOSE STATEMENTS Both the OPEN and CLOSE statements are unique to FORTRAN-20; they both use the same format and have the same options and arguments. The OPEN statement enables you to define all of the important aspects of each desired data transfer operation; it provides an extensive. list of required and optional arguments that define in detail: . 1. the name and location of the data file 2. the type of access required 3. the data format within the file 4. the protection code(l) to be assigned an output data file 5. the disposition of the data file 6. data file record, block and file sizes 7. a data file version identifier In addition, a DIALOG argument is provided that permits you to establish a dialogue mode of operation when the OPEN statement containing it is executed. In a dialogue mode, interactive terminal/program communication is established. This enables you to define, redefine, or defer the values of the optional arguments contained by the current OPEN statement during program ,execution. The general form of the OPEN statement is: OPEN(Argl,Arg2, ... ,Argn) 1. Refer to the Monitor Calls Manual, for a description of file access protection codes. 12-1 FILE CONTROL STATEMENTS Use the CLOSE statement in the termination of an I/O operation to dissociate the I/O device being used from the active file and file-related information, and to restore the core occupied by I/O buffers and other transfer-related operations. All required device dependent termination functions are also performed on the execution of a CLOSE statement. Note that the CLOSE statement can change the name, protection, directory, and disposition of the file being closed. Once a CLOSE statement has been executed, you must statement to regain access to the closed file. use another OPEN The general form of the CLOSE statement is: CLOSE(Argl.,Arg2., ... ,Argn} CAUTION If you use a filename argument in a CLOSE statement that is different from the current filename, the file will be renamed. 12.2.1 Options for OPEN and CLOSE Statements The options and their arguments, which you may use in and CLOSE statements, are: 1. UNIT both the OPEN This option is required; it defines the FORTRAN I/O unit number to be used. FORTRAN devices are identified by assigned decimal numbers within the range 1-63; however, UNIT may be assigned an integer variable or constant. The general form of this argument is: UNIT= An integer variable or constant NOTE FORTRAN-20 standard logical unit assignments are described in Chapter 10 (Table 10-1). The range, i.e., 1-63, of the possible UNIT numbers is an installation-defined parameter. 2. DEVICE This option may specify either the physical or the logical name of the I/O device involved. (A logical name always takes: precedence over a physical name.) The DEVICE arguments may specify I/O devices located at remote stations, as well as logical devices. The general form of the DEVICE argument is: DEVICE= 12-2 A literal constant or variable FILE CONTROL STATEMENTS If you omit this option, the logical name u (where u is the decimal unit number) is tried; if this is not successful, the standard (default) device is attempted. 3. ACCESS ACCESS describes the type of input and/or output statements and the file access mode to be used in a specified data transfer operation. You may assign ACCESS anyone of six possible names, each of which specifies a specific type of I/O operation. The assignable names and the operations specified are: a. SEQIN The specified data file is to be read in sequential access mode. b. SEQOUT The specified data file to be written in sequential access mode. c. SEQINOUT The specified data file may be first read, then written (READ/WRITE sequence) record-by-record in a sequential access mode. When you specify SEQINOUT, a WRITE/READ sequence is illegal. If no access is specified, SEQINOUT is assumed. d. RANDOM The specified data file may be either read or written into, one record at a time. In a random access mode of operation, the relative position of each record is independent of the previous READ or WRITE statement; all records accessed must have a fixed logical record length. The RECORD SIZE option is required for random access operations. You must specify a disk device when the random argument is used. e. RANDIN This argument enables you to establish a special, read-only random access mode with a named file. During a RANDIN mode, you may read the named file simultaneously with other users who have also established a RANDIN mode and with the owner of the file. The use of RANDIN enables a data base to be shared by more than one user at the same time. 12-3 is a FILE CONTROL STATEMENTS f. APPEND The record specified by a corresponding WRITE statement is to be added to the logical end of a named file. You must close and then reopen the modified file to permit it to be read. The general form of ACCESS argument is: the 'SEQIN' 'SEQOUT' 'SEQINOUT' ACCESS= 'RANDOM' 'RANDIN' 'APPEND' variable (set to literal) 4. MODE This option defines the character set of an external file or record. The use of this argument is optional; if you do not use it, one of the following is assumed: a. b. ASCII for a formatted I/O file transfer Binary for an unformatted I/O file transfer. NOTE Refer to the Monitor Calls Manual for a detailed description of the data modes given in the following list. You must use one of the following character set specifications with the MODE argument: Literal Action Indicated 'ASCII' Specifies an ASCII character set. 'BINARY' Specifies data formatted FORTRAN binary data file. as a 'IMAGE' Specifies an image (I) mode data transfer for the associated READ or WRITE statements. IMAGE is an unformatted binary mode. 'DUMP' The data file to be to be handled in operation. transferred is a DUMP mode of The general form of the MODE argument is: 'ASCII' 'BINARY' 'IMAGE' 'DUMP' variable (set to literal) MODE= 12-4 FILE CONTROL STATEMENTS 5. DISPOSE This option specifies an action to be taken regarding a file at close time. When used, DISPOSE must be either a variable or one of the following literals: Literal 'SAVE' Action Indicated Leave the file on the device. 'DELETE' If the device involved is a disk, remove the file: otherwise, take no action. 'PRINT' If the file is on disk, queue it for printing; otherwise, take no action. 'LIST' If the file is on disk, queue it for printing and delete the file: otherwise take no action. 'RENAME' Change filename. (This is redundant if a new filename is given.) If the DISPOSE argument is not given, argument DISPOSE 'SAVE' is assumed. general form of the DISPOSE argument is: DISPOSE= 6. FILE 'SAVE' 'DELETE' 'PRINT' 'LIST' 'RENAME' variable the The (set to literal) This option specifies the name of the file involved in the data transfer operation. FILE must be either a literal, double-precision, complex, or single-precision variable. Single-precision variables are assumed to contain a 1- to 5-character file specification: double-precision variables permit 10-character file specification. The format is a 1- to 6-character filename optionally followed by a period and a 0- to 3-character extension. Any excess characters in either the name or extension are ignored. If you omit the period and extension, the extension .DAT is assumed; if just the extension is omitted, a null extension is assumed. So if you want a filename without an extension, remember to use the period. If a filename is not specified or is zero, a default name is generated that has the form FORxx.DAT where xx is the FORTRAN logical unit number (decimal) or is the logical unit name for the default statements ACCEPT, PRINT, READ, or TYPE. The general form of a FILE argument is: 12-5 FILE CONTROL STATEMENTS FILE= 7. PROTECTION A literal or variable set to a literal This option specifies a protection code to be assigned the data file being transferred. The protection code determines the level of access to the file that three possible classes of users (owner, member, or other) will have. PROTECTION may be a 3-digit octal literal or a variable; if the argument is assigned a zero value or is not given, the default protection code established for the installation is used. The general form of the PROTECTION argument is: PROTECTION= 3-digit octal constant integer variable 8. DIRECTORY or Use this option for disk files only. It specifies the location of the user file directory (UFD) or the sub-file directory (SFD) that contains the file specified in the OPEN statement. A directory identifier may consist of either: a. Your project programmer number that identifies the UFD, for example, 10,7, or b. A UFD/SFD directory path specification. A path specification lists the UFD and the names of its SFDs that form a path to the desired SFD. For example, the following path specification identifies the path leading to SFD 1234: lO,7,SFDA,SFDB,1234 NOTE Refer to the Monitor Calls Manual for a complete description of directories and multilevel directory structures. The general form of a DIRECTORY argument is: DIRECTORY= array Literal or containing directory specification name path You may also establish an array containing the directory specification as its elements, and reference the array in the DIRECTORY argument. Single-precision arrays permit 5-character directory names to be used; double-precision arrays permit 6-character: 12-6 FILE CONTROL STATEHENTS (0 ) names to be used. You must use a zero entry to terminate a directory path specification given in an array. Examples of the use of singleand double-precision arrays in an OPEN statement DIRECTORY specification follow: a. Single-Precision Array 5, DIRECTORY = PATH, ... ) OPEN (UNIT where PATH and its elements are: DIMENSION PATH (5) PATH (1) = "10 ! (PROJECT NUMBER) PATH (2)= "7 ! (PROGRAHMER NUMBER) UFO PATH (3)='SFDA' Names of sub-file PATH (4)='SFDB' directories (SFD's) PATH (5)=0 b. Double-Precision Array OPEN (UNIT=5, DIRECTORY = PATH, ... ) where PATH and its elements are: DOUBLE PRECISION PATH (5) PATH (1) =11000000000010000000000007 ! (PROJ.,PROG. NUMBERS=UFD) PATH PATH PATH PATH (2)='SFDABC' (3)='MYAREA' (4)='YOURIT' (5)=0 !names of sub-file !directories (SFDs) The elements of a directory specification may then be either a literal or a singleor double-precision array. The following is specification: an example of a literal DIRECTORY='lO,7,SFDl,SFD2,SFD3' '---..--l \ , / ProJect Programmer Number b j '/l'v"'" Su -Fl e Directory Path Whenever the specification is an array, you may specify the required project and programmer numbers either of two ways. You can use one word with the project number in the left half and the programmer number in the right half, or, use the right halves of separate sequential word locations. 12-7 FILE CONTROL STATEMENTS 9. BUFFER COUNT This option enables you to specify the number of I/O buffers to be assigned to a particular device. If this argument is not given or is, assigned a value of zero, the Monitor default is assumed. The general form of this argument is: BUFFER 10. FILE SIZE COUNT= VERSION BLOCK SIZE An integer variable RECORD SIZE constant An octal constant variable or or integer You can use this option for all storage media except disk. It enables you to specify a i physical storage block size for a device. The value assigned the BLOCK SIZE arguments may be an integer constant or variable. The size specified must be greater than or equal to 3 and less than or equal to 4095. The general form of this argument is: BLOCK SIZE= An integer variable 13. or Use this option for disk operations only; it enables you to assign a 12-digit octal version number to a file when it is output. The quantity assigned to the VERSION argument may be either an octal constant or variable. The general form of the argument is: VERSION= 12. constant Use this option for disk operations only: it enables you to estimate the number of words that an output file is going to contain. The use of FILE SIZE enables you to ensure at the start of a program that enough space is available for its execution. If the size specified is found to be too small during program executions, the Monitor allocates additional space according to the normal Monitor algorithms. The value assigned to the FILE SIZE arguments may be an integer constant or variable and will be rounded up , to the next higher block boundary (multiple of 200 octal). The general form of this argument is: FILE SIZE= 11. An integer variable constant or This option enables you to force all logical records to be a specified length. If a logical record exceeds the specified length, it is truncated; if a logical record is less' than the specified size, nulls are added to pad the record to its full size. The RECORD SIZE argument is required whenever a random' access mode is specified. The value assigned to this argument may be either an integer constant or variable, and may be expressed as 12-8 FILE CONTROL STATEMENTS the number of words or characters, depending on the mode of the file being described. The general form of this argument is: RECORD 14. ASSOCIATE VARIABLE SIZE= An integer variable constant or Use this option for disk random access operations only. It provides storage for the number of the record to be accessed next if the program being executed were to continue to sequentially access records starting from the current READ. For example, if record number 3 were read, the ASSOCIATE VARIABLE would be equal to 4. The general form of this argument is: ASSOCIATE VARIABLE = Integer variable 15. PARITY Use this option for magnetic tape operations only; it permits you to specify the type of parity to be observed (odd or even) during the transfer of data. The general form of this option is: PARITY= 16. DENSITY DIALOG (set to literal) Use this option for magnetic tape operations only; it permits you to specify any of four possible bit-per-inch (bpi) tape density parameters for magnetic tape transfer operations. The general form of this option is: DENSITY= 17. 'ODD' 'EVEN' variable '200' '556' '800' '1600' variable (set to literal) The use of this option in an OPEN statement you to supersede or defer, at enables time, the values previously execution assigned to the arguments of the statement. There are two forms of this argument. The first is: DIALOG This form establishes a dialogue with your terminal when the OPEN statement is executed. FOROTS outputs the following messages at the user's terminal. UNIT=n:/ACCESS=SEQINOUT/MODE=ASCII ENTER NEW FILE SPECS. END WITH A $ (ALT) Once the message and defined file specification are output, you may enter any desired changes. You need enter only the arguments that are to be changed. 12-9 FILE CONTROL STATEMENTS The second form of the argument is: DIALOG= Literal or array The value assigned to DIALOG may be a literal or an array containing a file specification with the desired information. 18. ERR The use of this option in an OPEN or CLOSE statement enables you to transfer program control to an executable statement when an error is detected during the processing of the OPEN or CLOSE statement. The general form of this option is: ERR= s where s is the statement label of an executable statement (that appears in the same program unit as the error specifier) to which program control is transferred when an error is detected. Associated with the ERR= option on OPEN/CLOSE is the subroutine ERRSNS that enables you to pinpoint the error. See Appendix H for FOROTS error values returned by ERRSNS. Examples: OPEN (UNIT= 1, DEVICE= 'DSK', ACCESS= 'SEQIN ' , MODE= 'BINARY') causes a disk file named FOR01.DAT (since no FILE= option was specified) to be opened on unit 1 for sequential input in binary mode. OPEN (UNIT= 3, DEVICE= 'DSK', FILE= 'PAYROL.DAT', 1 ACCESS= 'RANDOM', MODE= 'ASCII', RECORD SIZE= 80, 2 ASSOCIATE VARIABLE= I, ERR= 240) causes a disk file named PAYROL.DAT to be opened on unit 3 for random input/output operations in ASCII mode. The records in PAYROL.DAT are 80 characters long; the ASSOCIATE VARIABLE for this file is I. If an error occurs during the execution of this OPEN statement, the OPEN will terminate and control will transfer to the statement labeled 240. CLOSE (UNIT= 3, DISPOSE= 'DELETE') causes the file on unit 3 to be closed and removed if the file disk. 12.2.2 is on Summary of OPEN/CLOSE Statement Options Table 12-1 summarizes the options permitted and required in the and CLOSE statements and the type of value required by each. 12-10 OPEN FILE CONTROL STATEMENTS Table 12-1 OPEN/CLOSE Statement Arguments Argument ACCESS= Possible Value Open* Close* SEQIN I , I SEQOUT I , I SEQINOUT I , RANDIN I , I RANDOM I , I APPEND I , or variable Integer variable Integer constant or variable Integer constant or variable Literal constant or variable Literal constant or variable Literal or array or none Literal or variable or array Literal constant or variable Statement Number Literal constant or variable Integer constant or variable Literal constant or variable Literal constant or variable An octal constant or integer variable Integer constant or integer variable Integer variable or constant Octal constant or variable 0 I 0 0 0 0 0 0 0 0 0 0 0 I I I I I I I I ASSOCIATE VARIABLE= BLOCK SIZE= BUFFER COUNT= DENSITY= DEVICE= DIALOG= DIRECTORY= DISPOSE= ERR= FILE= FILE SIZE= MODE= PARITY= PROTECTION= RECORD SIZE= UNIT= VERSION= * R = Required o = Optional I = Ignored 12-11 a 0 0 0 0 I I I 0 0 0 0 I R R 0 0 CHAPTER 13 FORMAT STATEMENT 13.1 INTRODUCTION Use FORMAT statements in conjunction with the I/O list of I/O statements during formatted data transfer operations. The FORMAT statements contain field descriptors that, together with the list items of associated I/O statements, specify the forms of the data and data fields that comprise each record. FORMAT statements may appear almost anywhere in a source program. The only placement restrictions are that they follow PROGRAM, FUNCTION, SUBPROGRAM, or BLOCK DATA statements; and that they precede the END statement. (Refer to Section 2.4.) You must label FORMAT statements so that I/O statements can them. 13.1.1 reference FORMAT Statement, General.Form The general form of a FORMAT statement follows: k FORMAT(SAl,SA2, ... ,SAn/SBl,SB2, ... ,SBn/ ... ) where k = the required statement label (which be referenced by I/O statements). SAl through SAn and SBI through SBn = individual field descriptor sets can only In the foregoing statement form, the individual field descriptors are delimited by commas (,). Field descriptor sets and records are delimited by slashes (/). For example, a FORMAT statement of the form: FORMAT(SAl,SA2/SBl,SB2/SCl,SC2) contains format specifications for three containing two field descriptor sets. records with each record Adjacent slashes (//) in a FORMAT statement specify that a record is to be skipped during input or is to consist of an empty record on output. For example, a FORMAT statement of the form: FORMAT (SA1,SA2///SBl,SB2) 13-1 FORMAT STATEMENT specifies four records are to be processed; third records are to be skipped. however, the second and You may represent repeated field descriptors or groups of field descriptors by using a repeat form. Indicate the repetition of a single field descriptor by preceding the descriptor with an integer constant that specifies how many times the descriptor is to be repeated. For example, a FORMAT statement of the form: FORMAT(SA1,SA2,SA3,SA1,SA2,SA3,SA1,SA2,SA3) may be written as FORMAT(3(SA1,SA2,SA3)) You may nest the repeat forms of field descriptors to any depth. example~ a FORMAT statement of the form: For FORMAT(SA1,SA2,SA2,SA3,SA1,SA2,SA2,SA3) may also be written in the form: FORMAT(2(SA1,2SA2,SA3)) The following paragraphs discuss the manner in which you may foregoing statement forms and the effect each has on involved. 13.2 use the the data FORMAT DESCRIPTORS FORMAT statement descriptors describe the record structure of the data, the format of fields within the record, and the conversion, scaling, and editing of data within specific fields. The following descriptors can be used with FORTRAN-20: Descriptors Comments rFw.d rEw.d rDw.d rGw.d Floating point numeric field descriptors rIw Integer field descriptor rLw Logical field descriptor rAw rRw Alphanumeric data field descriptor kHs 'text' Alphanumeric data in a FORMAT statement field descriptor Field formatting descriptors nP Numerical scale factor descriptor / Record delimiter $ Carriage return suppression for terminal raw Octal field descriptor 13-2 FORHAT STATEt·1ENT where r an optional unsigned integer representing a repeat count. This option enables a field descriptor to be repeated r times. w an optional integer constant representing the width (total number of characters contained) of the external form of the field being described. All characters, including digits, decimal points, signs, and blanks that are to comprise the external form of the field, must be included in the value of w . .d an optional unsigned integer specifying the number of fractional digits that are to appear in the external representation of the field being described. Note that w must be specified if .d is included in the descriptor. k an unsigned integer specifying the number of characters to be processed during the transfer of alphanumeric data. s represents a string of ASCII n a signed integer constant (plus signs are optional). (alphanumeric) characters. The characters A, D, E, F, G, H, I, L, 0, P, and R indicate the manner of conversion and editing to be performed between the internal (processor) and external representations of the data within a specific field; these characters are referred to as conversion codes. Table 13-1 gives the FORTRAN-20 conversion codes and a brief description of the function of each. Table 13-1 FORTRAN-20 Conversion Codes Code A D E F G H I L Q P R Function Transfer alphanumeric data Transfer real data with a D exponent{l) Transfer real data with an E exponent{l) Transfer real data without an exponent Transfer integer, real, complex, or logical data Transfer literal data Transfer integer data Transfer logical data Transfer octal data Numer icals'caling' factor Transfer alphanumeric data 1. An exponent of 0 is assumed if none is given. The use of commas to delineate format descriptors within a format specification is optional as long as no ambiguity exists. For example, FORMAT ( 3X, A2) can be written as FORMAT (3XA2) 13-3 FORMAT STATEMENT Since interpretation of a format specification the specification is left associative, FORMAT(I22,I5) can be written as FORMAT(I22I5) However, a comma is required when you wish to specify FORMA T ( 12 , 2 I 5 ) The following paragraphs provide detailed descriptions of the "various types of format descriptors, the manner in which they are written and employed, and their use in FORMAT statements. 13.2.1 Numeric Field Descriptors The forms of the field descriptors used conversion of numeric data follow. Fw.d Fw.d,Fw.d Iw '" ',' Gw Gw.d,Gw.d the format and Double-precision data with a D exponent Real data with an E exponent For the real and imaginary parts of a complex datum Real or double-precision data without an exponent For the real and imaginary parts of a complex datum Integer data r"Ow-"'-~~-"~-"'~~"'~ ~~'~'~':.J;:j'~I~~f·~"?I'at:~ ~Gw'.'d specify Type of Data Used For Description Dw.d Ew.d Ew.d,Ew.d to 'J Real or double-precision data For integer (or logical) data For the real and imaginary parts of a complex datum NOTE The G conversion code may be used all but octal numeric data types. Examples Consider the; following program segment: INTEGER 11,12 REAL Rl,R2,R3 DOUBLE PRECISION Dl,D2 II 506 12 8 Rl 506.0 R2 18.1 R3 506001.0 Dl 18.0 D2 -504.0 13-4 for FORMAT STATEMENT Table 13-2 describes the actions performed by several types of formatted WRITE statements on the data given in the foregoing program segment. Table 13-2 Action of Field Descriptors On Sample Data Item Descriptor Form Sample Descriptor 1 Dw.d Ew.d 2 Fw.d 3 4 Iw Iw S ~_ 6 , , Ow",~_" Gw.d 7 S Gw.d DS.2 ES.2 FS.2 IS I2 OS WRITE(-,-)Dl WRITE(-,-)Rl WRITE(-,-)R2 WRITE(-,-)Il WRITE(-,-)Il _,_, WRITE '(-: '-: }1?' GS.2 GS.2 GS WRITE(-,-)R3 WRITE(-,-)R2 WRITE(-,-)Il Gw.d Gw 9 10 where: "'-GS' ~-i"' WRITE Statement Using the Sample Descriptor "WRITE"( ::~ :Yb'i" External Form of Sample Field Described Z.nnD Z.nnE aa.nn aaaan an nnnnn Z.nnD Z.nnE aa.nn aaan nn nn External Appearance of Sample Data 0.lSD+02 0.SlE+03 lS.lO ,kS,l6s 0 6 ** ,9,Q~Q<~ ,9~ .,~ "A_~'_~M"Y'A'~h~J -.SOD+02 0.SlE+06 )5}6iS1S.lO iSiS 50 6 a. n represents a numeric character. b. Z represents either a - or O. (Note that if a negative number cannot be output.) c. a represents a digit, leading blank (¥) or sign depending on the numeric output. n-d>6, a minus Notes: 1. In Item 1, the value Dl has only two significant digits and d=2, so no rounding will occur on input. 2. In Item 2, since Rl has 3 significant digits, it is rounded to fit into the specified field. 3. In Item S, the width (w) part of a format descriptor specifies an exact field that permits no rounding of its contents. If the w specification is too small for the datum to be transferred, asterisks are output to indicate that the transfer was not made. S. In Items Sand 9, the relationship between G and fixed floating real data is discussed in Paragraph 13.2.3. 6. In Items 1, 2, 3, 7, and S, the D and E exponent prefixes are optional in the external form of the floating point constants. For example, 1.lE+3 may be written as 1.1+3. Table 13-3 summarizes the internal and external specified by the numeric format conversion code. 13-S forms of the and data FORMAT STATEMENT Table 13-3 Numeric Field Codes Internal Form Conversion Code External Form Binary floating-point double-precision D Decimal floating-point with D exponent Binary floating-point E Decimal floating-point with E exponent Binary floating-point F Decimal fixed-point Binary integer I Decimal integer Binary word o Octal value One of the following: single-precision binary floating-point, binary integer, binary logical, or binary complex G Single-precision decimal floating-point, decimal integer, logical (T or F), or complex (two decimal floating-point numbers), depending upon the internal form Complex quantities transfer as two independent real quantities. The format specification for complex quantities consists of either two successive real field descriptors or one repeated real field descriptor. For example, the statement FORMAT(2E15.4,2(F8.3,F8.5)) may transfer up to three complex quantities. The equivalent of the foregoing statement is FORMAT(E15.4,E15.4,F8.3,F8.5,F8.3,F8.5) 13.2.2 Interaction of Field Descriptors With I/O Variables The execution of an I/O statement that specifies a formatted data transfer operation initiates format control. The actions performed by format control depend on information provided by the elements of the I/O statement's list of variables and the field descriptors that comprise the referenced FORMAT statement's format specifications. In processing each FORMAT controlled I/O statement that has an I/O list, FORTRAN scans the contents of the list and the format specific?tions in step. Each time another variable or array element name is obtained from the list, the next field specification is obtained from the format specification. If the end of the format specification is reached and more items remain in the list, a new line or record is established and the scan process is restarted, either at the first item in the format specification or, if parenthesized, sets of format specifications exist within the format specification, with the last set within the format specification. 13-6 FORMAT STATEMENT When the I/O list is exhausted, control proceeds to the next statement in the program, but not before the FORMAT statement is scanned either to its end or to the next variable transfer format descriptor. (That is, the FORMAT statement is scanned past slashes, literal constants, Hollerith field descriptors, and spacing descriptors, but not past data field descriptors.) A record is terminated by one of the following: 1. a slash in the FORMAT specification 2. the delimiting right parentheses, ), of the FORMAT statement 3. a lack of items in the I/O list 4. a lack of Hollerith FORMAT statement or literal field descriptors in the On input, an additional record is read only when a single slash, /, is encountered in the FORMAT statement. A record is skipped when two slashes, //, are encountered or a slash is followed by the end of the FORMAT statement. If the FORMAT statement finishes a record by a slash or the end of the FORMAT statement, any data left in the input record is ignored. If the input record is exhausted before the data transfers are completed, the remainder of the transfer is completed as if the record were extended with blanks. is On output, an additional record is written only when a slash, /, encountered in the FORMAT statement. If a pair of consecutive slashes, //, or a single slash followed by the end of the FORMAT statement is encountered, an empty record.is written. 13.2.3 G, General Numeric Conversion Code You may use the G conversion code in field descriptors for the format control of real, double-precision, integer, logical, or complex data. With the exception of real and double-precision data, the type of converSlon performed by a type G field descriptor depends on the type of its corresponding I/O list variable. In the case of real and double-precision data, the kind of conversion performed is a function of the external magnitude of the datum being transferred. Table 13-4 illustrates the conversion performed for various ranges of magnitude (external form) of real and double-~recision data. 13.2.4 Numeric Fields with Scale Factors You may add scale factors to 0, E, F, and G conversion codes in descriptors. The scale factor has the form field nP where n is a signed integer (+ is optional) and P identifies the operation. When used, a scale factor is added as a prefix to field descriptors. 13-7 FORMAT STATEMENT Examples -2PFIO.5 IPE8.2 When you add a scale factor to an type F field descriptor (or type G if the external field is a fixed point decimal) a power of 10 is specified so that External Form of Number = (Internal Form)*lO**(scale factor) For example, assuming the data involved to be the real number the field descriptor 26.451, F8.3 produces the external field ,k>J2f26.451 Table 13-4 Descriptor Conversion of Real and Double-Precision Data According to Magnitude Equivalent Method of Conversion Performed Magnitude of Data in External Form (M) F (w-4) . d , 4X 0.1 M~l 1 M~lO F (w- 4) • (d -1) ,4 X 10d-2 M<lOd-l 10d-l M<lOd ALL OTHERS F (w-4) .1, 4X F(w-4).0,4X Ew.d NOTE In all numeric field conversions, the field width (w) you specify should be large enough to include the decimal point, slgn, and exponent character in addition to the number of digits. If the specified width is too small to accommodate the converted number, the field will be filled with asterisks (*). If the number converted occupies fewer character positions than specified by w, it will be right-justified in the field and leading blanks will be used to fill the field. 13-8 FORMAT SThTEMENT The addition of the scale factor of -IP -lPF8.3 produces the external field ~~~2.645 When you add a scale factor to D, E, and G (external field not a decimal fixed-point) type field descriptors, it multiplies the number by the specified power of ten and the exponent is changed accordingly. In input operations, type F (and type G, if the external field is decimal fixed-point) conversions are the only ones affected by scale factors. When you specify no scale factor, it is understood to be zero. Once you specify a scale factor, however, it holds for all subsequent types D, E, F, and G field descriptors within the same format specification unless another scale factor is specified. A scale factor is reset to zero when you specify a scale factor of zero. Scale factors have no effect on I and 0 type field descriptors. When you add a scale factor to a D or E field descriptor, it specifies a power of 10 so that the external form of the number has its mantissa multiplied by the specified power of 10; its exponent is adjusted accordingly. For example, assuming the data involved to be the real number the field descriptor 12.493, Ell.3 produces the external field ~~0.125E+02 The addition of the scale factor 2P 2PEll.3 produces the external field ~~12.49E+00 with a scale factor of zero, the number of significant digits by a format of the form printed Ew.d or Dw.d is the number of digits to the right of the decimal point. For a negative scale factor nP, for -d<n<O, there will be ABS(n) leading zeros and d-ABS(n) significant digits after the decimal point, for a total of d digits after the decimal point. If n~-d, there will be d insignificant digits (zeros) to the right of the decimal point. If the scale factor nP is positive, for 0<n<d+2 there will be n significant digits to the left of the decimal point and d-n+l significant digits to the right of the decimal point (for a total of 13-9 FORMAT STATEMENT d+l significant digits). If n~d+2, digits and n-d-l insignificant trailing decimal point. there will be d+l significant zeros on the left of the If the data to be printed is 12.493, these formats produce results follows: FORMAT OUTPUT SIGNIFICANT DIGITS REASON ElS.3 IPElS.3 -lPElS.3 2PElS.3 -3PElS.3 4PElS.3 6PElS.3 ~~~~~~0.12SE+02 ~~~~~~1.249E+Ol ~~~~~~.012E+03 ~~~~~~12.49E+00 ~~~~~~0.OOOE+05 ~~~~~~1249.E-02 ~~~~124900.E-04 3 4 3 4 n=O n<d+2 -d<n n<d+2 0 n~-d 4 4 n<d+2 13.2.S as n~d+2 Logical Field Descriptors You may transfer logical data under format control in a manner similar to numeric data transfer by use of the field descriptor Lw where L is the control character and w is an integer specifying the field width. The data is transmitted as the value of a corresponding logical variable in the associated input/output list. On input, the first non-blank character in the logical data field must be T or F, the value of the logical variable is stored in the list variable as true or false, respectively. If the entire input data field is blank or empty, a value of false is stored. On output, w minus 1 blanks followed by T or F will be output value of the logical variable is true or false, respectively. 13.2.6 if the Variable Numeric Field Widths Several of the conversion codes are acceptable in FORMAT statements without field width specifications, the w.d portion of the specification so that can be omitted(l). On input, the conversion codes D, E, F, G, I, L, and 0 are acceptable without field width specifications. The field begins with the first non-blank character encountered and ends with the first illegal character in the given field. (Blanks and tabs also terminate a field.) Note that for conversion code L (logical data), all consecutive alphabetics following a T (true) or an F (false) are considered part of the field and are ignored. In succeeding fields the input stream is scanned until a non-blank character is encountered. If the character is a comma (,), the next field is skipped, and the following input field begins with the character following the comma. Any character other than a comma is assumed to be the first character in the next input field. Null fields are 1. If d is given, w must also be specified. 13-10 FORMAT STATEMENT denoted by successive commas optionally separated by blanks or tabs. A null field is equivalent to a fixed-field input of blanks. For example, the source code READ 1, X, Y, Z, L, I, J 1 FORMAT (3F, L, I, A3) with data as follows ,1.OE+S"TRUEXXXl~~~~ABC results in X Y Z L I J 0.0 1.OE+S 0.0 TRUE 1 'ABC' Note that if a comma is included in the input data after the XXXI before the blanks, i.e., the data is ,1.OE+S " then J and TRUEXXXl,~~~~ABC = '~~~' I, L, 0, and Rare On output, the format codes A, D, E, F, G, acceptable without field width specifications. The following defaults are assumed: Format Code Assumed Default A single-precision A double-precision AS AIO 02S.18 ElS.7 FlS.7 GlS.7 G2S.18 lIS LIS OIS RS RIO o E F G single-precision G double-precision I L o R single-precision R double-precision 13.2.7 Alphanumeric Field Descriptors You may accomplish the formatted transfer of alphanumeric data in a manner similar to the formatted transfer of numeric data by use of the field descriptors Aw and Rw, where A and R are the control characters and w is the number of characters in the field. The A and R descriptors both transfer alphanumeric data into or from a variable in an input/output list depending on the I/O operation. A list variable may be of any type. For example, READ (6,S) V S FORMAT (A4) 13-11 FORMAT STATEMENT causes four alphanumeric characters to be read from unit 6 and in the variable v. stored The A descriptor deals with variables containing left-justified, blank-filled characters; the R descriptor deals with variables containing right-justified, zero-filled characters. The following paragraphs summarlze the result of alphanumeric data transfer (both internal and external representations) using the A and R descriptors. These paragraphs assume that w represents the field width and m represents the total number of characters possible in the variable. Double precision variables contain 10 characters (m=lO); all other variables contain 5 (m=5). A Descriptor 1. INPUT, where w ~ m -- The rightmost m characters of the field are read in and stored left-justified and blank-filled in the associated variable. 2. INPUT, where w < m A l l w characters are read in and stored left-justified and blank-filled in the associated variable. 3. m characters are output and OUTPUT, where w ~ m right-justified in the field. The remainder of the field is blank-filled. 4. OUTPUT, where w < m -- The left associated variable are output. most w characters of the R Descriptor 1. INPUT, where w ~m -- The right most m characters of the field are read in and stored right-justified, zero-filled in the associated variable. 2. INPUT, where w < m -- All w characters are read in and stored right-justified, zero-filled in the associated variable. 3. OUTPUT, where w ~ m -- m characters are output and right justified in the field. The remainder of the field is blank filled. 4. OUTPUT, where w < m -- The right most associated variable are output. 13.2.8 w characters of the Transferring Alphanumeric Data You may transmit alphanumeric data directly into or from the FORMAT stat:,eme,Ilt9Y ..' t:wo di~ferent . methods: .' ... H~conversion, r:QI">Ili~~"u~~~(),f] • si ngTe' .9~U 0 t e s ',"1 .wEi: w;w.,:a" .~ f~f ~ y~ii'~'> ~ rEird~~dei~ ciI~ ~ 0 r . : In H-conversion, the alphanumeric string is specified in the form nH, where H is the control character and n is the total number of characters (including blanks) in the string. For example, you may use the following statement sequence to print the words PROGRAM COMPLETE on the device LPT: PRINT 101 101 FORMAT (17H~PROGRAM~COMPLETE) 13-12 FORMAT STATEMENT Read and write operations of this type are initiated by I/O statements that reference a format statement and a logical device, but do not contain an I/O list (see preceding example). write transfers from a FORMAT statement cause the contents of the statement field descriptor to be output to a specified logical device. The contents of the field descriptor, however, remain unchanged. Read transfers with a FORMAT statement cause the contents of the field descriptors involved to be replaced by the characters input from the specified logical device. Alphanumeric data is stored in a field descriptor left-justified. If the data input into a field has fewer characters than the field, trailing blanks are added to fill the field. If the data input is larger than the field of the descriptor, the excess rightmost characters are lost. Examples WRITE (1,101) 101 FORMAT (l7H~PROGRA~COMPLETE) cause the string PROGRAM COMPLETE to be output to the file 1. on device Assuming the string START on device 1, the sequence READ (1,101) 101 FORMAT (l7H~PROGRAM~COMPLETE) would change the contents of statement 101 to 101 FORMAT (17HSTART~~~~~~~~~~~~) The foregoing functions may also be accomplished by a literal field descriptor consisting of the desired character string enclosed within apostro~hes, i.e., 'string'. For example, you may use the descriptors 101 FORMAT (l7H~PROGRAM~COMPLETE) 101 FORMAT ('~PROGRA~COMPLETE') and in the same manner. The result of literal conversion is the same as H-conversion. On input, the characters between the apostrophes are replaced by input characters, and on output, the characters between the apostrophes (including blanks) are written as part of the output data. An apostrophe character within a literal field should be represented by two successive apostrophe marks; otherwise, the statement will not compile. For example, the statement sequence 50 FORMAT ('DON' 'T') PRINT 50 will compile and will cause the word DON'T to be output printer. The statement 50 FORMAT ('DON'T') however, will cause a compile error. 13-13 on the line FORMAT STATEMENT 13.2.9 Mixed Numeric and Alphanumeric Fields You may place an alphanumeric field descriptor among other the format. For example, you may use the statement: FORMAT fields of (I4,7H~FORCE=FlO.5) to output the line: ~~22~FORCE=~~l7.6890l You may omit the separating comma after an alphanumeric format as shown in the foregoing statement. field, When you omit a comma delimiter from a format specification, format control associates as much information as possible with the leftmost of the two field descriptors. 13.2.10 Multiple Record Specifications To handle a group of input/output records where different records have different field descriptors, use a slash to indicate a new record. For example, the statement FORMAT (308/I5,2F8.4) is equivalent to FORMAT (308) for the first record, and FORMAT (I5,2F8.4) for the second record. You may appear written middle records omit separating commas when you use a slash. When n slashes at the end or beginning of a format, n blank records will be on output or skipped on input. When n slashes appear in the of a format, n-l blank records are written on output or n-l skipped on input. Both the slash and the closing parenthesis at the end of the format indicate the termination of a record. If the list of an input/output statement dictates that the transmission of data is to continue after the closing parenthesis of the format is reached, the format is repeated, starting with: 1. that group repeat specification terminated by the last parenthesis of the next lower level group, or 2. level zero if no higher level group exists. Thus, the statement ! /-vet FORMAT (F7.2, (2{E15.5,E15.4) ,17» leveI6' / level 1 level 1 level 2 13-14 a right FORMAT STATEMEN'l' causes the format 2(E15.5,E15.4) ,17 to be used after the first record. As a further example, consider the statement FORMAT (F7.2/(2(E15.5,E15.4) ,17)) The first record has the format F7.2 and the next 5 records have the format 2( E15 . 5 , E 15 . 4) ,17 13.2.11 Record Formatting Field Descriptors You may use two field descriptors, Tw and nX, to position data a record. within You may use the field descriptor Tw to specify the character position. (external form) in which a record begins. In the Tw field descriptor, . the letter T is the control character, and w is an unsigned integer constant that specifies the character position, in a record, where the; transfer of data is to begin. When the output is printed, w corresponds to the (w-l)th print position, since the first character> of the output buffer is a forms control character and is not printed. It is recommended that the first field specification of the output format be IX, except where a forms control character is used. . NOTE Two successive T field specifications in the second field will result field if the overwriting the first fields overlap. Examples The statement sequence PRINT 2 2 FORMAT (T50, 'BLACK',T30, 'WHITE') causes the following line to be printed WHITE t (print position 29) BLACK t (print position 49) The statement sequence 1 FORMAT (T35, 'MONTH') READ (2,1) 13-15 FORMAT STATEMENT causes the first 34 characters of the input data associated with logical unit 2 to be skipped, and the next five characters to replace the characters M, 0, N, T, and H in storage. If an input record containing ABC~~~XYZ is read with the format specification 10 FORMAT (T7,A3,Tl,A3) then the characters XYZ and ABC are read in that order. You may use the field descriptor nX to introduce blanks into output records or to skip characters of input records. The letter X specifies the operation, and n is a positive integer that specifies the number of character positions to be either made blanks (output) or skipped (input). Example The statement FORMAT (5H~STEP,I5,lOX,2Hy=,F7.3) may be used to print the line 13.2.12 $ Format Descriptor A $ format descriptor at the end of an output FORMAT is used to suppress the carriage return at the end of the current record. It is mainly used on terminal output but will work on non-terminal devices. A $ format descriptor is ignored in input FORMATs and has no effect if embedded in an output FORMAT. The $ format descriptor must be the next format descriptor to be processed when the corresponding output list is exhausted for the $ descriptor to have the defined effect. 13.3 CARRIAGE CONTROL CHARACTERS FOR PRINTING ASCII RECORDS You may use the first character of an ASCII record to control the spacing operations of the line printer or Teletype terminal printer unit on which the record is being printed. Specify the control character desired by beginning the FORMAT field specification for the ASCII record to be output with IHa .•. where a is the desired control character. Table 13-5 describes the control characters permitted in FORTRAN-20 and the effect each has on the printing device. 13-16 < FORMA'l' S'l'ATEMENT Table 13-5 FORTRAN-20 Print Control Characters FORTRAN Character Printer Character Effect Octal Value space LF 012 Skip to next line with form feed after 60 lines o zero LF,LF 012 Skip a line lone FF 014 Form feed - go to top of next page + plus Suppress skipping overprint the line * asterisk DC3 023 Skip to next line with no form feed - minus LF,LF,LF 012 Skip two lines 2 two DLE 020 Space 1/2 of a page 3 three VT 013 Space 1/3 of a page / slash DC4 024 Space 1/6 of a page period DC2 022 Triple space with a form feed after every 20 lines printed , comma DCl 021 Double space with a form feed after every 30 lines printed NOTE Printer control characters DLE, DCl, DC2, DC3, and DC4 affect only the line printer. 13-17 CHAPTER 14 DEVICE CONTROL STATEMENTS 14.1 INTRODUCTION You may use the following source programs: 1. REWIND , 2. UNLOAD 3. BACKSPACE (1) 4. ENDFILE , 5. SKIPRECORD (1) : 6. SKIPFILE 7. BACKFILE device control statements in FORTRAN-20 The general form of the foregoing device control statements is keyword u keyword (u) where keyword u is the statement name is the FORTRAN logical device number 10-1) (Chapter 10, Table The operations performed by the device control statement are normally used only for magnetic tape devices (MTA). In FORTRAN-20, however, the device control operations are simulated for disk devices. The following paragraphs describe the control statements. 14.2 form and use of the device REWIND STATEMENT Form: REWIND u Use: Move the file contained by device u to its initial (load) point. If the medium is already at its load point, this statement has no effect. Subsequent READ 1. The results of these commands are unpredictable when used on directed and NAMELIST-controlled data. 14-1 list- DEVICE CONTROL STATEMENTS or WRITE statements that reference device u will transfer data to or from the first record located on the medium mounted on device u. Example: 14.3 14.4 REWIND 16 UNLOAD STATEMENT Form: UNLOAD u Use: Move the medium contained on device u past its load: point until it has been completely rewound onto the i source reel. Example: UNLOAD 16 BACKSPACE STATEMENT Form: BACKSPACE u Use: Move the medium contained on device u to the start of the record that precedes the current record. If the preceding record prior to execution of this statement was an endfile record, the endfile record becomes the next record after execution. If the current record is the first record of the file, this statement has no effect. NOTE You cannot use this statement for files set up for random access, list-directed, or NAMELIST-controlled I/O operations. Example: 14.5 BACKSPACE 16 END FILE STATEMENT Form: END FILE u Use: Write an endfile record in the file located on device u. The endfile record defines the end of the file that contains it. If an endfile record is reached during an I/O operation initiated by a statement that does not contain an END= option, the operation of the current program is terminated. Example: END FILE 16 14-2 DEVICE CONTROL STATEMENTS 14.6 SKIP RECORD STATEMENT Form: SKIP RECORD u Use: In accessing the file located on record immediately following accessed) record. skip the device u, the current (last NOTE You cannot use this statement for files set for random access, list-directed, NAMELIST-controlled I/O operations. Example: 14.7 14.8 up or SKIP RECORD 16 SKIP FILE STATEMENT Form: SKIP FILE u Use: In accessing the medium located on unit U , skip the file immediately following the current (last accessed) file. If there is no file after the current file, an error will occur. Example: SKIP FILE 01 BACKFILE STATEMENT Form: BACKFILE u Use: Move the medium mounted on device u to the start of the file that precedes the current (last accessed) file. If there is no file before the current file, completion of the last operation will move the medium to the start of the first file on the medium. Example: 14.9 BACKFILE 20 SUMMARY OF DEVICE CONTROL STATEMENTS Table 14-1 summarizes the form and use of device control statements. 14-3 DEVICE CONTROL STATEMENTS Table 14-1 Summary of FORTRAN-20 Device Control Statements Use Statement Form REWIND u UNLoAb"u END FILE u SKIP RECORD u SKIP FILE u BACKFILE u BACKSPACE u 1_ Rewi~d medium to its loadpoi~t Rewind medium on't:o' its s'olirce reel Write an endfile record into the curient ,file, Skip the next record Skip the next file Move medium backwards one file Move medium back 6ne recoid 14-4 CHAPTER 15 SUBPROGRAM STATEMENTS 15.1 INTRODUCTION Procedures you use repeatedly in a program may be written once and then referenced each time you need the procedure. Procedures that may be referenced are either internal (written and contained within the program in which they are referenced) or external (self-contained executable procedures that may be compiled separately). The kinds of procedures that may be referenced are: 1. statement functions, 2. intrinsic functions 3. external functions, and 4. subroutines. (FORTRAN-defined functions), The first three of the foregoing categories are referred to collectively as functions or function procedures; procedures of the last category are referred to as subroutines or subroutine procedures. 15.1.1 Dummy and Actual Arguments Since you may reference subprograms at more than one point throughout a program, many of the values used by the subprogram may be changed each time it is used. Dummy arguments in subprograms represent the actual values to be used, which are passed to the subprogram when it is called. Functions and subroutines use dummy arguments to indicate the type of the actual arguments they represent and whether the actual arguments are variables, array elements, arrays, subroutine names, or the names of external functions. Each dummy argument must be used within a function or subroutine as if it were a variable, array, array element, subroutine, or external function identifier. Dummy arguments are given in an argument list associated with the identifier assigned to the subprogram; actual arguments are normally given in an argument list associated with a call made to the desired subprogram. (Examples of argument lists are given in the following paragraphs.) The position, number, and type of each dummy argument in a subprogram list must agree with the position, number, and type of each argument in the argument list of the subprogram reference. 15-1 SUBPROGRAM STATEMENTS Dummy arguments may be: 1. variables, 2. array names, 3. subroutine identifiers, 4. function identifiers, or 5. statement labei identi"fiers that are den()ted "*", "$", or u&". by the sym"S"of When you reference a subprogram, its dummy arguments are replaced by the corresponding actual arguments supplied in the reference. All appearances of a dummy argument within a function or subroutine are related to the given actual arguments. Except for subroutine identifiers and literal constants, a valid association between dummy and actual arguments occurs only if both are of the same type; otherwise, the results of the subprogram computations will be unpredictable. Argument association may be carried through more than one level of subprogram reference if a valid association is maintained through each level. The dummy/actual argument associations established when a subprogram is referenced are terminated when the desired subprogram operations are completed. The following rules govern the use and form of dummy arguments: 1. The number and type of the dummy arguments of a procedure must be the same as the number and type of the actual arguments given each time the procedure is referenced. 2. Dummy argument names may not appear in EQUIVALENCE, DATA, COMMON statements. 3. A variable dummy argument should have a variable, an array element identifier, an expression, or a constant as its corresponding argument. 4. An array dummy argument should have either an array name or an array element identifier as its corresponding actual argument. If the actual argument is an array, the length of the dummy array should be less than or equal to that of the actual array. Each element of a dummy array is associated directly with the corresponding elements of the actual array. 5. A dummy argument representing a subroutine identifier have a subroutine name as its actual argument. should 6. A dummy argument representing an external function must an external function as its actual argument. have 7. A dummy argument may be defined or redefined in a referenced subprogram only if its corresponding actual argument is a variable. If dummy arguments are array names, then elements of the array may be redefined. or Additional information regarding the use of dummy and actual arguments is given in the description of how subprograms are defined and referenced. 15-2 SUBPROGR~M 15.2 STATEMENTS STATEMENT FUNCTIONS Statement functions define an internal subprogram in statement. The general form of a statement function is: a single name(argl,arg2, ... ,argn)=E where name is a name you assign that consists of one to six characters. The name you use must conform to the rules for symbolic names given in Section 3.3. The type of a statement function is determined either by the first character of its name or by it being explicitly declared in a type statement. (argl ... argn) represents a list of dummy arguments. E is an arbitrary expression. The expression E of a statement function may be any legitimate arithmetic expression that may use the g1ven dummy arguments and indicates how they are combined to obtain the desired value. You may use the dummy arguments as variables or indirect function references; but you cannot use them as arrays. The dummy argument names bear no relation to their use outside the context of the statement function except for their data type. The expression may reference FORTRAN-defined functions (Section 15.3) or any other defined statement function, or call an external function. It may not reference any function that directly or indirectly references the given statement function or any subprogram in the chain of references. That is, recursive references are not allowed. Statement functions produce only one value, the result of the expression that it contains. A statement function cannot reference itself. You must define all statement functions within a program unit before the first executable statement of the program unit. When used, the statement function name must be followed by an actual argument list enclosed within parentheses and may appear in any arithmetic or logical expression. Examples: SSQR(K)=(K*(K+l)*2*K+l)/6 ACOSH(X)=(EXP(X/A)+EXP(-X/A»/2.0 15.3 INTRINSIC FUNCTIONS (FORTRAN DEFINED FUNCTIONS) Intrinsic functions are subprograms supplied by FORTRAN. Reference an intrinsic function by using its name as an operand in an expression. The name always refers to the intrinsic function unless it is preceded by an asterisk (*) or ampersand (&) in an EXTERNAL statement, declared in a conflicting explicit type statement, or specified as a routine dummy parameter. Table 15-1 describes FORTRAN-20 intrinsic functions and their arguments. Notice that octal constants are not allowed as arguments. 15-3 Table 15-1 Intrinsic Functions (FORTRAN-20 Defined Functions) Mnemonic Function I-' U1 I ~ Absolute value: Real Integer Double- precision Complex to real ABS* IABS* DABS* CABS Conversion: Integer to real Real to integer FLOAT* IFIX* Definition Number of Arguments arg arg arg c=(x**2+Y**2)**(1/2) 1 1 1 1 Real Integer Double Complex Real Integer Double Real 1 1 Integer Real Real Integer Sign of arg * largest integer arg ~ til c:: ~ tU !:O o 1 1 1 1 SNGL DBLE* DFLOAT REAL* Double to real Real to double Integer to double Complex to real (obtain real part) Complex to real (obtain imaginary part) Real to complex Type of Argument Functl.on Double Real Integer Complex G1 ~ Real Double Double Real 3: til ~ t-3 AIMAG 1 Complex til Real 3: til Z t-3 Truncation: Real to real CMPLX* c=Arg + i*Arg 2 Real Complex AINT Sign of arg* largest integer arg ~ 1 Real Real 1 1 Real Double Integer Integer INT* IDINT Real to integer Double to integer til i I I * In line functions. -------- --- -- -- I - - I Table 15-1 (Cont.) Intrinsic Functions (FORTRAN-20 Defined Functions) Function Remaindering: Real Integer Double- precision Mnemonic AMOD MOD* DMOD Definition {The remainder when Arg 1 is divided by Arg 2 Number of Arguments } Type of Argument Functlon 2 2 2 Real Integer Double Real Integer Double >1 >1 >1 >1 >1 Integer Real Integer Real Double Real Real Integer Integer Double Maximum value: til AMAXO AMAXl* MAXO* MAXI DMAXI I-' !Max (Argl ,Arg2, • • . )1 Ul I Ul c:: OJ ~ ~ G) ~ 3! ((J Minimum Value: 1-3 AMINO AMINl* MINO* MINI DMINI !Min(Ar g l'Ar g 2'···)1 Transfer of Sign: Real Integer Double precision SIGN* ISIGN DSIGN Positive Difference: Real Integer DIM* IDIM >1 >1 >1 >1 >1 Integer Real Integer Real Double Real Real Integer Integer Double {Si gn(Ar g 2) * Argl} 2 2 2 Real Integer Double Real Integer Double {Ar g l-Min(Ar g l,Ar g 2)} 2 2 Real Integer Real Integer * In line functions. ----- - - ~ I-J ttJ 3: ttJ z 1-] til SUBPROGRAM STATEMENTS 15.4 EXTERNAL FUNCTIONS External functions are function subprograms that consist of a FUNCTION statement followed by a sequence of statements that define one or more desired operations; subprograms of this .type may contain one or more RETURN statements and must be terminated by an END statement. Function subprograms are independent programs that may be referenced by other programs. The FUNCTION statement that identifies an external form: function has the type FUNCTION name (argl,arg2, ... ,argn) where type is an optional type specification as described in Section 6.3. These include INTEGER, REAL, DOUBLE PRECISION, COMPLEX or LOGICAL (plus the optional size modifier, *n, for compatibility with other manufacturers.) name is the name you assign to the function. The name may consist of from one to six characters, the first of which must be alphabetic. You may include the optional size modifier (*n) with the name if the type is specified. (Refer to Section 6.3.) (argl, .•. ,argn) is a list of dummy arguments. If you omit type in the FUNCTION statement, the type of the function may be assigned, by default, according to the first character of its name, or may be specified by an IMPLICIT statement or by an explicit statement given with the subprogram itself. Note that if you want to use the same name for a user-defined function and the name of a FORTRAN-20 defined function (library basic external function), the desired name must be declared in an EXTERNAL statement and prefixed by an asterisk (*) or ampersand (&) in the referencing routine. (Refer to Section 6.7 for a description of the EXTERNAL statement.) The following rules govern the structuring of a FUNCTION subprogram: 1. You must use the symbolic name assigned a FUNCTION subprogram as a variable name in the subprogram. During each execution of the subprogram, this variable must be defined and, once defined, may be referenced or redefined. The value of the variable at the time of execution on any RETURN statement is the value of the subprogram. NOTE A RETURN statement returns control to the calling statement that initiated the execution of the subprogram. See Section 15.6 for a description of this statement. 15-6 SUBPROGP~M SThTEMENTS 2. You may not use the symbolic name of a FUNCTION subprogram in any nonexecutable statement in the subprogram except in the initial FUNCTION statement or a type statement. 3. Dummy argument names may not appear in any EQUIVALENCE, COMMON, or DATA statement used within the subprogram. 4. The function subprogram may define or redefine one or more of its arguments so as to effectively return results in addition to the value of the function. 5. The function subprogram may contain any FORTRAN statement except BLOCK DATA, SUBROUTINE PROGRAM, another FUNCTION statement, or any statement that directly or indirectly references the function being defined or any subprogram in the chain of subprograms leading to this function. 6. The function subprogram should contain at least one RETURN statement and must be terminated by an END statement. The RETURN statement signifies a logical conclusion of the computation made by the subprogram and returns the computed function value and control to the calling program. A subprogram may have more than one RETURN statement. The END statement specifies the subprogram and implies a return. 15.4.1 physical end of the Basic External Functions (FORTRAN-20 Defined Functions) FORTRAN-20 contains a group of predefined external functions that are called basic functions. Table 15-2 describes each basic function, its name, and its use. These names always refer to the basic external functions unless declared in an EXTERNAL or conflicting explicit type statement. 15.4.2 Generic Function Names The compiler generates a call to the proper FORTRAN-20 defined function, depending on the type of the arguments, for the following generic function names: ABS AMAXI AMINI ATAN ATAN2 COS INT MOD SIGN SIN SQRT EXP ALOG ALOGIO In the following example K=ABS(I) 15-7 SUBPROGRAM STATEMENTS the type of I determines which function is called. If I is an integer, the compiler generates a call to the function lABS. If I is real, the compiler generates a call to the function ABS. If I is double precision, the compiler generates a call to the function DABS. The function name loses its generic properties if it appears in an explicit type statement, if it is specified as a dummy routine parameter, or if it is prefixed by n*n or n&" in an EXTERNAL statement. When a generic function name that was specified unprefixed in an EXTERNAL statement is used as a routine parameter, it is assumed to reference a FORTRAN-20 defined function of the same name, or if none exists, a user-defined function. Note that IMPLICIT statements have no effect upon the data type of generic function names unless the name has been removed from its class by use of an EXTERNAL statement. 15.5 SUBROUTINE SUBPROGRAMS A subroutine is an external computational procedure that is identified by a SUBROUTINE statement and mayor may not return values to the calling program. The SUBROUTINE statement used to identify a subprogram of this type has the form: SUBROUTINE name(argl,arg2, ... ,argn) where name is the symbolic name of the subroutine to defined. (argl, ... ,argn) is an optional list of dummy arguments. 15-8 be Table 15-2 Basic External Functions (FORTRAN-20 Defined Functions) Function Exponential: Real Double Complex Logarithm: Real Double I--' Ul I \D Complex Square Root: Real Double Complex Number of Arguments Type of Funct~on Argument EXP DEXP CEXP t9} 1 1 1 Real Double Complex Real Double Complex ALOG ALOGIO DLOG DLOGIO CLOG In (Arg) log (Arg) In (Arg) log (Arg) In (Arg) 1 1 1 1 1 Real Real Double Double Complex Real Real Double Double Complex UJ C ttl It! ~ G'l ~ s: SQRT* DSQRT CSQRT (Arg)**1/2 (Arg)**1/2 (Arg)**1/2 1 1 1 Real Double Complex Real Double Complex Ul t-3 :tJ t-3 j:l1 ~ Z 1-3 Sine: Real (radians) Real (degrees) Double (radians) Complex SIN* SIND DSIN CSIN Cosine: Real (radians) Real (degrees) Double (radians) Complex COS* COSD DCOS CCOS *Generic functions Definition Mnemonic {Sin (Ar 9 )} 1 1 1 1 Real Real Double Complex Real Real Double Complex {COS (Ar 9 )} 1 1 1 1 Real Real Double Complex Real Real Double Complex (fl Table 15-2 (Cont.) Basic External Functions (FORTRAN-20 Defined Functions) Function I-' U1 I I-' a Mnemonic Definition Hyperbolic: Sine Cosine Tangent SINH COSH TANH sinh(Arg} cosh(Arg) tanh(Arg} Arc sine ASIN Arc cosine ACOS Number of Arguments 1 Type of Argument I Function 1 Real Real Real Real Real Real asin(Arg} 1 Real Real acos(Arg} 1 Real Real 1 til c: III td Arc tangent Real Double Two REAL arguments Two DOUBLE arguments ATAN* DATAN ATAN2* DATAN2 atan(Arg} datan(Arg} atan(Argl/Arg2} atan(Argl/Arg2} 1 1 2 2 Real Double Real Double Real Double Real Double Complex Conjugate CONJG Arg=X+iY,CONJG=X-iY 1 Complex Complex Random Number RAN Result is a random number in the range of 0 to 1.0 Real 1 Dummy Argument Integer, Real, Double, or Complex ~ (j) ~ til 1-3 *Generic functions I ~ 1-3 t%j ~ Z 1-3 til SUBPROGRAM STATEHENTS The following subprogram: rules control the structuring of a subroutine 1. You may not use the symbolic name of the subprogram in any statement within the defined subprogram except the SUBROUTINE statement itself. 2. You may not use the given dummy arguments in an EQUIVALENCE, COMMON, or DATA statement within the subprogram. 3. The subroutine subprogram may define or redefine one or of its arguments so as to effectively return results. 4. The subroutine subprogram may contain any FORTRAN statement except BLOCK DATA, FUNCTION, another SUBROUTINE statement, or any statement that either directly or indirectly references the subroutine being defined or any of the subprograms in the chain of subprogram references leading to this subroutine. 5. Dummy arguments that represent statement labels may be either an *, $, or &. 6. The subprogram should contain at least one RETURN statement and must be terminated by an END statement. The RETURN statements indicate the logical end of a computational routine; the END statement signifies the physical end of the subroutine. 7. Subroutine subprograms may have as many entry points as desired (see description of ENTRY statement given in Section 15.7) . 15.5.1 more Referencing Subroutines (CALL Statement) You must reference subroutine subprograms by using a CALL statement of the following form: CALL name(argl,arg2, ... ,argn) where of the name is the symbolic name subroutine subprogram. (argl, ... ,argn) is an optional list of actual arguments. If the list is included, the given actual arguments must agree in order, number, and type with the corresponding dummy arguments given in the defining SUBROUTINE statement. The use of literal constants is an exception to the rule agreement of type between dummy and actual arguments. argument in a CALL statement may be: 1. a constant 2. a variable name 15-11 desired requiring An actual SUBPROGRAM STATEMENTS 3. an array element identifier 4. an array name 5. an expression 6. the name of an external subroutine, or 7. a statement label. Example: The subroutine SUBROUTINE MATRIX (I, J , K, M':*) END may be referenced by CALL MATRIX(lO,20,30,40,§lOl) 15.5.2 FORTRAN-20 Supplied Subroutines FORTRAN-20 provides you with an extensive group of predefined subroutines. Table 15-3 gives the descriptions and names of these predefined subroutines. 15.6 RETURN STATEMENT AND MULTIPLE RETURNS The RETURN statement causes control to be returned from a to the calling program unit. This statement has the form: RETURN (standard return) RETURN e (multiple returns) subprogram or : where e represents anintege~constant,variable! or expression. The executi6n of this st~t~m~nt in the first of the friiegoing f6rm~ '(i.e., standard return) causes control to be returned to the statement of the calling program that follows the statement that called the subprogram. ,... " ~, ,." , v~ The multiple returns form of this statement, i.e., RETURN e, enables you to select any labeled statement of the calling program as a return' point. When the multiple returns form of this statement is executed,' the assigned or calculated value of e specifies that the return is to; be made to the eth statement label in the argument list of the calling ,statement. The value of e should be a positive integer that is equal' to or less than the number of statement labels given in the argument, ' l i s t of the calling statement. If e is less than 1 or is larger than the number of available statement labels, a standard return operation: is performed. 15-12 SUBPROGRl\M STl\TEMENTS NorrE A dummy argument for a statement label must be either a *, $, or & symbol. You may use any number of RETURN (standard return) statements in any subprogram. The use of the multiple returns form of the RETURN statement, however, is restricted to subroutine subprograms. The execution of a RETURN statement in a main program will terminate the program. Example Assume the following statement sequence in a main program: CALL EXAMP(1,$lO,K,$15,M,'$20) GO TO 101 ' 10 15 20 15-13 SUBPROGRAM STATEMENTS Assume the following subprogram: statement sequence in the called SUBROUTINE SUBROUTINE EXAMP (L, ;*,M, ;*,N,::X) RETURN RETURN :RETURN(CjD) . END Each occurrence of RETURN returns control to the statement GO in the calling program. If, on t'he exe~ution of' th~ RETURN (C/D) stateme'nt,'0 the value of is: Less than or equal to: o 1 2 3 Greater than or equal to: 4 15.6.1 TO 0. 101 (C/I)f*~ The following is performed: a standard return to the GO TO statement is made the return is made to statement 10 the return is made to statement 15 the return is made to statement 20 101 The following is performed: a standard return to the GO TO 101 statement is made. Referencing External FUNCTION Subprogram Reference an external function subprogram by using its assigned name as an operand in an arithmetic or logical expression in the calling program unit. The name must be followed by an actual argument list. The actual arguments in an external function reference may be: 1. a variable name, 2. an array element identifier, 3. an array name, 4. an expression, 5. a statement number, or 15-14 SUI3PROGRAr·1 STATEMENTS 6. the name of SUBROUTINE) . another external procedure FUNCTION or NOTE Any subprogram name to be used as an argument to another subprogram must first appear in an EXTERNAL statement (Chapter 6) in the calling program unit. Example The subprogram defined as: INTEGER FUNCTION ICALC(IX,IY,IZ) RETURN END may be referenced in the following manner: TOTAL=ICALC(IAA,IAB,IAC)+SOO 15.7 MULTIPLE SUBPROGRAM ENTRY POINTS (ENTRY STATEMENT) FORTRAN-20 provides an ENTRY statement that enables you to specify additional entry points into an external subprogram. This statement< used in conjunction with a RETURN statement enables you to employ only one computational routine of a subprogram that contains several such routines. The form of the ENTRY statement is: ENTRY name(argl,arg2, ... ,argn) where name is the symbolic name desired entry point (argl, ... ,argn) is an optional list of dummy arguments. list may contain 1. variable names, 2. array declarators, 15-15 to be assigned the This SUBPROGRAM STATEMENTS 3. the name of an external (SUBROUTINE or FUNCTION), or procedure 4. are statement label identifiers that denoted by either a *, $, or & symbol. The rules for the use of an ENTRY statement follow: 1. The ENTRY statement allows entry into a subprogram at a place other than that defined by the subroutine or function statement. You may include any number of ENTRY statements in an external subprogram. 2. Execution is begun at the first following the ENTRY statement. 3. Appearance of an ENTRY statement in a subprogram does not. negate the rule that statement functions in subprograms must· precede the first executable statement. 4. Entry statements are nonexecutable execution flow of a subprogram. affect the 5. You may not use an ENTRY statement in a main program or a subprogram reference itself through its entry points. have. 6. You may not use an ENTRY statement in the range of a DO or an extended DO statement construction. 7. The dummy arguments in the ENTRY statement need not agree in order, number, or type with the dummy arguments in SUB~OUTINE or FUNCTION statements of any other ENTRY statement 1n the subprogram. However, the arguments for each call or function reference must agree with the dummy arguments in the: SUBROUTINE, FUNCTION, or ENTRY statement that is referenced. 8. Entry into a subprogram initializes only the dummy of the referenced ENTRY statement. 9. You may not reference a dummy argument unless it appears in the dummy list of an ENTRY, SUBROUTINE, or FUNCTION statement by which the subprogram is entered. 10. The source subprogram must be ordered such that references to dummy arguments in executable statements follow the appearance of the dummy argument in the dummy list of a SUBROUTINE, FUNCTION, or ENTRY statement. 11. Dummy arguments that were defined for a subprogram by some· previous reference to the subprogram are undefined for subsequent entry into the subprogram. 12. The value of the function must be current entry name. 15-16 executable and do returned statement not by use arguments of the SUBPROGRAM STATEMENTS Table 15-3 FORTRAN-20 Library Subroutines Subroutine Name Effect CALL AXIS(X,Y,ASC,NASC,S,THETA,XMIN,DX) AXIS AXIS causes an axis with tick marks and scale values at I-inch increments to be drawn. An identifying label may also be plotted along the axis. Parameters X and Y specify the start of the axis. The axis is plotted, starting at X, Y, at an angle of THETA degrees for a distance of S inches. The angle THETA is usually either 0 (X axis) or 90.0 (Y axis). Characters ASC of array ASC are plotted as a label for the axis drawn. If NASC is positive, the tic marks, label, and scale values are placed on the counterclockwise side of the axis; if NASC is negative, the foregoing items are placed on the clockwise side of the axis. Parameter XMIN is the value of the scale at the beginning of the axis; parameter DX is the change in scale for a I-inch increment. The values of XMIN and DX may be determined by subroutine SCALE. DATE CALL DATE (array) This subroutine places today's date as left-justified ASCII characters into a dimensioned 2-word array. The date is in the form: dd-mmm-yy where dd is a 2-digit day (if the first digit is 0, it is converted to a blank), mmm is a 3-letter month abbreviation, e.g., Mar, and yy is a 2-digit year. The data is stored in ASCII code, left-justified, in the two words. DEFINE FILE CALL DEFINE FILE (u,s,v,f,pj,pg) The arguments follows: u = of this subroutine are defined as logical device numbers. s = the size of the records comprising the file being defined. The argument s may be an integer constant or variable. v = an associated variable. The associated variable is an integer variable that is set to a value that points to the record that immediately follows the last record transferred. This variable is modified by the FIND statement (Chapter 10) . At the end of each FIND operation, the variable is set to a value that points to the record found. The variable v cannot appear in the I/O list of any I/O statement that accesses the file set up by the DEFINE FILE statement. 15-17 SUBPROGRAM STATEMENTS Table 15-3 (Cont.) FORTRAN-20 Library Subroutines Subroutine Name Effect = filename to be given the file being defined. pj = your project number. f pg your programmer's number. NOTE Numbers pj and Directory. pg identify your File Example The statement CALL DEFINE FILE (l,lO,ASCVAR, 'FORTFL.DAT',O,O) establishes a file named FORTFL.DAT on device 01, a disk, which contains ten word records. The associated variable is ASCVAR, and the file is in your area. A DEFINE FILE call can be used to establish and define the structure of each file to be used for random access 1/0 operations. NOTE The OPEN statement may be used to perform the same functions as DEFINE FILE. DUMP CALL DUMP (L ( I) , U(1) , F (I) , ... , L (n) I U (n) ,F (n) ) DUMP causes particular portions of memory to be dumped. L(l) and U(l} are the variable names that give the limits of memory to be dumped. Either L(l} or U(l} may be upper or lower limits. F(l) is a number indicating the format in which the dump is to be performed: 0 = octal, 1 = real, 2 = integer, and 3 = ASCII. If F is not 0, 1, 2, 3, the dump is in octal. If F(n) is missing, the last section is dumped in octal. If U(n} and F(n} are missing, an octal dump is made from L to the end of the job area. If L(n}, U(n), and F(n) are missing, the entire job area is dumped in octal. The dump is terminated by a call to EXIT. 15-18 SUBPROGR~M STATEMENTS Tctble lS-3 (Cant.) FORTRAN-20 Library Subroutines Subroutine Name ERRSET Effect CALL ERRSET(N) ERRSET allows you to control the typeout of execution-time arithmetic error messages. ERRSET is called with one integer argument. Typeout of all arithmetic and library error messages is suppressed after N occurrences of these error messages. If ERRSET is not called, the default value of N is 2. ERRSNS CALL ERRSNS(I,J) ERRSNS allows you to determine the exact nature of an error on READ, WRITE, OPEN, or CLOSE that was trapped with the "ERR= statement label" option. ERRSNS returns one or two integer values that describe the status of the last I/O operation performed by FOROTS. (The second integer value is optional.) CALL ERRSNS(I,J) returns a FORTRAN-standardized number in I and a processor-dependent number in J to describe the last I/O operation. See Appendix H and Table H-l for more information and a detailed description of the values returned. EXIT EXIT EXIT returns control to the Monitor and, terminates the execution of the program. ILL therefore, CALL ILL If the flag is set and an ILL sets the ILLEG flag. illegal character is encountered in floatingpoint/double- precision input, the corresponding word is set to zero. LEGAL CALL LEGAL LEGAL clears the ILLEG flag. If the flag is set and an illegal character is encountered in the floatingpoint/double- precision input, the corresponding word is set to zero. LINE CALL LINE (X,Y,N,K) LINE causes a line to be drawn through the N points specified by (X(l) ,Y(l», (X(2) ,Y(2» ... (X(N) ,Y(N» where the elements of X and Y are spaced K words apart in storage. 15-19 SUBPROGRAM STATEMENTS Table 15-3 (Cont.) FORTRAN-20 Library Subroutines Subroutine Name MKTBL Effect CALL MKTBL{I,J) MKT~L specifies a special character set where I is the number to be assigned the set and J contains the starting address of a character table of 200(8) consecutive words. In each character table word, the left half contains the number of strokes in the character (0 if nothing is to be plotted fOL the wOLd) and the right half contains the address of the table of strokes for the character. NUMBER CALL NUMBER(X,Y,SIZE,FNUM,THETA,NDIGIT) NUMBER causes a floating- point number to be plotted as text. PaLameters X, Y, SIZE, and THETA have the same meanings as for the SYMBOL call. PaLameter NDIGIT is the number of digits plotted to the right of the decimal point. If NDIGIT is a negative value, only the integeL part of the number is plotted. FNUM specifies the number to be plotted. PDUMP CALL PDUMP (L (1) I U ( 1) ,F (1) , •.. I L (n) I U (n) ,F (n) The arguments of PDUMP are the same as those of DUMP. PDUMP is the same as DUMP except that control returns to the calling program after the dump has been executed. PLOT CALL PLOT(X,Y,IPEN) PLOT moves the pen in a straight line from its current position to the position specified by X,Y. If IPEN=3, the pen is raised before the movement; if IPEN=2 the pen is loweLed before movement; if IPEN=l the pen is left unchanged from its previous state. If the value of IPEN is negative (-1, -2 or -3) the pen action is the same as for the corresponding positive values except that on completion of the indicated motion, the new pen position is taken as a new origin and the output buffer is sent to the plotteL. The plotter is not released specified movement. PLOTS on completion of the CALL PLOTS (I) PLOTS is the plotter setup routine. If the plotter LS not available, I is set to -1; if it is available, I is set to O. This call must be the first plotter routine called. 15-20 SUBPROGRAH STATm·mNTS Table 15-3 (Cont.) FORTRAN-20 Library Subroutines Subroutine Name RELEAS Effect CALL RELEAS(unit) RELEAS closes out I/O on a device initialized by the FORTRAN Object Time System and returns it to the uninitialized state. RELEAS should be the last call referencing that device. SAVRAN CALL SAVRAN(I) SAVRAN is called with one integer argument. SAVRAN sets its argument to the last random number (interpreted as an integer) that has been generated by the function RAN. SCALE CALL SCALE(X,N,S,XMIN,DX) SCALE selects scale values for an AXIS call where X and N specify a I-dimensional array X with the length N. Parameter S specifies the length of the desired axis, SCALE determines a value of DX that allows X to be plotted in S inches. XMIN is selected as the smallest element of the array X, and is truncated to be a multiple of DX. SETABL CALL SETABL(I,J) SETABL specifies a character set where I is an integer that gives the number of the desired character set. If a character set has been defined by I, the value of J is set to 0; if not, J is set to -1. The standard ASCII character set is defined as 1. SETRAN CALL SETRAN (I) SETRAN has one argument, which must be a non-negative integer <2**(31). The starting value of the function RAN is set to the value of this argument, unless the argument is zero. In this case, RAN uses its normal starting value. SORT CALL SORT ('OUTPUT/SWS=INPUT/SWS,INPUT/SWS') SORT sorts one or more files using the SORT program. The argument is an ASCII string that represents (version 3 or later) the standard SORT command string. Its components are: OUTPUT INPUT SWS file specification of the output file. file specification of the input file(s). one or more switches for the output file, the input file(s), the sorting process, and sometimes SCAN. The switches not allowed in the FORTRAN call are:/BLOCK, /COMP3, /EBCDIC, /INDUSTRY, /LABEL, /SIXBIT, and /VERSION. 15-21 SUBPROGRAM STATEMENTS Table 15-3 (Cont.) FORTRAN-20 Library Subroutines Subroutine Name Effect Wild card format is not allowed in the SORT call. For information about using the SORT program, see the SORT Userls Guide. Example: .. CALL SORT('SRTFIL.SRT=INSTRT/REC:80/KEY:l:2'} SYMBOL CALL SYMBOL(X,Y,SIZE,ASC,THETA,NASC) SYMBOL raises the plotter pen and moves it to position specified by X and Y. Lower pen and plot' characters found in array ASC. Parameter ~IZE specifies the height of the characters plotted in inches (floating- point values); THETA specifies the direction of the base line on which the text of array ASC is to be plotted, and NASC specifies the number of characters in array ASC.' TIME CALL TIME(X) or CALL TIME(X,Y) TIME returns the current time in its argument(s) in left-justified ASCII characters. If TIME is called with one argument, CALL TIME(X) the time is in the form hh:mm where hh is the hours (24-hour time) and mm minutes. If a second argument is requested, is the CALL TIME(X,Y) the first argument is returned in the same form as the one-argument call, and the second has the form bss.t where b is a blank, ss is in seconds, tenths of a second. WHERE and t is in. CALL WHERE(X,Y) Variables X and Yare set to the values identify the current position of the pen. 15-22 which CHAPTER 16 BLOCK DATA SUBPROGRAl>1S 16.1 INTRODUCTION Use block data subprograms to initialize data to be stored in any common areas. You may use only specification and DATA statements, i.e., DATA, COMMON, DIMENSION, EQUIVALENCE, and TYPE, in BLOCK DATA subprograms. A subprogram of this type must start with a BLOCK DATA statement. You may enter initial values into more than one labeled in a single subprogram of this type. common block An executable program may contain more than one block data subprogram. 16.2 BLOCK DATA STATEMENT The form of the BLOCK DATA statement is: BLOCK DATA name where name is a symbolic subprogram. 16-1 name given to identify the APPENDIX A ASCII-1968 CHARACTER CODE SET The character code set defined in the X3.4-l968 Version of the Information Interchange (ASCII) is American National Standard for given in the following matrix. 1st 2 octal digits Last octal digit o 1 OOX Olx 02x 03x NUL BS DLE CAN 04x ~ 05x ( 0 8 06x 07x lOx llx l2x 13x l4x l5x l6x 17x SOH HT DCl EM ! ) 1 9 A I Q Y a i q y @ H p X grave h p x 2 3 4 5 6 7 STX LF DC2 SUB ETX VT DC3 ESC ENQ CR NAK GS ACK SO SYN RS BEL SI ETB US " # + EOT FF DC4 FS $ % & , 3 4 5 6 : ; < = > B J R Z b j r z C K S [ c k s D L T E M U \ 1 d I t e m u { I } F N V A(t) f n v -(ESC) * 2 , / 7 ? G 0 W (*-) g - Characters inside parentheses are ASCII·1963 Standard. NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI Null Start of Heading Start of Text End of Text End of Transmission Enquiry Acknowledge Bell Backspace Horizontal Tabulation Line Feed Vertical Tabulation Form Feed Carriage Return Shift Out Shift In DLE DCl DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US DEL A-I Data Link Escape Device Control 1 Device Control 2 Device Control 3 Device Control 4 Negative Acknowledge Synchronous Idle End of Transmission Block Cancel End of Medium Substitute Escape File Separator Group Separator Record Separator Unit Separator Delete (Rubout) 0 w DEL Graphic subsets 64 95 APPENDIX B USING THE COMPILER This appendix explains how to access FORTRAN-20 and how to make use of the information it provides. You should be familiar with the FORTRAN-20 language and the DECsystem-20 TOPS-20 monitor. B.l RUNNING THE COMPILER The command to run FORTRAN-20 is: @FORTRA The compiler responds with an asterisk (*) and is then ready to accept a command string. A command is of the general form: object filename, listing filename=source filename(s) You are given the following options: B.l.l 1. The filenames can be fully specified with SFD paths. 2. You may specify more than one input file in the compilation command string. These files will be logically concatenated by the compiler and treated as one source file. 3. Program units need not be terminated at file may consist of more than one file. 4. If no object filename is file is generated. 5. If no listing filename is specified, no listing is generated. 6. If no extension is given, the defaults are .LST .REL (relocatable binary), and .FOR (source) respective files. specified, no boundaries relocatable and binary (listing) , for their Switches Available with FORTRAN-20 Switches to FORTRAN-20 are accepted anywhere in the command string. They are tQtally position- and file-independent. Table B-1 lists the switches. '. B-1 USING THE COMPILER Table B-1 FORTRAN-20 Compiler Switches Switch Meaning Defaults CROSSREF Generates a file that can be input to the CREF program OFF DEBUG (See Section B.l.l.l.) OFF EXPAND Includes the octal-formatted version of the object file in the listing. OFF INCLUDE Compiles a D in column 1 as space. OFF LNMAP Produces a line number/octal location map in the listing only if /MACROCODE was not specified. OFF MACROCODE Adds the mnemonic translation of the object code to the listing file. OFF NOERRORS Does not print error messages on the terminal. OFF NOWARNINGS Does not output warning messages. OFF OPTIMIZE Performs global optimization. OFF SYNTAX Performs syntax check only. OFF Each switch must be preceded by a slash (/). Switch names need only contain those letters that are required to make the switch name unique. You are encouraged to use at least three letters to prevent conflict with switches in future implementations. Example @FORTRA *OFILE,LFILE=SFILE/MAC,S2FILE The /MAC switch will cause the MACRO code equivalent of SFILE.FOR S2FILE.FOR to appear in LFILE.LST. All switches used or implied are printed at the top page. B-2 of each and listing USING THE COMPILER B.l.l.l The /DEBUG Switch - The /DEBUG switch tells FORTRAN-20 to compile a series of debugging features into your program. Several of these features are specifically designed to be used with FORDDT. Refer to Appendix E for more information. By adding the modifiers listed in Table B-2, you can include specific de~ugging features. Table B-2 Modifiers to /DEBUG Switch Meaning Modifiers :DIMENSIONS Generates dimension information in .REL FORDDT. : TRACE Generates references to FORDDT required for its trace features (automatically activates :LABELS). :LABELS Generates a label for each statement of the form "line-number L." (This option may be used without FORDDT.) :INDEX Forces DO LOOP indices to be stored at the beginning of each iteration rather than held in a register for the duration of the loop. :BOUNDS Generates the bounds checking code for all array references. Bounds violations will produce run-time error messages. Note that the technique of specifying dimensions of 1 for subroutine arrays will cause bounds check errors. (You may use this option without FORDDT.) :NONE Do not include any debug features. :ALL Enable all debugging aids. file for The format of the /DEBUG switch and its modifiers is as follows: /DEBUG:modifier or /DEBUG: (modifier list) Options available with the /DEBUG modifiers are: 1. No debug features - Either do not specify the or include /DEBUG:NONE. 2. All debug features - Either /DEBUG or /DEBUG:ALL. 3. Selected features - Either a i.e., /DEBUG:BOU/DEBUG:LAB or a list of modifiers /DEBUG: (BOU,LAB, •.. ) B-3 series of /DEBUG modified switch switches; USING THE COMPILER 4. Exclusion of features (if you wish all but one or modifiers and do not wish to list them all, you may use prefix "NO" before the switch you wish to exclude). exclusion of one or more features implicitly includes all others, i.e., /DEBUG:NOBOU is the same /DEBUG: (DIM,TRA,LAB,IND). two the The the as If you include more than one statement on a single line, only the first statement will receive a label (/DEBUG:LABELS) or FORDDT reference (/DEBUG:TRACE). (The /DEBUG option and the /OPTIMIZE option cannot be used at the same time.) NOTE If a source file contains line sequence numbers that occur more than once in the same subprogram, the /DEBUG option cannot be used. The following formulas may be used to determine the increases in program size that will occur as a result of the addition of various /DEBUG options. :DIMENSIONS For each array, 3+3*N words where N is the number of dimensions, and up to three constants for each dimension. : TRACE One instruction per executable statement. :LABELS No increase. :INDEX One instruction per instruction for some index of the loop. inner of the loop plus one references to the :BOUNDS For each array, DIMENSIONS:. formula is the the same as For each reference to an array element, use 5+N words where N is the number of dimensions in the array. If you do not specify :BOUNDS, approximately 1+3*(N-l) words will be used. B.l.2 LOAD-Class Commands You can invoke FORTRAN-20 by using LOAD-class commands. These commands cause the monitor to interpret the command and construct new command strings for the system programs actually processing the command. COMPILE LOAD EXECUTE DEBUG B-4 USING THE COMPILER Example .EXEC ROTOR The compiler switches OPT, CREF, and DEBUG may be specified LOAD-class commands and may be used globally or locally. in Example .EXECUTE/CREF Pl.FOR,P2.FOR/DEBUG:NOBOU The other compiler switches must be passed specific source file. in parentheses for each Example .EXECUTE Pl.FOR(M,I) Refer to the Monitor Calls User's Guide for further information. B.2 READING THE LISTING When you request a listing from the FORTRAN compiler, it contains following information: the 1. A printout of the source program plus an internal sequence number assigned to each line by the compiler. This internal sequence number is referenced in any error or warning messages generated during the compilation. If the input file is line-sequenced, the number from the file is used. If code is added via the INCLUDE statement, all INCLUDEd lines will have an asterisk (*) appended to their line-sequence number. 2. A summary of the names and relative octal) of scalars and arrays in compiler generated variables. 3. All COMMON blocks and the relative locations the variables in each COMMON block. 4. A listing of all equivalenced variables or arrays relative locations. 5. A listing of the subprograms referenced and FORTRAN defined library functions). 6. A summary of temporary locations generated by the compiler. 7. A heading on each page of the listing containing the program unit name (MAIN., program, subroutine or function, principal entry), the input filename, the list of compiler switches, and the date and time of compilation. 8. If you used the /MACRO switch, a mnemonic printout of the generated code (in a format similar to MACRO) is appended to the listing. This section has four fields: B-5 program locations (in the source program plus (both (in octal) and user of their defined USING THE COMPILER LINE: This column contains the internal sequence number of the line corresponding' to the mnemonic code. It appears on the first instruction of the code sequence associated with that internal sequence number. An asterisk indicates a compiler inserted line. LOC: The relative location in the object program of the instruction. LABEL: Any program or compiler generated label. Program labels have the letter "P" appended. Labels generated by the compiler are followed by the letter i'M". Labels generated by the compiler and associated with the /DEBUG:LABELS switch consist of the internal sequence number followed by an "L". GENERATED CODE: The MACRO mnemonic code. If you used the /LNMAP switch and did NOT use the /MACRO switch, a line number/octal location map is appended to the listing. This section lists the line numbers in increments of 10 on subsequent lines and each number from 0 through 9 for each line in adjacent columns. The numbers appearing inside the matrix are the relative octal locations of the statements in the FORTRAN program unit. For example, to find the relative octal location of line number 001043, find the row marked 001040 and then column 3 on that line. The number in that place is the desired relative location. This listing can be very large and sparse for line-numbered files with large increments, such as those produced by EDIT. NOTE One FORTRAN line can produce multiple octal locations. In this case the line number map lists only the first location. 9. A list of all argument blocks generated by the compiler. A zero argument appears first followed by argument blocks for subroutine calls and function references {in order of their appearance in the program}. Argument blocks for all I/O operations follow this. 10. Format statement listings. 11. A summary of errors during compilations. B.2.l detected or warning messages issued Compiler Generated Variables In certain situations the compiler will generate internal variables. Knowing what these variables represent can help you read the macro expansion. The variables are of the form: .letter digit digit digit digit i.e., .50001 B-6 USING THE COMPILER where: Letter Function of Variable A Register save area. F Arithmetic statement function formal parameters. I Result of a DO LOOP initial value expression parameter of an adjustably dimensioned array. o Result of a common subexpression (see Section or constant computation (C.2.1.3). Q Temporary storage for expression values. R Result of (C.2.1.2). S Result of the DO LOOP step size expression of iteration count for a loop. reduced operator strength or C.2.1.1) expression computed You may find these variables on the listing under SCALARS and ARRAYS. The following example shows a listing where pointed out. B-7 all these features are compiler Compiled for KI processor verlion ~CRO Code equivalent included Program Source Name Filename + MAIN. + T If<l 1 I co f'OHTKAfII v.~(~15) IKI/M 1o-MAk-77 Kl=r·J IfCK1.LT.500.uR.Kl.GT.1500) Kl=O 00009 00010 00011 00012 00013 00014 A(I,J)=Kl K2=1+J 00016 00017 00018 00019 PAGE 1 00 100 1=1,100 QOOOH 0001~ 16:05 IMPLICIT IhTEG~R (A-ZJ DIMENSION A(lUO,2u0J,H(100,200) .':iUt-i1=O SIJM2=O DO 100 J=1,20() 00001 00002 00003 00004 00005 00006 00007 tp 1 c:: en 1 f (1\2. ElJ • 100. OR • K2 • E(~ • 200 • OI~ .1\ 2. EO. 300 ) K2=K2+1 8(I,J)=K2 SUM1=SLJM1+Kl 10 tJl CUNTlfllLiE TYPE 10,SUMl,5UM2 FORMAT(7H SUM1= ,19,10H EfIIV Z 1-3 tI:: S{)H2=SUM2+K2 100 C H G1 (') o 3: "0 SUfv12= ,19) H t"t tJl ~ 5VI:1Pi-<lJGRAr"lS CALLi(; SCALARS AND ARRAYS "*" NO r.:Xt-'l.JICl'l' Ot:l'"I{liI'l'lUN n%" NOT Rt:Ft:RENCED J ~Compiler Generated Variable 47042 A 47043 .50001 116103 *K1 1 B 2 *J 116106 *"'2 11b107 *SUM1 116110 .50000 110104 *suM2 116105 *1 ~_________________________~Internal sequence n~ber of first instruction that goes with this line + LINE IJUC LABt:L GENt:kATEO COD£<.: • 3 4 5 tJj JFCL 1 2 3 4 JSP 7 B 8 10 11 2,SUMl 2,SUM2 C 2, (7774', 0000001 J Gl HLkEM 2,.50000 HRkZH 2,J MUVE 2,[777b3400(001) ra MOVE .3,J 3,0(2) t"" til H :z 1-3 ::c [tl 2 {Ill : () 3~1 : o 4M: H 12 J.MULI 13 MOVEt-l CAlL 14 15 16 17 20 16,RE5ET. l·iOVEN HOVt: SETZ~ ~ b 0,0 0,0 5 6 7 I Octal displacement of instruction o Jk5T 3,1<1 3,764 3,2734 O,oM JRS'I O,5""J SETZB 4,Kl CAIL~ 6rYl: .. t::l ~ Compiler Generated Label l-lAlfII. TIMl fUKTKAN 9 21 51>"1 : 22 10 11 I 3 , ~J 3,0(2) MOV~ 4,Kl 4,A-145(3) 26 "',uVE 3,J 27 3,OCD 30 AOD! ;v,uVt:M 31 i·IOVE 3:l CAlE 33 CAIN 5,K2 5,144 5,310 O,BM JRS'f 12 37 7 (vI: I--' 40 41 42 43 44 45 46 PAGE 1-1 3,K2 c:: til CAIN 5,454 AUS 3,K2 NOV~: 1 3,144 II1UL ADDI tviOVE 3,0(2) MUVEtvl 5,8-145(3) ADlJM A()DM ..... zG') 8 :c ttl (") 3,J 0 3: I'C ..... 5,K2 t'1 ttl ~ 4,SUlw11 5,SlJM2 Program label lOOP: .. 17 52 19 53 54 55 56 AOHJN AOS AOSG£ JRSl' i'tlQVEI PUSHJ MOVEl PUSHJ MUVE! 57 PUSrlJ 47 50 51 1b:05 Yt-\ ; Hr-. : 13 3,144 IMUI, AlJDI HOVEM 36 14 15 MOV~l 1 b-MAk--' I 2!J 11 0 IKI/M :t3 2,* 34 35 tp 'v.~(51~) 2,4M 2,J O,.SOOOO 0,3/1'1 16,lOM 17,UUT. 16,11M 17,IOLST. Ib,lM 17,t:XI'r. ARGUMENT BLOCKS: 60 61 62 1M: 0,,0 0, ,0 63 10M: 777773,,0 0,,777777 0, ,0 0,,0 64 65 340,,10P 0,,7 66 67 70 71 72 73 0,,0 11M: ll00"SUM1 1l00"SUM2 4000,,0 c: til H Z MAIN. TIMl FORTRAN V.~(515) IKI/M 16-MAR-77 16:05 PAGE 1-2 G1 8 tIl tJ:l I tZl I-' I-' () o :J: FORMAT STATEMENTS (IN LOW SEGMENT): 18 116111 lOP: (7H S 116112 116113 UM1= ,19,1 116114 116115 116116 OH SUM2 = ,19 116117 MAIN. [ NU ERRORS DETECTED ] td t-t t-t tZl ~d MAIN. TIM1 I I-' t\J V,S(S15) IKI 16-rAAH-77 16:09 PAGE 1 IMPLICIT INTEGER (A-Z) 00001 00002 00003 00004 00005 00006 00007 tJj FORT~AN DIMENSION A(10Q,200),B(lOO,200) SUMl=O SUM2=O DO 100 J=1,200 DO 100 1=1,100 Kl=l*J 00008 IF(Kt.LT.500.0R,Kl.GT,1500) Kl=O 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 ACI,J)=Kl K2=I+J IF(K2,~Q,100.0R.K2,EQ.200,OR.K2.EQ,300) K2=K2+1 BCI,J)=K2 100 C 10 SUM1=SUM1+Kl SUM2=SUM2+K2 CONTINUt C til H Z G'l TYPE 10,SUM1,SUM2 fORMAT(7H SUMl= ,I9,lOH END t-3 ::c SUN2;: ,19) tzJ n o 3: "0 H SUBPROGRAMS CALLED t"" tzJ ~ "%" NOT REFERENCED] SCALARS AND ARRAYS [ "*" NO EXPLICIT DEFINITION • *Kl 1 B ,50000 116104 *SUM2 2 116105 *~l *1 47042 11610b A *K2 47043 11b107 ,SOOOI 116103 *SUM1 116110 LINE NUMBER/OCTAL LOCATION MAP I 0 1 2 3 4 5 6 .·~·-~I·---·-----··-·---------·-------·---------·--~··~~.-5 3 10 00000 4 46 44 45 00010 26 37 31 [ NO ERRORS DETECTED MAIN, 7 8 9 11 14 21 56 ...~ .. --.----.. ---------... 52 Line number 11 starts at location 31. The previous listing shows that line 11 uses locations 31 through 36, but only the first location is shown here. MAIN. TIM1 FORTRAN V,5(515) /KI/OPT/M 16.MAR .. 77 16:07 PAG~ 1 c til to I ~ w 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 100 C 10 IMPLICIT INTEGER CA~Z) DIMENSION A(100,200),BC1OO,200) SU"l1 =0 SUM2=O DO 100 J=1,200 DO 100 1=1,100 1\1=1*J IF(Kl.LT.500,OR.Kl.GT,1500) K1=0 ACI,J)=Kl K2=I+J IFCK2,EQ.I00.QR,K2.EQ.200.0R.K2,EQ.300) K2=K2+1 B(I,J)=K2 SUM 1 =sur-1 1 +K 1 SUM2=SUM2+K2 CONTINUE TYPE 10,SUM1,SUM2 FORMAT(7H SUM1= ,I9,10H END SUM2= ,19) H ~ G') 8 == tlj n 0 :: to H tot tlj ~ SUBPROGRAMS CALLED SCALARS AND ARRAYS ( "*" NO EXPLICIT DEfINITION - *Kl 47045 ,00001 116111 2 ~.ROOOI 47042 ,50001 116105 ,SOOOO 116106 116112 *SUM1 116113 *K2 LINE LABEL 1 A t 4 * 5 ll:I I ~ ~ 1_- LOC Jf"CL 0,0 1 2 JSP 16,RESET, 0,0 3 4 5 6 SETZB MOV£<:l MOVE:M M()VNI 10,11 12,144 7 MOVe;! 12"ROOQl l2,3tO 7,1 10 MOVEM 12,,50000 11 12 * 13 7 14 15 16 17 8 20 21 22 Optimizer Created Statements 4M. *J *1 47044 116110 L Created Optimizer Variables c til t-t z (j) ~ tIl ~ () MOVE MOVE 6,7 2,[777634000001] MOV!':I ADD 4,0(2) 4"ROOOl 5,6 5,764 5,2734 0,7M O,6 M SMa MOVE CALL CAlLE JRST JRST 7M, ,ROOOO 47043 * 5 Ut-1 2 + 11 6 1 0 7 GENERATED CODE 0 6 8 B "I" NOT REfERENCED ,0 3: I"d t-t t"t ~ ~ MAIN, TIM1 FORTRAN V,5(515) IKI/OPT/N 9 23 6M: 10 24 25 26 27 30 11 lJj I I--' U'1 31 10MI 11 32 9MI 12 33 8MI :-.10VEI 5,0 16 .. t"'AR"7 7 16:07 PAGE 1-1 ~10VEM 5,1\""145(4) MOVE ADDI CAIE: CAIN JRST 3,7 3,144 3,310 O,9M CAIN 3,454 ADDI 3,1 HOVEM H 3,0(2) o 13 34 ADD 3,a"'145(4) 11,5 14 35 ADD 10,3 Gl *15 36 ADD 6,7 1-3 40 AOBJN MOVEl 41 ADDM 2,5 11 12, 144 12, IRooot o 4 1-1 * * 37 42 tOOPI 1MI 43 * * * *17 * 19 44 45 46 47 50 51 52 53 54 55 56 2M. ADOI AOSGE JRST MOVEM MOVEM MOVEM MOVEM MOVEl PUSHJ MOVEI PUSHJ MOVEI PUSHJ lJl 0, IS 0000 O,4M 11, UM14 10, UM24 5,K Z .. 7,1 .),K (J) • 4 16, 1M 17,0 UTI 16, 2M 4 17,IOLST. 16,3M 17,EXIT. tzl (') 3: I'C Optimizer Created Statements t'1 tzl :;0 BLOCKS: ARGUMr~NT 3t-i: 0, ,0 0,,0 U,M; 777773,,0 0,,777777 57 60 61 62 63 0, ,0 64 0,,0 65 66 67 70 340,,10P 0,,7 0,,0 12HZ 71 72 1100"SUMl 1100"SUM2 4000,,0 c::: en I-f Z MAIN, FORTRAN V.5(515) /KI/OPT/M TIM1 IJ:I I 16",r';AR",77 (j) 16:07 PAGF: 1-2 1-3 ta tzl ...... 0'1 (') o 3: FORMAT STATEMENTS (IN LOW SEGMENT): 18 MAIN. 116114 116115 116116 116117 116120 116121 116122 [ NO lOP: (7H S UM1= ,19,1 OH 5UM2 = ,19 ) ERRORS OETECTED ] to I-f t"" tzl ~ USING THE COMPILER B.3 ERROR REPORTING If an error occurs during the initial pass of the compiler (while the actual source code is being read and processed), an error message is printed on the listing immediately following the line in which the error occurred. Each error references the internal sequence number of the incorrect line. The error messages along with the statement in error are output to the user terminal. For example: .EXECUTE DAY.FOR FORTRAN: DAY 01300 ?FTNNRC LINE:01300 01500 100 ?FTNMSP LINE:01500 01600 ? ?FTNICL LINE:01600 ?FTNFTL MAIN. LINK: LOADING [LNKNSA NO START ADDRESS] Kl STATEMENT NOT RECOGNIZED CONTINE STATEMENT NAME MISSPELLED ILLEGAL CHARACTER C IN LABEL FIELD 3 FATAL ERRORS AND NO WARNINGS EXIT If errors are detected after the initial pass of the compiler, they appear in the list file after the end of the source listing. They are output to your terminal without the statement in error, but they may reference its internal sequence number. B.3.1 Fatal Errors and Warning Messages There are two levels of messages, warning and fatal error. Warning messages are preceded by "%" and indicate a possible problem. The compilation will continue, and the object program will probably be correct. Fatal errors are preceded by a"?". If a fatal error is encountered in any pass of the compiler, the remaining passes will not be called. Additional errors that would be detected in later compiler passes may not become apparent until the first errors are corrected. It is not possible to generate a correct object program for a source program containing a fatal error. The format of messages is ?FTNXXX LINE:n text or %FTNXXX LINE:n text where: ? % FTN XXX LINE:n text fatal warning FORTRAN mnemonic 3-letter mnemonic for the error message line number where error occurred explanation of error B-17 USING THE COMPILER The printing of fatal errors and warning messages on your terminal can be suppressed by the use of the /NOERRORS switch; however, messages will still appear on the listing. The /NOWARNINGS switch will suppress warning messages on both user terminal and listing. B.3.2 Message Summary At the end of the listing file and on the terminal, a message summary is printed after each program unit is compiled. This message has two forms: 1. when one or more messages were issued ?FTNFTL} { %FTNWRN name NO/number FATAL ERRORS AND NO/number WARNINGS or 2. when no messages were issued name [NO ERRORS DETECTED] where name is the program or subprogram name. ([NO ERRORS DETECTED] appears on the listing only.) Appendix G is a complete list of fatal errors and warning messages. B.4 CREATING A REENTRANT FORTRAN PROGRAM WITH LINK To produce a sharable program from the .REL file, give one of the following commands to LINK: 1. /SEG:DEFAULT MAIN/G 2. /OTS:SHAR MAIN/G The resulting core image can be SSAVEd or the used to produce a .SHR file. B-18 such /SSAVE as MAIN.REL, switch can be APPENDIX C WRITING USER PROGRAMS This appendix is a guide for writing effective programs with FORTRAN-20. It contains techniques for optimization, interaction with non-FORTRAN programs, and other useful programming hints. C.l GENERAL PROGRAMMING CONSIDERATIONS The following paragraphs describe programming considerations you should observe when preparing a FORTRAN program to be compiled by FORTRAN-20. C.l.l Accuracy and Range of Double-precision Numbers Floating-point and real numbers may consist of up to 16 digits in a double-precision mode. Their range is specified in Chapter 3, Section 3.2 of this manual. You must be careful when testing the value of a number within the specified range since, although numbers up to 10**38 may be represented, FORTRAN-20 can only test numbers of up to eight significant digits (REAL precision) and 16 significant digits (DOUBLE precision) • You must also be careful when testing the floating-point computation for a result of O. In most cases the anticipated result, i.e., 0 will be obtained; however, in some cases the result may be a very small number that approximates o. Such an approximation of o will cause tests within statements, i.e., an arithmetic IF, to fail. C.l.2 Writing FORTRAN-20 Programs for Execution On Non-DEC Machines If you prepare a program to run on both a DECsystem-20 computer and non-DIGITAL machine, you should: a 1. Avoid using the non-ANSI standard features of FORTRAN-20, and 2. Consider the accuracy and size of the numbers non-DIGITAL machine is capable of handling. C-l that the WRITING USER PROGRAMS C.l.3 Using Floating-Point DO Loops FORTRAN-20 permits you to employ non-integer single- or doubleprecision numbers as the parameter variables in a DO statement. This enables you to generate a wider range of values for the DO loop index variables, which may, in turn, be used inside the loop for computations. Be sure to consider the loss of precision that may occur. C.l.4 Computation of DO Loop Iterations The number of times through a DO loop is computed outside the loop and is not affected by any changes to the DO index parameters within the loop. The formula for the number of times a DO loop is executed is: DO 10 I=Ml,M2,M3 MAX (1, ((M2-Ml)/M3)+l)=Number of cycles The values of the parameters Ml, M2, M3 may be of any type; however, you must consider the foregoing formula, particularly when using logicals. One pass through each DO loop is always performed EVEN IF THE RESULT OF THE FOREGOING CALCULATION IS LESS THAN OR EQUAL TO ZERO. C.l.5 Subroutines - Programming Considerations Consider the following items when preparing and executing subroutines: 1. During execution, no check is made number of parameters was passed. to see if the proper 2. If the number of actual arguments passed to a subroutine is less than the number of dummy arguments specified, the values of the unspecified arguments are undefined. 3. If the number of actual arguments passed to a subroutine is greater than the number of dummy arguments given, the excess arguments are ignored. 4. If an actual parameter is a constant and its corresponding dummy argument is set to another value, all references made to the constant in the calling program may be changed to the value of the dummy argument. 5. No check is made to see if the parameters passed are of the same type as the dummy parameters. If an actual parameter is a constant and the corresponding dummy is of type real, be sure to include the decimal point with the constant. If the dummy is double-precision, be sure to specify the constant with a "D". Examples If the function F(A) is called by inputting F(2) and A is type real, F interprets the integer 2 as an unnormalized floating-point number. In this instance, F(A) should be called with F(2.0). Similarly, if the function Fl(D) is called by inputting Fl(2.5) and D is double-precision, Fl assumes that its C-2 HRITING USER PROGRAr·1S parameters have been specified with two words of precision and picks up whatever follows the constant 2.5 in memory. The proper method is to use Fl(2.5DOO). NOTE You are given no notice if any of the described in items 1,2,3,4, ana 5 occur. C.l.6 situations Reordering of Computations Computations that are not enclosed within parentheses may be reordered by the compiler. Sometimes it is necessary to use parentheses to ensure proper results from a specific computation. For example, assuming that 1. RLI represents a large number such that RLl*RL2 will cause an overflow condition, and 2. RSI is a very small number, i.e., less than sequence 1, the program A=RSl*RLl*RL2 B=RS2*RL2*RLI will not produce an overflow when evaluated left to right, since the first computation in each expression, i.e., RSl*RLl and RS2*RL2, will produce an interim result that is smaller than either large number (RLI or RL2). However, the compiler will recognize RLl*RL2 as a common subexpression (see Section C.2.I.l) and generate the following sequence: temp A B RLl*RL2 RSl*temp RS2*temp The computation of temp will cause an overflow. You should write the program as follows to results are obtained: ensure that the desired A=(RSI*RLl)*RL2 B=(RS2*RL2)*RLI Computations may be reordered even when selected. C-3 global optimization is not WRITING USER PROGRAMS C.l.7 Dimensioning of Formal Arrays When you specify an array as a formal parameter to a subprogram unit, you must indicate to the compiler that the parameter is an array. Dimension the array in a specification statement. This is the only way the compiler is able to distinguish a reference to such an array from a function reference. Designating the array with a dimension of 1 is a common practice. Example SUBROUTINE SUBl(A,B) DIMENSION A(l) the above technique is not adequate in There are disadvantages to using dimension information provided specifically: 1. because the some cases, Reading or writing the array by name DIMENSION ARRAY (10) READ (1) ARRAY The above is a binary read that ARRAY. will read ten words into SUBROUTINE SUBl(A) DIMENSION A(l) READ(l)A This binary read will cause one word to be read into A. 2. Reading the array as a format SUBROUTINE SUB2 (FMT) DIMENSION FMT(l) READ (l,FMT) This will cause one word of the array FMT to be written with the characters read from the record on unit 1. over When you use the /DEBUG:BOUNDS compilation switch, the dimension information used is that which is specified in the array declaration. SUBROUTINE DO IT(A) DIMENSION A(l) A(2)=0 The reference to A(2) will cause the out-of-bounds warning message be generated. C.2 to FORTRAN-20 GLOBAL OPTIMIZATION You have the option of invoking the global optimizer during compilation. The optimizer treats groups of statements in the source program as a single entity. The purpose of the global optimizer is to prepare a more efficient object program that produces the same results as the original unoptimized program, but takes significantly less execution time. The output of the lexical and syntactic analysis phase of the compiler is developed into an optimized source program equivalent (in results) to the original. The optimized program is then processed by the standard compiler code generation phase. C-4 WRITING USER PROGRAMS C.2.l Optimization Techniques C.2.l.l Elimination of Redundant Computations Often the same sUbexpression will appear in more than one computation throughout a program. If the values of the operands of such a common expression are not changed between computations, the subexpression may be written as a separate arithmetic expression, and the variable representing its resultant may then be substituted where the subexpression appears. This eliminates unnecessary recomputation of the subexpression. For example, the instruction sequence: A=B*C+E*F H=A+G-B*C IF((B*C)-H) 10,20,30 contains the subexpression B*C three times when it really needs to computed only once. Rewriting the foregoing sequence as: be T=B*C A=T+E*F H=A+G-T DIF((T)-H) 10,20,30 eliminates two computations of the sUbexpression B*C from the sequence. overall Decreasing the number of arithmetic operations performed in a source program by the elimination of common subexpressions shortens the execution time of the resulting object program. C.2.l.2 Reduction of Operator Strength - The time required to execute arithmetic operations will vary according to the operator(s) involved. The hierarchy of arithmetic operations according to the amount of execution time required is: MOST TIME OPERATOR ** / LEAST TIME * +,- During program optimization, the global optimizer replaces, where possible (1), some arithmetic operations that require the most time with operations that require less time. For example, consider the following DO loop that is used to create a table for the conversion of from 1 to 20 miles to their equivalents in feet. 10 DO 10 MILES=1,20 IFEET(MILES)=5280*MILES 1. Numeri~al analysis considerations cases where this is possible. C-5 severely limit the number of WRITING USER PROGRAMS The execution time of the foregoing loop would be shorter if the time-consuming multiply operation, i.e., 5280*MILES, could be replaced by a faster operation. Since you increment MILES on each pass, you can replace the multiply operation by an add and total operation. In its optimized form, the foregoing sequence equivalent to: 10 loop would be replaced by a K=5280 DO 10 MILES=1,20 IFEET(MILES)=K K=K+5280 In the optimized form of the loop, the value of K is set to 5280 for the first iteration of the loop and is increased by 5280 for each succeeding iteration of the loop. This foregoing situation occurs frequently in subscript calculations that implicitly contain multiplications whenever the size is two or greater. C.2.l.3 Removal of Constant Computation From Loops - The speed with which a given algorithm may be executed can be increased if instructions and/or computations are moved out of frequently traversed program sequences into less frequently traversed program sequences. Movement of code is possible only if none of the arguments in the items to be moved are redefinea within the code sequences from which they are to be taken. Computations within a loop consisting of variables or constants that are not changed in value within the loop may be moved outside the loop. Decreasing the number of computations made within a loop greatly decreases the execution time required by the loop. For example, in the sequence: 10 DO 10 1=1,100 F=2.0*Q*A(I)+F the value of the computation 2.0*Q, once calculated on the first iterations, will remain unchanged during the remaining 99 iterations of the loop. Reforming the foregoing sequence to: 10 QQ=2.0*Q DO 10 1=1,100 F=QQ*A(I)+F moves the calculation 2.0*Q outside the scope of movement of code eliminates 99 multiply operations. the loop. This In addition, it is possible to remove entire assignment statements from loops. This action can be easily detected from the macro expanded listings. The internal sequence number remains with the statement and appears out of order in the leftmost column of the macro expanded listing (LINE). C-6 ~1RITING USER PROGR.z\MS C.2.1.4 Constant Folding and Propagation In this method of optimization, expressions containing determinate constant values are detected and the constants are replaced, at compile time, by their defined or calculated value. For example, assume that the constant PI is defined and used in the following manner: PI=3.14IS9 X=2*PI*Y At compile time, the optimizer will have used the defined value of PI to calculate the value of the subexpression 2*PI. The optimized sequence would then be: PI=3.14IS9 X=6.28318*Y thereby eliminating a multiply operation from the object code program. The computation of determinate constant values at compile time is termed "folding"; the use of the defined value of a constant for replacement purposes throughout a program sequence is termed "propagation of the' constants." The execution time saved by the foregoing type of compile time optimization is particularly important when the modified instruction occurs in a loop. C.2.I.S Removal of Inaccessible Code The optimizer detects and eliminates any code within the source program that cannot be accessed. In general, this will not happen since programmers do not normally include such code in their programs; however, inaccessible code may appear in a program during the debugging process. The removal of inaccessible code by the optimizer will reduce the size of the object program. A warning message is generated for each inaccessible line removed. C.2.1.6 Global Register Allocation During the compilation of a source program, the optimizer controls the allocation of registers to minimize computation time in the optimized object program. The allocation process is designed to minimize the number of MOVE and MOVEM machine instructions that will appear in the most frequently executed portions of the code. C-7 WRITING USER PROGRAMS C.2.1.7 I/O Optimization - Every effort is made to minimize the number of required calls to the FOROTS system. This is done primarily through extensive analysis of implied DO loop constructs on READ, WRITE, ENCODE, DECODE, and REREAD statements. The formats of these special blocks are described in Appendix E. These optimizations reduce the size of the program (argument code plus argument block size is reduced) and greatly improve the performance of programs that use implied DO loop I/O statements. C.2.1.S Uninitialized Variable Detection A warning message is generated when a scalar variable is referenced before it has received a value. C.2.1.9 Test Replacement - If the only use of a DO loop index is to reduce operator strength (D.2.1.2) and the loop does not contain exits (GO TOs out of the loop), the DO loop index is not needed and can be replaced by the reduced variable. For example: DO 10 1=1,10 K=K+7*I CONTINUE 10 Reduction of operator strength and test replacement together transform this loop into DO 10 1=7,70,7 K=K+I CONTINUE 10 This occurs frequently in subscript computation. C.2.2 Improper Function References Consider this statement: P = F(X) + Q(Y) If: 1. the evaluation of F(X) defines or changes the variables A, B, and C, and 2. the evaluation of Q(Y) defines or changes the values of B, C, and D, then it is possible that different values of P could result, depending on which function is evaluated first. Let's see how this works. Let's assign some values (to begin with) to A, B, C, and D and define the functions F{X) and Q(Y): Let: F (X) : A B C D 2. 3. 4. 5. Q (Y) : A 6. B B 7. S. D + 9. C D C F C-S Q 10. 11. 12. A + 13. WRITING USER PROG~~MS Now play computer and evaluate P, calling first F(X), then Q(Y). Now re-evaluate P, calling Q(Y) first, then F(X). Notice that you got different values for P because the variables A, B, C, and D changed value depending on the order in which the functions were called. (Our answers were 33 when F(X) was called first and 36 when Q(Y) was called first.) The ANSI FORTRAN standard prohibits this kind of situation. But the compiler won't catch it unless you mention the affected variables in the function call itself. The compiler depends on strict adherence to this rule. There's a strong possibility that you won't get the results you want if you don't look for situations of this type and avoid them. Your best bet is to define your variables OUTSIDE the function and not change them in the course of the evaluation of the function itself. C.2.3 Programming Techniques for Effective Optimization Observe the following recommendations during the coding of a FORTRAN source program. They will improve the effectiveness of the optimizer. C.3 1. Do not use DO loops with an extended range. 2. Specify label lists when using assigned GO TOs. 3. Nest loops so that the innermost index is the largest range of values. 4. Avoid the use of associated input/output variables. 5. Avoid unnecessary use of COMMON and EQUIVALENCE. one with the INTERACTING WITH NON-FORTRAN PROGRAMS AND FILES C.3.1 Calling Sequences The following paragraphs describe the standard procedures for subroutine calls. 1. writing Procedure half of the first a. The calling program must load the right accumulator (AC) 16 with the address of argument in the argument list. b. The left half of AC 16 must be set to zero. c. The subroutine is then called by a PUSHJ AC 17. d. The return will be made to the after the PUSHJ 17 instruction. instruction immediately e. If you use the FOROTS trace sequence to a routine F must be facility, the MOVEI 16,AP PUSHJ 17,F C-9 instruction to calling WRITING USER PROGRAMS where AP is the pointer to the argument list. If you use the trace facility, the word preceding the first word of an entry point should have its name in SIXBIT. 2. Restrictions a. Skip returns are not permitted. b. The contents of the pushdown stack located before the address specified by AC 17 belong to the calling program; they cannot be read by the called subprogram. c. FOROTS assumes that it has control of the stack; therefore, you must not create your own stack. The FOROTS stack is initialized by: JSP l6,RESET. C.3.2 Accumulator Usage The specific functions performed by accumulators (AC) 17,16,0, are as follows: and 1 1. Pushdown Pointer - AC 17 is always maintained as a pushdown pointer. Its right half points to the last location in use on the stack, and its left half contains the negative of the number of (words-I) allocated to the unused remainder of the stack. {A trap occurs when something is pushed into the next to last location. A positive left half is not permitted. 2. Argument List Pointer - AC 16 is used as the argument pointer. The called subprogram does not need to preserve its contents. The calling program cannot depend on getting back the address of the argument list passed to the callee. AC 16 cannot point to the ACs or to the stack. 3. Temporary and Value Return Registers - AC and 1 are used as temporary registers and for returning values. The called subprogram does not need to preserve the contents of AC or 1 (even if not returning a value). The calling program must never depend on getting back the original contents of the data passed to the called subprogram. 4. ° ° Returning Values - At the option of the designer of a called subprogram, a subroutine may pass back results by modifying the arguments, returning a single-precision value in AC or a double-precision or complex value in AC and 1. A combination of the above may be used. However, two single-precision values cannot be returned in AC and 1, since FORTRAN would not be able to handle it. ° C-lO ° ° WRITING USER PROGRAMS 5. Preserved ACs - FORTRAN-20 FUNCTION subprograms preserve 2 through 15; subroutine subprograms do not. ACs The design of the called subprogram cannot depend on the contents of any of the ACs being set up by the calling subprogram, except for ACs 16 and 17. Passing information must be done explicitly by the argument list mechanism. Otherwise, the called subprograms cannot be written in either FORTRAN-20 or COBOL. C.3.3 Argument Lists The format of the argument list is as follows: Arg count word Arg list addr.---First arg entry Second arg entry Last arg entry The format of the arg count word is: bits 0-17 bits 18-35 These contain -n, where n is the entries. These are reserved and must be O. The format of an arg entry is as word) : bits 0-8 bits 9-12 bit 13 bits 14-17 bits 18-35 follows (each number entry Reserved for future DEC development now) . Arg type code. Indirect bit if desired. Index field, must be a for present. Address of the argument. of arg is a single (set to a for The following restrictions should be observed: 1. Neither the argument list nor the arguments themselves can be on the stack. This restriction is imposed so that the stack can be moved. The same restriction applies to any indirect argument pointers. 2. The called program may not modify the argument list itself. The argument list may be in a write-protected segment. Note that the arg count word is at position -1 with respect to the contents of AC 16. This word is always required even if the subroutine does not handle a variable number of arguments. A subroutine that has no arguments must still provide an argument list consisting of two words, i.e., the argument count word with a a in it and a zero argument word. C-ll WRITING USER PROGRAMS Example MOVEI l6,AP PUSHJ 17,SUB iSET UP ARG POINTER iCALL SUBROUTINE iRETURN HERE iARGUMENT LIST -3,,0 A AP: B C iSUBROUTINE TO SET THIRD ARG TO SUM OF FIRST TWO ARGS SUB: C.3.4 MOVE ADD MOVEM POPJ iGET FIRST ARG T,@0(16) T,@1(16) T,@2(16) 17, iADD SECOND ARG iSET THIRD ARG iRETURN TO CALLER Argument Types Table C-l Argument Types and Type Codes Type Code o 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 Description FORTRAN Use COBOL Use Unspecified FORTRAN Logical Integer Reserved Real Reserved Octal Label Double real Not applicable Double Octal Reserved Complex Not applicable Reserved ASCIZ string Unspecified Not applicable I-word COMP Reserved COMP-l Reserved Reserved Procedure address Not applicable 2-word COMP Reserved Reserved Not applicable Byte string descriptor Reserved Not applicable Literal arguments are permitted, but they must reside in a writable segment. This is because the FORTRAN-20 compiler makes a local of all non-array elements and copies all formals back to the caller's arguments. All unused type codes are reserved for future DIGITAL development. C-12 WRITING USER PROG~~MS C.3.5 Description of Arguments The types of the arguments that may be passed are: 1. Type 0 - Unspecified The calling program has not specified the type. The called subprograms should assume that the argument is of the correct type if it is checking types. If several types are possible, the called subprogram should assume a default as part of its specification. If none of the above conditions is true, the called subprogram should handle the argument as an integer (type 2). 2. Type 1 - FORTRAN logical A 36-bit binary value containing 0 or positive .FALSE. and negative to specify .TRUE .. 3. to specify Type 2 - Integer and l-word-COMP A 36-bit 2's complement signed binary integer. 4. Type 4 - Real and COMP-l A 36-bit DECsystem-20 format floating-point number. bit 0 bits 1-8 bits 9-35 5. sign excess 128 exponent mantissa Type 6 - Octal A 36-bit unsigned binary value. 6. Type 7 - Label and procedure address A 23-bit memory address. bits 0-12 bit 13 bits 14-17 bits 18-35 always 0 indirect flag o the address 7. Type 10 - Double precision real 8. Type 11 - 2-word COMP A 2-word (72-bit) word word word word 9. 1, 1, 2, 2, 2's complement signed binary integer. bit 0 bits 1-35 bit 0 bits 1-35 sign high order same as word 1, bit 0 low order Type 12 - Double octal A 72-bit unsigned binary value. C-13 WRITING USER PROGRAMS 10. Type 14 - Complex A complex number represented as an ordered pair of 36-bit floating-point numbers. The first represents the real part, and the second represents the imaginary part. 11. Type 15 - Byte String Descriptor The format of the byte string descriptor is: word 1: word 2: ILDB-type pointer, i.e., aimed at the preceding the first byte of the string EXP byte count byte The byte descriptor may not be modified by the called program. The byte string itself must consist of a string of contiguous bytes of uniform size. The byte size may be any number of bits from 1 to 36. The byte count must be large enough to encompass 256K words of storage, i.e., 24 bits for I-bit bytes. (See COBOL Program Reference Manual.) 12. Type 17 - ASCIZ string A string of contiguous 7-bit ASCII bytes left justified on the word boundary of the first word and terminated by a null byte in the last word. The length of the string may be from 1 to 256K words. C.3.6 Converting Existing MACRO Libraries for use with FORTRAN-20 The following sequence. simple example illustrates C-14 the FORTRAN-20 calling (") 1 n.. f~AR-7 7 MAIN" EX1 FORTRAN V,5(515) 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011. 00012 00013 00014 00015 00016 00017 C AN EXAMPLE OF A CALL TO A SUBROUTINE WITH A VARIETY'OF ARGUMENTS IKt/~ 16:02 PAGE: 1 DOUBLE PRECISION DP DIMENSION B(10) C C C C C C C C THE ARGUMENTS ARE, 1 , A REAL VARIABIJE 2, AN ARRAY NANE 3, AN APRAY ~LEMF.NT 4. AN INTEGER VARIABLE 5, A DOUBLE PRECISION VARIABLE 6, AN OCTAL CONSTANT 7, A LITERAL ~ ~ H 8 H CALL SUS1(A,B,B(I),K,DP,"777,'ABC') ~ Gl c END tf) t=l I ~ I-' U1 SUBPROGRAMS CALLED to ~ 0 Gl SUB1 S; SCALARS AND ARRAYS DP 1 *K ~ (fl "*" NO EXPLICIT DEFINITION • "%" NOT REFERENCED 3 S 4 *A 16 *1 17 LINE Loe LABEL JFCIJ JSP 0 15 1 2 3 4 0,0 16,RESET. 0,0 MOVE: MOVEl MOVEM MOVEI PUSHJ 5 17 GENERATED CODE 6 7 10 MOVEI PLJSHJ 11 2,1 2,S-1(2) 2,,00000 16,2M 17,SUBl 1.6,lM 17,EXIT. ARGUMENT BLOCKS, ~ ~ 12 (') 13 14 1M: 15 2M; 16 I ...... ~ H Z Cj) o en trl 21 220",QOOOO 100"K 400"DP 22 )00,,[000000000777] 17 20 0\ H 0,,0 0,,0 777771,,0 200"A 200"S ~ "tI ~ oCj) ~ :::c en FORTRAN V.5(515) IKI/M MAIN, EXl MAIN. 23 740,,[406050320100) [ NO ERRORS DETECTED 1 16-MAR-77 16102 PAGE 1-1 MAIN. 'EX1 fOHTRAN V.5(515) IKI/M 16:02 16~MAR~77 PAGE 1 00001 SUBROUTINE BUB1(REAL1,ARYNAM,ARYELM,INT1,DBLPRC,OCT,LIT) DOUBLE PRECISION DBLPRC DIMENSION ARYNAM(lO) 00002 (') I I-' " 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 C AN EXAMPLE Of THE USE AND MODIFICATION OF FORMAL PARAMETERS Xl=REALl X2=ARYNAM(J) X3=ARY~;LM 11=INTl X4=DBLPRC 12::0CT 13=LIT :e: ~t:I .-i .-3 .-i t~ G'l REALt=Xl APYNAM(J)=X2 ARYELM=X3 INT1=11 C tJ) tr;] ~t:I ttl OBLPRC=CMPLX(X4,0.) ~a o OCT="55 LIT::'Z¥XW' G'l .t:I ~ :1:: tJ) RETU~N END SUBPROG~AMS CALLED CMPLX. SCALARS AND ARRAYS [ "*" NO EXPLICIT DEFINITION • *LIT 1 DBLPRC 6 14 *INTl *OCT *13 *12 2 10 *X4 *REAL! 11 15 *X1 16 3 "%" NOT REFERENCED *ARYELM 4 12 17 *J *11 .X3 5 *X2 13 ARYNAt<\ 20 LINE LOC LABEL 636542,,210000 0 SUB1: 2 GENERATED CODE 0 1 2 3 4 5 6 7 10 11 12 MOVEM lb,.AOOlf> r-iOVE O,@O(16) ,',mVEt1 O,REALl r.10Vf-~I 1,@1(16) MOVr:r" 1,ARY.NAM MOVI': i.,OVEM 1,@2(16) 1 , ARYEI.JH .MOVE 2,@3(16) MOVEM DHOVE DMOVEM 2,INTl 4,@4(t6) ~ 4,OBLPRC lX' H 8 H Z Ci) SUB1 . EX1 FORTRAN V,5(515) IKJ/M lbI"HAR",,77 () 16:02 PAGE bill c en tzl ~ I I-' ex> '>10VE MOVEM MOVE MOVEM 13 14 8 9 10 15 16 17 20 21 22 23 24 3MI 3,oer 6,@6(16) 6,LIT "'0 lX' 0 Ci) ~ 3: en MOVEM O,Xl MOVE 7, \. 1 7, ARYNAt,1 ADO t·lOVE MOVEM MOVEM 11 12 25 ~~OVEM 26 27 PUSHJ MOVEM 13 30 31 32 MOVEN 33 ~~nVEM 14 16 3,@5(16) FIX MOVr~M 7,777777(7) 7,X2 I,X] 2,11 17,SNG.4 4,X4 3,3 3,12 6,13 0, lU:ALl / 17 r·mVE ADD 34 35 18 19 20 21 22 25 ~\oVEM 36 37 MOVEM MOVEM MOVEr 40 41 42 43 44 45 46 47 50 53 54 55 56 57 I ...., 5,0 5,0 D~1OVEM 4,DBLPRC r10VEI 2,55 MOVEM MOVE MOVEM 2,OC'l' MOVE HOVE MOVEM MOVE MOVEM 16,.AOO16 O,REALl O,ARYt:LM O,ca2(16) H MOVE O,INT! Cil MOVEM 0,(a3(16) O,DRLPRC c::: or-.10VE 2,LIT O,@O(16) ~ ~ 8 H z til DMOVEN MOVE MOVEM MOVE O,@4(16) a,OCT I'd 64 ~1OVEM 65 POPJ O,@6(16) 17,0 61 62 63 ARGUMENT BLOCKS. 66 67 SUBl 2,[552633053500] tIj ~ 60 \0 f.l0VEI 2M; 51 52 () 3, ,1 3,ARYNAH 7,777777(3.1 1,ARYELM 2,INTl H1= 0,,0 0,,0 [ NO ERRORS DETECTED O,@5(16) O,LIT ~ Cil ~ WRITING USER PROGRAMS To convert existing MACRO programs conveniently so that they still load and execute correctly when called from FORTRAN-20: 1. Transfer the initial entry sequence for a routine to entry: 2. will CAIA PUSH l7,CEXIT.## Change all returns to POPJ 17,0 These are the functions performed by the HELLO and GOODBY macros. These macros (available in the file FORPRM.MAC, part of the FOROTS release) were successfully used to convert the library routines to run with FORTRAN-20. In addition, since the FORTRAN-20 compiler uses the indirect bits on argument lists (note that this permits shared, pure code argument lists), it is essential for code that accesses parameters to take this into account. Specifically, sequences that obtained the values of parameters through use of operations such as HRRZ R,1(16) to pick up the address of the second argument should be changed to MOVEI R,@1(l6) The latter operation will work when interfacing with FORTRAN-20. Refer to the previous example, which illustrates the code generated by the FORTRAN-20 compiler, for specific details of how each argument IS accessed. Note that in the case of the formal array, it is the address of the array that is accessed. C.3.7 Interaction with COBOL The FORTRAN programmer may call COBOL programs as subprograms, and, conversely, the COBOL programmers may call FORTRAN-20 programs as subprograms. In either of the foregoing cases, I/O operation must not be in the called subprogram. C-20 performed WRITING USER PROGRAHS C.3.7.l Calling FORTRAN-20 Subprograms from COBOL Programs COBOL programmers may write subprograms in FORTRAN to use the conveniences and facilities provided by this language. The COBOL verb ENTER is used to call FORTRAN-20 subroutines. The form of ENTER is as follows: ENTER FORTRAN program name L rUSING {if~~;!iierl } [ {if~~;!i~er2}J ] procedure namel procedure2 The USING clause of the foregoing forms names the data within the COBOL program that is to be passed to the called FORTRAN subprogram. The passed data must be in a form acceptable to FORTRAN-20. The calling sequence used by COBOL in calling a FORTRAN subprogram is: MOVEI 16, address of first entry in argument list PUSHJ 17, subprogram address If the USING clause appears in the ENTER statement, the compiler creates an argument list that contains an entry for each identifier or literal in the order of appearance in the USING clause. It is preceded by a word containing, in its left half, the negative number of the number of entries in the list. If no USING clause is present, the argument list contains an empty word, and the preceding word is set to O. Each entry in the list is one 36-bit word at the form: 0-8 9-12 13-35 0 type address Bits 0-8 are always O. Bits 9-12 contain a type code that indicates the USAGE argument. of the Bits 13-35 contain the address of the argument of the first word of the argument; the address can be indexed or indirect. Following is a description of the types, their codes, how the codes appear in the argument list, and the locations specified by the addresses. 1. For I-word COMPUTATIONAL items CODE: IN ARGUMENT LIST: ADDRESS: 2 XWD 100, address that of the argument itself C-21 WRITING USER PROGRAMS 2. For 2-word COMPUTATIONAL items CODE: IN ARGUMENT LIST: ADDRESS: 3. 11 XWD 440, address that of the high-order argument word of the For procedure names (which cannot be used for calls to subprograms) COBOL For COMPUTATIONAL-l items CODE: IN ARGUMENT LIST: ADDRESS: 4. CODE: IN ARGUMENT LIST: ADDRESS: 4 XWD 200, address that of the argument itself 7 XWD 340, address that of the procedure The return from a subprogram (via POPJ 17,) is to the statement the call. after C.3.7.2 Calling COBOL Subroutines from FORTRAN-20 Programs - To COBOL subroutines use the standard subroutine calling mechanism: call CALL COBOLS (args ... ) X=COBOLS (args ... ) subroutine call function call You must have compiled the COBOL subroutine using the COBOL compiler described in the DECsystem-20 COBOL Programmer's Reference Manual. C.3.8 LINK Overlay Facilities LINK provides several routines that are accessible directly from a FORTRAN-20 program. These routines are presented here briefly, together with the FORTRAN-20 specification of their parameters. In general, LINK performs these functions automatically. These routines are available only for your convenience. Full details of the use of the overlay facilities can be found in the LINK Reference Manual. C.3.8.1 Conventions - The following terms are used parameters to LINK overlay routines. File spec Name List of link names to describe. the A literal constant consisting of device: filename. ext [directory] A LINK name or number that is a literal constant or variable. A sequence of name items separated by commas. The routines available are: INIOVL (File spec) Used to specify the overlay file to be found if the load time specification is to be overridden. GETOVL (List of link names) Used to overlay structure in memory. C-22 change the WRITING USER PROGRAi-iS RUNOVL (Name) Loads the specified transfers to that LINK. LINK REMOVL (List of link names) Removes the LINKs from memory. specified LOGOVL (File spec) Used to specify where the log file is to be written. If no arguments are given, the log file is closed. For a full description of these routines, refer to the LINK Manual. C-23 and Reference APPENDIX D FOROTS This appendix describes the facilities that FOROTS provides for the FORTRAN user. FOROTS implements all standard FORTRAN I/O operations as set forth in the IIAmerican National Standard FORTRAN, ANSI X3.9-l966. 11 In addition it provides the user with capabilities and programming features beyond those defined in the ANSI standard. The primary function of FOROTS is to act as a direct interface between user object programs and the DECsystem-20 monitor during input and output operations. Other capabilities include: D.l 1. Job initialization 2. Channel and memory management 3. Error handling and reporting 4. File management 5. Formatting of data 6. Mathematical library 7. User library (non-mathematical) 8. Specialized applications packages 9. Overlay facilities HARDWARE AND SOFTWARE REQUIREMENTS FOROTS may interface with all DECsystem-20 peripheral devices. In addition to monitor or user program requirements, a minimum of 14 pages of user memory is needed to run FOROTS. D-1 FOROTS The software required with FOROTS is the TOPS-20 monitor, version Other software items that can be associated with FOROTS include: D.2 1. The MACRO assembler 2. The LINK loader 3. The FORTRAN-20 compiler 1. FEATURES OF FOROTS The following list briefly describes many specific features; more detailed information concerning the implementation of these features is given later in this appendix. 1. Your program may run in either batch or timesharing mode without requiring a program change. All differences between batch mode and timesharing mode operations are resolved by FOROTS. 2. Your programs may access both devices in the same manner. 3. FOROTS helps provide complete data file compatibility between all system devices. 4. FOROTS does not require line-blocking (a requirement that each output buffer must contain only an integral number of lines) . 5. Up to 15 data files number or all of randomly. 6. FOROTS treats devices located at remote stations similarly to local devices. 7. Programs written for magnetic tape operations will run correctly on disk under FOROTS supervision. FOROTS simulates the commands needed for magnetic tape operations. 8. You may change or specify object program device and specifications via a FOROTS interactive dialogue mode. 9. Non-FORTRAN binary data files may be read in FOROTS. 10. FOROTS provides interactive processing routines. These execution of the program routines whenever designated 11. An error traceback facility for fatal errors provides a history of all subprogram calls made back to the main program at the address of the point where the error occurred. may the directory and non-directory be accessed simultaneously. Any open data files may be accessed D-2 image mode file by program/operating system error routines permit you to route the to specific error processing types of errors are detected. FOROTS 12. FOROTS provides a trap handling system for arithmetic functions, including default values and error reports. 13. You may mix ASCII and binary records in the same file, and both may be accessed in either sequential or random access mode. 14. FOROTS permits your program to switch from READ to WRITE the same I/O device without loss of data or buffering. 15. Although primarily designed for use with the FORTRAN-20 compiler, you may also use FOROTS as an independent I/O system, as an I/O system for MACRO object programs, and for FORTRAN-20 object programs. D.3 on ERROR PROCESSING Whenever a run-time error is detected, the FOROTS error processing system takes control of program execution. This system determines the class of the error and either outputs an appropriate message at the controlling terminal or branches the program to a predesignated processing routine. D.4 INPUT/OUTPUT FACILITIES FOROTS uses monitor-buffered I/O during all modes of access except DUMP mode. Display devices are supported in dump mode; formatted text is handled in ASCII line mode; unformatted files are accessed as FORTRAN binary files. (Refer to the Monitor Calls User's Guide.) The following paragraphs describe I/O data channel and access modes. D.4.1 Input/Output Channels Used Internally by FOROTS Fifteen software channels (1 through 15) are available in I/O operations. Software channel 0 is reserved for the following system functions: 1. The printing of error messages, and 2. The loading operations) Software transfer table is channel assigned FOROTS. and initialization of FOROTS (GETSEG UUO channels 1 through 15 are available for user program data operations. When a request is made for a data channel, a scanned until a free channel is found. The first free is assigned to the requesting program; on completion of the transfer, control of the software channel is returned to D-3 FOROTS D.4.2 File Access Modes Data may be transferred between processor storage devices in two major modes - sequential and random. and peripheral D.4.2.1 Sequential Transfer Mode In sequential data transfer operations, the records involved are transferred in the same order as they appear in the source file. Each I/O statement executed in this mode transfers the record immediately following the last record transferred from the accessed source file. A special version of the sequential mode (referred to as APPEND) is available for output (write) operations. The special APPEND mode permits you to write a record immediately after the last logical record of the accessed file. During the APPEND operation, the records already in the accessed file remain unchanged; the only function performed is the appending of the transferred records to the end of the file. You must specify transfer modes (other than SEQINOUT) by setting the ACCESS option of a FORTRAN-20 OPEN statement to one of several possible arguments. For the sequential mode, the arguments are ACCESS='SEQIN' (sequential read-only mode) ACCESS='SEQOUT ' (sequential write-only mode) ACCESS='SEQINOUT' (sequential read followed by a sequential write) ACCESS='APPEND' (sequential Append mode) D.4.2.2 Random Access Mode - This transfer mode permits records to be accessed and transferred from a source file in any desired order. Random access transfers must be made between processor memory and a device (disk) that permits random addressing operations to files that have been set up for random access. Files for random access must contain a specified number of identically sized records that may be individually accessed by a record number. You may accomplish random access transfers in either a read/write mode or a special read-only mode. You must specify random transfer modes by setting the ACCESS option of an OPEN statement to one of several possible arguments. ACCESS='RANDOM' ACCESS='RANDIN' D.S (random read/write mode) (random special read-only mode) ACCEPTABLE TYPES OF DATA FILES AND THEIR FORMATS The following paragraphs describe the types of acceptable to FOROTS. D.S.l data files that are ASCII Data Files Each record within an ASCII data file consists of a set of contiguous 7-bit characters. A vertical paper-motion character, such as, a Form Feed, a vertical Tab, or a Line Feed, terminates each set. All ASCII records start on a word boundary; the last word in a record is padded with nulls, if necessary, to ensure that the record also ends on a word boundary. Logical records may be split across physical blocks. There is no implied maximum length for logical records. D-4 FOROTS NOTE On sequential input, FOROTS does not require conformation to word boundaries; it reads what it sees. Therefore, any file that is written by FOROTS will conform to the foregoing format requirements. D.S.2 FORTRAN Binary Data Files Each logical record in a FORTRAN binary data file contains data that the executing program may reference with either a READ or WRITE statement. A logical record is preceded by a control word and may have one or more control words embedded within it. In FORTRAN binary data files, there is no relationship between logical records and physical device block sizes. There is no implied maximum length for logical records. D.S.2.1 Format of Binary Files - A FOROTS binary file may contain three forms of Logical Segment Control Words (LSCW). These LSCWs give FOROTS the ability to distinguish ASCII files from binary files. LSCW 001+ the number of words in the segment (exclusive of any "ENDII LSCWs) 002 indicates that the segment of a disk block boundary continues 003+ number of words in the preceding segment including LSCWs. START CONTINUE END If the access you specify for a file (through the OPEN statement ACCESS parameter) is 'SEQIN', 'SEQOUT', or 'SEQINOUT', all three LSCWs may appear in a record. If the access you specify is 'RANDIN', or 'RANDOM', all records are of the same length, and there are no CONTINUE LSCWs. The following examples illustrate the LSCW. file contains only 001 and 003 LSCWs. C C ~OOK AT A BINARY rl~E AND SEE THE CONTROL WOROS. The random access ~OGICAL OP~N(UNIT=1,ACCESS='RANDOM',MODt~i81NA~V'. 1 RECORD~l~~) I~5 WRIT~(l'~) J=' WRtTE(1'2) (I, J=l,l~~) (J,K=1,10~) END D-5 SEGMENT binary FOROTS 000000 007.001 00001212 210k-.;003 002-004 002005 "000"6 000007 002~1" 00~1011 000012 00Z013 00 ~.H2l14 000~15 0"~;016 00Jel17 00ll?l20 0~h~021 00;~022 ~~h;023 2lrch~024 ",,(3025 00 ;'1026 2l0(:H~27 rlI2I1000 21 00145 -Number of words 2100""5 in record counting LSCW or the 02100210 0"0"05 END number of words 21021121"0 21"'00215 following this ~"~0021 ~0210Z21 00~0021 "~00"5 21~21~05 ~00""0 000"0" :2J000~3 ""H,040 "02041 000042 000043 "00044 210'~045 ~0'~046 "0~12147 3"~~2I50 00~060 00212161 "0;i~062 210?-063 "0,,1212121 02'0005 00"'''''21 21~21005 0000rl10 eHHHH"5 0"0"021 211210"05 """""0 12100"215 "000210 0210005 0"H:HH~0 02'0"05 0"21 07H!J 2Iel0"05 ~00121~0 200"1215 ~0121021" 0""005 00210~21 ael0"'''5 12100""0 ~0""05 ';:'0210"0 0"121"1215 "0001210 ~"02105 r2J0~"0" 0"001215 "0210"0 0e0005 21~hH~ 7 6 01210077 00011210 00~11211 0121 ;:1102 "0~1r213 ""01214 007105 00?1216 ""~~107 "~H~110 ""00111 ""00112 00['113 "0'~ 114 00<1115 000116 00~00" 0121e12l55 000056 210012157 "0~037 ~H"0~05 0e;~07" 0"~"75 ~00005 ~2100~21 002035 00(::036 a"21~05 ~021000 00001~ ""0"1215 210.~054 "01.034 121000021 "'1210073 ~0"005 210012153, 2100052 1210:3053 2l01Z'032 "0r.033 21O')066 2121f!067 00\~072 0"'21"05 202121021 0002105 ~HHH?J00 ~""'''10 5 ~"0"'021 0"'21005 r2l000021 000"05 '" 0 ~"'" 0 """"05 0000"0 01210"05 "021-02121 ""0"05 1210002121 0"0"05 0000"21 ~CJl2I"05 "021000 0~"'005 0021121"" ~"""05 "000"" 000005 "002100 0"0"'1215 0~H.~0~0 kH"H~~0 0~HHHJ0 0lrH'12I7l ~0210"21 21"0"05 012100"0 0"0"05 "0"0t1l0 0r2l0"05 "000"" 000"1215 000"'~H~ ""0"05 0000021 0"0"05 012100"" 0"001215 0021000 0"'0"05 "0"000 0"012105 00~02l0 ""0"05 0121"""'0 0"0"05 00"0'-"0 0 0 00"5 000"03 0"0"05 01210003 0"021215 02102100 121~0035 "'0~~00 210"01215 0121~H'2I2I 0"0'1'05 000121~121 1210001215 "0"'''00 0021"215 "0"9'rlI2I ""'001215 0012103121 000005 00~~030 "0~J031 word to the END LSCW. 00L~117 l2Iek3120 000121 "0~122 000123 000124 00C125 r210~126 210"127 "0~13" "0"131 21e~lJ2 21121121133 "0121134 00~135 000136 21"~131 012101421 01210141 ~"'I2I01215 ~21000" 0~00"5 ~I2I0"~3 0000215 00~142 2101.143 210·1)144 0~I,H~12I5 02112100" rc'J00el05 ~0002l21 000005 00~rc'J~0 002101215 ~HH"~~3 002101215 00r}145 00 ;'~146 r210 ..~147 00 (.~ 15121 D-6 ~0"005 210~064 0'H~065 21"0005 ""HI""" 0"0""5 2l"0~00 ~""'r2105 "rcHJ" 2l" 0 0 ""05 "121"000 0021"215 o rcHc~ 0 0 21 21"'0"05 "1210"00 121 0 0005 1i10,,0"0 12100"05 "00000 0"0"05 ""0012121 ~r2J0005 00000121 0"'001215 00121000 0"0005 0121"00" 00""11,,5 "0"0""0 121"0"1215 0"0121215 ""BeeQJ 21"~~05 21"10e10 021QJ"05 ""00000 2100"215 "210"021 3021"21' 1211210021121 21"2101215 2100121el0 21£1"""'5 "3121~0121 0021"1215 2121!2112100 0021"05 02100321 1210121"121' 1212100"21 o"'HH!I 5 rc'J000 121" 0""~05 [2!2I0000 0021"05 0121"0"121 i2l"'121~"5 012100021 ~Q!0005 0~0"00 00121"05 "03000 121"0146 -END LSCW Containing the 02110~121 0021145 number of words "000~"" 000"1217 in the record rc'J00eJt'l2I eJ~21007 including LSCW's. """""' ' FOROTS '210'~ 151 00((H1~0 00:~152 00~153 00t'10210 0"21001 0021"00 21(210~07 o 2"H~ ~0 0121~HHP 000000 ~0121QJ01 QJ0;~154 00/1155 "0:~156 21rzL~157 1210216" '00/161 0rcH'.162 00 '1163 00J164 002'165 00·;166 012!QJI2!~0 ~H'002J7 2l0~HHH' 0"0007 ~"121007 012!012100 0~0"'07 00~253 00.~ 2 54 ~kH"0012! ~~001211 0000~0 00.'~177 eJ~W201 1210,~ 202 00~~ 203 00/2214 1?10?205 007206 0~H2217 00,'210 00'~1211 00 ~~ 212 1210~J213 0r,P214 00!~215 ~ 0 ~,~ 216 002'0~12! 00121007 00Q!l2ltJl2! ~00"07 012!0eJ2!0 "l'0007 eJ000al2! ""'0007 2ll2!el000 2"0~01 2100000 ~00eJ01 000255 00;'256 00?257 00;1260 00Z261 1lJ~ ~') 262 00{1263 00/264 00~A 2 65 0eh'.i266 1?10~· 267 00k""~eJ ,,00~07 2!12!~H~0" 000"07 0~H'271 ~00Q!~0 e!00~07 "'''0~~12I ""0007 2l0~000 ~0021~0 ~0el000 0~00"7 000~01 0~0~07 210012l~0 0~0eJ07 0"'0~01 i2l0~2221 002221 2112121030 ~~00"1 00~222 00~;223 0"Ql0~21 0~000? 00~'227 0i21~230 00~231 00J232 00,)212 002273 1?10t1214 2102275 eJ0J276 2102277 (2)0J30121 001.:301 21012102121 0"'0"1217 <H'" 21 121 0 ~H"0"07 a00001 ;;'021007 O00224 00;3225 0210226 00~27121 2100000 2100"1217 o 121 I(HHJ 0 eJ00~"7 000000 2100"01 i2l~~~~0 0000~0 i2l0i2l0~0 00(1217 00i~240 00iJ241 001/,242 000243 00 ~~ 244 2100245 00 ~~ 246 0,,,;::247 002.250 00J251 00Z252 00~1170 00 ;;200 00e237 00QJI2!QJ0 12100000 0000210 00001217 00121000 ~"'00"7 0000"121 ~00007 0012J0012! 0 0 0007 00~1167 000173 00(1114 00D175 001176 00~234 00~)235 00~236 ~00~01 ~fZl0012J7 ~e'0012!7 00012!0121 00121007 000000 ~H~I2I001 00"~ 171 00t~172 00J233 rai2l~302 i2lraZ303 00~3i2l4 "0"""0 0 0 0210' 0121012100 0000"7 o 121121 12! 1210 0(2)012101 00"12130 121"001211 00210121121 ~~012J01 00001210 0(2)012)07 i2l 0 r,Hl' 1210 000~i217 000000 000007 (2)0;~305 0(0312)6 i2l0~307 00~31I2J 000311 000312 000313 D-7 0000321 0021007 021000121 121012101217 00210021 000001 0""~00121 000001 0000121121 ""121"1217 2112!02100 2101210121" 0"H:10,-,,, 1210121007 0012!00121 0012!001 0121000121 0"0001 00~0et0 01210007 0021021121 0"0001 00Ql0012! ~0001211 000000 121~12112!2J1 00e!~eJl2! 00121007 21000121121 \I5~0e101 00000121 1210121~~" 001211210121 0210007 ell2J~0~0 VJI2!0"~0 0000012! 00121~flI7 0~0007 0~12101217 02)12!007 0210000 12!" ',H~ 0 7 2!12I0~0121 0"0007 ~12100"0 0"'02107 0"~0"" 0"0"07 210210210 21"0007 0000"0 0"121007 "00~00 21000210 0e'0~07 0~0001 2l0"0~0 012!~00" ,,012! 012! 7 2100001 2!(CH100121 "0"210121 1t1~121007 0000~" ~HHH'!"12! ~"'~"~1211 ~0121007 eJ00001 012!02121I2J 0 0 02107 21I2!eJ00121 000012!7 i2l12!~0012! 00012107 00fZ10eJ0 0~0"'01 00 ra i2l 0121 000007 0000121121 0~0e!01 ~00~012! 00121007 000000 12100""7 12l0I(H~~H' 00"0,,7 0~H~0~0 121"0007 i2leJ"0"0 0021'1107 012100021 ,,00 121 12! 1 2102112100 12100007 "121300121 00121146 ~00""0 FOROTS In the sequential access binary file, the second record crosses l28-word disk boundary and contains a 002 (CONTINUE) LSCW. C C ~OOK AT A BINARY r!~E AND SEE THE ~O$!CA~ SE~MENT CONTROL WOReS. OPENCUNIT z 1,MODEa I BINARY' ) 1-' WRIT(C1) (I, J-, WRIT((1) J=~'l~~) (J,K=1,100) END ~ fi" "21 0 0 001}001 ~010'H~ ~0~145 0~~"00 ~"0005 00~}043 0~2'~00 ~00005 ~000"0 00'''~05 000~"5 ~'HHH'0 ~00""5 (J00005 00.3003 ~000~0 00~00~ 00k'044 00(1045 ~0121"05 00.:.~046 0"V004 0~"H"~0 21012101215 0"12101215 00~H~47 00,~002 00;J005 00 ;~006 0~.~007 00,~01~ 00'.~P.!11 00 ..:012 ~0~013 0~/014 00;'.015 00\1;016 00'017 2101,020 210,~021 21~H:'022 fZl0;~fZl23 I2lfZl.~024 ~"0tJ~0 00~Ql30 0~'HH~5 00r.00~ ~000~0 000~00 e,"0Ql0~ 00121005 0 0 0005 002J"~0 00 '''Hl 5 0"'''H~5 a"'0~05 0~H~ra00 ,,00005 0"0121"0 00000121 ~00005 ~01210~5 ~0012105 0~H'HH'0 00;~055 000000 000005 0'HH31210 0~0005 000~H35 r2l~12I005 0000~H3 ~0~000 ~H'0t100 0 0 031215 0000210 0~00"5 0"0005 0002105 0P102105 00:'063 ~"'0021121 ~Z0005 2121;~2164 0000",,, ~000"5 210.1065 021~210121 ~0121005 2l2l00(Hl 017'0~05 00~2166 0"'121005 2!0~02J0 0~0~05 ~H'!" eI 05 "'022167 0021005 021:'071 00?kl72 000000 0012!r2!00 02100P121 0002'021 021~0~0 12l"'H~"5 000~~0 0'-"0005 00210~21 ~21e;0~0 2l0"'0~121 2l2l~0~21 "~0~215 021~~031 2102101210 ~H'0"'''5 2121212100 0~00"5 0I{H~0021 02'0005 0000021 0"0005 0210000 00121305 21121000121 00210215 00210"''' ~e!0~215 v"H'I000 1Zl12!12l005 ~elI2I0W3e1 2100005 ~00000 0"-'0",,5 021;)2141 12'21;;'042 0000eJ0 00~' 060 00l~61 021 ~·;2162 2100212'21 00~:~0421 ~00005 00012100 00,~054 00 . H2!56 1210001215 12l0ll2l25 00/026 "0.~ 027 "0~~ 12130 00:JfZl32 000033 0fZlG034 021\32135 021I.H3-36 00?2137 00i1050 00J051 00J052 002053 0"~2J'HI 000~05 00~0~" ,,01212J0S 000~210 0000~21 21000~0 1210.:~057 0r2!~070 ~0121005 12l0r~~073 12!0~~74 0"00~21 ZI~0"21S 12l0r075 210?076 0rcH~2177 12l0;:l100 210"101 021;~1"2 210,}'103 a001f(}4 ~0Jl215 D-8 2J00005 1Zl"0005 0 0 121005 "liH' " 0121 0"'~H3215 002'000 21°"1210' r2!02'~30 02121"'" 0210"0121 0~12"'05 00e'''021 3"0005 00~012l0 ~000021 012l~000 ~~00"5 ~0"12l2l5 0012l0et5 °21tH'I2I 21 a0"'121005 0 00e15 2J0~0"0 "r3021~121 ~0e1005 the FOROTS 001106 00Jl"7 "'0~11121 "'12I~~111 "'00112 01Zl~11J 1Zl0~l114 00;:115 000116 01ZlJ117 1Zl1Zl012121 12I1Zl~1121 1Zl0~122 12I1Zl~123 "'1Zl;.'124 003125 00~126 12100127 00013" "0~131 "00132 "0~133 "00134 "0~135 00~a36 "00137 "0~~14" "0r.141 00e142 "0~143 "'0~144 "'''~~145 210[1146 00J147 00~-150 "00151 1Zl0~~ 152 "02153 "0'~154 "0~' 155 000156 00?151 001160 00~161 00;1162 00 ~~ 163 "'f2J;~164 001165 1Z102166 "00167 1Z10~l1'0 "~H3171 00~.l172 01210~~121 ~12I0~eJl2I ~0Z17J 1Zl0;~174 21"'121"1215 ;301211211215 012100"121 121012101215 IZl 121 121121 0 121 121"'1211211215 ~121"k:1121121 121 0 1211Zl!2l5 0121"121"121 1210121"1215 12112101210121 0012101215 001211210121 12100"05 1Zl01Zl1Zl0121 121012101215 121012112100 12101211211215 0001210121 121"'0""5 "0",121"0 000""5 "0121""121 00001215 0121001('JI2I ~0001215 1Zl01Zl1Zl1Z1121 2'012112105 ""1210210 0"'121121"5 1210121""5 """0"121 121"12101215 " " QJ 'Hila 0"~00" """00' 00"""" 0"'''00!5 "1210""0 0"001215 "121"""" ~"'00"5 ~0121"0" 0~H'1'5 00Z176 "0~177 "'121 ~120121 "'1Zl~~201 1Zl0i21Zl2 1Zl0e:21ZlJ "'002(214 00,..'121215 1Zl1Zl0206 I2I'H~ 21217 1Zl1Zl;: 210 00~211 1Zl0~212 00C213 002214 002215 "0~216 00Z21' 1Zl0~22~ 00~221 """""5 "00"1ZI0 0"0"05 0"0"00 021""05 ~""02!" 0 0 0"05 0"0222 00e22:5 000224 "0e225 2100226 002227 002!230 000231 002232 000233 0~"005 """""" 21""0",, 121"001215 ""121000 """""5 "0"""0 0"12101215 "",,0"0 el03""" 021121146 ~2!"0"5 "1211121"" ~ ~ " " 3 2 - ~"""00 "'~""'" "0,,000 0"'0"1217 el0eJ0"0 00~HH:'!7 "000"0 121"'''''''7 "000"0 21~0rJ07 el02'~00 "n0"01 IZl~HlJ021121 elf2Jel012J12I ~0000k'1 Number of words to next LSCW. 0~h~234 002235 00~236 00;3237 00;)240 00e241 000242 "~"0~7 ~00007 0~f2J0f2J7 00~24J 002244 00000121 00"'12101 0~0~00 i2lf2J0~~0 i21000~121 00~245 ~01210'" '-"~0~12l7 ~eJ00"7 f2J0l246 0~H~247 00/250 00e251 21121000121 ~012101217 0000021 (10rcHl!{2J7 021210"'121 ~0"12107 00~l252 12'0;1253 ~00~"12I ~0"'001 00~~254 1Zl0~255 1210121000 ,,000~7 0121021210 121~"0217 000021121 0"0"'1217 00J256 00;~257 D-9 1Zl0~H'0121 2' '1211211217 0121 00 el 121 00 ItH' 121 7 0121 IZllZl eJ 121 ~"I2I"Ql' 12112101Zlell2l i£I 0 121 "121 7 IZl~H~"0121 (30121"1211 1Zl12l2~"12I 00121114 ... -Continue LSCW. 1210012121" 3"'12101217 "'1211210"121 ~0""12I7 1Zl01Zl1Zl1Zl" 00~HHH 000~HHI 0"12101217 "0,,0121" ~1Zl"1Zl1217 ""1211210121 1210121eJI2I7 0"2'0~121 121"'121007 01211Zl1Zl1Zl121 121012112107 "",,21"121 121"121"07 01211210121121 00"0"7 1211210000 1210121"1217 elI2I00~" 0~HH'12I7 "0Q10~" ~00~"7 ~"2!~00 ""0"2'1 rJl2I"0"0 0"121"'" ""rJ0 21 121 "~121"'" ""130~" 0"""0' ""e"~" 021""0' 121"0"01 o " '''' 121 " 0 0 ""07 0""0"0 01210~0" 0"0""7 0""""" 0""007 00"0~" 0~"00? 01210""0 0000"" "0"121"" "121"0"" el0e10"0 0"'0"07 0"121"01 0"00"7 ~""007 2100211217 ~0""121" ""0007 2l"HH'~" 0 0 121"07 "0"""0 0"121"1217 el0210021 ,,00~01 O000"" "r1121~01 ""0"~21 (1301210211 "00000 0"0"07 0eJet0021 0 0 001211 000{2J",,,, "''''''''01 ~H:H"0"" 0"0e107 00210021 002121121' 012100"'0 21"'''00' J12I0"00 f2J~"~01 000~00 0"1212101 12112100021 00"001 "1210000 000Ql01 121121000121 2100"'" 0000"" 00012107 ~"00"" 0~~0'" FOROTS ~0026" 1Z10~261 "E"~262 "0Z263 "~"3264 IlIrtH~265 00~~266 "0.,267 00:~ 27" 000271 00i272 00;1;273 12l0~~214 00Z275 "0~j276 """""" ~,,~""" "~"eJ07 0~"""7 "0i!27? "0e3"0 "003"1 "0;;'3""2 000""" """"07 ~"00~" 0~"""7 "0"0,,, "~HH'J"" "0021"" ""'0"0' r2J ~HHH'I " 0 '" '''' 0 7 """""" 00""00 000""7 000"07 "1c:I00"" 0""21211 "0"0"" 0~0"07 "000"0 0"'0"0' """~"0 000"21' """""" "'00000 0"0"07 0"0"'''7 0~H~303 "00304 000305 00J306 00~307 "0~310 "00311 "00312 00i'l313 0el314 Image mode files contain no LSCWs. C C "01210"" 21"00", 0000"" 0"""0' 2100""0 ~"0"0' "00000 0"0"07 "0"1lI1ZI0 "et0"0' ""r2J0"" ,,~""'" """00"" 00 rtH'l 07 "0""00 21"""07 "0"0"" ""0"07 0210""" 0~1c:I"07 00"""" 0""""7 "0"0021 0""""7 "0"0210 ,,0"2107 "Ql3"~" ""0147 You cannot backspace this file. AT AN IMAGE MODE rI~E AND SEE NO LOGJCA~ SEGMENT CONTROL WORDS. ~OOK OPENCUNI Tc 1,MODED'IMAGE') Ia5 WRITE(1) (I, J=l,l21'" J='7 WRITE(1) (J,K=1,1210) END "0 k~"" 0 121121~12I01 00"01212 0121001213 00?01214 0~HH'''5 0001211216 00.~1210? 1210001121 0121~011 l2I~hJ12I12 0121~12113 00~12I14 1210~312115 00:1016 00012117 0121002121 12l0J021 001022 e10.?1023 00J024 12100025 1210e12l26 210""00 0 0 0""5 1211210121121121 0012112105 "121~00121 1210''12105 ~121"00121 001211211215 1211211211210121 00121005 ell2l00 121121 0001211215 QI~}210 ~H' 0"'01211215 I21121e'000 0012101215 121121012100 0 0 01!ll2l5 el0000121 ~2!"12l05 1211211211210121 el2ll2l~12I5 e!12I000121 12100"1215 0121000121 ~00005 01210kl"0 ~001211215 0121121000 12Ie!~H!l12I5 0"001211Zl 12101Zl01215 ~000~0 0 0 0r2J05 ~121"000 1210001215 e1121121121~0 0121121005 "0I2HH,,,, 0r;,0~05 0121~12121 1210 Il 121 3121 00012131 12102!12132 0121012133 1!ll2l~034 121021035 00J036 00012131 11'001214121 121 0012141 000042 00;312143 00""044 D-IO 00001210 fc.1"0121121~ 012100~121 ~12l001215 12101210121121 0 0 21005 0000121" ~O12l005 "0000" 0"1211211215 12100121121121 001Zl00S ~12It:!l000 021121005 rtHHH~12I0 12112112101215 "00121"121 ~~001215 00001210 001211211215 1210121121121121 0 0 01211215 01Zl00~0 0"0"'1215 01211211210121 0001211215 001210~0 ~00"05 00,,1212'121 0012leJI2I0 00021121121 01Zl1210121" o "'1Zl 121 1215 0"'012105 01Z1001Zl5 00001215 00~12145 00~046 "l2IkHHHJ 000"41 0002!~0 ~0001215 el2!1Zl005 FOROTS ~~0"5~ ~00"51 ~~0052 00~"53 0"H'!054 00;'055 210J056 12100057 ~0~060 1210?061 0~H~062 00~063 ~0~~064 00\~065 00.1066 1210~·067 1210~07" 121 02071 121 0 ;~072 "0:'2173 00 ,;~" 7 4 00~075 1210~0'6 00~077 l2Ie<110" 00()101 1210?lel2 "0011213 003104 00~~105 00?11216 000107 1210ell'" 01210111 002112 "01113 1210~114 0121~115 "0v~116 00~11' 00~122J 0~H'121 01210122 000123 000124 "'12I{l12, 00~126 00~127 0"~132J 1210e131 0121~132 1210fl13J 12100134 """'0~9 ~00135 ~00136 k""H~ ~'" ~0"00~ ~~02100 0r2l0QJ05 00e137 ~~~0~~ k"iH'l 'H~" Qlk'J"'''05 00~14" 00~141 0~0000 ~0210QJ0 .,00005 21 0 02105 0001210121 0001211215 000121~0 ~0"0~121 ~00"0~ 000"~121 01210"00 0e1riHH~5 ~0000~ 2'00e'~0 ~00"05 00001210 JeJ00~5 12100142 1210ta43 0r,h~144 I2I~H~145 0~.a46 eI r2I 0121 05 000000 000005 210{,147 00~150 0"~~~" .J~"~05 0'H'''~0 ~"~0005 1210,1;151 2100152 00:a53 "'H:154 0riHHHljl2l ~~0005 "0~"'~0 0"'00215 J"0005 12102156 012100~0 00~1155 0~H'.157 00k')16121 00\?161 008162 ~""'0~12I "~12I~0~ 0fZl~~~0 '" el 0 v,,~ 5 ~000"0 ~Q!0~12I5 00~16J 0~W164 00e'1fZl00 0011:H'l12l5 0000e10 ,,00(;'l05 et12l00~121 0~H'I00121 el0J165 12102166 1210 ~~ 16 7 1210 ~~ 17" 0~0~12I5 ~~~01215 002101210 01210005 0~Hl000 000005 ~1,Hl!00~ 3 eJ 012105 el00000 210012105 "' ' ~H'"'' ~1,H~12I00 1210;·~171 00.~172 1210l17J 0~"'0fZl5 000121~5 1210~174 00~175 00(~176 02100121121 eHi'l0 0 1215 000000 ~eJ001215 ~00"00 0 e1 00215 0~HH'12I121 01211211211215 00000121 21"12112105 ~02112100 2100177 001~2~" 12100201 00~202 0~001215 1210:'1203 02Jel002J ~0"12I2J5 02J0"12I0 2J001212J5 1212J12I'''~0 000121"9 0"121121121121 3"'''005 "0012100 ~0"0"5 1212J0121~0 0"'01211215 ~012121"'0 121"''''005 21 Q""~ I2IPJ 012101211219 ""1210121121 121 e 0121 121 5 00~2Q14 0(21('.205 00;)206 k"h~21217 0121"~21121 00~211 1210\-1212 12100213 00~214 ~0"0"9 121""""", 0"1211211210 0~2J2I1215 01210215 1211210216 012112101210 0"'~H"05 12l121I212JPJ0 121012112105 121012101210 0121012105 0"~217 121121~22121 00iJ221 0"12I~12I121 121~"005 D-ll 0~HI~00 ~"HH'I00 ~00~00 0"e~05 ~"~Hl05 000005 ~"~"000 00"~05 ~0012100 0"'0~"'5 0~"1211210 21i21ICHH;'15 121002100 ~00"H!l5 00000a 000007 1Zl00000 ,,0"~"7 ~0000'" 211210001 1Zl!,H~"00 Ql0012107 0210"1210 0002107 ~0"01210 0~01210' 002101210 0021121"0 00121f2Jel0 0~012107 ~1210"1210 00012107 21"'0~07 ~HHHl07 00121"00 ~eJ"12I07 0~00210 ~12I0~~21 el00007 0012101217 "'''~000 ~~00~1 ~"~0k"121 000"~" 0~0Q11210 ~12I0~~0 ""'0007 00121007 0~012107 0et0007 012121021121 0e1121007 000000 000007 0012100~ 00121007 '" 0 2J 0 ~H?J 000~07 001210"'0 ~""0007 Ql~H~000 0012112107 021 0r,H~"~ 000"1217 000~~0 0"'001217 0000~H?J ~~0000 ~Ql0eJ"'7 0"'~12102J ~"2J007 00012107 021021210 21121001217 0021121e10 00121007 0021000 Qj02Jk'l07 el2J00~0 121210"07 012!00~12I (21121012107 2I0~i2I~0 ""'12100' 00e1i21"0 00121e!07 0000~'" 0121001211 12I"'0121~0 121"'012107 02J 121121 121 0 1ZI"'''l'l07 211210000 0Q\l2Iet07 ~01211211212J (21001211211 0012121"0 0~"et07 ~ 2J 121 ~H"'J 012112112112!1 12112I~l2Iell2I 20"007 ~0121000 elet0"'217 ""~12I1210121 ~21012107 FOROTS 1lJ"~222 0"~223 ~00224 0"~225 "eJ226 "0~22' 00023" ""H~231 "0~232 "0~233 ""H~234 "0Ql235 "0~236 "0~~237 "0~240 "0l241 "0·~ 242 000243 12101'244 12J0~245 "1210246 00,3247 00e25121 I2IrcH'251 001252 12102253 "0?254 0.5.3 0""~~1 """""~ 0~"~0" 0""0", "",,,,,,,,, """"' ' ' ""'''''''' """""" "'0""'" """""" 0"'''''''' 0",,0Z10 ,,00"'" ~0000~ 0"""'" "0"",,., 0!2JeI""" 0"0007 000264 ~""""0 0 1l1 """1 "0"""" 0010266 "'kHI""0 "'0"0210 0 0"07 :2'!2J~0"!2J 0"0~"~ "0~~265 0 0~"""0 0~""07 "0?26, 000270 0"0""0 0"""'" 0~"000 "'-'''''''7 00(('100" 0"0"0' 00"0e'0 0"""0' "00000 ""'~0"7 21000"0 "~~00' "0~~2'1 "0:?272 "0~27J "0r1274 00~'275 "000~12J ~00~12I7 0~Q!00" ~002l07 211210000 ~01210'" I2IlZlil276 12J0'~217 000300 0020301 001~ 30 2 c,~21e!1Zl7 00(2100121 Z0121eJ07 000121~0 121 0 01210' eJ0~~3eJJ 0~h~304 00~305 1210 ;~306 00~0"7 0121021121121 0 0 0007 ~0000~ el02'0~121 "'01('261 00'~262 "0~~26J 0~"",,,,, ""0"07 "0"""" Z"""07 1210"""" 000"07 "~00~" r210iH'", ~00000 000007 00""'0' 2!kHH' 210 ""'021!2J'1 "0~26" riHH.H~"" 00k'0~121 0~""00 "'02255 002256 "'02257 ~000"7 02!el~e'i 012103",., ""21021~ ,,00~0T "0000" 0P.!00217 "0"0"" 0"'''007 ""0f21~"~ 0"'''''0' 0"""~Hl' "'''''''07 "000"0 0"'0"07 000000 ~eI"0~7 I2IkHH:'l2l0 0"""01 01210"0121 12I~01210' "121000121 """'0'" 0121"0~", a0121l'11217 etl2l1210"0 0'='''1210'' 0"0"00 1210"121121' 21001210121 1210121001 01210"00 1Zl~00"7 12102101210 0001210' 01211Zleel0 12I~"007 Mixed Mode Data Files FOROTS permits files containing both ASCII and binary data records to be read. Mixed files may be accessed in either sequential or random access mode. Logical ASCII and binary records have the same format as described in the preceding paragraphs. In random access mode, the record size must be large enough to contain the largest record, either ASCII or binary. 0-12 FOROTS D.S.4 Image Files The image data transfer mode is a buffered mode in which data is transferred in a blocked format consisting of a word count located in the right half of the first data word of the buffer followed by the number of 36-bit data words. The devices that permit image data transfers and the form in which the data is read or written are: Device Data Forms Card Reader All 12 punches in all 80 columns are packed into the buffer as 12-bit bytes. The first 12-bit byte contains column 1. The last word of the buffer contains columns 79 and 80 as the left and middle bytes, respectively. Cards are not split between two buffers. Disk Data is written on the disk exactly as it appears in the buffer. Data consists of 36-bit words. Magnetic Tape Data appears on magnetic tape exactly as it appears in the buffer. No processing or checksumming of any kind is performed by the serV1ce routine. The parity checking of the magnetic tape system is sufficient assurance that the data is correct. All data, both binary and ASCII, is written with odd parity and at 800 bits per inch unless changed by the installation. Plotter Six 6-bit characters per word are transmitted to the plotter exactly as they appear in the buffer. D.6 USING FOROTS FOROTS has been designed to lend itself for use as an I/O system for programs written in languages other than FORTRAN. Currently, MACRO programmers may employ FOROTS as a general I/O system by writing simple MACRO calls that simulate the calls made to FOROTS by a FORTRAN compiler. The calls made to FOROTS are to routines that implement FORTRAN I/O statements such as READ, WRITE, OPEN, CLOSE, RELEASE, etc. FOROTS will provide automatic memory allocation, data conversion, buffering, and device interface operations to the MACRO user. D-13 I/O FOROTS D.6.l FOROTS Entry Points FOROTS provides the following entry points for FORTRAN compiler or a non-FORTRAN program: Entry Point ALCHN. ALCOR. CLOSE. DBMS. DEC. DECHN. DECOR. ENC. EXIT. FIN. FIND. FORER. FUNCT. IN. IOLST. MTOP. NLI. NLO. OPEN. OUT. RELEA. RESET. RTB. TRACE. WTB. D.6.2 calls from either a Function Allocate software channels Allocate dynamic memory blocks Close a file DBMS interface DECODE routine De-allocate software channels De-allocate dynamic memory blocks ENCODE routine Terminate program exeuction Input/Output list termination routine position to the next record (RANDOM ACCESS) Error processor Overlay interface Formatted input routine Input/Output list routine File utility processing routine NAMELIST input routine NAMELIST output routine Open a file Formatted output routine Release a device (CLOSE implied) Job initialization entry Binary input routine Trace subroutine calls Binary output routine Calling Sequences You must use the following general form for all calls made to FOROTS: MOVEI PUSHJ l6,ARGBLK l7,Entry Point (control is returned here) where: 1. ARGBLK is the address of a specifically formatted argument block that contains information needed by FOROTS to accomplish the desired operation. 2. Entry Point is an entry point identifier (see list given in Paragraph D.6.l) that specifies the entry point of the desired FOROTS routine. with three exceptions, all returns from FOROTS will be made to the program instruction immediately following the call (PUSHJ 17, entry point instruction). The exceptions are: D-14 FOROTS 1. An error return to a specified statement number, or WRITE statement ERR=option, 2. An end-of-file return to a statement number, WRITE statement END=option, i.e., READ 3. A fatal error that returns to package. or a the monitor i.e., to READ or debug Paragraphs 0.6.3.1 through D.6.3.ll give the MACRO calls and required argument block formats needed to initialize FOROTS and FOROTS I/O operations. Argument blocks conform to the subprogram calling convention described in Appendix C. However, there is one exception in dealing with the first word of an I/O initialization call, i.e., WTB., ENC., RTW., etc., for a FORTRAN logical unit number. In previous versions of FOROTS and FORTRAN-20, if the indirect bit was not set, the argument was immediate; if it was set to 1 (one), the argument was the address of the variable. The type field was always a (zero). with Version 4 of FORTRAN-20 and Version 4 of FOROTS this convention has been changed. If the type field of the first word of an I/O initialization call for the FORTRAN logical unit number is 0 (zero), the argument is an immediate mode (18 bit) constant wherever possible. If the type field is integer, the argument is indirect (see Appendix C, Table C-l, Type 2). This exception should not cause any upward compatibility problems, since all previously working programs will still function. An added feature with this convention is that it permits the following construct to be correctly implemented: 100 0.6.3 N=-4 READ (N, 100 ) I, J FORMAT (215) !SET FOR TERMINALS MACRO Calls for FOROTS Functions The following paragraphs describe the forms of the MACRO calls to FOROTS that are made by the FORTRAN-20 compiler. The calls described are identified according to the language statement that they implement. The following terms and abbreviations may be used in the description of the argument block (ARGBLK) of each call: pointer to the second word in the argument block. (This is the address pointed to by the argument ARGBLK in the calling sequence.) u a FORTRAN logical unit number f FORMAT statement address, v· the name of an array containing ASCII characters, list an Input/Output list, D-15 FOROTS c the statement to which control is transferred on an "END OF FILE" condition, d the statement to which "ERROR" condition, name a NAMELIST name, R a variable specifying random access mode, * list directed I/O; type type specification of a variable or constant, control the is logical transferred record on number an for the FORMAT statement is not used, where ARGBLK is 0-8 9-12 13 14-17 -6 Reserved Reserved 18-35 0 type I X u 7 I X c 7 I X d type I X f type I X type I X Format Size (in words) v D.6.3.l I/O Statements, Sequential Access Calling Sequences The READ and WRITE statements for formatted sequential data transfer operations and their calling sequences are: READ(u,f,END=C, ERR=d) list MOVEI 16, ARGBLK PUSHJ 17, IN. and WRITE(u,f,END=C, ERR=d) list MOVEI 16, ARGBLK PUSHJ 17, OUT. D-16 POROTS where ARGBLK is 0-8 9-12 13 14-17 18-35 -5 0 Reserved Reserved type I X u 7 I X c 7 I X d type I X f type I X Format Size (in words) The READ and WRITE statements for unformatted sequential data transfer operations and their calling sequences are: READ(u,END=C, ERR=d) list MOVEI 16, ARGBLK PUSHJ 17, RTB. and WRITE(u,END=c, ERR=d) list MOVEI 16, ARGBLK PUSHJ 17, WTB. where ARGBLK is 0-8 9-12 13 14-17 -3 18-35 0 Reserved type I X u 1 Reserved 7 I X c 7 I X d 0.6.3.2 NAMELIST I/O, Sequential Access Calling Sequences - The READ and WRITE statements for NAMELIST-directed sequential data transfer operations and their calling sequences are: RE.AD (u,name) READ (u, name, END=c, ERR=d) MOVEI 16, ARGBLK PUSHJ 17, NLI. and ,- WRITE (u, name) WRITE (u, name, END=c, ERR=d) MOVEI 16, ARGBLK PUSHJ 17, NLO. 0-17 FOROTS where ARGBLK is 0-8 9-12 13 14-17 18-35 -4 0 Reserved j Reserved type I X u 7 I X c 7 I X d type I X NAMELIST table address The NAMELIST table is generated from the FORTRAN NAMELIST. The first word of the table is the NAMELIST name; following that are a number of 2-word entries for scalar variables, and a number of {N+3)-word entries for array variables, where N is the dimensionality of the array. The names you specify in the NAMELIST statement are stored, in SIXBIT form, first in the table. Each name is followed by a list of arguments associated with the name; this argument list may be of any length and is terminated by a zero entry. The name argument list may be in either a scalar or an array form (refer to the following diagrams). D.6.3.3 Array Offsets and Factoring - Address calculations used to reference a given array element involve factors and offsets. For example: Array A is dimensioned DIMENSION A (Ll/Ul,L2/U2,L3/U3, ... Ln/Un) The size of each dimension is represented by Sl = Ul-Ll+l 52 = U2-L2+l etc. In order to calculate the address of an element referenced by A (Il,I2,I3, ... In) the following formula is used: A+{Il-L1)+(I2-L2)*Sl+{I3-L3)*S2*Sl+ ... +{In-Ln)*S[n-l]* ... *S2*Sl The terms are factored out depending on the dimensions of and not on the element referenced to arrive at the formula the array a single A+{-L-L2*Sl-L3*S2*Sl ... )+Il+I2*Sl+I3*S2*Sl ... The parenthesized part of this formula is the offset for precision array and it is referred to as the Array Offset. D-18 FOROTS For each dimension of a given array, there is a corresponding factor by which a subscript in that position will be multiplied. From the last expression, one can determine the factor for dimension n to be S[n-l]*S[n-2]* ... *S2*Sl For double-precision and complex arrays, the expression becomes A+2*(Il-Ll)+2*(I2-L2)*Sl+2*(I3-L3)*S2+Sl+ ... Therefore, the array offset for a double-precision array is 2*(-Ll-L2*Sl-L3*S2*Sl ... ) and the factor for the nth dimension is 2*S[n-l]*S[n-2]* ... *S2*Sl The factor for the first dimension of a double-precision array is always 2. The factor for the first dimension of a single-precision array is always 1. SCALAR ENTRY in a NAMELIST Table o. .8 .11 9. 12. .14 15. .17 . .35 18. SIXBIT/SCALAR NAME/ a a X Scalar addr 12-14 15-17 18-35 I X I ARRAY ENTRY in a NAMELIST Table 0-8 9-11 SIXBIT/ARRAY NAME/ #DIMS type ARRAY SIZE OFFSET I X Factor 1 I X Factor 2 I X Factor 3 . . I X D-19 Factor n FOROTS D.6.3.4 I/O Statements, Random Access Calling Sequences The READ and WRITE statements for random access data transfer operations and their calling sequences are: READ (u#R,f,END=c, ERR=d) list READ (u#R,END=c, ERR=d) list MOVEI 16, ARGBLK PUSHJ 17, RTB. and WRITE wRITE MOVEI PUSHJ (u#R,f,END=c, ERR=d) list (u#R,END=c, ERR=d) list 16, ARGBLK 17, WTB. where ARGBLK is 0-8 9-12 13 14-17 18-35 0 -6 type I X u 7 I X c 7 I X d type I X f , type I X format size (in words) Reserved 2 I X address of Record Number Reserved f and the format size in words are 0 if the I/O statement is unformatted. D.6.3.5 Calling Sequences for Statements That Use Default Devices The FORTRAN-20 statements that require the use of a reserved system default device and their calling sequences are: Default Device ACCEPT f, list READ f, list REREAD f, list (TTY) (CDR) (REREAD) UNIT=-4 UNI'I'=-5 UNIT=-6 MOVEI 16, ARGBLK PUSHJ 17, IN. D-20 FOROTS where ARGBLK is 0-8 9-12 13 14-17 18-35 a -5 Reserved 2 I X u 7 I X c 7 I X d , type I X f Reserved type I X Format Size (in words) Default Device PRINT f, list TYPE f, list UNIT=-3 UNIT=-l (LPT) (TTY) MOVEI 16, ARGBLK PUSHJ 17, OUT. where ARGBLK is \'-....._. 0-8 9-12 13 14-17 a -5 Reserved Reserved 18-35 2 I X u 7 I X c 7 I X d type I X f type I X D-21 format size (in words) FOROTS D.6.3.6 Statements to Pos~ition Magnetic Tape Units The FORTRAN-20 statements that may be used to control the positioning of a magnetic tape device and their calling sequences are: Function (FORTRAN Statement) FOROTS Code SKIPFILE (u) BACKFILE (u) BACKSPACE (u) ENDFILE (u) REWIND (u) SKIPRECORD (u) UNLOAD (u) 7 3 2 4 o 5 1 CALL: MOVEI 16, ARGBLK PUSHJ 17, NTOP. where ARGBLK is 0-8 9-12 13 14-17 -4 18-35 0 Reserved type I X u j 7 I X c 7 I X d Reserved type I X FOROTS code D.6.3.7 List Directed Input/Output Statements You may write any form of a sequential Input/Output statement as a list-directed statement by replacing the referenced FORMAT stateme~t number with an asterisk (*) . The list-directed forms of the READ and WRITE statements and their calling sequences are: READ (u, *, END=c, ERR=d) list MOVEI 16, ARGBLK PUSHJ 17, IN. and WRITE (u, *, END=c, ERR=d) list MOVEI 16, ARGBLK PUSHJ 17, OUT. D-22 POROTS where ARGBLK is 0-8 9-12 13 14-17 18-35 a -5 Reserved Reserved 2 I X u 7 I X c 7 I X d a a a a a a a a D.6.3.8 Input/Output Data Lists - The compiler generates a calling sequence to the runtime system if an I/O list is defined for the READ or WRITE statement. The argument block associated with the calling sequence contains the addresses of the variables and arrays to be transferred to or from an I/O buffer. The general form of an I/O list calling sequence is: MOVEI 16, ARGBLK PUSHJ 17, IOLST. Any number of elements may be included in the ARGBLK. The end of the argument block is specified by a zero entry or a call to the FIN. entry. Mnemonic Name FOROTS Value DATA SLIST ELIST FIN 1 2 3 4 The elements of an I/O list are: 1. DATA The DATA element converts one sing1e- or double-precision or complex item from external to internal form for a READ statement and from internal to external form for a WRITE statement. Each DATA element has the following format. 0-8 9-12 13 14-17 18-35 DATA type I X SCALAR ADDR D-23 FOROTS 2. SLIST The SLIST argument converts an entire array from internal to external form or vice versa, depending on the type of statement, i.e., READ or WRITE, involved. An SLIST table has the following form: 0-8 9-12 SLIST 0 type 13 14-17 18-35 I X #ELEMENTS I X INCREMENT I X 8ASE ADDR1. For example, the sequence: DIMENSION A(100) ,8(100) READ(-,-)A or READ(-,-) (A(I) ,1=1,100) !only when the IOPT switch is used develops an SLIST argument of the form: 0-8 9-12 13 14-17 0 0 2 0 0 0 0 0 0 0 0 0 18-35 0 2 0 0 4 144 1 A 0 More than one base address may appear in a SLIST as the increment is the same. The sequence DIMENSION A(lOO), 8(100) WRITE (-,-) (A(I) ,8(1) ,1=100) ! only when the IOPT switch is used develops a SLIST argument of the form: 0-8 9-12 13 14-17 18-35 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 144 1 A 8 0 0 2 0 0 0 4 D-24 long as FOROTS 3. ELIST The SLIST format permits only a single increment for a number of arrays to be specified while the ELIST permits different increments to be specified for different arrays. The format of the ELIST is 0-8 9-12 13 14-17 18-35 ELIST type I X No. Elements to transfer increment 1 type I X Base ADDR 1 increment 2 type I X Base ADDR 2 increment N type I X Base ADDR N For example, the FORTRAN sequence DIMENSION IC (6,100), IB (100) WRITE(-,-) (IB(I) ,IC(l,I) ,1=1,100) produces the ELIST 0-8 9-12 13 14-17 18-35 3 0 0 0 0 4 0 0 2 0 2 0 0 0 0 0 0 0 0 0 0 0 0 144 1 IB 12 IC 0 0 The increment may be zero. sequence DIMENSION A(lOO) WRITE(-,-) (K,I=100) This could be produced by the !on1y when the IOPT switch is used The zero may not appear as an immediate constant in the argument block. The ELIST for the previous example would be 0-8 9-12 13 14-17 18-35 144 3 0 0 0 0 2 0 0 0 type 0 0 K 4 0 0 0 0 D-25 Pointer to a word containing a zero FOROTS 4. FIN The end of an I/O list is indicated by a call to the FIN routine in the object time system. This call must be made after each I/O initialization call, including calls with a null I/O list. The FIN rout~ine may be entered by an explicit call or by an argument in the I/O list argument block. If both calls are used, the explicit call has no meaning. The FIN .element has the following format: EXPLICIT CALL: PUSHJ 17, FIN. D.6.3.9 OPEN and CLOSE Statements, Calling Sequences - The calling sequences for the OPEN and CLOSE statements are: form and OPEN STATEMENT CALL MOVEI 16, ARGBLK PUSHJ 17, OPEN. CLOSE STATEMENT CALL MOVEI 16, ARGBLK PUSHJ 17, CLOSE. where ARGBLK is 0-8 9-12 13 14-17 Negative of the number of words in block not including this one. 0 0 0 G G G · · 0 2 7 7 type type type · . · type G 18-35 I I I I I I X X X X X X · · · · · X · I · u c d H H H . H The G field (bits 0 through 8) contains a 2-digit numeric that defines the argument name; the H field (bits 18 through 35) contains an address which points to the value of the argument. D-26 FOROTS The numeric codes that may appear in the G field and the argument that each identifies are: G Field Open Argument G Field 01 02 03 04 DIALOG ACCESS DEVICE BUFFER COUNT BLOCK SIZE FILENAME PROTECTION DIRECTORY 12 13 14 15 16 22 23 24 as 06 07 10 Open Argument MODE FILE SIZE RECORD SIZE DISPOSE VERSION ASSOCIATE VARIABLE PARITY DENS I'I'Y D.6.3.10 Memory Allocation Routines - The memory management module is called to allocate or de-allocate memory blocks. There are two entry points, ALCOR. and DECOR., that control memory allocation and de-allocation. Use the ALCOR. entry to allocate the number of words specified in the argument block variable. Upon return, AC a will contain either the address of the allocated memory block or a -1 value, which indicates that memory is not available. The calling sequence for ALCOR. call is: MOVEI 16, ARGBLK PUSHJ 17, ALCOR. where ARGBLK is 0-8 9-12 13 14-17 a -1 Reserved 18-35 type I X Address of Number of Words Use the DECOR. entry to de-allocate a previously allocated block of memory; the argument variable must be loaded with the address of the memory block to be returned. Upon return AC a is set to O. If the number of desired words is N, ALCOR. actually removes N+l words from free storage. The pointer returned points to the second word (word 1 as opposed to word 0) removed from free storage. The a word contains the negative value of N in its left half. This word is used by FOROTS to maintain linked lists of allocated (using ALCOR.) and free storage. The calling sequence for a DECOR. call is: MOVEI 16, ARGBLK PUSHJ 17, DECOR. D-27 FOROTS where ARGBLK is 9-12 0-8 13 18-35 14-17 a -1 type Reserved I X Pointer to word containing address of block to be returned D.6.3.ll Software Channel Allocation and De-allocation Routines - You may allocate software channels in MACRO programs via calls to the ALCHN. routine and de-allocate them by calls to the DECHN. routine. Values are returned in AC o. Use the ALCHN. entry to allocate a particular channel or the next available channel. The channel to be allocated is passed to ALCHN. in the argument block variable. Zero is passed in the argument block variable to allocate the next available channel. Allowed channels are 1 through 17 (octal). If the channel requested is not available, or all channels are in use, ALCHN. returns with a -1 in AC O. In normal returns, AC a contains the assigned number. The calling sequence of an ALCHN. routine is: MOVEI 16, ARGBLK PUSHJ 17, ALCHN. where ARGBLK is 0-8 -1 Reserved 9-12 13 14-17 18-35 a \ type I X Pointer to a word containing the channel # or zero Use the DECHN. entry to de-allocate a previously assigned channel. The channel to be released is passed to DECHN. in the argument block variable. If the channel to be de-allocated was not assigned by ALCHN. and thus cannot be de-assigned, AC a is set to -1 on return. The calling sequence for a DECHN. routine is: MOVEI 16, ARGBLK PUSHJ 17, DECHN. D-28 FOROTS \vhere ARGBLK is 0-8 13 9-12 14-17 -1 Reserved D.7 18-35 0 type I X Pointer to a word containing the channel # to be released FUNCTIONS TO FACILITATE OVERLAYS FOROTS provides a subroutine (FUNCT.) to serve as an interface with the LINK overlay handler. This subroutine consists of a group of functions that allow the overlay handler to perform I/O, memory management, and error message handling. These functions have only one entry point, FUNCT., and they are called by the sequence MOVEI 16, ARGBLK PUSHJ 17, FUNCT. The general form of the ARGBLK is 0-17 ARGBLK~ 18-35 Negative of the number of words in block type type type type type type 0 function number error code status argument 1 argument 2 argument 3 . . . . type argument n where type function number error code status the FORTRAN argument type (see Appendix C) the number of one of the required functions the 3-letter mnemonic output by the object time system after ?, %, or [. (See Table D-l. ) undefined on the call and set on the return with one of the values below. -1 o 1 .... n D-29 Function not implemented Successful return Specific error message FOROTS Table D-l Function Numbers and Function Codes Function Number Function Mnemonic 8 9 ILL GAD COR RAD GCH RCH GOT ROT RNT IFS 10 CBC 0 1 2 3 4 5 6 7 Function Description Illegal function Allocates memory from a specific address Allocates memory from available core De-allocates memory Gets or assigns an I/O channel Releases an I/O channel Allocates memory from FOROTS De-allocates memory from FOROTS Returns the initial runtime from FOROTS Returns initial runtime file spec. from FOROTS Cuts back memory if possible FUNCTION 0 (ILL) - This function is illegal. The argument ignored, and the function always returns a status of -1. FUNCTION 1 (GAD) - This function address. The arguments are: arg 1 arg 2 allocates memory from block is a specific and arg 2 and arg 2 address at which to begin core allocation number of words of memory to allocate The return statuses are: o core allocated (arg 1 and 2 unchanged) 1 not enough memory available in system (arg 1 unchanged) 2 cannot allocate memory at specified address (arg 1 unchanged) 3 illegal arguments (i.e., address + size is greater (arg 1 and arg 2 unchanged) FUNCTION 2 (COR) - This function allocates memory The arguments are: arg 1 arg 2 from than any 256K) address. undefined size of core to allocate The returned statuses are: o core allocated (arg 2 unchanged, arg 1 beginning address of the allocated memory) 1 not enough memory available in system (arg 2 unchanged) 3 illegal argument (i.e., size is greater than 256K) FUNCTION 3 (RAD) - This function de-allocates memory at the address. The arguments are: arg 1 arg 2 specified address of core to be de-allocated number of words to be de-allocated The returned statuses are: o memory de-allocated 1 memory cannot be de-allocated 3 illegal argument (i.e., both the greater than 256K) D-30 address and the size are FOROTS FUNCTION 4 (GCH) - This function assigns an I/O channel. is: arg 1 The argument undefined The returned statuses are: o I/O channel assigned (arg 1 channel number) 1 no I/O channels available FUNCTION 5 argument is: arg 1 (RCH) - This function releases an I/O channel. The object time I/O channel number to be released The returned statuses are: o channel released 1 invalid channel number FUNCTION 6 (GOT) - This function gets system list. The arguments are: arg 1 arg 2 memory from the address at which to allocate memory number of words of memory to allocate The returned statuses are: 0 memory allocated (arg 1 and arg 2 unchanged) (arg 1 1 not enough memory available in system unchanged) 2 cannot allocate memory at specified address (arg 1 unchanged) 3 illegal argument(s) and arg 2 and arg 2 This function differs from function 1 in that if the object time system has two free memory lists, then function 1 is used to allocate space for links, and this function is used to allocate space for I/O buffers. Function 1 uses the free memory list for LINK, and function 6 uses the list for the object time system. FUNCTION 7 (ROT) - This function returns memory system. The arguments are: arg 1 arg 2 to the object time address of memory to be de-allocated and returned size of memory to be de-allocated and returned The returned statuses are: o memory de-allocated 1 memory cannot be de-allocated 3 illegal argument FUNCTION 8 (RNT) - This function returns the initial runtime from object time system. The argument is: arg 1 undefined The returned status is: o always (arg 1 - runtime from the object time system) This function is used only if the user desires a log file. D-31 the FOROTS FUNCTION 9(IFS) - This function returns the initial runtime file specification from the object time system. The specification is obtained from accumulators 0, 7, and 11 after the initial RUN command. The arguments are: arg 1 arg 2 arg 3 undefined undefined undefined The returned status is: o always (arg 1 - device from accumulator 11, arg 2 - filename from accumulator 0, and arg 3 - directory from accumulator 7) This function tells the overlay handler which file to read initial RUN command. after FUNCTION 10 (CBC) - This function cuts back memory if possible and used to reduce the size of the user job. There are no arguments. the is The returned status is: o always 0.8 LOGICAL/PHYSICAL DEVICE ASSIGNMENTS You make FORTRAN logical and physical device assignments at run time, or standard system assignments are made according to a FOROTS Device Table, i.e., DEVTB. Table D-2 shows the standard assignments contained by the Device Table. 0-32 FOROTS Table D-2 FORTRAN Device Table Device/Function REREAD CDR TTY LPT TTY o DSK CDR LPT CTY TTY FORTRAN Logical Unit Number -6 -5 -4 -3 -2 -1 00 01 02 03 04 05 Use REREAD statement READ statement ACCEPT statement PRINT statement Not valid TYPE statement ILLEGAL. DISK Card Reader Line Printer Console Teletype User's Teletype 06 through 15 not valid MTAO MTAl MTA2 FORTR DSK DSK DSK DSK DSK DEVl DEV2 DEV3 DEV4 DEV5 DEV39 t1agnetic Tape Magnetic Tape Magnetic Tape Assignable Device DISK DISK DISK DISK DISK Assignable Devices 16 17 18 19 20 21 22 23 24 25 26 27 28 29 63 D-33 APPENDIX E FORDDT FORDDT is an interactive program used to debug FORTRAN programs and control their execution. By using the symbols created by the FORTRAN compiler, FORDDT allows you to examine and modify the data and FORMAT statements in your program, set breakpoints at any executable statement or routine, trace your program statement-by-statement, and make use of many other debugging techniques described in this appendix. Table E-I lists all the commands available to the user of FORDDT. Table E-I Table of Commands Command Purpose Data Access Commands ACCEPT Modifies data locations. TYPE Displays data locations. Declarative Commands GROUP Defines indirect lists for TYPE statements. MODE Specifies format of typeout. OPEN Accesses program unit symbol table. PAUSE Places pause requests. REMOVE Removes pause requests. DIMENSION Defines dimensions of arrays for FORDDT references. (Unnecessary if /DEBUG:DIMENSIONS was used. See Table B-2.) Defines dimensions of double-precision arrays for FORDDT references. (Unnecessary if /DEBUG: DIMENSIONS was used. See Table B-2.) DOUBLE E-l FORDDT Table E-l (Cont.) Table of Commands Purpose Command Control Commands START Begins execution of FORTRAN program. CONTINUE Continues execution after a pause. GOTO Transfers control to some program statement within the open program unit. NEXT Traces execution of the program. STOP Terminates program and returns mode. to monitor Other Commands LOCATE Lists program unit names in which symbol is defined. STRACE Displays routine program status. WHAT Displays current DIMENSION, PAUSE information. E.l backtrace of a given current GROUP, and INPUT FORMAT FORDDT commands are made up of alphabetic FORTRAN-like identifiers and need consist of only those characters required to make the command unique. If you wish to specify parameters, a space or tab is required following the command name. FORDDT expects a parameter if a delimiter (i.e., space or tab) is found. Comments may be appended to command lines by preceding the comment with an !. E.l.l Variables and Arrays FORDDT allows you to access and modify the data locations in your program by using standard FORTRAN symbolic names. Variables are specified simply by name. Array elements are specified in the following format: name (Sl, ... ,Sn) where name (Sl, ... ,Sn) a FORTRAN variable or array name the subscripts of the particular array. You may reference an entire array simply by its unsubscripted name; you may specify a range of array elements by inputting the first and last array.elements of the desired range, separated by a dash(-). E-2 FORDDT Examples ALPHA ALPHA(7) ALPHA (PI) ALPHA(2)-ALPHA(5) E.l.2 Numeric Conventions FORDDT accepts optionally FORTRAN-20 input formats: signed numeric data in the standard 1. INTEGER - A string of decimal digits. 2. FLOATING-POINT A string of decimal digits optionally including a decimal point. Standard engineering and double-precision exponent formats are also accepted. 3. OCTAL - A string of octal digits double quote (II). 4. COMPLEX - An ordered pair of integer or real separated by a comma and enclosed in parentheses. E.l.3 optionally preceded by a constants Statement Labels and Source Line Numbers FORTRAN statement labels are input and output by straightforward numeric reference, i.e., 1234. However, source line numbers must be input to FORDDT with a number sign (#) preceding them. This mandatory sign distinguishes statement labels from source line numbers. E.2 NEW USER TUTORIAL The new FORDDT user can rely on the commands described below as a basis for debugging FORTRAN programs. These commands are easy to understand and apply. E.2.l Basic Commands The easiest method of loading and starting FORDDT is: @DEBUG filename.ext/FORTRAN/DEBUG FORDDT will respond with ENTERING FORDDT » Just as an asterisk (*) signifies FORTRAN-20's readiness, the two angle brackets signify that FORDDT is awaiting one of the following commands: OPEN Makes available to FORDDT the symbol names in a particular program unit of the FORTRAN program. When a program unit symbol table is opened, the previously E-3 FORDDT open program unit is automatically closed. When FORDDT is entered, the MAIN program is automatically opened. The command format is: OPEN name This will open the particular program unit named and allow all variables within that subprogram to be accessible to FORDDT. OPEN START with no arguments will reopen the symbol table main program unit. of Starts your program at the main The command format is: point. program entry the START STOP Terminates program execution, causes all files to be closed, and exits to the monitor. The command format is: STOP MODE Defines the display format for succeeding FORDDT TYPE commands. You need type only the first character of the mode to identify it to FORDDT. The modes are: Mode A C D F I o R Meaning ASCII (left-justified) COMPLEX DOUBLE-PRECISION FLOATING-POINT INTEGER OCTAL RASCII (right-justified) Unless the MODE command is given, the mode is the floating-point format. default typeout The command format is: MODE list where list contains one or more of the mode identifiers separated by commas. The current setting can be changed by issuing another MODE command. If more than one mode is given, the values are typed out in the order: F,D,C,I,O,A,R MODE with no arguments will reset FORDDT setting of floating-point format. TYPE to the original Allows you to display the contents of one or more data locations. They are displayed on your terminal formatted according to the last MODE specification. The command format is: TYPE list E-4 FORDDT where list may contain one or more arrays, variables, array elements, or array element ranges separated by commas. For example: TYPE I, ALPHA, BETA(2) ,J(3)-J(5) Each item will be displayed in each of the currently active typeout modes as set by the last MODE command. ACCEPT Allows you to change the contents of a FORTRAN variable, array, array element, or array element range. The command format is: ACCEPT name/mode value where name array, array the name of the variable, element, or array element range to be contains modified. If the field an unsubscripted array name or an element range, it causes all the elements to be set to the given value (see special case for ASCII in Section E. 6) . mode the format of the data value to be entered. If given, it must be preceded by a slash (/) and immediately follow the name. (Note tha t /mode does not apply to FORMAT modification.) value the new value to be assigned. It must correspond in format to the given mode. Data Modes You need type only the first character of a data mode to identify it to FORDDT. If not specified, the default mode is REAL. The following input modes are available: Mode Meaning A C D F I ASCII(left-justified) COMPLEX DOUBLE-PRECISION REAL INTEGER OCTAL RASCII(right-justified) SYMBOLIC o R S Example /FOO/ (l.25,-78.E+9) 123.4567890 123.45678 1234567890 76543210 \BAR\ PSI(2,4) An example of the ACCEPT command format is: ACCEPT ALPHA 100.6 This changes the value of the variable ALPHA to 100.6 with the default input mode of REAL, since mode was not specified. PAUSE Allows you to set a breakpoint at any label, line number, or subroutine entry in your program. You may set up to ten pauses at one time. When one of these pauses is encountered, execution of the FORTRAN program E-5 FORDDT is suspended and control is transferred to FORDDT. Also, when a pause is encountered, the symbol table of that subprogram is automatically opened. The command format is: PAUSE P where P is a statement label number, line routine entry point name; for example, number, or PAUSE 100 will cause a breakpoint at statement label 100 currently open program unit. of the Note that subprogram parameter values will be displayed when a pause is encountered at a subprogram entry point. CONTINUE Allows the program to resume execution after a FORDDT pause. After a CONTINUE is executed, the program either runs to completion, or it runs until another pause is encountered. If you include a value with this command, the program will run until the nth occurrence of the given pause or until a different pause is encountered. The command formats are: CONTINUE or CONTINUE n Example CONTINUE 15 will continue execution until the fifteenth of the pause. REMOVE occurrence Used to remove those pauses from the program previously set up by the PAUSE command. The command format is REMOVE P where P is the number of the statement label where pause was set, i.e., the REMOVE 100 will remove the pause at statement label 100. Note that REMOVE with no arguments will remove all pauses; therefore, no abbreviation of the command is allowed in this instance. This precaution prevents the accidental removal of all pauses. WHAT Displays on your terminal the name of the currently open program unit and any currently active pause settings. The command format is: WHAT E-6 FORDDT E.3 FORDDT AND THE FORTRAN-20/DEBUG SWITCH Most facilities of FORDDT are features; however, if you do a FORTRAN program, the trace available, and several of the available without the FORTRAN-20 /DEBUG not use the /DEBUG switch when compiling features (NEXT command) will not be other commands will be restricted. Using the /DEBUG switch tells FORTRAN-20 to compile extra information for FORDDT. (See Appendix B, Using the Compiler, for a complete description of each feature.) The additional features include: 1. /DEBUG:DIMENSIONS, which will generate dimension information to the REL file for all arrays dimensioned in the subprogram. The dimension information will automatically be available to FORDDT if you wish to reference an array in a TYPE or ACCEPT command. This feature eliminates the need to specify dimension information for FORDDT by using the DIMENSION command. 2. /DEBUG:LABELS, which will generate labels for every executable source line in the form "line-number L". If these labels are generated, they may be used as arguments with the FORDDT commands PAUSE and GOTO. This switch will also generate labels at the last location allocated for a FORMAT statement so that FORDDT can detect the end of the statement. These labels have the form IIformat-label F". If they are generated, you will be able to display and modify FORMAT statements via the TYPE and ACCEPT commands. Note that the :LABELS switch is automatically activated with the :TRACE switch, since labels are needed to accomplish the trace features. 3. /DEBUG:TRACE, which will generate a reference to FORDDT before each executable statement. This switch is required for the trace command NEXT to function. Note that if more than one FORTRAN statement has been placed on a single input line, only the first statement will have a FORDDT reference and line-number label associated with it. This also applies to the :LABELS switch. 4. /DEBUG:INDEX, which will force the compiler to store in its respective data location as well as a register the index variable of all DO loops at the beginning of each loop iteration. You will then be able to examine DO loops by using FORDDT. If you modify a DO loop index using FORDDT, it will not affect the number of loop iterations because a separate loop count is used. (See Section D.l.5.) Note that this switch has no direct commands in FORDDT. E.4 affect on any of the FORDDT is with LOADING AND STARTING FORDDT 1. The simplest method of loading and starting the following command string: @DEBUG filename.ext/FORTRAN/DEBUG E-7 FORDDT FORDDT responds with ENTERING FORDDT » The angle brackets indicate that FORDDT is ready to receive a command, just as an asterisk (*) signifies FORTRAN-20's readiness. The DEBUG command to the monitor will also load DDT (standard system debugging program). DDT can be used or ignored. 2. You may wish to load your compiled program and FORDDT directly with the LINK loader. (Loading with LINK was accomplished implicitly in the previous command string.) The command sequence is as follows: @LINK *filename.ext /DEB/G *filename.ext /DEB: FORDDT FORTRA *filename.ext /DEB: (DDT, (loads DDT) (loads FORDDT) /G FORDDT FORTRA )/G loads both DDT and FORDDT If the total FORTRAN program consists of many subroutines and insufficient memory is available to complete loading with symbols, it is possible to load with symbols just those sections expected to give trouble. The remaining routines need not be loaded. E.5 SCOPE OF NAME AND LABEL REFERENCES Each program unit has its own symbol table. When you initially enter FORDDT, you automatically open the symbol table of the main program. All references to names or labels via FORDDT must be made with respect to the currently open symbol table. If you have given the main program a name other than MAIN by using the PROGRAM statement (see Chapter 5, Section 5.2), FORDDT will ask for the defined program name. After you enter the program name, FORDDT will open the appropriate symbol table. At this point, symbol tables in programs other than the main program can be opened by using the OPEN command. (See Section F.5.) References to statement labels, line numbers, FORMAT statements, variables, and arrays must have labels that are defined in the currently open symbol table. However, FORDDT will accept variable and array references outside the currently open symbol table, providing the name is unique with respect to all program units in the given load module. E.6 FORDDT COMMANDS This section gives a detailed description of all commands The commands are given in alphabetical order. E-8 in FORDDT. FORDDT ACCEPT Allows you to change the contents of a FORTRAN array, array element, array element range, statement. The command format is: variable, or FORHAT ACCEPT name/mode value where name the variable array, array element, element range, or FORHAT statement modified. array to be mode the format of the data value to be entered. The mode keyword must be preceded by a slash (/) and immediately follow the name. Intervening blanks are not allowed. (Note that /mode does not apply to FORHAT modification.) value the new value to be assigned. The format of the input value must correspond to the specified mode. DATA LOCATION MODIFICATION Data Hodes The following data modes are accepted: Mode Heaning ASCII (left-justified) COMPLEX DOUBLE-PRECISION REAL INTEGER OCTAL RASCII (right-justified) SYMBOLIC A C D F I o R S Example /FOO/ (l.25,-78.E+9) 123.4567890 123.45678 1234567890 76543210 \BAR\ PSI(2,4) If not specified, the default mode is REAL. Two-Word Values For the data modes ASCII, RASCII, OCTAL, and SYMBOLIC, FORDDT will accept a II/LONG II modifier on the mode switch. This modifier indicates that the variable and the value are to be interpreted as two words long. Example ACCEPT VAR/RASCII/LONG '1234567890' will assume that VAR is two words long and store the given 10-character literal into it. Initialization of Arrays If the name field of an ACCEPT contains an unsubscripted array name or a range of array elements, all elements of the array or the specified range will be set to the given value. E-9 FORDDT Example ACCEPT ARRAY/F 1.0 or ACCEPT ARRAY(5)~ARRAY(10)/F 1.0 Note that this applies only to modes other than ASCII RASCII. and Long Literals When the value field of an ACCEPT contains an unsubscripted array name or range of array elements, and the specified data mode is ASCII or RASCII, the value field is expected to contain a long literal string. ACCEPT will store the string linearly into the array or array range. If the array is not filled, the remainder of the array or range will be set to zero. If the literal is too long the remaining characters will be ignored. Example ACCEPT ARRAY/RASCII 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' FORMAT STATEMENT MODIFICATION When the name field of an ACCEPT contains a label, FORDDT expects this label to be a FORMAT statement label and that the value field contains a new FORMAT specification. Example ACCEPT 10 (lHO,FlO.2,3(I2)) The new specification cannot be longer than the space originally allocated to the FORMAT by the compiler. The remainder of the area is cleared if the new specification is shorter. Note that FOROTS performs some encoding of FORMAT statements when it processes them for the first time. If any I/O statement referencing the given FORMAT has been executed, the FORTRAN program has to be restarted (re-initializing FOROTS). CONTINUE Allows the program to resume execution after a FORDDT pause. After a CONTINUE is executed, the program either runs to completion or until another pause is encountered. The command format is: CONTINUE n where the n is optional and, if omitted, will be assumed to be one. If a value is provided, it may be a numeric constant or program variable, but it will be treated as an integer. When the value n is specified, the program will continue execution until the nth occurrence of this pause. For example, CONTINUE 20 will continue execution after the 20th occurrence pause. E-IO of the FORDDT DIMENSION Sets the user-defined dimensions of an array for FORDDT access purposes. These dimensions need not agree with those declared to the compiler in the source code. FORDDT will allow you to redimension an array to have a larger scope than that of the source program. If this is done, a warning is given. The command format is: DIMENSION S where S is the name of the array specified. For example: DIMENSION ALPHA(7,5/6,lO) FORDDT will remember the is redefined or removed. dimen~ions of the array until it The command DIMENSION will give a full list of all the for all arrays. user-defined dimensions DIMENSION ALPHA will display the current information for the only. array ALPHA DIMENSION ALPHA/REMOVE will remove any user defined array ALPHA. array information for the Arrays, Array Elements, and Ranges Array elements are specified in the following format: name [dl/d2, ... ] (Sl, ... ) where name [ ... ] ( ... ) the name of the array optional, and contains dimension information. This form is equivalent in effect to the DIMENSION statement. the subscripts desired. of the specific element The entire array is referenced simply by its unsubscripted name. A range of array elements is specified by inputting the first and last array elements of the desired range separated by a dash (-) (A(5)-A(lO)). E-ll FORDDT DOUBLE Defines the dimensions of a double-precision array. The result of this command is the same as for the DIMENSION command except that the array so dimensioned is understood by FORDDT to be an array with two-word entries and, therefore, reserves twice the space. The command format is: DOUBLE arrayname GOTO Allows you to continue your program from a point other than the one at which it last paused. The GOTO allows you to continue at a statement label or code-generating source line number provided that the /DEBUG:LABELS switch has been used or the contents of a symbol previously ASSIGNed during the program execution. Note that the program must be STARTed before this command can be used, and also note that a GOTO is not allowed after the ~C~C REENTER sequence. (See Section E.7.) The command format is: GOTO n GROUP Sets up a string of text for input to a TYPE command. You can store TYPE statements as a list of variables identified by the numbers 1 through 8. This feature eliminates the need to retype the same list of variables each time you wish to examine the same group. Refer to the TYPE command for the proper format of the list. The command format is: GROUP n list where n the group number 1-8 list a string of TYPE statements to be called in future accessing of the current group number. GROUP with no arguments will cause FORDDT current contents of all the groups to type out the GROUP n will type requested. out the contents of the Note that one group may call another. E-12 particular group FORDDT LOCATE Lists the program unit names in which a given symbol is defined. This is useful when the variable you wish to locate is not in the currently open program unit and is defined in more than one program unit. The command format is: LOCATE n where n may be any FORTRAN variable, number, or FORMAT statement number. MODE array, label, line Defines the default formats of typeout from FORDDT. In initial default mode, variables will be typed in floating-point format. If you wish to change the typeout modes, the command format is: MODE list where list contains one or more of the modes in the following table. (Only the first character of each mode need be typed to identify it to FORDDT.) Mode F D C I Meaning FLOATING-POINT DOUBLE-PRECISION COMPLEX INTEGER OCTAL ASCII (left-justified) RAseII (right-justified) o A R A typical command string might be: MODE A,I,OCTAL NEXT Allows you to cause FORDDT to trace source lines, statement labels, and entry point names during execution of your program. This command will only provide trace facilities if the program was compiled with the FORTRAN-20 If this switch was not used, the NEXT /DEBUG switch. command will act as a CONTINUE command. The command format is: NEXT n/sw where n a program variable or and integer sw one of the following switches numeric value /S= statement label /L= source line /E= entry point The default starting value of n is 1, a trace. The default switch is /L. The command NEXT 20/L E-13 single statement FORDDT will trace the execution of the next 20 source numbers or until another pause is encountered. Note that if no argument is specified, the given will be used. For example, last line argument NEXT /E will change the tracing mode to trace only subprogram entries using the numeric argument previously supplied. OPEN Allows you to open a particular program unit of the loaded program so that the variables will be accessible to FORDDT. Any previously opened program unit is closed automatically when a new one is opened. Only global symbols, symbols in the currently open unit, and unique locals are available at anyone time. Note that starting FORDDT automatically opens the MAIN program. The command format is: OPEN name where name is the subprogram name. will reopen the MAIN program. OPEN with no arguments If the PROGRAM statement was used in the FORTRAN program, the name supplied by you will be requested upon entering FORDDT. PAUSE Allows you to place a pause request at a statement number, source line number, or subroutine entry point. Up to ten pauses may be set at anyone time. When a pause is encountered, execution is suspended at that point and control is returned to FORDDT. Also, when a pause is encountered, the symbol table of that subprogram is automatically opened. The command formats include: PAUSE PAUSE PAUSE PAUSE PAUSE PAUSE P P AFTER n P IF condition P TYPING /g P AFTER n TYPING /g P IF condition TYPING /g where P n g the point where the pause is requested, an integer constant or variable or element a group number array PAUSE 100 will set a pause at statement label 100, cause execution to be suspended, and cause FORDDT to be entered on reaching 100 in the program. PAUSE #245 AFTER MAX(5} will cause a pause to occur at source line number 245 after encountering this point the number of times specified by MAX(5}. Note that AFTER may not be abbreviated. E-14 FORDDT PAUSE DELTA IF LIMIT(3,l} .GT.2.5E-3 If the variable LIMIT(3,l} is greater than the value 2.5E-3, the pause request will be granted. The IF may not be abbreviated, but all the usual FORTRAN logical connectives are allowed. PAUSE 505 TYPING /5 will request a pause to be made at the first occurrence of the label 505, and the variables in group 5 will be displayed. The TYPING specification may not be abbreviated. PAUSE LINE#24 AFTER 16 TYPING 3 will place a request at source line number 24 after 16 (octal) times through; however, the contents of group 3 will be displayed every time. When the TYPING option is used with the PAUSE command, control can be transferred to FORDDT at the next typeout by typing any character on the terminal. Note that pause requests remain after a control C REENTER sequence, a START command, or a control C START sequence. REMOVE Removes the format is: previously requested pauses. The command REMOVE P For example, REMOVE #123 will remove a pause at program source line number 123. REMOVE ALPHA will remove a pause at the subroutine entry to ALPHA. REMOVE with no arguments will remove all your pause requests, and, in this case, no abbreviation of REMOVE is allowed. This prevents the unintentional removal of pauses. START Starts your program at the normal FORTRAN entry point. The command format is: main program START STOP Terminates the program, requests FOROTS to close all open files, and causes an exit to the monitor. The usual command format is: STOP STOP/RETURN will allow a return to monitor mode without releasing devices or closing files so that a CONTINUE can be issued. E-15 FORDDT STRACE Displays a subprogram level backtrace of the current state of the program. The command format is: STRACE TYPE Causes one or more FORTRAN defined variables, arrays, or array elements to be displayed on your terminal. The command format is: TYPE list where list may be one or more variable or array references and/or group numbers. These specifications must be separated by commas, and group numbers must be preceded by a slash (/). The command with no arguments will use the last argument list submitted to FORDDT. An array example: element range can also be specified. For TYPE PI(S)-PI(13) will display the values from PI(S) to PI(13) inclusive. If an unsubscripted array name is specified, the entire array will be typed. There are several methods of choosing the form of in conjunction with the MODE command. the typeout 1. If you do not specify a format, floating-point form. 2. You can specify a format via described in this appendix. 3. You can change the format previously designated by the MODE command by including print modifiers in the TYPE or GROUP string. The print modifiers are: the default MODE is command /A,/C,/D,/F,/I,/O,/R The first print modifier specified in a string of variables determines the mode for the entire string unless another mode is placed directly to the right of a particular variable. For example, in TYPE /IK,L/O,M,N/A,/2 the typeout mode is integer until another mode is specified. Therefore, K,M,and/2 L OCTAL N = ASCII wHAT = Integer Displays the information saved format is: WHAT E-16 by FORDDT. The command FORDDT E.7 ENVIRONMENT CONTROL If a program enters an indefinite loop, you can recover by typing a ~C~C REENTER sequence. This action will cause FORDDT to simulate a pause at the point of reentry and allow you to control your run-away program. Most commands can be used once the program has been reentered; however, GOTO, STRACE, TYPE, and ACCEPT cause transfer of control to routines external to FORDDT. No guarantee can be made to ensure that any of these commands following a ~C~C REENTER sequence will not destroy the user profile. The program must be returned to a stable state before any of these four commands can be issued. In order to restore program integrity, you should set a pause at the next label and then CONTINUE to it. If the /DEBUG:TRACE switch was used, a NEXT 1 command can be issued to restore program int8grity. E.8 FORTRAN-20/0PTIMIZE SWITCH You should never attempt to use FORDDT with a program that has been compiled with the /OPTIMIZE switch. The global optimizer causes variables to be kept in ACs. For this reason, attempts to examine or modify variables in optimized programs will not work. Also, since the optimizer moves statements around in your program, attempts to trace program flow will lead to great confusion. E.9 FORDDT MESSAGES FORDDT responds with two levels of messages - fatal error and warning. Fatal error messages indicate that the processing of a given command has been terminated. Warning messages provide helpful information. The format of these messages is: ?FDTXXX text or %FDTXXX text where fatal warning FORDDT mnemonic 3-letter mnemonic for error message explanation of error ? % FDT XXX text Square brackets ([ ]) in this section signify variables output on the terminal. and are not Fatal Errors The fatal errors in the following list are each preceded by ?FDT on the user terminal and on listings. They are listed in alphabetical order. BDF [symbol] IS UNDEFINED OR IS MULTIPLY DEFINED BOI BAD OCTAL OUTPUT An illegal character was detected in an octal input value. E-l7 FORDDT CCN CANNOT CONTINUE Pause has been placed on some form of skip instruction causing FORDDT to loop; should never be encountered in FORTRAN-20 compiled programs. CFO CORE FILE OVERFLOW The storage area for GROUP text has been exhausted. CNU THE COMMAND [name] IS NOT UNIQUE More letters of the command are required to from the other commands. CSH an acceptable FORTRAN-20 DIMENSION TABLE OVERFLOW FORDDT does not have the space to dimensions until some are removed. FCX it CANNOT START HERE The specified entry point is not main program entry point. DTO distinguish record any more array FORMAT CAPACITY EXCEEDED An attempt was made to specify a FORMAT statement requiring more space than was originally allocated by FORTRAN-20. FNI FORMAL NOT INITIALIZED Reference to a FORMAL parameter of some subprogram that never executed. FNR was [array name] IS A FORMAL AND MAY NOT BE RE-DEFINED FORMAL parameters may not be DIMENSIONed. IAF ILLEGAL ARGUMENT FORMAT The parameters to the given command were not specified properly. Refer to the documentation for correct format. IAT ILLEGAL ARGUMENT TYPE = [number] An unrecognized subprogram argument Submit an SPR if this message occurs. ICC type was detected. COMPARE TWO CONSTANTS IS NOT ALLOWED Conditional test involves two constants. IER E (number) Internal FORDDT error - please report via an SPR. IGN INVALID GROUP NUMBER Group numbers must be integral and in the range 1 through S. INV INVALID VALUE A syntax error was detected in the numeric parameter. E-lS FORDDT ITM ILLEGAL TYPE MODIFIER - S The mode S is only valid for ACCEPT statements. LGU [array name] LOWER SUBSCRIPT.GE.UPPER The lower bound of any given dimension must be less than equal to the upper bound. LNF [label] IS NOT A FORMAT STATEMENT MLD [array name] MULTI-LEVEL ARRAY DEFINITION NOT ALLOWED or The same array cannot be dimensioned more than once (via the [dimensions] construct) in a single command. MSN MORE SUBSCRIPTS NEEDED The array is defined to have more specified in the given reference. NAL dimensions than were NOT ALLOWED An attempt has been made to modify something other than data or a FORMAT. NAR NOT AFTER A RE-ENTER The given command is not allowed until program integrity has been restored via a CONTINUE or NEXT command. NDT DDT NOT LOADED NFS CANNOT FIND FORTRAN START ADDRESS FOR [program name] Main program symbols are not loaded. NFV [symbol] IS NOT A FORTRAN VARIABLE Names must be 6-character with a letter. alphanumeric NGF CANNOT GOTO A FORMAT STATEMENT NPH CANNOT INSERT A PAUSE HERE strings beginning An attempt has been made to place a pause at other executable statement or subprogram entry point. NSP an [symbol] NO SUCH PAUSE An attempt has been made to REMOVE a pause set up. NUD than that was never [symbol] NOT A USER DEFINED ARRAY An attempt has been made to remove dimension information for an array that was never defined. PAR PARENTHESES REQUIRED ( .. ) Parentheses are required for the statements and complex constants. E-19 specification of FORMAT FORDDT PRO TOO MANY PAUSE REQUESTS The PAUSE table has been exhausted. 10. SER The maximum limit SUBSCRIPT ERROR The subscript specified is outside the range of its dimensions. STL define an array larger than TOO MANY SUBSCRIPTS The array is defined to have fewer dimensions specified in the given element reference. URC defined [array name] SIZE TOO LARGE An attempt has been made to 256K. TMS is than are UNRECOGNIZED COMMAND Warning Messages Each warning message in this list is preceded by %FTN on your terminal and on listings. They are given here in alphabetical order. ABX [array name] COMPILED ARRAY BOUNDS EXCEEDED FORDDT has detected another symbol defined in the specified range of the array. Note that this will occur in certain EQUIVALENCE cases and can be ignored at that time. CHI CHARACTERS IGNORED: "[text]" The portion of the command string included thought to be extraneous and was ignored. NAR [symbol] IS NOT AN ARRAY NSL NO SYMBOLS LOADED in "text" was FORDDT cannot find the symbol table. NST NOT STARTED The specified command requires that a START be previously issued to ensure that the program is properly initialized. POV PROGRAM OVERLAYED The symbol table is different from the last time FORDDT control. SFA had SUPERSEDES FlO ARRAY The generated dimension is being superseded array. for the given outside the SPO VARIABLE IS SINGLE-PRECISION ONLY XPA ATTEMPT TO EXCEED PROGRAM AREA WITH [symbol name] An attempt has been made to access currently defined program space. E-20 memory APPENDIX F COMPILER MESSAGES FORTRAN-20 responds with two levels of messages fatal error and warning. If a warning message is received, the compilation will continue, but a fatal error will stop the program f+om being compiled. The format of messages is: ?FTNXXX LINE:n text or %FTNXXX LINE:n text where ? % FTN XXX LINE:n text fatal warning FORTRAN mnemonic 3-letter mnemonic for the error message line number where error occurred explanation of error Square brackets ([ ]) in this appendix signify variables and output on the terminal. are not Fatal Errors Each fatal error in the following list is preceded by ?FTN on the user terminal and on listings. They are presented here in alphabetical order. ABD [symbolname] HAS ALREADY BEEN DEFINED [definition] The usage given conflicts with current information about the symbol. For example, a symbol defined in an EQUIVALENCE statement cannot be referenced as a subprogram name. ATL ARRAY [name] TOO LARGE The total amount of memory necessary array is greater than 5l2P. AWN to accommodate ARRAY REFERENCE [name] HAS WRONG NUMBER OF SUBSCRIPTS The array was defined to have more or fewer dimensions the given reference. BOV this than STATEMENT TOO LARGE TO CLASSIFY To determine statement type, some portion of the statement must be examined by the compiler before actual semantic and syntactic analysis begins. During this classification the entire portion of the required statement must fit into the F-l COMPILER MESSAGES internal statement buffer (large enough for a normal 20-line statement). This error message is issued when the portion of a given statement required for classification is too large to fit in the buffer. Once FORTRAN-20 has classified a statement, there is no explicit restriction on its length. CER COMPILER ERROR IN ROUTINE [name] Submit an SPR for any occurrence of this message. CFF CANNOT FIND FILE The file referenced in an INCLUDE statment was not found. CPE CHECKSUM OR PARITY [name] CQL NO CLOSING QUOTE IN LITERAL CSF ILLEGAL STATEMENT FUNCTION REFERENCE IN CALL STATEMENT DDA [symbolname] IS DUPLICATE DUMMY ARGUMENT DFC VARIABLE DIMENSION [name] MUST BE SCALAR, DEFINED AS OR IN COMMON DFD DOUBLE [type] NAME ILLEGAL Duplicate fields specification. DIA ERROR were IN [source/listing/object] encountered in an FILE FORMAL INCLUDE file DO INDEX VARIABLE [name] IS ALREADY ACTIVE In any nest of DO loops, a given index variable may defined for more than one loop. DID CANNOT INITIALIZE A DUMMY PARAMETER IN DATA DLN OPTIONAL DATA VALUE LIST NOT SUPPORTED not The extended FORTRAN statement form that allows data to be defined in type specification statements supported by FORTRAN-20. SPECIFICATION ASSOCIATED values is not DNL IMPLIED DO VARIABLES DPR DUMMY PARAMETER [name] REFERENCED BEFORE DEFINITION DSF ARGUMENT [name] IS SAME AS FUNCTION NAME DTI THE DIMENSIONS OF [arrayname] MUST BE OF THE TYPE INTEGER DVE CANNOT USE DUMMY VARIABLE IN EQUIVALENCE DWL [source/listing/object] DEVICE [[device]] WRITE LOCKED ECT ATTEMPT TO ENTER [symbolname] INTO COMMON TWICE EDN EXPRESSION TOO DEEPLY NESTED TO COMPILE EID ENTRY STATEMENT ILLEGAL INSIDE A DO LOOP ElM ENTRY STATEMENT ILLEGAL IN MAIN PROGRAM F-2 WITHOUT be LIST OF COMPILER MESSAGES ENF LABEL [number] MUST REFER TO AN EXECUTABLE STATEMENT, NOT FORMAT A ETF ENTER FAILURE [filename] EXB EQUIVALENCE EXTENDS COMMON BLOCK [name] BACKWARD FEE FOUND [symbol] WHEN EXPECTING EITHER [symbol] OR A [symbol] General syntax error message. FNE LABEL [number] MUST REFER TO A STATEMENT FWE FOUND [symbol] WHEN EXPECTING [symbol] HDE HARDWARE DEVICE [ [device] ] lAC ILLEGAL ASCII CHARACTER [character] IAL INCORRECT ARGUMENT TYPE FOR LIBRARY FUNCTION [name] IBK ILLEGAL STATEMENT IN BLOCKDATA SUBPROGRAL1 ICL ILLEGAL CHARACTER [character] IN LABEL FIELD IDN DO LOOP AT LINE: ERROR ON FORMAT, NOT AN EXECUTABLE [source/listing/object] DEVICE IN SOURCE [number] IS ILLEGALLY NESTED You are attemping to terminate a DO loop before one or more loops defined after the given one. IDS IMPLICIT DO INDICES MAY NOT BE SUBSCRIPTED IDT ILLEGAL OR MISSPELLED DATA TYPE IDV IMPLIED DO INDEX IS NOT A VARIABLE lED INCONSISTENT EQUIVALENCE DECLARATION terminating The given EQUIVALENCE declaration would cause some name to refer to more than one physical location. IFD INCLUDED FILES MUST RESIDE ON DISK lID NON-INTEGER IMPLIED DO INDEX lIP ILLEGAL IMPLICIT SPECIFICATION PARAMETER lIS INCORRECT INCLUDE SWITCH ILF ILLEGAL STATEMENT AFTER LOGICAL IF symbolic Refer to Section 9.3.2 for restrictions on logical IF object statements. INN INCLUDE STATEMENTS MAY NOT BE NESTED IOD ILLEGAL STATEMENT USED AS OBJECT OF DO ISD ILLEGAL SUBSCRIPT EXPRESSION IN DATA STATEMENT Subscript expressions may be formed only indices and constants combined with +, F-3 with implicit *, or /. DO COMPILER MESSAGES ISN [symbolname] IS NOT [symbol type] The symbol cannot be used in the attempted manner. IUT PROGRAM UNITS MAY NOT BE TERMINATED WITHIN INCLUDED FILES IVP INVALID PPN IXM ILLEGAL MIXED MODE ARITHMETIC Complex and expression. IZM double-precision cannot appear in the same ILLEGAL [datatype] SIZE MODIFIER [number] Refer to Section 6.3. LAD LABEL [number] ALREADY DEFINED AT LINE: [number] LED ILLEGAL LIST DIRECTED [statement type] LFA LABEL ARGUMENTS ILLEGAL IN FUNCTION OR ARRAY REFERENCE LGB LOWER BOUND GREATER THAN UPPER BOUND FOR ARRAY [name] LLS LABEL TOO LARGE OR TOO SMALL Labels cannot be 0 or greater than 5 digits. LNI LIST DIRECTED I/O WITH NO I/O LIST LTL TOO MANY ITEMS IN LIST - REDUCE NUMBER OF ITEMS In rare instances, a combination of long lists in statement can exhaust the syntax stack. a single FORMAL LABEL MCE MORE THAN I COMMON VARIABLE IN EQUIVALENCE GROUP MSP STATEMENT NAME MISSPELLED MWL ATTEMPT TO ARGUMENTS NCF NOT ENOUGH CORE FOR FILE SPECS. NEX NO EXPONENT AFTER D OR E CONSTANT NFS NO FILENAME SPECIFIED DEFINE MULTIPLE RETURN WITHOUT TOTAL K NEEDED= [number] The INCLUDE statement requires a filename. NIO NAMELIST DIRECTED I/O WITH I/O LIST NGS CANNOT GET SEGMENT [name] - ERROR CODE: [number] Refer to the Monitor Calls User's Guide for full description of codes. NIR REPEAT COUNT MUST BE AN UNSIGNED INTEGER NIU NON-INTEGER UNIT IN I/O STATEMENT NLF WRONG NUMBER OF ARGUMENTS FOR LIBRARY FUNCTION [name] F-4 COMPILER MESSAGES NNF NO STATEMENT NUMBER ON FORMAT NRC STATEMENT NOT RECOGNIZED NUO .NOT. NWD INCORRECT USE OF OPW OPEN PARAMETER [name] IS OF WRONG TYPE PD6 FORTRAN WILL NOT RUN ON A PDP-6 PIC THE DO PARAMETERS OF [index name] MUST BE INTEGER CONSTANTS PRF PROTECTION FAILURE [filename] PTL PROGRAM TOO LARGE IS A UNARY OPERATOR * OR? IN [filename] The program takes up more than 5l2P QEF QUOTA EXCEEDED OR DISK FULL [filename] QEX BLOCK TOO LARGE OR QUOTA [source/listing/object] FILE [name] RDE RIB OR DIRECTORY ERROR [filename] RFC [function name] IS A RECURSIVE FUNCTION CALL RIC COMPLEX CONSTANT CANNOT BE USED TO REPRESENT IMAGINARY PART OF A COMPLEX CONSTANT SAD ARRAY [name] - SIGNED DIMENSIONS MAY APPEAR ONLY AS CONSTANT RANGE LIMITS SNL [statement name] STATEMENTS MAY NOT BE LABELED SOR SUBSCRIPT OUT OF RANGE TFL TOO MANY FORMAT LABELS SPECIFIED TOF MORE THAN 2 OUTPUT FILES ARE NOT ALLOWED Only a listing and a relocatable specified as output files. UCE USER CORE EXCEEDED UMP UNMATCHED PARENTHESES USI [symbol type] EXCEEDED binary THE file [symbol name] USED INCORRECTLY The given symbol cannot be used in this way. VNA SUBSCRIPTED VARIABLE IN EQUIVALENCE BUT NOT AN ARRAY VSE EQUIVALENCE SUBSCRIPTS MUST BE INTEGER CONSTANTS VSO VARIABLE DIMENSION ALLOWED IN SUBPROGRAMS ONLY F-5 FOR REAL may OR be COMPILER MESSAGES Warning Messages Each warning message in the following list is preceded by %FTN on the user terminal and on listings. They are presented here in alphabetical order. AGA OPT - OBJECT VARIABLE, OF LIST~ WAS NEVER ASSIGNED ASSIGNED CAl COMPLEX EXPRESSION USED IN ARITHMETIC IF CTR COMPLEX TERMS USED IN A RELATIONAL OTHER THAN EQ OR NE The result of the other relational operands is undefined. CUO GOTO WITHOUT operators OPTIONAL with complex CONSTANT UNDERFLOW OR OVERFLOW This message is issued when overflow or underflow is detected as the result of building constants or evaluating constant expessions at compile time. DIM POSSIBLE DO INDEX MODIFIED INSIDE LOOP A program that does this may be incorrectly compiled by the optimizer, since it assumes that indices are never modified. Note that the number of iterations is calculated at the beginning of the loop and is never affected by modification of the index within the loop. DIS OPT - PROGRAM IS DISCONNECTED - OPTIMIZATION DISCONTINUED Submit an SPR if this message occurs. DXB DATA STATEMENT EXCEEDS BOUNDS OF ARRAY [name] FMR MULTIPLE RETURNS DEFINED IN A FUNCTION FNA A FUNCTION WITHOUT AN ARGUMENT LIST ICC ILLEGAL CHARACTER, CONTINUATION FIELD OF INITIAL LINE Continuation lines cannot follow comment lines. ICD INACCESSIBLE CODE. STATEMENT DELETED The optimizer will delete statements that cannot be during execution. ICS ILLEGAL CHARACTER IN LINE SEQ# IDN OPT - ILLEGAL DO NESTING - reached OPTIMIZATION DISCONTINUED A GO TO within a DO loop goes to the ending statement of an inner, nested DO loop. The line number printed out with the warning message is that of the OUTER DO. DO GO TO F-6 COMPILER MESSAGES DO CONTINUE CONTINUE IFL OPT - INFINITE LOOP. OPTIMIZATION DISCONTINUED LID IDENTIFIER [name] MORE THAN SIX CHARACTERS The remaining characters are ignored. MVC NUMBER OF VARIABLES DOES NOT EQUAL THE NUMBERS OF IN DATA STATEMENT CONSTANTS NED NO END STATEMENT IN PROGRAM NOD GLOBAL OPTIMIZATION NOT SUPPORTED WITH /DEBUG - /OPT IGNORED NOF NO OUTPUT FILES GIVEN PPS PROGRAM STATEMENT PARAMETERS IGNORED For compatibility purposes. RDI ATTEMPT TO REDECLARE IMPLICIT TYPE SOD [name] STATEMENT OUT OF ORDER VAl [name] ALREADY INITIALIZED VND FUNCTION RETURN VALUE IS NEVER DEFINED VNI OPT - VARIABLE [name] IS NOT INITIALIZED The optimizer analysis determined that the given variable was never initialized prior to its use in a calculation. WOP OPT - WARNING GIVEN IN PHASE 1. CORRECT OPTIMIZED CODE MAY NOT BE One or more of the messages issued prior to this message resulted from situations that violate assumptions made by the optimizer and thus may cause it to generate code that does not execute as desired. XCR EXTRANEOUS CARRIAGE RETURN Carriage return was not immediately preceded or followed a line termination character. ZMT by SIZE MODIFIER [number] TREATED AS [data type] Message is issued when one of the data type size is used that is accepted only for compatibility. F-7 modifiers COMPILER MESSAGES Internal Compiler errors An internal compiler error is either an attempt by the compiler or the monitor to document an error inside the FORTRAN compiler. An occurrence of an internal compiler error signifies that something is wrong with the FORTRAN-20 compiler. Monitor-detected internal errors are of the form [message] AT LOCATION [address] IN PHASE [segment] WHILE PROCESSING STATEMENT [line-number] where [message] can be one of ILLEGAL MEMORY REFERENCE STACK EXHAUSTED MEMORY PROTECTION VIOLATION Compiler-detected errors are of the form ? INTERNAL COMPILER ERROR PROCESSING STATEMENT NUMBER [line-number] ? CALL TO [routine-name] FROM [address] Submit an SPR if you received an internal compiler error. F-8 APPENDIX G FOROTS ERROR MESSAGES Errors detected categories: at run-time by FOROTS fall into the following 1. system errors (SYS) - errors internal to FOROTS 2. open errors (OPN) and CLOSE I/O errors that occur 3. arithmetic fault calculations errors 4. library errors routines 5. data errors (DAT) - errors in data conversion on I/O 6. device errors (LIB) - errors during (APR) - errors generated by file OPEN in numeric FORLIB library (DEV) - I/O hardware errors APR and LIB errors are usually reported as warnings and the program continues. The number of APR and LIB errors listed on the user's terminal can be changed by the FORTRAN Library Subroutine ERRSET. See Table 15-3 for details. The I/O errors (SYS, OPN, DAT, and DEV) either cause messages to be printed on the terminal or can be trapped by an error exit argument (ERR=statement label) on OPEN, READ, WRITE, and CLOSE. Table G-l gives the text of the messages which can be printed for SYS, OPN, DAT, and DEV errors. The included footnotes give additional information. Table G-2 gives the text of the messages which can be printed for APR and LIB errors. The FORTRAN Library Subroutine ERRSNS allows you to find out which I/O error occurred. When called, ERRSNS returns one or two integer values that describe the status of the last I/O operation performed by FOROTS. (The second integer value is optional.) CALL ERRSNS (I,J) calls this subroutine. J is the second, optional integer value. G-1 FOROTS ERROR MESSAGES Table G-l FOROTS I/O Error Messages and ERRSNS Returned Values First Value o Second Value o 101 1 243 246 23 312 24 308 25 302 26 311 28 252 254 262 268 29 250 30 237 238 240 242 245 248 249 251 253 Explanation No error detected Satisfactory completion (no error detected) Normal end of job (1) Invalid error call Unidentified entry in FORERR (3) Unidentified entry in FORERR (3) Backspace error BACKSPACE illegal for device (9) End-of-file during READ Attempt to READ beyond valid input (8) Invalid record number LSCW illegal in binary record or reading ASCII; or attempt to read unwritten ASCII RANDOM ACCESS record or unwritten or destroyed record number Direct access not specified Cannot RANDOM ACCESS a SEQUENIAL file CLOSE error DTA directory is full (2) or protection error Rename file already exists (2) No room or quota exceeded (2) Cannot delete or rename a non-empty directory (2) No such file File was not found OPEN failure DUMP mode RANDOM or APPEND access not implemented; try IMAGE MODE DIALOG file cannot be opened (3) Record length missing for RANDOM ACCESS Too many devices open: fifteen maximum Device not available (2) Illegal ACCESS for device (2) Illegal MODE or MODE switch (2) No directory for project, programmer number (2) File was being modified (2) 1. Not currently implemented. 2. OPEN errors 251 through 276 map directly onto error returned by the OPEN UUO; see the Monitor Calls Manual. numbers 3. Error cannot currently occur. 8. Occurs when simulating mag tape output; SKIP RECORD and SKIP FILE are illegal. Also occurs when a non-existent file is opened in MODE= SEQINOUT and the first operation on that file is a READ. 9. Occurs if OPEN output with BACKSPACE is not a mag tape or disk. G-2 FOROTS ERROR MESSAGES Table G-l (Cont.) FOROTS I/O Error Messages and ERRSNS Returned Values First Value Second Value 255 256 259 265 266 267 269 270 271 272 274 277 31 315 32 239 39 310 42 244 260 45 241 47 263 59 313 62 301 306 314 63 305 Explanation Illegal sequence of Monitor Calls (11) Bad UFD or bad RIB (2) Device not available (2) Partial allocation only (2) Block not free on allocation (2) Cannot supersede an existing directory (2) SFD not found (2) Search list empty (2) SFD nested too deeply (2) No CREATE flag for specified UFD (2) File cannot be updated (2) LOOKUP ENTER or RENAME error (2) Mixed access modes Cannot do SEQUENTIAL ACCESS on a RANDOM file Invalid logical unit number Illegal FORTRAN unit number (2) Error during READ REREAD before first READ is illegal (1) Device handler not resident No such device (2) No such device (2) OPEN statement keyword error Switch error during DIALOG or OPEN statement scan (2) write on read-only file Write-lock error (2) List-directed I/O syntax error Illegal delimiter in LIST DIRECTED input Syntax error in FORMAT Illegal character in FORMAT statement (4) I/O list without data conversion in FORMAT Missing width field for A or R on input Output conversion error Optional * fill: unidentified entry in FORERR (7) 1. Not currently implemented. 2. OPEN errors 251 through 276 map directly onto error returned by the OPEN UUO; see the Monitor Calls Manual. numbers 4. In runtime FORMAT. 7. * fill controlled by compile-time variable ASTFIL. 11. Can occur on OPEN (MODE= 'APPEND') when file is found in LIB: or on [1,4] when device specified was SYS: and /NEW was in your search list. G-3 FOROTS ERROR MESSAGES Table G-l (Cont.) FOROTS I/O Error Messages and ERRSNS Returned Values First Value Second Value 64 303 307 67 304 81 102 261 699 247 257 258 264 273 275 276 799 309 899 400 401 402 403 404 407 999 100 103 104 105 106 Explanation Input conversion error Checksum error reading binary records (5) Illegal character in data Record too small for I/O list I/O list greater than record size (6) Invalid argument Argument block not in correct format Argument block not in correct format (2) Unclassifiable error on OPEN FOROTS system error (2,3) FOROTS system error (2) FOROTS system error (2) Not enough monitor table space (2) FOROTS system error (2) FOROTS system error (2) FOROTS system error (2) Unclassifiable data error Variable cannot be found in NAMELIST block Unclassifiable device errors write protected Device error Parity error Block too large, quota exceeded, or file structure full. Nonexistent CDR reader. Spooled CDR file does not exist. End-of-file (10) End-of-tape Unclassified system error FOROTS system error Monitor not build to support FOROTS Fatal error User program has requested more code than is available Run time memory management error 2. OPEN errors 251 through 276 map directly onto error returned by the OPEN UUO; see the Monitor Calls Manual. 3. Error cannot currently occur. 5. Checksumming controlled by compile-time variable CHKSUM. 6. Occurs when a type 2 LSCW is found in a FORSE binary record. 10. Trappable if there is no END= clause. G-4 numbers FOROTS ERROR MESSAGES Table G-2 FOROTS Arithmetic and Library Error Messages APR LIB Integer Overflow Attempt to take DLOG of Negative Arg. Integer Divide Check Attempt to take DSQRT of Negative Arg. Illegal APR Trap ACOS of Arg. > 1.0 in Magnitude Floating Divide Check ASIN of Arg. > 1.0 in Magnitude Floating Underflow Attempt to take SQRT of Negative Arg. Attempt to take LOG of Negative Arg. G-5 APPENDIX H DECSYSTEM-lO COMPATIBILITY The following items are included in the DECsystem-20 FORTRAN software for compatibility with the DECsystem-lO. They are not supported on the DECsystem-20. Users must not specify these items because their actions are undefined and the results cannot be guaranteed. 1. Logical Device Assignments. (Refer to pages 10-4 and E-27.) Device Logical unit number Use PTR PTP DIS DTAI DTA2 DTA3 DTA4 DTA5 DTA6 DTA7 06 07 08 09 Paper Tape Reader Paper Tape Punch Display DEC tape 10 11 12 13 14 15 DEC tape 2. PUNCH Statement 3. KAlO and KIlO compiler switches 4. The following Library Subroutines: SLITE(i) SLITET(i,j) SSWTCH(i,j) 5. DDT command to FORDDT. H-l INDEX A format descriptor, 13-12 ABS, 15-4 ACCEPT statement, 10-18 ACCEPT transfer, formatted, 10-18 into FORMAT statement, 10-19 ACCESS in file control statement, 12-3 Accumulator usage, C-10 Accuracy of double-precision numbers, C-1 ACOS function, 15-10 Addition, 4-1 Adjustable dimensions, 6-2 AlMAG, 15-4 AINT, 15-4 ALL with DEBUG, B-3 Allocation, register, C-7 ALOG function, 15-9 ALOG10 function, 15-9 Alphanumeric data transfer, 13-12 Alphanumeric FORMAT field descriptor, 13-11 AMAX,0, 15-5 AMAX1, 15-5 AMIN,0, 15-5 AMIN1, 15-5 AMOD, 15-5 .AND., 4-5 ANSI standard, 1-1 APPEND with ACCESS, 12-4 Argument, subprogram, 15-1 Argument type, COBOL/FORTRAN, C-12 Arithmetic, mixed-mode, 4-2 Arithmetic assignment statement, 8-1 Arithmetic expression, 4-1 Arithmetic IF statement, 9-3 Arithmetic operator, 4-1 Array, 3-7 dimensioning, 3-9, C-4 Array elements, storage of, 3-10 Array subscript, 3-8 ASCII with MODE, 12-4 ASCIZ string, C-14 ASIN function, 15-10 ASSIGN statement, 8-4 Assigned GOTO statement, 9-2 Assignment statement, arithmetic, 8-1 label, 8-4 logical, 8-4 mixed-mode, 8-1 ASSOCIATE VARIABLE in file control statement, 12-8 ATAN function, 15-10 ATAN2 function, 15-10 AXIS subroutine, 15-17 BACKFILE statement, 14-3 BACKSPACE statement, 14-2 BASIC, input from, 2-6 Basic external function subprogram, 15-7 BINARY with MODE, 12-4 Blank line, 2-6 BLOCK DATA statement, 16-1 BLOCK SIZE in file control statement, 12-8 Block data subprogram, 16-1 BOUNDS with DEBUG, B-3 BUFFER COUNT in file control statement, 12-8 CABS, 15-4 Call, FUNCTION, 15-14 subroutine, 15-11 CALL statement, 15-11 Carriage control character, 13-16 Category, statement, 1-1 CCOS function, 15-9 CEXP function, 15-9 Character code, A-1 Character set, 2-1 Character set with MODE, 12-4 Characters, line formatting, 2-2 line termination, 2-2 CLOG function, 15-9 CLOSE statement, 12-1 CLOSE statement summary, 12-10 CMPLX, 15-4 COBOL, interaction with, C-18 Index-1 INDEX (CONT . ) COBOL/FORTRAN argument type, C-12 Command, COMPILE, B-4 DEBUG, B-4 EXECUTE, B-4 LOAD, B-4 Comment line, 2-5 Common block name, 6-5 COMMON statement, 6-5 Compatibility with FORTRAN-10, H-l COMPIL in FOROTS, D-2 Compilation control statement, 5-1 COMPILE command, B-4 Compiler commands, B-4 Compiler generated variable, B-6 Compiler switches, B-1 Compiler version, B-8 Complex constant, 3-3 Complex format, 13-4 COMPLEX statement, 6-3 Computation, redundant, C-5 reordering, C-3 Computation in DO-loop, constant, C-6 Computed GO TO statement, 9-2 CONJG function, 15-10 Constant, 3-1 complex, 3-3 double-precision, 3-3 integer, 3-2 label, 3-6 literal, 3-5 logical, 3-5 octal, 3-4 real, 3-2 Constant computation in DO-loop, C-6 Constant folding, C-7 Constant propagation, C-7 Continuation field, line, 2-3 Continuation line, 2-4 Continue (G) option after PAUSE, 9-11 CONTINUE statement, 9-10 Control statement, 9-1 compilation, 5-1 Control-Z, 2-1 COS function, 15-9 COSD function, 15-9 COSH function, 15-10 CROSSREF switch, B-2 CSIN function, 15-9 CSQRT function, 15-9 D (double-precision notation) , 3-3 D format descriptor, 13-4 DABS, 15-4 .DAT extension, 12-5 Data files, FOROTS, D-4 DATA statement, 7-1 Data transfer operations, 10-1 Data type, 3-1 DATAN function, 15-10 DATAN2 function, 15-10 DATE subroutine, 15-17 DBLE, 15-4 DCOS function, 15-9 DEBUG command, B-4 Debug line, 2-6 DEBUG switch, B-2, B-3 Debugger, FORDDT, E-l Debugger code size, B-4 DECODE statement, 10-21 DEFAULT, B-15 DEFINE FILE subroutine, 15-17 DELETE with DISPOSE, 12-5DENSITY in file control statement, 12-9 Descriptor, G format, 13-7 Device control statement, 14-1 Device control statement summary, 14-3 DEVICE in file control statement, 12-2 Device number, logical, 10-3 DEXP function, 15-9 DFLOAT, 15-4 DIALOG in file control statement, 12-9 DIM, 15-5 DIMENSION statement, 6-1 Dimensioning, array in COMMON, 6-7 Dimensioning array, 3-9, C-4 Dimensions, adjustable, 6-2 DIMENSIONS with DEBUG, B-3 Directory, sub-file, 12-6 user file, 12-6 DIRECTORY, in file control statement, 12-6 DISPOSE in file control statement, 12-5 Index-2 INDEX (CONT . ) Division, 4-1 DLOG function, 15-9 DLOGIO function, 15-9 DMAXl, 15-5 DMINl, 15-5 DMOD, 15-5 DO statement, 9-5 DO-loop, constant computation in, C-6 execution, 9-6 extended range, 9-S floating-point, C-2 implied in I/O list, 10-5 nested, 9-6 parameters, 9-6 permitted transfers, 9-9 range, 9-5 DO-loop iteration, C-2 DO-loop replacement, C-S DOUBLE PRECISION statement, 6-3 Double-precision constant, 3-3 Double-precision format, 13-4 Double-precision numbers, accuracy of, C-l range of, C-l DSIGN, 15-5 DSIN function, 15-9 DSQRT function, 15-9 Dummy argument, subprogram, 15-1 DUMP subroutine, IS-IS DUMP with MODE, 12-4 E (exponential notation), 3-2 E format descriptor, 13-4 EDIT program, 2-6 ENCODE statement, 10-21 END argument in I/O statement, 10-10 END FILE statement, 14-2 END statement, 5-2, 15-6 ENTER in FOROTS, C-lS ENTRY statement, 15-15 .EQ., 4-7 EQUIVALENCE statement, 6-7 .EQV., 4-5 ERR argument in I/O statement, 10-10 ERR in file control statement, 12-10 Error, fatal, B-17 Error processing, FOROTS, 0-3 Error reporting, B-17 ERRSET subroutine, 15-19 ERRSNS subroutine, 15-19 Evaluation of expression, 4-9 EVEN with PARITY, 12-9 Executable statement, 1-1 EXECUTE command, B-4 Execution on non-DEC machines, C-l Exit (X) option after PAUSE, 9-11 EXIT subroutine, 15-19 EXP function, 15-9 EXPAND switch, B-2 Exponential notation, 3-2 Exponentiation, 4-1 permitted, 4-4 Expression, arithmetic, 4-1 evaluation of, 4-9 logical, 4-4 mixed-mode, 4-10, 4-11 nested, 4-9 relational, 4-7 External function subprogram, 15-6 basic, 15-7 EXTERNAL statement, 6-S F format descriptor, 13-4 . FALSE., 3-5 Fatal error, B-17 Field, label, 2-3 line continuation, 2-3 remarks, 2-4 statement, 2-3 Field descriptor, alphanumeric FORMAT, 13-11 FORMAT, 13-2 logical FORMAT, 13-10 numeric FORMAT, 13-4 File, directory subfile, 12-6 FOROTS data, 0-4 non-FORTRAN, C-9 File control statement, 12-1 File directory, user, 12-6 FILE in file control statement, 12-5 FILE SIZE in file control statement, 12-S FIND statement, 10-21 FLOAT, 15-4 Floating-point DO-loop, C-2 Folding, constant, C-7 Index-3 INDEX (CaNT.) FORDDT debugger, E-l FORDDT messages, E-17 FORMAT field descriptor, alphanumeric, 13-11 logical, 13-10 numeric, 13-4 record formatting, 13-15 FORMAT statement, 13-1 ACCEPT transfer into, 10-19 transfer into, 10-3 FORMAT statement descriptor, 13-2 Formatted ACCEPT transfer, 10-18 Formatted READ transfer, random access, 10-13 sequential, 10-11 Formatted WRITE transfer, random access, 10-17 sequential, 10-16 FOROTS, using, D-13 FOROTS data files, D-4 FOROTS error processing, D-3 FOROTS features, D-2 FOROTS hardware requirements, D-l FOROTS input/output facility, D-3 FOROTS messages, G-l FOROTS software requirements, D-l FOROTS/LINK interface, D-28 FORTRAN compiler, B-1 FORTRAN messages, F-l FUNCTION call, 15-14 Function references, order, C-8 FUNCTION statement, 15-6 Function subprogram, basic external, 15-7 external, 15-6 intrinsic, 15-3 statement, 15-3 Function subprogram structure, 15-7 FUNCTION type, 15-6 G (option after PAUSE), 9-11 G format descriptor, 13-4, 13-7 .GE., 4-7 General (G) numeric format, 13-7 GETOVL in LINK, C-20 Global optimization, C-4 GOTO statement, 9-1 assigned, 9-2 computed, 9-2 unconditional, 9-1 • GT., 4-7 H (literal notation), 3-5 H format descriptor, 13-12 Hardware requirements, FOROTS, D-l Hierarchy of operators, 4-9 Hollerith literal, 3-5 I format descriptor, 13-4 I/O list, 10-5 lABS, 15-4 IDIM, 15-5 IDINT, 15-4 IF statement, 9-3 arithmetic, 9-3 logical, 9-4 IF IX , 15-4 ILL subroutine, 15-19 IMAGE with MODE, 12-4 IMPLICIT statement, 6-5 In I/O list DO-loop, implied, 10-6 Inaccessible code, C-7 INCLUDE statement, 5-1 INCLUDE switch, B-2 INDEX with DEBUG, B-3 INIOVL in LINK, C-20 Initial line, 2-4 Input, line-sequence, 2-6 Input from BASIC, 2-6 Input from EDIT, 2-6 Input/output facility, FOROTS, D-3 Input/output list, 10-2 NAMELIST, 10-10 Input/output optimization, C-8 Input/output, format, 10-2 list-directed, 10-8 statement, 10-1 summary, 10-24 INT, 15-4 Integer constant, 3-2 Integer format, 13-4 Index-4 INDEX (CONT.) Logical FORMAT field descriptor, 13-10 Logical IF statement, 9-4 Logical operator, 4-5 LOGICAL statement, 6-3 Logical unit number, 10-3 LOGOVL in LINK, C-20 . LT., 4-7 INTEGER statement, 6-3 Intrinsic function subprogram, 15-3 ISIGN, 15-5 Iteration, DO-loop, C-2 Keyword, 1-1 L format descriptor, 13-10 Label assignment statement, 8-4 Label constant, 3-6 Label field, 2-3 LABELS with DEBUG, B-3 • LE., 4-7 LEGAL subroutine, 15-19 Line, blank, 2-6 comment, 2-5 continuation, 2-4 debug, 2 -6 definition, 2-2 fields, 2-2 initial, 2-4 multi-statement, 2-5 Line continuation field, 2-3 Line formatting characters, 2-2 Line sequence number, B-5 LINE subroutine, 15-19 Line termination characters, 2-2 Line types, 2-4 Line-sequence input, 2-6 LINK overlay facility, C-20 LINK/FOROTS interface, D-28 List, input/output, 10-2 NAMELIST input/output, 10-10 LIST with DISPOSE, 12-5 List-directed input/output statement, 10-8 List-directed transfer, sequential READ, 10-12 sequential WRITE, 10-17 Listing, program, B-5 Literal constant, 3-5 Literal format conversion, 13-13 LNMAP switch, B-2 LOAD command, B-4 Location in object program, B-5 Logical assignment statement, 8-4 Logical constant, 3-5 Logical expression, 4-4 ° MACRO in listing, B-5 MACRO libraries, C-14 MACROCODE switch, B-2 MAX 0 , 15-5 MAXI, 15-5 Messages, FORDDT, E-17 FOROTS, H-l FORTRAN, F-l realtime, G-7 MINO, 15-5 MINI, 15-5 Mixed-mode arithmetic, 4-2 Mixed-mode assignment statement, 8-1 Mixed-mode expression, 4-10, 4-11 MKTBL subroutine, 15-20 MOD, 15-5 MODE in file control statement, 12-4 Multi-statement line, 2-5 Multiple record transfer, 13-14 Multiplication, 4-1 Name, symbolic, 3-6 NAMELIST input/output list, 10-10 NAMELIST statement, 11-1 NAMELIST-controlled transfer, input, 11-2 output, 11-3 sequential READ, 10-13 sequential WRITE, 10-17 . NE., 4-7 Nested DO-loop, 9-6 Nested expression, 4-9 NOERRS switch, B-2 NONE with DEBUG, B-3 Nonexecutable statement, 1-1 Non-FORTRAN files, C-9 Non-FORTRAN programs, C-9 NONSHAR, B-18 Index-5 INDEX (CONT . ) .NOT., 4-5 NOWARNINGS switch, B-2 NUMBER subroutine, 15-20 Numeric, field width variable, 13-10 Numeric format, general (G), 13-7 Numeric FORMAT field descriptor, 13-4 o format descriptor, 13-4 Object program, location in, B-5 Octal constant, 3-4 ODD with PARITY, 12-9 OPEN statement, 12-1 OPEN statement summary, 12-10 Operator, arithmetic, 4-1 hierarchy, 4-9 logical, 4-5 Operator strength, C-5 Optimization, global, C-4 program, C-9 OPTIMIZE switch, B-2 .OR., 4-5 Order of statements, 2-7 OTS, B-18 Overflow, C-3 Overlay facility, LINK, C-20 PARAMETER statement, 6-9 PARITY in file control statement, 12-9 PATH with DIRECTORY, 12-7 PAUSE statement, 9-11 PDUMP subroutine, 15-20 PLOT subroutine, 15-20 PLOTS subroutine, 15-20 Precision for real constant, 3-2 PRINT statement, 10-19 PRINT with DISPOSE, 12-5 Program listing, B-5 PROGRAM statement, 5-1 Programs, non-FORTRAN, C-9 optimizing, C-9 writing, C-1 Propagation, constant, C-7 PROTECTION in file control statement, 12-6 R format descriptor, 13-12 RAN function, 15-10 RANDIN with ACCESS, 12-3 Random access data transfer, 10-1 Random access record specification, 10-7 Random access transfer, formatted READ, 10-13 formatted WRITE, 10-17 unformatted READ, 10-13 unformatted WRITE, 10-17 RANDOM with ACCESS, 12-3 Range of double-precision numbers, C-1 READ statement, 10-11 READ statement summary, 10-14 READ transfer, random access, 10-13 sequential, 10-11, 10-12, 10-13. REAL function, 15-4 Real constant, 3-2 Real format, 13-4 REAL statement, 6-3 Record formatting (T and X), 13-15 RECORD SIZE in file control statement, 12-8 Record specification, random access, 10-7 Reentrant program, B-18 Register allocation, C-7 Relational expression, 4-7 RELEAS subroutine, 15-21 Remarks field, 2-4 REMOVL in LINK, C-20 RENAME with DISPOSE, 12-5 Repeat for format descriptor, 13-3 Replacement, DO-loop, C-8 REREAD statement, 10-14 RESET in FOROTS, C-10 RETURN statement, 15-7, 15-12 REWIND statement, 14-1 RUNOVL in LINK, C-20 SAVE with DISPOSE, 12-5 SAVRAN subroutine, 15-21 Scale factor in FORMAT statement, 13-7 SCALE subrouti·ne, 15-21 SEG, B-18 SEQ IN with ACCESS, 12-3 SEQINOUT with ACCESS, 12-3 SEQOUT with ACCESS, 12-3 Index-6 INDEX (CONT.) '-" Sequence number, line, B-5 Sequential data transfer, 10-1 Sequential transfer, READ, 10-11, 10-12, 10-13 WRITE, 10-16, 10-17 SET RECORD statement, 14~3 SETABL subroutine, 15-21 SETRAN subroutine, 15-21 SFD, 12-6 Sharable program, B-18 .SHR extension, B-18 SIGN function, 15-5 SIN function, 15-9 SIND function, 15-9 SINH function, 15-10 SKIP FILE statement, 14-3 SNGL, 15-4 Software requirements, FOROTS, D-1 SORT subroutine, 15-21 Specification statement, 6-1 SQRT function, 15-9 SSAVE switch, B-18 Statement, ACCEPT, 10-18 Arithmetic assignment, 8-1 arithmetic IF, 9-3 ASSIGN, 8-4 assigned GOTO, 9-2 BACKFILE, 14-3 BACKSPACE, 14-2 BLOCK DATA, 16-1 CALL, 15-11 CLOSE, 12-1 COMMON, 6-5 COMPLEX, 6-3 computed GOTO, 9-2 CONTINUE, 9-10 control, 9-1 DATA, 7-1 DECODE, 10-21 device control, 14-1 DIMENSION, 6-1 DO, 9-5 DOUBLE PRECISION, 6-3 ENCODE, 10-21 END, 5-2, 15-6 END FILE, 14-2 ENTRY, 15-15 EQUIVALENCE, 6-7 executable, 1-1 EXTERNAL, 6-8 file control, 12-1 FIND, 10-21 FORMAT, 13-1 FUNCTION, 15-6 GOTO, 9-1 Statement (Cont.), IF, 9-3 IMPLICIT, 6-5 INCLUDE, 5-1 input/output, 10-1 INTEGER, 6-3 label assignment, 8-4 list-directed, input/output, 10-8 LOGICAL, 6-3 logical assignment, 8-4 logical IF, 9-4 mixed-mode assignment, 8-1 NAMELIST, 11-1 nonexecutable, 1-1 OPEN, 12-1 PARAMETER, 6-9 PAUSE, 9-11 PRINT, 10-19 PROGRAM, 5-1 READ, 10-11 REAL, 6-3 REREAD, 10-14 RETURN, 15-6, 15-12 REWIND, 14-1 SET RECORD, 14-3 SKIP FILE, 14-3 STOP, 9-10 SUBROUTINE, 15-8 TYPE, 10-20 type specification, 6-3 unconditional GOTO, 9-1 UNLOAD, 14-2 WRITE, 10-16 Statement category, 1-1 Statement field, 2-3 Statement function subprogram, 15-3 Statement label constant, 3-6 Statement numbers, 2-3 Statement summary, CLOSE, 12-10 device control, 14-3 input/output, 10-24 OPEN, 12-10 READ, 10-14 WRITE, 10-18 Statements, order of, 2-7 STOP statement, 9-10 Storage of array elements, 3-10 Sub-file directory, 12-6 Subprogram, basic external function, 15-7 block data, 16-1 external function, 15-6 intrinsic function, 15-3 multiple entries to, 15-15 multiple returns from, 15-12 Index-7 INDEX (CONT.) Subprogram, (Cont.) statement function, 15-3 subroutine, 15-8 Subprogram argument, 15-1 Subprogram dummy argument, 15-1 Subprograms, 15-1 Subroutine, DATE, 15-17 ERRSET, 15-19 ERRSNS, 15-19 EXIT, 15-19 FORTRAN supplied, 15-12 ILL, 15-19 LEGAL, 15-19 LINE, 15-19 programming consideration, C-2 Subroutine call, 15-11 SUBROUTINE statement, 15-8 Subroutine structure, 15-11 Subroutine subprogram, 15-8 Subscript, array, 3-8 Subtraction, 4-1 Switches, compiler, B-1 SYMBOL subroutine, 15-22 Symbolic name, 3-6 SYNTAX switch, B-2 T (trace after PAUSE), 9-12 T format descriptor, 13-15 TANH function, 15-10 TIME subroutine, 15-22 Trace (T) option after PAUSE, 9-12 TRACE function, 9-13 TRACE subroutine, 9-13 TRACE with DEBUG, B-3 Transfer operations, 10-1 .TRUE., 3-5 Type, FUNCTION, 15-6 Type specification statement, 6-3 TYPE statement, 10-20 UFD, 12-6 Unconditional GOTO statement, 9-1 Uninitia1ized variable, C-8 UNIT in file control statement, 12-2 unit number, logical, 10-3 Unformatted transfer, random access, READ, 10-13 WRITE, 10-17 sequential binary, READ, 10-12 WRITE, 10-16 UNLOAD statement, 14-2 User file directory, 12-6 Variable, 3-7 compiler generated, B-6 uninitia1ized, C-8 VERSION in file control statement, 12-8 Warning message, B-17 WHERE subroutine, 15-22 WRITE statement, 10-16 WRITE statement summary, 10-18 WRITE transfer, random access, 10-16, 10-17 sequential, 10-16, 10-17 Writing programs, C-1 X (option after PAUSE), 9-11 X format descriptor, 13-15 . XOR., 4-5 tz, 2-1 Index-8 DECsystem-20 FORTRAN Reference Manual AA-4l58B-TM READER'S COMMENTS NOTE: This form is for document comments only. DIGITAL will use comments submitted on this form at the company's discretion. Problems with software should be reported on a Software Performance Report (SPR) form. If you require a written reply and are eligible to receive one under SPR service, submit your comments on an SPR form. Did you find errors in this manual? ~ c I::: If so, specify by page. Did you find this manual understandable, usable, and well-organized? Please make suggestions for improvement. I.~ 1-£ Ig> I~ 1° la 1(1) I~ Q) 10: Is there sufficient documentation on associated system programs required for use of the software described in this manual? If not, what material is missing and where should it be placed? Please indicate the type of user/reader that you most nearly represent. o Assembly language programmer o Higher-level language programmer o Occasional programmer (experienced) o User with little programming experience o Student programmer o Non-programmer interested in computer concepts and capabilities Name Date __________________________ Organization ________~-----------------------------------------------------Street ____________, __________________________________________________________ City ____________________________ State ______________ Zip Code _______________ or Country -------------------------------------------------------------Fold flcrc------------------------------------------------------------ ------------------------------------------------ Do Not Tear - Fold Here and Staple ----------------------------------------------- FIRST CLASS PERMIT NO. 33 MAYNARD, MASS. BUSINESS REPLY MAIL NO POSTAGE STAMP NECESSARY IF MAILED IN THE UNITED STATES Postage will be paid by: _.j • Software Documentation 146 Main Street ML5-5/E39 Maynard, Massachusetts 01754
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies