Digital PDFs
Documents
Guest
Register
Log In
AA-N383B-TK
May 1985
546 pages
Original
18MB
view
download
Document:
FORTRAN Language Manual Feb87
Order Number:
AA-N383B-TK
Revision:
000
Pages:
546
Original Filename:
AA-N383B-TK_FORTRAN_Language_Manual_Ver_10_May85.pdf
OCR Text
TOPS-10/TOPS-20 FORTRAN Language Manual AA-N383B-TK May 1985 This document describes the language elements of FORTRAN-10 and FORTRAN-20. This manual supersedes the TOPS-10120 FORTRAN Language Manual, order number AA-N383A-TK. OPERATING 8YSTEIVI: SOFTWARE: TOPS-10 V7.02 TOPS-20 V4.1, V5.1 FORTHAN-10 V10 FORTF~AN-20 V10 Software and manuals should be orderecl by title and order numbEr. In the United States. send orders to the nearest distribution center Outside the United States. order~; should be directed to the nearest DIGITAL Field Sales Office or representative NortheasttMid-Atiantic Region Central Region Digital Equipment Corporation PO Box CS2008 Nashua. New Hampshire 03061 Telephone:(603)884-6660 Digital Equipment Corporation DlgHal Equipment Corporation Accessories and Supplies Center Accessories and Supplies Center 1050 East Remington Road 632 Caribbean Drive Schaumburg. Illinois 60195 Sunnyvale. California 94086 Telephone (312)64Q--5612 Telephone.(408)734-4915 Western Region digital equipment corporation. marlboro. massachusetts First Printing, February 1983 Revised, May 1985 © Digital Equipment Corporation 1983, 1985. All Rights Reserved. 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 only be used or copied in accordance with the terms of such license. No responsibility is assumed for the use or reliability of software on equipment that is not supplied by DIGITAL or its affiliated companies. The following are trademarks of Digital Equipment Corporation: ~DmDDmDTM DEC DECmate DECsystem-10 DECSYSTEM-20 DECUS DECwriter DIBOL MASSBUS PDP P/OS Professional Q-BUS Rainbow RSTS RSX RT UNIBUS VAX VMS VT Work Processor 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. CONTENTS CHAPTER 1 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 CHAPTER 2 2.1 2.2 2.2.1 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.4 CHAPTER 3 3.1 3.2 3.3 3.4 3.4.1 3.5 3.6 3.7 3.8 3.9 3.10 CHAPTER 4 4.1 4.2 4.3 4.3.1 4.3.2 4.3.3 4.4 CHAPTER 5 INTRODUCTION OVERVIEW • • • • • • • • • • • • • • ••••• ORGANIZATION • • • • • • • • • • • • • • • FORTRAN Language Elements (Part I) •• FORTRAN Statements (Part II) ••••••• FORTRAN Language Usage (Part III) •••• APPENDIXES • • • • • • • • • • • • • • • • • • • M~NUAL 1-1 1-1 1-2 1-2 1-3 1-4 CHARACTERS AND LINES CHARACTER SET • • • • • • • • • • • • • • • STATEMENT DEFINITION AND FORMAT • • • • • • • • • Statement Label Field and Statement Numbers •• Line Continuation Field •••• • • Statement Field • • • • • Remark Field • • • • . • •••••••••• LINE TYPES • • • • • • • • • • • • • • • • • Initial and Continuation Lines • • •••• Multi-Statement Lines •• Comment Lines and Remarks ••••• • • Debug Lines •••.•••• • Blank Lines • • • • • • • • • • • • ••• • LINE-SEQUENCED SOURCE FILES • • 2-1 2-2 2-3 2-3 2-4 2-4 2-4 2-4 2-5 2-5 2-6 2-7 2-7 CONSTANTS INTRODUCTION • • • • • • INTEGER CONSTANTS • • • • • • • • • • • REAL CONSTANTS • • • • • • • • • • • • • DOUBLE-PRECISION CONSTANTS • • • • • • • • • • • • Comparison of Real, D-floating, and G-floating • COMPLEX CONSTANTS • • • • • • • CHARACTER CONSTANTS • • • • • • • • • • • • • • • OCTAL AND DOUBLE-OCTAL CONSTANTS ••••••• LOGICAL CONSTANTS • • • HOLLERITH CONSTANTS • • • • • • • s'rATEMENT LABEL CONSTANTS • • • • • • • 3-1 3-1 3-2 3-2 3-3 3-4 3-4 3-5 3-6 3-6 3-7 SYMBOLIC NAMES, VARLr\BLES, AND ARRAYS SYMBOLIC NAMES • · VARIABLES ARRAYS • • • • •••• · Array Element Subscripts • • Dimensioning Arrays Order of Stored Array Elements • CHARACTER SUBSTRINGS • • • • • • . . . . . . . 4-1 • • • 4-2 . . . . • • • • • . . . 4-3 • 4- 3 • 4-4 • 4-5 • • 4-6 EXPRESSIONS ARITHMETIC EXPRESSIONS 5.1 Rules for Writing Arithmetic Expressions. 5.1.1 Arithmetic Constant Expressions 5.1.2 Integer Constant Expression 5.1.2.1 CHARACTER EXPRESSIONS • • • • • . 5.2 iii 5-1 • 5-2 • 5-5 • • • 5-5 • • 5-6 5.2.1 5.3 5.3.1 5.4 5.5 5.5.1 5.5.2 5.5.3 5.5.4 5.6 CHAPTER 6 6.1 6.2 6.3 6.4 6.4.1 6.4.2 CHAPTER 7 7.1 7.1.1 7.1.2 7.2 7.2.1 7.2.2 7.3 7.4 7.4.1 7.4.2 7.5 7.5.1 7.6 7.7 7.8 7.9 7.10 CHAPTER 8 8.1 8.2 8.3 8.4 CHAPTER 9 Character Constant Expression LOGICAL EXPRESSIONS . • . • • Logical Constant Expression RELATIONAL EXPRESSIONS . . • . EVALUATION OF EXPRESSIONS Parenthetical Subexpressions . Hierarchy of Operators • • • . • • • • Mixed-Mode Expressions • . • •••• Use of Logical Operands in Mixed-Mode Expressions • • •. CONSTANT EXPRESSIONS . • • . • . • . • • • • 5-7 • 5-7 5-10 5-11 5-13 5-13 5-14 5-15 5-15 5-15 EXECUTABLE AND NONEXECUTABLE STATEMENTS 6-1 EXECUTABLE STATEMENTS .•.••••••••. NONEXECUTABLE STATEMENTS . • • · 6-2 ORDERING OF FORTRAN STATEMENTS • • . • • • · 6-2 COMPILATION CONTROL STATEMENTS • . 6-4 PROGRAM Statement . • • • • • • • .. 6-4 INCLUDE Statement • • • • • • • • • • • • 6- 4 SPECIFICATION AND DATA STATEMENTS DIMENSION STATEMENT . • • . Adjustable Dimensions · Assumed-size Arrays • TYPE SPECIFICATION STATEMENTS Numeric Type Specification Statements Character Type Specification Statements IMPLICIT STATEMENTS • • • • • • . • • COMMON STATEMENT . • . • . . • . • • • • • Dimensioning Arrays in COMMON Statements Character Data in COMMON • • • . • • • EQUIVALENCE STATEMENT • . • • • • • EQUIVALENCE and Extended Addressing EXTERNAL STATEMENT • INTRINSIC STATEMENT PARAMETER STATEMENT DATA STATEMENT • • SAVE STATEMENT • • • • · 7-1 • • • .. 7-3 • • • .' 7 - 4 · 7-4 . • .. 7-5 • .. 7-6 • .. 7-7 • . • • • 7-8 7-10 7-10 7-11 7-17 7-17 7-18 7-20 7-21 7 -24 • . • • •• • • 8-1 8-3 8-3 8-4 • ASSIGNMENT STATEMENTS ARITHMETIC ASSIGNMENT STATEMENT • • • . • . • LOGICAL ASSIGNMENT STATEMENTS . . • • • • • • ASSIGN (STATEMENT LABEL) ASSIGNMENT STATEMENT CHARACTER ASSIGNMENT STATEMENT • . • • • . • • CONTROL STATEMENTS 9.1 GO TO STATEMENTS • Unconditional GO TO Statements . 9.1.1 Computed GO TO Statements 9.1.2 Assigned GO TO Statements 9.1.3 9.2 IF STATEMENTS . . • • • • • • • . Arithmetic IF Statements • • 9.2.1 Logical IF Statements 9.2.2 Logical Two-Branch IF Statements • • 9.2.3 Block IF Statements . . .. 9.2.4 Statement Blocks . . • . • . . • . 9.2.4.1 iv · 9-1 • . 9-2 9-2 · 9-3 • • 9-3 • 9-3 · 9-4 • 9-4 9-5 · 9-8 • Block IF Examples •••• 9.2.4.2 Nested Block IF Constructs • • • • • 9.2.4.3 DO STATEMENT • • • • • • • • • • 9.3 Indexed DO Statement • 9.3.1 Executing an Indexed DO Statement 9.3.1.1 • • DO Iteration Control 9.3.1.2 • • DO WHILE Statement • • 9.3.2 The Range of a DO Statement •••• 9.3.3 Nested DO Statements • • • • • 9.3.4 Extended Range • • . • • • • 9.3.5 Permitted Transfer Operations 9.3.6 END DO STATEMENT • • ••• • • • • • • 9.4 CONTINUE STATEMENT • • • • • 9.5 STOP STATEMENT • • 9.6 PAUSE STATEMENT • • • • 9.7 END STATEMENT • • • • 9.8 CHAPTER 10 • • • 9-8 • • • 9-9 9-10 9-10 9-12 • • 9-12 •• 9-13 9-14 9-14 9-15 9-16 9-17 9-17 9-18 9-19 9-20 DATA TRANSFER STATEMENTS DATA TRANSFER OPERATIONS • 10-5 10.1 DATA ACCESS ••••••••• 10-5 10.2 Sequential Access 10-5 10.2.1 Direct Access 10-6 10.2.2 FORMATTED AND UNFORMATTED DATA TRANSFERS • • 10-6 10.3 Formatted Data Transfers • • 10-6 10.3.1 Internal Files • • • • . • 10-7 10.3.1.1 Unformatted Data Transfers • 10-8 10.3.2 Unformatted Data Transfer to ASCII Devices • • 10-8 10.3.3 DATA TRANSFER STATEMENT FORMS 10-8 10.4 10.4.1 Data Transfer Statement Names • • • • •• 10-9 Data Transfer Control-Information List • • 10-9 10.4.2 Unit References in Data Transfer Statements • 10-10 10.4.3 FORTRAN LO'Jical Unit Identifier • • • • • • 10-11 10.4.3.1 Internal File Identifier • • • • • • • • • • 10-13 10.4.3.2 Record Number References In Data Transfer 10.4.4 Statements • • • • • • • • • • • • • • • • • • 10-13 Format References in Data Transfer Statements 10-13 10.4.5 FORMAT-Statement Formatting • • 10-14 10.4.5.1 List-Directed Formatting • • • • • • • 10.4.5.2 • 10-16 NAME LIST-Statement Formatting •••• 10.4.5.3 • 10-16 Optional End-of-File Transfer of Control 10.4.6 (END=) • • • • • • • • • • • • • • • • • • 10-17 10.4.7 Optional Dat3 Transfer Error Control (ERR=) • 10-18 10.4.8 Optional Error Variable For Error Reporting (IOSTAT=) ••••••••••••• • • 10-19 10.4.9 Data Transfer Statement Input/Output Lists • • 10-20 10.4.9.1 Simple List Elements. • • •• • • 10-21 10.4.9.2 Implied DO Lists. • • • • • • • • • • • 10-22 10.5 READ STATEMENT. . • • • • • • • • • • • 10-24 10.5.1 Formatted READ Transfers. • • • • 10-26 10.5.1.1 Sequential FORMAT-Statement READ. • • 10-26 10.5.1.2 Direct-Access FORMAT-Statement READ • • 10-27 10.5.1.3 Sequential List-Directed READ • • • • • 10-27 10.5.1.4 Sequential NAMELIST-Statement READ. • 10-28 10.5.2 Unformatted READ Transfers. • • • • 10-29 10.5.2.1 Sequential Unformatted READ • 10-29 10.5.2.2 Direct-Access Unformatted READ. • 10-30 10.6 WRITE STATEMENT • • • • • • • • • • • 10-30 10.6.1 Formatted WRITE Transfers 10-31 10.6.1.1 Sequential FORMAT-Statement WRITE • 10-32 10.6.1.2 Direct-Access FORMAT-Statement WRITE 10-33 10.6.1.3 Sequential List-Directed WRITE. • • • 10-34 10.6.1.4 Sequential NAMELIST-Statement WRITE • • 10-35 v • • • • · • • • • •• • • • • • • • • • 10-35 10-36 10-36 10-37 10-38 10-39 10-40 10-40 10-41 10-42 10-43 10-44 10-45 10-45 10-46 10-47 10-48 10-48 10-49 10-50 10-51 FILE-CONTROL STATEMENTS 11.1 OPEN STATEMENT • • • . . • 11.2 Implicit OPEN • • • • . 11.2.1 OPEN on a Connected Unit. • • • • . 11.2.2 OPEN STATEMENT SPECIFIERS 11.3 ACCESS Specifier • • • • • . 11.3.1 ASSOCIATEVARIABLE Specifier 11.3.2 BLANK Specifier ••.••• .•••• 11.3.3 BLOCKSIZE Specifier ••.••• 11.3.4 BUFFERCOUNT Specifier •• 11.3.5 CARRIAGECONTROL Specifier .••••• 11.3.6 DENSITY Specifier • 11.3.7 DEVICE Specifier . • • • • • • 11.3.8 DIALOG Specifier • • . • • • • 11.3.9 DIALOG= Specifier ••••• • •• 11.3.10 DIRECTORY Specifier (TOPS-I0) •• 11.3.11 DIRECTORY Specifier (TOPS-20) •• 11.3.12 DISPOSE Specifier . • • • • • • . • • • • • • 11.3.13 ERR Specifier •.••.•••.••••••• 11.3.14 FILE Specifier • • . • . • • • • • • • 11.3.15 FILESIZE (INITIALIZE) Specifier (TOPS-10 Only) 11.3.16 FORM Specifier • • 11.3.17 IOSTAT Specifier . • • . • • 11.3.18 LIMIT Specifier . • • • • 11.3.19 MODE Specifier • • • 11.3.20 NAME Specifier • • . • • 11.3.21 PADCHAR Specifier •• 11.3.22 PARITY Specifier • • • 11.3.23 PROTECTION Specifier (TOPS-10) ••• 11.3.24 PROTECTION Specifier (TOPS-20) •• 11.3.25 READONLY Specifier • • • • . • 11.3.26 RECL (RECORDSIZE) Specifier • • • • • • • 11.3.27 RECORDTYPE Specifier • • • . • • 11.3.28 STATUS (TYPE) Specifier ••••••• 11.3.29 TAPE FORMAT SPECIFIER • • . . .••• • • • 11.3.30 UNIT Specifier (Required) .••••••••• 11.3.31 VERSION Specifier (TOPS-I0) •• 11.3.32 CLOSE STATEMENT • • • 11.4 Implicit CLOSE. • • • • • • • ••••• 11.4.1 11-1 11-1 11-3 11-4 11-4 11-6 11-8 11-9 11-10 11-10 11-11 11-12 11-13 11-13 11-14 11-14 11-16 11-16 11-17 11-18 11-18 11-19 11-20 11-21 11-21 11-23 11-24 11-24 11-25 11-27 11-28 11-28 11-29 11-30 11-32 11-33 11-34 11-34 11-34 10.6.2 Unformatted WRITE Transfers 10.6.2.1 Sequential Unformatted WRITE • • 10.6.2.2 Direct-Access Unformatted WRITE •••• 10.7 REREAD STATEMENT . • • . • . • . . • • 10.7.1 Sequential FORMAT-Statement REREAD. 10.7.2 Sequential List-Directed REREAD • • • • • 10.8 ACCEPT STATEMENT • • • • • • • . • • • . • • 10.8.1 Sequential FORMAT-Statement ACCEPT. 10.8.2 Sequential List-Directed ACCEPT 10.9 TYPE STATEMENT . . • • . • • • • • • 10.9.1 Sequential FORMAT-Statement TYPE • • 10.9.2 Sequential List-Directed TYPE 10.10 PRINT STATEMENT • • • • . . • • . . 10.10.1 Sequential FORMAT-Statement PRINT 10.10.2 Sequential List-Directed PRINT • . . • 10.11 PUNCH STATEMENT • . • • • • • • • • • 10.11.1 Sequential FORMAT-Statement PUNCH 10.11.2 Sequential List-Directed PUNCH • • • • 10.12 INTERNAL FILES AND ENCODE/DECODE STATEMENTS 10.12.1 Internal READ and WRITE Statements. 10.12.2 ENCODE and DECODE Statements • • • • • • • CHAPTER 11 • • • • • • • • • • • • • FILE-CONTROL AND DEVICE-CONTROL STATEMENTS vi 11.5 11.5.1 CLOSE STATEMENT SPECIFIERS 11-34 DEVICE, DIRECTORY, FILE, NAME, and PROTECTION Specifiers • • • . . • 11-36 11.5.2 DIALOG Specifier. . • • . . • 11-36 11.5.3 DIALOG= Specifier • • • • 11-37 11.5.4 DISPOSE Specifier • 11-37 11.5.5 ERR Specifier . • • • • • • 11-39 11.5.6 IOSTAT Specifier. 11-39 11.5.7 LIMIT Specifier . • • • • 11-39 11.5.8 STATUS Specifier. . • 11-40 11.5.9 UNIT Specifier (Required) . . • • 11-41 11.6 OPEN AND CLOSE STATEMENT EXAMPLES • . • • • • • 11-41 11.7 INQUIRE STATEMENT • 11-42 11.7.1 INQUIRE by File • • •. • • • 11-42 11.7.2 INQUIRE by Lnit 11-43 11.7.3 Inquiry Specifiers. 11-43 11.7.3.1 ACCESS Specifier. 11-43 11.7.3.2 BLANK Specifier • • • 11-44 11.7.3.3 CARRIAGECONTROL Specifier • 11-44 11.7.3.4 DIRECT Specifier. 11-44 11.7.3.5 ERR Specifier ••••• • 11-45 11.7.3.6 EXIST Specifier . • 11-45 11.7.3.7 FORM Specifier. • • . •••• • 11-45 11.7.3.8 FORMATTED Specifier . • • • 11-45 11.7.3.9 IOSTAT Specifier. • 11-46 11.7.3.10 NAME Specifier. • • • . • . • • • • • 11-46 11.7.3.11 NAMED Specifier . • • • • • • 11-47 11.7.3.12 NEXTREC Specifier • • • 11-47 11.7.3.13 NUMBER Specifier. •• • • • • 11-47 11.7.3.14 OPENED Specifier. • • • • • 11-48 11.7.3.15 RECL (RECORDSIZE) Specifier • 11-48 11.7.3.16 RECORDTYPE Specifier. . • • • • 11-48 11.7.3.17 SEQUENTIAL Specifier. • • . • • • • • • 11-49 11.7.3.18 UNFORMATTED Specifier • • • • • 11-49 11.8 DEVICE CONTROL STATEMENTS • • • • • • • 11-52 11.8.1 FIND Statem~nt • • • • . • • • • • 11-53 11.8.2 REWIND Stat~ment • • • 11-54 11.8.3 UNLOAD Stat~ment • • • . • •• • 11-54 11.8.4 BACKSPACE Statement 11-55 11.8.5 ENDFILE Stat.ement • • • • • • 11-55 11.8.6 SKIPRECORD Statement. • 11-56 11.8.7 SKIPFILE Statement. 11-57 11.8.8 BACKFILE Statement. . • • 11-57 CHAPTER 12 12.1 12.1.1 12.1.2 12.1.3 12.1.4 12.1.5 12.2 12.2.1 12.2.2 12.2.3 12.3 12.3.1 12.3.2 FORMATTED DATA TRANSFERS FORMAT-STATEMENT FORMATTING • • • • • • . • •. 12-2 Specifying a Format List in a FORMAT Statement 12-2 Specifying a Format Specification as a Character E)pression • . • • • • • • • • • • • 12-3 Specifying a Format Specification in a Numeric Array • . • • • • • • • • • • • • • • • 12-4 Specifying a FORMAT Statement Using an ASSIGNed Variable • . • • • • • • • •. • • • • 12-4 The Ordering and Interpretation of Format List Items • . • • • • • • 12-5 EDIT DESCRIPTORS • . • • • • • • • • 12-6 Repeatable Edit Descriptors • • • • 12-7 NonrepeatabJe Edit Descriptors. 12-8 Carriage-Control Specifiers 12-9 INTERACTION or INPUT/OUTPUT LIST AND FORMAT LIST 12-11 General Description . • • • • • •• • 12-11 Formatted Input . • • • • • • • • • • • • 12-14 vii. Formatted Output • • • • • • • • • • 12.3.3 • • Embedded Format Specifications • 12.3.4 FORMAT EDITING • • • • • • • • • 12.4 • Apostrophe (') Editing. 12.4.1 • H Editing .••••.• 12.4.2 • positional Editing • • • 12.4.3 • ••••• T, TL, and TR Editing 12.4.3.1 • X Editing .•••••. 12.4.3.2 $ (Dollar Sign) Editing 12.4.4 • • • / (Slash) Editing 12.4.5 (Colon) Editing 12.4.6 S, SP,and SS Editing • 12.4.7 P Editing ••••••.••. 12.4.8 • BN and BZ Editing 12.4.9 • • Q Ed it i ng •.••• 12.4.10 • ••••. Numeric Editing 12.4.11 I Editing 12.4.11.1 F Editing 12.4.11.2 • E and D Editing •••• 12.4.11.3 • • • G Editing •••••••• 12.4.11.4 Complex Editing •••• 12.4.11.5 o ( Oc tal) Ed i tin g • • • • · 12.4.11.6 • •••.• Z Editing •••••••• 12.4.11.7 • . • L Editing ..••••. 12.4.12 • • A Editing 12.4.13 R Editing .••. 12.4.14 • LIST-DIRECTED FORMATTING • . • • • • 12.5 NAMELIST-STATEMENT FORMATTING • • • • • •• 12.6 • NAMELIST STATEMENT • • . • 12.7 NAMELIST-Controlled Data Input Transfer • 12.7.1 NAMELIST-Controlled Data Output Transfers 12.7.2 CHAPTER 13 12-15 12-15 12-16 12-16 12-17 12-18 12-19 12-21 12-22 12-23 12-24 12-24 12-25 12-28 12-29 12-29 12-31 12-32 12-32 12-33 12-36 12-36 12-37 12-38 12-39 12-40 12-41 12-44 12-44 12-45 12-46 FUNCTIONS AND SUBROUTINES INTRINSIC FUNCTIONS 13.1 . • •• Using an Intrinsic Function 13.1.1 Character Intrinsic Functions 13.1.2 Character Comparison Functions • • 13.1.3 Bit Manipulation Functions • • • 13.1.4 · STATEMENT FUNCTIONS • • • • • • 13.2 Defining a Statement Function •••• · • 13.2.1 Using a Statement Function • • • • 13.2.2 Statement Function Restrictions 13.2.3 EXTERNAL FUNCTIONS . • • . • • • • • • · 13.3 FORTRAN-Supplied External Functions 13.3.1 User-Defined External Functions · • 13.3.2 Function Subprogram Restrictions • • • • 13.3.3 Using a Function Subprogram · • • 13.3.4 • • SUBROUTINES • • . • • • • • • • 13.4 FORTRAN-Supplied Subroutines. • 13.4.1 · • ALCCHR Subroutine • • • • . • •• 13.4.1.1 CDABS Function . • . • . • 13.4.1.2 CDCOS Subroutine 13.4.1.3 • •••.. CDEXP Subroutine • 13.4.1.4 CDLOG Subroutine 13.4.1.5 CDSIN Subroutine • · 13.4.1.6 CDSQRT Subroutine · 13.4.1.7 CHKDIV Subroutine · 13.4.1.8 CLRFMT Subroutine • • 13.4.1.9 DATE Subroutine • 13.4.1.10 DIVERT Subroutine • 13.4.1.11 DTOGA . . • • • • • 13.4.1.12 DUMP Subroutine •••• · 13.4.1.13 viii 13-1 13-2 13-12 13-14 13-14 13-15 13-16 13-16 13-17 13-18 13-18 13-20 13-21 13-21 13-22 13-24 13-24 13-25 13-25 13-26 13-26 13-27 13-28 13-28 13-29 13-29 13-30 13-30 13-30 13.4.1.14 ERRSET Subroutine •. •• · 13-31 13.4.1.1S ERRSNS Subroutine • • • . • . . • . . 13-32 13.4.1.16 E XITS u b r c· uti n e • 13-33 13.4.1.17 FFUNIT Subroutine . • • • • . . • 13-33 13.4.1.18 GTODA Subroutine • • • 13-34 13.4.1.19 ILL Subroutine • • 13-34 13.4.1.20 LEGAL Subroutine • • · • 13-34 13.4.1.21 MVBITS Subroutine • 13-3S 13.4.1.22 OVERFL Subroutine · 13-3S 13.4.1.23 PDUMP Subroutine • . . • • • 13-36 13.4.1.24 QUIETX Subroutine ..•. · . 13-36 13.4til.2S SAVFMT Subroutine . . . • . • 13-37 13.4.1.26 SAVRAN Subroutine · 13-37 13.4.1.27 SETRAN Subroutine • • • • • 13-38 13.4.1.28 SORT Subrcutine · . 13-38 13.4.1.29 SRTINI Subroutine ..••. • 13-39 13.4.1.30 TIME Subrcutine • • 13-39 13.4.1.31 TOPMEM Subroutine • . • 13-40 13.4.1.32 TRACE Subroutine • • • • • . • • • • . . 13- 41 13.4.2 . • • • 13-42 User-Defined Subroutines • • 13.4.2.1 SUBROUTINE Statement • • • • • • • • . . . • 13-43 13.4.2.2 CALL Statement • • • . . . • • . . . • 13-44 13.4.2.3 Execution of a CALL Statement • • 13-44 13.4.2.4 Actual Arguments for a Subroutine • • 13-4S 13.4.3 ENTRY Statement •••• • . .•. · 13-4S 13.4.4 . • • 13-47 RETURN Statement • . • • . • • • . . 13.4.S Dummy and Actual Arguments • • • • • • • • 13-49 13.4.S.1 Length of Character Dummy and Actual Arguments ••••. • • • • • . • . . · 13-51 13.4.S.2 Character and Hollerith Constants as Actual 13-51 Argumen ts HAPTER 14 14.1 HAPTER IS BLOCK DATA SUBPROGRAMS BLOCK DATA STATEMENT • 14-1 WRITING USER PROGRAMS IS.1 lS.l.l lS.1.2 lS-l GENERAL PROGRAMMING CONSIDERATIONS Accuracy and Range of Double-Precision Numbers lS-1 Writing FORTRAN Programs for Use on Other lS-2 Computers •.•••••.•••••••••. IS-2 lS.1.3 Using Floating-Point DO Loops •••••. lS.1.4 Computation of DO Loop Iterations lS-2 15-3 Subroutines - Programming Considerations lS.l.S 15-4 lS.1.6 Reordering of Computations • • • . ••. 15-5 lS.1.7 Dimensioning of Dummy Arrays • • • • . • • lS.2 . • • . • • . lS-6 FORTRAN GLOBAL OPTIMIZATION 15-6 IS.2.1 Optimization Techniques ••••••••• lS.2.1.1 Elimination of Redundant Computations 15-6 lS-7 lS.2.1.2 Reduction of Operator Strength • • • Removal of Constant Computation from Loops . 15-7 lS.2.1.3 15-8 Constant Folding and Propagation lS.2.1.4 lS.2.1.S Removal of Inaccessible Code • IS-9 lS-9 lS.2.1.6 Global Register Allocation • • . • lS.2.1.7 lS-9 I/O Optimization • . • • • • • . • 15-9 Uninitialized Variable Detection • . • • • . lS.2.1.8 15-9 lS.2.1.9 Test Replacement • • • • • • • Programming Techniques for Effective lS.2.2 Optimization. . • • • • • • • . . • • lS-10 FUNCTION SIDE EFFECTS • • • • • • . • • . lS-10 lS.3 INTERACTING WITH NON-FORTRAN PROGRAMS AND FILES lS-10 lS.4 ix 15.4.1 15.4.2 15.4.3 15.4.4 15.4.5 15.4.6 15.4.7 15.4.7.1 15.4.7.2 15.4.8 15.4.8.1 15.4.8.2 15.4.9 15.4.10 15.4.11 CHAPTER 16 Using The Sharable High-Segment FOROTS • • • • 15-10 Calling Sequences • • • • • 15-11 Accumulator Usage • • 15-11 Ar g urn e n t Lis t s . • 15 -1 2 Argument Types • • • . • • • • • • • • • 15-14 Description of Arguments • • • • • . • • • 15-14 Interaction with COBOL. • • • • • 15-16 Calling FORTRAN Subprograms from COBOL Programs • • • • • • . • • • • • • • • • • • 15-16 Calling COBOL Subroutines from FORTRAN 15-18 Programs . • • • • • • • • • • • • 15-18 Interaction with BLISS-36 • • • • Calling FORTRAN Subprograms From BLISS-36 Programs • • • • • • • • • • • • • • • • 15-18 Calling BLISS-36 Routines From FORTRAN • • • 15-19 LINK Overlay Facilities . • • • • • • • • • • 15-19 FOROTS and Overlay Memory Management • • • • • 15-20 Extended Addressing Memory Layout (TOPS-20 only) • • • • • • • • • • • • • • • • • • • • 15-22 USING THE FORTRAN COMPILER USING THE FORTRAN-I0 COMPILER TOPS-I0 COMPILE-Class Commands • • RUNNING THE FORTRAN-IO COMPILER TOPS-I0 Compiler Command Switches • • • • USING THE FORTRAN-20 COMPILER TOPS-20 COMPILE-Class Commands • • RUNNING THE FORTRAN-20 COMPI LER • • • • • • • TOPS-20 Compiler Commands Switches ••••• THE /DEBUG SWITCH • • . • • • • • • • • • THE /NOWARN SWITCH • • • . • • • • • • • • THE /EXTEND SWITCH (TOPS-20 ONLY) /EXTEND and Applications with Large Arrays • • /EXTEND and Applications with Large Executable Code • • • • • • • • • • • • • • • • • • /EXTEND PSECT Placement •• • • • • • 16.5.2.1 16.5.2.2 Building Large-Code Applications.. •• Arguments to /EXTEND • • • • • • • • • • • • • 16.5.3 Linking With TWOSEG REL Files • 16.5.4 THE /FLAG (/FLAG-NON-STANDARD) SWITCH • 16.6 16.7 READING A FORTRAN COMPILER LISTING • • • • • • • 16.7.1 Compiler-Generated Variables • • • • • 16.8 ERROR REPORTING . • • • • • • • • • • Fatal Errors and Warning Messages •• 16.8.1 Message Summary • • • • • • 16.8.2 CREATING A SHARABLE HIGH SEGMENT FOR A FORTRAN 16.9 PROGRAM • • • • • • • • • • • • • • • ••• 16.1 16.1.1 16.1.2 16.1.3 16.2 16.2.1 16.2.2 16.2.3 16.3 16.4 16.5 16.5.1 16.5.2 CHAPTER 17 17.1 17.1.1 17.1.2 17.1.3 17.2 17.3 17.4 17.5 17.6 17.7 17.8 16-1 16-1 16-2 16-2 16-5 16-5 16-6 16-8 16-11 16-14 16-15 16-16 16-17 16-17 16-18 16-19 16-21 16-21 16-22 16-24 16-33 16-34 16-34 16-35 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) ..····· ···· ···· · INPUT FORMAT Variables and Arrays Constant Conventions Statement Labels and Source Line Numbers FORDDT AND THE FORTRAN /DEBUG SWITCH LOADING AND STARTING FORDDT SCOPE OF NAME AND LABEL REFERENCES FORDDT COMMANDS ENVIRONMENT CONTROL FORTRAN /OPTIMIZE SWITCH CALLING FORDDT . . ···· ·· . . . ····· . . .· · · · · . · . · ·· · · ·· · · · x 17-2 17-2 17-3 17-4 17-4 17-5 17-6 17-7 17-16 17-17 17-17 17.9 CHAPTER 18 18.1 18.2 18.3 18.3.1 FORDDT AND FORTRAN-20 EXTENDED ADDRESSING • 17-17 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) FEATURES OF FOROTS • • • • • • • • • • ERROR PROCESSING • • • • • • • • • INPUT/OUTPUT FACILITIES • • • Input/Output Channels Used By FOROTS • • • •. • • • •• • • • •• (TOPS-10 18-1 18-2 18-2 18-2 On 1 y) • • • • • '. • • • • • • • • • 18.3.2 File Access • • • • • • • • • • • • 18-3 18.3.3 Closing Files After Non-standard Termination. 18-3 18.3.3.1 Sequential Access •••••• • • • • 18-3 18.3.3.2 Direct (Random) Access Mode • • • • • • • • 18-4 18.4 ACCEPTABLE TYPES OF DATA FILES AND THEIR FORMATS 18-4 18-4 18.4.1 ASCII Data Files • • • • • • 18.4.2 FORTRAN Binary Data Files • • • • 18-4 • • • •• 18-4 18.4.2.1 Format of Binary Files. 18.5 USING FOROTS . • • • • • • • 18-14 18.5.1 FOROTS Entry Points • • • • • • • 18-15 • • • 18-16 18.5.2 Calling Sequences • • • • • • • 18.5.3 MACRO Calls for FOROTS Functions. • 18-17 18-18 18.5.3.1 Sequential-Access Calling Sequences 18-19 18.5.3.2 Internal Pile Calling Sequences • • • • 18.5.3.3 NAMELIST I/O, Sequential-Access Calling Sequences • • • • • • • • • • • • • • • 18-20 18-20 Array Offsets and Factoring ••.•• 18.5.3.4 I/O Statenents, Direct-Access Calling 18.5.3.5 Sequences • • • • • • • • • • • . • • • 18-22 Default Devices Statements, Calling 18.5.3.6 Sequences • • • • • • • • • • • • • • • • • 18-23 18.5.3.7 Statements to position Files. • • • • • 18-24 18.5.3.8 List-Directed Input/Output Statements . • • 18-24 18.5.3.9 Input/Output Data Lists ••••••• 18-25 18.5.3.10 OPEN and CLOSE Statements, Calling Sequences 18-28 18.5.3.11 Memory Al:.ocation Routines • • • • • • • • • 18-29 18.5.3.12 Channel A:1ocation and Deallocation Routines 18-30 18.6 FUNCTIONS TO FACILITATE OVERLAYS. • • 18-31 18.7 LOGICAL/PHYSICAL DEVICE ASSIGNMENTS • • • 18-36 18.8 F'OROTS AND INQUIRE BY FILE STATEMENT • • • • • • 18-36 CHAPTER 19 USING THE FORr;"'RAN RE:AL-TIME SOFTWARE (TOPS-I0 ONLY) INTRODUCTION 19.1 19.2 UlSING FORRTF 19.2.1 Memory 19.2.2 Modes Priority-Interrupt Levels 19.2.3 Masks 19.2.4 SUBROUTINES 19.3 19.3.1 LOCK RTINIT 19.3.2 CONECT 19.3.3 RTSTRT 19.3.4 BLKRW 19.3.5 RTREAD 19.3.6 19.3.7 RTWRIT 19.3.8 STATO STATI 19.3.9 RTSLP 19.3.10 RTWAKE 19.3.11 DISMIS 19.3.12 DISCON 19.3.13 ·. .· · · ·· · · ···· ········· ···· ····· ···· · · · · · ·· ·· · · · ····· ·· ·· ·· · ····· ···· ·· ·· ·· ·· ···· · · · ·· · ·· ·· ··· ··· ·· · · · ···· ···· ········· ···· ···· xi 19-1 19-2 19-2 19-2 19-2 19-2 19-3 19-3 19-3 19-4 19-4 19-4 19-5 19-5 19-5 19-6 19-6 19-6 19-6 19-7 19.3.14 19.3.15 19-7 19-7 UNLOCK • • • • • Error Messages • APPENDIX A SUMMARY OF FORTRAN STATEMENTS APPENDIX B ASCII-196S CHARACTER CODE SET APPENDIX C COMPILER MESSAGES APPENDIX D FOROTS ERROR MESSAGES D.1 ALPHABETICAL DESCRIPTION OF FOROTS MESSAGES APPENDIX E INTERACTIVE DEBUGGER (FORDDT) ERROR MESSAGES APPENDIX F FORTRAN-SUPPLIED PLOTTER SUBROUTINES • • • D-9 PLOTS SUBROUTINE • • F-2 F.1 AXIS SUBROUTINE • • • • • F-2 F.2 F.3 CAXIS SUBROUTINE • • • • • • • • • F-3 LINE SUBROUTINE . • • • • . F-4 F.4 MKTBL SUBROUTINE • F-5 F.S Character Tables • • • • • • • • • . F-S F.S.1 Creating a Character Table • • • F-6 F.S.1.1 Creating a Stroke Table • • . F-6 F.S.1.2 Sample Character Stroke Table . F-7 F.S.1.3 FORTRAN- and User-Defined Character Sets • • • F-9 F.S.1.4 F.6 NUMBER SUBROUTINE • • •• • • • • • . F-9 PLOT SUBROUTINE • • • • • • • • • • • • F-10 F.7 F.S SCALE SUBROUTINE • • • • • • • • • • • F-10 SETABL SUBROUTINE • • • • • . • •• F-11 F.9 SYMBOL SUBROUTINE F-12 F.10 WHERE SUBROUTINE • F-12 F.11 INDEX FIGURES 2-1 4-1 6-1 7-1 7-2 7-3 7-4 7-5 9-1 10-1 11-1 11-2 15-1 F-1 F-2 F-3 Fields Within a FORTRAN Line • • A 3 x 3 x 2 Array • • . • • • • • • • • Ordering of FORTRAN Statements. Shared Storage using EQUIVALENCE Statement • Equivalence of Substrings .•••••••••• Equivalence of Character Arrays • • • • • • Valid Equivalencing •••••• Invalid Equivalencing ••••• Examples of Block IF Constructs Components of Data Transfer Statements • . TOPS-10 File Protection Number • • TOPS-20 Protection Number •••• • • • • • Run-time Memory Layout for Section Zero Plotter Character Table Entry •••• Character Stroke Table Entry • • Sample Character Stroke Table .••• xii .. 2-3 .. 4- 4 . 6-3 7-12 7-13 7-14 7-16 7-16 .. 9-7 10-S 11-25 11-27 15-21 .. F-6 • F-6 .. F-S TABLES 2-1 3-1 4-1 5-1 5-2 5-3 5-4 5-5 5-6 5-7 8-1 10-1 10-2 10-3 10-4 10-5 10-6 10-7 10-8 10-9 10-10 10-11 11-1 11-2 11-3 11-4 11-5 11-6 12-1 12-2 12-3 12-4 12-5 12-6 13-1 13-2 15-1 15-2 16-1 16-2 16-3 16-4 16-5 16-6 16-7 16-8 17-1 18-1 18-2 19-1 D-l FORTRAN Character Set •• • • • • • • • • • • . Comparison of Real, D-floating, and G-floating • 2-2 Numbe r 5 • •• • • • • • • • • • • • • • • • • • • 3-4 Use of Symbolic Names • • • • • • • • • • • • . • 4-1 Arithmetic Operations and Operators • • • • • • • 5-2 ~rype of the Rt~sul t Obta ined from Mixed-Mode Operations • • • • • • • • • • • • • • . • . • 5-3 Permitted Base/Exponent Type Combinations . • • • 5-5 Logical Operators • • • • • • • 5-8 Logical Opera:ions Truth Table • • • • 5-9 Relational Operators and Operations 5-11 Hierarchy of PORTRAN Operators • • 5-14 Rules for Conversion in Mixed-Mode Assignments • • 8-2 FORTRAN I/O S':atement Categories. 10-2 Summary of Da~a Transfer Statement Forms • 10-3 FORTRAN Logical Device Assignments • 10-12 Summary of READ Statement Forms • • • • 10-25 Summary of WRITE Statement Forms • . . • • 10-31 Summary of REHEAD Statement Forms • • • • • • • 10-38 Summary of ACCEPT Statement Forms • • 10-40 Summary of TYPE Statement Forms • 10-43 Summary of PRINT Statement Forms . • . 10-45 Summary of PUNCH Statement Forms • • . 10-47 Summary of Internal READ/WRITE and ENCODE/DECODE Statement Forns • • • • • • • • . • . 10-49 Summary of OPEN Statement Specifiers and 11-5 Arguments .•••••••• . • 11-23 DEVICE and MODE Cross-Table 'I'OPS-I0 Protection Code Values · 11-26 'I'OPS-20 Protection Code Val ues •••• · 11-27 Summary of CLOSE Statement Specifiers and Arguments • • • • • • • .• • • • 11-35 Summary of Device-Control Statements • . . . 11-51 Repeatable FORTRAN Edit Descriptors 12-8 12-9 Nonrepeatable FORTRAN Edit Descriptors 12-11 Carriage-Control Specifiers ••••• Eecord, Format List" and I/O List Interaction · 12-13 Default Field Widths for Numeric Edit Descriptors • • . • • • . • • • • . • . . • • 12-30 Effect of Data Magnitude on G-Format Output Conversion • , • • • • • • • • • . • • • 12-35 FORTRAN Instrjnsic Functions . 13-4 FORTRAN-Suppl~,ed Subroutines. • . • • •. • 13-23 Argument Types and Types Codes . . 15-14 ~[emory Allocations for /EXTEND and /NOEXTEND • • 15-23 FORTRAN-I0 Compiler Switches. . • . . 16-3 FORTRAN-20 Compiler Switches. ••••. 16-9 JI,rg umen ts to /DEBUG Swi tch • • •.... 16 -12 Legal Dummy and Actual Argument Associations • . 16-14 Arguments to /NOWARN Switch •••• 16-15 /EXTEND DefauJt Memory Layout . • • • • 16-16 Arguments to /EXTEND Switch •••• . • • 16-20 Arguments to /FLAG Switch • • • • •• . 16-22 FORDDT Commands • • • • • • • . 17-1 FOROTS Entry Points ••• . • . • • 18-15 Function Numbers and Function Codes . • . 18-32 Error Messages - Code Format and Full Message Format . • • • • • • • • 19-8 . • D-2 FOROTS Error Codes • • • • • xiii PREFACE The FORTRAN-IO/20 Language Manual reflects the software as of Version 10 of the FORTRAN-IO/20 compiler, the FORTRAN-IO/20 Object Time System (FOROTS), and the FORTRAN-IO/20 debugging program (FORDDT). This manual describes the FORTRAN language as implemented for the TOPS-IO operating system (FORTRAN-IO) and the TOPS-20 operating system (FORTRAN-20). Any differences between FORTRAN-IO and FORTRAN-20 are noted in this manual. 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. CONVENTIONS The following conventions are used throughout the manual: Braces { indicate that a choice must be made from of the enclosed lines. Brackets [ ] indicate an optional feature. one or. indicate the omission of information from a programming example or that items in a command line can be optionally repeated. Lowercase letters indicate variable information you supply in a command string. UPPERCASE LETTERS indicate fixed (or literal) information that you must enter as shown in a command string. Ellipsis indicates a blank. The standard for FORTRAN is the American National Standards Institute (ANSI) FORTRAN, X3.9-1978 (also known as FORTRAN-77). FORTRAN-IO/20 extensions and additions to ANSI FORTRAN are in blue print in this manual. xv MANUALS REFERENCED The following manuals are referenced from TOPS-IO pUblications: • • • TOPS-IO Operating System Commands Man uaI -SOS Reference Manual TOPS-IO Moni tor Calls - - Manual • TOPS-IO Hardware Reference Manual • TOPS-IO LINK Reference Manual • • TOPS-IO SORT/MERGE User's Guide TOPS-IO FORTRAN Installation Guide The following manuals are referenced from TOPS-20 pUblications: • TOPS-20 Commands Reference Manual • TOPS-20 EDIT Reference Manua I • • • • • TOPS-20 User's Guide TOPS-20 Monitor Calls Manual TOPS-20 Link Reference Manual TOPS-20 SORT/MERGE User's Guide --TOPS-20 FORTRAN Installation Guide --- The following TOPS-IO/TOPS-20 manual are referenced: • FORTRAN-IO/20 and VAX-II FORTRAN Compatibility Manual • TOPS-IO/TOPS-20 FORTRAN Pocket Guide • TOPS-IO/TOPS-20 COBOL-74 Language Manual • TOPS-IO/20 BLISS Language Guide • TOPS-IO/20 Common Math Library Manual xvi CHAPTgR 1 INTRODUCTION 1.1 OVERVIEW The FORTRAN language, as implemented on the TOPS-IO and TOPS-20 operating systems, is compatible with and encompasses the standard described in "AmE~rican National Standard FORTRAN, X3.9-1978" (referred to as the FORTRAN-77 standard) at the full-language level. FORTRAN-10/20 provides many extensions and additions to the FORTRAN-77 standard that 9reatly enhance the usefulness of FORTRAN and increase its compatibility with FORTRAN languages implemented by other computer manufacturers. The extensions and additions to the standard FORTRAN-77 are printed in this manual in blue print. A FORTRAN source program cons~sts of a set of statements constructed using the language elements and the syntax described in this manual. A given FORTRAN statement performs anyone of the following functions: 1. It causes operations such as branching to be carr led out. 2. It specifies the 3. It specifies the characteristics of the source program. tYPE~ multiplication, division, and and format of the data being processed. FORTRAN statements are composE~d of keywords (words that are recognized by the compiler) used with elements of the language set: constants, variables, and expressions. ~here are two basic types of FORTRAN statements: executable and nonexecutable. Executable statements spec~.fy the actions of the program; nonexecutable statements describe the characteristics and arrangement of data, editing information, statement functions, and the kind of subprograms that may be incl.uded 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. 1.2 MANUAL ORGANIZATION This manual is divided into three parts: Language Elements, and Language Usage. Sections 1.2.1 through 1.2.3 contain general descriptions for each of these three parts. Section 1.2.4 contains a general description of the appendixes. Stater~nts, 1-1 INTRODUCTION 1.2.1 FORTRAN Language Elements (Part I) Part I of this manual describes the fundamental programs, including (by chapter): elements of FOHTRAN Chapter 2, CHARACTERS AND LINES, describes FORTRAN source program characters and lines. The FORTRAN compiler interprets your source program and translates it into machine code (executable code) • Chapter 3, CONSTANTS, describes FORTRAN data types and constants. FORTRAN enables you to manipulate information (data) in a variety of ways. This chapter describes the techniques for defining FORTRAN constants of various data types. Chapter 4, SYMBOLIC NAMES, VARIABLES, AND ARRAYS, describes symbolic names, variables, and arrays in FORTRAN. The symbolic name is used in a variety of ways in a source program; this chapter describes the conventions for using symbolic names to define both variables and arrays. introduces and describes FORTRAN Chapter 5, EXPRESSIONS, operators. Expressions in FORTRAN are formed using variables, constants, and operators. 1.2.2 FORTRAN Statements (Part II) Part II of this manual describes all the statements in the FORTRAN language. The following list describes (by chapter) the information presented in Part II: Chapter 6, EXECUTABLE AND NONEXECUTABLE STATEMENTS, defines the term "FORTRAN Statement", and describes the "Compilation Control Statements". Chapter 7, SPECIFICATION AND DATA STATEMENTS, describes all the statements within the category "Specification and Data Statements". The specification statements enable you to explicitly define the data types of variables used within your program; the DATA statement enables you to create initially defined constants within your program. Chapter 8, ASSIGNMENT STATEMENTS, describes all the statements within the category "Assignment Statements". FORTRAN assignment statements enable you to assign values to variables, and to assign statement labels to symbolic names. Chapter 9, CONTROL STATEMENTS, describes all the statements within the category "Control Statements". The default execution sequence of lines in a FORTRAN program is each line from left-to-right, and all lines from top-to-bottom. You use the FORTRAN control statements to alter the default execution sequence, to stop or pause during program execution, or to mark the end of an executable program. Chapter 10, DATA TRANSFER STATEMENTS, describes the data transfer category of "FORTRAN Input/Output (I/O) Statements". As the term implies, a data transfer statement moves data from one place to another. 1-2 INTRODUCTION Chapter 11, FILE-CONTROL AND DEVICE-CONTROL STATEMENTS, describes file-control and devi~e-control categories of "FORTRAN I/O Statements". The file-control statements enable you to associate a unit number with a file. Device-control statements enable you to position a storage medium (for example, magnetic tape) on a connected unit. Chapter 12, FORMATTED DATA TRANSFERS, describes three types of data formatting. During certain types of data transfer operations, you must specify the format of the data being transferred. FORTRAN provides three techniques for specifying the format of data: FORMAT-Statement, List-Directed, and NAMELIST-Statement formatting. Chapter 13, FUNCTIONS AND SUBROUTINES, describes FORTRAN functions and subprograms. Functions and subprograms provide a technique for producing clear and concise FORTRAN programs. FORTRAN-IO/20 provides both predefined functions and subprograms, and the statements for defining your own functions and subprograms. Chapter 14, BLOCK DATA SUBPROGRAMS, describes the block-data subprogram. This type of subprogram enables you to define initial values for variables in COMMON. 1.2.3 FORTRAN Language Usage (Part III) Parts I and II of the manual contain complete descriptions of FORTRAN elements and statements. Part III of the manual contains explanations of how you use FORTRAN-IO/20. The following usage topics are covered in Part III: Chapter 15 , WRITING USER PROGRAMS, presents some general considerations that you should follow when you are creating FORTRAN source programs. In addition, this chapter contains a description of the FORTRAN optimizer. Chapter 16, USING THE FORTRAN COMPILER, describes how to use the FORTRAN compiler and contains descriptions on how to compile, load, and execute a FORTRAN program. In addition, this chapter contains descriptions of how to read a compiler-generated program listing, and how to create a reentrant FORTRAN program. This Chapter also describes how to use FORTRAN-20 extended addressing. Chapter 17, USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT), describes how to use the FORTRAN interactive debugging program (FORDDT) to test and debug a running program. This chapter also contains a brief explanation of how to debug a running FORTRAN program using DDT, the system debugger. Chapter 18, USING THE FORTRAN OBJECT-TIME SYSTEM (FOROTS), describes the FORTRAN Object-Time System (FOROTS). This chapter also contains descriptions of how you can use the FOROTS software. Chapter 19, USING THE FORTRAN lREAL-TIME SOFTWARE (TOPS-IO ONLY), describes how to use the FORTRAN real-time software. This chapter is for TOPS-IO installations only. 1-3 INTRODUCTION 1.2.4 APPENDIXES The appendixes describe various useful topics are covered in the appendixes: The information. following Appendix A, SUMMARY OF FORTRAN STATEMENTS, summarizes the forms of all FORTRAN statements and provides a section reference where each statement is described in detail. Appendix B, ASCII-1968 CHARACTER CODE SET, lists the character code set defined in the X3.4-1968 version of the American National Standard Code for Information Interchange (ASCII). Appendix C, COMPILER MESSAGES, messages. describes the FORTRAN compiler Appendix D, FOROTS ERROR MESSAGES, messages. describes the FOROTS error Appendix E, FORDDT ERROR MESSAGES, messages. describes the FORDDT E!rror describes the Appendix F, FORTRAN-SUPPLIED PLOTTER SUBROUTINES, FORTRAN-supplied plotter subroutines. 1-4 CHAPTER 2 CHARACTERS AND LINES The basic elements of the FORTRAN source program are its characters and lines. Characters are l]sed to form statements, expressions, and comments in FORTRAN source programs. Lines, and fields within lines, are used to define the context in which characters are interpreted by the FORTRAN compiler. program This chapter describes the relationships among source characters, lines, and fields within source program 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 is acceptable within character or Hollerith constants or comment text, but these characters cause fatal errors in other contexts. NOTE The complete ASCII chdracter set is defined in the X3.4-1968 version of the "American National Standard Code for Information Interchange". A summary of the standard ASCII set ia also contained in Appendix B of this manual. NOTE Lowercase alphabetic upper-case outside character constants. characters are the context of 2-1 treated Hollerith as or CHARACTERS AND LINES Table 2-1: FORTRAN Character Set Letters Uppercase: ABC D E F G H I J K L M N 0 P Q R STU V W X Y Z Lowercase: abc d e f 9 h i j kIm n 0 p q r stu v w x y z Digits o 1 234 567 8 9 Symbols ! " # $ & , ( ) * + , Exclamation point Quotation Mark Number Sign Dollar Sign Ampersand Apostrophe Left Parenthesis Right Parenthesis Asterisk Plus - . / : ; < = > ,. Comma Hyphen (Minus) Period (Decimal Point) Slant (Slash) Colon Semicolon Less Than Equal To Greater Than Ci rcumflex Line Termination Characters Line Feed (LF), Form Feed (FF), Vertical Tab (VT) Line Formatting Characters Carriage Return (RET), Horizontal Tab (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 either includes or starts in character position 6. (Refer to Section 2.3.1 for a description of initial and continuation line types.) Tabs within character 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. As shown in Figure 2-1, each source program line is divided into four fields. 2-2 CHARACTERS AND LINES t-ol . . . .- - - · - - - - - - \1 Figure 2-1: 2.2.1 Line Character Positions ---------~·~I 2 !-~---___v--7-0--7-1-7-2-'/~ Statement Continuation Statement Field Remarks Label Field Field Mf1.S-176181 Fields Within a FORTRAN Line Statement Label Field and Statement Numbers You can 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 zel~OS and all blanks in the label field are ignored; for example, the numbers 00105 and 105 are both accepted as statement number 105. You can 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. A main program and a subprogram can 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 follows: Assume that main module MAINMD and subprogram SUBI both contain statement numbE~r 10~). A GO TO 105 statement, for instance, in MAINMD will refer to statement 105 in MAINMD, not to 105 in SUBI. A GO TO 105 in SUBI will transfer control to 105 in SUBI. An initial tab may be used to skip all or part of the label field. If an initial tab is encountered during compilation, FORTRAN-IO/20 examines the character immediately following the tab to determine the type of line being entered. If this character is one of the digits 1 through 9, FORTRAN-IO/20 cons:.ders the line as a continuation line and uses the second character after the tab as the first character of the statement field. If the character following thE! tab is not one of the digits 1 through 9, FORTRAN-10/20 considers the line to be an initial line and the character following the tab i~; considered to be the first character of the statement field. The character following the initial tab is considered to be in character position 6 for a continuation line, and in character position 7 for arl initial line. 2.2.2 Line Continuation Field Any character of the FORTRAN character set (except a blank, a zero, or an exclamation point) placed in the line continuation field (position 6) identifies the line as a continuation line (see Section 2.3.1). Whenever you use an initial 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 I through 9 to identify the line as a continuation line. 2-3 CHARACTERS AND LINES 2.2.3 Statement Field Any FORTRAN statement can appear in the statement field. Blanks (spaces) and tabs do not affect compilation of the statement. Blanks and tabs may be used freely in this field for appearance purposes, with the exception of textual data given within either a character or Hollerith specification, where blanks and tabs are significant characters. 2.2.4 Remark Field In lines consisting of 73 or more character positions, only the first 72 character positions are interpreted by FORTRAN. Note that tabs generally occupy more than one character position, usually advancing the cursor to the next character position that is an even multiple of 8. The pxcept:.ion is the tab in a label field, which advances the "llrSOr either to column 6 or 7, deoendinq on the character following 1-. he' tab (see Section 2.2.1). All other characters after character remarks and do not affect compilation. position 72 are treated as t-t1at remarks may also be added to a line jn character positions 1 L;-:r'onoh 72, provided the text of the remark is preceded by the symbol nTH (see Section 2.3.3). :JOt-p 2.3 LINE TYPES A line in a FORTRAN source program may be: 1. An initial line 2. A continuation line i\ 4. multi-statement line A comment line i\ debuo 1 j ne A blank line 6. These lines are described in Sections 2.3.1 through 2.3.5. 2.3.1 Initial and Continuation Lines A FORTRAN statement may occupy the statement fields of up to 20 consecutive lines. The first line in a multi-line statement is referred to as the initial line; the succeeding lines are referred to as continuation lines. Initial lines may be assigned a statement number and must have either a blank or a zero in character position 6. 'nltl~l , ; S (Co i j · ii ; prni--'rd. tab may be used to skip all or part of the label field. If i nIt i a 1 tab for t his 0 u r po s e , yo u mus t i mm e d i ate 1 y follow :wnrJUmerjc character; that is, the fjrst character of the i leid must be nonnumeric. .H) 2-4 CHARAc'rERS AND LINES You cannot assign a statement label to a continuation line. Instead, you identify a continuation line by placing a character from the FORTRAN character set (except blank, zero, or exclamation point) in character position 6 of that line. This position is the line continuation field. The label field of a continuation line must be blank. Note that blank lines, comments, and debug lines that are treated like comments (that is, debug line; that are not compiled with the rest of the program) are legal continuation lines and do not terminate a continuation sequence (see Section 2.3.4). The following is an example of a 3-line FORTRAN FORMAT statement two continuation lines: 105 with FORMAT (IX, 'This eX.3mple shows how continuation lines I, 2 'are used to accommodate FORTRAN statements that do not' 3 'entirely fit on a single line.') In this example the characters 2 and 3 in position lines as continuation lines. 6 identify those Mul t i-Sta tE~ment Li nes 2.3.2 You may write more than one FO~TRAN statement in the statement field of one line. The rules for structuring a multi-statement line are: 1. Successive statements must be separated by a semicolon (;). 2. Only the first statement in the series can have number. 3. The last statement in a line is continued to the next line if that next line is mad,? a continuation line. a statement An example of a multi-statement line is: 450 DIST=RATE * TIME; TIME=TIME+O.05; CALL PRIME(TIME,DIST) NOTE If a statem?nt sequence in a multi-statement line consists of a logical IF (see Section 9.2.2) followed by any other executable statement, then the statement f~llowing the IF will be executed in all cases, even if the IF expression evallates as false. 2.3.3 Comment Lines and Remarks Lines that contain descriptive text only are called comment lines. Comment lines commonly identify and introduce a source program, describe the purpose of a particular set of statements, and introduce subprograms. 2-5 CHARACTERS AND LINES 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 place the text of the comment in line. 3. You may place comment lines anywhere in the including preceding a continuation line. 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 c), *, $, /, or !) in its first character position. the remainder source The following is an example of a comment that occupies more line: C C c c of the program, than one SUBROUTINE - A12 This subroutine formats and stores the results of the HEAT-TEST program 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 text "Stop if card is blank" is identified as a remark by the preceding symbol. The compiler ignores all characters from the exclamation point to the end of the line. The characters following the exclamation point, however, appear in the source program listing. To be treated as a remark symbol, the exclamation point must not appear in a Hollerith or character constant. Note that characters appearing in character positions 73 and beyond are automatically treated as remarks, so that you need not use the symbol (see 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; that is, not compiled with the rest of the program unless the /INCLUDE switch is present in the compiler command string. (See Chapter 16 for a description of the compiler switches.) When the /INCLUDE switch is present in the compiler 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. A debug line can have a label following the D (or d). Note that if the debug statement is an initial line, all of its continuation lines must contain a D (or d) in character position 1. 2-6 CHARAC~lERS 2.3.5 AND LINES Blank Lines You may insert lines consisting of only blanks, tabs, or no characters anywhere in a FORTRAN source program. Blank lines that contain remarks only, are considered as blank lines. 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.4 LINE-SEQUENCE:D SOURCE FILgS FORTRAN-IO/20 accepts I ine--sequenced fi les as produced by line-oriented text editors (for E~xample, SOS on TOPS-IO or EDIT on TOPS-20). These sequence numb(~rs are used in place of the listing line numbers normally generated by FORTRAN. The listing line numbers are not the same as FORTRAN statement: numbers. 2-7 CHAPTEH 3 CONSTANTS 3.1 INTRODUCTION Constants are quantities that do not change value during the execution of the object program. The data types you can use for constants in FORTRAN-10/20 source programs are: 1. Integer 2. Real 3. Double-precision 4. Complex 5. Character 6. Logical 7. Octal 8. Double-octal 9. Hollerith 10. Statement: label The use and format: of each Sections 3.2 through 3.10. 3.2 of these data types are discussed in INTEGER CONSTANTS An integer constant is a string of 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 always be signed. You cannot use decjmal points, commas, or other symbols in integer constants (except for a preceding sign, + or -). Examples of valid integer constants are: 345 +345 -345 3-1 CONSTANTS Examples of invalid integer constants are: +34S. 3,4S0 34.S 3.3 (use of decimal point) (use of comma) (use of decimal point; not a whole number) REAL CONSTANTS A real constant can have any of the following forms: 1. A basic real constant: a string of decimal digits followed by a decimal point, followed optionally by a decimal fraction, for e~ample, LSS7.42. 2. A basic real constant followed by a decimal integer exponent written in E notation (exponential notation) form, for example, lSS9.E2 or lSS9.e2. The number following the E (or e) specifies a power of ten by which the basic real constant will be multiplied. 3. An integer constant (no decimal point) followed by a decimal integer exponent written in E notation, for example, lSS9E2 or lSSge2. Real constants may be of any size; however, each will fit the precision of 27 bits (7 to 9 decimal digits). be 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 cannot be empty (blank); it must be either a zero or an integer constant. The range of magnitude permitted a real constant is from approximately 1.47 * LO**(-39) to 1.70 * 10**(+38). The following are examples of valid real constants: -98.76S 7.0E+0 .7E-3 SE+S SOlIS. SO.El (= (= (= 7.) .0007) SOOOOO.) (= SOO.) The following are examples of invalid real constants: 72.6ES12 .37SE SOO 3.4 (exponent is too large) (exponent incorrectly written) (no decimal point given) DOUBLE-PRECISION CONSTANTS Double-precision constants are similar to real constants written in notation form; the differences between these two constants are: 1. E Double-precision constants, depending on their magnitude, have precision from 16 to 18 places, rather than the 8-digit precision obtained for real constants. 3-2 CONSTAN~rs constant occupies storage two 2. Each double-precision locations. 3. The letter 0 (or (1), instead of E, is used in double-precision constants to identify a decimal exponent. On KL model B systems, there a~e two forms of double-precision number formats. If the /GFLOATING compiler switch is specified (see Chapter 16), the double-precision numbE?r form.at is called G-floating. If the /OFLOATING compiler switch (the default) is specified (see Chapter 16), the double-precision number format is called O-floating. See Section 3.4.1 for a comparison of the different double-precision number formats. On KS systems, only the O-floating double-precision number provided. format is You must use both the letter 0 and an exponent (including zero) in writing a double-precision constant. The range of magnitude permitted a double-precision constant is from approximately: 1.47 * 10**(-39) to 1.70 * 10**(+38) for O-floating or 2.78 * 10**(--309) to 8.99 * 10**(+307) for G-floating The following are examples of valid double-precision constants: 7.9003 7.90+03 7.90-3 79003 7900 (= (= (= (= (= 7900.) 7900.) .0079) 79000.) 79.) The following are examples of invalid double-precision constants: 7.90999 7.9E5 (exponent is too large) ("E" denotes single precision; "0" denotes double prE~cision) 3.4.1 Comparison of Real, O-floating, and G-floating For KL model B systems, G-floal:ing double-precision is provided as an alternative double-precision number format. You must specify the /GFLOATING compiler switch (see Chapter 16) to invoke the G-floating double-precision format. If you specify the /OFLOATING compiler switch (the default), the O-floating format is used. Table 3-1 summarizes the comparisons among real, O-floating, and G-floating. 3-3 CONSTANTS Table 3-1: Comparison of Real, D-floating, and G-floating Numbers Bits of Exponent Bits of Mantissa Real 8 27 1.47 * 10** (-39) to 1.70 * 10**(+38) 8.1 D-floating 8 62 1.47 * 10** (-39) to 1.70 * 10**(+38) 18.7 G-floating 11 59 2.78 * 10** (-309) to 8.99 * 10**(+307) 17.8 Range Digits of Precision _. 3.5 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) constant of the pair represents the real part of the number; the second constant reprE~sents the imaginary part of the number. Both the real and imaginary parts of a complex constant can be signed. The constants that represent the real and imaginary parts of a complex constant occupy two consecutive storage locations in the object program. 3.6 CHARACTER CONSTANTS A character constant is a string of printable ASCII characters enclosed by apostrophes. Both delimiting apostrophes must be present, and the string must be at least one character in length. The compiler accepts control characters in character constants with the following exceptions: Character Octal Value - NUL - LF - VT FF "0 "12 1113 "14 - CR "IS "'@ "'J "'K "'L - "'M NOTE The CHAR function (see Chapte~ 13) can be used to build variables that contain these control characters. The value of a character constant is the string of characters b(=tween the delimiting apostrophes. The value does not include the delimiting apostrophes, but does include all spaces or tabs within the apostrophes. Within a character constant, the apostrophe character is represented by two consecutive apostrophes (with no space or other character between them). 3-4 CONSTANTS The length of the character constant is the number of characters between the apostrophes, except that two consecutive apostrophes count as a single apostrophe. Each character in the string has a character position that is numbered consecutively starting at one. The number indicates the sequential position of a character in a string, from left to right. There is one character storage location for each character in the string. If a character constant appears in a numeric context (for example, as the expression on the right side of an arithmetic assignment statement), it is considered a Hollerith constant (see Section 3.9). Examples of valid character constants and their lengths are: Length Value 'WHAT? ' 5 WHAT? 'TODAYS"S DATE IS: 18 TODAY'S DATE IS: 'He said, "hello'" 16 He said, "hello" ,,,, 1 Examples of invalid character constants are: 'HEADINGS ,, "Now or Never" 3.7 (no trailing apostrophe) (a character constant must contain one character) at least (quotation marks cannot be used in apostrophes) place of OCTAL AND DOUBLE-OCTAL CONSTANTS You may use octal numbers (radix 8) as constants in arithmetic expressions, logical expressi~ns, and data statements. Octal numbers up to 12 digits in length are considered standard octal constants; they are stored right-justified in one storage location. When necessary, standard octal constants are padded with leading zeros to fill their storage location. If 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-iustified octal digits; leading zeros are adde·j to fill any unused digits. If you assign a single-octal c~nstant to a double-precision or complex variable, it is stored right-justified in the high-order word of the variable. The low-order porti)n of the variable is set to zero. If you assign a double-octal c)nstant to a double-precision or complex variable, it is stored right-jJstified in the two words. All octal constants must: 1. Be preceded by a double quote octal, for example, "777 2. Be signed if negative, but optionally signed if positive 3. Contain one or more of the digits 0 through 7, hut not 8 or 9 3-5 (") to identify the digits as CONSTANTS The following are examples of valid octal constants: "123456700007 +"12345 (optional sign) -"7777 "-7777 The following are examples of invalid octal constants: "12368 7777 (contains an 8) (no identifying double quote) 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 + "202400000000) has as its result the sum of A with the floating point number 2.0; while the subexpression (I + "202400000000) has as its result the sum of I with a large integer. You cannot use octal constants 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 (or assign it to) either an integer or real variable, only the contents of the high order location (leftmost) are used. 3.8 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. You may use logical quantities in arithmetic and logical statements. Only the sign of a numeric value used in a logical IF statement is tested to determine if it is true (negative) or false (nonnegative). 3.9 HOLLERITH CONSTANTS A Hollerith constant is a string of alphanumeric and/or special characters preceded by nH (for example, nHstring). In the prefix nH, the letter n represents a number that specifies the exact number of characters (including blanks) that follow the letter H. \JOTE If a character constant appears it is considered a in a numeric context Hollerith constant (see Section 3.6) • The following are examples of Hollerith constants: 2HAB 14HLOAD TEST #124 6H#124-A 3-6 CONSTANTS NO'I'E A tab in a Holleritt constant .A.B. character; for examplE, 3H is counted as one You may enter Hollerith constents into DATA statements as a string of: 1. ASCI I Up to ten 7-bit characters double-precision tYPE variables 2. Up to five variables 7 -·b it ASCI I characters for for all complex or other type The 7-bit ASCII characters that comprise a Hollerith constant are stored left-justified (st2rting in the first word of a double-precision constant (thE high-order word) or the real part of a complex constant) with blarks placed in empty character positions. Holler i th constan ts tha t occur·y more than one var iable are stored as successive variables in the list. The following example illustrates how the string of characters is stored in a six-element array calle~ A: DIMENSION A(6) DATA A/27HA string of mary characters/ A (1) A(2) A(3} A(4) A (5) A(6) 3.10 is is is is is is set set set set set set to to to to to to 'A str' 'ing 0' 'f man' 'y chat 'racte' 'rs STATEMENT LABEL CONSTANTS Statement labels are statement numbers. numerjc identifiers that represent program You write statement label constants as strings of one to five decimal digits, that are preceded by either an asterisk (*), a dollar sign ($), or an ampersand (&). Foz' example, *11992, $11992, and &11992 are all valid statement label constants. You use statement label constants only in the argument. list of CALL statements to identify the number of the executable statement to return to in a multiple RETURN statement (see Chapter 13). 3-7 CHAPTF~R 4 SYMBOLIC NAMES,. VARIABLES, AND ARRAYS 4.1 SYMBOLIC NAMES Symbolic names consist of any alphanumeric combination of one to six characters, the first of which must be a letter. 1 i you use more than six characters in a symbolic name, the compiler prints a warning message and ignores all bu: the first six characters. The compiler interprets lowercase letters in symbolic names as uppercase letters. The following arE! examples of legal symbolic names: A12345 IAMBIC ABLE C The following arE! examples of illegal symbolic names: .AMBIC SAB ( fir s t c h a r act E~ r i s not ale t t e r ) (first charactE~r is not a letter) You use symbolic names to identify specific items of a FORTRAN source program; Table 4-1 lists these items, together with an example of a symbolic name and text reference for each. Table 4-1: Use Clf Symbolic Names Symbolic Names Can Identi fy 1. 2. 3. 4. 5. 6. 7. S. 9. 10. Variables Arrays Array elements Substrings Functions Subroutines Intrinsic functions PROGRAM Statement PARAMETER Statement COMMON block names 11. NAMELIST list For 8xample Pl r CONS1~ , LIMIT TAX TAX(3,5) FOO(l:N) MYFUNC, VALFUN CALCSB, SUB2, LOOKUP SIN, ATAN, COSH TEST VI, C2,K DA~r1AR, COMDAT DA':'A3 4-1. For a Deta iled Description See Section 4.2 4.3 4.3.1 4.4 13.2 13.4 13.1 6.4.1 7.S 7.4 ' ~ -, .".: .... ,. ;: 1 SYMBOLIC NAMES, VARIABLES, AND ARRAYS 4.2 VARIABLES A variable is a data storage location identified by a symbolic name; a variable is not a constant, an array, or an array element. Variables specify values that are assigned to them in such ways as assignment statements (Chapter 8), DATA statements (Chapter 7), or at run time through I/O data transfers (Chapter 10). Before you assign a value to a variable, its value is undefined; and you should not reference it except to assign a value to it. The value you assign to a variable can 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 IAB=5+IB, however, the value assigned lAB depends on the value of variable IB at the time the statement is executed. The type of a variable determines the interpretation of its Variables can be: 1. Integer 2. Real 3. Logical 4. Double-precision 5. Complex 6. Character contents. The type of a variable is determined either implicitly, by the first letter of the variable name (described below), or explicitly, by declaring the variable type in a type declaration statement (see Chapter 7). FORTRAN uses the following default types are not explicitly declared: conventions for variables whose 1. Variable names that begin with the letters I, J, K, L, M, N are integer variables. 2. Variable names that begin with any letter other than I, J, K, L, M, or N are real variables. or NOTE These default conventions can be altered use of the IMPLICIT statement, which described in Section 7.3. The following are examples of determining according to the preceding conventions: the type of by is a variable Variable Beginning Letter Assumed Data Type ITEMP OTEMP KAl23 AABLE I 0 Integer Real Integer Real K A 4-2 SYMBOLIC NAMES, VARIA.BLES, AND ARRAYS 4.3 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 for writing symbolic names (see Section 4.1). Arrays are made up of smaller units of data called array elements. As with variables, you may assign a value to an array element. Before you assign a value to an array element it has an undefined value. You should not reference an alray element until you have assigned it a value. An array element is referenced by using the array name together with some number of subscripts that describe the position of the element within the array. 4.3.1 Array Element Subscripts The general form of an array element name is AN (Sl, S2, ••• Sn), where AN is the array name and Sl ttrough Sn represent 1 through n subscript expressions. You may use any number of subscript quantities in an element name; however, the number used must always equal the number of dimensions (see Section 4.3.2) specified for the array. A subscript can be any constant or expression example: (see Chapter S), for 1. Subscript quantities may contain arithmetic expressions that involve addition, sobtraction, multiplication, division, and exponentiation. For example, (A+B,C*S,D/2) and (A**3,(B/4+C)*E,3) ale valid subscripts. 2. l\rithmetic expressic.ns (see Chapter 5) used in array subscripts may be of any type, but noninteger expressions (including complex) are converted to integer when the subscript is evaluatE!d. 3. A subscript may contain function references (see Chapter 13). 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 expression given is a nested 3-level array reference. Some examples of valid array elements are: 1. IAB(1,S,3) 2. ABLE (A) 3. TABLEl(lO/C+K**2,A,B) 4• ~AT ( A , AH (2 * L) , • 3 * TAB A, M + 1,0) , 55 ) i 4-3 SYMBOLIC NAMES, VARIABLES, AND ARRAYS 4.3.2 Dimensioning Arrays You must declare the size (number of elements) of an array to enable FORTRAN to reserve the number of locations needed 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, Figure 4-1 represents a 3-row, 3-column, 2-plane array. 3 ROWS .~ 'l'-~ ~'v -------~-------/ 3 COLUMNS Figure 4-1: MH S 11~~·81 A 3 x 3 x 2 Array You specify the size of an array by an array declarator written as a subscripted array name. In an array declarator each subscript quantity is a dimension of the array and must be either an integer expression, an integer variable, or an asterisk (*). Only the upper bound in the last dimension declarator in a list of dimension declarators can be an asterisk. An asterisk marks the declarators as an assumed-size array declarator (see Section 7.1.2). NOTE allowed in Variable array dimensions are only subprograms. See adjustable dimension statements, Section 7.1.1. For example, declarators. TABLE(I,J,K) and MATRIX(lO,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 IAB(2,3,4) has 24 elements (2 * 3 * 4 24) • You dimension arrays only in the specification statements DIMENSION, COMMON, and type declaration (see Chapter 7). Subscripted array names appearing in any of the these statements are array declarators; subscripted array names appearing in any other statements are always array element identifiers. 4-4 SYMBOLIC NAMES, VARIABLES, AND ARRAYS In array declarators, the position of a given subscript quantity determines the particular c:imension of the array (for example, row, column, or plane) that it represents. The first three subscript positions specify the number of rows, columns, and planes that comprise the named array; each following subscript given then specifies a set comprised of n-number (value of the subscript) of the previously defined sets. For example: SpE~cifies thE! Array(s) The Dimension Declarator TAB(2) ~~ ~~ TAB(2,2) TAB(2,2,2) ,.""".",*,' --' ," 1,1,1 1,1,2 1,2,2 2,1,2 2,2,2 1,2,1 2,1,1 TAB(2,2,2,2 ) ....... ........ 2,2,1 -- -1,1,1,1 1,2,1,1 2,1,1,1 2,2,1,1 .... "'''' "'''' .... ",- ....- '" - 1,1,2,1 I j .,.., '" -_ --.... 1,2,2,1 2,1,2,1 2,2,2,1 -'" - .~ '" .... " -'- -, 1,1,2,2 1,2,2,2 I 2,1,2,2 2,2,2,2 _-- 1,1,1,2 1,2,1,2 2,1,1,2 2,2,1,2 .,.., --- MH·S 1762-81 NOTE FORTRAN-IO/20 permits up to 127 dimensions in an array declarator. (The FORTRAN-77 Standard allows a maximum of 7 dimensions.) 4.3.3 Order of Stored Array E:lements The elements of an array are stored in ascending order. The value of the first (leftmost) subscript varies between its minimum and maximum values most rapidly. The value of the last (rightmost) subscript 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(1,3) 1(2,3) In the following list, the elE·ments of the three-dimensional array (B(3,3,3» are stored row by row from left to right and from top to bottom. 4-5 SYMBOLIC NAMES, VARIABLES, AND ARRAYS 8(1,1,1) 8(2,1,1) 8(3,1,1)--1 ,------------------------ - 8(1,2,1) 8(2,2,1) 8(3,2,1)-, ,-------------------------8(1,3,1) 8(2,3,1) 8(3,3,1)-, [:B(1~~2) - --B(2~1 ~2) - --a(3,1~2)==1 [------------ - ----------- 8(1,2,2) 8(2,2,2) 8(3,2,2)-, ~~~~,!~2I===~~~3~ ===~~'~~}=J 8(2,1,3) 8(3,1,3)-, -I - 8(1,1,3) = == ~ :~~,~~3I ~ = ~~~!~ =~(~,~~3~~; L - 8(1 ,3,3) 8(2,3,3) 8(3,3,3) MR·S·1756·81 Thus B(3,1,1) is stored before B(1,2,1), and so forth. Character array elements are stored in successive character positions, and do not necessarily start on a word boundary. Character array elements are stored five characters per word (seven bits per character), and the low order bit is never used, for example: CHARACTER*3 A(4) The array A will be stored in the following way: A(1) A(2) " ~ " A(3) A(4) A A \I " II 0 21 14 7 28 35 II x x x 0 7 14 21 28 35 Unused A.._ \1 0 7 14 I x 21 , x Ixl I 28 35 MR-S-2S28-83 where: x 4.4 means bits are not used. The value in bit 35 is zero. CHARACTER SUBSTRINGS A character substring is a contiguous segment of a character variable or character array element. A character substring is identified by a substring name and can be assigned values and referenced. A character substring reference has one of the following forms: v([el]:[e2]) or a(s[,s] •.. ) ([el]:[e2]) 4-6 SYl1BOLIC NAMES, VARIABLES, AND ARRAYS where: v is a character variable name. a is a character array name. s is a subscript expression. el is an optional nu~eric expression that specifies leftmost character position of the substring. the e2 is an optional nuneric expression that specifies rightmost character position of the substring. the Character positions within a character variable or array element are numbered from left to right, beginning at 1. For example, LABEL{2:7) specifies the substring beginning with the second character position and ending with the seventh character position of the character variable LABEL. If the value of the numeric integer, FORTRAN converts fractional part before use. Expression el or e2 is not of type it to an integer value by truncating any The values of the numeric expression el and e2 must meet the following conditions: 1 .LE. el .I.E. e2 .LE. len where: len is the length of the character variable or array element. If el is omitted, FORTRAN assumes that el is 1. FORTRAN assumes that e2 equals len. If e2 is omitted, For Qxample, NAMES{1,3) (:7) specifies the substring starting with the first character position and ending with the seventh character position of the character array element NAMES{1,3). 4-7 CHAPTER 5 EXPRESSIONS 5.1 ARITHMETIC EXPRESSIONS An arithmetic expression is formed with arithmetic operands and arithmetic operators. The evaluation of such an expression produces a numeric value. Arithmetic expressions may be either simple or compound. arithmetic expression consists of an operand that can be: 1. A numeric constant 2. A numeric variable 3. A numeric array element 4. An arithmetic function reference (see Chapter 13) 5. An a r i t hme tic parentheses or logical expression A simple written within Operands may be of integer, real, double-precision, complex, octal, double-octal, or Hollerith type. logical, The following are examples of valid simple arithmetic expressions: 105 lAB TABLE(3,4,5) SIN (X) (A+B) (integer constant) (integer variable) ( a r ray e 1 em E~ n t ) (function reference) (a parenthetical expression) A compound arithmetic expression consists of two or more operands combined by arithmetic operators. Table 5-1 lists the arithmetic operations permitted in FORTRAN and the operator recognized for each operation. 5-1 EXPRESSIONS Table 5-1: Arithmetic Operations and Operators Operation Binary Operator + * A+B A-B A*B ** or " A**B or A"'B Unary Operator Example Addition Subtraction Multiplication Division Exponentiation Operation I + Identity Negation 5.1.1 Example - AlB +A -B Rules for Writing Arithmetic Expressions Observe the following rules in structuring arithmetic expressions: 1. The operands comprising an arithmetic expression can be of different types. Tables 5-2 and 5-3 illustrate all permitted combinations of data types and the type assigned to the result of each. NOTE All combinations of numeric data types except double-precision with complex are allowed in FORTRAN. 2. If you specify two adjacent operators, and the second is a minus or a plus, the second operator is considered a unary operator and acts only on the term immediately following it. Thus, in the example (A*X+B)*+C, the subexpression, *+C, is interpreted as the binary operator * and the unary +. You cannot, however, have two adjacent binary operators in an expression. For example, the expression A*/B is not 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 specify a mUltiplication of the operands. 5-2 Table 5-2: Type of the Result Obtained from Mixed-Mode Operations Type of Argllment 2 For operators + ,-,', Double Precision Real Integer LO~lical Complex Double Octal Octal Literal ~------------------------~~--------------'-i----------------;--------------'----~---'------------~-------.--------_4----------------_+----- ----------+----------------~ 1. Type of operation Integer used 2_ Type associated with result 3_ Conversion on Argument 1 1. Integer 1. Uouble preCIS!'")!' 2. Integer :l (Jouble Preclslul' J. From InleClN Ie Doubie Pn~cISl(jp J. from jmegc' to ticaj 3. None , 'L. J. Holm InlNlc' 10 L(ln;:)I;:~ intr'q InteGer 3. No",,' 3 Nor". 3. Non" '.1,;' us -~d as Heai 4. Conversion on Argument 2 4. None 4. None :l. 4. Non" N( U' 4. Hig n order 1V0ro 4. is used directly' low oraer worli tilan ordPi \'\{(}, IS used dlleeti·, tunner worGS aft" IS Iqrlo.-eo 1. Type of operation 1. Real 1. Double PreCISion 2. Real '-- Doubie PreCISI,)!, 3. None 3. Used direGtlv as the high order 1. Heal used 2_ Type associated 2 lie.,1 with result 3. Conversion on Ul I Argument 1 Real w J 4. Conversion on Argument 2 4. I-rom 'me,:" to Rr-_! 4. None Lsed dlrp.cll~ as J J. Non.- None tile Real n.ll' wora: low orch!, wora IS zen, If jf]aln~T 'j D,~~7 4. Non,; 4. NOlii' 4. Norw 4. High orOel won; IS used dw'ctly lOW Ofoel wor,-j IS Iqnoreo 4. HI9h order wor.i is used dlrectlv further word, are Ignore,; ~--------------------------~----------------4_--------------~~-----------------------.-----------~----------------~----------------+_--------------_4----------------~ Double Precision 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 4. Conversion on Argument 2 1. Doubie Precis!. n I. Double PreC"Wii' 2. Uoubl" t-'reclslClJ :< None 4 f\h~: Hom Imeoer tu 4. ' Used direcllv 1. Double Precision 1. lJout.le PrecIsion 1. Double I'r,,~ls'on 1. 2. Douale t>recisloll 2. Double Precisiion 2. Double PrecIsIon 2. Double PrecIsion 2. Double PrecislO!' 3. None J. No,,' 3. Non . . · J NII'i! 4. None 4. Useo dllecTly a,; thl' hiqh onh': woro: lOW orde; 4. NOtl(' the nlun t.'rr:~"f Double Preclsl' I word: iew or!1:i""; wc:c !~, lP.'" Complex 1. Complex .l 4. I--rom Inteqer II. (.omDI~)! \I~IU'~ --------1---------.---1 !. L..omnlex 1. Compl~"" L. Lorfluh.:t, Cornplf· ... 2. Complex L. COlllllle! N[;; 3. None 3. Nol' 3. Nnr,~' 3. No"" 4. None 4. Used drrectlv .IS 't nneC'tiv .::. the HI"i";; p.u InlaQm~t \f I I .... " 4. First two WC"'j, 1 Us("o d!rf>(:tl': ttH! USP.r1 as. Hpal p. 'r' 1. New 4. first two WOI(j,: are used dir~~!!' further \Nunj-: are Ignorl'rl woro IS zer': ~---------.---------_+--------__f----------~---------_+---------f------.----_+--------~-.- 1. Type of operation used 2. Type associated with result 3_ Conversion on Argument 1 4. Conversion on Argument 2 Douoj~ ~rcClsloP 1. Double PrecIsion Hl:~ii 2. (~ompl"" me Heal par!; ..... 3. ': Imaqmary p.;; 1 nnaqlnary pctn 2. Cornplex USPfl are used olrcr.tl'..: Further WOf!;-.. are IQno,· ' .... Logical 1_ Type of operation used 2. Type associated with result 3. Conversion on Argument 1 4. Conversion on Argument 2 1 J. ~or1t;) I 1. 2. 1J0ubie Pree"'"'' 2. Octal 2 Oc!~1 2. Octal } Octa; f,.l . • " J. Used directly ~'. 3. None 3. NOfl(' J. None 3 Non" 4. None 4. None 4 Hiah order wc"r.! j ;-.tont: 4. Nnne :i lJ sed alrrcll" II e Heal lhe high order word; low order wora IS zern 4 Integ'~r 1. lJouble tJreclslul H. InICQ(" 0,.,' 1 inleat~r Ir laQlniU'" 0;1" io,lon .. -1 Hiqll order word rurtner ;}IIII~;; IS Iqnolt-'tl 1. I VDe OT ooeraV!n r . ,. "L. I voe assucICll.-;(i 2. Real 1. Double .... reCISILJ'. HC.JI ~. 1. Inl"q~" 1. 2. Oc.ai Double t-'reC'IS!I;, 3. Used directly as the hlqh ordet word; low orcl." "I Imeq'" Uclal Ncr-~ J. NOfn- word IS .ler n . 4 l.·(l~;;;'-:r">itljl a ,",; Non- 't 4 j'urll' Hiqh order ''II'ptd 4. Hioh order "'C>" IS U:icd dlifL.i:b. iow oloer 'J\'Cf{1 IS used drrcc;:'j furtner woc'" l!i lonOf~o:j ar~ IqnOrf>rJ ~-------------------------+_--------------.~--------------~--------------~---------------~---------------4---------------4---------------~------------~ 1. Uouole t-"reCISIUII H,'.!' L.. .1 "2.. LJouble t-"reCISlon !rHeaE" J (;'U1V .. ' ...... , ••••• IS used di, l-cil hJW OHler .fi{),,; IS IJseri nl;f~1 H!Qtl urder ...-vor,j 3. IS used dlrectlv I" low (Iral~r \Nil(fj I~ IQllort.·U 4. Non,. HIOh ararl"" wnni IS used t1!rf~~.:tb. lOW orner WO.I. 3. IS used ct, ' J. Hlqh orde, .f.- •. , ·'-.!d; j "'I; IS used Qtrc-:';'" lOW order W:.ii. are Igoor"" lOW order y..i 1 1'.1 IS Iqnorc'r. IS lunnrer1 4. NOlh:- HIUh 'Jr':1e, 4. Hloh order WGf~l IS used d""o.:tl •. 4. Hlch order ~",'(:f( I IS used dli;.;(';;·~· lOW orar.or ~·'..;f·!·. low orner ~""_'f;1 are Iqnot(\(i ~---------------_4----------- . r__---.-------+_-------.--_;_-.------------------. -------+----------11----------+---------1 ;. L i L iit .... : ,j t ~n:':.;::'!--;.ll;:r-:: .u'lHH~\,.nt In~,_·(' ... IrT~'f"- ,r:'C;l'.. - h.l.rtrit-"'f .'d' :1~-" IS IiSC'U (Hft.:' ,. jupr~er Hrst twu WO'lL are USP.(~ Oirec:·~ arc l"Un'Jn-~~: Nc· J i- !st ivvl) wurOb a' e used dlr.~c\iv J. Hlqn oroer word IS u<;f,·d oirectlV' further wm·,b Wnf(1 are IOnore{l -t Nu,',,' .I. t"Han ~Jr..:1cr ":Vl"" i .j Mlon Ordej .-vu' IS tunner WOIUS rurther W(;I':'; dt~ 1l.!l1uretj ·t. None I usea OIP'C!:'}. IS USeO tllret !., ctre IUfHHt'(1 4. Hlgtl order ""01·1 ,; . •1100 Of(;€i V.I." !S usea ol:-e::::: . furirler WOf{j are IU"Cf'I~'; 4. High oroer wOln is used din-. ct~'! low o·der word -----_._-,----- --... - ..--.-.- --_._------- -_..._----------\--------------"-----------------_.. _-----------_._- --.-----------''-----------~ MR-SI751-Bl ,.................a. .I ........ I. . . . .IIII. . . . . . . . . . .IIIIIIII. . . . . . . . . . . . .~. . . . . . . . . . . . . . . . . . . . . . . .~. . . . . . . . . . . . . . . . . . . . . .~. . . .I . . . . . . . . . . . .I. . . . . .~. .B . .& EXPRESSIONS Table 5-3: Permitted Base/Exponent Type Combinations Exponent Operand Base Operand DoublePrecision Integer Real Integer Integer Real DoublePrecision Complex Real Real Real DoublePrecision Complex DoublePrecision DoublePrecisio n DoublePrecision DoublePrecision (Illegal) Complex Complex Complex (I llega 1) Complex 5.1.2 Complex Arithmetic Constant Expressions An arithmetic constant expression is an arithmetic expression in which each operand is one of the following: 1. A numeric constant 2. A symbolic name of a numeric constant 3. An 4. A call to the function ICHAR (see Chapter argument is a character constant expression arith~etic constant expression enclosed in parentheses 13) where thp- The exponentiation operator is not permitted unless the exponent is of type integer. Note that variables, array elements, and function references are not allowed. Example: 5+6*(ICHAR('Z')-ICHAR('A ' )+1)*4.1**3 5.1.2.1 Integer Constant Expression - An integer constant expression is an arithmetic constant expression in which each constant or symbolic name of a constant is of type integer. Example: 3+4**6+2 5-5 EXPRESSIONS 5.2 CHARACTER EXPRESSIONS Character expressions consist of character operands and character operators. The evaluation of a character expression yields a single value of character data type. A character operand can be anyone of the following: 1. A character constant 2. A symbolic name of a character constant 3. A character variable 4. A character array element 5. A character substring 6. A character expression, optionally enclosed in parentheses 7. A character function reference The only character operator is the concatenation operator (II). A character expression has the form: character operand [Ilcharacter operand] •.• The value of a character expression is a character string formed by successive left-to-right concatenations of the value of the elements of the character expression. The length of a character expression is the sum of the lengths of the character elements. For example, the value of the character expression 'AB'II'CDE' is 'ABCDE', which has a length of 5. Note that the expression: A=AIIB has no effect on A, since the concatenation result is truncated to the length of A. Parentheses do not affect the value of a character expression. example, the following character expressions are equivalent: For ('ABC'II'DE')II'F' 'ABC'II('DE'II'F') 'ABC'II'DE'II'F' Each of these character expressions has the value 'ABCDEF'. If a character element in a character expression contains spaces, spaces are included in the value of the character expression. example, 'ABC 'II'D E'II'F' has a value of 'ABC D EF'. 5-6 the For E}(PRESSIONS 5.2.1 Character Constant Expression A character constant expression is a character each operand is one of the following: expression in 1. A character constant 2. The symbolic name of a character constant 3. A character constant expression enclosed in parentheses 4. A call to the function CHAR (see Chapter a r gum e n t i s ani n t e g E' r con s tan t ex pre s s ion 13) which where the Variables, array elements, substrings, and function references are not allowed. Example: 'HELLO' II:HAR (13)1 ICHAR (] 0)1I'GOODBYE' 5.3 LOGICAL EXPRESSIONS Logical expressions can be either simple or compound. Simple logical expressions consist of a logical operand, which can be one of the following: 1. A constant 2. A variable 3. An array element 4. A function reference (see Chapter 13) 5. An expression written within parentheses Compound logical expressions consist of two or more logical or numeric operands combined by logical operators. The evaluation of a logical expression produces a truth value (type logical, true or false) as determined by the resulting bit pattern. Table 5-4 gives the logical operators permitted description of the operation each provides. 5-7 by FORTRAN and a EXPRESSIONS Table 5-4: Operator Logical Operators 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. .NEQV. Exclusive OR operator (also .XOR.). If either but not both of the logical operands combined by .NEQV. is true, the result will be true. .EQV. Equivalence operator. If the logical operands being combined by .EQV. are both the same (both are true or both are false), the result will be true. .NOT. Complement operator. This operator 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 Logical expressions are of the general form P .op. Q, where P and Q are logical operands and .op. is any logical operator except ".NOT.". The .NOT. operator complements the value of an operand; it must appear immediately before the operand that it modifies, for example, .NOT.P. Table 5-5 is a truth table illustrating all possible logical combinations of two logical operands (P and Q) and the result of each combination. 5-8 EXPRESSIONS Table 5-5: Logical Operations Truth Table When P is And Q is: t-----------. -r------ Then the Expression: 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 False P .OR. Q False True True P .NEQV. Q False True False P • NEQV. Q True False True P .NEQV. Q True False False P • NEQV. 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 For example, consider the following variables: Variables PHETT, RUN I,J,K DP,D L,A,B CPX,C Type Real Inteqer Doubje-Precision Logical Complex 5-9 EXPRESSIONS Examples of valid logical variables are: expressions consisting of the preceding L.AND.B (PHETT*I).NEQV. (DP+K) L. AND. A. OR .• NOT. (I -K) Logical operations are performed on the full 36-bit binary representation of the operands involved. However, when an operand of a logical expression is double-precision or complex, only the first word of a double-precision operand (the high-order word) or the real part of the complex operand is used in the specified logical operation. The result of a logical operation is found by performing the specified operation simultaneously for each of the corresponding bits in each operand. r'or example, consider the expression A=C.OR.D, where C="456 and D="201. The operation performed by the processor and the result j s: Word Bits 0 Operand C 0 Operand D 0 Result A 0 1 .. 24 0 0 0 ~O ·0 .. 0 25 26 0 0 0 0 0 0 27 30 1 29 0 0 0 31 0 0 I 0 1 0 1 28 0 0 1 I 32 33 1 I 0 0 1 I 34 35 I 0 0 1 1 1 Table 5-5 also illustrates all possible logical combinations of two (P one-bit binary operands and Q) and gives the result of each Simply read 1 for true and 0 for false. combination. If a logical expression is used as an operand in an arithmetic expression, its value is not converted to accommodate it to the type of any other operand. 5.3.1 Logical Constant Expression A logical constant expression is a logical expression operand is one of the following: in which 1. A logical constant 2. The symbolic name of a logical constant 3. A relational expression in which each operand is expression 4. A logical constant expression enclosed in parentheses a each constant Variables, array elements, and function references are not allowed. Example: .NOT. (PARML1.NE.PARML2) where PARMLI and PARML2 are specified in a Sec t ion 7.8). 5-10 PARAMETER statement (see EXPRESSIONS 5.4 RELATIONAL EXPRESSIONS Relational expressions consist of two arithmetic expressions or character expressions combined by a relational operator. relational operator allows you to test the relationship between arithmetic or two character expressions. two The two The result of a relational expression is always a false value. or logically true You can write relational operators either as a 2-letter mnemonic enclosed within periods (for example, .GT.) or use the symbolic equivalent, for example, >, instead of .GT. Table 5-6 lists the mnemonic and symbolic forms of the FORTRAN-10/20 relational operators and specifies the type of test performed by each. Table 5-6: Relational Operators and Operations Operators Relation Tested 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 >:= < <~ - .- # Relational expressions are of the general form A .op. B, where A and B represent arithml~tic or character operands, and .op. is a relational operator. You can mix arithmetic operands of type double-precision in relational expressions. integer, real, and A relational expression cannot be used to compare the value of an arithmetic expression with the value of a character expression. However, you can compare a num~ric expression to a character constant. In this case, the character '~onstant is considered to be a Hollerith (see Section 3.9). You can compare complex operands using only the operators .EQ. (==) and .NE. (#) • Complex quantiti,es are equal if the corresponding parts of both words are equal. For example, assume the following variables: Variables Type PHETT, RON I,J,K DP,D L,A,B CPX,C CHR,RA Real Integer Double-Precision Logical Complex Character 5-11 EXPRESSIONS Examples of valid variables are: relational expressions consisting of the above Examples of invalid relational expressions variables are: consisting of the above by .EQ. operands and (PHETT) .GT.lO I -- 5 C.EQ.CPX CHR.LT.RA (PHETT) .GT 10 (closing period missing from operator) C.GT.CPX (complex operands can only and .NE. operators) RA.EQ.RON (you cannot compare character operands) be compared arithmetic Examples of valid expressions that use both logical operators to combine the preceding variables are: and relational ( I • GT. 10). AND. (J. L E. K) ( (I * RON) . EQ. (1/ J) ) • OR. L (I. AND. K) # ( (PHETT) . OR. (RON) ) '-:#CPX. OR. RON ~ Logical expression is used as an operand in an arithmetic its value is not converted to accommodate it to the type i)f any other operand. ':~-"'DreSSlon, In character relational expressions "less than" means "precedes in the ASCII collating sequence," and "greater than" means "follows in the ASCII collating sequence", for example: , AB ' / / ' ZZZ' . LT. 'CCCCC' This expression tests whether 'ABZZZ' is less than 'CCCCC'. Since that relationship does exist, the value of the expression is true. If the relationship stated does not exist, the value of the expression is false. If the two character expressions in a relational expression are not the same length, the comparison is performed as if the shorter one is padded on the right with spaces until the lengths are equal, for example: , ABC' • EQ. 'ABC , AB' • LT • ' C ' The first relational expression has a value of true even though the lengths of the expressions are not equal, and the second has a value of true even though 'AB' is longer than 'C'. 5-12 EXPRESSIONS NOTE The rule that character relationals extend the shorter operand with spaces to match the length of the longer operand has an interesting effect when the longer string ends with characters in the range CHARCO) to CHAR(31) (ASCII control characters such as 'bell' and line feed). Since space is CHAR(32), the trailing spaces supplied as filler by FORTRAN compare being greater than trailing control characters. Thus, the string 'FOO' is .GT. 'FOO"G' (FOO followed by a bell). 5.5 EVALUATION OF EXPRESSIONS The following considerations determine the order of computation FORTRAN expression: 1. The use of parenthesEs 2. An established hierarchy for the relational, and logical operations 3. The location of operators within an expression 5.5.1 execution of of a arithmetic Parenthetical Subexpressions In an expression, all sUbexpressions enclosed 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 in a parenthetical subexpression, the required computations are performed according to the hierarchy assigned to operators by FORTRAN (see Section 5.5.2). For example, the separate computations expression A+B/«A/B)+C)-C are: 1. Rl=A/B 2. R2=Rl+C 3. R3=B/R2 4. R4=A+R3 5. R5=R4-C performed in evaluating the results the where: Rl through R5 represent the interim and computations performed. 5-13 final of EXPRESSIONS 5.5.2 Hierarchy of Operators The following hierarchy (order classes of FORTRAN operators: first, second, third, of execution) is assigned to the arithmetic operators relational operators logical operators Table 5-7 specifies the precedence operators of the above classes. assigned to the individual With the exception of exponentiation and integer division, 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 5-7: Hierarchy of FORTRAN Operators -- Class Level EXPONENTIAL First ** or ARITHMETIC Second Third Fourth -(negation) and + (identity) * ,/ +,- RELATIONAL Fifth .GT.,.GE.,.LT.,.LE.,.EQ.,.NE. or Symbol or Mnemonic ... -'- _.- >,>=,<,<=,==,# LOGICAL Sixth Seventh Eighth Ninth .NOT. .AND. .OR. .EQV.,.NEQV. '- 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). 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**RI (final result). As with other expressions, parentheses alter the evaluation of the above expression. The expression (A**2)**B is evaluated in theSE! two steps: first RI = A**2 (intermediate result) second R2 = RI**B (final result) 5-14 EXPRESSIONS 5.5.3 Mixed-Mode Expressions Mixed-mode exprE!ssions arE~ evaluated on a basis of subexpression-by-subexpression r with the type of the results obtained converted and combined with other results or terms according to the conversion procedures described in Table 5-2. For example, assume the follow!ng variables and data types: Variables Type Double-Precision Real Integer D X I,J The mixed-mode expression D+X*(I/J) manner: is evaluated in the following 1. Rl I/J 2. R2 X*Rl Rl is converted to type real and is mUltiplied by X to produce H2 3. R3 D+R2 R2 is convel:ted to type added to D to produce R3 Rl is integE~r double-precision and is where: Rl and R2, and R3 repr(~sent the interim respectively of the computations performed. 5.5.4 and final results Use of Logical Operands in Mixed-Mode Expressions When you use logical operands :_n mixed-mode expressions, the value the log ical oper-and is not convertE~d in any way to accommoda te it the type of the other operands in the expression. For example, L*R, where L is type logical and R is type real, the expression evaluated without convertinq L to type real. 5.6 of to in is CONSTANT EXPRESSIONS A constant expression is an arithmetic constant expression (see Section 5.1.2), a character constant expression (see Section 5.2.1), or a logical constant expression (see Section 5.3.1). 5-15 CHAPTER 6 EXECUTABLE AND NONEXECUTABLE STATEMENTS Each statement is classified as executable or nonexecutable. Executable statements specify actions and form an execution sequence in a program. Nonexecutable statements do the following: 1. Specify characteristics, arrangement, and initial data 2. Contain editing information 3. Specify statement functions 4. Classify program units 5. Specify entry points within subprograms values of Nonexecutable statements are not part of the execution sequence. Nonexecutable statements may be labeled, but such statement labels must not be used to control the execution sequence. 6.1 EXECUTABLE STATEMENTS The following statements are classified as executable: 1. Arithmetic, logical, statement label (ASSIGN), and assignment statements 2. Unconditional GO TO, assigned statements 3. Arithmetic IF, logical IF statements, and two-branch logical IF statements, IF THEN, ELSE, and ELSE IF THEN statements 4. CONTINUE statement 5. STOP and PAUSE statements 6. DO and DO WHILE statements 7. READ, REREAD, WRITE, and PRINT statements 8. OPEN and CLOSE statements 9. REWIND, BACKSPACE, ENDFILE, BACKFILE, FIND and UNLOAD statements 10. CALL and RETURN statements 6-1 GO TO, and character computed SKIPRECORD, GO TO SKIPFILE, EXECUTABLE AND NONEXECUTABLE STATEMENTS 6.2 11. END, END IF, and END DO statements 12. DECODE and ENCODE statements 13. ACCEPT, PUNCH, and TYPE statements 14. INQUIRE statement NONEXECUTABLE STATEMENTS The following statements are classified as nonexecutable: 6.3 1. PROGRAM, FUNCTION, statements 2. DIMENSION, COMMON, EQUIVALENCE, IMPLICIT, INTRINSIC, EXTERNAL, and SAVE statements 3. INTEGER, REAL, DOUBLE PRECISION, COMPLEX, CHARACTER type-specification statements 4. DATA statement 5. FORMAT statement 6. Statement function statement 7. INCLUDE statement 8. NAMELIST statement SUBROUTINE, ENTRY, and BLOCK DATA PARAMETER, LOGICAL, and ORDERING OF FORTRAN STATEMENTS The order in which you place FORTRAN statements in a program unit is important. Certain types of statements must be processed before others to guarantee that compilation takes place as you expect. Figure 6-1 shows the required order of statements and comment lines within a program unit. Horizontal lines indicate (from the top of the diagram to the bottom) the order in which statements and comment lines must appear in a program. For example, a PROGRAM statement must occur before FORMAT statements. FORMAT statements, in turn, must occur before an END statement. Vertical lines in the diagram indicate how comment lines and statements may be interspersed in the program. For example, PARAMETER statements must be placed after all PROGRAM, FUNCTION, or SUBROUTINE statements, and before all statement function and executable statements. PARAMETER statements can be placed before, after, or between all IMPLICIT and other specification statements. Comment lines may be interspersed anywhere in a program. Generally if FORTRAN encounters statements that are out of place, it prints warning messages and continues compilation. In some cases, however, out-of-place statements cause the compiler to terminate compilation or generate unexpected results. 6-2 EXECUTABLE AND NONEXECUTABLE STATEMENTS PROGRAM, FUNCTION, SUBROUTINE, or BLOCI( DATA 1 Statements IMPLICIT Statements PARAMETER Statements Comment Lines and INCLUDE:i Statements Other Specification Statements FORMAT and Entry2 Statements NAMELIST and DATA Statements Statement Function Definitions Executable Statements E'~D Statement 1 BLOCK DATA subroutines cannot contain any executable statements, statement functions, FORMAT statements, EXTERNAL statements, INTRINSIC statements, or NAMELIST statements (See Section 14.1). 2 The ENTRY statement is allowed only in functions or subroutines. All executable statements which reference an~1 dummy parameters must physically follow the ENTRY statement unless the references appear in the FUNCTION statement, the SUBROUTINE statement, or in a precedin9 ENTRY statement. :i The placement of an INCLUDE :,tatement is dictated by the types of statements to be included. MR-S-3822-85 Figure 6-1: Ordering of FORTRAN Statements NOTE In FORTRAN-IO/20, a DATA statement can precede a PARAMETER statement or another specification statement. 6-3 EXECUTABLE AND NONEXECUTABLE STATEMENTS 6.4 COMPILATION CONTROL STATEMENTS 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 are: 1. PROGRAM statement 2. INCLUDE statement 3. END statement The PROGRAM statement and the INCLUDE statement are described in the following sections. The END statement is described in Section 9.8. 6.4.1 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. (See Section 4.1 for a description of symbolic names.) The PROGRAM statement must be the first statement in a program unit. (see Section 6.3 for a discussion of the ordering of FORTRAN sta temen ts. ) 6.4.2 INCLUDE Statement This statement allows you to include code segments or external declarations in a program unit without having them in the same file as the primary program unit. When an INCLUDE statement is encountered during compilation, the compiler replaces the INCLUDE statement with the contents of the specified file. The general form of the INCLUDE statement is: INCLUDE 'filespec [/switch]' where: filespec is a TOPS-IO or TOPS-20 file specification (refer to the TOPS-IO or TOPS-20 Operating System Commands manliaT):-- The only restricti~is-- that under---rfOps=lo you cannot speci fy subd i rectory information. switch is one of the following optional switches: /CREF indicates the included statements are to be used to augment the cross-reference listing (default). 6-4 EXECUTABLE AND NONEXECUTABLE STATEMENTS /LIST indicates that the statement in the specified file is to be listed in t~e compilation source listing. A number indicating the depth of rlesting of include files precedes (>.3ch statement listed (default). /NOLI3T indicates that the included statements are not to be prInted in tje compilation listing. /NOCREF indicates ,; ta temen t s Llqmen t listjng. ,j that the included are not to be used to the cross-reference The following rules govern the use of the INCLUDE statement: 1. The INCLUDEd file can contain any legal ~ORTRAN statement except a statement that terminates the current program unit, such as the END, PROGRAM, FUNCTION, SUBROUTINE, or BLOCK DATA statements. The INCL~DEd file can contain other INCLUDE statements. This is called nestinq INCLUDE statements. The number of nested levels i'3 restricted to 12. 2. The proper placement of the INCLUDE statement within a program unit depends upon the types of statements to be INCLUDEd. (See Section 6.3 for information on the orderinq of FORTRAN statements.) 3. The file 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. The level ot nesting is indicated following the asterisk. 6-5 CHAPTE1R 7 SPECIFICATION AND DATA STATEMENTS Specification statements are used to specify storage allocation, and data arrangement. specification statements: 1. DIMENSION 2. Statements that explicitly specify type, including INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, or CHARACTER 3. IMPLICIT 4. COMMON 5. EQUIVALENCE 6. EXTERNAL 7. INTRINSIC 8. PARAMETER 9. DATA 10. SAVE Specification statements are nonexecutable and ordering guidelines described in Section 6.3. 7.1 type characteristics, There are ten types of must conform to the DIMENSION STATEMENT The DIMENSION statement provides FORTRAN with information needed to identify and allocate the space required for 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 a(d) [,a(d) ••• ] where: each a(d) is an array declarator. An array declarator provides the name and dimension(s) of an array. An array declarator is written in the following form: a(d [,d •.• ]) 7-1 SPECIFICATION AND DATA STATEMENTS where: a is the symbolic name of the array. d is the array dimension declarator. declarator is as follows: dl: The form of a dimension ] d2 where: dl is an optional integer expression or integer variable specifying the lower dimension bound. The lower dimension bound is the first element in that dimension of the array. If dl is not specified the default is 1. d2 is an integer expression or integer variable that specifies the upper dimension bound. The upper dimension bound is the greatest element in that dimension of the array. You must have at least one d2 specification in each array declaration. If both dl and d2 are specified, dl cannot have a value greater than d2. The values dl and d2 can, however, be the same. An asterisk (*) can also occur as an upper bound, but only as the last dimension. An asterisk marks the declarator as an assumed-size array declarator (see Section 7.1.2). NOTE A dimension bound expression must function or array element reference. not contain a If the array is a dummy argument to a subprogram, then dl and d2 can be integer dummy arguments and d2 can be an asterisk; otherwise, they must be constants. If the symbolic name of a constant or variable that appears in a dimension bound expression is not of implicit default integer type (see Section 4.2), it must be specified integer by an IMPLICIT statement or a type-statement. Examples: DIMENSION EDGE (-1:1,4:8), NET (5,10,4), TABLE DIMENSION TABLE (IAB:J,K,M,10:20) where: lAB, J, K, and M are of type integer. 7-2 (567) SPECIFICATION AND DATA STATEMENTS 7.1.1 Adjustable Dimensions When used within a subprogram, a declarator for an array that is a dummy argument can use integer dummy arguments as dimension bounds. The following rules govern the use of adjustable dimensions in a subprogram: 1. The array name must be a dummy argument. Each variable that is used as a dimension bound must be either a dummy argument or in COMMON (see Section 7.4). 2. For multiple entry suoprograms, if any variables that specify dimension bounds are dummy arguments which do not occur in the formal argument list of the entry point used, the value of the variables as passed for a prevIous call are used. However, this is only permitted if the subprogram has not changed those dummy arguments. Futhermore, when overlays are used, a SAVE statement that preserves the local variables of the subprogram is neejed. 3. If the value of an array dimension variable is altered within the program, the dimensionality of the array is not affected. 4. The size of an array within a subprogram cannot size of the original array, as defined in program. exceed the the calling Example 1: 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 In the example above, the dimensions of ARRAY each time the subroutine SBR is entered. will be re-specified Example 2: SUBROUTINE SBI (ARR1,M,N) DIMENSION ARRl(M,N) ARRl(M,N)=VALUE ENTRY SB2(ARRl,M) ENTRY SB3(ARRl,N) ENTRY SB4(ARRl) END In the example above, the first call made to the subroutine must be made to SBI so that all of the dimension bounds have defined values. If a call is made to SBI with the values M=ll and N=13, a succeeding call to SB2 will use the value N=13, but will give M a new value. If a succeeding call is made to SB4, the last values passed through entries SBl, SB2, or SB3 are used for M and N. 7-3 SPECIFICATION AND DATA STATEMENTS 7.1.2 Assumed-size Arrays An assumed-size array is a dummy array for which the upper bound the last dimension is specified as an asterisk(*), for example: of SUBROUTINE SUB(A,N) DIMENSION A(l:N,l:*) Since storage for array A is allocated in the calling routine, the upper bound of the rightmost dimension of A does not affect the subscript calculations or storage allocation for A. Therefore, subroutine SUB can be written to handle arguments with any rightmost dimension (the last subscript is never range checked for being too large, even when the /DEBUG:BOUNDS compiler switch is specified). Such a subroutine can declare assumed-size arrays. The size of an assumed-size array, and the number of elements that can be referenced, are determined as follows: 1. If the actual argument corresponding to the dummy array is a noncharacter array name, the size of the dummy array is the size of the actual-argument array. 2. If the actual argument corresponding to the dummy argument is a noncharacter array element name, with a subscript value of s in an array of size a, the size of the dummy array is: a+l-s. 3. If the actual argument is a character-array name, character-array element name, or character-array element substring name, and begins at character storage unit b of an array with n character storage units, the size of the dummy array is INT«n+l-b)/y). Where y is the length of an element of the dummy array. Because the actual size of an assumed-size assumed-size array name cannot be used as: 7.2 array is not known, 1. An array name in the list of an I/O statement 2. A unit identifier for an internal file in an I/O statement 3. A format specifier in an I/O statement 4. A NAMELIST statement element an TYPE SPECIFICATION STATEMENTS Type specification statements explicitly declare the data type of variables, arrays, or function names. You can give an array name in a type specification statement, either alone (unsubscripted) to declare the type of all its elements, or with dimension bounds, to specify both its type and dimensions. There are two forms of type specification statements: numeric type specification (see Section 7.2.1) and character type specification (see Section 7.2.2). 7-4 SPECIFICATION AND DATA STATEMENTS 7.2.1 Numeric Type Specification Statements The general form of numeric type specification statements is: type v [ , v ••• ] where: type can be anyone of the following declarators: 1. INTEGE:R 2. REAL 3. DOUBLE: PRECISION 4. COMPLE:X 5. LOGICJ,L is a variable, array, or function name 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. v Examples: INTEGER A, REAL R, M, a, TABLE, FUNC ARRAY(5:l0,lO~20,5) If a name that is the same as an intrinsic FORTRAN function name appears in a conflicting type statement, it is assumed that the name refers to a user-defined routine, variable, or array of the given type. If you place a generic FORTRAN function name in an explicit type statement, it loses its qeneric properties. NO'I'E The data type size modifier, *n, is accepted by FORTRAN-IO/20 to be compatible with the type statements used by other manufacturers. You may append this size mod-.fier to the declarators, causing some to E~licit messagE~s warning users of the form of the variable specified by FORTRAN-IO/20: Declarator INTEGER*2 INTEGER*4 LOGICAL*1 LOGICAL*2 LOGICAL*4 REAL*4 REAL*8 COMPLEX*8 COMPLEX*16 REAL*16 COMPLEX*32 Forn of Variable Specified Full word integE~r with warning message Full word i n tegE~r Full word logical with warning message Full word logical with warning message Full word logical Full word real Doubl e-pr~?c is ion real Complex Complex with warning message Doubl e-prl?c is ion real with warning message Complex with wal::'ning message 7-5 SPECIFICATION AND DATA STATEMENTS addition, you can append the data 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, fn ~ype HEAL*4 A, 8*8, C*8(lO}, D A ~nd D are single-precision (one word) real, and Band C are double-precision (two words for each element) real. 7.2.2 Character Type Specification Statements The form of the character type specification statement is: CHARACTER [*len[,]] v[*len] [,v[*len]] ••• where: v len is one of the following: • The name of a symbolic constant, variable, function subprogram • An array declarator array, or is the length of the character data item and is one of the following: • An unsigned, nonzero integer constant • An integer constant expression enclosed in parentheses and with a positive value • An asterisk enclosed in parentheses If you specify CHARACTER*len, len is the default length specification for that list. If an item in that list does not have a length specification, the item's length is len. But if an item does have a length specification, it overrides the default length specified in CHARACTER*len. A length specification of asterisk (for example, CHARACTER*(*» specifies that a dummy argument or function name assumes the length specification of the corresponding actual argument or function reference (see Chapter 13). A length specification of asterisk for the symbolic name of a constant specifies that the symbolic constant assumes the actual length of the constant that it represents. If you do not specify a length, a length of one is assumed. Note that a length specification of zero is invalid. You can use a character type declaration statement to define arrays by including array declarators (see Section 4.3.2) in the list. If you specify both an array declarator and a length, the array bounds precede the length, the form is: a [ (d) ] [*len] 7-6 SPECIFICATION AND DATA STATEMENTS where: a is an array name, and a(d) is an array declarator. Examples of character type specification statements follow: CHARACTER*32 NAMES(lOO) SOCSEC(lOO)~9, The above stateme'nt specifies an array SOCSEC comprising one hundred 9-character elements, and an array NAMES comprising one hundred 32-character elements. PARAMETER (LENGTH=4) CHARACTER* (4 +LENGTH) LAS~I, FIRST The above statements specify two 8-character variables, LAST FIRST. (The PARAMETER statemEmt is described in Section 7.8.) and SUBROUTINE SI(BUBBLE) CHARACTER LETTER(26), BUBBLE*(·) The above statements specify an array LETTER comprising twenty-six I-character elements and a dummy argument, BUBBLE, which has a length defined by the cCllling program. CHARACTER*16 QUEST* (5*IN~1 (A» The above statement is invalid. an integer constant expression. 7.3 The length specifier for QUEST is not IMPLICIT STATEMENTS IMPLICIT statements declare the data type of variables and functions according to the first letter of each symbolic name. The IMPLICIT statement has two forms: IMPLICIT type (a[,a] ••• )[,type (a[,a] .•• )] ••• IMPLICIT NONE As shown in the statement above, an IMPLICIT statement consists of one or more type declarators sE~parated by commas. Each type declarator has the form: type (a[,a] .•• ) where: type can be anyone of the following declarators: 1. INTEGER 2., REAL 3., DOUBLE PRECISION 4., COMPLEX 5" LOGICAL 6" CHARACTER [,'" len] 7-7 SPECIFICATION AND DATA STATEMENTS a is an alphabetic specification in either of the general forms: c or cl-c2, where c, cl, or c2 is an alphabetic character. The latter form specifies a range of letters, from cl through c2, which must occur in alphabetical order. When you specify type as CHARACTER*len, len specifies the length for character data type. Len is an unsigned, nonzero integer constant or an integer constant expression enclosed in parentheses and with a positive value. If you do not specify a length, a length of one is assumed. Each letter in a type declarator list specifies that each symbolic name (not declared in an explicit type specification statement) starting with that letter is assigned the data type named in the declarator. For example, the statement: IMPLICIT REAL (R,M,N,O) declares that all names that begin with the letters R, M, N, or 0 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 declaratinns do not affect intrinsic functions. The length is also overridden when a particular name appears in a CHARACTER or CHARACTER FUNCTION statement (see Chapter 13). 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, for example, A-E for A,B,C,D,E. Thus, the statement: IMPLICIT INTEGER (I,L-P) declares that all symbolic names that I,L,M,N,O, and P are of type INTEGER. begin with the letters You may use more than one IMPLICIT statement, but they must appear before any other declaration statement in the program unit. (See Section 6.3 for a discussion on ordering FORTRAN statements.) The same letter must not appear as a single letter, or be included in a range of letters, more than once in all of the IMPLICIT statements in a program unit. You can use an IMPLICIT NONE statement to provide warning messages for variables not explicitly declared, including variables implicitly declared by other IMPLICIT statements. If you specify IMPLICIT NONE, no other IMPLICIT statement should be included in the program unit. 7.4 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 reference the same data in different subprograms without passing arguments. 7-8 SPECIFICATIOlJ AND DATA STATEMENTS COMMON statements have the COMMON [/cb/] fo~lowing form: nlist[[,]/[cb]/nlist] •.. where: cb is an optional common block name. the rules for ~;ymbol ic names.) nlist names, array names, and array that are to occupy the common area. The items specified for a common area (block) are ordered within storagc~ as they are listed in the COMMON statement. is a list of (See Section 4.1 for variablE~ dE~clarators all numeric data type or all The items in nlist must be (~ither character data type. A common block cannot contain both numeric and character data. A symbolic name can be used to identify each block. However, you can This omit the symbolic name fo~ one block in a program unit. unlabeled block is called the blank common block. The elements of a named commOll block can be assigned initial values by DATA statements appearing ill the BLOCK DATA subprograms (see Chapter 14). In standard-conforming programs, the elements of the blank common block may not be assigned initial values. However, FORTRAN-lO/20 allows any comml)n block elements to be defined in a DATA statement in any program unit. A given common block name may appear more than once in the same COMMON statement, and in more th.3n one COMMON statement within the same program or subprogram. When extended addressing is i~ effect, COMMON blocks reside in the large data area by def3ult. However, the /EXTEND:COMMON or /EXTEND:NOCOMMON switches can be used to explicitly allocate COMMON blocks in the large data area or small data area (see Section 16.5). During compilation of a source program, FORTRAN strings together all items listed for each commo~ block in the order in which they appear in the source program. For e~ample: COMMON X,Y,Z/STl/A,B COMMON/STl/TST(3,4)/ST2/rAB(2,2) COMMON/ST2/C,D,E//P,Q COMMON W has the same effect as the si,gle statement: COMMON X,Y,Z,P,Q,W/STl/A,B,TST(3,4)/ST2/TAB(2,2),C,D,E All elements specified for a common block are placed into one area. Common block names must be unique with respect to all subroutine, function, and entry point names. 7-9 SPECIFICATION AND DATA STATEMENTS NOTE If you use overlays, you can use the SAVE statement to retain the value of variables in a named common across overlays (see Section 7.10). (Blank common is always saved.) For example: Main Program Subprogram COMMON DELTA, LENGTH COMMON /COMI/KILOS,PRICE SUBROUTINE CALC COMMON/COMl/N,A COMMON Z,KOUNT CALL CALC The COMMON statements in the main program put DELTA and LENGTH into the blank common block, and put KILOS and PRICE into a common block named COM1. The COMMON statements in the subroutine make Z correspond to DELTA in the main program, KOUNT correspond to LENGTH, N correspond to KILOS, and A correspond to PRICE. To prevent conflict with other COMMON blocks, LINK requires largest definition for each common block be loaded first. 7.4.1 that the Dimensioning Arrays in COMMON Statements Array names with dimension bounds can be given in COMMON statements. However, variables cannot be used as dimension bounds in a declarator appearing in a COMMON statement; adjustable 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. For examples, COMMON /A/B(lOO), C(lO,lO) COMMON X(5,15) ,Y(5) 7.4.2 Character Data in COMMON Each character variable in a COMMON block is allocated to start at the first available character position. For example, CHARACTER B*3,C*3,D(3)*2 COMMON B,C,D 7-10 SPECIFICATION AND DATA STATEMENTS The COMMON block will be allocated in the following way: B C 0(1) 0(2) 0(3) Unused ~ r,,------A----___, rr----',A------..,,--~----...\f~~ Ix I o 7 14 21 28 35 0 14 7 ~!1 28 35 x I 0 7 14 x I 28 21 35 MR-S-252783 where x means the bits are not used. 7.5 EQUIVALENCE STATEMENT The EQUIVALENCE statement associates two or more same storage location. The format of the EQUIVALENCE EQU I VALENCE (n lis t) HtatemE~nt variables with the is: [, (n Ii!; t ••• ) ] where: nlist is a list of variablE~ names, array elements, array names, and chal~acter substring references separated by commas and enclosed in parentheses. You must specify two or more of these items in each list. In an EQUIVALENCE statement, each expression in a subscript substring reference must be an integer constant expression. The EQUIVALENCE statement a:.locatE!s all of the items in parenthesized list beginning at the same storage location. example, the statements: or a one For EQUIVALENCE (,A,B,C) EQUIVALENCE (LOC,SHARE{3): specify that the variables A, B, and C are to share the same storage location, and that: the variablE! LaC and the array element SHARE(3) are to share the same location. The relationship of equivalence is transitive. following statements have the game effect: For example, the EQUIVALENCE ('A,B) , (B,C) EQUIVALENCE (A,B,C) The following EQUIVALENCE statE~ment makes the first character of the character variables KEY and STAR share the same storage location. The character variable STAR is equjvalent: to the substring KEY (l:lO): CHARACTER KEY*16, STAR*lO EQUIVALENCE (KEY,STAR) You can equivalence variables of different numeric data types. Character variables must not: be equivalenced to numeric variables. For example, you can equivalence a real variable equivalent to a complex variable. In this case, since each complex variable occupies 7-11 SPECIFICATION AND DATA STATEMENTS two words of storage, and each single-precision variable occupies one word of storage, if you equivalence a real and a complex variable, the real variable shares storage with the real part of the complex variable. Figure 7-1 depicts the shared storage when a complex variable is equivalenced with a real variable. Source Program Statements: COMPLEX A REAL B EQUIVALENCE (A,B) 1. Memory Location A or B Stores: Real Part of Complex A or Entire Real B 2. Second Part of Memory Location A Stores: Imaginary Part of Complex A ~-------------------------~ 1--36-8il word--! MR-S-1764-81 Figure 7-1: Shared Storage using EQUIVALENCE Statement The EQUIVALENCE statement does not imply (or perform) any type conversions. If you equivalence a real variable and an integer variable, the data within the equivalenced location will be treated as a real or integer number, depending on whether it is referenced by the real or integer variable. If you equivalence a real variable with a double-precision variable, the data in the high-order word of the double-precision variable will be used by the real variable. For positive D-floating double-precision numbers (see Section 3.4), the high-order word is in the same format as a single-precision number. For G-floating double-precision numbers (KL model B only - see Section 3.4), the high-order word is not in the format of a single-precision number. Thus, equivalencing a real variable and a G-floating double-precision variable will produce incorrect results. Equivalencing a negative D-floating number and a real variable may not produce correct results either, for example the number: 577000000000 000000000001 777777777777, almost 1.0) (the negative of 200777777777 does not have a valid single-precision number in its high-order word. If you equivalence an array and a variable, the array does not assume any of the properties of the variable, and the variable does not assume any of the properties of the array. When you use an array element in EQUIVALENCE statements, it must have either as many subscripts as dimensions of the array, or only one subscript. In either case, the subscripts must be integer constants. Note that the single subscript case treats the array as a one-dimensional array of the given type. 7-12 SPECIFICATION AND DATA STATEMENTS The following example shows the effect I-dimensional and a 2-dimensional array: of equivalencing a DIMENSION A(3,2) ,B(6) EQUIVALENCE (A(l,l) ,B(l» or EQUIVALENCE (A(l),B (1» In this example, each array elE~ent of array A shares the same storage area with an element of array B: A(I,l) A(2,1) A(3,1) A(1,2) A(2,2) A(3,2) B(l) B (2) B(3) B (4) B(5) B(6) Specifying an array name wjthout subscripts in an EQUIVALENCE statement is the same as specifying the first element of the array. When you make one character substring equivalent to another character substring, the EQUIVALENCE statement also sets equivalences between the other corresponding characters in the character strings, for example, CHARACTER NAME*16, 10*9 EQUIVALENCE (NAME (10: 13), ID (2: S) ) As a result of these statements, the character variables NAME share space as illustrated in rigure 7-2. NAME Character Position 1 2 3 4 5 6 7 10 Character Position 8 9 1 2 10 11 3 4 5 6 7 1 '.I.1 ~I 1 t!~ H. Hi 8 9 MR-S-2523-83 Figure 7-2: Equivalence of Substrings 7-13 and ID SPECIFICATION AND DATA STATEMENTS The following statement also aligns the variables as shown 7-2: in Figure EQUIVALENCE (NAME(9:9) ,ID(l:l)) the If the character substring references are array elements, between the other EQUIVALENCE statement sets equivalences corresponding characters in the complete arrays. Character elements of arrays can overlap at for example: CHARACTER FIELDS(6)*4, STAR(5)*5 EQUIVALENCE (FIELDS(l) (2:4), STAR(2) any character posit.ion, (3:5)) As a result of these statements, the character arrays FIELDS and share storage space as shown in Figure 7-3. STAR Character Position Subscript 1 1 2 3 FIELDS 4 Subscript Character Position 1 1 5 1 2 3 2 3 4 5 4 4 5 1 1 2 3 2 3 4 4 1 5 2 3 1 4 2 3 1 4 2 3 5 4 2 3 1 1 2 3 4 5 4 6 1 2 3 4 MR-S-2S24-83 Figure 7-3: 2 2 3 Equivalence of Character Arrays 7-14 3 4 5 STAR SPECIFICATION AND DATA STATEMENTS General EQUIVALENCE Restrictions: 1. You cannot cause two different elements of an array to become equivalenced to each other. Thus, the following statement sequence is prohibited because it specifies the same storage location (B) for A(l) and A(2): DIMENSION A(2) EQUIVALENCE (A(l) ,B), (A(2) ,B) 2. An EQUIVALENCE statement must not specify that two consecutive locations are nonconsecutive. For example, the following statement sequence is prohibited because B(l) takes two storage locations, the second of which would make A(2) nonconsecutive to A(l): INTEGER A(2) DOUBLE PRECISION B(2) EQUIVALENCE (A(l) ,B(l)), 3. (A(2) ,B(2)) An EQUIVALENCE statement in a SUBROUTINE or FUNCTION subprogram must not refer to an argument of the subprogram. For example, the following statement sequence is prohibited: SUBROUTINE A(B,C) EQUIVALENCE (B,X) 4. You cannot cause two different substrings of the same character variables or arrays to become equivalenced to each other. For example, the following statement sequence is prohibited because it specifies the same substring B(1:3) for A(1:3) and A(2:4): CHARACTER A(3)*4,B*4 EQUIVALENCE (A(l) (1:3) ,B(1:3)), 5. (A(l) (2:4) ,B(1:3)) You also cannot use the EQUIVALENCE statement to assign memory locations in a way that is inconsistent with the normal linear storage of character variables and arrays. For example, the following statement sequence is prohibited because it would require the character variable B(2:2) to be equivalent to both A(l) (2:2) and A(l) (1:1): CHARACTER A(2)*lO,B*lO EQUIVALENCE (A(l) (1:3) ,B(1:3)), (A(l) (4:6) ,B(5:7)) Restrictions on EQUIVALENCE and COMMON: 1. You cannot use the EQUIVALENCE statement to equivalence two elements in different common blocks. Thus, the following statement sequence is prohibited: COMMON /BLOCKl/A,B,F/BLOCK2/C,D,E EQUIVALENCE (A,C) 2. You cannot set two quantities declared in a COMMON block to be equivalent to one another. Thus, the following statement sequence is prohibited: A,B,C EQUIVALENCE (A,C) COM~MON 7-15 SPECIFICATION AND DATA STATEMENTS 3. Quantities placed in a common area by means of an EQUIVALENCE statement are permitted to extend the end of the common area forward. 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 shown in Figure 7-4. Location X Location Y and A(1) } ~-----------t Shared Locations Location Z and A(2) Location A(3) Location A( 4) MR-S-1746-81 Figure 7-4: 4. Valid Equivalencing 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 in Figure 7-5. Location A(1) Location A(2) Location X and A(3) t-----------I } Causes COMMON R to Extend Backward Location Y and A(4} Location Z MR-S-1747-81 Figure 7-5: Invalid Equivalencing 7-16 SPECIFICATION AND DATA STATEMENTS 7.5.1 EQUIVALENC:E: and Extended Addr1essing When extended addressing is in effect, and an EQUIVALENCE statement causes a variable to be in COMMON, that variable resides in the same psect as the rest of the COMMON block. For variables not in COMMON, if you equivalence a large variable (default 10,000 or more words) with other variables (including scalars), all these variables will reside in the large data psect. For example, REAL A(20000),X EQUIVALENCE (A(l),X) causes variable X to be placed in the large data psect, equivalenced with a large array. since it is Conversely, if each equivalence variable is small (default less than 10,000 words), they will reside in the small data psect, even if the total size of the equivalence class is over the small variable limit. For example, REAL A(8000) ,B(8000) EQUIVALENCE (A (8000), B (1» The arrays will reside in the small data psect, because smaller than 10,000 words. each one See Sections addressing. on extended 7.6 15.4.11 and 16.5 for more information is EXTERNAL STATEMENT Any user 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. The subprograms mentioned in the EXT:E:RNAL statement cannot be FORTRAN intrinsic functions; they can be only user-supplied functions, subroutines, or block data subprograms. (The INTRINSIC statement discussed in Section 7.7 allows intrinsic function names to be used as arguments.) The EXTERNAL state~ent has the following form: EXTERNAL proc[,proc •.• ] where: proc is the symbolic name of a user-supplied subprogram, the name of a dummy argument associated with the name of a subprogram, or a block data subprogram. The EXTERNAL statement declares each symbolic name included in it to be the name of an external procedure, even if a name is the same as that of an intrinsic function. For example, if SIN is specified in an EXTERNAL statement (EXTERNAL SIN), all subsequent references to SIN are to a user-supplied function name SIN, not to the intrinsic function of the same name. The name specified in an EXTERNAL statement can be used as an actual argument to a subprogram, which can then use the corresponding dummy argument in a function reference or a CALL statement. 7-17 SPECIFICATION AND DATA STATEMENTS NOTE Note that a complete function reference used as an argument, for instance, FUNC(B) in CALL SUBR (A(FUNC(B) ,C», represents a value, not a subprogram. therefore, A complete function reference is not, defined in an EXTERNAL statement. The interpretation of the EXTERNAL statement described above is different from that of earlier versions of FORTRAN-lO/20. :f the INOF77 compiler switch is specified (see Sections 16.1.3 and 16.2.3), lhe subprogram names can be intrinsic functions. the names Por compatibility with previous versions of FORTRAN-10/20, of external subprograms can be preceded by an asterisk (* ) or an ampersand (&) within an EXTERNAL statement. For example, EXTERNAL *SIN, &COS declares SIN and COS to be user subprograms. (If a prefixed not an intrinsic function, then the prefix is ignored.) name is Note that specifying an intrinsic function in an EXTERNAL statement without a prefix (that is, 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 the actual argument 1 ist. (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 declarator statement other than a type statement. 7.7 INTRINSIC STATEMENT The INTRINSIC statement allows you to use intrinsic function names as arguments to subprograms. See Section 13.1 for further information on intrinsic functions. The INTRINSIC statement has the form: INTRINSIC fun[,fun] ••• where: fun is the symbolic name of an intrinsic function. The INTRINSIC statement declares each symbolic name included in it to be the name of an intrinsic procedure. This name can then be used as an actual argument to a subprogram, which can use the corresponding dummy argument in a function refe~ence or a CALL statement. The appearance of a generic function name in an INTRINSIC does not cause that name to lose its generic property. 7-18 statement SPECIFICATION AND DATA STATEMENTS NOTE You cannot use a generic-only name in an INTRINSIC statement. The generic name must be the same as an instrinic function name. For example, INTRINSIC LOG is illegal because there is no function named 'LOG'. LOG is the generic name that selects between functions such as ALOG, DLOG, or CLOG. Only one appearance of a symbolic name is permitted in all of the INTRINSIC statements of a program unit. Also, a symbolic name must not appear in both an EXTERNAL and an INTRINSIC statement in a program unit. An example of follows: the use of the EXTERNAL and INTRINSIC statements Main Program EXTERNAL CTN INTRINSIC SIN, COS CALL TRIG(ANGLE,SIN,SINE) CALL TRIG(ANGLE,COS,COSINE) CALL TRIG(ANGLE,CTN,COTANT) Subprograms SUBROUTINE TRIG(X,F,Y) Y = F(X) RETURN END FUNCTION CTN(X) CTN = COS(X)/SIN(X) RETURN END In this example, when TRIG is called with a second argument of SIN or COS, the function reference F(X) references the math library functions SIN and COS; but when TRIG is called with a second argument of CTN, F(X) references the user function CTN. 7-19 SPECIFICATION AND DATA STATEMENTS 7.8 PARAMETER STATEMENT The PARAMETER statement allows you to during compilation. define constants symbolically The general form of the PARAMETER Statement is: PARAMETER (p=c[,p=c) ••. ) where: s~nbolic P is a name. c is a constant expression (except for expressions involving multiplication, division, or exponentiation of complex numbers). (See Chapter 3 for a descr ipt ion of FORTRAN constants.) The constant acquires the same data type as the symbolic name. If the symbolic name is of type integer, real, double precision, or complex, the corresponding expression (c) must be an arithmetic constant expression (see Section 5.1.2). If the symbolic name is of type character or logical, the corresponding expression (c) must be a character constant expression (see Section 5.2.1) or a logical constant expression (see Section 5.3.1), respectively. The data type of a symbolic name defined to be a constant is specified by a type-statement or IMPLICIT statement preceding the defining PARAMETER statement. Also, if the length specified for the symbolic name of a character constant is not the default length of one, its length must be specified by a type-statement or IMPLICIT statement preceding the symbolic name of the constant. NOTE The form and the interpretation to the PARAMETER statement described above are different from those of the PARAMETER statement provided in earlier versions of FORTRAN-IO/20. The earlier version is described below. This form and interpretation can still be used, however a warning message will be issued. This form of the PARAMETER statement is: PARAMETER p=c[,p=c ••• ] The symbolic name acquires the same data type constant. as the During compilation, the symbolic names are replaced by their associated constants, provided the following rules are observed: 1. Symbolic names may appear only where acceptable. 2. Symbolic name references statement definition. 3. Symbolic names must be unique with respect to all other names in the program unit. must 7-20 appear FORTRAN after constants the are PARAMETER SPECIFICATION AND DATA STATEMENTS 4. Symbol ic names must r!ot be redef ined in subsequent statements. 5. Symbolic names must not be used as part of another constant, such as within a character constant or as the count for a Hollerith constant. 6. Symbolic names specification. part of a DATA statements are used to supply the initial values arrays, array elements, substrings, and COMMON areas. of variables, 7.9 must not be used as PARAMETER format DATA STATEMENT The form of th~ data statement. is: DATA nlist/clist/ [[,]nlist/clist/] •.. where: nlist identifies a set of items to be initialized. clist contains the set of values to be assigned the items nlist. in For example, the statement: DATA IA/5/,IB/IO/,IC/15/ initializes variable IA to the value 5, variable IB to the value 10, and variable IC to the value 15. The number of storage locations you specify in the list of variab]es must be equal to the number of storage locations you specjfy in its associated list of values. If not, a warning m€!ssage is output. When the value list specifies more storage locations than the variable list, the excess values are ignored. When the value list specifies fewer storage locations than the variable list, the excess variables are not initialized. The nlist portion of each nlist/clist/ set can contain the names of one or more variables, array names, array elements, character substring names, or labeled COMMON variables. You may specify an entire array (unsubscripted array name) or a portion of an array in a DATA statement nlist as an implied DO loop construct. (See Section 10.4.9.2 for a description of implied DO loops.) The form of an implied-DO list: in a DATA statement is: (dlist,i=n1,n2[,n3]) where: d1ist is a list of array element names, names, or impljed-DO lists. i is the name of an integer index variable. variable, called n1,n2,n3 are integer E~xpressions that can constants and loop index variables. contain 7-21 character substring the loop integer SPECIFICATION AND DATA STATEMENTS 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, and 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 Initial, Terminal, and Increment parameters of the loop must be of type INTEGER. In a DATA statement, references to an array element or substring must be integer expressions in which all terms are either integer constants or indices of embracing implied DO loops. These types of integer expressions can include the exponentiation operator. The clist portion of each nlist/clist/ set can contain one or more numeric, logical, Hollerith, octal, hexadecimal, or character constants. You may specify literal data as either a Hollerith sgecific3tion, for example, SHABCDE, or a string enclosed in single quotes, for example, 'Abcde'. Each ASCII data item is stored left-justified and is padded with blanks if necessary. When you assign the same value to more than one item in nlist, a repeat specification may be used. The repeat specification has the form: n*d where: n is an integer that specifies how many times the value d is to be used. For example, a clist 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 converts the data item to the type of the variable. The type conversion is performed using the rules 9iven for type conversion in arithmetic assignments. (See Table 8-1.) Octal, logical, Hollerith, hexadecimal, and character constants are not converted. Sample Statement Result DATA PRINT,I,0/'TEST',30, 11 77/, (TAB(J),J=1,30)/30*S/ The first 30 elements of array TAB are initialized to S.O. DA TA ( (A ( I , J) , I = 1 , S) , J = I , 6 ) /30 * I . 0/ No conversion required. DATA( (A(I,J) ,I=S,10) ,J=6,15)/60*2.0/ No conversion required. 7-22 SPECIFICATION AND DATA STATEMENTS When character variables are initialized, length conversions are made. The conversion is based on the following rules: 1. If the constant contains fewer characters than the length of the element in nlist, the rightmost character positions of the element are initialized with spaces. 2. If the constant contains more characters than the length of the element in nlist, the character constant is truncated to the right. Character constants and HollErith constants can also be used to initialize numeric variableE. The character string is stored left justified in the numeric variable. When the character string specified is longer than one numeric variable can hold, the string is stored left justified across ES many variables as are needed to hold it. If necessary, the last variable used is padded with blanks up to its right boundary. For character variables, each variable or array exactly one character constant in the data list. For example, assuming that X, statement: Y, and Z are element must have single-precision, the DATA X,Y,Z/'abcdefghijkl'/ causes: X to be initialized to '2bcde' Y to be initialized to 'fghij' Z to be initialized to '~lbbb' When a character 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 iE padded with blanks. For example, assuming that thE variable C is complex, the statement: DATA C/'ABCDE','FGHIJ'/ causes the first word of C to be initialized to 'ABCDE' and its second word to be initialized to 'bbbbb'. The string 'FGHIJ' is ignored. The first word contains the rEal part of the ~omplex variable; the second word contains the imaginary part. In addition, the following twc in DATA statements: forms of bit data constants are allowed O'di ... dn' Z'hi ... hn' where di are octal digits and hi are hexadecimal digits with A-F representing the decimal eGuivalent of 10-15. These constants are right-justified. Note that you can also use the double quote (") form of octal constants as describE'd in Section 3.7. 7-23 SPECIFICATION AND DATA STATEMENTS 7.10 SAVE STATEMENT The SAVE statement retains the values stored in a variable, array, or common block after execution of a RETURN or END statement in a subprogram. The SAVE statement has the following form: SAVE [a[,a] ••• ] where: a is a named common block name (preceded and slash), a variable name, or an array name. followed by a NOTE Ordinarily, the values of all variables are retained after execution of a RETURN or END statement. However, when overlays are used, the SAVE statement must be used to ensure retention of values. An entity specified by a SAVE statement within a program unit does not become undefined upon execution of a RETURN or END statement in that unit. If the entity is in a common block, however, it may be redefined in another program unit that references that common. Procedure names, the names of variables and arrays in a common and dummy argument names cannot be used in a SAVE statement. block, A SAVE statement that does not explicitly contain a list is treated as though it contained a list of all allowable items in the program unit that contains the SAVE statement. If a particular common block name is specified by a SAVE statement in a subprogram of an executable program, it must be specified by a SAVE statement in every subprogram in which that common block appears. NOTE It is not necessary to use the SAVE statement to retain the value of a blank common block; the definition status of blank common is automatically retained after a RETURN or END statement. Also, when the SAVE statement is used, it is not necessary to specify the LINK switch /OVERLAY:WRITABLE when loading a program. 7-24 CHAPTER 8 ASSIGNMENT STATEMENTS Assignment statements assign values to variables, array elements, or character substrings. There are four kinds of assignment statements: 8.1 1. Arithmetic assignment statements (see Section 8.1) 2. Logical assignment statements (see Section 8.2) 3. Statement Label assignment (ASSIGN) 8.3) 4. Character assignment statements (see Section 8.4) statements (see Section ARITHMETIC ASSIGNMENT STATEMENT You use statements of this type to assign numeric values to numeric variables or array elements. Arithmetic assignment statements have the form: v=e where: v is the name of the numeric variable or array element that is to receive the specjfied value. e is an arithmetic expression. In assignment statements, the equal symbol (=) does not imply equality as it would in algebraic E?xpressions; it implies replacement. For example, the expression v=e is interpreted as "the contents of the location identified as v are t:o be replaced by the value of expression e; the previous contents of v are lost." When the type of the specified variable or array element name differs from that of its assigned value, FORTRAN converts the value to the type of its assigned variable or array element. Table 8-1 describes the type conversion operations performed by FORTRAN for each possible combination of variable and value types. 8-1 ASSIGNMENT STATEMENTS Table 8-1: Rules for Conversion in Mixed-Mode Assignments ~---------------r------------------------------------------------------------. Expression Type (e) VariabLe Type (v) ~------------------------------------------.--------------------~ REAL INTEGER COMPLEX DOUBLEPRECISION LOGICAL CHARACTER ~---------------+----------------------------------------------------------------~ Real D C R,I H,L D X Integer F D R,F,I M D X Complex R C,R D R,L R X Doubleprecision o N H,I D H X Logical o D R,I H,L D x Octal o D R,I H,L D x Hollerith D% D% 0& D& D% x Character x x x x x D DoubleOctal* H H D# D H x ~--------------~-------------------------------------------------------------. Legend D = Direct replacement C = Conversion from real to integer with truncation, overflow i ~ possible F = Conversion from integer to real with rounding R = Real part only I = Set imaginary part to 0 H = High-order only L = Set low-order part to 0 M = Convert with no truncation and no rounding N = Convert with rounding; truncation can occur and overflow is possible 0 = Round to one word of precision, overflow is possible X = Not allowed Notes * 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. 8-2 ASSIGNMENT STATEMENTS & Use the first two words of the Hollerith constant. If the Hollerith constant is only one word long, the second word is padded with blanks. % Use the first word of # To convert double-octal ~umbers 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. 8.2 thE~ HollE!rith constant. LOGICAL ASSIGNMENT STATEMENTS Statements of this type are used to assign values to variables and array elements of type logical. Logical assignment statements have the following form: v=e where: v is the name of a variable or array element e is a logical expression For example, assuming that the variables L, F, M, and G logical, the following statements are valid: Sample Statement of type replaced by Results L=.TRUE. The contents of L are logical truth. F=.NOT.G The contents of F are replaced by the complement of the contents of G. M=A.GT.T or M=A)T L=«I.GT.H) .AND. (J<=:K) 8.3 are If A is greater than T, the contents of M are replaced by logical truth; if A is less than or equal to T, the contents of Mare replaced by logical false. This can also be read: If A is greater than T, then M is true, otherwise, M is false. The contents of L are replaced by either the true or false resultant of the expression. ASSIGN (STATEMENT LABEL) ASSIGNMENT STATEMENT The ASSIGN statement is used to assign a statement label constant (a 1 to 5 digit statement number) to a variable name. The form of the ASSIGN statement is: ASSIGN s TO i 8-3 ASSIGNMENT STATEMENTS where: s is a statement number in the current program unit. i is a variable name. For example, the statement: ASSIGN 2000 TO LABEL specifies that the variable 2000. LABEL references the statement number with the exception of complex, double-precision, or character, you can use any type of variable in an ASSIGN statement. Use the ASSIGN statement in conjunction with assigned GO TO control statements (see Chapter 9), or as a format identifier in an I/O statement (See Chapter 10). The ASSIGN statement sets up statement label variables that are then referenced in subsequent GO TO control statements, or in format specifiers in I/O 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.4 CHARACTER ASSIGNMENT STATEMENT The character assignment statement assigns the value of the character expression on the right of the equal sign to the character variable, array element, or substring on the left of the equal sign. The form of the character assignment statement is: v=e where: v is a character variable, array element, or substring. e is a character expression. If the length of the expression on the right side of the assignment is greater than the length of the variable on the left side, the character expression is truncated on the right. If the length of the expression on the right side of the assignment is less than the length of the variable on the left side, the character expression is filled on the right with blanks. 8-4 ASSIGNMENT STATEMENTS FORTRAN-IO/20 allows overlap between the character expression and the character variable, array element, or substring. (That is, the character positions defined in the character variable, array element, or substring can be referenced in the character expression.) For example, the following assignments are allowed: CHARACTER *4 A,B DATA A/'abcd'/,B/'efgh'/ A(1:3) A(2:4) B(2:4) B(1:3) After the above assignment statements, A is 'bcdd', and B is 'eefg'. The expression must be of character data type. You cannot assign numeric value to a character variable, array element, or substring. a Note that assigning a value to a character substring does not affect character positions in the character variable or array element not included in the substring. If a character position outside of the substring has a value previously assigned, it remains unchanged. If the character position is undefined, it remains undefined. Examples of valid and invalid character assignment statements follow. All variables and arrays in the examples are assumed to be of character data type. Valid FILE = 'PROG.2' REVOL(l) = 'MAR'//'CIA' LOCA(3:8) = 'PLANTS' TEXT ( I , J +1) (.2: N-1 ) NAME//X Invalid 'ABC' CHARS (the left side must be a character variable, array element, or substring reference) CHARS 25 (expression on the right must be data type) 8-5 of character CHAPTEn 9 CONTROL STATEMENTS FORTRAN object programs normally execute statement by statement in the order in which they were p~esented to the compiler. The following control statements, however, enable you to alter the normal sequence of statement execution: 1• CAL L (Sec t ion 1 3 • 4 . 2 • :2) 2. CONTINUE 3• DO 4. DO WHILE 5. ELSE (Section 9.2.4) 6. ELSE IF 7. END (Section 9.8) 8. END DO 9. END IF (Section 9.2.4) (Section 9.5) ( Sec t ion 9. 3 ) (Section 9.3.2) ~~HEN (Section 9.2.4) (Sec t ion 9.4) (SE~ction 10. GO TO 11. IF (Section 9.2) 12. IF THEN 13. STOP (Section 9.6) 14. PAUSE 1 5• RET URN ( Sec t ion 13. 4 • '0 9.1) (Section 9.2.-1) (SE~ction 9.7) The CALL and RETURN statements are described in Sections 13.4.2.2 and 13.4.4, respectively. The rernainin9 statements are described in this chapter. 9.1 GO TO STATEMENTS A GO TO statement causes the statement that it identifies executed next, regardless of i~s position within the program. Unconditional There are three kinds of GO TO statements: 9. 1. 1), Compu ted (see Sec t ion 9. 1.2) , and Assigned 9.1.3). 9-1 to be (see Section (see Section CONTROL STATEMENTS 9.1.1 Unconditional GO TO Statements An unconditional GO TO statement specified statement label. transfers program control to the You can position an unconditional GO TO statement anywhere in source program, except as the terminating statement of a DO loop. the The form of the unconditional GO TO statement is: GO TO s where: s is a statement label of an executable statement. For example: GO TO 300 9.1.2 Computed GO TO Statements The form of a computed GO TO statement is: GO TO ( s [, s] ••• ) [ ,] e where: (s[,s] ••• ) is a list of statement labels. e is an integer expression. You may include any number of statement labels in the list of a computed GO TO statement. However, each statement label must appear within the program unit containing the GO TO statement. The same statement label can appear more than once in the list. The value of the expression must be an integer value (it will be truncated if necessary) that is greater than 0 and less than or equal to the number of statement labels given in the list. If the value of the expression is not within this range, the next sequential statement is executed. When a computed GO TO statement is executed, the value of the expression is computed first. The value of the expression specifies the position of the label (within the given list of statement labels) that identifies the statement to be executed next. For example, in the statement sequence: GO TO ( 2 0, 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 CONTROL STATEMENTS 9.1.3 Assigned GO TO Statements The form of an assigned GO TO statement is: GO TO i [[,] (s [, s] ••• ) ] where: i is a variable name and the optional parenthesized list is a list of statement labels. The statement labels specified must appear within the program unit containing the GO TO statement. Assigned GO TO statements must be logically preceded by an ASSIGN statement (see Section 8.3) that assigns a statement label value to the variable i. The assigned GO TO statement transfers program control to the label that has been ASSIGNed. The statement label value assigned must appear within the same program unit as the GO TO statement that uses that value. In statements with a specified list, if i is not assigned one of the statement label values given in the list, the next sequential statement is executed. Examples: ASSIGN 300 TO STAT1 GO TO STATI GO TO STATl, (177,300,777) 9.2 IF STATEMENTS There are four kinds of IF statements: arithmetic (see Section 9.2.1), logical (see Section 9.2.2), logical two-branch (see Section 9.2.3), and block IF (see Section 9.2.4). 9.2.1 Arithmetic IF Statements The form of the arithmetic IF statement is: IF (e) sl, s2, s3 where: e is an expression enclosed within parentheses and sl, s2, and s3 are statement labels of three executable statements appearing within the program unit containing the IF statement. The expressIon e must not be of type complex. The same statement label can appear more than once in the IF statement. 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 label sl. is transferred to the sta tement 2. Equal to 0, control identified by label s2. is transferred to the statement 9-3 CONTROL STATEMENTS 3. Grea ter than 0, con trol identified by label s3. is transferred to the sta tE~ment Examples: IF(ETA)4, 7~ 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. 12 IF ( KA P PA- L (1 0) ) 2 0 , 14 , 14 9.2.2 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. Logical IF Statements The form of the logical IF statement is: IF (e) st where: e is any expression. complex. The expression st is an executable statement. must not be of type If the value of the expression is true (negative), control is transferred to the executable statement within the IF statement. If the value of the expression is false (nonnegative), control is transferred to the next sequential executable statement. The statement you give in a logical IF statement may be any executable statement except a DO statement, an END statement, or another logical IF statement. Examples: IF(T.OR.S) X=Y+l Performs an arithmetic assignment operation if the result of the IF is true. IF(Z.GT.X(K» Performs a subroutine call if the result of the IF is true. CALL SWITCH(S,Y) IF(K.EQ.INDEX) GO TO 15 Logical Two-Branch IF Statements 9.2.3 '[''lP Performs an unconditional transfer if the result of the IF is true. format of a logical two-branch IF statement is: [l-' ( e) 5,1, s2 9-4 CONT~OL STATEMENTS where: c is any expression, and sl and s2 are statement labels appearing within the program unit containing the IF statement. The expression must not be of type complex. Logical two-branch IF statemer;ts transfer control to either statement sl or s2, depending on the corrputed value of the given expression. If the value of the given logical .expression is true (negati.ve), control is transferred to statement 51. If the value of the expression is false (nonnegative), control is transferred to statement s2. Examples: Transfers control to statement LO if LOGl is true (negative) ; 0therwise transfers control to statement 20. IF (LOG1) 10,20 IF (A.LT.B.AND.A.LT.C) 9.2.4 31,32 Transfers control to statement if A is less than both B and transfers control to statement i f A is qreater than or equal I~ i ther B or C. 31 C; 32 to Block IF Statements Block IF statements conditionally execute blocks statements. The four block IF statements are: • IF THEN • ELSE IF THEN • ELSE • END IF These statements are used in block construct has the followinQ form, statements are optional: - (or groups) of IF constructs. The block IF where the ELSE IF THEN and ELSE IF (e) THEN block ELSE IF (e) THEN block ELSE block END IF where: e is block is a sequence of zero or more complete. FORTRAN statements. This sequence is called a statement block. d logical expression. 9-5 CONTROL STATEMENTS Each block IF statement, except the END IF statement, has an associated statement block. The statement block consists of all the statements following the block IF statement up to (but not including) the next block IF statement in the block IF construct. The statement block is conditionally executed based on the values of logical expressions in the preceding block IF statements. A statement block can be empty. The IF THEN statement begins a block IF construct. The block following it is executed if the value of the logical expression in the IF THEN statement is true. The first statement of the block cannot directly follow the THEN on the same line. For example, the following is ilLegal: IF (T.LT.X) THEN T X The correct form is: IF (T.LT.X) THEN T = X The ELSE statement specifies a statement block to be executed if no preceding statement block in the block IF construct was executed. The ELSE statement is optional. The ELSE IF THEN statement is similar to the ELSE statement, except it requires an additional condition for execution. The ELSE IF THEN statement specifies a statement block to be executed if both the value of the logical expression in the ELSE IF THEN statement is true, and no preceding statement block in the block IF construct was executed. A block IF construct can contain any number of ELSE IF THEN statements. The ELSE IF THEN statement is optional. The END IF statement terminates the block IF construct. Figure 9-1 describes the flow of control for four examples of block IF constructs. 9-6 CONTROL STATEMENTS CONTROL STATEMENTS Flow of Contml Construct IF (e) THEN block END IF Execute block IF (e) THEN block1 ELSE block2 END IF IF (e 1) THEN block 1 ELSE IF (e2) THEN block2 END IF IF (e 1) THEN block1 ELSE IF (e2) THEN block2 ELSE IF (e3 ) THEN block3 ELSE block4 END IF False Execute block1 Execute block1 I Execute block2 Execute blo,ck2 False Execute block1 Execute block2 Execute block3 Execute block4 MR-S-2525-83 Figure 9-1: Examples of Block IF Constructs After the last statement in a statement block is executed, control passes to the next executable statement following the END IF statement. Consequently, at most one statement block in a block IF construct is executed each time the IF THEN statement is executed. 9-7 CONTROL STATEMENTS these ELSE IF THEN and ELSE statements can have statement labels, but labels cannot be referenced. The END IF statement can have a statement label to which control can be transferred, but only from within the block IF construct. Section 9.2.4.1 describes restrictions on statements in a statement block. Section 9.2.4.2 describes examples of block IF constructs. Section 9.2.4.3 describes nested block IF constructs. can contain any 9.2.4.1 Statement Blocks - A statement block executable FORTRAN statement except an END statement (see Section statement block, but you 9.8). You can transfer control out of a Note that you cannot cannot transfer control back into the block. transfer control from one statement block into another. DO loops cannot ove~lap statement blocks. When a statement block contains a DO statement (see Section 9.3), it must also contain the DO loop's terminal statement or END DO statement. Conversely, if a block IF construct appears within the range of a DO loop, the corresponding END IF statement must also appear within the range of that DO loop. 9.2.4.2 Block IF Examples - The simplest block IF construct consists of the IF THEN and END IF statements; this construct conditionally executes one statement block. Form Example IF (e) THEN block END IF IF (LOWER.LE.UPPER) THEN MIDDLE=(LOWER+UPPER)/2 END IF The statement block consists of all the statements between the IF THEN and END IF statements. The IF THEN statement first evaluates the logical expression (e), (LOWER.LE.UPPER). If the value of e is true, the statement block is executed. If the value of e is false, control transfers to the next executable statement after the END IF statement; the block is not executed. The following example contains a block IF construct with THEN statement: Form Example IF (el) THEN blockl ELSE IF (e2) THEN block2 END IF IF (ITEM.LT.A(MIDDLE» THEN UPPER=MIDDLE-I ELSE IF (ITEM.GT.A(MIDDLE» THEN LOWER=MIDDLE+l END IF an ELSE IF Blockl consists of all statements between the IF THEN and the ELSE IF THEN statements; block2 consists of all the statements between the ELSE IF THEN and the END IF statements. If ITEM is less than A(MIDDLE), blockl is executed. If ITEM is not less than A(MIDDLE), A(MIDDLE), block2 is executed. 9-8 but ITEM is greater than CONTROL STATEMENTS If ITEM is not less than A(MIDDLE) and ITEM is not greater than A(MIDDLE), neither blockl nor block2 is executed; control transfers directly to the next executable statement after the END IF statement. The following example contain5 a statement: block IF construct Form Example IF (e) THEN block1 ELSE block2 IF (ITEM.GT.A(MIDDLE» LOWER=MIDDLE+1 ELSE S8ARCH=MIDDLE RETURN END IF END IF with an ELSE THEN Block1 consists of all the statements between the IF THEN and the ELSE statements; block2 consists of all the statements between the ELSE and the END IF statements. If ITEM is greatE~r than A(MIDJ)LE), block1 is executed. If ITEM is not greater than A(MIDDLE), block2 is executed. 9.2.4.3 Nested Block IF Constructs - A block IF construct can be included in a statement bloc~ of another block IF construct. But the nested block IF construct m~st be completely contained within a statement block; it must not ~verlap statement blocks. The following example contains a nested block IF construct. Form Example FUNCTION SEARCH(A,N,ITEM) CHARACTER*(*) A(N),ITEM INTEGER SEARCH,N,LOWER,MIDDLE,UPPER LO'~ER=l UPlI?ER=N IF(LOWER.LE.UPPER) THEN MIDDLE=(LOWER+UPPER)/2 IF (e) THEN blockl IF (e) THEN 10 blocka ELSE IF (e) THEN blockb ELSE blockc IF (ITEM.LT.A(MIDDLE» THEN UPPER=MIDDLE-1 ELSE IF (ITEM.GT.A(MIDDLE» THEN LOWER=MIDDLE+1 ELSE SEARCH=MIDDLE RETURN END IF END IF GOTOIO END IF END IF 20 SEARCH=O RE'rURN END 9-9 CONTROL STATEMENTS If LOWER is less than or equal to UPPER, blockl is executed. Block1 contains a nested block IF construct. If ITEM is less than A(MIDDLE), blocka is executed. If ITEM is greater than A(MIDDLE) blockb is executed. If ITEM is equal to A(MIDDLE), blockc is executed. If LOWER is greater than UPPER, control is transferred to the first The nested IF executable statement after the last END IF statement. construct is not executed. 9.3 DO STATEMENT The two types of DO statements are: 1. Indexed DO (DO statement) 2. Pretested indefinite DO (DO WHILE statement) The indexed DO statement is described in Section WHILE statement is described in Section 9.3.2. 9.3.1 9.3.1, ,=Fld the DO Indexed DO Statement DO statements simplify the coding of iterative procedures; that is, the statements in the DO statement range are executed repeatedly a specified number of times. The form of an indexed DO statement is: Indexing Parameters /L ---=--TERMINAL STATEMENT LABEL INDEX VARIABLE i = el, \~:-::-IN~C~R=E~M=E~NT=\ (OPTIONAL) TERMINAL PARAMETER PARAMETER INITIAL PARAMETER Mns1760·S1 where: s Terminal statement label s identifies the last statement of the DO statement range. The statement must follow the DO statement in the same program unit. s is omitted, then the loop must be terminated by an END DO statement (see Se c t ion 9. 4) • The terminal statement can be any executable statement than one of the following: • Unconditional or assigned GO TO statement • Arithmetic IF :n logical two-branch IF statemE-?nt • Block IF, ELSE IF, ELSE, or END IF statement 9-10 other CONTROL STATEMENTS • RETURN statement • STOP statement • END statement • DO statement If the terminal statement is a logical IF, it can contain any executable statement except one of the following: i • DO statement • Block IF, ELSE IF, ELSE, or END IF statement • END statement • Another logical IF statement Index variable i is an unsubscripted numeric variable whose value is defined at the start of the DO statement operations. The index variable must not be of type complex. The index variable is available for use execution of the range of the DO statement, value within the DO loop does not change the the DO loop will execute. The DO loop index available for use in the program when: throughout each but altering its number of times variable is also a. Control is transferred outside the range of the DO loop by a GO TO, IF, cr RETURN statement located within the DO range b. Control is transferred outside the range of the DO loop by an I/O statement with either or both the options END= or ERR= (see Chapter 10) c. A subprogram is executed from within the DO statement range having the index variable as an argument or in COMMON e1 Initial parameter el assigns the index variable i its initial value. This parameter can be any expression, but cannot be of type complex. e2 Terminal parameter e2 provides the value used to determine how many repetitions of the DO statement range are performed. This parameter can be any expression, but cannot be of type complex. e3 Increment parameter e3 specifies the value to be added to the initial parameter (e!1) on completion of each cycle of the DO loop. The increment parameter is optional. If e3 and its preceding comma are omitted, e3 is assumed to be equal to 1. This parameter can be any expression, but cannot be of type complex. 9-11 CONTROL STATEMENTS 9.3.1.1 Executing an Indexed DO Statement - The indexing parameters el, e2 or e3 can be any expressions. Their values are calculated only once, at the start of each DO loop operation, to determine the values for the initial, terminal, and increment parameters. If necessary, the initial, terminal, and increment parameters are converted, before use, to the data type of the index variable. The number of times that a DO loop will execute, called the count, is specified by the formula: iteration MAX(INT«e2-el+e3)/e3) ,0) If the iteration count is less than or equal to zero, the body of the loop is not executed. The index variable retains its assigned value (el) • NOTE The interpretation of the iteration count described above is different from that of earlier versions of FORTRAN-I0/20. If the /NOF77 compiler switch is specified (see Sections 16.1.3 or 16.2.3), and the iteration count is less than or equal to zero, the body of the loop is executed once. Since the iteration 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 (el); and the iteration count is established. 9.3.1.2 DO Iteration Control - At the end of each DO loop cycle, following steps are executed: is (e3) added to the the 1. The value of the increment parameter index variable. 2. The iteration count is decremented. 3. If the iteration count is greater than zero, control transfers to the first executable statement after the DO statement for another iteration of the loop. 4. If the iteration count is less than execution of the DO loop terminates. or equal to zero, Exit from a DO loop upon completion of the number of iterations specified by the loop count is referred to as a normal exit. If no other DO loop shares the terminal statement, or if this DO loop statement is outermost, control passes to the first executable statement after the terminal statement of the DO loop. The final value of the index variable is the value determined by 1. 9-12 step CONTROL STATEMENTS NOTE: The interpretation of the index variable described above is different from that of earlier versions of FORTRAN-10/20. ! f tile /NO~"77 compiler switch is specified (see Sections 16.1.3 or 16.2.3), the final value of the index var:.able of the DO statement is undefined after a normal loop exit. 8xit 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. Th~.s is called an extended range DO loop (see Section 9.3.5). When execution of a DO loop terminates, and other DO loops share its terminal statement, control transfers outward to the next most enclosing DO loop in the DO nesting structure (see Section 9.3.4). Examples of DO Iteration Control: 100 DO 100 I = 1,10 J=I After execution of these statements, 1=11 and J=lO. switch is specified, I is undefined and J=lO). 200 L=O DO 200 K L=K the /NOF77 (If the /NOF77 5,1 After execution of these statements, K=5 and switch is specified, K is undefined and L=5). 9.3.2 (I f L=O. DO WHILE Statement The DO WHILE statement is simiJ.ar to the DO statement described in Section 9.3.1. Instead of executing a fixed number of iterations, the DO WHILE statement. executes for as long as a logical expression contained in the statement continues to be true. The form of the DO WHILE statement is: DO [s[,]] WHILE (e) where: is the label of an executable statement that must physically follow in the same program unit. is a logical express:on. 'rhe DO WHILE statement tests the logical expression at the beginning of each execution of the loop, including the first. If the value of the expression is true, the statements in the body of the loop are executed; if the expression is false, control transfers to the statement followinq the loop. If no Label appears in a DO WH:LE statement, the DO WHILE loop must be terminated with an END DO statement (see Section 9.4). 9-13 CONTROL STATEMENTS The following example demonstrates the use of the DO WHILE statement: CHARACTER*132 LINE 1=1 LINE (132:) = IX I DO WHILE (LINE(I:I) I = I + 1 END DO 9.3.3 .EQ. I I) The Range of a DO Statement The range of a DO statement is defined as the series of statements that follows the DO statement, up to and including the specified terminal statement or END DO statement. If another DO statement appears within the range of a DO statement, the range of that statement must be entirely contained within the range of the first DO statement. More than one DO statement may have the same labeled terminal statement but not unlabeled END DO statement. (See Section 9.3.4, Nested DO Statements.) If a DO statement appears within an IF block, ELSE IF block, or ELSE block (see Section 9.2.4), the range of the DO statement must be contained entirely within that block. If a block IF statement appears within the range of a DO statement, the corresponding END IF statement must also appear within the range of the DO statement. 9.3.4 Nested DO Statements One or more DO statements can be contained within the range of another DO statement. This is called nesting. The following rules govern the nesting of DO statements: 1. The number of nested levels restricted to 79 DO loops. (DO loop 2. The range of each nested DO statement must be entirely within the range of the containing DO statement (such as, they cannot overlap). For example: Valid Invalid DO 1 DO 1 DO 2 DO 2 ~ c= C DO 3 9-14 The ranges of loop DO 2 and DO 3 overlap MR·S·1758·81 within DO loop) is CONTROL STATEMENTS 3. More than one DO loop within a nest of labeled DO loops can 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. Only a statement that occurs within the range of the innermost DO statement can use the statement label of the shared terminal statement for transfer of control. For example: DO 4 - - - ..- Outermost DO Loop 004 _ _ un 00_4_ _ [I~..- Innermost DO Loop - - - . . - Terminal Statement MR-S-1759-81 Although all four DO loops share the same terminal statement, the terminal statement "belongs" to the innermost DO loop. 4. Nested loops cannot share an unlabeled END DO statement. Each unlabeled END DO terminates exactly one DO loop. For example: Correctly Nested DO Loops Incorrectly Nested DO Loops DO 10 1= 1,20 DO 10 1=1,5 DO J=1,!i DO J= 1,10 DO K=1,10 CONTINUE END DO END DO [ END DO 10 9.3.5 CONTINUE Extended Range By following certain rules, it is possible to transfer out of a DO loop, perform a series of statements elsewhere in the program, and then transfer back into the DO loop. The statements that are executed after a transfer out of a DO loop and before a transfer back into the same DO loop are collectively known as the "extended range." A DO loop that permits transfer in and out of its range is called an extended range DO loop. 9-15 CONTROL STATEMENTS NOTE ;'his feature makes the flow of a program difficult to follow, does not conform to the FORTRAN-77 standard, ;Ind is therefore discouraged. "'he following rules govern the use of extended range DO loops: The statement that causes the transfer out of the DO loop 'oust be contained within the most deeply nested DO (innermost loop having the same terminal statement). This loop must ~lso contain the statement to WhICh the extended range r-eturns. I. A transfer into the ranqe of a DO statement is permitted only if the transfer is made from the extended range of that DO ~; ta temen t . The extended range of a DO statement must not contain another s ta temen t . )")0 4. The extended range of a DO statement cannot change the v~riable or indexing parameters of the DO statement. ~ You can call a subprogram within an extended range. The following example illustrates the use loop: of an extended index range DO DIMENSION TABLE(10,5), VALUE(10) LOGICAL LOGARR(lO) 1)0 1000 I = 1, 10 An extended range DO loop If (LOGARR(I» GOTO 500 Test logical array item I=K CALL SUBROT(K) Invoke subroutine using current index value DO 2 () 0 J = 1, 5 Nonextended range loop TABLE(I,J) 0 CONTINUE :.;00 GOTO 2000 VALUE(I) )000 CONTINUE :: 000 2100 Extended range invocation Invoke function GETVAL with current index Terminal statement for outer loop GETVAL(K) STOP TYPE 2100, I FORMAT (' I = " I 2) LOGARR(I) = .TRUE. GOTO 500 Extended range starts Extended range ends and r.::eturns END 9.3.6 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 occurs, the value of the controlling DO loop's index variable is defined as the current value. 9-16 CONTROL STATEMENTS 2. A transfE~r into the r,3.nge of a DO statement is permitted it is made from the ectended range of the DO statement. 3. You can call a subprogram from within the range of any: a. b. c. if DO loop nested DO loop extended ranqe 101)p (in which you leave the loop through a GO TO, execu~e statements in the extended range, and return to the oriqinal loop) The following examples illustrate the transfer from within the ranges of nested DO statements: Valid Transfers Invalid Transfers 01 01 ~. operations permitted .. ~"""I--_e_xt_ended~rangle MR-S-17,7-81 9.4 END DO STATEMENT The END DO statemE'nt terminatE!s the range of a DO or DO WHILE statement. The END DO statemE~nt must be used to terminate a DO block if the DO or DO WIULE statement defining the block does not contain a terminal-statement label~ The END DO statement may also be used as a labeled terminal statement if the DO or DO WHILE statement does contain a terminal-statement label. The form of the END DO statemerlt is: END DO 9.5 CONTINUE STATEMENT The form of the CONTINUE statement is: CONTINUE Execution of the CONTINUE statE~ment has no effect. the terminating statement of a DO loop. 9-17 It may be used as CONTROL STATEMENTS In the following example, the labeled CONTINUE statement legal termination for the range of the DO loop. provides a DIMENSION STOCK(lOO) DO 20 1=1, 100 STOCK(I)=O CALL UPDATE (STOCK(I» IF(STOCK (I) .EQ. 0) GO TO 30 20 CONTINUE STOP 30 TYPE 35 35 FORMAT (' UPDATE ERROR') END 9.6 STOP STATEMENT Execution of the STOP statement causes program execution to be terminated. A descriptive message may optionally be included in the STOP statement to be output to your terminal immediately b«~fore program execution is terminated. The form of the STOP statement is: STOP [n] where: n is an optional decimal integer constant of up to 6 digits, or a character constant. The constant is printed at the terminal when the STOP statement is executed. You can have any number of characters in the character constant. You can use continuation lines to accommodate large character strings. The constant is printed without leading zeroes, unless they are specified in the statement. NOTE The word STOP is not printed when the STOP statement is executed unless the word STOP is included in the statement as a character constant. The following examples show the results of executing STOP statements that contain a 6-digit decimal string and a character constant. 10 PROGRAM TEST STOP 123456 END EXECUTE STOP1.FOR FORTRAN: STOPl TEST LINK: Loading [LNKXCT TEST execution] 123456 CPU time 0.1 Elapsed time 0.3 9-18 CONT~OL 10 STATEMENTS PROGRAM TEST STOP 'The prograrr has stopped' END EXECUTE STOP2.FOR FORTRAN: STOP2 TEST LINK: Loading [LNKXCT TEST execution] The program has stopped CPU time 0.1 Elapsed time 0.3 9.7 PAUSE STATEMENT Execution of a PAUSE statement suspends the execution of the object program and gives you the option of continuing execution of the program, exiting from the program, or beginning a TRACE operation. The form of the PAUSE statement is: PAUSE [n] where: n is an optional integer constant of up to 6 digits, or a character constant. The constant is printed at the terminal when the PAUSE statement is executed. You can have any number of characters in the character constant. You can use continuation lines to accommodate large character strings. The constant is printed without leading zeros, unless they are specified in the statement. If execution of the program is resumed after a PAUSE, program control continues as if a CONTINUE had been executed. Execution of the PAUSE statement causes the word PAUSE, the optionally specified constant, and the following prompt to be printed at the terminal: Type G to Continue, X to Exit, T to Trace The responses to this prompt are: G continues program execution at following the PAUSE statement. X causes program termination. T produces a trace back list at the terminal. This list consists of invoked routine names and locations, plus the location and module names of the callers of those routines. Using this information you can track the active path of execution from the main program to the PAUSE trace routine. (See Section 13.4.1.32 for a detailed description of this feature.) 9-19 the statement immediately CONTROL STATEMENTS PROGRAM PTEST PAUSE PAUSE 234 PAUSE 'Character String' END EXECUTE PTEST.FOR FORTRAN: PTEST PTEST LINK: Loading [LNKXCT PTEST execution] PAUSE Type G to Continue, X to Exit, T to Trace. G PAUSE 234 Type G to Continue, X to Exit, T to Trace. G PAUSE Character String Type G to Continue, X to Exit, T to Trace. X CPU time 0.3 9.8 Elapsed time 18.8 END STATEMENT This statement signals FORTRAN that the physical end of a program unit has been reached. END is an executable statement. The general form of an END statement is: END The following rules govern the use of the END statement: 1. This statement must be the last physical statement source program unit (main program or subprogram). 2. When executed in a main program, the END statement has the effect of a STOP statement; in a subprogram, END has the effect of a RETURN statement. 3. An END statement may be labeled, but it must not be continued (that is, it must appear only on an initial line). 9-20 of a CHAPTER 10 DATA TRANSFER STATEMENTS FORTRAN I/O statements are divided into three categories by as follows: function, 1. Data Transfer Statements transfer data between memory and files. The "files" can be devices such as TTY: or MTA:. Internal files and ENCODE/DECODE statements are used for memory-to-memory data transfers. 2. File Control Statements associate and disassociate files and FORTRAN logical unit numbers, and can specify characteristics of such an association. 3. Device Control Statements position files. For example, using the device control statements you can position magnetic tape to a particular file or record. This chapter describes data transfer statements. file-control and device-control statements. Chapter 11 describes Table 10-1 lists the three categories of I/O statements, the statements within each category, and the sections in which each I/O statement is further described. 10-1 DATA TRANSFER STATEMENTS Table 10-1: FORTRAN 110 Statement Categories Categories Statements Sections Data Transfer READ WRITE REREAD ACCEIYf TYPE PRINT PUNCH ENCODE DECODE Internal READ Internal WRITE OPEN CLOSE INQUIRE FIND REWIND UNLOAD BACKSPACE ENDFILE SKIPRECORD SKIPFILE BACKFILE 10.5 10.6 10.7 File Control Device Control Table 10-2, on the statement forms. tab-divider, 10.8 10.9 10.10 10.11 10.12 10.12 10.12 10.12 11.2 11.4 11.7 11.8.1 11.8.2 11.8.3 11.8.4 11.8.5 11.8.6 11.8.7 11.8.8 summarizes 10-2 all the data transfer DATA TRANSFEd STATEMENTS Table 10-2: Summary of Data Transfer Statement Forms Data Access Statement Construct Section Sequential Formatted (FORMAT Statement) READ(UNIT un,FMT fI ,END = sll ,ERR= sll ,IOSTAT- iosilliolistl READ( un,FMT -- fI ,END - s II ,ERR = s II ,IOSTAT = ios III iolist I READ( un. fI ,END - sII,ERR= sll ,JOSTAT = ioslli iolistl READ fI ,iolist I READ(UNIT-*,FMTo /l,END-sll,ERR -sll,IOSTATc. iosilliolistl 10.5.1.1 WRITE(UNIT, un,FMT -fi.ERR-sll,IOSTAT=iosDliolistl WRln.:( un,FMT - flERR - sll ,lOSTAT = ioslHiolistl WRITE( un, fI ERR-slI,lOSTATc iosilliolistl 10.6.1.1 W({ITI': f1.iolist I WRITE (UNIT - *,FMT - fi ,FRR - sll ,IOSTAT ~ iosPliolistl 1<i<:I{I':'\I)IF1\l'J' t[.l-:NJ) In':I{EAJ) {'1.lolist I sl.EHf{ sll,lOSTAT ioslJliolistl ;iJ.i.] \(TI',I'TIFMT f'lYNJ) \('( '1':\ ''I' f'I.iolisll sl.EH,I{ sllJOSTAT iosiJiiolistl ; iI.h.1 TYI'Eil·iV1T· n.Elm TYPE f'I.iolis! I "II.J(JSTA'!' ioe,llliolistl I'I.EIn{ ,.:II.H)STAT iosliJiolistl sll.IUS,\,AT io"liJiolis!1 II{IN'J'!VMT I) III i PRINT fI ,iolist I l'l!:\'(,IIIFMT fl.J-:I{H j'llNCII l'I.iollstl 1';~(:OJ)E(l'.f'.al.EI{f{ 1)/':<'( )DEIl'.Lal.l~KJ-{ Sequential Formatted (List Directed) .-;II.J(S'I'AT ,.: II.JUSTAT I'.) ] I. J ioslJiiolistl ios ill iolis! I III I~ READ(UNIT - un,FMT ~- *I,END - sll,ERR = sll ,lOSTAT = iosilliolistl READ( un,FMT - *I.END - sll ,ERR = sll ,lOSTAT= iosDliolistl un. *1.END~sll,ERR=sll,lOSTAT=ioslliiolistl READ( READ *1 ,iolist I READ(uNIT- *,FMT ~ *I,END sll,ERR-sll,IOSTAT-iosIHiolistl 10.5.1.:3 WRlTE(uNJT - un,FMT = *1 ,ERR - s II ,lOST AT = ios DI iolist I un,FMT- *1,ERR~sll,IOSTAT=iosDliolistl WRI'I'E( WRITE( un, ~I ,ERR = sll ,lOSTAT= ioslJl iolistl 10.6.1.3 \\'I{ITE 'I.ioli,,! I WRITE(UNIT = ';',FMT - *1 ,ERR- sll ,lOSTAT = ioslHiolistl i{I·:I<I-:ADIF1\1T'I.i<:l\'[) I~ F H I':A D"I.IOII:"t I ~ II.Elm ,.:I.JUSTAT iosliJlOiI,.:t I \('('!':I'TI1'1\l'I' 'I.END \(.(' 1·:I>'I"I.iolist I o-II.EHI\ ,,11.lOSTAT io"liJio]i"tl TYPI'>v:vn I.EHH TY 1'1':'I.iolist I ,,11.l1)STAT Im;lllioli"tl 10.9.2 'UINTIFMT sll.OS'I'AT lOslljiolist I 10.10.2 s: .IUS'I'AT io:"l!liolistl 'I.":HH :(i 1-' ~ PRINT *1 ,iolist I !'l'NCIIIFMT 'IYIW I'll'~ (' III. i III i st I 10-3 1(' 11.2 DATA TRANSFER STATEMENTS Table 10--2: Summary of Data Transfer Statement Forms (ConLl Data Access Statement Construct ~;('qu('nti<ll Formatted ,:\Al\H:J.lST Statement! /{EA /)1 I J N IT HEAD( l.TNIT /IUi./.4 ]{E.\/)( un.FMT lI<lnwl.END sll.Elm· sll.IOSTAT iosll \lfl.:\':\1 L namP! .END ;.;11.Elm· s IIJOSTAT - ins il llllYi\1T nanH'I.E]\;J) sHElm sll.lOSTAT - ioslJ IITl.NML nall1l'l./<:ND sll.ERR s II.JOSTAT io;.; II 1111. nanwl.END sll.Elm ;.;II.IOSTAT iosll WI{ITEJ 11NI'I' WHITEIUNJT WHITEI WHITEr \VHJTEI Illl.F!\1T 1Ii1111('I.EHH sll.IOSTAT insll I1I1.Ni\lL 1l<lIll<'l.EHH s 1I.Ji )STAT iosll lIrlYMT nanwl.EJ{H ;.;II.l0STAT io;.;IJ I1I1.NML naml'I.EJm ;.;II.H)STAT insll nallll'l.EJU{ sll./OSTAT illsl J lin. /IUi /.1 I\E.\/)( I{EADI Sequential Unformatted Direct Formatted READ( UNIT - unl ,END ~ s II ,ERR ~ s II ,IOSTAT = ios III iolist I READ( unl,END = sll ,ERR - sll JOSTAT- ioslliiolistl 10.5.2.1 WRITE (UNIT = unl ,ERR = sll ,IOSTAT- ioslll iolistl WHITE( unl,ERR -sll,IOSTAT~iosllliolistl 10.6.2.1 HEAD(UNIT- un,FMT ~ f,REC - rnl,ERR sll,lOSTAT~ ioslliiolistl READ( un.FMT = f,REC - rnl ,ERR - sll ,IOSTAT~ ioslHiolistl READ( un, f,HEC-rnl,ERR- sll,IOSTAT~iosllliolistl IU:ADI un'rn.F\rr I' I.EJu{ ;.;II.IOS'I'AT iosillinlisli HEADI 11111'11. r I,EHH sll.lOSTAT iosliliolisll 10.5.1.2 WRITE(UNIT~un,FMT 10,6.1.2 WRITE( WHITE( \VJ{IT/':I \rJ{]TEI Direct Unformatted Section f,REC rnl,EHR-sll,IOSTAT un,FMT ~ f,HEC - rnl ,ERH - sll,IOSTAT un, f,REC=rnl,ERR sll,IOSTAT un'rn.FMT f I.EJm ,1i.IOSTAT 1I1l'1'll, r I,Elm 'ill.lOSTAT iosilliolistl ioslliiolistl iosilliolistl ins III inlist I io;.;ll/iolist I READ(UNIT - un,REC ~ rnl ,ERH ,'co sll ,lOSTAT - ioslliiolistl READ( un,REC - rnl ,ERR - s II ,IOSTAT = ios III iolist I J{EADI un'rn I.Elm sll.IOSTAT io;.;ll/iolistl 10.5.2.2 un,REC - rnl ,ERR = sl/ ,IOSTAT= ioslliiolistl un,REC ~ rnl ,ERR - sll ,lOSTAT~ ioslliiolistl IIn'rn 1.f<:HH ;.;II.10STAT iosilliolistl 10.6.2.2 WRITE (UNIT WRITE( Key: UNIT- un is a FORTHAN logical unit number or internal file specifier (Section 10.4,3). UNIT-* is a default unit specification used with the READ Statement to read from CDR, and with the WHITE Statement to write to LPT: (see Section 10.4.3). REC~rn is a direct-access record number (Section 10.4.4). IIIl rn I" an all(,1'nat(' W<l\' of specifying Logical Unit NumiJl'r and n'cord numhc'r of a riirectI (j ,-l.·1 I. ~1c('('"S transfer! SI'ct Ion FMT~f is FORMAT-statement formatting; iolist is optional (Section 1O.4.5.ll. FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). F!\IT nan\(' I\' \1 I. . is th(' ;1I1('rnal in' form of Ihl' NA:\1FLlST st;tll'nwnt f;1I'mal ;';J)('cifi!'1' ISection 1().·L'J,:~1 END"'-'s is an optional end-of-file transfer specifier (Section 10.4.6), ERR- s is an optional error transfer specifier (Section 10.4.71. IOSTAT= ios is an optional 1/0 status specifier (Section lO.4.S). iolist is a data transfer 110 list ISection 10.4.9). 10-4 DATA TRANSFER STATEMENTS 10.1 DATA TRANSFER OPERATIONS Data transfer statements are used to transfer data between memory and files or between memory and memory. Data can be transferred sequentially (sequential access) or randomly (direct access). 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 data transfer statement 2. A list defined by a 3. FORMAT specifications statement ~AMELIST statement referenced in the The appearance and arrangement of transferred data by: data transfer be specified can 1. Format specifications located in either a FORMAT statement or an array (FORMAT-statement I/O) 2. The contents of an I/O list 3. An I/O list defined (list-directed I/O) in a NAMELIST statement (NAMELIST I/O) These three methods are known collectively as formatted I/O. In contrast to formatted I/O transfers, FORTRAN has several methods for transferring data without regard for the type and arrangement of the data being transferred. These methods are known collectively as unformatted I/O. Unformatted I/O transfers are particularly useful when you want the internal (memory) representation of the data being transferred to be the same as the external (file) representation of the data. In addition, unformatted data transfers are generally faster than formatted transfers. This is because unformatted data transfers do not convert the data to or from its ASCII representation during the transfer. The following sections describe the types of access available, the types of data transfers available, and the statements used for I/O transfer operations. 10.2 DATA ACCESS There are two forms of access available sequential These forms are described in the following sections. 10.2.1 and direct. Sequential Access If the data access is sequential, the data records are transferred in a serial fashion to or from the external data file. Each sequential-access input stateMent transfers the next record(s) from the accessed data file, such that data records are transferred in the same order that they appear in the file. 10--5 DATA TRANSFER STATEMENTS 10.2.2 Direct Access If the data access is direct, the data records are transferred to or from a file in any desired order, as specified by a record number in the data transfer statement. (Section 10.4.4 describes specifying records in data transfer statements.) Direct-access transfers, however, can be made only to files residing on disk that have been previously set up (using an OPEN statement) for direct access. Direct-access files must contain identically sized records that are accessed by a record number. You must use the OPEN statement to establish direct access (see Section 11.2). Execution of the OPEN statement must precede the first data transfer statement for the specified logical unit. 10.3 FORMATTED AND UNFORMATTED DATA TRANSFERS The term "formatted data transfer" describes an intermediate step that occurs during a data transfer. This intermediate step, which does not occur in an unformatted data transfer, converts the data from its internal (memory) representation to a different external (file) representation. (Formatted data transfers are described in Section 10.3.1.) An unformatted data transfer refers to the transfer of data with no change to the data during the transfer. In an unformatted data transfer, the internal (memory) representation of the data and the external (file) representation of the data are the same. (Unformatted data transfers are described in Section 10.3.2.) 10.3.1 Formatted Data Transfers In a formatted data transfer, the internal and external format of data is controlled during the data transfer in one of three ways: 1. the FORMAT-Statement Formatting The data transfer statement contains a statement number, a numeric array name, a character expression, or an integer, real, or logical variable as a format identifier. The statement number references a line that contains a FORMAT statement. The array name references an array that contains a format specification. The value of the character expression is a format specification. The integer, real, or logical variable references a FORMAT statement number that was assigned with an ASSIGN statement. In the following example, the data transfer statement contains a statement number of a FORMAT statement. The FORMAT statement, in turn, contains edit descriptors that control the formatting of the data during the transfer: WR I T E 101 (2 2 , 1 01 ) X, J , Z FORMA T ( 1 X, FlO. 5, I 5 , F 6 . 4 ) See Section 10.4.5.1 for more information on FORMAT-statement formatting. 10-6 DATA TRANSFER STATEMENTS 2. List-Directed Format~ing The data transfer statement contains an asterisk as thE~ format identifier. The asterisk signifies that the transfer is controlled by the data type of the variables in the data transfer statement I/O list. In the following example, the data transfer is controlled the I/O list items X, J, and Z: WR I ~~E by ( 2 2, * ) X, J , Z In this example, unless the data types of X, J, and Z have been set explicitly to a type other than the default data type, the transferred values of X and Z appear in floating-point form, and the transferred value of J appears in integE~r form. See Section 10.4.5.2 for more formatting. 3. information on list-directed NAMELIST-Statement Formatting The data transfer statement contains a NAMELIST name as the format identifier. This NAMELIST name associates the data transfer statement with a NAMELIST I/O list defined in the NAMELIST statement elsewhere in the same program unit. Elements in the NAMELIST I/O list, in turn. dictate th~ formatting of the data during the data transfer. In the following exam9le, the data transfer is controlled the NAMELIST. by PROGRAM NAMLS'r NAMELIST/VAR/X,Y,Z READ (22, VAR) WRI'[,E (5,VAR) END See Section 10.4.5.3 fornore information formatting. on NAMELIST-statement 10.3.1.1 Internal Files - Internal files provide the capability to perform formatted data transfers between character variables and the elements of an I/O list. T~eir use with formatted sequential READ and WRITE statements reduces the need to use the ENCODE and DECODE statements for internal 1/0 (s~e Section 10.12). An internal file consists of a character variable, a character array element, a character array, or a character substring; a record In an internal file consists of any of the above except a character array. If an internal file is a character variable, array element, or substring, that file comprises a single record whose length is the same as the length of the variable, array element, or substring. If an internal file is a character array, that file comprises a sequence of records, with each record consisting of a single array element. The sequence of records in an internal file is determined by the order of subscript progression (see Section 4.3.2). Every record of the file has the same length, which is the length of an array element in the array. 10-7 DATA TRANSFER STATEMENTS The character variable, array element, or substring that is the record of the internal file becomes defined by writing the record. If the number of characters written in a record is less than the length of the record, the remaining portion of the record is left-justified and filled with blanks. A record in an internal file can be read only if the character variable, array element, or substring comprising the record has been defined (that is, a value has been assigned to the record). Prior to data transfer, an internal file is always positioned at the beginning of the first record. 10.3.2 Unformatted Data Transfers Unformatted data is transferred in two forms on TOPS-20 (BINARY or IMAGE), and three forms on TOPS-IO (BINARY, IMAGE, or DUMP). In an explicit OPEN statement (Section 11.2.1), you can specify one of these forms as an argument to the MODE specifier. (Section 11.3.20 describes the MODE specifier and its arguments.) On disk devices and CORE-DUMP tapes, numeric data items are transferred directly as 36-bit words. Character data items are t~ansferred as 7-bit bytes. Numeric and character items can be interpersed in the same I/O list. Nu~eric data items and, for BINARY files, record markers (LSCWs) are always word-aligned (see Section 18.4.2). On INDUSTRY tapes, numeric data items should not be used. Character data items are transferred one character per frame (see Section 11.3.30). 10.3.3 Unformatted Data Transfer to ASCII Devices Unformatted data transfer can be done to and from ASCII devices (such as line printer, plotter, or terminal). Character data is transferred exactly as it appears in the input/output list, with no formatting or carriage control. The method for transferring numeric data items depends on the device. For non-terminal devices (such as, line printer or plotter), numeric data is treated as if it were packed (Hollerith) data, left-justifited, five characters per word. For the terminal, the data is treated as if it were right-justified, one character per word. 10.4 DATA TRANSFER STATEMENT FORMS Table 10-2, on the tab divider, summarizes the forms of all the FORTRAN data transfer statements. Figure 10-1 shows the three major components of data transfer statements. Statement Name (Control-Information List) I/O List '-----" I I'---..r---J (See Section 10.4.1) (See Section 10.4.9) (See Section 10.4.2 - 10.4.8) MF~· Figure 10-1: s· 1750-8i Components of Data Transfer Statements 10-8 DATA TRANSFER STATEMENTS 10.4.1 Data Transfer Statement Names In a data transfer statement, the statement name indicates whether the operation is an input (read) or output (write) operation. The FORTRAN data transfer statements described in this chapter are: 1. READ (See Section 10.5) 2. WRITE (See Section 10.6) 3. REREAD (See Section 10.7) 4. ACCEPT ( Sc!e Section 10.8) 5. TYPE (See Section 10.9) 6. PRINT (See Section 10.10) 7. PUNCH (Se(;:! Section 10.ll) 8. ENCODE 9. DECODE (See Section 10.12) 10. Internal READ (See Section 10.12) 11. Internal 1(vRITE (See Section 10.12) 10.4.2 (S(?e Section 10.12) Data Transfer Control-Information List A control-information list is included in every data transfer statement. Each control-information list (including those having an implicit definition of device) can contain: 1. One unit specifier (see Section 10.4.3) 2. One forma t specifier (see Section 10.4.5) 3. One record specifier (see Section 10.4.4) 4. One I/O status specifier (se1e Section 10.4.8) 5. One error specifier (see Section 10.4.7) 6. One end-of-file specifier (see Section 10.4.6) The following rules govern the placement and inclusion of items control-information list: 1. If the keyword UNIT= is omitted from the unit specifier, unit specifier must be the first item in control-information list. 10-9 in a the the DATA TRANSFER STATEMENTS 2. If the control-information list contains a format specifier (FMT= or NML=), the statement is a formatted data transfer statement. Otherwise, it is an unformatted data transfer statement. The NML= keyword is used for NAMELIST formatting only, although you can also use the FMT= keyword for NAMELIST formatting. If the keywords FMT= or NML= is omitted from the format specifier, the format specifier must be the second item in the control-information list, and the first item must be the unit specifier without the keyword UNIT=. 3. If the control-information list contains a record specifier (REC=), the statement is a direct-access data transfer statement. Otherwise, it is a sequential-access data transfer statement. If the keyword REC= is omitted from the record specifier, the unit specifier (without the keyword UNIT=) must appear first in the control-information list, followed by a single quote ( ' ) ! and then the record specifier. 4. A control-information list cannot contain specifier and an end-of-file specifier. 5. If the format specifier is an asterisk or a NAMELIST name, a record specifier must not Je included in the ~ontrol-information list. G. A control-information list in an internal file or ENCODE or CECODE statement must contain a format specifier other than dn ~sterisk or NAMELIST name, and must not contain a record ';0ecifier. 10.4.3 both a record Unit References in Data Transfer Statements The unit specifier is used to refer to a file or device. a unit specifier is: UNIT The form of un where: un is a logical unit identifier or an internal file identifier. A logical unit identifier (see Section 10.4.3.1) is used to refer to an external file. An internal file identifier (see Section 10.4.3.2) is used to refer to an internal file. The keyword UNIT= is optional if the unit specifier is the first in the control-information list. 10-10 item DATA TRANSFER STATEMENTS 10.4.3.1 FORTRAN Logical Unit Identifier - The FORTRAN logical unit identifier is associated with the file to or from which data is being transferred. This identifier is an integer expression whose value is in the range of 0 to 99, or an asterisk. For example, the following WRITE statement contains the reference to logical unit number 22 as the first item in the control-information list: WRITE (22,101) Note Table 10-3 lists the default logical unit number assignments. that 22 logical unit number identifies the file as DSK:FOR22.DAT. The unit Thus, the sample WRITE statement references a disk. for the READ identifier asterisk corresponds the card reader to statement, and to the line printer for the WRI'rE statement. The compiler automatically assigns default logical unit numbers for the REREAD, READ, ACCEPT, PRINT, PUNCH, TYPE, and WRITE statements. Default unit numbers are negative integers that cannot be accessed. For example: where 1. OPEN(UNIT=n) or READ/WRITE (UNIT=n) integer is illegal. 2. Assigning a negative decimal number to a level is illegal. n is device a negative at command assign a You can, however, from monitor command level, default device to another device. For example, using the TOPS-20 DEFINE command (or TOPS-IO ASSIGN command), you can assign LPT: (line printer) to DSK: (disk). If you do this, then any I/O statements that reference the line printer actually reference the disk. You can optionally make the logical device assignments at runtime, or you can use the default assignments contained by the FORTRAN Object Time System (FOROTS). Table 10-3 lists the default logical device assignments. You should specify the device explicitly in an OPEN statement (see Section 11.2) if you wish to override the default assignment. 10-11 DATA TRANSFER STATEMENTS l allll' ill-:{: FOHTHAN Logical Device Assignments I)('fault Devices (inaccessible to til£' user) --! I)~-ia~I~FiI;~~J~l~--------l- i~~);i~~ll;~it'-N-~~~I;~;- -- --.F()J{PI.T.DAT Fi Ie last read I ,'j H{ HH{( 'UR.nAT "Y F( )l{TTY.1 )AT FOI{IJYr. [)AT I FOl{PTP.UAT FORTTY ()AT -7 -on I -A I ._ 1__________ ~~__ ._______ _ -----------Usc For use by FORPLT REREAD statement READ stat.emellt ACCEPT statement PRINT statement PUNCH stat.ement TYPE statement Standard Devices" i}pvicc 'I-D~t:~~lt ~~ii~n;~~-------TLOgiC-;ll~it N-~;b~;-------- I FOJ{(Hl.DAT FOIWl.DAT 00 01 I I 02 03 i i · TY f)4 I I I "',' i I , I )'1'1' "'.\ 1 0.') f)(:; fJl i {1.'I I 09 ----------- Usc Disk Disk Card Reader Line Pnnter Console Teletype lJser's Teletype Paper Tape Reader Paper Tape Punch Display' DECtape 10 11 !",\-i l~ iT.\.-' i';'.l,f; l:{ 14 1[, \I! Au 16 .11'-'\1 17 ! i '-)TA~ 11"1 , iHTl{ 19 :;',1" 2fl :1.--;'" n ...-:.;'; n · ,:-; f\ 2:{ M • )~!{ IW\, 1 ! W\'2 · "F\':; · ;;·:\'·t , 25 FOH25.DAT Magnetic Tape Assignable DeVice Disk Assigna ble Devices 2fi 27 .. . ~ \ ' -: : ! . \ oJ I Di:-;k I I . FOH99./lAT _. _____.__.=~ ___ .________J_[)i'k _____.__.__ ":1i' device table ean be altered when l'OHOTS is installed or bv the ,,;v~,telIl administrator. The supplied q!! Hili,., are PHhpr value;; in the default tabll' pictured above. or all positive logical unit numhers default to disk. ;H'ck to sm' vvhich device taole is oein!! uH:d at vour installation. 10-12 DATA TRANSFER STATEMENTS 10.4.3.2 Internal File Identifier - The internal file identifier specifies the internal file to be used. This identifier is the name of a character variable, character array, character array element, or character substring. Example: CHARACTER*132 LINE WRITE (UNIT=LINE,FMT= I (F) ') 3.14159 10.4.4 Record Number References In Data Transfer Statements All direct-access data transfer statements must contain a record specifier, which is used in the transfer to identify the number of the record to be accessed. The form of the record specifier in the control-information list is: REC=rn where: is a positive integer record number. rn expression that indicates the When you use the REC=rn form to specify the record number, you can place the record specifier anywhere in the control-information list. An alternative way for including the record specifier is: un'rn where: is a positive integer constant, variable, or array el'2men t tha t represents the logical unit number of the device to or from which the data transfer is beinq made. When you use this form for specifying the loqical unit nu~ber, you cannot use the UNIT= keyword. un is an apostrophe delimiting from the record number. rn the unit is a positive integer constant, variable, element that represents the record number. When you use the alternative form for specifying you cannot use the keyword REC=. 10.4.5 logical the record or number array number, Format References in Data Transfer Statements All formatted data transfer statements must contain a format specifier in the control-information list. The general form of the format specifier is: FMT=f or NML= a NAMELIST name 10-13 DATA TRANSFER STATEMENTS where: FMT= format is the keyword used in the keyword form of the specifier. Using the keyword form of the format specifier makes it positionally independent in the control-information list. NML= is the keyword that can be used instead of FMT= for NAMELIST formatting. Either FMT= or NML= can be used for NAMELIST formatting. f is a format identifier. Depending on the type formatting chosen, f can be one of the following: 1. A statement number 2. A numeric array name 3. A character expression 4. An integer, real, or logical variable 5. An asterisk 6. A NAMELIST name If you do not use the keyword form of the format specifier, you place the format specifier as the second item of control-information list (immediately following the logical number specifier) (see Section 10.4.2). Sections 10.4.5.1 through 10.4.5.3 describe all forms specifier. 10.4.5.1 FORMAT-Statement Formatting specifier has the following form: The of of must the unit the format FORMAT-statement format FMT=f where: FMT= is the optional keyword in the format specifier. f is one of the following: 1. The statement number FORMAT statement of a appearing in the same program unit as the data transfer statement 2. The name of a numeric array 3. A character expression 4. An integer, real, or logical variable that has been assigned a FORMAT statement number with an ASSIGN statement (see Section 8.3) (See Section 12.1 for FORMAT-statement formatting.) 10-14 more information on DATA TRANSFER STATEMENTS The following examples show all forms of the FORMAT-statement format specifier. In the first e~ample, the format specifier (FMT=lOl) references the FORMAT statement 101 in the same program unit. 101 PROGRAM TEST 1=67 P=90.8 WRITE (UNIT=22,FMT=lJl) I,P FORMAT (IX, 'FIRST VA::'UE IS: ' , I , ' SECOND VALUE IS: END ',F) In the second example, the saml~ format list used in the first example is stored in an la-element ar~ay. Note that the word "FORMAT" is not included in the array. PROGRAM TESTB DIMENSION MYARAY(lO) MYARAY (1) =' (IX,' , , MYARAY(2)='FJRST' MYARAY(3)=' "ALU' MYARAY(4)='E IS:' MYA RA Y (5 ) =' '1', I , , MYARAY(6)=' ,q SEC' MYARAY(7)='OND V' MYARAY(8)='ALUE ' MYARAY(9)='IS: '" MYARAY (10) =' "F) , 1=67 P=90.8 WRITE END (UNIT=22,FMT=MYARAY)I,P In the third example, the same format list used examples is stored in a character expression. in the first ", I ," ' // two PROGRAM TESTe INTEGER I REAL P CHARACTER WORDl*5,WORD2*6 1=67 P=90.8 WORDl='FIRST' WORD2='SECOND' WR I 'r E (U NI 'r = 2 2 , FM T =' (1 X, " , / /WO R01/ /' VA L UE IS: 1 WORD2//' V.I\LUE IS: ",F)') I,P END In the fourth example, the format specifier (FMT=IFORMT) variable that has been assigned a statement number. 101 PROGRAM TESTD ASSIGN 101 TO IFORMT 1=67 P=90.8 WRITE (UNIT=22,FMT=IFORMT) I,P FORMAT (IX, 'FIRST VALUE IS: " I, END references 'SECOND VALUE IS: a ',F) For more information on FORMAT-statement formatting, see Section 12.1. 10-15 DATA TRANSFER STATEMENTS 10.4.5.2 List-Directed Formatting - In list-directed formatting, the variables in the I/O list of the data transfer statement dictate the formatting of the data during the transfer. The form of the list-directed format specifier is: FMT=* where: FMT= is the optional keyword part of the format specifier. Including this keyword in the format specification makes the specification positionally independent in the control-information list. If you omit the FMT= keyword, the format specifier must be the second specifier (the unit specifier must he first). * is an asterisk that indicates that list-directed. In the following example, the variables list-directed formatting. I and P the formatting is are formatted by PROGRAM TESTLD 1=67 P=90.8 WRITE (UNIT=22,FMT=*) END I,P List-directed formatting is further described in Section 12.5. Formatting - If the formatting is 10.4.5.3 NAMELIST-Statement \lAMELIST, the format specifier in the control-information list reference to a NAMELIST name defined in a NAMELIST contains a statement in the same program unit. Since the NAMELIST name defInition contains an I/O list, a data transfer statement that contains a NAMELIST name in the format specifier cannot also contain 'n1 I/O 1 ist. The form of the NAMELIST format specifier is: FMT=name or NML=name !"MT= is the optional keyword part of the format specifier. Including the keyword in the format specification makes i t positionally independent in the control-information list. If you do not include the keyword part of the Format specifier, you must place the format specifier :;econd (after the logical unit :1umber specifier) in the control-information list. ~~ML= is an alternative keyword that can be used in place ::'MT. of IS the NAMELIST name. The NAMELIST name is defined NAMELIST statement in the same program unit. in ,;ame ~ 10-16 DATA TR~NSFER STATEMENTS In the following example, the data transfer statement uses a name in its format reference: NAMELIST PROGRAM TESTNL NAMELIST/MYIOLT/I,P READ (UNIT=5,NML=MYIOLT) WRITE (UNIT=5,FMT=MYIOLT) END 'rhe execution of this sample program is as follows: EXECUTE TES'I.FOR LINK: Loading [LNKXCT TESTNL execution] $MYIOLT I=675,P=34.71$ $MYIOLT 675, P= 34.71000 $END 1= CPU time O.L~ Elapsed t:me 32.0 For further information on thE! NAMELIST statement, see SectIon 12.7. 10.4.6 Optional End-of-File Transfer of Control (END=) The optional end-of-file transfer specifier (END=) specifies a statement number to which control passes if this statement attempts to read past the last data record of a file. If you include an ERR= specifier (Section 10.4.7) and no specifier, control passes to the statement indicated in the specifier whenever an end-of-file condition occurs. Note that an specifier on any output statement and on an input statement direct-access file is ignored. END= ERR= END= of a If no END= specifier, IOSTAT= specifier, or ERR= specifier is included in the data transfer stab~ment, and an end-of-file condition is encountered, an error message is displayed on the controlling terminal, and program execution is terminated. The form of the END specifier is: END=s where: The END= statement in END= is the keyword part of the END= specifier. portion of the END= specifier is required. s is the statement number of an executable the current program unit. transfer In the following example, the end-of-file specifier causes a of control to statement 50 after the data transfer statement encounters an end-of-file on unit 22. 10-17 DATA TRANSFER STATEMENTS PROGRAM TESTEN READ (UNIT=22,FMT=30,END=50) A,B,C FORMAT (FjFjF) GO TO 100 WRITE (UNIT=5,FMT=75) FORMAT (lX,'END-OF-FILE HAS BEEN ENCOUNTERED') WRITE (UNIT=5,FMT=105) FORMAT (IX, 'EXECUTION HAS ENDED') END 30 50 75 100 105 The following shows the sample program being executed and the end-of-file branch being taken. In this example, the READ statement reads from the default filename, FOR22.DAT. To demonstrate the end-of-file branch, FOR22.DAT is an empty file. Thus, when the READ statement attempts to read records from FOR22.DAT, an immediate end-of-file condition is detected. EXECUTE TEST. FOR FORTRAN:TESTEN TESTEN LINK: Loading [LNKXCT TESTEN execution] END-OF-FILE HAS BEEN ENCOUNTERED EXECUTION HAS ENDED CPU time 0.2 Elapsed time 0.5 10.4.7 Optional Data Transfer Error Control (ERR=) The optional error specifier (ERR=) enables you to specify a statement to which control passes if an error occurs during the data transfer. If an error occurs other than for end-of-file, the file is positioned after the record containing the error. NOTE If the program attempts to read from the same unit after an ERR= branch occurs, the record following the record containing the error will be read. To read a record containing the error, the program must execute either a REREAD statement (Section 10.7) or a BACKSPACE (Section 11.8.4) followed by a READ statement. If no ERR= specifier or IOSTAT= specifier is present and occurs during the data transfer, the program is aborted. an error The form of the error specifier is: ERR=s where: ERR= is the keyword portion of the error specifier. s is the statement number of an executable the same program unit. 10-18 statement in DATA TRANSFER STATEMENTS The following example shows the error specifier being used to pass control to the statement at ljne 85 if an error occurs during the data transfer. 30 50 75 85 86 100 105 PROGRAM TESTEN READ (UNIT=22,FMT=30,END=50,ERR=85) A,B,C FORMAT (F/F/F) GO TO 100 WRITE (UNIT=5,FMT=7~) FORMAT (lX,'END-OF-E'ILE HAS BEEN ENCOUNTERED') GO TO 100 WRITE (UNIT=5,FMT=86) FORMAT (lX,'THE TRANSFER ENCOUNTERED AN ERROR') WRITE (5,105) FORMAT (' EXECUTION HAS ENDED') END TYPE FOR22.DAT 100. 200. AAAA BBBB CCCC DDDD EXECUTE TESTEN.FOR FORTRAN: TESTEN TESTEN LINK: Loac\ ing [LNKXCT TESTEN execution: THE TRANSFER ENCOUNTERED AN ERROR EXECUTION HAS ENDED Elapsed t::.me 2. B CPU time 0.2 In this example, the error branch is taken when the input routine detects a nonnumeric da1:a item while attempting to read a floating-point number into val~iable C. If the file FOR22.DAT contains more than three records, the next READ accesses record 4 in the file. 10.4.8 Optional Error Variable For Error Reporting (IOSTAT=) The optional I/O status specifier enables you to designate an integer variable which receives a value indicating the success or failure of the data transfer. When the data transfer statement is successfully executed, the variable is assigned a valu«? of ZE?ro. If an error occurs during the data transfer, the variable is assigned a positive value indicating which error occured (see Appendix D). In this case, if there is no ERR= specifier, the program proceeds to the statement after the data transfer statement. If an end-of-filE:?, occurs during the data transfer, the variable is set to -1. In this case, if there is no END= or ERR= specifier, the program proceeds to the statement after the data transfer statement. The form of the error variabl,~ specifier is: IOSTAT=ios where: ios is an integer specifier. variable 10-19 that is the I/O status DATA TRANSFER STATEMENTS The following example shows the I/O status specifier being used to report the number of the error on default unit 5 if the error branch is taken. 10 30 40 50 75 85 86 100 105 PROGRAM TESTEN READ {UNIT=22,FMT=30,END=50,ERR=85,IOSTAT=J)A,B,C FORMAT (F4.1/F4.1/F4.1) WRITE {UNIT=5,FMT=40)A,B,C FORMAT (lX,'THE VALUES ARE: ',3F6.1) GO TO 100 WRITE (UNIT=5,FMT=75) FORMAT (lX,'END-OF-FILE HAS BEEN ENCOUNTERED') GO TO 100 WRITE {UNIT=5,FMT=86)J FORMAT (lX,'THE TRANSFER ENCOUNTERED AN ERROR; STATUS: IF(J.GT.O) GO TO 10 WRITE (5,105) FORMAT (' EXECUTION HAS ENDED') END ',IS) TYPE FOR22.DAT 100. 200. AAAA BBBB CCCC DODD 80. 90. 95. EXECUTE TESTEN.FOR FORTRAN: TESTEN TESTEN LINK: Loading [LNKXCT TESTEN execution] THE TRANSFER ENCOUNTERED AN ERROR; STATUS: THE VALUES ARE: 80.0 90.0 95.0 EXECUTION HAS ENDED CPU time 0.2 307 Elapsed time 1.5 In this example, the IOSTAT variable J is set when the first READ detects a nonnumeric data item while trying to input the data for variable C. In this case, the value of 10STAT represents the processor specific error number (the second value listed in the FOROTS error messages in Section 0.1), and indicates that an illegal character has been detected in the data. After the error status has been printed, the second READ successfully executes using records 4, 5, and 6 from the file. 10.4.9 Data Transfer Statement Input/Output Lists The I/O list in an input or output statement contains the names of variables, arrays, array elements, or character substrings. The I/O list in an output statement can also contain expressions, function references, or constants. An I/O list has the following form: e[,e] .•. 10-20 DATA TRANSFER STATEMENTS The variable i and the parameters el, e2, and e3 have the same forms and the same functions that they have in the DO statement (see Section 9.3). The list immediately preceding the DO loop control variable is the range of the implied DO loop. Elements in that list can reference the index, but they must not alter it. Some examples are: WRITE (3,200) (A,B,C, 1=1,3) The statement in this example functions as though you had written: WRITE (3,200) A,B,C,A,B,C,A,B,C The following two statements are WRITE (3,200) thE~ same: (X(I),I=l,]) WR I T E ( 3 , 200) X (l) ,X ( 2) ,;(( 3 ) Another example is: WRITE (6) (1, (J,P(I) ,Q(I,.J) ,J=l,L) ,I=l,M) The I/O list in this example consists of an implied DO list containing another implied DO list nested with it. The implied DO lists together write a total of (l+3*L) *M fields, varying values of J for each value of I. In a series of nested implied DO lists, the parentheses indicate the nesting (see Section 9.3.4). Execution of the innermost list is repeated most often. For example: 150 WRITE (6,150) «FORl1(K,L) •. L=l,lO), K=l,10,2) FORMAT (FIO.2) Because the inner DO loop is E~xecutE~d 10 times for each iteration of the outer loop, the second subscript, L, advances from 1 through 10 for each increment of the first subscript. This is the reverse of the order of subscript progression. In addition, K is incremented by 2, so only the odd-numbered rows of the array are output. The entire list of an implied DO list is transmitted control variable is increment(~d, fOl= example: READ ( 5, 999) (P (I), before the (Q ( I , J), J := 1 , 10), I = 1 , 5 ) In this example, pel), Q(l,l), Q(1,2), ••• ,Q(1,10) are read before I is incremented to 2~ When processing multidimensional an=ays, you can use a combination of fixed subscripts and subscripts that vary according to an implied DO list, for example: READ (3,555~» (BOX(l,J), J=l,lO) This statement assigns input values to BOX(l,l) through BOX(l,lO) then terminates without affecting any other element of the array. and The value of the control variable can also be example: For WR I T E (6, 1111) (I, output directly. 1=1, 21) This statement simply outputs the integers 1 through 20. 10-23 DATA TRANSFER STATEMENTS READ Statement 10.5 READ STATEMENT The READ statement transfers data from a file into memory. There are two categories of READ statements: formatted (see Section 10.5.1) and unformatted (see Section 10.5.2). Table 10-4 summarizes the various forms of the READ statement. 10-24 DATA Table 10-4: TRA~SFER STATEMENTS Summary of READ Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) READ(UNI'l = un,FMT = fI ,END = s H,ERR = sJ[ ,lOSTAT = ios])! iolist I READ( un,FMT = fI ,END = s 11 ,ERR ~ s 11 ,lOSTAT = ios 1)[ iolist 1 REA D( un, fl ,END = s If,ERR = s H,10STAT = ios])1 iolist 1 Sequential Formatted (List Directed) READ(UNI'l = un,FMT = *1 ,END = s 11 ,ERR = s 11 ,10STAT = ios])l iolist I READ( un,FMT = *1 ,END = s]l ,ERR --,- s 11 ,lOSTAT = ios III iolist I READ( un, *1 ,END = s 11 ,ERR = s 11 ,lOSTAT-=- ios I)] iolist 1 Sequential Formatted I NAMELIST Statement! HEAD(UNl'I-un.FMT--namel.END- sll.EHH ~IIJOSTAT -iosl) REAJ)(UNlT un.NML - namel.END sll.ERR sliJOSTAT -iosl) HEAD! un.FMT namel.END-slI.EHR sll.lOSTAT iosl) READ! un.NMLc namel.END' sll.ERH sll.lOSTAT ios]) READ( un. namel.END-- !:i11.ERR sliJOSTAT iosl) Sequential Formatted (Default Unit) READ fI ,ioli.,t 1 READ *I,iolistl READ(UNI'l = *,FMT =fl,END=s]l,ERR= sll,lOSTAT= iosllliolistl READ( UNI'l = *,FMT = *1 ,END = s 11 ,ERR = s 11 ,lOSTAT =- ios 1)] iolist 1 Sequential Unformatted READ(UNI'I = unl ,END = s 11 ,ERR = s 11 ,10STAT = ios])l iolist 1 READ( unl ,END = sll,ERR= sJ!,10STAT= iosl)]iolistl Direct Formatted READ(UNI1 = un,FMT= f,REC = rnl,ERR= sll ,10STAT= iosl)liolistl READ( un,FMT = f,REC = rnl ,ERR ~ s 11 ,lOSTA T = ios 1)1 iolist 1 un, f,REC = rnl ,ERR = s 11 ,lOSTA T --,- ios III iolist I READ( I{EADI un'rn.Fl\1T f I.ERH sliJOSTAT iosi!liolistl un'rn. f I.EHH-sIiJOSTAT iosilliolistl READI Direct Unformatted READ(UNI'I = un,REC = rnl ,ERR = s 11 ,lOSTAT = ios])1 iolist 1 un,REC =rnl,ERR= sll ,10STAT= ios])]iolistl READ( un'rn I.EHH sil.lOSTAT - iosllJiolis11 Key: UNIT=un is a FORTRAN logical unit number (Section 10.4.3), UNIT=* is a default unit specification mection 1004.3). REC=rn is a direct-access record number (Section 10.4.4). un 1'n is an alternate way of specifying Logical Unit Number and record number for a direct-access 1ransfer (Section 10.4.4). FMT=f is FORMAT-statement formatt'ng; iolist is optional (Section 10.4.5.l>. FMT-* is list-directed formatting; iolist is optional (Section 10.4.5.2). FMT -- name is NAMELIST-siatell1cnt form[ tting; iolist is prohiuited (Section 10.4.5.3). Nl\lL- name is the altl'rnativ(' form of the !'.AMELlST-statement format spl'cifier ISection 10.4.5.:3) END=s is an optional end-of-file transf.~r specifier (Section 10.4.6). ERR=s is an optional error transfer spl~cifier (Section 10.4.7!. IOSTAT=ios is an optional 110 status specifier (Section 10.4.8). iolist is a data transfer 110 list (Section 10.4.9), 10-2 !3 DATA TRANSFER STATEMENTS 10.5.1 Formatted READ Transfers A formatted READ transfer uses a READ statement that specifies that the transferred data is edited during the transfer, such that the external and internal representation of the data are different. The three types of formatted READ statements are: FORMAT-statement, list-directed, and NAMELIST-statement. There are two types of access to the device from which the READ statement transfers data. They are sequential and direct. If you want to perform a direct-access formatted READ from a device, you must use FORMAT-statement formatting. List-directed and NAMELIST formatting can only be used with sequential-access formatted READ statements. 10.5.1.1 Sequential FORMAT-Statement READ - This section descl~ibes the sequential-access (FORMAT-statement) formatted READ statement. This statement has the following forms: READ (UNIT=un,FMT=f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,FMT=f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] If an I/O list is included in these forms, it specifies that data is transferred from logical unit un, formatted according to the specification given by f, and transferred into the elements of the specified I/O list. If an I/O list is not included, the input record is skipped. (If the FORMAT statement specifies slash editing, more than one record can be skipped. H or apostrophe editing can cause data transfers to occur to the FORMAT statement itself. See Section 12.4.) The following example contains two READ contains an I/O list; the second does not: 5 statements: the first READ (22, 5) A, Z, J FORMA T (2 FlO. 2 , I 5 ) READ (22,5) END In this example, the first READ statement reads one record from logical unit 22, formats the data according to the FORMAT statement, and assigns the values to the variables A, Z, and J. The second READ statement skips one input record on logical unit 22. The default unit forms of this READ statement operates in the same way as the first forms, except that data transfers reference the card reader, which is the default logical unit for these forms. The default unit forms of this statement are: READ f[,iolist] READ (UNIT=*,FMT=f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] 10-26 DATA TRANSFER STATEMENTS 10.5.1.2 Direct-Access FORMAT-Statement READ - This section describes the direct-access (FORMAT-statement) formatted READ statement. The forms of this statement are: READ (UNIT=un,FMT=f,REC=rn[ ,ERR:=s] [,IOSTAT=ios]) [iolist] READ (un,FMT::f,REC=rn[,ERR=s] [, IOSTAT=ios]) [iolist] READ (un,f,REC=rn[,ERR=s] [,IOSTi\T=ios]) [iolist] If an I/O list is included in these forms, the data specified by record rn is transferred, according to the format specifications given in f, into the elements of the I/O list. These forms can be used only with disk files that have been opened by an OPEN statement that specifies ACCESS='DIRECT', ACCESS='RANDOM', or ACCESS='RANDIN' (see Sec t i on 11. 3. 1) • If the record specified by rn has not been written, an (except for IMAGE mode files). error results The following example shows this form of the READ statement. 5 OPEN(22,RECORDSIZE=25,ACCESS='DIRECT') READ (22,5,REC=10)A,Z,J FORMAT (2F10.2,I5) END In this example, the READ stab?ment lreads record 10 from logical unit 22, formats the data according to the FORMAT statement, and assigns the values to variables A, Z, dnd J. The alternative forms of this ~EAD statement operate in the same way as the first forms. The only difference between the forms is the way in which the unit and record s~ecifications are expressed. The alternative forms for this statement are: READ (un'rn,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] READ (un'rn,f[,ERR=s] [,IO;:;TAT=ios]) [iolist] In the alternative forms, the unit and record references do not contain the keywords UNIT= and REC=. Instead the unit number is specified first; a single quot'? (') is specified next; followed by a record number, a comma, and finally the format reference. 10.5.1.3 Sequential List-Directed READ - This section describes sequential-access (list-directed) formatted READ statement. the This statement has the following forms: READ (UNIT=un,FMT=*[,END=:3] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,FMT:=*[,END=s] [,EHR=s] [,IOSTAT=ios]) [iolist] READ (un,*[,END=s] [,ERR=sl [,IOS~PAT=ios]) [iolist] with these forms, the data is transferred from logical device un and is formatted according to the data types of the elements of the I/O list. If the I/O list is not included, a record is skipped. 10-27 DATA TRANSFER STATEMENTS The default unit forms of this statement are: REA 0 * [ , i 0 1 is t ] READ (UNIT=* ,FMT=* [,END=s] [,ERR=s] [, IOSTAT=ios]) [iolist] With these forms, the data is transferred from the card reader (the default device), and is formatted according to the data types of the elements in the specified I/O list. The following example shows this form of the READ statement: CHARACTER*14 C DOUBLE PRECISION T COMPLEX D,E LOGICAL L,M READ (l,*) I,R,D,E,L,M,J,K,S,T,C,A,B END The external record to be read contains the following: 4 6.3 (3.4,4.2), (3,2 ) , T,F,,3*14.6 ,'ABC,DEF/GHI' 'JK'/ Upon execution of the program unit, the following values are to the I/O list elements: I R D E L M K S T C assigned 4 6.3 (3.4,4.2) (3.0,2.0) .TRUE. .FALSE. 14 14.6 14.6DO ABC,DEF/GHI'JK A, B, and J are unchanged. :0.5.1.4 Sequential NAMELIST-Statement READ - This section describes t:)C sequential-access (NAMELIST-statement) formatted READ statement. ~~lS statement has the following forms: ,'~EAD (UNIT=un,FMT=name[,END=sJ [,ERR==s] [,IOSTAT=ios]) l~EAD (UNI'r=un,NML=namet,END=s] [,ERR=s] [,IOSTAT=ios]) i;;EAD (un,FMT=name/,END=sJ [,ERR==s] [,IOSTAT=ios]) i~EAD (un,NML=name[ ,END=sJ [,ERR=s] [,IOSTAT=ios]) !.;;r:AD (un,name( ,END=s] [,ERR=s] [, IOSTAT=ios]) WIth these forms, the data is transferred from the specified unit into locations specified by the NAMELIST list. The formatting is ·»ntrolled by the implicit data types of the NAMELIST list items. We >;~lagest that you use the NAMELIST form of the READ statement to '~-,lnsfer data from files created by the NAMELIST form of the WRITE :-. t-,d ternent (Sect ion 10.6.1.4). ~he 10-28 DATA TRANSFER STATEMENTS where: e is a simple input or output item (see Section an implied DO list :see Section 10.4.9.2). 10.4.9.1) or The I/O statement: assigns values to, or transfers values from, the list elements in the order in which they appear (from left to right). 10.4.9.1 Simple List Elements - A simple input list item can of the following: 1. A variable name 2. An array element 3. A character substring name 4. An array name be one namE~ For example: READ (5, 10) J, K (3) , CH (1 : ]) A simple output list item can be one of the above, or it can be one of the following: 1. A consta.nt 2. A function reference 3. An expression For example: WRITE (5,10) J,K(3),(L+4)/2,CH(1:3) An input list itE~m cannot be an expression. However, it expressions as subscr ipts or ~)ubstr ing bounds. I/O list items can be of the following types: 1. In teger 2. Real 3. Double-precision 4. Complex 5. Logical 6. CharactE~r 7. Octal 8. Double Octal 9. Hollerith 10-21 can contain DATA TRANSFER STATEMENTS When you use an unsubscripted array name in an I/O list, an input statement reads enough data to fill every element of the array; an output statement writes all the values in the array. Data transfer begins with the initial element of the array and proceeds in the order of subscript progression, with the leftmost subscript varying most rapidly from lower to upper bound. For example, the following defines a two-dimensional array: DIMENSION ARRAY(3,3) If the name ARRAY with no subscripts appears in a READ statement, that statement assigns values from the input record(s) to ARRAY(I,I) , ARRAY(2,1) , ARRAY(3,1) , ARRAY(I,2), and so on through ARRAY(3,3). In an input statement, variables in the I/O list can be used in subscripts later in the list, for example: array READ (1,1250) J,K,ARRAY(J,K) FORMAT (Il,IX,Il,IX,F6.2) 1250 The input record contains the following values: 1,3,721.73 When the READ statement is executed, the first input value is assigned to J and the second to K, thereby establishing the actual subscript values for ARRAY(J,K). Then the value 721.73 is assigned to ARRAY(I,3). Variables that are to be used as subscripts in this way must appear before (to the left of) their use as the array subscripts in the I/O list. 10.4.9.2 Implied DO Lists - An implied DO list is an I/O list element that functions as though it were part of an I/O statement within a DO loop. Implied DO lists can be used to: 1. Specify iteration of part of an I/O list 2. Transfer part of an array 3. Transfer array elements in a sequence order of subscript progression different from the As in explicit DO loops, zero-trip implied DO loops are possible Section 9.3). (see An implied DO list has the form: (d 1 i s t , i =e 1, e 2 [ ,e3] ) where: dlist is an I/O list. Dlist implied DO lists. i is the index control variable that can represent a subscript appearing in a preceding subscript list. el,e2,e3 are the indexing parameters that specify, respectively, the initial, terminal, and increment values that control the range of i. If e3 is omitted (with its preceding comma), a value of 1 is assumed. 10-22 can also contain other DATA TRANSFER STATEMENTS The following example shows this form of the READ statement: NAMELIST /DATA/A,Z,J ( 2 2 , DA TA) END l~ EAD In this example, the NAMELIST 3tatement associates the NAMELIST name DATA with a list of three items. The corresponding READ statement reads input data and assigns v::dues to the specified namelist items. 10.5.2 Unformatted READ Transfers Unformatted READ transfers move data from a specified file to locations in memory. Unlike formatted READ transfers, unformatted transfers do not involve any editing of the data. The two types of unformatted data transfers enable specified file either sequentially or directly. you to access a NOTE: The OPEN statement MJDE specifier enables you to specify in which form the unformatted data file exists (see Section 11.3.20). If you execute an unformatted READ statement without having first specified the MODE in an OPEN statement, the data file is assumed to be BINARY. (For additi·)nal information on unformatted data file forms, see S'?ction 11.2.) 10.5.2.1 Sequential Unformatted READ - This sequential-access unformatted READ statement. section describes the This statement has the following forms: READ (UNIT=un[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] If the I/O list is present, the data is transferred as one logical record from the specified logical unit. This type of read should only be used to read files that have been created by unformatted WRITE statements. If you omit the I/O list portion of the statement, the statement skips one logical record on input from the specified unit. The following example shows this type of READ statement used both with and without the I/O list: READ (22) A, Z, J READ (22) END In this example, the first READ statement reads one record from logical unit 22 and assigns values to variables A, Z, and J. The second READ statement skip one record from logical unit 22. 10-29 DATA TRANSFER STATEMENTS 10.5.2.2 Direct-Access Unformatted READ - This section describes direct-access unformatted READ statement. the This statement has the following forms: READ (UNIT=un,REC=rn[,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,REC=rn[,ERR=s] [,IOSTAT=ios]) [iolist] If an I/O list is included in these forms, the data, in the form of one logical record, is transferred from the specified unit into the elements of the I/O list. Only files that have been output by an unformatted WRITE statement should be transferred by this form of the READ statement. In addition, for FORTRAN binary files, if the record specified by rn has not been written, an error results. These forms can be used only with disk files that have been opened by an OPEN statement that specifies ACCESS='DIRECT', qCCESS='RANDOM ' , or ACCESS='RANDIN ' (see Section 11.3.1). Tne alternative form of this READ statement functions the same as the first forms. The only difference between the forms is in the way that the unit and record are specified. The alternative form of this statement is: READ (un'rn[,ERR=s] [,IOSTAT=ios]) (iolist] In this form, the unit and record references do not contain the keywords UNIT= and REC=. Instead the unit number is specified first; a single quote (I) is specified next; then the record numbe:r is specified last. The following example demonstrates the use statement: of the unformatted READ OPEN (22,ACCESS='DIRECT' ;.·:CCORDSIZE=3) READ (22,REC=10)A,Z,J READ (22Il2)B,X,K END In this example, the first READ statement reads record 10 from logical unit 22 and assigns values to the variables A, Z, and J. The second READ statement reads record 12 from logical unit 22 and assigns values to the variables B, X, and K. WRITE Statement 10.6 WRITE STATEMENT WRITE statements transfer data from memory to a file. The various forms of the WRITE statement enable it to be used in sequential, append, and direct-access transfer modes for formatted, unformatted, list-directed, Jnd NAMELIST-controlled data transfers. 10-30 DATA TRANSFER STATEMENTS Table 10-5 summarizes all forms of the WRITE statement. Table 10--5: Summary of WRITE Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) WRlTE(UNIT =, un,FMT =£1 ,ERR = sll ,10STAT= iosilliolistl un,FMT = £I ,ERR = s 11 ,lOSTAT ~ ios])l iolistl WRITE( un, fl,ERR=slI,IOSTAT=ios111iolist1 WRITE( Sequential Formatted (List Directed) WHITE(UNIT =, un,FMT = *1 ,ERR = s 1[ ,10STAT = ios DI iolist I WRITE( un,FMT = *[,ERR = sll ,10STAT = ios 1lI iolist I WRITE( un, *[,ERR=sJ[,10STAT=iosl)liolist1 Sequential Formatted (j\,"AMELIST Statement) WEITE(UI'IT - un.FMT - namel.ERH - sll.IOSTAT, iosll WHITE(LWIT- un.NML- namel.EHR - sll.lOSTAT iusll WHITEr un.FMT - namel.ERH s II.IOSTAT - ios i I WHITEr un.NML namel.EHR - sllJOSTAT - lOS!1 WHITEI un. namel.ERH sll.lOSTAT iosll Sequential Formatted (Default Unit) w nnE fI.i )]jst I WHITE ';-I.iolist I WRITE(UNIT ~ *,FMT = £I ,ERR = s 1[ ,lOST AT = ios 1lI iolist I WRITE (UNIT =, *,FMT = *1 ,ERR = s I[ ,IOSTAT = ios 1)1 iolist I Sequential Unformatted WRITE(UNIT =- unl ,ERR = sJ[ ,10STAT = ioslll iolistl unI,ERR= sJ[ ,10STAT= iosllliolistl WRITE ( Direct Formatted WRITE( UNIT =, un,FMT = f,REC = rnl ,ERR = s J[ ,lOSTAT - ios l)j iol ist I WRITE( un,FMT = f,REC = rnl ,ERR = s 11 ,lOSTAT ~. ios 1)1 iolist I WRITE( un, f,REC = rnl ,ERR= sll ,IOSTAT 'co iosDliolistl WHIT~;I un'rn,FMT f I.EHR- sll.lUSTAT -ioslJliolistl \\'R.IH) un'rn. r I.ERH --sIiJOSTAT iosDliolistl Direct Unformatted WRITE (UNIT =, un,REC = rnl,ERR == s11,10STAT ios III iolist 1 un,REC = rnl ,ERR = s 11 ,lOSTAT - ios 111 iolist 1 WRITE( Wf{JTE( un'rn I.ERR-sII.lOSTAT iosliliolistl co- Key: UNIT=un is a FORTRAN logical unit number (Seetion 10.4.3), UNIT=* is a detmlt unit specification (Section 10.4.3). REC=rn is a direct-access record number (Section 10.4.4). un'rn is an alternate way of sppcifYcng Logical Unit Number and record number fill' a direct-access transfer (Section 10.4.4 J. FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.11. FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). FMT-'-name is NAMELIST-statement fornatting; iolist is prohihited (Section 10.4.5.:3). NML is the alternative form of the NAME LIST-statement format specifier (Section 10.4_5.3) name ERR=s is an optional error transfer Epecifier (Section 10.4.7). 10STAT=ios is an optional 110 status spec: fier (Section 10.4.8). iolist is a data transfer 110 list (Se<tion 10.4.~1). 10.6.1 Formatted WRITE Transfers A formatted WRITE transfer USE'S a WRITE statement that specifies that the transferred data is edited during the transfer, such that the external and internal representations of the data are different. The three types of formatted ~lRITE statements are: FORMAT-statement, list-directed, and NAMELIST-st.atement. 10-31 DATA TRANSFER STATEMENTS There are two types of access to the device to which the WRITE statement transfers data. They are sequential and direct. If you want to perform a direct-access formatted WRITE to a device, you must use FORMAT-statement formattin~. List-directed and NAMELIST-statement formatting can only be used for sequential-access formatted WRITE statements. 10.6.1.1 Sequential FORMAT-Statement WRITE - This section describes the sequential-access (FORMAT-statement) formatted WRITE statement. This statement has the following forms: WRITE (UNIT=un ,FMT=f [ , ERR=s] [, IOSTAT=ios] ) [iol ist] WRITE (un,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE (un,f[,ERR=s] [,IOSTAT=ios]) [iolist] If the I/O list is included in these forms, the data specified by the elements of the I/O list are output to a file on logical unit un. The output data is formatted in this file according to the FORMAT specifications given in f. A blank record is written if the I/O list is not specified, and one of the following is true: 1. The FORMAT statement is empty. 2. No slash, H, or apostrophe editing descriptors occur alone. 3. No slash, H, or apostrophe editing first repeatable edit descriptors. descriptors precede the WRITE that See Section 12.4. The following example contains a sequential contains an I/O list, and one that does not: 5 15 formatted A=11.4 Z=13.9 J=5 WRITE (22,5)A,Z,J FORMAT (IX,2FIO.2,I5) WR I T E (22, 15 ) FORMAT (' PAGE NO.1') END The following is written to logical unit 22: 11.40 PAGE NO. 1 13.90 5 The default unit forms of this statement are: vvRITE f[,iolist] WRITE (UNIT=*,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] 10-32 DATA TRANSFER STATEMENTS If an I/O list is included in these forms, the data, specified by the elements within the I/O list, are transferred to the default device (line printer). The transferIed data are formatted according to the FORMAT specification given by f. The following example shows both forms of this WRITE transfer: 5 15 A=11.4 Z=13.9 J=5 WRITE ~>,A,Z,J FORMAT (lX,2FIO.2,I~.) WRITE 15 FORMAT (I PAGE NO. J. I ) END The following is written to the default device (line printer): 11.40 PAGE NO. 1 13.90 5 10.6.1.2 Direct-·Access FORM1~T-Statement WRITE - The direct-access (FORMAT-statement) formatted WRITE statement is described in this section. This statement has the following forms: WRITE(UNIT=un,FMT=f,REC=l~n[,ERH=s] [,IOSTAT=ios]) [iolist] WRITE (un ,FM'l'=f, REC=rn [ , EHR=s] [" IOSTAT=ios] ) [iol ist] WRITE(un,f,HEC=rn[,ERR=s:i [,IOSTAT=ios]) [iolist] If you include an I/O list in these forms, the data in the I/O list is written starting at record rn to a file on logical unit un. The formatting is controlled by the FOR1'1AT specifications given at f. Only disk files that have been opened by an OPEN statement that specifies ACCESS='DIRECT ' or ACCESS='RANDOM ' (see Section 11.3.1) can be accessed by a WRITE statement of this form. If you omit the I/O list portion of this statement, at least one blank record (specified by REC=rn) is written to logical unit un. The following example shows a direct-access formatted WRITE that contains an I/O list, and one that does not: 5 15 A=11.4 Z=13.9 J=5 OPEN(22, RECORDSIZE=25,ACCESS='RANDOM ' ) WRITE (22,5,REC=10)A,Z,J FORMAT (2FlO.2,I5) WRITE (22,15,REC=11) FORMAT (I PAGE NO. II) END 10-33 statement DATA TRANSFER STATEMENTS The following is written to logical unit 22: 11.40 PAGE NO. 1 13.90 5 The alternative forms of this WRITE statement operate the same way as the first forms. The only difference between the forms is in the way that the logical unit and the record number are expressed. The alternative.forms of this statement are: WRITE (un'rn,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE (un'rn,f[,ERR=s] [,IOSTAT=ios]) [iolist] In these forms, the unit and record references do not contain the keywords UNIT= and REC=. Instead the unit number is specified first; a single-quote (I) is specified next, followed by a record number, a comma, and finally the format reference. 10.6.1.3 Sequential List-Directed WRITE - This section describes sequential-access (list-directed) formatted WRITE statement. the This statement has the following forms: WRITE (UNIT=un,FMT=*[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE (un,FMT=* [, ERR=s] [, IOSTAT=ios]) [iolist] WRITE (un,*[,ERR=s] [,IOSTAT=ios]) [iolist] These forms of the WRITE statement specify that the data identified in the I/O list is written to logical unit un. Because the transfer is list-directed (FMT=*), the data is formatted according to the implicit data types of the variables in the I/O list. If the I/O list is not included, a blank record is written. The default unit forms of this statement are: WRITE *[,iolist] WRITE (UNIT=*,FMT=*[,ERR=s] [,IOSTAT=ios]) [iolist] The default unit forms function in the same way as the first forms, except that the output is written to the default device (line printer) • The following example shows the list-directed WRITE statement: DIMENSION A(4) DATA A/4*3,4/ WRITE (1, *) 'ARRAY VALUES FOLLOW' WRITE (1,*) A,4 END The following is written to logical unit 1: ARRAY VALUES FOLLOW 4*3,400000, 4 10-34 DATA TRANSFER STATEMENTS 10.6.1.4 Sequential NAMELIST-Statement WRITE - This sectIon describes the sequential-access (NAMELJET-statement) formatted WRI'l'E statement. This statement has the followjng forms: VvRITE (UNIT=un,FMT=namel ,ERR=sJ [,IOSTAT=ios]) WRITE (UNIT=un,NML=namel ,ERR=sJ [,IOSTA'I'=ios]) WRITE (un, FMT=name I, EHR=~;J [, IOSTAT=ios] ) WRITE (un,NML=name[ ,ERR=~iJ \'.7RITE (un,namef ,ERR=:sll,JOSTAT=:ios]) I ,IOSTAT=iosJ) These forms of the WRITE sti-:tement transfer data defined referenced NAMELIST statE:'ment (FtvIT=name or NML=name) to the the logical unit specified by un. The following statement: example demonstrates the NAMELIST CHARACTER*19 NAME(2) DA TAN AM E /2 '*' I / I~EAL PITCH, ROLL, YAW, POSIT(3) iJOGICAL DIAC:NO INTEGER ITEPA'l' NAMELIST /PP,RAM/ NAME, P TCH, HOLL, ACCEPT (FMT=PARAM) WRITE (UNIT=l,FMT=PARAM) ':ND The input contaLns the YAW, form POSIT, of DIAGNO, the in the f i l e on WRITE ITERAT fcllow_nq: bSPARAM NAME(2) (lO:)='HE:SENBEHG', hPITCH=5.0, YAW=O.O, ROLL=5.0, ',)LH AGNO =. TRUE. hITERAT=lO$END 'I' heW R I T Est ate men t w r I tEO'S SPARAM NAME= ' 5.000000, ROLL= 5.000000, DIAGNO= T, ITERAT= 10 $END 10.6.2 t h (~ YAW= toll ow i n q : HE ISENBERG', PI TCH= O.OOOOOOOE+OO, POSIT= 3*0.0000000E+00, Unformatted WRITE Transfers Unformatted WRITE transfers move data from memory to a file. formatted WRITE transfers, u1formatted WRITE transfers do not any editing of the data. The two types of unformatted data transfers enable you f i l e either sequentially or directly. 10-35 to write Unlike involve to a DATA TRANSFER STATEMENTS NOTE The MODE spRcifier of the OPEN statemRnt enables you :0 sORcify thR type of unformatted data file you want ~o create (see Section 11.3.20). If you execute an I.~nformatted WRITE statRment without having first specIfied the MODE in an OPEN statement, the data file IS by default BINARY. For additional information on unformatted data file forms, see Section 11.2. 10.6.2.1 Sequential Unformatted WRITE - This section sequential-access unformatted WRITE statement. describes the This statement has the following forms: WRITE (UNIT=un[,ERR=s) [,IOSTAT=ios)) [iolist) WRITE (un[,ERR=s) [,IOSTAT=ios)) [iolist) If the I/O list is present in these forms, the data is written as one logical record to the file contained on the specified logical unit un. If you omit the I/O list in this statement, the statement writes one blank logical record to the file contained on the specified loqical unit un. The following example shows this form of the WRITE statement with I/O list and without the I/O list: WRITE WRITE END the (22)A,Z,K (22) In this example, the first WRITE statement writes a record to the file connected to logical unit 22 containing the values of the variables A, Z, and K. The second WRITE statement writes one blank record to the file connected to logical unit 22. 10.6.2.2 Direct-Access Unformatted WRITE - This section describes the direct-access unformatted WRITE statement. This statement has the following forms: WRITE (UNIT=un,REC=rn[ ,ERR=s) [,IOSTAT=ios)) [iolist] WRITE (un,REC=rn[,ERR=s] [,IOSTAT=ios)) [iolist] These forms can be used only with disk files which have been opened by an OPEN statement that specifies ACCESS='DIRECT' or ACCESS='RANDOM' (see Section 11.3.1). If an I/O list is included in these forms, the data, in the form of one logical record, is transferred from the memory to record rn of the file on the specified logical unit. If the I/O list is not specified, the statement blank record. 10-36 outputs one logical DATA TRANSFER STATEMENTS The following example shows this type of WRITE statement with list and without an I/O list: an I/O OPEN (22,ACCESS= 'DIRECT' ,id:.:CORDSIZE=3) WRITE (22,REC=10)A,Z,K WRITE (22,REC=12) In this example, the first WRITE statement writes the values of the variables A, Z, and K to record 10 on logical unit 22. The second WRITE statement writes one logical blank record to record 12 on logical unit 22. 'rhe alternative form of this ~ype of WRITE statement operates in the same way as the first forms. The difference between the forms is in the way that the unit and the record are specified. The alternative form of this ::;tatement is: WRITE (un'rnr,ERR=sl [,IO:,TAT=ios]) [iolist] In this form, the unit and ~ecord references do not contain the keywords UNIT= and REC=. In,;tead the unit number is sp2cified first; a single quote (') is specified next; then the record number is specified last. 10.7 REREAD STATEMENT The REREAD statenent causes the last record read from the last sequential formatted READ or ~CCEPT statement to again be accessed and processed. You cannot use th,= REREAD feature until an input (READ) transfer has been accomplishe,j. You can use the REREAD statement only for sequential-access formatt,?d data transfers. The REREAD statement can be used with both FORM,\T-statement formatting a.nd list-directE:'d formatting. Once a record has been access,?d by a formatted READ statement, the record transferred can be reread as many times as desired. You can use the same or a new format 5pecification for each successive REREAD statement. Table 10-,6 summal~izes all the forms of the REREAD statement. 10-37 DATA TRANSFER STATEMENTS Tahlt, lO-(): Summary of IU~I{I'~AD Stait'nwllt "onns r-'----. ~ )~~~ Access :)L:tH'm('ui ( \_.__.._---- . ----"'-' ._-_. i Sequential Formatted r onstrucl 'i l.l\ 1. \I) . I- 1\1'1" 1\1<: N I)~ Ii Y IW s 11.1 ()STAT . .. _-_.,_._ . .,, ios III IOlist I FORMAT Statt'JIlenU f-.-.---------.---.- . -. . I S(·quential Fornwttt'd i LI,,{ Din'("\.I'(jl I--K-t~;; ic: iist-riin'cipd IClrtllal j II~!'. 1I,j,,;t ic: (llll iOl1:1i ,:--;.'ci IIlI1 I iJ 4.;).! I. FMT ;():-iTAT- li1.7.1 IOC: Sequential FORMAT-Statement REREAD Tllis section describes :::;::a tcmen t • 'l' '1 e fir s t for m I~EI~F:AD 0 f the secuentlal-dccess t h 1 s s t ,:, t em e n t (FORMAT-statement) REREAD J S : (FMT=tl.END=sl 1.ERR=sll,lOS'l'AT=ioSI) i i o l i s t j It' the I/O l i s t is snecifled in ttlis Lorm, t'-le preVIOUS record is l?:"C1nsterred trom the loalcaL urllt (soecllleeJ In ttle preVIOUS tormatted READ statement) to the memory locatIons specItled by the elements in tt1e I/O list. The transterred record IS tocrndtted according to the :~':)RMAT soecifications oiv(~n in f. rt you omit the 110 l i s t from thIS stdternent, the Input record is skipged. (If the FORMAT st~tement specIfies 31ash editInq, more than ::)ne record can be skipped. H or apostrophe editIng can cause data transfers to occur to the t'vkf'i!AT statement Its(~lt. See SectIon 12.4.) Ule second first t'ORMAT form at this R~R~AU statement operates In the form. The diLletence beLweel1 tile two torms soecitiers are exrnf.l.sspd. ],'10 second form of rile ln~l~EAD this SLdL(.l.lI1l-:'IIT_ same way as is In the way I.S: t[,iolistJ not this forrn, the keyword (oun oj thp i'ORMAT sJecltier (t'M'I'=) IS in the t'OkMAT ref ,,::,rence. Whenever YOU use tne Keyword torm of t:1is specifier, you must. enclose the keywurd l l s t in parentheses. IlJ ;.c;c·d 10-38 DATA TRANSFER STATEMENTS The following example shows tte formatted REREAD being used: 1. r, 10 15 CHARACTER J*5 DIMENSION J(5) READ (20,5)A,X,I FORMAT (2F10.2,I5) REREAD 15,J FORMAT (5A5) END In the above sequence, statemEnt 1 reads the two real varIables A and and the integer I. StatemEnt 10 rereads the last record input from unit 5 as a character string cf 25 characters, five per word, and puts five characters per element irto the array J. x, 10.7.2 Sequential List-Directed REREAD 'rhis section describes the statement. sE·quential-access (list-directed) REREAD The first form of this statemE'nt is: F~EREAD (FMT=*r,END=s] [,Ef'R=s] [,IOSTAT=jos)) [iolist) In this form, the last record read by a formatted READ statement is transferred from the loqic"l unit (specified in the formatted READ statement) into the memory locations identified by the elements of the I/O list. Since the formatting is list-directed, the format of the data is controlled by the date types of the elements in the I/O list. If no I/O list is included, no data is transferred. The second form of this statement operates in the same way as the first form. The difference between the two forms is the way in which the formatting is specified. The second form of this statement is: I~ ERE AD * [,i 0 1i s t ) The following example shows statement: HEAD (L:O,*) *, B 1:he list-directed form of the REREAD A I~EREAD END In this example, the READ stai:ement reads data from logical unit 20 into variable "A. The REREAD statement rereads the data from logical unit 20 into variable B. 10-39 DATA TRANSFER STATEMENTS r------------.---J l__~~:em_=:____ _ ACCEPT 10.8 ACCEPT STATEMENT The ACCEPT statement enables you to input data from your terminal into memory. You can use the ACCEPT statement only for sequential-access formatted data transfers. This statement can be used with both FORMAT-statement and list-directed formattina. Table 10-7 summarizes all forms of the ACCEPT statement. I Summal'~' of ACCEPT Statement Forms Table ]()-7: ----------.- ---. _--------------. _- Data Access - - - - - - ----- ----- ----- --S('4Uenlial Formatted I FURl\lAT Statement) Statement Consh'ud ~-- r ACCEPT(FMT fl,ENJ) ACCEPT fI,ioli~tl ,,11.Elm c.II.1()STAT io" ill iol i"j I I (List DirC'ded' .1-:1\'1) "11.Elm ;-;II.lOSTAT io" III iolist I ACCEPTI.ioli~t I ~ Sequential Forlllatt~J--- --- ---- ACCEPT( F\JT "-'---"--1 I --"---"1 Key: FMT--{, is FOf{:\lAT-statenwnt forma11inl!: inlist is optional I.S('ction lO.4:)]) II is list-directed formatting; iolist is optional ISt'ctiol1 104 ..'1.2l. I I END is an optional end-of-fil(' transfer "pl'cifipr IS,'ction lO.4.f)). s EHH ;-; is an optiol1a I error transfl'r spccifi('l' IS('ction 10...1-.71 IOSTAT - ios is an optional I,n slatus specifier 'Section lO.4.H). 101 ist is a dala transfer 10 list (S('ction lO49! l ___ ...._._..._.___ .. __ 10.8.1 Sequential FORMAT-Statement ACCEPT This section describes the sequential-access ~~ t a temen t . (FORMAT-st~tement) ACCEPT The first form of this statement is: ACCEPT (FMT=f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist) ff you include the I/O list in this form, the data is taken from the terminal and stored in the memorv locations identified in the I/O list. The transferred data is formatted accordina to the FORMAT specifications given in f. 10-40 DATA TRANSFER STATEMENTS vou omit the 1/0 list from this form, the input record is skipped. thE~ FORMAT statement soecifies slash editing, more than one record CLln bf~ skipped. H or apostropne editing can cause data transfers to occur to the FORMAT statement itself. See Section 12.4.) If (If '['h0 spconri form of this statem,~nt operates in the same way as the first form. The rlifference between the two forms is in how the FORMAT l"p"!"prence is expressed. "'11 (' S (> con d for III '\lCF:PT t his s tat e m ~ n t i s : f r • i 01 is t 1 in this form, omItted. ':'11(' 0 [ the keyword portion of the FORMAT specifier (FMT=) is followinq example sho'Ns both forms of the FORMAT-statement ACCEP'r. (FMT=3S)A,Z,J FORMAT (2FlO. 2, IS) t'.·,::::CEPT J 5, B FORMAT (FIO.2) ACCEPT lr, "\J D )n this example, i::he first ACCEPT statement accepts the values of the variables A~ Z, and J from the terminal in th~~ form of FORMAT ~;tatement 35. Thf~ second AC(~EPT statement accepts the value of variable P, from the termi~')al i1 the form of FORMAT statement 15. 10.8.2 SequentiaJ List-Direct·:?d ACCEPT '1'hEO' list-directed ACCEPT statement transfers data entered from the t.crminal into variables specified in the I/O list. The formattinq of the transferred dilta is controlled by the data types of the items in t he I /0 1 i st. T rH~ fir s t form !\ ( :C E f-' T 0 f t his s tat em el t i s : ( F M T= :', r , END = s 1 [ , ERR =s] [, lOS TAT = i 0 s] ) [i ali s t ] In this form, the data is tra1sferred from the terminal into the memory iocations identiried in the I/O list. Since the transfer is "i1,st-clirected, thE:' data is formatted according to the data types of lhe items in the I/O list. If no I/O list is inc]uded, a line is :: k i ppea • The second form oJ:: this statpm~nt operates in the same :l,st fcrm. 'rhe dlff('renr,::> in the two forms is ! ist-directed iormattina refer~nre is specified. Thf> spcond V'C E P'P form of this starpm,~nt: is: * I • i o:t is t 1 10-41 way as in how the the DATA TRANSFER STATEMENTS In the following example, both forms of the list-directed ACCEPT statement are used to take information, character-by-character, from the terminal. This example additionally shows the list-directed TYPE statement being used to print the ACCEPTed data at the terminal: PROGRAM ACCTST ACCEPT *,I,J,K TYPE *,K,I,J ACCEPT (FMT=*)G,H,F 'P Y P E *, H , F , G END EXECUTE ACCEPT.FOR FORTRAN: ACCEPT ACCTST LINK: Loading [LNKXCT ACCTST execution] 23456 9876 12 12, 23456, 9876 12.34 98.16 789.67 98.16000, 789.6700, 12.34000 CPU time 0.2 Elapsed time 40.4 I _ 0 _____0_] __"__" TYPE Statement I 10.9 TYPE STATEMENT Use The TYPE statement enables you to output data to your terminal. the TYPE statement only for sequential-access formatted data transfers. This statement can be used with both FORMAT-statement and list-directed formatting. Table 10-8 summarizes all the forms of the TYPE statement. 10-42 DATA TRANSFER STATEMENTS Summar" of TYPE Stalenwnt FI' rt,,~; Tahle' 1(1-8: Data Ac("pss '~'i 'qllPnlla I Form;l1l<·d I "IJf'~ I-'\j'i 1'1'\'1'1,: n "d, ... i Form:lttpd ,I.i;;! f)i r('I'j ('0 I i'l\'I'I-: ,";"IJll!'nl iai ,;;II()~Tj,T ill~llii"!i,,tl I I'I{I~ ,..;11 I()STAT ill"lllillli;;tl Ii 1<1(f{ i'(lHMXr ~tatt'l1l(>ntl I l'I'Yf'I'; 1-1\1'1 I I,.! ~T: :\1T i()STAT Ill;; ",Ii,,) iO.9.1 Sequential FORMAT-Statement ';' his seC' t :t 0 n '; td temen t. d E~ S C rIb e s t h (~ fir s t t his ':' h p tor mot ~.; po 0 tJ, > n t 1 a ] -- dec f~ s S TYPE (FORMAT-statement) ~; t (~ t (> in t 1'1 [ - I S : ( PM'T' = t , ,. P. R R::: s! i' ':' P I<~ TYPE ! , I OS T A '1':: lOS I ) I 1 01 i s t: I I f you inc 1 u d e t h ," 1 / (j lIS t I n t: i11 S t () r m ~ t he cj ,;j t a l S t r (1 nsf err e d f r om t-hr: I/O 1 i st tr) your h->rmi nal. 'rhe transfprred data is formatted ICCOrolnq to the t'ORMAT SPPcltl,'atlons aiven in t. it' the· 1/0 -I ist hlank T\ record is written foLlo'vJinq ,is true: 'he FORMAT <'tHe> staternE'nt is not- st)pc;ifipd~ and one of emntv. 1'::; :Jo sldsr1. H. or <-1L'()strool1e eciltinq descriptors occur alone. ; J0 s 1 .') S h. H. 0 r ,()f) <1 D () S t Ll.'-+ ior r n 0 rl 1''' e cj 1 t- j 1'1 q d p s (~ r 1 p t- 0 r s . ;lIor'p riescrlntors Jnrormatl.on on i'ormat: precede the editinq) spcond form ot thIS statement operates in the same way as the irs t form. The d i [ f EO rel1('e be h<Jpen t he two forms is in how the FORMAT Thp i sC"C'ond Th(=' torm at this statement, lS: I,iolistl fn this '.)n1 i t form, the keyword portiul1 of tpo . 10-43 the FORMAT specifier (FMT=) " ,~ I .~ DATA TRANSFER STATEMENTS The following example shows both forms of the FORMAT-statement TYPE: A=11.4 2=13.9 .1=5 K=lO T YP E ( FM T =5 ) A , Z , J FORMAT (IX,2FIO.2,I5) TYPE 15,K FORMAT (lX.IIO) 5 J5 ~:ND T~e following is typed on your terminal upon execution: LINK: Loading [LNKXCT TEST40 execution] ll.40 13.90 5 10 CPU t I me O. 22 Elaosed time 2.00 10.9.2 Sequential List-Directed TYPE The list-directed TYPE statement transfers dat~ from a program to the terminal. The formatting of the transferred data is controlled by the ridta types of the items in the I/O list. TrJ.e fIrst form of this statement is: TYP~~ (FMT=* [, ERR=s] [, IOSTAT= ios]) [iolist] In this form, the data is transferred from the program to the terminal. Since the transfer is list-directed, the data is formatted according to the data types of the items in the I/O list. If no I/O list is included, a blank record is written. T~e second form of this statement operates in the same way as the fLrst form. The difference between the ~wo forms is in how the I lst-directed formatting reference is specified. The second form of the statement is: TYPE *[,iolistJ 'fhe following example shows statement: both forms of the list-directed 1\=11.4 = ~: l3 • 9 ,1=') ~' YP E ( FM T = *) , A , Z , J TYPE *,K r:ND 'rho following is typed on the terminal upon Loading rLNKXCT TEST41 executionl 11.40000, 13,90000, 5 :,INK: ;() CPU tIme 0.20 Elapsed time 0.87 10-44 ex~cution: TYPE DATA TRANSFER STATEMENTS PRINT Statement 10.10 PRINT STATEMENT The PRINT statement transfers data from memory to the line printer. You can use the PRINT statement only for sequential-access formatted data transfers. 'This statement can be used with both FORMAT-statement formatting and list-directed formatting. Table 10-9 summarizes all forms of the PRINT statement. Table 10-9: Summary of PRINT Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) :'IW\'T(FMT-lI.ERH Sequential Formatted (List Directed) i'!?lI\T(f<'MT I.I';IW PRINT *[ ,iol: st 1 sll.lOSTAT- iosiilioiistl PRINT f[,iolistl ;.;II,IOSTAT ios!ilinlisti Key: FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT = * is list-dirl~cted formatting; iolis', is optional (Section 10.4.5.2). ERR = s is an optional error transfer sp(,cifier (Section 10.4.7). IOSTAT ~ ios is an optional 110 status specifi.~r (Section 10.4.8). ioIist is a data transfer 110 list (Section 10.4.9). 10.10.1 Sequential FORMAT-Statement PRINT This section describes the sequential-access (FORMAT-statement) statement. PRINT The first form of this statement is: PRINT (FMT=fr,ERR=-s] r,IOSrAT=-ios]) [iolist] If the I/O list is included in this form, the data identified by the I/O list is transferred from memory to the line printer. The formatting of the transferred data is controlled by the FORMAT specifications given in f. 10-45 DATA TRANSFER STATEMENTS A blank record is written if the I/O list is not specified, and one of the following is true: 1. The FORMAT statement is empty. 2. No slash, H, or apostrophe editing descriptors occur alone. 3. No slash, H, or apostrophe editing first repeatable edit descriptor. descriptors precede the See Section 12.4. The second form of this statement operates in the same way as the first form. The difference between the two forms is in how the FORMAT specifier is expressed. The second form of this statement is: PRINT f[,iolist] The following example shows two PRINT statements; one with an I/O list and one without: 10 20 A=7.6 B=12.5 C=20.9 PRINT 10 PRINT 20,A,B,C FORMAT (' Beginning of test') FORMAT (' Values are:',3F) END The following is printed to the line printer upon execution: Beginning of test Values are: 7.6000000 10.10.2 12.5000000 20.9000001 Sequential List-Directed PRINT This section describes statement. the sequential-access (list-directed) PRINT The first form of this statement is: PRINT (FMT=*[,ERR=s) [,IOSTAT=ios]) [iolist] This form of the PRINT statement specifies that the data identified by the elements of the I/O list is output on the line printer. The data is formatted according to the data types of the elements in the I/O list. If no I/O list is included, a blank record is written. The second form of the list-directed PRINT statement operates in the same way as the first form. The difference between the two forms is in the way that the formatting is expressed. The second form of this statement is: PRINT *[,iolist] 10-46 DATA TRAI-JSFER STATEMENTS The following statement: example shows the use of the list-directed PRINT 0=1 E=40 F=23.3 PR I NT *,0, E, l:!' END The following is printed to the line printer upon execution: 1.000000, 40.00000, 23.30000 i-PUNCH L____:~ta:ment ____ 10.11 J PUNCH STATEMENT The PUNCH statement transfers data from memory to the paper tape punch. You can use the PUNCH statement only for sequential-access formatted data transfers. This statement can be used with both FORMAT-statement formatting and :List-directed formatting. Table 10-10 summarizes all forms of the PUNCH statement. Table 10-10: Summary of PUNCH Statemenl Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) PUNC H(Fl\lT - fl,ERH - s IIJOSTAT = ios III iolist I PUNCH fI.iolistl Sequential Formatted (List Directed) PUNCHd,'l\lT ~~I ,ERH"" s II ,10STA'I' - ios Iii iolist I PUNCH *1. olistl 1--------------- - - - - - - - ""------ Key: FMT-f is FOHMAT-statement formattll1g; iolist is optional (Section 10.4.5.1). FMT ~ * is list-directed formatting; iolist is optional (Section 10.4.5.2). is an optional error tram;fer s )ecifier (Section ]0.4.71. IOSTAT-~ ios is an optional 1'0 status ::'peci'ier I Section 1O.4.8!. iolist is a data transfer 1'0 list (Sec~ion I0.4.9). 10-47 DATA TRANSFER STATEMENTS 10.11.1 Sequential FORMAT-Statement PUNCH ThIS section describes the seauential-access ,; i . , temen t. TrlP first (FORMAT-statement) PUNCH form of this statement is: PUNCH (FMT=f[,ERR=s] [,IOSTAT=ios]) [iolistl " the I/O list is specified in this form, the data identified by the in the I/O list are transferred to the paper tape punch. The formattinq of the data is controlled by the FORMAT specifications (J I ven in f. i c'_'ms \ blank record is written if the I/O list is not specified, and one of the followinSl is true: 1. The FORMAT statement is empty. 2. No slash, H, or apostrophe editing descriptors occur alone. ~. No slash, H, or apostrophe editinq first repeatable edjt descriptor. ~ee descriptors precede the Section 12.4. The second form of this statement operates in the same way as the First form. The difference between the two forms is in the way that the format specification is referenced. rhe second PUNCH form of this statement is: f[,iolist] The followinq example shows the formatted PUNCH statement: i?UNCH lO,A,B,C F'ORMAT (iF) 10 to.ll.2 Sequential List-Directed PUNCH Thls section describes the sequential-access (list-directed) PUNCH :; t 'i t em e n t . T~e first ~')UNCH form of this statement is: (FMT=*[ ,ERR=s] [,IOSTAT=ios]) [iolist] Phis form of the PUNCH statement transfers the data identified by the ,"oments of the I/O list to the paper tape punch. Since the transfer i:i list-directed, the formatting of the data is controlled by the data :-Yges of the items within the I/O list. If no I/O list is includE~d, a ~]ank record is wrItten. 10-48 DATA TR~NSFER STATEMENTS The second form of this staterr,ent operates in the same way as the first form. The difference between the two forms is in the way that the list-directed format reference is written. The second form of this statement is: PUNCH *[,iolist] The following example shows the list.-directed PUNCH statement: PUNCH *,D,E,F INTERNAL FILES AND ENCODE/DECODE Statements 10.12 INTERNAL FILES AND ENCODE/DECODE STATEMENTS Internal READ/WRITE statements dnd ENCODE/DECODE statements for internal I/O. Table 10-11 summarizes all the forms of the ENCODE/DECODE statements. Table 10-11: internal are used READ/WRITE and Summary of Internal READ/WRITE and ENCODE'DECODE StatemeD1 Forms Data Access Statement Construct Sequential Formatted (FORMA T Statement) l:t,C()OBk.f.al.BW{o s II,lOSTAT ioslJI iolist I DECODE(! .Lal.BHJ{ -- s :1.l0STAT - ios III iolist I READ(UNIT = un,FMT = fl ,END = s][ ,ERR = s If ,lOSTA T = ios ])[iolist] READ(un,FMT = fl,END = s][,ERR = slI,IOSTAT= ios])[iolist] READ(un,fl ,END = s]1 ,ERR = s]! ,IOSTAT = ios])[iolistl WRITE(UNIT = un,FMT = fl,ERR = s][ ,IOSTAT = ios])[iolist] WRITE( un ,FMT = fl ,ERR = s][ ,lOSTA T = ios])[ iolist1 WRITE(un,fl,ERR = sH,IOSTAT = ios])[iolist] Key: UNIT=un is an Internal File identifier Section 10.4.3.2). c is the total number of characters being transferred. f is a FORMAT-statement formatting reference. a is the name of the array from which or to which data is being transferred. END=s is an optional END-of-file specifier. is an optional error transfer Hpecifier (Section 10.4.7). JOSTAT- iOB is an optional 110 status specifier (Section 10.4.8). iolist is a data transfer 110 list (Se:::tion 1O.4.B). 10-49 DATA TRANSFER STATEMENTS 10.12.1 Internal READ and WRITE Statements The internal READ statement transfers data from an internal file to I/O list elements. The internal WRITE statement transfers data from I/O list elements to an internal file. Internal READ and WRITE statements are always formatted. NOTE The DECODE statement can he used as an alternative to the internal READ statement, and the ENCODE statement can be used as an alternative to the internal WRITE statement. (See Section 10.3.1.1 for more information on internal files.) The internal READ statement has the following forms: READ (UNIT=un,FMT=f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,FMT=f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,f[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] In the above forms, un is an internal 10.4.3.2) • file identifier (see Section If an I/O list is included in these forms, it specifies that data is transferred from internal file identifier, un, formatted according to the specification given by f, and transferred into the elements of the specified I/O list. If an I/O list is not included, the input record is skipped. (If the FORMAT statement specifies slash editing, more than one record can be skipped. Apostrophe or H editing can cause data transfers to occur to the FORMAT statement itself. See Section 12.4.) The following example statement: 10 20 demonstrates CHARACTER*9 STRING STRING = '3.14 6.02' READ(STRING,lO) PI, A FORMAT(F4.2, IX, F4.2) WRITE(5,20) PI, A, PI+A FORMAT(' PI=', F6.3, 5X, STOP END the use of the internal 'A=', F6.3, 5X, 'PI+A=', F6.3) READ The READ statement in this example is an internal file read. It extracts the two numbers that are encoded in the character variable STRING, converts the numbers to floating point, and then stores them into the two variables PI and A. The following is printed at the terminal when the above program is executed: EXECUTE IR.FOR LINK: Load ing [LNKXCT IR execution] PI= 3.140 A= 6.020 PI+A= 9.160 CPU time 0.19 Elapsed time 0.40 10-50 DATA TRANSFER STATEMENTS The internal WRITE statement has the following forms: WRITE (UNIT=un ,FMT=f [, ERR=s] [, IOSTAT=ios] ) [iol ist] WRITE (un,FM'r=f[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE (un,f[,ERR=s] [,IOSTAT=ios]) [iolist] If the I/O list is included in these forms, the data specified by the elements of the I/O list are output to a file on internal file identifier un. The output data is formatted in this file according to the FORMAT specifications given in f. A blank record is written if the I/O list is not specified, and one of the following is true: 1. The FORMAT statement is empty. 2. No slash, H, or apostrophe editing descriptors occur alone. 3. No slash, H, or apostrophe editing descriptors first repeatable edit descriptors. preceded the See Section 12.4. The following example demonstrates statement: 10 20 the use of CHARACTER*20 CHARS(3) INTEGER PHNE(3) PHNE(l) = 617 PHNE(2) = 481 PHNE(3) = 4054 WRITE(CHARS,10) (I, PHNE(I), 1=1,3) FORMAT ( 'PHNE(', 11, ')=',14) WRITE(5,20) (I, CHARS(I), 1=1,3) FORMAT (' Record " 11, I of CHARS is'" STOP END the internal WRITE A20, I " ' ) The first WRITE statement in the above program is an internal file write. Since the characteI variable being written to is a three element array, the internal file is a file of three records. When this program is executed, the following is output to the terminal: EXECUTE IW.F'OR LINK: Loading [LNKXCT IW execution] Record 1 Record 2 Record 3 CPU time 10.12.2 of CHARS is "PHNE(l)= 617 of CHARS is "PHNE(2)= 481 of CHARS is "PHNE(3)=4054 0.2,4 Elapsed time 0.82 " " " ENCODE and DECODE Statements The DECODE statement can be u~;ed as an alternative to an internal READ, and the ENCODE statement can be used as an alternative to the internal WRITE. 10-Sl DATA TRANSFER STATEMENTS 'r'he ENCODE statement transfers data from the variables of a specified rio list into a specified array. ENCODE operations are similar to those performed by a WRITE statement. The DECODE statement transfers data from a specified array into the variables of an 1/0 list. DECODE operations are similar to those performed by a READ statement. ENCODE and DECODE statements have the following forms: ~;NCODE (c,f,a[,ERR=s] [,IOSTAT=iosl) [iolist] Jt-':CODE (c,f,a[,ERR=s] [,IOSTAT=ios]) [iolistl where: specifies the number of characters in each internal record of the array. This argument can be any integer expression, and must be the first specification in the stntement. c NOTE ~ivp ~rray characters per word are stored in the without regard to the type of the array. ~pecifies either a FORMAT-statement or a numeric array 1:hat contains format specifications. This must b,e the second specification. f specifies the array, array element, variable, or character substrinq reference that is to be used in the transfer operations, and it must contain at least c characters. More than one element of the array can be used by the ENCODE/DECODE. iolist specifies an 1/0 list of the standard form. multiple records are stored by ENCODE or read by DECODE, each new record starts c characters nfter the previous record; no CR/LF (carriage return/line feed) is inserted between records. ~hen NOTE the array contains fewer characters than required the format and the I/O list, the variables followinq the array in memory are used. If the processing of the I/O list requires more characters in 1 single record than are specified by the character count c, blanks are used. rf by l'he fo1lowinq example shows how the ENCODE and DECODE Jsed: DIMENSION B(4) ,A(2) A(l)=300.45 A(2)=3.0 C='l2345' no 2 ,J=1, 2 :0 I'; NC ODE (1 6 , I 0 , B) J , A ( J ) FORMAT (IX. 'A ( I , I l, I) 10-52 FB.2) statements are DATA TRANSFER STATEMENTS s 11 'rYPE 11,B FORMAT(4A5) 2 CONTINUE :2 DECODE(5,12,C)B FORMJI.T(3Fl.0,.lX,F: .• O) 13 TYPE 13,B FORMAT(4F5.2) END During the first iteration of the DO loop, the ENCODE statement has transferred the contents o~ variable J and array element A(l) into array B. rrhe formatting of the data being transferred is specified by the FORMAT statement at lineLO. After the first iteration of:he DO loop, the contents of array Bare: A (1) I 13(1) R (2) B (3) '300.4 ' 13 (4 ) '5 I I = The TYPE statement at line 5 :ypes array B on the terminal during first iteration of the DO Loop. the During the second iteration of the DO loop, the data IS transferred from variable J and array element A(2) into array B. Atter the second iteration, the contents of array Bare: B (1) I A (2) , 13(2) I3 (3 ) 13(4) ,0 3 .. 0' The TYPE statement at line 5 types array B on the terminal during second iteratjon of the DO 10Jp. The DECODE statement: 1. Extracts the digits 1, 2. Converts them to fl03ting-point values 3. Stores them in 4. Skips the next character S. Extract.:;; the digit 5 from C 6. Converts it to a i. Stores the value in 8(4) B( L), 2, and 3 from C B(2), and B(3) (the digit 4) floating-point value 10-53 the DATA TRANSFER STATEMENTS The following shows what is printed at the program is executed: EXECUTE T.FOR LINK: Loading [LNKXCT T execution] A(l) 300.45 A(2) = 3.00 1.00 2.00 3.00 5.00 CPU time 0.1 Elapsed time 0.8 10-54 terminal when the above CHAPTER 11 FIL8-CONTROL AND DEVICE-CONTROL STATEMENTS 11.1 FILE-CONTROL STATEMENTS Prior to transferring any data using one of the forms of data transfer statements, you can establish a connection between a logical unit and a file by using the OPEN statement. After the completion of a data transfer, you can terminate the connection between the logical unit and the file before ending the program by using the CLOSE statement. The OPEN statement enables you to explicitly connect a logical unit to a file prior to the first data transfer, and also to specify a variety of characteristics about the file and the data transfers. After the last data transfer is completed, the CLOSE statement enables you to explicitly disconnect the logical unit from the file and, optionally, to specify a variety of characteristics about the CLOSE. If you do not precede an I/O statement with an OPEN statement, FOROTS automatically performs an "implicit OPEN" (see Section 11.2.1). Similarly, if you do not specify a CLOSE statement to explicitly disconnect a file from a logical unit, FOROTS performs an "implicit CLOSE" (see Section 11.4.1) when your program terminates. You need not specify the OPEN and CLOSE statements if performed by the implicit OPEN or CLOSE are satisfactory. the actions OPEN Statement 11.2 OPEN STATEMENT The OPEN statement is used to specify characteristics of a file you wish to read or write. An example of an OPEN statement is: OPEN that (UNIT=20,FILE='MYDATA.DAT') The specifiers inside the parentheses give information about the and determine how the file is opened. 11-1 file FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The UNIT specifier (in the example above, "UNIT=20") is required in an OPEN statement. All other specifiers are optional, including the FILE specifier in the example shown above. You can supply many other optional specifiers (see Section 11.3 for a description of OPEN statement specifiers). The order in which the specifiers appear does not affect the execution of the OPEN statement. By using the OPEN specifiers, you are able characteristics of each data transfer, including: 1. The name of the data file 2. The type of access required 3. The data format of the file 4. The disposition of the data file 5. The data file record and block sizes to define certain In addition, a DIALOG argument permits you to establish a dialog mode of operation when the OPEN statement containing it is executed. In a dialog mode, interactive terminal/program communication is established, enabling the user to define or redefine the values of the OPEN statement specifiers. When a file is open for output (STATUS='NEW' or ACCESS='SEQOUT'), a null file is created on the device specified by FILE= OEVICE=, or if none, the first structure in the job's search list. An OPEN statement is referred to as a both of the following are true: "deferred" OPEN • The OPEN statement specifies STATUS='UNKNOWN' specify a STATUS value). • The OPEN 'SEQUENTIAL' statement (or does statement specifies ACCESS='SEQINOUT' (or does not specify an ACCESS value). if not or The actual opening of the file is deferred until the first data transfer statement (READ, WRITE, PRINT, PUNCH, or SKIPRECORD). The actual opening of the file means the determination of the physical device, and for TOPS-20, the generation number (if not explicitly specified) . If the first data transfer statement is a READ or SKIPRECORD the first file that matches the file specification given in the OPEN statement is opened. If no file exists that matches the file specification given, a null file is created on the device specified by FILE= or DEVICE=, or if none, the first structure in the job's search list. The file is positioned as if a READ or SKIPRECORD statement had been executed, and an end-of-file error will be generated (see END=, Section 10.4.6). If the first data transfer statement is a WRITE, PRINT, or PUNCH statement, a new file (with a new generation on TOPS-20) will be created on the device specified by FILE= or DEVICE=, or if none, the first structure in the job's search list. If the file specified in the OPEN statement does not exist, and either a CLOSE statement is executed oi the program runs to completion, a null file is created on the device specified by FILE= or DEVICE=, or if none, the first structure in the job's search list. 11-2 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.2.1 Implicit OPEN When the OPEN statement has not been executed before a data transfer that references the unit number, an implicit OPEN is performed. An implicit OPEN has almost exactly the same effect as if you had put an OPEN statement with the following format in the program just before the data transfer statement: OPEN (UNIT=un,STATUS='UNKNOWN' ,FORM=fm) where: nu~ber un is the unit statement. specified in the data transfer fm is 'UNFORMATTED' if the data transfer statement is an unformatted RE~D or WRITE statement; otherwise fm is 'FORMATTED' • In addition, if the data transfer statement has an ERR specifier, the implicit OPEN has this same qualifier included. This is also true of the IOSTAT specifier. NOTE The default for the BLANK specifier is different depending on whether the OPEN is implicit or explicit (see Section 11.3.3). 11-3 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.2.2 OPEN on a Connected Unit If the OPEN statement contains a STATUS=OLD specifier (see Section 11.3.29), then its action depends on whether a file is already OPEN on the unit, and whether the file specified by the OPEN is the same file that is currently on the unit. If the file specified by the OPEN is different from the OPEN file, the connected file is closed and the new file is opened. If the file specified by the OPEN is the same as the connected file, the file is not closed, and the file pointer is not moved. This action is not affected by the /F66 compiler switch (described in Chapter 16). 11.3 OPEN STATEMENT SPECIFIERS All of the OPEN statement specifiers are optional, except the UNIT specifier, which is required. Some specifiers have default values that can depend on the unit number or the values of other specifiers. Table 11-1 summarizes the type of value required by to detailed description"s specifiers are summarized specifiers in the OPEN statement and the each. A section number is provided to refer of each specifier. The CLOSE statement in Table 11-5. 11-4 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-1: Summary of OPEN Statement Specifiers and Arguments Argument Possible Value Section ACCESS= Character expression \\ ith one of the following values: ~;EqlN', 'SEQOLJT'. 'SEQINOUT', 'SEQUENTIAL', 'DIRECT', ru\ NJ)()M' 'I{ANIHN', 'APPEND' 11.3.1 ,\SSO(,IATEV ARIABLE i:Jll'gl'], variuble or intlg('r array element 11:3_2 BLANK ~ Character expression \\ ith one of the following values: 'NULL', 'ZERO' 11.3.3 HLOCKSIZE 1'1lcgcr ('xpre:.;sioll 11,;31 ('haracter exp]'(-'s:.;ion \\ ith ol1e of the following valups: "( mTRAN' , 'LIST', 'IIEVICE' 11_:U; 'Iwractcr t'xp)'('s~ion \\ iih "me of lhe following valw's: 'GGG'. 'BOO'. 'l(iW)', '6:250', 'SYSTEM' II ;{'i DEVICE Character exprp:.;sion I\,:U-I IJ\:\LOG ('haractt'r expl'es~ion D] HECTOI{Y ,TO I'S 10 i l-h;ll'<:ictc'r expreS:--lOn I I_:\. 11 ! >I1{E('TOHY ,T()I'S,-2()\ ('h:}r<}clt'r pxprcs~\()n 1 LT IL' r )!SI'()S"~ (h;II'Llcj('r expn'sslOll IH 1FFEI{(,OUNT( 'AlmlA(~ECONTI{OL I )J':NSITY ',~()()', \\ ith one of the following values: <.\ VE', '[)I':LE'n:', 'I' {lNT', 'KEEP', 'UST, '!'llNClI'. : 1 , j 1;1 I':XI'UNCE EHR= Statement number 11.3.14 FILE c- Character expression 11.3.15 11,:1 Hi I'-IIYSIZI': INITIALIZE FOHM- Character expression v:ith one of the following values: 'FORMATTED', 'UNFORMATTED' 11.3.17 IOSTAT Integer variable or intt~ger array element 11.3.18 Lll\lIT l\1() I )J.: ('lwracll'J' ('xprl's<-.iol1 v'it h one- of the following value:-: \:-->('11', 'LINE)), 'BHlA[{Y'. 'IMAGE', 'I)lIMP' '\ ,\1\11': ('JWl'HctC'l' l'xpr'cs~i()11 1':\ 1)( '1IAI{ ,\ character e:,;pl'l':';SIU:l 111 which thl' fir::;t charilctl'l' is • , ::. ~! ",.:t,d I',\I{ITY (-haractc<]' ('xpn'S,'lOll \'"lth one of' the' following v:t1u(':--: " )I)J)', EVEN' I'[WTI-:( 'TION /'()J'S 10\ 11-5 1 • .:~2:\ FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 'fable 11-1: Summary of OPEN Statement Specifiers and ArJ,{uments (Coni.) Possible Value Argument Section !'!{(),[,H'TI()N 11 :::2.> Teil'S :ZO' 1{1':-\\)()NLY HECL- Integer expression 11.3.27 HH '()IWSIZE i 1.:\.:.!1i STATUS- Character expression with one of the following values: TYPF 'OLD', 'NEW'. 'SCHATCII'. 'UNKNOWN', 1\ FI':!'· .. ()[':LET!': I' \PI':F< )I{MAT ('hdl':lCtel' ('xpn'ssi(lll with OIl(> .)1' till' f'()!!()\\'ing \',d\ll'~: (·()In.: 1)['I\11' or INI>L'STI{Y 11.:UO UNIT- Integer expression 11.:3.:11 11..3.29 :'~\I'[l:\(;E' li.:U:2 NOTE Par compatibility with previous versions of PORTRAN-10/20, you can specify a numeric array name as the value of each of the followinq specifiers: DIALOG= DIRECTORY NAME When a numeric array name is used, FOROTS assumes that it contains a string of characters terminated by a null character. In addition, you can specify a numeric variable as the value of the DEVICE and FILE specifiers. If the variable is single precision, FOROTS assumes that it contains 5 characters; if it is double precision, FOROTS assumes that is contains 10 characters. The use of numeric array names and numeric variables in place of character variables is a nonstandard feature. ACCESS Specifier 11.3.1 ACCESS Specifier The ACCESS specifier describes the type of data transfer statements allowed. Records within files can be accessed directly (randomly) and sequentially. The form of the ACCESS specifier is: ACCESS acc 11-6 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: acc is a character expression having a value equal to the following: one of 'SEQIN' 'SEOOUT' 'SEQINOUT' 'SEQUENTIAL' 'DIRECT' 'RANDOM' 'RANDIN ' 'APPEND ' ACCESS has a number of arguments, each of which specifies a method of data access. SEQUENTIAL is the default access unless the device (UNIT) opened is a read-only device, in which case the default is SEQIN. If the device ope~ed is a write-only device, the default access is SEQOUT. The arguments to the ACCESS specifier are: SEQIN (Implies ST~TUS='OLD') The specified opened tor read-only sequential ACCESS='SEOIN' is specified, it is specifying ACCESS='SEQUENTIAL' and Section 11.3.26). SEQOUT and The specifi~d data file is opened for output sequential If access. the specified file already exists, it is superseded (TOPS-IO) , a new or generat:ion is created (TOPS-20) . SEQUENTIAL The specified data file is opened for sequential access. Records can be read from or written to the file in sequential order. However, when a record is written to the file, it becomes the last record of the file. Any data following that record becomes i naccess i bl data file is access. When equivalent to READONLY (see ,=. Records can also be written to the file and then read, as long as a device-positioning statement (BACKSPACE or REWIND, Section 11.8) is used before the READ statement. SEQINOUT Same as SEQJENTIAL DIRECT The specified data file may be read from and/or written to in units of fixed-length records. The record to be accessed next is specified in the data transfer statement by a record number. The relative position of each record is independent of the previous READ or WRITE statement. The RECL specifier (see Section 11.3.27) is required for random-access operations. You must specify a disk device when the DIRECT argument is used. 11--7 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS :~'ANDI N (Implies STATUS='OLD ' ) The specified data file is ,:)t·'neo torread-only direct access. More than one j'-;P[ can read the same tile at the same time wi th ·Ti.:!':SS=· RANDIN·. When ACCESS= I RAND IN , is spec it i ed, ;s l~quivalent to specifying ACCESS='RANDOM' and ·L\LJUNLY (see Section 11.3.26). i'ANDOM Same as DiRECT '\.PPEND The specItIed tile IS opened for sequential access. APPEND is the same as SEQOUT .~~~p~ tnat the file is positioned at its end after h, id">EN statement. Headinq an APPEND mode file is ;~eqal. R~WIND and BACKSPACE are illegal for files "t)t-'neu Wltfl APPEND access. r J tl-'-on1v ASSOCIATEVARIABLE Specifier ,I Ii L._._ ...__._._P,._P ____ .. __ .. ~ .._u . . _N".. __ .. __ ... __,__ ,_··_~._n·. ; '.3.2 ASSOCIATEVARIABLE SpecItier ~his specifier enables you to declare a variabie whose value is the 11umber ot the next record that will be read from or written to the L i 1e • ~or example, atter the execution of an OPEN statement and prior to the [irst data transfer, the associate varIable is set to 1. a data transfer atter the first record is transferred, the value of he associate variable is 2. ~n 'f'he form of the ASSOCIATEVARIABLE specItier is: /\SSOCIATEVARIABLE= Inteqer varIable or integer array element r~ you are using the ASSOCIATEVARIABLE specitier in a program that makes use of the LINK overlay facility, please read the paragraphs ~ ~l a t toll ow . ;;~ the variable yOU specify as the ASSOCIATEVAHIABLE is declared in a subroutine. then that subroutine must be loaded in the root i ink of the overlay structure. It the subroutine cannot be loaded in ~lle root link of the overlay structure, declare your ASSOCIATEVARIABLE l n a (.;Or-U40N statement so that the ASSOCIATEVARIABLE will operate :):'"operly. ~ORTRAN The reasons tor these steps are: ~hen the overlay facility is used to load FORTRAN modules, va ria b 1 e s i n the mod u 1 (~ s are g r 0 up e d wit h the .-:, 'Jr_ 1 n e In wh i c n they are declared. ,1 e 10 c a .i j~;len .'iE:"/ _, FuRTRAN subroutInes are loaded bv the overlay are uivided into sets called overlay links. '..;!' t:- 1 ink, the 0 n e s p e c 1 LL edt 0 bet her 0 0 t 1 ink, reSIdent in memory. The other overlay links are ff; 2' m(j r 'l a s rea u i r. e d • u Ve r 1 d Y i:W~VS ; ~; i. ~. facility, 11-8 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Accessing a file opened with arl ASSOCIATEVARIABLE changes the value of the specified variable. If tilis variable is in a nonresident overlay link when the access is made, J>roqram execution produces unpredictable res u 1 t s . M0 reo v E' r , t: his val' i a b 1 e is res e t to Z e roe a c h tim e its 8verlay link is removed froIT! memory. Only variables declared in routines loaded into the root link are always resident. Variables declared in COMMON statements and those declared in the main proqram al'e always resident and can always be l)Sea as an assocIate variable. For more information Ofl the LINK overlay facility. see t.he LINK ProgrammE~r' s F~eterence Manual. and Chapter 15 BLANK Specifier 11.3.3 BLANK Specifier The BLANK specifier applj,es only when reading formatted (FORMAT-statement) numeric fjelds that have a field width specified. BLANK enables you to specify how blanks in formatted numeric fields are treated in a read transfer (either as zero or ignored). The form of the BLANK specifier is: BLANK = blnk where: blnk is a character expression having a value equal 'NULL' or 'ZERO'. to either The arguments to the BLANK specifier are: NULL specifies that all blank characters within numeric formatted input fields are ignored. The exception is that a field of all blanks has a value of zero. ZERO specifies that all blanks are treated as zeros. If an OPEN statement is executed and the BLANK specifier is not given, the default is BLANK='NULL'. If no explicit OPEN statement js executed before a data transfer on a unit, the default is BLANK='ZERO' for all devices except terminals. For terminals, the default js always BLANK='NULL' regardless of whether or not the OPEN statement is given. The BLANK specifier is overridden if a corresponding data transfer statement references a format, list that contains either the BN or BZ descriptor. In this case, the BN or BZ descriptor in the format list overrides the setting in the OPEN statement until the end of the format list, or until the settjng is changed within the format list. (The BN or BZ descriptors are described in Section 12.4.9.) 11-9 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Example: OPEN(UNIT=l,~EVICE='DSK',FILE='FOO.DAT',BLANK='ZERO') READ(I,10)K 10 FORMAT(I5) CLOSE(UNIT=I) OPEN(UNIT=I,DEVICE='DSK',FILE='FOO.DAT' ,BLANK='NULL') READ(I,10)L CLOSE (UNIT=I) END In the above example, if FOO.DAT contains 123bb, K has the value 12300 and L has the value 123. f""--' . ---. . -. . . . . -- ~---''''''''----''-------''--'-'-l i I BLOCKSIZE I I' Specifier L.__ .._. _ . . _ ......... __. . . . __. .__. . . . . . _ ..... _. __ ......____..-1I il.3.4 BLOCKSIZE Specifier The BLOCKSIZE specifier enables you block size for magnetic tape files. to specify a physical storage NOTE '\LOCKSIZE specltles the physical record length, and specifies the logical record length. lU~CL(RECORDSIZE) The argument is an integer expression, and for CORE-DUMP tape format, the value assigned represents the number of words in the physical ~lock. For INDUSTRY tape tormat, the value represents the number of hytes in the physical block. (See the TAPEFORMAT specifier, Section 11.3.30.) ':'he form of the BLOCKSIZE specifier is: ;),LOCKSIZE= Integer; expression BUFFERCOUNT ;pecifier 11.1.5 hE: BUFFERCOUNT Specifier BUFFERCOUNT specifier enables you to llsed in the data transfer. . lHLers 11-10 define the number of I/O FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The BUFFERCOUNT is the number of pages used in disk transfers, and ignored for nondisk transfers. " (~ I .:> The form of the BUFFERCOUNT specifier is: BUFFERCOUNT= Integer expression If a BUFFERCOUNT is not specified, or is assigned a value at zero, buffercount is four pages. the NOTE If MODE='DUMP' is specified, BUFFERCOUNT is ignored. The BUFFERCOUNT specifier does not affect the operation at program, but it can affect execution time and memory req1lirements. the buffercount specifies the maximum For random I/O, are in memory (not yet written to dISk) buffers which operations. the numbe r o t during I/O NOTE For TOPS-20 extended addressing, all fit in FOROTS's secticn. I/O buffers must r~-·"---"-11 11.3.6 CARRIAGECONTROL Specifier CARRIAGECONTROL Specifier The CARRIAGECONTROL specifier enables you to decide how the first character of each record er~countered during an output data transfer operation is treated. (Section 12.2.3 describes carriage-control specifiers.) The form of the CARRIAGECONTR(IL speCIfier is: CARRIAGECONTROL = cc where: cc is a character expression having a value e<1Ud.L the following: 'FORTRAN' 'LIST' I TRANSU\TED' 'DEVICE' 11-11 to one of FILE-CONTROL AND DEVICE-CONTROL STATEMENTS _~\~ arquments to the CARRIAGECONTROL specifier- are: speclties that the FORTRAN data file attribute is .. , In the file's access information, so that when 'H~ tIle is printed, the fj_rst character of each r~~ord IS replaced with a carriage return and the ]rrC~pondlng printer-control vertical motion 'Jaracter(s) (see Table 12-3). The record i l~rmindtor at the end of the record will be r.I:-''1' specifies that the first character is output with no ;- " pia c e men t . TRANSLATED speclties that the first character of each record is :~Dlacea wIth a carrIage return and the , orresponalng printer-control vertical motion -,en deLer (s) (see Table 12-3). No record terminator , written at the end of the record. c,- .-} t e t hat the 1 a s t d a t a r e cor din the f i 1e has no "=lcJinq carriaqe return/line feed sequence unless a '~aflk record is written. O[ i lxed-ienuth tiles, TRANSLATED is treated as ,. c· 'T" i • ~.) specifies that the first character will only be i~pldce8 for a carriage-control device (such as LPT () [ :'he default value l'TY). is CARRIAGECONTROL='DEVICE' 1 inp nrintp.r software aSS1]meS that the first (;f1-':1rdcter at all data files is a carriage-control ,:ildracter It the fIle has the extension .DAT or if the :!TLE:FORTRAN switch is specified. '!hp 1 DENSITY Specifier I .I i j ,3.7 DENSITY Specifier ';'he DE:NSITY specifier is ionored except when used with magnetic tape; lr Germlts you to specity the tape density. If you do not specify a '_Jpe densIty, FORTRAN assumes that you have set the density at monitor ievel "hp or tor~ that ot the you are D~NSITY satisfied specifier is: 11-12 with the system default for the FILE-CONTROL ANI> DEVICE-CONTROL STATEMENTS where: dens is a character expression having a value equal. to the f.ollowinq: one ot for the '200' '51)6 I '800' '1600' 'G250' . :;YSTEM' SYSTEM specifies that the den:)lty magnetic tape device being us!~d. JLS the detault denslty 0r:VICE : ;[}ecifier 11.3.8 DEVICE Specifier The DEVICE speciJ~ler enablt~s IOU to specity tne name oJ.: Lfle deVIce involved in the data transter. A loqlcal name always taKes precedence over a physical name. The DE~ICE arguments can specity 1/0 devlces located at remote statlons, a3 weil as loglcal deVIces. The form of the DEVICE specltier is: DEVICE= Character expreS.310n It you omit this option, tne logical name un (wnere un IS tne decimal unit number) is tried. IE this is not successtul, the standard ( d e fa u 1 t) de vic e ass 0 cia ted wit h the un i t I S use d ( see '1 a ole 1 U- 3) • ;J~!'\LOG ~p:edfier 11.3.9 DIALOG Specifier The DIALOG specifier enables you to type In additIonal when the OPEN statement is actually executed. UP~N speciiiers If the DIALOG specifier is found In an OPEN llSt, tnen eacn time the OPEN statement is executed FUHU'l'S suspenejs executIon dnd prompcs t:.he terminal with an asterisk. The torm of the DIALOG specltier is: DIALOG 11-13 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Yuu can respond to the asterisk prompt by entering a file ;',pecification, DIALOG switches (see below), or a file specification followed bv DIALOG switches. The file specification may be a full file specification including the device, directory name, and so on. i'JUTE i) I A L OG s wit chi san v 0 PEN s p e c i fie r ( ex c e p t D I AL OG , CIALOG=, UNIT, NAME, FILE, IOSTAT, or ERR) preceded by d ::; 1 ash (/). 1\ ;"-,r example, when FOROTS enters DIALOG mode, you :3uch as: can type a string *DSK:FOO.BAR/MODE:BINARY/ACCESS:DIRECT DIALOG= Specifier .j J 1 .3.10 DIALOG= Specifier The DIALOG= specifier enables you to include all or a portion of the ·,:?EN speclfiers in a character expression. The contents of the character expression are interpreted as if yOll had given the DIALOG :pecifier (see above); and, when the asterisk prompt was given, you liad typed in the same strinq as is contained in the character 0xpression, followed by a carriaqe return. The form of the DIALOG= specifier is: ~) tAL 0(; = C h a r act ere x pre s s ion L:xample: OPEN(UNIT=l,DIALOG='DSK:FOO.BAR/ACCESS:SEQOUT/MODE:ASCII') L c:22 !')O l'JnITE(1,100)I FORMAT(I5) ;~ND DIRECTORY (TOP5-10) Specifier 1 j . L 11 DIRECTORY Specifier (TOPS-IO) 'in TOPS-lO, the DIRECTORY specltier is iqnored except for disk files. !t Sp8cltles the location of the User File Directory (UFD) and, .) EJL. ion a 11 y, the Sub F i leD ire c tor y ( S FD), e i t h er a f wh i c h can can t a i n , }!'~ fi le snecified in the OPEN statement. 11-14 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS . c • 1· "" 'l'he form of the DIRECTORY specitier U1RECTORY:=: Character express10n The UFD is the di~ectory in which a user's files are stored; the SFD exists within the UFD. An SFD is often used to group files into ::cpdrate subdirectories. The following is a sample of the UFD and SFD specification: lO,7,SFDA,SFDB In the sample specification, 10,7 is the project-programmer number. 'I'his is an adequate directory specification if the file is in the UFD ~;peci[ied by 10,7. The SFDA and SFDB specify two levels of subfile (lirectories. The complete directory specification indicates that the ! lIe is located in subtile directory SFDB. As indicated, the path to SFDB is through the UFD lU,l and through the SFD SFDA. NOTE Hefer to the TOPS-IO Mon1tor Calls o f- d ire c t o--r i e s complete description dIrectory structures. The follo\ving Manual tor a and multilevel is an example of a character expression specification: 1'[ HECTORY= t 10,7, SFDl, SFD2, SFD3· - ....-. ~.~ - -_.---...-- .- ..... --- ~---. Project SubFile programmer Directory Number Path f 0 11 0 win 9 i 5 a n ex am p 1 e individual elements: '1' he 0 tho w to ass em b l e a s pe c 1 tic a t ion f r om (:HARACTER* 1 0 PROJ, PROG, PATH.l, PATH2 (:HARACTER* 1 COMM P R O,J == i?HOG:= I I 0 I 17 1 :'/:.,TH== I SFDA I PATH= 'SFDB' l'OMM:= I llPEN(UNIT=l,DIRECTORY=PRtJ//COMM//PROG//COMM//PATHl//COMM//PATH2) Th~ above specification is equivalent ,:~ x pre s s ion: I l 0, 1 , SFDA, SFDB I 11-15 to the following character --------] FILE-CONTROL AND DEVICE-CONTROL STATEMENTS E DIRECTORY (TOPS-20) Specifier - - - - - - - - . - - -..... 11.3.12 DIRECTORY Specifier (TOPS-20) On TOPS-20, the DIRECTORY specifier is ignored except for disk files. The DIRECTORY specifier enables you to define the path through the directory structure to a file specified in the OPEN statement. The form of the DIRECTORY specifier is: DIRECTORY= Character expression The argument to the DIRECTORY specifier is 3 character expression whose elements comprise the directory path specification, for example: OPEN(UNIT=22,DIRECTORY= 'GUEST') !Looks for DSK:(GUEST)FOR22.DAT or CHARACTER*12 ID 1D= 'GUEST.CLASS3' OPEN(UNIT=22,DIRECTORY=ID) !Looks for DSK:(GUEST.CLASS3)FOR22.DAT ---···__· __···-_.'" .-. . . . ._. . ._. _. __._. . ."._DISPOSE r I ""J' Specifier L ___.__.__._____ 11.3.13 DISPOSE Specifier The DISPOSE specifier enables you to specify an action to the file is closed. occur when The form of the DISPOSE specifier is: DISPOSE = dis where: dis is a character expression having a value equal to the following: 'KEEP' 'SAVE' 'l)ELETE' '2XPUNGE' 'PRINT' I [.1ST I 'PUNCH' 11-16 one of FILE-CONTROL ANI> DEVICE-CONTROL STATEMENTS The DISPOSE specj~fier must ha'le one of the following values: KEEP Specifies that the file is to be left where the OPEN statement specifies. DISPOSE='KEEP' is the default. SAVE Same as KE:EP. DELETE Specifies on TOPS-I0 that, if the device is either a DECtape or disk, delete the file; otherwise, take no action. On TOPS-20, if the device involved is the file; otherwise, take no action. a disk, delete EXPUNGE On TOPS-I0, saIne as DELETE. On TOPS-20, if the device involved is .3 disk, expunge the file; otherwise, take !10 action. PRINT Specifies that the file will be printed and kept. file must be o~ disk. LIST Specifies that the file will be The file must ~e on disk. PUNCH Specifies that the file will be punched on the tape punch and kept. The file must be on disk. printed and The deleted. paper ERR Specifier 11.3.14 ERR Specifier The ERR specifier enables you to designate a statement number of an executable statement, in the current program unit, to which control passes if an error occurs during the execution of an I/O statement. If an error occurs and no ERR specifier or IOSTAT specifier (see Section 11.3.18) is supplied, the program types an error message. If the program is running under batch, it is aborted. If the program is not running under batch, it enters DIALOG mode after processing all of the other specifiers, as if you had supplied the DIALOG specifier (see Section 11.3.9). This is true regardless of whether or not the OPEN statement was explicitly executed or implied by the execution of the first data transfer statement for a unit. The form of the ERR specifier is: ERR= s where: s is the number of an executable statement to which program control passes if an error occurs during the execution of the statement that includes the ERR specifier. The subroutine ERRSNS can be called to pinpoint the Appendix D for FOROTS error values returned by ERRSNS. 11-17 error. See FILE-CONTROL AND DEVICE-CONTROL STATEMENTS FILE Specifier 11.3.15 FILE Specifier The FILE specifier enables you to name the file involved in the transfer operation. You can specify a full file specification. data The form of the FILE specifier is: FILE= Character expression The value of the character expression is any legal TOPS-IO or TOPS-20 file specification. (See the TOPS-IO Operating System Commands Manual or the TOPS-20 User's Guide.) -----If you omit the period and extension, the extension .DAT is assumed. If just the extension is omitted, a null extension is assumed. Thus, if you want a filename without an extension, remember to use the period. If a filename is not specified, a default name is generated the form: that has FORxx.DAT where: xx is the FORTRAN logical unit number (decimal) or the logical unit name for the default statements ACCEPT, PRINT, PUNCH, READ, WRITE, or TYPE. FILESIZE (INITIALIZE) Specifier (TOPS-10 only) 11.3.16 FILESIZE (INITIALIZE) Specifier (TOPS-IO Only) The FILESIZE (or INITIALIZE) specifier is used for disk operations only. It enables you to estimate the number of words that an output file is going to contain. The form of the FILESIZE specifier is: FILESIZE= Integer expression The value assigned as a FILESIZE argument can be a integer expression, and is rounded up to the next higher block boundary (multiple of 128). 11-18 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The value specified by FILESIZE= is used as an estimate only. The effect of FILE~3IZE= is to help the monitor try to choose the best place on the disk to put the file. FORM Specifier 11.3.17 FORM Specifier The FORM specifier designates whether the records in a data transfer operation are formatted or unformatted. You should not mix formatted (character) and unformatted (binary) records in the same file. The form of the FORM specifier is: FORM ft where: ft is a character expression having , FORMATTED' 0 r 'UtJFORMA'1'TED'. a value equal to The arguments to the FORM specifier are: FORMATTED specifies that the records being contain character (formatted) data. transferred UNFORMATTED specifies that the records being contain bj.nary (unformatted) data. transferred If FORM is not specified and HaDE is 'ASCII' or 'LINED', the default value for FORM is 'FORMATr~~ED'. Otherwise, if MODE is 'BINARY', 'IMAGE', or 'DUMP' (TOPS-IO only), the default value for FORM is 'UNFORMATTED' • If both FORM and MODE are specified and they are incompatible, then DIALOG mode is entered, and you are asked to correct the incompatibility. In the following example, MODE='BINARY' and FORM='FORMATTED' are specified in the same OPEN statement. As shown below, when the program is executed, interactive DIALOG mode is automatically entered to enable the user to correct the incompatibility. PROGRAI'-l TRIMP ,FORM='FORMATTED') ltoJRITE (UNIT=l ,FMT=lO:.) FORMATflX,'This is il test .. '} OPEN(UNIT=l,MODE='B~NARY' lOl END EXECUTE TRINP LINK: Loading [LNKXCT TRIMP execution] ?OPEN unit 1 DSK:FOROl.DAT at MAIN.+4 in TRIMP (PC InS) ?Incompatible attributes /MODE:BINARY /FORM:FORMATTED 11-19 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS [Enter correct file specs] */MODE:ASCII CPU time 0.3 Elapsed time 11.4 TYPE FOROl.DAT This is a test. If neither FORM nor MODE is specified the default value for FORM depends on the access. If the access is SEQUENTIAL (or is defaulted), the default for FORM is FORMATTED. If the access is DIRECT or RANDOM, the default for FORM is UNFORMATTED. NOTE For ASCII devices (line printer, plotter, terminal, industry magnetic tape), the FORM= specifier has no meaning and is ignored; both formatted and unformatted data transfers are legal (see Section 10.3.3). IOSTAT Specifier 11.3.18 IOSTAT Specifier The IOSTAT specifier identifies an integer variable that is used store the I/O status code during the execution of a statement. to The form of the IOSTAT specifier is: IOSTAT= Integer variable or integer array element If no error occurs during the execution of the statement, the variable is set to zero. defined If an error does occur during the execution of the statement, the defined variable is assigned a positive integer value that corresponds to the number of the FOROTS error that occurred (see Appendix D for FOROTS error codes). When an error occurs, no error message is typed; instead, the program either continues at the ERR= statement number (if the ERR specifier is included), or continues at the statement immediately following the OPEN statement (if no ERR specifier is included). 11-20 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS [ 11.3.19 ._--- - - ._-_ .. .. _ .. _ __-_ _ _.] •... .. ... ... LIMIT Specifier --.- - - ... .. ..- - - - - - - - - LIMIT Specifier The LIMIT specifier designates the number of output units (such as pages) for spooled print or punch requests, which result from using DISPOSE='PRINT', DISPOSE='PUNCH', or DISPOSE='LIST' (see Section 11.3.13). The form of the LIMIT specifier is: LIMIT= Integer expression 11.3.20 MODE Specifier The MODE specifier defines the record. data mode of an external file or is a character expression having a value equal to the following: one of After a MODE has been assigned (either explicitly or by default), cannot be changed until the file is closed and then reopened. it The form of the MODE specifier is: MODE mod where: mod 'ASCII' 'LINED' 'BINARY' I IMAGE' 'DUMP' The default value of MODE depends on the values of FORM and ACCESS. If FORM is FORMATTED, then the default MODE is ASCII. If FORM is UNFORMATTED, then the default MODE is BINARY. If ACCESS is SEQUENTIAL and no FORM= is specified, then the default MODE is ASCII; if ACCESS is DIRECT or RANDOM, and no FORM= is specified, then the default MODE is BINARY. (See Section 11.3.17 for details on FORM, and Section 11.3.1 for details on ACCESS.) 11-21 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Character data is supported in formatted BINARY and IMAGE mode it is not supported in DUMP mode files. tiles; The possible values ot MODE are: l\SCI I specities the data to be )-bit ASCII characters. are terminated with a line feed, form teed, or \/ertlcal tab. l~ecor(js Takes effect on Input only. For output, this mode defaults to ASCII. LINED specifies the data to be 7-bit ASCII characters with optional line sequen~e numbers. FORTRAN removes the line sequence numbers, if present, before supplying the data to the user. (The 1 ine sequence number can be obtained by using the lunction LSNGET, see Section 13.3.1.) Note that a page mark in a file containing line ::equence numbers is a separate record. FORTRAN removes the blank sequence number, and the carriage return/form tRed sequence is read as a blank record. BINARY Specifies that data is formatted as a FORTRAN binary data tile. A BINARY file is composed of 36-bit words ~ [-; C e Sec t ion 1 0 • 3 . 2). The fir s t wo r d 0 f e a c h r e cor d i s written by FOROTS and specifies the beginning of the ;iinary record; this 36-bit value is called a type I :.()uical Segment Control Word (LSCW). i<rlct! binary record i ,:~;CWs . The type contain one or more type 2 LSCW, vir it ten by FOROTS und e r ::(~r ta in condi tions. is used to mark a record that spans lnternal buffer boundaries. i\ '..I f can 2 third FOROTS-written word, the type 3 LSCW, is always Itt en as the I a s t 36 - bit va III e i n e a c h BIN ARY r E~ cor d • All data in a "BINARY" transfer remains equivalent its external form with its internal representation. IMAGE in Specifies an unformatted binary mode. Like the BINARY form of unformatted transfers, IMAGE specifies that dAta is transferred as 36-bit values, with the internal ~nd external representation of the data remaining the '~a me. Unlike BINARY tiles, IMAGE files do not contain record ~nformation (LSCWs); they contain only the data ~r~nsterred. IMAGE files can be backspaced if a record ~; i ze i s s pec if i ed • DUMP TOPS-IO corresponds to TOPS-IO DUMP mode I/O. (See the TOPS-lO Mon i to r Ca 11 s Man ua I .) Reco rd size i s igrl-or-ecf~ Cha~acterdafa can~cif "be written into or read from DUMP 1l1Ode files. Note that there is little or no pertormance advantage to uSlng DUMP, as FOROTS uses DUMP mode internally for all disk files. NOTE For ASCII devices (line printer, plotter, termInal, Lndustry magnetic tape), the MODE= specifier has no meaning and is ignored; both formatted and unformatted clata transfers are leqal (see Section 10.3.3). 11-22 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS :'d:)le 11-2 summarizes the different MODE arquments that are n a iff ere n t de vic e s • supported l) Tahle 11-2: DEVICE and MODE Cross-Tahl,~ I 'ASCII' I)pvi('p J)lc;k (sequential) X X X X X X X X X X Disk Idin~ct.) 11I'~Ctapc 'j'f'nninal l'vhl~tap(' I ,j lit' Print!'f H.t·ader <. ';11'(1 Punch I 'aper Tapt' Reader !';iper Tape Punch I ';lrd I, 'BINARY' 'LlNI~))' r- X X X X I I I X iI i_ x x x x x X I 'IMA(~E' I T I X X X I I I I I i X A X X X A P(:~~~~011 I I I I i I .1 ~.J NL\:VlE ~. pi-"clfier I i.3.21 NAME Specifier The NAME specifier is used to specitv a full t i l e speclflcatlon. You :-:an use this specifier instEad of the DEVICE, FILE, and/or UllH..:CTORY ...:;pecifiers. ~'he form of the NAME specifier ~. L"',M E:= C h a r act ere x pre s sic n ~xamples at the NAME specifier IS: are: : TOPS-l 0): NAME= I DSK : FOCi. BAR I 1 () ,34.1 ' 'T()PS-20): NAME=ipS:<SMITH)BILLING.DAT i rhe NAME specifier can not be qiven in DIALOG mode. Also, the OPEN ,Latement cannot have both a I.·lALOG= specitier and a NAMEspecltler. 11-23 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS PADCHAR Specifier il.3.22 PADCHAR Specifier The PADCHAR specifier is used onlv lperations. PADCHAR enables vou ,]sed to pad fixed-lenqth formatted ~pecified record lenqth (see the with formatted output data transfer to speclfv a character that will be records, on output only, to their RECL(RECORDSIZE) specltier, Section :l.3.27). 'rho torm tor the PADCHAR specltier is: lADCHAR= A character expreSSIon In WhICh the tirst character is lsed ignored if The default pad character is space. The pad character IS is, if the tixed-lenqth records are not beinq used (that HECL(RECORDSIZE) specitler is absent). or if formatted I/O is not :)e i nq done. ~o specity a null character tor the pad character, you inList use the tunction CHAR (see Chapter 13), since the ;'::Clrnpiler does not allow null character constants, for l~xamp..i.e: \,Pf·;N (UNI'),=l. PADCHAR=CHAR (0)) PARITY Specifier 11.3.23 PARITY Specifier The PARITY specitier ')ermics ~ransfer is onlv Llsed for maqnetic tape operations. It you to specitv paritv to be oi)served (odd or even) during the at aata. The form ot the PARITY 'ARITY = sPE~citler IS: par '",here: D~r IS d cnaraccer exuression navlnq a value equal to 10DD' or , ~:VEN; • 11-24 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS PROTECTION (TOP5-10) c::,pecifier 11.3.24 PROTECTION Specifier (TOPS-lO) This option specifies a protection code to be assigned to the data file being transferred. The protection code is a 3-dIglt octal value indicating the level of acces~ to the tile. Each of tne three numbers in the protection code ha3 a specItic meaning. The number in tte leftmost position desIgnates the tile owner's protection; the middlE- numbe·r designates the pro]ect member's protection; and the rightmost number designates the protection tor all others users on the system. The system default tor t.he file protection is assigned if a protection is not specitied. On TOPS-IO, the form of the PLOTECTION specitler is: PROTECTION= Inteqer expression Figure 11-1 illustrates the code. 1'OPS-IO 3-digIt octal tile protectIon When sett.ing the protection code for a file open tor output, be sure not to set the protection SUCt1 that the file is protected against writing by the program; if you should do this the OPEN statement WIll fail. To protect the fj_le aqainst writing by the owner, you should give the PROTECTION specIfIer in t.he CLOSf<~ ~3tatement • r----·-- File Owner PROTECTION = nnn ~.- Other Users t_.____. . _Prolect Member~ File owner An octal dlQlt In the tirst r'OSitiOn speCifies the file access for tile 111e owner. I he file owner IS tle user whose pro'lrarnmer number maiches the directory !n wllietl the file IS con·:alned. PrOject Members An actal digit in the seC::>nd position specltles the tile access tor me project members. Protect members are us(~rs whose prolect number matches the Ijlrectory In which the file IS comalned. Other Users An octal value In the thlr,j Dosltlon speCifies the file access for all users other than the file owner or a protect rnerntJer_ -"1 p '!' •• " Fig ure 11-1: TOPS-IO F i 1 e Pr,)tect ion Nurnbe r 11-25 f"' ~ FILE-CONTROL AND DEVICE-CONTROL STATEMENTS ":1ble 11-3 lists all the possible values for each field of the "-ocectlon COde. keter to the TOPS-IO Monitor Calls Manual for more information. T'l()TE referred to in Table extended file protection . i" i 1 P. Daemon allows any user to v who can and who cannot access ,t:lr tiles (if applicable). (Refer to l'uP~-lU Operating §ystem _~o_l!I_m_~r~d_s ]:, ; I:" Daemon D~ovides • r "f" ;, r-:; l a _L • ) Tahl~' 11--:~: TOPS-IO Protection Cod£' Valm's '!klHI .VI~>aning in Owner Field \' dill{' ':'~.1\' [ill' "WIlt'r C<Ill ex('cule. i fl,' /'('ad. append to. update. wntc. re!wme. or change the protection of j'dp Tlw I'ill' I>al'rnon 1;'; not called Oil a protection failure, :'f 1,· ,1 I.. ,;\\,111'1' {',In !'Xl'CUlt~_ n'ad. apPl'nd to. update. write. or ~'pname the fill', Thl' Fill' Daemon i'- nol 1',lilpt! 011 il prott'ctioll j~lIlun', ':'IH' fi I,' {)Wllt'!' ('(in I'xpcute. read. dDpend to. UpJcltt'. Of' write the file, The Vile Daemon is not ,::1< ,j ::!1 ,I pr!ll.I'('t\OI1 lailun'. :'Iw Ii 1(' OWIH'1' C<1l1llot acce;.;;.; the hie. HUwl'\'l'r. tile uwner can use the RENAME monitor call to 'h,111l:l' IIII' 1111' prolL'lllOll. The hie Dal'mon 1:- nut called on a protection failure, Tit!' ii I" OWIl,'!' call eXI'cute. read. append to. update. writl', rename. or change till' protection of :111' iill', The mOl11tor calb thl' fIle Daemon on a protection fadUl'e, i fl!' iii" "Wlwr ('all Px('cute. n·ad. apPl'nd to. update. or write the fill', The monitor calls the File : :;il'iiliiil .1I1 ;, ['IH' prlJlvclllJlI {'ad un', fil(· O\Vlwr can ('xt'cut(' or !'l'ad thl' file, The monitor call~ the File Daemon on a protection f"; I i I t 1 !'( ~ . I'hl' lilt' Il\VTlI'r call1lot atT,'SS the file, Howe\'er. the owner can use the 1{r.;NAME monitor call to LfH' Idp pnll.t'l'tlOll. The Il)onitor call,.; the Fill' Daemon on a protection failure, :,;IOll'" ,:ktal Meaning in Proj('('t Member and Other User Fields Value I1Il'mtH'!' IO/' Olilel" c<ln l'xecute. read. append to. update. write. rename, or change the • !'i'p ,11'1111'('t iii '!!'.ilj-'l'!jlll! ,:q ;;;('i('('l dl" iilt" IIIL'llllwl illl' "lIwl' I I'<tll ,'xl'cuLl'. 1"',1(1. appt'nd to. update. write. or rename the file, ! :". [)f'('ll'('[ 1T1t'lflilt'l' ;(Ii' olifl'l j ,'all (·Xl'cut!'. /'('ad_ appt'nd to. update. or write the file. f i'h., nl'OIl'I" IflI'llltH'1' lor ottH'1'1 call t'Xl'Cutl'. rpad. appl'nd to. O!' update the file. !'IH' (l1'1J1l't'1 IIWIlllwl' lor ntiw!,1 call I'XI'l'ute. I't'ad. or append to the file, II II,' prlllVl't 11I1~fl1tlel' (or Ultlt'I'1 can execule or reaL! the tile. TIlt' nrOf('1'1 11lt'1Il1H'1' lor other I call onlv execute the fIle, 'j';ii' i'liP;'-> L ii. pnlll'l.'i 1I1l'lllhe)' Ill)' oliler! has Ill) at'Ll'S" to the file. PH,()'l'U:T LON can be an integer expression. If the argument zero vdlue or lS not specified, the default protection i '.J [ Lile TOPS-10 Installation is used. 11-26 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS PROTECTION (TOPS-20) -:recifier 11.3.25 PROTECTION Specifier (TOPS-20) The PROTECTION specifier enab:.es you to designate an octal protectIon code for the file. The protE!ction code is a 6-digjt octal value that designates the access to the 1:ile of the owner, group members, and other system users. On TOPS-20, the form of the PHOTECTION specltler IS: PROTECTION= Integer Figure 11-2 illustrates a -r· - - expr(~ssion TOP~;-20 pI:otection cone. File Owner ! : ' - - G r o up Memter r--Other Users + PROTECTION = nnnnnn File Owner The leftmost two digits jesiqnate the file access tor the 111e owner user who is connected 10 the directory in which the file resl(ies. Group Member The middle two digits d,;slgnatc the file access tor group memt)ers l~roup memDers ar(~ established by the syst;m administrator. A group member~;hip enatdes a user to srlarl"; files among other users In the same group. Other Users The rightmost two digit~: designate the file access fOI all us~~rs on lilC systern. oltwr Ulan the file owner or a qrouo member. Figure 11-2: I he tile owner IS the TOPS-20 Protect Lon Number Table 11-4 lists the possible protection values and their meaninqs the TOPS-20 file protection code. Table 11-4: Octal Value TOPS-20 Protection Code Values Meaning in 0" ncr, Group Member. or Other Ust'!" Field" 77 Permits fu II access to th(.' fi Ie. 40 Permits rC'ld-only access io the j Ie. 20 Permits write and delete access: 0 the file. 10 Permits execute-only access to tll' file. 04 Permits append-only ac('cs~ to the fill>. 02 Permits li;;,ting of the fil!' specification using the DIRE('TOI{Y (,()lllnwlld. 00 Permits nco access to the' fil('. 11-:27 In FILE-CONTROL AND DEVICE-CONTROL STATEMENTS TOPS-20, PROTECTION specities a protection code to be assigned to data tile belna transterred. The protection code determines the i0vel of access cnat three classes ot users have to the file. 0n ~ne takes an lnteaer expreSSIon as an argument. If PROTECTION asslqnea a zero value or is not specified. the default protection >;rle establishE~d for vour connected directorv 1S used. ')!~OTECTION READONLY Specifier ~1.3.26 READONLY Specitier READONLY specltier is used to speclty that the program will only from the tile. Output to the tIle is L_leqal and will cause an 'rro[ ~t execution tIme. ':"lC -,-','10 ~': e form of the READ a NL Y s p e cit i e r is: '::f\iJON L Y REel (RECORDSIZE) Specifier 11.3.27 RECL . :::'>:'RDSIZE) Specifier The RECL (0r KECORDSIZEI of characters or words for all files opened for ';~ANDIN'). (See Section specifier enables you to specify the number in each record transferred. RECL is required direct access (ACCESS='DIRECT', ~RANDOM'. or 11.3.1.) The form of the REeL specifier is: REeL= Integer expression an ASCII transter (MODE=fASCII or 'LINED'). the value assigned the number 0 f cha r acte rs in each record. I to ;n<CL spec 1 ties For output to disk or CORE-DUMP tape files, in addition to these characters, FOROTS adds a carriage return/line feed to each record, followed by enough null characters to fill the current word, so that records are word-aligned. REeL is enforced on output by padding short records with the padding character for formatted records. Long records are truncated. FORTRAN enforces a specified REeL for all input operations. If the REeL specified in an OPEN statement is different from the actual size of the records, FOROTS reads the number of characters specified by REeL. 11-28 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS For input to disk or CORE-DUMP tape files, specifying a record size directs FOROTS to read records that are word-aligned. The calculation of the actual recordsize is the size specified, plus two for the carriage return/line feed, plus the number of nulls necessary to word-align the record. 1"0 r INDUSTRY tapes, wi th RJ~COf~DTYPE=:' FIXED', RECL spec 1 t 1 es the exact ilumber of characters In edch record; there are no termInators or ;),ldd ing character s. .b'or lNDU~i·l·H.Y t:apes WI th RECORDTYPE=' VARIABLE' , f~ECL :;pecifies the maximum record size in the f i l e , excludIng the RCW. When the record is read, regardless of the contents of the record, it is interpreted as specified by the rules above; there are RECL characters of data, and the rest are ignored. No interpretation is done of the characters in the data part of the record. These characters appear in the FOROTS line buffer exactly as they appear in the file, including nulls and control characters. T ~1 the cas e 0 t ,: fld r ac te r s and M0 1) E = ' LIN E: D', 1: h e va Iu e 0 t R E C L e x c 1 u (1 e s t h e tab in each .lltte-sequence n umbe r • t i ve iJilldrV tran!::;ter (MODE::::'B_:NARY'" or 'IMAGE'), the value assigned f-n:CL specitles the fluml>er ot 36-bit words in eacl1 record. .For MODE='BINARY', ttle value In RJ;CL excludes the LSCWs wrItten by t'UROTS. fn d 1-0 i t MOD E '" ' 1) U M P' 1 ssp e c i fie d" R EeL 1s 1 g nor e d • RECORDTYPE SDecifier 11.3.28 RECORDTYPE SpecltIer The Rr~CORDTYPE specitier detilles magnetic tape fIle. The torm of the HECORDTYPE lRCORDTYPE the Spl~cltIer format. is: = rtype tJhere: Lype l ~j den d r d C !_ e r t-' X pre S :::0. 1 0 n 11-29 ot the records In a FILE-CONTROL AND DEVICE-CONTROL STATEMENTS ncr: (CORE-DUMP) . For the standard ANSI Tnu3, the record data is r~Ym;~A[orS or carriaae control 7"""'''y"'1 ·'11 r~C';-1.y arter another. to : x;·rj-- i ."!ui fl >iocks. For this record OPEN tne c;l?rlrU-'(] format jh-oir: tor t -, l s i s :1: f n ,- f~, ,-'i t- &. I.," I ~ i '~I '-: ,1Iil P '/ f-' P n h v:::; 1 r. A l b -1 0 c k s () n t h f> X" An, f () r the last b Joe k . thi~ ,~ !:! format sDecifies standard stream record pnd of r~~()rrl ~ lIes. ,. : f,',:.;;r • ~t?lnn'1l"'C1 _OJ -;, :::;rrprlm rj,~ i 1mi t t)'" ""- ,ii'[ldV [()r I;; rerminAi.or is records. For irjpntical to that the _.,'. ::. ,'x '"", ~',(~ ,; l r or the i.ASr:. nl.ocK. : '; i (~. :-.... ;.:; .. ,-- ! ;--' r r - ,-: -- r ) ! l M P i 1 A -..-: 1 f!!, , i ;:nii:-;;'-;f':~ '" n('), c1eflne(1 tor r t1 p h v t- p s i n r .~ c~ r:- p r ot dat:.a _ ,,_ ; ,,, (i 'I ,;, ,if"> is 1 t a i p t n P A C t: II i'I i r e cor d Rr~CORDS I Z E CRLr'. rlrit'i'I. formAt t-Anp 11-,-hlt WIlt 1 ,--i chis the And (COR f<---:-D1JMP) • is the standard recon1s are (latA IS wr'lttpn Tnus. rp("r)rO rn-"'lY',"lcrprs. , .. / r ~ ~~ - (.....l. r ", ,... ,. , ~ ---". •.:..:- 1 () t to .. r~ ""7 £.,l. exceed the block i t tl" " :ti ; -) : i. i'. f:· ! -: .~~ ;"'; ( .. C" Cl this 1 , W; i i , f.."ofi t .. ~ • ~rJ tS rOijr rpcord tess cnaracters .. STATUS ;-; 'f:~E) Specifier 11.3.29 STATUS Specifier The STATUS specifier lets you specify whether or not the file being opened must exist, or what to do with the opened file when it is closed. 11-30 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The form of the STATUS specifier is: STATUS = sta where: sta is a character expression whose value is equal to the following: one of 'F:XPUNGE' 'OLD' 'NEW' 'SCRATCH' 'UNKNOWN' 'KEEP' 'DELETE' The arguments to STATUS are: I';XPUNGE On TOPS-lO, thjs specifies that the fIle IS ~eletej \!lhen it is clo~,ed. On TOPS-20, this spec fies that the f iJp is deletec. and expunged when it is ctosed. NOTE On TOPS-IO any delete also expunges a t J I.e from st.orage. On TOPS-20, a DELETE operatIon marks the 1ile as deleted; an EXPUNGE c)peratlon immediat:.ely erases the file from storaqe. I OLD Specifies that the file being opened must already exist. If the file does not exist, an error results. NEW On TOPS-10, STATUS='NEW' specifies that the file must not exist. ]f the file does exist, an error results. An error also occurs if you specify STATUS='NEW' with ACCESS=" ·::O:N', 'SEQUENTIAL',· ~'i:(;TN()UTi (to a read-only device), .Il~ '[U,NDIN' (see Section 11.3.1). acts On TOPS-20, the STATUS='NEW' specifier in the differently, depending on what you have directory befoI·e STATUS='NEW' is executed. Also, the way you specify the file in the OPEN statement which contains the STATUS='NEW' specifier influences the way the STATUS='NEW' specifier operates. The following list describes the ways that this specifier can operate when used on TOPS-20. 1. If the file specified in the OPEN statement does not currently exist in the directory, and no generation number is specified, then the STATUS='NEW' specifier creates the specified file and gives jt a generation number of 1. 2. If the fj.le specified in the OPEN statement contains a name, extension, and generation number that does not exist, the specified file is used. 3. If the flle specified in the OPEN or CLOSE statement contains a name, extension, and generation number that is exactly the same as an existing file in your directory, then STATUS='NEW' causes an error, and no file is created. 11-31 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 4. If you did not specify a generation number, but the file specified has the same name and extension as an existing file in your directory, then the file with the same name and extension and the next highest generation will be created. Specifies that the file will be automatically deleted when the file is closed. STATUS='SCRATCH' implies SCRATCH The A SCRATCH file is always given a name by FOROTS. the FOHTRAN name of the file is inaccessible to program. If STATUS='SCRATCH' is used, you must not specify FILE, 'l( Vr:RSl()N. If your program is writing a file with STATUS='SCRATCH', and the file is being written to disk, you can retain it by executing a CLOSE statement that renames the file to a specified name. !-\ i-i,i;',,,',i!()N, '! If a file is opened with STATUS='SCRATCH', the access must be ACCESS=' SEQUENTIAL' ',.;JUT· 1 or ACC ES S = ' DIRE CT ' , " , ',,, til . ) ( see Sec t ion 11. 3 • 1) • ,I Specifies that a file opened for an input operation must exist. When a file is opened for output with STATUS='UNKNOWN', if the file exists, it is superseded; if it does not exist, it is created. UNKNOWN UNKNOWN is the default for STATUS. This value is used unless you specify STATUS or unless the value of STATUS is otherwise determined by the ACCESS specifier. , ; ;-:; c '-: ; i i e ,c:; t, tl a t ;'~ h (; :- i i e i s no',: del e ted • to )i..Ja~ent .1fi': :-,'l'/\'J'lJS=' UNKNOWN' • ",.j', lj n TOP S - 1 O. S U t' elL 1 e s t II a L the UidL I I ~- ! ..::: tlle ,~ 1 () :, pd. IS T' ~i,PEFORMAT S!J(::ci iier I l.3.JO :nrrn TAPE FORMAT SPECIFIER oj 1 ne iAi"r;i'UHMAT Soecifyinq specifvinq snecltler 11-32 IS: elI e w i 11 bee r a sed w hen tile will be deleted t i l e IS erased when a (]lVt~n. 'J'o undelete a TIl e FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: tmode is a character expression 'CORE-DUMP' or 'INDUSTRY'. having a value equal to The values for the TAPEFORMAT specifier are: CORE-DUMP specifies the "DIGITAL-compatible" tape format, which is 36-bits stored in five frames on a 9-track tape. The SET TAPE RECORDSIZE (TOPS-20) or SET BLOCKSIZE (TOPS-IO) command is interpreted to be the number of 36-bit words in the magnetic tape blocks on the tape, and is used if no BLOCKSIZE specifier is given in the OPEN statement. If a BLOCKSIZE specifier is given in the OPEN statement, it is interpreted to be the number of 36-bit words for both formatted and unformatted files. INDUSTRY specifies characters are read or written in standard industry tape format, one character per tape frame. UNIT Specifier (required) 11.3.31 UNIT Specifier (Required) The UNIT specifier defines the FORTRAN logical unit number to be used. FORTRAN devices are identified by assigned decimal numbers within the range 0-99 (see Table 10-3). UNIT must be an integer expression. The form of the UNIT specifier is: UNIT= Integer expression If the unit specifier is the first specifier given in the OPEN statement, the keyword UNIT= is optional. For example the following statement opens a file on unit 20: OPEN (20,FILE='MYFILE') NOTE The FORTRAN standard logical unit assignments are described in Section 10.4.3.1. Although the range of logical unit numbers shown in Table 10-3 is 0-99, the range of UNIT numbers is an installation-defined parameter. 11-33 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS VERSION (TOP5-10) Specifier 11.3.32 VERSION Specifier (TOPS-IO) Use the VERSION specifier for disk operations only; it enables you assign a 12-digit octal version number to an output file. to The form of the VERSION specifier is: VERSION=Integer expression 11.4 CLOSE STATEMENT The CLOSE statement disassociates an active file from a logical unit and releases the memory occupied by I/O buffers and other unit-related data. The CLOSE statement can also change some of the file characteristics that were assigned during the OPEN, such as the name, protection, directory, and disposition of the file. Once a CLOSE statement has been executed, you must use another OPEN statement (or implicit OPEN) to regain access to the closed file. The form of the CLOSE statement is: CLOSE (closelist) where: closelist 11.4.1 is a list of CLOSE statement specifiers. This list must contain the UNIT specifier (see Section 11.5.9) and can optionally contain other specifiers. Implicit CLOSE An implicit CLOSE occurs when FOROTS automatically closes a logical unit without execution of a CLOSE statement. This can happen when a program terminates, or when you execute an OPEN for a unit that is already connected to another file. 11.5 CLOSE STATEMENT SPECIFIERS All of the CLOSE statement specifiers are optional, except the UNIT specifier which is required. Some CLOSE statement specifiers have the same formats as the corresponding specifiers in the OPEN statement. Table 11-5 summarizes the specifiers in the CLOSE statement, and the typ~ of value required by each. A section number is provide~ to refer to detailed descriptions of each specifier. 11-34 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-5: Summary of CLOSE Statement SpecifiHs and Arguments Argument Pnssible Value DLVICE Section ~ : .S. I DIALO(; ( 'haractcr cxpn'SSlOn I 1IIn:( "I'< my t 'harllctcl' exprcsslOn J)1:--iI'OSE lliaractl'l' l'XPI'l'''c-IOJ1 \nth ol1e of tlll' following values: :-;1\ VE', 'IWU:Tl';', 'l'l{lNT', KEEP', 'LIST', Pl 'Nell', i i.0 .. 1 EXPUNCE' ERR- Statement number 11.5.5 IOSTAT= [nteger variable or integer array element 11.5.6 1.1\11'1' I l.f) " .\i,\.l\lE II.j I'IU),),ECTION ~ 1.'. 1 STATUS· i Character expression with one of the following values: 'KEEP', 'DELETE', :\!'UN<a.;' 11.5.8 TYI'E UNIT- Integer expression 11.5.9 QOTE For compat:.bility with previous versions of FORTRAN-lOj20, you can sp(~cify a numeric array name as the value of each of the :ollowing specifiers: DIALOG= DIRECTOHY NAME When a numeric array name is used, FOROTS assumes that it contains a strIng ~f characters terminated by a null character. In addition, you can specify a numeric variable as the value of the DEVICE and FILE specifiers. If the variable is single precision, FOROTS assumes that it contains 5 characters; if it is double precision, FOROTS assumes that is contains 10 characters. The use of numeric array names and numeric variables in place of character variables is a nonstandard feature. 11-35 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS DEVICE, DIRECTORY] FILE, NAME, and PROTECTION Specifiers 11.5.1 DEVICE, DIRECTORY, FILE, NAME, and PROTECTION Specifiers The CLOSE statement file identification specifiers can be used when you want to rename the output file when it is closed. Their formats are the same as the corresponding specifiers in the OPEN statement. If any of these specifiers are given in the CLOSE statement, the file is renamed when it is closed. If some, but not all of the file identification parameters are specified on a CLOSE statement, only the specified parameters are changed when the file is renamed. Example: OPEN(20,ACCESS='SEQOUT' ,FILE='FOO.BAR') CLOSE(20,FILE='NEWFIL') The above sequence renames the output file to DKSB:NEWFIL.BAR. Refer to the following sections under the OPEN statement: FILE - see Section 11.3.15 NAME - see Section 11.3.21 DEVICE - see Section 11.3.8 DIRECTORY (TOPS-I0) - see Section 11.3.11 DIRECTORY (TOPS-20) - see Section 11.1.12 PROTECTION (TOPS-IO) - see Section 11.3.24 PROTECTION (TOPS-20) - see Section 11.3.25 DIALOG Specifier 11.5.2 DIALOG Specifier The DIALOG specifier enables you to type in additional specifiers when the CLOSE statement is actually executed. CLOSE If the DIALOG specifier is found in the CLOSE list, then each time the CLOSE statement is executed, FOROTS suspends execution and prompts the terminal with an asterisk. The form of the DIALOG specifier is: DIALOG 11-36 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS respond to t.tle a~terlSK Drornot by enterLnq a tile iJiALOG switcres (see below), or a t1le spec1fication r,)11owed by DIALOG switches. The file specification cal. be a full " I p ~~nA"ltication 1ncludino the device. directorv namE:. cmd so on. ~:an ',,11 ")E:~cirication. '/0 II :,)eCli ': i E-' r e nc. e r a i 1.1 e S Dec 1 t 1 cat 1 0 rl t h d t IS dlr:1:ererlt lcacion currencly a!:Osloned co trle [lIe. ruH\JiS it- ! ~o. ci ()~~~~j to tile r1(~W name. tlom KE1"AMf~s the tile the tile :.,""',': !'! 1\ LUG . '. '!/\.LOG=. :_.1 ash s WIt c 11 UNIT. 1 san \. NAME:. C L OS Esp e c 1 t 1 e r foILf:o~. [USTAT, or (e x c e p t J) J l\ LOG , preceded bv t:RH) (I). ;~:ie.~_::)G -=- ;:"'--ifier D[ALOG= Specitier DTAL()(;= spec1tier enables vou to include all or a portion ot the spec1lIers 1n a cl1aracter expression. l'ne C()[1tents at the :j'~'ract:C'r expressIon are incerpreteri as if vou had qiverl the DIALOG ';~"C'11:1er (see above); and, when the asterIsk prompt was gIven, you :jdd tVDed 1n the same strirq as 1S contaIned in Lhe character '~Dression, followed by a carriaqe return. "'lie ':_:JSE :';1'2 the DIALOG= specif1er 1S: form 01 ! 1\ L OC; = C h a rae t e r e x 0 res S Ion '<xamOJe: .()f;:~ (UNIT=20,ERR=lO,DIflLO(3=' /DISPOSE:DELETE') .-Jhen DIALOG= 1 S a i ven in the l LOSE 1 i st, -'Lher ::;wecitie[~. exceDt DIALOl. :l t IS processed alter all 'l~ J>OSE -.,:",:,:ifier DISPOSE Specifier !' '--I e IH~:) PO:"; Esp e c 1 tIe r en a 1) 1 e s v 0 U to ;hp tile is closed. !'IIt=' form ,)t the DISPOSE specliier f'r~;p()sF. is: = dis 11-37 S Pe c 1 t Y a n act 1 0 n t () occur when FILE-CONTROL AND DEVICE-CONTROL STATEMENTS , 'er. e: i ; ::'lc:l(=jcter expression having a value equal to on'= ot ! { ) i i OW 1 no: flO" X i-~U~·lG E ' f NT I "j( !,jJNCH I i '" ~1 C iJ I S PO S E ':~p spec 1 tie r In u s t have one 0 t the to 11 0 win g va I u e s : Epccitles that the file is to be left on the connected n: , 1, • U I S PO S E = 'KE: E P ' i s the de fa u 1 t • You can not ';:';~:clt\/ DISPOSE='KEEP' if in the corresponding OPEN ~~;_lr.ement yOU specified STATUS='SCRATCH' (see Section ~ • ,:; ~ 1 • ~ame as Kr:r:P. :'~Dt::cifies :; ''; (: tap e on TOPS-IO that, if the device is either a dis k , del e t e the f i Ie; 0 the r w i s e, t a ken 0 0 r ·;n TUPS--20, if the device involved is fk tile: otherwise, take no action. a disk, delete On TOPS-IO, same as DELETE. On TOPS-20, if the device ;;"i'Jolved is a disk. expunge the file; otherwise, take "j U (j c t 10 n • iT NT Specifies that the file will be printed and kept (the tile wlil not be kept if you specify the CLOSE ·;Latement STATUS='DELETE' or 'EXPUNGE'). The file must H' on dlSK. :~T specifies that the file will be printed, deleted, and '«;)~Inaed (the file will not be deleted if you specify :-h,_, CL()Sr~ statement STATUS='KEEP'). The file must be ~ i 1s k • . I .. ;;C;_~CltU?S ;, , tJ : H: c that n the ,HI d flie k e pt. will be punched on the paper The f i 1 emu s t be 0 n dis k • value ot the CLOSE statement DISPOSE specifier the value of the OPEN statement DISPOSE ~ecifier and the OPEN statement STATUS specifier if ':'.'\TUS=· EXPUNGE', 'KEEP', and 'DELETE'. [':-It:: '!)er :--;edes 11-38 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS ERR Specifier 11.5.5 ERR Specifier The ERR specifier enables you to designate a statement label of an executable statement, in the current program unit, to which control passes if an error occurs during the execution of an I/O statement. The form of the ERR specifier is: ERR= s where: s is the number of an executable statement to which program control passes if an error occurs during the execution of the statement in which the ERR specifier is included. The ERR specifier works the same way when it is given in a CLOSE as it does when given in an OPEN statement (see Section 11.3.14). IOSTAT Specifier 11.5.6 IOSTAT Specifier The IOSTAT specifier identifies an integer variable that is used store the I/O status code during the execution of a statement. to The form of the IOSTAT specifier is: - - - -.- .-._" - - -- - ] 1. IOSTAT= Integer variable or integer array element LIMIT Specifier I 11.5.7 ___________________ LIMIT Specifier The LIMIT specifier designates the number of output units (such as pages) for spooled print or punch requests, which result from using DISPOSE='PRINT', DISPOSE='PUNCH', or DISPOSE='LIST' (see Section 11.5.4) . 11-39 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The form of the LIMIT specifier is: LIMIT= Integer expression STATUS Specifier 11.5.8 STATUS Specifier The STATUS specifier tells FOROTS what to do with a file when it is closed. In the CLOSE statement, STATUS values are a subset of the DISPOSE specifier (see Section 11.5.4) values. NOTE The ANSI-77 standard does not have DISPOSE allows STATUS='KEEP' or STATUS='DELETE'. and only The form of the STATUS specifier is: STATUS = sta where: sta is a character expression having a value equal to the following: one of 'KEEP' 'DELETE' 'EXPUNGE' The arguments to STATUS are: KEEP Specifies that the file is not deleted. DELETE On TOPS-IO, specifies that the file is deleted. On TOPS-20, specifies that the file is marked for deletion when the file is closed. The file is erased when a TOPS-20 EXPUNGE command is given. To undelete a deleted file, use the TOPS-20 UNDELETE command. EXPUNGE On TOPS-IO, the same as delete. On TOPS-20, specifies that the file is deleted and expunged. NOTE The value of the CLOSE statement STATUS specifier supersedes the value of the OPEN statement DISPOSE specifier and OPEN statement STATUS specifier if STATUS='EXPUNGE', 'KEEP', and 'DELETE'. 11-40 this FILE-CONTROL AND DEVICE-CONTROL STATEMENTS UNIT Specifier (Required) 11.5.9 UNIT Specifier (Required) The UNIT specifier tells FOROTS which logical unit number is to be closed. This specifier corresponds to the UNIT specifier in the OPEN statement (see Section 11.3.31) and to the UNIT specifiers in the data transfer statements (see Section 10.4.3). The form of the UNIT specifier is: UNIT= Integer expression If the unit specifier is the first specifier given in the CLOSE statement, the keyword UNIT= is optional. For example, to close a file on unit 20, you can use the following command: CLOSE (20) 11.6 OPEN AND CLOSE STATEMENT EXAMPLES The following are examples of OPEN and CLOSE statements: OPEN (UNIT=l,DEVICE='DSK' ,ACCESS='SEQIN' ,MODE='BINARY') causes a disk file named FOROI.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',RECORDSIZE= 80, 2 ASSOCIATEVARIABLE=I,ERR=240) Causes a disk file named PAYROL.DAT to be opened on unit 3 for random I/O 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 terminates, and control is transferred to the statement labeled 240. CLOSE (UNIT=3,DISPOSE='DELETE') The above statement causes the file closed and deleted. 11-41 associated with unit 3 to be FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7 INQUIRE STATEMENT The INQUIRE statement inquires about specific properties of a file name or of a logical unit number on which a file might be opened. The INQUIRE statement has two forms: one inquires by file, and the other inquires by unit. 11.7.1 INQUIRE by File An INQUIRE by file is an INQUIRE statement containing the following: • A FILE= keyword • An associated file specification • No UNIT= keyword It is used to obtain information about a file based on the file name. INQUIRE by file can be used to get information on the following files: • Files that are "connected"; meaning files for which an OPEN statement has been executed or for which a data transfer statement has been executed. • Files that are not "connected." INQUIRE by file has the following form: INQUIRE (FILE=fi [, fl ist] ) where: fi is a character expression whose value specifies of the file to be inquired about. flist is a list that can contain at most one of inquiry specifiers (see Section 11.7.3). each the name of the INQUIRE by file may be used any time during the execution of a program. It can be used before a file is opened to find out about the existence of the file, or after the file is opened to find out other attributes of the file. It can also be used to find the unit number on which the file is opened. If the same file is opened on more than one unit, the smallest number on which the file is opened is returned. The determination of whether a file specified in an INQUIRE is opened on a unit is the following: statement 1. The file specification given in the INQUIRE statement is used to lookup the file. 2. If the file exists, the file specification, expanded with the physical device name and generation (TOPS-20 only), is compared with the file specification for each open unit, in ascending order, until there is an exact string match. 11-42 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 3. If the Eile does not exist, the specification given in the INQUIRE statement (with a default of DSK: added if necessary for the device name), is compared with the file specification for each open unit, in ascending order, until there is an exact string match. Note that this match will only be successful for 'deferred' OPEN files, since non-deferred OPEN files are always established in the specified directory immediately. Therefore, the file exists (see item 2 above). NOTE If a file exists, INQUIRE by file will not generally match the file with a unit for which a 'deferred' OPEN has been done, since the file specification for the unit has not been expanded. For example, the file's logical device name has not been replaced by a physical device name. (See Section 18.8 for information on FOROTS and INQUIRE by file.) 11.7.2 INQUIRE by Unit INQUIRE by unit is an INQUIRE statement containing a UNIT= keyword and no FILE= keyword. It is used to find out information about the file that may be "connected" to the specified unit. INQUIRE by unit has the following form: INQUIRE ([UNIT=]u,ulist) where: u is the number of the logical unit to be inquired about. The unit need not exist, nor need it be connected to a file. If the unit is connected to a file, the inquiry encompasses both the connection and the file. ulist is a list that can contain at most one of inquiry specifiers (see Section 11.7.3). each of the If the optional UNIT= keyword if omitted, u must be the first item the list. in INQUIRE by unit can be used at any time during the execution of a program. It can be used before a file is opened to find out if there is another file open on the unit, or after the file is opened to find out other attributes of the file. 11.7.3 Inquiry Specifiers The specifiers described in the following either form of the INQUIRE statement. 11.7.3.1 form: sections ACCESS Specifier - The ACCESS specifier ACCESS acc 11-43 may has be the used in following FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: acc 11.7.3.2 form: is a character variable, array element, or substring reterence. It is assigned the value 'SEQUENTIAL' if the file is connected for sequential access, or 'DIRECT' if the file is connected for direct access. If there is no connection, acc is 'UNKNOWN'. BLANK Specifier - The BLANK BLANK specifier has the following blk where: array element, or substring is a character variable, reference. It is assigned the value 'NULL' if the file and is assigned the was last opened with BLANK='NULL', value 'ZERO' if the file was opened with BLANK='ZERO'. If the file is not open, blk is 'UNKNOWN'. blk 11.7.3.3 CARRIAGECONTROL has the following form: Specifier - The CARRIAGECONTROL Specifier CARRIAGECONTROL = cc where: ~c 11.7.3.4 form: is a character variable, array element, or substring reterence. It is assigned the following values: L 'FORTRAN' if the file has the FORTRAN carriage-control attribute 2. 'LIST' if the file has attribute L 'NONE' 1. 'TRANSLATED' if the file has FORTRAN carriage-control characters being translated directly into vertical motion characters. ~. UNKNOWN if the CARRIAGECONTROL value determined. or the file is not open. the implied if the file has no carriage-control attribute DIRECT Specifier - The DIRECT specifier DIRECT carriage-control dir 11-44 has cannot the be following FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: dir is a character variable, array element, or substring reference. It is assigned the following values: 11.7.3.5 ERR 1. 'YES' file if DIREc'r is an allowed access method for the 2. 'NO' if DIRECT is not an allowed access method for the file 3. 'UNKNOWN' if tne processor is unable to whether DIRECT is an allowed access method determine ERR Specifier - The ERR specifier has the following form: = s where: s 11.7.3.6 form: EXIST is the label of an executable statement. ERR is a control specifier; if an error occurs during execution of the INQUIRE statement, control is transferred to the statement whose label is s. EXIST Specifier - The EXIST specifier has the following ex where: ex 11.7.3.7 FORM is a logical variable or logical array element. It is assigned the value .TRUE. if the specified file or unit exists, and the value .FALSE. if the specified file or unit does not exist. FORM Specifier - The FORM specifier has the following form: = fm where: fm is a character variable, array element, or substring reference. It is assigned the value 'FORMATTED' if the file is connected for formatted I/O, and 'UNFORMATTED' if the file is connected for unformatted I/O. If there is no connection, fm is 'UNKNOWN'. 11.7.3.8 FORMATTED following form: FORMATTED SpecifieI' - The = fmd 11-45 FORMATTED specifier has the FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: fmd 11.7.3.9 form: is a character variable, array element, or substring reference. It is assigned the value 'YES' if formatted is an allowed form for the file. It is assigned the value 'NO' if formatted is not an allowed form of the file, and the value 'UNKNOWN' if the form cannot be determined. IOSTAT Specifier - The IOSTAT specifier IOSTAT has the following ios where: ios 11.7.3.10 is an integer variable or integer array element. It is assigned a processor-dependent positive integer value if an error occurs during execution of the INQUIRE statement, or assigned the value zero if there is no error condition. NAME Specifier - The NAME specifi~r has the following form: NAME = nme where: nme is a character reference. It inquired about. variable, array element, or substring is assigned the name of the file being The value assigned to nme is not necessarily identical to the value specified with FILE=. For example, the value that the processor returns may contain a directory name or generation number (TOPS-20 only). However, the value that is assigned is always valid for use with FILE= in an OPEN statement. NOTE FILE and NAME are synonyms when used with the OPEN statement, but not when used with the INQUIRE statement. For INQUIRE by unit, FOROTS returns the full, expanded file specification if any of the following is true: • If there is a file open on the specified STATUS other than UNKNOWN or SCRATCH. unit with • If there is a file open on the ACCESS other than SEQUENTIAL. unit with • An I/O transfer statement has been executed using specified unit and the unit has not been closed. the 11-46 specified FILE-CONTROL ANI> DEVICE-CONTROL STATEMENTS FOROTS returns thE! string given in the OPEN for NAME= with defaults applied j,f both of the following are true: • If the file is open on the specified unit as a result of an OPEN statement in which STATUS='UNKNOWN' and ACCESS='SEQUENTIAL' are specified or implied. • No I/O transfE!r statement has been executed us ing specified unit. the If STATUS='SCRATCII', FOROTS returns blanks for NAME=. If there has been no OPEN statement, and no I/O transfer statement has bE~en executed using the specified unit, FOROl'S returns for NAME:: the default file specification for that unit. For INQUIRE by file, FOROTS returns the full, expanded file specification if the file exists in the specified directory. If the file does not yet exist on the speci.fied directory, but has been opened by a 'deferred' OPEN, FOROTS returns the string given in the INQUIRE statement, with defaults applied for the device and generation number (TOPS--20 only). Otherwise, blanks are returned. 11.7.3.11 form: NAMED Specifier - The NAMED NAMED specifier has the following nmd where: nmd is a logical varidble or logical array element. It is assigned the value .TRUE. if the specified file has a name, and the val~e .FALSE. if the file does not have a name .. 11.7.3.12 form: NEXTREC Specifier .- The NEXTREC specifier has the following NEXTREC nr where: nr 11.7.3.13 form: NUMBER is an integer variable or integer array element. It is assigned an integer value that is one more than the last record number read or written on the specified direct access file. If no records have been read or written, the value of nr is one. If the file is not connected for direct access, or if the position is indeterminate because of an error condition, nr is zero. NUMBER Specifier - The NUMBER specifier has num 11-47 the following FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: num is an integer variable or integer array element. It is assigned the number of a logical unit currently connected to the specified file. If there is no logical unit connected to the file, num is not defined. If more than one unit is connected to the file, the smallest unit number is returned. 11.7.3.14 form: OPENED Specifier - The OPENED specifier has OPENED the fo1101Ning od where: od is a logical variable or logical array element. assigned the value .TRUE. if the specified file is on a unit or if the specified unit is opened; assigned the value .FALSE. if the file or unit open. 11.7.3.15 RECL (RECORDSIZE) Specifier - The specifier has the following form: RECL RECL It is opened it is is not (RECORDSIZE) = rcl where: rcl is an integer variable or integer array element. If the file (or unit) is opened, rcl is the record length for fixed-length record files. In all other cases, rcl is zero. If the file is opened for formatted I/O, rcI is expressed in characters, and in words if the file is unformatted. 11.7.3.16 RECORDTYPE Specifier - The fallowing form: RECORDTYPE RECORDTYPE specifier has the rtype where: rtype is a character variable, array element, or substring reference. It is assigned the value 'FIXED' if the file has fixed-length records, assigned the value 'VARIABLED if the file has variable-length records, and assigned the value 'STREAM' if the file is a stream file (default for disk and maqnetic tape). If the processor cannot ,Jetermine the record type, rtype is assigned the value 'UNKNOWN' . 11-48 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3.17 SEQUENTIAL Specifier - The following form: SEQUENTIAL SEQUENTIAL specifier has the seq where: seq is a character variable, array element, or reference. It is assigned the following values: 1. 'YES' if SEQUENTIAL is an allowed the specified file access 2. 'NO' 3. 'UNKNOWN' if the processor cannot determine SEQUENTIAL is an allowed access method method for if SEQUENTIAL is not an allowed access method 11.7.3.18 UNFORMATTED Specifier - The UNFORMATTED specifier following form: UNFORMATTED substring whether has the unf where: unf is a character variable, array element, or substring reference. It is assigned the value 'YES' if unformatted is an allowed form for the file. It is assigned the value 'NO' if unformatted is not an allowed form of the file, and the value 'UNKNOWN' if the form cannot be determined. 11-49 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-6 summarizes the form and use of the FORTRAN statements. Table 11-6: Summary of FORTRAN Device Control Statements Statement Form Section FIND il~NIT 11l1.Ht:C rnl.EIW ~II.IOSTAT FIND lun'rnl.Elm ~1I,lOSTAT j()~11 ioo;l! IUU HEWIND un HEWIND (UNIT - unl ,ERR - s" ,IOSTAT = ios II REWIND (unl,ERR ~ sll,IOSTAT'- iosl) :I 1.8.2 l TNLOA D lIn l'!'.'LOAD ((TNIT unl.EIW o;ll.IOSTAT llNI.OAD (unl.EHH o;lI.IOSTAT io~11 ll.!-i.:l io~1 BACKSPACE un BACKSPACE (UNIT- unl,ERR sll,I08TAT-iosl) BACKSPACE (unl,ERR=sll,IOSTAT-- ios)) I 1.8.4 ENDFILE un ENDFILE (UNIT = unl ,ERR = s II ,lOST AT - ios)) ENDFILE (unl,ERR'=sll,IOSTAT~iosl) 11.8.5 SKII'J{JTOHf) un 11.S.G SKIPRECOH]) dJNJT unl.END o;lIYlm 0;1I.108TA" iosll SKII'HECOJ{I) iunl.r:ND o;lI.Elm 0;II.10STAT ioo;li 1 - - - - - - - - - - - - - - . - - - - - - - - - - - - - 1 - . - -. SKIPFILE un llY'.I SKIPFILE IT [NIT unl.EHH ~ II.IOSTAT ioo; II 8KII'FILE (unl.EHH.;II.IOSTA'1 iosll I ;\('I(FI1.E lIn IA(,KFII.E((TNIT unl.EHH 0;11.I08TAT I ACKFII.E (lI11I.ERR 0;II.10STAT ius Ii 11.H.H io',11 11-51 device control FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.8 DEVICE CONTROL STATEMENTS Device control statements enable you to position external devices. For example, when performing data transfers with magnetic tape, you use device control statements to position the tape. The device control statements may be used for both formatted and unformatted files. The following list contains all of the device control statements, the section in which each statement is described. . FIND 2. REWIND (Section 11.8.2) .J • J UNLOAD (Section 11.8.3) 4. BACKSPACE 5. ENDFILE 6. SKIPRECORD /'. SKIPFILE (Section 11.8.7) 8. BACKFILE (Section 11.8.8) ] and (Section 11.8.1) (Section 11.8.4) (Section 11.8.5) (Section 11.8.6) NOTE The results of the BACKSPACE and SKIPRECORD statements are unpredictable when used on list-directed and NAMELIST formatted data. The general form of every device control statement is: keyword un or keyword (UNIT=un [,END=s] [,ERR=s] r ,IOSTAT=ios]) or keyword (un[,END=s] [,ERR=s] [,IOSTAT=ios]) where: keyword is the statement name. un is the FORTRAN logical unit number. Table 10-3 lists the default logical unit numbers. If you enclose the logical unit specification In parentheses, you can include the keyword portion (UNIT=) of the logical unit specification. The keyword form of the unit specifier makes the specification positionally independent in the parenthetical list. END=s is the optional end-of-file specifier 10.4.6) • 11-52 (see Section FILE-CONTROL AND DEVICE-CONTROL STATEMENTS ERR=s is the optional 10.4.7) • IOSTAT=ios is the optional I/O error Sec t ion 1 'J • 4 • 8) " error specifier (see status specifier Section (see The operations performed by the device control statements are usually used only for magnetic tape devices (MTA). In FORTRAN, however, the device control operations are simulated for disk devices. [ 11.8.1 - - - - -- --.------] FIND Statement -----_.. - FIND Statement In earlier versions of FORTRA1-.J-IO/20, the FIND statement could be used during direct-access READ/WRITE operations to reduce the time necessary to do data tran:;fers and to locate records in a direct-access fi.le. For FORTRAN-IO/20 Version 10, the FIND statement has no effect, except for se:ting the current record number and, therefore, the associate vari.:tble. The first form of the FIND st.ltement is: FIND (UNIT=un,REC=rn [,ERH=s] [, IOSTAT=ios]) The second form of the FIND s~atement operates in the same way as the first form. The difference between the two forms is in the way that the unit number and record number are specified. The second form of this statement . c' • 1· ", FIND(unl rn[ ,.ERR=s] [,IOSTAT=ios]) In this form, the unit number and record number do not contain the keywords UNIT= and REC=. Ins·:ead, the unit number is specified first, followed by a single quote ( I ' , and finally the record number. The following example demonst~ates how the FIND statement is used: PIND(UNIT=I,REC=lOO) This statement positions the rcads record 100. ~ile so that the next READ statement FILE-CONTROL AND DEVICE-CONTROL STATEMENTS REWIND Statement 11.8.2 REWIND Statement The REWIND statement, used for disk files, causes a specified file to be positioned at its initial point. For magnetic tape, execution of the REWIND statement positions the magnetic tape at its initial point. The forms of the REWIND statement are: REWIND un or REWIND (UNIT=un[ ,ERR=s] [,IOSTAT=ios]) or REWIND (un[ ,ERR=s] [,IOSTAT=ios]) where: un I~EWIND is the logical unit number of the device on which the REWIND is being performed. Table 10-3 lists the default logical unit numbers. is illegal for files opened with ACCESS='APPEND'. r -- . _.-. -' ",-- -,-..--.._.......... -- --..._- -.-----,-.------- ..,- I UNLOAD Statement I L,_______ .,. ,_. I l.8.3 UNLOAD Statement rne UNLOAD statement rewinds and unloads the magnetic tape with the specified unit. The forms of the UNLOAD statement are: UNLOAD un or UNLOAD (UNIT=un[ ,ERR=s] [,IOSTAT=ios]) ur LiNLOAD (un [ , ERR=s] [ , IOSTAT= ios] ) 11-54 associated FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: un is the logical unit number of the device on whi.ch the UNLOAD is being performe~. Table 10-3 lists the default logical unit numbers. BACKSPACE Statement 11.8.4 BACKSPACE Statement Execution of a BACKSPACE statement causes the file connected to the specified unit to be positioned before the preceding record. If there is no preceding record, the position of the file is not changed. If the preceding record is an ENDFILE record (see Section 11.8.5), the file is positioned before the ENDFILE record. The BACKSPACE statement cannot be used for direct-access files, append-access files, or files that are formatted with list-directed or NAMELIST-statement formatting. The forms of the BACKSPACE statement are: BACKSPACE un or BACKSPACE (UNIT=un [ ,ERR=~.] [ ,IOSTAT= ios] ) or BACKSPACE (un [ ,ERR=s] [ ,IOSTAT= ios] ) where: un the is the logical unit number of the device on which BACKSPACE is being performed. Table 10-3 lists the default logical unit numbers. ENDFILE Statement 11.8.5 ENDFILE Statement The ENDFILE statement closes the file on the specified unit. On magnetic tape, an 'ENDFILE record' is written and is then positioned after the end-of-file mark. For disk, the file is closed and then positioned at the end of the file, and an end-of-file status is set. This status is the equivalent of the file being positioned after an 'ENDFILE record'. 11-55 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Thus, for both disk and magnetic tape, a BACKSPACE operation given after an end file operation positions the file after the last data record (that is, before the physical (or virtual) 'ENDFILE record'). The ENDFILE statement can be used only with sequential access files. The forms of the ENDFILE statement are: ENDFILE un or ENDFILE (UNIT=un [ ,ERR=s] [ ,IOSTAT= ios] ) or ENDFILE (un[ ,ERR=s] [,IOSTAT=ios]) where: un is the logical unit number of the device on which the Table 10-3 lists the default ENDFILE is being performed. logical unit numbers. SKIPRECORD Statement 11.8.6 SKIPRECORD Statement The SKIPRECORD statement skips the record immediately following the current (last accessed) record. If the SKIPRECORD statement is executed prior to accessing any records, then the first record in the file is skipped. You cannot use SKIPRECORD on direct-access files. The forms of the SKIPRECORD statement are: SKIPRECORD un or SKIPRECORD (UNIT=un [ , END=s] [ , ERR=s] [ , IOSTAT=ios] ) or SKIPRECORD{un[ ,END=s] [,ERR=s] [,IOSTAT=iosj) where: un is the logical unit number of the device on which the SKIPRECORD is being performed. Table 10-3 lists the default logical unit numbers. 11-56 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS -_.__.__ .=._-J-.. [ SKIPFILE Statement ---. -------- 11.8.7 SKIPFILE Statement This statement is used only for magnetic tape operations. Unless an end-of-file has been encountered, the SKIPFILE statement advances to the beginning of the next file. If an end-of-file has been encountered, SKIPFILE skips the next file. If the number of SKIPFILE executions exceeds the number of files available to be skipped, an error occurs. The forms of the SKIPFILE statement are: SKIPFILE un or SKIPFILE (UNIT=un [,ERR=s] [, IOSTAT=ios]) or SKIPFILE (un[ ,ERR=s] [,IOSTAT=ios]) where: un is the logical unit number of the device on which the SKIPFILE is being performed. Table 10-3 lists the default logical unit numbers. -_·_-_·_--J C BACKFILE Statement 11.8.8 BACKFILE Statement This statement is used only for magnetic tape operations. If an end-of-file has been encountered, the BACKFILE statement positions to the start of the file whose end-of-file was detected. Otherwise, the BACKFILE statement positions to the start of the file that precedes the current (last accessed) file. 11-57 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The forms of the BACKFILE statement are: bACKFILE un ,~ r F;ACKFILE (UNIT=un r , ERR=s] [ , IOSTAT= ios] ) or BACKFILE (un [ , ERR=s] [, IOSTAT=s] ) \vhere: is the logical unit number of the device on which the BACKFILE is being performed. Table 10-3 lists the default logical unit numbers. un NOTE On a magnetic tape with multiple files, the position the tape after an ENDFILE record of one file is equivalent to the position at the beginning of the next file. of 11-58 CHAPTER 12 FORMATTED DATA TRANSFERS Data transfers can be either formatted or unformatted. When the internal (memory) representation of the data is translated to a different external (peripheral storage) representation during a data transfer, that data transfer is considered formatted. Conversely, when the internal and external representations of the data are the same, that data transfer is considered unformatted. A formatted data transfer involves editing of data as it is transferred to and from memory. FORTRAN provides you with three ways for specifying how the data is formatted during a formatted data transfer. These are: 1. FORMAT-Statement Formatting 2. List-Directed Formatting 3. NAMELlST-Statement Formatting Of the three types, FORMAT-statement formatting provides you with the most control over how the data is formatted. Section 12.1 describes FORMAT-statement formatting. List-directed formatting means that the formatting is controlled by the data types of the l/C list elements. Section 12.5 describes list-directed formatting. NAMELlST-statement formatting is the third method for formatting the data; the formatting is controlled by the data types of the namelist elements. In this form, the I/O list is defined in a NAMELIST statement and referenced by the data transfer statement. Section 12.6 describes NAMELlST-statement formatting. 12-1 FORMATTED DATA TRANSFERS FORMAT-Statement Formatting 12.1 FORMAT-STATEMENT FORMATTING A FORMAT statement directs the editing of data during its transfer between internal and external storage. Every formatted (FORMAT statement) data transfer statement contains a reference to one of the following: 1. A line containing a FORMAT statement with a format list 2. A numeric array containing a format list 3. A character expression containing a format list 4. An integer, real, or logical variable that has been a FORMAT statement number with an ASSIGN statement assigned The format list is made up of format specifiers. During execution of a formatted data transfer statement, items in the I/O list are associated with specifiers in the referenced format list. The specifiers dictate how the various data items are formatted. Section 12.1.1 describes how to create a format list in a FORMAT statement; Section 12.1.2 describes how to create a format specification as a character expression. Section 12.1.3 describes how to create a numeric array that contains a format list. Section 12.1.4 describes how to specify a FORMAT statement using an ASSIGNed variable. 12.1.1 Specifying a Format List in a FORMAT Statement The general form of a FORMAT statement is: n FORMAT fs where: n is the required statement number. This number, referenced in the control-information list of an I/O statement (see Section 10.4.2) provides the association between the data transfer statement and the FORMAT statement. fs is a format specification. specification is: ([format list]) 12-2 The form of a format FORMATTI!D DATJll TRANSFERS where: format list is a list of items following forms: which may take any of the [r] ed or ned or [r] (fl) where: r is a nonzel~O, unsigned, integer constant called repeat specification. ed is a repeatable 12.2.1) • edit descriptor (see Section ned is a nonrepeatable edit 12.2.2) • descriptor (see Section fl is a nonempty format list. a The only placement restrictions for FORMAT statements are that they follow PROGRAM, FUNCTION, SUBPROGRAM, or BLOCK DATA statements, and that they precede the END stat.~ment. The following example illustrates FORMAT-statement formatting. The FMT specifier in the WRITE statement references the label of FORMAT statement 101. This FORMAT statement contains a list of edit descriptors (X, I, and F) that dictate the formatting of the data in I/O 1 i s t ( va ria b 1 E~ S J, Y, and :~). 101 12.1.2 J=2 Y=3.0 Z=S.l WRITE(UNIT=S,FMT=lOl)J,Y,Z FORMAT(lX,I,F,F) Specifying a Format Specification as a Character Expression You can store format specifications in character variables, character arrays, character array elements, character substrings, or character expressions. A character format specification must be of the form described in Section 12.1.1. Note that the form begins with a left parenthesis and ends with a right parenthesis. Charc~cter data may follow the right parenthesis that ends the format sp.~cification, with no effect on the format specification. Blank characters may precede the format specification. If the format identifier is a character array name, the format specification may be contained in more than the first element of the array. (A character array format specification is considered to be a concatenation of all the array .~lements of the array in the order given by array element ordering (see Section 4.3.3).) 12-.3 FORMATTED DATA TRANSFERS However, if a character array element name is specified as a format identifier, the length of the format specification must not exceed the length of the array element. The following example shows the same format specification used in the examples in Section 12.1.1. This time, however, instead of referencing the format specification by statement number, or referencing the name of a numeric array, the data transfer statement references the name of the character variable in which the format specification is contained. J=2 Y=3.0 Z=5.1 CHARACTER FORNAM*lO FORNAM = '( 1 X, I , F, F) , WRITE(UNIT=5,FMT=FORNAM)J,Y,Z 12.1.3 Specifying a Format Specification in a Numeric Array An alternative to using FORMAT statements specification in a numeric array. is to store the format The format specifications are associated with a data transfer statement by referencing the array name containing the format specification, instead of a statement label of a FORMAT statement. The following example shows the same format specification used in the example in Section 12.1.1. This time, however, instead of referencing the format specification by statement number, the data transfer statement references the name of the numeric array in which the format specification is contained. T~TEGER FORNAM(2) FORNAM (I) = (IX, I FORNAt-1 ( 2 ) = F, F) I I I , I J=2 y= 3.0 2::::5.1 WRITEfUNIT=5,FMT=FORNAM)J,Y,Z END In the above example the format specification is stored in both words array FORNAM. This is because the format contains ten characters: the first five are in FORNAM(l); and the last five are in FORNAM(2). o( NOTE When storing a format specification in an array, always include the outer most parentheses enclosing the form~t specifiers. Note that the word FORMAT should not be included in the string. 12.1.4 Specifying a FORMAT Statement Using an ASSIGNed Variable Integer, rcal, or logical variables that have been ASSIGNed FORMAT statement numbers can be used as format specifiers. (See Section 8.3 for information on the ASSIGN (statement label) assignment statement.) 12-4 FORMATTED DATA TRANSFERS The variable is assigned a statement number by an ASSIGN statement. that refers to the The format specifier references the variable statement number it has been assigned. The following example shows thE! same format specification used in the examples in Sections 12.1.1, :2.1.2, and 12.1.3. This time, however, instead of referencing the forrlat specification by statement number, the data transfer statement references a variable that has been assigned a statement number by an ASSIGN statement. 101 12.1.5 ASSIGN 101 TO IFORMT WRITE(UNIT=5,FMT=IFOHMT)J,Y,Z FORMAT ( lX, I , F , F) The Ordering and Interpretation of Format List Items For standard conforming programs, all items within the format list should be separated by comMas, with the exception of the following cases: 1. Between a P edit descriptor and an immediately following E, D, or G edit descriptor (See Section 12.4.11) 2. Before after a sla:,h edit descriptor (See Section 12.4.5) 3. Before or after a colon edit descriptor (See Section 12.4.6) Ol~ F, In FORTRAN-I0/20, the use of c.)mmas to delimit format edit descriptors wit h i n a for mat 1 i s t i s 0 P t i 0:1 a 1 as 1 0 n gas no am big u i t Y ex i s t s . Fo r example, FORMAT (3X,A2) can be written as FORMAT (3XA2) Rut the specification FORMAT (12215) is ambiguous, since it can represent FORMAT (122,15) or FORMi\ T (1,22 15) and requires the comma to eliminate ambiguity. 12-5 FORMATTED DATA TRANSFERS FORMAT-Statement Edit Descriptors 12.2 EDIT DESCRIPTORS Edit descriptors within the format list describe the manner of editing performed on the data being transferred. For example, when you transfer integers from a file to memory, you use an I edit descriptor. When the data transfer statement is executed, an item in the I/O list is associated with the I edit descriptor in the format list, and the following results: 1. Before being stored in memory, the data is converted to an internal integer format by the I edit descriptor in the format list. 2. The memory location in which the data is stored is identified by the I/O list element. The following sample program demonstrates how an integer is read from the terminal (external device) into the memory location identified in the I/O list of the ACCEPT statement. PROGRAM FORMAT 101 102 TYPE *,'Please enter a two digit number:' ACCEPT 101,K FORMAT(I2) TYPE 102,K FORMAT(lX,IS) END The sample output below shows what happens when the user executes the above program. The user enters 78 in response to the ACCEPT statement. This causes the integer value to be stored in the variable K according to the I edit descriptor in FORMAT statement 101. Then the type statement causes the value of variable K to be printed at the terminal according to the I edit descriptor in FORMAT statement 102. EXECUTE TEST LINK: Loading [LNKXCT FORMAT execution] Please enter a two digit number: 78 78 Elapsed Time 8.7 CPU Time 0.1 The I edit descriptor is an example of a repeatable edit descriptor. FORTRAN has two types of edit descriptors: repeatable (Section 12.2.1) and nonrepeatable (Section 12.2.2). The third type of item that appears in a format list is the carriage-control specifier (Section 12.2.3). 12-6 FORMATTED DATA TRANSFERS Repeatable Edit Descriptors 12.2.1 Repeatable Edit Descriptors A repeatable edit descriptor may be preceded by an optional, unsigned, nonzero, integer constant that specifies a repeat count. This integer is called a repeat specification. Using a repeat specification in an edit descriptor gives you a shorthand way to specify multiple fields with a single specification. For example, without using the repeat specification, if you wanted to specify four fields, each of which contain an integer value that is six characters long, you might construct the following FORMAT statement: 101 FORMAT (lX,I6,I6,I6,I6) If you use the repeat specification, however, you need only the edit descriptor and field width a single time, as follows: 101 specify FORMAT (lX,416) These two FORMAT statements are equivalent. Table 12-1 lists the repeatable edit descriptors. Each descriptor listed in the table is shown in its complete form. The key at the bottom of Table 12-1 describes all the optional elements in each edit descriptor. The right-most column of Table 12-1 references the section in which each edit descriptor is discussed. 12-7 FORMATTED DATA TRANSFERS Table 12-1: Repeatable FORTRAN Edit Descriptors Edit Descriptor Descriptor Type Hefer to: Irlllwl.mll Integer Section 12.4.11.1 IrJFI w.dl Floating Point Section 12.4.11.2 IrlEI w.dlEell Scientific Notation Section 12.4.11.3 IrlD! w.dl Eell Scientific Notation Section 12.4.11.3 IrlGlw.dlEell General Conversion Section 12.4.11.4 F,E,D,G (Two successive) Complex Section 12.4.11.5 IrlOlwl.mll Octal Section 12.4.11.6 IrlZlwl.mll Hexadecimal Section 12.4.11.7 IrJLlwl Logical Section 12.4.12 IrJAlwJ Character or Hollerith Section 12.4.13 IrlRlwl Hollerith Section 12.4.14 --_._._-_.... - _..- _._.-- --- _.- Key: r is a nonzero, unsigned, integer constant called a repeat specification. w is a nonzero, unsigned, integer constant which is equal to the total number of characters in the numeric field being described. The numeric edit descriptors are described in Section 12.4.11. .m is an unsigned, integer constant which specifies the minimum number of digits to be output to the field being described. If necessary, leading zeros are output. The value of m must not exceed the value of w. If m is zero and the value of the internal data item is zero, the output field consists of only blank characters, regardless of the sign control in effect. .d is a nonzero, unsigned, integer constant which specifies the total number of digits to the right of the decimal point in the numeric field being described. If .d is specified, w must also be specified. The maximum value is 63 digits. e is a nonzero, unsigned, integer constant which is equal to the total number of digits in the exponent field of the numeric field being described. The maximum value is 15 digits. Nonrepeatable Edit Descriptors 12.2.2 Nonrepeatable Edit Descriptors A nonrepeatable edit descriptor can not be preceded by a repeat specification. The nonrepeatable edit descriptors provide a vaI-iety of editing possibilities, such as positioning within a record, including character constants in a FORMAT statement, and delimiting records within a single format descriptor. Table 12-2 lists the nonrepeatable edit descriptors. The format, function, and section number where each descriptor is discussed are listed in the table. 12-8 FORMATT3D DATA TRANSFERS Table 12-2: Nonrepeatable FORTRAN Edit Dpscriptors mction Edit Descriptor 'h1. .. hn' Character Data Refer to: Section 12.4.1 ------ nHh Hollerith Data Section 12.4.2 Tc TLc TRc In-Hecord Positio ning Section 12.4.3.1 -------- InlX In-Hecord Positio ning Section 12.4.3.2 $ (Do dar sign) Pre" ents recl lrd from terminating with END OF LINE Section 12.4.4 ------! (Slash) Record De limiter Section 12.4.5 : (Colon) Format-C ontrol TI !rmination Section 12.4.6 -------- S SP SS PIll!; sign control for outpl It of positive numeric fields Section 12.4_7 kP Scal ing Factor fo r Numer c Fields Section 12.4.8 BN BZ Specifies the ha ndling 0 f blanks during the input of Numeric Fields Section 12.4.9 Q Input Only Descriptor - returns the number of characters left in the cu rrent re< ord. Section 12.4.10 -------- Key: n is a nonzero, unsigned, integer consta nt whicr is equal to a number of spaces (X descriptor) or the total number of characters (H descriptor). h is a character capable of representation by the p rocessor. This type of character is described in Appendix B. c is a nonzero, unsigned, in teger constan t which i s equal to a number of characters within a record relative to the current position. k is an optionally signed integer constan t which ::!eclares the scaling factor for the field being described. -------- Carriage-Control Specifiers 12.2.3 Carriage-Control Specifiers In a data output transfer, the first character of each record can be used for carriage control. A carriage-control specifier dictates the action of the printing mechanism on output devices. For example, carriage-control specifiers determine the vertical spacing for line-printer output. 12-9 FORMATTED DATA TRANSFERS NOTE The CARRIAGECONTROL specifier of the OPEN statement enables you to decide how the first character of each record is treated. Depending on the value of the CARRIAGECONTROL specifier, the first character can be: the printer-control 1. Replaced with character (s) . appropriate 2. Disregarded as a carriage-control character and, instead, be transferred as part of the record. For more information on the CARRIAGECONTROL specifier, see Section 11.3.6 The carriage-control specifier may be written as a character constant. The following example shows the blank carriage-control character in a FORMAT statement: WRITE(5,101) 101 FORMAT(' I ,'This is a string') END When this example is executed, the string printed on unit 5, the terminal, as follows: in the format list is This is a string If you omit the carriage-control specifier from a data output transfer format list, FOROTS interprets the first character to be output to the record as the carriage-control character. using the example above, if we omit the blank specifier, FOROTS assumes that the first character encountered (in this case, the "T" in "This") is the carriage-control character. Executing this example, after removing the carriage-control specifier, causes the first character to be stripped from the character constant. Thus, the output at the terminal is: his is a string The carriage-control characters are summ~rized in Table 12-3. The $ (dollar sign) output edit descriptor modifies the action of the carriage-control specifier (see Section 12.4.4). 12-10 FORMATTED DATA TRANSFERS Table 12-3: Carriage-Control Specifiers --------.~------- Specifier Format List Form Pr inter Ct·aracter -r--"--- .. - - ... Octal Value Effect on Carriage Control 012 Skip to next. line (form feed after 60 lines on printer). - - - - - - . - - - - - - - - - .. - ... ·. r-·-·--. . _-· blank LF ... _ - - - - I - - -- - - - ---'--"-'- ~--. - - - - - - - - + - - - . - plus '+' zero '0' one* '1' -_._ -_._--- ..- ..... -----_._--- '2' three'" '3' minus - asterisk'" '*' period* ' , comma'" ' , slash* '/' .. - ... 012,012 FF I-----------~.-- 014 - - - - - - I---- - - - _ . _ - - two* ~------- LF,LF Suppress line feed: overprint tl1<' line . ............ _ _--Skip a line. -- - - - - -_ ... DLE 020 VT 013 ... _ - - - - I - - -- - - - - _ . _ - - - - - - - _ .. ---_ .. 012,012,012 .. .... .. .... .. .. - _........ _--- Skip two lines. - - - - - - - - - - - - - - - - f - - - - - -. - ....----- DC3 .. -.. - - . -...... - . - - __- Space to next half page . _--_ .._ __ _ __ Space to next one-third of a page . .._ - - - - r---- - - - - . - - - - - - - - - - - - _ .. - LF,LF,LF ... --- - ....... - Form feed to top of next page. .......... 023 - . --.---....- - . - Skip to next line; suppress form feed. (Continous print) - - - - - . - - - - - - - - - - - - f - - - - -......- - -- .-- - -. . -.----- DC2 .._---- - 022 Triple space. with a form feed after every 20 lines printed. - - - - - - . - - -.--------t--------.-.-- --------- DC1 021 Double space, with a form feed after every 30 lines printed. - - - - - . - - - - - - - - - - - - - - 1 - . _ - _ . _ _ ._- - - - - - - - DC4 024 _ _ _ _ _ •_ _ _•...L- _ _ _ _ _ * Space to next one-sixth of a page. --'~ _ _ _ _ _ _ _ . _ ... _ _ _ _ .. _ _ _ _ Indicates carriage-control specifiers for which the effect on carriage control is device dependent. The effpct described is for a line printer with a standa! d form set.up. Note - This table assumes a st.andard form setlip for your line printer (or other output dcyic('l. 1/0 List & FORMAT List Interaction INTERACTION OF 12.3 INPUT/OU~'PUT This section describes how during a data transfer. 12.3.1 thE~ LIST AND FORMAT LIST I/O list and the format list interact General Description Format control is initiated by execution of a formatted data transfer statement. The actions performed by format control depend on the interaction of the edit descrjptors in the format specification and the I/O list elements in the data transfer statement. The following example shows how the I/O list elements in a data transfer statement interact with the edit descriptors in the format list in a simple data transfer. 100 READ (5, 100) N, X, Y FORMAT (I5,FI2.0,F'10.O) 12-11 FORMATTED DATA TRANSFERS In this example, the I/O list is N,X,Y and the format specification is (I5,F12.0,FI0.0) The variables in the I/O list and the specifiers up as follows: in the format are mat~hed N X Y I5 F12.0 FI0.0 A formatted data transfer statement matches elements of the I/O list and specifiers in the format specification. The matching proceeds from left to right, one I/O list element to one repeatable edit descriptor. In the above example, there are three elements in the I/O list and three format specifiers. However, the interactions can be more complicated than those in the example. A format specifier can be preceded by a repeat count, in which case it corresponds to more than one element in the I/O list. Also, an element of the I/O list can be an array name, in which case it can correspond to more than one format specifier. The number of elements in the I/O list and in the format specification do not have to be the same. Table 12-4 details what happens in these more complex cases. 12-12 FORMATTED DATA TRANSFERS Table 12-4: 1. Record, Format List, and 110 List Interaction Record ends Format specification continues 110 list continues Action: The transfer continues as if the record was extended with blanks. Example: 10 READ (5 dO) A ,8 ,C FORMAT (3F10.0) Record contains: 40 10 Resulting values: A = 40.0 B 10.0 C '"" 0.0 Note that this situation :is not applicable to an output transfer. 2. 110 list ends Format specification continues Action: The format scan continues until it encounters 1 repeatable edit descriptor, a colon, or until the rightmost right parenthesis of the format is reached. Nonrepeatable edit descriptors up to and including the first colon, if present, are processed if they are encountered during the scan. Example: A 12 123 C 1234 D = 12345 B 20 WRITE (5,20) A,8,C FORMAT (' A'= I ,F3.0, 1 D= I ,F6.0) I 8= I ,F4.0, I C= I ,F5.0, I Resulting output: A= 12., B = 123., C = 1234., D = Note that the', D =' descriptor was processed. The format scan does not terminate until it encounters a descriptor which requires an 1'0 list element, and 1here is no 110 list element to supply. However, the colon edit descriptor will cause the format scan to stop if there is nothing left in the 110 list (see Section 12.4.6J. 3. Format specification ends 110 list continues Action: A new record is started. The format scan contiIlues, starting at the beginning of the last complete parenthesized h1TOUP within the format specification. If there is no parenthesized group within the format, the format is restarted from the beginning (see Section 12.34). Example: A=123. 8=7654.125 C=1.6125 10 WRITE (5 dO) A ,8 ,C FORMAT (F15.6) 12-13 FORMATTED DATA TRANSFERS Table 12-4: Record, Format List, and 1/0 List Interaction (Cont.) Resulting output: 123.000000 7654.125000 1.612500 4. 1/0 list ends Format specification ends Action: On input, if there are any characters remaining in the record, they are ignored. On output, the record is simply terminated without any extra characters added. Example: 10 READ (5 ,10) GAMMA FORMAT (F5.2) Record contains: 12.34 value of GAMMA Resulting values: GAMMA = 12.34 The extra data (the comment) in the input record is ignored. The execution of a formatted I/O statement proceeds by matching I/O list elements and FORMAT edit descriptors. The edit descriptors I, 0, Z, R, F, E, 0, G, L, A, and Q each correspond to one element of the I/O list. No I/O list element corresponds to H, X, P, T, :, $, S, SP, SS, BN, BZ, or apostrophe edit descriptors. If one of these descriptors is encountered, it is executed and the format scan continues. 12.3.2 Formatted Input A formatted input statement begins by reading a record from the specified unit. The format is scanned from left to right. X, P, T, BN, BZ, and / edit descriptors are executed as they are encountered. If an I, 0, Z, R, F, E, 0, G, L, A, or Q descriptor is encountered, data is read into the corresponding I/O list element as specified by the edit descriptor. If the I/O list contains no more elements, execution of the READ statement ends. Additional records will be read from the specified unit when a slash occurs in the format, or when the last right parenthesis of the format is reached, and I/O list elements remain to be filled. When an input record is terminated by a slash or by the end of the format, any data left in the input record is discarded. 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. 12-14 FORMATTED DATA TRANSFERS 12.3.3 Formatted Output A formatted output statement begins by scanning the format. The H, X, P, T, BN, BZ, :, /, $, s, SS, SP, and apostrophe edit descriptors are executed as they are encountered. If an I, 0, Z, R, F, E, D, G, L, or A descriptor is encountered, data is translated from the corresponding I/O list element, as specified by the edit descriptor, and placed in the output record. If the I/O list contains no more elements, the output record is written to the specified unit, and execution of the WRITE statement ends. Additional records will be written to the specified unit when a slash occurs in the format, or when the last right parenthesis is reached, and I/O list elements remain to be transferred. 12.3.4 Embedded Format Specifications Format specifications may contain embedded format specifications with optional repeat specifications. If a repeat specification is used, the entire format specification that it precedes is scanned the specified number of times during the I/O transfer. In the example: 100 WRITE (1,100) A,B,C,D,E,F,G,H,I,J FORMAT (FlO.2,4(I5,lX,I3) ,18) the variable A is matched with the format item FlO.2. Then, the variable B is matched with IS, variable C with 13, variable D with IS, and so on for four iterations of the embedded format specification. Finally, the variable J is matched with the format item 18. If no repeat specification is used preceding specification, a repeat count of 1 is implied. an embedded format When the last right parenthesis of the format is reached, and more I/O list elements remain to be transferred, a new record is started and format scanning continues. The scanning continues at the beginning of the format specification whose right parenthesis is the next to last right parenthesis in the format. If there are no embedded format specifications, format scanning continues at the beginning of the format. For example: DIMENSION A(lOO) INTEGER CASE CASE=33 100 WRITE (l,lOO)CASE, (A{I) ,1=1,100) FORMAT ('THIS IS CASE' ,I6,//,4{lX,FI0.5» After A{l) through A(4) are written, a new line is started and format scanning continues at the beginning of the embedded format specification. Thus, A(5) through A(8) are written; a new record is started, and so forth. 12-15 FORMATTED DATA TRANSFERS The output file would appear as follows: THIS IS CASE 33 A (1) A (2) A(5) A(9) A(6) A (10) A(3) A(7) A (II) A(4) A(8) A (12) Example: DIMENSION A(5) ,DATl(100) ,B(4,100) ,DAT2(100) WRITE (1,100) CASE, (A(K) ,K=1,5), (DATI (J), (B{I,J) ,I=1,4), 1 DAT2 (J) ,J=l, 100) 100 FORMAT ('CASE' ,I5,11,5(lX,FI0.3) ,1,{FI0.3,4(3X,F15.5) 1 ,lX,FI0.3» In this example, after A{l) through A(5), DAT1(1), B(l,l) through B(4,1), and DAT2(1) are written, a new record is started, and format scanning begins. The format scanning begins at the embedded format specification following the 'I' (the specification whose right parenthesis is the next to last right parenthesis) • The output file would appear as follows: CASE A{l) DATl(l) DATl(2) DATI (3) 12.4 33 A (2) B{l,l) B(1,2) B(1,3) A(3) B(2,1) B(2,2) B(2,3) A(4) B{3,1) B(3,2) B{3,3) A(5) B(4,1) B(4,2) B{4,3) DAT2 (l) DAT2(2) DAT2(3) FORMAT EDITING Tables 12-1 and 12-2 describe forms of all the FORMAT edit descriptors. The edit descriptors enable you to specify the form of a record and to specify the editing of the data as it is transferred. The edit descriptors are described according to the character used to accomplish a particular modification to the data or record in ~lhich the data are stored. APOSTROPHE (') Editing 12.4.1 Apostrophe (') Editing The apostrophe (') edit descriptor (single-quote) include a character constant in a format list. 12-16 enables you to FORMATTED DATA TRANSFERS The form of the apostrophe edit descriptor is: 'hl ••• hn' where: 'hl ••• hn' is a character constant. To include an apostrophe as part of the character constant, use two successive apostrophes. This descriptor is only used for output; the the apostrophes are written. characters you must enclosed by Example: 10 TYPE 10 FORMAT (' That' 's the way!') will output That's the I~ay! H Editing 12.4.2 H Editing The H edit descriptor (also called the Hollerith descriptor) you to include character strings in a format list. enables The form of the H edit descriptor is: nHhl ••• hn where: n is a nonzero, unsigned, integer constant that indicates the total number of ASCII characters included in the string. hI ••• hn is a string of ASCII characters. set is described in Appendix B.) (The ASCII character You may transmit alphanumeric data directly from the FORMAT using either the H or apostrophe specifiers. statement This descriptor is only used for output; the n characters that follow the H are written. For example, you can use the following statement sequence to print the words PROGRAM COMPLETE on the printer: PRINT 101 I 101 FORMAT (17HlpROGRAM~COMPLETE) 12-17 FORMATTED DATA TRANSFERS The result of apostrophe editing is the same For example, you may use the descriptors: as Hollerith editing. 101 FORMAT (17H~PROGRAM~COMPLETE) and 101 FORMAT ('~PROGRAM~COMPLETE') in the same manner. Apostrophes can appear anywhere within a Hollerith edit descriptor without having to be represented by two apostrophes. However, if the H edit descriptor occurs within a character constant, the apostrophe is written as two apostrophes, which are counted as one character. POSITIONAL Editing 12.4.3 positional Editing The positional edit descriptors specify the position at which the next character will be transmitted to or from the record. The positional edit descriptors are: T, TL, TR, and X. The T edit descriptor specifies the character position within a record where the next character will be transmitted (see Section l2.4.3.1). The TL and TR descriptors specify the number of character positions to the left or right, respectively, of the current position for the character position of the next character (see Section 12.4.3.1). The X descriptor specifies the number of character positions to the right of the current position for the character position of the next character (see Section 12.4.3.2). NOTE On output, a record is initially filled with blanks. Therefore, fields skipped by the positional editing descriptors will be blank-filled. However, the output record length is determined by actual output. Merely specifying a positional editing descriptor with no output will not change the record size. Thus, the record written with: FORMAT (I6,50X,T10,I3) will have a record length of 13 characters, output was done after the 50X. Examples: The statement sequence: PRINT 2 2 FORMAT (T50,'BLACK' ,T30,'WHITE') 12-18 since no FORMAT~(,ED DATA TRANSFERS causes the following line to be printed: BLACK lHITE (print position 30) t (print position 50) The statement sequence: 1 FORMAT (T35,'MONTH') READ (2,1) 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: ABCP{~J6XYZ is read with the format specification: 10 FORMAT (T7,A3,Tl,A3) then the characters XYZ and ABC are read in that order. You can 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). The statement: FORMAT (5H~3TEP,I5,10X,2Hy=,F7.3) may be used to print the line: T, TL, and TR Editing 12.4.3.1 T, TL, and TR Editing - The T edit descriptor specifies that the transmission of the next character to or from a record is to occur at the specified character position. The form of the T descriptor is: Tc where: c is a positive, unsigned, integer constant that indicates the character position to or from which the next character will be transferred. For example: FORMAT (T20,I5,T8,I2) 12-19 FORMATTED DATA TRANSFERS specifies that the characters read or written for the 15 descriptor will start in character position 20, and the characters read or written for the 12 descriptor will start in character position 8. For out put to car ria g e - con t r o l d e vic e s ( 1 i n e p r i n t era n d t e r min a 1), Tn specifies that n-l will be the next character written, since the character position 1 is the carriage-control character position. The TL edit descriptor specifies that the transmission of the next character to or from the record is to occur at a position which is a specified number of positions backward from the current position. The form of the TL edit descriptor is: TLc where: c is a positive, unsigned, integer constant that indicates the character position, c positions backward from the current position, to or from which the next character will be transferred. If c would cause transmission to start at a position before the beginning of the current record, transmission will start instead at position one. For example: FORMAT (I5,T13,A5,TLI0,I2) specifies that the characters read or written for the A5 descriptor will start at character position 13, and that the characters read or written for the 12 descriptor at will start at character position 8. The TR edit descriptor specifies that the transmission of the next character to or from a record will occur at a position that is a The specified number of positions forward from the current position. function of this form is identical to that of the X descriptor (see Section 12.4.3.2). The form of the TR edit descriptor is: TRc where: c is a positive, unsigned, integer constant that indicates the character position, c positions forward from the current position, from which the next character will be transferred. Example using all three types of T descriptor: 10 TYPE 10 FORMAT(' 20 TYPE 20 FORMAT(T29,'BLACK' ,TIO,'WHITE') 30 40 234567890123456789012345678901234567890') TYPE 30 FORMAT(TI0,'9012' ,TR5,'8901') TYPE 10 TYPE 40 FORMAT(T20,'<SECOND)' ,TLI0,')FIRST<') END 12-20 FORMATT~D DATA TRANSFERS EXECUTE TEST2.FOR FORTRAN: TES~~2 MAIN. LINK: Loading [LNKXCT TEST2 execution] 2345678901234567890123456 '78 90 1234 56 78 90 WHITE BLACK 9012 8901 2345678901234567890123456'78901234567890 )FIRST<ND> CPU time 0.1 Elapsed tim~ 0.5 In FORMAT 20, 'BLACK' is writt~n, then 'WHITE' is written to the left of it. In FORMAT 30, fiv~ positions are skipped between the two character strings being printed. In FORMAT 40, '<SECOND)' is written, the format goes back ten positions and writes ')FIRST<' over the previously written character string. X Editing 12.4.3.2 X Editing - The X edit descriptor specifies that the transmission of characters to or from a record will occur a specified number of characters forward from the current position. The form of the X edit descriptor is: (n]X where: n is an optional, unsigned, positive, integer constant that indicates the number of characters forward from the current position, at which the next character will be transmitted. The default value is 1. Example: 10 TYPE 10 FORMAT(' 1234567890123456789012345678901234567890') 20 TYPE 20 FORMAT(' A WORD OR TWO' ,10X,'OR THREE') END EXECUTE TEST3.FOR FORTRAN: TEST3 MAIN. LINK: Loading [LNKXCT TEST3 execution] 1234567890123456789012345678901234567890 A WORD OR TWO OR THREE CPU time 0.2 Elapsed time 2.1 12-21 FORMATTED DATA TRANSFERS In this example, ten positions are skipped between the printing of 'A WORD OR TWO' and 'OR THREE'. $ (DOLLAR SIGN) Editing 12 • 4 .4 $ (Do 11 a r S i g n) Ed i t i ng The $ (dollar sign) output edit descriptor suppresses all carriage control at the end of the current record (for CARRIAGECONTROL='LIST') or at the beginning of the next record (for CARRIAGECONTROL='FORTRAN' or 'TRANSLATED'). This descriptor is used for interactive I/O; it leaves the terminal position at the end of the text so that a response will follow the output on the same line. Example: WRITE (5,10) READ (5, *) N FORMAT (' Number of samples:' WR I TE ( 5 ,20 ) READ (5,*) X FORMAT (' Mean value: END 10 20 $) $) If the user enters 100 for Nand 1.23 for will produce the typescript: X, executing the program the of several Number of samples: 100 Mean value: 1.23 The $ edit descriptor can be used to append statements into a single line. For example: DO 10 I = 1,10 WR I TE (5, 20) I FORMAT (lX,I3,$) WRITE (5,20) END 10 20 will produce one line of output: 1 2 3 4 5 6 7 8 9 10 The $ edit descriptor is ignored for input. 12-22 output FORMATTED DAT1~ TRANSFERS / (SLASH) Editing 12.4.5 / (Slash) Editing The / (slash) edit descriptor indicates the end of data transfer for a record. Two consecutive slashl!s indicate the transmission of an empty record. On input to a file connected Eor sequential access, the remaining portion of the current record is skipped, and the file is positioned at the beginning of the next record. This new record becomes the current record. On output to a file connected for sequential access, the current record is terminated, and a new record is created, which becomes the current and last rl!cord of the file. A record that contains no char~cters may be written. record may be skipped on input. Also, an entire If the file is connected for direct access, the record number is increased by one, and the file is positioned at the beginning of the record that has that record number. This record becomes the current record. The following statements will write a record with no characters: 100 WRITE (1,100) FORMAT(/) To handle a group of I/O records where different records have different field descriptors, use a slash to indicate a new record. For example, the statement FORMAT (308/15,2F8.4) is equivalent to FORMAT (308) for the first record, and FORMAT (15,2F8.4) for the second record. You may omit separating commas when you use a slash. When n slashes appear at the beginning or end of a format, n blank records will be written on output or skipped on input. When n slashes appear in the middle of a format, n-l blank records are written on output or n-l records are skipped on input. 12-23 FORMATTED DATA TRANSFERS : (COLON) Editing 12.4.6 (Colon) Editing The: (colon) edit descriptor terminates format control if there are no more items in the I/O list of the corresponding data transfer statement. The colon edit descriptor has no effect if there are any items left in the I/O list of the corresponding data transfer statement. Example: Xl X2 X3 10 20 100 200 300 TYPE 10, Xl,X2 FORMAT(F6.1,F6.1,:,'THIS SHOULD NOT PRINT' ,F6.1) TYPE 20,Xl,X2,X3 FORMAT(F6.1,F6.1, :,' BUT THIS SHOULD' ,F6.1) END EXECUTE TEST4.FOR FORTRAN: TEST4 MAIN. LINK: Load ing [LNKXCT TEST4 execution] 100.0 200.0 100.0 200.0 BUT THIS SHOULD 300.0 CPU time 0.1 Elapsed time 1.5 S, SP, and SS Editing 12.4.7 S, SP,and SS Editing The S, SP, and SS edit descriptors control the output of the optional plus sign in numeric output fields. These descriptors are used as follows: S indicates that the system-defined action is taken. system-defined specification for Digital FORTRAN is SSe SP indicates that the plus sign numer ic output fields. SS indicates that the plus sign is not printed in positive numeric output fields. This descriptor is the default. 12-24 is printed in all The positive FORMATTED DAT}~ TRANSFERS The S, SP, and SS edit descrip~ors affect only I, F, E, D, and G editing during the executiOJl of a data transfer output statement; these edit descriptors have no effect during input transfers. These descriptors stay in effect un":il the end of the I/O transfer or until another S, SP, or SS is encoun':ered. Example: Xl X2 X3 X4 10 100 200 300 400 TYPE 10, XI,X2,X3,X4 FORMAT(" ,S,F7.1, SP,F7.1, SS,F7.1, SP,F7.1) END EXECUTE TESTS.FOR FORTRAN: TESTS MAIN. LINK: Loading [LNKXCT TESTS execution] 100.0 +200.,0 300.0 +400.0 CPU time 0.1 Elapsed time 0.2 In this example, X2 and X4 have plus signs because of the descriptors in front of the F descriptors that correspond to them. SP p Editing 12.4.8 P Editing The P edit descriptor is used and G edit descriptors. ":0 specify a scale factor for F, E, D, representing the The form of the P edit descrip':or is:: kP where: k is an optionally signed integer scale factor. constant If a scale factor is not specified in a format list, a scale factor of zero is assumed., Once a scale factor is specified in a format list, that scale factor remains in effect for all F, E, D, and G edit descriptors unti1 a new scale factor is specified, or to the end of the execution of the current I/O statement. Scale factors have no effect on I, Z, and 0 edit descriptors. 12-25 FORMATTED DATA TRANSFERS The scale factor affects the F, E, D, and G data transfers as follows: On input: If there is an exponent field, the scale factor k has no effect. If there is no exponent field on the number read in, the number is multiplied by 10**(-k) before being assigned to the input variable. On output: The basic real constant part of the quantity, in E and D editing only, is multiplied by 10**k and the exponent is reduced by k. For G editing, the scale factor has no effect unless the magnitude of the data item to be edited is outside of the range that permits the use of F editing. If G editing is specified, and the magnitude of the data item to be edited is such that E editing is required, the scale factor has the same effect as with E output editing (see Section 12.4.11.3). The comma is optional between a P edit descriptor following F, E, D, or G edit descriptors. and For example, assume the data involved is the real number edit descriptor immediately 26.451; the F8.3 produces the external field ~~26.45l The addition of the scale factor of -lP, as in FORMAT (-lP,F8.3) produces the external field When you add a scale factor to D, E, and G (external field not a decimal fixed-point) edit descriptors, the scale factor 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 add a scale factor to a D or E edit descriptor, it specifies a power of 10 so that the e~ternal form of the number has its mantissa multiplied by the specified power of 10; its exponent is adjusted accordingly. For example, assume the data involved is the real edit descriptor Ell.3 produces the external field ¥~0.125E+02 The addition of the scale factor 2P, as in FORMAT (2P,E11.3) 12-26 number 12.49; the FORMATTED DATA TRANSFERS produces the external field Y/jS12.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 d,ecimal point). If ns...-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 d+l significant digits). If n>d+2, there will be d+l significant digits and n-d-l insignificant trailing zeros on the left of the decimal point. If the data to be printed is 12.493, these formats produce results follows: FORMAT OUTPUT SIGNIFICANT DIGITS REASON E15.3 IPE15.3 -lPE15.3 2PE15.3 -3PE15.3 4PE15.3 6PE15.3 J6J6J6J6;))1) 0 • 125 E+ 0 2 3 4 n=O n<d+2 -d<n n<d+2 J6t6J6)$,K>)S1.249E+Ol )5JzS}6}6b))0.012E+03 2 ~JzSt6}6J6J612.49E+OO 4 16)S)Sk):>,kS0.000E+05 J6t6,kSjSJzSjS12 4 9. E- 0 2 J6JzS X> pn 2 4 9 0 0 • E - :) 4 o n~-d 4 n<d+2 n>d+2 4 Example: 10 20 30 40 TYPE 10 FORMAT(' Type in a real number') ACCEPT 20,Xl FORMAT(2P,F) TYPE 30"Xl FORMAT(' Number read with P=2 =' ,F, 1 I,' (Number read)*10**(-2) ') TYPE 40~X1 FORMAT(/,' The above number written with P=2' ,I, 1 ' is:::', 2 P , F ,I " ( N urn b era b a v e) * 1 0 * * (2) , ) END 12-27 as FORMATTED DATA TRANSFERS EXECUTE TESTP.FOR FORTRAN: TESTP MAIN. LINK: Loading [LNKXCT TESTP execution] Type in a real number 5. Number read with P=2 = (Number read)*10**(-2) 0.0500000 The above number written with P=2 is = 5.0000000 (Number above)*10**(2) CPU time 0.2 Elapsed time 5.1 The number the program receives is (5.)*(10**(-2)) out is (.05) * (10** (2)) • and the value typed BN and BZ Editing 12.4.9 BN and BZ Editing The BN and BZ edit descriptors specify how blanks other than leading blanks are interpreted only for numeric input fields where a width has been specified. These edit descriptors have no effect on numeric output fields. The BZ descriptor specifies that blanks will be read as zeroes. The BN descriptor specifies that blanks will not be read as zeroes. The use of the BN or BZ edit descriptors in a format overrides the BLANK= specifier in the OPEN statement for the duration of the use of that format. (The BLANK= specifier is described in Section 11.3.3.) For example: 101 ACCEPT (FMT=101)A,B,C,D FORMAT (BN,r5,FI0.2,BZ,FI0.2,F8.5) reads the first two numbers of data, ignoring blanks embedded in the numbers. Then the program reads the second two numbers, substituting zeroes for blanks embedded in the numbers. 12-28 FORMATTED DATA TRANSFERS ------·-------r, a I ! [, Editing ~ _ _ _ ,, __ , __ , _ _ _ _ _- - - - JI 12.4.10 0 Editing The 0 edit descriptor sets a cJrresponding integer variable in the I/O list to the numbe~ of characters left in the record being transferred. This descriptor is for use wit, input transfers only. You can use multiple Q descriptors in the same format list. The Q edit descriptor is useful when you need to kno~ the number of characters remaining in a record. For example: TYPE *,'Enter text:' ACCEPT 1.00,L,Jl FORMAT (A5,Q) 100 when used to read the data Enter text: HELLO THIS IS A TEST would yield ~haracters the value 15 for variable Jl, in the data, and A5 reads 5 of them. since there are 20 Numeric Editing 12.4.11 Numeric Editing The I, F, E, D, G, Z, and 0 edit descriptors are used to specify the input and output of integer, real, complex, double-precision, hexadecimal, and octal data. The numeric edit descriptors are repeatable, and can be used without specifying size. For output, if you use a numeric edit descriptor without specifying a field width, the defaults shown in Table 12-5 are used. For input, the data is scanned until a blank, comma, or character illegal for the specified edit descriptor is encountered, except for A format, which uses the defaults shown in Table 12-5. 12-29 FORMATTED DATA TRANSFERS I'ahle 12-5: ))dault Field Widths for NUJlwrie Edit D('scriptors -------- - ----- - - --- -- - - - ~=t~~.~~.~:~or _~ _!" ~;ia~l:;, .... _. . .. _-_. -_. __ . _. -_.. _-_... _. - .. __._.._ - - - - - - - , Field Width .. F ':-'lnglp pr(>c ) r-;::-:lio~;bk,-~;~e~·~--- ---.-------------~ F15 -; --- . ;·F25.1H __ .... -_ . ._.. _.- ----.-.. ---.---------------~ _._-_ .. ---------.---~ \.: isingle prec. 1 E (double prec.) E2f>.lH D isingle prec. 1 ])1 f>. 7 [) Idouble prec.) D2f>.IH - -.- -.- - ...- - -------.-- - - - - - l (; (single prec. I (; (double prec.1 o lsi ngle prec. I OJ ;j .... -- .. -··---···--······-------------------l () (double prec. 1 LUi L Z I smgle prec.) .. -... --.- ....--.-- - - - - - - - - - 1 Z Idouble prec. 1 . ···-·-·-·---·····-·-··-------·-----l A:"i .-\ Isingle prec. 1 A 'double prec.) ··-I-{(-si-ngT(-:-p~·~~-·- . ------ t---- All) [{5 L..._R_(_d-_~_lb_l(> ~};;~--- - =~-=t~~-_: HI 0 _.... - .- ... _---_._- ._._----------------' If t}ll' dd~lUlt Eeld width for F furmat is too small li)r the data, the field width expands to fit the data. The following conventions apply to all I/O transfers using the numeric edit descriptors: 1. The interpretation of blanks is determined by a combination of any BLANK= specifier in the corresponding OPEN statement (see Section 11.3.3), and any BN or BZ edit descriptor (see Section 12.4.9) that is currently in effect in the format list. A field of all blanks is always equal to zero. 2. On input transfers, with F, E, D, and G editing, a decimal point appearing in the input field overrides the portion of the edit descriptor that specifies the location of the decimal point. 3. On output transfers, the representation of a positive or zero value in the field may be prefixed with a plus, as controlled by the S, SP, and SS edit descriptors (see Section 12.4.7). The representation of a negative value in the field is prefixed with a minus sign. 4. On output transfers, the representation of the transferred datum is right-justified in the specified field. If the number of characters produced by the editing is smaller than the specified field width, leading blanks are inserted in the field. 12-30 FORMATTED DATA TRANSFERS 5. On output transfers, if the number of characters produced exceeds the field width, or if an exponent exceeds its length (as specified in the Ew.dEe or Gw.dEe forms), the entire field width, represented by w, is filled with asterisks. The next sections describe the individual numeric edit descriptors. I Editmg 12.4.11.1 editing. I Editing - The 1 edit descriptor specifies integer The form of the I edit descriptor is: [r]I[w[.m]] where: r is an optional, nonzero, unsigned, integer constant indicat.ing how many fields of I are being specified. The default is one field. w is an cptional, nonzero, unsigned, integer constant that is equal to the total number of digits in the integer field being described. If w is not specified, for output, the value is 15 (the default); for input, the data is scanned until a blank, commil, or character illegal for the I edit descriptor is encountered . •m is an optional, uns~gned, integer constant (separated from w by a period) that indicates the minimum number of digits to be output to the integer field being described. The default is one digit (Il~j.l). If necessary, leading zeroes are output .' The value of m must not exceed the value of w. If m is zero and the value of the internal data item is zero, the output field consists of only blank characters, regardless of the sign control in effect. On input, the Iw.m and the Iw forms treated the same. of the I edit descriptor are Example: 10 FORMAT(I,I8,2I9.5) The first data item is output as a 1- to IS-digit right-justified integer in the first 15 columns. The second item is a 1- to 8-digit integer occuPyin9 the next 8 columns. The third and fourth items are 5to 9-digit integers occupying 9 columns each, with leading zeroes appended to the data to make ~hem 5 digits if necessary. 12-31 FORMATTED DATA TRANSFERS F Editing 12.4.11.2 F Editing - The (floating-point) editing. edit F descriptor specifies real The form of the F edit descriptor is: [r]F:w.dJ where: r is an optional, nonzero, unsigned, integer constant indicating the number of fields of F being specified. The default is one field. w is an optional, nonzero, unsigned, integer constant equal to the total number of digits in the F field being described. This total includes the digits to the right and left of the decimal point, the decimal point itself, and (if included) the sign. On input, if the decimal point is omitted, the rightmost d digits of the string, with leading zeros assumed if necessary, are interpreted as the fractional part of the value represented. If w is not specified, for output, the value for single-precision is 15 (the default), and the value for double-precision is 25 (the default). For input, the data is scanned until a blank, comma, or character illegal for the F edit descriptor is encountered • •d is an optional, nonzero, unsigned, integer constant that specifies the total number of fractional digits in the field of width w. The default for single-precision is 7 digits; the default for double-precision is 18. The maximum is 63 digits. NOTE If the default field width for F format (with no width specified) is too small for the data, the field width expands to fit the data. E and 0 Editing 12.4.11.3 E and D Editing - The E editing of real data. and The form of the E edit descriptor is: [r]E:w.d[Ee] : 12-32 D edit descriptors specify FORMAT~'ED DATA TRANSFERS The form of the D edit descriptor is: [r]D[w.d[Ee]] where: r is is an optional, non~ero, unsigned, integer constant that equal to the numbE~r of E: or D fields being described. The one defaults are one single-precision E field and do ubI e-·prec i s ion D field. w is an optional, non~ero, unsigned, integer constant equal to the total number of digits in the E or D field being described. The total for both types of fields is equal to: 1. ThE! total number of digits on both sides of the point 2. ThE! decimal point 3. ThE! sign for 4. ThE~ 5. The digits in the exponent thE~ decimal itsE~lf numbE~r (if included) exponent character (i f included) If w is not specifi«~d, for output, the value for single precision is 15 :the default), and the value for double precision is 2!:' (th(~ default). For input, the data is scanned until a blank, comma, or character illegal for the E or D edit descripto~ is encountered. d is an optional, non~ero, unsigned integer constant equal to the total number of fractional digits in the field being described (unless a scale factor greater than one is in effect). The defaults for both the E and D edit descriptors are 7 digits if single precision, and 18 if double precision. The maximum is 63 digits. e is an optional, non~ero, unsigned, integer constant equal to the total number of digits in the E or D field being described. The default for both types of edit descriptors is two digits. The maximum is 15 digits. For KL model B systems, if the program is compiled with the /GFLOATING switch (see Section 16.1.3 or 16.2.3), you may want to specify three digits to accommodate the exponent field of double-precision numbers. G Editing 12.4.11.4 G Editing - The G edit descriptor allows editing of integer, real, double-precision, logical, complex, or character data. With the exception of real, double-precision, and complex data, the type of conversion performed by the G edit descriptor depends on the type of the corresponding variable in the I/O list. 12-33 FORMATTED DATA TRANSFERS The form of the G edit descriptor is: [r] G [w.d [Ee] ] where: r is an optional, nonzero, unsigned, integer constant that is equal to the number of G fields being described. The default is one. w is an optional, nonzero, unsigned, integer constant equal to the total number of digits in the G field being described. The total for both types of fields is equal to: 1. The total number of digits on both sides of the point 2. The decimal point itself 3. The sign for the number (if included) 4. The exponent character (if included) 5. The digits in the exponent decimal If w is not specified, for output, the value for single precision is 15 (the default), and the value for double precision is 25 (the default). For input, the data is scanned until a blank, comma, or character illegal for the G edit descriptor is encountered. d is an optional, nonzero, unsigned integer constant equal to the total number of fractional digits in the field being described (unless a scale factor greater than one is in effect). The defaults are 7 digits if single precision, and 18 if double precision. The maximum is 63 digits. e is an optional, nonzero, unsigned, integer constant equal to the total number of digits in the G field being described. The default is two digits. The maximum is 15 digits. For KL model B systems, if the program is compiled with the /GFLOATING switch (see Section 16.1.3 or 16.2.3), you may want to specify three digits to accommodate the exponent field of double-precision numbers. For input, in the case of real, double-precision, and complex data, the G-format conversion is the same as for E-format conversion. For output, however, the type of conversion performed depends on the magnitude of the data items. Table 12-6 illustrates the conversion performed for various ranges of real, double-precision, and complex data. 12-34 FORMATTED DATA TRANSFERS Table 12-6: Effect of Dalla Magnitude on G-Format Output Conversions Data Magnitude (m) Effective Cor,version m .LT. 0.1. 0.1 .LE. m .LT. 1.0 1.0 .LE. m .LT. 10.0 Ew.d F(w - nl.d,n(x) F(w - nUd-l ),n(x) 10**d-2 .LE. III .LT. 10**d-J 10**d-l .LE. III .LT. 10**d m .GE. 10**d F(w - nl.1,n(x) F(w - nl.O,n(x) Ew.d where: x is a blank n is 4 for Gw.d and e + 2 for Gw.dEc where: x is a blank. n is 4 for Gw.d and e~2 for Gw.dEe NOTE I naIl n urn e ric fie 1 d co n v e r s ion s, the fie 1 d wid t h ( w) you specify should be large enough to include the decimal point, sign, and, where applicable, the exponent character (E), the exponent sign, plus the exponent digits. This is in addition to the number of digits in the number to be represented. 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 rig h t - j us t i fie din t h I~ fie 1 d , and 1 e a din g b 1 an k s will be used to fill the field. If the numeric data u~presentation cannot fit into the field width F(w-n), the n spaces (n(x» are removed from the right, and the numeric data representation is again processed into :he field width Fw. Examples of G output conversions (where the Format Inter:1al Value G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 -1.1234S678 1.23456789 12.34567890 123.45678901 -1234.56789012 12345.67890123 123455.78901234 -1234567.89012345 I) • 0 1 2 3 4 5 6 7 12-35 ¥ signifies a blank) are: External Representation ~0.123457E-Ol -0.123457J6)6;)~ )6)51. 23457l6)'5~J6 ;.sp512.3457}6J6~~ J6t6 12 3.457j25.kS.l6'» t6-1234.57)5J6)S~ J6}612 3 4 5 • 7,t6kS~t6 PSj25123457.j6}25pJpJ -0.123457E+07 FORMATTED DATA TRANSFERS F~r comparison, consider the following example of the same output under the control of an equivalent F field descriptor. values Format Internal Value External Representation F13.6 F13.6 F13.6 F13.6 F13.6 F13.6 F13.6 F13.6 F13.6 0.01234567 -0.12345678 1.23456789 12.34567890 123.45678901 -1234.56789012 12345.67890123 123456.78901234 -1234567.89012345 ~J6)6});S0 • 012346 ,lzSJ6)S;S-0.123457 ~J61t5JzS;S1.234568 jSJt5~~12.345679 ~p5PS123.456789 J'.'-1234.567890 ~12345.678901 123456.789012 ************* Complex Editing 12.4.11.5 Complex Editing - A complex number consists of a pair of separate real numbers. The first number of the pair is the real part of the complex number; the second number is the imaginary part. The editing of a complex number involves specifying two successive F, E, D, or G edit descriptors. The edit descriptors need not be the same. A sample format list description for a complex number is: 101 FORMAT (FIO.2,EIO.2) In this sample, the FIO.2 edit descriptor provides editing for the real part of the complex number; the ElO.2 edit descriptor provides editing for the imaginary part. You may include any nonrepeatable edit descriptors between and imaginary edit descriptors for a complex number. [ the real ~----.----.J o (Octal) Editing ________ ._ _, _ •. _., __._._ _ _ _ _ _ _ _ _ M._ 12.4.11.6 0 (Octal) octal editing. Editing - The 0 The form of the 0 edit descriptor is: ··rjO[w[.m]] 12-36 (octal) edit descriptor specifies FORMATTED DATA TRANSFERS \.yflere: i oS ()escribed. '., non z e r 0 , un s i 9 ned , 1 n t e \.1 t r co fj oS tan L the number ot successive octal tielas beinq The detault IS one octal tleld. d n a p t ion a 1 , ~;pecifying 1 san opt ion aI, f1 0 n z e r 0 , un s 1 9 ned , I n t e q £:' r con!::) t d II C ::-pecifying the total number ot dlglts In ttlt' octal tield l)einq described. It w is not specified, for output, the value tor d c.ingie-precision octal field is l~ (the detault), and the vdlue tor a double-precision octal field IS 2S (the clefault). For inI=ut, the data is scanned untll a blank, comma, or character illeqal for the 0 edIt descrIptor is .:~ncountered • '1.1 j s an optional, unsiqned, integer constant speci tyinq the min i murn n urn b e r o t dig its to be 0 u t put t o t net] e 1 a • The cl e fa u] t s are 1 2. tor sin 9 1 e - pre cis ion 0 c tal v 0 .iu e san d / 4 tor double-precision octal values. 1 i (Hexadecimal) I ::::~:d;inq i J 12.4.11.7 Z Editing - The Z edit descriptor speclties lnput and out put 0 f hexadE~c ima 1 val ues. Hexadec ima l i s u ba se J f) n umoe r system where the characters 0-9 and A-F (or a-f) represent the numbers 0-9 and 10-15, respectively. (On output, A-F only.) The form of the Z edit descrIptor is: ir)Z[w[.m]] where: r- Ls a n 0 p t ion aI, il n s i 9 ned , non z e r 0 , I n L e q (~ r c () 11 oS Ld n t :; p e cit yin 9 the nun b e r 0 f con sec UtI ve hex ad e c 1 mal tie 1 d s beinq specified. The default is one hexadeclmal tleJd. i.s an optional, unsigned, nonzero, inleger constant ot digItS in tile 11exaciec Imal .:;pecltying the to::al number field being describE~d. w is not: spe(:lfied" for output, tne \1a.lue Lor a :;ingle-precision h(~xadec:lmal fie_Ld is .is (tile detaul C), dnd :~ h e val u e for at do u I) 1 e - pre cis ion hex ad e c 1 mcLl tIe J d 1S L S (the default). FIH input, the data i,"; scanned untll a )lank, comma, or ch,Hacter illegal for the Z ecilt (jescrlptor is encountered. [f in is an optional, uns lqned, integer constant StJ-=Cl LYlnq tne .ninimum number at digits to be output In the tleld. The iefault for sinqle-~recision hexadecimal tlclds is 9 dlgits; the detault for double-precIsion fields IS Hi dlqlCS. 12-37 FORMATTED DATA TRANSFERS L Editing 12.4.12 L Editing The L edit descriptor provides editing of logical data. The form of the L edit descriptor is: [r]L[w] where: r is an optional, unsigned, nonzero, integer constant specifying the number of consecutive logical fields being described. The default is one logical field. w is an optional, unsigned, nonzero, integer constant specifying the total number of characters in the logical field being described. If w is not specified, for output, the value is 15 (the default) For input, the data is scanned until a blank, comma, or character illegal for the L edit descriptor is encountered. 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 I/O list. The input field consists of optional blanks, optionally followed by a period, followed by a T for true or F for false, optionally followed by any series of characters (such as, .TRUE. for true or .FALSE. for false) • 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. 12-38 if the FORMATT3D DATA TRANSFERS A Editing 12.4.13 A Editing The A edit descriptor specifies the editing of character or Hollerith data. The data are stored left-justified in a word and padded with blanks to the right. NOTE The R edit descriptor performs the same function for Hollerith data, only it stores the data right-justified in a word with leading nulls. The R edit descriptor is not supported for character data. For a description of the R edit descriptor, see Section 12.4.14. The form of the A edit descriptor is: [r]A[w] where: r is an optional, unsigned, integer constant specifying the number of consecutive A fields being defined. The default is one A field. w the is an optional, unsigned, integer constant specifying total number of characters in the field being defined. The default for single-precision values is 5 characters; the default for double-precision and complex values is 10 characters. Depending on the I/O operation, the A edit descriptor transfers character or Hollerith data into or from a variable in an I/O list. A list variable may be of any type. For example, READ (6,5) V 5 FORMAT (A4) causes four character or Hollerith characters to be read from and stored in the variable v. unit 6 The A descriptor deals with variables containing left-justified, blank-filled characters. The following list summarizes the result of character or Hollerith data transfer (both internal and external representations) using the A descriptor. These explanations assume that w represents the field width and m represents the total number of characters possible in the variable. Double-precision and complex variables contain 10 characters (m=lO)i integer, real, and logical variables contain 5 (m=5). 12-39 FORMATTED DATA TRANSFERS A Descriptor 1. INPUT, where w > m -- The rightmost m characters of the field are read in and stored in the corresponding variable. 2. INPUT, where w < m -- All w characters are read in and stored left-justified and blank-filled in the corresponding 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 leftmost corresponding variable are output. w characters of the ._--_._---:------------- [ Editing 12.4.14 R Editing _.--------_._---_._--------_._-- The R edit descriptor specifies the editing of Hollerith data. The Hollerith data are stored right-justified with leading nulls. The R edit descriptor is not supported for character data. >,JOTE The A edit descriptor, described in ~ection 12.4.13, performs the same function as the R descriptor except that it left-iustifies the data in storaqe with t:cailing spaces. The form of the R edit descriptor is: [r] R [w] where: r is an optional, unsigned, nonzero, integer constant specifying the number of consecutive R fields being defined. The default is one R field. w is an optional, unsigned, nonzero, integer constant that specifies the total number of characters in the R field. If w is not specified, for output, the value for a single-precision field is 5 (the default), and the value for a double-precision or complex field is 10. For input, the data is scanned until a blank, comma, or character illegal for the R edit descriptor is encountered. 12-40 FORMATT8D DATA TRANSFERS The R descriptor deals with variables containing right-justified, zero-filled characters. The following list summarizes the result of Hollerith data transfer (both internal and external representations) using the R descriptor. These explanations assume that w represents the field width and m represents the total number of characters possible in the variable. Double-precision and complex variables contain 10 characters (m=lO); integer, real, and logical variables contain 5 (m=5). NOTE When more than five characters are stored, bit zero of the low-order word is skipped. Thus, a double-precision or complex variable filled by an R-format data transfer is of the form: R Descriptor 1. INPUT, where w > m -- The rightmost m characters of the field are read in and storej in the corresponding variable. 2. INPUT, where w < m -- All w characters are read in and stored right-justified and zero-filled in the corresponding variable. 3. OUTPUT, where w > m 1m characters are output and right-justified in the field. The remainder of the field is zero-filled. 4. OUTPUT, where w < rn -- The rightmost corresponding variable are output. w characters of the List-Directed Formatting 12.5 LIST-DIRECTED FORMATTING The use of an asterisk in a data transfer statement in place of a FORMAT statement label specifies list-directed formatting. For this type of formatting, the type of each transferred data item is specified by the types of respective elements in the I/O list. List-directed input data transfers are performed without regard for column, card, or line boundaries. List-directed output transfers produce records with a maximum length of 72 characters (the default) or the length specified by the RECL specifier (see Section 11.3.27 for devices other than the terminal). Otherwise, the maximum length of the current terminal width is used. The following is a sample list-directed data transfer statement: READ (5,*)I,IAB,M,L 12-41 FORMATTED DATA TRANSFERS You may use list-directed transfers to read data from any acceptable input device, including a terminal. However, do not use device-positioning commands in conjunction with list-directed data transfers. 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 characteristics: 1. Input constants must be of a form acceptable to FORTRAN. 2. Character constants must be enclosed within single quotes, for example, 'ABLE'. Each apostrophe in a character constant must be represented by two apostrophes. 3. The end of a record is equivalent to a blank except when it occurs in a character constant. In this case, the end of the record is ignored and the character constant is continued with the next reco~d. The first character of the continued record must be blank, which is ignored. 4. If the string of a character constant exceeds the length of the data item, the string is truncated. If the string is shorter than the data item, the string is left-justified and remaining character positions are blank filled. 5. Blanks are used as delimiters in list-directed input. not permitted in any Embedded blanks are, therefore, list-directed data item, with the exception of character constants. 6. Decimal points may be omitted from real constants that do not have a fractional part. In this case, it is assumed that the decimal point follows the rightmost digit of a real constant. 7. Complex constants must be enclosed within parentheses. 8. Octal constants must be preceded with a double quote (II). 9. A numeric data item can correspond only to a numeric constant, and a character data item can correspond only to a character constant. A delimiter in a list-directed list of data items separates one data item from another. Delimiters in data for list-directed input must comply with the following: 1. Delimiters may be commas, blanks, or slashes. 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 treated as a single delimiter. 3. A null item (the complete absence of a data item) is represented by two consecutive commas that have no intervening constant (s). You may place any number of bl anks, tabs, or carriage return/line feed characters between the commas of a null item. Each time you specify a null item in the input data, its corresponding list element is skipped (unchanged) • 12-42 FORMATTED DATA TRANSFERS The following illustrates the effect of the input of item: I/O List A,B,IAB,N Data input 101,'A' ,,20 a null Resulting contents of I/O list items: A B IAB N 101. 'A' unchanged 20 4. Slashes (/) cause the current input operation to terminate even if all the items of the I/O list are not filled. The contents of items of the I/O list that either are skipped (by null items) or have not received an input data item before the transfer is terminated remain unchanged. Once the I/O list of the data transfer 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 null items in data for list-directed assigned a repeat count so that an item is repeated. input may be A constant with a repeat count is written as: r*K where: is an integer constant that specifies the number of times the constant is repeated, the asterisk delimits the repeat count from the constant, and K represents the constant. r A null item with a repeat count is written as an specifies the repeat count, followed by an asterisk. integer, The following are examples of constants and null items: 10*5 3*'ABLE' 3* represents 5,5,5,5,5,5,5,5,5,5 represents 'ABLE' ,'ABLE' ,'ABLE' represents null,null,null NOTE The asterisk form representing nulls must be delimited by a comma or slash; in this case spaces are ignored and not treated as delimiters. 12-43 which FORMATTED DATA TRANSFERS ~O!/\!\':'ELlST·Statement - -,rn'li:Htmq NAMELIST-STATEMENT FORMATTING transter statements descrIbed in Chapter 10 usually include i~; a list ot varIable, array, or array element ::-' ,-1 r data beinq transferred. 'jata " (-~ " ... ~ ~ltrrn~tive way ot creating 1/0 lists is to use the NAMELIST t his In e tho d , v0 u can s p e c i f v the I/O 1 i s t i n a ·1\.~L'LIf~,], :~t,v-Rment and then reterence the list by name in the "'!)[)fi,-iiP elilla r.ransrer statement. i : U c; 1 n:.l "'Ii (' r: r- • u~e '·1 ~ ,do. NAf'1ELlST-statement tormatt inq, as opposed to ! ~ ~ t -- rl ire c ted for mat tin q, V0 U nee rl 0 n 1 y ret ere nee NAi"1t:LIST name In a data transter statement. c: '"'1. :~ r t:i'/ G r- N.~MELIST Slatement J /'-. ~.: F: r . T S r r / n a me / 1 i s t r .1 n am e I .1 i s t J • • • L::~: :ld!!l!~ '::~,.::!:eci ",' !':'':;\ ! ~ 1i h j t. e ITl S com p r i sin a the N AM ELI S T I /0 tIle 1 i s t may bE' va ria b 1 e n arne s a r :jC'Jd[rlte fTlUitlPie list items with commas. : :; ••J !i .,> i _,::rFl rn (' s is 'l' !\l~ L t: t- ()! L t: 1 1 n i :"; t '·.r'!l~~!rj ! ~1 t.lw NAMELIST I/O list. This is the name In ddta transter statements. Each NAMELIST ')C cnc.1used in slashes. OL 1 i st. a r ray ,) t a N 1\ MEL 1ST s tat e Ilt e n t I S ide n t i fie d a n d by the name immediately precedinq the list. an example ot creatinq two NP,MELIST I/O lists and SUM S • having C(),4.l ,TOTAL(lU) '~I~,'!I,''\!<-:T!)N . '- :',":'/\:..\L~~~/.Il,,~!C/SUMS/TOTAL ,i ..:: j r _. d (1 (1 '-'l~:::' TABLE l(jentlties thE list consistinq of the d r r a v C. and the n am e SUM Sid en t i fie s the 1 i s t ndIlle:' f _ r: ':' dr(d'i l"Yl'.A,L. 12-44 FORMATT~D DATA TRANSFERS Once a list has been defined ill a NAMELIST statement, one or more statements may ref:erence its name. I/O The rules for structur ing a NAr1ELIST statement are: 1. You may use a maximum of six characters for a NAMELIST name. 2. You must begin the li:,t name with an alphabetic character. 3. You must enclose the 4. You should use program. S. You may define a NAMEL.IST name only once, and you mllst detine it by a NAMELIST s~atement. Once defined, you may use the name only in I/O tran!,ter statements. 6. You must define the NAMELIST name before "tatement.s in WhICh ii: is used. 7. You must define any dimensioned variable contained in a NAMELIST statement In an array declaration statement precedinq the NAf'lELIST statement. 12.7.1 NAMELI~3T NAMELI~)T NAMELIST-Controlled Da~a names name in slashes. that are unique the wi thin data the transfer Input Transfer During data input transfers ~n which a NAMELIST-detined name is referenced, records are read Imtil a record is found that begins with a blank, then $ (dollar sign), and then the desired NAr'1ELIST name. The dollar sign must be the s,~cond character in the rE~cord; the first character in the record must b,~ a blank. NOTE You may use "&" input. instea(l of II C" II ~) in NAMELIST-controlled Da t a i tern s 0 f r e cor d s to be i n put (r e ad) us i n g NAM ELI S T - d e fin e d must be separated by commas and may be of the following form: lists V=Kl,K2, ••• ,f(n where: v may be a variable, array, or array element name. K 1 , ••• , Kn are constants. A series of ident.ical constants may be rj~presented as a single constant preceded by a repetLtion count (5*5 represents 5,5,5,5,5). You can :;pecify more than one constant only if V is an arra'/. If V is a scalar, then you may have only Kl. The input data is always conve~ted to the type of the list variable when there is a conflict of t'lpes. A character constant 1S truncated from the right, or extended on the right with blanks, if necessary, to yield a constant of the same lE~ngth as the variable, array, or substring. 12-45 FORMATTED DATA TRANSFERS ~he 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. i\ character constant must have del imi ting apostrophes. If an apostrophe is part of a character constant, it must be represented by two consecutive apostrophes, which must be contained in the same record (one apostrophe cannot end a record, and the other apostrophe :~tart a record). For example, assume: 1. A is a 2-dlmensional real array 7.. B is a I-dimensional integer array 3. C is an inteqer variable 4. 0 is a character variable of length 5. 5. The program contains the NAMELIST declaration: NAMELIST /FRED/ A,B,C,D b. The input data is as follows: ~$FRED A(7,2)=4, B=3,6*2.8, C=3.32, D='RON'$ A READ statement referring to the NAMELIST-defined name FRED will result in the following: 1. The inteqer 4 will be converted to floating point and in A(7,2). 2. The integer 3 will be placed in B(l). 1. The inteqer 2 (after ,~ \ 2) being truncated) be placed in , B ( 3) , • • • , B ( 7) • 4. The floating point number 3.32 integer 3 and placed in C. 5. The character strinq 'RON~~' 12.7.2 will placed will be converted to the will be placed in D. NAMELIST-Controlled Data Output Transfers When a WRITE statement reters 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. Character constants are written with delimiting apostrophes. 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 ~AMELIST-defined list. 12-46 statement contain all referencing a FORMAT,]'ED DATA TRANSFERS For example, if ARRAY is a 2 X 3 real array, Al is a real variable, Kl is an integer variable, and D is a character variable containing the five characters }\B'CD, the statements: REAL ARRAY (L~ , 3) CHARACTER D"~ 5 DATA ARRAy,Al,KI,D/-6.75~ 0.234E-04, 680.0, -17.8,0.0,00, AB' 'CD' / NAMELI ST/NAMI/ARRAY, AI, K"., D WRITE (u, NAtvll) 1 7 3 • 1, 3, generate the following form ! o~ output: io!umn 1 ~$NAMl ARRAY= Al= $END -6.750000, 0.2340000E-04, 680.0000, -17.80000, 2*0.0000000, 73.10000, Kl= 3, D='AB' 'CD' NOTE Do not use device-positioning commands such as BACKSPACE or SKIPRECORD with NAMELIST-contro.lled I/O operations. If you do, the results are unpredictable. 12-47 CHAPTER 13 FUNCTIONS AND SUBROUTINES Procedures you use repeatedly in a program can be written once and then referenced each time you need the procedure. Procedures that may be referenced are either contained within the program in which they are referenced, or self-contained executable procedures that can be compiled separately. The kinds of procedures that can be referenced are: 1. Intrinsic functions 2. Statement functions 3. External functions 4. Subroutines (FORTRAN-defined functions) The first three of these categories are referred to collectively as functions or function procedures; procedures of the last category are referred to as subroutines or subroutine procedures. Intrinsic functions perform a predefined computation with a specific number and type of arguments. These functions are provided by FORTRAN (see Section 13.1). Statement functions are user-defined, single statement procedures that resemble assignment statements. The appearance of a statement function reference in an expression causes the user-defined computation to be performed (see Section 13.2). External functions are separate program units that generally compute a single value using one or more parameters. There are two types of external functions available: user-defined and FORTRAN-supplied. A user-defined external function is defined with a FUNCTION statement. Both types of external functions are invoked by including a function reference in an expression (see Section 13.3). Subroutines are external program units that are used to perform multiple computations or alter variables. There are two types of subroutines available: user-defined and FORTRAN-supplied. User-defined subroutines are defined with a SUBROUTINE statement (see Section 13.4.2.1). Both types of subroutines are invoked with a CALL statement (see Section 13.4.2.2). 13.1 INTRINSIC FUNCTIONS Intrinsic functions are supplied with the FORTRAN software. Each intrinsic function performs a predefined computation. There are two types of intrinsic functions: specific and generic. 13-1 FUNCTIONS AND SUBROUTINES Specific functions have an implicitly defined data type. Each specific function requires arguments of a particular type and returns results of a predefined type. The IMPLICIT statement cannot be used to change the type of a specific intrinsic function. The data type of the return value of a generic function is determined by the data type of its arguments. The FORTRAN generic functions are: ASS ACOS AINT ALOG ALOGIO AMAXI AMINI ANINT ASIN ATAN ATAN2 CMPLX COS COSH DSLE DIM EXP INT LOG LOGlO MAX MIN MOD NINT REAL SIGN SIN SINH SQRT TAN TANH NOTE Table 13-1 lists all the specific and generic intrinsic functions. For ease of identification, each generic function name in the table is indicated by an asterisk. 13.1.1 Using an Intrinsic Function An intrinsic function is used in a FORTRAN expression by referencing the name of the function in an expression. For example, the following program contains two intrinsic functions: ASS (returns the absolute value of the argument) and SQRT (returns the square root of the argument) • PROGRAM TEST Y = -64 A = ASS (Y) TYPE ,A S = SQRT (A) TYPE ,B END When the preceding program is executed, variable Y is assigned the value -64. The ABS function in the second expression calculates the absolute value of -64. Next, in the third expression, the SQRT function calculates the square root of the absolute value of Y, which is A. The square root of A is assigned to B in the third expression. Executing the program yields the following resulta: 13-2 FUNCTIONS AND SUBROUTINES EXECUTE TEST. FOR FORTRAN: TEST TEST LINK: Load i ng [LNKXCT TEST execution] 64.00000 8.000000 CPU time 0.1 Elapsed time 4.0 The following example contains specific and generic functions. In the example, the generic function SQRT is used to find the square root of the double-precision value 64.0. Next, the specific function DSQRT is used to find the square root of the double-precision value 64.0. If the argument supplied to DSQRT was not a double-precision number, a fatal compilation error would I"esult. PROGRAM TESFUN DOUBLE PRECISION A,B,AR,BR REAL C,eR A B C C C 64.00DO 64.00DO 64.00 GENERIC SQRT RETURNS DP SQRT BECAUSE ARG TYPE IS DP AR = SQRT(A) C C C SPECIFIC DSQRT PERFORMS THE SAME FUNCTION WHEN GIVEN A DP ARGUMEN'1' BR C C = DSC!RT (A) SPECIFIC SQRT RETURNS A REAL VALUE RESULT CR = SQRT(C) TYPE, ]\.R,BR,CR END Executing the program above yields the following results: EXE TESFUN LINK: Load ing [LNKXCT TESFUN Execution] 8.0000000000000000, 8.0000000000000000, 8.000000 CPU time 0.1 Elapsed time 0.7 Table 13-1 lists the FORTRAN intrinsic functions. This table gives function definitions, argument and function types, and ranges of acceptable values.. Each function contains a description of the range for valid arguments(s) and the range within which the function returns valid results. If function arguments do not fall within the specified range, the result of the function is undefined. For more information on the precision and accuracy of the FORTRAN intrinsic functions, refer to the TOPS-IO/TOPS-20 Common Math Library Manual. 13-:3 FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions - .. Name Argument Type Definition Argument Restrictions Function Type Result Range Exponential EXP* y = e**x Real ·89.415 .LE. x .LE.88.029 Real y .GT. 0 DEXP** y = e**x Double D-floating: -89.415 .LE. x .LE. 88.029 Double D·-floating: y .GT. 0 G·-floating: 710.475 .LE. x .LE. 709.089 CEXP w = e**z Complex -89.415 .LE. REAUzl .LE. 88.029 IAIMAG(zll .LE. 36394.429 G-floating: y .GT. 0 Complex All COMPLEX Numbers Logarithm (LOG, LOG 10 =Generic Functions) ALOG* y = log(x) [base eJ Real x .GT. 0 Real -89.415 .LE. y .LE. 88.029 DLOG** y = log(x) [base eJ Double D-floating: x .GT. 0 Double D-floating: 89.415 .LE. y .LE. 88.029 G- floating: x .GT. 0 CLOG w = log(z) [base eJ Complex z .NE. (o,m G-floating: -710.4 75 .LE. y .LE. 709.08B Complex -89.415 .LE. REAUw) .LE. 88.029 -PI .LT. AIMAG(w) .LE. PI ALOGlO* y = log(x) [base 1O[ DLOG10** y = log(x) [base 1O[ Real x .GT. 0 Real -38.832 .LE. y .LE. 38.230 Double D-·floating: x .GT. 0 Double D-floating: -38.832 .LE. y .LE. 38.320 G-floating: x .GT. 0 G-floating: -308.555 .LE. y .LE. 307.953 Square Root SQRT* y = SQRT(x) = x**12 DSQRT** y = SQRT(x) = x**L'2 _.- Real x .GE. 0 Real y .GE. () Double D-floating: x .GE. 0 Double D-floating: y .GE. 0 G-floating: x .GE. 0 CSQRT w = SQRT(z) ~ z**112 Complex Any COMPLEX Number 13-4 G-floating: y .GE. 0 Complex All COMPLEX Numbers REAL(w) .GE. 0 FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Name Definition Argument Type A rgument Restrictions Function Type Hesult Hange Trigonometric SIN* y ,= sin(x) .;in(x) (degrees) :-iJND v DSIN** y ,= sin(x) Real 1,,1 .LE. 210828714 Real Heal 1:1 .LE. --l7IH!)919 Heal Double D-floating: I> i .LE. 6746~j18852 Double (-floating: 1>·1 .LE. 1686()29713 CSIN w = sin(z) COS* y (;()SD :". DCOS** y = cos(x) = cos(x) cos(xl (degn'cs) w = cos(z) TAN* y DTAN** [)COTAN' LE. I Complex IHEAUzlj .LE. 210828714 11\IMAG(z)1 .LE. 88.895 Complex All COMPLEX Numbers Real I>.j .LT. 210828714 Real 1 .LT. y .LE. 1 J{eal ;: .LT. 4711-\5919 Heal 1 .1.T. \ . LE. 1 Double ii-floating: 1;:1 .LT. 6746518852 Double D-floating: 1.LE.y.LE.l G-floating: 1 .LE. y .LE. 1 Complex IImAL(zll .LE. 210828714 IAIMAG(zlj .LE. 88.895 Complex All COMPLEX Numbers tan(x) Real 1:..:1 .LE. 363913 Real All REAL Numbers y = tan(x) Real II-floating: I:{i .LE. 3373259426 Double D-floating: All D-·FLOATING Numbers ~ (f-floating: I{i .LE. 843314856 C<JTAN I .LE ..\ D-floating: -1 .LE. y .LE. 1 G-floating: . 1 .LE. y .LE. 1 G-floating: Ixl .LT. 1686629713 CCOS -1 .LE. y .LE. 1 \" ". U:. :Hi:!96 eoUx l Ilpal XI cotlxl (l()uble tloating: x .LK :1:373259426 ) ; !1(1ating: x .LE. 8433.148[,6 13-5 G-floating: All G-FLOATING Numbers Ileal All HKA.L Numbers Ilouhlc Df10ating All D FLOATING Numbers G· floating: All G FLOATINU Numbcrs FUNCTIONS AND SUBROUTINES Table 13-1: Name FORTRAN Intrinsic Functions (Cont.) Definition Argument Type Argument Restrictions Function Type Result Range Inverse Trigonometric -- ASIN* y = arcsin(x) Real - 1 .LE. x .LE. 1 Real - PJ/2 .LE. y .LE. PII2 DASIN** y = arcsin(x) Double D-floating: -1 .LE. x .LE. 1 Double D-floating: -PJ/2 .LE. y .LE. PII2 G-floating: -1 .LE. x .LE. 1 G-floating: -PJ/2 .LE. y .LE. PII2 ACOS* y = arccos( x) Real -1 .LE. x .LE. 1 Real DACOS** y = arccos( x) Double Dfloating: -1 .LE. x .LE. 1 Double o .LE. y .LE. PI D-floating: o .LE. y .LE. PI G-floating: I .LE. x .LE. I G-floating: o .LE. y .LE. PI ATAN* y = arctan(x) Real x ~ any REAL Numbers Real -Pl/2 .LE. y .LE. PII2 DATAN** y = arctan(x) Double D-floating: x = any D-FLOATING Numbers Double D-floating: -Pl/2 .LE. y .LE. PI/2 G-floating: x = any G-FLOATING Numbers ATAN2* y = arctan(argliarg2) DATAN2** y = arctan(argllarg2) G-floating: -Pl/2 .LE. y .LE. PII2 Real argl,arg2 = any REAL Numbers Real -PI .LE. y .LE. PI Double D--floating: arg I ,arg2 = any f)-·FLOATING Numbers Double D-floating: -PI .LE. y .LE. PI G-floating: argl,arg2 = any G--FLOATING Numbers G-floating: -PI .LE. y .LE. PI Hyperbolic SINH* y = sinh(x) Real Ixl .LE. 88.722 Real All REAL Numbers DSINH** y = sinh(x) Double D--floating: Ixl .LE. 88.722 Double D-floating: All D-FLOATING Numbers G-floating: Ixl .LE. 709.782 G-floating: All G-FLOA TING Numbers COSH* y = cosh(x) Real ixl .LE. 88.722 Double y .GE. 1 DCOSH** y = cosh(xl Double D-floating: !xi .LE. 88.722 Double D-floating: y .GE. 1 G-floating: ix! .LE. 709.782 G-floating: y .GE. 1 TANH* y = tanh(x) Real Any REAL Numbers Real -1 .LE. y .LE. 1 DTANH** y = tanh(x) Double D-floating: Any D-FLOATING Numbers Double D--floating: -1 .LE.y.LE. 1 G-floating: Any G-·FLOATING Numbers 13-6 G-floating: -1 .LE. y .LE. 1 FUNCTIONB AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Name Definition Argument Type Argument RE!strictions Function Type Result Range Absolute Value ABS* Y = Ixl Real ArlY REAL Numbers Real Y .GE. 0 lABS Y = Iii Integer ArlY INTEGER Numbers Integer Y .GE. 0 Y = Ixl Double D-floating: AllY D--FLOATING Numbers Double D--floating: Y .GE. 0 DABS** G-floating: AllY G--FLOATING Numbers CABS Y = Izl Complex AllY COMPLEX Numbers -- G--floating: Y .GE. 0 Real Y .GE. 0 Truncation AINT* Sign of arg * largest integer .LT.largl Real AllY REAL Numbers Real All REAL Numbers INT* Sign of arg * largest integer .LT·largl Real AllY REAL Numbers Integer All INTEGER Numbers IDINT Sign of arg * largest integer .LT·largl Double AllY DOUBLE PRECISION Numbers Integer All INTEGER Numbers DlNT** Sign of arg* largest integer .LT·largl Double D-floating: AllY D--FLOATING Numbers Double D·-floating: All DFLOATING Numbers G-floating: AllY G--FLOATING Numbers G-floating: All G--FLOATING Numbers ---. Nearest Whole Number ANINT* Y = int(x + .5) if x .GE. 0 else y=int<x-.5) Real AllY REAL Numbers Real All REAL Numbers DNINT** Y = int(x + .5) if x .GE. 0 else Y = int<x -.5) Double D- ·floating: AllY D--FLOATING Numbers Double Dfloating: All D--FLOATING Numbers G--floating: AllY G--FLOATING N'lmbers G-floating: All G--FLOA TING Numbers Nearest Integer NINT* Y = int(x + .5) if x .OE. 0 else Y = int(x -.5) Real x LE. 12"*35)·-1 x GE. -(2"*35) Integer All INTEGER Numbers IDNINT Y = int(x + .5) if x .GE. 0 else Y = int(x -.5) Double x LE. 12**35) 1 x GK (2"*:~5) Integer All INTEGER Numbers 13-7 -- FUNCTIONS AND SUBROUTINES Table 13-1: Name FORTRAN Intrinsic Functions (Cont.) Definition Argument Type Argument Restrictions Function Type Result Range Remaindering AMOD Remainder when argl is divided byarg2 Real arg2 .NE. 0 Real o .LE. y .LT. arg2 MOD* Remainder when argi is divided byarg2 Integer arg2 .NE. 0 Integer o .LE. y .LT. arg2 DMOD** Hemainder when argi is divided byarg2 Double D-floating: arg2 .NE. 0 Double 0-· floa ting: o .LE. y .1.1'. arg2 G- floating: arg2 .NE. 0 G-floating o .LE. y .LT. arg2 -- Maximum Value (MAX = Generic Function) -- AMAXO Argument with greatest value Integer Any INTEGER Numbers Real All HEAL Numbers AMAXl* Argument with greatest value Real Any REAL Numbers Real All REAL Numbers MAXO Argument with greatest value Integer Any INTEGER Numbers Integer All INTEGER Numbers MAXI Argument with greatest value Real Any REAL Numbers Integer All INTEGER Numbers DMAXI*'" Argument with greatest value Double D floating: Any D FLOATING Numbers Double D-floating: All D-FLOA TING: Numbers G- floating: Any G-FLOATING Numbers G-floating: All G-FLOATING Numbers Minimum Value (MIN = Generic Function) _.- AMINO Argument with least value Integer Any INTEGER Numbers Real All REAL Numbers AMINI" Argument with least value Real Any REAL Numbers Real All REAL Numbers MINO Argument with least value Integer Any INTEGER Numbers Intl'ger All INTEGER Numbers MINI Argument with least value Real Any REAL Numbers Integer All INTEGER Numbers DMINI** Argument with least value Double D floating: Any D-·FLOATING Numbers Double D-floating: All D-FLOATING Numbers G-floating: Any G-FLOATING Numbers 13-8 G-floating: All G-FLOATING Numbers FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Name Definition Argument Type Argument Restrictions Function Type Result Range Transfer of Sign SIGN* If arg2 .GE. 0 then larg11 else -!arg11 Real Any REAL Numbers Real All REAL Numbers ISIGN If arg2 .GE. 0 then larg11 else -Iargl! Integer Any INTEGER Numbers Real All INTEGER Numbers DSIGN** If arg2 .GE. 0 then iarg11 else -Iargll Double D-floating: Any D-·FLOATING Nlmbers Double D-·floating: All D-FLOATlNG Numbers G-floating: Any G-FLOATING Nlmbers G-floating: All G-FLOATING Numbers Positive Difference DIM'" If argl .GT. arg2 then arg1 - arg2 else 0 Real Any REAL Numbers Real y .GE. 0 IDIM If arg1 .GT. arg2 then argl - arg2 else 0 Integer Any INTEGER Numbers Integer y .GE. 0 DDlM** If arg1 .GT. arg2 then argl - arg2 else 0 Double D-floating: Any D-FLOATING Nlmbers Double D-floating: y .GE. 0 G- floating: Any G-FLOATING Nlmbers G-floating: y .GE. 0 Double Preeision Product DPROD argl *arg2 ~Y REAL Numb", Double ALL DOUBLE PRECISION Numbers Conversion Routines CONJG arg = x ·t i"'y, CONJG = x·- i*y Complex Any COMPLEX Numbers Complex All COMPLEX Numbers REAL* arg = x + i*y returns x Complex Any COMPLEX Numbers Real All REAL Numbers AIMAG arg = x + i*y returns y Complex Any COMPLEX Numbers Real All REAL Numbers CMI'LX" Returns argl I i"arg~ Real Any HEAL Numhers Complex All COMPI.EX Numbers DFLOAT lnte~er to double preCISIOn Integer An\' INTEGEIi~ Numbers Double iy: .LT. ~"" :~5 DBLE* Real to double precision Real Any REAL Numbers Double All DOUBLE PRECISION Numbers SNGL Double precision to real Double Any DOUBLE PRECISION Numbers Real All REAL Numbers FLOAT Integer to real Integer Any INTEGEF: Numbers Real Iyl .LT. 2**35 IFIX Real to integer Real Ix! ,LT, 2**35 Integer All INTEGER Numbers ICHAR Character to Integer Character FiJ st character of character value Integer o ,LE. y .LE. 127 CHAR Integer to Character Integer o . '~E. y .LE, 127 Character All Single Character 13-9 FUNCTIONS AND SUBROUTINES Table 13-1: Name FORTRAN Intrinsic Functions (Cont.) Definition Argument Type Argument Restrictions Function Type Result Range Length LEN Length of character entity Character Any CHARACTER Value Integer y .GE. 1 Integer y .GE. 0 Index of a Substring INDEX Return location of arg2 within argl if not found return 0 Character Size of character string argl must be larger than or equal to arg2 LGE argl .GE. arg2 Character Any CHARACTER Value Logical .TRUE. or .FALSE. LGT argl .GT. arg2 Character Any CHARACTER Value Logical .TRUE. or .FALSE. LLE argl .LE. arg2 Character Any CHARACTER Value Logical .TRUE. or .FALSE. LLT argl .LT. arg2 Character Any CHARACTER Value Logical .TRUE. or .FALSE . Character Comparisons Bit Manipulation lAND IOH Pf'rforms a logical AND on corresponding hit,.. of argl and arg2 Integer arg I .arg2 o. any Inte~er Numbers Integer All Integer Numbers Pl'rf()rm~ an inclu~ive Integer arg l.arg2 = any Integer Numbers Integer All Integer Numbers 01{ on corresponding hits of argl ;md arg2 IEOR Pertl)rm;.; an exclusive Oft on corresponding bits of argl and arg2 Integer arg l.arg2 = any Integer Numbers Integer All Integer Numbers NOT Complements each bit of argument Integer Anv Integer Number Integer All Integer Numbers ISHFT L()~icall:v shiftt< argl Integer argJ any Integer Number :16 . I.E. arg2 .LE. 36 Integer All Integer Numbers argl Ir;teger All Integer Numbers leit arg2 bits if arg2 is positive; argl is logically shifted right aq~L ~,its if arg2 is nt~~atlve ISHFTC Circularlv shifts (rotates) Intpger rightmost arg:3 bits of argl by arg2 places. If ilrg2 is positive. the rutation is to the left: :f arg2 is negative. the mtation is to the nght anv Inte~er Numbpr :16 .LE. arg2 .U: 36 I .LE. arg3 .I.E. 36 13-10 FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Name Definition Argument Type Arl!Ument Restrictions Function Type Result Range Bit Manipulation IBITS Extracts bits arg2 through arg2 + arg:l-] from argl *** Integer IBSET Returns the value of argl with bit arg2 of argl set to 1 integer IBCLR Returns the value of argl with bit arg2 of argJ set to 0 Integer ar~ 1 ~ Returns .TRUE. if bit arg2 of argl equals 1; returns .FALSE. if hit arg2 of argl is 0 Integer BTEST any Integer All Integer Numbers arl'l = any Integer Number o .LE. arg2 .LE. 35 Integer All Integer Numbers any Integer All Integer Numbers Logical .TRUE. or .FALSE. ar~ 1 7 Int'~ger Number (] .LE. arg2 .LE. :{5 ar~ 2 -+ arg3 .LE. 36 Int~ger Number o .LE. arg2 .LE. 35 ar!!l ~ any Int'~ger NumbE-r o .LE. arg2 .LE. 35 Notes: * = Generic function ** =- G-floating double-precision functions (KL model B only) -- are used if IGFLOA TING compiler switch is specified (see Section 16.1.3 or 16.2.3l. *** ,= See also the MVBITS Subroutine. Section 13.4.Ul (2**35)-1 = 34359738367 -(2**35) = -34359738368 13-11 FUNCTIONS AND SUBROUTINES 13.1.2 Character Intrinsic Functions Character intrinsic functions are functions that take character arguments or return character values. Character comparison intrinsic functions are functions that take character arguments and return logical values. FORTRAN provides four character intrinsic functions: 1. LEN The LEN function returns the length of a character expression. The LEN function has the following form: LEN(arg) where: arg is a character indicates how expression. returned expression. The value many characters there are in the The following example illustrates the LEN function: C C This subroutine reverses an entire character string. SUBROUTINE REVERS(S) CHARACTER T, S*(*) J = LEN(S) DO 10 I=1,J/2 T = S(I:I) S(I:I) = S(J:J) S(J:J) = T J 10 = J - 1 CONTINUE RETURN END 2. INDEX The INDEX function searches for a substring (arg2) in a specified character string (arg1), and, if it finds the substring, returns the substring's starting position. If arg2 occurs more than once in argl, the starting position of the first (leftmost) occurrence is returned. If arg2 does not occur in arg1, the value zero is returned. The INDEX function has the following form: INDEX(argl,arg2) where: arg1 is a character expression specifying the string to be searched for the substring specified by arg2. arg2 is a character expression substring that is searched for. 13-12 specifying the FUNCTIONS AND SUBROUTINES The following example illustrates the INDEX function: C C C C This subroutine places the symbol # into the variable MARKS at places corresponding to the beginning of all occurrences of the substring SUB within the string S. SUBROUTINE FINSTR(SUB,S) CHARACTER*(*) SUB, S CHARACTER*132 MARKS INTEGER I,J 1=1 MARKS 10 1 1 = INDEX(S(I:), SUB) IF (J .NE. 0) THEN J I = 1 + J MARKS(I-l:I-l) = 1#1 IF (I .LE. LEN(S» GO TO 10 END IF 91 3. WRITE (5,91) S, MARKS FORMAT (2(/lX,A» END ICHAR The ICHAR function converts a character expression to equivalent ASCII code and returns the ASCII value. ICHAR function has the following form: its The ICHAR(arg) where: arg 4. is the character to be converted to an ASCII code. If arg is longer than one character, only the value of the first character is returned; the remaining characters are ignored. CHAR The CHAR function returns the single character whose ASCII code is the integer or octal argument. The CHAR function has the following form: CHl\R(arg) where: arg is an integer expression. The following example illustrates the CHAR and ICHAR functions: CHARACTER C*l INTEGER I C C Convert number between 0 and 9 in I to a character digit C = CHAR(I+ICHAR('O'» END 13-13 FUNCTIONS AND SUBROUTINES 13.1.3 Character Comparison Functions The four character comparison functions provided with FORTRAN are: LLT, where LLT{argl,arg2) is equivalent to (argl.LT.arg2) LLE, where LLE{argl,arg2) is equivalent to (argl.LE.arg2) LGT, where LGT{argl,arg2) is equivalent to (argl.GT.arg2) LGE, where LGE{argl,arg2) is equivalent to (argl.GE.arg2) The comparison functions have the following form: func{argl,arg2) where: arg is a character expression. The character comparison functions defined by the FORTRAN-77 standard are guaranteed to make comparisons according to the ASCII collating sequence, even on non-ASCII processors. On TOPS-IO/20 systems, the character comparison functions are identical to the corresponding character relationals. An example of the use of a character comparison function follows: CHARACTER*lO CH2 IF (LGT{CH2,'SMITH'» STOP The IF statement in this example is equivalent to: IF (CH2.GT.'SMITH') STOP :3.1.4 Bit Manipulation Functions intrinsic bit manipulation functions are used for manipulation of the in the binary patterns that represent integers. Integer data Lypes are represented internally in binary two's complement notation. !3it positions in the binary representation are numbered from right ~least siqnificant bit) to left (most significant bit); the rightmost 0it position is numbered 0, and the leftmost bit position is numbered ~5. A bit in a binary pattern has a value of 0 or 1. ;;i ts The intrinsic functiDns lAND, lOR, lEaR, and NOT perform bitwise ')perations on all the bits of their arguments. Bit 0 of the result is -~e result of applying the specified logical operation to bit 0 of the .lrguments. Bit 1 of the result is the result of applying the .~pecified logical operation to bit 1 of the arguments, and so on for .j ~ l the bi ts of the resul t. shift functions lSHFT and lSHFTC shift binary patterns. A :)ositive shift count indicates a left shift, while a negative shift <aunt indicates a right shift. A shift count of zero means no shift. _SHFT specifies a logical shift; bits shifted out of one end are lost ",nd zeros are shifted in at the other end. ISHFTC performs a circular .hift; bits shifted out at one end are shifted back in at the other '''hi':' 13-14 FUNCTIONS AND SUBROUTINES The function IBITS and the subroutine MVBITS (see Section 13.4.1.21) operate on bit fields. A bit field is a contiguous group of bits within a binary pattern. Bit fields are specified by a starting bit position and a length. A hi: field must be entirely contained in its source operand. For example, the integer 79 i:; represented pattern: by the following binary o ••• 0101111 n ••• 6543210 (bi t posi t ion) where: n is 35 ,:the number oE bit positions in an integer). You can refer to the bit field contained in bits 3 through 6 by specifying a starting position of 3 and a length of 4. In the above example, the selected bit pat~ern would be the following: o ••• 000101 Negative integer~; are represented in two's complement notation. integer -79 is represented by the following binary pattern: The 1 .•• 1010001 n ••• I) 5 4 3 21 0 ( bit po sit ion) where: n is 35 ': the number 0,: bi t posi tions in an integer). NOTE is negative The value of bit pos i': i on 1 a for 35 ,~ number for non--negative. Also, all the and 0 high-order bits of th,~ pa t tE~ rn to the left of the value up to bit 35 ar·~ the same as bit 35. IBITS and MVBITS operate on bLt fields. Both the starting position of a bit field and its lenqth a~e arguments to these intrinsics. IBSET, IBCLR, and BTEST operate only on one bit. Thus, they do not require a length argument. 13.2 STATEMENT FUNCTIONS A statement function is a procedure specified by a single statement that is similar in form 1:0 an arithmetic, character, or logical assignment statement. The statement function enables you to define a single-line computation once in your program, give it a name, and have that calculation performed each time you reference the statement function in the program. A statement function is classified as a nonexecutable statement. 13-15 FUNCTIONS AND SUBROUTINES 13.2.1 Defining a Statement Function Statement functions have the following form: fun [d [, d] ••• ] ) = e where: fun is the symbolic name for the statement function. The function name follows the rules for forming symbolic names in FORTRAN (see Chapter 4). d is an optional dummy argument. Separate multiple dummy arguments with commas. (Dummy arguments are described in Section 13.4.5.) The parentheses are still required if no dummy arguments are specified. e is any type of FORTRAN expression. The expression part of the statement function (to the right of the equal sign) defines the computation performed using the dummy arguments. The relationship between fun and e must conform to the assignment rules in Sections 8.1, 8.2, and 8.4. Note that the type of the expression may be different from the type of the statement function name. The following functions: rules govern the formation and use of statement 1. The dummy argument list in the statement function serves only to indicate the order, number, and type of arguments for the statement function. 2. The dummy arguments used in a statement function are local to that statement function. It is valid to use the same names in multiple statement functions in the same program unit. A dummy argument name may also be used elsewhere in the program unit to identify a variable of the same type, including its appearance as a dummy argument in a FUNCTION, SUBROUTINE, or ENTRY statement. 3. Each dummy argument in a statement function dummy argument list must be unique; the same dummy argument cannot appear twice in a single list. Each variable reference in the function can be either a reference to a dummy argument of the statement function, or a reference to a variable that appears within the same program unit as the statement function statement. If a statement function dummy argument name is the same as the name of another entity, the appearance of that name in the expression of a statement function statement is a reference to the statement function dummy argument. 13.2.2 Using a Statement Function Statement functions are used in FORTRAN programs by referencing the name of the statement function in an expression that is in the same program unit as the statement function definition. If a character function is referenced in a program unit, the function length specified in the program unit must be an integer constant expression. 13-16 FUNCTIONS AND SUBROUTINES For example, the following program uses a statement function (called PROFIT) to determine the ?rofit for a product. In the statement function definition, PROFIT is defined as the difference between wholesale and retail prices minus .05 sales tax. PROGR)\M STAFUN PROFrl' (A,B) == 100 ((A - B) -- (A * .05» WRITE (UNIT=5,FMT==lOO) FORMAT(lX,'Enter Mlolesale Price and Retail Price') ACCEPT *, WHOSAL, RET.\I L 150 C = PROFIT(RETAIL,WHOSAL) 101 WRITE(UNIT=5,FMT=lQl) C FORMA'r(lX, 'The Profit (minus sales tax) is: ',F8.2) END When the program is executed, the retail and wholesale values are entered at the terminal. Next, the expression at statement number 150 uses the values of RETAIL and WHO SAL to calculate the profit as defined in the PROFIT statement function. A sample execution of this program yields the following results: EXECUTE STATE LINK: Load i ng [LINKXCT STAFUN executio~] Enter Wholesale Price and Retail Price 31.67 45.95 The profit (minus sales tax) is: 11.98 CPU time 0.2 Elapsed time 18.5 When a FORTRAN expression that contains a statement function reference is executed, the following happens: 1. The actual arguments contained reference are evaluated. 2. The actual arguments in the statement function are associated with the dummy arguments in the statement function definition. 3. The expression portion of the statement function is evaluated using the actual arguments. 4. If necessary, the value of the expression is converted to the type of the statement function. Finally, the value resulting from the expression evaluation is substituted in the expression containing the statement function reference. 13.2.3 in statement function Statement Function Restrictions The following rules and restrictions must be statement functions: 1. the adhered to when using The actual arguments in a function reference must agree in type and number with the corresponding dummy arguments in the statement function dummy argument list. 13-17 FUNCTIONS AND SUBROUTINES 2. An actual argument in a statement function reference can itself be an expression; all actual arguments must be defined when a statement function reference is evaluated. 3. A statement function can only be referenced in the unit that contains the statement function statement. 4. A statement function must not contain a reference to another statement function that appears later in the program unit, but can contain a reference to another statement function that appears earlier in the program. 5. The symbolic name used to identify a statement function must not appear as a symbolic name in any specification statement except a type statement (to specify the type of the function) or as the name of a common block in the same program unit. 6. An external function reference (see Section 13.3) in the expression part of a statement function statement must not cause a dummy argument of the statement function to become undefined or redefined. 7. The symbolic name of a statement function may not be an actual argument. It must not appear in an EXTERNAL statement ( see Se c t ion 7. 6) • 8. A statement function statement in a function subprogram (see Section 13.3.4.) must not contain a function reference to the name of the function subprogram or an entry name in the function subprogram. 9. An actual argument in a statement function reference can be any expression, ~ncluding a character expression involving concatenation of an operand whose length specification is an asterisk in parentheses. 10. The length specification of a character must be an integer constant expression. 13.3 statement program function EXTERNAL FUNCTIONS An external function is a procedure that is defined externally to the program unit that references it. FORTRAN offers two types of external functions: FORTRAN-supplied and user-defined. The FORTRAN-supplied external functions are described in Section 13.3.1; the user-defined functions are described in Sections 13.3.2 through 13.3.4. lJ.3.1 FORTRAN-Supplied External Functions ORTRAN-supplied external functions are similar to intrinsic unctions. To use a FORTRAN-supplied function, you reference its name n an expression. 13-18 FUNCTIONS AND SUBROUTINES The following are the FORTRAN-supplied external functions: x=DTOG (y) returns a G-floating double-precision number in the range 1.47 x 10**-39 to 1.70 x 10**+38. The argument y is aD-floating double-precision number. (Also, see the 0TOGA subroutine, Section 13.4.1.12.) x=GTOD (y) returns a D-floating double-precision number in the ranqe 1.47 x 10**-39 to 1.70 x 10**+38. The argument y is a G-floating double-precision number. (Also, see the GTODA subroutine, Section 13.4.1.18.) x=LSNGET(unit} returns the last line number read in a line sequenced file. LSNGET returns a positive integer if the last line has a valid line number; returns zero if the last line is a page mark; or returns -1 If the last line number is invalid (such as, AAAA with bit 35 se t) • It al so returns -1 It the tile contains no line number, or was opened with a mode other than, LINED (see Section 11.3.20). x=RAN(O} returns a pseudo random floating-point number in the range of D.LT.x.LT.1. The argument is a durrmy (not used) and may be any number. Refer to the related subroutines SETRAN (see Section 13.4.1.27) and SAVRAN (see Section 13.4.1.26) • x=RANS(O) returns a pseudo random floating-point number in the range of O.LT.x.LT.l. RANS is a primE-modulus random number generator with shuffling capability. It calls RAN to generate its initial table of random devi2tes. Refer to related subroutins SETRAN (see Section 12.4.1.27) and SAVRAN (see S~ction 12.4.1.26). y=SECNDS(x} returns the system tIme in seconds as a single-precision, floating-point value, minus the value of its sinqle-precision, floating-point argument. The argument y is set equal to the time in seconds since midnjght, minus the user-supplied value of x. x=TIM2GO (0) returns the number of seconds remaining in the -job's run-time limit. The time limit is set by the /TIME switch when submitting the hatch iob. The argument is a dummy (not used) and may be any number. ntay also specify a time limit for an interactive job by using the SET TIME-LIMIT COffiffictnd on TOPS-20, 0 r the SET TIME command on TOPS-IO. You FORTRAN-supplied external functions are treated in the same manner as user-defined functions. Impljcit or explicit type declarations affect these funct ions, and no a I"g umen t check ing (type or numbe r) is performed at compile time. 13-19 FUNCTIONS AND SUBROUTINES 13.3.2 User-Defined External Functions An external user-defined function is a procedure that is external to the program unit that references it. The function subprogram enables you to define a multiline function. By referencing the name of that function in an expression, the lines of the function are automatically executed. The FUNCTION statement is always the first statement subprogram. The form of the FUNCTION statement is: [type] FUNCTION fun ([arg1 in a function [,arg2] .•• ]) where: type is an optional type specification for the external function. This may be INTEGER, REAL, DOUBLE PRECISION, COMPLEX, LOGICAL, or CHARACTER (plus the optional size modifier *len). For CHARACTER, len is the length specification of the result of the character function. If you specify CHARACTER*(*), the function assumes the length declared for it in the program unit that invokes it. If len is an integer constant, the value of len must agree with the length of the function specified in the program unit that invokes the function. If a length is not specified in a CHARACTER FUNCTION statement, a length of one is assumed. function If you do not specify a type, the type of the subprogram name determines the data type of the external function. fun is the symbolic name of the externa~ function subprogram. Unless the optional data type is specified in the FUNCTION statement, the type of the function name determines the data type of the function subprogram. arg is an optional dummy argument. Arg may be a variable name, array name, or dummy procedure name. Separate multiple dummy arguments with commas. The parentheses are optional if no dummy arguments are specified. You must define the symbolic name assigned a function subprogram as a variable name in the function. During each execution of the function, this variable can be redefined. The value of the variable at the time of execution of any RETURN statement is the value of the function. NOTE The RETURN statement returns control to the statement that referenced the function subprogram (see Section 13.4.4). Additionally, you may desire to have a function start executing at a statement other than the first executable statement in the function subprogram. The ENTRY statement (see Section 13.4.3) enables you to define an alternate entry point in the function subprogram. 13-20 FUNCTIONS AND SUBROUTINES 13.3.3 Function Subprogram R~strictions The following rules govern the structuring of a function subprogram: 1. You can not use the ~;ymbolic name of a function subprogram in any nonexecutable ~;tatement in the subprogram except in the initial FUNCTION statement or a type statement. 2. Dummy argument names cannot appear in any EQUIVALENCE, COMMON, or DATA statement used within the subprogram. 3. The function subprogram can define or redefine one or more of its arguments so as to return results in addition to the value of the function. 4. The function subprogram can contain any FORTRAN statement except BLOCK DATA, SUBROUTINE, PROGRAM, or another FUNCTION statement. 5. 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 can have more than one RETURN statement. The END statement specifies the subprogram and implies a return. physical end of the 6. If the type of a function is specified in a FUNCTION statement, the function name must not appear in a type statement. Note that a name must not have its type explicitly specified more than once in a program unit. 7. A function specified in a subprogram may be referenced within any other procedurl~ subprogram or the main program of the executable program. A function subprogram must not reference itself, either directly or indirectly. 8. If the name of a func:tion subprogram is of type character, each entry name il1 the function subprogram must be of type character. If the name of the function subprogram or any entry in the subprogram has a length of (*) declared, all such items must have a length of (*) declared; otherwise, all such items must have a length specification of the same integer value. 13.3.4 Using a Function Subprogram After defining a function subprogram, you use it by referencing the name of the function s~bprogram in an expression. Function subprograms are referenced in expressions using the following form: fun ([argl,a.rg2, ••• argn]) where: fun is the function subprogram name. This is the same name that appears in the corresponding FUNCTION statement. The length of the character function in a character function reference must be the same as the length of the character function in the referenced function. 13-21 FUNCTIONS AND SUBROUTINES arg is an optional list of actual arguments. These arguments must agree in type and number with the dummy argument list of the corresponding FUNCTION statement. If the actual and dummy arguments do not agree, no type conversion is done; and the results are unpredictable. The parentheses are required even if no actual arguments are specified. When an expression that contains a function executed, the following happens: subprogram reference 1. Evaluation of actual arguments that are expressions 2. Association of actual arguments with the corresponding arguments 3. Execution of the referenced function subprogram dummy Section 13.3.3 describes all the restrictions that must be adhered when using function subprograms. 13.4 is to SUBROUTINES A subroutine subprogram is a procedure that is external to the program units that reference it. FORTRAN offers two types of subroutines: user-defined dlllj FORTRAN-supplied. FORTRAN-supplied subroutines are described in Sections 13.4.1 - 13.4.1.32; user-defined subroutines are described in Sections 13.4.2 through 13.4.2.4. NOTE The FORTRAN-supplied subroutines are described in this manual in two sections. Section 13.4.1 describes the ~eneral ~ORTRAN subroutines; Appendix F describes the ~;ubroutines that enable you to use a plotter. Program units reference subroutines with the CALL statement (see Section 13.4.2.2). The subroutine reference in the CALL statement contains the unique name of the subroutine, as defined in a SUBROUTINE statement (see Section 13.4.2.1). The SUBROUTINE statement is always the first statement in a subroutine. When a CALL statement reference is made to a subroutine subprogram, program execution transfers from that CALL statement to the referenced subroutine subprogram. By including the ENTRY statement (see Section 13.4.3) within the body of a subroutine subprogram, you can enter the subroutine at a point other than the first statement in the subroutine. In this case, the CALL statement used to reference an entry point in a subroutine contains a reference to an entry point name, as opposed to the subroutine name. Return of program control from the subroutine to the calling program unit occurs when the RETURN statement is executed (see Section 13.4.4). The RETURN statement is always the last statement executed in a subroutine subprogram. 13-22 FUNCTIONS AND SUBROUTINES 'fable 13-2: FORTRAN-Supplied Subroutines '---"--- --"------------_._-----.....----------. Form Se(~tion Function ~----------------------------.--~-------------------.-----------------.------~~------------CALL ALCCllR(size) Allocates span' for dynamic character concatenation operatiolls. 13.4.1.1 rlpres - CDABS(dparg) Heturns tIll' dO'lble··precision absolute valUl' of the spPcifipd do Ible-precu:iion complex number. 1 :3.4.1.2 ('ALL CDCOSldparg.dpresl Finds the complex co~ine of the double-prccisioJI compll'x number. ~pecifil'd 1 :~.4.1 :\ ('ALL CDEXPldparg.dpres) Finds the comllex l'xponenlial of the sp('citied doubk-prl'cisio 1 complt'x number. 1 :3.4.1.4 ('ALl. CDLOG(dparg,rlpres) R<.'turns lhl' C( mplex logarithm of a duubll'-pn'cisiol ('ompll'x numher. ~pecified ('ALL CDSIN(dparg,dprps) Returns thl' 20mplex Sll1e of tlw precision comp ex number spt'cificci. doubll'- 1:1.<1.16 ('ALL CDSQRT(dparg.dpres) i{eturns the complPx ~quan' root of the double preciSIOn complex number sp<'cificd. 1:1.4.1. 7 CALL CHKDIV(unitvarl I{eturns thl' numb!.'r of t1w unit to which error messages an' t'l'ing written. 1:IA.l.H ('ALL CLRFMT(arraynanH') Discards the H)I{M AT statement .-;<lvpd by the ('xpcutioT1 of' tll' SAVFMT ~;ubroutine. 1:1.4. l.!::l ('ALL DATEII1amc) I'lacl's thp cU!'l'('nt data. left-justified. in a characll'r "'arlahle 1:1.4.1.10 CALL 1)\ VERT(un) Enables you 0 n'dll'l'ct error messages from tIll' current dtvin' to an open file on a sp<'cified devictc'. };3.4.1.11 ('ALL IrrO(;A(sname.dname,n \ Convert" del wnts of doublp-precision arrays fi'om D float II1g double-prl'cision format to (; .floating do .lbl(L.pr<'cisioJ1 format. \:U.1.12 CALL IJ LJ 1\1 p( LB I . U H 1.limned I 1 ...• LBn.UBn,fi)rmatn II Causl'1' spl'ci ied portions of memory to be dumped to th,' line prillter (LPT:I. (:ALI, El{HSETln) ('ALL EHH~ET(n.ll CALL EHHSET(n.l,subri Controls the output or arithmetIC error m('~ sage~ dlll'ing program ('xl'l'ution. 1:1.4.1.14 ('ALL EHH~NS( II ('ALL ERI{SNS(] .•J) CALL EI{]{SNS!I.,J.MSG I J)('t<.'I·l11lfH'S t 1l' f('as()n for <In error trapped by ERR on an OPEN. CLOSE, or datil tran.",fl'r oPP),;,tiOll. 1:1.4.1.15 ('ALL 1'~XlT 'I't'rminat.l's t w program and l'l'turns control to the monitor. 1:1.4.1.1 () Heturm the IHlrntwr or thp first FOHTRAN l'lgical unit availabll' n.<1 1 17 COIl\'('rb pit-ments of doublL'-precislOn arra.vs from (;t1o;lting double·precision l(lrJnat to I) lloatll1g d lUbll'-pn'cision format. U.4 1 I H CALL ILL Sl't~ th(' lLU:(; flag. 1:U 1.1!) CALL LE( ;AL ('lear~ the lLU:(; J:U.1.20 CALL MVBJTS(m.Uen.n.jl Tral1sfi'rs a bit lipid from one storag(' location to a sl'('ond ,torClgt' location. CA LL ()" EJ{FLIIANS I I{('turns iniJrll1atlOll about ov('rf1ow. unckrflow. and di'ide' che'ck. CALL (;T(H)A(sllame.dname.ni nag. ('ALL PIHTMP(LB1.UD1JorJlIatl Function,; l'xactly Ilk(, DUMP suhroutllw ('X- I ... LBn.U Bn.limnatn I) l'{'pl that COllt rol returns to the call1l1g program 1:1.1.1.21 ;II'Il'r tlw dump has bn'n t'xt'l'uted. QlJIETX Suppn'Si-'es .111 SUlllll1ar~' typ<' out wlH'1l tlw proI-!'rarn tl'rmi WIt's. ___ ____ _ _ ._ _ _ _ ._ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 13-23 I;U.l.~4 ~ _ _ _ _ _ _ _ __ _ J FUNCTIONS AND SUBROUTINES Tah/£' 1:J-2: FORTHAN--Supplipd Suhroutines !Cont.) ,----------Form I - - 1--- - - - - - - - - Function ('AIJ. SAVFMT1n;lnH'i,arravsiZ<'!! Section Directs rOBOTS tl) ('ncodc format sp('('ificain the slwcifipd charart(']' vari- (lOllS l'ontain('rl I dhl(' (/1' :lrrav, <'ALI. SAVHAN,tl' j (',\I,L SOHTI'sort string', I Sav('s the last internal integer spcd valup gen,·rat(·d hv the nAN function, I:1A.L26 Specifi('s the intl'rnal ill(('gn :-;('f'd valup filr th(' I{AN function, 1:3A,1.27 Sorts onl' or mon' tih's progT;lnl, CALL SHTINllnl using the SOHT Din'c(s FOf{OTS to "tart allocating memory 13.4, 1.29 from top downward to account itJr large overla,v programs and pn'allocatc's pages (jOO:677 for SOH'/', CALL TIME, x I CALL TIMI'~'x,yl I{eturns the curn'llt ! ill1e of day in left-justifipd CALL TOPMEMI n' Direch FOROTS !o start allflenring rnpll10ry from top rlowllward to account for largp overla:v ASCII 13A.1.31 prllgr,lIl1S, ,'ALL THACE ,-------------13.4.1 (;pnpr;] tes a Ii sf. of act i ve subprograms Oil the (('rrninaL ____,____ ,__ -----------.1---------- FORTRAN-Supplied Subroutines The FORTRAN software includes a set of predefined subroutines. Th. section describes the general FORTRAN subroutines (and a function thi is similar) in alphabetical order. (See Appendix F for t! tORTRAN-supplied plotter subroutines.) NOTE Sections 13.4.1.2 through 13.4.1.7 describe subroutines (and a function) that are used for calculations on double-precision complex numbers. You must supply your own subroutines for performing addition, subtraction, multiplication, and division of double-precision complex numbers. In addition, FORTRAN does not support the double-precision complex data type (called COMPLEX*16). These numbers are kept as arrays and cannot be used in expressions or as the arguments of generic routines. 1 ALCCHR Subroutine ] L_____________ _ 13.4.1.1 ALCCHR Subroutine - The ALCCHH subroutine allocates spaCE for dynamic character concatenation operations. You do not normall~ need to allocate space for this purpose unless you are doing very large character concatenation operations. 13-24 FUNCTIONS AND SUBROUTINES The form of the ALCCHR subroutine is: CALL ALCCHR(size) where: size is the integer size in characters for or expanding the character stack. L either CDABS Function creating ] ---------------- CDABS Function - The function returns the 13.4.1.2 CDABS double-precision absolute value of the specified double-precision complex number. (Although CDABS is a function and is not a subroutine, it is included here because it is similar to some subroutines. ) The form of the CDABS function is: dpres = CDABS(dparg) where: dparg is a 2-element double-precision array containing the complex value whose absolute value you want calculated. The first element of dparg contains the real part of the double-precision complex number; the second element contains the imaginary part. dpres is a double-precision variable that absolute value of the complex number. is set to the ~ DCOS Subroutine ---------_. 13.4.1.3 CDCOS Subroutine - Tje CDCOS subroutine finds cosine of the specified double-precision complex number. the complex The form of the CDCOS subrouti,e is: CALL CDCOS(dparg,dpres) where: dparg is a 2-element jouble-precision array containing the complex value whose cosine you want calculated. The first element of dparg contains the real part of the double-precision complex number; the second element contains the im3ginary part. 13-25 FUNCTIONS AND SUBROUTINES dpres is a 2-element double-precision array in which the subroutine returns the result of the calculation. The first element of dpres contains the real part of the double-precision complex number; the second element contains the imaginary part. Example: DOUBLE PRECISION dparg(2) ,dpres(2) dparg(l) = IDa !arg is dparg(2) = -IDa CALL CDCOS(dparg,dpres) ~ (1,-1) C~EXP Subroutine -------~ 13.4.1.4 CDEXP Subroutine - The CDEXP subroutine finds the exponential of the specified double-precision complex number. complex The form of the CDEXP subroutine is: CALL CDEXP(dparg,dpres) where: dparq is a 2-element double-precision array that contains the complex argument to the subroutine. The first element of dparg contains the real part of the double-precision complex number; the second element contains the imaginary part. dpres is a 2-element double-precision array that stores the result of the calculation. The first element of dpres stores the real part of the result; the second element stores the imaginary part. Example: DOUBLE PRECISION dparg(2) ,dpres(2) dparg(l) = aDO dparg(2) = IDa !arg is (0,1) CALL CDEXP(dparg,dpres) 13.4.1.5 CDLOG Subroutine - The CDLOG subroutine returns the logarithm of a specified double-precision complex number. 13-26 complex FUNCTIONS AND SUBROUTINES The form of the CDLOG subrout~ne is: CALL CDLOG(dparg,dpres) where: dparg is a 2-element double-precision array that contains the double-precision complex number whose logarithm you want calculate(i. The first element of dparg contains the real part of the complex number; the second element contains the inaginary part. dpres is a 2-element double-precision array that stores the result returnt~rl by CDLOG. The first element of dpres contains the rt~al part of the double-precision complex number; the second element contains the imaginary part. Example: DOUBLE PRECISION dparg(2: ,dpres(2) dparg(l) = IDO !arg is dparg(2) = ODD CALL CDLOG(dparg,dpres) (1,0) ------l [ eOSIN Subroutine _____________ -.J 13.4.1.6 CDSIN Subroutine - ~~he CDSIN subroutine returns the sine of the double-precision complex number specified. complex The form of the CDSIN subrout:.ne is: CALL CDSIN(dparg,dpres) where: dparg is a 2-element double-precision array that contains the number whose sine you want calculated. The first element of dparg contains the real part of the double-precision complex number; the second element contains the inaginary part. c]pres is a 2-element double-precision array in which the result of thf! calculation is returned. The first element of dpr~!s contains the real part of the result; tr..e second ele!11ent contains the imaginary part. Example: DOUBLE PRECISION dparq(2; ,dpres(2) dparg(l) = -lDO !arg is dpar9(2) = lDO CALL CDSIN(dparg,dpres) 13-27 (-1,01) FUNCTIONS AND SUBROUTINES CDSQRT Subroutine 13.4.1.7 CDSQRT Subroutine - The CDSQRT subroutine returns the complex square root of the specified double-precision complex number. The form of the CDSQRT subroutine is: CALL CDSQRT(dparg,dpres) where: dparg is a 2-element double-precision array that contains the riouble-precision complex number whose square root you want calculated. The first element of dparg contains the real part of the double-precision complex number; t::.he second element contains the imaginary part. dpres is a 2-element double-precision array that contains the result of the calculation. The first element of dpres contains the real part of the complex square root; the second element contains the imaginary part. SXClmple: :JOUBLE PRECISION dparg(2) ,dpres(2) ciparg(l) = lODO dpres(2) = -lODO !arg is CALL CDSQRT(dparg,dpres) (10,-10) ICHKDIV i Subroutine I 13.4.1.8 CHKDIV Subroutine - The CHKDIV subroutine returns the number the unit to which error messages are being written. This c;ubroutine returns the value -1 if the messages are being sent to the '__ erminal. 0f The form of the CHKDIV subroutine is: ~ALL CHKDIV(unitvar) where: unitvar is the variable in which the unit number 13-28 is stored. FUNCTIONS AND SUBROUTINES r·-----· i i CLRFMT Subroutine L. 13.4.1.9 CLRFMT Subroutine - The CLRFMT subroutine discards the encoded form of the FORMA']' statement saved by the execution of the SAVFMT subroutine (see Sectior 13.4.1.25). The form of the CLRFMT subroutine is: CALL CLRFMT(arrayname) where: is the nan!e of the array that contains the encoded form of the FORMAT specifications saved by the SAVFMT sut·routine. arrayname r-------"-- --- -- --------] ~ I ! DATE Subroutine i L_____ ____ ._ 13.4.1.10 DATE Subroutine - 'l'he DATE subroutine stores the current date as a left-justified AE;CII string in a character variable. The date is in the form: dd-mmm-yyb where: is a 2-digit day (if the first digit is 0, it is converted to a blank), mmm i~. a 3-1etter month abbreviation (such as, Jan,Feb), yy is a 2-letter year, and b is a blank. The data is stored in ASCII, left-iustified, and blank filled. rid The form of the DATE subroutir.e is: CALL DATE(name) where: name is the name of a character variable. The date returned by the subroutjne is stored in this variable. NOTE For compatibility with previous versions of FORTRAN-IO/20, you car:. specify a numeric array name as the argument for the DATE subroutine. The current date is stored as a left-iustified ASCII strinq in a 2-word array or data item (double-precision or complex). The array ITlust have at least two elements. 13-29 FUNCTIONS AND SUBROUTINES DIVERT Subroutine 13.4.1.11 DIVERT Subroutine - The DIVERT subroutine enables you to redirect error messages from the current device to an open file on a specified device. The form of the DIVERT subroutine is: CALL DIVERT(un) where: un is the logical device number of the file on which file resides. the open ----] [ DTOGA ~broutine 13.4.1.12 DTOGA - The DTOGA subroutine converts elements of double-precision arrays from D-floating double-precision format to G-floating double-precision format. The form of the DTOGA subroutine is: CALL DTOGA (sname,dname,n) where: sname is the name of the source array. dname is the name of the destination array. n is the number of elements to convert. (See Section 13.4.1.18 for the GTODA subroutine.) DUMP Subroutine 13.4.1.13 DUMP Subroutine - The DUMP subroutine portions of memory to be dumped to the line printer 13-30 causes (LPT:). specified FUNCTIO~IS AND SUBROUTINES The form of the DUMP subroutire is: CALL DUMP(LBl,UBl,tormatJ [ .•• ,LBn,UBn,formatn]) where: LBl,UBl are the integer values of the upper addresses to bE dumped. formatl is an integer that indicates possible specifications are: the and lower dump format. memory The octal real inteqEr /l.SC I I 0 1 '") ~- -3 If no arguments are supplied, all of user memory is dumped In octal. If only the bounds arguments are specified, or if the format value is out of range, the dump format is octal. If only the first bound argument i s ' specified, all locations from that address to the end of memory are dumped. The dump is terminated by a c2l1 to EXIT. r'------I I, ~ L ___ _ 13.4.1.14 ERRSET' Subroutine - The ERRSET subroutine output of warning messages during program execution. controls the The ERRSET subroutine has thrEe forms: 1. CALL ERRSET(n) 2. CALL ERRSET(n,i) 3. CALL ERRSET(n,i,subr) where: n is the maximum number of error messaqes to type. is the code to which error the call applies; one of the followinq: -1 r) 1 ~) 3 4 ~ G " R C'1nv 01 the followinG inLeq('r overflow jnteQ('r divide input integer overflow input floating overflow float ng overflow fluatJnq divide check floatinG underflow in~ut floating underflow 1 ihrarv routine error 13-31 FUNCTIONS AND SUBROUTINES 3 output field width too small FORLIB warnings nonstandard usage warnings Bounds check warnings 1 2 1 is not specified, -1 is assumed if :3ubr is the name of the user-defined error handling routine be invoked each time any of the above errors occur. The e~fect is as if [0 CALL SUBR (I,IPC,N2,ITYPE,UNFIXD,FIXED) were placed in the program just after causing the trap. I the instruction = error number of trap, same as above IPC PC of trap instruction (if trapped, IPC = PC of the IOLST. call N2 = second error number code is 9 (reserved for Digital) ITYPE = data type of value UNFIXD = value returned by the hardware ¥IXED = value after fixup \/Alue) (SUBR can change If SUBR is not specified, no routine is called the APR trap. this on ,--------------i I ERRSNS Subroutine t_. . _______. ._.___._______._ .__. . _ _.__._. _. ________. l3.4.l.l5 ERRSNS Subroutine - The ERRSNS subroutine returns integer values that describe the status (success or failure) of the last I/O nperation (see Appendix D). This subroutine can be used to determine the reason for an error trapped by ERR= on an OPEN, CLOSE, or data transfer operation. Both return values are always cleared after a successful data transfer operation. The forll1s of the ERRSNS subroutine are: CALL ERRSNS (I) ::::ALL ERRSNS (I, J) )r :ALL ERRSNS (I,J,MSG) 13-32 FUNCTIONS AND SUBROUTINES where: I returns a FORTF:AN-supplied number class of failure that occurred. describes the a processor-specific number that or qualifies the type of the last optionally returns further descrjbes error. MSG that the If present, is a character variable used to return text of the last error message. ASCII It the variable is the text for MSG is less than 80 characters, if than truncated; the variable is greater 80 with right is padded the characters, th{~ text to blanks. NOTE For compat .. bility with previous versions of FORTRAN-lO;'20, you can specify a numeric array as the MSG argument. The numeric array is used as a 16-word array to return the ASCII text ot the last error message. 13.4.1.16 EXIT Subroutine - The EXIT subroutine terminates the program and returns control to the monitor. The EXIT subroutine takes no arguments. The form of the EXIT subrolltine is: CALL EXIT --·-···_- --- .'- ---·------------1 r FFUNIT I Subroutine L__.__________ ....__._______ J 13.4.1.17 FFUNIT Subroutine - The FFUNIT subroutine returns lowest available FORTRAN logic:al unit number (see Table 10-3). The form of the FFUNIT subrou~ine is: CALL FFUNIT (n) 13-33 the FUNCTIONS AND SUBROUTINES 1··----·.--.----------------GTODA Subroutine l _______. _p ______ -I _...1 ~L i3.4.1.18 GTODA Subroutine - The GTODA subroutine converts elements double-precision arrays from G-floating double-precision format to D-floating double-precision format. ~f The form of the GTODA subroutine is: CALL GTODA(sname,dname,n) v..'here: ~See sname is the source array name. dname is the destination array name. n is the number of array elements to convert. Section 13.4.1.12 for the DTOGA subroutine.) 13.4.1.19 ILL Subroutine - The ILL subroutine sets the ILLEG flag. [f this flag is set and an illegal character is encountered in floating-point, double-precision input, the corresponding value is set to zero and no error message is issued. The ILL subroutine takes no ~rguments. The ILLEG flag is not set initially. rhe form of the ILL subroutine is: CALL ILL r-·····-·--~---·--·---·-·---··- I I ! --.----.---- . .----.- LEGAL Subroutine L. . . _. . ._. _. _._. ___ . . _. 11.4.1.20 LEGAL Subroutine - The LEGAL subroutine clears the ILLEG [lag sec by the ILL subroutine. The LEGAL subroutine takes no 1'rq umen ts . T'iL' form of the LEGAL subroutine is: 13-34 FUNCTIONS AND SUBROUTINES [ -----'-------1 MVBITS Subroutine ._.__. .'.. _.. ___, ______ J 13.4.1.21 MVBITS Subroutine -. The MVBITS subroutine transfers a bit field from one storage location (source) to a field in a second storage location (destination). The form of the r.'iVBITS subrout:ine is: CALL MVBITS(m,i,len,n,j) where: m is an integer expre~;sion that represents the source location from which a bit fiE!ld is transferred. i is an integer exprE!ssion that identifies the position in the SOUI-ce field transferred from m. first len is an integer expre~;sion that identifies the length field transferred fl-om m. of bit the n is an integer val-iable or array element that is the destination location to which a bit field is transferred. j is an integer expression that identifies the first position in the c1estination field transferred from m. bit The MVBITS subroutine transfel~s len bits from position i through i+len-l of the source locat~on (m) to positions j through j+len-l of the destination location (n). Other bits of the destination location and all of the bits of the source location remain unchanged. The values of i+len and j+len musi: not be greater than 36. (See Section l3.J~.4 for infornation on bit manipulation functions.) [ -----.----.-.--J. OVERFL Subroutine --- '-.'~ -------.------ 13.4.1.22 OVERFL Subroutin,~ _. The OVERFL subroutine information about overflow, ulderflow, and divide check. The form of the OVERFL subrou':ine is: CALL OVERFL(IANS) 13-35 returns FUNCTIONS AND SUBROUTINES wnere: is an integer variable whose value specifies whether an overflow, underflow, or divide check has occurred since the last call to OVERFL. The values returned are: ~ANS at least one overflow, check occurred. underflow, or divide none occurred. 2 - I-----s~~~~~ne L_. ___________._._____________. . . ___ . . __ . . _ t 13.4.1.23 PDUMP Subroutine - The PDUMP subroutine functions exactly like the DUMP subroutine (see Section 13.4.1.13) except that control returns to the calling program after the dump has been executed. The form of the PDUMP subroutine is: CALL PDUMP(LBl,UBI,formatl[ .•. ,LBn,UBn,formatn]) where: LBI,UBI are the integer values of the upper addresses to be dumped. formatl is an integer that indicates possible specifications are: the and lower dump format. memory The octal real integer ASCII 0 _L 2 ) _.1 no arguments are supplied, all of user memory is dumped in octal. If only the bounds arguments are specified, or if the format value is aut ot range, the dump format is octal. If only the first bound 3rgument is specified, all locations from that address to the end of memor yare dumped. [f ,-.-.-------.--.----.-.-.-----...---.-. -. '-1 I ! I a U I E T X II' Subroutine L._ . _________________. ____________.___ . _J l~.4.1.24 QUIETX Subroutine - The QUIETX subroutine suppresses all :>llmmary typeout when the program terminates, including library error :,ilmmaries and CPU times. The OUIETX subroutine takes no arguments. "'he form of the OUIETX subroutine is: "ALL OUIETX 13-36 FUNCTIONS AND SUBROUTINES -- -_._- _. -------.- --_._------j [ SAVFMT Subroutine ---_._----------- 13.4.1.25 SAVFMT Subroutine _. The SAVFMT subroutine directs FOROTS to encode the FORMAT specificat~ons contained in the specified character variable or array, and to SaVE! the encoded form. This action improves the performance of any fuLure 1/0 statements which that character variable or array is the format identifier. FOROTS saves the encoded form of the format until a call to CLRFMT (see Section 13.4.1.9) is executed for that variable or array, or until another call to SAVFMT -os executed for that variable or array. NOTE After a call to SAVFMr~, you must not change the value of the variable or array_ If the value is changed, the new value may be _.gnorecl. A call to SAVFMT with a variable or array whose address is identical to that in a previous call, does an implied call to CLRFMT. The form of the SAVFMT subroutine is: CALL SAVFMT(name[ ,arrays:.ze]) where: name is the nane of the character variable or array that contains the FORMAT descriptors that you want encoded. urraysize is the nunber of array elements specified. if an array is NOTE For compatibility with previous versions of FORTRAN-10/20, you can specify a numeric array name as the argument for the ::;AVFMT subroutine. [ 13.4.1.26 internal function, time it to SETRAN ------- -----------] SAVRAN Subroutine ------.-------- SAVRAN Subroutine -- The SAVRAN subroutine saves the last integer seed valu'~ generated by the RAN function. The RAN described in Sectio'1 13.3.1, returns a random number each is called. This value can be used at a later time in a call to reestablish the .3ame random number sequence. 13-37 FUNCTIONS AND SUBROUTINES The form of the SAVRAN subroutine is: CALL SAVRAN(n) where: n is an integer variable into which the SAVRAN subroutine stores the last internal integer seed value generated. ~ --~ SETRAN Subroutine 13.4.1.27 SETRAN Subroutine - The SETRAN subroutine specifies the internal integer seed value for the RAN function. If the SETRAN argument is zero, RAN uses its own default starting value. The form of the SETRAN subroutine is: CALL SP,TRAN(n) where: n is a nonnegative integer constant 2**31) . or variable (less than SORT Subroutine 13.4.1.28 SORT Subroutine - The SORT subroutine sorts one or more files using the SORT program. You can successfully use this sub r 0 uti n eon 1 y i f the SORT so f twa r e has been ins tall e d ( see the FORTRAN Installation Guide). The SORT software is sold as a separate product and may -i1O-t-be-avaTlable at your installation. The form of the SORT subroutine is: CALL SORT('sort string') where: sort string is a command line containing file specifications and SORT switches. For specific information about the SORT command line, see the SORT/MERGE User's Guide. 13-38 FUNCTIONS AND SUBROUTINES NOTE The sert string must be compatIble with the current version of the standalone SORT. Therefore, the string is not the same for TOPS-I0 and TOPS-20 (see the '§~Q?_T / r-' ~~g_~ ~~~ r 's G~_~~_~) • 13.4.1.29 SRTINI Subroutine - The SRTINI subroutine directs FOROTS to start allocating memory from t.op downward to account for large overlay programs and preallocates pagE·s 600: 677 (octal) for SORT. The form of the SRTINI routinE is: CALL SRTINI(n) where: n is top page number t.o use when allocating memory. Note that FOROTS will not alle,cate pages (including DDT pages) have been marked as unavailabJe at memory initialization. 13.4.1.30 TIME Subroutine - ~'he TIME subroutine returns time of day in left-justified ASCII. the that current The TIME subroutine has two forms: CALL TIME(x) or CALL TIME(x,y) where: x i s a c h a r act e r va r i (\ b 1 e • In the 0 n e a r 9 urn e n t tor m , TIM E r~eturns the time :_n x in the form: hh:mm, where hh is the h 0 u r ( 2 4 - h 0 u r tim e) and mm i s the min ute s • y is a character variable. When the two argument form of the TIME subroutine is used, the forms of the time returned in x is the same as the one arqument form, and the value returned in y has the f 0 ]- m : b s s • t, wher e b i s a b 1 an k, s s i s the current seconds, and t is the current tenths 01' seconds. 13-39 FUNCTIONS AND SUBROUTINES HOTE For compatibility with previous versions of FORTRAN-IO/20, you can specify a numeric variable or array element as an argument of the TIME subroutine. The following example demonstrates using the one and the two forms of the TIME subroutine in a program. argument PROGRAM TIMTST CHARACTER*lO X,Y CALL TIME(X,Y) WRITE(UNIT=5,FMT=101)X,Y CALL TIME(X) 102 WRITE (UNIT=5, FMT=102)X FORMAT(lX,'THE ONE ARGUMENT TIME RETURNS: ',A) SND EXECUTE TIMTST LINK: Loading [LNKXCT TIMTST execution] THE TWO ARGUMENT TIME RETURNS: 09:00 20.9 THE ONE ARGUMENT TIME RETURNS: 09:00 CPU time 0.1 Elapsed time 0.2 S:~~:~i~e ] I L______________________________ 13.4.1.31 TOPMEM Subroutine - The TOPMEM subrJutine directs FOROTS to start allocating memory from a specified page number downward to account for large overlay programs. The form of the TOPMEM subroutine is: CALL TOPMEM(n) where: n is the top page number to use in allocating memory. Note that FOROTS will not allocate paqes (including DDT pages) have been marked as unavailable at memory initialization. 13-40 that FUNCTIONS AND SUBROUTINES I---~ I TRACE I . SUb~Uline _____ 13.4.1.32 TRACE Subroutine - The TRACE subroutine generates a list of active subprograms on the terminal. An active subprogram is one that has been called but has not YEt returned. The main program is always active. The trace listinq st2rts at the currently active routine (the one containing the call to TFACE) and proceeds back to the main program. The form of the TRACE subroutine is: CALL TRACE The information produced by tte TRACE routine consists subprogram: of, for each The name of the routjne The address of the rcutine (in octal) J. The address of the slbprogram call offset) (expressed as routine-name -I- 4. The address of the slbprogram call fset with the calling routine) (expressed as label + ()f ~. The number of argumerts passed to the called routine 6. The types of the argLments passed including: 'i l" - (; ~ : :. i) - 'J - :{ - Character string descriptor D-tloating couble precision Heal G-floating couble precision Integer or couble integer Literal string Logical Octal or dOlble octal Statement 12bel Unknown arglment type Complex If there are too many arguments to display, the contain ' 'types' column will If local symbols are loadec with the program, the label+offset information will be much more informative. A label of the form 12345P refers to FORTRAN statement nLmber 12345; a label of the form 56789L refers to line number 56789 in the compiler listing. Line number labels only appear if the program was compiled with /DEBUG:LABELS (see Chapter 16). The traceback listing is sent to the error-message unit, which is normally the terminal. YOl can use the DIVERT subroutine (Section 13.4.1.11) to change where thE listing is sent. 13-41 FUNCTIONS AND SUBROUTINES Example: 10 20 PROGRAM MAIN TYPE 10 FORMAT (I' Calling 8UBl:') CALL 8UBl TYPE 20 FORMAT (I' Calling 8UB2:') CALL 8UB2 (A,B) END SUBROUTINE SUBl Y = F(X) END SUBROUTINE SUB2 (G,H) CALL SUB3 (G,H,I) END SUBROUTINE SUB3 CALL TRACE END (Al,A2,A3) FUNCTION F(Y) CALL SUB2 (Y,O) 1:"=2. END EXECUTE TRC.FOR Load i ng LINK: [LNKXCT TRC execution] Calling 8UBl: Name TRACE. SUB3 SUB2 (Loc) (426373) (256 ) (232) F ( 30"1) SUBl (214) «--«--«--«--«--«--- Caller 8UB3+2 8UB2+6 F+20 8UB1+2 MAIN.+7 (Loc) (SUB3+2) (SUB2+6) (F+20) (SUB1+2) (MAIN.+7) Args 0 3 2 1 0 Types «--«--«--«--- Caller 8UB3+2 8UB2+6 MAIN.+14 ( Loc) (SUB3+2) (SUB2+6) (MAIN.+14) Args Types 3 2 FFI FF FFI FI F Calling SUB2: Name TRACE. SUB3 SUB2 ( Loc) (426373) (256 ) (232) CPU time 0.4 13.4.2 o Elapsed time 3.1 User-Defined Subroutines A subroutine subprogram is a separate program unit. The FORTRAN CALL statement is used in a program unit to call a subroutine subprogram. The CALL statement contains the name of the subroutine to which control passes when the CALL statement is executed. The CALL statement can also optionally contain actual arguments that are passed to the called subroutine. The CALL statement is described in Section 13.4.?'.2. 13-42 FUNCTIONS AND SUBROUTINES The SUBROUTINE statement is always the first statement in a subroutine subprogram. The SUBROUTINE statement defines the name and, optionally, any dummy arguments used by the subroutine. The SUBROUTINE statement is described in Section 13.4.2.1. The ENTRY statement enables yeu to enter a subroutine subprogram at a statement other than the first statement of the subroutine. The ENTRY statement is described in Section 13.4.3. The last logical statement of a subroutine subprogram is always the RETURN statement. By default, the RETURN statement always returns control to the first executable statement in the calling program that immediately follows the CALL statement. Optionally, you may use the alternate return form of the RETURN statement to return control to a statement other than the default. Both forms of the RETURN statement are described in Section 13.4.4. 13.4.2.1 SUBROUTINE Statement - The SUBROUTINE statement is always the first statement in a subroutine subprogram. It is used to define the name of the subroutine and, optionally, to define dummy arguments that are used by the subroutine. The form of the SUBROUTINE statement is: SUBROUTINE sub [([dl[,d2) ••• ])] where: sub is the symbolic name of the subroutine or dummy procedure. d is an optional dummy argument for the subroutine subprogram. This argument can be a variable name, an array name, a dummy procedure name, or any combination of these separated by commas. The parentheses are optional if no dummy arguments are specified. The following subprogram: rules control the structuring of a subroutine 1. You can not use the symbolic name of the subprogram in any statement within the defined subprogram except the SUBROUTINE statement itself. The symbolic name of a subroutine is a global name and must not be the same as any other global name or any local name in the program unit. 2. The symbolic name of a dummy argument is local to the program unit and must not appear in an EQUIVALENCE, PARAMETER, SAVE, INTRINSIC, COMMON, or DATA statement except as a common block name. 3. The subroutine subprogram may define or redefine one or of its dummy arguments so as to return results. more 4. If the actual argument is a constant or expression, subroutine must not change the value of that argument. the 5. The subroutine subprogram may contain any FORTRAN statement except BLOCK DATA, FUNCTION, PROGRAM, 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. 13-43 FUNCTIONS AND SUBROUTINES 6. Dummy arguments that represent statement labels may be either an *, $, 0 r &. 7. The subprogram should contain at least one RETURN statement and must be terminated by an END statement. The RETURN statement indicates a logical end of the routine; the END statement signifies the physical end of the subroutine. If no RETURN precedes the END statement, then the RETURN statement is implicit. 8. Subroutine subprograms can have as many entry points as desired (see description of ENTRY statement given in Section 13.4.3) • 9. A character dummy argument whose length specification is an asterisk in parentheses may appear as an operand for concatenation. 13.4.2.2 CALL Statement - The CALL statement is used in a program unit to reference a subroutine. Execution of the CALL statement causes a transfer of program control to the subroutine referenced in the CALL statement. The CALL statement can also contain a list of arguments that by the computation performed in the referenced subroutine. is used The form of the CALL statement is: CALL sub [([al[,a2] ••• ])] where: sub is the symbolic name of a subroutine or dummy procedure. a is an optional actual argument that is used by the subroutine. The actual arguments in the CALL statement must agree in position and type with the dummy arguments in the referenced SUBROUTINE statement. The parentheses are optional if no actual arguments are specified. 13.4.2.3 Execution of a CALL Statement - When executed, the following results occur: a CALL statement is 1. Any actual arguments in the CALL statement argument list that are expressions are evaluated. 2. The actual arguments are then associated with arguments in the referenced SUBROUTINE statement. 3. Control passes to the subroutine and it is executed. 4. Return of control calling program statement. the dummy from the referenced subroutine to the completes the execution of the CALL A subroutine can be referenced within any other procedure or the main program of the executable program. A subprogram cannot, however, reference itself, either directly or indirectly. 13-44 FUNCTIONS AND SUBROUTINES 13.4.2.4 Actual Arguments for a Subroutine - Actual arguments can appear in the CALL statement argument list. Actual arguments must agree in order, number, and type with the corresponding dummy arguments in the dummy argument list of the referenced subroutine. The exception to the agreement rules between actual and dummy argument lists is the use of a subroutine name or an alternate return specifier as an actual argument. Actual arguments in CALL statements can be any of the following: 1. Any expression, including a character expression whose length specification is an asterisk in parentheses. 2. An array name 3. An intrinsic function name 4.. An external proced ure name 5. A dummy procedure name 6. An alternate return label An actual argument in a subroutine reference may be a dummy argument name that appears in a dummy argument list within the subprogram containing the reference. An asterisk dummy argument must not be used as an actual argument in a subprogram reference. 13.4.3 ENTRY Statement The ENTRY statement provides you with a method for entering a function or subroutine subprogram at any executable statement. The ENTRY statement can appear anywhere within a function subprogram after the FUNCTION statement, or within a subroutine subprogram after the SUBROUTINE statement. An ENTRY statement cannot appear between a DO statement and the terminal statement of its DO-loop or inside a block-IF statement. A subprogram may optionally have one or more ENTRY statements. ENTRY statement is classified as a nonexecutable statement. An The form of the ENTRY statement is: EN TR Yen [( d 1 [, d 2 ••• ] ) ] where: en is the symbolic name of an entry in a function or subroutine subprogram. This symbolic name is called an entry name. If the entry name appears in a subroutine subprogram, it is referred to as a subroutine name; if the entry name appears in a function subprogram, it is called an external function name. d is a variable name, array name, dummy procedure name, or the symbols: *, $, or & (these symbols can represent a dummy argument which is an alternate return label). The symbol references (asterisk, ampersand, and dollar sign) are permitted only when the ENTRY statement appears in a subroutine subprogram. 13-45 FUNCTIONS AND SUBROUTINES If you do not specify any parentheses after the entry name, you need not specify any dummy arguments. If, however, you include the parentheses, you must specify at least one dummy argument. 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 more than one ENTRY statement in an external subprogram. 2. Execution begins at the first executable statement 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. 5. You can not use an ENTRY statement in a main program or a subprogram reference itself through its entry points. 6. You can not use an ENTRY statement statement construction. 7. The dummy arguments in the ENTRY statement need not agree in order, number, or type with the dummy arguments in SUBROUTINE or FUNCTION statements or any other ENTRY statement in 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 can not reference a dummy argument unless it appears in the dummy list of the 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 a function current entry name. 13. If an entry name in a function subprogram is of type character, each entry name and the name of the function subprogram must be of type character. If the name of the function subprogram or any entry in the subprogram has a length of (*) declared, all such items must have a length specification of the same integer value. must 13-46 be and in do the returned not following affect range by use of the have a DO arguments of the FUNCTIONS AND SUBROUTINES 13.4.4 RETURN Statement The RETURN statement returns control to the referencing and may appear only in a function subprogram or subprogram. program unit a subroutine The RETURN statement has two possible forms, depending on whether it is the last statement in a function subprogram or a subroutine subprogram. The form of the HETURN stateml;nt in a function subprogram is: RETURN The form of the HETURN stateml;nt in a subroutine subprogram is: RETURN [e] where: e is an integer constant, variable, or expression. This form of thE~ RETURN statl;ment is called an alternate return. The alternate return fonn enables you to select any labeled statement in the calling program unit as a return point after I'~xecution of the program unit in which the alternate RETURN statement appenrs. The value of e shou1d be a positive integer that is equal to or less than the number of statement labels given in the argument list of th(; calling statement. If e is less than 1 or is larger than ":he number of available statement labels, a standard return is performed. (A standard return transfers control back to the first executable statement immediately following the calling statement in the calling program unit). A dummy argument for a statE:!ment label must be either an asterisk (*), a dollar sign ($), or an ampersand ( &) • You may use more than one RETURN (standard return) subprogram. The use of the alternate return statement is restricted to subroutine subprograms. 13-47 statement in any form of the RETURN FUNCTIONS AND SUBROUTINES For example, program: assume the following statement sequence in a main Each occurrence of RETURN returns control to the statement GO in the calling program. TO 101 CALL EXAMP(1,*10,K,*15,M,*20) GO TO 101 10 alternate return #1 15 alternate return #2 20 alternate return #3 END SUBROUTINE EXAMP (L, *,M, *,N,*) RETURN RETURN RETURN(I+J) END If, on the execution of the RETURN(I+J) is: statement, the value of Value The following is performed: less than one 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 the GO TO a standard return to statement is made. 1 2 3 Greater than 3 13-48 (I+J) 101 101 FUNCTIONS AND SUBROUTINES 13.4.5 Dummy and Actual Argwnents Since you may reference subprograms at more than one point throughout a program, many of the val~es used by the subprogram may be changed each time it is used. Dummy ~rguments in subprograms represent the actual values to be used, w~ich are passed to the subprogram when it is called. For example, shown below is a subroutine (TEST) being called from the main program by a CALL statement. In this example, the variables in the CALL statement, A, B, and C(2), represent actual values in the main program. They are therefore called actual arguments. On the other hand, the variables in the SUBROUTINE statement, R, X, and Z, do not represent any values until they have values passed to them from the CALL stateme~t. They are therefore called dummy arguments. (The CALL, SUBROUTINE, and RETURN statements are described in Sections 13.4.2.2, 13.4.2.1, and 13.4.4, respectively.) CALL TEST (A,B,C(2» END SUBROUTINE TEST (R,X,Z) RETURN END Functions and subroutines use dummy arguments to indicate the type of the actual arguments they represent and whether the actual arguments are variables, 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, 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. The position, number, and type of each dummy argument in a subprogram list must agree with the position, number, and type of each argument list of the subprogram reference. NO'TE If the /DEBUG:ARGUMENTS compiler switch is specified (see Section 16.3), optional type checking is performed at load time on dummy and actual arguments. 13-49 FUNCTIONS AND SUBROUTINES Dummy arguments may be: 1. variables 2. array names 3. subroutine identifiers 4. function identifiers 5. the symbols *, $, or & that are used to denote of alternate return labels the position 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 character 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. 13-50 FUNCTIONS AND SUBROUTINES 13.4.5.1 Length of Character Dummy and Actual Arguments - The length of a dummy argument of type character must not be greater than the length of its associated actual argument. Note that if the character dummy argument's length is specified as *(*), the length used is exactly the length of the asscciated actual argument. This is known as a passed length character 6rgument. The length of the dummy argument is determined each time control transfers to the function. The length of the actual argument can be the length of a character v~riable, array element, substring, or expression. A character array dummy argumE'nt can have passed length. of each element in the dummy argument is the length of the the actual argument. The passed length and the array together determine the size of the passed length character The length elements in declaractor array. The following example of a function subprogram uses a passed length character argument. The function finds the position of the character with the highest ASCII code value; it uses the length of the passed length character argument t.o control the iteration. (Note that the intrinsic function LEN is used to determine the length of the argument. See Table 13-1 for a description of the LEN function.) 10 INTEGER FUNCTION ICMAX(CVAR) CHARACTER*(*) CVAR ICMAX =: 1 DO 10 I = 2, LEN (CV]\R) IF (CVAR(I:I) .GT. CVAR(ICMAX:ICMAX)) RETURN END ICMAX =1 Each of the following functiorl references specifies a different length for the dummy argument: CHARACTER VAR*lO, CARRAY:3,5)*20 11 12 13 I 4 IS ICMAX (VAR) ICMAX(CARRAY(2,2)) ICMAX(VAR(3:8)) I CMAX (CARRAY (1,3) (5 15)) ICMAX (VAR(3:4)//CAHRAY(3,.5)) 13.4.5.2 Character and Hollerith Constants as Actual ArgumentsActual arguments and their cOJ~responding dummy arguments must agree in data type. If the actual al~gument is a Hollerith constant (for example, 4HABCD),. the dummy aJ~gument must be of numeric data type. In FORTRAN-IO/20, if an actua: argument is a character constant (for example 'ABCD') r the corresponding dummy argument can have either numeric or character data tYPE!. If the dummy argument has a numeric data type, the character cons~ant 'ABCD' is, in effect, converted to a Hollerith constant by the FOR'rRAN compiler and the loader. An exception to this occurs when the function or subroutine name is itself a dummy argument. It is not possible to determine at compile time or load timE~ whether a charactEH constant or Hollerith constant is required. In this case, a character constant actual argument can correspond only to a characte~ dummy argument. 13-51 CHAPTEFt 14 BLOCK D}\TA SUBPROGRAMS Block data subprograms provide initial values for variables and elements in named common blocks. array A block data subprogram must st:art with the BLOCK DATA statement. The only valid statements within a block data subprogram are the specification and DATA statemE~nts (COMMON, DIMENSION, EQUIVALENCE, IMPLICIT, PARAMETER, SAVE, type statements, and DATA statements). The last statement of a block data subprogram must be an END statement. You can enter initial values illto more than one labeled in a single subprogram of this type. common block An executable program can contain more than one block data subprogram. 14.1 BLOCK DATA STATEMENT The form of the BLOCK DATA sta":ement is: BLOCK DATA [sub] where: sub is the optional symbolic name of a block data subprogram which the BLOCK DATA statement appears. in The name sub is a global name and must therefore be a unique symbolic name within the executable program. The following is an example of a block data subprogram: BLOCK DATA TEST COMMON /SQUARE/ CIRCLE,RECTAN,PI DATA CIRCLE,RECTAN,PI/1.,2.,3.14159/ END This example initializes the COMMON variables CIRCLE, RECTAN, to 1., 2., and 3.14159 respectively. 14-1 and PI CHAPTER 15 WRITING USER PROGRAMS This chapter is a guide for writing effective programs with FORTRAN. It contains techniques for optimization, interaction with non-FORTRAN programs, and other useful programming hints. 15.1 GENERAL PROGRAMMING CONSIDERATIONS The following paragraphs describe programming considerations you should observe when preparing a FORTRAN program to be compiled by FORTRAN. 15.1.1 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. 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 can only test numbers of up to eight significant digits (REAL precision) and 16 significant digits (DOUBLE precision). NOTE For KL model B systems, if the /GFLOATING compiler switch is specified (see Section 16.1.3 or 16.2.3), double-precision numbers up to 10**307 can be represented. You must also be careful when testing floating-point computations for a result of O. In most cases the anticipated result, that is, 0 will be obtained; however, in some cases the result may be a very small number that approximates O. Such an approximation of 0 will cause tests for equality to 0 to fai1. To increase the accuracy of its compile-time arithmetic, the compiler does all floating point arithmetic in double precision (it converts back to single precision when necessary). For KL model B systems, if the /GFLOATING compiler switch is specified (see Section 16.1.3 or 16.2.3), the compiler does its compile-time arithmetic in G-floating double-precision. If the /DFLOATING compiler switch is specified (the default), the compiler does its compile-time arithmetic in D-floating double-precision. Compile-time arithmetic done in G-floating double-precision may not overflow or underflow as it. might with D-floating double-precision arithmetic. G-floating double-precision has a greater range than D-floating double-precision (see Section 3.4). 15-1 WRITING USER PROGRAMS 15.1.2 Writing FORTRAN Programs for Use on Other Computers If you prepare a program to run on both TOPS-I0 or TOPS-20 and another manufacturer's computer, you should: 1. Avoid using any blue print language extensions in this manual. (All information in blue print represents aspects of FORTRAN that are extensions to the FORTRAN-77 Standard.) 2. Consider the accuracy and size of the numbers that manufacturer's computer is capable of handling. another You can use the /FLAG compiler switch to invoke the compatibility flagger. This feature provides warning messages for language elements that are extensions to the FORTRAN-77 standard or that are incompatible with VAX FORTRAN (see Section 16.6). 15.1.3 Using Floating-Point DO Loops FORTRAN permits you to use noninteger, single- or double- precision numbers as the parameter variables in a DO statement. This lets you generate a wider range of values for the DO loop index variables, which may, in turn, be used inside the loop for computations. WARNING If a noninteger index is used, accumulation of rounding errors may lead to unexpected values for the loop variable. 15.1.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 farmula far the number of times a DO loop is executed is: DO 10 I=Ml,M2,M3 Number of cycles=MAX (INT((M2-Ml+M3)/M3) ,0) The values of the parameters Ml, M2, M3 can be of any type except complex. If the iteration count is less than or equal to zero, the body of the loop is not executed. The index variable retains its assigned value (Ml). (See Section 9.3.) NOTE The interpretation of the iteration count and the index variable described above is different from that of earlier versions of FORTRAN-IO/20. If the /NOF77 compiler switch is specified (see Section 16.1.3 or 16.2.3), and the iteration count is less than or equal to zero, the body of the loop is executed once. In addition, the final value of the index variable of the DO statement is undefined after a normal exit. 15-2 WRITING USER PROGRAMS 15.1.5 Subroutines - Programming Considerations Consider the following items when preparing and executing subroutines: 1. During execution, no check is made to see if the proper number of arguments is passed (unless the /DEBUG:ARGUMENTS compiler switch is specified, see Section 16.3). 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 3rguments are undefined (unless the /DEBUG:ARGUMENTS compiler switch is specified, see Section 16.3) • 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 (unless the /DEBUG:ARGUMENTS compiler switch is specified, see Section 16.3). 4. If an actual argument is a constant and its corresponding dummy argument is set to another value (an illegal usage), all references made to the constant in the calling program may be changed to the new value of the dummy argument. 5. No check is made to see if the arguments passed are of the same type as the dummy arguments (unless the /DEBUG:ARGUMENTS compiler switch is specified, see Section 16.3). NOTE An exception is that a check is always made for G-floating and D-floating type mismatches regardless of the /DEBUG:ARGUMENTS switch being specified. In addition, w~en you pass character data to a subroutine or function that is compiled wi th the /EXTE.'1D switch, the calling program must also be? compiled with the /EXTEND switch. If an actual parameter is a constant and the corresponding dummy is of type real, be sure to include the decimal point in the constant. If t~e dummy is double-precision, be sure to specify the constant with a "D". NOTE You are given no warning if any of the situations described in items 1,2,3,4, or 5 occur (unless the /DEBUG:ARGUMENTS compiler switch is specified, see Section 16,.3). Examples: If a function F has a single dummy arqument of function is called with: F(2) 15-3 type real, and that WRITING USER PROGRAMS F interprets the integer 2 as an unnormalized In this instance, F(A) should be called with: floating-point number. F(2.0) Similarly, if the function Fl(D) is called with: Fl (2.5) and D is double-precision, Fl assumes that its 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.5DO) 15.1.6 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 an overflow condition, and will cause 2. RSI is a very small number, that is, less than 1, the program sequence: 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 (that is, RSl*RLl and RS2*RL2) will produce an interim result that is smaller than either large number (RLI or RL2). However, the compiler may recognize RLl*RL2 as a common sUbexpression (see Section 15.2.1.1) 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=(RSl*RLl)*RL2 B=(RS2*RL2)*RLI computations may be reordered even when selected. 15-4 global optimization is not WRITING USER PROGRAMS 15.1.7 Dimensioning of Dummy Arrays When you specify an array as a dummy argument to a subprogram unit, you must indicate to the compiler that the parameter is an array by dimensioning 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. A dummy array can be dimensioned the following ways: 1. Assumed size 2. Adjustable dimensioned 3. Fixed dimension bound Dimensioning the array with a size of 1 dangerous, practice. The alternative to assumed-size arrays (see Section 7.1.2). is a common, although this practice is to use Example: SUBROUTINE SUBl(A,B) DIMENSION A (l) There are disadvantages to using the above technique because it may prevent the compiler from diagnosing illegal programs, specifically: 1. Reading or writing the array by name DIMENSION ARRAY READ (l) ARRAY (10) 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. Using the array as a format SUBROUTINE SUB2(FMT) DIMENSION FMT(l) READ (l, FMT) Only the first word of the format specification contained FMT is used. 3. in Using the /DEBUG:BOUNDS compilation switch (see Section 16.3), the dimension information used is that which is specified in the array declaration SUBROUTINE SUB3(A) DIMENSION A(l) A(2)=0 The reference to A(2) will cause message to be generated. 15-5 the out-of-bounds warning WRITING USER PROGRAMS 15.2 FORTRAN 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. 15.2.1 Optimization Techniques 15.2.1.1 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. Also, 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 preceding sequence as: be T=B*C A=T+E*F H=A+G-T IF(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. 15-6 WRITING USER PROGRAMS 15.2.1.2 Reduction of Operator Strength - The time required to execute arithmetic operations varies 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 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 The execution time of the loop would be shorter if the time-consuming multiply operation, that is, 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 equivalent to: 10 loop would be replaced by a sequence 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 situation occurs frequently implicitly contain multiplications. in subscript calculations that 15.2.1.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 redefined 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 INumerical analysis considerations severely limit the cases where this is possible. 15-7 number of WRITING USER PROGRAMS the value of the computation 2.0*Q, once calculated on the first iteration, will remain unchanged during the remaining 99 iterations of the loop. Reforming the preceding 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). 15.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.14159 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.14159 X=6.28318*Y thereby eliminating a multiply operation from the object code program. The evaluation of constant expressions at compile time is called "folding"; the replacement of variables with their constant values is called "constant propagation". NOTE For KL model B systems, use of the /GFLOATING compiler switch (see Section 16.1.3 or 16.2.3) may affect compile-time arithmetic. 15-8 WRITING USER PROGRAMS 15.2.1.5 Removal of Inaccessible Code - The optimizer detects and eliminates any code within the source program that cannot be accessed. In general, this will not happ8n since programmers do not normally include such code in their ]Jrograms; however, inaccessible code may appear in a program during the debugging process. The removal of inaccessible code by the o]Jtimizer reduces the size of the object program. A warning message is generated for each inaccessible line removed. 15.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. 15.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 I/O data transfer statements. The formats of these special blocks are described in Chapter 18. These optimizations reduce the size of the program (argument code plus argument block size is reduced) and greatly improve the performanc8 of programs that use implied DO loop I/O statements. 15.2.1.8 Uninitialized Variable Detection - A warning message may be generated when a scalar variable is referenced before it has received a value (only when optimizing). 15.2.1.9 Test Replacement - If the only use of a DO loop index is to reduce operator strength (see Section 15.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: 10 DO 10 1=1,10 K=K+7*I CONTINUE Reduction of operator strength and test replacement together transform this loop into: 10 DO 10 1=7,70,7 K=K+I CONTINUE This situation occurs frequently in execution of these statements, 1=11. 15-9 subscript computation. After WRITING USER PROGRAMS lS.2.2 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: 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 I/O variables. S. Avoid unnecessary use of COMMON and EQUIVALENCE. lS.3 one with the calls to FUNCTION SIDE EFFECTS Unpredictable results can occur if a statement includes different functions that modify the same variables. Consider the following example: COMMON A A=S. P=F(1.)+Q(2.) END FUNCTION F(X) COMMON A A=O. F=X+l END FUNCTION Q(Y) COMMON A Q=A END In the preceding sequence, if P is evaluated by calling F before Q, the value of P will be 2. If P is evaluated by calling Q before F, the value of P will be 7. lS.4 INTERACTING WITH NON-FORTRAN PROGRAMS AND FILES 1S.4.1 Using The Sharable High-Segment FOROTS If your program does not contain a FORTRAN main program module, and you wish to have the sharable FOROTS GETSEGed at run time, you must do the following: 1. Force the loading of the FOROTS initialization routine RESET. by declaring it as an external. 2. Define the symbol FOROT% as a global with a positive, nonzero value before FORLIB.REL is searched. IS-l0 WRITI1~G 3. USER PROGRAMS Initialize FOROTS by the appropriate initialization call: JSP 16, RESET. EXP 0 15.4.2 Calling Sequences The following paragraphs describe the standard procedures for subroutine calls. 1. writing Procedure a. The calling program must load the accumulator (AC) 16 with the addre::;s of the first argument in the argument list. b. The subroutine i ::; then using AC 17. c. The return will be made to the after the PUSHJ 17 instruction. d. The FOROTS trace facility requires the to be: called PUSHJ instruction instruction immediately by a calling sequence XMOVEI 16,AP PUSHJ 17,F where AP is the ?ointer to the argument list and F is the subprogram name. The word preceding the first word of an entry point should have its name in SIXBIT. 2. 15.4.3 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 rl~ad 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 the call to RESET. (See Section 15.4.1). Accumulator Usage The specific functions performed by accumulators (AC) 17,16,0, are: 1. and 1 Pushdown Pointer - AC 17 is always maintained as a pushdown pointer. In sectio~ zero, its right half points to the last location in use on the stack, and its left half contains the negative of the n~mber of words allocated to the unused remaindE~r of the staGk. In non-zero sections, the pushdown pointer contains global address of the last location in use on the stack. 15-11 the WRITING USER PROGRAMS 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 called subprogram. AC 16 cannot point to the ACs or to the stack. 3. Temporary and Value Return Registers - AC a and 1 are used as temporary registers and for returning values. The called subprogram does not need to preserve the contents of AC 0 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 - A subroutine results by modifying arguments. subprogram may pass back A numeric function subprogram always returns the value of the function in AC a (or ACs 0-1 if the value is double precision or complex). A function subprogram may also pass back additional results by modifying the arguments. (See Section 15.4.4 for a description of character functions.) 5. Preserved ACs - FORTRAN function subprograms preserve through 15; subroutine subprograms do not. ACs 2 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 or COBOL. 15.4.4 Argument Lists Since the FORTRAN 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 XMOVEI R,@1(16) The latter operation will work when interfacing with FORTRAN. 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 number of arg entries. Reserved for future DIGITAL development, and must be o. 15-12 WRITING USER PROGRAMS The format of an arg entry is as wo rd) : bit o bits bits bit bits bits 1-8 9-12 13 14-17 18-35 follows (each entry is a single IFIW (Instruction Format Indirect Word) flag, must be 1. Reserved for future DIGITAL development, must be o. Arg type code. Indirect bit if desired. Index field, must be O. Address of the argument. For character functions, the first argument points to the return value, which is a character string descriptor (see Section 15.4.6). The actual arguments to the function start in the second argument entry. The following restrictions shculd be observed: 1. Neither the argument list nor the arguments themselves can be on the stack. 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, that is, the argument count word with a 0 in it and a zero argument word. Example: XMOVEI 16,AP PUSHJ 17,SUB AP: ;SET UP ARG POINTER ;CALI. SUBROUTINE ;RETURN HEHE ;ARGUMENT LIST -3, ,0 IFIW 4,A IFIW 4,B IFIW 4,C ;SUBROUTINE TO SET THIRD ARG TO SUM OF FIRST TWO ARGS SUB: MOVE ADD MOVEM POPJ T,@O 16) T,@l 16) T,@2 16) 17, 15-13 ;GET FIRST ARG ;ADD SECOND ARG ;SET THIRD ARG ;RETURN TO CALLER WRITING USER PROGRAMS 15.4.5 Argument Types Table 15-1: Argument Types and Types Codes Type Code (Octal) Description FORTRAN Use COBOL Use I--------------+-------------+---------,-----.--......j o 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 Unspecified FORTRAN Logical Integer Reserved Real Reserved Octal Label Double real (D-floating) Not applicable Double octal Double real (G-floating) Complex Character Reserved Hollerith Unspecified Not applicable I-word COMP Reserved COMP-l Reserved Reserved Procedure address Not applicable 2-word COMP Not applicable Not applicable 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 compiler makes a local copy of all non array elements and may copy dummy arguments back to the actual arguments. All unused type codes are reserved for future DIGITAL development. 15.4.6 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. Type 2 - Integer and l-word-COMP A 36-bit 2's complement signed binary integer. 15-14 to specify WRITING USER PROGRAMS 4. Type 4 - Real and COMP-l A 36-bit 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 pl-ocedure address The address of the parameter is the address of return label or a subprogram. 7. Type 10 - Double real number represented in Type 11 - 2-word COMP A 2-word (72-bit) word word word word 9. alternate (D-f1oating) A double-precision floating-point D-floating form. (See Section 3.4.) 8. an 1, 1, 2, 2, 2'~; bit 0 bits 1-35 bit 0 bits 1-35 complement signed binary integer. sign high order same as word 1, bit 0 low order Type 12 - Double octal A 72-bit unsigned binary value. 10. Type 13 - Double real (G-floating) (KL model B only) A double-precision floating-point G-floating form. (See Section 3.4.) 11. number represented in Type 14 - Complex A complex number represented as an ordered pair of 36-bit floatin9-point numbers. The first represents the real part, and the second repre:,ents the imag inary part. 12. Type 15 - Character string descriptor The format of the character string descriptor is: word 1: word 2: ILDB-type pointer, that is, aimed at the character preceding the first character of the string EXP character count The character descriptor may not be modified by the called program. The character string itself must consist of a string of contiguous 7-bit ASCII characters. 15-15 WRITING USER PROGRAMS 13. Type 17 - Hollerith A string of contiguous 7-bit ASCII characters left justified on the word boundary of the first word and terminated by a null character in the last word. The FORTRAN compiler emits constants that are padded with spaces to a word boundary, followed by a full-word containing zero. 15.4.7 Interaction with COBOL FORTRAN programs conversely, the subprograms. can call COBOL programs as subprograms, and, COBOL programs can call FORTRAN programs as Note that I/O operations can be performed only in subprograms that are written in the same language as the main program. Also note that APR trap handling will be done in a manner consistent with the language used in the main program. 15.4.7.1 Calling FORTRAN Subprograms from COBOL Programs - COBOL programmers may write subprograms in FORTRAN to use the conveniences and facilities provided by this language. The CbBOL verb ENTER is used to call FORTRAN subroutines. The form of ENTER is as follows: EWfER FORTRAN program name IuSING \lprocedure-name-1\ ~~~~~!i~~r-l I l~!{procedure-2 ~~~~;!i~~~::!J, [ The USING clause 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 (see Table 14-1). NOTE G-floating double-precision does not exist as type in COBOL. a data 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 3n-bit word of the form: 0-8 9-12 13-35 a type address Bits 0-8 are reserved for DIGITAL. 15-16 WRITING USER PROGRAMS Bits 9-12 contain a type code that indicates argument. the USAGE of the Bits 13-35 contain the address of the argument of the first of the argument; the address can be indexed or indirect. word Following is a description of the types generated by COBOL, 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: FORTRAN 'rYPE: 2. For 2-word COMPUTATIONAL items CODE: IN ARGUMENT LIST: ADDRESS: FORTRAN 'rYPE: 3. 11 XWD 440, address that of the high-order argument Not allowed word of the For COMPUTATIONAL-l items CODE: IN ARGUMENT LIST: ADDRESS: FORTRAN TYPE: 4. 2 XWD 100, address that of the argument itself INTEGER 4 XWD 200, address that of the argument itself REAL For DISPLAY-6 and DISPLAY-7 items CODE: IN ARGUMENT LIST: ADDRESS: WORDl: WORD2 : FORTRAN TYPE: 15 XWD 640, address that of a 2-word descriptor for the argument a byte pointer to the identifier or literal bit 0 is 1 if the item is numeric bit 1 is 1 if the item is signed bit 2 is 1 if the item is a figurative constant (including ALL) bit 3 is 1 if the item is a literal bits 4 through 11 are reserved for expansion bit 12 is 1 if the item has a PICTURE with one or more Ps just before the decimal point, that is, 99PPV. bits 13 through 17 are the number of decimal places. If bit 12 is 1, this is the number of Ps. bits 18 through 35 contain the size of the item in bytes. If FORTRAN is called, the string must be DISPLAY-7, nonnumeric, and either a figurative constant or literal. The bits 0-17 of words must be zero. The FORTRAN type is then character. 15-17 WRITING USER PROGRAMS 5. For procedure names (which cannot be used for calls to subprograms) CODE: IN ARGUMENT LIST: ADDRESS: FORTRAN TYPE: COBOL 7 XWD 340, address that of the procedure External subprogram name The return from a subprogram (through POPJ 17,) after the call. is 15.4.7.2 Calling COBOL Subroutines from FORTRAN COBOL subprograms use the CALL statement: to the statement Programs - To call CALL sub (args •.• ) where sub is a COBOL subprogram. 15.4.8 Interaction with BLISS-36 FORTRAN programs can call BLISS-36 routines as subprograms, and, conversely, BLISS-36 programs can call subprograms written in FORTRAN. BLISS routines called by FORTRAN programs must be able to coexist compatibly with FOROTS. For instance, they must use FUNCT. functions (see Section 18.6) for dynamic memory management within the section that FOROTS is in, since FOROTS assumes that it has control of that section. One problem that the BLISS routines can encounter is stack The size of the program stack as set up by FOROTS may be too BLISS routines which have several STACKLOCAL variables. supported way to increase the size of the stack is to use FORLIB that has been assembled with a larger stack. overflow. small for The only a copy of 15.4.8.1 Calling FORTRAN Subprograms From BLISS-36 Programs - To call a FORTRAN subprogram from a BLISS-36 program, the FORTRAN subprogram must be declared an EXTERNAL ROUTINE in any module that contains a call to the subprogram. In addition, if the FORTRAN subprogram is a subroutine, it must be declared with a linkage type of FORTRAN SUB. If the FORTRAN subprogram is a function, then it must be declared-with a linkage of FORTRAN_FUNC. For example: EXTERNAL ROUTINE FOO: BAR: FORTRAN SUB, FORTRAN=FUNC; declares FOO to be the name of a FORTRAN subroutine which will be called in this module, and declares BAR to be the name of a FORTRAN function. After the FORTRAN subprogram has been declared appropriately, it can be called just like any function written in BLISS. 15-18 WRITING USER PROGRAMS 15.4.8.2 Calling BLISS-36 Routines From FORTRAN - A BLISS-36 routine that is to be called from a FORTRAN program must have either the FORTRAN SUB linkage attribute (if the routine is to be used as a subroutTne) or the FORTRAN FUNC linkage attribute (if the routine is to be used as a funct ion) • The programmer that wishes to write a BLISS-36 routine to be called from FORTRAN must be familiar with the calling sequence used by FORTRAN to call subprograms (see Section 15.4.2), FORTRAN argument lists (see Section 15.4.4), and FORTRAN argument descriptors (see Sections 15.4.5 and 15.4.6). This knowledge is necessary because the values of the formal arguments of the BLISS-36 routine are the FORTRAN argument list entries that correspond to actual arguments of the BLISS routine. compiled with In general, the BLISS routines must be ADDRESSING MODE (INDIRECT) , or MACHOP calls must be used to generate any instruction that references formals since all FORTRAN arguments must be accessed through indirect addressing. This must be done indirect bit in because the FORTRAN compiler frequently sets the argument lists (see Section 15.4.4). See the BLISS-36 .~anguage Guid~ for more information. NOTE ADDRESSING_MODE (INDIRECT) can have far reaching effects on your program, which you should understand fully before using. 15.4.9 LINK Overlay Facilities LINK provides several routines that are accessible directly from a FORTRAN program. These routines are presented here briefly, together with the FORTRAN 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. NOTE Overlays are not allowed addressing is used. The following terms are overlay routines. used to when TOPS-20 describe the extended to LINK File spec A character expression consisting 'dev:file.ext[directory] , (TOPS-IO) , 'dev:(directory>file.typ.gen' (TOPS-20) • of or Name A quoted string giving a link name, or an integer constant or variable giving a link number. List of link names A sequence of name items separated by commas. 15-19 parameters WRITING USER PROGRAMS The routines available are: CLROVL Specifies a non-writable overlay. GETOVL(List of link names) Used change to structure in core. INIOVL(File spec) Used to specify the overlay file to be found if the load time specification is to be overridden. LOGOVL(File spec) Used to specify where the log file is to be written. If no arguments are given, the log file is closed. REMOVL(List of link names) Removes the core. specified links from RUNOVL(Name) Loads the specified transfers to that LINK. link and SAOVL Specifies a writable overlay. the For a full description of these routines, refer to the LINK Manual. overlay Reference NOTE The SAVE statement retains the values stored in a variable, array, or common block after execution of a RETURN or END statement in a subprogram. When overlays are used, the SAVE statement must be used to ensure retention of values. When the SAVE statement is used, it is not necessary to specify the LINK switch /OVERLAY:WRITABLE when loading a program (see Section 7.10). 15.4.10 FOROTS and Overlay Memory Management For sharable FOROTS, the FOROTS static data area is several pages located at the top of FOROTS. FOROTS dynamic memory is allocated at runtime below FOROTS and in a downward direction (toward the user's program) . For nonsharable FOROTS (FOROTS loaded from FORLIB), the FOROTS data area is located in the low segment, so that it will be linked with variables used by the user's program. FOROTS dynamic memory is allocated at runtime starting at the page designated by the symbol STARTP in FORPRM.MAC, downward toward the user program. The distributed value for this page number is 577. If the user's program has two segments, FOROTS allocates memory down to the user's high segment, skips over the high segment, and begins allocating memory below the user's high segment toward the user's low segment. For both sharable and nonsharable FOROTS, when FOROTS can no longer allocate memory downward toward the user's low segment, it allocates memory starting at the top of memory downward. When FOROTS can no longer allocate any memory, it reports: ?Memory full and returns to the monitor after attempting to close all files. 15-20 WRITING USER PROGRAMS Figure 15-1 illustrates the run-time memory layout. Page 777 Reservl:!d for SORT, DBMS, and DDT 600 FOROTS FOROTS Static Data 500 FOROl S Dynamic Data -1- - - - - -- -1- - - - - - - Used fl)r Dynamic Character Concatenations User Program o MR-S-3878-85 Figure 15-1: Run-time Memory Layout for Section Zero FOROTS has a separate memory manager specifically designed for use by OVRLAY. This memory managE'r allocates memory at the top of the users's low segment. In general, user programs that use overlays should not use the FUNCT. calls GAD, COR, and RAD. OVRLAY expects to be able to use memory beginning at the top of the user's low segment, allowing for a special FOROTS scratch space allocated by the /SPACE switch. Under certain circumstances, notably when concatenating character expressions whose length is not known until runtime, FOROTS dynamically allocates a special scratch area using the FUNCT. COR function (see Section 18.6). This area is allocated the first time a dynamic concatenation is performed. such The /SPACE switch to LINK determines the maximum size for The default value "dynamic concatenations" if overlays are used. (See the LINK Reference given by LINK for this value is 4000 (octal). Manual.) 15-21 WRITING USER PROGRAMS You can allocate space for dynamic character concatenation ALCCHR subroutine (see Section 13.4.1.1). 15.4.11 using the Extended Addressing Memory Layout (TOPS-20 only) The FORTRAN compiler must determine which psect every word of data or code should reside in. For non-extended addressing compilations, the data and code reside in either the low segment or the high segment. For extended addressing compilations, there are three segments (psects) in which the data and code can be allocated: 1. The code psect corresponds to the non-extended high The default name is .CODE •• segment. 2. The data psect corresponds to the non-extended The default name is .DATA •• low segment. 3. The .LARG. psect is where large data resides. name of this psect cannot be changed.) (Note that the A data item can be placed following ways: in the .LARG. psect by either of the 1. The data item is an array or any character scalar whose size is greater or equal to the value of the /EXTEND:DATA switch (default 10,000 words). (See Section 16.5). 2. The data item is placed in a COMMON group that is in the .LARG. psect. block Table 15-2 describes the various memory allocations for non-extended compilations. 15-22 or EQUIVALENCE extended and WRITING USER PROGRAMS Table 15-2: Memory Allocations for !EXTEND and /NOEXTEND Item /NOEXTEND !EXTEND User subprogram Hiseg Code FORLIB Hiseg .CODE. Argument blocks Hiseg Code Compile-time constant character descriptors Hiseg Code Array dimension information Hiseg Code EFIWS N/A Code Symbol tables (from LINK) Lowseg or Hiseg .DATA. FORMAT statements Lowseg Data Constants Lowseg Data Small arrays and scalars Lowseg Data Large arrays Lowseg .LARG. COMMON variables Lowseg .LARG. Variables EQUIVALENCED to large arrays Lowseg .LARG. PDV N/A .DATA. (by default) (by default) NOTE When the sharable FOROTS is used, LINK loads the /NOEXTEND high-segment into the low-segment. This is done so that the sharable FOROTS can be used as the high-segment (see Section 16.9) 15-23 CHAPTER 16 USING THE FORTRAN COMPILER This chapter explains how to use the FORTRAN compiler. Section 16.1 describes using the FORTRAN-I0 compiler and Section 16.2 describes using the FORTRAN-20 compiler. 16.1 USING THE FORTRAN-IO COMPILER This section describes how use the FORTRAN-I0 compiler. You should be familiar with the TOPS-IO operating system. The TOPS-IO Operating System provides commands that enable you to compile, execute, and debug FORTRAN programs. These commands are known as the COMPILE-Class commands. 16.1.1 TOPS-IO COMPILE-Class Commands You can invoke the FORTRAN-IO compiler by using TOPS-IO COMPILE-Class commands. These commands enable you to compile, execute, and debug a program by giving the commands at TOPS-IO command level. The COMPILE-Class commands are: COMPILE LOAD EXECUTE DEBUG Example: .EXECUTE ROTOR. FOR The compiler switches OPTIMIZE, CREF, and DEBUG may be specified directly in COMPILE-Class commands and may be used globally or locally. (See Section 16.1. 3 for a description of FORTRAN-IO switches.) Example: .EXECUTE/CREF Pl.FOR,P2.FOR/DEBUG The other compiler swi tches specific source file. mu~~t be passed 16-1 in parentheses for each USING THE FORTRAN COMPILER Example: .EXECUTE Pl.FOR(INCLUDE) Refer to the TOPS-IO Operating System Commands information about the COMPILE-Class commands. 16.1.2 Manual for further RUNNING THE FORTRAN-IO COMPILER On TOPS-lO, the command to run the FORTRAN compiler directly is: .R FORTRA The compiler responds with an asterisk (*), and is then ready to accept a command string. The form of the FORTRAN compiler command string is: object filespec, listing filespec=source filespec(s) You are given the following options: 1. File specifications consist of an optional device name, a one to six character filename, an optional one to three character file extension, and an optional directory path specification. The path may include SFDs. 2. You may specify more than one source file in the compilation command string. These files will be logically concatenated by the compiler and treated as one source file. 3. More than one program unit source file. 4. A program unit may consist of more than one source file. 5. If no object file is specified, no relocatable binary file is generated. 6. If no listing file is specified, no listing is generated. 7. If no extension is given, the defaults are the following the respective files: may be contained in a single for .LST (listing) .REL (relocatable binary) .FOR (source) .CRF (cross reference) if the specified (see Section 16.1.3) 16.1.3 /CROSSREF switch is TOPS-IO Compiler Command Switches anywhere in the Switches to the FORTRAN-I0 compiler are accepted command string. They are totally position and file independent. Table 16-1 lists the switches. 16-2 USING THE FORTRAN COMPILER Table 16-1: FORTRAN-IO Compiler Switches Switch Meaning De fa ul ts /CROSSREF Generates a file with extension .CRF that can be input to the CREF program. OFF /DEBUG Includes debugging information in your program (see Section 16.3). NONE /DFLOATING Indicates that double-precision numbers are stored in D-floating format. (See Sectio:1 3.4.) ON /EXPAND Includes the octal-formatted version of the object file in the listing. OFF /F66 The FOHTRAN-66 standard rules apply for DO loops and EXTERNAL statements. (Same function as the /NOF77 switch.) OFF /F77 The FOHTRAN-77 stan<lard rules apply for DO loops and EXTERNAL statements. ON /FLAG Invokes the compatibility Section 16.6). OFF /GFLOATING Indicates that double-precision numbers are stored in G-floating format .. (See Section 3.4.) OFF CompilE~s OFF /INCLUDE flagger (see a D in card column 1 as space. /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 :.isting file. OFF /NOFLAG Indicates that no compatibility flagging will be done (seE! Section 16.6) • ON /NOF77 The FORTRAN-66 standard rules apply for DO loops and EXTERNAL statements. (Same function as the /F6(1 swi tch.) OFF /NOERRORS Does not print error messages on the terminal. OFF /NOWARN Suppresses warning nlessages (see Section 16.4). NONE /OPTIMIZE Performs global optjmization. OFF /SYNTAX Performs syntax check only. OFF 16-3 USING THE FORTRAN COMPILER 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: .R FORTRA *OFILE,LFILE=SFILE/MAC,S2FILE The /MAC switch will cause the S2FILE to appear in LFILE.LST. ~ACRO code generated for SFILE All switches, used or implied, are printed at the top of each page. 16-4 and listing USING THE FORTRAN COMPILER 16.2 USING THE FORTRAN-20 COMPILER This section describes how to use the FORTRAN-20 compiler. You should be familiar with the TOPS-20 Operating System. The TOPS-20 Operating System provides commands that ~nable you to compile, execute, and debug FORTRAN program. These commands are known as the COMPILE-Class commands. 16.2.1 TOPS-20 COMPILE-Class Commands The TOPS-20 COMPILE-Class commands enable you to initiate compilation, execution, and debugging of FORTRAN programs from TOPS-20 command level. The TOPS-20 COMPILE-Class commands are: COMPILE LOAD EXECUTE DEBUG Example: @EXECUTE ROTOR. FOR The following FORTRAN compiler switches (see Section specified directly in a COMPILI:-Class command: 16.2.3) can be /ABORT /BINARY /CROSS-REFERENCE /DEBUG /LIST /MACHINE-CODE: /NOWARNINGS /OPTIMIZE /WARNINGS NOTE When you specify the svllitches /BINARY, /DEBUG, /LIST, and !NOWARNINGS directly in a COMPI LE-Class comrland, the swi tches cannot have arguments as they can when running the compiler. All other switches must b(~ specified by using as shown in the following example: Language-switches, @COMPILE TEST.FOR/OPT/LANG:"/NOWARNINGS" Refer to the TOPS-20 Commands Reference Manual information about the COM1)ILE-Class commands. for NOTE You cannot use long TOPS-20 COMPILE-Class commands. 16-5 filenames with the more USING THE FORTRAN COMPILER 16.2.2 RUNNING THE FORTRAN-20 COMPILER On TOPS-20, the command to run the FORTRAN compiler directly is: @FORTRA The compiler responds with the following prompt: FORTRAN> and is then ready to accept a command string. You can use the question mark to list the commands beginning with a specific letter or letters. Type the letter or letters followed by a question mark. (Refer to the TOPS-20 User's Guide.) You can type commands to the system by using either full input, recognition input, abbreviated input, or a combination of these methods. To give a command using full input, type the complete command name, arguments, or switches (if any), using a space to separate the fields. To give a command using recognition input, type a portion of the switch or filename and press the ESC key. You must type enough of the switch or filename to make it unique. Continue typing and pressing the ESC key until the switch or filename is complete. Recognition input requires less typing than full input, so you are less likely to make a mistake. You can use recognition in typing switches, switches arguments, and file specifications. When typing file specifications, you can also use CTRL/F to complete the rest of a partial file specification. To give a command using abbreviated input, type only enough of the switch or filename to distinguish one switch or filename from another. (Refer to the TOPS-20 User's Guide.) You should enter a command string in one of the following forms: 1. [COMPILE]<source-file-spec> [switches] If no switches are specified, the compiler produces a .REL file, with the same filename as the source file. The user must use a /LISTING switch to get a listing file (see Section 16.2.3 for a description of FORTRAN-20 compiler switches). COMPILE is optional if the command begins with a switch or begins with a file specification that cannot be confused with the words EXIT, HELP, TAKE, or COMPILE. 16-6 USING THE FORTRAN COMPILER 2. [COMPI LE] < so urce- f i 1 e--s pec>+<source- f i 1 e-s pec>+ ••• [swi tches] The source files are ':reated as if they were together prior to the beginning of compilation. concatenated If no switches are specified, the compiler produces a .REL file, with the same filename as the last source file in the list. The user must Ilse a /LISTING switch to get a listing (see Section 16.2.3 for a description of FORTRAN-20 compiler switches). COMPILE is optional if the command begins with a switch or begins with a file specification that cannot be confused wi th the words EXI~{" HELP, TAKE, or COMPILE. 3. TAKE <file-spec> [/ECIlO] The compiler reads the file specified as the command input stream. The TAKE command is legal within 'take' files. The ma x i mum n est i n g de p t his 1 0 't a k e ' f i 1 e s • The on can the 4. /ECHO switch optionally causes commands to be displayed TTY: as they ar~ executed. The optional /NOECHO switch be used on a nestl~d takE~ command to cancel the affect of /ECHO switch while processing that nested command file. RUN <file-spec> [/OFF:3ET:<integer>] This command runs another program (for example, LINK). It causes an exit from the FORTRAN compiler and the start of execution of the prog~am indicated by the file specification, with the additional option of starting that program at an OFFSET relative to thl~ normal starting address. 5. HELP This command prints il1formation on the user's terminal how to use the FORTRAN compiler. 6. about EXIT This command exits from FORTRA. You are given the following options: 1. Filename specificatio:1s consist of the following: An optional device name (the default device is DSK:) An optional dir~ctory name An up to 39 alphanumeric character filename An optional up to 39 alphanumeric character file type An optional g~neration version of the Eile number that identifies An optional file attribute to specify characteristics of a file specification (Refer to the TOPS-20 User's Guide) 16-7 the distinctive USING THE FORTRAN COMPILER NOTE LINK is restricted to 3-character extensions. 6-character filenames and 2. You may specify more than one source file in the compilation command string. These files will be concatenated by the compiler and treated as one source file. The name of the last source file is used as the default name of the object and listing files. If the last source file does not have a name (such as, TTY:), FORTRAN-OUTPUT is used as the default filename. 3. More than one program unit may source file. 4. A program unit may consist of more than one file. 5. If no /LISTING switch is specified (see Section 16.2.3), listing is generated. 6. If no extension is given, the defaults are the following for the respective files: .LST (listing) be contained in a single no if the /CROSSREF switch is not specified .CRF (cross reference) if the specified (see Section 16.2.3) /CROSSREF switch is .REL (relocatable binary) .FOR (source) 16.2.3 TOPS-20 Compiler Commands Switches Switches to the FORTRAN-20 compiler are accepted anywhere in the command string. They are totally position and file independent. Table 16-2 lists the switches. 16-8 USING THE FORTRAN COMPILER Table 16-2: FORTRAN-20 Compiler Switches Switch Meaning Defaul ts /ABORT Causes the compiler to exit at the end of a compilation that contains errors. OFF /BINARY[:relfile] Indicates that a relocatable binary file is qenerated. You can optionally specify the file specification. ON /CROSS-REFERENCE Generates a file with extension .CRF that can be input to the CREF proqram. OFF /DEBUG [keys: ] Includes debugging information in your proqram (see Section 16.3). NONE /DFLOATING Indicates that double-precision numbers are stored in D-floating format. (See SE~ction 3.4.) ON /ECHO-OPTION Echo switches selected from the SWITCH. Irn filE~. OFF /EXPAND Includes the octal-formatted version of the object file in the listing. OFF /EXTEND[keys:] Indicates extended addressing. Programs can have up to 30 sections of code and data (see Sec t ion :~ 6 • 5) • OFF /F66 The FORTHAN-66 standard rules apply for DO loops and EXTERNAL statements. (Same function as the /NOF77 switch.) OFF /F77 The FORTHAN-77 standard rules apply for DO loops and EXTERNAL statements. ON /FLAG-NON-STANDARD Invokes t.he compatibility flagger (see Section 16.6). OFF /GFLOATING IndicateE; that double-precision numbers are stored in G-floating format. fSee Section 3.4.) OFF /INCLUDE Compiles a D in card column 1 as space. OFF /LISTING[:listfile] Indicates a list file will be generated. You can optionally specify the file specification. OFF 16-9 USING THE FORTRAN COMPILER Table 16-2: FORTRAN-20 Compiler Switches (Cont.) Switch Meaning Defaults ILNMAP Produces a line number/octal location map in the listing only if IMACHINE-CODE was not specified. OFF IMACHINE-CODE Adds the mnemonic translation of the object code to the listing file. This command will cause a default ILISTING. OFF INOBINARY Indicates that no relocatable binary file is generated. OFF INOF77 The FORTRAN-66 standard rules apply for DO loops and EXTERNAL statements. (Same function as the IF66 switch.) OFF INOFLAG-NON-STANDARD Indicates that no compatibility flagging will be done (see Section 16.6) • ON INOERRORS Does not print error messages on the terminal. OFF INOEXTEND Indicates extended addressing is not in effect (see Section 16.5). ON INOWARN Suppresses warning messages (see Section 16.4). NONE IOPTIMIZE Performs global optimization. OFF IOPTION [:option] Only read lines from the SWITCH.INI file that start with FORTRA:option. OFF ISYNTAX Performs syntax check only. OFF ~---- ____________________L -________________________________________- L__._ _ _ _ _ _ ~ Each switch must be preceded by a slash (I). 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. NOTE When using switches in control files, you encouraged to type the full name of the switch. 16-10 are USING TEE FORTRAN COMPILER Example: @FORTRA FORTRAN)SFILE+S2FILE/MAC/LIST:LFILE The /MAC switch will cause the MACRO code generated for SFILE and S2FILE to appear in LFILE.LST. An relocatable binary file will be created with the name S2FILE.REL. All switches, used or implied, are printed at the top of each page. 16.3 listing THE /DEBUG SWITCH The /DEBUG switch tells FORTRAN to compile a series of debugging features into your program. Several of these features are specifically designed to be used with the FORTRAN debugging program (FORDDT). Refer to Chapter 17 for more information. By using the DEBUG switch arguments listed in Table 16-3, you can include specific debugging features. The form of the /DEBUG switch is: /DEBUG:arg or /DEBUG: (argl,arg2, ••• ) 16-11 USING THE FORTRAN COMPILER Table 16-3: Arguments to /DEBUG Switch Arguments Meaning ~----------------+-----------------------------------------------------------~ DIMENSIONS Includes dimension information in FORDDT. .REL file for TRACE Generates references to FOR DDT required for its trace features (automatically activates LABELS). LABELS Generates a label for each statement of the form <line-number>L. (This option can be used without FOR DDT .) INDEX Forces DO LOOP indexes to be stored at the beginning of each iteration rather than held in a register for the duration of the loop. In addition, this switch forces all function values to be stored in memory prior to return from the function. If this switch is specified, you can set a FOR DDT pause on the RETURN statement (see Section 13.4.4) and then examine the value to be returned. BOUNDS Generates the bounds checking code for all array references and substring 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.) ARGUMENTS Generates type checking information at load time for actual argument types and associated dummy argument types. Type violations will produce non-fatal load-time error messages. This switch also performs type checking at compile-time for statement functions. NONE Do not include any debug features. ALL Enable all debugging aids. ' " -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _--L-_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _----J Options available with the /DEBUG arguments 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 that is: /DEBUG:BOU/DEBUG:LAB or a list of modifiers /DEBUG: (BOU, LAB, ..• ) 16-12 series of /DEBUG modified switch switches, USING TilE FORTRAN COMPILER 4. Exclusion of features - If you wish all but one or modifiers and do not wish to list them all, you can use prefix "NO" before the swi.tch you wish to exclude. exclusion of one or more features implicitly includes all others, that is, /DEBUG:NOBOU is the same /DEBUG:(DIM,TRA,LAB,:ND,ARG) • If you include more than one statement on first statement will receive a label reference (/DEBUG:TRACE). two the The the as a single line, only the (/DEBUG:LABELS) or FORDDT NO'I'E If a source file contains line sequence numbers that occur more than once in the same subprogram, the /DEBUG option cannot be used. Also, the /DEBUG option and the /OPTIMIZE option cannot be used at the same time. The following formulas may be used to determine the increases in program size that will occur as at 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. 'I'RACE One instruction per executable statement. LABELS No increase. INDEX One instruction per inner loop plus one instruction for some of the references to the index of the loop. Also one instruction per subprogram. BOUNDS For each array, DIMENSIONS. the formula is the same as For each reference to an array element, 5+N words additional words are generated, 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. For each reference to a substring, add 5 words. ARGUMENTS No increa~;e. If the /DEBUG:ARGUMENTS switch argument is specified, type checking is performed at LINK time for calls to external programs and at compile time for calls to statement functions. Non-fatal error messages are issued at LINK time for the following cases: 1. If the number of arguments in the called subprogram calling program unit are not equal. 2. If the length of an array or character scalar actual argument is less than that of the corresponding dummy argument. (This is checked only if the length of the actual is known at compile time.) 16-13 and the USING THE FORTRAN COMPILER 3. If the associations 'of actual argument data types with dummy argument data types are other than those indicated as legal in Table 16-4. 4. routine name is If a non-routine name is passed where a expected, or a routine name is passed where a non-routine name is expected. Non-fatal error messages are issued at compile time for the cases (only for statement functions): following 1. routine name is If a non-routine name is passed where a expected, or a routine name is passed where a non-routine name is expected. 2. If the length of the actual character expression being passed to a statement function is less than that of the corresponding character expression dummy argument. Table 16-4: Legal Dummy and Actual Argument Associations Actual Argullwnt Type Alternate Heturn Label Iloublp Logical Intcger Heal D-tloating (i-tloating Complex Character (1<'1'11 IlolI('rith Oetal Alternate Return III Co X Label ;., Eo< ~ Logical E ~ Integer ;., Heal :\ X III X .\ .( E E ;:s Q \ X D-tloating G-floating X \" X Complex :'O.~ ,- X X Character X mdicates legal associations. All others will cause a warning to be issued if DEBUG:ARGUMENTS is specified. 16.4 THE /NOWARN SWITCH The /NOWARN switch is used to suppress compiler warning messages. If this switch is used with no arguments, all warning messages are suppressed. The /NOWARN switch may also be used with arguments as shown in Table 16-5. 16-14 US ING THE Table 16-5: FOR~rRAN COMPI LER Arguments to /No\'lARN Switch Arguments Meaning ALL Suppress all warning messages. NONE Do not suppress warning messages. xxx Where xxx i~; the three character error mnemonic for the el~ror mE~ssage to be suppressed. This is example the three letters that follow %FTN, for %FTNABD. For example, /NOWARN:LID will suppress all warnings of characters. an identifier A list of arguments is also allowed. having more than six For example, /NOWARN: (LI D, DIM) would suppress both LID and DIM types of warning messages. (See Appendix C for a list of all compiler error mnemonics.) 16.5 THE /EXTEND SWITCH (TOP!;-20 ONLY) Support for extended addressing is almost completely transparent; a program compiled with the /EXTEND switch will use extended addressing without requiring! changes to the FOHTRAN source program. When /EXTEND is specified, an-ays and COMMON blocks can extend across multiple sections. Executable code can also reside in multiple sections, with the restriction that a single subprogram must not cross a section boundary. The /EXTEND switch can be spE~cified without arguments to use the default extended address space layout. This is suitable for most applications in which the executable code fits within a single section, but which may employ data structures that require more than a section of memory. When such an application is compiled /EXTEND without further arguments, a default memory layout is used that depends on the default size settings for arrays and strings: 16-15 USING THE FORTRAN COMPILER Table 16-6: /EXTEND Default Memory Layout Section Pages Contents 1 0-477 Executable code Argument blocks Literals Non-COMMON scalars Non-COMMON arrays smaller than 10,000 words Non-COMMON strings smaller than 10,000 words 1 SOO-S77 FOROTS 1 600-777 Reserved - - ~ _. _. 2-31 0-777 COMMON blocks Arrays larger than 10,000 words Strings larger than 10,000 words -. Additional arguments to /EXTEND (COMMON:, DATA:, PSECT:, and CODE), in conjunction with the /SET switch to LINK, can be supplied to override these defaults and direct specific placement of COMMON blocks, non-COMMON arrays and scalars, and executable code. For example, a decimal argument can be specified for the DATA: keyword, which overrides the 10,000 word default minimum size for large arrays and character scalars. /EXTEND:COMMON can be used to direct specific named COMMON blocks to non-default sections of extended memory. (Section 16.S.3 describes the /EXTEND arguments.) 16.S.1 /EXTEND and Applications with Large Arrays The simplest usage of extended addressing is for applications in which the executable code fits in one section. These applications may have very large arrays or common blocks. In many cases, these applications can be compiled with the /EXTEND switch with no arguments, using the default memory layout in Table 16-6. In some cases, you may need to use the DATA or COMMON arguments to /EXTEND to redirect the placement of variables in areas when default placements cannot be used. Specifying a smaller /EXTEND:DATA size may be necessary if the total size of non-COMMON scalars and arrays causes them to overlap FOROTS pages. If such overlap occurs, program execution will terminate with the error messages: "?Can't get FOROIO.EXE" and "?Can't overlay existing pages" A smaller DATA size will force these data structures into a non-FOROTS section. 16-16 USING TEE FORTRAN COMPILER 16.5.2 /EXTEND and Applications with Large Executable Code A more complex use of extended addressing is one where the application's executable code is larger than a section. In order to build an application that has more than one section of executable code, you have to specify which program units will be linked together in each section. When /EXTEND is specified, the extended code will be in three PSECTS, one analogous to the present hiseg, one analogous to the present lowseg, and one containing the large variables. If the user does not specify the extended addressing switch, FORTRAN will generate a TWOSEG REL file as it always has. The three PSECTS generated under /EXTEND are: 1. The "large data area" psect (.LARG.) has a maximum size of 30 sections. It will consist of user-specified COMMON blocks, arrays and character scalars that are larger than a user-specified size (or default). There is no restriction on the size of an individual array or COMMON block, beyond the restriction on the total size of the large data area. 2. The "small data area" psect (default name .DATA.) of a program consists of Dser-specified COMMON blocks, and scalars and arrays that are smaller than a user-specified size (or default). If FORDDT is used, it will reside in the • DATA. psec t. 3. The "executable code and sharable data area" psect (default name .CODE.) of a program consists of all executable code, argument blocks anc literals. Library functions and subroutines used by the program are placed in the .CODE. psect. This does not include space used by SORT, which occupies its own section. For each "executable code area" (code psect) there will be a corresponding "small data area" (data psect). The combined size of these two areas must not exceed 256K words. The default psect names .DATA. and .CODE. can be changed at compile time by the /EXTEND:PSECT command switch (see Section 16.5.3). 16.5.2.1 /EXTEND PSECT Placement - The three psects will according to the table below: be set Psect De fa ul t Origin Attributes data 1001000 code 1300000 • LARG. 2000000 Sing IE section, Non-zero section, Concatenated, Writable Single section, Non-zero section, Concatenated, Read-only Non-ZEro section, Concatenated, Writable ------- 16-17 up USING THE FORTRAN COMPILER You can alter the default psect origins when loading programs by giving a /SET switch to LINK (see the LINK Reference Manual). This may be necessary if a program has' too much code or local data to fit in the regions allocated for them by the default psect origins. This would cause the psects to overlap, and would be indicated by a LINK warning message (%LNKPOV). Altering the defaults is also useful if the user wants to reserve one or more sections for some purpose (such as telling the monitor where dynamic libraries should be loaded). The first page (locations 000-777) of any section that contains code is reserved for use by FORDDT. The LINK /SET switch should not specify a psect origin less than 1000 for any such section. 16.5.2.2 Building Large-Code Applications - When compiling large-code applications, the following considerations apply: 1. The code and small data psects for a single program unit must always reside together in the same section, since the PC will not advance across section boundaries, and the small data area is assumed to be in the same section. 2. keyword. This You will need to use the /EXTEND:CODE specifies that the object code emitted by the compiler assumes that all subprograms that it calls may be in a separate section. 3. You must also use the PSECT argument to /EXTEND to specify the psect names for code and small data. If you wish to link the program units in several different compilations (source files) togeth~r in the same section, you should use the same psect names for those program units. At link-time, you must specify the starting address for using the /SET switch, according to the following rules: 1. The code and small data psects for a program linked in the same section with each other. 2. If a section contains any executable code, section is reserved for FORDDT and FOROTS. 16-18 each unit page 0 psect must be of that USING THE FORTRAN COMPILER 3. You must always allo~ate space for the .CODE. and .DATA. psects, since FORLIB routines will be linked in these psects. 4. Pages 500-577 of the section that contains .CODE. and are reserved for FOROTS. 5. Pages 600-777 are reserved for FOROTS I/O buffers and DDT. 6. You must always allocate space for the .LARG. psect. 16.5.3 .DATA. Arguments to /EXTEND By using the /EXTEND switch al'guments listed in Table include specific extended addlessing features. The form of the /EXTEND switch is: /EXTEND:arg or /EXTEND: (argl,arg2, ••• ) 16-19 16-7, you can USING THE FORTRAN COMPILER Table 16-7: Arguments to /EXTEND Switch Arguments Meaning CODE Specifies that the object code produced by the compiler has to assume that any subprogram that it calls could be in a separate section. NOCODE is the default. COMMON [ : name] or COMMON: (name, ••• ) Without a common block name specified, causes all common blocks that have not already been allocated by /EXTEND: [NO] COMMON to be allocated in the .LARG. psect. This is the default. Individual common blocks can be placed explicitly in .LARG. by putting their names in a list after COMMON:. When you explicitly place an individual common block in .LARG., any common blocks that have not already been allocated by /EXTEND: [NO] COMMON are placed in the small data psect. DATA[:decimal number] Specifies a decimal argument that is the minimum si ze (in words) for non-common arrays and character scalars, which will be allocated to the .LARG. psect. The default is 10,000. NOCODE Allows the compiler to assume that all of the code will be in the same section. A program compiled with the NOCODE argument cannot call any subprograms compiled with the CODE argument. This is the default. NOCOMMON [:name] or NOCOMMON:(name, •.• ) Without a common block name specified, causes all common blocks to be allocated in the data psect. Individual common blocks can be placed explicitly in the data psect by putting their names in a list after COMMON:. COMMON is the default. NODATA Specifies that all non-common variables will reside in .DATA. This is equivalent to DATA:I073741823, which excludes all variables from .LARG. PSECT[: [data psect] Allows users to set the code and data psect [:[code psect]]] names explicitly (the large data psect is always called .LARG.) If PSECT is specified with one argument, that argument becomes the name of the small data area psect. Any second argument becomes the name of the code psect. This allows separate program units to be put in separate psects, then the psect can be placed in different sections with the /SET switch at LINK time (see the LINK Reference Manual). NOTE When using the PSECT argument, the small data psect and code psect for any given program unit must be loaded into the same memory section. 16-20 USING THE FORTRAN COMPILER 16.5.4 Linking ~rith TWOSEG RE~L Files If a main program unit compiled with /EXTEND is linked with subprogram units (FORTRAN or not) that were compiled for non-extended use, then LINK will automatically place the LOWSEG of non-extended units in the .DATA. psect, and the HISEG of such units into the .CODE. psect. A program compiled with /EXTEND can call a subprogram that is not compiled with /EXTEND; however, it is illegal for a subprogram that is not compiled with /EXTEND to call a subprogram that is. Programs that were compiled by old versions of FORTRAN-IO/20 (prior to Version 7) will not work if loaded in a non-zero section. Most MACRO routines written for non-extended use will require conversion to run in non-zero sections. Data structures accessed with IS-bit address fi.elds, indexed and indirect words, stack pointers and some monitor calls may need modification to perform correctly in extended sections. See the TOPS-20 Monitor Call User's Guide for more information concerning extend(~d MACHO progra~ 16.6 THE /FLAG (/FLAG-NON-STANDARD) SWITCH The /Ii'LAG switch invokes the compatibility flagger. NO"fE For TOPS-20 systems, the full switch names are /FLAG-NON-STANDARD and /NOFLAG-NON-STANDARD; however /FLAG and /NOFLAG work. This feature provides warning messages for language elements used that are the following: • Extensions to the ANSI FORTRAN-77 standard • Features not found in VAX FORTRAN • Features that could ,::ause logically used on the VAX FORTRAN system different results when No'rE VAX FORTHAN is used 0:1 the VAX/VMS operating system. This allows the flagging of a~y element that could cause conversion problems for programs written on the TOPS-IO/20 system that might be compiled and executed on a VAX/VI~S system or an ANSI-compatible system. This includes problems that could occur at object time, as well as compilation incompatibilities. 16-21 USING THE FORTRAN COMPILER By using the FLAG switch arguments specify which features to flag. listed in Table 16-8, you can The form of the /FLAG switch is: / F LA G [ : a r g ] or / FLAG [ : (a rg 1 ,a rg 2, ••• ) ] Table 16-8: Arguments to /FLAG Switch Arguments Meaning ALL Gives warning messages for language elements incompatible with both FORTRAN-77 and VAX FORTRAN. ANSI Gives warning messages whenev~r a language element is an extension to the FORTRAN-77 standard. NOANSI Does not flag FORTRAN-77 extensions. NONE Does not flag. NOVMS Does not flag VAX incompatibilities. VMS Gives warning messages whenever a language element is incompatible with VAX FORTRAN. If no /FLAG switch is specified, no flagging is done. If no arguments are given with the /FLAG switch, then flagging is done for both FORTRAN-77 and VAX incompatibilities. The /NOFLAG switch indicates that no flagging will be done. 16.7 READING A FORTRAN COMPILER LISTING When you request a listing from the FORTRAN compiler, it may contain the following information, depending on the switches used at compilation time: 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 war.ning messages generated during the compilation. If the input file is line-sequenced, the number from the file is used. If code is added by means of the INCLUDE statement, all INCLUDEd lines will have an asterisk (*) appended to their line-sequence number. 2. A summary of the names and relative program locations (in octal) of scalars and arrays (including unreferenced character scalars and arrays) in the source program plus compiler-generated variables. 16-22 USING THE FORTRAN COMPILER 3. All COMMON blocks and the relative locations the variables in each COMMON block. (in 4. A listing of all equivalenced variables or arrays and their relative locations. Note that all equivalenced variables that are also in COM~ON are listed only as being in COMMON. 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., .BLOCK, 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: (both octal) of user-defined LINE: This column contains the internal sequence number of the line corresponding to the mnemonic code. It appears on the first line of the code sequence associated witt. 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 "pH appended. Labels generated by thE compiler are followed by the letter "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 use the /LNMAP switch and do 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 the edit.or SOS on TOPS-IO (or the editor EDIT on TOPS-20) • NOTE A single FOR1'RAN line can produce mUltiple machine inst.ructions. In this case the line number map Ijsts only the first location. 16-23 USING THE FORTRAN COMPILER 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. 16.7.1 detected or warning messages issued Compiler-Generated Variables In certain situations the compiler generates 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 The function of these variables can be determined by the first of the variable name as described below: Letter letter Function of Variable A Register save area. D Compile-time constant character descriptor F Arithmetic statement function formal parameters. I Result of a DO LOOP initial value expression parameter of an adjustable dimensioned array. o Result of a computation. Q Temporary storage for expression values. R Result of reduced operator strength expression. S Result of the DO LOOP step size expression of iteration count for a loop. common sUbexpression or or constant computed For example: .SOOOI You may find these variables on the listing under SCALARS and ARRAYS. The following examples show listings where all of these pointed out. 16-24 features are USING TEE FORTRAN COMPILER , Example 1: Program Name MAiN. Compiler Version Source Name TI~l.FoR FORTRAN V.l0(1601l)/F77/~ 5-AUG-82 10:26 MACRO code listing included 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 100 C 10 IMPLICIT INTEGER (A-Z) DIMENSION A(100,200) COMMON I~ ( 100 ,200) oPEN(UNIT=22,FILE='TIM.oAT') SUM1=0 SUM2=0 00 1 00 ~,= 1 ,200 00100]=11100 Kl=I*J IF (K1 .Ll. 500 .0R. Kl ,GT. 1500) K1=0 A(I,J)=K1 K2=I+J IF (K2 .EQ. 100 .0R. K2 .EQ. 200 .0R. K2 .EQ. 300) K2=K2+1 B(I,J)=K2 SUM1=SUM1+Kl SUM2=SUM2+K2 CONTINUE WRITE(22 110)SUM1 ,SUM2 FORMAT ( , SUM 1 = " 19, ' END SUM2= ' 119) COMMON BLOCKS /. CoMM. / (+47040 ) ___ --Relative addres:;es of each. variable - - - - - - - - - - . . . . , B +0 *K 1 *SUM2 47045 ~oIEXpLICIT *J 2 47046 "EFINITIONL "z" " J 47047 L .SOOOl *SUMl 47043 47050 .SOOOO 47044 t Relative address of each character data descriptor CHARACTER DATA NAME 'TIM1.DAT' U*U NO EXPLICIT DEFINITION] OESeR I PToR ADDRESS START OF DATA ADDR ( POS I TI ON) .HSCHD+O 4~054~ L LENGTH 8 - # of characters Relative address of first character of string Character position of first character of string 16-25 USING THE FORTRAN COMPILER Internal sequence number on first instruction for this source Ii ne ! LINE Octal displacement of instruction ~OC lABEL GENERATED CODE >(MOI.JE I PUSHJ SETZB MOI.JEM MOI.JE HlREM 0,0 16,RESET. 0,0 16,2M 17,OPEN. 2,SUM1 2,SUM2 2,[777470000001] 2 , • SOOOO HRRZM 2,J MOI.JE 2.[777634000001] MOI.JE I MULI MOI.JEM CAll CAllE JRST JRST 3,J 3,0 (2) 3 ,1\ 1 3,764 3,2734 0,7M 0,6M SETZB 4 .1\1 MOI.JE I IMUl ADDI MOI.JE MOI.JEM MOI.JE ADDI MOI.JEM MOI.JE CAIE CAIN JRST Compiler generated label 3.144 3,J 3,0 (2) 4 .1\1 4.A-145(3) 3,J 3.0 (2) 3.1\2 5,1\2 5 .144 5.310 0.8M CAIN 5.454 ADS 3.1\2 MOI.JE I IMUL ADDI MOI.JE MDI.JEM ADDM ADDM 3.144 3.J 3.0 (2) 5,1\2 5.B-145(3) 4,SUM1 5.SUM2 Program label 2,5M 2, I 2,J o , . SOOOO 0,4M 16tl1M 17,DUT. 16 tl2M 17 , I DlST • 16 tl M 17,E>(IT. JFCl JSP 0 2 4 3 4 5 6 7 10 11 3M: 8 12 4M: 9 13 5M: 5 6 7 10 14 15 16 17 20 21 7M: 10 11 23 6M: . 24 25 26 27 30 31 32 33 34 35 36 37 10M: 13 40 8M: 14 41 8M: 15 16 17 42 43 44 45 46 47 50 12 13 18 21 51 52 53 54 55 56 57 60 61 6'"' lOOP: • AOBJN HRRZM ADS AOSGE JRST :-:MDI.JE I PUSHJ :-:MOI.JE I PUSHJ :-:MDI.JE I PUSHJ 16-26 USING THE FORTRAN COMPILER ARGUMnn BLOCKS : _ - - - Function, subnutine, and FOROTS argument blocks 63 64 65 66 67 70 71 72 73 74 75 76 0, ,0 0, ,0 777776, ,0 436000 , ,26 1 M: 2M: 4066tW, , • H~;CHD+O 777776, ,0 401000,,26 4023tW, dOll 777775 , ,0 401100, ,SUrll 401100, ,SUr12 4000, ,0 11 M : 12M: FORMAT STATEMENTS (11\' lOW SEGMENT) : 20 6 47056 47057 (' SUM1= ',IB,' lOP: SUM2= 'dB) No err 0 r s de t e c ted J .....o---------Summary of errors MAIN. Example 2: MAIN. 00001 00002 00003 00004 00005 00006 00007 00008 OOOOB 00010 00011 00012 00013 00014 00015 00016 00017 00018 0001B 00020 00021 TIM1.FoR 100 C 10 FORTRAN I,J. 10 ( 16(4) IF77 I l 5-AUG-82 10:28 IMPLICIT INTEGER (A-Z) DIMENSION A(100,200) COMMON 5(100,200) oPEN(UNIT=22 ,FIlE= 'TIM .DAT') SUM1=0 SUM2=0 DO 100 _'=1,200 DO 100 1=1,100 Kl=I*J IF (Kl .IT. 500 .0R. Kl GT. 1500) Kl=O A(I,J)=Kl K2=I+J IF (K2 .EO. 100 .0R. K2 EO. 200 .0R. K2 .EO. 3(0) K2=K2+1 B(I.J)=K2 SUM1=SUM1+Kl SUM2=SUM2+K2 CONTINUE WRITE(22 dO)SUMl ,SUM2 FoRMAT(' SUM1= 'dB,' END SUM2=' dB) COMMON BLOCKS I.CoMM./(+47040) B +0 SCALAR!:; AND ARRAYS "*" NO E>~PLICIT CEFINITION - "'X," NOT REFERENCED 2 2 47043 47050 .SOOOO 47044 Requested with ILNMAP LI NE NUMBER 10CTAl loCATI ON MAP_.--- : 0 .SOOOl *SUMl 3 47047 47046 47045 5 3 6 7 8 B ------:---------------------------- .. -----------------------------------------00000 00010 00020 MAIN. 30 23 61 [ No errors detected 16 33 3 41 5 46 6 47 7 50 12 13 55 Line #11 starts at octal offset 23 (from the prevous example, note that line 11 uses locations 23 through 27, but only the first location is shown here). 16-2:7 USING THE FORTRAN COMPILER Example 3: MAIN. 00001 00002 00003 00004 00005 00006 00007 00008 00008 00010 00011 00012 00013 00014 00015 00016 00017 00018 00018 00020 00021 FORTRAN t,! .10 (1604) IF77/0PT 1M TIM1.FOR 5-AUG-82 10:30 IMPLICIT INTEGER (A-Z) DIMENSION A(100,200) COMMON B(100,200) OPEN(UNIT=22,FILE='TIM1.DAT') SUM1=0 SUM2=0 DO 100 J= 1 ,200 DO 100 1=1,100 K1=I*J IF (K1 .LT. 500 .OR. K1 .GT. 15(0) K1=0 100 K2=I+J IF (K2 .EO. 100 .OR. K2 .EO. 200 .OR. K2 .EO. 3(0) K2=K2+1 B(Id)=K2 SUM1=SUM1+K1 SUM2=SUM2+K2 CONTINUE C 10 WRITE(22 dO)SUM1,SUM2 FORMAT(' SUM1= ' d8,' END SUM2= ' d8) COMMON BLOCK S I.COMM./(+47040) B +0 SCALARS AND ARRAYS "*" NO E:<PLICIT DEFINITION - "'X," NOT REFERENCED] ,.------Optimizer created variables - - - - - - - - , *K1 • SOOO 1 470t!5 *K2 47052 .R0001 .SOOOl *SUM1 2 47046 47053 .ROJoo 3 *SUM2 47047 CHARACTER DATA [ "*" NO D(PLICIT DEFINITION NAME DESCR I PTOR ADDRESS START OF DATA AD DR ( POS IT I ON) 'TIM1.DAT' .HSCHD+O 47060(1) 16-28 1 *J *1 5 4 A 47050 .00001 47051 LENGTH 8 USING THE FORTRAN COMPILER LINE LOC LABEL 0 GENERATED (ODE JFCL JSP 2 LI 6 * 7 * 3 LI 5 6 7 10 11 12 13 8 ill * 15 9 10 16 17 20 21 )<MOI.JE I PUSH~J 10 8M: 11 25 7M: 12 26 27 30 31 32 33 11 M: 13 3L1 10M: ill 35 9M: 15 16 36 37 L10 L11 * * * * * *19 * 21 L12 L13 LIL1 L15 L16 L17 50 51 52 53 5L1 55 56 57 60 61 62 7,1 1 ~ t • SOOOO MOI.JE MOI.JE 2 t [77763L100000 1 ] Asterisks indicate opt.imizer generated statements 1~t310 6t7 6M: 22 *17 SETZB MOI.JEI MOI.JEM MOI.JN I MOI.JE I MOI.JEM 5M: 23 2L1 13 OtO 1 '3 tRESET • o to li3tLlM 17tOPEN. 1 ,) t 11 1~ ,1 LIL1 1.~ t • ROOO 1 MOI.IE I ADD MOI.IE CAlL CAlLE JRST JRST L1t(l(2) L1t.ROOOl MOI.JE I 5tO MOI.JH1 MOI.JE ADDI CAIE CAIN JRST 5tA-1L15(LI) 3 t7 3 to (2) 3 t 1 LIL1 3 t31 0 o t 10M CAIN 3tLl5L1 ADDI 3,1 MOI.JEM ADD ADD ADD 3tB-1L15(4) 11 t 5 1) t 3 6 t7 AOBJN HRRZM MOI.JE I ADDM 2t6M 1 ~ ,1 LIL1 1 ~ ,1L1L1 1 ~ t • ROOO 1 ADDI AOSGE JRST MOI.IEM MOI.IEM MOI.IEM MOI.JEM MOI.IEM )-<MOt.JE I PUSHJ )-<MOI.IE I PUSHJ 7,1 Ot.SOOOO Ot5M 7 tJ I I tSUMl 1)tSUM2 5 tK1 3tK2 13 t 12M 17tOUT. 1,3,13M 17tIDLST. )<MOI.JE I PUSH,J 13t3M 17 t D<IT. 5t6 5t76L1 5t273L1 Ot8M Ot7M 100 P : 1 M: 2M: 16-29 USING THE FORTRAN COMPILER ARGUMENT BLOCKS: 63 64 65 66 67 70 71 72 73 74 75 76 0, ,0 0,,0 3M: 4M: 12M: 13M: 777776, ,0 436000, ,26 406640, ,.HSCHD+O 777776, ,0 401000 , ,26 402340,,10P 777775, ,0 401100"SUM1 401100"SUM2 4000, ,0 FORMAT STATEMENTS (I N LOW SEGMENT) : 20 MAIN. 47062 47063 lOP: [ No err a r s 6 (' SUM1= ',18,' SUM2= ',18) oj e te c t e oj 16-30 USING THE FORTRAN COMPILER Example 4: MAIN. 00001 00002 00003 00004 00005 00008 00007 00008 00008 00010 00011 00012 00013 00014 00015 00018 00017 00018 00018 00020 00021 TIM1.FoR 100 C 10 COMMON BLOCKS FORTRAN I,J.1Cl(253C )/F77/M/E>:T 24-APR-85 18:27 IMPLICIT INTEGER (A-Z) DIMENSICN A( 100 ,2(0) COMMON B( 100 ,200) oPEN(UNIT=22,FILE='TIM1.DAT') SUM1=0 SUM2=0 DO 100 J= 1 ,200 001001=1,100 K 1 =I*J IF (Kl .LT. 500 .0R. Kl .GT. 15(0) Kl=O A(I,J)=kl K2=I+J IF (K2 .EO. 100 .0R. K2 .E:). 200 .(JR. K2 .EO. 300) K2=K2+1 B<I,J)=k2 SUM1=SUl"ll+Kl SUM2 = SUI"12+K 2 CONTINUE WRITE (2:'::: dO)SUMl ,SUM2 FORMAT ( , SUM 1 = ' d ~~ , ' END SUM2= 'd8) [ " I " STORED IN • LARG. I. CoMM. / (+47040 ! ) +0 tL._________ Large com mon block B SCALARS AND ARRAYS "*" NO E>: PLI C IT [JEF I N IT I ON - "'X," NOT REFERENCED II ! II l,.l A R I A B L EST 0 r~ E 0 IN. LA R G t ] • *K .SOOOl *1 *J 2 .SOOOO 4 *K2 7 3 8 ] Large variable !A *SUM2 *SUMl 0 5 10 CHARACT!::R DATA [ "*" NO E><PLICIT DEFINITION - "!" I,JARIABLE STORED IN .LARG. DESCR 1 PTOR ADDRESS START OF DATA LENGTH NAME ADDR ( PoS IT I ON) 'TIM1.DAT' .HSCH[)+O LINE LABEL LoC 5 8 7 ><Mol,JE I 12 4M: 8 13 5M: 10 0,0 18,RESET. 0,0 i8,2M PUSHJ SETZB Mol,JEM Mol)E HLREM 17,oPEN. 2,SUMl 2,SUM2 2,[777470000001] 2 , • SOOOO HRRZM 2d Mol,JE 2,[777834000001] Mol)E I MULI Mol,JEM CAlL CAlLE JRST JRST 3d 3,0 (2) 3 ,K 1 3,784 3,27:::4 0,7M 0,8M SETZB 4 ,K 1 3M: 8 10 GENERATED COOL JFCL JSP 0 2 3 4 5 8 7 10 11 14 ( 1 ) 14 15 18 17 20 21 7M: 16-31 8 ] USING THE FORTRAN COMPILER 11 23 6M: 24 25 26 27 30 31 32 33 34 35 36 37 10M: 13 40 8M: 14 41 8M: 15 16 17 42 43 44 45 46 47 50 12 13 18 21 MoVEI IMUL ADDI MOVE Mol,JEM Mol,JE AoDI Mol.'EM Mol.'E CAIE CAIN JRST 3.t44 3d 3,0 (2) 4,Kl 4 ,@[ .EFIW A-145(3)] 3,J CAIN 5,454 ADS 3,K2 Mol,JE I IMUL ADDI Mol.'E Mol.'EM ADDM AD OM 3,144 3,J 3,0 (2) 5,K2 5 ,@[ .EFIW B-145(3)] 4,SUMl 5,SUM2 3,(H2) 3,K2 5,K2 5,144 5,310 0,8M lOOP: AoBJN 2,5M HRRZM 2,1 ADS 2,J AoSGE O,.SOOOO JRST (l,4M ){Mol,JEI16.tlM PUSHJ 17,oUT. XMol.'EI16,12M PUSHJ 17,IOLST. ){MOI.'E I 16 t1 M 17,E){IT. PUSHJ 51 52 53 54 55 56 57 60 61 62 ARGUMENT BLOCKS: 63 64 65 66 67 70 71 72 73 74 75 76 0, ,0 1 M: 2M: 11M: 12M: 0,,0 777776 , ,0 436100,,[000000000026] 1I06GlIO, , • HSCHD+O 777776, ,0 1I01000, ,26 1I02340, ,lOP 777775, ,0 401100, ,SUMI 401100, ,SUM2 1I000, ,0 FORMAT STATEMENTS (I N LOW SEGMENT) : 20 MAIN. 17 20 6 lOP: ( I SUM 1 = I tI 8, I SUM2= [ No errors detected] 00001 00002 00003 16-32 I tI8) USING THE FORTRAN COMPILER NOTE Note that in the scalars and arrays list, 'NO EXPLICIT DEFINITION' indicates that the variable was never explicitly defined, as in a TYPE or DIMENSION statement. Also, 'NOT REFERENCED' indicates that the variable was declared, but never used, and therefore was never allocated any storage in the program. Character variables that are declared, but not referenced, appear under the scalars and arrays section of the listing. No storage is allocated for either the character descriptor or the character data. 16.8 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. When pertinent and possible, the 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. Example: TYPE DAY. FOR 01000 01100 01200 01300 01400 01500 100 01600 C 01700 200 01800 01900 1=10 IMPLICIT INTEGER (X) J=I**4 Kl X=I+J+Kl CONTNUE TYPE 200,X FORMAT(lX,I8) END COMPILE DAY.FOR FORTRAN: DAY IMPLICI,]' INTEGER (X) 01100 IMPL]CIT statement out of order %FTNSOD LINE:OI100 01300 Kl ?FTNNRC LINE:01300 Statement not recognized 100 CONTNUE 01500 ?FTNMSP LINE:01500 Statement name misspelled 01600 ? ?FTNICL LINE:01600 Illegal character C in label field ?FTNFTL If errors appear in output to reference MAIN. 3 fatal errors and 1 warning are detected after the initial pass of the compiler, they the list file after the end of the source listing. They are your terminal without the statement in error, but they may its internal sequence number. 16-33 USING THE FORTRAN COMPILER 16.8.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 may 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, and no relocatable binary file will be generated. 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 indicates a fatal message indicates a warning message is the FORTRAN mnemonic is the 3-letter mnemonic for the error message is the optional line number where error occurred is the explanation of error 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 /NOWARN switch will suppress warning messages on both the user terminal and in the listing. Specific warnings can be suppressed by using options to the /NOWARN switch (see Section 16.4). 16.8.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 name name name 1 fatal error and no warnings 2 fatal errors and no warnings no fatal errors and 1 warning no fatal errors and 2 warnings or 2. When no messages were issued name [No errors detected] where name is the program or subprogram name. Appendix C complete list of fatal errors and warning messages. 16-34 contains a USING THE FORTRAN COMPILER 16.9 CREATING A SHARABLE HIGH SEGMENT FOR A FORTRAN PROGRAM For non-extended addressing programs, the FORTRAN compiler always generates two segment code for a program unit. However, by default, the linking loader loads all FORTRAN code into the low segment to allow the sharable run-time system to be bound to the program at run-time rather than at load-time. This default action of the loader can be overridden by using the LINK switch /OTS:NONSHAR when loading the program. If this switch is given, the linking loader loads the impure code (the data areas) in the low segment, loads the pure code (the machine instructions) in the high segment, and binds a private copy of the run-time system to the program at load-time. A program loaded with the /OTS:NONSHAR switch can be saved in order to produce an executable file with a sharable high segment using the TOPS-IO SSAVE command or the TOPS-20 EXEC SAVE command. (The LINK switches /SSAVE (TOPS-lO) or /SAVE (TOPS-20) can also be used to produce the sharable executable file.) This is an advantage if a large application program is to be run by several users simultaneously. The code unique to the program and the copy of the FORTRAN run-time system that is private to the program is shared between all the program's users. The possible benefits gained by the users of the application program sharing the high segment of their program containing both user and FOROTS code must be weighed against the loss of not sharing the common copy of FOROTS as all other users. (See the LINK Reference Manual.) 16-35 CHAPTER 17 USING THE FORTRAN INTERACTIVE DEBUGGER (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 chapter. Table 17-1 lists all the commands available to the user of FORDDT. Table 17-1: FORDDT Commands Command Purpose Control Commands a CONTINUE Continues execution breakFoint. DDT Enters DDT. GOTO Transfers control to some program statement within the open program unit. NEXT Traces execution of the program. START Begins execution of the FORTRAN program. STOP Terminates the monitor mode. after program and FOR DDT returns to Data Access Commands ACCEPT Modifies variables or FORMAT statements. TYPE Displays variables. CHARACTER Defines dimensions of character arrays for FORDDT references. (This command is unnecessary if /DEBUG is specified at compile time. See Table 16-3.) 17-1 Declarative Commands USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) Table 17-1: FORDDT Commands (Cont., ~------------------------~---------------------------------------------------- Command Purpose ~------------------------~-----------------------------------------------,------ DIMENSION Defines dimensions of real and integer arrays for FORDDT references. (This command is unnecessary if /DEBUG is specified at compile time. See Table 16-3.) DOUBLE Defines dimensions of double-precision and complex arrays for FORDDT references. (This command is unnecessary if /DEBUG is specified at compile time. See Table 16-3.) GROUP Defines indirect lists for TYPE statements. MODE Specifies format of typeout. OPEN Accesses program unit symbol table. PAUSE Sets FORDDT breakpoints. PAUSE ON ERROR Sets FORDDT breakpoints (for errors such as arithmetic overflows). REMOVE Clears FORDDT breakpoints. REMOVE ON ERROR Clears PAUSE ON ERROR breakpoints. Other Commands LOCATE Lists program unit names in which symbol is defined. STRACE Displays routine program status. WHAT Displays current DIMENSION, GROUP, FORDDT breakpoint information. traceback of a given current and ~------------------------~---------------------------------------------------- The FORDDT commands are described in detail in Section 17.5. 17.1 INPUT FORMAT FORDDT commands consist 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 is required following the command name. Comments may be appended to command lines by preceding the comment with an exclamation point (!). 17.1.1 Variables and Arrays FORDDT allows you to access and modify the data in your program using standard FORTRAN symbolic names. Variables are specified simply by name. For example: name 17-2 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) where: name is a variable name. E~lernents Array are specified in the following formats: name n am e ( s 1 , ••• s n) j' where: name is the name of the array (sl, ••. ,sn) are the sub:5cripts of a particular array. The subscripts mllst be integer constants or variables. You may reference an entire ar~ay simply by typing the array name (without subscripts). You may specify a range of array elements by typing the first and last element in the chosen range, separated by a dash (-). The following examples show and arrays to FORDDT: thl~ various ways of specifying variables ALPHA ALPHA(7) ALPHA(PI) ALPHA(2)-ALPHA(5) 17.1.2 Constant Conventions FORDDT accepts optionally signed numeric data in the standard input formats: FORTRAN 1. INTEGER - A string of decimal digits. 2. REAL - A string of decimal digits optionally including a decimal point. Standard engineering and double-precision exponent formats are ~lso accepted. 3. OCTAL - }I.,. string of octal d:igits double quote ("). 4. COMPLEX - An ordered pair of integer or real separated by a comma and enclosed in parentheses. 5. LOGICAL - A Boolean argument, either .TRUE. 6. CHARACTER - A string of printable ASCII by apostrophes. 7. HOLLERITH A stri~g of alphanumeric and/or special characters delimited by any alphanumeric or special character, excluding the space character, which does not occur with the strin'J itself. Such as, # 12AB#, where # is the delimiting character. 17-3 optionally preceded by a constants or .FALSE. characters enclosed USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) 17.1.3 Statement Labels and Source Line Numbers FORTRAN statement labels are input and output by straightforward numeric reference, such as 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. 17.2 PAUSE #3 !This causes a pause at source line number 3. PAUSE 3 !This causes a pause at the statement labeled 3. FORDDT AND THE FORTRAN /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 /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 to compile extra information for debugging. (See Chapter 16 for more information.) These features are: 1. /DEBUG:DIMENSIONS, which generates dimension information in the .REL file for all arrays dimensioned in the subprogram. The dimension information is automatically 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 FOR DDT by using the DIMENSION command. 2. /DEBUG:LABELS, which generates 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 also generates 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 <format-label>F. If they are generated, you can display and modify FORMAT statements by means of 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 generates 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 is placed on a single input line, only the first statement has a FORDDT reference and line-number label associated with it. This also applies to the :LABELS switch. 4. /DEBUG:INDEX, which forces 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. 17-4 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) In addition, this switch forces all function values to be stored in memory prior to return from the function. If this switch is specified, you can set a FORDDT pause on the RETURN statement (see Section 13.4.4) and then examine the value to be returned. 17.3 5. /DEBUG:BOUNDS, which generates the bounds checking code for all arralY references. Bounds violations produce run-time e r ro r messag es. No te tha t the techn ique 0 f spec i fyi ng dimensions of 1 fOl" subroutine arrays causes bounds check errors. (You can use this option without FORDDT.) 6~ /DEBUG:ARGUMENTS, which performs type checking at load time for actual argument types and associated dummy argument types. Type violations produce non-fatal, load-time error messages. This swj,tch also performs type checking at compile-time for statement functions. LOADING AND STARTING FORDDT 1. On TOPS-10, the simplest method of debugging with FORDDT is: .DEBUG filespec{DEBUG) On TOPS-20, the corre~;ponding command is: @DEBUG filespec /DEBUG On both systems, FORDDT responds with: STARTING FORTRAN DDT Program name: When FOR DDT prompts you for a program name, type the same name specified in th~ PROGRAM statement of the program being debugged. If the PROGRAM sta temen t i s not used in the program being debugged, FORDDT uses MAIN., and will not prompt for a program name. FORDDT next prints its command prompt: » The angle brackets indicate that FORDDT is ready to receive a command. 2. If you are on TOPS-20, you can type a question mark to prompt to get a list of all FORDDT commands, as follows: »? One ACCEPT GOTO OPEN TYPE of the following: CHARACTER CONTINUE GROUP HELP REMOVE PAUSE WHAT DDT LOCATE START Also on 'I'OPS-20, you can use· the ESCape key of FORDD'I' commands. For example: »CON<ESC>TINUE 17-5 the DIMENSION DOUBLE MODE NEXT STOP STRACE for recognition USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) On both systems, you need only type the of a specific FOR DDT command. 3. unique abbreviation program and FOR DDT You may wish to load your compiled directly with the linking loader. (Loading with LINK is The accomplished implicitly in the DEBUG command string.) command sequence is as follows: On TOPS-la, to start LINK, type: .R LINK On TOPS-20, type: @LINK On both systems, when LINK prompts you with an asterisk, can type a command string in any of the following forms: *filespec /DEB/G (loads DDT) *filespec /DEB:{FORDDT}/G {FORTRA} (loads FORDDT) *filespec /DEB: (DDT,{FORDDT})/G {FORTRA} (loads DDT and FORDDT) *filespec /DEB: ({FORDDT} ,DDT)/G {FORTRA} (loads FORDDT and DDT) you In the last two command forms shown, the first debugging program specified (FORDDT or DDT) in the command string is the one you communicate with after the LINK command string is executed. See Section 17.9 for addressing programs. 17.4 information on loading extended 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 through FOR DDT 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 Section 6.4.1), FORDDT asks for the defined program name. After you enter the program name, FORDDT opens the appropriate symbol table. At this point, symbol tables in programs other than the main program can be opened by using the OPEN command. 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. 17-6 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) 17.5 FORDDT COMMANDS This section gives a detailed description of all commands The commands are given in alphabetical order: ACCEPT in FORDDT. Allows you to change the contents of a FORTRAN variable, array, array element, array element range, or FORMAT statement. The command format is: ACCEPT namE'[/mode] value where: name is the variable, array, array element, range, or FORMAT statement modified. eleme~t array to be mode is the format of the data value to be entered. The mode keyword must be preceded by a slash (/) and immediately follows the name. Intervening blanks are not allowed. (Note that /mode does not apply to FORMAT modification.) value is the new value to be assigned. The format of the input value must correspond to the specified mode. DATA LOCATION MODIFICATION Data Modes The following data modes are accepted: Mode A C D F I 0 L R S X Meaning Example ASCII (left-justified) CHARACTEF( DOUBLE-PF:EC IS ION REAL INTEGER OCTAL LOGICAL RASCII (right-justified) SYMBOLIC COMPLEX /FOO/ 'ABC' 123.4567890 123.45678 1234567890 7654321 • TRUE. or .FALSE • \BAR\ PS I ( 2,4) (1.25,-78.E+9) If not specifie6, the default mode is REAL (F). 1. Two-Word Va]ues For the data modes (R), and SYMBOLIC modifier on the indicates that the interpreted as two 17-7 ASCII (A), OCTAL (0), RASCII (S), FORDDT will accept a "/BIG" mode switch. This modifier variable and the value are to be words long. USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) Example: ACCEPT VAR/RASCII/BIG '1234567890' assumes that VAR is two words long and given 10-character literal into it. stores the The /BIG modifier can also be used to display more than the first 256 characters of long character strings. 2. Character Variables A character variable can be initialized by using an ACCEPT command of the following form: ACCEPT VAR/C 'string' Note that length fo the variable is that which is specified in the source program. If the string is longer than the variable, the rightmost characters are truncated. If the string is shorter than the variable, it is stored left-justified and padded on the right with blanks. 3. 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 are set to the given value. Example: ACCEPT ARRAY/F 1.0 or ACCEPT ARRAY(5)-ARRAY{10)/F 1.0 Note that this applies only ASCII and RASCII. to modes other than For character arrays, if the value has fewer characters than the length of the array element, the rightmost character positions of the element are initialized with spaces. If the value has more characters than the length of the array element, the value is truncated to the right. 4. 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, the value field is expected to contain a long literal string. ACCEPT stores the string linearly into the array or array range. If the array is not filled, the remainder of the array or range is filled with zeroes. If the literal is too long, the remaining characters are ignored. 17-8 USING ~rHE FORTRAN INTERAC~rIVE DEBUGGER (FORDDT) Example: ACCEPT ARRAY/ASCII 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 5. FORMAT Stat(~ment Modification When the name field of an ACCEPT contains a label, FORDDT expt~cts this label to be a FORMAT statement label and that the value field contains a new format specification. Example: ACCEPT 10 (lHO,FIO.2,3(I2» The new specification cannot be longer than the space originally allocated to the FORMAT by the compiler. 'rhe 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 restal~ted (re-initializing FOROTS). CHARACTER character array. The Defines the dimensions of a result of this command is the same as for the DIMENSION the array so dimensioned is command except that understood by FORDDT to be a character array. The command fo rma t .~ s : CHARACTER arrayname ([Ll:]Ul[,[L2:]U2, ••. ]) NOTE This declal-ator cannot be used to specify element length. The length specified in the user progran will be used. CONTINUE Allows the progl-am 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, is assumed to be 0 n e • If a val u e i s pro v ide d, i t can be a n urn e ric constant or proqram variable, but it is treated as an integer. When the value n is specified, the program continues execution until the nth occurrence of this pause. For exarlple, CONTINUE 2() continues execution until the 20th occurrence of pause, or until a different pause is encountered. . DDT the Transfers control of the program to DDT, the standard system debugging program. Any files currently opened by FOROTS are unaffected, and a return to FORDDT is possible so that program execution may be resumed. 17-9 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) %FDDT is the global symbol used to FORDDT. The command format is: return control to %FDDT<ESC)G Your program will be in the same condition as before unless you have modified your core image with DDT. DIMENSION Sets, displays, or removes 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 allows you to redimension an array to have a larger scope than that of the source program. If this is done, a warning is given. NOTE The DIMENSION command cannot be used to declare double-precision, complex, or character arrays (see the CHARACTER and DOUBLE commands) • The command format is: DIMENSION name ([Ll:]Ul[,[L2:]U2, .•• ]) where: name is the name of the array ([Ll:]Ul .•. ) specifies the bounds of the array, where L is the lower bound and U is the upper bound. The default value of L is 1. The bounds must be integer constants or variables. For example: DIMENSION ALPHA(7,5:6,10) FORDDT remembers the dimensions of the array until they are redefined or removed. The command: DIMENSION gives a full list of all for all arrays. the user-defined dimensions DIMENSION ALPHA displays the current information for only. the array ALPHA DIMENSION ALPHA/REMOVE removes any user-defined array ALPHA. 17-10 array information for the USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) DOUBLE Defines the dimensions of a double-precision or complex 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 elements. The command format . 1" c· • ~) DOUBLE arrayname ([Ll:]Ul[,[L2:]U2, ••• ]) 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 source line number provided that the IDEBUG:LABELS switch has been used or the contents of a symbol previously ASSIGNed during the program execution has been used. Note that the program must be STARTed before this command can be used, and also note that a GOTO is not allowed after the <CTRL/C>, REENTER sequence (see Section 17.6). The command format .. • 1" C" ~ GOTO n GROUP SE'ts up a str ing 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 el iminates the neE!d to retype the same 1 ist of variables each time you wish to examine the same group. Refer to the ~'YPE command for the proper format of the list. The command format is: GROUP [n list] where: n is the group number 1-8 list is a list of group numbers preceded by a slash (I) and/or variable names to be typed when you give the command: TYPE In, where n is the group number. The validity of the list is not checked. GROUP with no arguments causes FOR DDT to type out the current contents of all the grroups. GROUP n types out requested. thE! contents of the particular Note that one group may refer to another. Fa r exampl e : GROUP 2 VAR2,VAH3 GROUP 3 I ~'. ,/2 17-11 group USING THE FORTRAN INTERACTIVE DEBUGGER (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, array, label, line number, or FORMAT statement number. MODE Defines the display format for succeeding FORDDT TYPE commands. You need type only the first character of the mode to identify it to FOR DDT because all characters after the first are ignored. The modes are: Mode C F D X I o A R L Meaning CHARACTER REAL DOUBLE-PRECISION COMPLEX INTEGER OCTAL ASCII (left-justified) RASCII (right-justified) LOGICAL Unless the MODE command is given, the mode is the REAL (F) format. default typeout The command format is: MODE list where list separated changed by one mode order: C, contains one or more of the mode identifiers by commas. The current setting can be issuing another MODE command. If more than is given, the values are typed out in the F, D, X, I, 0, A, R, L. A typical command string might be: MODE A,I,OCTAL NEXT Allows you to cause FOR DDT to trace source lines, statement labels, and entry point names during execution of your program. This command only provides trace facilities if the program is compiled with the FORTRAN /DEBUG switch. If this switch is not used, the NEXT command acts as a CONTINUE command. The command format is: NEXT [n] [/sw] where: n is a program variable or integer numeric value sw is one of the following switches /S= statement label /L= source line /E= entry point 17-12 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) The default starting value of n is 1, statement trace. The default switch is /L. a single The command NEXT 20/L traces the execution of the next 20 source line numbers or until another pause is encountered. Note that if no argument argument given is used. is specified, the last For example: NEXT /E changes 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 prograrr so that the variables are 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. arguments reopens the main program. PAUSE OPEN with no Allows you to place a FORDDT breakpoint at a statement number, source line number, or subroutine entry point. Up to ten breakpoints may be set at anyone time. When a breakpoint is encountered, execution is suspended at that point and control is returned to FORDDT. The symbol table of that subprogram is also automatically opened. The command formats are: PAUSE PAUSE PAUSE PAUSE PAUSE PAUSE PAUSE P P p p P P AFTER n IF condition TYPING /g AFTER n TYPING /g IF condition TYPING /g where: P n g is the point where the breakpoint inserted is an integer constant, variable, array element is a group number PAUSE 100 17-13 is or USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) sets a breakpoint at statement label 100, causes execution to be suspended, and causes FORDDT to be entered on reaching 100 in the program. PAUSE #245 AFTER MAX(5) causes a break to occur at source line number 245 after encountering this point the number of times specified by MAX(5). Note that AFTER can not be abbreviated. PAUSE DELTA IF LIMIT(3,1) .GT.2.5E-3 causes a FORDDT break to occur if the variable LIMIT(3,1) is greater than the value 2.5E-3. The IF can not be abbreviated, and the following FORTRAN logical connectives are allowed: .GT., .GE., .LT., .LE., .EQ., .NE. Double-precision comparisons and arithmetic operations are not allowed. However, comparisons can be made between variables, constants, and logical constants (such as .TRUE. and .FALSE.). PAUSE 505 TYPING /5 sets a FORDDT breakpoint at label 505, and the variables in group 5 are displayed. The TYPING specification can not be abbreviated. PAUSE #24 AFTER 16 TYPING /3 causes a break at source line number 24 after 16 times through; however, the contents of group 3 are displayed every time. 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. Whe~ Note that pause requests remain after a (CTRL/C) REENTER sequence, a START command, or a (CTRL/C) START sequence. PAUSE ON ERROR Causes the program to enter FORDDT whenever an error occurs (such as an arithmetic overflow). It has the same command format as the PAUSE command. REMOVE Removes the previously command format is: set FORDDT from the breakpoints. The REMOVE [p] Fo r exampl e, REMOVE L#123 removes a breakpoint number 123. REMOVE ALPHA 17-14 program source line USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) removes a ALPHA. breakpoint from the subroutine entry to your FOR DDT REMOVE with no arguments removes all breakpoints, and, in this case, no abbreviation of REMOVE is allowed. REMOVE ON ERROR Removes a PAUSE ON ERROR breakpoint. It has the same command format as the REMOVE command. START Starts your program at the normal FORTRAN main entry point. lhe command format is: program START STOP Terminates the program, closes all files opened by FOROTS, and causes an exit to the monitor. The usual command format is: STOP STOP IRETURN allows a return to devices or closing issued. STRACE monitor mode without releasing files so that a CONTINUE can be Displays a subprogram level traceback of the state of the program. The command format is: current STRACE TYPE Displays FORTRAN defined variables, arrays, or array elements on YOlr terminal. The command format is: TYPE list where list may be one or more variables or array references anc/or group numbers. These specifications must be separated by commas, and group numbers must be preceded by a slash (I). The command with no arguments uses the last argument list submitted to FORDDT. An array elemert range example: can also be specified. For TYPE PI(5)-PI(13) displays the values from PI(5) to PI(13) inclusive. If an unsubscripted array name is specified, the entire array is typed. There are several methods of choosing the typeout in conjunction with the MODE command: 1. If you do not specify real. 2. You can specify a format through the described jn this chapter. 17-15 a format, the form of default is MODE command USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) 3. You can change the format(s) previously designated by the MODE command by including print modifiers in the TYPE or GROUP string. The print modifiers are: A B C D F I L o R X 4. ASCII(left-justified) LONG CHARACTER DOUBLE-PRECISION REAL INTEGER LOGICAL OCTAL RASCII(right-justified) COMPLEX (C) , the in mode CHARACTER If you type a variable is equal to the length number of characters printed declared in the FORTRAN source prog ram, up to a max imum The IB switch can be used to of 256 characters. override the 256 character max imum. The B switch may be used in conjunction with the A, 0, and R switches. This modifier indicates that the variable is to be interpreted as two words long. The B switch can also be used with the C switch to display more than the first 256 characters of long character strings. The B switch can not be used alone. 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 II K,L/O,M,N/A,/2 the typeout mode is integer specified. Therefore, K, M are integer integer L is OCTAL N is ASCII WHAT until another mode is the default mode for group 2 is Displays on your terminal the name of the currently open program unit, any currently active breakpoints, any group specifications, and any user-set array dimensions. The command format is: WHAT 17.6 ENVIRONMENT CONTROL If a program enters an infinite loop, you can recover by typing a <CTRL/C> (twice) REENTER sequence. This action causes FORDDT to simulate a pause at the point of reentry and allows you to control your run-away program. 17-16 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) Most commands can be used once the program has been reentered; howevE!r, 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 (CTRL/C) REENTER sequence will not destroy the program integrity. The program must be returned to a stable state bE'fore 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 is used, a NEXT 1. command can be issued to restore program integrity. 17.7 FORTRAN /OPTIMIZE SWITCH You should never attempt to m;e 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. 17.8 CALLING FORDDT FORDDT can be called directly appropriate statement is: from a user FORTRAN program. The CALL FORDDT where no argument is required. FORDDT must be loaded and initialized before a CALL to FORDDT is made. This is done by starting the program in debug mode prior to the first call (see Section 17.3, item 1). All FORDDT commands are allowed. A CONTINUE will resume normal execution of thE~ user program (similar ":0 a RETURN from a subroutine). Since FORDDT is defined as a global symbol, users should be careful if they decide to use FORDDT as a program, subroutine, or function name. 17.9 FORDDT AND FORTRAN-2a EXTENDED ADDRESSING FORDDT VIa has been modified to be able to run in any section and access data and code in all sl~ctions. The user interface to FOR DDT is the same regardless of whether or not a program uses extended addressing. FORDDT VIa is section independent. The same FORDDT.REL will either section a or a non-zerl) section. work in If a program is loaded with the /DEBUG:FORDDT option, LINK loads FORDDT.REL with the prograln. FORDDT.REL is a single-segment module (it has only low segment code); therefore, when loaded with a FORTRAN object program that was compiled with the /EXTEND switch (see Section 16.5), FORDDT, by default, is redirected to the .DATA. psect. 17-17 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) FORDDT Version 10 will not versions of FORTRAN-IO/20. be guaranteed to work with previous FORDDT and FORLIB must be in the same section. Since they would by default go into the .DATA./.CODE. section, the user normally would not need to be concerned about this. However, you should be cautious when you use the LINK /REDIRECT switch. NOTE The first page of any section that reserved for FOR DDT and FOROTS. 17-18 contains code is CHAPTER 18 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) This chapter describes the facilities that the FORTRAN Object Time System (FOROTS) provides for the FORTRAN user. FOROTS implements all standard FORTRAN I/O operations as set forth in the FORTRAN-77 standard 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 TOPS-IO or TOPS-20 monitor during input and output operations. Other capabilities include: 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 (nonmathematical) 8. Specialized applications packages 9. Overlay facilities FOROTS runs on any TOPS-IO or 1'OPS-20 system. all TOPS-IO or TOPS-20 peripheral devices. 18.1 FOROTS interfaces with FEATURES OF FOROTS The following list briefly describes many specific features of FOROTS; more detailed information concerning the implementation of these f eat u r E! s i s g i v e n 1 ate r i nth i~; c hap t e r • 1. Your program can run :.n 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 proglrams can access both devices in the same manner. 3.. FOROTS helps provide complete data file compatibility between all system devices. 18-1 directory and nondirectory USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 4. FOROTS treats devices located at remote stations in the way it treats local devices. 5. Programs written for magnetic tape operations will run correctly on disk under FOROTS supervision. FOROTS simulates the commands needed for magnetic tape operations. 6. You may change or specify object program device specifications with a FOROTS interactive dialogue. and 7. Non-FORTRAN binary data files may be read in FOROTS. mode 8. FOROTS provides interactive program/operating system error-processing routines. These routines permit you to route the execution of the program to specific error-processing routines whenever designated types of errors are detected. 9. An error traceback facility for fatal errors provides the active execution path (by subroutine calls) between the main program and the subroutine where the fatal error occurred. 10. FOROTS provides a trap-handling system for arithmetic functions, including default values and error reports. 11. FOROTS permits your program to switch from READ to WRITE the same I/O device without loss of data or buffering. 12. Although primarily designed for use with the FORTRAN-I0/20 object programs, you can also use FOROTS as an independent I/O system, and as an I/O system for MACRO object programs. 18.2 IMAGE same file by 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. 18.3 INPUT/OUTPUT FACILITIES On TOPS-I0, FOROTS uses monitor-buffered I/O for SEQUENTIAL, SEQINOUT, SEQIN, and SEQOUT files access, and uses dump mode I/O for DIRECT(RANDOM), RANDIN, and dump mode files access. On TOPS-20, FOROTS uses PMAP monitor calls for disk files access other than APPEND, and uses monitor-buffered I/O for all other file accesses. The following sections describe I/O data channel and access modes. 18.3.1 Input/Output Channels Used By FOROTS (TOPS-I0 Only) FOROTS uses extended channels starting operations. User programs can request through the ALCHN. and FUNCT. routines. 18-2 at channel 20 for I/O I/O channels 0 through 17 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) When a request is made for an I/O channel, a table is scanned until a free channel is found. ThE! first free channel is assigned to the requesting program. On completion of the assigned transfer, control of the I/O channel is returned to FOROTS by using the DECHN. routine. lS.3.2 File Access Data can be transferred between processor storage and devices using either sequential or direct (random) access. lS.3.3 peripheral Closing Files After NOll-standard Termination When a FORTRAN program is aborted by <CTRL/C> or an error, open files cannot be closed with the monitor command CLOSE. The following command should be used: REENTER FOROTS then asks if you want the files to be closed. YES, then, the files are closed. If you answer lS.3.3.1 Sequential Access -- In a sequential-access transfer operation, the I"ecords involved are transferred in the same order as they appear in the source file. Each I/O statement executed transfers the record immediately following the last record transferred from the accessed source file. A type of the sequential access is available for output (write) operations. This type of access is called APPEND and is specified by the OPEN statement specifier ACCESS='APPEND' (see Section 11.3.1). APPEND lets you write a rE!cord immediately after the last logical record of the accessed file. During 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 specify transfer type!; (other than SEQINOUT) by setting the ACCESS option of a FORTRAN OPEN statement to one of several possible arguments. For the sequential access, the arguments are: ACCESS='SEQIN' ACCESS='SEQOUT' ACCESS='SEQUENTIAL' ACCESS='SEQINOUT' ACCESS='APPEND' (file is opened for read-only access) (file is opened for output) (file is opened for input or output) (same as SEQUENTIAL) (sequential append access) NOTE A common way to append data to a file opened with SEQUENTIAL access is to read past the end of file, and then begin writing. The FORTRAN-77 standard requires that a BACKSPACE operation be done to back over the 'end file reco rd' precE!d i ng the WRITE. lS-3 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.3.3.2 Direct (Random) Access Mode - Direct access permits records to be accessed and transferred from a source file in any desired order. Direct access can only be used with disk files that have been set up for direct access. Direct-access files must contain a specified number of identically sized records that may be individually accessed by a record number. Direct-access transfers may be done in either a read/write direction or a special read-only direction. You must specify random transfer direction by setting the ACCESS option of an OPEN statement (see Section 11.3.1) to one of several possible arguments. ACCESS='DIRECT' ACCESS='RANDOM' ACCESS='RANDIN' 18.4 (direct read/write access) (same as DIRECT) (direct read-only access) ACCEPTABLE TYPES OF DATA FILES AND THEIR FORMATS The following sections describe the acceptable to FOROTS. 18.4.1 types of 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 (that is, a form feed, a vertical tab, or a line feed) terminates each set. Logical records may be split across physi~al blocks. There is no maximum length for logical records. 18.4.2 FORTRAN Binary Data Files Each logical record in a FORTRAN binary data file contains data that the executing program can reference with either a READ or a WRITE statement. A logical record is preceded and ended by a control ~Nord 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. 18.4.2.1 Format of Binary Files - A FOROTS binary file can contain three f~rms of Logical Segment Control Words (LSCW). These LSCWs give FOROTS the ability to distinguish ASCII files from binary files. The value in the high-order 9 bits of an LSCW tells what kind of LSCW it is: START, CONTINUE, or END. LSCW START CONTINUE END 001+ the number of words in the segment including the START LSCW word (exclusive of the END LSCW) 002+ the number of words in the segment including the CONTINUE LSCW in the whole record 003+ the number of words including all LSCWs 18-4 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) If the access you specify for a file through the OPEN statement ACCESS=: argument is 'SEQIN' 'SEQOUT', 'SEQUENTIAL', or 'SEQINOUT', all three LSCWs can appear in a record. If you specify a record size, all records are of the same length, and there are no CONTINUE LSCWs. j The following examples illustrate the LSCW. file contains only 001 and 003 LSCWs. C C The direct-access LOOK AT A BINARY FILl: AND SEE THE LOGICAL SEGMENT CONTROL WORDS. OPEN (UNI T= 1, ACCESS= 'I>I RECT' ,MODE=' BINARY' , RECORDSIZE=100) 1 1=5 WRITE(l'l) J=7 WRITE(1'2) END (I, J=I,10) (J,K=l,IO) 18-5 binary USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 0/ 1/ 2/ 3/ 4/ 5/ 6/ 7/ 10/ 11/ 12/ 13/ 14/ 15/ 16/ 17/ 20/ 21/ 22/ 23/ 24/ 25/ 26/ 27/ 30/ 31/ 32/ 33/ 34/ 35/ 36/ 37/ 40/ 41/ 42/ 43/ 44/ 45/ 46/ 47/ 50/ 51/ 52/ 53/ 54/ 55/ 56/ 57/ 60/ 61/ 62/ 63/ 64/ 65/ 66/ 67/ 70/ 71/ 72/ 73/ 74/ 75/ 76/ 77/ 001000,000145~Number 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 of words in record counting START LSCW 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107/ 110/ 111/ 112/ 113/ 114/ 115/ 116/ 117/ 120/ 121/ 122/ 123/ 124/ 125/ 126/ 127/ 130/ 131/ 132/ 133/ 134/ 135/ 136/ 137/ 140/ 141/ 142/ 143/ 144/ 145/ 146/ 147/ 150/ 151/ 152/ 153/ 154/ 155/ 156/ 157/ 160/ 161/ 162/ 163/ 164/ 165/ 166/ 167/ 170/ 171/ 172/ 173/ 174/ 175/ 176/ 177/ 18-6 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 003000,000146~END 001000,000145 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 LSCl..v containing the number of words in the record including all LSCWs. USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 200/ 201/ 202/ 203/ 204/ 20:)/ 206/ 207/ 210/ 211/ 212/ 213/ 214/ 215/ 216/ 217/ 220/ 221/ 222/ 223/ 224/ 225/ 226/ 227/ 230/ 231/ 232/ 233/ 234/ 235/ 236/ 237/ 240/ 241/ 242/ 243/ 244/ 245/ 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 246/ 247/ 250/ 251/ 252/ 253/ 254/ 255/ 256/ 257/ 260/ 261/ 262/ 263/ 264/ 265/ 266/ 267/ 270/ 271/ 272/ 273/ 274/ 275/ 276/ 277/ 300/ 301/ 302/ 303/ 304/ 305/ 306/ 307/ 310/ 311/ 312/ 313/ 18-7 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 000000,000000 003000,000146 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) On TOPS-I0, in the sequential-access binary file, the second record crosses the disk block boundary and contains an 002 (CONTINUE) LSCW. On TOPS-20, the CONTINUE LSCW occurs on buffer boundaries, whose size is determined by the BUFFERCOUNT keyword in the OPEN statement (see Section 11.3.5) (default is four pages, 4000 octal words). C C LOOK AT A BINARY FILE AND SEE THE LOGICAL SEGMENT CONTROL WORDS. OPEN(UNIT=l,MODE='BINARY') 1=5 WRITE(l) J=7 WRITE(l) END (I, J=l,lOO) (J,K=l,lOO) 18-8 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 0/ 1/ 2/ 3/ 4/ 5/ 6/ 7/ 10/ 11/ 12/ 13/ 14/ 15/ 16/ 17/ 20/ 21/ 22/ 23/ 24/ 25/ 26/ 27/ 30/ 31/ 32/ 33/ 34/ 35/ 36/ 37/ 40/ 41/ 42/ 43/ 44/ 45/ 46/ 47/ 50/ 51/ 52/ 53/ 54/ 55/ 56/ 57/ 60/ 61/ 62/ 63/ 64/ 65/ 66/ 67/ 70/ 71/ 72/ 73/ 74/ 75/ 76/ 77/ 001000,000145 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000n05 OOOOOO,OOOOOS 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 100/ ]01/ 102/ 103/ 104/ 105/ 106/ 107/ 110/ 111/ 112/ 113/ 114/ 115/ 116/ 117/ 120/ 121/ 122/ 123/ 124/ 125/ 126/ 127/ 1 30/ 131/ 132/ 133/ 134/ 135/ 136/ 137/ 140/ 141/ 142/ 143/ 144/ 145/ 146/ 147/ 150/ 151/ 152/ 153/ 154/ 155/ 156/ 157/ 160/ 161/ 162/ 163/ 164/ 165/ 166/ 167/ 170/ 171/ 172/ 173/ 174/ 175/ 176/ 177/ 18-9 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 003000,000146 of words to next LSCW 001000,000032~Number 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 200/ 201/ 202/ 203/ 204/ 205/ 206/ 207/ 210/ 211/ 212/ 213/ 214/ 215/ 216/ 217/ 220/ 221/ 222/ 223/ 224/ 225/ 226/ 227/ 230/ 231/ 232/ 233/ 234/ 235/ 236/ 237/ 240/ 241/ 242/ 243/ 244/ 245/ 002000,000114~Continuc 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 LSCW 246/ 247/ 250/ 251/ 252/ 253/ 254/ 255/ 256/ 257/ 260/ 261/ 262/ 263/ 264/ 265/ 266/ 267/ 270/ 271/ 272/ 273/ 274/ 275/ 276/ 277/ 300/ 301/ 302/ 303/ 304/ 305/ 306/ 307/ 310/ 311/ 312/ 313/ 313/ 18-10 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 003000,000147 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) Image files contain no LSCWs. You can only backspace that is created with a record size. C C an IMAGE LOOK AT AN IMAGE MODE FILE AND SEE NO LOGICAL SEGMENT CONTROL WORDS. OPEN{UNIT=l,MODE='IMAGE') I=5 WRITE(l) (I, J=l,lOO) J=7 WRITE(l) END (J,K=l,lOO) 18-11 file USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 0/ 1/ 2/ 3/ 4/ 5/ 6/ 7/ 10/ 11/ 12/ 13/ 14/ 15/ 16/ 17/ 20/ 21/ 22/ 23/ 24/ 25/ 26/ 27/ 30/ 31/ 32/ 33/ 34/ 35/ 36/ 37/ 40/ 41/ 42/ 43/ 44/ 45/ 46/ 47/ 50/ 51/ 52/ 53/ 54/ 55/ 56/ 57/ 60/ 61/ 62/ 63/ 64/ 65/ 66/ 67/ 70/ 71/ 72/ 73/ 74/ 75/ 76/ 77/ 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 100/ 101/ 102/ 103/ 104/ 105/ 106/ 107/ 110/ 111/ 112/ 113/ 114/ 115/ 116/ 117/ 120/ 121/ 122/ 123/ 124/ 125/ 126/ 127/ 130/ 131/ 132/ 133/ 134/ 135/ 136/ 137/ 140/ 141/ 142/ 143/ 144/ 145/ 146/ 147/ 150/ 151/ 152/ 153/ 154/ 155/ 156/ 157/ 160/ 161/ 162/ 163/ 164/ 165/ 166/ 167/ 170/ 171/ 172/ 173/ 174/ 175/ 176/ 177/ 18-12 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,(100005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000005 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 200/ 201/ 202/ 203/ 204/ 205/ 206/ 207/ 210/ 211/ 212/ 213/ 214/ 215/ 216/ 217/ 220/ 221/ 222/ 223/ 224/ 225/ 226/ 227/ 230/ 231/ 232/ 233/ 234/ 235/ 236/ 237/ 240/ 241/ 242/ 243/ 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 244/ 245/ 246/ 247/ 250/ 251/ 252/ 253/ 254/ 255/ 256/ 257/ 260/ 261/ 262/ 263/ 264/ 265/ 266/ 267/ 270/ 271/ 272/ 273/ 274/ 275/ 276/ 277/ 300/ 301/ 302/ 303/ 304/ 305/ 306/ 307/ 18-13 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 000000,000007 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The following example illustrates the binary files. C C LSCWs for character data in LOOK AT BINARY MODE FILE WITH CHARACTER DATA AND SEE THE LOGICAL SEGMENT CONTROL WORDS OPEN (UNIT=l,MODE='BINARY') 0/ 1/ 2/ 3/ 4/ 5/ 6/ 7/ 10/ 11/ 12/ 13/ 14/ WRITE (1) 3, 'ABCDEF' ,4,'GHIJKL' WRITE (1) END 'MNOPQR' ,'STUVWX' 001000,000007 000000,000003 406050,342212 430000,000000 000000,000004 436211,145226 460000,000000 003000,000010 001000,000004 466351,750242 512472,452654 536600,000000 003000,000005 The following example illustrates the format image files. Image files contain no LSCWs. C C of character data in LOOK AT IMAGE MODE FILE WITH CHARACTER DATA AND SEE NO LOGICAL SEGMENT CONTROL WORDS OPEN (UNIT=I,MODE='IMAGE') WRITE (1) 3, 'ABCDEF' ,4, 'GHIJKL' WRITE (1) END 0/ 1/ 2/ 3/ 4/ 5/ 6/ 7/ 18.5 'MNOPQR' ,'STUVWX' 000000,000003 406050,342212 430000,000000 000000,000004 436211,145226 462331,647640 506452,352252 532573,000000 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, or CLOSE. FOROTS will provide automatic memory allocation, data conversion, buffering, and device interface operations to the MACRO user. 18-14 I/O USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.5.1 FOROTS Entry Points FOROTS provides the following entry points for FORTRAN compiler or a non-FORTRAN program. contained in FORLIB.REL. Table 18-1: calls from either a These entry points are FOROTS Entry Points Entry Point Function ALCHN. Allocates ar I/O channel for use subroutine (see Section 18.5.3.12) ALCOR. Allocates memory (see Section 18.5.3.11) CLOSE. Closes a fil~. In a FORTRAN program, this call is made when the CLOSE statement is ex~cuted (see Section 18.5.3.10) DBMS. DBMS interface. DEC. DECODE routine. This call, coupled with an call, handles decoding. DECHN. Deallocates an I/O channel that was ALCHN (see SE'ction 18.5.3.12) DECOR. Deallocates memory that was allocated by call (see Section 18.5.3.11) ENC. ENCODE rout i rle EXIT. Closes all files, clears interrupt system, and terminates program execution. In a FORTRAN program, this call is made when an END statement is executed in t.he main program. EXITI. Writes out buffers, closes and unmaps all files FIN. I/O list termination routine (see Section 18.5.3.9) FIND. FIND statement FORER. Err 0 r pro c e s ~; 0 r FOROP. Miscellaneou~; FUNCT. OTS-independE~nt interface to provide common functions (J.ike memory and I/O channel management) for programs such as overlay handler and DBMS. FUNCT. is an interface that works the same way with FORTRAN, COBOL, and ALGOL run-time systems (see Section 18.6). IFI. In t ern a 1 f i 1 E~ i n put ( see Sec t ion 18. 5 • 3 • 2 ) by a MACRO IOLIST obtained an from ALCOR FORO'I'S utilities 18-15 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) Table 18-1: FOROTS Entry Points (Cont'd) Entry Point Function IFO. Internal file output (see Section 18.5.3.2) IN. Formatted input routine (see Sections 18.5.3.5, 18.5.3.6, and 18.5.3.8) IOLST. I/O list routine (see Section 18.5.3.9) MTOP. REWIND, BACKSPACE, Section 18.5.3.7). NLI. NAMELIST input routine (see Section 18.5.3.3) NLO. NAMELIST output routine (see Section 18.5.3.3) OPEN. Opens a file. Connects FORTRAN Logical Unit Number to a file for I/O (see Section 18.5.3.10) OUT. Formatted output routine (see Sections 18.5.3.5, 18.5.3.6, and 18.5.3.8) RESET. Job initialization entry TB. Binary input routine 18.5.3.5) TRACE. Traces subroutine calls WTB. Binary output routine (see 18.5.3.5) and (see ENDFILE 18.5.3.1, statements (see 18.5.3.1, Sections 18.5.3.1 and Sections 18.5.3.1 and ~_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _L -_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _~ 18.5.2 Calling Sequences You must use the following general form for all calls made to FOROTS: XMOVEI PUSHJ 16,ARGBLK 17,Entry Point (control is returned here) where: ARGBLK is the address of a specifically formatted argument block that contains information needed by FOROTS to accomplish the desired operation. Entry Point is an entry point identifier (see Table 18-1) 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: 1. An error return to a specified statement number, that READ or WRITE statement ERR=option (see Section 10.4.7), 18-16 is, USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) ;~. An end-of-file return to a statement number, that is, READ or WRITE statement END=option (see Section 10.4.6), 3. A fatal error that returns to the monitor. Sections 18.5.3.1 through 18.~i.3.12 give the MACRO calls and required argumE~nt block formats needed to initialize FOROTS and FOROTS I/O operations. 18.5.3 MACRO Calls for FOROTB Functions The following sections describe the forms of the MACRO calls to FOROTS that are made by the FORTRAN compiler. The calls described are identified by the language statement that they implement. The following terms and abbreviations are used in the description of the argument block U\RGBLK) 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.) II FORTRAN logical unit number n count of ASCII characters f FORMAT statement address list an name a NAMELIST naml; r. a variable specifyinq the random access mode * list-directed [/0 (the FORMAT statement is not used) type type specification of a variable or constant Input/Outpu~ list logical record number for The argument block for all I/O statements is a sequence of keyword specifiers. Bits 2-8 of each argument specify which argument is being supplied, as follows: 1 :2 3 4 5 6 7 10 11 12 13 UNIT FMT address FMT size (in words) END= address ERR= address IOSTAT= address REC= NAMELIST table addre3s File-positioning function code ENCODE/DECODE array 3ddress Internal record length 18-17 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The format of ARGBLK is: 0-1 2-S 9-12 13 14-17 a (-count - negative of number of words in block not including this one) ---. ARGBLK: lS-35 a kwd type I a y · ·· 1· a kwd type I a y 1 ·· where: I = y = kwd indirection bit IS-bit address or data keyword number NOTE Future versions of FOROTS will not support argument blocks with index registers specified either in the arguments or in memory locations referenced indirectly by these arguments. Arguments must not reside in the ACs. In addition, so-called 'immediate' arguments (those with a type code of zero) will not be supported. 18.5.3.1 Sequential-Access Calling Sequences - The READ and WRITE statements for formatted sequential data transfer operations and their calling sequences are: READ (u, f) 1 is t XMOVEI 16, ARGBLK PUSHJ 17, IN. and WR I T E ( u , f) 1i st XMOVEI 16, ARGBLK PUSHJ 17, OUT. The following arguments must be specified in ARGBLK: 1 2 3 UNIT FMT address FMT size The following may also appear: 4 5 6 ERR END IOSTAT IS-IS USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The READ and WRI'rE statements for unformatted sequential data transfer operations and their calling sequences are: READ(u) list XMOVEI 16, ARGBLK PUSHJ 17, R'rB. and WR I T E ( u) 1 i s t XMOVEI 16, ARGBLK PUSHJ 17, w'rB. The following arguments must be specified in ARGBLK: 1 UNIT The following may also appear: 4 5 6 END ERR IOSTAT 18.5.3.2 Internal File Calling Sequences - The READ and WRITE statements for formatted sequential data transfer operations using internal files and their calling sequences are: READ ( u , f ) 1 i s t XMOVEI 16, ARGBLK PUSHJ 17, I1PI. ,and WR I T E ( u , f ) lis t XMOVEI 16, ARGBLK PUSHJ 17, IlPO. The following arguments must be specified in ARGBLK: 1 2 3 UNIT (must be a character scalar or array) FMT address FMT si:ze The following may also appear: 4 5 6 ERR END IOSTAT 18-19 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.5.3.3 NAMELIST I/O, Sequential-Access Calling Sequences - The READ and WRITE statements for NAMELIST-directed sequential data transfer operations and their calling sequences are: READ (u, name) XMOVEI 16, ARGBLK PUSHJ 17, NLI. and WRITE (u, name) XMOVEI 16, ARGBLK PUSHJ 17, NLO. The following arguments must be specified in ARGBLK: 1 10 UNIT NAMELIST address The following may also appear: 4 5 6 END ERR IOSTAT The NAMELIST table is generated from the FORTRAN NAMELIST statement. 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+4) 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 format, first in the table. Each name is followed by a list of arguments associated with the name. The NAMELIST table is terminated by a zero entry. The name argument list can be in either a scalar or an array form. used 18.5.3.4 Array Offsets and Factoring - Address calculations 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 S2 UI-Ll+1 U2-L2+1 In order to calculate the address of an element referenced by: A (Il,I2,I3, ••• In) the following formula is used: A+(II-Ll)+(I2-L2)*Sl+(I3-L3)*S2*Sl+ .•• +(In-Ln)*S[n-l]* •.• *S2*Sl 18-20 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The terms are factored out depending on the dimensions of not on the element referenced, to arrive at the formula: the array, A+(-LI-L2*Sl-L3*S2*Sl ••• )+Il+I2*Sl+I3*S2*Sl ..• The parenthesized part of this formula is the offset for single-precision array; it is referred to as the Array Offset. a 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: 5[n-l]*S[n-2]* ••• *S2*Sl For double-precision and complex arrays, the expression becomes: A+2*(II-Ll)+2*(I2-L2)*Sl+2*(I3-L3)*S2+S1+ ••• Therefore, the array offset for a double-precision array is: 2*(-LI-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. For character arrays, the offset is calculated in bytes instead of words. The byte offset from the start of a character array whose elements are of length X is: X* ( (II-Ll) + (I2-L2) *S2+ ••• ) This offset is X times the offset of a single-precision numeric array. NAMELIST Table 35 I) NAMELIST name in SIXBIT NAIv1.ELIST entry 1 NAIv1.ELIST en try 2 NAJ.1ELIST entry n 4000,,0 (FOROTS FIN. word) 18-21 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) SCALAR ENTRY in a NAMELIST Table o 1 9-12 18-35 SIXBIT/SCALAR NAME/ o 1 0 Scalar addr ARRAY ENTRY in a NAMELIST Table 0-1 1 2-8 9- 12 1 13 1 1 14-17 1 18-35 SIXBIT/ARRAY NAME/ 1 0 I tDIMS I type I I 0 I ARRAY SIZE I BASE ADDR OFFSET Factor 1 Factor 2 · · · n Factor 18.5.3.5 I/O Statements, Direct-Access Calling Sequences - The READ and WRITE statements for formatted direct-access data transfers and their calling sequences are: READ (u'r,f) list XMOVEI 16, ARGBLK PUSHJ 17, IN. and WR I T E ( u ' r , f ) 1i st XMOVEI 16, ARGBLK PUSHJ 17, OUT. The following arguments must be specified in ARGBLK: 1 2 3 7 UNIT FMT address FMT size REC 18-22 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The following may also appear: 4 5 6 END ERR IOSTAT The READ and WRITE statements for unformatted direct-access and their calling sequences a~e: transfers READ (u'r) XMOVEI l6,ARGBLK PUSHJ P,RTB. and WRITE (u'r) XMOVEI l6,ARGBLK PUSHJ P,WTB. The following argument must be specified in ARGBLK: 1 7 UNIT REC The following may also appear: 4 5 6 END ERR IOSTAT 18.5.3.6 Default Devices Statements, Calling Sequences - The FORTRAN 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 UNIT=-4 (TTY) (CDR) (REREAD) UNIT~-5 UNIT~-6 XMOVEI 16, ARGBLK PUSHJ 17, IN. and PRINT f, list PUNCH f, list TYPE f, list (LPT) (PTP) (TTY) UNIT~-3 UNIT~-2 UNIT~-l XMOVEI 16, ARGBLK PUSHJ 17, OUT. The arguments for these calls are the same as formatted sequential READ and WRITE statements. 18-23 for the standard USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.5.3.7 Statements to Position Files - The formatted and unformatted FORTRAN statements that can be used to control the positioning of files 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: XMOVEI 16, ARGBLK PUSHJ 17, MTOP. The following arguments must be specified in ARGBLK: 1 11 UNIT FOROTS code The following may also appear: 4 5 6 END ERR IOSTAT NOTE For disk files, UNLOAD is the same as REWIND; BACKFILE and SKIPFILE are ignored. 18.5.3.8 List-Directed Input/Output Statements - You may write any form of a sequential I/O statement as a list-directed statement by replacing the referenced FORMAT statement number with an asterisk (*). The list-directed forms of the READ and calling sequences are: WRITE statements and their READ (u, *) list XMOVEI 16, ARGBLK PUSHJ 17, IN. and WR I T E ( u, *) 1i s t XMOVEI 16, ARGBLK PUSHJ 17, OUT. The arguments for these calls are the same as for the standard formatted sequential READ and WRITE statements, except that the FORMAT statement address and FORMAT statement size must be specified as zero. 18-24 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.5.3.9 Input/Output Data Lists - The compiler generates a calling sequence to the run-time system for the I/O list in a 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: XMOVEI 16, ARGBLK PUSHJ 17, IOLST. Any number of elements may be included in the ARGBLK. The end of argument block is specified by a zero entry or a FIN entry. Mnemonic Name the FOROTS Value DATA SLIST ELIST FIN F77 SLIST F77 ELIST 1 2 3 4 5 6 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: ~EE ~bb 2. 2 13 14-17 18-35 e I a SCALAR SLIST The SLIST argument converts an entire array from internal to external form or vice versa, depending on the type of statement (that is, READ or WRITE) involved. An SLIST consist of a table of arguments that has the following form: 0-1 9-12 2-8 13 14-17 18-35 ,--I-- a SLIST tyt: e I a #ELEMENTS a 1 a a tyt: e I a INCREMENT a type I a BASE ADDRI 1 1 18-25 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) For example, the sequence: DIMENSION A(100) ,B(100) READ(-,-)A or READ(-,-) (A(I) ,1=1,100) !only when the /OPT switch is used develops an SLIST argument of the form: 0-1 2-8 9-12 13 14-17 18-35 1 1 1 0 2 0 0 4 2 2 2 0 0 0 0 0 0 0 0 0 [144] [1 ] A 0 0 0 0 0 More than one base address may appear in a SLIST as the increment is the same. The sequence: DIMENSION A(100), B(100) WRITE (-,-) (A(I) ,B(I) ,1=100) long as !only when the /OPT switch is used develops an SLIST argument of the form: 3. 0-1 2-8 9-12 13 14-17 18-35 1 1 1 1 0 2 0 0 0 4 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 [144 ] [1 ] A B 0 0 0 0 0 0 ELIST The SLIST format permits only a single increment to be specified for a number of arrays, while the ELIST permits different increments to be specified for different arrays. An ELIST consists of a table of arguments that has the following form: The format of the ELIST is: 0-1 2-8 9-12 13 14-17 1 0 ELIST type I 0 No. Elements to transfer increment 1 1 0 0 type I 0 Base ADDR 1 increment 2 1 0 0 type I 0 Base ADDR 2 increment N 1 0 0 type I 0 Base AD DR N 18-26 18-35 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) For example, the FORTRAN sequence: DIMENSION IC(6,100), IB(lOO) WRITE(-,-) (IB(I) ,IC(l,I) ,1=1,100) produces the ELIST: 0-1 2-8 9-12 13 14-17 18-35 1 1 1 1 1 0 3 0 0 0 0 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 [144] [1 ] IB [6] IC 0 This could be 0 0 0 0 0 0 4 The increment may be zero. sequence: WRITE(-,-) (K,I=l,lOO) produced by the !cnly when the /OPT switch is used Produces the ELIST: 4. 0-1 2-8 9-12 13 14-17 18-35 1 0 3 2 0 0 [144 ] 1 0 0 2 0 0 [0 ] 1 0 0 2 0 0 K 0 0 4 C 0 0 0 FIN The end of an I/O list is indicated by a FIN the I/O processor interprets this element, it to FIN to terminate the I/O. This call must each I/O initialization call, including calls list. element. When performs a call be made after with a null I/O The FIN routine may be entered by an explicit call or by an argument in this I/O list argument block. Both calls can not be used. The FIN element has the following format: I :-:~,=t._3_--L.._l_4_:_1_7--,_1_8_:_3_5_j....l EXPLICIT CALL: PUSHJ 17, FIN. 18-2:7 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 5. F77 SLIST if the numb€!r This is the same as SLIST except that elements is less than or equal to zero, no I/O is done. 6. of F77 ELIST is the number This is the same as ELIST except that elements is less than or equal to zero, no I/O is done. of 18.5.3.10 OPEN and CLOSE Statements, Calling Sequences - The form and calling sequences for the OPEN and CLOSE FORTRAN statements are: OPEN statement call: XMOVEI 16, ARGBLK PUSHJ 17, OPEN. CLOSE statement call: XMOVEI 16, ARGBLK PUSHJ 17, CLOSE. where ARGBLK is: 0-1 9-12 2-8 14-17 13 Negative of the number of words in block not including this one. 18-35 0 1 0 1 0 1 0 G G G type I type I type I X X X H H H ·· · · ·· 1· 0· · · · · G ·· · · ·· · type I· · · ·· X ·· · · H The G field (bits 2 through 8) contains a value that defines the argument name; the H field (bits 18 through 35) contains an address that points to the value of the argument. Note that the G field values for OPEN and CLOSE statements are not the same as those for other I/O statements. 18-28 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The numeric codes that may appear in the G field are: G Field Open Argument 01 02 03 04 05 06 07 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 G Field DIALOG ACCESS= DEVICE= BUFFERCOUNT= BLOCKSIZE= FILE= PROTECTION= DIRECTORY= LIMIT= MODE= FILESIZE= RECORDSIZE= DISPOSE= VERSION= Reserved Reserved IOSTAT= ASSOCIATEVARIABLE= PARITY= DENSITY= BLANK= CARRIAGECONTROL= 27 30 31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 50 51 52 53 Open Argument FORM= BYTESIZE= PADCHAR= RECORDTYPE= STATUS= TAPEFORMAT= READONLY= UNIT= ERR= EXIST= FORMATTED= NAMED= NEXTREC= NUMBER= OPENED= SEQUENTIAL= UNFORMATTED= NAME= Reserved Reserved DIALOG= lS.5.3.11 Memory Allocation Routines - The memory management module is called to allocate or deallocate memory blocks. There are two entry points (ALCOR. and DECOR.) that control memory allocation and deallocation. When TOPS-20 extended addressing is in effect, ALCOR. and DECOR. can be used; however, memory will be allocated in FOROT's section instead of in the user's section. You can use the LINK switch /OTSEGMENT:NONSHARABLE to put FOROTS in the user's section. Use the ALCOR. entry to allocate the number of words specified in the argument block variable. Upon return, AC 0 will contain either the address of the allocated memory block or -1, which indicates that memory is not available. The calling sequence for an ALCOR. call is: XMOVEI 16, ARGBLK PUSHJ 17, ALCOR. where ARGBLK is: r-0__-_l____ ~__2_-S______~1_9_-_1_2_~ -1 l~served type E lS-29 14-17 1S-35 0 0 Address of number of words USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) Use the DECOR. entry to deallocate a previously allocated block of memory; the argument variable must be loaded with the address of the memory block to be returned. If the number of desired words is N, ALCOR. actually removes N+2 words from free storage. The pointer returned points to the third word (word 2 as opposed to word 0) removed from free storage. The first two words are used by FOROTS to maintain linked lists of allocated (using ALCOR.) and free storage, and must not be modified. The calling sequence for a DECOR. call is: XMOVEI 16, ARGBLK PUSHJ 17, DECOR. where ARGBLK is: 0-1 2-8 _r- 12 13 14-17 - -I 1 0 18-35 --0 Reserved type I 0 Pointer to word containing address of block to be returned .18.5.3.12 Channel Allocation and Deallocation Routines - You may allocate software channels in MACRO programs by means of calls to the ALCHN. routine and deallocate 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 as an argument to ALCHN. Zero is passed as an argument 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 0 contains the assigned number. The calling sequence of an ALCHN. routine is: XMOVEI 16, ARGBLK PUSHJ 17, ALCHN. where ARGBLK is: 0-1 2-8 9-12 13 14-17 18-35 ---1 0 ---... 1 0 Reserved type I 18-30 0 Pointer to a word containing the channel # or zero USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) Use the DECHN. entry to deallocate a previously assigned channel. The channel to be released is passed as an argument to DECHN. If the channel to be deallocated was not assigned by ALCHN. and thus cannot be deassigned, AC 0 is set to -Ion return. The calling sequence for a DECHN. routine is: XMOVEI 16, ARGBLK PUSHJ 17, DECHN. where ARGBLK is: I 0-1 9 12 1 - 2-8 1 i 13 14-17 -1 1 0 18.6 18-35 0 Reserved type [ 0 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: XMOVEI 16, ARGBLK PUSHJ 17, FUNCT. The format of the ARGBLK is: ARGBLK: -(n+3>"O IFIW 2,address of integer function code IFIW 17,address of 3-letter ASCII error prefix IFIW 2,address of status code on return IFIW type,address of first argument IFIW type,address of nth argument where: type function code error prefix status is the FORTRAN argument type (see Chapter 14) is the number of one of the required functions is ignored by FOROTS is undefined on the call and set on the return with cne of the values below. -1 o l •••• n Function not implemented Successful return Specific error message When TOPS-20 extended addressing is in effect, FUNCT. can be used; however, memory will be allocated in FOROTS's section instead of in the user's section. You can use the LINK switch /OTSEGMENT:NONSHARABLE to put FOROTS in the user's section. 18-31 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) Table 18-2: Function Number (Octal) Function Numbers and Function Codes Function Mnemonic 0 1 2 ILL GAD COR 3 4 6 RAD GCH RCH GOT 7 10 ROT RNT 11 IFS 12 CBC 13 14 15 16 RRS WRS GPG RPG 17 20 21 22 GPSI RPSI MPG UPG 5 L-____________- L_ _ _ _ _ _ _ _ _ _ _ _ _ _ Function Description Illegal function; returns -1 status Gets a specific segment of memory Gets a given amount of memory from anywhere in the space allocated to the overlay handler Returns a specific segment of memory Gets an I/O channel Returns an I/O channel Gets memory from the space allocated to the object-time system Returns memory to the object-time system Gets the initial run time from the object-time system time file Gets the initial run specification from the object-time system Cuts back memory (if possible) to reduce job size Reads RETAIN status (DBMS) Writes RETAIN status (DBMS) Allocates memory on a page boundary Deallocates memory obtained by function 15 Gets TOPS-20 PSI channel Returns TOPS-20 PSI channel Gets a contiguous set of pages Returns a contiguous set of pages ~ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _._________ ._ _ _ _ ~ Each function of the FUNCT. subroutine is described below. The arguments described in each of the following functions are what should be in the addresses pointed to by the argument block described above. ILL (0) FUNCTION - This function is illegal. ignored, and the status returned is -1. The argument block is GAD (1) FUNCTION - This function gets memory from a specific address in the space allocated to the overlay handler. The arguments are: arg 1 arg 2 address of requested memory address of number of words of memory to allocate A call to GAD with arg 2 equal to -1 requests all available memory. On return, the status is one of the following: o 1 2 3 successful allocation not enough memory available memory not available at specified address illegal arguments (such as, address + size than 256K) 18-32 is greater USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) COR (2) FUNCTION - This function gets memory from any available allocated to the overlay handler. The arguments are: space undefined (address of allocated memory on return) address of siz~ of requested allocation On return, the status is one of the following: o memory allocatE'd not enough memory available illegal argument (that is, size is greater than 256K) 1 3 RAD (3) function - This funct.ion returns address within the space allocated to arguments are: arg 1 arg 2 memory at the specified the overlay handler. The address of memory to be return address of si ZE! of memory to be returned (in words) On return, the status is one of the following: o successful return of memory me-mory cannot be returned illegal argument (that is,the address or g reate r than 2~i6K) 1 3 GCH (4) are: FUNCTION - This function gets an I/O channel. arg 1 arg 2 undefined return) ignored (address of channel number the size is The arguments allocated on On return, the status is one of the following: () 1 sllccessful channel allocation no I/O channels available RCH (5) FUNCTION arguments are: arg 1 arg 2 This function returns an I/O channel. The address of number of channel to be returned isrnored On return, the status is one of the following: o 1 channel releasl~d invalid channel number GOT (6) FUNCTION - This function gets memory from the space to the object-time system. The arguments are: arg 1 arg 2 allocated undefined (address of allocated memory on return) address of sizl~ of mE~mory requested On return, the status is one of the following: o 1 3 successful allocation not enough memory available illegal argument (such as, size is greater than 256K) 18-33 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 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. ROT (7) FUNCTION - This function returns system. The arguments are: arg 1 arg 2 memory to the address of memory to be returned address of size of memory to be returned object-time (in words) On return, the status is one of the following: a successful return of memory memory cannot be returned illegal argument (such as, the address or the greater than 256K) 1 3 size is RNT (10) FUNCTION - This function returns the initial run time from the object-time system. (At the beginning of the program, the object-time system will have executed a RUNTIM UUO; that result is the time returned by RNT.) The arguments are: arg 1 arg 2 undefined return) ignored (contains address of initial run On return, the run time is in arg 1, and the status is O. is 0: time The on status IFS (11) FUNCTION (TOPS-IO only) - This function returns the initial run-time file specification from the object-time system. (This initial file specification is the one used to begin the program; that is, it was given with the system RUN command.) The arguments are: arg I arg 2 arg 3 undefined (address of SIXSIT device on return) undefined (address of SIXSIT filename on return) undefined (project-programmer number on return address of path block if run from SFD or On return, the status is one of the following: a successful return error I This function tells the overlay handler which file to read initial RUN command. after CSC (12) FUNCTION - This function cuts back memory if possible, reduces the size of the user job. There are no arguments. the which The returned status is: a RRS WRS (13) (14) always FUNCTION FUNCTION - These functions are reserved for use by DBMS. GPG (15) FUNCTION - This function gets memory on a page boundary. arguments are the same as for FUNCTION 6, GOT. arg 1 arg 2 ignored address of number of words of memory to allocate 18-34 The USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) On return, arg 1 has the address of the allocated memory. It will be on a page boundary. (That is, it will be a multiple of 1000 octal.) On return, the status is one of the following: o 1 3 RPG 15. successful not enough memory available illegal argument (16) FUNCTION - This function returns memory obtained by The arguments are the sarre as for FUNCTION 7, ROT. arg 1 arg 2 FUNCTION address of memcry to be returned address of SiZE of memory to be returned (in words) On return, the status is one of the following: o 1 3 successful return of memory was not allocated i 11 ega 1 a r g urn e r, t GPSI (17) FUNCTION - This function gets the TOPS-20 PSI channel. It assigns a software interrupt channel number. GPSI provides only controlled access to the PSI tables. It arranges that the tables exist and that SIR and EIR have been done, but does not do AIC or any other JSYS necessary to set up the channel (ATI or MTOPR, for example) • arg 1 arg 2 arg 3 address of channel number to allocate, or -1 to allocate any user-assignable channel address of lev~l number address of int~rrupt routine (if the FORTRAN program is running on a system that supports extended addressing, the interrupt Ioutine address may be a 30-bit address in any section, including section o. Otherwise, the interrupt addr~ss must be an 18-bit address.) On return, the status is one of the following: o 1 2 3 allocated OK (arg 1 is the channel number sent) requested channel was already assigned no free channe]s arg ument error if -1 was RPSI (20) FUNCTION - This function returns the TOPS-20 PSI channel. It returns a PSI channel allocated by FUNCTION 17. RPSI provides only controlled access to the PSI tables. It removes the given channel from the tables. This function does not do DIC or any other JSYS necessary to remove an interrupt condition from a channel. arg 1 address of charlnel number to return On return, the status is one () f the following: 0 01< 1. channel was not. allocated argument error 3 MPG (21) FUNCTION - This function gets a contiguous set of pages. The pages requested are always allocated from the section FOROTS is in. The user cannot depend upon this call to either create or destroy the pages. 18-35 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) arg 1 first page number to allocate. in the range to 777. arg 2 number of pages to allocate ° The page number must be On return, the status is one of the following: successful allocation of all given pages one or more pages were already allocated illegal argument (bad page number or count) °3 1 UPG (22) FUNCTION- This function returns a contiguous set of pages. The pages returned are considered to be in the section FOROTS is in. The user cannot depend upon this call to either create or destroy the pages. arg 1 first page number to deallocate. be in the range 9 to 777 arg 2 number of pages to deallocate The page number must On return, the status is one of the following: °1 successful deallocation of all given pages one or more pages was not allocated by MPG illegal argument (bad page number or count) 3 18.7 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, that is, DEVTB. Table 10-3 in Section 10.4.3 shows the standard assignments contained by the Device Table. 18.8 FOROTS AND INQUIRE BY FILE STATEMENT See Section 11.7 for a description of the INQUIRE statement. If no device is given for the FILE= specifier, FOROTS uses DSK: as the default. If no extension is given, FOROTS uses .DAT. For TOPS-20, if no generation number is given, FOROTS uses a generation number of 0. FOROTS determines if the device specified is a disk. a disk, the following happens: • If the device is FOROTS determines if a file exists with the file specification given in the INQUIRE statement. It returns the answer (either .TRUE. or .FALSE.) in the variable specified by the EXIST= specifier, if any. If such a file exists, FOROTS 'expands' the file specification as follows: • A logical name is translated into a physical device name. • For TOPS-20, the file specification, which is overlaid by the user-specified directory, filename, extension, and generation. • For TOPS-20, an actual file generation number substituted for a generation number of 0, -1, or -2, 18-36 is USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The resultant file specification, in string form, the 'full (expanded) file string.' • is called FOROTS searches for a match between the file specification given in the INQUJ:RE statement and a file specification associated with a logical unit for which there is a "connection." This is to determine the values to be returned for the INQUIRE spec~.fiers OPENED= and NUMBER= (see Section 11.7.3). FOROTS looks at all FORTRAN logical units for which there is a connection in ascending order, starting with zero. FOROTS compares the j~ile specification given in the INQUIRE statement (with FILE= defaults applied) with the exact file specification given in the OPEN statement (with FILE= defaults applied) if the following is true: • The file does not exist on the directory. • An OPEN statement: has been executed and STATUS='UNKNOWN' and ACCESS='SEQUI:NTIAL' (see Section 11.3.1). • No data transfer statements have been executed using unit. the If the file exists, FOROTS compares the full file string associated with the unit wi.th the full (expanded) file string given in the INQUIRE statement. The file exists if the following is true: • An OPEN has bE!en executed wi th STATUS other 'UNKNOWN' or ACCESS other than 'SEQUENTIAL'. • An I/O transfer ~;tatement than has been executed. If neither of these two comparisions are successful, FOROTS returns the curren1: unit number in the variable specified with the NUMBER= specifier,. and returns 'YES' in the variable specified with the OPENED= specifier. If the same file is connected on several units, the matching technique described will rE!turn the snallest unit number for which there is a match. For non-disk devices specifiecl in the INQUIRE statement file string specification, FOROTS looks a1: all the FORTRAN logical units for which there is a connection in ascending order, starting with zero. If the device in the file str~ng specified in the INQUIRE statement is not the user's controlling terminal, FOROTS expands the file specification given in the IN(~UIRE statement by translating a logical name given as the device :.nto its corresponding physical name. It then compares the device part of this expanded file specification with the dE!vice part of the full (E!xpanded) file string associated with the logical unit. If the device is the user's controlling terminal (device 'TTY'), FOROTS determines if the device associated with the logical unit is also the user's controlling terminal. 18-37 CHAPTEIR 19 USING THg FORTRAN REAL-TIME SOFTWARE (TOPS-IO ONLY) 19.1 INTRODUCTION The FORRTF library subroutines are designed to allow the timesharing FORTRAN user to do real-time programming on TOPS-IO systems. These subroutines, described in Section 19.3, are listed below: LOCK R'rIN IT CONECT R'rSTRT BLKRW RTREAD RTWRIT STATO STATI RTSLP RTWAKE DISMIS DISCON UNLOCK With these subroutines, the timesharing job can dynamically connect real-time devices to the priority Interrupt (PI) system, respond to these devices at interrupt level, remove the devices from the PI system, and change their PI level. Use of these routines requires that you have real-time privileges and are able to lock your job in core. The privilege bits required are: JP.RTT JP.LCK (bit 13) - real-time privileges (bit 14) - locking privileges The number of real-time devices that can be handled at one time is an assembly-time constant (RTDEVN) in the FORRTF source. The DIGITAI...-d i str ibuted so ftware h,3S RTDEVN equal to 2, but it can be changed (up to 6) by editing the statement IRTDEVN==2" in FORRTF.MAC and reassembling. The error messages output by F~RRTF can be in either full message format or coded format (refer to Table 19-1). Use of the code and format saves over 100 words of run-time core. If core is limited, reassembly of FORRTF.MAC with the assembly-time constant SHORT changed from the DIGITAL-distributed a (full format) to -1 (coded format) accomplishes the core saving. On multiprocessor systems, the real-time traps apply only to the processor specified by t~e job's CPU specification. If the specification indicates more tnan one processor, the specification is changed to indicate CPUO. Note that the priority interrupt channel is only for the indicated CPU. 19-1 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-IO ONLY) 19.2 USING FORRTF Users of FORTRAN-IO real-time software must consider the following: 1. Use of memory 2. Device control in block or single mode 3. Priority-interrupt levels 4. Masks 19.2.1 Memory The job being executed must be locked in memory with the LOCK subroutine (see Section 19.3.1). Any data being read into memory can only be read into the low segment and above the protected job data area (the first 140 locations). The BLKRW subroutine (see Section 19.3.5) tests the validity of the locations specified to receive data in block reading to ensure that no overwritings occur. However, when in block mode, the block pointer must be reset before dismissing the end-of-block interrupt; otherwise, all memory could be overwritten. 19.2.2 Modes Real-time jobs can control their devices in one of two ways: block mode or single mode. In block mode, an entire block of data is read or written before the user-interrupt routine is run; whereas, in single mode, the user-interrupt program is run every time the device interrupts. fast-block mode and normal-block There are two types of block mode: mode. A device in fast-block mode requires that a PI channel be dedicated entirely to itself. 19.2.3 Priority-Interrupt Levels Priority-interrupt levels 1 through 6 are legal depending on the system configuration. The lower the number of the level, the higher the priority of that level. Programs that execute for a long time should not be put on high-priority interrupt levels, since they could cause other real-time programs on lower levels to lose data. Specification of the PI level as zero for a particular device causes the device to be removed from the PI system. 19.2.4 Masks For a description of the bits included in the startmsk and intmsk parameters of RTSTRT and the status word in STATO and STATI, see the DECsystem-10 Hardware Reference Manual. 19-2 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-I0 ONLY) 19.3 SUBROUTINES Each of the 14 subroutines associated with FORTRAN real-time software is described briefly in Sections 19.3.1 through 19.3.14. These subroutines have been programmed to be compatible with programs written according to the TOPS-10 Monitor Calls Manual. 19.3.1 LOCK LOCK locks the job in memory and allocates and initializes the internal controlling tables for all real-time devices. LOCK must be called before any of the other real-time routines, and must be called exactly once. The form of the LOCK subroutine is: CALL LOCK 19.3.2 RTINIT RTINIT initializes the internal tables controlling a real-time device. RTINIT must be called for each individual device being used. The form of the RTINIT subroutine is: CALL RTINIT (unit, dev, pi, trpadr, intmsk) where: unit is the real-timE device unit number (any number from I to RTDEVN). This number is not connected in any way with the FORTRAN logical unit number. dev is the device code for the real-time device DECsystem-l_Q Hardware Reference Manual) • pi is the priority-interrupt level on which the real-time device is to be run. Each individual device in fast-block mode must have a level dedicated to itself. If the level is equal to zero, the device will be removed from the priority-interrupt system altogether. (see the If it is necessary to connect one device to several levels simultaneously, a negative value for PI tells the system not to remove any other occurrences of the device from any other (or the same) PI level. (Note that this count~. as another real-time device.) tr pad r is the address of a FORTRAN entry to which real-time interrupts are to trap. This can be a function or subroutine subprogram. Any variables that must be shared betwe~n the user-level code and the interrupt-level routine must be passed by means of COMMON. Passing them as parameters causes disastrous results. 19-3 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-IO ONLY) intmsk is the mask of all interrupting flags for the real-time This is actually set up by RTSTRT and should be zero whenever the real-time device is inactive (that is, in a call to RTINIT, except in the case of fast-block mode). In fast-block mode, intmsk must be set to -1. device. 19.3.3 CONECT CONECT tells the system to connect a real-time device to the proper PI level and sets up several elements of the device-controlling tables. Every device must be CONNECTED. The form of the CONECT subroutine is: CALL CONECT (unit, mode) where: unit is the real-time device unit number mode is either: (see RTINIT). -2, write a block of data, fast mode; then interrupt. -1, write a block of data, normal mode; then interrupt. 0, interrupt every word +1, read a block of data, normal mode; then interrupt. +2, read a block of data, fast mode; then interrupt. 19.3.4 RTSTRT RTSTRT can be used to start a real-time device, as well as to stop it and zero its interrupt mask. A device must be started to be used and should be stopped before it is disconnected. The form of the RTSTRT subroutine is: CALL RTSTRT (unit, startmsk, intmsk) where: unit is the real-time device unit number startmsk is the flags necessary to start the device (see the DECsystem-lO Hardware Reference Manual). If the device is being stopped, this parameter should be zero. intmsk is the mask of all interrupting bits for the particular device (see the DECsystem-lO Hardware Reference Manual). If the device is in fast-block mode and being started, intmsk should equal -1; if, however, the device in any mode is being stopped, the parameter must be o. 19.3.5 (see RTINIT). BLKRW BLKRW is used with either of the block modes. It sets up the size and starting address of the data block being handled. A new count and starting address must be set up each time the current one runs out. 19-4 USING THE: FORTRAN REAL-TIME SOFTWARE (TOPS-I0 ONLY) The form of the BLKRW subroutine is: CF.LL BLKRW (unit, count, blkadr) where: real-tim~ unit is the count is the number of words to be read or written. bl kad r is the array into which the data is to fro m wh i chi t i~; tab e' rea d • 19.3.6 device unit number (see RTINIT). be written or RTREAD RTREAD, used with a device in single mode, reads a single word of data from the device. The form of the RTREAD subroutine is: CALL RTREAD (unit, datadr) where: unit is the datadr is the address of the location in which data read. 19.3.7 real-tim~ device unit number (see RTINIT). to store the RTWRIT RTWRIT sends a single word of data to a mode. real-time device in single The form of the RT'WRIT subrouti ne is: CALL RTWRIT (unit, datadr) where: real-tim~ unit is the datadr is the location of the data word device. 19.3.8 device unit number (see RTINIT). to be sent to the STATO STATO sends the specified status word to real-time device. The form of the STATO subroutine is: CALL STATO (unit, statadr) 19-5 the status register of a USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-IO ONLY) where: unit is the real-time device unit number statadr is the location of the word of status bits to to the real-time device. 19.3.9 (see RTINIT). be sent STATI STATI reads the current device status bits into the location specified for inspection by the FORTRAN program. The form of the STATI subroutine is: CALL STATI (unit, adr) where: unit is the real-time device unit number (see RTINIT). adr is the location into which the device status to be read. 19.3.10 bits are RTSLP RTSLP is called from the timesharing level and causes the FORTRAN job to sleep until RTWAKE is called from interrupt level. The program goes to sleep for the specified number of seconds (up to 60). When it wakes up, it checks to see if RTWAKE has been called from interrupt level. If RTWAKE has been called, RTSLP returns to the calling program; otherwise the job goes back to sleep again. The form of the RTSLP subroutine is: CALL RTSLP (time) where: time 19.3.11 is the length of sleep time in seconds. RTWAKE RTWAKE is called at interrupt level to wake up the FORTRAN program. The form of the RTWAKE subroutine is: CALL RTWAKE 19.3.12 DISMIS DISMIS dismisses the interrupt user-interrupt routine must be causes its execution to begin. currently being processed. The sure to dismiss the interrupt that The form of the DISMIS subroutine is: CALL DISMIS 19-6 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-IO ONLY) 19.3.13 nISCON nISCON disconnects a real-time device from its PI level. All devices should be disconnected through calls to nISCON before the job is terminated. The form of the nISCON subrout~ne is: CALL nISCON (unit) where: unit 19.3.14 is the real-time device unit number (see RTINIT). UNLOCK UNLOCK unlocks the job from core. When execution of a job is complete, the job is automatically unlocked before the return to the monitor. The UNLOCK subroutine provides a method to unlock a job before execution is complete. Note that all real-time device handling must be finished before the job is unlocked. The form of the UNLOCK subroutine is: CALL UNLOCK 19.3.15 Error Messages Table 19-1 lists real-time software error messages, including the code format, the full message format, and the subroutine in which the messag(~ occurs. 19-7 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-IO ONLY) Table 19-1: Error Messages - Code Format and Full Message Format ~------------~------------------------------------------~-------------.~ Code Format Full Message Format 1 A 2 Subroutine in which message occurs ?ILLEGAL UNIT NUMBER. TO HANDLE MORE DEVICES, REASSEMBLE FORRTF WITH A LARGER ?ERROR COMES FROM THE SUBROUTINE "subroutine name" "RTDEVN" ?RTINIT MUST BE CALLED BEFORE CONECT CONECT ~------------~--------------------------'----------'-------r----------------- ?CONECT MUST BE CALLED BEFORE RTSTRT OR BLKRW 3 RTSTRT,BLKRW ~------------~-------------------------------------------+-------------.---- ?REAL TIME BLOCK OUT OF BOUNDS BLKRW ?END OF BLOCK TOO HIGH [such as, overwrites some program or in high segment] ?END OF BLOCK TOO LOW, such as, start address less than 140 4 A B ~------------~-----------------------------------------.--+--------------.---- ?JOB CANNOT BE LOCKED IN CORE ?JOB NOT PRIVILEGED ?NOT ENOUGH CORE AVAILABLE FOR LOCKING 5 A B LOCK ?APR ERROR AT INTERRUPT LEVEL ?PDL OVERFLOW ?ILLEGAL MEMORY REFERENCE 6 A B ~------------~------------------------------------'-------r-------------'---- 7 A B C D E o 1 8 A B ?RTTRP ERROR realtime trap error of the following sort ?ILLEGAL PI NUMBER PI channel not available ?TRAP ADDRESS OUT OF BOUNDS ?SYSTEM LIMIT FOR REALTIME DEVICES EXCEEDED ?JOB NOT LOCKED IN CORE OR NOT PRIVILEGED ?DEVICE ALREADY IN USE BY ANOTHER JOB ?OCCURRED IN THE DISCON ROUTINE ?OCCURRED IN THE CONECT ROUTINE ?NOT ENOUGH CORE AVAILABLE FOR THE CONTROL BLOCKS ?NOT ENOUGH CORE AVAILABLE DISCON CONECT LOCK ~------------~~----------------------------------------~-------------.---- 19-8 l\PPENDIX A SUMMARY OF FORTRAN STATEMENTS This appendix summarizes the forms of all FORTRAN statements and provides a section referenCE! where each statement is described in detail. Form Section Reference ACCEPTIFMT= n,END = sll,ERR= sl[,IOSTA':' = iosliliolistl ACCEPTIFMT= *[,END = s][,ERR = sJ[,IOSTA'f = iosjHiolistj ACCEPT f1,iolist] ACCEPT *r,iolistl Section 10.8 ASSIGN s to i Section 8.3 BACKFILE un BACKFILE (UNIT = unr ,ERR = ]r ,IOSTAT = io:; l) BACKFILE (un[,ERR ,= s][JOSTAT = ios1) Section 11.8.8 BACKSPACE un BACKSPACE (UNIT = un[,ERR= s][,IOSTAT c: iosl) BACKSPACE (unf,ERR=s][,IOSTAT=:iosj) Section 11.8.4 BLOCK DATA [sub] Section 13.1 CALL sub r( fa1 [,a2]. .. ])] Section 13.4.2.2 CHARACTER[*LEN[,]]v[*LEN]r,vf*LENII Section 7.2.2 CLOSE (doselist) Section 10.16 COMMON [lrcb]/1nlistf[,]/[eb]/nlist1... Section 7.4 COMPLEX v Lv ... ] Section 7.2 CONTINUE Section 9.4 DATA nhst/clistl [[,]nlist/clist/J... Section 7.9 DECODE(c,f,a/,ERR= sll ,IOSTAT = ios])liolistl Section 10.12 DIMENSION a(d) [,a(d) ... l Section 7.1 DO s [,1 i = e1,e21,e31 Section 9.3.1 DO s r,1 WHILE (e) Section 9.3.2 DOUBLE PRECISION v [, v ... ] Section 7.2 ELSE Section 9.2.4 ELSE IF (e) THEN Section 9.2.4 ENCODE:(c,f,a[,ERR = s]1 ,IOSTAT = ioslHiolist Section 10.12 END Section 9.7 A-I SUMMARY OF FORTRAN STATEMENTS Section Reference Form ~_:"-IJ) no Section 9.4 END IF Section 9.2.4 ENDFILE un ENDFILE (UNIT = un[,ERR = s][,IOSTAT = ios]) ENDFILE (un[,ERR = s][,IOSTAT = ios]) Section 11.8.5 ENTRY en [(d1 [,d2 ... ])] Section 13.4.3 EQUIVALENCE (nlist) [,(nlist) ... ] Section 7.5 EXTERN AL proc [,proc]. ... Section 7.6 FIND (UNIT"'un.REC-"'rnl.ERR sll JOSTAT '" iosl) FIND (un'rnl.l<:RR - sll.IOSTAT~ iosl) Section 11.8.1 FORMAT (fs) Section 12.1.1 fun ([arg1,arg2 ... argnJ) Section 13.3.4 [typ 1 FUNCTION fun aarg1 r,arg21. .. 1) Section 13.3.2 GO TO i [[,](s [,s] ... )] Section 9.1.3 GO TO s Section 9.1.1 GO TO (s [,s]. ..)[,] e Section 9.1.2 INCLUDE filespec. switch Section 6.4.2 IF (e) st Section 9.2.2 IF (e) sl, s2, s3 Section 9.2.1 IF (e) sl, s2 Section 9.2.3 IF (e) THEN Section 9.2.4 IMPLICIT type (a [,a ... m,type (a[,a ... ]) ... IMPLICIT NONE Section 7.3 INQUIRE (FILE = fil,flist1) INQUIRE ([UNIT =] u,ulistl Section 11.7.1 Section 11.7.2 INTEGER v [,v ... ] Section 7.2 INTRINSIC fun[ ,fun1 Section 7.7 LOGICAL v Lv ... ] Section 7.2 ;'\iAMELIST ifIameilistl!namc.lisil. .. Section 12.7 OPEN (openlist) Section 10.14 PARAMETER (p=c [,p=c ... ]) PARAMETER p=c[.p"--cl Section 7.8 PAUSE [n] Section 9.6 PHINT( FMT = fI.ERR - s II JOSTAT =, ins I Ii iolist I I'RINT(FMT -;'I.ERR - sll.lOSTAT-c iosilliolistl Section 10.10 PRINT n,iolist] PRINT *f,iolist1 PROGRAM name Section 6.4.1 F :NCH(FMT'- f1.ERR-slI.lOSTAT=iosilliolistl P 'NCH(F!\lT",-,c"'I.ERR-slI.lOSTAT josilliolistl " T!'JCH fI.iolistl I' "NCII;'I.iohstl Section 10.11 A-2 SUMMARY OF FORTRAN STATEMENTS Form Section Reference READ(UNIT = un,FMT = fl ,END = s][,ERR = ~;][ ,IOSTA'T = ios l)[iolist] READ( un,FMT = fl ,END = s][ ,ERR = ~;]l,IOSTA 'T = ios])[iolist] READ( un, fl ,END = s]l,ERR = s]l,IOSTA'T = ios])[iolist] READ(UNIT = un,FMT = *f ,END = s]f ,ERR = .,][,IOSTAT = ios])[iolist] un,FMT = *[ ,END = s][ ,ERR = ., H,IOSTAT = ios])[iolist] READ( READ( un, *LEND = s][,ERR = .,][,IOSTAT = ios])[iolist] READ( UNIT = un,FMT = name I,END = slf ,ELR sH ,IOSTAT= ios 1) READ( un,FMT = namel ,END = s If ,ELR .=.c sll ,IOSTAT = ios]) un, namel ,END = 8 ]f,Ef:,R -=c s 1f,IOSTAT -= ios]j READ( READ f[ ,iolist1 READ *[ ,iolist1 READ(UNIT = * ,FMT = fl ,END = s][ ,ERR = s]l ,IOSTAT = ios])[iolist] READ(UNIT= *,FMT= *[,END = s][,ERR= s][,IOSTAT= ios])[iolist] READ(UNIT = un[,END == sl[,ERR = s][,IOSTAT = ios])[iolist] un[,END =:= s][,ERR = s][,IOSTAT = ios])[iolist] READ( READ(UNIT = un,FMT = f,REC = rn[,ERR = s ILIOSTAT = ios])[iolist] READ( un,FMT = f,REC = rnl,ERR = s II ,lOSTAT = ios])[iolist] READ( un, f,REC = rn[,ERR = s][ ,IOSTAT = ios])[iolist] un'rn.FMT = f [,ERR = 811 ,10STAT =. iosllliolistl READ( READ( un'rn, f [,ERR=sll,IOSTAT=:ios1)[iolistl READ(UNIT = un,REC = rnl ,ERR = sJ[ ,IOSTAT = ios])[iolist] READ( un,REC = rnl,ERR = s][,IOSTAT = ios])[iolist] READ( un'rn I,ERR=sl[,IOST.AT =ios])liolistl Section 10.5 REAL v [,v ... 1 Section 7.2 REREAD(FMT = fl ,END" s][,ERR= sl[,IOST.\.T = ios1lliolist1 REREADWMT = *1 ,END·~ sll ,ERR -- f',11 ,IOST-\T ,= ios1j[iolist1 REREAD fl ,iolist1 REREAD *[ jolist1 Section 10.7 RETURN lel Section 13.4.4 REWIND un REWIND (UNIT = unl,ERR = s][ ,lOST AT = ios)) REWIND (unl,ERR = s]l,lIOSTAT = ios]) Section 11.8.2 SAVE la Lal ... l Section 7.10 SKIPFILE un SKIPFILE (UNIT = unl ,E RR = s ]I ,I OSTAT -'-' i )8 I) SKIPFILE (unl.ERR - sll,IOSTAT - ios]) Spction 11.8.7 -0. SKIPRECORD un SKIPRECORD (UNIT =- lllli ,ERR -=- s 11 JOSTA r SKIPRECORD (unl.ERR·'-. sll .lOSTAT= ios1) Section 11.8.6 ios I) STOP In] Section 9.5 SUBROUTINE sub l( Id1 [,d21. .. l)] Section 13.4.2.1 TYPEIF'MT= fl ,ERR - s]1 ,IOSTAT = i()sl)fioli~t1 TYPE(FMT = *[ ,ERR --' s II ,IOSTAT _oc i08 111 ioli:it I TYPE f1 .iolist] TYPE *I.iolist1 Section 10.9 v = e Section 8.2 UNLOAD un UNLOAD (UNIT = unl ,ERR = s 11 .lOSTA T ~ it·s 1) UNLOAD (unl, ERR -- s II ,lOST A T = ios I) Section 11.8.3 A-3 SUMMARY OF FORTRAN STATEMENTS Form Section Reference WRITE(UNIT = un,FMT = f1 ,ERR = s]!,I OST A T = ios 1)1 iolist I WRITE( un,FMT = fl ,ERR-' sll ,10STAT = ioslHiolist] WRITE( un, fl ,ERR - sJ[ ,10STAT = ios111iolist1 WRITE(UNIT= un,FMT= *I,ERR _c sH,IOSTAT-=-- ioslliiolistl WRITE( un,FMT = *1 ,ERR - sJ[ ,10STAT= ios])(iolistl un, *1 ,ERR = s]1 ,10STAT = ios])1 iolist 1 WRITE( WRITE( UNIT =- un.FMT = namel ,ERR -=. s 1I ,10STAT = ios 1) WRITE( un,FMT = namel.ERR '-- sll ,10STAT= iosl) WRITE( un. namel,ERR-sll.IOSTAT=-iosj) WRITE fl ,iolist 1 WRITE*I.iolist1 WRITE(UNIT = *,FMT = fl ,ERR= sll ,IOSTAT = iosj)[iolistl WRITE(UNIT = *,FMT = *1 ,ERR = sll ,10STA1' = iosj)[iolistl WRITE(UNIT = unl ,ERR= s](,10STAT = ioslliiolistl WRITE( unl ,ERR = sll ,10STAT= iosl)liolist] WRITE(UNIT = un,FMT = f,REC = rnl ,ERR = sJ[,10STAT = ioslHiolistl WRITE( un,FMT = f,REC = rn(,ERR·cc sl[ ,IOSTAT = ioslJ(iolistl un, f,REC - rnl ,ERR= sJ/ ,10STAT = ios111iolist1 WRITE( WRITE( un'rn,FMT'-'- f I,ERR'"" sl/ ,10STAT:.;o ios]ll iolistl WRITE( un'rn, f I,ERR = 81/ ,10STAT = ioslliiolistl WRITE(UNIT= un,REC -'- rnl,ERR=sll,lOSTAT= iosJ)liolistl WRITE( un,REC - rnl ,ERR = sll ,IOSTAT = iosJHiolist] WRITE( un'rn [,ERR=slIJOSTAT""iosj)lioli::3tl Section 10.6 A-4 APPENDIX B 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 this appendix. B-1 ASCII-1968 CHARACTER CODE SET ASCII CODE Control Characters Even Parity Bit 7-Bit Decimal 7-Bit Octal Character 0 000 000 NUL 001 001 SOli CC Start of heading [SaM, start of message] . Control A. 002 002 STX CC Start of text [EOA, end of address]. Control B. 003 003 ETX CC End of text [EOM, end of message] . Control C. 004 004 EaT CC End of transmission: shuts off TWX machines and disconnects some data sets. Control D. 0 005 005 ENQ CC Enquiry [WRU, "Who arc you?"]. Triggers identification ("lIere is ... ") at remote station ifso equipped. Control E. 0 006 006 ACK CC Acknowledge [RU, "Arc you ... ?"]. Control f. I 007 007 BEL 1 008 010 BS FE Backspace. Control II. 0 009 011 liT FF Horizontal tabulation. Control I. 0 010 012 Lf J 1 011 013 012 014 FE FE FE Vertical tabulation. Control K. 0 VT 3 fF 3 013 015 CR fE Carriage return (to beginning of line). Control M. 014 016 SO 0 015 017 SI I 016 020 OLE 0 017 021 DCl Device control I, turns transmitter (reader) on. Control Q (X ON). 0 018 022 DC2 Device control 2, turns punch or auxiliary on. Control R (TAPE, AUX ON). 0 Class l Remarks Null, tape feed. Control (Ii (control shift p2). Bell (audible or attention signal). Control C. Line feed. Control J. Form feed (to top of next page). Control L. Shi ft out; change character set or change ribbon color to red. Control N. Shift in; ret urn to standard character set or color. Control O. CC Data link escape [DeO]. Control P. 1 019 023 DC3 Device control 3, turns transmitter (reader) off. Control S (X OFF). 0 020 024 DC4 Device control 4 (stop), turns punch or auxiliary off. Control T (TAPE, AUX OFF). 021 025 NAK CC Negative acknowledge [ERR, error]. Control U. I 022 026 SYN CC Synchronous idle [SYNC] . Control V. 0 023 027 ETB CC 0 024 030 CAN 025 031 EM End of medium [SI]' Control Y. 026 032 SUB Substitute [S2]' Control Z. End of transmission block [LEM, logical end of medium]. Control W. Cancel [Sol. Control X. 0 027 033 ESC 1 028 034 FS IS File separator [S4]' Control \ (control shift L2). 0 029 035 CS IS 0 030 036 RS IS Croup separator [Ss]' Control] (control shift M2). Record separator [S 6]' Control ~ (control shift N2 ). 031 037 US IS Unit separator [S?]. Control - (control shift 0 2). Escape, prefix [S3]' Control [ (control shift K2). 1 CC communication control, FE format effector, IS information separator. 20n LT33, LT35 and similar units. 3 Includes a carriage return on some equipment, but not on standard DEC units. 8-2 ASCII-1968 CHARACTER CODE SET Graphic Characters Figures Upper Case Lower Case Even 7-Bit 7-Bit Parity Bit Decimal Octal Character 032 040 SP 1 033 041 o 042 034 o 035 043 # $ 044 036 o 045 037 % 1 038 046 & 1 047 039 o 040 050 o 051 041 042 052 * + 043 053 o 044 054 1 045 055 o 056 046 o 047 057 1 fIJI 048 060 o 049 061 1 2 1 050 062 3 063 o 051 4 052 064 1 5 053 065 o 6 054 066 o 7 067 055 070 8 1 056 057 071 9 o 058 072 o 073 059 060 074 o < 075 061 062 076 > 077 063 o Even Parity 7-Bit 7-Bit Bit Decimal Octal Character 064 100 (a 1 065 101 A o B 066 102 o 067 103 1 C 104 068 D o E 105 069 1 F 106 070 1 107 071 G o II 110 o 072 073 III 074 112 075 113 K o 114 L 1 076 115 M 077 o 116 078 N o 079 117 1 a 080 P o 120 Q 081 121 082 122 R 123 o 083 S 124 1 084 T 125 o 085 U V o 086 126 W 127 1 087 1 088 130 x y 089 131 o o 090 132 133 1 091 [ \2 134 o 092 135 1 093 I 094 1 136 137 095 o Even Parity 7-Bit 7-Bit Bit Decimal Octal Character 3 o 096 140 ,2 z I o I o o o o I o I o 1 o o I o I o o 1 o 1 o o 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 141 142 143 144 145 146 147 150 151 152 153 154 155 156 157 160 161 162 163 164 165 166 167 170 171 172 173 174 175 176 177 a b c d e g h j k 1 m n o p q 1I v w x y z .........,2,5 I Zero-slash absent on many units. 2 Under study by responsible American National Standards Committee for possible change at next revision of ASCII (ca. 1982). 3 Codes 140-173 first defined in 1965. For a full ASCII character set the operating system accepts codes 140-176 as lower case. For a program requiring a character ;;et that lacks lower case, the operating system translates input codes 140-174 into the corresponding upper case codes (100-134) and translates both 175 and 176 into 033, escape. Early versions of the DECsystem-l0 Monitor l(sed 175 as the escape code and translated both 176 and 033 to it. 4 Unassigned control character (usually ALT MODE) before 1965. Code generated by ALT MODE key on some DEC units, especially earlier ones; on some more reccnt units, the ALT key generates the standard escape code, 033. 5 Control character ESC before 1965; code generated by ESC key on some DEC units designed at that time. 6 Delete, rub out (not part oflower case set). 8-3 ASCII-1968 CHARACTER CODE SET Remarks on Special Graphic Characters > SP Space - normally nonprinting. Question mark. Exclamation point. " Quotation mark, diaeresis. # Number sign. £ on some (non-DEC) units. $ Dollar sign. % Percent. & Ampersand. (a \ Circumflex, upward arrow head. t before 1965, but used until 1972 on DEC units. Opening parenthesis. + Plus. Underline, underscore. - before 1965, but used until 1972 on DEC units. Grave accent, opening single quotation mark. (a 1965-67, but never on DEC units. Comma, cedilla. Opening brace. Hyphen, minus. Vertical line. Control character ACK before 1965;--'1965-67, but never on DEC units; : in appearance 1968-19-77, but generally not on DEC units. Period, decimal point. Slant, slash, solid us. Closing brace. Unassigned control (usually ALT MODE) before 1965. Colon. character Overline, tilde, general accent. Control char· after ESC before 1965; I 1965-67, but never on DEC units. Semicolon. < Reverse slant. ~ 1965-67, but never on DEC units. Shift L on LT33, LT35 and similar units. Closing bracket. Shift M on LT33, LT35 and similar units. Closing parenthesis. Asterisk. Commercial at. ' 1965-67, but never on DEC units. Opening bracket. Shift K on LT33, LT35 and similar units. Apostrophe, closing single quotation mark, acute accent. " in appearance on some DEC units. * Greater than. Less than. Equals. 8-4 APPENDIX C COMPILER MESSAGES The FORTRAN compiler issues tvlO tYPE~S of messages: warning and fatal error. While compiling thE! progrram, if the compiler encounters a situation that does not prevent it from completing the compilation, but does warrant your knowing about, it prints a warning message and continues compilation. If, however ,. the problem in your program is such that compilation cannot continue, the compiler prints a fatal-error message and stops compilation of the program. Whenever a fatal error is generated a relocatable object module will not be prod uced • Compiler messages are printed in the following form: ?FTNxxx LINE:n text or %FTNxxx LINE:n flag: text where: ? indicates a fatal message indicates a warning message FTN is the FORTRAN mnemonic xxx is the 3-letter mnemonic for the error message Line:n is the optional ljne number where the error occurred text is the explanation of error flag: is the prefix for warning messages generated when the compatibility flagger is invoked. This prefix describes the type of incompatibility the message refers to, and can be one of the fol]owing: ~; • Extension to Fortran-77: • VMS incompatibility: • F'ortran-77 and VMS: See Section 16.6 for more information on the compatibility flagger. Square brackets ([ ]) in this appendix signify variables and output on the terminal. C-l are not COMPILER MESSAGES 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. AHE IF' at line [number] already has ELSE AOA Assumed-size arrays only allowed in subprograms ASA Assumed-size arrays cannot be used 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 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-IO/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. CEL Character entry points must have the same length CEN Character expression used where numeric expression required CEX Constant or constant expression required CFF Cannot find file The file referenced in an INCLUDE statement was not found. CFL Reference to character function [name] length CNE Character and numeric entry points cannot be mixed CPE Checksum or parity [ name] error C-2 in must have a fixed [source/listing/object] fil e COMPILER MESSAGES ~haracter CQL No closing quote in CSA Can't split string CSF Illegal statement function reference in CALL statement DDA [symbolname] DDN DO loops too deeply nested - DFC Variable dimension [name] must be scalar, defined as or in COMMON DFD Double [type] numeric and character variables is duplicate dummy argument reduce nesting formal name illegal Duplicate fields specification. DIA a~ross constant were encountered DO index variable [name] in an INCLUDE file 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-IO/20. specification without associated be values is not DNL Implied DO variables list DPR Dummy parameter [name] DSF Argument [name] DTI The dimensions of [arrayname] DVE Cannot use dummy variable in EQUIVALENCE ECS [variable] statement ECT Attempt to enter [symbolname] EDN Expression too deeply nested to compile EID ENTRY statement illegal inside a block IF or DO loop ElL Expression illegal in an input list ElM ENTRY statement illegal in main program ENF Label [number] must refer to an executable statement, not FORMAT ETF Enter failure [number] EXB EQUIVALENCE extends COMMON block [name] FEE Found [symbol] of referenced before definition is same as FUNCTION name EQUIVALENCE-d to must be of the type integer COMMON is illegal in SAVE into COMMON twice [filespec] backwards when expecting either [symbol] General syntax error message. C-3 or [symbol] a COMPILER MESSAGES FER [file error text] An error has specification. occured when processing a command FID Can't initialize character function name FNE Label [number] must refer to a statement FWE Found IAC Illegal ASCII character [character] IAL Incorrect argument type for library function IAN Illegal assignment between character and numeric data IBD Illegal substring bound in DATA statement IBK Illegal statement in BLOCK DATA subprogram ICL Illegal character ICN Illegal combination of character and numeric data IDN DO loop at line: [symbol] when expecting [character] [ n urn be r ] FORMAT, not an file executable [symbol] in source [name] in label field i s i l l eg all y n est e d You are attempting to terminate a DO loop before terminating one or more loops defined after the given one. IDS Implicit DO indices may not be subscripted IDT Lllegal or misspelled data type IDV Implied DO index is not a variable IED Inconsistent EQUIVALENCE declaration The given EQUIVALENCE declaration would cause some name to refer to more than one physical location. IFD INCLUDEd files must reside on disk IFE [INCLUDE file error] This error occured while trying INCLUDE file on the DECSYSTEM-20. to open IFS Illegal format specifier I ID Non-integer implied DO index IIP Illegal implicit specification parameter IIS Incorrect INCLUDE switch ILF Illegal statement after logical IF the symbolic specified Refer to Section 9.2.2 for restrictions on logical IF object statements. IND Improper nesting: DO at line [number] C-4 has not terminated COMPILER MESSAGES INI Improper nesting: ]"F at line [number] has not terminated INN INCLUDE statements may not be nested IOC Illegal operator fOl character data IOD Illegal statement used as object of DO ION Numeric operand of concatenation operator IOR Substring bound out of range IQB INQUIRE - IQN INQUIRE - neither ISD Illegal subscript expression in DATA statement both UNIT and FILE keywords were specified U~IT nor FILE keywords were specified Subscript expressions may be formed only indexes and constants combined with +, ISN [symbolname] with implicit DO *, or I. is not [symbol type] The symbol cannot be used in the attempted manner. ISS [variable] ITL Illegal transfer into loop to label IUT Program units may not be terminated within INCLUDEd files IVC Invalid character constant IVH Invalid hollerith constant IVP Invalid PPN IXM Illegal mixed mode arithmetic Complex and expression. illegal in SAVE statement double-precision [OPEN specifier] [number] cannot appear in the IXS Illegal IZM Illegal [datatype] KA FORTRAN will not run on a KA KAS FORTRAN can not compile for a KA LAD Label 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 [number] same specifier size modifier [number] al ready defined at line: [number] Labels cannot be 0 or greater than five digits. LND Label [number] declaration must refer C-5 to a [statement] , not a COMPILER MESSAGES 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 1 COMMON variable in EQUIVALENCE group MSP Statement name misspelled MST [OPEN specifier] must be [integer or array] MWL Attempt to arguments NCC Can't store numeric constant in character variable NCF Not enough core for [number] NEX No exponent after D or E in constant NFS No filename specified define multiple the file RETURN without specs. Total K needed The INCLUDE statement requires a filename. NGS Cannot get segment [segment name] code] error code [GETSEG error This message means the system is unable to GETSEG one of the compiler segments on the DECsystem-lO. NIF No matching IF NIO NAMELIST directed I/O with I/O list NIR Repeat count must be an unsigned integer NIU Non-integer unit number in I/O statement NLF Wrong number of arguments for library function [name] NLS [variable] may not be declared length star NMD No matching DO NNA NAMELIST not allowed in ENCODE, DECODE, and REREAD NNF No statement number on FORMAT NNN NML= must specify a NAMELIST NRC Statement not recognized NUO .NOT. NWB Numeric variable must be aligned on word boundary NWD Incorrect use of NYI Not yet implemented OAG Octal or logical argument illegal to generic function is a unary operator * or? in [filespec] C-6 COMPI LER fJIESSAGES OBO [variable] may only be specified once OPW OPEN/CLOSE parameter" [name] OUB Only upper bound of last dimension asterisk PD6 FORTRAN will not rurl on PDP6 PIC The DO parameters of" [index name] must be integer constants PN4 Project number must be 4 in ppn is of wrong type This error is for DI:CsystE!m-IO file DECSYS'I'EM-20. PRF Pro t e c t ion fa i I u rei n urn b e r ] PTL Program too large The program unit ta~es of [arrayname] may specifications be on the real or [ f i I e s pe c ] up more than 5l2P. QEF Quota exceeded or disk full RDE Rib RFC [function name] RIC Complex constant cannot be used to represent imaginary part of a complex constant RUS Relational expression illegal as UNIT specifier SAD Array [name] - signed dimensions may appear only as constant range limits SMC Size modifier conflict for variable [name] SNC Substring of non-character variable SNL [statement name] SOR Subscript out of range STD Statement [number] TDO [symbol type] TFL Too many FORMAT labEls specified UCE User core exceeded at location [address] while processing statement [number] UEC Label [number] previously used in executable context UFC Label [number] previously used in FORMAT context UKW Unrecognized keyword UMP Unmatched parentheses UNS UNIT may not be specified 0 r [number] d ire c tor y err 0 r [ n urn be r ] is a [filespec) [ f i I e s pe c ] recursive function call the statements may not be labeled is a declaration type declaration out of order C-7 in phase [segment] COMPILER MESSAGES USI [symbol type] [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 WIF [I/O type] ZLD Zero-trip DO loop illegal in DATA statement is illegal with internal files 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. ACB Argument out of range of CHAR, high order bits ignored ADS Variable [name] AGA Opt - object variable, of list, was never assigned AIL Illegal length argument for ICHAR, first character used AIS Extension to Fortran-77: ANS VMS incompatibility: ASSOCIATEVARIABLE not OPEN CAl COMPLEX expression used in arithmetic IF CAO Consecutive arithmetic operators illegal CAP Extension to Fortran-77: Consecutive arithmetic operators CCC Fortran-77 and VMS: Carriage control character CCN CHARACTER constant used where numeric expression required CIS Conflicting INCLUDE switches CNM Character and numeric variables mixed CNS Extension to Fortran-77: non-specific length COS Extension to Fortran-77: Comment on statement COV Extension to Fortran-77: character expression CSM Extension to Fortran-77: Comma field separator is missing already declared in SAVE statement C-8 assigned GOTO without optional Apostrophe in I/O specifier Concatenation Assigned set with variable by VMS on variable of appears in COMPILER MESSAGES CTR Complex terms used in a relational other than EQ or NE The result of the other relational operands is undefined. CUO operators 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 expressions at compile time. DEB Extension to Fortran-77: DEBUG lines DFN VMS incompatibility: Default file name on VMS Fortran-IO/20 011 Previous declaration of intrinsic function is ignored DIM possible DO index modification inside loop differs from A program that does this may be incorrectly compiled by the optimizer, since it assumes that indexes 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. DOW Extension to Fortran-77: DO WHILE statement OPE VMS incompatibil i ty: Di ffE~rent precedence in exponentiation OWE Fortran-77 and VMS: [descriptor] OWL Extension to Fortran-77: DO without statement label DXB DATA st.atement EDD Extension to Fortran-77: END DO statement EDS Extension to Fortrall-77: DECODE statement EDS Extension to Fortran-77: EDX Fortran-77 and VMS: FORMAT edit descriptor [descriptor] EOC Fortran-77 and VMS: Exponential operator EXD Extension to Fortran-77: Transfer of control into DO loop at label [label] FAR Extension to Fortran-77: F'ormat in numeric array FIF Extension to Fortran-77: function in Fortran-77 FIN Extension to Fortran-77: FIND statement FMR Multiple RETURNs defined in a FUNCTION FMT VMS incompatibility: Keyword FMT instead of NML Default exceE~ds widths with edit descriptor bounds of array [name] ENCODE statement [function name] C-9 A is not an intrinsic COMPILER MESSAGES FNA A function without an argument list FNG Extension to Fortran-77: function in Fortran-77 FNS Extension to subroutine FOO Statement function dimensioned HCP VMS incompatibility: Hollerith constant padded with spaces HCN Hollerith constant used where numeric expression required HCU Extension to Fortran-77: Hollerith constant IAT Illegal type for argument [number] ICC Illegal character, continuation field of initial line [function name] Fortran-77: declared is not a generic [name] is not a FORTRAN-77 out of order or array not for statement function 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 sequence number ION 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 20 GO TO 10 DO 10 10 CONTINUE 20 CONTINUE IFL Opt - infinite loop. Optimization discontinued IMN IMPLICIT NONE INC Extension to Fortran-77: INS VMS incompatibility: /NOCREF switch INS VMS incompatibility: /CREF switch INS VMS incompatibility: Default for VMS is /NOLIST INCLUDE statement C-IO COMPILER MESSAGES IUA Illegal use of an array - use scalar variable instead KIS Obsolete switch /KI KWU Fortran·-77 and VMS: Keyword [keyword name] KWV Fortran-77 and VMS: Keyword value for LID Identifier [name] more than six characters [keyword name] The remaining characters are ignored. LNC Fortran·-77 and VMS: Non-numeric operand in numeric context LNE VMS incompati bi 1 i ty: EQUIVALENCE-d LOL VMS incompatibility: List .of labels LSP Extension to Fortran-77: MBD IMPLICIT NONE - MLN Fortran·--77 and VMS: Mixing logical and numeric MSL Fortran-77 and VMS: Multi-statement line MVC Number of variables [is less than/is numbers of constants in DATA statement NAM Extension to Fortran-77: NAMELIST statement NDP Fortran-77 and VMS: No decimal places with edit descriptor NEC Extension to Fortran-77: context NED No END statement in program NIB Extension to Fortran-77: Non-integer substring bounds NIG Extension to Fortran-77: Non-integer as GOTO NIK Extension to Fortran-77: Non-integer used with [keyword] NIS Extension to Fortran-77: Non-integer subscript NIX Extension to Fortran-77: Non-integer as index to RETURN NLC Fortran·-77 and VMS: Non-lo9ical operand in logical context NLK Extension to Fortran-77: Use of NAMELIST NOD Global optimization not supported with /DEBUG - NOF No output file given NPC VMS incompatibility: Null padding before [symbolic name] NPP Extension to Fortran-77: list NSC Fortran-77 and VMS: Non-standard character in column 1 L.og ical and [data type] numer ic variables length specifier [variable] must be explicitly declared Numeric No C-ll greater expression parentheses index than] in to the character computed /OPT ignored around PARAMETER COMPILER MESSAGES OCU Fortran-77 and VMS: Octal constant OHC Octal or hexadecimal constant 010 Extension to Fortran-77: 010 Fortran-77 and VMS: PAV PARAMETER used as associative variable PLP PARAMETER list must be enclosed in parentheses PPS PROGRAM statement parameters ignored [statement name] [statement name] statement statement Used for compatibility purposes. PSR Pound sign (#) instead PWS Fortran-77 and VMS: PRINT (Specifiers) RDI Attempt to redeclare implicit type RIM RETURN statement illegal in main program RLC Extension to Fortran-77: & used with return label RLC Fortran-77 and VMS: $ used with return label RLX Fortran-77 and VMS: Return label [label] SBC Extension to Fortran-77: Substring bounds not constant SEP VMS incompatibility: name or entry point SID Slash (I) SMD Extension to Fortran-77: Single multi-dimensioned array [array name] SNN VMS incompatibility: name SOD [name] SOR Fortran-77 and VMS: Subscript out of range for array name] SPN VMS incompatibility: PARAMETER name SRO Fortran-77 and VMS: Symbolic relational operator [operator] SVN VMS incompatibility: function name TLF Fortran-77 and VMS: TSI Type of symbolic constant ignored VAl [name] in random access - use REC= or apostrophe (') [symbolic name] in dimension bound - statement is the same as use colon (:) [symbolic name] program instead with subscript is the same as NAMELIST statement out of order [symbol ic name] [symbolic name] is C-12 same as is same as variable or Two-branch logical IF already initialized the [array COMPILER MESSAGES VFS VMS incompatibility: routine on VMS [function name] is VGF VMS incompatibility: on VMS [function name] is a VIF VMS incompatibil i ty: function on VMS [function VND FUNCTION return value is never defined VNF VMS incompatibility: function on VMS [function name] VNG VMS incompatibility: f unct ion on VMS [func t i on VNI Opt - variable [name] a name] Fortran-supplied generic function an intrinsic an intrinsic is is name] not is not a generic is not initialized The optimizer analysis determined that the given variable was never initialized prior to its use in a calculation. VNS VMS incompatibility: subroutine VSD VMS incompatibility: Subroutine [subroutine name] WDU Fortran·-77 and VMS: wRITE wi th defaul t WNA Wrong number of WOP Opt - warnings given in phase incorrect [subroutine name] argu~ents is not a VMS-supplied may differ uni t for statement function 1. Optimized code may 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 1esired. XCR Extraneous carriage return Carriage return was not immediately preceded or followed a line termination character. XEN Fortran--77 and VMS: XOR Extension to Fortran-77: Logical ZMT Size modifier [* or ,&] [number] by with external name .XOR. operator treated as [data type] This message is issued when one of the data type size modifiers that is accepted only for compatibility is used. Internal Compiler Errors An internal compiler error is an attempt by either the compiler or the monitor to document an err~r inside the FORTRAN compiler. An occurrence of an internal compiler error signifies that something is wrong with the FORTRAN compiler. C-13 COMPILER MESSAGES Monitor-detected internal errors are of the form: ? ? ? Internal compiler error [message] at location [address] in phase [segment] While processing statement [line-number] where [message] can be one of the following for TOPS-IO: Illegal memory reference A read or write was attempted to a non-existent page Stack exhausted Monitor detected PDL overflow Memory protection violation Illegal reference to high segment or where [message] can be one of the following for TOPS-20: Illegal memory reference A read was attempted to a non-existent page Non-existent memory write A write was attempted to a non-existent page Illegal memory read A memory read failed Illegal memory write A memory write failed Stack exhausted Monitor detected PDL overflow Compiler-detected errors are of the form: ? Internal compiler error-processing statement [line-number] ? Call to [routine-name] from [address] Submit an SPR if you receive an internal compiler error. At the end of program unit compilation, the compiler prints summary line, which is one of the following: [ No error detected ] %FTNWRN no warning(s) %FTNWRN [warning count] warnings(s) ?FTNFTL [fatal count] fatal error(s) ?FTNFTL [fatal count] fatal error(s) warning (s) C-14 an and no warning(s) and [warning count] error APPENDIX D 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 during a file 3. Arithmetic fault calculations errors 4. Library errors (LIB) routines 5. Data errors (DAT) - errors in data conversion on I/O 6. Device 7. Compatibility errors compatibility flagger I~rrors (DEV) (APR) - errors errors generated by OPEN in numer ic FORLIB library - I/O hardware errors (COM) - errors generated by the The messages generated by FOROTS contain the following elements: 1. A 3-letter code that identifies the type of message only) 2. The message encountered 3. For I/O errors, two integer values which are retrieved by the ERRSNS subroutine 4. For compatibility errors, a prefix precedes the message that describes the type of incompatibility the messages refers to; one of the following: itself, which • Extenstion to FORTRAN-77: • VMS incompatibility: • FORTRAN-77 and VMS: describes See Section 16.6 for more information flagger .. D-1 what on the (TOPS-IO FOROTS has compatibility FOROTS ERROR MESSAGES The 3-letter code (TOPS-I0 only) and the message are, by default, printed at your terminal when an error occurs; the two ERRSNS values are stored within the arguments you have supplied for the ERRSNS subroutine. If you do not include a call to the ERRSNS subroutine in your program, your program cannot have access to the two ERRSNS values. (For instructions on how to use the ERRSNS subroutine, see Section 13.4.1.15.) Table D-l contains a list of all the 3-letter message ERRSNS values that are generated by FOROTS. Table D-l: 1st Value codes and the FOROTS Error Codes 2nd Value(5) Code(l) Meaning - No error detected No error detected 0 0 IDC ( 3 ) Arithmetic trap Integer divide check IOV (3 ) Input Conversion Error Integer overflow n (7) FOV (3 ) Input Conversion Error Floating overflow n (7 ) FOV (3 ) Arithmetic trap Floating overflow n (7) FDC ( 3 ) Arithmetic trap Floating divide check n (7 ) FUN Arithmetic trap Floating underflow n (7 ) FUN (3) 1 n (7 ) --- 2 n (7) --- 3 4 - 5 6 (3) 7 Input Conversion Error Floating underflow --- Output Conversion Error field width too Output small 9 0 FTS (3 ) - 21 104 IDU 105 106 UNO NOF 107 CWU 108 CLE 109 ICE 110 NCS FORLIB errors and warnings DIVERT: illegal to divert to unit DIVERT: unit not open DIVERT: unit not open for formatted I/O DIVERT: Can't write to unit Concatenation result longer than expected Illegal length character expression stack No character allocated D-2 FOROTS Table D-l: 1st Value ERROI~ MESSAGES FOROTS Error Codes (Cont'd) 2nd Va 1 ue (5) Code (1) Meaning 112 AQS 113 114 11 ~; SSE (3) SRE (3) TMA 116 CGP 117 CRP (1) lIE: NSS (2) 119 120 121 CFS CGS CPP (2) (2) (3) 122 123 IPN CCS 124 ECS First argument of SORT must be a quoted string Substring range error Subscript range error Too many arguments in call to SORT Can't get pages 600:677 for SORT Can't return pages 600:677 after call to SORT No free section available for SORT Can't find SYS:SORT.EXE Can't get SYS:SORT.EXE Can't preallocate pages 600:677 for SORT Illegal page number Not enough memory for creating character stack Not enough memory for expanding character stack Argument less than or equal to zero Must give lower and upper bounds to dump in non-zero sections ALZ 126 DMA (2,3) 509 ETL ': 3) 532 583 ARC ': 3) FVM (3) 584 RIF (3) 590 DQW (2,3) 22 I/O warnings Attempt to WRITE beyond fixed-length record Ambiguous repeat count Format and variable type do not match Reading into FORMAT non-standard Disk full or quota exceeded - Please EXPUNGE, then type CONTINUE 113 114 SSE f 3) SRE f 3 ) FORLIB bounds check warnings Substring range error Subscript range error -1 EOF End of file End of file 23 24 25 302 510 BBF RNR 512 517 IRN RTL 536 CBI 536 CSI Record or record number error Bad format binary file Attempt to read a record that has not been written Illegal record number Record too large memory full Cannot backspace image file with no RECORDSIZE Cannot skiprecord image file with no RECORDSIZE D-3 FOROTS ERROR MESSAGES Table D-l: 1st Value FOROTS Error Codes (Cont.) 2nd Val ue (5) Code(l) Meaning 570 ICD 572 RSM 573 FCL 576 WBA 577 SLN Non-digit in record delimiter Record size different from that specified in OPEN Unexpected continuation LSCW found Attempt to WRITE beyound variable or array Record length negative or zero ~------+------~------~------------------.---I 26 502 CSF (2,3) 535 BS I 541 UOA (3) 542 NCK (3) 550 CQF (1,3) OGX (1,3) 595 (3 ) OPEN/CLOSE warnings Can't set FORTRAN carriage control attribute BLOCKSIZE ignored: device is not a magnetic tape Unknown OPEN keyword, ignored OPEN-only keyword specified in CLOSE, ignored Cannot QUEUE file Galaxy version 2 not supported ~-------+--------~r-'----------4-------------------------------~ 28 J J 250+n 250+n 250+n C LF (2) RNM CLS DEL RNM (1) (1) CLOSE error Cannot CLOSE file Cannot RENAME file "Close" FILOP. error n (4) "Delete" FILOP. error n (4) "Rename" FILOP. error n (4) (2) (1) 30 OPEN error Cannot set up to append to magnetic tape file 240 FRR /RECORDTYPE:FIXED requires /RECORDSIZE 240 RRI Random I/O requires RECORDSIZE specifier in OPEN statement 240 RRR Random I/O requires /RECORDSIZE 242 NFC (1) Too many OPEN units 243 CIR /CARRIAGECONTROL:TRANSLATED illegal with this /RECORDTYPE 244 RLB /RECORDSIZE larger than /BLOCKSIZE 245 NSD No such device 248 lAC Specified ACCESS illegal for this device 249 IDM Specified MODE is illegal for this device 250+n OPN (1) Cannot OPEN file 405 PPN (2) JSYS error - PPN cannot be translated 503 CEF (2) End of command file _ _ _ _ _ _- i_ _ _ _ _ _L -_ _ _ _ _ _ _ _L -_ ___________________________ encountered J ~ APP (2) D-4 ~ FOROTS ERROR MESSAGES Table 0-1: FOROTS Error Codes (Cont.) ··----r- 1st Value 2nd Va 1 ue (5) Code(l) Meaning 506 540 ICA SDO 569 TFM 585 IAV Incompatible attributes Same device open on another unit with conflicting spec i fiers Tape format conflicts with OPEN statement or default Illegal value for OPEN spec i fier 31 ~) CDR 31 ~) CDS 593 POI 594 CDF 239 IUN 321 CFC (3) 322 CFF (3) 323 CFR (2,3) 323 CFX (2,3) 323 CFR (1,3) 323 CFX (1,3) 32~1 CFK (3) 32~i CFT (3) 326 CFO (3) 327 CFG 310 RBR 31 Mixed ACCESS modes Can't do direct I/O to sequential file Can't do sequential I/O to direct file Illegal for DIRECT (RANDOM) files Can't determine whether formatted or unformatted 32 Illegal logical unit number Illegal unit number 33 39 (3) Compatibility error FORTRAN-77 and VMS: Carriage control character VMS incompatibility: Intrinsic routine invoked incompatibly FORTRAN-77 extension: FORTRAN-20 supplied routine invoked FORTRAN-77 and VMS: FORTRAN-20 supplied routine invoked FORTRAN-77 extension: FORTRAN-IO supplied routine invoked FORTRAN-77 and VMS: FORTRAN-IO supplied routine invoked FORTRAN-77 and VMS: Keyword [keyword] FORTRAN-77 and VMS: Trailing spaces in output record extension: FORTRAN-77 Overlap of character assignments FORTRAN-77: and VMS: G format descriptor used with character REREAD error REREAD not proceeded READ by FOROTS ERROR MESSAGES Table D-l: 1st Value FOROTS Error Codes (Cont.) 2nd Val ue (5) Code(l) Meaning 45 OPEN/CLOSE statement syntax errors Unknown or ambiguous keyword Unknown swi tch Ambiguous switch Dialog string too long Error parsing DIALOG string No device specified with 241 ESV 241 241 533 539 544 USW (1) ASW (1) DLT EDS/EDA (2) NDI (1) 545 546 547 548 IPP TMF NS I IDD (1) (1) (1) (1) Illegal PPN Too many SFDs Null SFD Illegal character in DIALOG str ing 551 NQS (1) PADCHAR must be single character in double quotes 263 CDT 554 CWL 301 306 ILF DLF 524 RIC 538 552 553 575 IRC IHC IFW UDT 583 FVF 307 ILC 501 508 574 579 581 582 UNS IOL IMV I DI (1 ) DLL (1) IWI 599 ICE 47 .. : " WRITE on READ-only file Cannot WRITE to READ-only file Cannot write a file with MODE=LINED 62 Syntax error in FORMAT Illegal character in FORMAT Data in I/O list but not in FORMAT Reading into character format illegal Illegal repeat count Illegal Hollerith constant Illegal field width Undefined data type or internal FOROTS error Format and variable type do not match 64 Input conversion error Illegal character in data 81 FOROTS calling errors Unit not specified Bad I/O list Illegal MTOP value Illegal DUMP mod~ I/O list Dump mode I/O list too long Illegal to initiate another I/O statement Illegal length for character expression D-6 FOROTS ERROR MESSAGES Table 0-1: 1st Value FOROTS Error Codes (Cont.) 2nd Va 1 ue (5) Code(l) Meaning 96 530 537 I LM UMO UTE UTO 537 UTO (1,3) 587 ITE (1) 309 513 VNN NEQ 514 515 NRP ILN 516 519 I LS CCC 521 522 RPE SNV 580 596 NLS NEC 597 ISS 598 SNQ J J (2) (2,3) (1) (1) 97 NAMELIST data errors Variable not in namelist "=" not found in namelist data Missing right paren Variable or namelist does not start with letter Illegal subscript Cannot convert constant to correct type Illegal repeat count Sign with null value Null string illegal Found character when expecting ":" Substring descriptor illegal String not within single quotes 98 J J J 250+n 250+n 400 586 590 ISW IOE OSW ISW OSW IOE MFU DQE Error in magnetic tape operations Unexpected MTOPR% error (2) Error trying to set tape Unexpected TAPOP. error Unexpected TAPOP. error trying to set parameters Unexpected TAPOP. error trying to set parameters Tape is not usable by your job Unclassifiable device errors Cannot switch to input General purpose I/O error Cannot switch to output Cannot switch to input Cannot switch to output General-purpose I/O error Memory full Disk full or quota exceeded (2) (2) (2) (1) (1) (1) (2) No ERRSNS values B LK (3,6) CCP CDP CGD DBM DST (1,6) (1,6) (6) (6) (1,6) D-7 Blocks allocated but deallocated Cannot create page Cannot destroy page Can't get DBMS DBMS not loaded Error in dialog string not FOROTS ERROR MESSAGES Table D-1: 1st Value FOROTS Error Codes (Cont.) 2nd Val ue (5) Code(l) Meaning EFS (6 ) FFX (6 ) Enter correct file specs FOROP function code exceeds range Error in memory management "Impossible" JSYS error Memory full Error number out of range Pages allocated but not deallocated Deallocating more pages than allocated PDL overflow Internal FOROTS error Trap occured during trap processing IEM IJE MFU NOR PAG (6 ) (2,6) (6 ) ( 3 ,6) (3,6) PGD (6 ) POV (6) SNH (6) TDT (6) (1) TOPS-I0 only (2) TOPS-20 only (3) This is a warning, not an error. The error cannot be trapped with an ERR= branch, but IOSTAT and ERRSNS will be set. (4) See the TOPS-IO Monitor Calls Manual FILOP. error codes and their meanings. ( 5 ) " J " mea n s the TOP S - 2 0 J S YS err 0 r cod e • be between 600000 and 610000 (octal). for the list of Th i s n urn b e r will (6) No ERRSNS values (7) Where n is the number of times the error occurs 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 Section 13.4.1.14). The I/O errors either cause messages to be printed on the terminal or can be trapped by an error exit argument (ERR=statement number) on OPEN, READ, WRITE, and CLOSE. The FORTRAN Library Subroutine ERRSNS (see Section 13.4.1.15) aLlows you to find out which I/O error occurred. When called, ERRSNS rE!turns one or two integer values that describe the status of the last I/O operation performed by FOROTS. (The second integer value is optional.) For example, CALL ERRSNS (I,J) calls this subroutine. J, the second integer value, is optional. D-8 FOROTS ERROR MESSAGES D.l ALPHABETICAL DESCRIPTION OF FOROTS MESSAGES This section contains alphabetical descriptions of each warning and fatal error message that is generated by FOROTS during program execution. Each message is first listed; then is followed by a brief description of how it is generated; followed by, in some cases, a recovery procedure; and finally, where applicable, followed by the ERRSNS values associated with the message. ALZ? Arg umen t less than or Cause: to zero E~qual An argument (sllch as a memory size) was specified a value less than or equal to zero. with Recovery: Specify the correct value for the argument. APP? onl y) = 21 Second Value = 125 file error) (TOPS-20 The MTOPR% JSYS failed trying to position the tape with the function .MOFWF or .MOBKR. magnetic ERRSNS val UE!S: First Value Can't setup to append to magtape Ca use: <JSYS Recovery: Use the information provided to determine a recovery. ERRSNS valUES: First Value = 30 Second Value = JSYS error number AQS? First argument to SORT must be a quoted string Cause: The SORT routine detected that the first argument was of type CHARAC~'ER, but the string was not word aligned. Recovery: If the first argument to the SORT program is of type CHARACTER, it must be word aligned and terminated by an ASCII null. The most. reliable way to generate such an argument is to use a character constant. ERRSNS values: First Vc:lue 21 Second Value = 112 ARC % Ambiguous repeat count Cause: In a FORMAT statement, a number between two format specifiers can be considered belonging to either one. Recovery: Insert a comma before or after the number, depending on which specifier the number belongs with. ERRSNS values: Fir s t Va 1 ue = D-9 22 Second Value = 532 FOROTS ERROR MESSAGES ASW? Ambiguous switch /<sw> Cause: (TOPS-I0 only) In dialog mode, a switch was specified, but not enough of the switch was given to uniquely specify which switch was intended. Recovery: Retype the line, completely specifying which switch you mean. ERRSNS values: BBF? First Value 45 Second Value 241 Bad format binary file Cause: The control information stored in a binary file is incorrect. The file cannot be read using MODE='BINARY'. This error can be caused when the file you are reading was not written by FORTRAN using MODE='BINARY' • Recovery: Make sure that you are using the correct file and mode. Any file can be read with MODE='IMAGE'. Section 11.3.19) ERRSNS values: First Value 25 Second Value data (See 302 BLK % Pages allocated but not deallocated Ca use: Internal FOROTS error in memory management. Recovery: Submit an SPR and include your program. BSI % Blocksize ignored: Cause: A BLOCKSIZE specifier was given in an OPEN statement (see Section 11.3.4) but was not used because the device being opened is not a magnetic tape. ERRSNS values: CBI? device is not a magnetic tape First Value = 26 Second Value = 535 Can't BACKSPACE IMAGE file with no RECORDSIZE Cause: An OPEN statement with the MODE='IMAGE' specifier (but not the RECORDSIZE= specifier) was executed prior to a BACKSPACE statement that referred to the open unit. Recovery: If you are using fixed-length records, specify the RECORDSIZE parameter in the OPEN statement (see Section 11.3.27). Otherwise, the BACKSPACE cannot be done. ERRSNS values: First Value = 25 D-I0 Second Value = 536 FOROTS ERROR MESSAGES CCC? Can't convert constant to correct type In NAMELIST input, a variable was assigned a value that does not match. For example, if C is a complex variable, the input: Ca use: C=.TRUE. is in error, number. since .TRUE. is not a legal complex Recovery: Correct the error in the source program. ERRSNS values: CCP? Can't create page <n> (PAGE. error <n» (TOPS-IO only) FOHOTS attempted to use a page of memory for some task, but was unabl~ to. The monitor error code gives the reason. This can be caused by erroneous MACRO subroutines. If no such cause is found, it is an internal FOROTS error. Cause: CCS? Second Value = 519 First Value = 97 Not enough memory for creating character stack A character stack was requested that was larger than 36 sections (larqer that the maximum virtual memory aVcdlable) • Ca use: Recovery: Specify correct call argument. ERRSNS values: CDF? The specified file has had both formatted and unformatted I/O operations (or OPENs) performed on it. Recovery: Use I/O operations specifier. and OPENs ERRSNS values: 31 Second Value Can't destl~oy Ca use: CDR? 124 Second Value Can't determine whether formatted or unformatted Cause: CDP? First Value = :21 First Value page <n> (PAGE. error <n» with the same FORM= 594 (TOPS-IO only) FOHOTS attempted to use a page of memory for some task, but was unabll~ to. The monitor error code gives the reason. This can be caused by erroneous MACRO subroutines. If no such cause is found, it is an internal FOROTS error. Can't do direct I/O to ::iequential file Cause: An attempt was made to perform I/O to already open in a conflicting mode. Recovery: a file Second Value 315 Open file in the appropriate mode. ERRSNS values: Fir s t Va:!. u e = 3 1 D-ll that is FOROTS ERROR MESSAGES CDS? Can't do sequentail I/O to direct file Cause: Recovery: An attempt was made to perform I/O to a already open in a conflicting mode. is First Value = 31 Second Value 315 Can't <read/write> an <input/output>-only file Cause: An attempt was made to perform I/O to a file, but the file is not open for I/O in the appropriate direction. Recovery: Open the file with ACCESS='SEQINOUT' or 'RANDOM', as appropriate. It is not possible to open a file for APPEND access and then read from it. (See Section 11.3.1.) ERRSNS values: CEF? that Open file is the appropriate mode. ERRSNS values: CDT? file Fi rst Val ue 47 End of command file encountered Second Value (TOPS-20 only) Ca use: An indirect file was specified as and the end of the file was terminator character (line-feed). Recovery: Edit the file and insert a line-feed. ERRSNS values: First Value = 30 CFC % Fortran-77 and VMS: 263 a DIALOG argument, encountered before a Second Value 503 Carriage control character Cause: A carriage-control character was used that incompatible with ANSI FORTRAN and VAX FORTRAN. Recovery: If you want the program to be compa ti bl e FORTRAN or VAX FORTRAN, use a carriage-control character. ERRSNS values: First Value = 33 CFF % VMS incompatibility: Second Value is wi th ANSI compatible 321 Intrinsic routine invoked incompatibly Ca use: An intrinsic routine was invoked in a method incompatible with VAX FORTRAN (such as use of an EXTERNAL statement for an intrinsic function). Recovery: If you want the program to be compatible with VAX FORTRAN, change to a method of invoking intrinsic routines that is compatible with VAX. ERRSNS values: First Value = 33 D-12 Second Value 322 FOROTS ERROR MESSAGES CFG % Fortran-77 and VMS: G format descriptor used with character Ca use: The G format descriptor was used with character data, which is an extension to ANSI FORTRAN and VAX FORTRAN. Recovery: If you want the program compatible with ANSI FORTRAN or VAX FORTRAN, do not use the G format descriptor to edit character data. ERRSNS values: First Value CFK % Fortran-77 and VMS: Second Value 327 Keyword [keyword] Cause: An OPEN or CLOSE: keyword was used that is wi th ANSI FORTRJ,N and VAX FORTRAN. Recovery: If you want the program compatible with ANSI FORTRAN or VAX FORTRAN, USE a compatible OPEN or CLOSE keyword. ERRSNS values: First Value = 33 CFO % Fortran-77 extension: incompatible = 324 Second Value Overlap of character assignments Cause: A character assignment statement was used in which the character positions defined in the character variable, array element or substring on the left of the equal sign are refer~nced in the character expression on the right of the equal sign. This is incompatible with ANSI FORTRAN. Recovery: If you want the program to be compatible with ANSI FORTRAN, use a character assignment statement that does not overlap the character expression and the character variable, array element, or substring. ERRSNS values: CFR % Fortran-77 (TOPS-20 only) CFR % Fortran-77 (TOPS-IO only) Fir s t Va 1 ue = 33 Second Value 326 extension: FORTRAN-20 supplied routine invoked extension: FORTRAN-IO supplied routine invoked Ca use: A FORTRAN-IO/20-supplied subroutine was invoked that is not available with ANSI FORTRAN. Recovery: If you want your program to be compatible FORTRAN, use a compatible subroutine. ERRSNS values: CFS? 33 First Value Can't find SYS:SORT.EXE Ca use: = 33 Second Value <JSYS error> (TOPS-20 only) Recovery: Use the information provided by the determine the proper course of action. First Value = 21 D-13 ANSI 323 The file SORT.EXE cannot be found on SYS:. A supplied error message will give more detail. ERRSNS values: to Second Value monitor monitor 119 to FOROTS ERROR MESSAGES CFT % Fortran-77 and VMS: Trailing spaces in output record Cause: Your program contains a FORMAT that specifies trailing blanks (X format and $ format). In this case, FORTRAN-IO/20 preserves the trailing spaces. Recovery: If you want the program compatible with ANSI FORTRAN and VAX FORTRAN, do not use this form of the FORMAT statement. ERRSNS values: First Value 33 Second Value 325 FORTRAN-20 supplied routine invoked CFX % Fortran-77 and VMS: (TOPS-20 only) FORTRAN-IO supplied routine invoked (TOPS-IO CFX % Fortan-77 and VMS: only) Cause: A FORTRAN-IO/20-supplied subroutine was invoked that is not available with ANSI FORTRAN or VAX FORTRAN. Recovery: If you want the program to be compatible with ANSI FORTRAN or VAX FORTRAN, use a compatible subroutine. ERRSNS values: CGP? First Value = 33 Second Value = 323 Can't get pages 600:677 for SORT Cause: The SORT subroutine brings the SORT program into core in pages 600 through 677. Some of these pages were already occupied by programs or data at the time that SORT was called. Recovery: Decrease the size of your program. Having fewer files open or using a BUFFERCOUNT=l specifier in OPEN statement may help (see Section 11.3.5). If this does not help, you can segment the program by using LINK's overlay facility (see the LINK Reference Manual). ERRSNS values: CGS? First Value = 21 Can't get SYS:SORT.EXE Ca use: Second Value <JSYS error> (TOPS-20 only) The file SORT.EXE was found on SYS:, however for some reason it could not be merged into your program in order to sort files. A monitor supplied error message will give more detail. Recovery: Use the information provided by the determine the proper course of action. ERRSNS values: CIR? = 116 First Value = 21 Second Value monitor 120 /CARRIAGECONTROL:TRANSLATED illegal with this /RECORDTYPE Ca use: Recovery: ERRSNS values: First Value 30 D-14 Second Value 243 to FOROTS ERROR MESSAGES CLE? Concatenation result larger than expected Cause: The specified substring bounds are out of range. Recovery: Specify legal substring bounds. ERRSNS values: CLS? First Va]ue = 21 CLOSE failed, <I/O error message> Cause: Second Value 108 (TOPS-IO only) A CLOSE UUO. or FILOP. CLOSE function failed. Recovery: Use the informat.ion provided to determine a recovery. ERRSNS values.: First Value = 28 Second Value = 250+n CPP % Can't preallocate pages fiOO:677 for SORT Ca use: A call to preallocate allocated. the SRTINI subroutine was SOHT's pages because they unable to were already Recovery: Decrease the si~e of your program. Having fewer files open or using a BUFFERCOUNT=l specifier in the OPEN statement may help (sE!e Section 11.3.5). ERRSNS values: CQF % Can't queue file: Cause: First Value = 21 Second Value QUEUE. VUO ERROR <N> (TOPS-lO only) This error may occur \lihen executing a CLOSE statement in which the DI~)POSE specifier is given with one of the values: 'LIST', 'PRINT', or 'PUNCH', and GALAXY release 4 is running. (See Section 11.5.4.) Recovery: Refer to the TOPS-H) Monitor Calls Manual ex pIa nat ion 0 f ~: h e QUE UE. err 0 r n urn be r < n> • ERRSNS values: CRP? 121 Fir s t Va :~ ue = 26 for an Second Value = 550 Can't return pages 600:1)77 after call to SORT (TOPS-IO only) Cause: Before the SORT subroutine returns to the user, it tries to deallocate the pages that the SORT program resides in. Th,= pages could not be deallocated. This is not expected to occur. Recovery: Submit an SPR. ERRSNS values: First Value 21 D-15 Second Value 117 FOROTS ERROR MESSAGES CSF % Can't set FORTRAN carriage control attribute Cause: (TOPS-20 only) You are running a TOPS-20 system that does not have Edit 2981, which allows support for the FORTRAN carriage-control attribute. Recovery: Autopatch the monitor to include Edit 2981. ERRSNS values: CSI? First Value = 26 Second Value = 502 Can't skiprecord image file with no RECORDSIZE Cause: A SKIPRECORD statement was executed for a file opened with MODE=IMAGE, and the file did not have a RECORDSIZE(RECL) specified. Since there are no record markers in IMAGE mode files, FOROTS cannot determine how far to skip. Recovery: Add a RECL= specifier (see Section 11.3.27) to the OPEN statement. ERRSNS values: CWL? First Value 25 536 Can't write a file with MODE='LINED' Cause: The program attempted to execute an output operation such as a WRITE statement after an OPEN statement for the same unit. The OPEN statement contained a MODE='LINED' specifier. Recovery: Change the OPEN statement (See Section 11.3.20.) ERRSNS values: CWU? Second Value DIVERT: Cause: First Value = 47 specifier to Second Value MODE='ASCII'. 554 Can't write to unit <n> DIVERT file is not opened for output. Recovery: Open DIVERT file for output. ERRSNS values: DBM? First Value = 21 Second Value 107 DBMS not loaded Cause: A DBMS call to a sharable FOROTS was attempted DBMS. without Recovery: The system manager must build DBMS into sharable FOROTS or remove the file from FORLIB that directs the DBMS call to the sharable FOROTS. D-16 FOROTS ERROR MESSAGES DEL? Can't delete file:(FILOP. Ca use: error message> The "DELETE" FILOP. failed. (TOPS-IO only) The file is not deleted. Recovery: Usually you can correct the problem when the program is finished and delete the file with the monitor DELETE command. ERRSNS values: First Value 28 Second Value 250+n DLF % Data in 10 list but not in format Cause: An I/O statement has requested data to be but the FORMAT statement does not descriptor that would translate the data. Recovery: Fi~ the FORMAT statement. following descriptors: transferred, specify any It must contain one of the A,B,E,F,G,I,L,O,Q,R,Z ERRSNS values: DLL? = 62 First Value DUMP mode I/O list too long Ca use: Second Value (TOPS-IO only) The I/O list sfecified for a DUMP mode READ or WRITE statement is too long for the FOROTS internal DUMP mode control list. Recovery: Split the I/O list across two or statements. ERRSNS values: First Value 81 more READ Second Value 581 DMA % Must give lower and upper bounds to dump (TOPS-20 only) Ca use: 306 in non-zero or WRITE sections A call to PDUMP or DUMP was made without specifying memory bounds. In section zero, this is interpreted as 'all of memory'. For extended addressing, lower and upper bounds must be specified. Recovery: Specify lower and upper bounds for memory_ ERRSNS values: DQE? Disk full or quota Cause: = 21 First Vclue Second Value = 126 exc~eded The disk quota for the disk on which a file is being written is e~hausted, or the entire disk structure is full. If this error is encountered while running under batch, the program is aborted and an attempt is made to close all files. If this error is encountered while timesharing, t.he user is requested to type an EXPUNGE command and then a CONTINUE command. Recovery: EXPUNGE or create structure. more First Value 98 ERRSNS values: D-17 room on the Second Value specified 590 disk FOROTS ERROR MESSAGES DQW % Disk full or quota exceeded (TOPS- 20 onl y) Cause: Please EXPUNGE, then type CONTINUE The file or files being written on the disk have either exhausted your disk quota or filled the structure. Recovery: FOROTS leaves the terminal at EXEC level so that you have more options to use to provide space on the disk structure. You can type CONTINUE to resume processing if you don't reset the current fork. ERRSNS values: First Value = 22 DSS % DISPOSE='SAVE' assumed Cause: device is not a disk First Value Error in dialog string Cause: 590 A DISPOSE value other than 'SAVE' was specified fa r a Section file on a device other than disk. (See 11.3.13.) ERRSNS values: DST? Second Value 26 Second Value 549 (TOPS-IO only) A syntax error in the DIALOG= specifier. Recovery: Correct the error in the program (See Section 11.5.3.) or in DIALOG mode. DTL % Dialog string too long Cause: The argument to DIALOG= cannot be parsed because it too long. is Recovery: Use a shorter string. ERRSNS values: ECS? First Value = 45 Second Value 533 Not enough memory for expanding character stack Cause: More memory than is available on a KLI0 was requested by either a dynamic concatenation (concatenation of character variables of length*) or by a call to the ALCCHR subroutine. Recovery: Reduce the size of your concatenation or argument to ALCCHR. If you are running extended addressing, you can present parts of the character stack by invoking SORT and dynamic libraries at the beginning of the program. ERRSNS values: EDS/EDA? Ca use: 21 First Value Error in DIALOG string - Second Value <message> 124 (TOPS-20 only) A syntax error in the DIALOG= specifier. 11.5.3.) (See Recovery: Retype the specifier correctly in DIALOG mode. ERRSNS values: First Value = 45 D-18 Second Value = 539 Section FOROTS ERROR MESSAGES EFS [ Enter correct file specs ] Cause: Dialog mode. You should respond to this message by entering any information you wish to change about the indicated file. This can include the device, filename, directory, or any OPEN parameter. The form of a response is: TOPS-IO TOPS-20 DEV:FILE.EXT[DIRECTORY] /SWITCH:VAL /SWITCH:VAL DEV:<DIRECTORY)FILE.EXT.GEN /SWITCH:VAL /SWITCH:VAL All parts of this specification are optional. EOF? End of file Cause: ESV? An input statement has attempted to read more data than the file contains. Recovery: Use an END= specifier lengthen the file. in ERRSNS values: Second Value Fi rst Va I ue 24 the READ statement, -1 <unknown/ambiguous> keyword value /<switch>:<value> only) Ca use: A switch entered in dialog mode was not was not specified uniquely. or (TOPS-20 recognized or Recovery: Retype the line, specifying the correct switch. ERRSNS values: First Value = 45 Second Value = 241 ETL % Attempt to write beyond fixed-length record Cause: In an ENCODE statement, the format specified more characters than the string will hold. The excess characters are ignored. (See Section 10.12.) Recovery: Shorten the format or lengthen the string. ERRSNS values: FCL? First Value = 22 Second Value = 509 Found unexpected continuation LSCW Cause: A RECL(RECORDSIZE) has been specified in an OPEN statement, and FOROTS has encountered a continuation (type 2) logical segment control word (LSCW). This type LSCW is never written in fixed-length binary records. Recovery: Remove the RECL(RECORDSIZE) statement. specification in ERRSNS values: Second Value First Value 25 D-19 573 the OPEN FOROTS ERROR MESSAGES FDC % Floating divide check Ca use: The program contains a floating-point division in which the divisor is too small compared to the dividend to yield a result that is in the floating-point range. Recovery: Correct program so floating-point range. ERRSNS values: FFX? that First Value = 5 division Second Value is wi. thin n where n is the number of times the error occurs FOROP. function code exceeds range Cause: A library routine has called for an operation that is not available. This can be caused by using a mismatched FOROTS and FORLIB, or by an erroneous MACRO subroutine. Recovery: Make sure the versions of FOROTS.EXE and FORLIB.REL that you are loading from are matching versions. If this doesn't help, find the subroutine causing the problem and alter or remove the erroneous call. FOV % Floating overflow Cause: A REAL or DOUBLE PRECISION number was read that is too large in magnitude (see Chapter 3). This is only a warning and does not stop execution of the program. The results of a calculation that overflows are set to the largest representable number with the sign of the correct result. Recovery: Modify the data so that its values fall in the range of values that can be represented for the data type. ERRSNS values: FRR? First Value = 3 or 4 Second Value = n where n is the number of times the error occurs /RECORDTYPE:FIXED requries /RECORDSIZE Ca use: A RECORDTYPE='FIXED' was specified in an OPEN statement without a RECORDSIZE (RECL) specifier. Recovery: Specify RECL 11.3.27) • ERRSNS values: in the First Value 30 D-20 OPEN statement (see Second Value 240 Section FOROTS ERROR MESSAGES FTS % Output field width too small Ca use: The field width specified in a FORMAT statement was not large enough to allow the printing of the value being output. For example, this error would occur if the number 100 is output with the format specifier "12". ERRSNS values: First Value = 9 Second Value = a FUN % Floating underflow Cause: A REAL or DOUBLE PRECISION number was read that is too small in magnitude (see Chapter 3). This only a warning and does not stop execution of the program. The result of a calculation that underflows is set to zero. Recovery: Modify the data so that its values fall in the range of values that can be represented for the data type. ERRSNS values: First Value = 6 or 7 Second Value = n where n is the number of times the error occurs FVF? Format and variable type do not match Ca use: An attempt was made to READ or with other than A or G format. WRITE character Recovery: Specify A or G edit descriptors when reading data. ERRSNS values: First Value 62 Second Value data character 583 FVM % Format and variable type do not match Cause: An I/O statement has been executed that uses a format edit descriptor with a type that does not match the I/O list item being processed. Recovery: Specify the appropriate format edit descriptor for I/O list item. ERRSNS values: lAC? First Value 22 Second Value the 583 /ACCESS illegal for this device Ca use: An attempt was made to OPEN a device for access specified (or implied) is illegal. which Recovery: Change the ACCESS specifier in the OPEN statement data transfer statement. (See Section 11.3.1.) ERRSNS values: First Value = 30 D-21 Second Value = 248 the or FOROTS ERROR MESSAGES IAV? Illegal value for OPEN specifier Cause: An OPEN statement specifier has that specifier. a value illegal for Recovery: Specify a legal value for that OPEN specifier. ERRSNS values: ICA? First Value = 30 Second Value = 585 Incompatible attributes Ca use: An illegal combination specified. of open attributes has been Recovery: Change one or more of the conflicting specifiers. ERRSNS values: ICD? First Value = 30 Second Value = 506 Non-digit in record delimiter Cause: The format of the tape being read is not 'D' (DELIMITED). The Record Control Word (RCW) contained a non-digit, or the data on the tape is incompatible. Recovery: Specify the correct TAPEFORMAT in the OPEN statement. ERRSNS values: ICE? First Value = 25 Second Value = 570 Illegal length for character expression Ca use: A program has specified a zero length or negative length character substring as an I/O list element. Recovery: Fix program to specify a positive length substring. ERRSNS values: First Value = 81 Second Value = 599 IDC % Integer divide check Cause: Program contains an integer division by O. Recovery: Correct division in program. ERRSNS values: First Value = 1 Second Value n where n is the number of times the error occurs IDD? Illegal character <chr> Cause: (TOPS-IO only) An illegal character was encountered in dialog mode. Recovery: Retype the response without illegal characters. ERRSNS values: First Value = 45 D-22 Second Value = 548 FOROTS ERROR MESSAGES IDI? Illegal DUMP mode I/O list Cause: (TOPS-IO only) An I/O list entry has been specified whose entry size (number of words) is different from its increment. This can only happen if an implied DO loop is specified for the I/O list, the index increment is set to a value other than 1, and the program is compiled with /OPTIMIZE. Recovery: Use an index increment of 1, program with /OPTIMIZE. ERRSNS values: 10M? First Value = 81 or do not Second Value the 579 /MODE:<mode> illegal for this device Ca use: Not all devices can do I/O in all modes. terminals cannot do binary I/O. For Recovery: Change the MODE= specifier or the device. 11.3.19.) ERRSNS values: IOU? compile DIVERT: Cause: Fi rst Va 1 ue 30 Second Value example, (See Section 249 illegal to divert to unit <n> Unit specified is an input-only device. Recovery: Specify a unit for which output is legal. ERRSNS values: IEM? First Value = 21 Second Value = 104 FOROTS internal error in memory management Cause: This is an internal error that is not expected to occur. It means that the memory management routines have detected a problem with their control information. Recovery: Submit an SPR. IFW? Illegal field width Ca use: An illegal (negative) FORMAT statement. field width was specified in a Recovery: Specify a legal field width in the FORMAT statement. ERRSNS values: IHC? First Value = 62 Second Value = 553 Illegal Hollerith constant Ca use: A Eormat specification contains an H edit descriptor that is not preceded by a length or does not contain enough characters. Recovery: Use the correct format for an H edit descriptor. Section 12.4.2.) ERRSNS values: First Value 62 0-23 Second Value 552 (See FOROTS ERROR MESSAGES IJE? "Impossible" JSYS error at <PC) Ca use: This is an internal FOROTS to occur. A monitor call to. A monitor-supplied assistance in avoiding the <JSYS ERROR) (TOPS-20 only) error that is not expected failed that was not expected error message may be of problem. Recovery: Submit an SPR. ILC ? Illegal character in data Ca use: A format descriptor that nonnumeric character. requires a number found a with no rerun the operation that Recovery: Fix the input data or FORMAT statement. ERRSNS values: ILF ? First Value = 64 A format specification contains defined meaning. Recovery: Correct the error in the program. ERRSNS val ues: First Value 62 fo rma t character a list Second Value An error was encountered during a file FOROTS did not expect. 301 Recovery: This type of error should not happen. SPR. Please submit an First Value JSYS error number ERRSNS values: 96 Second Value Variable or namelist does not start with letter Ca use: NAMELIST input contains something other than a legal variable or NAMELIST name in a context where a variable or NAMELIST name is required. Recovery: Correct the source program with a (See Section 12.6.) NAMELIST name. ERRSNS values: ILS ? and Unexpected MTOPR% ERROR (TOPS-20 only) Cause: ILN? 307 Illegal character in format Ca use: ILM ? Second Value First Value = 97 legal Second Value variable or 515 Illegal subscript Ca use: In NAMELIST I/O, an illegal subscript was given for array. ERRSNS values: First Value 97 D-24 Second Value 516 an FOROTS ERROR MESSAGES IMV? Illegal MTOP value Ca use: A MARCO program has issued an MTOP call to FOROTS an illegal valuE for the function. with Recovery: Specify a legal function value in the call. ERRSNS values: IOE? First Value = 81 Second Value = 574 <IO error message> Cause: An I/O error has occurred. The monitor error code is given, along with an interpretation of the probable meaning of the error bits. This message normally indicates that the data recorded on an external device has been damaged and cannot be read correctly. ERRSNS values: First Va]ue = 98 Second Value = 400 (TOPS-IO) JSYS error number (TOPS-20) IOL? Bad format IO list Cause: The code generated by the compiler for an I/O list is not. understood by this version of FOROTS. The erroneous entry in the I/O list is ignored. This probably indicates an internal error in the compiler or in FOROTS. prob~em Recovery: Locate the it. area of the I/O Fir s t Va ::. ue ERRSNS values: Bl list and Second Value 508 simplify IOV % Integer overflow Cause: IPP? An attempt was made to read data that was out of for an integer variable. ERRSNS values: First Value Illegal PPN (TOPS-IO only) Ca use: = 2 Second Value range o A directory specification starts with something that is not a legal PPN specification. The forms of legal PPNs a rE~ : [n,n], [n,l, [,n], or [,] where n represents a 1- to 6-digit octal number. Recovery: Use a legal ERRSNS values: dir~ctory First Value D-25 specification. = 45 Second Value 545 FOROTS ERROR MESSAGES IPN? Illegal page number <n> Cause: A call to TOPMEN or SRTINI has specified a page outside the range 1:777. number Recovery: Specify a correct page number ERRSNS values: IRC? First Value = 21 Second Value 122 Illegal repeat count Ca use: An illegal statement. repeat count was given FORMAT a in Recovery: Correct the FORMAT statement. ERRSNS values: IRN? First Value = 62 Second Value 538 Illegal record number <n> Ca use: A direct-access I/O statement has number that is zero or negative. specified a record Recovery: Correct the invalid record number in the program. ERRSNS values: ISS? First Value = 25 Second Value = 512 Illegal substring descriptor Cause: An I/O statement refers to an illegal substring delimiter (substring not within bounds of string). Recovery: Correct the substring specifier. ERRSNS values: ISW? First Value = 97 Second Value 597 Can't switch to input Cause: A file that was being written cannot be open for output. The file is either protected against reading, or has been deleted before the OPEN for read is executed. Recovery: Specify correct protection for OPEN write. ERRSNS values: First Value = 98 Second Value = 250+n (TOPS-IO) JSYS error number (TOPS-20) ITE? Tape is not usable by your job (TOPS-IO only) Cause: A tape unit was specified or implied that is not owned by your job, and is probably owned by another job. Recovery: ASSIGN the drive or MOUNT the tape. ERRSNS values: First Value = 96 D-26 Second Value 587 FOROTS ERROR MESSAGES IUN? Illegal unit number <n> Cause: An I/O statement has specified a unit negative or too large. number that is Recovery: Change the UNIT specifier value and rerun the program. ERRSNS values: IWI? First Value Illegal to initiate <I/O statement) Cause: = 32 another I/O Second Value statement = 239 while processing An I/O statement, STOP statement, or PAUSE statement has been initiated while processing another I/O statement (such as in a function reference used as an I/O list element), or while within a subroutine called as a result of an I/O error through ERRSET. Recovery: Remove the offending I/O statement, STOP statement, PAUSE statement. ERRSNS values: MFU? First Value 81 Second Value or 582 Memory full Cause: There is insufficient memory to complete the program. execution of Recovery: Some memory can be saved by opening fewer files at a time, by using BUFFERCOUNT=l in OPEN statements, and by using minimal tape block sizes. If these techniques do not help, you can segment the program using LINK's overlay facility (see the LINK Reference Manual). NCA? No memory available for character stack Cause: For non-overlay programs, this message indicates that the- memory manager has allocated all available space bet.ween the uselo's 10\<1 segment and FOROTS. For overlay programs, this messages indicates that /SPACE:O has be€~n speci fied to LINK. Recovery: For non-overlay programs, LINK with /OTS:NONSHARE. For overlay programs, specify at least 1000 to the /SPACE switch in LINK (see the LINK Reference Manual). ERRSNS values: First Value = 21 NCK % <keyword> in CLOSE is medningless Ca use: Second Value = III ignored Options have be~n included in the CLOSE statement are meaningless for closing the file. Recovery: Use valid CLOSE options. (See Section 10.17.) ERRSNS values: Second Value = 542 First Value = 26 D-27 that FOROTS ERROR MESSAGES NCS? No character stack allocated - compiler error Cause: An internal compiler error has occurred. Recovery: Submit an SPR. ERRSNS values: NOI? Second Value 110 (TOPS-I0 only) An OPEN statement has specified a null device name. ERRSNS values: First Value = 45 Second Value = 544 Found "<chr>" when expecting ":" Cause: Substring parameters not separated by":" Recovery: Insert a ":" between substring parameters. ERRSNS values: NEQ? 21 No device specified with ":" Ca use: NEC? First Value First Value = 97 Second Value = 596 Found "<chr>" when expecting "=" Ca use: NAMELIST input found an illegal character in a that requires an equal sign. context Recovery: Replace illegal character with equal sign. ERRSNS values: NFC? First Value Too many open units Cause: = 97 Second Value = 513 (TOPS-IO only) On TOPS-I0 monitors before version 7.00, at most, 16 units can be open at the same time. only Recovery: Arrange the program so that it never needs to have more than 16 simultaneously open units. ERRSNS values: NLS? First Value = 30 Second Value 242 Null string illegal Cause: An attempt was made to input to a during list-directed input. zero length string Recovery: Insert characters into the string, or remove the string delimiting quotes. ERRSNS values: NQS? First Value 97 Second Value PAOCHAR must be single char in double quotes Cause: 580 (TOPS-IO only) In dialog mode, the PAOCHAR specifier must be by the pad character in double quotes. ERRSNS values: Fir s t Va 1 ue = 45 0-28 Second Value 551 followed FOROTS ERROR MESSAGES NRP? Missing right paren Cause: In NAMELIST or list-directed complex input, the closing right parenthesis that ends a complex number was not found. ERRSNS values: NSD? First Value 97 Second Value 514 No such device <dev> Ca use: The specified device does not exist. Recovery: Change the device name to one that does exist. ERRSNS values: NSI? = 30 Second Value = 245 Null SFD (TOPS-IO only) Cause: A directory specification contains a null SFD. ERRSNS values: NSS? First Value First Value = 45 Second Value = 547 No free section available for SORT (TOPS-20 only) Cause: SORT runs it its own section on machines that support free sections extended addressing. There are no available. Recovery: There are 31 sections normally available when a FORTRAN program runs. If your application trying to use e~tended addressing, this error not occur, and you should submit an SPR. ERRSNS values: First Va]ue = 2:1 OGX % Galaxy version 2 not supported = 118 (TOPS-IO only) Cause: Your system is using an unsupported version of GALAXY. Recovery: Inform the system administrator supported version of GALAXY. ERRSNS values: OPN? Second Value simple is not should First Value = 26 to Second Value upgrade to the 595 Can't OPEN file Ca use: The specified fj.le could not be opened. The reason given is taken from the monitor error code (see the TOPS-IO Monitor Calls Manual) • ERRSNS values: First Va:.ue = 30 D-29 Second Value 250+n FOROTS ERROR MESSAGES OSW? FILOP. Ca use: error n - can't switch to output An attempt to open a file for write access which previously been open for read-only access failed. has Recovery: Change protection code; remove other file access. ERRSNS values: First Value = 98 Second Value = 250+n (TOPS-IO) JSYS error number (TOPS-20) PAG % Pages allocated but not deallocated Ca use: Internal FOROTS error in memory management. Recovery: Submit an SPR and include your program. PGD? Deallocating more pages than allocated Cause: Internal FOROTS error in memory management. Recovery: Submit an SPR and include your program. POI? <file positioning operation) Illegal for DIRECT (RANDOM) Cause: A file positioning operation (such BACKSPACE) was attempted on a DIRECT(RANDOM) access. file as REWIND file open or for Recovery: Remove the file positioning statement. PPN? = 31 ERRSNS values: First Value <JSYS error> (TOPS-20 only) Cause: 593 A TOPS-20 OPEN statement has specified a PPN instead of a directory name, but the PPN has no matching directory. Recovery: Specify the correct PPN, or directory name instead. ERRSNS values: RBR? Second Value = 30 First Value better yet, Second Value specify the 405 REREAD not preceded by READ Cause: A REREAD statement was encountered before any READ statement. A READ must be executed first so there is something to reread. Recovery: Cause a READ statement to be executed first. ERRSNS values: First Value = 39 D-30 Second Value = 310 FOROTS ERROR MESSAGES RLB? /RECORDSIZE larger than /BLOCKSIZE Cause: A RECORDSIZE was specified in an OPEN statement that is larger than the specified or implied BLOCKSIZE. Recovery: Correct either RECORDSIZE or BLOCKSIZE, BLOCKSIZE if it is not specified. ERRSNS values: RIC? First Value = 30 or specify 244 Second Value Reading into character format illegal Ca use: An attempt was made to READ into a character format. Recovery: Correct program to avoid this construct. READ into a (perhaps character variable and use this variable concatenated with other character expressions) for a modifiable format. ERRSNS values: Fi rst Va] ue 62 524 Second Value RIF % Reading into FORMAT nonst.andard Cause: A READ statement. was executed that reads data into a Hollerith or quoted string in a FORMAT statement. This is a practice contrary to the ANSI standard and is likely not to work in future releases of FORTRAN-IO/20. Recovery: READ into character variables and use (perhaps concatenated wit.h character constants) as the FORMAT. ERRSNS values: RNM? First Va]ue = 22 Second Value = 584 Can't rename file Cause: An attempt to rename the specified file failed. Recovery: Change file protection, remove other file access. ERRSNS values: First Value = 28 Second Value = 250+n (TOPS-IO) JSYS error number (TOPS-20) RNR? Record <n> has not been written Ca use: In direct-acces~; input, an attempt was made to read a record that was never written. This may indicate the USE~ of an incorrect rE~cord number. Recovery: Make sure you ERRSNS values: al~e First Va:Lue requesting the correct record. = 25 D-31 Second Value = 510 FOROTS ERROR MESSAGES RPE? Illegal repeat count Cause: In NAMELIST or list-directed input, a repeated constant was found, but the repeat count is not a positive integer. Recovery: Correct the input and try again. ERRSNS values: RR1? First Value = 97 Second Value 521 Random I/O requires RECORDSIZE specifier in OPEN statement Cause: Direct-access I/O was attempted to a file that has not been opened with the RECL or RECORDSIZE specifier to give the size of the record(s). Recovery: Specify a record size. The record size is in characters for formatted files, words for unformatted files. (See Section 11.3.27.) ERRSNS values: RRR? First Value = 30 Second Value 240 Random IO requires /RECORDSIZE Ca use: An OPEN statement was attempted that specified ACCESS=DIRECT(RANDOM) with no record size specified Recovery: Specify a record size. ERRSNS values: RSM? First Value = 30 Second Value 240 Record size different from that specified Ca use: A record size found in a binary record is than that specified in the OPEN statement. different Recovery: Specify the correct record size in the OPEN statement. ERRSNS values: SDO? First Value = 25 Second Value = 572 Same device open on unit with conflicting specifiers Ca use: An OPEN statement was attempted for a device for which another OPEN or data transfer statement had been already executed, and the file specifications were in conflict. Recovery: Change file specifications ERRSNS values: SLN? First Value = 30 Second Value 540 Record length negative or zero Ca use: An ENCODE or DECODE statement was initiated that has a negative or zero value for the record (string) length. Recovery: Correct program to specify a legal record length. ERRSNS values: First Value = 25 D-32 Second Value = 577 FOROTS ERROR MESSAGES SNH? Internal FOROTS error at <PC> Ca use: This error is Dot expected to occur. consistency check has found a bug. An in te rnal Recovery: Please submit an SPR if you get this message. SNQ? String not within Cause: quotes A character date\ item read as list-directed or NAMELIST input is not enclosed in single quotes. Recovery: Enclose ERRSNS values: SNV? singl~ charactE~r data item in single quotes. First Va:.ue = 97 Second Value = 598 Sign with null value Cause: List-directed Ol~ NAMELIST input contains a + or not followed by a value. sign Recovery: COI-rect the input and try again. ERRSNS values: Fir s t Va :~ u e SRE % Subscript range error <n> Cause: = 97 Second Value subscript <n> of array 522 <name> on line An illegal subs~ript or range has been specified for an array reference. Recovery: Specify a legal array reference. ERRSNS values: First Value = 23 SSE % Substring range error <var(bound» Cause: Second Value 114 on line <n> An illegal substring bound or range has been in a character expression. specified Recovery: Specify a legal reference. ERRSNS values: TFM? First Value = 23 Second Value 113 Tape format conflicts with OPEN statement or default Cause: The actual format of the tape (either CORE-DUMP or INDUSTRY) conflicts with the format specified in the OPEN statement or by the monitor. At this point, the file is already opened in the wrong format. Recovery: Specify the correct TAPEFORMAT in the OPEN statement or with the EXEC. ERRSNS values: First Value 30 0-33 Second Value 569 FOROTS ERROR MESSAGES TMA? Too many arguments in call to SORT Cause: When the first argument in a call to SORT is a character constant, the argument list must be copied in order to convert the argument to a Hollerith constant. At most, 10 arguments can be copied. Recovery: Change the first argument to a Hollerith use less than 10 arguments. ERRSNS values: TMF? Too many SFDs Cause: First Value = 21 Second Value constant, or 115 (TOPS-IO only) A directory specification contains more than five SFDs. Recovery: Specify the correct directory. ERRSNS values: UDT? First Value = 45 Second Value 546 Undefined data type or internal FOROTS error Cause: Internal FOROTS error. Recovery: Submit an SPR. ERRSNS values: UME? Fi rst Val ue Unexpected MTCHR error <n> Cause: Second Value 62 575 (TOPS-I0 only) This message is not expected to occur. It indicates that a MTCHR UUO has failed. The monitor-supplied error code may give some indication of the reason. Recovery: Submit an SPR. ERRSNS values: First Value Second Value 96 531 UMO % <JSYS error> trying to set tape <density/parity/data mode> (TOPS-20 onl y) Cause: It was not possible to set the indicated parameter of the tape. The monitor error message gives the reason. Recovery: Make sure you are using requested operations. ERRSNS values: UNO? DIVERT: Ca use: First Value = 96 a drive that Second Value supports the JSYS error number unit <n> is not open The file to which error messages are diverted opened for output before DIVERT is called. Recovery: Open the file for output before calling DIVERT. ERRSNS values: First Value = 21 D-34 Second Value = 105 must be FOROTS ERROR MESSAGES UNS? Unit not specified Cause: A call was made to FOROTS which did not contain a number. unit Recovery: Correct calling code. ERRSNS values: First Value = 81 Second Value 501 UOA % Unknown OPEN keyword <n>, ignored Cause: The compiler has generated an OPEN call that an unknown keyword. 'rhe keyword is ignored. Recovery: Make sure you are using the correct compiler, FORLIS, and FOROTS. ERRSNS values: USW? First Value Unknown switch /<sw> Cause: = 26 contains versions Second Value of the 541 (TOPS-IO only) In dialog mode, an unknown switch was specified. Recovery: Retype the line, specifying the correct switch. ERRSNS values: UTE? First Value Unexpected TAPOP error <n> Ca use: = 45 Second Value = 241 (TOPS-IO only) This message is not expected to occur. It indicates that a TAPOP UUO has failed. The monitor-supplied error code may give some indication of the reason. Recovery: Submit an SPR. ERRSNS values: First Value Second Value 96 UTO % UnexpectedTAPOP. error <n> trying to set mode/blocksize> (TOPS-IO only) Ca use: <density/parity/data It is not possible to set the indicated parameter of the tape. The monitor error message gives the reason. Recovery: Make sure you are using requested operation. ERRSNS values: VNN? 530 First Value = 96 a drive that supports Second Value the 537 Variable <var> not in namelist Ca use: NAMELIST input contains an assignment that is not in the namelist. to a Recovery: Correct the input and try again. ERRSNS values: First Vc,lue = 97 D-35 Second Value 309 variable FOROTS ERROR MESSAGES WBA? Attempt to WRITE beyond variable or array Ca use: An attempt was made to write beyond the end of a character variable or array with an internal file WRITE statement. Recovery: Correct program to variable or array. ERRSNS values: First Value stay 25 D-36 within limits Second Value of 576 character APPENDIX E INTERACTIVE DEBUGGER (FORDDT) ERROR 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 tex t where: ? indicates a fatal message indicates a warning message FDT is the FOR DDT mnemonic xxx is the 3-letter mnemonic for error message text is the explanation of error % Square brackets ([ ]) in this section signify variables output on the terminal. and are not ?FDT on Fatal Errors The fatal errors in the following list are each preceded by the user terminal. They are listed in alphabetical order. BDF [symbol] [symbol] BOI Bad octal input is undefined is multiply defined An illegal CCN characte~ was detected in an octal input value. Cannot continue A pause has been placed on some form of causing FORDDT to loop; should never FORTRAN-compiled programs .. CFO Core file overflow The storage area CNU skip instruction be encountered in The command fOl~ [name] 1S GROUP text has been exhausted. not unique More letters of the command are required to from the other commands. E-l distinguish it INTERACTIVE DEBUGGER (FORDDT) CSH ERROR MESSAGES Cannot START here The specified entry point is not an acceptable FORTRAN program entry point. DNA Double-precision comparisons not allowed DTO Dimension table overflow FORDDT does not have the space to dimensions until some are removed. FCX record any more main array Format capacity exceeded An attempt was made to specify a FORMAT statement requiring more space than was originally allocated by the FORTRAN compiler. FNI Formal not initialized, please retype There was a reference to a formal subprogram that was never executed. FNR [array name] parameter of some is a formal and may not be redefined Formal parameters may not be DIMENSIONed. IAF Illegal argument format [rest of user line] 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. Comparison of two constants is not allowed A conditional test involves two constants. IER Internal FORDDT error [number] Internal FORDDT error - IGN please report through an SPR. Invalid group number Group numbers must be integers and in the range one eight. INV through Invalid value [rest of user line] A syntax error was detected in the numeric parameter. IPN Illegal program name IRS Illegal range specification The particular range specified for an array is not defined. ITM Illegal type modifier - S The mode S is only valid for ACCEPT statements. E-2 INTEHACTIVE DEBUGGER (FORDDT) IWI ERROR MESSAGES I/O within I/O error An attempted TYPE or ACCEPT command cannot be executed because a fatal "I/O within I/O" error from FOROTS would result, since the user program is currently processing an IOLST call. JSE [JSYS error message] Error reading program name input) • LGU [array name] (on TOPS-20 or some other lower subscript .GE. FORDDT upper The lower bound of any given dimension must be less than equal to the upper bound. LNF [label] MCD Compile program with the statement MLD [array name] is not a FORMAT statement DEBUG switch type a FORMAT dimensioned more than once (by construct) in a single command. More subscripts needed The array is defined to have more specified in the given reference. NAL to multi-level array definition not allowed The same array cannot be means of the [dimensions] MSN or dimensions than were Not allowed An attempt has been made to modify something other than data or a FORMAT. NAR Not after a reenter The given command is not allowed until program integrity has been restored by means of 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 breakpoint at other than an executable statement or subprogram entry point. NSP [symbol] no such PAUSE An attempt has been made to REMOVE never set up. E-3 a breakpoint that was INTERACTIVE DEBUGGER (FORDDT) NUD [symbol] ERROR MESSAGES not a user-defined array An attempt has been made to remove dimension information for an array that was never defined. PAR Parentheses required, please retype Parentheses are required for the statements and complex constants. PRO specification of FORMAT Too many PAUSE requests The PAUSE table has been exhausted. The maximum limit is 10. RGR Recursive group reference A group may not reference itself. SER Subscript error The subscript specified is outside the range of its dimensions. STL [array name] defined size too large An attempt has been made to define an array larger than 256K. TMS Too many subscripts [dimensions] The array is defined to have fewer dimensions specified in the given element reference. URC than are Unrecognized command [command] Warning Messages Each warning message is preceded by %FDT on your terminal. warning messages are listed here in alphabetical order. ABX [array name] The 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. CAB Cannot allocate buffer for help file CHI Characters ignored: "[text]" The portion of the command string included thought to be extraneous and was ignored. ECI Buffer full - excess characters ignored EOH Error opening help file IOE I/O error reading help file E-4 in "text" was INTEHACTIVE DEBUGGER (FORDDT) IWI ERROR MESSAGES I/O within I/O FORDDT has PAUSEd at a breakpoint while the user program is currently processing an IOLST call. TYPE and ACCEPT commands cannot be PJ~ocessE~d at this breakpoint. aJ~ray NAA [symbol] is not an NHF Cannot find help file; NSL No symbols loaded I'm sorry I can't help you FORDDT cannot find the symbol table. NST Not STAHTed The specified command requ:lres that a START be previously issued to ensure tha~ the program is properly initialized. POV Program overlayed by [program name] Program overlayed by *** The symbol table is different from the last time FOR DDT had control. The program name is printed only if it has changed" otherwise ,.***, is printed. SCA Supersedes compiled ~rray dimension The FowrRAN generated dimension is being superseded for g iven al~ray. SPO Variable is single-precision only WSP Writing to shared page XPA Attempt to exceed pr~gram area with [symbol name] An attempt has been made to access currently defined pr~gram space. E-5 the memory outside the APPENDIX F FORTRAN-SUPPLIED PLOTTER SUBROUTINES The FORTRAN subroutine library contains a set of subroutines that are used with plotting devices. To successfully use these routines, a plotter must be connected to your system. The FORTRAN software contains the following plotter subroutines: PLOTS The PLOTS subroutine initializes the plotter or reports if the plotter is not available. This must be the first plotter subroutine specified. (See Section F.I.) AXIS The AXIS subroutine ciraws an axis with tic marks and scale values at I-inch increments. An identifying label may also be plotted along the axis. (See Section F.2.) CAXIS The CAXIS subroutine performs the same functions as the AXIS subroutine. (See Section F.3.) LINE The LINE subroutine draws a specified. (See Section F.4.) line MKTBL The MKTBL subroutine (See Section F.S.) a NUMBER The NUMBER subroutine causes floating-point plotted as text. (See Section F.6.) PLOT The PLOT subroutine lnoves the plotter pen to a new position. Raising and lowering the pen is also specified in the PLOT subroutine. (See Se=tion F.7.) SCALE The SCALE subroutine selects scale values for CAXIS subroutine. (See Section F.8.) SETABL The SETABL subroutine Section F.9.) SYMBOL The SYMBOL subroutine raises the plotter pen, moves it to the position specified by x and y, and plots a string of characters. (See Section F.IO.) WHERE The WHERE subroutine reports on the current position of plotter pen. (See Section F.II.) specifies specifies F-l through special a the points character set. numbers character the to AXIS set. be or (See the FORTRAN-SUPPLIED PLOTTER SUBROUTINES PLOTS Subroutine F.l PLOTS SUBROUTINE The PLOTS subroutine initializes the plotter or reports if the plotter is not available. This must be the first plotter subroutine specified. The form of the PLOTS subroutine is: CALL PLOTS(i[,steps]) where: is an integer variable, which is set to -1 if the plotter is not available, or set to a if the plotter is available. i The plotter may not be available because: the system does not have a plotter; the plotter is in use by another user; the plotter is turned off; or the plotter is being spooled, but you are trying to write to it directly. steps is an optional floating-point variable or constant that specifies the number of steps (per inch) used by the plotter. The default is 100 steps per inch, and may be changed by the installation. Commonly, plotters plot 100 steps per inch, 200 steps per inch, or 100 steps per centimeter (about 254 steps per inch). AXIS Subroutine F.2 AXIS SUBROUTINE The AXIS subroutine draws an axis with tic marks and scale values at I-inch increments. An identifying label may also be plotted along the axis. NOTE The AXIS subroutine is provided for compatibility with previous versions of FORTRAN-IO/20. The AXIS subroutine uses a numeric array to contain the label that is plotted along the axis. The CAXIS subroutine (see Section F.3) allows a character expression to contain the label. F-2 FORTRAN-SUPPLIED PLOTTER SUBROUTINES The form of the AXIS subroutine is: CALL AXIS{x,y,asc,nasc,size,theta,xmin,dx) where: x,y is a variable or constant starting point of the axis. pair that specifies asc is the name of a numeric array that that is plotted along the axis. nasc is an integer constant or variable that specifies the number of characters contained in array asc. If nasc is negative, the label in the array is placed on the clockwise side of the axis. If nasc is positive, the tic marks, label, and scale values are placed on the counterclockwise side of the axis. size is a constant or variable that specifies the length the axis in inches. theta is a constant or variable that specifies the angle at which the axis is plotted. The value of theta is usually 0.0 or 90.0. xmin is a variable or constant that specifies the the scale at the beginning of the axis. value of dx is a variable or constant that specifies the change scale for a I-inch increment. in contains a the label of NOTE The proper values for xmin and dx may be determined by calling the SCALE subroutine (see Section F.8). CAXIS Subroutine F.3 CAXIS SUBROUTINE The CAXIS subroutine draws an axis with tic marks and scale values at I-inch increments. An identifying label may also be plotted along the axis. The form of the CAXIS subroutine is: CALL CAXIS{x,y,asc,sign,size,theta,xmin,dx) F-3 FORTRAN-SUPPLIED PLOTTER SUBROUTINES where: x,y is a variable or constant starting point of the axis. pair that specifies the asc is the name of a character expression that label that is plotted along the axis. sign If nasc is negative, the label in the array is placed on the clockwise side of the axis. If nasc is positive, the tic marks, label, and scale values are placed on the counterclockwise side of the axis. size is a constant or variable that specifies the length the axis in inches. theta is a constant or variable that specifies the angle at which the axis is plotted. The value of theta is usually 0.0 or 90.0. xmin is a variable or constant that specifies the the scale at the beginning of the axis. value of dx is a variable or constant that specifies the change scale for a I-inch increment. in contains a of NOTE The proper values for xmin and dx may be determined by calling the SCALE subroutine (see Section F.8). LINE Subroutine F.4 LINE SUBROUTINE The LINE subroutine draws a continuous line through a set of points. The form of the LINE subroutine is: CALL LINE(x,y,n,k) where: x is the name of an array that contains the x-coordinates of the points to be plotted. floating-point Y is the name of an array that contains the y-coordinates of the points to be plotted. floating-point F-4 FORTRAN-SUPPLIED PLOTTER SUBROUTINES n is an integer constant or variable that specifies the number of points to be plotted. total k is an integer constant or variable that equals the number of elements of x and y. Since single-precision one-dimensional arrays are usually used, this value is usually 1. MKTBL Subroutine F.S MKTBL SUBROUTINE The MKTBL subroutine defines a special character set to be used when plotting; the SETABL subroutine (see Section F.9) enables you to use the character set defined by the MKTBL subroutine. The form of the MKTBL subroutine is: CALL MKTBL(setnumber,tableaddress) where: F.S.l setnumber is an integer variable from 1 to 10 that specifies the numeric identifier of the character set, for example, the number of the ASCII character set is 1. If the character set cannot be defined by a call to MKTBL, a value of zero is returned in this variable. tableaddress is a constant or variable that specifies the starting address of a character table that has 128 (200 octaJ) consecutive words. Each character table word contains the number of strokes (line segments) for the character in the left half, and the addr~ss of the table of strokes in the right half. Se~ Section F.S.l for a description of these tabJes. Character Tables The next sections describe how to define and organize a character table. The charc3lcter set, called by the MKTBL subroutine, enables to create and use a character set other than the default character that is used to plot characters. (Usually the default character is ASC I I.) set you set set To create your own character set, you need to create a character table and a character stroke table. These two tables are descr ibed in Sections F.S.l.l and F.S.l.2, respectively. F-5 FORTRAN-SUPPLIED PLOTTER SUBROUTINES F.S.l.l Creating a Character Table - A character table contains 128 entries (200 octal). Each entry in the character table, regardless of whether the table is defined in the plotter subroutine library or by you through a call to the MKTBL subroutine, indicates the character to be plotted for the ASCII character that has that numerical value. Figure F-l is a diagram of an entry word in a character table. Strokes Address ~~ 18 bits 18 bits MnS1752·81 Figure F-l: Plotter Character Table Entry As shown in Figure F-l, each entry in the character table contains the number of strokes (line segments) required to plot the character in its left half and an address reference in the right half of the word. The address in the right half of the entry references an entry in the character stroke table for the character set. The character stroke table is described in the next section. F.S.l.2 Creating a Stroke Table - Each character in the character table has a corresponding character stroke table. The purpose of the character stroke table is to define the number and type of strokes (drawn line segments) it takes to produce a character in the character table. Figure F-2 is a diagram of an entry in a character stroke table. I \ I y x pen I "" I Three 5-bit bytes Fig ure F-2: 1~'<~81 Character Stroke Table Entry As shown in Figure F-2, each stroke is stroke table by three 5-bit bytes. three bytes are: described in the character The possible values for these Value and Meaning Byte 1 MH c; o 1 pen is raised (off the paper) pen is lowered (on the paper) 2 x-coordinate value at end of stroke 3 y-coordinate value at end of stroke F-6 FORTRAN-SUPPLIED PLOTTER SUBROUTINES When determining the height and width of each character to be plotted, consider the following conventions: 1. Characters are drawn within a grid that is IS units eight units wide. high by 2. Characters are generally plotted six units above the base line. Two units are generally left blank to the right of each character; one cnit is generally left blank on top of each character. The spacing above, below, and on either side of each character provides adequate spacing between characters and between lines. 3. The plotter starts drawing each character at the lower left corner of the character grid. If the grid is set up in the conventional manner, the lower left corner is grid position (0,6). Normal width characters end at the lower right corner of the character grid after allowing spacing between characters. The last coordinate in each character grid is usually (8,6). The character grid for the next character has as its origin (0,0) at the ending coordinate in the previous grid (8,6). 4. Accents, circumflexes, underscores, and other characters that are to be plotted in the same character grid as another character should end at the same grid position as they began. By doing this, for example, the ASCII character that represents the accent character is plotted before the character that is thE! letter to be accented. F.S.l.3 Sample Character Stroke Table - In this sample, you want to plot the Greek letter beta as a normal sized character. When plotted, the letter is drawn on a IS x 8 unit grid above the base line, allowing for spacing between c:haracters and between lines. The strokes (line segments) for beta, including the invisible segments, are then determined. The character will be plotted more smoothly if as many of the liIle segments as possible are connected, and if doubled segments are avoided. Note that stroke 9 (the return stroke for the crossbar of the beta) and stroke IS (moving the pen to ending point (8,6) are not visible; the pen is raised. F-7 FORTRAN-SUPPLIED PLOTTER SUBROUTINES 15 4 Y 2 ~ 6 lh 8,9 N° 10 11 ~4 1/ 1V 15 ~ 13 V Base Line 5 ° Figure F-3: 5 rv'In S 1754·81 Sample Character Stroke Table If the address at the beginning of the table that includes the character in Figure F-3 is called GREEK, then the FORTRAN call to set up the table could be: IGREEK=4 CALL MKTBL (IGREEK, GREEK) The above call to the MKTBL subroutine defines the GREEK character table to be the fourth character table. To use the GREEK table for plotting, use the FORTRAN call: CALL SETABL (IGREEK, IFLAG) The entry in the character table for beta is: RADIX BETA: ~ DIO iVALUES IN DECIMAL IS"TBETA iCHARACTER TABLE ENTRY FOR BETA Note that the character table entry for beta contains the starting address of the character stroke table (TBETA) in its right half. The character stroke table for beta is: TBETA: SEEN==1 iIF 'SEEN' THEN THE STROKE MARKS THE PAPER UNSEEN==O iIF 'UNSEEN' THEN THE STROKE IS INVISIBLE RADIX ~DIO iALL VALUES ARE IN DECIMAL BYTE{S) SEEN,2,8,SEEN,2,13 BYTE{S) SEEN,3,14,SEEN,S,14 BYTE{S) SEEN,6,13,SEEN,6,12 BYTE{S) SEEN,S,II,SEEN,2,11 BYTE{S) UNSEEN,S,11,SEEN,6,IO BYTE{S) SEEN,6,9,SEEN,S,8 BYTE(S) SEEN,3,8,SEEN,2,9 BYTE{S) UNSEEN,8,6 F-8 FORTRAN-SUPPLIED PLOTTER SUBROUTINES F.S.I.4 FORTRAN- and User-Defined Character Sets - The standard ASCII character set is always defined and is character set I for calls to the SETABL subroutine, unless character set 1 is redefined by a user call to the MKTBL subroutine. If SETABL is not called, the ASCII character set is the default. The Cyrillic (Russian) character set is available as character set 2, and the Feanorian character set is available as character set 3 (unless character sets 2 or 3 has been redefined by a user call to the MKTBL subroutine). In order to use these character sets, the user program must contain an EXTERNAL statement for variable PLOTF (Feanorian) or PLOTC (Cyrillic). User-defined character sets should use character sets 4 through 10 avoid conflicts with the standard character sets. to NUMBER Subroutine F.6 NUMBER SUBROUTINE The NUMBER subroutine causes floating-point numbers to be text. plotted as The form of the NUMBER subroutine is: CALL NUMBER(x,y,size,fnum,theta,ndigit) where: x,y are variables or constants that specify the x and y coordinates of the point to be plotted. The specified point is the lower left corner of the first character to be plotted. size is a variable or constant that specifies the size (in inches) of the digits to be plotted. The specified value should be a multiple of .08 inches (or centimeters if plotter is metric) if a small value is used. fnum is a variable or constant that number to be plotted. theta is a variable or constant that specifies the direction (in degrees) of the base line on which the characters are plotted. ndigit is a variable or constant that specifies the number of digits to be p~.otted to the right of the decimal point. If ndigit is negative, only the integer part of the n urn be r i s plot ted; the res u 1 t i ng in t eg e r i s r 0 u nd ed • F-9 is the floating-point FORTRAN-SUPPLIED PLOTTER SUBROUTINES PLOT Subroutine F.7 PLOT SUBROUTINE The PLOT subroutine moves the plotter pen to a new position. Raising and lowering the pen is also specified in the PLOT subroutine. NOTE The plotter is not released after specified movement. completion of the The form of the PLOT subroutine is: CALL PLOT(x,y,penup/down) where: x,y are the variables or constants that specify the x and y coordinates for the point to which the pen will be moved. penup/down is an integer constant or variable that specifies whether the pen is on the paper or above the paper. The possible values for this variable are: 3 2 1 raise pen before movement lower pen before movement leave pen in current state (raised or lowered) -1, -2, or -3 same as 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 plotter. Using the negative values is helpful if you are plotting consecutive characters in the same program. SCALE Subroutine F.B SCALE SUBROUTINE The SCALE subroutine scales values for the AXIS subroutine. The form of the SCALE subroutine is: CALL SCALE(x,n,s,xmin,dx) F-IO FORTRAN-SUPPL1ED PLOTTER SUBROUTINES where: x is an array nam~ of a one-dimensional floating-point array to be scaled for the AXIS subroutine. n is an integer C(lnstant or variable that length of the at"ray in words (36-bit). s is a constant or variable that specifies the length (in inches) of the desired axis. xmin is a constant or variable that specifies the smallest element in an"ay x." The value of xmin will be the value of the scale at the beginning of the axis. dx i s a c 0 n s tan t 0 I" va ria b 1 e t hat equals the change in scale for a I-inch interval so that array x can be plotted in inches. specifies the SETABL Subroutine F.9 SETABL SUBROUTINE The SETABL subroutine enables used to plot characters. fOU to select the character set that is The form of the SETABL subroutine is: CALL SETABL (setnum,status) where: setnum is an integer constant or variable that equals the number of the character set. The standard ASCII character set is defined to be set 1 and is the default. Character sets are defined by the MKTBL subroutine (see Section F. 5) • status is an integer variable whose value after the call to the SETABL subroutine is either 0, if the character set specified in setnum is valid, or -1, if the character set specified by setnum is invalid. NOTE If you use a character set other than the character sets defined by default in the plotter subroutine library, you must call the MKTBL subroutine before calling the SETABL subroutine. F-II FORTRAN-SUPPLIED PLOTTER SUBROUTINES SYMBOL Subroutine F.IO SYMBOL SUBROUTINE The SYMBOL subroutine plots a specified string of characters (from either the default character set or the character set specified by the last successful call to the SETABL subroutine) . The form of the SYMBOL subroutine is: CALL SYMBOL(x,y,size,asc,theta[,nasc]) where: x is a constant or variable that equals the x coordinate of the lower left corner of the first character to be plotted. y is a constant or variable that equals the y coordinate of the lower left corner of the first character to be plotted. The plotter pen is raised and moved to pos i t ion x,y before the string of characters is plotted. size is a constant or variable that specifies the height (in inches) of the character to be plotted. The specified value should be a multiple of .08 inches (or c en tim e t e r s i f yo u h a v e a met ric plot t e r) • asc is the name of a character expression or numeric array that contains the ASCII characters to be plotted. theta is a constant or variable that specifies the direction (in degrees) of the base line on which the characters are to be plotted. nasc is an integer constant or variable that is equal to the number of characters in numeric array asc that are to be plotted. This is ignored if a character expression is specified for asc. WHERE Subroutine F.Il WHERE SUBROUTINE The WHERE subroutine reports on the current position pen, in inches, relative to the origin. F-12 of the plotter FORTRAN-SUPPLIED PLOTTER SUBROUTINES NOTE The plotter origin is set by a call to the AXIS subroutine or a call to the PLOT subroutine that has a negative value for the penup/down variable. Also, the WHERE subroutine does not allow you to determine whether the plotter pen is raised or lowered. The form of the WHERE subroutine is: CALL WHERE(x,y) where: x is a variable in which the subroutine coordinate of the current print position. returns the x y is a variable in which the subroutine coordinate of the current pen position. returns the y F-13 INDEX A ed i t i ng, 12 - 3 9 ABORT switch, 16-9 ACCEPT seq u e n t i alL i s t - d ire c ted, 1 (! - 4 1 ACCEPT statement, 10-40 sequential FORMAT-statement, 10-40 Access direct, 10-6, 18-4 sequential, 10-5, 18-3 ACCESS specifier in INQUIRE, 11-43 in OPEN, 11-6 Accumulator usage, 15-11 Actual arguments, 13-49 Length of character, 13-51 Adjustable dimensions, 7-3 ALCCHR subroutine, 13-24 ALL with DEBUG, 16-12 ALL with FLAG, 16-22 ALL with NOWARN, 16-15 .AND. logical operator, 5-8 ANSI standard, 1-1 ANSI with FLAG, 16-22 Apostrophe editing, 12-16 Argument lists, 15-12 Argument types, 15-14 Argumen ts Actual, 13-49 Dummy, 13-49 Arguments to FLAG, 16-22 ARGUMENTS with DEBUG, 16-12 Arithmetic assignment statement, 8-1 Arithmetic constant expressions, 5-5 Arithmetic expressions, 5-1 writing, 5-2 Arithmetic IF statement, 9-3 Arithmetic operations, 5-2 Arithmetic operator3, 5-2 Array declarator, 4-4, 7-1 Array element subscript, 4-3 Array elements order of stored, 4-5 Array names, 4-3 Arrays, 4-3 assumed-size, 7-4 dimensioning, 4-4 Dimensioning dummy, 15-5 ASCII character code, B-1 ASCII data files, 18-4 ASSIGN statement, 8-3 Assigned GO TO statement, 9-3 Assignment statement, 8-1 ar i thmetic, 8-1 character, 8-4 Assignment statements logical, 8-3 Assignments mixed~mode, 8-2 ASSOCIATEVARIABLE specifier in OPEN, 11-8 Assumed-size arrays, 7-4 AXIS subroutine, F-2 BACKFILE statement, 11-57 BACKSPACE statement, 11-55 Binary data files, 18-4 BINARY switch, 16-9 Bit data constants, 7-23 Bit manipulation functions, 13-14 Blank lines, 2-7 BLANK specifier in INQUIRE, 11-44 in OPEN, 11-9 BLISS-36 calling routines, 15-19 Interaction with, 15-18 BLKRW subroutine, 19-4 BLOCK DATA statement, 14-1 Block data subprograms, 14-1 Block IF constructs indexed, 9-9 Block IF statements, 9-5 BLOCKSIZE specifier in OPEN, 11-10 BN editing, 12-28 Boolean values, 3-6 BOUNDS with DEBUG, 16-12 BUFFERCOUNT specifier in OPEN, 11-10 BZ editing, 12-28 CALL statement, 13-44 Calling BLISS-36 routines, 15-19 Calling COBOL subroutines, 15-18 Calling FORDDT, 17-17 Calling sequencEs FOROTS, 18-16 Carriage-control specifiers, 12-9 CARRIAGECONTROL specifier in INQUIRE, 11-44 in OPEN, 11-11 CAXIS subroutine, F-3 CBC function, 18-34 CDABS function, 13-25 CDCOS subroutine, 13-25 CDEXP subroutine, 13-26 CDLOG subroutine, 13-26 CDSIN subroutine, 13-27 CDSQRT subroutine, 13-28 Channel allocation routines, 18-30 Channel deallocation routines, 18-30 Character assignment statement, 8-4 Ind ex--l Character code ASCII, B-1 Character comparison functions, 13-14 Character constant expressions, 5-7 Character constants, 3-4 Character expressions, 5-6 Character intrinsic functions, 13-12 Character set, 2-1 FORTRAN-defined, F-9 User-defined, F-9 Character substrings, 4-6 Character tables, F-5 Character type specification s ta temen ts, 7-6 CHARACTER*len, 7-6 CHKDIV subroutine, 13-28 CLOSE DEVICE specifier in, 11-36 DIALOG specifier in, 11-36 DIALOG= specifier in, 11-37 DIRECTORY specifier in, 11-36 DISPOSE specifier in, 11-37 ERR specifier in, 11-39 FILE specifier in, 11-36 Implicit, 11-34 IOSTAT specifier in, 11-39 LIMIT specifier in, 11-39 NAME specifier in, 11-36 PROTECTION specifier in, 11-36 STATUS specifier in, 11-40 UNIT specifier in, 11-41 CLOSE specifiers Summary of, 11-35 CLOSE statement, 11-34 CLOSE statement specifiers, 11-34 CLRFMT subroutine, 13-29 CLROVL in LINK, 15-20 COBOL calling subroutines, 15-18 Interaction with, 15-16 CODE with EXTEND, 16-20 Colon editing, 12-24 Commands COMPILE, 16-1, 16-5 DEBUG, 16-1, 16-5 EXECUTE, 16-1, 16-5 FORDDT, 17-1, 17-7 LOAD, 16-1, 16-5 Comment lines, 2-5 Common block, 7-9 Common block name, 7-9 COMMON statement, 7-8 Common storage, 7-9 COMMON with EXTEND, 16-20 Compilation control statements, 6-4 COMPILE command, 16-1, 16-5 Compiler Running FORTRAN-I0, 16-2 Running FORTRAN-20, 16-6 Compiler (Cont.) using, 16-1 Compiler errors internal, C-13 Compiler generated label, 16-23 Compiler generated variables, 16-24 Compiler listing, 16-22 Compiler messages, C-l Compiler switches FORTRAN-I0, 16-2 FORTRAN-20, 16-9 Compiling programs, 16-1, 16-5 Complex constants, 3-4 Complex editing, 12-36 Computed GO TO statements, 9-2 Concatenation operator, 5-6 CONNECT subroutine, 19-4 Constant expressions, 5-15 arithmetic, 5-5 character, 5-7 integer, 5-5 logical, 5-10 Constant folding, 15-8 Constant propagation, 15-8 Constants, 3-1 bit data, 7-23 character, 3-4 complex, 3-4 double-octal, 3-5 double-precision, 3-2 Hollerith, 3-6 integer, 3-1 logical, 3-6 octal, 3-5 real, 3-2 statement label, 3-7 Continuation lines, 2-4 CONTINUE LSCW, 18-4 CONTINUE statement, 9-17 Control information list, 10-9 Control statements, 9-1 COR function, 18-33 CROSSREF switch, 16-3, 16-9 D editing, 12-32 D-floating double-precision format, 3-3 Data access, 10-5 Data magnitude on G-format, 12-35 DATA statement, 7-21 Data transfer operations, 10-5 Data transfer statements, 10-1 Data transfers Formatted, 12-1 formatted, 10-6 unformatted, 10-8 DATA with EXTEND, 16-20 DATE subroutine, 13-29 DEBUG and FORDDT, 17-4 DEBUG arguments ALL, 16-12 Index- 2 DEBUG arguments (Cont.) ARGUMENTS, 16-12 BOUNDS, 16-12 DIMENSIONS, 16-12 INDEX, 16-12 LABELS, 16-12 NONE, 16-12 TRACE, 16-12 DEBUG command, 16-1, 16-5 Debug lines, 2-6 DEBUG switch, 16-3, 16-9, 16-11 Debugger FORDDT, 17-1 Debugging programs, 16-1, 16-5 DECODE statement, 10-51 Default memory layout /EXTEND, 16-15 Deferred OPEN statement, 11-2 DENSITY specifier in OPEN, 11-12 Device assignments logical, 10-12 Device control statements, 10-1, 11-52 DEVICE specifier in CLOSE, 11-36 in OPEN, 11-13 Devices real-time, 19-1 DFLOATING switch, 16-3, 16-9 DIALOG specifier in CLOSE, 11-36 in OPEN, 11-13 DIALOG= specifier in CLOSE, 11-37 in OPEN, 11-14 Dimension declarator, 7-2 DIMENSION statement, 7-1 Dimensioning arrays, 4-4 Dimensioning dummy arrays, 15-5 DIMENSIONS with DEBUG, 16-12 Direct access, 10-6 direct access, 18-4 Direct FORMAT-statement READ, 10-27 Direct FORMAT-statement WRITE, 10-33 DIRECT specifier in INQUIRE, 11-44 Direct unformatted READ, 10-30 Direct unformatted WRITE, 10-36 DIRECTORY specifier in CLOSE, 11-36 in OPEN, 11-14, 11-16 DISCON subroutine, 19-7 DISMIS subroutine, 19-6 DISPOSE specifier in CLOSE, 11-37 in OPEN, 11-16 DIVERT subroutine, 13-30 DO iteration control, 9-12 DO lists implied, 10-22 DO loop extended range, 9-15 DO loop iterations, 15-2 DO loops Floating-point, 15-2 DO statements nested, 9-14 DO WHILE statement, 9-13 Dollar sign editing, 12-22 Double-octal constants, 3-5 Double-precision constants, 3-2 Double-precision format D-floating, 3-3 G-floating, 3-3 DTOG function, 13-19 DTOGA subroutine, 13-30 Dummy arguments, 13-49 Length of character, 13-51 DUMP subroutine, 13-30 E ( e x po n e n t i a 1 not a t ion), 3 - 2 E editing, 12-32 ECHO-OPTION switch, 16-9 Edit descriptors FORMAT-statement, 12-6 Nonrepeatable, 12-8 numer ic, 12-29 Repeatable, 12-7 Ed i ting A, 12-39 Apostrophe, 12-16 BN, 12-28 BZ, 12-28 Colon, 12-24 complex, 12-36 D, 12-32 Dollar sign, 12-22 E, 12-32 F, 12-32 G, 12-33 H, 12-17 I, 12-31 L, 12-38 Nurn e ric, 1 2 - 2 9 o (octal), 12-36 P, 12-25 Positional, 12-18 Q, 12-29 R, 12-40 S, 12-24 Slash, 12-23 SP, 12-24 SS, 12-24 T, 12-19 TL, 12-20 TR, 12-20 X, 12-21 Z (hexadecimal), 12-37 ELSE IF THEN statement, 9-5 ELSE statement, 9-5 Embedded format specifications, 12-15 ENCODE statement, 10-51 END DO statement, 9-17 Index-3 END IF statement, 9-5 END LSCW, 18-4 END statement, 9-20 END= specifier, 10-17 ENDFILE statement, 11-55 Entry points FOROTS, 18-15 ENTRY statement, 13-45 EQUIVALENCE and extended addressing, 7-17 EQUIVALENCE statement, 7-11 .EQV. logical operator, 5-8 ERR specifier in CLOSE, 11-39 in INQUIRE, 11-45 in OPEN, 11-17 ERR= specifier, 10-18 Error codes FOROTS, D-2 Error messages FORDDT, E-l FOROTS, D-l real-time, 19-7 Error processing FOROTS, 18-2 Error reporting, 16-33 Errors fatal, C-2 Fatal compiler, 16-34 ERRSET subroutine, 13-31 ERRSNS subroutine, 13-32 ERRSNS values, D-2 Evaluation of expressions, 5-13 Executable statements, 1-1, 6-1 EXECUTE command, 16-1, 16-5 Executing programs, 16-1, 16-5 EXIST specifier in INQUIRE, 11-45 EXIT subroutine, 13-33 EXPAND switch, 16-3, 16-9 Expressions ar i thmetic, 5-1 arithmetic constant, 5-5 character, 5-6 character constant, 5-7 constant, 5-15 evaluation of, 5-13 integer constant, 5-5 log ical, 5-7 logical constant, 5-10 mixed-mode, 5-15 relational, 5-11 EXTEND applications with large arrays, 16-16 applications with large code, 16-17 EXTEND arguments, 16-19 CODE, 16-20 COMMON, 16-20 DATA, 16-20 NOCOMMON, 16-20 NODATA, 16-20 EXTEND arguments (Cont.) PSECT, 16-20 EXTEND psect placement, 16-17 EXTEND switch, 16-9, 16-15 Extended addressing, 16-15 and EQUIVALENCE, 7-17 and FORDDT, 17-17 default memory layout, 16-15 memory layout, 15-22 Extended range DO loop, 9-15 External functions, 13-18 FORTRAN-supplied, 13-18 user-defined, 13-20 EXTERNAL statement, 7-17 F editing, 12-32 F66 switch, 16-3, 16-9 F77 switch, 16-3, 16-9 Fatal compiler errors, 16-34 Fatal errors, C-2 FFUNIT subroutine, 13-33 Field line continuation, 2-3 remark, 2-4 statement, 2-4 statement label, 2-3 File control statements, 10-1, 11-1 File identifier internal, 10-13 FILE specifier in CLOSE, 11-36 in OPEN, 11-18 Files ASCII data, 18-4 binary data, 18-4 internal, 10-7, 10-49 linking TWOSEG REL, 16-21 non-FORTRAN, 15-10 FILESIZE specifier in OPEN, 11-18 FIND statement, 11-53 FLAG a rg umen ts ALL, 16-22 ANSI, 16-22 NOANSI, 16-22 NONE, 16-22 NOVMS, 16-22 VMS, 16-22 FLAG switch, 16-3, 16-21 FLAG switch arguments, 16-22 FLAG-NON-STANDARD switch, 16-9 Floating-point DO loops, 15-2 FORDDT and extended addressing, 17-17 calling, 17-17 load ing, 17-5 starting, 17-5 FORDDT and DEBUG, 17-4 FORDDT commands, 17-1, 17-7 FORDDT debugger, 17-1 FORDDT error messages, E-l Index-4 FORM specifier in INQUIRE, 11-45 in OPEN, 11-19 format control, 12-11 Format editing, 12-16 Format list I/O list interaction, 12-11 format list, 12-3 Format specifications embedded, 12-15 Format specifier, 10-13 FORMAT statement, 12-2 FORMAT-statement ACCEPT sequential, 10-40 FORMAT-statement edit descriptors, 12-6 FORMAT-statement formatting, 10-14, 12-2 FORMAT-statement PRINT sequential, 10-45 FORMAT-statement PUNCH sequential, 10-48 FORMAT-statement READ direct, 10-27 equential, 10-26 FORMAT-statement REREAD sequential, 10-38 FORMAT-statement TYPE sequential, 10-43 FORMAT-statement WRITE direct, 10-33 sequential, 10-32 Formatted data transfers, 10-6, 12-1 Formatted input, 12-14 Formatted output, 12-15 Formatted READ transfers, 10-2~ FORMATTED specifier in INQUIRE, 11-45 Formatted WRITE transfers, 10-31 Formatting FORMAT-statement, 10-14, 12-2 list-directed, 10-16, 12-41 NAMELIST-statement, 10-16, 12-44 FOROTS, 18-1 and INQUIRE by file, 18-36 MACRO calls for, 18-17 RESET in, 15-11 sharable, 15-10 using, 18-14 FCROTS calling sequences, 18-16 FOROTS entry points, 18-15 FOROTS error codes, D-2 FOROTS error messages, D-l FOROTS error processing, 18-2 FOROTS features, 18-1 FOROTS input/output facility, 18-2 FOROTS memory management, 15-20 FORRTF subroutine, 19-1 FORTRAN-I0 compiler switches, 16-2 FORTRAN-I0 (Cont.) running the compiler, 16-2 FORTRAN-I0/20, 1-1 ]~ORTRAN-20 Running the compiler, 16-6 FORTRAN-20 compiler using, 16-5 FORTRAN-20 compiler switches, 16-9 FORTRAN-77 standard, 1-1 FORTRAN-defined character set, F-9 FORTRAN-supplied external functions, 13-18 FORTRAN-supplied plotter subroutines, F-l FORTRAN-supplied subroutines, 13-24 Function effects, 15-10 FUNCTION statement, 13-20 Function subprogram, 13-20 Function subprograms using, 13-21 Functions, 13-1 bit manipulation, 13-14 CBC, 18-34 CDABS, 13-25 character comparison, 13-14 character intrinsic, 13-12 COR, 18-33 DTOG, 13-19 External, 13-18 FORTRAN-supplied external, 13-18 GAD, 18-32 GCH, 18-33 Generic, 13-2 GOT, 18-33 GPG, 18-34 GPSI, 18-35 GTOD, 13-19 IFS, 18-34 ILL, 18-32 Intrinsic, 13-1 LSNGET, 13-19 MPG, 18-35 RAD, 18-33 RAN, 13-19 RANS, 13-19 RCH, 18-33 RNT, 18-34 ROT, 18-34 RPG, 18-35 RPSI, 18-35 RRS, 18-34 SECNDS, 13-19 Spec i fic, 13-2 Statement, 13-15 TIM2GO, 13-19 UPG, 18-36 user-defined external, 13-20 Using intrinsic, 13-2 Using statement, 13-16 Index--5 Functions (Cont.) WRS, 18-34 Functions for overlays, 18-31 G editing, 12-33 G-floating double-precision format, 3-3 G-format Data magnitude on, 12-35 GAD function, 18-32 GCH function, 18-33 Generic functions, 13-2 GETOVL in LINK, 15-20 GFLOATING switch, 16-3, 16-9 Global optimization, 15-6 Global register allocation, 15-9 GO TO statement assigned, 9-3 GO TO statements, 9-1 computed, 9-2 unconditional, 9-2 GOT function, 18-33 GPG function, 18-34 GPSI function, 18-35 GTOD function, 13-19 GTODA subroutine, 13-34 H editing, 12-17 Hierarchy of operators, 5-14 High segment sharable, 16-35 Hollerith constants, 3-6 I editing, 12-31 I/O optimization, 15-9 I/O 1 ist, 10-20 I/O list and format list interaction, 12-11 IF statement arithmetic, 9-3 logical two-branch, 9-4 IF statements, 9-3 block, 9-5 logical, 9-4 IF THEN statement, 9-5 IFS function, 18-34 ILL function, 18-32 ILL subroutine, 13-34 Implicit CLOSE, 11-34 Implicit OPEN, 11-3 IMPLICIT statements, 7-7 Implied DO lists, 10-22 INCLUDE statement, 6-4 INCLUDE switch, 16-3, 16-9 Index variable, 9-11 INDEX with DEBUG, 16-12 INIOVL in LINK, 15-20 Initial lines, 2-4 Initial tab, 2-3 INITIALIZE specifier in OPEN, 11-18 Input formatted, 12-14 NAMELIST-controlled, 12-45 Input/output facility FOROTS, 18-2 Input/output statements, 10-1 INQUIRE by file and FOROTS, 18-36 INQUIRE specifiers ACCESS, 11-43 BLANK, 11-44 CARRIAGECONTROL, 11-44 DIRECT, 11-44 ERR, 11-45 EXIST, 11-45 FORM, 11-45 FORMATTED, 11-45 IOSTAT, 11-46 NAME, 11-46 NAMED, 11-47 NEXTREC, 11-47 NUMBER, 11-47 OPENED, 11-48 RECL, 11-48 RECORDSIZE, 11-48 RECORDTYPE, 11-48 SEQUENTIAL, 11-49 UNFORMATTED, 11-49 INQUIRE statement, 11-42 by file, 11-42 by unit, 11-43 INQUIRE statement specifiers, 11-43 Integer constant expressions, 5-5 Integer constants, 3-1 Interaction with BLISS-36, 15-18 Interaction with COBOL, 15-16 Internal compiler errors, C-13 Internal file identifier, 10-13 Internal files, 10-7,· 10-49 Internal READ statement, 10-50 Internal WRITE statement, 10-50 Intrinsic functions, 13-1 character, 13-12 Using, 13-2 INTRINSIC statement, 7-18 IOSTAT specifier, 10-19 in CLOSE, 11-39 in INQUIRE, 11-46 in OPEN, 11-20 Iteration control DO, 9-12 Keywords, 1-1 L editing, 12-38 Labels compiler generated, 16-23 LABELS with DEBUG, 16-12 Large arrays and extended addressing, 16-16 Large code applications, 16-18 Index-6 Large executable code and extended addressing, 16-17 LEGAL subroutine, 13-34 Length of character actual arguments, 13-51 Length of character dummy a r g urn en t s, 1 3 -- 51 Length specification, 7-6 LIMIT specifier in CLOSE, 11-39 in OPEN, 11-21 Line continuation field, 2-3 LINE subroutine, F-4 Line types, 2-4 Line-sequence number, 16-22 Line-sequenced source files, 2-7 Lines blank, 2-7 comment, 2-5 continuation, 2-4 debug, 2-6 initial, 2-4 multi-statement, 2-5 LINK CLROVL subroutine, 15-20 GETOVL subroutine, 15-20 INIOVL subroutine, 15-20 LOGOVL subroutine, 15-20 REMOVL subroutine, 15-20 RUNOVL subroutine, 15-20 SAOVL subroutine, 15-20 LINK overlay facilities, 15-19 LINK overlay handler, 18-31 Linking TWOSEG REI... files, 16-21 List-directed ACCEPT sequential, 10-41 List-directed formatting, 10-16 list-directed formatting, 12-41 List-directed PRINT sequential, 10-46 List-directed PUNCH sequential, 10-48 List-directed READ sequential, 10-27 List-directed REREAD sequential, 10-39 List-directed TYPE sequential, 10-44 List-directed WRITE sequential, 10-34 LISTING switch, 16-9 LNMAP switch, 16-3, 16-10 LOAD command, 16-1, 16-5 Loading FORDDT, 17-5 Loading programs, 16-1, 16-5 LOCK subroutine, 19-3 Logical assignment statements, 8-3 Logical constant expressions, 5-10 Logical constants, 3-6 Logical device assignments, 10-12 Logical expressions, 5-7 Logical IF statements, 9-4 Logical operators, 5-8 Logical segment control words, 18-4 Logical two-branch IF statement, 9-4 Logical unit identifier, 10-11 LOGOVL in LINK, 15-20 LSCW, 18-4 CONTINUE, 18-4 END, 18-4 START, 18-4 LSNGET function, 13-19 MACHINE-CODE switch, 16-10 MACRO calls for FOROTS, 18-17 MACROCODE switch, 16-3 Memory allocation routines, 18-29 Memory layout extended addressing, 15-22 Memory management FOROTS, 15-20 Over 1 a y, 1 5 - 2 0 Message summary, 16-34 Messages compiler, C-l warning, 16-34, C-8 Mixed-mode assignments, 8-2 Mixed-mode expressions, 5-15 Mixed-mode operations, 5-3 MKTBL subroutine, F-5 MODE specifier in OPEN, 11-21 MPG function, 18-35 Multi-statement lines, 2-5 MVBITS subroutine, 13-35 Name Common block, 7-9 NAME specifier in CLOSE, 11-36 in INQUIRE, 11-46 in OPEN, 11-23 NAMED specifier in INQUIRE, 11-47 NAMELIST statement, 12-44 NAMELIST-controlled input, 12-45 NAMELIST-controlled output, 12-46 NAMELIST-statement formatting, 10-16, 12-44 NAMELIST-statement READ sequential, 10-28 NAMELIST-statement WRITE sequential, 10-35 Names array, 4-3 symbolic, 4-1 variable, 4-2 .NEQV. logical operator, 5-8 Nested Block IF constructs, 9-9 Nested DO statements, 9-14 NEXTREC specifier in INQUIRE, 11-47 Index·-7 NOANSI with FLAG, 16-22 NOBINARY switch, 16-10 NOCOMMON with EXTEND, 16-20 NODATA with EXTEND, 16-20 NOERRORS switch, 16-3, 16-10 NOEXTEND switch, 16-10 NOF77 switch, 16-3, 16-10 NOFLAG switch, 16-3 NOFLAG-NON-STANDARD switch, 16-10 non-FORTRAN files, 15-10 non-FORTRAN programs, 15-10 NONE with DEBUG, 16-12 NONE with FLAG, 16-22 NONE with NOWARN, 16-15 Nonexecutable statements, 1-1, 6-2 Nonrepeatable edit descriptors, 12-S .NOT. logical operator, 5-S NOVMS with FLAG, 16-22 NOWARN arguments ALL, 16-15 NONE, 16-15 NOWARN switch, 16-3, 16-10, 16-14 NUMBER specifier in INQUIRE, 11-47 NUMBER subroutine, F-9 Numeric edit descriptors, 12-29 Numeric editing, 12-29 Numeric type specification statements, 7-5 o (octal) editing, 12-36 Object time system, lS-l Octal constants, 3-5 OPEN ACCESS specifier in, 11-6 ASSOCIATEVARIABLE specifier in, 11-S BLANK specifier in, 11-9 BLOCKSIZE specifier in, 11-10 BUFFERCOUNT specifier in, 11-10 CARRIAGECONTROL specifier in, 11-11 DENSITY specifier in, 11-12 DEVICE specifier in, 11-13 DIALOG specifier in, 11-13 DIALOG= specifier in, 11-14 DIRECTORY specifier in, 11-14, 11-16 DISPOSE specifier in, 11-16 ERR specifier in, 11-17 FILE specifier in, II-IS FILESIZE specifier in, II-IS FORM specifier in, 11-19 Implicit, 11-3 INITIALIZE specifier in, 11-18 IOSTAT specifier in, 11-20 LIMIT specifier in, 11-21 MODE specifier in, 11-21 NAME specifier in, 11-23 PADCHAR specifier in, 11-24 OPEN (Cont.) PARITY specifier in, 11-24 PROTECTION specifier in, 11-25, 11-27 READONLY specifier in, 11-28 RECL specifier in, 11-2S RECORDSIZE specifier in, 11-2S RECORDTYPE specifier in, 11-29 STATUS specifier in, 11-30 TAPEFORMAT specifier in, 11-32 TYPE specifier in, 11-30 VERSION specifier in, 11-34 OPEN statement, 11-1 deferred, 11-2 on connected unit, 11-4 OPEN statement specifiers, 11-4 Summary of, 11-6 OPENED specifier in INQUIRE, 11-48 Operations arithmetic, 5-2 Operators arithmetic, 5-2 concatenation, 5-6 hierarchy of, 5-14 log ical, 5-S relational, 5-11 Optimization Global, 15-6 I/O, 15-9 Optimization techniques, 15-6 OPTIMIZE switch, 16-3, 16-10, 17-17 OPTION switch, 16-10 .OR. logical operator, 5-8 Order of stored array elements, 4-5 Ordering of statements, 6-2 Output formatted, 12-15 NAMELIST-controlled, 12-46 OVERFL subroutine, 13-35 Overlay facilities LINK, 15-19 Overlay handler LINK, 18-31 Overlay memory management, 15-20 Overlays Functions for, 18-31 P editing, 12-25 PADCHAR specifier in OPEN, 11-24 PARAMETER statement, 7-20 Parenthetical subexpressions, 5-13 PARITY specifier in OPEN, 11-24 PAUSE statement, 9-19 PDUMP SUbroutine, 13-36 PLOT subroutine, F-I0 PLOTS subroutine, F-2 Positional editing, 12-18 Index-S PRINT sequential FORMAT-statement, 10-45 sequential List-'directed, 10--46 PRINT statement, 10-45 Priority interrupt levels, 19-2 Priority interrupt system, 19-~. PROGRAM statement, 6-4 Prog rams compiling, 16-1, 16-5 debugg ing, 16-5 executing, 16-5 load ing, 16-1, 16-5 non-FORTRAN, 15-10 source, 1-1 wr i t i ng, 1 5-1 Programs debugging, 16-1 Programs executing, 16-1 PROTECTION specifier in CLOSE, 11-36 in OPEN, 11-25, 11-27 Psect placement /EXTEND, 16-17 PSECT with EXTEND, 16-20 PUNCH sequential FORMAT-statement, 10-48 sequential List--directed, 10--48 PUNCH statement, 10-47 Q editing, 12-29 QUIETX Subroutine r 13-36 R editing, 12-40 RAD function, 18-33 RAN function, 13-19 RANS function, 13-19 RCH function, 18-33 READ direct FORMAT-statement, 10-17 direct unformatted, 10-30 sequential FORMAT-statement, 10-26 sequential List-directed, 10·-27 sequential NAMELIST-statement, 10-28 Sequential unformatted, 10-29 READ statement, 10-24 internal, 10-50 READ transfers formatted, 10-26 unformatted, 10-29 READONLY specifier in OPEN, 11-28 Real constants, 3-2 Real-time devices, 19-1 Real-time error messages, 19-7 Real-time software, 19-1 RECL spec i f ier in INQUIRE, 11-48 in OPEN, 11-28 Record specifier, 10-13 RECORDSIZE specifier in INQUIRE, 11-48 in OPEN, 11-28 RECORDTYPE specifier in INQUIRE, 11-48 in OPEN, 11-29 Register allocation Global, 15-9 Relational expressions, 5-11 Relational operators, 5-11 Remark field, 2-4 Remarks, 2-6 REMOVL in LINK, 15-20 Reordering computations, 15-4 Repeat specification, 7-22 Repeatable edit descriptors, 12-7 REREAD sequential FORMAT-statement, 10-38 sequential List-directed, 10-39 REREAD statement, 10-37 RESET in FOROTS, 15-11 RETURN statement, 13-47 REWIND statement, 11-54 RNT function, 18-34 ROT function, 18-34 Routines calling BLISS-36, 15-19 channel allocation, 18-30 channel deallocation, 18-30 memory allocation, 18-29 RPG function, 18-35 RPSI function, 18-35 RRS function, 18-34 RTINIT subroutine, 19-3 RTREAD subroutine, 19-5 RTSLP subroutine, 19-6 RTSTRT subroutine, 19-4 RTWAKE subroutine, 19-6 RTWRIT subroutine, 19-5 Running the FORTRAN-10 compiler, 16-2 Running the FORTRAN-20 compiler, 16-6 RUNOVL in LINK, 15-20 S ed i ting, 12-24 SAOVL in LINK, 15-20 SAVE statement, 7-24 SAVFMT subroutine, 13-37 SAVRAN subroutine, 13-37 SCALE subroutine, F-I0 SECNDS function, 13-19 Sequential access, 10-5, 18-3 Sequential FORMAT-statement PUNCH, 10-48 Sequential FORMAT-statement ACCEPT, 10-40 Sequential FORMAT-statement PRINT, 10-45 Sequential FORMAT-statement READ, 10-26 Index--9 Sequential FORMAT-statement REREAD, 10-38 Sequential FORMAT-statement TYPE, 10-43 Sequential FORMAT-statement WRITE, 10-32 Sequential List-directed ACCEPT, 10-41 Sequential List-directed PRINT, 10-46 Sequential List-directed PUNCH, 10-48 Sequential List-directed READ, 10-27 Sequential List-directed REREAD, 10-39 Sequential List-directed TYPE, 10-44 Sequential List-directed WRITE, 10-34 Sequential NAMELIST-statement READ, 10-28 Sequential NAMELIST-statement WRITE, 10-35 SEQUENTIAL specifier in INQUIRE, 11-49 Sequential unformatted READ, 10-29 Sequential unformatted WRITE, 10-36 SETABL subroutine, F-ll SETRAN subroutine, 13-38 Sharable high segment, 16-35 SKIPFILE statement, 11-57 SKIPRECORD statement, 11-56 Slash editing, 12-23 Software Re a 1- tim e, 1 9-1 SORT subroutine, 13-38 Source files line-sequenced, 2-7 Source program, 1-1 SP editing, 12-24 Specific functions, 13-2 Specification statements, 7-1 Specifiers Carriage-control, 12-9 CLOSE statement, 11-34 END=, 10-17 ERR=, 10-18 format, 10-13 INQUIRE statement, 11-43 IOSTAT, 10-19 OPEN statement, 11-4 record, 10-13 SRTINI subroutine, 13-39 SS editing, 12-24 START LSCW, 18-4 Starting FORDDT, 17-5 Statement block, 9-8 Statement definition, 2-2 Statement field, 2-4 Statement format, 2-2 Statement functions, 13-15 Using, 13-16 Statement label constants, 3-7 Statement label field, 2-3 Statement numbers, 2-3 Statements ACCEPT, 10-40 arithmetic assignment, 8-1 arithmetic IF, 9-3 ASSIGN, 8-3 assigned GO TO, 9-3 ass i g nm e nt, 8 -1 BACKFILE, 11-57 BACKSPACE, 11-55 BLOCK DATA, 14-1 block IF, 9-5 CALL, 13-44 character assignment, 8-4 character type specification, 7-6 CLOSE, 11-34 COMMON, 7-8 compilation control, 6-4 computed GO TO, 9-2 CONTINUE, 9-17 control, 9-1 DATA, 7-21 data transfer, 10-1 DECODE, la-51 Device control, 10-1, 11-52 DIMENSION, 7-1 DO WHILE, 9-13 ELSE, 9-5 ELSE IF THEN, 9-5 ENCODE, la-51 END, 9-20 END DO, 9-17 END IF, 9-5 ENDFILE, 11-55 ENTRY, 13-45 EQUIVALENCE, 7-11 executable, 1-1, 6-1 EXTERNAL, 7-17 . File control, 10-1, Ll-l FIND, 11-53 FORMAT, 12-2 FUNCTION, 13-20 GO TO, 9-1 IF, 9-3 IF THEN, 9-5 IMPLICIT, 7-7 INCLUDE, 6-4 indexed DO, 9-10 Input/output, 10-1 INQUIRE, 11-42 internal READ, 10-50 internal WRITE, la-50 INTRINSIC, 7-18 logical assignment, 8-3 logical IF, 9-4 logical two-branch IF, 9-4 NAM ELI S T, 1 2 - 4 4 nested DO, 9-14 Index-l0 Statements (Cont.) nonexecutable, 1-1, 6-2 numeric type specification, '7-5 OPEN, 11-1 order ing of, 6-2 PARAMETER, 7-20 PAUSE, 9-19 PRINT, 10-45 PROGRAM, 6-4 PUNCH, 10-47 READ, 10-24 REREAD, 10-37 RETURN, 13-47 REW I ND, 11- 54 SAVE, 7-24 SKIPFILE, 11-57 SKIPRECORD, 11-56 specification, 7-1 STOP, 9-18 SUBROUTINE, 13-43 Summary of, A-I TYPE, 10-42 type specification, 7-4 unconditional GO TO, 9-2 UNLOAD, 11-54 WRITE, 10-30 STATI subroutine, 19-6 STATO subroutine, 19-5 STATUS specifier in CLOSE, 11-40 in OPEN, 11-30 STOP statement, 9-18 Storage common, 7-9 Subexpressions parenthetical, 5-13 Subprogram function, 13-20 subroutine, 13-22 Subprograms Block data, 14-1 Subroutine calls writing, 15-11 SUBROUTINE statement, 13-43 Subroutine subprogram, 13-22 Subroutines, 13-1, 13-22 ALCCHR, 13-24 AXIS, F-2 BLKRW, 19-4 calling COBOL, 15-18 CAXIS, F-3 CDC 0 S , 1 3 - 2 5 CDEXP, 13-26 CDLOG, 13-26 CDS IN, 13-27 CDSQRT, 13-28 CHKDIV, 13-28 CLRFMT, 13-29 CONNECT, 19-4 DATE, 13-29 DISCON, 19-7 DISMIS, 19-6 DIVERT, 13-30 Subroutines (Cont.) DTOGA, 13-30 DUMP, 13-30 ERRSET, 13-31 ERRSNS, 13-32 EXIT, 13-33 FFUNIT, 13-33 FORRTF, 19-1 FORTRAN-supplied, 13-24 FORTRAN-supplied plotter, F-l GTODA, 13-34 ILL, 13-34 LEGAL, 13-34 LINE, F-4 LOCK, 19-3 MKTBL, F-5 MVBITS, 13-35 NUMBER, F-9 OVERFL, 13-35 PDUMP, 13-36 PLOT, F-10 PLOTS, F-2 programming considerations, 15-3 QUITEX, 13-36 RTINIT, 19-3 RTREAD, 19-5 RTSLP, 19-6 RTSTRT, 19-4 RTWAKE, 19-6 RTWRIT, 19-5 SAVFMT, 13-37 SAVRAN, 13-37 SCALE, F-10 SETABL, F-l1 SETRAN, 13-38 SORT, 13-38 SRTINI, 13-39 STATI, 19-6 STATO, 19-5 SYMBOL, F-12 TIME, 13-39 TOPMEM, 13-40 TRACE, 13-41 UNLOCK, 19-7 user-defined, 13-42 WHERE, F-12 Subscript array element, 4-3 Substrings character, 4-6 Summary of CLOSE specifiers, 11-35 Summary of OPEN statement specifiers, 11-6 Summary of statements, A-I Switches ABORT, 16-9 BINARY, 16-9 CROSSREF, 16-3, 16-9 DEBUG, 16-3, 16-9, 16-11 DFLOATING, 16-3, 16-9 ECHO-OPTION, 16-9 Index--ll Switches (Cont.) EXPAND, 16-3, 16-9 EXTEND, 16-9 F66, 16-3, 16-9 F77, 16-3, 16-9 FLAG, 16-3, 16-21 FLAG-NON-STANDARD, 16-9 FORTRAN-20 compiler, 16-9 GFLOATING, 16-3, 16-9 INCLUDE, 16-3, 16-9 LISTING, 16-9 LNMAP, 16-3, 16-10 MACHINE-CODE, 16-10 MACROCODE, 16-3 NOBINARY, 16-10 NOERRORS, 16-3, 16-10 NOEXTEND, 16-10 NOF77, 16-3, 16-10 NOFLAG, 16-3 NOFLAG-NON-STANDARD, 16-10 NOWARN, 16 - 3, 16 -1 0, 16 -1 4 OPTIMIZE, 16-3, 16-10, 17-17 OPTION, 16-10 SYNTAX, 16-3, 16-10 SYMBOL subroutine, F-12 Symbolic names, 4-1 SYNTAX switch, 16-3, 16-10 UNFORMATTED specifier in INQUIRE, 11-49 Unformatted WRLTE direct, 10-36 sequential, 10-36 Unformatted WRITE transfers, 10-35 Unit identifier logical, 10-11 UNIT specifier in CLOSE, 11-41 UNLOAD statement, 11-54 UNLOCK subroutine, 19-7 UPG function, 18-36 User-defined character set, F-9 User-defined external functions, 13-20 User-defined subroutines, 13-42 Using FOROTS, 18-14 Using FORRTF, 19-2 Using function subprograms, 13-21 Using intrinsic functions, 13-2 Using statement functions, 13-16 Using the compiler, 16-1 Using the FORTRAN-20 compiler, 16-5 T editing, 12-19 TAPE FORMAT specifier in OPEN, 11-32 TIM2GO function, 13-19 TIME subroutine, 13-39 TL editing, 12-20 TOPMEM subroutine, 13-40 TR editing, 12-20 TRACE subroutine, 13-41 TRACE with DEBUG, 16-12 TYPE sequential FORMAT-statement, 10-43 sequential List-directed, 10-44 Type declaratars, 7-5 Type specification statements, 7-4 character, 7-6 n urn e ric, 7 - 5 TYPE specifier in OPEN, 11-30 TYPE statement, 10-42 unconditional GO TO statements, 9-2 Unformatted data transfers, 10-8 to ASCII devices, 10-8 Unformatted READ direct, 10-30 sequential, 10-29 Unformatted READ transfers, 10-29 Variable names, 4-2 Variables, 4-2 compiler generated, 16-24 VERSION specifier in OPEN, 11-34 VMS with FLAG, 16-22 Warning messages, 16-34, C-8 WHERE subroutine, F-12 WRITE direct FORMAT-statement, 10-33 direct unformatted, 10-36 sequential FORMAT-statement, 10-32 sequential List-directed, 10-34 sequential NAMELIST-statement, 10-35 sequential unformatted, 10-36 WRITE statement, 10-30 internal, 10-50 WRITE transfers formatted, 10-31 unformatted, 10-35 Writing arithmetic expressions, 5-2 Writing programs, 15-1 Writing subroutine calls, 15-11 WRS function, 18-34 X editing, 12-21 Z (hexadecimal) Index-12 editing, 12-37 TOPS-10/TOPS--20 FORTRAN Language Manual AA-N383B-TK READER'S COMMENTS NOTE: This form is for documen1 comments only. DIGITAL will use comments submitted on this form at the company's discretion. If you require a written reply and are eligible to receive one under Software Performance Report (SPR) service, submit your comments on an SPR form. Did you find this manual understandablE, usable, and well-organized? Please make suggestions for improvement. Did you find errors in this manual? If so, specify the error and the page number. Please indicate the type of reader that you most nearly represent. [J Assembly language programmer [J Higher-level lan~]uage programmer [J Occasional programmer (experinnced) [J User with little programming experience o Student programmer [J Other (please specify)~~~_~~~~~~~~~~~~.~~~~~~~ Name Date ~____________ Organization ~_ _~ _ _ _ _ _~ _______ Telephone ___~_ _ _ _ __ Street ___________ City _ _ _ _ _ _ _ ,~_ __ _ ____~ State ____ Zip Code _ _ __ or Country --~.--0 ~.ot -F~HDere 00 oTear ~ w o and Tape - - - - - - - - - - - - - - - - - - - - - - rfl-ll1--------~~~~;:;~~- ~ if Mailed in the United States BUSINESS REPLY MAIL •• FIRST CLASS PERMIT NO. 33 MAYNARD MASS. POSTAGE WILL BE PAID BY ADDRESSEE SOFTWARE PUBLICATIONS - - - - 200 FOREST STREET MR01-2/L 12 MARLBOROUGH, MA 01752 • Do Not Tear - Fold Here and Tape - - - - - - - - - - - - - - - - - - - - - - - - - - - -- - - - - - - - - - - - - -- -
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies