Digital PDFs
Documents
Guest
Register
Log In
AA-N383B-TK
May 1987
592 pages
Original
22MB
view
download
Document:
FORTRAN Language Manual Feb87
Order Number:
AA-N383B-TK
Revision:
0
Pages:
592
Original Filename:
AA-N383B-TK_FORTRAN_Language_Manual_Feb87.pdf
OCR Text
TOPS-10/TOPS-20 FORTRAN Language Manual AA-N383B-TK,AD-N383B-T1 February 1 987 This document describes the language elements of FORTRAN-10 and FORTRAN-20. This manual supersedes the TOPS-10jTOPS-20 FORTRAN Language Manual, order number AA-N383B-TK. Operating System and Version: TOPS-10 V7.03 TOPS-20 V4.1 (KS) TOPS-20 V6. 1 (KL) Software Version: FORTRAN-10 V 11 FORTRAN-20 V 11 LlNK-10 V5.1 LlNK-20 V6 RMS-20 V3 digital equipment corporation maynard, massachusetts First Printing, February 1983 Revised, May 1985 Updated, February 1987 Copyright © 1983, 1987 by Digital Equipment Corporation. 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 Equipment Corporation or its affiliated companies. The following are trademarks of Digital Equipment Corporation: DEC DECmate DECUS DECwriter DIBOL MASSBUS MicroVAX PDP PjOS Professional Q-BUS Rainbow RSTS RSX RT UNIBUS VAX VAXBI VAXELN VMS VT Work Processor ~DrnDIl~D The postpaid 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 PREFACE 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 5.1 5.1.1 INTRODUCTION OVERVI EW • • • • • • • • • • • • • • • • • 1-1 MANUAL ORGANIZATION • • • • • • • • • • 1-1 FORTRAN Language Elements (Part I) • • • • • • • 1-2 FORTRAN Statements (Part II) • • • • • 1-2 FORTRAN Language Usage (part III) • • 1-3 APPENDIXES • • • • • • 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 •••• ••• • STATEMENT 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, VARIABLES, AND ARRAYS SYMBOLIC NAMES • • • • • • • • 4-1 ••••••••• 4-2 VARIABLES ARRAYS • • • • • • • • • • • • • • • 4-3 Array Element Subscripts • • • • • • • • • • • • 4-3 Dimensioning Arrays • • • • • 4-4 Order of Stored Array Elements • • 4-5 CHARACTER SUBSTRINGS • • • • • • • • • • • • • 4-6 EXPRESSIONS ARITHMETIC EXPRESSIONS • • • • • • • • • • Rules for Writing Arithmetic Expressions iii • • 5-1 • 5-2 February 1987 5.1.2 5.1.2.1 5.2 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 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 Arithmetic Constant Expressions • • • • • • 5-5 Integer Constant Expression • 5-5 CHARACTER EXPRESSIONS • • • • • • • • • • • 5-6 Character Con~tant Expression • • • • • • 5-7 LOGICAL EXPRESSIONS • • • • • • • • • • • • • 5-7 Logical Constant Expression •••• 5-10 RELATIONAL EXPRESSIONS • • • • • 5-11 EVALUATION OF EXPRESSIONS 5-13 Parenthetical Subexpressions • • 5-13 Hierarchy of Operators • • • • • • 5-14 Mixed-Mode Expressions • • ••• 5-15 Use of Logical Operands in Mixed-Mode Expressions • • •• •••• 5-15 CONSTANT EXPRESSIONS • • • • • • • • • • • 5-15 EXECUTABLE AND NONEXECUTABLE STATEMENTS EXECUTABLE STATEMENTS NONEXECUTABLE STATEMENTS • • • • • • • • ORDERING OF FORTRAN STATEMENTS • COMPILATION CONTROL STATEMENTS • PROGRAM Statement INCLUDE Statement • • • • • • • 6-1 • • • 6-2 • 6-2 • • • 6-4 • • 6-4 • • 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 ASSIGNMENT STATEMENTS ARITHMETIC ASSIGNMENT STATEMENT • • • • • • • • • 8-1 LOGICAL ASSIGNMENT STATEMENTS • • • • • • • • 8-3 ASSIGN (STATEMENT LABEL) ASSIGNMENT STATEMENT 8-3 CHARACTER ASSIGNMENT STATEMENT • • • • • • • • • • 8-4 CONTROL STATEMENTS GO TO STATEMENTS • • • • • • • • • • Unconditional GO TO Statements • Computed GO TO Statements Assigned GO TO Statements IF STATEMENTS • • • • • • • • • • • • • • Arithmetic IF Statements • • • • • • • • Logical IF Statements iv • • 9-1 • 9-2 • • • 9-2 9-3 9-3 9-3 • 9-4 February 1987 9.2.3 9.2.4 9.2.4.1 9.2.4.2 9.2.4.3 9.3 9.3.1 9.3.1.1 9.3.1.2 9.3.2 9.3.3 9.3.4 9.3.5 9.3.6 9.4 9.5 9.6 9.7 9.8 CHAPTER 10 Logical Two-Branch IF Statements • Block IF Statements • • • • • Statement Blocks • • • • • Block IF Examples • • • • • • • • • • • Nested Block IF Constructs • • DO STATEMENT • • • • • • Indexed DO Statement • • • • • • • • Executing an Indexed DO Statement DO Iteration Control • • • • DO WHILE Statement • • • • • The Range of a DO Statement Nested DO Statements • • • • • Extended Range • • • • • • • • Permitted Transfer Operations • • • • • END DO STATEMENT • CONTINUE STATEMENT • STOP STATEMENT • • • • • PAUSE STATEMENT • • • • END STATEMENT • • • • • • 9-4 • • 9-5 • • 9-8 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.1 10.2 DATA ACCESS • • • • • • Sequential Access 10.2.1 Direct Access • • • • 10.2.2 10.2.3 Keyed Access (TOPS-20 RMS) 10.3 FORMATTED AND UNFORMATTED DATA TRANSFERS • • 10.3.1 Formatted Data Transfers • • 10.3.1.1 Internal Files • • • • • • • • • • 10.3.2 Unformatted Data Transfers • • Unformatted Data Transfer to ASCII Devices 10.3.3 10.4 DATA TRANSFER STATEMENT FORMS • • • • 10.4.1 Data Transfer Statement Names • • • • • • 10.4.2 Data Transfer Control-Information List • • 10.4.3 Unit References in Data Transfer Statements • 10.4.3.1 FORTRAN Logical Unit Identifier ••••• • 10.4.3.2 Internal File Identifier • • • • • • • • • • Record Number References In Data Transfer 10.4.4 Statements • • • • • • • • • • • • • • • • • • Format References in Data Transfer Statements 10.4.5 FORMAT-Statement Formatting •••••••• 10.4.5.1 List-Directed Formatting • • • • • 10.4.5.2 NAMELIST-Statement Formatting • • • • • • • 10.4.5.3 10.4.6 Optional End-of-File Transfer of Control (END=) • • • • • • • • • • • • • • • • • • Optional Data Transfer Error Control (ERR=) • 10.4.7 Optional Error Variable For Error Reporting 10.4.8 (IOSTAT=) •••••••••••••••••• 10.4.9 Key-Field-Value Specifier (TOPS-20 RMS) • 10.4.9.1 Key Attributes. • • • • • • • • • • • 10.4.10 Key-of-Reference Specifier. • • • • • •• 10.4.11 Data Transfer Statement Input/Output Lists • • 10.4.11.1 Simple List Elements. • • • • • • • 10.4.11.2 Implied DO Lists. • • • • • • • • 10.5 READ STATEMENT • • • • • • • • • • • • • • 10.5.1 Formatted READ Transfers. • • • • • • • 10.5.1.1 Sequential FORMAT-Statement READ • • • • • • 10.5.1.2 Direct-Access FORMAT-Statement READ •• 10.5.1.3 Sequential List-Directed READ • 10.5.1.4 Sequential NAMELIST-Statement READ. • 10.5.2 Unformatted READ Transfers. • • •• 10.5.2.1 sequential Unformatted READ • v 10-5 10-5 10-6 10-6 10-6 10-6 10-7 10-8 10-8 10-8 10-9 10-9 10-9 10-11 10-11 10-13 10-13 10-14 10-15 10-16 10-17 10-18 10-19 10-20 10-21 10-23 10-23 10-23 10-24 10-25 10-27 10-29 10-29 10-30 10-30 10-31 10-32 10-32 February 1987 10.5.2.2 Direct-Access Unformatted READ. • ••• 10.5.3 Indexed READ Transfers (TOPS-20) ••• 10.5.3.1 Sequential Indexed READ • • • • • • • • • • 10.5.3.2 Formatted Indexed READ •••• 10.5.3.3 Unformatted Indexed READ •••• • 10.6 WRITE STATEMENT • • • • • • • • 10.6.1 Formatted WRITE Transfers • • • • • 10.6.1.1 Sequential FORMAT~Statement WRITE ••• 10.6.1.2 Direct-Access FORMAT-Statement WRITE • • • • 10.6.1.3 Sequential List-Directed WRITE • • • • • • • 10.6.1.4 Sequential NAMELIST-Statement WRITE •• 10.6.2 Unformatted WRITE Transfers •• 10.6.2.1 Sequential Unformatted WRITE. • • • •• 10.6.2.2 Direct-Access Unformatted WRITE ••• 10.6.3 Writing to RMS Files (TOPS-20) • • • ••• 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. • •••• 10.13 DELETE STATEMENT (TOPS-20) • • • •••• 10.13.1 Current-Record DELETE •••••••••• 10.13.2 Direct-Access DELETE. • • • • •••• 10.14 REWRITE STATEMENT (TOPS-20) •••• • 10.14.1 Formatted REWRITE • • • • • • 10.14.2 Unformatted REWRITE Statement ••••• 10.15 UNLOCK STATEMENT (TOPS-20) • • • • CHAPTER 11 10-33 10-33 10-34 10-34 10-35 10-35 10-37 10-37 10-38 10-39 10-40 10-40 10-41 10-41 10-42 10-43 10-43 10-44 10-45 10-45 10-46 10-47 10-48 10-49 10-50 10-50 10-51 10-52 10-53 10-53 10-54 10-55 10-56 10-59 10-60 10-60 10-60 10-61 10-61 10-62 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.1 FILE-CONTROL STATEMENTS 11.2 OPEN STATEMENT Impl ic i t OPEN 11.2.1 11.2.2 OPEN on a Connected Unit 11.3 OPEN STATEMENT SPECIFIERS 11.3.1 ACCESS Specifier 11.3.2 ASSOCIATEVARIABLE Spec! f ier 11.3.3 BLANK Specifier 11.3.4 BLOCKSIZE Specifier 11.3.5 BUFFERCOUNT Specifier BYTESIZE Specifier 11.3.6 11.3.7 CARRIAGECONTROL Specifier 11.3.8 DEFAULTFILE Specifier (TOPS-20) 11.3.9 DENSITY Specifier 11.3.10 DEVICE Specifier 11.3.11 DIALOG Specifier 11.3.12 DIALOG= Specifier 11.3.13 DIRECTORY Specifier (TOPS-10) 11.3.14 DIRECTORY Specifier (TOPS-20) DISPOSE Specifier 11.3.15 . .. · · · · · · · · · ·· ····· · · · · 11-1 11-1 ·· ·· · · · · ·· ·· ·· ·· .. ·· · · · ······ · · · ·· ·· ·· ··· ··· ··· ··· ··· ··· ··· · · ·· ·· ·· · · · · · · · · ·· · · ·· · ·· ········ vi 11-3 11-4 11-4 11-7 11-8 11-9 11-10 11-11 11-12 11-12 11-14 11-15 11-15 11-16 11-16 11-17 11-18 11-19 February 1987 11.3.16 ERR Specifier • • • • • • • • • • • • • • • • 11.3.17 FILE Specifier • • • • • • • • • • • • • • • • 11.3.17.1 Remote File Specifications (TOPS-20) • • • • 11.3.18 FILESIZE (INITIALIZE) Specifier (TOPS-10) •• 11.3.19 FORM Specifier • • • • • • • • • • 11.3.20 IOSTAT Specifier • • • • • • • 11.3.21 KEY Specifier (TOPS-20) • • • • • • • 11.3.22 LIMIT Specifier • • • • • • 11.3.23 MAXREC Specifier (TOPS-20) • • • • • 11.3.24 MODE Specifier • • • • • •••• 11.3.25 NAME Specifier • • • ~ • • • • • • 11.3.26 NOSPANBLOCKS Specifier (TOPS-20) • • • • • 11.3.27 ORGANIZATION Specifier (TOPS-20) • 11.3.28 PADCHAR Specifier •••••••••••• 11.3.29 PARITY Specifier • • • • • • • • •• 11.3 .. 30 PROTECTION Specifier (TOPS-10) • • • • • • • • 11.3.31 PROTECTION Specifier (TOPS-20) 11.3.32 READONLY Specifier • • • • • • •• 11.3.33 RECL (RECORDSIZE) Specifier ••••••• 11.3 .. 34 RECORDTYPE Specifier • • • • • • • • • • 11.3.35 SHARED Specifier (TOPS-20) •••• 11.3.36 STATUS (TYPE) Specifier •••••• • 11.3.37 TAPEFORMAT SPECIFIER • • • • • 11.3.38 UNIT Specifier (Required) •• • ••••• 11.3.39 USEROPENSpecifier (TOPS-20) •• 11.3.40 VERSION Specifier (TOPS-10) ••••••••• 11.4 CLOSE STATEMENT • • • • • • • • • 11.4.1 Impl ic it CLOSE • '. • • • • • • • 11.5 CLOSE STATEMENT SPECIFIERS • • • • • • 11.5.1 DEVICE, DIRECTORY, FILE, NAME, and PROTECTION Specifiers • • • • • • •••••••••• 11.5.2 DIALOG Specifier • • ••••• 11.5.3 DIALOG= Specifier ••••• 11.5.4 DISPOSE Specifier • 11.5.5 ERR Specifier •• • •••••••• 11.5.6 IOSTAT Specifier • • • • • • • • 11.5.7 LIMIT Specifier • • •••• 11.5.8 STATUS Specifier • • • • • • •••• 11.5.9 UNIT Specifier (Required) •• 11.6 OPEN AND CLOSE STATEMENT EXAMPLES • 11.7 INQUIRE STATEMENT • • • • • • 11.7.1 INQUIRE by File • • • • • • 11.,7.2 INQUIRE by Unit •• • • • • • • 11.7.3 INQUIRE Specifiers • • • • • •• 11.7.3.1 ACCESS Specifier • • • 11.7.3.2 BLANK Specifier. •• • • • 11.7.3.3 BYTESIZE Specifier • • • • • • • • • •• 11.7.3.4 CARRIAGECONTROL Specifier •••• • • 11.7.3.5 DIRECT Specifier • • • 11. 7 • 3 ..-6 ERR Specifier • • • • • 11.7.3.7 EXIST Specifier • • • • • • • 11.7.3.8 FORM Specifier • • • • • • • • • • • • • FORMATTED Specifier ••• 11.7.3.9 IOSTAT Specifier • • • • • •• 11.7.3.10 11.7.3.11 KEYED Specifier • 11.7.3.12 NAME Specifier • • • • • • • • • • • • NAMED Specifier • • • • • 11.7.3.13 NEXTREC Specifier' • 11.7.3.14 NUMBER Specifier • • 11.7.3.15 11.7.3.16 OPENED Specifier • • • • • 11.7.3.17 ORGANIZATION Specifier • • • •••• 11.,7.3.18 RECL (RECORDSIZE) Specifier •••••••• RECORDTYPE Specifier 11.7.3.19 SEQUENTIAL Specifier • • • • • • • 11.7.3.20 vi i 11-20 11-20 11-21 11-21 11-22 11-23 11-24 11-25 11-25 11-26 11-28 11-28 11-29 11-29 11-30 11-30 11-32 11-34 11-34 11-36 I1-j8 11-39 11-41 11-42 11-42 11-43 11-43 11-44 11-44 11-46 11-46 11-47 11-47 11-49 11-49 11-49 11-50 11-51 11-51 11-52 11-52 11-53 11-54 11-54 11-54 11-54 11-54 11-55 11-55 11-55 11-56 11-56 11-56 11-56 11-57 11-58 11-58 11-58 11-58 11-59 11-59 11-59 11-60 February 1987 11.7.3.21 UNFORMATTED Specifier ••••••• 11.8 DEVICE CONTROL STATEMENTS ••• 11.8.1 FIND Statement. • • • • • • •• 11.8.2 REWIND Statement.. •••••• • 11.8.3 UNLOAD Statement. • • • • • 11.8.4 BACKSPACE Statement • • • • • • • • • • 11.8.5 ENDFILE Statement • • • • • • • • • 11.8.6 SKIPRECORD Statement •••• 11.8.7 SKIPFILE Statement. • •••••••••• 11.8.8 BACKFILE Statement • • • • • • CHAPTER 12 11-60 11-61 11-62 11-63 11-64 11-64 11-65 11-66 11-67 11-67 FORMATTED DATA TRANSFERS 12.1 12.1.1 12.1.2 FORMAT-STATEMENT FORMATTING • • • • • • • • • • 12-2 Specifying a Format List in a FORMAT Statement 12-2 Specifying a Format Specification as a Character Expression • • • • • • • • • • • • • 12-3 12.1.3 Specifying a Format Specification in a Numeric Array • • • • • • • • • • • • • • • • • 12-4 12.1.4 Specifying a FORMAT Statement Using an ASSIGNed Variable • • •••••• • • • • • • • 12-4 12.1.5 The Ordering and Interpretation of Format List Items • • • • • • • • • • • • 12-5 12.2 EDIT DESCRIPTORS • • • • • • • • • • • • •• 12-6 12.2.1 Repeatable Edit Descriptors • • • • • 12-7 12.2.2 Nonrepeatab1e Edit Descriptors • 12-8 12.2.3 Carriage-Control Specifiers • • • • •• 12-9 12.3 INTERACTION OF INPUT/OUTPUT LIST AND FORMAT LIST 12-11 12.3.1 General Description • • • • • • • 12-11 12.3.2 Formatted Input • • • • • • • • • • • • 12-14 12.3.3 Formatted Output • • • • • • • • • • • • • • • 12-15 12.3.4 Embedded Format Specifications • • • • • • 12-15 12.4 FORMAT EDITING • • • • • • • • • 12-16 12.4.1 Apostrophe (I) Editing • • • • • • • 12-16 12.4.2 H Editing •••••••• •• • 12-17 12.4.3 positional Editing • • • • • • • • 12-18 12.4.3.1 T, TL, and TR Editing ••••••• • 12-19 12.4.3.2 X Editing •••••••••••••• • 12-21 12.4.4 $ (Dollar Sign) Editing • • 12-22 12.4.5 / ( S 1 ash) Ed i t i ng • • • • • • • • 12 - 23 12.4.6 : (Colon) Editing •• • • • • 12-24 12.4.7 S, SP,and SS Editing • • • • • • • • • • 12-24 12.4.8 P Editing •••• • • • • 12-25 12.4.9 BN and BZ Editing • • • • • • • • • • • 12-28 12.4.10 Q Editing • • • 12-29 12.4.11 Numeric Editing • • • • • • 12-29 12.4.11.1 I Editing • • • • • • • • • 12-31 12.4.11.2 F Editing • • • • • • • • 12-32 12.4.11.3 E and D Editing • • • • • • • • •• 12-32 12.4.11.4 G Editing • • • • • • • • • • • • • • 12-33 12.4.11.5 Complex Editing • • • • • • • • • • 12-36 12.4.11.6 o (Octal) Editing • • • • • • 12-36 12.4.11.7 Z Editing • • • • 12-37 12.4.12 L Editing • • • • • • • • • • • • • 12-38 12.4.13 A Editing • • • • • • • • • • • • • • 12-39 12.4.14 R Editing • • • • • • • • • • • • • 12-40 12.5 LIST-DIRECTED FORMATTING • • • • • 12-41 12.6 NAME LIST-STATEMENT FORMATTING • • 12-44 12.7 NAMELIST STATEMENT • • • • • • • • • • • • • 12-44 12.7.1 NAMELIST-Contro11ed Data Input Transfer • • • 12-45 12.7.2 NAMELIST-Contro11ed Data Output Transfers • • 12-46 vi ii February 1987 CHAPTER 13 FUNCTIONS AND SUBROUTINES 13.1 INTRINSIC FUNCTIONS • • • • • • • • • 13.1.1 Using an Intrinsic Function • • • •• 13.1.2 Character Intrinsic Functions • • • • • • • • 13.1.3 Character Comparison Functions • • • • • • • • 13.1.4 Bit Manipulation Functions • • 13.2 STATEMENT FUNCTIONS • • • • • • • • 13.2.1 Defining a Statement Function • • • • • • • • Using a Statement Function • • • • •• 13.2.2 Statement Function Restrictions • • • • 13.2.3 13.3 EXTERNAL FUNCTIONS • • • • • • .. • • • • 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 13.4 SUBROUTINES • • • • • • • • • • • • • • • • • • FORTRAN-Supplied Subroutines. • • • • • • 13.4.1 13.4.1.1 ALCCHR Subroutine • • • • • CDABS Function • • 13.4.1.2 13.4.1.3 CDCOS Subroutine • • • • • • • • 13.4.1.4 CDSXP Subroutine. • • • • • • • CDLOG Subroutine • ••• • • • • • • 13.4.1.5 13.4.1.6 CDSIN Subroutine • • • • • • • • 13.4.1.7 CDSQRT Subroutine • • • • • • • • CHKDIV Subroutine • • • • • • 13.4.1.8 CLRFMT Subroutine • • 13.4.1.9 DATE Subroutine • • • • • 13.4.1.10 DIVERT Subroutine • 13.4.1.11 13.4.1.12 DTOGA • • • • • • • • • • • • ••• • • DUMP Subroutine • • • • • • • • 13.4.1.13 ERRSET Subroutine • • • • • • • • 13.4.1.14 ERRSNS Subroutine • • • • • • • • 13.4.1.15 EXIT Subroutine • 13.4.1.16 FFUNIT Subroutine • • • • • • 13.4.1.17 GTODA Subroutine • • • 13.4.1.18 ILL Subroutine • • • • • • • • • • • • • 13.4.1.19 LEGAL Subroutine • 13.4.1.20 MVBITS Subroutine • • • • • 13.4.1.21 OVERFL Subroutine • • • • • 13.4.1.22 PDUMP Subroutine • 13.4.1.23 QUIETX Subroutine • • • • • 13.4.1.24 SAVFMT Subroutine • • • • • • • • • • 13.4.1.25 SAVRAN Subroutine • • • • •• • • • 13.4.1.26 SETRAN Subroutine • • • • • • • 13.4.1.27 SORT Subroutine • • • • • • •• • 13.4.1.28 SRTINI Subroutine • • • • • • • • • • • 13.4.1.29 TIME Subroutine • • • • • • 13.4.1.30 TOPMEM Subroutine ••••• 13.4.1.31 TRACE Subroutine • • • • • • • • 13.4.1.32 User-Defined Subroutines •••• • 13.4.2 SUBROUTINE Statement • • • • • • • • 13.4.2.1 CALL Statement • • • • 13.4.2.2 Execution of a CALL Statement • • • • • 13.4.2.3 Actual Arguments for a Subroutine • • • 13.4.2.4 ENTRY Statement •••••••••• • 13.4.3 RETURN Statement • • • • • • • • • • • • • 13.4.4 Dummy and Actual Arguments • • • • • • • • • • 13.4.5 Length of Character Dummy and Actual 13.4.5.1 Arguments • • • • • • • • • • • • • • • • • Character and Hollerith Constants as Actual 13.4.5.2 Arguments ••••••••••••••••• 0 ix • • • • 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-31 13-32 13-33 13-33 13-34 13-34 13-34 13-35 13-35 13-36 13-36 13-37 13-37 13-38 13-38 13-39 13-39 13-40 13-41 13-42 13-43 13-44 13-44 13-45 13-45 13-47 13-49 13-51 13-51 February 1987 CHAPTER 14 14.1 CHAPTER 15 BLOCK DATA SUBPROGRAMS BLOCK DATA STATEMENT • . . . . . . . . . . . . . 14-1 WRITING USER PROGRAMS 15.1 15.1.1 15.1.2 GENERAL PROGRAMMING CONSIDERATIONS • • • • • •• 15-1 Accuracy and Range of Double-Precision Nu.mbers 15-1 Writing FORTRAN Programs for Use on Other Computers • • • • • • • • • • • • • • 15-2 15.1.2.1 Remote Links • • • • • • • • • • • 15-2 15.1.2.2 Reducing Network Overhead • • • • 15-2 Using Floating-Point DO Loops •••• 15.1.3 15-2 15.1.4 Computation of DO Loop Iteratio~s • • • • 15-2 .. 1 15.1.5 Subroutines - Programming Considerations • 15-3 15.1.6 Reordering of Computations • • .- •• 15-4 Dimensioning of Dummy Arrays • • • • • • • 15.1.7 15-5 15.2 FORTRAN GLOBAL OPTIMIZATION • • • • • • • 15-6 15.2.1 Optimization Techniques • • • • • • • • 15-6 Elimination of Redundant Computations 15.2.1.1 15-6 15.2.1.2 Reduction of Operator Strength • • • 15-7 Removal of Constant Computation from Loops • 15-7 15.2.1.3 Constant Folding and Propagation • 15.2.1.4 15-8 Removal of Inaccessible Code • • • • • • • • 15-9 15.2.1.5 Global Register Allocation • • • 15.2.1.6 15-9 I/O Optimization • • • • • • • • • 15.2.1.7 15-9 Uninitia1ized Variable Detection 15.2.1.8 15-9 Test Replacement •• •• • • • • • • • • 15-9 15.2.1.9 programming Techniques for Effective 15.2.2 Optimization . . . . . . . . . . . . . . . . . . 15-10 15.3 FUNCTION SIDE EFFECTS • • • • • • • • • • • • • 15-10 15.4 INTERACTING WITH NON-FORTRAN PROGRAMS AND FILES 15-10 15.4.1 Using The Sharable High-Segment FOROTS • • • • 15~10 15.4.2 Calling Sequences • • • 15-11 15.4.3 Accumulator Usage • • • • • • • 15-11 15.4.4 Argument Lists • • • • • • • • • • • • • 15-12 15.4.5 Argument Types • • • • • • • • • • • 15-14 15.4.6 Description of Arguments • • • 15-14 15.4.7 Interaction with COBOL. • • • • • • • 15-16 Calling FORTRAN Subprograms from COBOL 15.4.7.1 Programs • • • • • • • • • • • • • • • 15-16 15.4.7.2 Calling COBOL Subroutines from FORTRAN Programs • • • • • • • • • • • • • •• 15-18 15.4.8 Interaction with BLISS-36 • • • • • • • • • • 15-18 15.4.8.1 Calling FORTRAN Subprograms From BLISS-36 Programs • • • • • • • • • • • • • • • • • • 15-18 15.4.8.2 Calling BLISS-36 Routines From FORTRAN • • • 15-19 15.4.9 LINK Overlay Facilities • • • • • • • • • • • 15-19 15.4.10 FOROTS and Overlay Memory Management • • • • • 15-20 15.4.11 Extended Addressing Memory Layout (TOPS-20 only) •••••••••• • • • 15-22 15.5 USING INDEXED FILES (TOPS-20 ONLY) • • • • • 15-24 Creating an Indexed File • • • • • • • • • • • 15-24 15.5.1 15.5.2 Writing Indexed Files • • • • • • • • • • 15-26 15.5.2.1 Duplicate Values in Key Fields • • • 15-26 15.5.2.2 Preventing the Indexing of Alternate Key Fields • • • • • • • • 15-27 15.5.3 Reading Indexed Files • • • • • • 15-28 15.5.4 Updating Records • • • • • • • • • •• •• 15-29 15.5.5 Deleting Records • • • • • • • • • • • • 15-29 15.5.6 Current Record and Next Record Pointers • • • 15-29 15.5.7 Exception Conditions • • • • • • • • • • • • • 15-30 x February 1987 CHAPTER 16 USING THE FORTRAN COMPILER 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 USING THE FORTRAN-10 COMPILER • • • • TOPS-10 COMPILE-Class Commands • • RUNNING THE FORTRAN-10 COMPILER • • •• TOPS-10 Compiler Command Switches • • •• USING THE FORTRAN-20 COMPILER TOPS-20 COMPILE-Class Commands • • RUNNING THE FORTRAN-20 COMPILER • 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 Building Large-Code Applications • • 16.5.2.2 • • Arguments to /EXTEND • • • • • • • • • 16.5.3 Linking with TWOSEG REL Files 16.5.4 • • • THE /FLAG (/FLAG-NON-STANDARD) SWITCH • • • • • 16.6 READING A FORTRAN COMPILER LISTING • • 16.7 • • • Compiler-Generated Variables • • • • 16.7.1 • • • ERROR REPORTING • • • • • • • • • • 16.8 • Fatal Errors and Warning Messages 16.8.1 • Message Summary • • • • 16.8.2 • CREATING A SHARABLE HIGH SEGMENT FOR A FORTRAN 16.9 PROGRAM • • • • • • • • • • • • • • • • • 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 I 17.8 17.9 CHAPTER 18 16-1 16-1 16-2 16-2· 16-5 16-5 16-6 16-8 16-11 16-15 16-16 16-17 16-17 16-18 16-19 16-19 16-21 16-21 16-22 16-24 16-33 16-34 16-34 16-35 USING THE FORTRAN INTERACTIVE DEBUGGER (.FORDDT) 17-2 ..········· 17-2 ·· ·· ·· ·· ·· ·· 17-3 17-4 17-4 . · · ·· 17-5 · · · ·· 17-6 17-7 · · ·· ·· ·· ·· ·· · · · · · · ·· 17-16 17-17 . · · · · ·· ·· ·· · . · · · · ·· 17-17 · 17-17 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 FORDDT AND FORTRAN-20 EXTENDED ADDRESSING USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) FEATURES OF FOROTS • • • ••• • • • • • •• ERROR PROCESSING • • • • ••• • • • • • •• INPUT/OUTPUT FACILITIES •••••••••• Input/Output Channels Used By FOROTS (TOPS-10 Only) •••••••••• • •••• 18.3.2 File Access ••••••• • • • •• 18.3.3 Closing Files After Non-standard Termination. 18.3.3.1 Sequential Access • • • • • • • • •• 18.3.3.2 Direct (Random) Access Mode • • • • • • • • 18.4 ACCEPTABLE TYPES OF DATA FILES AND THEIR FORMATS 18.4.1 ASCII Data Files. • • • • • • • 18.4.2 FORTRAN Binary Data Files • • • • • • •• 18.4.2.1 Format of Binary Files. • • • • • •• 18.4.3 RMS Data Files (TOPS-20 only) •••• 18.5 USING FOROTS • • • • • ••••• • 18.5.1 FOROTS Entry Points • • • • • • • 18.1 18.2 18.3 18.3.1 xi 18-1 18-2 18-2.1 18-2.1 18-3 18-3 18-3 18-4 18-4 18-4 18-4 18-4 18-14 18-15 18-15 February 1987 18.S.2 18.S.3 18.S.3.1 18.S.3.2 18.S.3.3 Calling Sequences • • • • • • • • • • • 18-16.1 MACRO Calls for FOROTS Functions • • • • * • • 18-17 Sequential-Access Calling Sequences • 18-18 Internal File Calling Sequences • • • • 18-19 NAMELIST I/O, Sequential-Access Calling Sequences • • • • • • • • • • • • • • • 18-20 18.S.3.4 Array Offsets and Factoring • • • • • • • • 18-20 I/O Statements, Direct-Access Calling 18.S.3.S Sequences • • • • • • • • • • • • • • • 18-22 Default Devices Statements, Calling 18.S.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 Listg ••••••• • 18-25 18.5.3.10 OPEN and CLOSE Statements, Calling Sequences 18-28 18.S.3.11 Memory Allocation Routines • • • • • • • • • 18-29 18.S.3.12 Channel Allocation and Dea11ocation Routines 18-30 18.6 FUNCTIONS TO FACILITATE OVERLAYS • • • • • 18-31 18.7 LOGICAL/PHYSICAL DEVICE ASSIGNMENTS • • 18-36 18.8 FOROTS AND INQUIRE BY FILE STATEME~T • • • • • • 18-36 18.9 USEROPEN PROCEDURES • • • • • • • • • • • • 18-38 18.9.1 Example of a USEROPEN • • • • • • • • • • • • 18-38 18.9.2 RMS/FOROTS Data and Control Structures. • 18-40 CHAPTER 19 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-10 ONLY) 19.1 INTRODUCTION 19.2 USING FORRTF • • • • 19.2.1 Memory • • • • • • • • • • 19.2.2 Modes • • • • • • • priority-Interrupt Levels 19.2.3 19.2.4 Masks • • • • • • • • SUBROUTINES 19.3 19.3.1 LOCK • • • • • • • • • • 19.3.2 RTINIT • • • • • • 19.3.3 CONECT • • • • • RTSTRT • 19.3.4 19.3.S BLKRW • • • • • • • 19.3.6 RTREAD • • • • • • 19.3.7 RTWRIT •••• STATO 19.3.8 19.3.9 STATI • • • • RTSLP 19.3.10 RTWAKE 19.3.11 19.3.12 DISMIS • • • • • • • • • 19.3.13 DISCON 19.3.14 UNLOCK • • • • • • • • • • Error Messages • 19.3.1S • • • • • • • • • 19~7 • • • • • • • • 19-7 19-7 ALPHABETICAL DESCRIPTION OF FOROTS MESSAGES D-10 APPENDIX A SUMMARY OF FORTRAN STATEMENTS APPENDIX B ASCII-1968 CHARACTER CODE SET APPENDIX C COMPILER MESSAGES APPENDIX D FOROTS ERROR MESSAGES D.1 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 xii February 1987 APPENDIX E INTERACTIVE DEBUGGER (FORDDT) ERROR MESSAGES APPENDIX F FORTRAN-SUPPLIED PLOTTER SUBROUTINES F.1 PLOTS SUBROUTINE • • • F-2 F.2 AXIS SUBROUTINE • • • • • • F-2 CAXIS SUBROUTINE • • • • • • • • • • F-3 F.3 F.4 LINE SUBROUTINE • • • • • • F-4 MKTBL SUBROUTINE • • F-5 F.5 Character Tables • • F-5 F.5.1 Creating a Character Table • F-6 F.5.1.1 Creating a Stroke Table • • • • • F-6 F.5.1.2 Sample Character Stroke Table • • • • • • • • F-7 F.5.1.3 FORTRAN- and User-Defined Character Sets • • • F-9 F.5.1.4 F.6 NUMBER SUBROUTINE • • • • • • • • • F-9 F.7 PLOT SUBROUTINE F-10 F.8 SCALE SUBROUTINE • • F-10 F.9 SETABL SUBROUTINE F-11 SYMBOL SUBROUTINE • • • • • F-12 F.10 F.11 WHERE SUBROUTINE • • • • • • F-12 . 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 • • • • • • • • • 2-3 A 3 x 3 x 2 Array • • • • • • • • • • • • • • 4-4 Ordering of FORTRAN Statements • • • • • • • • 6-3 Shared Storage using EQUIVALENCE Statement • 7-12 Equivalence of Substrings • • • • 7-13 Equivalence of Character Arrays • • • • • 7-14 Valid Equivalencing •••••• 7-16 Invalid Equivalencing •••••• • • • • 7-16 Examples of Block IF Constructs • • • • • • • 9-7 Components of Data Transfer Statements • • 10-9 TOPS-10 File Protection Number • • • • 11-31 TOPS-20 Protection Number •••• • • 11-33 Run-time Memory Layout for Section Zero • • 15-21 Plotter Character Table Entry • • • F-6 Character Stroke Table Entry • • • • • • F-6 Sample Character Stroke Table •••••• • F-8 2-1 3-1 FORTRAN Character Set • • • • • • • • • • • • • Comparison of Real, D-f1oating, and G-floating Numbers ••••••••••••••••••• Use of Symbolic Names ••••••••••• Arithmetic Operations and Operators • • • • Type of the Result Obtained from Mixed-Mode Operations • • • • • • • • • • • • • • • • • Permitted Base/Exponent Type Combinations • • • Logical Operators • • • • • • • • • • Logical Operations Truth Table • • • • • • Relational Operators and Operations • • • • Hierarchy of FORTRAN Operators • • • • • • • • • Rules for Conversion in Mixed-Mode Assignments • FORTRAN I/O Statement Categories • • ••• Summary of Data Transfer Statement Forms FORTRAN Logical Device Assignments • TABLES 4-1 5-1 5-2 5-3 5-4 5-5 5-6 5~ 8-1 10-1 10-2 10-3 xiii • 2-2 3-4 • 4-1 • 5-2 • • • • 5-3 5-5 5-8 5-9 5-11 5-14 • 8-2 10-2 10-3 10-12 February 1987 10-4 10-5 10-6 10-7 10-8 10-9 10-10 10-11 10-12 10-13 10-14 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 16-9 17-1 18-1 18-2 19-1 D-1 Summary of READ Statement Forms • • • • Summary of WRITE Statement Forms • • • Summary of REREAD Statement Forms • Summary of ACCEPT Statement Forms •••• • Summary of TYPE Statement Forms • • Summary of PRINT Statement Forms • • Summary of PUNCH Statement Forms • • • • • • • • Summary of Internal READ/WRITE and ENCODE/DECODE Statement Forms • • • • • • • • • • • • Summary of DELETE Statement Forms • Summary of REWRITE Statement Forms • • • • • • • Summary of UNLOCK Statement Forms • • • • • Summary of OPEN Statement Specifiers and Arguments •••••••••• • • • • DEVICE and MODE Cross-Table • • • • • TOPS-10 Protection Code Values • • • • TOPS-20 Protection Code Values • • • • Summary of CLOSE Statement Specifiers and Arguments ••••••••••••• Summary of Device-Control Statements • • Repeatable FORTRAN Edit Descriptors • • •• Nonrepeatable FORTRAN Edit Descriptors • Carriage-Control Specifiers • • • • • • • Record, Format List, and I/O List Interaction • Default Field Widths for Numeric Edit Descriptors •••••••••••••••••• Effect of Data Magnitude on G-Format Output Conversion • • • • • • • • • FORTRAN Instrinsic Functions • • • • • FORTRAN-Supplied Subroutines. • • • • • • • Argument Types and Types Codes • • • • • • • Memory Allocations for /EXTEND and /NOEXTEND • • FORTRAN-10 Compiler Switches • • • • •• FORTRAN-20 Compiler Switches • Arguments to /DEBUG Switch • • • • • • • Legal Dummy and Actual Argument Type Associations • • • • • • • • • • • • • ••• Legal Dummy and Actual Argument Structure Associations • • • • • • • • • • • •••• Arguments to /NOWARN Switch ••• /EXTEND Default Memory Layout ••• Arguments to /EXTEND Switch • • • • • • • • • • Arguments to /FLAG Switch •••••• FORDDT Commands • • • • • • • • • • • • • • • • FOROTS Entry Points •••••••••••••• Function Numbers and Function Codes • Error Messages - Code Format and Full Message Format • • • • FOROTS Error Codes • • • • • • xiv 10-28 10-36 10-43 10-45 10-48 10-50 10-52 10-54 10-59 10-61 10-62 11-5 11-27 11-32 11-33 11-45 11-61 12-8 12-9 12-11 12-13 12-30 12-35 13-4 13-23 15-14 15-23 16-3 16-9 16-12 16-14 16-15 16-15 16-16 16-20 16-22 17-1 18-15 18-32 19-8 • D-3 February 1987 PREFACE The TOPS-10/TOPS-20 FORTRAN Language Manual reflects the software as of Version 11 of the FORTRAN-10/20 compiler, the FORTRAN-10/20 Object Time System (FOROTS), and the FORTRAN-10/20 debugging program (FORDDT) • This manual describes the FORTRAN language as implemented for the TOPS-10 operating system (FORTRAN-10) and the TOPS-20 operating system (FORTRAN-20). Any differences between FORTRAN-10 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-10/20 extensions and additions to ANSI FORTRAN are in blue print in this manual. FORTRAN-10/20 VII xv February 1987 MANUALS REFERENCED The following manuals are referenced from TOPS-10 publications: • TOPS-10 Operating System Comma!1 ds Manual • SOS Reference Manual • TOPS-10 Monitor Calls Manual • TOPS-10 Hardware Reference Manual • TOPS-10 LINK Reference Manual • TOPS-10 SORT/MERGE User's Guide • TOPS-10 FORTRAN Installation Guide --- The following manuals are referenced from TOPS-20 publications: • • TOPS-20 Commands Reference Manual TOPS-20 EDIT Reference Manual • TOPS-20 User's Guide • • • • • TOPS-20 Monitor Calls Manual TOPS-20 Link Reference Manual TOPS-20 SORT/MERGE Use r' s Guide --- TOPS-20 FORTRAN Installation Guide TOPS-20 RMS User's Guide • RMS-20 Pro9rammer's Reference Manual The following TOPS-10/TOPS-20 manual are referenced: • FORTRAN-10/20 and VAX FORTRAN Compatibility Manual • TOPS-10/TOPS-20 FORTRAN Pocket Guide • TOPS-10/TOPS-20 COBOL-74 Language Manual • TOPS-10/20 BLISS Lan9uage Guide • TOPS-10/20 Common Math Library Manual FORTRAN-10/20 VII xvi February 1987 CHAPTER 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 "American National Standard FORTRAN, X3.9-l978" (referred to as the FORTRAN-77 standard) at the full-language level. FORTRAN-IO/20 provides many extensions and additions to the FORTRAN-77 standard that greatly 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 consists 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 carried out. multiplication, division, and 2. It specifies the type and format of the data being processed. 3. It specifies the characteristics of the source program. FORTRAN statements are composed of keywords (words that are recognized by the compiler) used with elements of the language set: constants, variables, and expressions. There are two basic types of FORTRAN statements: executable and nonexecutable. Executable statements specify the 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 included in the program. The compilation of executable statements results in the creation of executable code in the object program. Nonexecutable statements provide information only to the compiler; they do not create executable code. 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. State~~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 FORTRAN 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. Chapter 5, EXPRESSIONS, introduces and describes FORTRAN 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 device-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-lO/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-lO/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 REAL-TIME SOFTWARE (TOPS-lO ONLY), describes how to use the FORTRAN real-time software. This chapter is for TOPS-lO installations only. 1-3 INTRODUCTION 1.2.4 APPENDIXES The appendixes describe various useful tqpics 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 C~ARACTER 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 error 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 used 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 character 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 is 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 g h i j k 1 m n 0 p q r s t u v w x y z Digits o 1 234 5 6 789 Symbols ! " # $ & , ( ) * + - , Exclamation point Quotation Mark Number Sign Dollar Sign Ampersand Apostrophe Left Parenthesis Right Parenthesis Asterisk Plus Underscore - . / : i < = > ... Comma Hyphen (Minus) Period (Decimal Po i nt) Slant (Slash) Colon Semicolon Less Than Equal To Greater Than Circumflex 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 with~n 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. FORTRAN-10/20 VII 2-2 February 1987 CHARACTERS AND LINES I. .------------ Line Character Positions ----------11.....1 \1 2 3 .... 4 5~.1 8 Statement Continuation Label Field Field Figure 2-1: 2.2.1 70 y Statement Field 71 • J 72 " 73 ... Remarks MR-S-1 761 -81 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 zeros 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 number 105. 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-lO/20 considers 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 I through 9, FORTRAN-IO/20 considers the line to be an initial line and the character following the tab is considered to be the first character of the statement field. The character following the initial tab is considered to be in character position 6 for a continuation line, and in character position 7 for an 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 1 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 exception is the tab in a label field, which advances the cursor either to column 6 or 7, depending on the character following the tab (see Section 2.2.1). All other characters after character remarks and do not affect compilation. position 72 are treated as Note that remarks may also be added to a line in character positions 1 through 72, provided the text of the remark is preceded by the symbol "!" (see Section 2.3.3). 2.3 LINE TYPES A line in a FORTRAN source program may be: 1. An initial line 2. A continuation line 3. A multi-statement line 4. A comment line 5. A debug line 6. A blank line These lines are described in Sections 2.3.1 through 2.3.5. 2.3.1 Initial and Continuation Lines FORTRAN statement may occupy the statement fields of up to 100 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. A An initial tab may be used to skip all or part of the label field. If you use an initial tab for this purpose, you must immediately follow it with a nonnumeric character; that is, the first character of the statement field must be nonnumeric. FORTRAN-10/20 VII 2-4 Feb!:'uary 1987 CHARACTERS 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 lines 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 FORMAT (lX,'This example shows how continuation lines', 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. 2.3.2 with 6 identify those Multi-Statement Lines You may write more than one FORTRAN statement in the statement field of one line. The rules for structuring a multi-statement line are: 1. Successive statements must be separated by 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 made a continuation line. a statement An example of a multi-statement line is: 450 DIST=RATE * TIME; TIME=TIME+0.05; CALL PRIME(TIME,DIST) NOTE If a statement 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 following the IF will be executed in all cases, even if the IF expression evaluates 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), *, $, I, 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), *, $, I, 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 IINCLUDE switch is present in the compiler command string. (See Chapter 16 for a description of the compiler switches.) When the IINCLUDE switch is present in the compiler command string, the 0 (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 0 (or d). Note that if the debug statement is an initial line, all of its continuation lines must contain a 0 (or d) in character position 1. 2-6 CHARACTERS AND LINES 2.3.5 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-SEQUENCED SOURCE FILES FORTRAN-IO/20 accepts line-sequenced files as produced by line-oriented text editors (for example, SOS on TOPS-IO or EDIT on TOPS-20). These sequence numbers 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 CHAPTER 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 decimal 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: +345. 3,450 34.5 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 example, 1557.42. 2. A basic real constant followed by a decimal integer exponent written in E notation (exponential notation) form, for example, 1559.E2 or 1559.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, 1559E2 or l55ge2. 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 * 10**(-39) to 1.70 * 10**(+38). The following are examples of valid real constants: -98.765 7.0E+0 .7E-3 5E+5 50115. 50.E1 (= (= (= 7.) .0007) 500000.) (= 500.) The following are examples of invalid real constants: 72.6E512 .375E 500 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 CONSTANTS constant occupies two storage 2. Each double-precision locations. 3. The letter 0 (or d), instead of E, is used in double-precision constants to identify a decimal exponent. On KL model B systems, there are two forms of double-precision number formats. If the /GFLOATING compiler switch is specified (see Chapter 16), the double-precision number format 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 3.4.1 (exponent is too large) ("E" denotes single precision; "0" denotes double precision) Comparison of Real, D-floating, and G-floating For KL model B systems, G-floating 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 3.5 Range Digits of Precision 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 represents 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 "0 "12 1113 1114 1115 "@ "J - LF "K - VT "L - FF "M - CR NOTE The CHAR function (see Chapter 13) can be used to build variables that contain these control characters. The value of a character constant is the string of characters between 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 expressions, 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-justified octal digits; leading zeros are added to fill any unused digits. If you assign a single-octal constant to a double-precision or complex variable, it is stored right-justified in the high-order word of the variable. The low-order portion of the variable is set to zero. If you assign a double-octal constant to a double-precision or complex variable, it is stored right-justified 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, but 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. NOTE If a character constant appears in a numeric context it is considered a Hollerith constant (see Section 3.6) • The following are examples of Hollerith constants: 2HAB 14HLOAD TEST #124 6H#124-A 3-6 CONSTANTS NOTE A tab in a Hollerith constant character; for example, 3H AB. is counted as one You may enter Hollerith constants into DATA statements as a string of: 1. Up to ten 7-bit ASCII characters double-precision type variables 2. Up to five variables 7-bit ASCII characters for for all complex or other type The 7-bit ASCII characters that comprise a Hollerith constant are stored left-justified (starting in the first word of a double-precision constant (the high-order word) or the real part of a complex constant) with blanks placed in empty character positions. Hollerith constants that occupy more than one variable are stored as successive variables in the list. The following example illustrates how the string of characters is stored in a six-element array called A: DIMENSION A(6) DATA A/27HA string of many 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' ling 0' 'f man' 'y chat 'racte' Irs STATEMENT LABEL CONSTANTS Statement labels are statement numbers. numeric 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 (&). For 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 CHAPTER 4 SYMBOLIC NAMES, VARIABLES, AND ARRAYS 4.1 SYMBOLIC NAMES Symbolic names consist of any alphanumeric combination of one to 31 characters, the first of which must be a letter. The special characters dollar sign ($) and underscore ( ) are allowed. If you use more than 31 characters in a symbolic name, the compiler prints a warning message and ignores all but the first 31 characters. The compiler interprets lowercase letters in symbolic names as uppercase letters. The following are examples of legal symbolic names: A12345 IAMBIC PENTAMETER ABLE C The following are examples of illegal symbolic names: .AMBIC 8AB (first character is not a letter) (first character 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 of Symbolic Names Symbolic Names Can Identify 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. Variables Arrays Array elements Substrings Functions Subroutines Intrinsic functions PROGRAM Statement PARAMETER Statement COMMON block names NAMELIST list FORTRAN-10/20 VII For Example For a Detailed Description See Section PI, CONST, LIMIT TAX TAX (3,5) FOO (1: N) MYFUNC, VAL FUN CALCSB, SUB2, LOOKUP SIN, ATAN, COSH TEST Vl,C2,K DATAR, COMDAT DATA3 4.2 4.3 4.3.1 4.4 13.2 13.4 13.1 6.4.1 7.8 7.4 12.6 4-1 February 1987 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. or 2. Variable names that begin with any letter other than I, J, K, L, M, or N are real variables. 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 KA123 AABLE I 0 K Integer Real Integer Real A 4-2 SYMBOLIC NAMES, VARIABLES, 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 array 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 through 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, subtraction, multiplication, division, and exponentiation. For example, (A+B,C*S,D/2) and (A**3,(B/4+C)*E,3) are valid subscripts. 2. Arithmetic expressions (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 evaluated. 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. MAT(A,AB(2*L),.3*TAB(A,M+l,D) ,55) 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-~ ____3 COLUMNS --~v------_J Figure 4-1: q,v MR-S-1755-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 Variable array dimensions are only allowed in 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 dimension 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: The Dimension Declarator Specifies the Array(s) TAB(2) 2 TAB(2,2) TAB(2,2,2) .... TAB(2,2,2,2 ) ...... ...... ...... ...... ...... ...... 1,1,1 1,2,1 2,1,1 2,2,1 -" ---- 1,2,1,1 2,1,1,1 2,2,1,1 1,2 2,1 2,2 1,1,2 1,2,2 2,1,2 2,2,2 .... ,,- _...... 1,1,1,1 1,1 _...... -- 1,1,2,1 I _ ...... 1,2,2,1 ------- 2,1,2,1 2,2,2,1 _- ------- .~ I 1,1,1,2 1,2,1,2 2,1,1,2 2,2,1,2 1,1,2,2 1,2,2,2 2,1,2,2 2,2,2,2 _...... --' -- MR-S-1762-81 NOTE FORTRAN-10/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 Elements 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) 1(2,2) 1(1,3) 1(2,3) In the following list, the elements of the three-dimensional array (B(3,3,3» are stored row by row from left to right and from top to bottom. 4-5 SYMBOLIC NAMES, VARIABLES, AND ARRAYS 8(1,1,1) 8(2,1,1) 8(3,1,1)--1 r------------------------ - 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) - - -8(3,1 ~)= =, [------------- ----------- 8(1,2,2) 8(2,2,2) 8(3,2,2)-"'j 1------ - - - - - - - - - - --------- --8(1,3,2) 8(2,3,2) 8(3,3,2)-"'j [": B(1,1 ~3) - - - B(2~ ~3) - - - 8(3,1 ~3): J r- ------------ ---------- =-.:~~,~~3~ ___ ~~~~~ ___~(~,~~3~:J 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. ~ '" " 0 14 7 21 " Ix I 28 35 0 7 14 " 21 28 Ix I 35 0 Unused '( 7 14 , x I x I x Ix I A 21 28 35 MR·S·2528-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 SYMBOLIC 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 numeric expression that specifies leftmost character position of the substring. the e2 is an optional numeric 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. e 1 • LE. e 2 • LE • 1 en where: len is the length of the character variable or array element. If e1 is omitted, FORTRAN assumes that e1 is 1. FORTRAN assumes that e2 equals len. If e2 is omitted, For example, 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 arithmetic parentheses or logical expression written Operands may be of integer, real, double-precision, complex, octal, double-octal, or Hollerith type. A simple within logical, The following are examples of valid simple arithmetic expressions: 105 lAB TABLE(3,4,5) SIN (X) (A+B) (integer constant) (integer variable) (array elemen 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 + Addition Subtraction Multiplication Division Exponentiation Operation * I ** or Unary Operator + Identity Negation 5.1.1 A - Example A+B A-B A*B AlB A**B or A. . B Example +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 Argument 2 For operators +,-,\1 Integer V1 Real I Integer Real Complex Logical Octal Double Octal Literal 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 1. Integer 1. Real 1. Double Precision 1. Complex 1. Integer 1. Integer 1. Integer 1. Integer 2. Integer 2. Real 2. Double Precision 2. Complex 2. Integer 2. Integer 2. Integer 2. Integer 3. None 3. From Integer to Real 3. From Integer to Double Precision 3. None 3. None 3. None 3. None 4. Conversion on Argument 2 4. None 4. None 4. None 3. From Integer to Complex. Value used as Real part 4. None 4. None 4. None 4. High order word is used directly; low order word is Ignored 4. High order word is used directly; further words are ignored. 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 1. Real 1. Real 1. Double Precision 1. Complex 1. Real 1. Real I. Real 1. Real 2. Real 2. Real 2. Real 2. Double Precision 2. Complex 2. Real 2. Real 2. Real 3. None 3. None 3. None 3. None 3. None 4. None 3. Used directly as the Real part; imaginary part is zero 4. None 3. None 4. From Integer to Real 3. Used directly as the high order word; low order word is zero. 4. None 4. None 4. None 4. High order word is used directly; low order word is ignored. 4. High order word is used directly; further words are ignored. w 4. Conversion on Argument 2 Double Precision Double Precision 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 4. Conversion on Argument 2 1. Double Precision 1. Double Precision 1. Double Precision 1. Double Precision 1. Double Precision 1. Double Precision 1. Double Precision 2. Double Precision 2. Double Precision 2. Double Precision 2. Double Precision 2. Double Precision 2. Double Precision 2. Double Precision 3. None 3. None 3. None 3. None 3. None 3. None 3. None 4. From Integer to Double Precision 4. Used directly as the high order word; low order word is zero 4. None 4. Used directly as the high order word; low order 4. None 4. First two words are used directly further words are ignored word is zero I Complex 1. Complex 1. Complex 2. Complex 2. Complex 2. Complex 3. None 3. None 3. None 4. From Integer to Complex. Value used as Real part. 4. Used directly as the Real part; imaginary part is zero. 4. None 1. Type of operation used 2. Type assocleted with result 3. Conversion on Argument 1 1. Integer 1. Real 1. Double Precision 2. Integer 2. Real 2. Double Precision 3. None 3. None 4. Conversion on Argument 2 4. None 4. None 3. Used directly as the high order word; low order word Is zero 4. None 3. Used directly as the Real part; imaginary part is zero 4. None 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 4. Conversion on Argument 2 ~ 1. Complex 1. Complex 2. Complex 2. Complex 2. Complex 2. Complex 3. None 3. None 3. None 3. None 4. Used directly as the Real part; imaginary part is zero. 4. Used directly as the Real part; imaginary part is zero. 4. None 4. First two words are used directly. Further words are ignored. 1. Complex 1. Integer 1. Integer I. Integer I. Integer 2. Complex 2. Octal 2. Octal 2. Octal 2. Octal 3. None 3. None 3. None 3. None 4. None 4. None 4. High order word is used directly; low order word 4. High order word is used directly; further words 1. Complex 1 Complex 1. Complex ::J ~ <C '0 8. ~ Logical is ignored Octal Double Octal 1. Integer 1. Real 1. Double Precision 1. Complex 1. Integer 1. Integer 1. Integer 1. Integer 2. Integer 2. Real 2. Double Precision 2. Complex 2. Octal 2. Octal 2. Octal 2. Octal 3. None 3. None 3. None 3. None 3. None 4. None 4. None 3. Used directly as the Real part; Imaginary part is zero. 4. None 3. None 4. Conversion on Argument 2 3. Used directly as the high order word; low order word is zero. 4. None 4. None 4. None 4. High order word is used directly; low order word is ignored 4. High order word is used directly; further words are ignored 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 1. Integer 1. Real 1. Double Precision 1. Complex 1. Integer 1. Integer 1. Integer 1. Integer 2. Integer 2. Real 2. Double Precision 2. Complex 2. Octal 2. Octal 2. Octal 1. Octal 3. High order word is used direclly; low order word is Ignored 4. None 3. High order word is used direclly; low order word is ignored 4. None 3. None 3. None 4. None 4. None 3. High order word is used directly; low order word is ignored 4. None 3. High order word is used direclly; low order word is ignored 4. None 3. High order word is used directly; low order word is ignored 4. High order word is used directly. low order word is ignored 3. High order word is used directly; low order words are ignored 4. High order word is used directly; low order words are ignored 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 4. Conversion on Argumenl2 Literal are ignored 1. Type of operation used 2. Type associated with result 3. Conversion on Argument 1 4. Conversion on Argument 2 ,. Integer 1. Real 1. Double Precision 1. Complex 1. Integer 1. Integer 1. Integer 1. Integer 2. Integer 2. Real 2. Double Precision 2. Complex 2. Octal 2. Octal 2. Octal 2. Octal 3. High order word Is used direclly; further words are ignored 4. None 3. High order word Is used directly; further words are ignored 4. None 3. First two words are used directly; further words are ignored 4. None 3. First two words are used directly; further words are ignored 4. None 3. High order word is used directly; further words are ignored 4. None 3. High order word is used directly; further words are ignored 4. None 3. High order word is used directly; further words are ignored 4. High order word is used directly. low order word is ignored 3. High order word is used directly; further words are ignored 4. High order word is used directly; further words are Ignored MR-S·17S1-81 EXPRESSIONS Table 5-3: Permitted Base/Exponent Type Combinations Base Operand Exponent Operand DoublePrecision Complex Real DoublePrecision Complex Real Real DoublePrecision Complex DoublePrecision DoublePrecision DoublePrecision DoublePrecision (Illegal) Complex Complex Complex (I llega 1) Complex Integer Real Integer Integer Real 5.1.2 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 arithmetic constant expression enclosed in parentheses 4. A call to the function ICHAR (see Chapter argument is a character constant expression 13) where the 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 (//). A character expression has the form: character operand [//character 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'//'CDE' is 'ABCDE', which has a length of 5. Note that the expression: A=A//B 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'//'DE')//'F' 'ABC'//('DE'//'F') 'ABC'//'DE'//'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 '//'D E'//'F' has a value of 'ABC D EF'. 5-6 the For EXPRESSIONS 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 argument is an integer constant expression 13) which where the Variables, array elements, substrings, and function references are not allowed. Example: 'HELLO'//CHAR(13)//CHAR(lO)//'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 expresslon 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: 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 Then the Expression: For example, consider the following variables: Variables PHETT, RUN I,J,K DP,D L,A,B CPX,C Type Real Integer Double-Precision Logical Complex 5-9 Is: 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. For example, consider the expression A=C.OR.D, where C="456 and D="201. The operation performed by the processor and the result is: Word Bits 0 Operand C 0 Operand D 0 Result A 0 I 0 0 0 --24 ·0 ·0 .0 25 26 0 0 0 0 0 0 27 1 0 1 28 0 1 1 29 0 0 0 30 1 0 1 31 0 0 0 32 33 1 I 0 0 1 1 34 35 I 0 0 I 1 1 Table 5-5 also illustrates all possible logical combinations of two one-bit binary operands (P and Q) and glves the result of each combination. Simply read 1 for true and 0 for false. 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 Section 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-1etter 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-lO/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 arithmetic 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 numeric expression to a character constant. In this case, the character constant is considered to be a Hollerith (see Section 3.9). You can compare complex operands using only the operators .EQ. (==) and .NE. (#) • Complex quantities 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 expressions consisting of the above Examples of invalid relational expressions variables are: consisting of the above by .EQ. operands and Examples of valid variables are: relational (PHETT) .GT.IO [ -- 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.LE.K) ( (I * RON) • EQ. (I / J) ) • OR • L (I. AND. K) # ( (PHETT) • OR. (RON) ) C#CPX.OR.RON rf 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. 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 paddad 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 CHAR(O) 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**Rl (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 Rl = A**2 (intermediate result) second R2 = Rl**B (final result) 5-14 EXPRESSIONS 5.5.3 Mixed-Mode Expressions Mixed-mode expressions are evaluated on a basis of subexpression-by-subexpression, 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 following 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 Rl is integer 2. R2 X*Rl Rl is converted to type real and is multiplied by X to produce R2 3. R3 D+R2 R2 is converted to type added to D to produce R3 double-precision and is where: Rl and R2, and R3 represent 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 in mixed-mode expressions, the value the logical operand is not converted in any way to accommodate 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 converting 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, 8. DELETE and UNLOCK statements 9. OPEN and CLOSE statements 10. REWIND, BACKSPACE, ENDFILE, BACKFILE, FIND and UNLOAD statements FORTRAN-10/20 Vll GO TO, and character computed GO TO REWRITE, and PRINT statements 6-1 SKIPRECORD, SKIPFILE, February 1987 EXECUTABLE AND NONEXECUTABLE STATEMENTS 6.2 11. CALL and RETURN statements 12. END, END IF, and END DO statements 13. DECODE and ENCODE statements 14. ACCEPT, PUNCH, and TYPE statements 15. INQUIRE statement NONEXECUTABLE STATEMENTS The following statements are classified as nonexecutable: 6.3 SUBROUTINE, ENTRY, and 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 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. Tor 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 February 1987 EXECUTABLE AND NONEXECUTABLE STATEMENTS PROGRAM, FUNCTION, SUBROUTINE, or BLOCK DATA l Statements IMPLICIT Statements PARAMETER Statements Comment Lines and INCLUDE3 Statements Other Specification Statements FORMAT and Ent ry 2 Statements NAMELIST and DATA Statements Statement Function Definitions Executable Statements END 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 any dummy parameters must physically follow the ENTRY statement unless the references appear in the FUNCTION statement, the SUBROUTINE statement, or in a preceding ENTRY statement. 3 The placement of an INCLUDE statement 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 statements.) 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-I0 or TOPS-20 file specification (refer to the TOPS-IO or TOPS-20 Operating System Commands manual). The only restrlction is that unde~'fOPS-IO you cannot specify subdirectory 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 the compilation source listing. A number indicating the depth of nesting of include files precedes each statement listed (default). /NOLIST indicates that the included statements are not to be printed in the compilation listing. /NOCREF indicates statements augment listing. 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 FORTRAN statement except a statement that terminates the current program unit, such as the END, PROGRAM, FUNCTION, SUBROUTINE, or BLOCK DATA statements. The INCLUDEd file can contain other INCLUDE statements. This is called nesting INCLUDE statements. The number of nested levels is 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 ordering 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 of nesting is indicated following the asterisk. 6-5 CHAPTER 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: The form of a dimension dl: ] 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 (567) DIMENSION TABLE (IAB:J,K,M,10:20) where: lAB, J, K, and M are of type integer. 7-2 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 subprograms, 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 needed. 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 (ARRl,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 S81 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(1:N,1:*) 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 dummi 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 Sec t i on 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 v can be anyone of the following declarators: 1. INTEGER 2. REAL 3. DOUBLE PRECISION 4. COMPLEX 5. LOGICAL 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. Examples: INTEGER A, B, TABLE, FUNC REAL R, M, 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 generic properties. NOTE The data type size modifier, *n, is accepted by FORTRAN-lO/20 to be compatible with the type statements used by other manufacturers. You may append this size modifier to the declarators, causing some to elicit messages warning users of the form of the variable specified by FORTRAN-IO/20: Declarator INTEGER*2 INTEGER*4 LOGICAL*l LOGICAL*2 LOGICAL*4 REAL*4 REAL*8 COMPLEX*8 COMPLEX*16 REAL*16 COMPLEX*32 Form of Variable Specified Full word integer with warning message Full word integer Full word logical with warning message Full word logical with warning message Full word logical Full word real Double-precision real Complex Complex with warning message Double-precision real with warning message Complex with warning message 7-5 SPECIFICATION AND DATA STATEMENTS In addition, you can append the data type size modifier to individual variables, arrays, or function names. Its effect is to override, for the particular element, the size modifier (explicit or implicit) of the primary type. For example, REAL*4 A, B*8, C*8(lO), 0 A and 0 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 SOCSEC(100)*9, NAMES (100) The above statement 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) LAST, FIRST The above statements specify two 8-character variables, LAST FIRST. (The PARAMETER statement is described in Section 7.8.) and SUBROUTINE Sl(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 calling program. CHARACTER*16 QUEST*(5*INT(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 separated 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 are type REAL names, unless declared otherwise in an explicit type statement. NOTE Type declarations given in an explicit type specification override those also given in an IMPLICIT statement. IMPLICIT declarations do not affect 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 SPECIFICATION AND DATA STATEMENTS COMMON statements have the following form: COMMON [/cb/] nlist[[,]/[cb]/nlist] ••• where: (See Section 4.1 for cb is an optional common block name. the rules for symbolic names.) nlist is a list of variable names, array names, and array declarators that are to occupy the common area. The items specified for a common area (block) are ordered within storage as .they are listed in the COMMON statement. type or all The items in nlist must be either all numeric data 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 omit the symbolic name for one block in a program unit. This unlabeled block is called the blank common block. The elements of a named common block can be assigned initial values by DATA statements appearing in 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-I0/20 allows any common 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 than one COMMON statement within the same program or subprogram. When extended addressing is in effect, COMMON blocks reside in the large data area by default. 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 common block in the order in which they appear in the source program. For example: COMMON X,Y,Z/ST1/A,B COMMON/ST1/TST(3,4)/ST2/TAB(2,2) COMMON/ST2/C,D,E//P,Q COMMON W has the same effect as the single statement: COMMON X,Y,Z,P,Q,W/ST1/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 /COMl/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 COMl. 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: 0 B C Ito Ito " 14 7 21 0(1) 0(2) \~~ Ix I 28 35 0(3) Unused ~( A Ix I I 0 7 14 21 28 35 0 \ x I x I x 7 14 21 28 Ix I 35 MR-S-2527-83 where x means the bits are not used. 7.5 EQUIVALENCE STATEMENT The EQUIVALENCE statement associates two or more same storage location. variables with the The format of the EQUIVALENCE statement is: EQUIVALENCE (nlist) [,(nlist ••• )] where: nlist is a list of variable names, array elements, array names, and character 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 allocates 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 LOC and the array element SHARE(3) are to share the same location. The relationship of equivalence is transitive. following statements have the same effect: For example, the EQUIVALENCE (A,B), (B,C) EQUIVALENCE (A,B,C) The following EQUIVALENCE statement makes the first character of the character variables KEY and STAR share the same storage location. The character variable STAR is equivalent to the substring KEY (1:10): 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 ea~h 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 WO,d---! 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 equiva~ence 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(l» In this example, each array element of array A shares the same storage area with an element of array B: A(l,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 without 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(lO:13), ID(2:5}) As a result of these statements, the character variables NAME share space as illustrated in Figure 7-2. NAME Character Position 1 2 3 4 5 6 10 Character Position 7 8 9 1 2 10 11 12 13 14 15 16 3 4 5 6 7 8 9 MR·S·2523·83 Figure 7-2: Equivalence of Substrings 7-13 and 10 SPECIFICATION AND DATA STATEMENTS The following statement also aligns the variables as shown 7-2: in Figure EQUIVALENCE (NAME(9:9) ,ID(1:1» If the character substring references are array elements, the EQUIVALENCE statement sets equivalences between the other corresponding characters in the complete arrays. Character elements of arrays can overlap at for example: CHARACTER FIELDS(6)*4, STAR(5)*5 EQUIVALENCE (FIELDS (1) (2:4), STAR (2) any character position, (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 1 2 1 2 3 4 5 6 Character Position 1 2 3 4 1 2 3 4 1 2 3 4 1 5 1 2 3 4 5 1 2 3 2 3 4 5 1 2 3 4 2 3 4 1 2 3 4 1 2 5 1 2 3 4 5 3 4 MR-S-2524-83 Figure 7-3: 1 3 4 FIELDS Subscript Subscript Equivalence of Character Arrays 7-14 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), (~(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: COMMON A,B,C EQUIVALENCE (A,C) 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) } 1----------1 Shared Locations Location Z and A(2) Location A(3) Location A(4) MR-S-1746-S1 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-S1 Figure 7-5: Invalid Equivalencing 7-16 SPECIFICATION AND DATA STATEMENTS 7.5.1 EQUIVALENCE and Extended Addressing 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(l» 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 EXTERNAL 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 statement 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 subpro.gram. 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-10/20. If the /NOF77 compiler switch is specified (see Sections 16.1.3 and 16.2.3), the subprogram names can be intrinsic functions. For compatibility with previous versions of FORTRAN-10/20, the names 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 list. (The name has no generic properties within an argument list.) The names declared in a program EXTERNAL statement are reserved throughout the compilation of the program, and cannot be used in any 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[,funJ ••• 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 reference 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 J ••• ) where: p is a symbolic name. c is a constant expression (except for expressions involving multiplication, division, or exponentiation of complex numbers). (See Chapter 3 for a description 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 ather names in the program unit. must 7-20 appear FORTRAN after constants the are PARAMETER SPECIFICATION AND DATA STATEMENTS 4. Symbolic names must not be redefined 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 the 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/10/,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 variables must be equal to the number of storage locations you specify in its associated list of values. If not, a warning message 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=~1,n2[,n3]) where: dlist is a list of array element names, names, or implied-DO lists. i is the name of an integer index variable. variable, called nl,n2,n3 are integer expressions 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,5)/1,2,3,4,5/ initializes the first five elements of array NARY(2)=2, NARY(3)=3, NARY(4)=4, and NARY(5)=5. 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 specification, for example, 5HABCDE, 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 given 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,O/'TEST' ,30,"77/,(TAB(J) ,J=1,30)/30*5/ The first 30 elements of array TAB are initialized to 5.0. DATA«A(I,J),I=1,5),J=1,6)/30*l.0/ No conversion required. DATA«A(I,J),I=5,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 variables. 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 as 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 'abcde' Y to be initialized to 'fghij' Z to be initialized to 'klbbb' 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 is 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 complex variable; the second word contains the imaginary part. In addition, the following two forms of bit data constants are allowed in DATA statements: O'di ••• dn' Z'hi ••• hn' where di are octal digits and hi are hexadecimal digits with A-F representing the decimal equivalent of 10-15. These constants are right-justified. Note that you can also use the double quote (") form of octal constants as described 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 a~l 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) statements 8.3) 4. Character assignment statements (see Section 8.4) (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 specified value. e is an arithmetic expression. In assignment statements, the equal symbol (=) does not imply equality as it would in algebraic expressions; it implies replacement. For example, the expression v=e is interpreted as "the contents of the location identified as v are to 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 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 0 N H,I D H X Logical D D R,I H,L D X Octal D D R,I H,L D X Hollerith D% D% D& 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 is 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 the Hollerith constant. # 8.2 To convert double-octal numbers to complex, the low-order octal digits are assumed to be the imaginary part, and the high-order digits are assumed to be the real part of the complex value. 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: of type replaced by Results Sample Statement 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 tru~, 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-10/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 = 'PROG2' REVOL(l} = 'MAR'//'CIA' LOCA(3:8) = 'PLANT5' FILE TEXT(I,J+l) (2:N-l) 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 da ta type) 8-5 of character CHAPTER 9 CONTROL ST1\TE.MENTS FORTRAN object programs normally execute statement by statement in the order in which they were presented to the compiler. The following control statements, however, enable you to alter the normal sequence of statement execution: 1. CALL (Section 13.4.2.2) 2. CONTINUE (Section 9.5) 3• DO (Sec t ion 9. 3) 4. DO WHILE (Section 9.3.2) 5. ELSE (Section 9.2.4) 6. ELSE IF THEN (Section 9.2.4) 7. END (Section 9.8) 8. END DO (Section 9.4) 9. END IF (Section 9.2.4) 10 • GO TO ( Sec t ion 9. 1 ) 11. IF (Section 9.2) 12. IF THEN (Section 9.2.4) 13. STOP (Section 9.6) 14. PAUSE (Section 9.7) 15. RETURN (Section 13.4.4) The CALL and RETURN statements are described in Sections 13.4.2.2 and 13.4.4, respectively. The remaining 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 its position within the program. to be There are three kinds of GO TO statements: Unconditional (see Section 9.1.1), Computed (see Section 9.1.2), and Assigned (see Section 9.1.3). 9-1 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 J ••• ) [ , J 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 (20, 10, 5)K CALL XRANGE(K) the variable K acts as a switch, causing a transfer to statement 20 if K=l, to statement 10 if K=2, or to statement 5 if K=3. The subprogram XRANGE is called if K is less than 1 or greater than 3. 9-2 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 STATl GO TO STAT1, (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 statement 2. Equal to 0, control is identified by label s2. transferred to the statement 9-3 CONTROL STATEMENTS 3. Greater than 0, control identified by label s3. is transferred to the statement Examples: IF(ETA)4, 7, 12 Transfers control to statement 4 if ETA is negative, to statement 7 if ETA is 0, and to statement 12 if ETA is greater than O. IF(KAPPA-L(10»20, 14, 14 Transfers control to statement 20 if KAPPA is less than the 10th element of array L and to statement 14 if KAPPA is greater than or equal to the 10th element of array L. 9.2.2 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 9.2.3 Performs an unconditional transfer if the result of the IF is true. Logical Two-Branch IF Statements The format of a logical two-branch IF statement is: [F (e) sl, s2 9-4 CONTROL STATEMENTS where: e 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 statements transfer control to either statement sl or s2, depending on the computed value of the given expression. If the value of the given logical expression is true (negative), control is transferred to statement sl. If the value of the expression is false (nonnegative), control is transferred to statement s2. Examples: IF (LOGl) 10,20 Transfers control to statement 10 if LOGl is true (negative) ; otherwise transfers control to statement 20. IF (A.LT.B.AND.A.LT.C) 31,32 Transfers control to statement 31 if A is less than both Band Ci transfers control to statement 32 if A is greater than or equal to either B or C. 9.2.4 Block IF Statements Block IF statements conditionally execute blocks statements. The four block IF statements are: • IF THEN • ELSE IF THEN • ELSE • END IF (or groups) of The block IF These statements are used in block IF constructs. where the ELSE IF THEN and ELSE construct has the following form, statements are optional: IF (e) THEN block ELSE IF (e) THEN block ELSE block END IF where: e is a logical expression. block is a sequence of zero or more complete FORTRAN statements. This sequence is called a statement block. 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 Construct Flow of Control IF (e) THEN block END IF Execute block IF (e) THEN block1 ELSE block2 END IF IF (e 1) THEN block1 ELSE IF (e2) THEN block2 END IF IF (e1) THEN block1 ELSE IF (e2) THEN block2 ELSE IF (e3) THEN block3 ELSE block4 END IF False Execute block1 Execute block2 Execute block 1 Execute block2 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 ELSE IF THEN and ELSE statements can have statement labels, but these 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 9.8). You can transfer control out of a statement block, but you cannot transfer control back into the block. Note that you cannot transfer control from one statement block into another. DO loops cannot overlap 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 sta teme'nt: Form Example IF (el) THEN blockl ELSE IF (e2) THEN block2 END IF IF (ITEM.LT.A(MIDDLE» THEN UPPER=MIDDLE-l 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 contains a statement: block IF construct Form Example IF (e) THEN blockl ELSE block2 IF (ITEM.GT.A(MIDDLE» LOWER=MIDDLE+I ELSE SEARCH=MIDDLE RETURN END IF END IF with an ELSE THEN Blockl 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 greater than A(MIDDLE), blockl 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 block of another block IF construct. But the nested block IF construct must be completely contained within a statement block; it must not overlap 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 LOWER=l UPPER=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+l ELSE SEARCH=MIDDLE RETURN END IF END IF GOT010 END IF END IF 20 SEARCH=O RETURN END 9-9 CONTROL STATEMENTS If LOWER is less than or equal to UPPER, blockl is executed. Blockl 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 executable statement after the last END IF statement. The nested IF 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, and 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 ----=-- TERMINAL STATEMENT LABEL INDEX VARIABLE I = el, \~~IN~C~R~EM~EN~T~ \ (OPTIONAL) TERMINAL PARAMETER PARAMETER INITIAL PARAMETER MR-S-1760-81 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. If s is omitted, then the loop must be terminated by an END DO statement (see Section 9.4). The terminal statement can be any executable statement than one of the following: • Unconditional or assigned GO TO statement • Arithmetic IF or logical two-branch IF statement • 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, or RETURN statement located within the DO range b. Control is transferred outside the range of the DO loop by an I/O statelnent 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 e1 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 (e1) 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 e1, 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-e1+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 (e1) • NOTE The interpretation of the iteration count described above is different from that of earlier versions of FORTRAN-IO/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-IO/20. If the /NOF77 compiler switch is specified (see Sections 16.1.3 or 16.2.3), the final value of the index variable of the DO statement is undefined after a normal loop exit. Exit from a DO loop may also be accomplished by a transfer of control by a statement within the DO loop range to a statement outside the range of the DO statement. This 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 (If L=O. DO WHILE Statement The DO WHILE statement is similar 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: s is the label of an executable statement that must physically follow in the same program unit. e is a logical expression. The 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 following the loop. If no label appears in a DO WHILE 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:) = 'X, DO WHILE (LINE (I: I) I = I + 1 END DO 9.3.3 .EQ. ' ') 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 C The ranges of loop DO 2 and DO 3 overlap DO 3 c:::= MR-S-17SB-B 1 9-14 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: r°..;;;0_4.;....._ _ _ -411- Outermost DO Loop 004 DO 4 I pO 4 ____ Innermost DO Loop Terminal Statement l-..I.--'--.l-_ _ _ - - - - 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,5 DO J= 1,10 DO K= 1,10 CONTINUE END DO END DO [ END DO 10 9.3.5 CONTINUE MR·S·2526·83 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 This feature makes the flow of a program difficult to follow, does not conform to the FORTRAN-77 standard, and is therefore discouraged. The following rules govern the use of extended range DO loops: 1. The statement that causes the transfer out of the DO loop must be contained within the most deeply nested DO (innermost loop having the same terminal statement). This loop must also contain the statement to which the extended range returns. 2. A transfer into the range of a DO statement is permitted only if the transfer is made from the extended range of that DO statement. ~. The extended range of a DO statement must not contain another DO statement. 4. The extended range of a DO statement cannot change the variable or indexing parameters of the DO statement. 5. You can call a subprogram within an extended range. The following exampLe illustrates the use loop: of an extended index range 200 DIMENSION TABLE(10,5), VALUE (10) LOGICAL LOGARR(10) DO 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 no 200 J= 1, 5 Nonextended range loop 'rABLE (I ,J) 0 CONTINUE 500 GOTO 2000 VALUE(I) 1000 CONTINUE 2000 2100 DO Extended range invocation Invoke function GETVAL with current index Terminal statement for outer loop GETVAL(K) STOP TYPE 2100, I FORMA T (' I = " I 2 ) LOGARR(I) = .TRUE. GOTO 500 Extended range starts Extended range ends and returns 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 transfer into the range of a DO statement is permitted it is made from the extended 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 range loop (in which you leave the loop through a GO TO, execute statements in the extended range, and return to the original loop) The following examples illustrate the transfer from within the ranges of nested DO statements: Valid Transfers Invalid Transfers 01 01 operations permitted • extendedtrange MR-S-1757-Bl 9.4 END DO STATEMENT The END DO statement terminates the range of a DO or DO WHILE statement. The END DO statement must be used to terminate a DO block if the DO or DO WHILE 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 statement is: END DO 9.5 CONTINUE STATEMENT The form of the CONTINUE statement is: CONTINUE Execution of the CONTINUE statement 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(100) 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 before 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: STOPI TEST LINK: Loading [LNKXCT TEST execution] 123456 Elapsed time 0.3 CPU time 0.1 9-18 CONTROL STATEMENTS 10 PROGRAM TEST STOP 'The program 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 February 1987 DATA TRANSFER S.TATEMENTS Table 10-1 FORTRAN I/O Statement Categories Categories Statements Sections Data Transfer READ WRITE REREAD ACCEPT TYPE PRINT PUNCH DECODE Internal READ Internal WRITE DELETE HEWRITE UNLOCK 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12 10.12 10.12 10.12 10.13 10.14 10.15 File Control OPEN CLOSE INQUIRE 1l.2 1l.4 1l.7 Device Control FIND REWIND UNLOAD BACKSPACE ENDFILE SKIPRECORD SKIPFILE BACKFILE 1l.8.1 1l.8.2 11.8.3 11.8.4 1l.8.5 1l.8.6 1l.8.7 11.8.8 I<~NCODE Table 10-2, on the statement forms. FORTRAN-10/20 VII tab-divider, summarizes 10-2 all the data transfer February 1987 DATA TRANSFER STATEMENTS Table 10-2 Data Access Sequential Formatted (FORMAT Statement) Sequential Formatted (List Directed) Sequential Formatted (NAMELIST Statement) Summary of Data Transfer Statement Forms Statement Construct Section READ(UNIT=un,FMT=f[,END=s ][,ERR=s][,10ST AT=ios ])[iolist] READ( un,FMT=f[,END=s][,ERR=s][,IOSTAT=ios])[iolist] READ( un, f[,END=s][,ERR=s][,10STAT=ios]) [iolist] READ f[,iolist] REAp (UNIT=*,FMT=f[,END=s ][,ERR=s ][,IOSTAT=ios])[ iolist] 10.5.1.1 WRITE(UNIT=un,FMT=f[,ERR=s][,10STAT=ios])[iolist] WRITE( un,FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un, f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE fl,iolist] WRITE(UNIT=*,FMT=f[,ERR:"s][,IOSTAT=ios]) [iolist] 10.6.1.1 REREAD(FMT=fl,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] REREAD fl,iolist] 10.7.1 ACCEPT(FMT=f[,END=s][,ERR=s][,IOSTAT=ios])[iolist] ACCEPT fl,iolist] 10.8.1 TYPE(FMT=fl,ERR=sj[,10STAT=ios]) [iolist] TYPE f[,iolistj 10.9.1 PRINT(FMT=fl,ERR=s ][,IOST AT=ios]) [iolist j PRINT f[,iolist] 10.10.1 PUNCH(FMT=fl,ERR=s][,IOSTAT=ios]) [iolistj PUNCH fl,iolistj 10.11.1 ENCODE(c,f,a[,ERR=s][,IOSTAT=ios]) [iolist] DECODE(c,f,a[,ERR=s][,IOSTAT=ios])[iolist] 10.12 READ (UNIT=un,FMT=* [,END=sj [,ERR=s][,IOSTAT=iosj)[iolistj READ( un,FMT=*[,END=s][,ERR=s][,IOSTAT=ios]) [iolist] READ ( un, *[,END=s][,ERR=s][,IOSTAT=ios])[iolistj READ *[,iolistj READ (UNIT=*,FMT=*[,END=s][,ERR=s][,IOSTAT=ios]) [iolistj 10.5.1.3 WRITE(UNIT=un,FMT=*[,ERR=s ][,IOSTAT=ios])[iolist] WRITE( un,FMT=*[,ERR=s][,IOSTAT=ios]) [iolist] WRITE ( un, *[,ERR=s][,IOSTAT=ios]) [iolistj WRITE *[,iolist] WRITE(UNIT=*,FMT=*[,ERR=s] [,IOSTAT=ios]) [iolistj 10.6.1.3 REREAD(FMT=*[,END=s][,ERR=s][,IOSTAT=ios]) [iolistj REREAD *[,iolist] 10.7.2 ACCEPT(FMT=*[,END=s][,ERR=s][,IOSTAT=ios]) [iolist] ACCEPT *[,iolistj 10.8.2 TYPE(FMT=* [,ERR=sj [,IOSTAT=ios]) [iolist] TYPE *[,iolist] 10.9.2 PRINT(FMT=*[,ERR=s][,IOSTAT=ios]) [iolistj PRINT *[,iolist] PUNCH(FMT=*[,ERR=s][,IOSTAT=ios])[iolist] PUNCH *[,iolistj 10.10.2 10.11.2 READ (UNIT=un,FMT=name[,END=s][,ERR=s] [,IOSTAT=ios]) READ (UNIT=un,NML=name[,END=s ][,ERR=s j[,IOSTAT=ios]) READ( un,FMT=name[,END=s][,ERR=s] [,IOSTAT=ios]) READ ( un,NML=name[,END=s][,ERR=s][,IOSTAT=ios]) READ ( un, name[,END=s ][,ERR=s][,IOSTAT=ios]) 10.5.1.4 WRITE(UNIT=un,FMT=name[,ERR=s] [,IOSTAT=ios]) WRITE(UNIT=un,NML=name[,ERR=s ][,IOSTAT=ios]) WRITE( un,FMT=name[,ERR=s][,IOSTAT=ios]) WRITE( un,NML=name[,ERR=s ][,IOSTAT=ios]) WRITE( un, name[,ERR=s ][,IOSTAT=ios]) 10.6.1.4 10-3 February 1987 DATA TRANSFER STATEMENTS Table 10-2 (Cont.) Summary of Data Transfer Statement Forms Data Access Statement Construct Section Sequential Unformatted READ(UNIT=un[,END=s][,ERR=sj[,IOSTAT=iosj)[iolist] READ ( un[,END=s][ ,ERR=s][,I OST AT=ios]) [iolist] 10.5.2.1 WRITE(UNIT=un[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un[,ERR=s][,IOSTAT=ios])[iolist] 10.6.2.1 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][,IOSTAT=ios])[iolist] READ( un'm,FMT=f, [,ERR=sjf,lOSTAT=iosl)[iolist] READ( un'rn, f, r,ERR=s][JOSTAT=ios]) [iolistj 10.5.1.2 WRITE(UNIT=un,FMT=f,REC=rn[,ERR=s] [,IOST AT=ios ])[iolist] WRITE( un,FMT=f,REC=rn[,ERR=s][,IOSTAT=ios])[iolist] WRITE( un, f,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un'rn,FMT=f, [,ERR=s][ ,lOSTAT=ios])[ iolistl WRITE( un'rn. f. [.ERR=s][,10STAT=ios])[iolistl 10.6.1.2 READ (UNIT=un ,REC=rn[,ERR=s][,I OST AT=ios])[ iolist] READ( un,REC=rn[,ERR=s][,IOST AT=ios])[ iolist] HEAD( un'm [,ERR=s][JOSTAT=ios])[iolistj 10.5.2.2 WRITE(UNIT=un,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un,rn r,ERR=s][JOSTAT=ioslHiolistj 10.6.2.2 Indexed Formatted READ(UNIT=un,FMT=f,key=val[ ,KEYID=kn j[ ,ERR=s ][,IOST AT=ios]) [iolist] READ(un, FMT=f,key=val[ ,KEYID=kn j[,ERR=s][ ,lOST AT=ios])[ iolist] HEAD(un, f,key=val[,KEYID=knj[,ERR=s][,IOSTAT=ios]) [iolist] 10.5.3.2 Indexed Unformatted READ (UNIT=un,key=val[ ,KEYID=kn] [,ERR=s] [,I OST AT=ios]) [iolist] READ( un,key=val[,KEYID=knj[,ERR=s][,10STAT=ios]) [iolist] 10.5.3.3 Currentrecord DELETE DELETE(UNIT=un[,ERR=s][,IOST AT=ios j) DELETE( un[,ERR=s][,IOSTAT=iosj) 10.13.1 Direct DELETE DELETE (UNIT=un,REC=rn[,ERR=s I[,IOSTAT=iosj) DELETE( un,REC=rn[,ERR=s][,IOSTAT=iosl) DELETE( un'rn [,ERR=s][,IOSTAT=ios]) 10.13.2 Formatted REWRITE REWRITE(UNIT=un,FMT=f[ ,ERR=s j[,IOSTAT=ios]) [iolist] REWRITE( un, f[,ERR=s][,10STAT=iosj)[iolist] 10.14.1 Unformatted REWRITE REWRITE(UNIT=un[,ERR=s][,IOSTAT=ios])[iolistj REWRITE( un[,ERR=sH,IOSTAT=iosl)[iolistj 10.14.2 UNLOCK UNLOCK(UNIT=un[,ERR=sj[,IOSTAT=ios)) UNLOCK( un[,ERR=s][,IOSTAT=iosj) UNLOCK un 10.15 Direct Formatted Direct Unformatted Key: UNIT=un is a FORTRAN logical unit number or internal file specifier (Section 10.4.3). is a default unit specification with the READ Statement to read from CDR:, and with the WRITE Statement to write to LPT: (Section 1004.3). REC=rn is a direct-access record number (Section 10.4.4). un'rn is an alternate way of specifying Logical Unit Number and record number of a direct-access transfer (Section 10.4.4). FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FORTRAN-10/20 VII 10-4 February 1987 DATA TRANSFER STATEMENTS FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). FMT=name is NAMELIST-statement formatting; iolist is prohibited (Section 10.4.5.3). NML= is the alternative form of the NAMELIST-statement format specifier (Section 10.4.5.3). 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.7). 10STAT=ios is an optional I/O status specifier (Section 10.4.8). key=val is an optional key-field-value specifier (Section 10.4.9). KEYID=kn is an optional key-of-reference specifier (Section 10.4.10). iolist is a data transfer I/O list (Section 10.4.11). 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 NAMELIST statement 3. FORMAT specifications 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 (list-directed I/O) 3. An I/O list defined 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 three forms of access available sequential, direct, and keyed. These forms are described in the following sections. FORTRAN-10/20 Vll 10-5 February 1987 DATA TRANSFER STATEMENTS 10.2.1 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.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.2.3 Keyed Access (TOPS-20 RMS) If the data access is keyed, the data records are transferred to or from an indexed file as specified by character values or integer values called keys. The keys are defined as permanent attributes of the file when the file is created. Each READ statement contains the key that locates the record. The key value in the I/O statement is compared with index entries until the record is located. When you insert a new record, the values contained in the key fields of the record determine the record's placement in the file; you do not have to indicate a key. You can use organization. keyed access only for RMS files with an indexed Your program can mix keyed access and sequential access I/O statements on the same file. You can use keyed I/O statements to position the file to a particular record and then use sequential I/O statements to access records with increasing key values in the current key-of-reference. 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.) FORTRAN-10/20 VII 10-6 February 1987 DATA TRANSFER STATEMENTS 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: 101 WRITE (22,101)X,J,Z FORMAT (lX,F10.5,I5,F6.4) See Section 10.4.5.1 for more information on FORMAT-statement formatting. 2. List-Directed Formatting 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: by WRITE (22,*)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 appear in type, the transferred values of X and Z floating-point form, and the transferred value of J appears in integer 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 the formatting of the data during the data transfer. In the following example, the data transfer is controlled the NAMELIST. by PROGRAM NAMLST NAMELIST/VAR/X,y,Z READ(22,VAR) WRITE(5,VAR) END See Section 10.4.5.3 for more information formattjng. 10-7 on NAMELIST-statement February 1987 DATA TRANSFER STATEMENTS 1m.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. Their use with formatted sequential READ and WRITE statements reduces the need to use the ENCODE and DECODE statements for internal I/O (see 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. 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. 1m.3.2 Unformatted Data Transfers Unformatted data is transferred in two forms on TOPS-20 (BINARY or IMAGE), and three forms on TOPS-1m (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.24 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 transferred as 7-bit bytes. Numeric and character items can be interpersed in the same I/O list. Numeric 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.37). 1m.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, 1eft-justifited, five characters per word. For the terminal, the data is treated as if it were right-justified, one character per word. 1m-8 February 1987 DATA TRANSFER STATEMENTS 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) "----v-----'\ (See Section 10.4.1) . 1 I flO List I\ I (See Section 10.4.11 ) (See Section 10.4.2 - 10.4.10) MR-S-4649-87 Figure 10-1: 10.4.1 Components of Data Transfer Statements 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 (see Section 10.8) 5. TYPE (see Section 10.9) 6. PRINT (see Section 10.10) 7. PUNCH (see Section 10.11) 8. ENCODE (see Section 10.12) 9. DECODE (see Section 10.12) 10. Internal READ (see Section 10.12) 11. Internal WRITE (see Section 10.12) 12. DELETE (see Section 10.13) 13. REWRITE (see Section 10.14) 14. UNLOCK (see Section 10.15) 10.4.2 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 format specifier (see Section 10.4.5) 3. One record specifier (see Section 10.4.4) FORTRAN-10/20 VII 10-9 February 1987 DATA TRANSFER STATEMENTS 4. One I/O status specifier (see Section 10.4.8) 5. One error specifier (see Section 10.4.7) 6. One end-of-file specifier (see Section 10.4.6) 7. One key-field-value specifier (see Section 10.4.9) 8. One key-of-reference specifier (see Section 10.4.10) The following rules govern the placement and inclusion of items control-information list: in a 1. If the keyword UNIT= is omitted from the unit specifier, unit specifier must be the first item in control-information list. the the 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 (I), 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 be included in the control-information list. 6. A control-information list in an internal file or ENCODE or DECODE statement must contain a format specifier other than an asterisk or NAMELIST name, and must not contain a record specifier. 7. If the control-infQrmation list contains a key-of-reference specifier (KEYID=), the statement must also contain a key-field-value specifier. If a key-field-value specifier is present, KEYID= may be omitted; the current key-of-reference as specified by a previous KEYID= specifier is used (or the primary index, if never set). FORTRAN-10/20 VII 10-10 both a record February 1987 DATA TRANSFER STATEMENTS 10.4.3 Unit References in Data Transfer Statements The unit specifier is used to refer to a file or device. a unit specifier is: The form of UNIT = 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. item 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) Table 10-3 lists the default logical unit number assignments. Note that logical unit number 22 identifies the file as DSK:FOR22.DAT. Thus, the sample WRITE statement references a disk. The unit identifier asterisk corresponds to the card reader for the READ statement, and to the line printer for the WRITE 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: 1. OPEN(UNIT=n) or READ/WRITE (UNIT=n) integer is illegal. where 2. Assigning a negative decimal number to a level is illegal. n is a negative device at command assign a You can, however, from monitor command level, default device to another device. For example, us ing the you can TOPS-20 DEFINE command (or TOPS-10 ASSIGN command) , 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 February 1987 DATA TRANSFER STATEMENTS Table 10-3 FORTRAN Logical Device Assignments Device Default Filename PLT FORPLT.DAT -7 For use by FORPLT Device last read File last read -6 REREAD statement CDR FORCDR.DAT -5 READ statement TTY FORTTY.DAT -4 ,ACCEPT statement LPT FORLPT.DAT -3 PRINT statement PTP FORPTP.DAT -2 PUNCH statement TTY FORTTY.DAT -1 TYPE statement Device Default Filename DSK FOROO.DAT 00 Disk DSK FOROl.DAT 01 Disk CDR 02 Card Reader LPT 03 Line Printer CTY 04 Console Teletype TTY 05 User's Teletype PTR 06 Paper Tape Reader PTP 07 Paper Tape Punch DIS 08 Display DTA1 09 DECtape DTA2 10 DTA3 11 DTA4 12 DTA5 13 DTA6 14 DTA7 15 MTAO 16 MTA1 17 MTA2 18 FORTR 19 Default Devices (inaccessible to the user) Logical Unit Number Use Standard Devicest Logical Unit Number Use Magnetic Tape Assignable Device tThe device table can be altered when FOROTS is installed or by the system administrator. The supplied options are either values in the default table pictured above. or all positive logical unit numbers default to disk. Check to see which device table is being used at your installation. 10-12 Februa ry 1987 DATA TRANSFER STATEMENTS Table 10-3 (Cont.) FORTRAN Logical Device Assignments Default Filename Device Standard Devicest Logical Unit Number Use DSK 20 DSK 21 DSK 22 DSK 23 DSK 24 DEVI FOR25.DAT 25 DEV2 26 DEV3 27 DEV4 28 DEV5 29 DSK 30 DSK 31 DSK FOR99.DAT 99 Disk Assignable Devices Disk Disk tThe device table can be altered when FOROTS is installed or by the system administrator. The supplied options are either values in the default table pictured above, or all positive logical unit numbers default to disk. Check to see which device table is being used at your installation. 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=' (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: rn is a positive integer record number. 10-13 expression that indicates the February 1987 DATA TRANSFER STATEMENTS 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 element that represents the logical unit number of the device to or from which the data transfer is being made. When you use. this form for specifying the logical unit number, you cannot use the UNIT= keyword. un is an apostrophe delimiting from the record number. the unit is a positive integer constant, variable, element that represents the record number. rn 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 where: FMT= is the keyword used in the keyword form of the format 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 10-14 of February 1987 DATA TRANSFER STATEMENTS 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. 1~.4.5.1 FORMAT-Statement Formatting - The specifier has the following form: 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 of a FORMAT statement 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 more FORMAT-statement formatting.) bold) information on The following examples show all forms of the FORMAT-statement format specifier. In the first example, the format specifier (FMT=101) references the FORMAT statement 101 in the same program unit. 101 PROGRAM TEST I=67 P=90.8 WRITE (UNIT=22,FMT=101) I,P FORMAT (lX,'FIRST VALUE IS: ',I,' SECOND VALUE IS: END 10-15 ',F) February 1987 DATA TRANSFER STATEMENTS In the second example, the same format list used in the first example is stored in an 10-element array. Note that the word "FORMAT" is not included in the array. PROGRAM TESTB DIMENSION MYARAY(10) MYARAY (1) =' (IX, , , , MYARAY(2)='FIRST ' MYARAY(3)=' VALU' MYARAY(4)='E IS:' MYARAY (5) =' " , I, , MYARAY(6)='" SEC' MYARAY(7)='OND V' MYARAY(8)='ALUE ' MYARAY (9) = , IS: '" MY ARAY ( 10 ) =' , F) I 1==67 P=90.8 WRITE (UNIT=22,FMT=MYARAY)I,P END In the third example, the same format list used examples is stored in a character expression. in the first two PROGRAM TESTC INTEGER I REAL P CHARACTER WORDl*5,WORD2*6 1=67 P=90.8 WORDl=' FIRST' WORD2='SECOND' WRITE(UNIT=22,FMT=' (IX," '//WORDI//' VALUE IS: ",I," 1 WORD2//' VALUE IS: ",F) ') I,P END In the fourth example, the format specifier (FMT=IFORMT) variable that has been assigned a statement number. 101 '// references a PROGRAM TESTD ASSIGN 101 TO IFORMT 1=67 P=90.S" WRITE (UNIT=22,FMT=IFORMT) I,P FORMAT (lX,'FIRST VALUE IS: ',I, 'SECOND VALUE IS: ',F) END For more information on FORMAT-statement formatting, see Section 12.1. 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=* 10-16 February 1987 DATA TRANSFER STATEMENTS 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 be first). * is an asterisk that indicates that list-directed. In the following example, the variables list-directed formatting. PROGRAM TESTLD I=67 P=90.8 WRITE (UNIT=22,FMT=*) END I and P the formatting is are formatted by I,P List-directed formatting is further described in Section 12.5. 10.4.5.3 NAMELIST-Statement Formatting - If the formatting is NAMELIST, the format specifier in the control-information list contains a reference to a NAMELIST name defined in a NAMELIST 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 an I/O list. The form of the NAMELIST format specifier is: FMT=name or NML=name where: FMT= is the optional keyword part of the format specIfier. Including the keyword in the format specification makes it 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 second (after the logical unit number specifier) in the control-information list. NML= is an alternative keyword that can be used in place FMT. of name is the NAMELIST name. The NAMELIST name is defined a NAMELIST statement in the same program unit. in 10-17 February 1987 DATA TRANSFER 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 The execution of this sample program is as follows: ~~XECUTE TEST. FOR LINK: Loading [LNKXCT TESTNL execution] $MYIOLT I=675,P=34.71$ $MYIOLT 1= 675, P= 34.71000 $END CPU time 0.2 Elapsed time 32.0 For further information on the NAMELIST statement, see Section 12.7. 1~.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 1~.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 statement, 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: 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. The END= statement in In the following example, the end-of-file specifier causes a transfer of control to statement 5~ after the data transfer statement encounters an end-of-file on unit 22. 10-18 February 1987 DATA TRANSFER STATEMENTS PROGRAM TESTEN READ (UNIT=22,FMT=30,END=50) A,B,C FORMAT (F/F/F) GO TO 100 WRITE (UNIT=5,FMT=75) FORMAT (lX,'END-OF-FILE HAS BEEN ENCOUNTERED') WRITE (UNIT=5,FMT=105) FORMAT (lX,'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 I I I· When sequentially reading records from an RMS indexed file, the end-of-file branch, if specified, will be taken if the statement attempts to read past the last data record of the current index. 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. FORTRAN-10/20 VII 10-19 statement in February 1987 DATA TRANSFER STATEMENTS The following example shows the error specifier being used to pass control to the statement at line 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=75) FORMAT (lX,'END-OF-FILE HAS BEEN ENCOUNTERED') GO TO 100 WRITE (UNIT=5,FMT=86) FORMAT (lX,'THE TRANSFER ENCOUNTERED AN ERROR') WRITE (~,105) FORMAT (' EXECUTION HAS ENDED') END TYPE FOR22.DAT 100. 200. AAAA BBBB CCCC DDDD EXECUTE TESTEN.FOR FORTRAN: TESTEN TESTEN LINK: Loading [LNKXCT TESTEN execution] THE TRANSFER ENCOUNTERED AN ERROR EXECUTION HAS ENDED CPU time 0.2 Elapsed time 2.8 In this example, the error branch is taken when the input routine detects a nonnumeric data item while attempting to read a floating-point number into variable 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 value of zero. 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 variable specifier is: IOSTAT=ios where: ios is an integer specifier. variable 10-20 that is the I/O status February 1987 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.0) GO TO 10 WRITE (5,105) FORMAT (' EXECUTION HAS ENDED') END ',I5) TYPE FOR22.DAT 100. 200. AAAA BBBB CCCC DDDD 80. 90. 95. EXECUTE TESTEN.FOR FORTRAN: TESTEN TESTEN Loading LINK: [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 IOSTAT represents the processor specific error number (the second value listed in the FOROTS error messages in Section D.l), 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 Key-Field-Value Specifier (TOPS-20 RMS) The key-field-value specifier is used to specify the key field value of a record to be accessed in an indexed file. Indexed files are composed of records that have one or more fields in common; that is, the byte offset, type and length of the field(s) are the same in each record in any given indexed file. A key-field-value specifier has two components: • An expression, which specifies the key field value to be used in locating the record to be transferred • A match criterion, which specifies the selection conditions FORTRAN-10/20 VII 10-21 February 1987 DATA TRANSFER STATEMENTS A key-field-value specifier has one of the following forms: KEY=val KEYEQ=val KEYGE=val KEYGT=val where: is a character expression or an integer expression. Character expressions must be used with character key fields, and integer expressions must be used with integer key fields. val An integer expression in a key-field-value real or complex values. specifier cannot contain The match criterion specifies which key values in the record can match the expression. There are three possible criteria: • Equal - the key field value must be equal to specified. • Greater - the key field expression specified. • Greater than or equal - the key field value must than or equal to the expression specified. The following parameters are criterion: KEY=val KEYEQ=val KEYGT=val KEYGE=val specifies specifies specifies specifies used value to must be establish the expression greater the than the be greater desired match an equal match an equal match a greater than match a greater than or equal match For character expressions, the comparison is made according to the ASCII collating sequence. For integer expressions, the comparison is made according to the signed integer value. For character keys, either generic match or exact match can be used. A generic match compares only a specified number of leading characters in the key. The length of the search key determines how many characters are compared. For example, if the expression is 'ABCD' and the key field is 10 characters long, then an equal match is obtained for the first record containing 'ABCD' as the first 4 bytes of the key field. The remaining six characters are arbitrary. An approximate-generic match occurs when approximate match (KEYGT or KEYGE) is selected in addition to generic match. In that case, only the leftmost characters are used for comparison. For example, if the expression is 'ABCD', the key field is five characters long, and a greater-than match is selected, then the value 'ABCDA' does not match; 'ABCEx' does match. FORTRAN-10/20 VII 10-22 February 1987 DATA TRANSFER STATEMENTS 10.4.9.1 Key Attributes - By default, FOROTS creates new indexed files with the "No duplicate" and "No change" attributes set for the primary index. Secondary indexes default to the duplicates and allowed changes. Thus, new records containing a primary key that, when written, produces a duplicate primary key in the index, cause an error message or the ERR= branch to be taken. Records updated with a REWRITE statement that results in a revised primary key, also produce an error. The default "No duplicate" attribute for primary key can be changed only in a USEROPEN routine (see Section 11.3.39). RMS requires that primary keys cannot be changed. 10.4.10 Key-of-Reference Specifier The key-of-reference specifier may optionally be included with a key-field-value specifier; it is used to specify the key field index that is to be searched for the specified key field value. The form of the key-of-reference specifier is: KEYI·D=kn where: kn is an integer expression, called the key-of-reference number, which designates the key field index to be searched. The key-of-reference number is an integer value in the range zero to the maximum key number defined for the file. A value of zero specifies the primary key, a value of one specifies the first alternate key, and so forth. If no key-of-reference number is given, it defaults to the last specification given in a keyed I/O statement for that logical unit, or the primary key-of-reference, if never set. 10.4.11 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] ••• where: e is a simple input or output item (see Section 10.4.11.1) an implied DO list (see Section 10.4.11.2). 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). FORTRAN-10/20 VII 10-23 February 1987 DATA TRANSFER STATEMENTS 10.4.11.1 Simple List Elements - A simple input list item can be of the following: 1. A variable name 2. An array element name 3. A character substring name 4. An array name one For example: READ (5,10) J, K (3) , CH (1 : 3) A simple output list item can be one of the above, or it can be one of the following: 1. A constant 2. A function reference 3. An expression For example: WRITE (5,10) J,K(3) ,(L+4)/2,CH(1:3) input list item cannot be an expression. However, it expressions as subscripts or substring bounds. An can contain I/O list items can be of the following types: 1. Integer 2. Real 3. Double-precision 4. Complex 5. Log ical 6. Character 7. Octal 8. Double Octal 9. Hollerith 10-24 February 1987 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(l,l), ARRAY(2,1), ARRAY(3,1), ARRAY(1,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,lX,Il,lX,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(1,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.11.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 Sect jon 9.3). (see An implied DO list has the form: (dlist,i=el,e2[,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-25 can also contain other February 1987 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 the same: (X ( I) , I =1, 3 } WR I T E (3, 2 00 ) WR I T E ( 3 , 20 0 ) X ( 1) , X ( 2) , X ( 3 ) Another example is: WR I T E ( 6 ) ( I , (J , P ( I) , Q ( I , J) , J = I , L) , I = I , 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 (1+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) «FORM(K,L), L=1,10}, K=1,10,2} FORMAT (F10.2) Because the inner DO loop is executed 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 incremented, for example: READ (5 , 9 99 ) ( P ( I), before the (Q ( I , J), J = 1 , 10), I = 1 , 5 } In this example, P(l), Q(1,1}, Q(1,2} , ••• ,Q(1,10) are read before I is incremented to 2. When processing multidimensional arrays, you can use a combination of fixed subscripts and subscripts that vary according to an implied DO list, for example: READ (3,5555) (BOX(1,J), J=1,10) This statement assigns input values to BOX(l,l) through BOX(1,10) 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 ) output directly. ( I, 1=1, 20 ) This statement simply outputs the integers 1 through 20. 10-26 February 1987 DATA TRANSFER STATEMENTS READ Statement 1~.5 READ STATEMENT The READ statement transfers data from a file into memory. There are two categories of READ statements: formatted (see Section 1~.5.l) and unformatted (see Section 1~.5.2). An indexed READ statement (see Section 1~.5.3) applies only to RMS indexed files, and can be either formatted or unformatted. For RMS relative files that are accessed sequentially, RMS reads the next existing record, skipping any deleted or empty record cells. Relative files accessed randomly return a "?Record not found" error (or take the ERR= branch) for deleted or non-existent records. Table 1~-4 summarizes the various forms of the READ statement. FORTRAN-10/20 VII 10-27 February 1987 DATA TRANSFER STATEMENTS Table 10-4 Summary of READ Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) 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] Sequential Formatted (List Directed) READ(UNIT=un,FMT=*[,END=s][,ERR=s][,IOSTAT=ios]) [iolist] READ( un,FMT=*[,END=s ][,ERR=s )[,IOST AT=ios])[ iolist] READ( un, *[,END=s][,ERR=s][,IOSTAT=ios]) [iolist] Sequential Formatted (NAMELIST Statement) READ(UNIT=un,FMT=name[,END=s][,ERR=s][,IOSTAT=ios]) READ(UNIT=un,NML=name[,END=s][,ERR=s][,IOSTAT=ios]) READ( un,FMT=name[,END=s][,ERR=s][,IOSTAT=ios)) READ( un,NML=name[,END=s][,ERR=s][,IOSTAT=ios]) READ( un, namef,END=s][,ERR=s][,IOSTAT=ios]) Sequential Formatted (Default Unit) READ f[,iolist] READ *[,iolist] READ (UNIT=*,FMT=f[,END=s][,ERR=s][,IOSTAT=ios]) [iolist] READ (UNIT=*,FMT=*[,END=s][,ERR=s][,IOSTAT=ios])[iolist] Sequential Unformatted READ (UNIT=un[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ ( un[,END=s)[,ERR=s){,IOSTAT=ios ])[iolist] Direct Formatted READ(UNIT=un,FMT=f,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] READ ( un,FMT=f,REC=rn[,ERR=s )[,IOST AT=ios]) [iolist] READ ( un, f,REC=rn[,ERR=s )[,IOST AT=ios]) [iolist] READ( un'rn,FMT=f [,ERR=s][,IOSTAT=ios])[iolist] READ( un'rn, f [,ERR=sH,IOSTAT=ios])[iolist] Direct Unformatted READ(UNIT=un,REC=rn[,ERR=s] [,IOSTAT=ios]) [iolist] READ ( un,REC=rn[,ERR=s][,IOSTAT=ios])[iolist] READ( un'rn [,ERR=s][,IOSTAT=ios])[iolist] Indexed Formatted READ(UNIT=un,FMT=f,key=val[,KEYID=kn ][,ERR=s)[,IOSTAT=ios])[ iolist] READ (un, FMT=f,key=val[,KEYID=kn ][,ERR=s H,IOST AT=ios]) [iolist] READ(un, f,key=val[,KEYID=kn][,ERR=s] [,IOSTAT=ios]) [iolist] Indexed Unformatted READ (UNIT=un,key=val[,KEYID=kn H,ERR=s ][,IOST AT=ios]) [iolist] READ( un,key=val[,KEYID=kn][,ERR=s ][,IOSTAT=ios ])[iolist] Key: UNIT=un is a FORTRAN logical unit number (Section 10.4.3). UNIT=* is a default 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 specifying Logical Unit Number and record number for a direct-access transfer (Section 10.4.4). FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). FMT=name is NAME LIST -statement formatting; iolist is prohibited (Section 10.4.5.3). NML=name is the alternative form of the NAMELIST-statement format specifier (Section 10.4.5.3). 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.7). 10STAT=ios is an optional I/O status specifier (Section 10.4.8). key=val is an optional key-field-value specifier (Section 10.4.9). KEYID=kn is an optional key-of-reference specifier (Section 10.4.10). iolist is a data transfer I/O list (Section 10.4.11). FORTRAN-10/20 VII 10-28 February 1987 DATA TRANSFER STATEMENTS l~.S.l 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. l~.S.l.l Sequential FORMAT-Statement READ - This section describes 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 to the transferred from logical unit un, formatted according 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 FORMAT (2Fl~.2,I5) 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] 1~-29 February 1987 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] [ , IOSTAT= ios] ) [ iol i st] 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 ion 11. 3 • 1) • If the record specified by rn has not been written, an (~xcept 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 statement reads record 10 from logical unit 22, formats the data according to the FORMAT statement, and assigns the values to variables A, Z, and J. The alternative forms of this READ 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 specifications 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] [,IOSTAT=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 quote C I ) 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=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,FMT=*[ ,END=S] [,ERR=s] [,IOSTAT=ios]) [iolist] READ (un,* [,END=s] [,ERR=s] [,IOSTAT=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-30 February 1987 DATA TRANSFER STATEMENTS The default unit forms of this statement are: READ * [ , iol ist] 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 (1,*) I,R,D,E,L,M,J,R,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' 'JR'/ Upon execution of the program unit, the following values are to the I/O list elements: I 4 R D E L M 6.3 (3.4,4.2) (3.0,2.0) .TRUE. .FALSE. 14 14.6 14.600 ABC,DEF/GHI'JR R S T C assigned A, B, and J are unchanged. 10.5.1.4 Sequential NAMELIST-Statement READ - This section describes the sequential-access (NAMELIST-statement) formatted READ statement. This statement has the following forms: READ (UNIT=un,FMT=name[ ,END=s] [,ERR=s] [,IOSTAT=ios]) READ (UNIT=un,NML=name[,END=s] [,ERR=s] [,IOSTAT=ios]) READ (un, FMT=name [ , END=s] [ , ERR=s] [ , IOSTAT= ios] ) READ (un,NML=name[,END=s] [,ERR=S] [,IOSTAT=ios]) READ (un,name[ ,END=s] [,ERR=s] [,IOSTAT=ios]) With these forms, the data is transferred from the specified unit into the locations specified by the NAMELIST list. The formatting is controlled by the implicit data types of the NAMELIST list items. We suggest that you use the NAMELIST form of the READ statement to transfer data from files created by the NAMELIST form of the WRITE statement (Section 10.6.1.4). 10-31 February 1987 DATA TRANSFER STATEMENTS The following example shows this form of the READ statement: NAMELIST /DATA/A,Z,J READ (22, DATA) END In this example, the NAMELIST statement associates the NAMELIST name DATA with a list of three items. The corresponding READ statement reads input data and assigns values. 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 transf~rs 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 MODE specifier enables you to specify in which form the unformatted data file exists (see Section 11.3.24). 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 additional information on unformatted data file forms, see Section 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] ) [ io list] 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-32 February 1987 DATA TRANSFER STATEMENTS le.S.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]) [io1ist] READ (un,REC=rn[ ,ERR=s] [,IOSTAT=ios]) [io1ist] 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' , ACCESS='RANDOM', or ACCESS='RANDIN' (see Section 11.3.1). The 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]) [io1ist] 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 (') is specified next; then the record number is specified last. The following example demonstrates the use statement: of the unformatted READ OPEN (22,ACCESS='DIRECT' ,RECORDSIZE=3) READ (22,REC=le)A,Z,J READ {22'12)B,X,K END In this example, the first READ statement reads record 1e 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. 1e.S.3 Indexed READ Transfers (TOPS-2g) RMS indexed files can be read either sequentially or randomly by key-of-reference and key-fie1d-va1ue. The access mode is determined by the READ statement, and can be switched from one mode to the other in successive read statements. Keyed or random READ statements from an indexed file require specification of a key relational value (match criterion), optionally, a key-of-reference. Keyed or random READ statements be formatted or unformatted. FORTRAN-1e/2e V11 1e-33 the and can February 1987 DATA TRANSFER STATEMENTS le.S.3.l Sequential Indexed READ - Indexed files can be read sequentially on any index defined when the file i s c rea ted • A sequential indexed read does not require any new syntax in the READ statement. Sequential reads retrieve successive records in an indexed file by ascending key value for a specific key of reference. The key of reference can be established by a prior keyed read (the key of reference remains unchanged until the next keyed read changes it), or defaults to the primary key of reference. A sequential read on a key of reference returns end-of-file records with a higher key value exist in that index. le.S.3.2 Formatted Indexed READ - This formatted indexed READ statement. section when describes no the This statement has the following forms: READ (UNIT=un ,FMT=f, key=val [,KEYID=kn] [, ERR=S] [, IOSTAT=ios] ) [iol ist] READ (un, FMT=f, key=va 1 [ , KEYID=kn] [ , ERR=s] [ , IOSTAT= ios] ) [ iol i st] READ (un,f ,key=val [,KEYID=kn] [,ERR=s] [,IOSTAT=ios]) [iolist] where key= can be either KEY=, KEYEQ=, KEYGT=, or KEYGE=. The formatted indexed READ statement can be used only on indexed files. If the I/O list and format specifications specify that additional records are to be read, the statement reads those additional records sequentially using the current key-of-reference value. If the KEYID= keyword is omitted, the key-of-reference remains unchanged from the most recent specification. If the KEYID= keyword is omitted from the first keyed read, the key-of-reference is the primary key. If the specified key value is shorter than the key field referred to, the key value is matched against the leftmost characters of the appropriate key field until a match is found; the record supplying the match is then read. An example of the use of the formatted indexed READ statement is: READ (1 ,KAT(2S) ,KEY=' ABCD') A,B,C,D In this example, the READ statement retrieves a record with a key value of "ABCD' in the primary key, and then uses the format contained in the array item KAT(2S) to read the first four fields from the record into variables A,B,C, and D. FORTRAN-10/20 VII 10-34 February 1987 DATA TRANSFER STATEMENTS 10.5.3.3 Unformatted Indexed READ - This unformatted indexed READ statement. section describes the This statement has the following forms: READ (UNIT=un ,key=val [ ,KEYID=kn] [, ERR=s] [, IOSTAT=ios] ) [iol ist] READ (un,key=val[ ,KEYID=kn] [,ERR=s] [,IOSTAT=ios]) [iolist] where key= can be either KEY=, KEYEQ=, KEYGT=, or KEYGE=. The unformatted indexed READ statement can be used only on indexed files. If the number of the I/O list elements is less than the number of fields in the record being read, the unused fields in the record are discarded. If a specified key value is shorter than the key field referred to, the key value is matched against the leftmost characters of the appropriate key field until a match is found; the record supplying the match is then read. The following example demonstrates the use of the unformatted READ statement: OPEN 1 2 3 indexed (UNIT=l,STATUS='OLD', ACCESS=' KEYED' ,ORGANIZATION=' INDEXED' FORM='UNFORMATTED' , KEY=(1:5,30:37,18:23» READ (l,KEY='SMITH') ALPHA, BETA In this example, the READ statement reads from the indexed file connected to logical unit 1 and retrieves the record with the value 'SMITH' in the primary key field (bytes 1 to 5). The first two fields of the record retrieved are placed in variables ALPHA and BETA, respectively. READ (l,KEYGE='XYZDEF' ,KEYID=2,ERR=99) IKEY In this example, the READ statement retrieves the first record having a value equal to or greater than 'XYZDEF' in the second alternate key field (bytes 18 to 23). This first field of that record is placed in the variable IKEY. 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, and NAMELIST-controlled data transfers. WRITE statements cannot write to existing records in an indexed file. For statements that can perform this function in indexed files, see the REWRITE statement (Section 10.14). Table 10-5 summarizes all forms of the WRITE statement. FORTRAN-10/20 VII 10-35 February 1987 DATA TRANSFER STATEMENTS Table 10-5 Summary of WRITE Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) WRITE(UNIT=un,FMT=f[,ERR=s ][,IOSTAT=ios])[iolist] WRITE( un,FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un, f[,ERR=s][,IOSTAT=ios]) [iolist] Sequential Formatted (List Directed) WRITE(UNIT=un,FMT=* [,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un,FMT=* [,ERR=s )[,IOSTAT=ios])[ iolist] WRITE( un, *[,ERR=s][,IOSTAT=ios])[iolist] Sequential Formatted (NAMELIST Statement) WRITE(UNIT=un,FMT=name[,ERR=s ][,IOSTAT=ios]) WRITE(UNIT=un,NML=name[,ERR=s][,IOSTAT=ios]) WRITE( un,FMT=name[,ERR=s][,IOSTAT=ios]) WRITE( un,NML=name[,ERR=s][,IOSTAT=ios]) WRITE( un, name[,ERR=s][,IOSTAT=ios]) Sequential Formatted (Default Unit) WRITE f[,iolist] WRITE *[,iolist] WRITE(UNIT=*,FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE(UNIT=*,FMT=*[,ERR=s] [,IOSTAT=ios]) [iolist] Sequential Unformatted WRITE(UNIT=un[,ERR=s H,IOSTAT=ios])[ iolist] WRITE( un[,ERR=sH,IOSTAT=ios]) [iolist] Direct Formatted WRITE(UNIT=un,FMT=f,REC=rn[,ERR=s] [,IOSTAT=ios D[iolist] WRITE( un,FMT=f,REC=rn[,ERR=s ][,IOSTAT=ios])[ iolist] WRITE( un, f,REC=rn[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE( un'rn,FMT=f [,ERR=s][,IOSTAT=ios])[iolist] WRITE( un'rn, f [,ERR=s][,IOSTAT=ios])[iolist] Direct Unformatted WRITE(UNIT=un,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un,REC=rn[,ERR=s )[,IOSTAT=ios]) [iolist] [,ERR=s][,IOSTAT=ios])[iolist] WRITE( un'rn Key: UNIT=un is a FORTRAN logical unit number (Section 10.4.3). UNIT=* is a default 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 specifying Logical Unit Number and record number for a direct-access transfer (Section 10.4.4). FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). FMT=name is NAMELIST-statement formatting; iolist is prohibited (Section 10.4.5.3). NML=name . is the alternative form of the NAMELIST -statement format specifier (Section 10.4.5.3). ERR=s is an optional error transfer specifier (Section 10.4.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer I/O list (Section 10.4.11). 10-36 February 1987 DATA TRANSFER STATEMENTS 1~.6.l Formatted WRITE Transfers A formatted WRITE transfer uses 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 WRITE statements are: FORMAT-statement, list-directed, and NAMELIST-statement. 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 formatting. List-directed and NAMELIST-statement formatting can only be used for sequential-access formatted WRITE statements. 1~.6.1.l 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]) [io1ist] WRITE (un,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE (un, f [ , ERR=S] [ , IOSTAT= ios] ) [ iol i st] 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 (lX,2F10.2,I5) WRITE (22,15) FORMAT (' PAGE NO. I') END The following is written to logical unit 22: 11.40 PAGE NO. 1 13.90 5 10-37 February 1987 DATA TRANSFER STATEMENTS The default unit forms of this statement are: WRITE f( ,iolist] WRITE (UNIT=*,FMT=f[,ERR=s) [,IOSTAT=ios) [iolist] 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 transferred 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 S,A,Z,J FORMAT (lX,2F10.2,I5) WRITE 15 FORMAT (I PAGE NO. 11) 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 FORMAT-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=rn[,ERR=s) [,IOSTAT=ios]) [iolist) WRITE(un,FMT=f,REC=rn[,ERR=s) [,IOSTAT=ios) [iolist] WRITE(un,f,REC=rn[,ERR=s] [,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 FORMAT spe6ifications given at f. Only disk files that have been opened by an OPEN statement that specifies ACCESS=IDIRECT I or ACCESS=IRANDOM I (see Section 11.3.1) can be accessed by a WRITE statement of this form. This form is not permitted for RMS indexed files. 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 statement A=11.4 Z=13.9 J=5 OPEN(22,RECORDSIZE=25,ACCESS=IRANDOM I ) WRITE (22,5,REC=10)A,Z,J FORMAT (2F10.2,I5) WRITE (22,15,REC=11) FORMAT (I PAGE NO. 11) END FORTRAN-10/20 VII 10-38 February 1987 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 (') 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 (UN IT=un, FMT=* [ , ERR=s] [ , IOSTAT= ios] ) [ iol i st] WRITE (un, FMT=* [ , ERR=s] [ , IOSTAT= ios] ) [iol i st] WRITE (un, * [ , ERR=s] [ , IOSTAT= ios] ) [ io 1 i st] 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 * [ , iol i st] WRITE (UNIT=* ,FMT=* [,ERR=s] [, IOSTAT=ios] ) [iolist] forms, The default unit forms function in the same way as the first 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' WR I TE ( 1 , * ) A, 4 END The following is written to logical unit 1: ARRAY VALUES FOLLOW 4*3,400000, 4 10-39 February 1987 DATA TRANSFER STATEMENTS 10.6.1.4 Sequential NAMELIST-Statement WRITE - This section describes the sequential-access (NAMELIST-statement) formatted WRITE statement. This statement has the following forms: WRITE (UNIT=un,FMT=name[,ERR=s] [,IOSTAT=ios]) WRITE (UNIT=un,NML=name[,ERR=s] [,IOSTAT=ios]) WRITE (un,FMT=name[,ERR=s] [,IOSTAT=ios]) WRITE (un, NML=name [ , ERR=S] [ , IOSTAT= ios] ) WRITE (un,name[,ERR=s] [,IOSTAT=ios]) These forms of the WRITE statement transfer data defined in the referenced NAMELIST statement (FMT=name or NML=name) to the file on the logical unit specified by un. The following example demonstrates the statement: NAMELIST form of the WRITE CHARACTER*19 NAME(2) DATA NAME/2*' 1/ REAL PITCH, ROLL, YAW, POSIT(3) LOGICAL DIAGNO INTEGER ITERAT NAMELIST /PARAM/ NAME, PITCH, ROLL, YAW, POSIT, DIAGNO, ITERAT ACCEPT (FMT=PARAM) WRITE (UNIT=l,FMT=PARAM) END The input contains the following: b$PARAM NAME(2) (10:)='HEISENBERG ' , bPITCH=5.0, YAW=0.0, ROLL=5.0, bDIAGNO=.TRUE. bITERAT=10$END The WRITE statement writes the following: $PARAM NAME= I , HEISENBERG ' , PITCH= 5.000000, ROLL= 5.000000, YAW= 0.0000000E+00, POSIT= 3*0.0000000E+00, DIAGNO= T, ITERAT= 10 $END 10.6.2 Unformatted WRITE Transfers Unformatted WRITE transfers move data from memory to a file. Unlike formatted WRITE transfers, unformatted WRITE transfers do not involve any editing of the data. The two types of unformatted data transfers enable you to write file either sequentially or directly. 10-40 to a February 1987 DATA TRANSFER STATEMENTS NOTE The MODE specifier of the OPEN statement enables you to specify the type of unformatted data file you want to create (see Section 11.3.24). If you execute an unformatted WRITE statement 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 logical unit un. The following example shows this form of the WRITE statement with I/O list and without the I/O list: the WRITE (22)A,Z,K WRITE (22) END 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 non-indexed 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 bl ank reco rd. FORTRAN-10/20 VII 10-41 outputs one logical February 1987 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' ,RECORDSIZE=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. The alternative form of this type 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 statement is: WRITE (un' rn[ ,ERR=S] [,IOSTAT=ios]) [iolist] In this f~rm, the unit and record references do not contain the keywords UNIT= and REC=. Instead the unit number is specified first; a single quote (') is specified next; then the record number is specified last. 10.6.3 Writing to RMS Files (TOPS-20) WRITE statements to RMS files can be either formatted or unformatted. Records written to RMS files that have a RECORDSIZE value (see Section 11.3.33), cannot be larger than the size specified at file creation time. Formatted records that are shorter are padded by FOROTS to RECORDSIZE with the character specified in PADCHAR before being written. Unformatted records are padded with nulls. Records that are larger than the size specified at file creation are truncated with a warning. WRITE statements to indexed files are indistinguishable from normal sequential WRITE statements. WRITE statements to indexed files must not contain key-relational or key-of-reference data. RMS examines the record being written and determines the position of the new record on the basis of the record's primary key. New records cannot be larger than the size specified at the file creation time; FOROTS pads shorter formatted records to RECORDSIZE with the character specified in PADCHAR (see Section 11.3.28). An indexed WRITE statement writes a new record; the REWRITE statement must be used to update an existing record. Each new record in an indexed file must contain a complete primary key. Alternate keys can be partially or completely absent. RMS does not make an entry for the new record in the associated alternate indexes. When performing a formatted WRITE to an indexed file that contains integer key data types, the key is translated from internal binary form to external character form. A subsequent attempt to read the record using an integer key produces unpredictable results. FORTRAN-10/20 VII 10-42 February 1987 DATA TRANSFER STATEMENTS REREAD Statement 10.7 REREAD STATEMENT The REREAD statement causes the last record read from the last sequential formatted READ or ACCEPT statement to again be accessed and processed. You cannot use the REREAD feature until an input (READ) transfer has been accomplished. You can use the REREAD statement only for sequential-access formatted data transfers. The REREAD statement can be used with both FORMAT-statement formatting and list-directed formatting. Once a record has been accessed 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 specification for each successive REREAD statement. Table 10-6 summarizes all the forms of the REREAD statement. Table 10-6 Summary of REREAD Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) REREAD (FMT=f[,END=s][,ERR=s ][,IOSTAT=ios])[iolist] REREAD f[,iolist] Sequential Formatted (List Directed) REREAD (FMT=*[,END=s][,ERR=s][,IOSTAT=ios])[iolist] REREAD *[,ioIist] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -------- Key: FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). 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.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer I/O list (Section 10.4.11). - - - - - - - - - - - - - - - - - - - - - - - --- 10.7.1 Sequential FORMAT-Statement REREAD This section describes the sequential-access (FORMAT-statement) REREAD statement. The first form of this statement is: REREAD (FMT= f [ , END=s] [ , ERR= s] [ , IOSTAT= ios] ) [ iol i st] 10-43 February 1987 DATA TRANSFER STATEMENTS If the I/O list is specified in this form, the previous record is transferred from the logical unit (specified in the previous formatted READ statement) to the memory locations specified by the elements in the I/O list. The transferred record is formatted according to the FORMAT specifications given in f. If you omit the I/O list from this statement, 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 second form of this REREAD statement operates in the same way as the first form. The difference between the two forms is in the way the FORMAT specifiers are expressed. The second form of this statement is: REREAD f[,iolist] In this form, the keyword form of the FORMAT specifier (FMT=) is not used in the FORMAT reference. Whenever you use the keyword form of this specifier, you must enclose the keyword list in parentheses. The following example shows the formatted REREAD being used: 1 5 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 X, a~ the integer I. Statement 10 rereads the last record input from unit 5 as a character string of 25 characters, five per word, and puts five characters per element into the array J. 10.7.2 Sequential List-Directed REREAD This section describes the statement. sequential-access (list-directed) REREAD The first form of this statement is: REREAD (FMT=*[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] In this form, the last record read by a formatted READ statement is transferred from the logical 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 data 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: REREAD *[,iolist] 10-44 February 1987 DATA TRANSFE'R STATEMENTS The following example shows statement: the list-directed form of the REREAD READ (20,*) A REREAD *,B END In this example, the READ statement reads data from logical unit 20 into variable A. The REREAD statement rereads the data from logical unit 20 into variable B. ACCEPT Statement 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 formatting. Table 10-7 summarizes all forms of the ACCEPT statement. Table 10-7 Summary of ACCEPT Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) ACCEPT(FMT=f[,END=s] [,ERR=s][,IOSTAT=ios]) [iolist] ACCEPT f[,iolist] Sequential Formatted (List Directed) ACCEPT(FMT=*[,END=s][,ERR=s][,IOSTAT=ios])[iolist] ACCEPT *[,iolist] Key: FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). END=s is an optional end-of-file transfer specifier (Section 10.4.6). ERR=s is an optional error transfer specifier (Section 1O.4.7). 10STAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer I/O list (Section 10.4.11). 18.8.1 Sequential FORMAT-Statement ACCEPT This section describes the sequential-access (FORMAT-statement) ACCEPT statement. The first form of this statement is: ACCEPT (FMT=f[,END=s] [,ERR=s] [,IOSTAT=ios])[iolist] 10-45 February 1987 DATA TRANSFER STATEMENTS If you include the I/O list in this form, the data is taken from the terminal and stored in the memory locations identified in the I/O list. The transferred data is formatted according to the FORMAT specifications given in f. If you omit the I/O list from this form, the input record is skipped. (If the FORMAT statement specifies slash editing, m~re 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 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 reference is expressed. The second form of this statement is: ACCEPT f[,iolist] In this form, the keyword portion of the FORMAT omitted. specifier (FMT=) is The following example shows both forms of the FORMAT-statement ACCEPT. 35 15 ACCEPT (FMT=35)A,Z,J FORMAT (2F10.2,I5) ACCEPT 15,B FORMAT (F10.2) END In this example, the first ACCEPT statement accepts the values of the variables A, Z, and J from the terminal in the form of FORMAT statement 35. The second ACCEPT statement accepts the value of variable B from the terminal in the form of FORMAT statement 15. 10.8.2 Sequential List-Directed ACCEPT The list-directed ACCEPT statement transfers data entered from the terminal into variables specified in the I/O list. The formatting of the transferred data is controlled by the data types of the items in the I/O list. The first form of this statement is: ACCEPT (FMT=*[,END=s] [,ERR=s] [,IOSTAT=ios])[iolist] In this form, the data is transferred from the terminal into the memory locations identified in the I/O list. 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 line is skipped. The second form of this statement operates in the same first form. The difference in the two forms is list-directed formatting reference is specified. way as in how the the The second form of this statement is: ACCEPT *[ ,iolist] 10-46 February 1987 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 TY PE *, H, F , G END EXECUTE ACCEPT. FOR FORTRAN: ACCEPT ACCTST Loading LINK: [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 TYPE Statement 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-47 February 1987 DATA TRANSFER STATEMENTS Table 10-8 Summary of TYPE Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) TYPE(FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] TYPE f[,iolistl Sequential Formatted (List Directed) TYPE(FMT=*[,ERR=s ][,IOSTAT=ios]) [iolist] TYPE *[,iolist] Key: FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). ERR=s is an optional error transfer specifier (Section 10.4.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer I/O list (Section 10.4.11). 10.9.1 Sequential FORMAT-Statement TYPE This section describes the sequential-access statement. (FORMAT-statement) TYPE The first form of this statement is: TYPE (FMT=f[ ,ERR=s] [, IOSTAT=ios]) [iolist] If you include the I/O list in this form, the data is transferred from the I/O list to your terminal. The transferred data is formatted 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 (See Section 12.4 for more information on format editing). 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 reference is expressed. The second form of this statement is: TY P E f [ , i 0 1 i s t] In this form, the keyword portion of the FORMAT omitted. 10-48 specifier ( FMT=) is February 1987 DATA TRANSFER STATEMENTS The following example shows both forms of the FORMAT-statement TYPE: 5 15 A=11.4 Z=13.9 J=5 K=10 TYPE (FMT=5)A,Z,J FORMAT (lX,2F10.2,I5) TYPE l5,K FORMAT (lX,I10) END The following is typed on your terminal upon execution: LINK: Loading [LNKXCT TEST40 execution] 11.40 13.90 5 10 CPU time 0.22 Elapsed time 2.00 10.9.2 Sequential List-Directed TYPE The list-directed TYPE statement transfers data from a program to the terminal. The formatting of the transferred data is controlled by the data types of the items in the I/O list. The first form of this statement is: TYPE(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. 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 list-directed formatting reference is specified. The second form of the statement is: TY P E * [ , i 0 1 i s t ] The following example shows statement: both forms of the list-directed TYPE A=11.4 Z=13.9 J=5 K=10 TYPE (FMT=*) ,A,Z,J TYPE *,K END The following is typed on the terminal upon execution: LINK: Loading [LNKXCT TEST4l execution] 11.40000, 13,90000, 5 10 CPU time 0.20 Elapsed time 0.87 10-49 February 1987 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) PRINT(FMT=f[,ERR=sj [,IOSTAT=ios]) [iolistj PRINT f[,iolistj Sequential Formatted (List Directed) PRINT(FMT=*[,ERR=s][,IOSTAT=iosj)[iolistj PRINT *[,iolistj Key: FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). ERR=s is an optional error transfer specifier (Section 10.4.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer I/O list (Section 10.4.11). 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=f[,ERR=S] [,IOSTAT=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-50 February 1987 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 [ , iol ist] The following example shows two PRINT statements; one with an I/O list and one wi tho ut: 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 l0.le.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-51 February 1987 DATA TRANSFER STATEMENTS The following statement: example shows the use of the list-directed PRINT D=l E=40 F=23.3 PRINT *,D,E,F END The following is printed to the line printer upon execution: 1.000000, 40.00000, 23.30000 PUNCH Statement 10.11 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 Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) PUNCH (FMT=f[,ERR=sj [.IOSTAT=ios]) [iolistj PUNCH f[,iolist) Sequential Formatted (List Directed) PUNCH(FMT=* [,ERR=s) [,IQSTAT=ios]) [iolistj PUNCH *[,iolist) Key: FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). FMT=* is list-directed formatting; iolist is optional (Section 10.4.5.2). ERR=s is an optional error transfer specifier (Section 10.4.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer 1/0 list (Section 10.4.11). 10-52 February 1987 DATA TRANSFER STATEMENTS 10.11.1 Sequential FORMAT-Statement PUNCH This section describes the sequential-access (FORMAT-statement) statement. PUNCH The first form of this statement is: PUNCH (FMT=f[,ERR=s] [,IOSTAT=ios])[iolist] If the I/O list is specified in this form, the data identified by the items in the I/O list are transferred to the paper tape punch. The formatting of the data is controlled by 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 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 the way that the format specification is referenced. The second form of this statement is: PUNCH f[,iolist] The following example shows the formatted PUNCH statement: 10 10.11.2 PUNCH l0,A,B,C FORMAT (3F) Sequential List-Directed PUNCH This section describes statement. the sequential-access (list-directed) PUNCH The first form of this statement is: PUNCH (FMT=*[,ERR=s] [,IOSTAT=ios]) [iolist] This form of the PUNCH statement transfers the data identified by the elements of the I/O list to the paper tape punch. Since the transfer is list-directed, the formatting of the data is controlled by the data types of the items within the I/O list. If no I/O list is included, a blank record is written. 10-53 February 1987 DATA TRANSFER STATEMENTS 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 list-directed format reference is written. The second form of this statement is: PUNCH * [ , iol i st] 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 and ENCODE/DECODE statements for internal I/O. Table 10-11 summarizes all the forms of the ENCODE/DECODE statements. internal are used READ/WRITE and Table 10-11 Summary of Internal READ/WRITE and ENCODE/DECODE Statement Forms Data Access Statement Construct Sequential Formatted (FORMAT Statement) ENCODE(c,f,a[,ERR=sj[,IOSTAT=iosj)[iolist] DECODE(c,f,a[,ERR=sj[,IOSTAT=ios])[iolistj 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=sH,ERR=s][,IOSTAT=ios]) [iolist] WRITE(UNIT=un,FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE(un,FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE(un,f[,ERR=s][,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 (Section 10.4.6). ERR=s is an optional error transfer specifier (Section 10.4.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer I/O list (Section 10.4.11). 10-54 February 1987 DATA TRANSFER STATEMENTS le.12.l 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 c~n be 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 le.4.3.2) • file identifier (see Section If an I/O list is included in these forms, it spe~ifies 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: Ie 2e demonstrates the use of the internal READ CHARACTER*9 STRING STRING = '3.14 6.e2' READ(STRING,le) PI, A FORMAT(F4.2, IX, F4.2) WRITE(5,2e) PI, A, PI+A FORMAT(' PI=', F6.3, 5X, 'A=', F6.3, 5X, 'PI+A=', F6.3) STOP END 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.14e A= 6.02e PI+A= 9.160 CPU time 0.19 Elapsed time 0.4e Ie-55 February 1987 DATA TRANSFER STATEMENTS The internal WRITE statement has the following forms: WRITE (UNIT=un,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] 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 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), I=1,3} FORMAT ( 'PHNE(', II, ')=', 14) WRITE(5,20} (I, CHARS{I), I=1,3) FORMAT{' Record " II, , of CHARS is"' STOP END the internal WRITE A20, "") The first WRITE statement in the above program is an internal file write. Since the character 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.FOR LINK: Loading [LNKXCT IW exedution] Record lof CHARS is "PHNE(l)= 617 Record 2 of CHARS is "PHNE(2}= 481 Record 3 of CHARS is "PHNE(3}=4054 CPU time 0.24 Elapsed time 0.82 10.12.2 " " " ENCODE and DECODE Statements The DECODE statement can be used as an alternative to an internal READ, and the ENCODE statement can be used as an alternative to the internal WRITE. 10-56 February 1987 DATA TRANSFER STATEMENTS The ENCODE statement transfers data from the variables of a specified I/O 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 I/O list. DECODE operations are similar to those performed by a READ statement. ENCODE and DECODE statements have the following forms: ENCODE (c, f , a [ , ERR=s] [ , IOSTAT= ios] ) [ iol i st] DECODE (c,f ,a[ ,ERR=s] [, IOSTAT=ios]) [iolist] where: c 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 statement. NOTE Five characters per word are stored in the array without regard to the type of the array. f specifies either a FORMAT-statement or a numeric array that contains format specifications. This must be the second specification. a specifies the array, array element, variable, or character substring 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 I/O list of the standard form. When multiple records are stored by ENCODE or read by DECODE, each new record starts c characters after the previous record; no CR/LF (carriage return/line feed) is inserted between records. NOTE If the array contains fewer characters than required by the format and the I/O list, the variables following the array in memory are used. If the processing of the I/O list requires more characters in a single record than are specified by the character count c, blanks are used. The following example shows how the ENCODE and DECODE used: statements are DIMENSION B(4) ,A(2) A(1)=300.45 A(2)=3.0 C='12345' DO 2 J=1,2 10 ENCODE(16,10,B)J,A(J) FORMAT (IX, , A (' , II, ') = " 10-57 F8. 2) February 1987 DATA TRANSFER STATEMENTS 5 11 TYPE 11,B FORMAT(4A5) 2 CONTINUE 12 DECODE(5,12,C)B FORMAT(3Fl.0,lX,Fl.0) 13 TYPE 13,B FORMAT(4F5.2) END During the first iteration of the DO loop, the ENCODE statement has transferred the contents of variable J and array element A(l) into array B. The formatting of the data being transferred is specified by the FORMAT statement at line 10. After the first iteration of the DO loop, the contents of array Bare: B(l) B(2) B(3) B(4) 'A(l)' '= '300.4' '5 The TYPE statement at line 5 types array B on the terminal during first iteration of the DO loop. the is transferred During the second iteration of the DO loop, the data from variable J and array element A(2) into array B. After the second iteration, the contents of array Bare: B(l) B(2) B(3) B(4) 'A(2)' '= 3.0' '0 The TYPE statement at line 5 types array B on the terminal during second iteration of the DO loop. the The DECODE statement: 1. Extracts the digits 1, 2, and 3 from C 2. Converts them to floating-point values 3. Stores them in B(l), B(2), and B(3) 4. Skips the next character (the digit 4) 5. Extracts the digit 5 from C 6. Converts it to a floating-point value 7. Stores the value in B(4) 10-58 February 1987 DATA TRANSFER STATEMENTS The following shows what is printed at the program is executed: terminal when the above EXECUTE T.FOR LINK: Load ing [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 DELETE (TOPS-20) Statement 10.13 DELETE STATEMENT (TOPS-20) The DELETE statement deletes records from RMS relative and indexed files. It logically removes the appropriate record from the specified file by locating the record and marking it as a deleted record. The position occupied by the deleted record becomes available so that a new record can be written into that position. The DELETE statement is illegal organization, and for non-RMS files. for RMS files with sequential Table 10-12 summarizes all forms of the DELETE statement. Table 10-12 Summary of DELETE Statement Forms Data Access Statement Construct Current-record DELETE DELETE(UNIT=un[,ERR=s ][,IOSTAT=ios)) DELETE( un[,ERR=s][,IOSTAT=ios)) Direct DELETE DELETE(UNIT=un,REC=rn[,ERR=s][,IOSTAT=ios)) DELETE( un,REC=rn[,ERR=s][,IOSTAT=ios)) DELETE( un'rn [,ERR=s][,IOSTAT=ios)) Key: UNIT=un is a FORTRAN logical unit number or internal file specifier (Section 10.4.3). REC=rn is a direct-access record number (Section 10.4.4). un'rn is an alternate way of specifying Logical Unit Number and record number of a direct-access transfer (Section 10.4.4). 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.7). IOSTAT=ios is an optional 1/0 status specifier (Section 10.4.8). iolist is a data transfer 1/0 list (Section 10.4.11). FORTRAN-10/20 V11 10-59 February 1987 DATA TRANSFER STATEMENTS 10.13.1 Current-Record DELETE The current-record DELETE statement has the following forms: DELETE (UNIT=un[,ERR=s] [,IOSTAT=ios]) DELETE (un[ ,ERR=S] [,IOSTAT=ios]) This form of the DELETE statement deletes the last record from an indexed or sequentially-accessed relative file that has been successfully accessed by a previous READ or FIND statement. The current-record DELETE is the only form of the DELETE statement that is permitted for indexed files. 10.13.2 Direct-Access DELETE The direct-access DELETE statement has the following forms: DELETE (UN~T=un,REC=rn[,ERR=s] [,IOSTAT=ios]) DELETE (un,REC=rn[ ,ERR=s] [,IOSTAT=ios]) DELETE (un' rn [ , ERR=s] [ , IOSTAT= ios] ) The direct-access DELETE is permitted only for direct-access RMS relative files. It deletes the record specified by rn. After a direct-access DELETE statement, any associate variable is set to the next record number. The alternative form of this type of DELETE statement (the last form shown) operates in the same way as the first two forms. The difference between the forms is in the way that the unit and the record are specified. 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 (') is specified next; then the record number is specified last. REWRITE (TOPS-20) Statement 10.14 REWRITE STATEMENT (TOPS-29) The REWRITE statement transfers data from internal storage to the current record (the record most recently accessed by a READ or FIND statement) of an RMS indexed or relative file. The REWRITE statement can be formatted or unformatted. Table 10-13 summarizes all forms of the REWRITE statement. FORTRAN-10/20 VII 10-60 February 1987 DATA TRANSFER STATEMENTS I Table 10-13 Summary of REWRITE Statement Forms Data Access Statement Construct Formatted REWRITE REWRITE(UNIT=un,FMT=f[,ERR=sjLIOSTAT=iosj)[iolistj REWRITE( un, f[,ERR=s][ ,lOSTAT=ios]) [iolist j Unformatted REWRITE REWRITE(UNIT=un[,ERR=s][,lOSTAT=ios]) [iolistJ REWRITE( un[,ERR=s ][,IOSTAT=ios]) [iolist] Key: UNIT=un is a FORTRAN logical unit number (Section 10.4.3). FMT=f is FORMAT-statement formatting; iolist is optional (Section 10.4.5.1). ERR=s is an optional error transfer specifier (Section 10.4.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). iolist is a data transfer I/O list (Section 10.4.11). 10.14.1 Formatted REWRITE The formatted REWRITE statement has the following forms: REWRITE (UNIT=un, FMT= f [ , ERR=s] [ , IOSTAT= ios]) REWRITE (un,f[,ERR=s] [,IOSTAT=ios]) [iol i st] [iolist] Note that a WRITE to an indexed file always writes a new record. If the primary key for the new record is changed, an error results. Records rewritten with the REWRITE statement cannot exceed the length of the record being updated, or an error results. An example of the use of a formatted REWRITE statement follows: 10 REWRITE (1,10,ERR=99) NAME, AGE, BIRTH FORMAT (A16,I2,A8) In this example, the REWRITE statement updates the current record contained in the indexed file connected to logical unit 1 with the values represented by NAME, AGE, and BIRTH. 10.14.2 Unformatted REWRITE Statement The unformatted REWRITE statement has the following forms: REWRITE (UNIT=un[ ,ERR=ios] [,IOSTAT=ios]) REWRITE (un[ ,ERR=ios] [,IOSTAT=ios]) [iolist] [iolist] The unformatted REWRITE statement retrieves binary values from internal storage and writes those values to an existing record in a RMS file with indexed or relative organization. The values are not translated. FORTRAN-10/20 VII 10-61 February 1987 DATA TRANSFER STATEMENTS UNLOCK (TOPS-20) Statement 19.1S UNLOCK STATEMENT (TOPS-2g) The UNLOCK statement unlocks a record in a RMS relative or indexed file locked by a previous READ or FIND statement, without performing any other I/O operations. If no record is locked, the operation has no effect. This statement is illegal for RMS sequential and non-RMS files. Table Ig-14 summarizes all forms of the UNLOCK statement. Table 10-14 Summary of UNLOCK Statement Forms Data Access Statement Construct UNLOCK UNLOCK(UNIT=un[,ERR=sj[,IOSTAT=iosj) UNLOCK( un[,ERR=s][,IOSTAT=iosj) UNLOCK un Key: UNIT=un is a FORTRAN logical unit number (Section 1004.3). ERR=s is an optional error transfer specifier (Section 1004.7). IOSTAT=ios is an optional I/O status specifier (Section 10.4.8). FORTRAN-10/20 VII 10-62 February 1987 CHAPTER 11 FILE-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 the performed by the implicit OPEN or CLOSE are satisfactory. 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: that OPEN {UNIT=20,FILE='MYDATA.DAT'} The specifiers inside the parentheses give information about the and determine how the file is opened. 11-1 file February 1987 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= or DEVICE-, 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: "defer red" OPEN statement • The OPEN statement specifies STATUS='UNKNOWN' specify a STATUS value). (or does • The OPEN statement specifies ACCESS='SEQINOUT' 'SEQUENTIAL' (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 or 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 February 1987 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: un is the unit statement. number specified in the data transfer fm is 'UNFORMATTED' if the data transfer statement is an unformatted READ 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 February 1987 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.36), 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 f1le 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 oD the unit number or the values of other specifiers. Table 11-1 summarizes the specifiers in the OPEN statement and the type of value required by each. A section number is provided to refer to detailed descriptions of each specifier. The CLOSE statement specifiers are summarized in Table 11-5. 11-4 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-1 Summary of OPEN Statement Specifiers and Arguments Argument Possible Value Section ACCESS= Character expression with one of the following values: 'SEQIN', 'SEQOUT', 'SEQINOUT', 'SEQUENTIAL', 'DIRECT', 'RANDOM', 'RANDIN' 'APPEND', 'KEYED' 11.3.1 ASSOCIA TEV ARIABLE= Integer variable or integer array element 11.3.2 BLANK= Character expression with one of the following values: 'NULL', 'ZERO' 11.3.3 BLOCKSIZE= Integer expression 11.3.4 BUFFERCOUNT= Integer expression 11.3.5 BYTESIZE= Integer expression 11.3.6 CARRIAGECONTROL= Character expression with one of the following values: 'FORTRAN', 'LIST', 'DEVICE', 'TRANSLATED', 'NONE' 11.3.7 DEFAULTFILE= (TOPS-20) Character expression 11.3.8 DENSITY= Character expression with one of the following values: '200', '556', '800', '1600', '6250', 'SYSTEM' 11.3.9 DEVICE= Character expression 11.3.10 11.3.11 DIALOG DIALOG= Character expression 11.3.12 DIRECTORY= (TOPS-lO) Character expression 11.3.13 DIRECTORY= (TOPS-20) Character expression 11.3.14 DISPOSE= Character expression with one of the following values: 'SAVE', 'DELETE', 'PRINT', 'KEEP', 'LIST', 'PUNCH', 'EXPUNGE' 11.3.15 ERR= Statement number 11.3.16 FILE= Character expression 11.3.17 FILESIZE= INITIALIZE= Integer expression 11.3.18 FORM= Character expression with one of the following values: 'FORMATTED', 'UNFORMATTED' 11.3.19 IOSTAT= Integer variable or integer array element 11.3.20 KEY= (TOPS-20) Keyspec 11.3.21 LIMIT= Integer expression 11.3.22 MAXREC= (TOPS-20) Integer expression 11.3.23 MODE= Character expression with one of the following values: 'ASCII', 'LINED', 'BINARY', 'IMAGE', 'DUMP' 11.3.24 NAME= Character expression 11.3.25 11.3.26 NOSPANBLOCKS= (TOPS-20) FORTRAN-10/20 VII 11-5 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-1 (Cont.) Summary of OPEN Statement Specifiers and Arguments Argument Possible Value Section ORGANIZATION= (TOPS-20) Character expression with one of the following values: 'SEQUENTIAL', 'RELATIVE', 'INDEXED', 'UNKNOWN' 11.3.27 PADCHAR= A character expression in which the first character is used 11.3.28 PARITY= Character expression with one of the following values: !ODD', 'EVEN' 11.3.29 PROTECTION= (TOPS-10) Integer expression 11.3.30 PROTECTION= (TOPS-20) Integer expression 311.3.31 READONLY 11.3.32 RECL= HECORDSIZE= Integer expression 11.3.33 HECORDTYPE= Character expression with one of the following values: 'FIXED', 'STREAM!, 'VARIABLE', 'UNKNOWN' 11.3.34 SHARED (TOPS-20) 11.3.35 STATUS= TYPE Character expression with one of the following values: 'OLD', 'NEW', 'SCRATCH', 'EXPUNGE', 'UNKNOWN', 'KEEP', 'DELETE! 11.3.36 TAPEFORMAT= Character expression with one of the following values: CORE-DUMP or INDUSTRY 11.3.37 UNIT= Integer expression 11.3.38 USEROPEN= (TOPS-20) Function name 11.3.39 VERSION= Octal constant, integer variable, or integer array element 11.3.40 NOTE For compatibility with previous versions of FORTRAN-10/20, you can specify a numeric array name as the value of each of the following 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. FORTRAN-10/20 VII 11-6 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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), sequentially, or by specified key (RMS). The form of the ACCESS specifier is: ACCESS = acc where: acc is a character expression having a value equal to the following: one of 'SEQIN' 'SEQOUT' 'SEQINOUT' 'SEQUENTIAL' 'DIRECT' 'RANDOM' 'RANDIN' 'APPEND' 'KEYED' 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 opened is a write-only device, the default access is SEQOUT. The arguments to the ACCESS specifier are: da ta file is access. When equivalent to READONLY {see SEQIN (Implies STATUS='OLD') The specified opened for read-only sequential ACCESS='SEQIN' is specified, it is specifying ACCESS='SEQUENTIAL' and Section 11.3.32). SEQOUT The specified data file is opened for output and sequential access. If the specified file already exists, it is superseded (TOPS-U~n, or a new generation 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 inaccessible. 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. FORTRAN-10/20 VII 11-7 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS SEQINOUT Same as SEQUENTIAL 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.33) is required for random-access oper~tions. You must specify a disk device when the DIRECT argument is used. RANDIN (Implies STATUS='OLD') The specified data file is opened for read-only direct access. More than one user can read the same file at the same time with ACCESS='RANDIN'. When ACCESS='RANDIN' is specified, it is equivalent to specifying ACCESS='RANDOM' and READONLY (see Section 11.3.32). RANDOM Same as DIRECT APPEND The specified file is opened for sequential write-only access. APPEND is the same as SEQOUT except that the file is positioned at its end after the OPEN statement. Reading an APPEND mode file is illegal. REWIND and BACKSPACE are illegal for files opened with APPEND access. KEYED The specified data file is an RMS indexed file opened for either random keyed access or sequential access. The file is accessed by a specified key. Invokes RMS (as if ORGANIZATION=' INDEXED' is specified) • ASSOCIATEVARIABLE Specifier 11.~.2 ASSOCIATEVARIABLE Specifier This specifier enables you to declare a variable whose value is the number of the next record that will be read from· or written to the file. For RMS files, this specifier is ignored unless ACCESS='DIRECT' • For example, after the execution of an OPEN statement and prior to the first data transfer, the associate variable is set to 1. In a data transfer after the first record is transferred, the value of the associate variable is 2. The form of the ASSOCIATEVARIABLE specifier is: ASSOCIATEVARIABLE= Integer variable or integer array element If you are using the ASSOCIATEVARIABLE specifier in a program that makes use of the LINK overlay facility, please read the paragraphs that follow. FORTRAN-10/20 VII 11-8 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS If the variable you specify as the ASSOCIATEVARIABLE is declared in a FORTRAN subroutine, then that subroutine must be loaded in the root link of the overlay structure. If the subroutine cannot be loaded in the root link of the overlay structure, declare your ASSOCIATEVARIABLE in a COMMON statement so that the ASSOCIATEVARIABLE will operate properly. The reasons for these steps are: 1. When the overlay facility is used to load FORTRAN modules, the local variables in the modules are grouped with the routine in which they are declared. 2. When FORTRAN subroutines are loaded by the overlay they are divided into sets called overlay links. 3. Only one overlay link, the one specified to be the root link, 1S always resident in memory. The other overlay links are read in memory as required. facility, Accessing a file opened with an ASSOCIATEVARIABLE changes the value of the specified variable. If this variable is in a nonresident overlay link when the access is made, program execution produces unpredictable results. Moreover, this variable is reset to zero each time its overlay link is removed from memory. Only variables declared in routines loaded into the root link are always resident. variables declated in COMMON statements and those declared in the main program are always resident and can always be used as an associate variable. NOTE For more information on the LINK overlay facility, see the LINK Programmer's Reference Manual, and Chapter 15 of this manual. BLANK Specifier 11.3.3 BLANK Specifier The BLANK specifier applies only when reading formatted (FORMAT-statement) numeric fields 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'. 11-9 to either February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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 is executed before a data transfer on a unit, the default is BLANK='ZERO' for all devices except terminals. For terminals, the default is 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 setting is changed within the format list. (The BN or BZ descriptors are described in Section 12.4.9.) Example: OPEN(UNIT=l,DEVICE='DSK' ,FILE='FOO.DAT' ,BLANK='ZERO') READ(1,10)K 10 FORMAT ( I 5 ) CLOSE (UNIT=l) OPEN(UNIT=l,DEVICE='DSK' ,FILE='FOO.DAT' ,BLANK='NULL') READ(1,10)L CLOSE(UNIT=l) END In the above example, if FOO.DAT contains 123bb, K has the value 12300 and L has the value 123. BLOCKSIZE Specifier 11.3.4 BLOCKSIZE Specifier The BLOCKSIZE specifier enables you block size for magnetic tape files. to specify a physical storage NOTE BLOCKSIZE specifies the physical record length, and RECL(RECORDSIZE) specifies the logical record length. 11-10 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The argument is an integer expression, and for CORE-DUMP tape format, the value assigned represents the number of words in the physical block. For INDUSTRY tape format, the value represents the number of bytes in the physical block. (See the TAPEFORMAT specifier, Section 11.3.37.) The form of the BLOCKSIZE specifier is: BLOCKSIZE= Integer expression BUFFERCOUNT SpecH~r 11.3.5 BUFFERCOUNT Specifier The BUFFERCOUNT specifier enables you to buffers used in the data transfer. of I/O The BUFFERCOUNT is the number of pages used in disk transfers, and ignored for nondisk transfers. is For RMS files, BUFFERCOUNT specifies the MBF (Multi-Buffer Count) RMS internal buffering. for The form of the BUFFERCOUNT specif~er define the number is: BUFFERCOUNT= Integer expression If a BUFFERCOUNT is not specified, or is assigned a value of zero: • For non-RMS files, the buffercount is four pages. • For RMS files, the RMS default is used. NOTE If MODE='DUMP' is specified, BUFFERCOUNT is ignored. The BUFFERCOUNT specifier does not affect the operation of the program, but it can affect execution time and memory requirements. For random I/O, the buffercount specifies the maximum number of in memory (not yet written to disk) during I/O buffers which are operations. NOTE For TOPS-20 extended addressing, all I/O buffers fit in FOROTS's section. FORTRAN-10/20 VII 11-11 must February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS BYTESIZE Specifier 11.3.6 BYTESIZE Specifier The BYTESIZE specifier determines the integer byte size for the file. For existing RMS files, this value must agree with the actual byte size of the file. The form of the BYTESIZE specifier is: BYTESIZE = Integer expression If no BYTESIZE is specified, FOROTS defaults to 7 for TOPS-10/20 files (defaults to 8 for VMS files). If BYTESIZE is specified for a remote VMS file, the bytesize must be 8. If BYTESIZE is specified when creating a new TOPS-20 RMS indexed file that has CHARACTER keys defined, the bytesize must be 7. CARRIAGECONTROL Specifier 11.3.7 CARRIAGECONTROL Specifier The CARRIAGECONTROL specifier enables you to decide how the first character of each record encountered during an output data transfer operation is treated. (Section 12.2.3 describes carriage-control spec i f i ers.) The form of the CARRIAGECONTROL specifier is: CARRIAGECONTROL = cc where: cc is a character expression having a value equal to the following: one of 'FORTRAN' 'LIST' 'TRANSLATED' 'DEVICE' 'NONE' FORTRAN-10/20 VII 11-12 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The arguments to the CARRIAGECONTROL specifier are: FORTRAN specifies that the FORTRAN data file attribute is set in the file's access information, so that when the file is printed, the first character of each record is replaced with a carriage return and the corresponding printer-control vertical motion character(s) (see Table 12-3) • The record terminator at the end of the record will be discarded. LIST specifies that the first character is output with no replacement. Since RMS sequential files do not have record terminators, when LIST is used, you cannot specify that a record should not have a CRLF added when it is printed. Thus, the dollar sign format edit descriptor, which eliminates the CRLF after a record, has no effect for RMS files with LIST specified. TRANSLATED specifies that the first character of each record is replaced with a carriage return and the corresponding printer-control vertical motion character(s) (see Table 12-3). No record terminator is written at the end of the record. Note that the last data record in the file has no ending carriage return/line feed sequence unless a blank record is written. For fixed-length files, LIST. TRANSLATED is treated as For RMS files, TRANSLATED is treated as FORTRAN. DEVICE specifies that the first character will only be replaced for a carriage-control device (such as LPT or TTY). NONE specifies that no carriage-control action is taken. The default value is CARRIAGECONTROL='DEVICE'. NOTE The line printer software assumes that the first character of all data files is a carriage-control character if the file has the extension .DAT or if the /FILE:FORTRAN switch is specified. FORTRAN-10/20 VII 11-13 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS [ EFAULTFILE (TOPS-20) Specifier --_._. 11.3.8 ---_.._-_._-_._.--- DEFAULTFILE Specifier (TOPS-20) The DEFAULTFILE specifier defines a default file specification string. If you do not specify either FILE or DEFAULTFILE, FORTRAN uses the default value FORnn.DAT, where nn is the unit number with leading zeros. The DEFAULTFILE specifier can be used in place of, or in addition to the FILE or NAME specifier. If DEFAULTFILE is used without FILE or NAME, it replaces the FILE or NAME specifier. If DEFAULTFILE is used with FILE or NAME, the DEFAULTFILE file specification is merged with the FILE or NAME value to form the full file specification. The form of the DEFAULTFILE specifier is: DEFAULTFILE = ce where: ce is a character expression that name specification string. You can specify defaults for specification components: one or more contains of the • node (if the file specification contains will be used to access the file) a • device • directory • filename • filetype • file generation number • network attributes a default file following file node name, RMS When yo u spec i fy any of the above components in the FILE or NAME specifier, they override those values specified in DEFAULTFILE. Since FOROTS processes DEFAULTFILE, FILE, and NAME in that order, the components specified in NAME supercede all previous corresponding components. FORTRAN-10/20 VII 11-14 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS DENSITY Specifier 11.3.9 DENSITY Specifier The DENSITY specifier is ignored except when used with magnetic tape; it permits you to specify the tape density. If you do not specify a tape density, FORTRAN assumes that you have set the density at monitor level or that you are satisfied with the system default for the device. The form of the DENSITY specifier is: DENSITY = dens where: dens is a character expression having a value equal to the following: one of for the '200' '556' '800' '1600' '6250' 'SYSTEM' SYSTEM specifies that the density magnetic tape device being used. is the default density DEVICE Specifier 11.3.10 DEVICE Specifier The DEVICE specifier enables you to specify the name of the device involved in the data transfer. A logical name always takes precedence over a physical name. The DEVICE arguments can specify I/O devices located at remote stations, as well as logical devices. The form of the DEVICE specifier is: DEVICE= Character expression If you omit this option, the logical name un (where un is the decimal unit number} is tried. If this is not successful, the standard (default) device associated with the unit is used (see Table 10-3). 11-15 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS DIALOG Specifier 11.3.11 DIALOG Specifier The DIALOG specifier enables you to type in additional OPEN specifiers when the OPEN statement is actually executed. If the DIALOG specifier is found in an OPEN list, then each time the OPEN statement is executed FOROTS suspends execution and prompts the terminal with an asterisk. The form of the DIALOG specifier is: DIALOG You can respond to the asterisk prompt by entering a file spec if ica t ion, DIALOG swi tches (see below), or a file spec if ica t ion followed by DIALOG switches. The file specification may be a full file specification including the device, directory name, and so on. NOTE A DIALOG switch is any OPEN specifier (except DIALOG, DIALOG=, UNIT, NAME, FILE, IOSTAT, or ERR) preceded by a slash (/). For example, when FOROTS enters DIALOG mode, you such as: can type a string *DSK:FOO.BAR/MODE:BINARY/ACCESS:DIRECT DIALOG = Specifier 11.3.12 DIALOG= Specifier The DIALOG= specifier enables you to include all or a portion of the OPEN specifiers in a character expression. The contents of the character expression are interpreted as if you had given the DIALOG specifier (see above); and, when the asterisk prompt was given, you had typed in the same string as is contained in the character expression, followed by a carriage return. The form of the DIALOG= specifier is: DIALOG= Character expression 11-16 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Example: OPEN(UNIT=l,DIALOG=' DSK:FOOeBAR/ACCESS:SEQOUT/MODE:ASC II') I=22 WRITE(1,100)I 10 0 FORMAT ( I5 ) END DIRECTORY (TOP5-10) Specifier 11.3.13 DIRECTORY Specifier (TOPS-10) On TOPS-10, the DIRECTORY specifier is ignored except for disk files. It specifies the location of the User File Directory (UFD) and, optionally, the Sub File Directory (SFD), either of which can contain the file specified in the OPEN statement. The form of the DIRECTORY specifier is: DIRECTORY= Character expression The UFD is the directory in which a user's files are stored; the SFD exists within the UFD. An SFD is often used to group files into separate subdirectories. The following is a sample of the UFD and SFD specification: 10,7,SFDA,SFDB In the sample specification, 10,7 is the project-programmer number. This is an adequate directory specification if the file is in the UFD specified by 10,7. The SFDA and SFDB specify two levels of subfile directories. The complete directory specification indicates that the file is located in subfile directory SFDB. As indicated, the path to SFDB is through the UFD 10,7 and through the SFD SFDA. NOTE Refer to the TOPS-10 Monitor Calls complete description of directories directory structures. Manual for a and multilevel The following is an example of a character expression specification: DIRECTORY='10,7,SFD1,SFD2,SFD3' ---.-- ~ project SubFile Programmer Directory Number Path 11-17 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The following is an example of how to assemble individual elements: a specification from CHARACTER*10 PROJ,PROG,PATHl,PATH2 CHARACTER*l COMM PROJ= '10' PROG= '7' PATHl= 'SFDA' PATH2= 'SFDB' COMM= ' , ' OPEN(UNIT=I,DIRECTORY=PROJ//COMM//PROG//COMM//PATHI//COMM//PATH2) The above specification expression: is equivalent to the following character '10,7,SFDA,SFDB' DIRECTORY (TOPS-20) Specifier 11.3.14 DIRECTORY Specifier (TOPS-2~) 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 a 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 ID= 'GUEST.CLASS3' OPEN(UNIT=22,DIRECTORY=ID) !Looks for DSK:(GUEST.CLASS3>FOR22.DAT FORTRAN-10/20 VII 11-18 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS DISPOSE Specifier 11.3.15 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: one of 'KEEP' 'SAVE' 'DELETE' 'EXPUNGE' 'PRINT' , LIST' 'PUNCH' The DISPOSE specifier must have 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 KEEP. DELETE Specifies on TOPS-10 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-10, same as DELETE. On TOPS-20, if the device involved is a disk, expunge the file; otherwise, take no action. PRINT Specifies that the file will be printed and kept. file must be on disk. LIST Specifies that the file will be The file must be on disk. PUNCH Specifies that the file will be punched on the tape punch and kept. -The file must be on disk. 11-19 printed and The deleted. paper February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS ERR Specifier 11.3.16 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.20) 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.11). 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. error. See The FILE specifier enables you to name the file involved in the transfer operation. You can specify a full file specification. data FILE Specifier 11.3.17 FILE Specifier The form of the FILE specifier is: FILE= Character expression The value of the character expression Is any legal TOPS-10 or TOPS-20 file specification. (See the TOPS-10 Operating System Commands Manual or the TOPS-20 User's Guide.) 11-20 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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 per iod. If a filename is not specified, a default name is generated the fo rm: 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. 11.3.17.1 Remote File Specifications (TOPS-20) - A remote file specification is a file specification that contains a nodename and optionally, network access information in the following format: node::dev:<dir>file[.ext.gen;USERID:id;PASSWORD:pwdiACCOUNT:act] USERID, PASSWORD, and ACCOUNT attributes may be optional depending on the default access privileges of the remote directory or file. DEVICE may be optional depending on the defaults in effect at the remote host. When the file specification is remote, RMS is used to access the file. For all remote access, RMS uses the default protection of the remote directory or system. NOTE FORTRAN supports remote file access only to other TOPS-20 and VMS systems. Note that logical names defined at the local host will not be expanded or interpreted by FORTRAN/RMS before transmission to the remote host. FILESIZE (INITIALIZE) Specifier (TOPS-10 only) 11.3.18 FILESIZE (INITIALIZE) Specifier (TOPS-10) 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). FORTRAN-10/20 VII 11-21 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The value specified by FILESIZE= is used as an estimate only. The effect of FILESIZE= is to help the monitor try to choose the best place on the disk to put the file. FORM Specifier 11.3.19 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' or 'UNFORMATTED'. 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 binary (unformatted) data. transferred , LIN ED', the de fa u 1 t If FORM is not specified and MODE is'ASCII' or value for FORM is 'FORMATTED'. Otherwise, if MODE is 'BINARY', FORM is 'IMAGE', or 'DUMP' (TOPS-10 only), the default value for '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. 101 PROGRAM TRIMP OPEN(UNIT=l,MODE='BINARY' ,FORM='FORMATTED') WRITE(UNIT=1,FMT=101) FORMAT(lX,'This is a test.') END EXECUTE TRIMP LINK: Loading [LNKXCT TRIMP execution] ?OPEN unit 1 DSK:FOR01.DAT at MAIN.+4 in TRIMP (PC 165) ?Incompatible attributes /MODE:BINARY /FORM:FORMATTED 11-22 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS [Enter correct file specs] */MODE:ASCII CPU time 0.3 Elapsed time 11.4 TYPE FOR01.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.20 IOSTAT Specifier The IOSTAT specifier identifies an integer variabie 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-23 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS KEY (TOPS-20) Specifier 11.3.21 KEY Specifier (TOPS-20) The KEY specifier defines the keys used by RMS to access records in an i n de xed f i 1 e • For new RMS indexed files the KEY specifier is mandatory. The presence of KEY= causes RMS to be invoked, whether or not ORGANIZATION= is specified. If the KEY specifier is present without the ORGANIZATION= being specified, ORGANIZATION= defaults to 'INDEXED'. If ORGANIZATION= and KEY= are both specified, ORGANIZATION= must be 'INDEXED', or an error occurs or the ERR= branch is taken. For existing RMS indexed files, the KEY specifier is optional; if given, it is ignored, although RMS does update the KEY XAB chain given by the user with the key information from the file. (See Chapter 18 for more information on RMS data structures.) The form of the KEY specifier is: KEY = (kspec[,kspec] ••• ) where: kspec has the form: e1:e2[:dt] where: el is an integer expression specifying the first byte position of the k~y. e2 is an integer expression specifying the last position of the key. dt is the optional data type INTEGER or CHARACTER. of the key: byte either The default data type of a key is CHARACTER. The position of a key specification in the list determines a key's key-of-reference number. This number is used in any subsequent I/O statement to specify the same key. The primary key is key-of-reference number 0, the first alternate key is key-of-reference number 1, and so forth. The key fields and key-of-reference numbers are permanent attributes of an indexed file and are established when the file is created. When an existing file is opened, key definitions and key-of-reference numbers are obtained from the file itself. FORTRAN-10/20 VII 11-24 February 1987 FI LE-CONTROL AND DEVICE-CONTROL STATEM.ENTS The KEY specifier defines the access key for records in an indexed file. The key starts at position el in the record and has a length of e2-el+l. The values of el and e2 must be such that: 1 .LE. 1 .LE. (el) .LE. (e2-el+l) (e2) .LE. record-length .LE. 255 You must define at least one key for a new indexed file. This mandatory key is called the primary key of the file and usually has a unique value of each record (this is the default condition). You can also define other keys, called alternate keys. RMS allows up to 254 alternate keys. When using keys of type INTEGER, RMS requires that key length e2-el+l equals 4. INTEGER key lengths other than 4 generate an error. LIMIT Specifier 11.3.22 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.15) • The form of the LIMIT specifier is: LIMIT= Integer expression MAXREC (TOPS-20) Specifier 11.3.23 MAXREC Specifier (TOPS-20) The MAXREC specifier defines the maximum number of records permitted in a direct access RMS file. If MAXREC is omitted, the maximum number is unlimited. If MAXREC is specified, RMS returns an error when a record number greater than the value specified is written to the file. This keyword is ignored for non-RMS files. The form of the MAXREC specifier is: MAXREC = Integer expression FORTRAN-10/20 VII 11-25 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS MODE J ~____s_p_e_C_if_ie_r____ 11.3.24 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' , 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.19 for details on FORM, and Section 11.3.1 for details on ACCESS.) Character data is supported in formatted BINARY and IMAGE mode it is not supported in DUMP mode files. files; The possible values of MODE are: ASCII Specifies the data to be 7-bit ASCII characters. Records are terminated with a line feed, form feed, or vert i c'al tab. LINED 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 sequence numbers. FORTRAN removes the line sequence numbers, if (The present, before supplying the data to the user. 1 ine sequence number can be obtained by using the function LSNGET, see Section 13.3.1.) Note that a page mark in a file containing line sequence numbers is a separate record. FORTRAN removes the blank sequence number, and the carriage return/form feed sequence is read as a blank record. This value is ignored for RMS files. FORTRAN-10/20 VII 11-26 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS BINARY specifies that data is formatted as a FORTRAN binary data file. A BINARY file is composed of 36-bit words (see Section 10.3.2). The first word of each record is written by FOROTS and specifies the beginning of the binary record; this 36-bit value is called a type 1 Logical Segment Control' Word (LSCW). Each binary record can contain one or more type 2 LSCWs. The type 2 LSCW, written by FOROTS under certain conditions, is used to mark a record that spans internal buffer boundaries. A third FOROTS-written word, the type 3 LSCW, is always written as the last 36-bit value in each BINARY record. IMAGE All data in a "BINARY" transfer remains equivalent its external form with its internal representation. in For RMS files, specifying BINARY is equivalent specifying IMAGE. RMS files do not contain LSCWs. to 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 and external representation of the data remaining the same. Unlike BINARY files, IMAGE files do not contain record information (LSCWs); they contain only the data transferred. IMAGE files can be backspaced if a record size is specified. DUMP TOPS-10 Corresponds to TOPS-10 DUMP mode I/O. (See the TOPS-10 Monitor Calls Manual.) Record size is ignored. Character data cannot be written into or read from DUMP mode files. Note that there is little or no performance advantage to using DUMP, as FOROTS uses DUMP mode internally for all disk files. NOTE For ASCII devices (line printer, plotter, terminal, industry magnetic tape), the MODE= specifier has no meaning and is ignored; both formatted and unformatted data transfers are legal (see Section 10.3.3). Table 11-2 summarizes the different MODE arguments that are on different devices. supported Table 11-2: DEVICE and MODE Cross-Table MODE = Device Disk (sequential) Disk (direct) DECtape Terminal Magtape Line Printer Card Reader Card Punch Paper Tape Reader Paper Tape Punch 'ASCII' 'LINED' 'BINARY' 'IMAGE' X X X X X X X X X X X X X X X X X X X X X X X X X X .x X X X (TOPS-10) 'DUMP' X ~-- FORTRAN-10/20 VII 11-27 -- ._--,..,-- February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS NAME Specifier 11.3.25 NAME Specifier The NAME specifier is used to specify a full file specification. You can use this specifier instead of the DEVICE, FILE, and/or DIRECTORY specifiers. The form of the NAME specifier is: NAME= Character expression Examples of the NAME specifier are: (TOPS-H~): NAME='DSK:FOO.BAR[10,34]' (TOPS-20): NAME='PS:<SMITH)BILLING.DAT' The NAME specifier can not be given in DIALOG mode. Also, the OPEN statement cannot have both a DIALOG= specifier and a NAME specifier. NOSPANBLOCKS (TOPS-20) Specifier 11.3.26 NOSPANBLOCKS Specifier (TOPS-20) The NOSPANBLOCKS specifier enables you to specify that RMS records are not to cross disk block (page) boundaries. If any record exceeds the size of the physical block, an error occurs. The form of the NOSPANBLOCKS specifier is: NOSPANBLOCKS This specifier has no effect on non-RMS files or on than new relative or sequential files. FORTRAN-10/20 VII 11-28 RMS files other February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS ORGANIZATION (TOPS-20] Specifier 11.3.27 ORGANIZATION Specifier (TOPS-20) The ORGANIZATION specifier determines the internal organization of an RMS file. This specifier invokes RMS (unless 'UNKNOWN' is specified). The form of the ORGANIZATION specifier is: ORGANIZATION org where: org is a character expression having a value equal of the following: to one 'SEQUENTIAL' 'RELATIVE' 'INDEXED' 'UNKNOWN' For new files, the default file organization is SEQUENTIAL. For existing files, the value specified must be the same value as that of the existing file, or an error message is displayed or the ERR= branch is taken. PADCHAR Specifier 11.3.28 PADCHAR Specifier The PADCHAR specifier is used only operations. PADCHAR enables you used to pad fixed-length formatted specified record length (see the 11.3.33) • with formatted output data transfer to specify a character that will be records, on output only, to their RECL(RECORDSIZE) specifier, Section The form for the PADCHAR specifier is: PADCHAR= A character expression in which the first used FORTRAN-10/20 VII 11-29 character is February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS if ignored The default pad character is space. The pad character is is, if the fixed-length records are not being used (that I/O is not RECL(RECORDSIZE) specifier is absent), or if formatted being done. NOTE To specify a null character for the pad character, you must use the function CHAR (see Chapter 13), since the compiler does not allow null character constants, for example: OPEN (UNIT=1,PADCHAR=CHAR(0)) PARITY Specifier 11.3.29 PARITY Specifier The PARITY specifier is only used for magnetic tape operations. It permits you to specify parity to be observed (odd or even) during the transfer of data. The form of the PARITY specifier is: PARITY = par where: par is a character expression having a value equal to 'ODD' or 'EVEN' • PROTECTION (TOP5-10) Specifier 11.3.30 PROTECTION Specifier (TOPS-10) This option specifies a protection code to be assigned to the data file being transferred. The protection code is a 3-digit octal value indicating the level of access to the file. Each of the three numbers in the protection code has a specific meaning. The number in the leftmost position designates the file owner's protection; the middle number designates the project member's protection; and the rightmost number designates the protection for all others users on the system. The system default for the file protection is assigned if a protection is not specified. 11-30 February 1987 FILE~CONTROLAND DEVICE-CONTROL STATEMENTS On TOPS-10, the form of the PROTECTION specifier is: PROTECTION= Integer expression Figure 11-1 illustrates the code. TOPS-10 3-digit octal file protection NOTE When setting the protection code for a file open for output, be sure not to set the protection such that the file is protected against writing by the program; if you should do this, the OPEN statement will fail. To protect the file against writing by the owner, you should give the PROTECTION specifier in the CLOSE statement. tr---- File Owner PROTECTION = nnn....-Other Users +I----prOject Members File owner An octal digit in the first position specifies the file access for the file owner. The file owner is the user whose programmer number matches the directory in which the file is contained. Project Members An octal digit in the second position specifies the file access for the project members. Project members are users whose project number matches the directory in which the file is contained. Other Users An octal value in the third position specifies the file access for all users other than the file owner or a project member. MR-S-1748-B1 Figure 11-1: TOPS-10 File Protection Number Table 11-3 lists all the possible values for each field of the protection code. Refer to the TOPS-10 Monitor Calls Manual for more information. NOTE The File Daemon referred to in Table 11-3 provides extended file protection. The File Daemon allows any user to specify who can and who cannot access their files (if applicable). (Refer to the TOPS-10 Operating System Commands Manual.) 11-31 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-3: TOPS-lO Protection Code Values ,- Octal Value Meaning in Owner Field 1--- 0 The file owner can execute, read, append to, update, write, rename, or change the protection of the file. The File Daemon is not called on a protection failure. 1 The file owner can execute, read, append to, update, write, or rename the file. The File Daemon is not called on a protection failure. 2 The file owner can execute, read, append to, update, or write the file. The File Daemon is not called on a protection failure. 3 The file owner cannot access the file. However, the owner can use the RENAME monitor call to change the file protection. The File Daemon is not called on a protection failure. 4 The file owner can execute, read, append to, update, write, rename, or change the protection of the file. The monitor calls the File Daemon on a protection failure. 5 The file owner can execute, read, append to, update, or write the file. The monitor calls the File Daemon on a protection failure. 6 The file owner can execute or read the file. The monitor calls the File Daemon on a protection failure. 7 The file owner cannot access the file. However, the owner can use the RENAME monitor call to change the file protection. The monitor calls the File Daemon on a protection failure. Octal Value I Meaning in Project Member and Other User Fields 0 The project member (or other) can execute, read, append to, update, write, rename, or change the protection of the file. 1 The project member (or other) can execute, read, append to, update, write, or rename the file. 2 The project member (or other) can execute, read, append to, update, or write the file. 3 The project member (or other) can execute, read, append to, or update the file. 4 The project member (or other) can execute, read, or append to the file. l The project member (or other) can execute or read the file. The project member (or other) can only execute the file. The project member (or other) has no access to the file. ------------------- On TOPS-10, PROTECTION can be an integer expression. If the argument is assigned a zero value or is not specified, the default protection code established for the TOPS-10 installation is used. PROTECTION (TOPS-20) Specifier 11.3.31 PROTECTION Specifier (TOPS-29) The PROTECTION specifier enables you to designate an octal protection code for the file. The protection code is a 6-digit octal value that designates the access to the file of the owner, group members, and other system users. 11-32 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS On TOPS-20, the form of the PROTECTION specifier is: PROTECTION= Integer expression Figure 11-2 illustrates a TOPS-20 protection code. File Owner r:==Grou p Member Other Users ++ [fr== PROTECTION =nnnnnn File Owner The leftmost two digits designate the file access for the file owner. The file owner is the user who is connected to the directory in which the file resides. Group Member The middle two digits designate the file access for group members. Group members are established by the system administrator. A group membership enables a user to share files among other users in the same group. Other Users The rightmost two digits designate the file access for all users on the system, other than the file owner or a group member. MA-S-1749-81 Figure 11-2: TOPS-20 Protection Number NOTE This specifier is ignored for remote files. Instead, the default protection of the remote directory or system is used. Table 11-4 lists the possible protection values and their meanings the TOPS-20 file protection code. in Table 11-4: TOPS-20 Protection Code Values Octal Value Meaning in Owner, Group Member, or Other User Fields 77 Permits full access to the file. 40 Permits read-only access to the file. 20 Permits write and delete access to the file. 10 Permits execute-only access to the file. 04 Permits append-only access to the file. 02 Permits listing of the file specification using the DIRECTORY command. 00 Permits no access to the file. FORTRAN-10/20 VII 11-33 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS On TOPS-20, PROTECTION specifies a protection code to be assigned to the data file being transferred. The protection code determines the level of access that three classes of users have to the file. PROTECTION takes an integer expression as an argument. If PROTECTION is assigned a zero value or is not specified, the default protection code established for your connected directory is used. READONlY Specifier 11.3.32 READONLY Specifier For local non-RMS files, the READONLY specifier is used to specify that the program will only read from the file. The accessing process can read but not write to the file. Output to the file is illegal and will cause an error at execution time. For RMS or remote files, if the first process to access the file specifies READONLY, the file is open for read-only access by that process, as for non-RMS files. Any subsequent accessing process must specify READONLY to obtain any a~cess to the file. If READONLY is not specified by the subsequent accessor, or if SHARED (see Section 11.3.35) is specified, access to the file is denied with a "?File is locked" error. Thus, the access-sharing capabilities of the file are determined by the first process to access the file. The form of the READONLY specifier is: READONLY RECl (RECORDSIZE) Specifier 11.3.33 RECL (RECORDSIZE) Specifier For non-RMS files, the RECL (or RECORDSIZE) specifier enables you to specify the number of characters or words in each record transferred. RECL lS required for all files opened for direct access (ACCESS='DIRECT', 'RANDOM', or 'RANDIN'). (See Section 11.3.1.) For RMS files, RECL specifies the Maximum Record Size (MRS). The form of the RECL specifier is: RECL= Integer expression FORTRAN-10/20 VII 11-34 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS For non-RMS files: • In an ASCII transfer (MODE='ASCII' or 'LINED'), the value assigned to RECL specifies the number of characters in each record. 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. RECL is enforced on output by padding short records with the padding character for formatted records. Long records are truncated. • FORTRAN enforces a specified RECL for all input operations. If the RECL specified in an OPEN statement is different from the actual size of the records, FOROTS reads the number of characters specified by RECL. • 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. • For INDUSTRY tapes, with RECORDTYPE='FIXED', RECL specifies the exact number of characters in each record; there are no terminators or padding characters. For INDUSTRY tapes with RECORDTYPE='VARIABLE', RECL specifies the maximum record size in the file, 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. • In the case of MODE='LINED', the value of RECL excludes five characters and tab in each line-sequence number. the • In a binary transfer (MODE='BINARY', or 'IMAGE'), the value assigned to RECL specifies the number of 36-bit words in each record. For MODE='BINARY', the value in RECL excludes the LSCWs written by FOROTS. NOTE If MODE=' DUMP' is specified, RECL is ignored. For RMS files: • If the file contains fixed-length records, RECL specifies the size of each record. • If the file is a sequential file and contains variable-length records, RECL is optional and specifies the maximum length for each record. If no RECL has been specified, RMS does not perform maximum-length checking. FORTRAN-10/20 V11 11-35 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS • As with non-RMS files, if the records are formatted, length is in bytes; if unformatted, in words. the • If RECL is not specified, the MRS value file was created is used. the • If RECL is specified for an existing file with fixed-length records or relative organization, and the value is different from the actual length of the records in the file, an error message is displayed, or the ERR= branch is taken. • If a program attempts to write a variable-length record that is longer than the non-zero MRS value specified when the file was created, an error is displayed or the ERR= branch is taken. Writing fixed-length records that exceed RECL produces a run-time warning, and the record is truncated to the specified size. • RECL is required when creating a new relative or indexed file, or when the RECORDTYPE is (or defaults to) FIXED. specified when For local RMS files, RMS allows the following maximum record sizes for file/record formats: Organization Record format Maximum Sequential Sequential Relative Relative Indexed Indexed Fixed-length Variable-length Fixed-length Variable-length Fi x ed-leng th Variable-length 262,143 bytes 262,143 bytes 262,143 bytes 262,143 bytes 3,579 words 3,578 words For remote files, the maximum size for an RMS record transfer cannot exceed RMS's DAP buffer size. If the record exceeds this limit, a "?Record too big" error is displayed or the ERR= branch is taken. RECORDTVPE Specifier 11.3.34 RECORDTYPE Specifier The RECORDTYPE specifier defines the format of the records in a file. The form of the RECORDTYPE specifier is: RECORDTYPE = rtype where: rtype is a character expression having a value equal of the following: to one 'FIXED' 'STREAM' 'VARIABLE' 'UNKNOWN' FORTRAN-10/20 VII 11-36 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The possible values for RECORDTYPE are: FIXED is not defined for 36-bit format (CORE-DUMP). For INDUSTRY magnetic tape, this is the standard ANSI "F" tape record format. Thus, the record data is written with no terminators or carriage control characters, one record directly after another, to fill exactly fixed-length blocks. For this record format, a RECORDSIZE must be specified in the OPEN statement. With this record format, all physical blocks on the tape are the same size except for the last block, which may be a short block. STREAM For all tape formats, this record format specifies that for formatted files, a standard stream record terminator (CRLF) is placed at the end of each record, and that a standard stream terminator is expected on input to delimit records. For unformatted files, the behavior is identical to that of MODE='IMAGE'. With this record format, all physical blocks on the tape are the same size except for the last block, which may be a short block. For 36-bit mode (CORE-DUMP), the bytes in the last 36-bit word after the last character of data will be nulls. For all tape formats, if a RECORDSIZE is specified for a formatted file, the actual record read or written consists of the data, CRLF, and the number of nulls necessary to word-align the record. VARIABLE is not defined for 36-bit tape format (CORE-DUMP). For INDUSTRY magnetic tape, this is the standard ANSI "D" tape record format. Thus, records are variable in length, and the record data is written with no terminators or carriage-control characters, and preceded by a 4-byte record size (referred to as the Record Control Word or RCW). Blocks are variable length, not to exceed the block length specified in the OPEN statement. If a RECORDSIZE is specified in the OPEN statement, this is the maximum number· of bytes specified in the 4-byte RCW that precedes each record. The record actually read or written is four characters less than specified in the RCW. UNKNOWN If the record type cannot be determined. If no RECORDTYPE specifier is used, its default record types are the following: value is UNKNOWN, File Type Default Record Type Non-RMS files 'STREAM' RMS relative and indexed files 'FIXED' All other RMS files 'VARIABLE' FORTRAN-10/20 VII 11-37 and the February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS NOTE VMS FORTRAN may write special 'segmented' RMS sequential files with embedded record control bytes as part of the data for each RMS record in the file (VMS FORTRAN RECORDTYPE='SEGMENTED'). These files can be read correctly only from VMS FORTRAN. Attempts to read these files from a remote TOPS-20 system using FORTRAN-10/20 VII will return two bytes of control information as part of the data. SHARED (TOPS-20) Specifier 11.3.35 SHARED Specifier (TOPS-20) The SHARED specifier, for RMS and remote non-RMS files, specifies that the file is opened for write sharing: at least one program is writing a file and at least one other program is either reading or writing the same file. For write sharing to occur, all programs that access the file must specify SHARED. Attempts by a subsequent accessor to write a record that has already been locked results in a "?Record locked" error, or the ERR= branch is taken. The form of the SHARED specifier is: SHARED If neither READONLY nor SHARED is specified, the file is open for exclusive access; that is, the initial accessor can read and write to the file, but subsequent accessors are denied any access. This specifier is ignored for local non-RMS files. FORTRAN-10/20 VII 11-38 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS STATUS (TYPE) Specifier 11.3.36 STATUS (TYPE) Specifier The STATUS (or TYPE) 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. The form of the STATUS specifier is: STATUS = sta where: sta is a character expression whose value is equal to the following: one of 'EXPUNGE' 'OLD' 'NEW' 'SCRATCH' 'UNKNOWN' 'KEEP' 'DELETE' The arguments to STATUS are: EXPUNGE On TOPS-10, this specifies that the file is deleted when it is closed. On TOPS-20, this specifies that the file is deleted and expunged when it is closed. NOTE On TOPS-10, any delete also expunges a file from storage. On TOPS-20, a DELETE operation marks the file as deleted; an EXPUNGE operation immediately erases the file from storage. 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. If the file does exist, an error results. An error also occurs if you specify STATUS='NEW' with ACCESS='SEQIN' ,'SEQUENTIAL' ,'SEQINOUT' (to a read-only device), or 'RANDIN' (see Section 11.3.1). On TOPS-20, the STATUS=' NEW' specifier acts differently, depending on what you have in the directory before STATUS=' NEW' is executed. 11-39 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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. SCRATCH 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 it a generation number of 1. 2. If the file specified in the OPEN statement contains a name, extension, and generation number that does not exist, the specified file is used. 3. If the file 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. 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' impl ies DISPOSE='EXPUNGE' • A SCRATCH file is always given a name by FOROTS. The name of the file is inaccessible to the FORTRAN program. If STATUS=' SCRATCH' is used, you must not specify FILE, DIRECTORY, PROTECTION, or VERSION. 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. If a file is opened with STATUS='SCRATCH', the access must be ACCESS='SEQUENTIAL' (or 'SEQINOUT') or ACCESS='DIRECT' (or 'RANDOM') (see Section 11.3.1). UNKNOWN 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 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. KEEP Specifies that the file is not deleted. STATUS='KEEP' is equivalent to DISPOSE='SAVE' and STATUS='UNKNOWN'. 11-40 Specifying specifying February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS DELETE On TOPS-10, specifies that the file will be erased when the file is closed. On TOPS-20, specifies that the file will be deleted 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. TAPEFORMAT Specifier 11.3.37 ] . TAPEFORMAT SPECIFIER The TAPEFORMAT specifier defines the physical format of tape. the magnetic The form of the TAPEFORMAT specifier is: TAPEFORMAT = tmode 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-10) 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. 11-41 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS UNIT Specifier (required) 11.3.38 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 l0-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. USER OPEN (TOPS-20) Specifier 11.3.39 USEROPEN Specifier (TOPS-20) The USEROPEN specifier is used to specify the name of an optional user-supplied external function. This function can set various RMS parameters that FORTRAN otherwise defaults, and must perform the actual OPEN in place of FOROTS. This function is intended for use with RMS files only; a USEROPEN function used with a remote non-RMS file can produce indeterminate results. The form of the USEROPEN specifier is: USEROPEN proc ed ur e- name where: proced ure-name FORTRAN-10/20 VII is the symbolic name of the USEROPEN function. The function name must be declared EXTERNAL. 11-42 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The function must perform both $OPEN and $CONNECT RMS service calls, returning AC0 non-zero on any non-recoverable failure. If AC0 is returned zero, FOROTS assumes the function has succeeded, and program execution continues. If AC0 is returned non-zero, FOROTS assumes the USEROPEN function has failed, and issues an error (or takes the ERR= branch) based on the STS and STV values returned by RMS to FOROTS. See Section 18.9 for more information on USEROPEN. VERSION (TOP5-10) Specifier 11.3.40 VERSION Specifier (TOPS-10) 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 FORTRAN-10/20 VII 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. 11-43 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.4.1 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 type of value required by each. A section number is provided to refer to detailed descriptions of each specifier. 11-44 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-5: Summary of CLOSE Statement Specifiers and Arguments Argument DEVICE = Possible Value Character expression DIALOG Section 11.5.1 11.5.2 DIALOG = Character expression 11.5.3 DIRECTORY = Character expression 11.5.1 DISPOSE = Character expression with one of the following values: 'SAVE', 'DELETE', 'PRINT', 'KEEP', 'LIST', 'PUNCH', 'EXPUNGE' 11.5.4 ERR = Statement number 11.5.5 FILE = Character expression 11.5.1 IOSTAT= Integer variable or integer array element 11.5.6 LIMIT = Integer expression 11.5.7 NAME = Character expression 11.5.1 PROTECTION = Integer expression 11.5.1 STATUS = TYPE = Character expression with one of the following values: 'KEEP', 'DELETE', 'EXPUNGE' 11.5.8 UNIT = Integer expression 11.5.9 NOTE For compatibility with previous versions of FORTRAN-10/20, you can specify a numeric array name as the value of each of the following 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. numeric variables The use of numeric array names and is a nonstandard in place of character variables feature. 11-45 February 1987 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.17 NAME - see Section 11.3.25 DEVICE - see Section 11.3.10 DIRECTORY (TOPS-10) - see Section 11.3.13 DIRECTORY (TOPS-20) - see Section 11.3.14 PROTECTION (TOPS-10) - see Section 11.3.30 PROTECTION (TOPS-20) - see Section 11.3.31 DIALOG Specifier 11.~.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 FORTRAN-10/20 Vll 11-46 February 1987 FILE-CONTROL AND DEV~CE-CONTROL STATEMENTS You can respond to the asterisk prompt by entering a file specification, DIALOG switches' (see below), or a file specification followed by DIALOG switches. The file specification can be a full file specification including the device,.directory name, and so on. If you enter a file specification that is different from the file specification currently assigned to the file, FOROTS RENAMEs the file after it is closed to the new name. NOTE A DIALOG switch is any CLOSE specifier (except DIALOG, DIALOG=, UNIT, NAME, FILE, IOSTAT, or ERR) preceded by a slash (/). = DIALOG Specifier 11.5.3 DIALOG= Specifier The DIALOG= specifier enables you to include all or a portion of the CLOSE specifiers in a character expression. The contents of the character expression are interpreted as if you had given the DIALOG specifier (see above); and, when the asterisk prompt was given, you had typed in the same string as is contained in the character expression, followed by a carriage return. The form of the DIALOG= specifier is: DIALOG= Character expression Example: CLOSE (UNIT=20,ERR=10,DIALOG='/DISPOSE:DELETE') When DIALOG= is given in the CLOSE list, it other specifiers except DIALOG. is processed after all DISPOSE Specifier 11.5.4 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 FORTRAN-10/20 VII 11-47 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: dis is a character expression having a value equal to the following: one of 'KEEP' , SAVE' 'DELETE' 'EXPUNGE' 'PRINT' 'LIST' 'PUNCH' The DISPOSE specifier must have one of the following values: KEEP Specifies that the file is to be left on the connected unit. DISPOSE='KEEP' is the default. You can not specify DISPOSE='KEEP' if in the corresponding OPEN statement you specified STATUS='SCRATCH' (see Section 11.3.36) • SAVE Same as KEEP. DELETE Specifies on TOPS-10 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. EXPUNGE a disk, delete On TOPS-10, same as DELETE. On TOPS-20, if the device involved is a disk, expunge the file; otherwise, take no action. EXPUNGE deletes but does not expunge a local RMS file. Depending on the capabilities of the remote system, EXPUNGE may also expunge a remote RMS or non-RMS file. PRINT Specifies that the file will be printed and kept (the file will not be kept if you specify the CLOSE statement STATUS=' DELETE' or 'EXPUNGE'). The file must be on disk. This value is not supported for TOPS-20 RMS files; however, it is supported for VMS RMS files. LIST Specifies that the file will be printed, deleted, and expunged (the file will not be deleted if you specify the CLOSE statement STATUS='KEEP'). The file must be on disk. This value is not supported for TOPS-20 RMS files; however, it is supported for VMS RMS files. PUNCH Specifies that the file will be punched on the paper tape punch and kept. The file must be on disk. This value is not supported for RMS or remote non-RMS files. NOTE The value of the CLOSE statement DISPOSE specifier supersedes the value of the OPEN statement DISPOSE specifier and the OPEN statement STATUS specifier if STATUS='EXPUNGE', 'KEEP', and 'DELETE'. FORTRAN-10/20 VII 11-48 February 1987 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.16). 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: IOSTAT= Integer variable or integer array element LIMIT Specifier 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-49 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS The form of the LIMIT specifier is: LIMIT= Integer expression STATUS Specifier 11.5.8 STATUS Specifier it is The STATUS specifier tells FOROTS what to do with a file when 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-10, 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-10, the same as delete. On TOPS-20, specifies that the file is deleted and expunged. this EXPUNGE deletes but does not expunge a local RMS file. Depending on the capabilities of the remote system, EXPUNGE may also expunge a remote RMS or non-RMS file. 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'. FORTRAN-10/20 VII 11-50 February 1987 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.38) 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 FOR01.DAT (since no FILE= option was specified) to be opened on unit 1 for sequential input in binary mode. OPEN (UNIT=3,DEVICE='DSK' ,FILE='PAYROL.DAT', 1 ACCESS='RANDOM' ,MODE='ASCII' ,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. OPEN 1 1 (UNIT=I, FILE='IDX.DAT', ORGANIZATION='INDEXED' ,STATUS='NEW', KEY=(1:15:CHARACTER) ,RECORDSIZE=80) Invokes RMS and causes an RMS indexed disk file named IDX.DAT to be created on unit 1. A primary index of datatype CHARACTER, specifying character positions 1 through 15 of each record has been defined for the file. CLOSE (UNIT=3,DISPOSE='DELETE') The above statement causes the file closed and deleted. FORTRAN-10/20 VII 11-51 associated with unit 3 to be February 1987 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[DEFAULTFILE=dfi] ,flist) where: fi is a character expression whose value name of the file to be inquired about. flist is a list that can contain at most one of each inquiry specifiers (see Section 11.7.3). dfi is a character expression specifying name specification string. specifies a the of the default file DEFAULTFILE=dfi can be used in addition to or in place of FILE=fi when used in connection with an inquiry about a file. If both FILE and DEFAULTFILE are used, then the DEFAULTFILE specification is merged with FILE to obtain the full fIle specification, with file specification fields in FILE superceding corresponding fields in DEFAULTFILE. NOTE If the file specification is remote, RMS access the file. is used to 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. FORTRAN-10/20 VII 11-52 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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. 3. If the file 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-53 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3 INQUIRE Specifiers The specifiers described in the following either farm of the INQUIRE statement. 11.7.3.1 form: sections ACCESS Specifier - The ACCESS specifier ACCESS may has be the used in following acc where: acc 11.7.3.2 form: is a character variable, array element, or substring reference. It is assigned the value 'SEQUENTIAL' if the file is connected for sequential access, 'DIRECT' if the file is connected for direct access, or 'KEYED' if the file is connected for keyed access. If there is no connection, acc is 'UNKNOWN'. BLANK Specifier - The BLANK BLANK specifier has the following blk where: blk is a character variable, array element, or substring reference. It is assigned the value 'NULL' if the file was last opened with BLANK='NULL', and is assigned the value' ZERO' if the file was opened with BLANK='ZERO'. If the file is not open, blk is 'UNKNOWN'. 11.7.3.3 BYTESIZE follow i ng form: BYTESIZE Specifier - The BYTESIZE specifier has the is the integer bytesize of the file (or 0 if is not open). the file byte where: byte 11.7.3.4 CARRIAGECONTROL has the following form: Specifier - The CARRIAGECONTROL specifier CARRIAGECONTROL = cc where: cc is a character variable, array element, or substring reference. It is assigned the following values: 1. 'FORTRAN' if the file has the FORTRAN carriage-control attribute FORTRAN-10/20 VII 11-54 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3.5 form: 2. 'LIST' if the file has attribute the implied 3. 'NONE' 4. 'TRANSLATED' if the file has FORTRAN carriage-control characters being translated directly into vertical motion characters. 5. 'UNKNOWN' if the CARRIAGECONTROL value determined, or the file is not open. if the file has no carriage-control attribute DIRECT Specifier - The DIRECT specifier DIRECT carriage-control has the cannot be following dir where: dir 11.7.3.6 is a character variable, array element, or substring reference. It is assigned the following values: 1. 'YES' file if DIRECT is an allowed access method for the 2. 'NO' if DIRECT is not an allowed access method for the file 3. 'UNKNOWN' if the processor is unable to whether DIRECT is an allowed access method determine ERR Specifier - The ERR specifier has the following form: ERR = s where: s 11.7.3.7 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 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. 11-55 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3.8 FORM Specifier - The FORM specifier has the following form: 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.9 FORMATTED follow i ng form: FORMATTED Specifier - The FORMATTED specifier has the fmd where: fmd 11.7.3.10 form: IOSTAT 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 Speci~ier - The IOSTAT specifier has the following ios where: ios 11.7.3.11 form: KEYED 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. KEYED Specifier - The KEYED specifier has the following kyd where: kyd is assigned the value 'YES' if KEYED is an allowed access method for the file (that is, the file is indexed), 'NO' if KEYED is not an allowed access method, and 'UNKNOWN' if the file is not open. FORTRAN-10/20 VII 11-56 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3.12 NAME Specifier - The NAME specifier 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 specified FOROTS returns the string given in the OPEN for NAME= with defaults applied if 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 transfer statement has been executed using specified unit. the If STATUS='SCRATCH', FOROTS returns blanks for NAME=. If there has been no OPEN statement, and no I/O transfer statement has been executed using the specified unit, FOROTS 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 specified 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. NOTE INQUIRE on a remote file that returns a full file specification, returns the network attributes. FORTRAN-10/20 VII 11-57 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3.13 form: NAMED Spec~fier - The NAMED specifier has the following NAMED = nmd where: nmd is a logical variable or logical array element. It is assigned the value .TRUE. if the specified file has a name, and the value .FALSE. if the file does not have a name. 11.7.3.14 form: NEXTREC Specifier - The NEXTREC specifier has the following NEXTREC nr where: nr 11.7.3.15 form: 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 the following NUMBER = num where: num 11.7.3.16 form: 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. OPENED Specifier - The OPENED specifier has the following OPENED = od where: od is a logical variable or logical array element. It is assigned the value .TRUE. if the specified file is opened on a unit or if the specified unit is opened; it is assigned the value .FALSE. if the file or unit is not open. 11-58 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3.17 ORGANIZATION Specifier - The ORGANIZATION specifier has the following form: ORGANIZATION org where: org is a character variable, array element, or substring reference. It is assigned the value 'SEQUENTIAL' if the file is a sequential file, 'RELATIVE' if the file is a relative file, 'INDEXED' if the file is an indexed file, or 'UNKNOWN' if the file is not open or the file is not an RMS file. 11.7.3.18 RECL (RECORDSIZE) Specifier specifier has the following form: The RECL (RECORDSIZE) RECL = rcl where: rcl is an integer variable or integer array element. For non-RMS files, 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, rcl is expressed in characters, and in words if the file is unformatted. For RMS files, if the file is open, RECL returns the maximum record size value associated with the file in either bytes (for formatted I/O) or words (for unformatted I/O). If the file is not open, RECL returns zero. 11.7.3.19 RECORDTYPE Specifier - The following 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 'VARIABLE' if the file has variable-length records, and assigned the value 'STREAM' if the file is a stream file (default for disk and magnetic tape). If the file is not open, rtype is assigned the value 'UNKNOWN'. FORTRAN-10/20 VII 11-59 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 11.7.3.20 SEQUENTIAL Specifier - The following form: SEQUENTIAL SEQUENTIAL specifier has the seq where: seq is a character variable, array element, or substring reference. It is assigned the following values: 1. 'YES' if SEQUENTIAL is an allowed the specified file access method 2. 'NO' 3. 'UNKNOWN' if the processor cannot determine SEQUENTIAL is an allowed access method if SEQUENTIAL is not an allowed access method 11.7.3.21 UNFORMATTED Specifier - The UNFORMATTED specifier following form: UNFORMATTED for 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-60 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS Table 11-6 summarizes the form and use of the FORTRAN statements. device control Table 11-6: Summary of FORTRAN Device Control Statements Statement Form Section FIND (UNIT = un,REC = rnf,ERR = s][,IOSTAT = ios]) FIND (un'rn[,ERR=sl[,IOSTAT=iosD 11.8.1 REWIND un REWIND (UNIT = un[,ERR = s][,IOSTAT = ios]) REWIND (un[,ERR=s][,IOSTAT=ios]) 11.8.2 UNLOAD un UNLOAD (UNIT = un[,ERR = s][,IOSTAT = ios]) UNLOAD (un[,ERR = s If,IOSTAT = iosD 11.8.3 BACKSPACE un BACKSPACE (UNIT = un[,ERR = s][,IOSTAT = ios]) BACKSPACE (un[,ERR = s][,IOSTAT = ios]) 11.8.4 ENDFILE un END FILE (UNIT = un[,ERR = s][,IOSTAT = ios]) ENDFILE (un[,ERR=s][,IOSTAT=ios]) 11.8.5 SKIPRECORD un SKIPRECORD (UNIT = un[ ,END = s][,ERR = s][,IOSTAT = ios 1) SKIPRECORD (un[,END= s][,ERR=s][,IOSTAT=ios]) 11.8.6 SKIPFILE un SKIPFILE (UNIT = un[ ,ERR = s][,IOSTAT = ios]) SKIPFILE (un[,ERR=s][,IOSTAT=iosD 11.8.7 BACKFILE un BACKFILE (UNIT = un[,ERR = s][,IOSTAT = ios 1) BACKFILE (unLERR= sl[,IOSTAT= ios]) 11.8.8 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. 1. FIND (Section 11.8.1) 2. REWIND (Section 11.8.2) 3. UNLOAD (Section 11.8.3) 4. BACKSPACE (Section 11.8.4) 5. ENDFILE (Section 11.8.5) 6. SKIPRECORD (Section 11.8.6) 7. SKIPFILE (Section 11.8.7) 8. BACKFILE (Section 11.8.8) 11-61 and February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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] [,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 posi.tional1y independent in the parenthetical list. END=s is the optional end-of-file specifier (see Section 10.4.6) • ERR=s is the optional 10.4.7) • IOSTAT=ios is the optional I/O error Section 10.4.8). error specifier (see Section status specifier (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. FIND Statement 11.8.1 FIND Statement In earlier versions of FORTRAN-10/20, the FIND statement could be used during direct-access READ/WRITE operations to reduce the time necessary to do data transfers and to locate records in a direct-access file. For FORTRAN-10/20 Version 11, the FIND statement has no effect on non-RMS files, except for setting the current record number and, therefore, the associate variable. FORTRAN-10/20 VII 11-62 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS For an RMS relative file, the FIND statement positions the file at the record number specified. This establishes the record as the current record, sets th€ associate variable, and returns. The file on the specified unit must be a relative file opened for direct access. The first form of the FIND statement is: FIND (UNIT=un,REC=rn[ ,ERR=s] [,IOSTAT=ios]) The second form of the FIND statement 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 is: FIND(un' rn[ ,ERR=s] [, IOSTAT=ios]) In this form, the unit number and record number do not contain the keywords UNIT= and REC=. Instead, the unit number is specified first, followed by a single quote ('), and finally the record number. The following example demonstrates how the FIND statement is used: FIND(UNIT=1,REC=100) This statement positions the file so reads record 100. that the next READ statement 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 REWIND sequential files. statement can be used with access RMS relative files. RMS sequential files or It is illegal for indexed The forms of the REWIND statement are: REWIND un or REWIND (UNIT=un[,ERR=s] [,IOSTAT=ios]) or REWIND (un [ , ERR=S] [ ,IOSTAT= ios] ) FORTRAN-10/20 VII 11-63 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: un is the logical unit number of the device on which the REWIND is being performed. Table 10-3 lists the default logical unit numbers. REWIND is illegal for files opened with ACCESS='APPEND'. I Statement 11.8.3 UNLOAD Statement UNLOAD] ' - - - - - The UNLOAD statement rewinds and unloads the magnetic tape with the specified unit. associated The forms of the UNLOAD statement are: UNLOAD un or UNLOAD (UNIT=un[,ERR=s] [,IOSTAT=ios]) or UNLOAD (un[ ,ERR=s] [,IOSTAT=ios]) where: un is the logical unit number of the device on which the UNLOAD is being performed. 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. For RMS files, this statement repositions a file with sequential organization to the beginning of the previous record. When the next I/O statement is executed, this preceding record is available for processing. FORTRAN-10/20 VII 11-64 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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. For RMS files, BACKSPACE cannot be used for files open ACCESS='APPEND' or with ORGANIZATION='RELATIVE' or 'INDEXED'. The forms of the BACKSPACE statement are: BACKSPACE un or BACKSPACE (UNIT=un[,ERR=s] [,IOSTAT=ios]) or BACKSPACE (un[,ERR=s] [,IOSTAT=ios]) where: un is the logical unit number of the device on which the Table 10-3 lists the default BACKSPACE is being performed. 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 RMS files, ENDFILE is supported only organization. for files with sequential 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'. FORTRAN-10/20 VII 11-65 February 1987 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]J ,IOSTAT=ios]) where: un is the logical unit number of the device on which the ENDFILE is being performed. Table 10-3 lists the default 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. You can use SKIPRECORD on RMS indexed files; it does a sequential read on the current index as established by a previous indexed READ, or the primary index if no current index has been set. 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=ios] ) 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. FORTRAN-10/20 VII 11-66 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS 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. 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. The forms of the BACKFILE statement are: BACKFILE un or BACKFI LE (UNIT=un [ ,ERR=S] [ ,IOSTAT= ios] ) or BACKFILE (un [ ,ERR=s] [ ,IOSTAT=s] ) FORTRAN-10/20 VII 11-67 February 1987 FILE-CONTROL AND DEVICE-CONTROL STATEMENTS where: un is the logical unit number of the device on which the BACKFILE is being performed. Table 10-3 lists the default logical unit numbers. NOTE On a magnetic tape with multiple files, the position of the tape after an ENDFILE record of one file is equivalent to the position at the beginning of the next file. 11-68 February 1987 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. NAMELIST-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 I/O list elements. Section 12.5 describes list-directed formatting. NAMELIST-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 NAMELIST-statement formatting. NOTE FOROTS/RMS supports transparent data transfers to and from VMS systems for all formatted data, and for unformatted character data. Numeric data transfers are not supported. DIL (Data interchange Library) routines or DIU (Data Interchange Utility) should be used to correctly exchange numeric data between TOPS-20 and VMS systems. FORTRAN-10/20 VII 12-1 February 1987 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 FORMATTED DATA 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 nonzero, unsigned, integer constant called repeat specification. a ed is a repeatable 12.2.1) • edit descriptor (see Section ned is a non repeatable edit 12.2.2) • descriptor (see Section fl is a nonempty format list. The only placement restrictions for FORMAT statements are that they follow PROGRAM, FUNCTION, SUBPROGRAM, or BLOCK DATA statements, and that they precede the END statement. 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 list (variables J, Y, and Z). 101 12.1.2 J=2 Y=3.0 Z=5.1 WRITE{UNIT=5,FMT=101)J,Y,Z FORMAT(1X,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. Character data may follow the right parenthesis that ends the format specification, 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 elements 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 = I (1 X, I , F , F) I 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. INTEGER FORNAM(2) FORNAM(l)=' (lX,I' FORNAM(2)=' ,F,F)' ,J'=2 Y==3.0 2=5.1 WRITE(UNIT=5,FMT=FORNAM)J,Y,Z END In the above example the format specification is stored in both words of 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). NOTE When storing a format specification in an array, always include the outer most parentheses enclosing the format 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, real, 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. The format specifier references the variable that refers to the statement number it has been assigned. The following example shows the same format specification used in the examples in Sections 12.1.1, 12.1.2, and 12.1.3. This time, however, instead of referencing the format 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=IFORMT}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 l2.4.ll) F, 2. Before or after a slash edit descriptor (See Section 12.4.5) 3. Before or after a colon edit descriptor (See Section l2.4.6) In FORTRAN-10/20, the use of commas to delimit format edit descriptors within a format list is optional as long as no ambiguity exists. For example, FORMAT (3X,A2) can be written as FORMAT (3XA2) But the specification FORMAT (I22I5) is ambiguous, since it can represent FORMAT (I22,I5) or FORMAT (I,22I5) 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 numbera' ACCEPT 101,K FORMAT(I2) TYPE 102,K FORMAT(lX,I5) 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 CPU Time 0.1 Elapsed Time 8.7 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 (Se c t ion 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 specify the edit descriptor and field width a single time, as follows: 101 FORMAT (lX,4I6) 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 Refer to: [r]lfw[.m]l Integer Section 12.4.11.1 [r]Flw.dl Floating Point Section 12.4.11.2 [r]E[ w.d[Ee]l Scientific Notation Section 12.4.11.3 [r]D! w .d[Ee1] Scientific Notation Section 12.4.11.3 [r ]G[ w.d[Ee]] General Conversion Section 12.4.11.4 F,E,D,G (Two successive) Complex Section 12.4.11.5 Ir JO[ w[ .m]] Octal Section 12.4.11.6 !rlZ[w[.mll Hexadecimal Section 12.4.11.7 [rlUwl Logical Section 12.4.12 [r]A[wl Character or Hollerith Section 12.4.13 lrlR[w] 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 variety 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 FORMATTED DATA TRANSFERS Table 12-2: Nonrepeatable FORTRAN Edit Descriptors Function Edit Descriptor Refer to: 'hl. .. hn' Character Data Section 12.4.1 nHh Hollerith Data Section 12.4.2 Tc TLc TRc In-Record Positioning Section 12.4.3.1 InlX In-Record Positioning Section 12.4.3.2 $ (Dollar sign) Prevents record from terminating with END OF LINE Section 12.4.4 / (Slash) Record Delimiter Section 12.4.5 : (Colon) Format-Control Termination Section 12.4.6 S SP SS Plus sign control for output of positive numeric fields Section 12.4.7 kP Scaling Factor for Numeric Fields Section 12.4.8 BN BZ Specifies the handling of blanks during the input of Numeric Fields Section 12.4.9 Q Input Only Descriptor - returns the number of characters left in the current record. Section 12.4.10 Key: n is a nonzero, unsigned, integer constant which is equal to a number of spaces (X descriptor) or the total number of characters (H descriptor). h is a character capable ofrepresentation by the processor. This type of character is described in Appendix B. c is a nonzero, unsigned, integer constant which is equal to a number of characters within a record relative to the current position. k is an optionally signed integer constant which declares 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 reco~d 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: 1. Replaced with character (s) • the appropriate printer-control 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(' ','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 summarized 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 Printer Character Octal Value Effect on Carriage Control 012 Skip to next line (form feed after 60 lines on printer). blank ' , plus '+' zero '0' LF,LF 012,012 Skip a line. one* '1' FF 014 Form feed to top of next page. two* '2' DLE 020 Space to next half page. three* '3' VT 013 Space to next one-third of a page. minus '-' LF,LF,LF 012,012,012 Skip two lines. asterisk* ,*, DC3 023 Skip to next line; suppress form feed. (Continous print) period* ', DC2 022 Triple space, with a form feed after every 20 lines printed. comma* ' ,, DC1 021 Double space, with a form feed after every 30 lines printed. slash* '1' DC4 024 Space to next one-sixth of a page. * LF Suppress line feed; overprint the line. Indicates carriage-control specifiers for which the effect on carriage control is device dependent. The effect described is for a line printer with a standard form setup. Note - This table assumes a standard form setup for your line printer (or other output device). I/O List & FORMAT List Interaction 12.3 INTERACTION OF INPUT/OUTPUT LIST AND FORMAT LIST This section describes how the I/O list and the format during a data transfer. 12.3.1 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 descriptors 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,F12.0,FlO.0) 12-11 FORMATTED DATA TRANSFERS In this example, the I/O list is N,X,Y and the format specification is (IS,F12.0,FI0.0) The variables in the I/O list and the specifiers matched up as follows: N X Y in the format are IS 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: Record, Format List, and 110 List Interaction 1. Record ends Format specification continues 1/0 list continues Action: The transfer continues as if the record was extended with blanks. Example: 10 READ (S dO) A ,6 ,C FORMAT (3Fl0.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 a 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 B = 123 C = 1234 D = 12345 20 WRITE (S ,20) A ,6 ,C FORMAT (' A=' ,F3.0, ',6=' ,FLI.O, ',C=' ,FS.O, " 1 D=' ,F8.0) 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 I/O list element, and there is no I/O list element to supply. However, the colon edit descriptor will cause the format scan to stop if there is nothing left in the I/O list (see Section 12.4.6). I, I 3. Format specification ends 1/0 list continues Action: A new record is started. The format scan continues, starting at the beginning of the last complete parenthesized group within the format specification. If there is no parenthesized group within the format, the format is restarted from the beginning (see Section 12.3.4). Example: A=123. 6=78SLI.12S C=1.812S 10 WRITE (SilO) A,6,C FORMAT (F1S.8) 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 t1 0) 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 WR I TE (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 F10.2. Then, the variable B is matched with 15, 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 (1,100)CASE, (A(I) ,1=1,100) FORMAT ('THIS IS CASE' ,I6,//,4(lX,FlO.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(l) A(5) A(9) A (2) A(3) A(4) A(6) A(lO) A(7) A (11) A (12) A(8) Example: DIMENSION A(5) ,DATl(lOO) ,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,FlO.3) ,1,(FI0.3,4(3X,F15.5) 1 ,lX,FlO.3» In this example, after A(l) through A(5), DATl(l), 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 (1) DATI (1) DATl(2) DAT1(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(1) 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 which the data are stored. APOSTROPHE (') Editing 12.4.1 Apostrophe (I) 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 way! 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. hl ••• 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 101 FORMAT (17HiPROGRAM)iCOMPLETE) 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 12.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,SOX,TIO,I3) will have a record length of 13 characters, output was done after the SOX. Examples: The statement sequence: PRINT 2 2 FORMAT (TSO,'BLACK' ,T30,'WHITE') 12-18 since no FORMATTED DATA TRANSFERS causes the following line to be printed: fLACK rHITE (print position 30) (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: ABC}J)i~XYZ is read with the format specification: 10 FORMAT (T7,A3,T1,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~STEP,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 output to carriage-control devices (line printer and terminal), 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,TLlO,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 specified number of positions forward from the current position. The 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(' 234567890123456789012345678901234567890') 20 TYPE 20 FORMAT(T29,'BLACK' ,TlO,'WHITE') 30 40 TYPE 30 FORMAT(TlO,'90l2' ,TR5,'890l') TYPE 10 TYPE 40 FORMAT(T20,'(SECOND)' ,TLI0,')FIRST(') END 12-20 FORMATTED DATA TRANSFERS EXECUTE TEST2.FOR FORTRAN: TEST2 MAIN. LINK: Loading [LNKXCT TEST2 execution] 234567890123456789012345678901234567890 WHITE BLACK 9012 8901 234567890123456789012345678901234567890 )FIRST<ND) CPU time 0.1 Elapsed time 0.5 In FORMAT 20, 'BLACK' is written, then 'WHITE' is written to the left of it. In FORMAT 30, five 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'. -c:- '--'--;-":J (DOLLAR SIGN) Editing 12.4.4 $ (Dollar Sign) Editing 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:' WRITE (5,20) READ (5,*) X FORMAT (I 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 DATA TRANSFERS / (SLASH) Editing 12.4.5 / (Slash) Editing The / (slash) edit descriptor indicates the end of data transfer for a record. Two consecutive slashes indicate the transmission of an empty record. On input to a file connected for 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 record of the file. A record that contains no characters 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 (I5,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 in the written on output or skipped on input. When n slashes appear format, n-l blank records are written on output or n-l middle of a 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,X1,X2,X3 FORMAT(F6.1,F6.1,:,' BUT THIS SHOULD' ,F6.1) END EXECUTE TEST4.FOR FORTRAN: TEST4 MAIN. LINK: Loading [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 5S 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 numeric output fields. SS indicates that the plus sign is not printed in positive numer ic output fields. This descriptor is the default. 12-24 is printed in all The positive FORMATTED DATA TRANSFERS The S, SP, and SS edit descriptors affect only I, F, E, D, and G editing during the execution of a data transfer output statement; these edit descriptors have no effect during input transfers. These descriptors stay in effect until the end of the I/O transfer or until another S, SP, or SS is encountered. Example: Xl X2 X3 X4 10 100 200 300 400 TYPE 10, XI,X2,X3,X4 FORMAT(" ,S,F7.l, SP,F7.1, SS,F7.l, SP,F7.l) END EXECUTE TEST5.FOR FORTRAN: TEST5 MAIN. LINK: Loading [LNKXCT TEST5 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 to specify a scale factor for F, and G edit descriptors. E, D, representing the The form of the P edit descriptor 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 until 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 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 external 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 1jO.125E+02 The addition of the scale factor 2P, as in FORMAT (2P,Ell.3) 12-26 number 12.49; the FORMATTED DATA TRANSFERS produces the external field .J2fj512.49E+00 with a scale factor of zero, the number of significant digits by a format of the form: printed Ew.d or Dw.d is the number of digits to the right of the decimal point. For a negative scale factor nP, for -d<n<O, there will be ABS(n) leading zeros and d-ABS(n) significant digits after the decimal point (for a total of d digits after the decimal point). If n<-d, there will be d insignificant digits (zeros) to the right of the decimal point. If the scale factor nP is positive, for 0<n<d+2 there will be n significant digits to the left of the decimal point and d-n+l significant digits to the right of the decimal point (for a total of 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 lPE15.3 -lPE15.3 2PE15.3 -3PE15.3 4PE15.3 6PE15.3 }6p5J6J6J6~0.125E+02 3 4 n=O n<d+2 -d<n n<d+2 n<-d n<d+2 n>d+2 J'6t6J6)6,lSjSl.249E+Ol ~J'6t6J6}6,kS0.012E+03 2 4 t6t6J6J6J6J6l2.49E+00 t6.kS.kSJ6.kS)60.000E+05 J6J6)6,sJ'6jS1249.E-02 Jz$JzSJDjlS124900.E-04 o 4 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,Xl FORMAT(/,' The above number written with P=2' ,I, 1 ' i s =' , 2 P , F , I " ( Nurn b era b 0 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,I5,FIO.2,BZ,FIO.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 ~ -- Q Editing .. 12.4.10 . ------J _--------- Q Editing The Q edit descriptor sets a corresponding integer variable in the I/O list to the number of characters left in the record being transferred. This descriptor is for use with input transfers only. You can use multiple Q descriptors in the same format list. The Q edit descriptor is useful when you need to know the number of characters remaining in a record. For example: 100 TYPE *,'Enter text:' ACCEPT 100,L,Jl FORMAT (AS,Q) when used to read the data Enter text: HELLO THIS IS A TEST would yield the value IS for variable Jl, characters in the data, and AS reads S of them. since there are 20 Numeric Editing 12.4.11 Numeric Editing The I, F, E, D, G, Z, and a 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 l2-S 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-S. 12-29 FORMATTED DATA TRANSFERS Table 12-5: Default Field Widths for Numeric Edit Descriptors r - - - - - - - - - - - -.. -.- .-.--..-.-..---....... ---. - . - - - - - - - - - - - - - - - - - - - - - - - - - - - - - , Edit Descriptor Default Field Width ----.----- --.- .---. .-----.- . .-.----. -. --...-. -- _..__._.__._...._._-_._--_._._._-------------1 115 -_._-----_._-_ .. _._+ .. _......_._... . F (single prec.) *1<'15.7 F (double prec.) *F25.18 E (single prec.) E15.7 . -.---.----.- - .-.- ._._ ..._-... _-_._._--_._------------------1 -...- - . - . - - - - - - - - - - - - - - - - . - - . - - - - - - - - . - - . - - - - - - - - - - - - -- - - - - I E (double prec.) E25.18 - - - - - - -. --.--- --.--.-----.---- .--.----. ----.--. - - - - - - - - - - - . - - - - - - - - - - - - - - - - 1 D15.7 D (single prec.l . .---- ._-_._._._--------_._----------------1 D (double prec.l D25.l8 r----------.---+-.----.-.--.--.-.-.------.-------.---------------------/ G (single prec.) 1-----_._-------- GI5.7 .-.--------..---.--.------... ----- G (double prec.) G25.18 o (single prec.) o (double prec.) 015 ....-..---.-.--.-.-..-...---.-- ... - - - - - - - - - - - - - - - - - - - - - - 1 ----.-.. --.-------.-.-.. - - - - - - - - - - - - - - - 1 --.------..... ------.------. -. -----_._---_._----------------1 025 ------_._._--_._---_.__. _ - - - - - - - - - - - - - - - - - - - - - - - - - 1 L LI5 Z (double prec.) Z25 A (single prec.l A5 A (double prec.) Ala R (single prec.l R5 r - - - - - - - - - - --+-------------.--- - . - - - -..--.------.-------.----------1 Z (single prec.l Z15 -----------.--.---------------------1 -.. --.---.. -- .---.---.-.------------------1 .-.-- ..--..-.-.-----.-.--.---.-.-.---.-.--.. - . - - - - - - - - - . - - . - - . - - - - - f 1------------_._- R (double prec.) ---.-.. - - - - - - - . - - - - - - - - - - - - - - - - - - - - - - - - - f .-. ----.----- ..--.-------------.--------------------1 RIO If the default field width for F tormat is too small for 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 Editing 12.4.11.1 editing. I Editing - The I 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 indicating how many fields of I are being specified. The default is one field. w is an optional, 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, comma, or character illegal for the I edit descriptor is encountered • •m is an optional, unsigned, 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 (I15.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,219.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 occupying the next 8 columns. The third and fourth items are 5- to 9-digit integers occupying 9 columns each, with leading zeroes appended to the data to make them 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.d] 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 FORMATTED DATA TRANSFERS The form of the D edit descriptor is: [r]D[w.d[Ee]] where: r is an optional, nonzero, unsigned, integer constant that is equal to the number of E or D fields being described. The defaults are one single-precision E field and one double-precision D field. w is an optional, nonzero, 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 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 E or D 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 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, nonzero, 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 Edmng 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 5. The digits in the exponent decimal (if included) 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 Data Magnitude on G·Format Output Conversions Data Magnitude (m) Effective Conversion m .LT. 0.1. 0.1 .LE. m .LT. 1.0 1.0 .LE. m .LT. 10.0 Ew.d F(w - n).d,n(x) F(w - n).(d-1),n(x) 10**d-2 .LE. m .LT. 10**d-1 10**d-1 .LE. m .LT. 10**d m .GE. 10**d F(w - n).l,n(x) F(w - n).O,n(x) Ew.d where: x is a blank n is 4 for Gw.d and e + 2 for Gw.dEe where: x is a blank. n is 4 for Gw.d and e+2 for Gw.dEe NOTE In all numeric field conversions, the field width (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 t~o small to accommodate the converted number, the field will be filled with asterisks (*). If the number converted occupies fewer character positions than specified by w, it will be right-justified in the field, and leading blanks will be used to fill the field. If the numeric data representation 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 the field width Fw. Examples of G output conversions (where the ~ signifies a blank) are: Format Internal Value External Representation G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 G13.6 0.01234567 -1.12345678 1.23456789 12.34567890 123.45678901 -1234.56789012 12345.67890123 123456.78901234 -1234567.89012345 9I0.123457E-01 -0. 123457J6Jb;5» Jb)51. 23457t6~)5J6 12-35 y.sp512.3457)5J6t5JzS: J6t6123.457j2S}6.J6~ t6-1234.57J6J6J6~ ,t6,t612 345. 7p5J6,l6iz{ J2Sj2S123457.J6J2S}6'P{ -0.123457E+07 FORMATTED DATA TRANSFERS For 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)5;S0 • 012346 ,JzS)6)S)S-0.123457 Jzl)6JlSJ6J61.234568 J6Jl5JlSJzH2.345679 ~Jijp5123.456789 J2l-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 (FI0.2,EI0.2) In this sample, the FI0.2 edit descriptor provides editing for the real part of the complex number; the E10.2 edit descriptor provides editing for the imaginary part. You may include any nonrepeatab1e edit descriptors between and imaginary edit descriptors for a complex number. (O~al) the real ] Editing '----------"~-.-.--.-----'"- 12.4.11.6 a (Octal) Editing - The 0 (octal) edit descriptor specifies octal editing. The form of the a edit descriptor is: [r]O[w[.m]] 12-36 FORMATTED DATA TRANSFERS where: r is an optional, nonzero, unsigned, integer constant specifying the number of successive octal fields being described. The default is one octal field. w is an optional, nonzero, unsigned, integer constant specifying the total number of digits in the octal field being described. If w is not specified, for output, the value for a single-precision octal field is 15 (the default), and the value for a double-precision octal field is 25 (the default). For input, the data is scanned until a blank, comma, or character illegal for the 0 edit descriptor is encountered. m is an optional, unsigned, integer constant specifying the minimum number of digits to be output to the field. The defaults are 12 for single-precision octal values and 24 for double-precision octal values. c; ~--"---- Z (Hexadecimal) Editing --~.-,-,---,- ------_.__ ... 12.4.11.7 Z Editing - The Z edit descriptor specifies input and output of hexadecimal values. Hexadecimal is a base 16 number 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: [r] Z [w[ .m]] where: r is an optional, unsigned, nonzero, integer constant specifying the number of consecutive hexadecimal fields being specified. The default is one hexadecimal field. w is an optional, unsigned, nonzero, integer constant specifying the total number of digits in the hexadecimal field being described. If w is not specified, for output, the value for a single-precision hexadecimal field is 15 (the default), and the value for a double-precision hexadecimal field is 25 (the default). For input, the data is scanned until a blank, comma, or character illegal for the Z edit descriptor is encountered. m is an optional, unsigned, integer constant specitying the minimum number of digits to be output in the field. The default for single-precision hexadecimal fields is 9 digits; the default for double-precision fields is 18 digits. 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 enti re 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 FORMATTED 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 is an optional, unsigned, integer constant specifying the 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); 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 var iable. 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 R 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. NOTE The A edit descriptor, described in Section 12.4.13, performs the same function as the R descriptor except that it left-justifies the data in storage with trailing 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 FORMATTED 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)i 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: , 0 I da ta I I '0 da ta R 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 right-justified and zero-filled in the corresponding variable. 3. m characters are output and OUTPUT, where w > m in the field. The remainder of the field is right-justified zero-filled. 4. OUTPUT, where w < m -- 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 record. 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 ("). 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 blanks, 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 lAB 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 t2.6 NAMELIST-STATEMENT FORMATTING The data transfer statements described in Chapter 10 usually include ~n I/O list, which is a list of variable, array, or array element names that identify the names of the data being transferred. An alternative way of creating I/O lists is to use the NAMELIST statement. Using this method, you can specify the I/O list in a NAMELIST statement and then reference the list by name in the appropriate data transfer statement. When you use NAMELIST-statement formatting, as opposed to fORMAT-statement or list-directed formatting, you need only reference an I/O list by NAMELIST name in a data transfer statement. [ "---------------"-""] NAMELIST Statement ----"-.------.-~.~- 12.7 ..".,- .. ,~-,-- -.---~~- NAMELIST STATEMENT The form of the NAMELIST statement is: NAMELI ST /name/ list [/name/l i st] ••• where: name is the name of the NAMELIST I/O list. This is the name referenced in data transfer statements. Each NAMELIST name must be enclosed in slashes. 1 i st is the list of items comprising the NAMELIST I/O list. [terns within the list may be variable names or array names. Separate multiple list items with commas. Each list of a NAMELIST statement is identified and referenced by the name immediately preceding the list. The following is an example of creating two NAMELIST I/O lists the names TABLE and SUMS. having DIMENSION C(2,4) ,TOTAL(lO) NAMELIST/TABLE/A,B,C/SUMS/TOTAL In this example, the name TABLE identifies the list consisting of the scalars A and B and the array C, and the name SUMS identifies the list consisting of the array TOTAL. 12-44 FORMATTED DATA TRANSFERS Once a list has been defined in a NAMELIST statement, one or more statements may reference its name. I/O The rules for structuring a NAMELIST statement are: 1. You may use a maximum of six characters for a NAMELIST name. 2. You must begin the list name with an alphabetic character. 3. You must enclose the NAMELIST name in slashes. 4. You should use NAMELIST names program. 5. You may define a NAMELIST name only once, and you must define it by a NAMELIST statement. Once defined, you may use the name only in I/O transfer statements. 6. You must define the NAMELIST name before statements in which it is used. 7. You must define any dimensioned variable contained in a NAMELIST statement in an array declaration statement preceding the NAMELIST statement. 12.7.1 that are unique the within data the transfer NAMELIST-Controlled Data Input Transfer During data input transfers in which a NAMELIST-defined name is referenced, records are read until a record is found that begins with a blank, then $ (dollar sign), and then the desired NAMELIST name. The dollar sign must be the second character in the record; the first character in the record must be a blank. NOTE You may use "&" instead of "$" in input. NAMELIST-controlled Data items of records to be input (read) using NAMELIST-defined must be separated by commas and may be of the following form: lists V=Kl,K2, ••• ,Kn where: v may be a variable, array, or array element name. Kl, ••• ,Kn are constants. A series of identical constants may be represented as a single constant preceded by a repetition count (5*5 represents 5,5,5,5,5). You can specify more than one constant only if V is an array. If V is a scalar, then you may have only Kl. The input data is always converted to the type of the list variable when there is a conflict of types. A character constant is truncated from the right, or extended on the right with blanks, if necessary, to yield a constant of the same length as the variable, array, or substring. 12-45 FORMATTED DATA TRANSFERS The input operation continues until another $ symbol is detected. If variables appear in the NAMELIST record that do not appear in the NAMELIST list, an error condition will occur. A character constant must have delimiting 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 start a record). For example, assume: 1. A is a 2-dimensional real array 2. B is a I-dimensional integer array 3. C is an integer variable 4. D is a character variable of length 5. 5. The program contains the NAMELIST declaration: NAMELIST /FRED/ A,B,C,D 6. 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 result in the following: the NAMELIST-defined name FRED 1. The integer 4 will be converted to floating point and in A{7 ,2) • 2• Th e in t e g e r 3 will be pIa c ed in B ( 1) • 3. The integer 2 (after B(2) ,B(3) , ••• ,B(7). 4. The floating point number 3.32 integer 3 and placed in C. 5. The character string 'RON~~' will be placed in D. 12.7.2 being truncated) will will be be will placed placed converted to in the NAMELIST-Controlled Data Output Transfers When a WRITE statement refers to a NAMELIST-defined name, all variables and arrays and their values belonging to the named list are written out, each according to its type. 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 NAMELIST-defined list. 12-46 statement contain all referencing a FORMATTED 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 AB'CD, the statements: REAL ARRAY(2,3) CHARACTER D*5 DATA ARRAY,Al,KI,D/-6.75, 0.234E-04, 680.0, -17.8,0.0,00, 1 73 • 1, 3, 'AB' I CD' / NAMELIST/NAMl/ARRAY,Al,Kl,D WRITE (u,NAM1) generate the following form of output: I01umn 1 9f$NAMl ARRAY= Al= $END -6.750000, 0.2340000E-04, 680.0000, -17.80000, 2*0.0000000, 73.10000, Kl= 3, D='AB' 'CD I NOTE Do not use device-positioning commands such as BACKSPACE or SKIPRECORD with NAMELIST-controlled 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 (FORTRAN-defined functions) 2. Statement functions 3. External functions 4. Subroutines 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: ABS ACOS AINT ALOG ALOGIO AMAXI AMINI ANINT ASIN ATAN ATAN2 CMPLX COS COSH DBLE DIM EXP INT LOG LOGIO 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: ABS (returns the absolute value of the argument) and SQRT (returns the square root of the argument) • PROGRAM TEST Y = -64 A = ABS (Y) TYPE ,A B = SQRT CA) 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 results: 13-2 FUNCTIONS AND SUBROUTINES EXECUTE TEST. FOR FORTRAN: TEST TEST LINK: Loading [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 result. PROGRAM TESFUN DOUBLE PRECISION A,B,AR,BR REAL C,CR 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 ARGUMENT BR = DSQRT(A) C C SPECIFIC SQRT RETURNS A REAL VALUE RESULT CR = SQRT(C) TYPE , AR,BR,CR END Executing the program above yields the following results: EXE TESFUN LINK: Loading [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 Definition Argument Type 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. REALCz) .LE.88.029 IAIMAG(z)1 .LE. 36394.429 G-floating: y .GT. 0 Complex All COMPLEX Numbers Logarithm (LOG, LOG10=Generic Functions) ALOG* y = log(x) [base e) Real x .GT. 0 Real -89.415 .LE. y .LE. 88.029 DLOG** y = log(x) [base e) 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 e) Complex z .NE. (0,0) G-floating: -710.475 .LE. y .LE. 709.089 Complex -89.415 .LE. REAL(w) .LE. 88.029 -PI .LT. AIMAG(w) .LE. PI ALOGlO* y = log(x) [base 10] DLOGIO** y = log(x) [base 10] 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**112 Real x .GE. 0 Real y .GE. 0 DSQRT** y = SQRT(x) = x**112 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 Argument Restrictions Function Type Result Range Trigonometric SIN* y = sin(x) Real Ixl .LE. 210828714 Real -1 .LE. y .LE. 1 SIND y = sin(x) (degrees) Real Ixl .LE. 47185919 Real --1 .LE. y .LE. 1 DSIN** y = sin(x) Double D-floating: Ixl .LE. 6746518852 Double D-floating: -1 .LE. y .LE. 1 G-floating: -1 .LE. y .LE. 1 G-floating: Ixl .LE. 1686629713 CSIN w = sin(z) Complex IREAL(z)1 .LE. 210828714 IAIMAG(z)1 .LE. 88.895 Complex All COMPLEX Numbers COS* y = cos(x) Real Ixl .LT. 210828714 Real -1 .LT. y .LE. 1 COSD y = cos(x) (degrees) Real Ixl .LT. 47185919 Real -1 .LT. y .LE. 1 DCOS** y = cos(x) Double D-floating: Ixl .LT. 6746518852 Double D-floating: -1 .LE. y .LE. 1 G-floating: -1 .LE. y .LE. 1 G-floating: Ixl .LT. 1686629713 CCOS w = cos(z) Complex IREAL(z)1 .LE. 210828714 IAIMAG(z)1 .LE. 88.895 Complex All COMPLEX Numbers TAN* y = tan(x) Real Ixl .LE. 36396 Real All REAL Numbers DTAN** y = tan(x) Real D-floating: Ixl .LE. 3373259426 Double D-floating: All D-FLOATING Numbers G-floating: All G-FLOATING Numbers G-floating: Ixl .LE. 843314856 COTAN y = cot(x) DCOTAN** y = cot(x) Real Ixl .LE. 36396 Real All REAL Numbers Double D--floating: Ixl .LE. 3373259426 Double D-floating: All D-FLOATING Numbers G-floating: Ixl .LE. 843314856 13-5 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 Inverse Trigonometric ASIN* y = arcsin(x) Real -1 .LE. x .LE. 1 Real -PI/2 .LE. y .LE. PII2 DASIN** y = arcsin(x) Double D-floating: -1 .LE. x .LE. 1 Double D-floating: -PI/2 .LE. y .LE. PI/2 G-floating: -1 .LE. x .LE. 1 G-floating: -PI/2 .LE. y .LE. PII2 ACOS* y = arccos(x) Real -1 .LE. x .LE. 1 Real DACOS** y = arccos(x) Double D-floating: -1 .LE. x .LE. 1 Double y = arctan(x) DATAN** y = arctan(x) G-floating: o .LE. y .LE. PI Real x = any REAL Numbers Real -P1/2 .LE. y .LE. PII2 Double D-floating: x = any D-FLOATING Numbers Double D-floating: -PI/2 .LE. y .LE. PII2 G-floating: x = any G-FLOATING Numbers ATAN2* y = arctan(argllarg2) DATAN2** y = arctan(argllarg2) D-floating: o .LE. y .LE. PI G-floating: -1 .LE. x .LE. 1 ATAN* o .LE. y .LE. PI G-floating: -PII2 .LE. y .LE. PII2 Real arg1,arg2 = any REAL Numbers Real -PI .LE. y .LE. PI Double D-floating: argl,arg2 = any D-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-FLOATING Numbers COSH* y = cosh(x) Real Ixl .LE. 88.722 Double y .GE. 1 DCOSH** y = cosh(x) Double D-floating: Ixl .LE. 88.722 Double D-floating: y .GE. 1 G-floating: Ixl .LE. 709.782 TANH* y = tanh(x) DTANH** y = tanh(x) G-floating: y.GE.l Real Any REAL Numbers Real -1 .LE. y .LE. 1 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 FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Name Definition Argument Type Argument Restrictions Result Range Function Type Absolute Value ABS* y = Ixl Real Any REAL Numbers Real y .GE. 0 lABS y = Iii Integer Any INTEGER Numbers Integer y .GE. 0 DABS** y = Ixl Double D-floating: Any D-FLOATING Numbers Double D-floating: y .GE. 0 G-floating: Any G-FLOATING Numbers CABS y = Izl Complex Any COMPLEX Numbers G-floating: y .GE. 0 Real y .GE. 0 Truncation AINT* Sign of arg * largest integer .LT.largl Real Any REAL Numbers Real All REAL Numbers INT* Sign of arg * largest integer .LT·largl Real Any REAL Numbers Integer All INTEGER Numbers IDINT Sign of arg * largest integer .LT·largl Double Any DOUBLE PRECISION Numbers Integer All INTEGER Numbers DlNT** Sign of arg* largest integer .LT·largl Double D-floating: Any D-FLOATING Numbers Double D-floating: All D-FLOATING Numbers G-floating: Any 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 Any REAL Numbers Real All REAL Numbers DNINT** y = int(x + .5) if x .GE. 0 else y = int(x -.5) Double D-floating: Any D-FLOATING Numbers Double D-floating: All D-FLOATING Numbers G-floating: Any G-FLOATING Numbers G-floating: All G-FLOATING Numbers Nearest Integer NINT* y = int(x + .5) if x .GE. 0 else y = int(x -.5) Real x .LE. (2**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. (2**35)-1 x .GE. -(2**35) Integer All INTEGER Numbers 13-7 FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Argument Type Argument Restrictions Remainder when argi 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** Remainder when argi is divided byarg2 Double D-floating: arg2 .NE. 0 Double Name Definition AMOD Function Type Result Range Remaindering G-floating: arg2 .NE. 0 D-floating: o .LE. y .LT. arg2 G-floating o .LE. y .LT. arg2 Maximum Value (MAX = Generic Function) AMAXO Argument with greatest value Integer Any INTEGER Numbers Real All REAL Numbers AMAXI* 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 DMAXl** Argument with greatest value Double D-floating: Any D-FLOATING Numbers Double D-floating: All D-FLOATING: 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 Integer All INTEGER Numbers MINI Argument with least value Real Any REAL Numbers Integer All INTEGER Numbers DMINl** 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 largll else -Iargll Real Any REAL Numbers Real All REAL Numbers ISIGN If arg2 .GE. 0 then larg11 else -Iargll Integer Any INTEGER Numbers Real All INTEGER Numbers DSIGN** If arg2 .GE. 0 Double D-floating: Any D-FLOATING Numbers Double D-floating: All D-FLOATING Numbers then larg11 else -larg11 G-floating: Any G-FLOATING Numbers 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 argl .GT. arg2 then arg1 - arg2 else 0 Integer Any INTEGER Numbers Integer y .GE. 0 DDIM** If arg1 .GT. arg2 then arg1 - arg2 else 0 Double D-floating: Any D-FLOATING Numbers Double D-floating: y .GE. 0 G-floating: Any G-FLOATING Numbers G-floating: y .GE. 0 Double Precision Product DPROD arg1*arg2 Real Any REAL Numbers CONJG arg = x + i*y, CONJG = x - i*y Complex REAL* arg = x + i*y returns x AIMAG Double ALL DOUBLE PRECISION Numbers Any COMPLEX Numbers Complex All COMPLEX Numbers Complex Any COMPLEX Numbers Real All REAL Numbers arg = x + i*y returns y Complex Any COMPLEX Numbers Real All REAL Numbers CMPLX* Returns arg1 + i*arg2 Real Any REAL Numbers Complex All COMPLEX Numbers DFLOAT Integer to double precision Integer Any INTEGER Numbers Double Iyl .LT. 2**35 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 INTEGER Numbers Real IYI .LT. 2**35 IFIX Real to integer Real Ixl .LT. 2**35 Integer All INTEGER Numbers ICHAR Character to Integer Character First character of character value Integer o .LE. y .LE. 127 CHAR Integer to Character Integer o .LE. y .LE. 127 Character All Single Character Conversion Routines 13-9 FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Name 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 Character Comparisons 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. Bit Manipulation lAND Performs a logical AND on corresponding bits of argl and arg2 Integer argl,arg2 = any Integer Numbers Integer All Integer Numbers lOR Performs an inclusive OR on corresponding bits of argl and arg2 Integer argl,arg2 = any Integer Numbers Integer All Integer Numbers lEaR Performs an exclusive OR on corresponding bits of argl and arg2 Integer arg1,arg2 = any Integer Numbers Integer All Integer Numbers NOT Complements each bit of argument Integer Any Integer Number Integer All Integer Numbers ISHFT Logically shifts argl left arg2 bits if arg2 is positive; argl is logically shifted right arg2 bits if arg2 is negative Integer argl = any Integer Number -36 .LE. arg2 .LE. 36 Integer All Integer Numbers ISH FTC Circularly shifts (rotates) Integer rightmost arg3 bits of arg1 by arg2 places. If arg2 is positive, the rotation is to the left; if arg2 is negative, the rotation is to the right argl = any Integer Number -36 .LE. arg2 .LE. 36 1 .LE. arg3 .LE. 36 Integer All Integer Numbers 13-10 FUNCTIONS AND SUBROUTINES Table 13-1: FORTRAN Intrinsic Functions (Cont.) Argument Type Argument Restrictions Function Type Result Range Name Definition IBITS Extracts bits arg2 through arg2 + arg3-1 from argl ......... Integer argl = any Integer Number o .LE. arg2 .LE. 35 arg2 + arg3 .LE. 36 Integer All Integer Numbers IBSET Returns the value of argl with bit arg2 of argl set to 1 Integer argl = any Integer Number o .LE. arg2 .LE. 35 Integer All Integer Numbers IBCLR Returns the value of argl with bit arg2 of ,argl set to 0 Integer argl = any Integer Number o .LE. arg2 .LE. 35 Integer All Integer Numbers BTEST Returns .TRUE. if bit arg2 of argl equals 1; returns .FALSE. if bit arg2 of argl is 0 Integer argl = any Integer Number o .LE. arg2 .LE. 35 Logical .TRUE. or .FALSE. Bit Manipulation Notes: * = Generic function •• = G-floating double-precision functions (KL model B only) - are used if IGFLOATING compiler switch is specified (see Section 16.1.3 or 16.2.3). "'.* = See also the MVBITS Subroutine, Section 13.4.1.21 (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. expression. The value returned 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*(*) 10 J = LEN(S) DO 10 I=1,J/2 T = S(I:I) S(I:I) = S(J:J) S(J:J) = T J = J - 1 CONTINUE RETURN END 2. INDEX The INDEX function searches for a substring (arg2) in a specified character string (argl), 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 argl, 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 specifying substring that is searched for. 13-12 the FUNCTIONS AND SUBROUTINES The following example illustrates the INDEX function: C C C C This subroutine places the symbol i 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 I = 1 MARKS 10 91 3. , , J = INDEX(S(I:), SUB) IF (J • NE. 0) THEN I = 1 + J MARKS(I-l:I-l) = 'i' IF (I .LE. LEN(S)) GO TO 10 END IF 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: CHAR(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 (arg1.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-10/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 13.1.4 Bit Manipulation Functions Intrinsic bit manipulation functions are used for manipulation of the bits in the binary patterns that represent integers. Integer data types are represented internally in binary two's complement notation. Bit positions in the binary representation are numbered from right (least significant bit) to left (most significant bit); the rightmost bit position is numbered 0, and the leftmost bit position is numbered 35. A bit in a binary pattern has a value of 0 or 1. The intrinsic functions lAND, lOR, lEaR, and NOT perform bitwise operations on all the bits of their arguments. Bit of the result is the result of applying the specified logical operation to bit of the arguments. Bit I of the result is the result of applying the specified logical operation to bit 1 of the arguments, and so on for all the bits of the result. ° ° The shift functions ISHFT and ISHFTC shift binary patterns. A positive shift count indicates a left shift, while a negative shift count indicates a right shift. A shift count of zero means no shift. ISHFT specifies a logical shift; bits shifted out of one ~nd are lost and zeros are shifted in at the other end. ISHFTC perform~ a circular shift; bits shifted out at one end are shifted back in at the other end. 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 bit field must be entirely contained in its source operand. For example, the integer 79 is represented pattern: by the following binary 0 ••• 0101111 n ••• 6543210 (bit position) where: n is 35 (the number of 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 pattern would be the following: 0 ••• 000101 Negative integers are represented in two's complement notation. integer -79 is represented by the following binary pattern: The 1 ••• 1010001 n ••• 6543210 (bit position) where: n is 35 (the number of bit positions in an integer). NOTE The value of bit position 35 is 1 for a negative all the number and 0 for a non-negative. Also, high-order bits of the pattern to the left of the value up to bit 35 are the same as bit 35. IBITS and MVBITS operate on bit fields. Both the starting position of a bit field and its length are 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 to 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 profit for a product. In the statement function definition, PROFIT is defined as the difference between wholesale and retail prices minus .05 sales tax. PROGRAM STAFUN PROFIT (A,B) = ((A - B) 100 (A * .05» WRITE(UNIT=5,FMT=100) FORMAT(lX,'Enter Wholesale Price and Retail Price') ACCEPT*,WHOSAL,RETAIL 150 C = PROFIT (RETAIL,WHOSAL) 101 WRITE(UNIT=5,FMT=101) C FORMAT(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 WHOSAL to calculate the profit as defined in the PROFIT statement function. A sample execution of this program yields the following results: EXECUTE STATE LINK: Loading [LINKXCT STAFUN execution] 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 1383) 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 Section 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, including 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. 13.3.1 FORTRAN-Supplied External Functions FORTRAN-supplied external functions are similar to intrinsic functions. To use a FORTRAN-supplied function, you reference its name in 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 DTOGA subroutine, Section 13.4.1.12.) x=GTOD (y) returns a D-floating double-precision number in the range 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 set) • It also returns -1 if the file 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 O.LT.x.LT.l. The argument is a dummy (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 deviates. Refer to related subroutins SETRAN (see Section 12.4.1.27) and SAVRAN (see Section 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 single-precision, floating-point argument. The argument y is set equal to the time in seconds since midnight, minus the user-supplied value of x. x=TIM2GO(O) returns the number of seconds remaining in the job's run-time limit. The time l~mit is set by the /TIME switch when submitting the batch job. The argument is a dummy (not used) and may be any number. You may also specify a time limit for an interactive job by using the SET TIME-LIMIT command on TOPS-20, or the SET TIME command on TOPS-lO. FORTRAN-supplied external functions are treated in the same manner as user-defined functions. Implicit or explicit type declarations affect these functions, and no argument checking (type or number) 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 ([argl 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. If you do not specify a type, the type of the function subprogram name determines the data type of the external function. fun is the symbolic name of the external 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 Restrictions The following rules govern the structuring of a function subprogram: 1. You can not use the symbolic name of a function subprogram in any nonexecutable statement in the subprogram except in the initial FUNCTION statement or a type statement. 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 procedure 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 function subprogram is of type character, each entry name in 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 subprogram in an expression. Function subprograms are referenced in expressions using the following form: fun ([argl,arg2, ••• 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 units that user-defined described in described in subprogram is a procedure that is external to the program reference it. FORTRAN offers two types of subroutines: and FORTRAN-supplied. FORTRAN-supplied subroutines are Sections 13.4.1 - 13.4.1.32; user-defined subroutines are 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 general FORTRAN subroutines; Appendix F describes the subroutines 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 Table 13-2: FORTRAN-Supplied Subroutines Form Function Section CALL ALCCHR(size) Allocates space for dynamic character concatenation operations. 13.4.1.1 dpres = CDABS(dparg) Returns the double-precision absolute value of the specified double-precision complex number. 13.4.1.2 CALL CDCOS(dparg,dpres) Finds the complex cosine of the specified double-precision complex number. 13.4.1.3 CALL CDEXP(dparg,dpres) Finds the complex exponential of the specified double-precision complex number. 13.4.1.4 CALL CDLOG(dparg,dpres) Returns the complex logarithm of a specified double-precision complex number. 13.4.1.5 CALL CDSIN(dparg,dpres) Returns the complex sine of the doubleprecision complex number specified. 13.4.1.6 CALL CDSQRT(dparg,dpres) Returns the complex square root of the double precision complex number specified. 13.4.1.7 CALL CHKDIV(unitvar) Returns the number of the unit to which error messages are being written. 13.4.1.8 CALL CLRFMT(arrayname) Discards the FORMAT statement saved by the execution of the SAVFMT subroutine. 13.4.1.9 CALL DATE(name) Places the current data, left-justified, in a character variable. 13.4.1.10 CALL DIVERT(un) Enables you to redirect error messages from the current device to an open file on a specified device. 13.4.1.11 CALL DTOGA(sname,dname,n) Converts elements of double-precision arrays from D--floating double-precision format to G-floating double-precision format. 13.4.1.12 CALL DUMP(LB1,UB1,formatl Causes specified portions of memory to be dumped to the line printer (LPT:). 13.4.1.13 CALL ERRSET(n) CALL ERRSET(n,1) CALL ERRSET(n,1,subr) Controls the output of arithmetic error messages during program execution. 13.4.1.14 CALL ERRSNS(l) CALL ERRSNSO,J) CALL ERRSNS(l,J,MSG) Determines the reason for an error trapped by ERR = on an OPEN, CLOSE, or data transfer operation. 13.4.1.15 CALL EXIT Terminates the program and returns control to the monitor. 13.4.1.16 CALL FFUNIT Returns the number of the first available FORTRAN logical unit. 13.4.1.17 CALL GTODA(sname,dname,n) Converts elements of double-precision arrays from G-floating double-precision format to D-floating double-precision format. 13.4.1.18 CALL ILL Sets the ILLEG flag. 13.4.1.19 CALL LEGAL Clears the ILLEG flag. 13.4.1.20 CALL MVBITS(m,l,len,n,j) Transfers a bit field from one storage location to a second storage location. 13.4.1.21 CALL OVERFUIANS) Returns information about overflow, underflow, and divide check. 13.4.1.22 CALL PDUMP(LB1,UB1,formatl Functions exactly like DUMP subroutine except that control returns to the calling program after the dump has been executed. 13.4.1.23 1... ,LBn,UBn,formatn1) QUIETX Suppresses all summary type out when the pro- 13.4.1.24 I ... ,LBn, UBn,formatn 1) gram L-_ _ _ _ _ _ _ _ _ _ _L -_ _terminates. _ _ _ _ _ _ _ _ _ _ _ _ _--JL..-_ _ _.___ .. _. 13-23 FUNCTIONS AND SUBROUTINES Table 13-2: FORTRAN-Supplied Subroutines (Cont.) .-------'--------,,-------------,._------------'-.--------.. Section Function Form CALL SA VFMT(namel ,arraysize j) Directs FOROTS to encode format specifications contained in the specified character variable or array. 13.4.1.25 CALL SAVRAN(n) Saves the last internal integer seed value generated by the RAN function. 13.4.1.26 CALL SETRAN(n) Specifies the internal integer seed value for the RAN function, 13.4.1.27 CALL SORT('sort string') Sorts one or more files using the SORT program, 13.4.1.28 CALL SRTINHn) Directs FOROTS to start allocating memory from top downward to account for large overlay programs and preallocates pages 600:677 for SORT. 13.4.1.29 CALL TIME(x} CALL TIME(x,y) Returns the current time of day in left-justified ASCII. 13.4.1.30 CALL TOPMEM(n) Directs FOROTS to start allocating memory from top downward to account for large overlay programs. 13.4.1.31 CALL TRACE Generates a list of active subprograms on the terminal. 13.4.1.32 13.4.1 FORTRAN-Supplied Subroutines The FORTRAN software includes a set of predefined subroutines. This section describes the general FORTRAN subroutines (and a function that is similar) in alphabetical order. (See Appendix F for the FORTRAN-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. ALCCHR Subroutine 13.4.1.1 ALCCHR Subroutine - The ALCCHR subroutine allocates space for dynamic character concatenation operations. You do not normally 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. either creating COABS Function Function - The COABS function returns the 13.4.1.2 COABS double-precision absolute value of the specified double-precision (Although COABS is a function and is not a complex number. subroutine, it is included here because it is similar to some subroutines.) The form of the CDABS function is: dpres = COABS(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 COCOS Subroutine 13.4.1.3 COCOS Subroutine - The COCOS subroutine finds cosine of the specified double-precision complex number. the complex The form of the COCOS subroutine is: CALL COCOS(dparg,dpres) where: dparg is a 2-element double-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 imaginary 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 (1,-1) dparg(2) = -IDa CALL CDCOS(dparg,dpres) COEXP 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 COEXP subroutine is: CALL CDEXP(dparg,dpres) where: dparg 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) = 000 dparg(2) = 100 !arg is (0,1) CALL CDEXP(dparg,dpres) COLOG Subroutine 13.4.1.5 COLOG Subroutine - The COLOG subroutine returns the logarithm of a specified double-precision complex number. 13-26 complex FUNCTIONS AND SUBROUTINES The form of the CDLOG subroutine 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 calculated. The first element of dparg contains the real part of the complex number; the second element contains the imaginary part. dpres is a 2-element double-precision array that stores the result returned by CDLOG. 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) = 100 !arg is (1,0) dparg(2) = 000 CALL CDLOG(dparg,dpres) CDSIN~ Subroutine 1 - -_ _ _ _ __ 13.4.1.6 CDSIN Subroutine - The CDSIN subroutine returns the sine of the double-precision complex number specified. complex The form of the CDSIN subroutine 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 imaginary part. dpres is a 2-element double-precision array in which the result of the calculation is returned. The first element of dpres contains the real part of the result; the second element contains the imaginary part. Example: DOUBLE PRECISION dparg(2) ,dpres(2) dparg(l) = -lDO !arg is (-1,01) dparg(2) = IDa CALL CDSIN(dparg,dpres) 13-27 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 double-precision complex number whose square root 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 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. Example: DOUBLE PRECISION dparg(2) ,dpres(2) dparg(l) = 1000 dpres(2) = -1000 !arg is (10,-10) CALL CDSQRT(dparg,dpres) CHKDIV Subroutine 13.4.1.8 CHKDIV Subroutine - The CHKDIV subroutine returns the number of the unit to which error messages are being written. This subroutine returns the value -1 if the messages are being sent to the terminal. The form of the CHKDIV subroutine is: CALL CHKDIV(unitvar) where: unitvar is the variable in which the unit number is stored. 13-28 FUNCTIONS AND SUBROUTINES 13.4.1.9 CLRFMT Subroutine - The CLRFMT subroutine discards the encoded form of the FORMAT statement saved by the execution of the SAVFMT subroutine (see Section 13.4.1.25). The form of the CLRFMT subroutine is: CALL CLRFMT(arrayname) where: is the name of the array that contains the encoded form of the FORMAT specifications saved by the SAVFMT subroutine. arrayname 13.4.1.10 DATE Subroutine - The DATE subroutine stores the current date as a left-justified ASCII string in a character variable. The date is in the form: dd-mmm-yyb where: dd is a 2-digit day (if the first digit is 0, it is converted to a blank), mmm is a 3-letter month abbreviation (such as, Jan,Feb) , yy is a 2-letter year, and b is a blank. The data is stored in ASCII, left-justified, and blank filled. The form of the DATE subroutine is: CALL DATE(name) where: name is the name of a character variable. The date returned by the subroutine is stored in this variable. NOTE For compatibility with previous versions of FORTRAN-IO/20, you can specify a numeric array name as the argument for the DATE subroutine. The current date is stored as a left-justified ASCII string in a 2-word array or data item (double-precision or complex). The array must 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. DTOGA Subroutine the open 1 ' - - - - - - - 13.4.1.12 DTOGA - The DTOGA subroutine converts elements of double-precision arrays fromD-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 causes portions of memory to be dumped to the line printer (LPT:). 13-30 specified FUNCTIONS AND SUBROUTINES The form of the DUMP subroutine is: CALL DUMP(LBl,UBl,formatl[ ••• ,LBn,UBn,formatn]) where: LBl,UBl are the integer values of the upper addresses to be dumped. and lower formatl is an integer that indicates possible specifications are: dump format. a 1 2 3 the memory The octal real integer ASCII 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 is specified, all locations from that address to the end of memory are dumped. The dump is terminated by a call to EXIT. ERRSET Subroutine 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 messages to type. i is the code to which error the call applies; one of the following: -1 a 1 2 3 4 5 6 7 8 any of the following integer overflow integer divide input integer overflow input floating overflow floating overflow floating divide check floating underflow input floating underflow library routine error 13-31 FUNCTIONS AND SUBROUTINES 9 21 22 23 if i subr output field width too small FORLIB warnings nonstandard usage warnings Bounds check warnings is not specified, -1 is assumed is the name of the user-defined error handling routine to be invoked each time any of the above errors occur. The effect is as if 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 code 9 is N2 = second error number (reserved for Digital) = data type of value UNFIXD = value returned by the hardware ITYPE FIXED = value after fixup val ue) (SUBR can change If SUBR is not specified, no routine is called the APR trap. this on ERRSNS Subroutine 13.4.1.15 ERRSNS Subroutine - The ERRSNS subroutine returns integer values that describe the status (success or failure) of the last I/O operation (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 forms of the ERRSNS subroutine are: CALL ERRSNS (I) or CALL ERRSNS (I,J) or CALL ERRSNS FORTRAN-10/20 VII (I,J,MSG,K) 13-32 February 1987 FUNCTIONS AND SUBROUTINES where: I returns a FORTRAN-supplied number class of failure that occurred. that describes the J optionally returns further describes error. MSG If present, is a character variable used to return the ASCII text of the last error message. If the variable for MSG is less than 80 characters, the text is truncated; if the variable is greater than 80 characters, the text is padded to the right with blanks. a processor-specific number that or qualifies the type of the last NOTE For compatibility with previous versions of FORTRAN-10/20 , you can specify a numeric array as the MSG argument. The numeric array is used as a l6-word array to return the ASCII text of the last error message. K optionally returns the RMS STV code that reason for the last RMS error. explains the EXIT Subroutine 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 subroutine is: CALL EXIT FFUNIT Subroutine 13.4.1.17 FFUNIT Subroutine - The FFUNIT subroutine returns lowest available FORTRAN logical unit number (see Table 10-3). the The form of the FFUNIT subroutine is: CALL FFUNIT (n) FORTRAN-10/20 VII 13-33 February 1987 FUNCTIONS AND SUBROUTINES GTODA Subroutine 13.4.1.18 GTODA Subroutine - The GTODA subroutine converts elements of double-precision arrays from G-f1oating double-precision format to D-f1oating double-precision format. The form of the GTODA subroutine is: CALL GTODA(sname,dname,n) where: sname is the source array name. dname is the destination array name. n is the number of array elements to convert. (See Section 13.4.1.12 for the DTOGA subroutine.) ILL Subroutine 13.4.1.19 ILL Subroutine - The ILL subroutine sets the ILLEG flag. If this flag is set and an illegal character is encountered in floating-point, double-precision input, the corr~sponding value is set to zero and no error message is issued. The ILL subroutine takes no arguments. The ILLEG flag is not set initially. The form of the ILL subroutine is: CALL ILL LEGAL Subroutine' ILLEG 13.4.1.20 LEGAL Subroutine - The LEGAL subroutine clears the flag set by the ILL subroutine. The LEGAL subroutine takes no arguments. The form of the LEGAL subroutine is: CALL LEGAL 13-34 FUNCTIONS AND SUBROUTINES MVBITS Subroutine 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 MVBITS subroutine is: CALL MVBITS(m,i,len,n,j) where: m is an integer expression that represents the source location from which a bit field is transferred. i is an integer expression that identifies the position in the source field transferred from m. first len is an integer expression that identifies the length field transferred from m. of bit the n is an integer variable 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 destination field transferred from m. bit The MVBITS subroutine transfers len bits from position i through i+1en-l of the source location (m) to positions j through j+1en-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+1en and j+1en must not be greater than 36. (See Section 13.1.4 for information on bit manipulation functions.) ~_____O_V_E_R_F_L________] ~ Subroutine 13.4.1.22 OVERFL Subroutine - The OVERFL subroutine information about overflow, underflow, and divide check. The form of the OVERFL subroutine is: CALL OVERFL(IANS) 13-35 returns FUNCTIONS AND SUBROUTINES where: fANS 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: 1 = at least one overflow, check occurred. 2 underflow, or divide none occurred. 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,UBl,formatl[ ••. ,LBn,UBn,formatn) where: LBl,UBl are the integer values of the upper addresses to be dumped. and lower formatl is an integer that indicates possible specifications are: dump format. o 1 2 3 the memory The octal real integer ASCII 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 is specified, all locations from that address to the end of memory are dumped. aUIETX Subroutine 13.4.1.24 QUIETX Subroutine - The QUIETX subroutine suppresses all summary typeout when the program terminates, including library error summaries and CPU times. The QUIETX subroutine takes no arguments. The form of the QUIETX subroutine is: CALL QUIETX 13-36 FUNCTIONS AND SUBROUTINES 13.4.1.25 SAVFMT Subroutine - The SAVFMT subroutine directs FOROTS to encode the FORMAT specifications contained in the specified character variable or array, and to save the encoded form. This action improves the performance of any future I/O 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 is executed for that variable or array. NOTE After a call to SAVFMT, you must not change the value of the variable or array. If the value is changed, the new value may be ignored. 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[,arraysize]) where: name is the name of the character variable or array that contains the FORMAT descriptors that you want encoded. arraysize is the number of array elements specified. if an array is NOTE For compatibility with previous versions of FORTRAN-IO/20, you can specify a numeric array name as the argument for the SAVFMT subroutine. ~ .. -----.'"--.---- _-_ - ... ... SAVRAN Subroutine 13.4.1.26 internal function, time it to SETRAN SAVRAN Subroutine - The SAVRAN subroutine saves the last integer seed value generated by the RAN function. The RAN described in Section 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 same 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 SETRAN(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 subroutine only if the SORT software has been installed (see the FORTRAN Installation Guide). The SORT software is sold as a separate pr-od-uc-E and may not be available 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 sort string must be compatible with the current version of the standalone SORT. Therefore, the string is not the same for TOPS-IO and TOPS-20 (see the SORT/MERGE User's Guide) • SRTINI ·-----l Subroutine 13.4.1.29 SRTINI Subroutine - The SRTINI subroutine directs FOROTS to start allocating memory from top downward to account for large overlay programs and preallocates pages ~OO:677 (octal) for SORT. The form of the SRTINI routine is: CALL SRTINI(n) where: n is top page number to use when allocating memory. Note that FOROTS will not allocate pages (including DDT pages) have been marked as unavailable at memory initialization. that TIME Subroutine 13.4.1.30 TIME Subroutine - The TIME subroutine returns time of day in left-justified ASCII. the current The TIME subroutine has two forms: CALL TIME(x) or CALL TIME(x,y) where: x is a character variable. In the one argument form, TIME returns the time in x in the form: hh:mm, where hh is the hour (24-hour time) and mm is the minutes. 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 argument form, and the value returned in y has the form: bss.t, where b is a blank, S5 is the current seconds, and t is the current tenths of seconds. 13-39 FUNCTIONS AND SUBROUTINES NOTE 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) L02 WRITE (UNIT=5, FMT=102)X FORMAT(lX,'THE ONE ARGUMENT TIME RETURNS: ',A) END 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 --] TOPMEM Subroutine 13.4.1.31 TOPMEM Subroutine - The TOPMEM subroutine 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 pages (including DDT pages) have been marked as unavailable at memory initialization. 13-40 that FUNCTIONS AND SUBROUTINES TRACE Subroutine ------_..__._------- j 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 listing starts at the currently active routine (the one containing the call to TRACE) and proceeds back to the main program. The form of the TRACE subroutine is: CALL TRACE The information produced by the TRACE routine consists subprogram: of, 1. The name of the routine 2. The address of the routine (in octal) 3. The address of the subprogram call + offset) 4. The address of the subprogram call offset with the calling routine) 5. The number of arguments passed to the called routine 6. The types of the arguments passed including: for each (expressed as routine-name (expressed as label + C D F G I K L - Character string descriptor D-floating double precision Real G-floating double precision Integer or double integer Literal string Logical a - Octal or double octal S - Statement label U - Unknown argument type X - Complex If there are too many arguments to display, the contain ' ••• ' . 'types' column will If local symbols are loaded with the program, the label+offset information will be much more informative. A label of the form 12345P refers to FORTRAN statement number 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. You 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 8UB1:') CALL 5UB1 TYPE 20 FORMAT (I' Calling 5UB2:') CALL 5UB2 (A,B) END SUBROUTINE SUB1 Y = F(X) END SUBROUTINE 5UB2 (G,H) CALL 5UB3 (G,H,I) END SUBROUTINE 5UB3 CALL TRACE END (Al,A2,A3) FUNCTION F(Y) CALL 5UB2 (Y,O) F=2. END EXECUTE TRC.FOR Load ing LINK: (LNKXCT TRC execut ion] Calling 5UB1: Name TRACE. SUB3 5UB2 F 8UB1 (Loc) (426373) (256 ) (232) (307) (214) «--«--«--«--«--«--- Caller 5UB3+2 5UB2+6 F+20 5UB1+2 MAIN.+7 (Loc) (5UB3+2) (5U82+6) (F+20) (5U8l+2) (MAIN.+7) Args 0 3 2 1 0 Types «--«--«--«--- Caller 5UB3+2 5UB2+6 MAIN.+14 (Loc) (5U83+2) (8U82+6) (MAIN.+14) Args Types 3 FFI FF FFI FI F Calling 8UB2: Name TRACE. 5UB3 SUB2 ( Loc) (426373) (256 ) (232) CPU time 0.4 13.4.2 o 2 Elapsed time 3.1 User-Defined Subroutines A subroutine subprogram is a separate ptogram 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.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 you 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: CAL L sub [( [a 1 [ , a 2] ••• ] ) ] 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 procedure 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: ENTRY en [(dl [,d2 ••• ])] 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. affect the 5. You can not use an ENTRY statement in a main program or a subprogram reference itself through its entry points. have 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 range by use of 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. prog ram un i t 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 RETURN statement in a function subprogram is: RETURN The form of the RETURN statement in a subroutine subprogram is: RETURN [e] where: e is an integer constant, variable, or expression. This form of the RETURN statement is called an alternate return. The alternate return form enables you to select any labeled statement in the calling program unit as a return point after execution of the program unit in which the alternate RETURN statement appears. The value of e should be a positive integer that is equal to or less than the number of statement labels given in the argument list of the calling statement. If e is less than 1 or is larger than the 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 prog ram un it) • NOTE A dummy argument for a statement 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(I,*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 a stahdard return to the GO 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 Arguments Since you may reference subprograms at more than one point throughout a program, many of the values used by the subprogram may be changed each time it is used. Dummy arguments in subprograms represent the actual values to be used, which are passed to the subprogram when it is called. For example, shown belaw is a subroutine (TEST) being called from the maln 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 statement. 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. NOTE 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 associated actual argument. This is known as a passed length character argument. 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 variable, array element, substring, or expression. A character array dummy argument 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 to 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 (CVAR) IF (CVAR(I:I) .GT. CVAR(ICMAX:ICMAX» RETURN END ICMAX =1 Each of the following function references specifies a different length for the dummy argument: CHARACTER VAR*lO, CARRAY(3,5)*20 II 12 13 14 15 ICMAX (VAR) ICMAX(CARRAY(2,2» ICMAX(VAR(3:8» ICMAX(CARRAY (1,3) (5:15» ICMAX (VAR(3:4)//CARRAY(3,5» 13.4.5.2 Character and Hollerith Constants as Actual ArgumentsActual arguments and their corresponding dummy arguments must agree in data type. If the actual argument is a Hollerith constant (for example, 4HABCD) , the dummy argument must be of numeric data type. In FORTRAN-IO/20, if an actual argument is a character constant (for example 'ABCD'), the corresponding dummy argument can have either numeric or character data type. If the dummy argument has a numeric data type, the character constant 'ABCO' is, in effect, converted to a Hollerith constant by the FORTRAN 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 character constant or Hollerith constant is required. In this case, a character constant actual argument can correspond only to a character dummy argument. 13-51 CHAPTER 14 BLOCK DATA SUBPROGRAMS Block data subprograms provide initial values for variables and elements in named common blocks. array A block data subprogram must start with the BLOCK DATA statement. The only valid statements within a block data subprogram are the specification and DATA statements (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 into 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 statement 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/l.,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 fail. To increase the accuracy of its cO~Rile-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-10 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.2.1 Remote Links - A remote network link is established each time an OPEN statement or INQUIRE-by-file for a remote file is performed. The link remains open until the file is closed or the INQUIRE statement completes. The maximum number of simultaneous open links available to a user process is a site-dependent monitor parameter. 15.1.2.2 Reducing Network Overhead - A substantial part of the overhead associated with 'remote file access consists in establishing the remote link. Since a READ, READ, WRITE sequence for a file opened for read access causes FOROTS to close and reopen the file for read/write access, network overhead can be reduced by ensuring that remotes files to be written to are opened with an ACCESS specifying both read and write access. Likewise, file specifications in CLOSE statements for remote files, which cause FOROTS to establish a link for a network rename operation, should not be routinely used unless a full remote rename is required. 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. FORTRAN-10/20 VII 15-2 February 1987 WRITING USER PROGRAMS 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 formula for 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) ,O) 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-10/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.1 February 1987 WRITING USER PROGRAMS This page intentionally left blank. 15-2.2 February 1987 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 arguments 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, when you pass character data to a subroutine or function that is compiled with the /EXTEND 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 the 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 argument 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.S) 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.S in memory. The proper method is to use: Fl(2.SDO) lS.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*RLl will not produce an overflow when evaluated left to right, since the first computation in each expression (that is, RS1*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 lS.2.1.l) and generate the following sequence: temp A B RLl*RL2 RSl*temp RS2*temp The computation of temp will cause an overflow. You should write the program as follows to results are obtained: ensure that the desired A=(RSl*RLl)*RL2 B=(RS2*RL2)*RLI Computations may be reordered even when selected. lS-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 (10) READ (1) ARRAY The above is a binary read that ARRAY. will read ten words into SUBROUTINE SUBl(A) DIMENSION A (1) 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 wo~ld 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 I=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 happen since programmers do not normally include such code in their programs; however, inaccessible code may appear in a program during the debugging process. The removal of inaccessible code by the optimizer 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 performance 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 15.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. 5. Avoid unnecessary use of COMMON and EQUIVALENCE. 15.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=5. 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. 15.4 INTERACTING WITH NON-FORTRAN PROGRAMS AND FILES 15.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. 15-10 WRITING USER PROGRAMS 3. 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 address of the first argument in the argument list. b. The subroutine is 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 by a PUSHJ instruction instruction immediately calling sequence XMOVEI 16,AP PUSHJ 17,F where AP is the pointer 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 read by the called subprogram. c. FOROTS assumes that it has control of the stack; therefore, you must not create your own stack. The FOROTS stack is initialized by 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 section zero, its right half points to the last location in use on the stack, and its left half contains the negative of the number of words allocated to the unused remainder of the stack. 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 0 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 0 (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 word) : 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 should 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: iSET UP ARG POINTER iCALL SUBROUTINE iRETURN HERE iARGUMENT LIST -3,,0 IFIW 4,A IFIW 4,B IFIW 4,C iSUBROUTINE TO SET THIRD ARG TO SUM OF FIRST TWO ARGS SUB: MOVE ADD MOVEM POPJ T,@0(16) T,@1(16} T,@2(16} 17, 15-13 iGET FIRST ARG iADD SECOND ARG iSET THIRD ARG iRETURN TO CALLER WRITING USER PROGRAMS 15.4.5 Argument Types Table 15-1: Argument Types and Types Codes Type Code (Octal) Description FORTRAN Use 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 COBOL Use Unspecified Not applicable I-word CaMP Reserved COMP-l Reserved Reserved Procedure address Not applicable 2-word CaMP 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 procedure address The address of the parameter is the address of return label or a subprogram. 7. represented in Type 11 - 2-word COMP A 2-word (72-bit) word word word word 9. alternate Type 10 - Double real (D-floating) A double-precision floating-point number D-floating form. (See Section 3.4.) 8. an Type 12 1, 1, 2, 2, 2's complement signed binary integer. bit 0 bits 1-35 bit 0 bits 1-35 sign high order same as word 1, bit 0 low order - Double octal A 72-bit unsigned binary value. 10. Type 13 - Double real (G-floating) (KL model B only) A double-precision floating-point number G-floating form. (See Section 3.4.) 11. represented in Type 14 - Complex A complex number represented as an ordered pair of 36-bit floating-point numbers. The first represents the real part, and the second represents the imaginary part. 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 COBOL verb ENTER is used to call FORTRAN subroutines. The form of ENTER is as follows: ENTER FORTRAN program name~SING identifier-l } literal-l { procedure-name-l [ ' { i~entifier-2}J Ilteral-2 ••• procedure-2 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 0. Each entry in the list is one 36-bit word of the form: 0-8 9-12 0 type 13-35 Effective address (E) where: type is a 4-bit code that indicates the USAGE of the argument, and bits 13-35 contain the effective address (E) of the first word of the argument. FORTRAN-10/20 VII 15-16 February 1987 WRITING USER PROGRAMS If the passed argument is a I-word COMP item, the type code is 2 and E is the location of the argument. If the passed argument is a 2-word COMP item, the type code is 11 (octal) and E is the location of the first word of the argument; the second word of the argument is at E+l. If the passed argument is a COMP-l item, the code is 4 and location of the argument. E is the if the passed argument is a COMP-2 item, the code is 10 (octal) and E is the location of the first word of the argument; the second word of the argument is at E+l. If the passed argument is a DISPLAY-6, DISPLAY-7, DISPLAY-9, or COMP-3 item, the code is 15 (octal) and E is the location of a 2-word descriptor for the argument. The first word of the descriptor is a byte pointer word pointing to the argument. Its byte-size is 6 for DISPLAY-6, 7 for DISPLAY-7, and 9 for DISPLAY-9 or COMP-3. The second word of the descriptor is of the form: Bit 0 Reserved Bit 1-4 Type code: 1= DISPLAY-6 2= DISPLAY-7 3= DISPLAY-9 4= COMP-3 Bit 5 Item is a literal Bit 6 Item is a figurative constant (such as SPACES) Bit 7 Item is numeric if bit 7 0; Bit 8-11 Reserved Bit 12-35 Size of item in bytes If bit 7 1; Bit 8 Item is signed Bit 9 Item is scaled (such as PICTURE contains "PiS" to left of implied decimal point, for example, 999PP) Bit 10 Item is numeric edited If bit 9 = 0; Bits 11-25 Reserved Bits 26-30 Number of decimal places Bits 31-35 Size of item in bytes If bit 9 Bits 11-25 FORTRAN-10/20 VII 1; Reserved 15-17 February 1987 WRITING USER PROGRAMS Bits 26-30 Scale factor (such as, 2 if picture was 999PP) Bits 31-35 Size of item in bytes (such as, 3 if picture was 999PP) 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. NOTE COBOL l2C subroutines called from FORTRAN programs must be compiled with the /R COBOL switch to prevent an undefined global error at LINK time. 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 BLTSS-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. FORTRAN-10/20 VII 15-18 February 1987 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 function). 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. In general, the BLISS routines must be compiled with ADDRESSING MODE (INDIRECT) , or MACHOP calls must be used to generate FORTRAN arguments any instruction that references formals since all This must be done must be accessed through indirect addressing. indirect bit in because the FORTRAN compiler frequently sets the argument lists (see Section 15.4.4). See the BLISS-36 Language Guide 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 when TOPS-20 extended addressing is used. In addition, the overlay handler does not support programs using long symbols (symbols longer than six characters). The following terms are overlay routines. to LINK File spec A character expression consisting 'dev:file.ext[directory]' (TOPS-10), '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. FORTRAN-10/20 VII used to describe 15-19 the parameters February 1987 WRITING USER PROGRAMS The routines available are: CLROVL Specifies a non-writable overlay. GETOVL(List of link names) Used to change 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 Reserved for SORT, DBMS, and DDT 600 FOROTS FOROTS Static Data 500 -1- - - - - -FOROTS Dynamic Data -1- - - - --- Used for 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 manager 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. The /SPACE switch to LINK determines the maximum size for such "dynamic concatenations" if overlays are used. The default value (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 ( de fa u 1 t 10, aaa wo r d s). ( See Sec t ion 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. (by default) Variables EQUIVALENCED to large arrays Lowseg .LARG. PDV N/A .DATA. (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 WRITING USER PROGRAMS lS.S USING INDEXED FILES (TOPS-2~ ONLY) Traditionally, sequential and direct access have been the only file access modes available to FORTRAN programs. To overcome some of the limitations of these access modes', FORTRAN-20 supports a third access mode, called keyed access (see Section 10.2.3). Keyed access allows you to retrieve records, at random or in sequence, based on key fields that are established when you create a file with indexed organization. You can access files with indexed organization using either sequential or keyed access, or a combination of both. 1. Keyed access retrieves records randomly bas~d on particular key fields and key values that you specify. 2. Sequential access retrieves records in an ascending sequence based on the values within the particular key field that you specify. the The combination of keyed and sequential access is commonly referred to as the Indexed Sequential Access Method (ISAM). Once you have read a record by means of an indexed read request, you can then use a sequential read request to retrieve records with ascending key field values, beginning with the key field value in the record retrieved by the initial read request. Indexed organization is especially suitable for maintaining complex files in which you want to select records based on one of several criteria. For example, a mail-order firm could use an indexed organization file to store its customer list. Key fields could be a unique customer order number, the customer's zip code, and the item ordered. Reading sequentially based on the zip code key would enable you to produce a mailing list sorted by zip code. A similar operation based on customer order number or item number key would enable you to list the records in customer order number or item number sequence. The remainder of this section provides information topics: on the following • Creating an indexed file (Section IS.S.l) • Writing records to an indexed file (Section IS.S.2) • Reading records from an indexed file (Section IS.S.3) • Updating records in an indexed file (Section IS.S.4) • Deleting records from an indexed file (Section lS.S.5) Information is also ~rovided about the effects of read and write operations on positioning your program to records within an indexed file (Section 15.5.6) and about how to build logic into your program to handle exception conditions that commonly occur (Section 15.5.7). lS.5.l Creating an Indexed File You can create a file with an indexed organization by using either the FORTRAN OPEN statement or the RMSUTL utility. FORTRAN-10/20 VII 15-24 February 1987 WRITING USER PROGRAMS • Use the OPEN statement to specify the file options by FORTRAN. supported • Use the RMSUTL utility supported by FORTRAN. directly to select features not When you create an indexed file, you define certain fields within each record key fields. One of these key fields, called the primary key, is identified as key number zero and must be present in every record. Additional keys, called alternate keys, can also be defined; they are numbered from 1 through a maximum of 254. An indexed file can have as many as 255 key fields defined. In practice, however, few applications require more than 3 or 4 key fields. The data types CHARACTER. used for key fields must be either INTEGER or In designing an indexed file, you must decide the byte positions of the key fields. For example, in creating an indexed file for use by a mail-order firm, you might define a file record to consist of the following fields: INTEGER ORDER NUMBER CHARACTER*20 NAME CHARACTER*20 ADDRESS CHARACTER*19 CITY CHARACTER*2 STATE CHARACTER*9 ZIPCODE INTEGER ITEM NUMBER positions positions positions positions positions positions positions Given this record definition, you statement to create an indexed file: 1:4, key 0 5:24 25:44 45:63 64:65 66:74, key 1 75:76, key 2 could use the following OPEN (UNIT~l,FILE='CUSTOMER.DAT',STATUS='NEW' , 1 ORGANIZATION=' INDEXED' ,ACCESS='KEYED', RECORDTYPE='VARIABLE' ,FORM='UNFORMATTED', RECL=19, KEY=(1:4:INTEGER, 66:74:CHARACTER, 75:76:INTEGER) , IOSTAT=IOS, ERR=9999) 2 3 4 5 OPEN This OPEN statement establishes the attributes of the file, including the definition of a primary key and two alternate keys. The data type size is determined by the number of character positions allotted to the key fields, which in this case are 4 and 2 character positions, respectively. If you specify the KEY= specifier (see Section 11.3.21) when opening an existing file, the key specification that you give is ignored. However, RMS does update the key XAB chain with key information from the file. (See Chapter 18 for more information on RMS data structures.) FORTRAN uses RMS default key attributes when creating an indexed file. These default are: • The values in primary key fields cannot be changed record is rewritten and cannot have duplicates. when • The values in alternate key fields can have duplicates. and FORTRAN-10/20 VII 15-25 be changed a can February 1987 WRITING USER PROGRAMS You can use the RMSUTL utility or a USEROPEN routine to override these defaults and to specify other values not supported by FORTRAN-20, such as null key field values, null key names, and key data types other than integer and character. See Section 18.9 for information on the use of the USEROPEN specifier in OPEN statements. The RMS-20 programmer's Reference Manual has more information on indexed file options. Use of the RMSUTL utility is explaind in the TOPS-20 RMS User's Guide. 15.5.2 Writing Indexed Files You can write records to an indexed file with either formatted or unformatted indexed WRITE statements (see Section 10.6.3). Each write operation inserts a new record into the file and updates the key index(es) so that the new record can be retrieved in a sequential order based on the values in the respective key fields. For example, you could add a new record to the file for the mail-order firm, described in Section 15.5.1, with the following ~tatement: WRITE (UNIT=1,IOSTAT=IOS,ERR=9999) The following two sections write operations: describe considerations that relate values in to • The effect of writing records with duplicate fields (Section 15.5.2.1) key • The method by which you can prevent an alternate key field in a record from being indexed during a write operation (Section 15.5.2.2) 15.5.2.1 Duplicate Values in Key Fields - It is possible to write two or more records with the same value in a single key field. The attributes specified for the file when it is created determine whether this duplication is allowed. By default, FORTRAN cr~ates files that allow duplicate alternate key field values and prohibit duplicate primary key field values. If duplicate key field values are present in a file, the records with equal values are retrieved on a first-in/first-out basis. For example, assume that five records are written to an in this order (for clarity, only key fields are shown): ORDER NUMBER ZIP CODE 1023 942 903 1348 1263 70856 02163 14853 44901 33032 FORTRAN-10/20 VII indexed file ITEM NUMBER 375 2736 375 1047 690 15-26 February 1987 WRITING USER PROGRAMS If the file is later opened and read sequentially by primary key (ORDER NUMBER), the order in which the records are retrieved is not affected by the duplicated value (375) in the ITEM NUMBER key field. In this case, the records would be retrieved in the following order: ORDER NUMBER ZIP CODE 903 942 1023 1263 1348 14853 02163 70856 33032 44901 ITEM NUMBER 375 2736 375 6~0 1047 However, if the read operation is based on the second alternate key (ITEM_NUMBER), the order is which the records are retrieved is affected by the duplicate key field value. In this case, the records would be retrieved in the following order: ORDER NUMBER ZIP CODE 1023 903 1263 1348 942 70856 14853 33032 44901 02163 ITEM NUMBER 375 375 690 1047 2736 Notice that the records containing the same key field value (375) retrieved in the order in which they were written to the file. are 15.5.2.2 preventing the Indexing of Alternate Key Fields - When writing to an indexed file that contains variable-length records, you can prevent entries from being added to the key indexes for any alternate key fields. This is done by omitting the names of the alternate key fields from the WRITE statement. The ommitted alternate key fields must be at the end of the record; another key field cannot be specified after the omitted key field. For example, assume that the last record (ORDER NUMBER 1263) mail-order example is written with the following statement: in the WRITE (UNIT=1,IOSTAT=IOS,ERR=9999) ORDER_NUMBER, 1 NAME, ADDRESS, CITY, 1 STATE, ZIP_CODE Because the field name ITEM NUMBER is omitted from the WRITE statement, an entry for that-key field is not created in the index. As a result, an attempt to read the file using the alternate key ITEM NUMBER would not retrieve the last record and would produce the following listing: ORDER NUMBER ZIP CODE 1023 903 1348 942 70856 14853 44901 02163 ITEM NUMBER 375 375 1047 2736 You can omit only trailing alternate keys from a record; key must always be present. FORTRAN-10/20 VII 15-27 the primary February 1987 WRITING USER PROGRAMS 15.5.3 Reading Indexed Files You can read records in an indexed file with either sequential or indexed READ statements (formatted or unformatted) under the keyed mode of access (see Section 10.5.3). By specifying ACCESS=' KEYED' in the OPEN statement (see Section 11.3.1), you enable both sequential and keyed access to the indexed file. Indexed READ statements position the file pointers (see Section 15.5.6) at a particular record, determined by the key field value, the key-of-reference, and the match criterion. Once you retrieve a particular record by an indexed READ statement, you can then use sequential access READ statements to retrieve records with increasing key field values. The form of the external record's key field must match the form of the value you specify in the KEY= specifier (see Section 11.3.21). Thus, if the key field contains character data, you should specify the KEY= specifier value as a CHARACTER data type. If the key field contains binary data, then the KEY= specifier value should be of INTEGER data type. Note that if you write a record to an indexed file with formatted I/O, the data type is converted from its internal representation to an external representation. As a result, the key value must be specified in the external form when you read the data back with an indexed read. Otherwise, a match will occur when you do not expect it. The following FORTRAN program segment prints ths order number and zip code of each record where the first five characters of the zip code are greater than or equal to '10000' but less than '50000': C C Read first record with ZIP CODE key greater than or equal to '10000'. READ (UNIT=1,KEYGE='10000' ,KEYID=1,IOSTAT=IOS,ERR=9999) 1 ORDER NUMBER, NAME, ADDRESS, 1 CITY,STATE,ZIP_CODE,ITEM_NUMBER C C While the zip code previously read is within range, print the order number and zip code, then the next record. DO WHILE (ZIP CODE .LT. '50000') PRINT *, "Order number' ,ORDER_NUMBER, 'has zip code', 1 ZIP CODE READ (UNI~=1,IOSTAT=IOS,END=200,ERR=9999) 1 ORDER NUMBER, NAME, ADDRESS 1 . CITY,-STATE, ZIP_CODE, ITEM_NUMBER C C 200 END= branch will be taken if there are no more records in the file. END DO CONTINUE The error branch on the keyed READ in this example is taken if no record is found with a zip code greater that or equal to '10000'; An attempt to access a nonexistent record is an error. If the sequential READ has accessed all records in the file, however, an end-of-file status occurs, just as with other file organizations. If you wish to detect a failure of the keyed READ, you can examine the I/O status variable (lOS) for the appropriate error number (see Table D-l for a list of the returned error codes). FORTRAN-10/20 VII 15-28 February 1987 WRITING USER PROGRAMS 15.5.4 Updating Records The REWRITE statement (see Section 10.14) updates existing records in an indexed file. You cannot replace an existing record simply by writing it again; a WRITE statement would attempt to add a new record. An update operation is accomplished in two steps. First, you must read the record in order to make it the current record. Next, you execute the REWRITE statement. For example, to update the record containing ORDER NUMBER 903 (see prior examples) so that the NAME field becomes 'Theodore Zinck', you might use the following FORTRAN code segment: READ (UNIT=1,KEY=903,KEYID=0,IOSTAT=IOS,ERR=9999) 1 ORDER NUMBER, NAME, ADDRESS, CITY, STATE, ZIP_CODE, 1 ITEM NUMBER NAME = 'Theodore Zinck' REWRITE (UNIT=1,IOSTAT=IOS,ERR=9999) When you rewrite a record, key fields may change. The attributes specified for the file when it was created determines whether this type of change is permitted. 15.5.5 Deleting Records To delete records from an indexed file, you use the DELETE statement (see Section 10.13). The DELETE and REWRITE statements are similar; a record must first be locked by a READ statement before it can be operated on. The following FORTRAN code segment deletes the second file with ITEM_NUMBER 375 (see previous examples): record in the READ (UNIT=1,KEY=375,KEYID=2,IOSTAT=IOS,ERR=9999) READ (UNIT=1,IOSTAT=IOS,ERR=9999) (IOLIST) IF (ITEM NUMBER .EQ. 375) THEN DELETE (UNIT=l, IOSTAT=IOS, ERR= 9999) ELSE PRINT *, 'There is no second record,' END IF Deletion removes a record from all defined indexes in the file. 15.5.6 Current Record and Next Record Pointers The RMS file system maintains two pointers into an open indexed the "next record" pointer and the "current record" pointer. • file: The next record pointer indicates the record to be retrieved by a sequential read. When you open an indexed file, the next record pointer indicates the record with the lowest primary key field value. Subsequent sequential read operations cause the next record pointer to be the one with the next higher value in the same key field. In case of duplicate key field values, records are retrieved in the order in which they were written. FORTRAN-10/20 VII 15-29 February 1987 WRITING USER PROGRAMS • 15.5.7 The current record pointer indicates the record most recently retrieved by a READ operation; it is the record that is locked from access by other programs sharing the file. The current record is the one operated on by the REWRITE statement and the DELETE statement. The current record is undefined until a read operation is performed on the file. Any file operation other than a read causes the current record pointer to become undefined. Also, an erior results if a rewrite or delete operation is performed when the current record pointer is undefined. Exception Conditions You can expect to encounter certain exception conditions when using indexed files. The two most common of these conditions involve valid attempts to read locked records and invalid attempts to create duplicate keys. Provisions for handling both of these situations should be included in a well-written program. When an indexed file is shared by several users, any ,read operation may result in a "record locked" error. One way to recover from this error condition is to ask if the user would like to reattempt the read. If the user's response is positive, then the program can go back to the READ statement. You should avoid simply looping back to the READ statement without first providing some type of delay (caused by a request to try again, or to discontinue). If your program reads a record but does not intend to modify the record, you should place an UNLOCK statement (see Section 10.15) immediately after the READ statement. This technique reduces the time that a record is locked and permits other programs to access the record. The second exception condition, creation of duplicate keys, occurs when your program tries to create a record with a key field value that is already in use. When duplicate key field values are not desirable, you might have your program prompt for a new key field value whenever an attempt is make to create a duplicate. FORTRAN-10/20 VII 15-30 February 1987 CHAPTER 16 USING THE FORTRAN COMPILER This chapter explains how to use the FORTRAN compiler. Section 16.1 describes using the FORTRAN-IO 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-IO 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-l 0 switches.) Example: .EXECUTE/CREF Pl.FOR,P2.FOR/DEBUG The other compiler switches must be passed specific source file. 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-I0 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 in the Switches to the FORTRAN-IO compiler are accepted anywhere command string. They are totally position and file independent. Table 16-1 lists the switches. 16-2 USING THE FORTRAN COMPILER Table 16-1: Switch FORTRAN-10 Compiler Switches Meaning Defaul 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 Section 3.4.) ON /EXPAND Includes the octal-formatted version of the object file in the listing. OFF /F66 The FORTRAN-66 standard rules apply for DO loops and EXTERNAL statements. (Same function as the /NOF77 switch.) OFF /F77 The FORTRAN-77 standard 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 /INCLUDE Compiles a D in card column 1 as space. OFF /LNMAP Produces a line number/octal location map in the listing only if /MACROCODE was not specified. OFF /MACROCODE Adds the mnemonic translation of the object code to the listing file. OFF /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 /F66 switch.) OFF /NOERRORS Does not print error messages on the terminal. OFF /NOWARN Suppresses warning messages (see Section 16.4). NONE /OPTIMIZE Performs global optimization. OFF /SYNTAX Performs syntax check only. OFF 16-3 flagger (see 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 MACRO S2FILE to appear in LFILE.LST. 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 enable 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 COMPILE-Class command: 16.2.3) can be /ABORT /BINARY /CROSS-REFERENCE /DEBUG /LIST /MACHINE-CODE /NOWARNINGS /OPTIMIZE /WARNINGS NOTE When you specify the switches /BINARY, /DEBUG, /LIST, and /NOWARNINGS directly in a COMPILE-Class command, the switches cannot have arguments as they can when running the compiler. All other switches must be 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 COMPILE-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: @FOR~RA 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. [COMPILE]<source-file-spec>+<source-file-spec>+ ••• [swi tches] The source files are treated 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 use 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 with the words EXIT, HELP, TAKE, or COMPILE. 3. TAKE <file-spec> [/ECHO] The compiler reads the file specified as the command input stream. The TAKE command is legal within 'take' files. The maximum nesting depth is 10 'take' files. The on can the 4. /ECHO switch optionally causes commands to be displayed TTY: as they are executed. The optional /NOECHO switch be used on a nested take command to cancel the affect of /ECHO switch while processing that nested command file. RUN <file-spec> [/OFFSET:<integer>] This command runs another program (for example, LINK). It causes an exit from the FORTRAN compiler and the start of execution of the program indicated by the file specification, with the additional option of starting that program at an OFFSET relative to the normal starting address. 5. HELP This command prints information 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 specifications consist of the following: An optional device name (the default device is DSK: ) An optional directory name An up to 39 alphanumeric character filename An optional up to 39 alphanumeric character file type An optional generation version of the file 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 generated. You can optionally specify the file specification. ON /CROSS-REFERENCE Generates a file with extension .CRF that can be input to the CREF program. OFF /DEBUG [keys: ] Includes debugging information in your program (see Section 16.3). NONE /DFLOATING Indicates that double-precision numbers are stored in D-floating format. (See Section 3.4.) ON /ECHO-OPTION Echo switches selected from the SWITCH.INI 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 Section 16.5). OFF /F66 The FORTRAN-66 standard rules apply for DO loops and EXTERNAL statements. (Same function as the /NOF77 switch.) OFF /F77 The FORTRAN-77 standard rules apply for DO loops and EXTERNAL statements. ON /FLAG-NON-STANDARD Invokes the compatibility flagger (see Section 16.6). OFF /GFLOATING Indicates that double-precision numbers are stored in G-floating format. (See 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 /LNMAP Produces a line number/octal location map in the listing only if /MACHINE-CODE was not specified. OFF /MACHINE-CODE Adds the mnemonic translation of the object code to the listing file. This command will cause a default /LISTING. OFF /NOBINARY Indicates that no relocatable binary file is generated. OFF /NOF77 The FORTRAN-66 standard rules apply for DO loops and EXTERNAL statements. (Same function as the /F66 switch.) OFF /NOFLAG-NON-STANDARD Indicates that no compatibility flagging will be done (see Section 16.6) • ON /NOERRORS Does not print error messages on the terminal. OFF /NOEXTEND Indicates extended addressing is not in effect (see Section 16.5). ON /NOWARN Suppresses warning messages (see Section 16.4). NONE /OPTIMIZE Performs global optimization. OFF /OPTION [:option] Only read lines from the SWITCH.INI file that start with FORTRA:option. OFF /SYNTAX Performs syntax check only. OFF Each switch must be preceded by a slash (/). Switch names need only contain those letters that are required to make the switch name unique. You are encouraged to use at least three letters to prevent conflict with switches in future implementations. NOTE When using switches in control files, you encouraged to type the full name of the switch. 16-10 are USING THE 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 FORDDT 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 FORDDT. ) 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 FORDDT pause on the RETURN statement ( see Sec t i on 13. 4 • 4) and t h en 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. 1 NOTE 1 1 1 1 1 1 1 If the /DEBUG switch is specified without arguments, then the defaults are used for all the arguments. The /DEBUG switch used without arguments is the same as /DEBUG:(ARGUMENTS,BOUNDS,DIMENSIONS,INDEX,LABELS, TRACE) • 1 1 1 1 1 "I 1 1 1 You can invoke a single aspect of debugging without affecting the other features controlled by the switch. For example, specifying /DEBUG:ARGUMENTS does not cause BOUNDS checking to also be invoked. However, you can change multiple features of the /DEBUG switch in the same command line. For example, /DEBUG:ARGUMENTS /DEBUG:BOUNDS would invoke both argument checking and bounds checking. FORTRAN-10/20 VII 16-12 February 1987 USING THE FORTRAN COMPILER 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 that is: Either a series of /DEBUG modified switch switches, /DEBUG:BOU/DEBUG:LAB or a list of modifiers /DEBUG:(BOU,LAB, ••• ) 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 switch 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,IND,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 NOTE 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 a result of the addition of various /DEBUG options. DIMENSIONS For each array, 3+3*N words where N is the number of dimensions, and up to three constants for each dimension. TRACE One instruction per executable statement. LABELS No increase. INDEX One instruction per 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 increase. 16-13 February 1987 USING THE FORTRAN COMPILER 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.) 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. If a non-routine name is passed where a routine name is expected, or a routine name is passed where a non-routine name is expected (see Table 16-5). Non-fatal error messages are issued at compile time for the cases (only for statement functions): and the following 1. If a non-routine name is passed where a routine name is 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 Argument Type Alternate Double Return Label Logical Integer Real D-floating G-floating Complex Character Octal Hollerith Octal Alternate Return Label Logical X X Integer Real D-floating G-floating X X X X Complex X X X X X X X X X X X X X X Character X indicates legal associations. All others will cause a warning to be issued if IDEBUG:ARGUMENTS is specified. FORTRAN-10/20 VII 16-14 February 1987 USING THE FORTRAN Table 16-5: COMP~LER Legal Dummy and Actual Argument Structure Associations Actual Argument Structure Singleton Singleton Array X Array Routine X X Routine X legal associations. All others will cause warning to be issued if /DEBUG:ARGUMENTS is specified. X indicates 16.4 a 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-6. Table 16-6: Arguments to /NOWARN Switch Arguments Meaning ALL Suppress all warning messages. NONE Do not suppress warning messages. xxx Where xxx is the three character error mnemonic the error message to be suppressed. This is for for example the three letters that follow %FTN, %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:(LID,DIM) would suppress both LID and DIM types of warning messages. (See Appendix C for a list of all compiler error mnemonics.) FORTRAN-10/20 VII 16-15 February 1987 USING THE FORTRAN COMPILER THE /EXTEND SWITCH (TOPS-20 ONLY) 16.5 Support for extended addressing is almost completely transparent; a program compiled with the /EXTENb switch will use extended addressing without requiring changes to the FORTRAN source program. When /EXTEND is specified, arrays ~nd 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 specified 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: Table 16-7: /EXTEND Default Memory Layout Section Pages Contents 1 O-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 50O-577 FOROTS 1 60O-777 Reserved 2-31 O-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, an~ 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.5.3 describes the /EXTEND arguments.) 16-16 February 1987 USING THE FORTRAN COMPILER NOTE If the /EXTEND switch is specified without arguments, then the default-s are used for all the arguments. The /EXTEND switch used without arguments is the same as /EXTEND:(DATA:10000,COMMON,NOCODE,PSECT:.DATA.:.CODE.) (See Section 16.5.3.) You can invoke a single aspect 9f extended addressing without affecting the other features controlled by the switch. For example, specifying /EXTEND:DATA does not cause COMMON blocks to be placed into the large psect, which is done with the /EXTEND:COMMON argument. However, you can change multiple features of the /EXTEND switch in the same command line. For example, /EXTEND:CODE:100/EXTEND:COMMON would place all non-common data items not less than 100 words long and all COMMON blocks into the large psect. 16.5.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-7. 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 FOROll.EXE" and "?Can't overlay existing pages" A smaller DATA size will force these d-ata structures into a non-FOROTS section. 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. FORTRAN-10/20 VII 16-17 February 1987 USING THE FORTRAN COMPILER 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 larg~ variables. If the user does not specify the extended addressing switch, FORTRAN will gene.rate a TWOSEG REL file as it always has. The three PSECTS generated under /EXTEND are: 1. The "large data area" psect (.LARG.) has a maximu~ 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 user-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. psect. 3. The "executable code and sharable data area" psect (default name .CODE.) of a program consists of all executable code, argument blocks and 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 Default Origin Attributes data 1001000 code 1300000 .LARG. 2000000 Single section, Non-zero section, Concatenated, Writable Single section, Non-zero section, Concatenated, Read-only Non-zero section, Concatenated, Writable up You can alter the default psect origins when loading programs by glvlng 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-18 February 1987 USING THE FORTRAN COMPILER 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 no advance across section boundaries, and the small data area is assumed to be in the same section. 2. You will need to use the /EXTEND:CODE keyword. This 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) together 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: each 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. 3. You must always allocate 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 unit psect page 0 must be of that .DATA. Arguments to /EXTEND By using th~ /EXTEND switch arguments listed in Table include specific extended addressing features. 16-8, you can The form of the /EXTEND switch is: /EXTEND: a rg or /EXTEND: (argl,arg2, ••• ) 16-19 February 1987 USING THE FORTRAN COMPILER Table 16-8: 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 size (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:1073741823, which excludes all variables from • LARG. PSECT[:[data psect] [ : [code psect]]] Allows users to set the code and data 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 February 1987 USING THE FORTRAN COMPILER 16.5.4 Linking with TWOSEG REL 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; howeve~, 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-10/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 18-bit address fields, 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 extended MACRO progra~ 16.6 ----- THE /FLAG (/FLAG-NON-STANDARD) SWITCH The /FLAG switch invokes the compatibility flagger. NOTE 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 cause logically used on the VAX FORTRAN system different results when NOTE VAX FORTRAN is used operating systems. on the VAX/VMS and ULTRIX This allows the flagging of any element that could cause conversion problems for programs written on the TOPS-10/20 system that might be compiled and executed on a VAX/VMS system or an ANSI-compatible system. This includes problems that could occur at object time, as well as compilation incompatibilities. FORTRAN-10/20 VII 16-21 February 1987 USING THE FORTRAN COMPILER By using the FLAG switch arguments specify which features to flag. listed in Table 16-9, you can The form of the /FLAG switch is: /FLAG [ : arg] or /FLAG [: (argl ,arg2, ••• )] Table 16-9: 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 whenever 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 warning 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 February 1987 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 COMMON are listed only as being in COMMON. S. A listing of the subprqgrams referenced and FORTRAN-defined li~rary 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 with that internal sequence number. An asterisk indicates a compiler inserted line. LOC: The relative location in the object program of the instruction. LABEL: Any program or compiler generated label. Program labels have the letter UP" 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 ln 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 editor SOS on TOPS-10 (or the editor EDIT on TOPS-20) • NOTE A single FORTRAN line can produce multiple machine instructions. In this case the line number map lists only the first location. 16-23 February 1987 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 ,detected during compilations. 16.7.1 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 computat ion. 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: 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 February 1987 USING THE FORTRAN COMPILER Example 1 , , Program Name Source Name MAIN. TIM1.FOR 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 100 Compiler Version FORTRAN V.11(4543)/F77/M 2-DEC-86 t 10:26 MACRO code listing included IMPLICIT INTEGER (A-Z) DIMENSION A(100,200) COMMON B(100,200) OPEN(UNIT=22,FILE='TIM1.DAT') INTEGER_SUM1=O INTEGER_SUM2=0 DO 100 J=1,200 DO 100 1=1,100 K1=I*J IF (K1 .LT. 500 .OR. K1 .GT. 1500) K1=O A(I,J)=K1 K2=I+J IF (K2 .EQ. 100 .OR. K2 .EQ. 200 .OR. K2 .EQ. 300) K2=K2+1 B(I,J)=K2 INTEGER_SUM1=INTEGER_SUM1+K1 INTEGER_SUM2=INTEGER_SUM2+K2 CONTINUE C 10 WRITE(22,10)INTEGER_SUM1,INTEGER_SUM2 FORMAT('INTEGER_SUM1=' ,19,' INTEGER_SUM2=' ,19) END COMMON BLOCKS / . COMM. / (+47040) ..._ _ _ Relative addresses of each variable _ _ _ _ _ _ _ _ _..... B "*" N0 1EXPLICIT DEFINITION +0 *K1 *INTEGER_SUM2 1 47045 l *J l::2 *1 47046 A *K2 -J"%,, NOT REFERENCED] 3 47047 .S0001 *INTEGER_SUM1 Relative address of each character data descriptor CHARACTER DATA NAME 'TIM1.DAT' "*" NO EXPLICIT DEFINITION] DESCRIPTOR ADDRESS START OF DATA ADDR(POSITION) . HSCHD+O 47043 47050 .SOOOO 47044 t Compiler generated variable LENGTH I 8 - # of characters t Relative address of first character of string 47b54(1) Character position of first character of string FORTRAN-10/20 VII 16-25 February 1987 USING THE FORTRAN COMPILER Internal sequence number on first instruction for this source line 1 LINE 4 5 6 7 , Octal displacement of instruction LOC LABEL 0 1 2 3 4 5 6 7 10 JFCL JSP 11 3M: 8 12 4M: 9 13 5M: 10 14 15 16 17 20 21 22 7M: 11 23 6M: • 10 24 25 26 27 30 31 32 33 34 35 36 37 10M: 13 40 9M: 14 41 8M: 15 16 17 42 43 44 45 46 47 50 12 13 19 21 GENERATED CODE XMOVEI PUSHJ SETZB MOVEM MOVE HLREM 0,0 16,RESET. 0,0 16,2M 17,OPEN. 2,INTEGER_SUMl 2,INTEGER_SUM2 2, [777470000001] 2, .SOOOO HRRZM 2,J MOVE 2, [777634000001] MOVE IMULI MOVEM CAlL CAlLE JRST JRST 3,J 3,0(2) 3,Kl 3,764 3,2734 O,7M O,6M SETZB 4,Kl MOVEI ·IMUL ADD I MOVE MOVEM MOVE ADD I MOVEM MOVE CAIE CAIN JRST 3,144 3,J 3,0(2) 4,Kl 4,A-145(3) 3,J 3,0(2) 3,K2 5,K2 5,144 5,310 O,9M CAIN 5,454 ADS 3,K2 MOVEI IMUL ADD I MOVE MOVEM ADDM ADDM 3,144 3,J 3,0(2) 5,K2 5,B-145(3) 4,INTEGER_SUMl 5,INTEGER_SUM2 AOBJN HRRZM ADS AOSGE JRST XMOVEI PUSHJ XMOVEI PUSHJ XMOVEI PUSHJ 2,5M 2,1 2,J 0, .SOOOO ,O,4M 16,l1M 17,OUT. 16,12M 17,IDLST. 16,lM 17 ,EXIT. Compiler generated label lOOP: • 51 52 53 54 55 56 57 60 61 62 FORTRAN-10/20 VII Program label 16-26 February 1987 USING THE FORTRAN COMPILER ARGUMENT BLOCKS: ...- - - - Function, subroutine, and FOROTS argument blocks 63 64 65 66 67 70 71 72 73 74 75 76 0,,0 0,,0 777776, ,0 436000,,26 406640" . HSCHD+O 777776, ,0 401000, ,26 402340, ,lOP 777775, ,0 401100, ,INTEGER_SUMl 401100, ,INTEGER_SUM2 4000, ,0 1M: 2M: 11M: 12M: FORMAT STATEMENTS (IN LOW SEGMENT): 20 MAIN. 47056 47057 6 lOP: (' INTEGER_SUM1= ',19,' [No errors detected ] _ INTEGER_SUM2=' ,19) Summary of errors Example 2 MAIN. 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 TIM1.FOR 100 FORTRAN V.ll(4543)/F77/LN 2-DEC-86 10:28 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=l,200 DO 100 1=1,100 Kl=I*J IF (Kl .LT. 500 .OR. Kl .GT. 1500) Kl=O A(I,J)=Kl K2=I+J IF (K2 .EQ. 100 .OR. K2 .EQ. 200 .OR. K2 .EQ. 300) K2=K2+1 BO, J)=K2 SUM1=SUM1+Kl SUM2=SUM2+K2 CONTINUE C 10 WRITE(22,10)SUM1,SUM2 FORMAT(' SUM= ',19,' END SUM2=' ,19) COMMON BLOCKS /.COMM./(+47040) B +0 SCALARS AND ARRAYS [ "*" NO EXPLICIT DEFIIhTION - "%" NOT REFERENCED] *Kl *SUM2 1 47045 2 A 3 47046 *K2 47047 .SOOOl *SUMl 47043 47050 .SOOOO 47044 LINE NUMBER/OCTAL LOCATION MAP ...----Requested with /LNMAP : 0 00000 00010 00020 MAIN. 2 16 3 23 30 33 61 [ No errors detected ] 4 5 6 7 8 3 5 6 7 12 41 46 47 50 9 13 55 Line #11 starts at octal offset 23 (from the previous example, note that line 11 uses locations 23 through 27, but only the first location~is shown here). FORTRAN-10/20 VII 16-27 February 1987 USING THE FORTRAN COMPILER Example 3 MAIN. 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 TIM1.FOR 100 FORTRAN V.11(4543)/F77/0PT/M 2-DEC-86 10:30 IMPLICIT INTEGER (A-Z) DIMENSION A(100.200) COMMON B(100.200) OPENCUNIT=22.FILE='TIM1.DAT') SUM1=O SUM2=0 DO 100 J=1.200 DO 100 1=1.100 K1=hJ IF (K1 .LT. 500 .OR. K1 .GT. 1500) K1=O ACI.J)=K1 K2=I+J IF (K2 .EQ. 100 .OR. K2 .EQ. 200 .OR. K2 .EQ. 300) K2=K2+1 B(I.J)=K2 SUM1=SUM1+K1 SUM2=SUM2+K2 CONTINUE C 10 WRITE(22.10)SUM1.SUM2 ' FORMAT ( , SUM1= '.19.' END SUM2= '.19) COMMON BLOCKS /.COMM./(+47040) B +0 SCALARS AND ARRAYS [ n"n NO EXPLICIT DEFINITION - n%n NOT REFERENCED] • Optimizer,created variables *K1 1 .S0001 47045 *K2 47052 . R0001 .S0001 *SUM1 CHARACTER DATA NAME [ n*n NO EXPLICIT DEFINITION] DESCRIPTOR ADDRESS START OF DATA ADDR(POSITION) LENGTH 'TIM1.DAT' . HSCHD+O 8 FORTRAN-10/20 VII 2 47046 47053 .ROODO *SUM2 3 47047 *J *1 47060(1) 16-28 4 47050 A .00001 5 47051 February 1987 USING THE FORTRAN COMPILER LINE 4 6 * 7 * 8 * LOC 0 1 2 3 4 5 6 7 10 11 12 13 14 15 LABEL JFCL JSP 8M: 11 25 7M: 12 26 27 30 31 32 33 11M: 13 34 10M: 14 35 9M: 15 16 36 37 40 41 *17 * * * * * * 19 * 21 42 43 44 45 46 47 50 51 52 53 54 55 56 57 60 61 MOVE MOVE 6,7 2, [777634000001] MOVE I ADD MOVE CAlL CAlLE JRST JRST 4,0(2) 4, . ROOOl 5,6 5,764 5,2734 O,8M O,7M MOVEI 5,0 MOVEM MOVE ADDI CAIE CAIN JRST 5,A-145(4) 3,7 3,0(2) 3,144 3,310 O,10M CAIN 3,454 ADDI 3,1 MOVEM ADD ADD ADD 3,B-145(4) 11,5 10,3 6,7 AOBJN HRRZM MOVEI ADDM 2,6M 12,144 12,144 12, . ROOOl ADDI AOSGE JRST MOVEM MOVEM MOVEM MOVEM MOVEM XMOVEI PUSHJ XMOVEI PUSHJ 7,1 0, .SOOOO O,5M 7,J 11, SUMl 10,SUM2 5,Kl 3,K2 16,12M 17,OUT. 16,13M 17,IDLST. XMOVEI PUSHJ 16,3M 17,EXIT. Asterisks indicate optimizer generated statements 6M: 10 13 XMOVEI PUSHJ SETZB MOVEI MOVEM MOVNI MOVEI MOVEM 0.0 16,RESET. 0,0 16,4M 17,OPEN. 10,11 12,144 12, . ReOOl 12,310 7,1 12, . SOOOO 5M: 16 17 20 21 22 23 24 9 10 GENERATED CODE lOOP: 1M: 2M: 62 FORTRAN-10/20 VII 16-29 February 1987 USING THE FORTRAN COMPILER ARGUMENT BLOCKS: 63 64 65 66 67 70 71 72 73 74 75 76 3M: 4M: 12M: 13M: 0, ,0 0,,0 777776, ,0 436000, ,26 406640, , . HSCHD+O 777776, ,0 401000, ,26 402340, ,lOP 777775, ,0 401100, ,SUMl 401100, ,SUM2 4000, ,0 FORMAT STATEMENTS (IN LOW SEGMENT): 20 MAIN. 47062 6 47063 lOP: ('SUM1=' ,19,' [No errors detected ] FORTRAN-10/20 VII SUM2=' ,19) 16-30 February 1987 USING THE FORTRAN COMPILER Example 4 MAIN. 00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 TIM1.FOR 100 FORTRAN V.ll(4543)/F77/M/EXT 2-DEC-86 16:27 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=l,200 DO 100 1=1,100 Kl=I*J IF (Kl .LT. 500 .OR. Kl .GT. 1500) Kl=O A(I,J)=Kl K2=I+J IF (K2 .EQ. 100 .OR. K2 .EQ. 200 .OR. K2 .EQ. 300) K2=K2+1 B(I,J)=K2 SUM1=SUM1+Kl SUM2=SUM2+K2 CONTINUE C 10 WRITE(22,10)SUM1,SUM2 FORMAT ( I SUM1= 1,19, I END COMMON BLOCKS SUM2= 1,19) ["!" STORED IN .LARG. /.COMM./(+47040!) +0 .L._____ Large common block B SCALARS AND ARRAYS *Kl 1 .SOOOl 3 *1 6 CHARACTER DATA NAME "*" NO EXPLICIT DEFINITION - "%" NOT REFERENCED ] "!" VARIABLE STORED IN .LARG. ] *J 2 ! J...----O-- Large variable .SOOOO 4 *K2 7 'TIM1.DAT' . HSCHD+O LABEL o 14(1) XMOVEI PUSHJ SETZB MOVEM MOVE HLREM 0,0 16,RESET. 0,0 16,2M 17,OPEN. 2,SUMl 2,SUM2 2, [777470000001] 2, .SOOOO HRRZM 2,J MOVE 2, [777634000001] MOVE lMULI MOVEM CAlL CAlLE JRST JRST 3,J 3,0(2) 3,Kl 3,764 3,2734 O,7M O,6M SETZB 4,Kl 2 3 4 5 6 7 5 6 7 10 11 3M: 8 12 4M: 9 13 5M: 10 10 14 15 16 17 20 21 22 8 GENERATED CODE JFCL JSP 1 4 5 10 ["*" NO EXPLICIT DEFINITION - "!" VARIABLE STORED IN .LARG. ] DESCRIPTOR ADDRESS START OF DATA LENGTH ADDR(POSITION) LINE LOC *SUM2 *SUMl 7M: FORTRAN-10/20 VII 16-31 February 1987 USING THE FORTRAN COMPILER LINE LDC LABEL 11 23 6M: 24 25 26 27 30 31 32 33 34 35 36 37 10M: 13 40 9M: 14 41 8M: 15 16 17 42 43 44 45 46 47 50 12 13 19 21 GENERATED CODE MOVE I lMUL ADDI MOVE MOVEM MOVE ADDI MOVEM MOVE CAIE CAIN JRST 3,144 3,J 3,0(2) 4,Kl 4,~[ .EFIWA-145(3) 3,J 3,0(2) 3,K2 5,K2 5,144 5,310 O,9M CAIN 5,454 ADS 3,K2 MoVEI lMUL ADDI MOVE MoVEM ADDM ADDM 3,144 3,J 3,0(2) 5,K2 5,~[ .EFIW B-145(3) 4,SUMl 5,SUM2 AoBJN HRRZM ADS AoSGE JRST XMOVEI PUSHJ XMoVEI PUSHJ XMoVEI PUSHJ 2,5M 2,1 2,J 0, .SOOOO O,4M 16,11M 17,oUT. 16,12M 17,IDLST. 16,lM 17,EXIT. lOOP: 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 1M: 2M: 11M: 12M: 0, ,0 777776, ,0 436100" [000000000026] 406640" . HSCHD+O 777776, ,0 401000, ,26 402340, , lOP 777775, ,0 401100"SUMl 401100, ,SUM2 4000, ,0 FORMAT STATEMENTS (IN LOW SEGMENT): 20 MAIN. 17 20 6 lOP: ('SUM1= ',19,' SUM2=' ,19) [No errors detected] FORTRAN-10/20 VII 16-32 February 1987 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 wi th "the statement in error are output to the user terminal. Example: TYPE DAY.FOR 01000 01100 01200 01300 01400 01500 100 01600 C 01700 01800 200 01900 I=10 IMPLICIT INTEGER (X) J=I**4 Kl X=I+J+Kl CONTNUE TYPE 200,X FORMAT (IX, I8) END COMPILE DAY.FOR FORTRAN: DAY IMPLICIT INTEGER (X) 01100 IMPLICIT statement out of order %FTNSOD LINE:01100 Kl 01300 ?FTNNRC LINE:01300 Statement not recognized 01500 100 CONTNUE ?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 February 1987 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 1 fatal error and no warnings name 2 fatal errors and no warnings name no fatal errors and 1 warning name 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 February 1987 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, LINK 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 LINK can be overridden by using the LINK switch /OTSEGMENT:NONSHARABLE when loading the program. If this switch is given, LINK 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. On TOPS-10, a program loaded with the /OTSEGMENT:NONSHARABLE switch can be saved to produce an executable file with a sharable high segment using the TOPS-10 SSAVE command or the TOPS-20 EXEC SAVE command. (The LINK switch /SSAVE 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. Both the code unique to the program and the copy of the FORTRAN run-time system that is private to the program are shared between all the program's users. On TOPS-20, all pure and impure pages of all programs begin as sharable pages, however, as impure pages are modified by stores, TOPS-20 creates non-sharable copies of the pages. The default action of LINK in programs that do not use extended addressing is to load all FORTRAN code into the low segment. This results in the impure and pure code of each program unit being loaded as one contiguous unit. Since the presence of impure code on a page will ultimately result in the page becoming non-sharable, the effective number of pages that are sharable in the program is less that the maximum that could be achieved. However, if the /OTSEGMENT:NONSHARABLE switch is used, all of the pure code of the program is loaded with a private copy of FOROTS into the high segment. Since the pure code in this case is not mixed with the impure code, a greater number of pages remain sharable in the program (also, the number of page faults may be reduced). Note that extended addressing programs on TOPS-20 by default have impure code and pure code loaded into disjoint areas so that /OTSEGMENT~NONSHARABLE does not increase the sharability or decrease the number of page faults of these programs. In addition, these programs use the system-wide sharable FOROTS, and thus make the best use of system resources. On both TOPS-10 and TOPS-20, 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 with all other users. (See the LINK Reference Manual for more information on the switch.) FORTRAN-10/20 VII 16-35 /OTSEGMENT February 1987 CHAPTER 17 USING THE FORTRAN INTERACTIVE DEBUGGER (PORDDT) 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 breakpoint. after 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. 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 (FORODT) 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. Array elements are specified in the following formats: name name (sl, ••• ,sn) where: name is the name of the array (sl, ••• ,sn) are the subscripts of a particular array. The subscripts must be integer constants or variables. You may reference an entire array 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 the various ways of and arrays to FORDDT: 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 also accepted. 3. OCTAL - A string of octal digits 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 string of alphanumeric and/or special characters delimited by any alphanumeric or special character, excluding the space character, which does not occur with the string itself. Such as, # l2AB#, 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 IThis causes a pause at source line number 3. PAUSE 3 IThis causes a pause at the statement labeled 3. FORDDT AND THE FORTRAN /DEBUG SWITCH Most facilities of FOR DDT are available without the FORTRAN /DEBUG features. However, if you do not use the /DEBUG switch when compiling a FORTRAN program, the trace features (NEXT command) will not be available, and several of the other commands will be restricted. In addition, the /DEBUG switch must be used if long symbols are to be made available to FORDDT. If long symbols are used in your FORTRAN program, and you do not use the /DEBUG switch when compiling, only the first six characters of each symbol is available to FORDDT. 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 FORDDT 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 with 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 abl~ 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. FORTRAN-10/20 Vll 17-4 February 1987 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 array references. Bounds violations produce run-time error messages. Note that the technique of specifying dimensions of 1 for 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 switch also performs type checking at compile-time for statement functions. LOADING AND STARTING FORDDT 1. On TOPS-IO, the simplest method of debugging with FORDDT is: .DEBUG filespec (DEBUG) On TOPS-20, the corresponding command is: @DEBUG filespec /DEBUG On both systems, FORDDT responds with: STARTING FORTRAN DDT Program name: When FORDDT prompts you for a program name, type the same name specified in the PROGRAM statement of the program being debugged. If the PROGRAM statement is not used ln 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: »7 One of the following: CHARACTER CONTINUE ACCEPT GROUP HELP GOTO PAUSE REMOVE OPEN WHAT TYPE DDT LOCATE START Also on TOPS-20, you can use the ESCape key of FORDDT 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 FORDDT You may wish to load your compiled program and directly with the linking loader. (Loading with LINK is The accomplished implicitly in the DEBUG command string.) command sequence is as follows: On TOPS-IO, 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 FORDDT must be made with respect to the currently open symbol table. If you have given the main program a name other than MAIN. by using the PROGRAM statement (see 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, substring, array, array element, array element range, or FORMAT statement to be modified. mode is the format of the data value to be entered. The mode keyword must be preceded by a slash (I) and immediately follows the name. Intervening blanks are not allowed. (Note that Imode 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 o L R S X Meaning Example ASCII (left-justified) CHARACTER DOUBLE-PRECISION REAL INTEGER OCTAL LOGICAL RASCII (right-justified) SYMBOLIC COMPLEX IFOOI 'ABC' 123.4567890 123.45678 1234567890 7654321 .TRUE. or .FALSE. \BAR\ PSI(2,4) (1.25,-78.E+9) If not specified, the default mode is REAL (F). 1. Two-Word Values For the data modes ASCII (A), OCTAL (O), RASCII (R), and SYMBOLIC (S), FORDDT will accept a "/BIG" modifier on the mode switch. This modifier indicates that the variable and the value are to be interpreted as two words long. FORTRAN-10/20 VII 17-7 February 1987 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) Example: ACCEPT VAR/RASCII/BIG '1234567890' assumes that VAR is two words long and given l0-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 the length of 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. FORTRAN-10/20 VII 17-8 February 1987 USING THE FORTRAN INTERACTIVE DEBUGGER (FORDDT) Example: ACCEPT ARRAY/ASCII 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 5. FORMAT Statement Modification When the name field of an ACCEPT contains a label, FORDDT expects this label to be a FORMAT statement label and that the value field contains a new format specification. Example: ACCEPT 10 (lHO,FIO.2,3(I2)) The new specification cannot be longer than the space originally allocated to the FORMAT by the compiler. The remainder of the area is cleared if the new specification is shorter. Note that FOROTS performs some encoding of FORMAT statements when it processes them for the first time. If any I/O statement referencing the given FORMAT has been executed, the FORTRAN program has to be restarted (re-initializing FOROTS). CHARACTER Defines the dimensions of a character 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 a character array. The command format is: CHARACTER arrayname ([Ll:]Ul[,[L2:]U2, ••• ]) NOTE This declarator cannot be used to specify element length. The length specified in the user program will be used. CONTINUE Allows the program to resume execution after a FORDDT pause. After a CONTINUE is executed, the program either runs to completion or until another pause is encountered. The command format is: CONTINUE [n] where the n is optional and, if omitted, is assumed to be one. If a value is provided, it can be a numeric constant or program 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 example, CONTINUE 20 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 is: 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 Sec t ion 17.6). The command format is: GOTO n GROUP Sets up a string of text for input to a TYPE command. You can store TYPE statements as a list of variables identified by the numbers 1 through 8. This feature eliminates the need to retype the same list of variables each time you wish to examine the same group. Refer to the TYPE command for the proper format of the list. The command format is: GROUP [n list] where: n is the group number 1-8 list is a list of group numbers preceded by a slash (I) andlor variable names, substrings, array elements, and array elemerit ranges 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 FORDDT to type out the current contents of all the groups. GROUP n types out requested. the contents of the particular group Note that one group may refer to another. For example: FORTRAN-10/20 V11 GROUP 2 VAR2,VAR3 GROUP 3 11,/2 17-11 February 1987 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 forma t 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 FOR DDT 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) fo rma t • default typeout The command format is: MODE list where list contains one or more of the mode identifiers separated by commas. The current setting can be changed by issuing another MODE command. If more than one mode is given, the values are typed out in the order: C, 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 trac~ 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. T~e default switch is IL. 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 program 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 FOR DDT 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 AFTER n p IF condition p TYPING Ig P AFTER n TYPING /g P 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 FOR DDT 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. Whe~ the TYPING option is used with the PAUSE command, control can be transferred to FORDDT at the next typeout by typing any character on the terminal. Note that pause requests remain after a <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] For example, 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 REMOVE with no arguments removes all your FORDDT 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. The 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 /RETURN 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, substrings, arrays, or array elements on your terminal. The command format is: TYPE list where list may be one or more variables, substrings, or array references and/or group numbers. These specifications must be separated by commas, and group numbers must be preceded by a slash (/). The command with no arguments uses the last argument list submitted to FORDDT. An array element 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 in this chapter. FORTRAN-10/20 VII 17-15 a format, the form of default is MODE command February 1987 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 If you type a variable in mode CHARACTER (C), the number of characters printed is equal to the length declared in the FORTRAN source program, up to a maximum of 256 characters. The IB switch can be used to override the 256 character maximum. 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, until another mode is K, M are integer - the default mode for group 2 is integer L is OCTAL N is ASCII WHAT 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 ENVIRONM·ENT 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; however, GOTO, STRACE, TYPE, and ACCEPT cause transfer of control to routines external to FORDDT. No guarantee can be made to ensure that any of these commands following a <CTRL/C> REENTER sequence will not destroy the program integrity. The program must be returned to a stable state before any of these four commands can be issued. In order to restore program integrity, you should set a pause at the next label and then CONTINUE to it. If the /DEBUG:TRACE switch is used, a NEXT 1 command can be issued to restore program integrity. 17.7 FORTRAN /OPTIMIZE SWITCH You should never attempt to use FOR DDT 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 to a RETURN from a subroutine). NOTE Since FORDDT is defined as a global symbol, users should be careful if they decide to use FOR DDT as a program, subroutine, or function name. 17.9 FORDDT AND FORTRAN-20 EXTENDED ADDRESSING FORDDT VI0 has been modified to be able to run in any section and access data and code in all sections. The user interface to FORDDT is the same regardless of whether or not a program uses extended addressing. FORDDT VI0 is section independent. The same FORDDT.REL will either section 0 or a non-zero section. work in If a program is loaded with the /DEBUG:FORDDT option, LINK loads FORDDT.REL with the program. 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 FORDDT 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-10 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. Formatt ing of data 6. Mathematical library 7. User library (nonmathematical) 8. Specialized applications packages 9. Overlay facilities 10. RMS-20 interface (TOPS-20 only) 11. Network file access (TOPS-20 only) FOROTS runs on any TOPS-10 or TOPS-20 system. all TOPS-l~ 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 features is given later in this chapter. 1. Your program can run in either batch or timesharing mode without requiring a program change. All differences between batch-mode and timesharing-mode operations are resolved by FOROTS. FORTRAN-10/20 VII 18-1 February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 2. Your programs can access both devices in the same manner. 3. FOROTS helps provide complete data file compatibility between all system devices. 4. FOROTS treats devices located at remote stations in the way it treats local devices. 5. directory and nondirectory same Programs written for magnetic tape operations will run on disk under FOROTS supervision. FOROTS simulates the commands needed for magnetic tape operations. c~rrectly 18.2 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-10/20 object programs, you can also use FOROTS as an independent I/O system, and as an I/O system for MACRO object programs. 13. FOROTS provides an interface to RMS-20 (TOPS-20 Record Management Services) for I/O to RMS-20 sequential, relative, and indexed file organizations. 14. FOROTS allows transparent access from TOPS-20 systems to remote RMS and non-RMS files residing on other TOPS-20 and VMS systems. IMAGE 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. FORTRAN-10/20 VII 18-2 February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.3 INPUT/OUTPUT FACILITIES On TOPS-10, 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. On TOPS-20, FOROTS uses the RMS-20 subsystem for disk I/O if the ORGANIZATION keyword specifies an RMS file organization, or if the file is remote. The following sections describe I/O data channel and access modes. 18.3.1 Input/Output Channels Used By FOROTS (TOPS-10 Only) FOROTS uses extended channels starting operations. User programs can request through the ALCHN. and FUNCT. routines. FORTRAN-10/20 VII 18-2.1 at channel 20 for I/O I/O channels 0 through 17 February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) This page intentionally left blank. 18-2.2 February 1987 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. 18.3.2 File Access Data can be transferred between processor storage and devices using either sequential or direct (random) access. 18.3.3 peripheral Closing Files After Non-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 18.3.3.1 Sequential Access - In a sequential-access transfer operation, the records 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 record 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 types (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 record' preceding the WRITE. USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) l8.~.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' (direct read/write access) ACCESS='RANDOM' (same as DIRECT) ACCESS='RANDIN' (direct read-only access) ACCESS='KEYED' (direct indexed-file read/write access) 18.4 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 physical 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 word and may have one or more control words embedded within it. In FORTRAN binary data files, there is no relationship between logical records and physical device block sizes. There is no implied maximum length for logical records. 18.4.2.1 Format of Binary Files - A FOROTS binary file can contain three forms 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. START CONTINUE END FORTRAN-10/20 VII LSCW 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 003+ the number of words in the whole record incl ud ing all LSCWs 18-4 "February 1987 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. The following examples illustrate the LSCW. file contains only 001 and 003 LSCWs. C C The direct-access LOOK AT A BINARY FILE AND SEE THE LOGICAL SEGMENT CONTROL WORDS. OPEN(UNIT=l,ACCESS='DIRECT' ,MODE='BINARY', 1 RECORDSIZE=lOO) 1=5 WR1TE(I'I) J=7 WR1TE(l'2) END (I, J=l,lO) (J,K=I,lO) 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 LSCW containing the number of words in the record including all LSCWs. 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/ 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/ L61/ 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-10, 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 WRI~E(l) (I, J=l,lOO) J=7 WRITE(l) END (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,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-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~Continue 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) J=7 WRITE(l) END (I, J=l,lOO) (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,000005 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,0000'07 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') WRITE (I) 3, 'ABCDEF' ,4,'GHIJKL' WRITE (1) END 0/ 1/ 2/ 3/ 4/ 5/ 6/ 7/ 10/ 11/ 12/ 13/ 14/ 'MNOPQR' ,'STUVWX' 001000,000007 000000,000003 406050,342212 430000,000000 000000,000004 436211,145226 460000,000000 003000,000010 001000,0000e4 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=l,MODE='IMAGE') WRITE (1) 3, 'ABCDEF' ,4,'GHIJKL' WRITE (1) END 0/ 1/ 2/ 3/ 4/ 5/ 6/ 7/ 18.4.3 'MNOPQR' ,'STUVWX' 000000,000003 406050,342212 430000,000000 000000,000004 436211,145226 462331,647640 506452,352252 532573,000000 RMS Data Files (TOPS-20 only) The FOROTS/RMS-20 interface can be used to access RMS-20 (and remote VMS RMS-32) files with sequential, relative, or indexed organizations. ,An RMS record file consists of a prologue section and a data section. The prologue section is the repository of the file's attributes. The data section contains data records (and indexes, if applicable). See the TOPS-20 RMS User's Guide for formats. FORTRAN-10/20 VII 18-14 more information on RMS file February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.5 USING FOROTS FOROTS has been designed to lenq 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.5.1 I/O 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 an I/O channel for use subroutine (see Section 18.5.3.12) ALCOR. Allocates memory (see Section 18.5.3.11) CLOSE. Closes a file. In a FORTRAN program, this call is made when the CLOSE statement is executed (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 Section 18.5.3.12) DECOR. Deallocates memory that was allocated by call (see Section 18.5.3.11) DELTR. Deletes an RMS relative or indexed file record. In a FORTRAN program, this call is made when a DELETE statement is executed (see Section 10.13). ENC. ENCODE routine 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 the main program. EXITI. Writes out buffers, closes and unmaps all files FIN. I/O list termination routine (see Section 18.5.3.9) FORTRAN-10/20 VII 18-15 by a MACRO IOLIST obtained an from ALCOR February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) Table 18-1: FOROTS Entry Points (Cont'd) Entry Point Function FIND. FIND statement FORER. Error processor FOROP. Miscellaneous FOROTS utilities FUNCT. OTS-independent interface to provide common functions (like 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. Internal file input (see Section 18.5.3.2) 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 REWRF. Formatted REWRITE output routine. In a FORTRAN program, this call is made when a formatted REWRITE statement is executed for RMS files (see Section 10.14.1) • REWRU. Unformatted REWRITE output routine. In a FORTRAN program, this call is made when an unformatted REWRITE statement is executed for RMS files (see Sec t i on 1 0 • 14 • 2) • RTB. Binary input routine 18.5.3.5) TRACE. Traces subroutine calls UNLOC. UNLOCK record routine for RMS files. UNLOCK statement, Section 10.15.) WTB. Binary output routine (see 18.5.3.5) FORTRAN-10/20 VII 18-16 and (see ENDFILE 18.5.3.1, statements Sections Sections (see 18.5.3.1, 18.5.3.1 and (See the 18.5.3.1 and February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 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), is, 2. 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.5.3.12 give the MACRO calls and required argument block formats needed to initialize FOROTS and FOROTS I/O operations. 18-16.1 February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) This page intentionally left blank. 18-16.2 February 1987 USING THE FORTRAN 18.5.3 OBJ~CT TIME SYSTEM (FOROTS) MACRO Calls for FOROTS 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 (ARGBLK) of each call: pointer to the second word in the argument block (This is the address pointed to by the argument ARGBLK in the calling sequence.) u FORTRAN logical unit number n count of ASCII characters f FORMAT statement address list an Input/Output list name a NAMELIST name r a variable specifying the random access mode * list-directed I/O (the FORMAT statement is not used) type type specification of a variable or constant 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 14 15 16 UNIT FMT address FMT size (in words) END= address ERR= address IOSTAT= address REC= NAMELIST table address File-positioning function code ENCODE/DECODE array address Internal record length Relational type for indexed READ Key number of key for indexed READ Key relational value FORTRAN-10/20 VII 18-17 February 1987 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) ~ 1 a ARGBLK: ·· ·· ·· 1 a wnere: I = y = kwd lS-35 kwd type I a y kwd type I a y 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) list XMOVEI 16, ARGBLK PUSHJ 17, IN. and WR I TE ( u , f) 1 i s t 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 18-18 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The READ and WRITE statements for unformatted sequential data transfer operations and their calling sequences are: READ(u) list XMOVEI 16, ARGBLK PUSHJ 17, RTB. and WRITE(u) list XMOVEI 16, ARGBLK PUSHJ 17, WTB. 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) 1i s t XMOVEI 16, ARGBLK PUSHJ 17, IFI. and WR I T E (u , f) 1i st XMOVEI 16, ARGBLK PUSHJ 17, IFO. The following arguments must be specified in ARGBLK: 1 2 3 UNIT (must be a character scalar or array) FMT address FMT size The following may also appear: 4 5 6 ERR END IOSTAT 18-19 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) lS.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. 18.5.3.4 Array Offsets and Factoring - Address calculations used to reference a given array element involve factors and offsets. For example: Array A is dimensioned DIMENSION A (Ll:Ul,L2:U2,L3:U3, ••• Ln:Un) The size of each dimension is represented by: Sl S2 UI-Ll+l 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+(I1-L1)+(I2-L2)*Sl+(I3-L3)*S2*Sl+ ••• +(In-Ln)*S[n-1]* ••• *S2*Sl lS-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+(-Ll-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 giverr array, there is a corresponding factor by which a subscript in that position will be multiplied. From the last expression, one can determine the factor for dimension n to be: S[n-l]*S[n-2]* ••• *S2*Sl For double-precision and complex arrays, the expression becomes: A+2*(Il-Ll)+2*(I2-L2)*Sl+2*(I3-L3)*S2+Sl+ ••• Therefore, the array offset for a double-precision array is: 2*(-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 0 35 NAMELIST name in SIXBIT NAMELIST entry 1 NAMELIST entry 2 · · · NAMELIST 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 1 9- 12 1 13 1 14-17 18-35 1 SIXBIT/ARRAY NAME/ 1 0 I IDIMS 0 1 type 1 I 1 ARRAY SIZE 1 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 I r , f) 1 is t XMOVEI 16, ARGBLK PUSHJ 17, IN. and WRITE CUi r ,f) list 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 are: transfers READ (u I r) XMOVEI l6,ARGBLK PUSHJ P,RTB. and WRITE (u I 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, 1 i st REREAD f, list UNIT=-4 UNIT=-5 UNIT=-6 (TTY) (CDR) (REREAD) UNIT=-3 UNIT=-2 UNIT=-l (LPT) (PTP) (TTY) XMOVEI 16, ARGBLK PUSHJ 17, IN. and PRINT f, list PUNCH f, list TYPE f, list 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) SKIPFILE (u) BACKFILE (u) BACKSPACE (u) ENDFILE (u) REWIND (u) SKIPRECORD (u) UNLOAD (u) FOROTS Code 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 statem~nt 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: READ (u, *) WRITE statements and their 1i s t 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 FOROTS Value DATA SLIST ELIST FIN F77 SLIST F77 ELIST 1 the 2 3 4 5 6 The elements of an I/O list are: 1. DATA The DATA element converts one single- or double-precision or complex item from external to internal form for a READ statement and from internal to external form for a WRITE statement. Each DATA element has the following format: 0-1 1 2. a 2-8 9-12 13 14-17 DATA type I a 18-35 SCALAR AD DR 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 2-8 9-12 13 14-17 a SLIST type I a #ELEMENTS a 1 a a type I a INCREMENT a type I a BASE ADDRI 1 1 18-25 18-35 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) For example, the sequence: DIMENSION A(lOO) ,B(lOO) READ(-,-)A or READ(-,-) (A(I) ,I=l,lOO) !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(lOO), B(lOO) WRITE (-,-) (A(I) ,B(I) ,I=lOO) long as !on1y 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 AD DR 2 increment N 1 0 0 type I 0 Base ADDR N 18-26 18-35 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) For example, the FORTRAN sequence: DIMENSION IC(6,100), IB(lOO) WR I T E ( - , - ) ( I B ( I) , I C ( 1 , I) , I = 1 , 1 0 0 ) 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 4 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 The increment may be zero. produced by the s~quence: WRITE(-,-) (K,I=I,lOO) !only 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 0 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: 9-12 13 14-17 18-35 o o o o EXPLICIT CALL: PUSHJ 17, FIN. 18-27 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 5. F77 SLIST This is the same as SLIST except that if the number elements is less than or equal to zero, no I/O is done. 6. of F77 ELIST This is the same as ELIST except that is the number 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 2-8 9-12 13 14-17 Negative of the number of words in block not including this one. 0 1 0 1 0 1 0 G G G type I type I type I X X X ·· ·· 1· 0· · · · · G · · · · · ·· 18-35 ··· X ·· ·· type I H H H ·· · · 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 numer ic 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 27 30 G Field DIALOG ACCESS= DEVICE= BUFFERCOUNT= BLOCKSIZE= FILE= PROTECTION= DIRECTORY= LIMIT= MODE= FILESIZE= RECORDSIZE= DISPOSE= VERSION= ORGANIZATION= SHARED IOSTAT= ASSOCIATEVARIABLE= PARITY= DENSITY= BLANK= CARRIAGECONTROL= FORM= BYTESIZE= 31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 50 51 52 53 54 55 56 57 Open Argument PADCHAR= RECORDTYPE= STATUS= TAPEFORMAT= READONLY= UNIT= ERR= EXIST= FORMATTED= NAMED= NEXTREC= NUMBER= OPENED= SEQUENTIAL= UNFORMATTED= NAME= KEY= USEROPEN= DIALOG= DEFAULTFILE= KEYED= NOSPANBLOCKS MAXREC= 18.5.3.11 MemQry 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: 0-1 2-8 9-12 13 14-17 -1 1 0 Reserved FORTRAN-10/20 VII 18-35 0 type I 18-29 0 Address of number of words February 1987 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 9-12 13 14-17 -1 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 -1 -.. 1 0 Reserved type 18-35 0 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: 0-1 9-12 2-8 13 14-17 -1 1 0 18.6 18-35 0 Reserved type I 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.i and they are called by the sequence: XMOVEI 16, ARGBLK PUSHJ 17, FUNCT. The format of the ARGBLK is: ARGBLK: -<n+3>,,0 IFIW 2,address of integer function code IFIW l7,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 one 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 5 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 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 Gets the initial time file run specification from object-time the 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 CO) FUNCTION - This function is illegal. ignored, and the status returned is -1. The argument block is GAD (I) 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: arg 1 arg 2 space undefined (address of allocated memory on return) address of size of requested allocation On return, the status is one of the following: a memory allocated not enough memory available illegal argument (that is, size is greater than 256K) 1 3 RAD (3) function - This function 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 size of memory to be returned (in words) On return, the status is one of the following: a successful return of memory memory cannot be returned illegal argument (that is,the address or greater than 256K) I 3 GCH (4) are: FUNCTION - This function gets an I/O channel. arg I 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: a 1 successful channel allocation no I/O channels available RCH (5) FUNCTION - This arguments are: arg 1 arg 2 function returns an I/O channel. The address of number of channel to be returned ignored On return, the status is one of the following: a 1 channel released 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 size of memory requested On return, the status is one of the following: a 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 object-time address of memory to be returned address of size of memory to be returned (in words) On return, the status is one of the following: o 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 RUNT 1M UUO; that result is the time returned by RNT.) The arguments are: arg 1 arg 2 undefined (contains address return) ignored 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 1 arg 2 arg 3 undefined (address of SIXBIT device on return) undefined (address of SIXBIT 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: o successful return error 1 This function tells the overlay handler which file to read initial RUN command. after CBC (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: o RRS (13) WRS (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: a 1 3 RPG 15. successful not enough memory available illegal argument (16) FUNCTION - This function returns memory obtained by The arguments are the same as for FUNCTION 7, ROT. arg 1 arg 2 FUNCTION address of memory to be returned address of size of memory to be returned (in words) On return, the status is one of the following: a 1 3 successful return of memory was not allocated illegal argument 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 level number address of interrupt routine (if the FORTRAN program is running on a system that supports extended addressing, the interrupt routine address may be a 30-bit address in any section, including section O. Otherwise, the interrupt address must be an IS-bit address.) On return, the status is one of the following: a 1 2 3 allocated OK (arg 1 is the channel number sent) requested channel was already assigned no free channels argument 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 channel number to return On return, the status is one of the following: a 1 3 OK channel was not allocated argument error 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. lS-35 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) arg 1 first page number to allocate. in the range 0 to 777. arg 2 number of pages to allocate The page number must be On return, the status is one of the following: o successful allocation of all given pages one or more pages were already allocated illegal argument (bad page number or count) 1 3 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: o successful deallocation of all given pages one or more pages was not allocated by MPG illegal argument (bad page number or count) 1 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 O. FOROTS determines if the device specified is a disk. a disk, the following happens: If the device is if a file with file FOROTS determines exists the • 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 INQUIRE 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 specifiers 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 file 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='SEQUENTIAL' (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 with the full (expanded) file string given in the INQUIRE statement. The file exists if the following is true: • An OPEN has been executed with STATUS other 'UNKNOWN' or ACCESS other than 'SEQUENTIAL'. • An I/O transfer statement has been executed. than If neither of these two comparisions are successful, FOROTS returns the current 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 return the smallest unit number for which there is a match. For non-disk devices specified in the INQUIRE statement file string specification, FOROTS looks at all the FORTRAN logical units for which there is a connection in ascending order, starting with zero. If the device in the file string specified in the INQUIRE statement is not the user's controlling terminal, FOROTS expands the file specification given in the INQUIRE statement by translating a logical name given as the device into its corresponding physical name. It then compares the device part of this expanded file specification with the device part of the full (expanded) 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 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) 18.9 USEROPEN PROCEDURES The USEROPEN keyword in a FORTRAN OPEN statement (see Section 11.3.39) provides a way to access RMS-20 facilities that are otherwise not available to FORTRAN programs. The USEROPEN keyword specifies a user-written external procedure controls the opening of a file. It has the form: that USEROPEN = procedure-name where procedure-name is the symbolic name of a user-written function. The procedure must be declared in an EXTERNAL statement (see Section 7.6) • When an OPEN statement (wi th or wi thout the USEROPEN keyword) is executed on an RMS file, FOROTS uses the OPEN statement keywords to establish the RMS File Access Block (FAB), the Record Access Block (RAB), and optionally one or more Extended Argument Blocks (XABs). If a USEROPEN keyword is included in the OPEN statement, FOROTS establishes defaults for some of the data structure fields, then calls your USEROPEN routine instead of opening the file according to its normal defaults. The USEROPEN routine can then provide additional parameters to RMS, as well as read values from the FAB, RAB, and XABs as returned by RMS. FOROTS will call a USEROPEN routine following form: xM: with an argument list of the can perform the -3, ,0 IFIW TP%INT,address of unit IFIW TP%LBL,address of FAB IFIW TP%LBL,address of RAB Using these arguments, the following operations: USEROPEN routine then 1. Modify the FAB/RAB or XAB(s). 2. Issue the $OPEN or $CREATE RMS service calls (depending on whether the file exists or is to be created), followed by the $CONNECT RMS service call to prepare the file for record I/O. (Required) 3. Check the status indicators returned by RMS after each of the above service calls. Your procedure should return immediately with the RMS error code in AC0 if RMS returns a failure status. (Required) 4. Read file attribute information returned by RMS to RAB, or XAB(s). (Optional) 5. Return a success or failure status value in AC0 must be zero on success. (Requi red) 18.9.1 (Optional) AC0 the to FAB, FOROTS. Example of a USEROPEN The following example shows a FORTRAN OPEN statement calling a USEROPEN routine UOPN, which changes the default "No duplicate" attribute for the primary index in an indexed file. FORTRAN-10/20 VII 18-38 February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) EXTERNAL UOPN OPEN (UNIT=l,FILE='IDX.DAT' ,ORGANIZATION='INDEXED', 1 STATUS='NEW' ,KEY=(1:10) ,RECL=40, 1 USEROPEN=UOPN) A USEROPEN routine may cause a first-time invocation of RMS. To ensure that RMS is invoked compatibly with FOROTS, the following code must be placed in all USEROPEN and MACRO routines that may invoke RMS: SEARCH RMSINJ iRMS/dynamic library universal file .REQUIRE SYS:RMSZER .REQUIRE SYS:RTLZNM .REQUIRE SYS:ZERBOO .REQUIRE SYS:DYNBOO iDynamic library boot-strap files The following function UOPN creates an RMS indexed file after setting the FLG XAB field in the primary index XAB to allow duplicate primary keys: TITLE UOPN SEARCH RMSINJ,MACSYM,MONSYM INTERN UOPN .REQUIRE SYS:RMSZER .REQUIRE SYS:RTLZER .REQUIRE SYS:ZERBOO .REQUIRE SYS:DYNBOO STDAC. iStandard AC definitions T0==0 UOPN: XMOVEI MOVX $STORE Tl,@1(16) T2,FB$SUP T2,FOP,«Tl» iGet FAB address i Get "Supersede existing" bit i Set in FAB $FETCH MOVX $STORE Tl,XAB,«Tl» T2,XB$DUP T2,FLG,«Tl» iGet address of 1st XAB in chain iGet "allow dupe" bit ;Set in XAB $CREATE @1(16) T2,ER$MIN CAlL BADRET JRST ;Create the file ;Error? iYes $CONNECT @2(16) CAlL T2,ER$MIN JRST BADRET ;CONNECT RAB iError? iYes SETZ POPJ T2, P, ;Return success T0,T2 P, ;Return error code in AC0 BADRET: MOVE POPJ END UOPN To allow an existing file to be superseded with a higher generation, the routine first turns on the FB$SUP bit in the FAB. It then fetches the address of the first XAB in the XAB chain (in this case the only XAB) and sets the XB$DUP bit in the FLG field to allow duplicate primary keys (the RMS/FOROTS default is to disallow duplicate primary keys) • FORTRAN-10/20 VII 18-39 February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) For local RMS indexed files, the XAB field of the FAB will always point to the first key XAB in any XAB chain. For all remote files, the XAB field of the FAB points to a CONFIG XAB containing network system information; the NXT field of the CONFIG XAB will point to the start of the key XAB chain. Refer to the RMS-20 programmer's Reference Manual and the TOPS-20 RMS User's Guide for more information of RMS data structures. 18.9.2 RMS/FOROTS Data and Control Structures When RMS is invoked to access a file on a particular unit, FOROTS allocates and initializes the following RMS data structures for each such uni t: • FAB - File Access Block • RAB - Record Access Block • XAB - Extended Attribute Block. the file is indexed or remote. One or more are allocated if In addition, a statically allocated NAM and TYP block are linked to unit's FAB block during OPEN processing. a Values in these control structures are set or defaulted by FORTRAN as described below. In addition, RMS may update these control structures with information derived from the file after it is opened. Unless an error intervenes, these data structures are not deallocated until the unit is closed. User-written subroutines and USEROPEN functions may alter or examine field values in these structures, but they must not alter their allocation. Caution should be exercised when changing fields that have been set as a result of FORTRAN keywords (such as MRS or FAC values), since unpredictable results may occur during subsequent I/O. In general, if a desired value can be obtained through the use of a FORTRAN keyword, use the keyword. The following RMS FAB, RAB and XAB fields are either initialized by FORTRAN and/or examined upon return from an RMS service call. Fields not listed here take the RMS defaults, or are returned by RMS. FAB FIELDS Field Name FORTRAN OPEN keyword/value F$BSZ Bytesize n if BYTESIZE=n; else TOPS-20, 8 for VMS files F$CTX Context Reserved for Digital F$FAC File access Set at OPEN depending on STATUS, ACCESS and READONLY or SHARED keywords. Set to FB$GET for read else access files; to FB$GET+FB$PUT+FB$DEL+FB$UPD+FB$TRN FB$BRO files FORTRAN-10/20 VII 18-40 also for remote .., for non-RMS February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) FILE= filename + DEFAULTFILE= file name if present, else FORnn.DAT if neither given F$FNA File specification string address F$FOP File-processing options FB$SUP Supersede Set at OPEN depending on STATUS and ACCESS keywords FB$DLT Delete on close Set at CLOSE depending on DISPOSE keyword in OPEN or CLOSE, or STATUS keyword in CLOSE FB$SPL Spool to printer Set at CLOSE depending on DISPOSE keyword in OPEN or CLOSE, or STATUS keyword in CLOSE FB$SCF Submit command Set at CLOSE depending on DISPOSE keyword in OPEN or CLOSE, or STATUS keyword in CLOSE F$MRS Maximum record size For RMS files, set to RECORDSIZE=n; else to 0 n if F$MRN Maximum record number For RM.8 files, set MAXREC=n; else to 0 n if F$NAM Name block address Set to address of name block; both the expanded and resultant string areas are set up F$TYP Type block address Set to address of type block for remote non-RMS files. T$CLA is set to TY$IMA F$ORG File organization FB$IDX if ORGANIZATION='INDEXED' FB$REL if ORGANIZATION='RELATIVE' FB$SEQ if ORGANIZATION='SEQUENTIAL' or omi tted F$RAT Record attributes to FB$BLK Do not cross page boundaries I if NOSPANBLOCKS F$RFM Record format FB$FIX if RECORDTYPE='FIXED' FB$VAR if RECORDTYPE='VARIABLE' FB$STM if RECORDTYPE='STREAM' FB$FIX if no RECORDTYPE and ORGANIZATION is 'RELATIVE' or 'INDEXED' F$SHR File sharing FB$PUT Allow other FB$GET Allow other FB$DEL Allow other FB$UPD Allow other FORTRAN-10/20 VII PUTs GETs DELETEs UPDATEs I I I I if if if if 18-41 SHARED SHARED SHARED SHARED February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) F$XAB o if the file is not indexed or Extended attribute not remote. contains the XAB, whose beginning of any. For contains the key XAB. is For all remote files, address of a CONFIG N$NXT points to the the key XAB chain, if local indexed files, address of the first RAB FIELDS Field Name FORTRAN OPEN keyword/value R$BKT Bucket code Set to n processing R$CTX Context Reserved for DIGITAL R$FAB FAB address Set to block R$KBF Key buffer address Set to address of record number if ACCESS='DIRECT' or address of key data if ACCESS='KEYED' R$KRF Key of reference Set to key of reference for indexed files R$KSZ Key size Set to files R$MBF Multibuffer count n if BUFFERCOUNT=n, else 0 R$RAC Record access mode RB$KEY cKEYED' during address size if of remote non-RMS file argument of key for indexed ACCESS='DIRECT' or RB$SEQ if ACCESS='SEQUENTIAL', 'APPEND' or ACCESS is omitted. RB$BLK for remote non-RMS files R$RBF Record buffer address R$ROP Record-processing options Set during READ or WRITE RB$EOF End-of-file RB$KGE Key .GE. RB$KGT Key .GT. I R$RSZ Record size Set during READ and WRITE R$UBF User record area Set during READ and WRITE address R$USZ User record area size Set during READ and WRITE FORTRAN-10/20 VII if ACCESS='APPEND' If indexed READ If indexed READ 18-42 February 1987 USING THE FORTRAN OBJECT TIME SYSTEM (FOROTS) The following KEY XAB fields are set by FORTRAN for indexed files: XAB FIELDS Field Name FORTRAN OPEN keyword/value X$DTP Key datatype XB$STG if CHARACTER (default); else XB$IN4 if INTEGER X$FLG Key options flags XB$DUPIXB$CHG index X$REF Key of reference Set depending on OPEN KEY= position of key specifier X$POS Key position From OPEN KEY= specifier X$SIZ Key size From OPEN KEY= specifier X$NXT Link address Address of next XAB in chain, or 0 FORTRAN-10/20 VII 18-43 for each secondary February 1987 CHAPTER 19 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-10 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 RTINIT CONECT RTSTRT 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-t ime constant (RTDEVN) in the FORRTF source. The DIGITAL-distributed software has RTDEVN equal to 2, but it can be changed (up to 6) by editing the statement "RTDEVN==2" in FORRTF.MAC and reassembling. The error messages output by FORRTF 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 the job's CPU specification. If the specification indicates more than 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. There are two types of block mode: fast-block mode and normal-block 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 DECsystern-l0 Hardware Reference Manual. 19-2 USING THE FORTRAN REAL-TIME SOFTWARE (TOPS-IO 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-IO 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 iDdividual 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 1 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-lO 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 counts as another real-time device.) trpadr 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 between 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. devic~. 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 (see RTINIT). mode is either: -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-IO ONLY) The form of the BLKRW subroutine is: CALL BLKRW (unit, count, blkadr) where: unit is the real-time device unit number (see RTINIT). count is the number of words to be read or written. blkadr is the array into which the data is to from which it is to be read. 19.3.6 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 real-time device unit number (see RTINIT). datadr is the address of the location in which data read. 19.3.7 to store the RTWRIT RTWRIT sends a single word of data to a mode. real-time device in single The form of the RTWRIT subroutine is: CALL RTWRIT (unit, datadr) where: unit is the real-time device unit number (see RTINIT). datadr is the location of the data word device. 19.3.8 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-10 ONLY) where: unit is the real-time device unit number (see RTINIT). statadr is the location of the word of status bits to to the real-time device. 19.3.9 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 OISCON DISCON disconnects a real-time device from its PI level. All devices should be disconnected through calls to DISCON before the job is terminated. The form of the DISCON subroutine is: CALL DISCON (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 message 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 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" 2 ?RTINIT MUST BE CALLED BEFORE CONECT CONECT 3 ?CONECT MUST BE CALLED BEFORE RTSTRT OR BLKRW RTSTRT,BLKRW 1 A ?REAL TIME BLOCK OUT OF BOUNDS ?END OF BLOCK TOO HIGH BLKRW [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 AVATLABLE FOR LOCKING 5 A B ?APR ERROR AT INTERRUPT LEVEL ?PDL OVERFLOW ?ILLEGAL MEMORY REFERENCE 6 A B 7 A B C D E o 1 8 A B LOCK ?RTTRP ERROR realtime trap error of the followi ng so r t ?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 19-8 DISCON CONECT LOCK APPENDIX A SUMMARY OF FORTRAN STATEMENTS FORTRAN statements and This appendix summarizes the forms of all provides a section reference where each statement is described in detail. Section Reference Form ACCEPT(FMT=f{,END=s][,ERR=s][,IOSTAT=ios]) [iolist] ACCEPT(FMT=*[,END=s ][,ERR=s][,IOSTAT=ios]) [iolist] ACCEPT f{,iolist] ACCEPT *[,iolist] Section 10.8 ASSIGN s to i Section 8.3 BACKFILE un BACKFILE(UNIT=un[,ERR=][,IOSTAT=ios]) BACKFILE(un[,ERR=s][,IOSTAT=ios]) Section 11.8.8 BACKSPACE un BACKSPACE(UNIT=un[,ERR=s][,IOSTAT=ios]) BACKSPACE(un[,ERR=s][,IOSTAT=ios]) Section 11.8.4 BLOCK DATA [sub] Section 13.1 CALL sub [( [a1 [,a2] ... ])J Section 13.4.2.2 CHARACTER [*len[,J] v[*len] [,v[*lenJ] Section 7.2.2 CLOSE (closelist) Section 10.16 COMMON [![cbJl]n~ist[[,]/[cb]/nlist] ... Section 7.4 COMPLEX v [,v ... ] Section 7.2 CONTINUE Section 9.4 DATA nlist/clist/ [[,]nlist/clist/] ... Section 7.9 DECODE(c,f,a[,ERR=s][,IOSTAT=i'os]) [iolist] Section 10.12 DELETE(UNIT=un[,ERR=s ][,IOSTAT=ios]) DELETE( un[,ERR=s][,IOSTAT=ios]) DELETE(UNIT=un,REC=rn[,ERR=s][,IOSTAT=ios J) DELETE( un,REC=rn[,ERR=s ][,IOSTAT=ios J) DELETE( un'rn [,ERR=s][,IOSTAT=iosJ) Section 10.13 DIMENSION a(d) [,a(d) ... ] Section 7.1 DO s[,] i=el,e2[,e3] Section 9.3.1 . DO s[,] WHILE(e) Section 9.3.2 Section 7.2 DOUBLE PRECISION v[,v ... ] FORTRAN-10/20 VII A-I February 1987 SUMMARY OF FORTRAN STATEMENTS Form Section Reference ELSE Section 9.2.4 ELSE IF (e) THEN Section 9.2.4 ENCODE(c,f,a[,ERR=s][,IOSTAT=iosj)[iolist] Section 10.12 END Section 9.7 END DO Section 9.4 END IF Section 9.2.4 ENDFILE un ENDFILE(UNIT=un[,ERR=s][,IOSTAT=iosj) ENDFILE(un[,ERR=s][,IOST AT=iosj) Section 11.8.5 ENTRY en [(dl [,d2 ... ])] Section 13.4.3 EQUIVALENCE (nlist) [,(nlist) ... ] Section 7.5 EXTERNAL proc [,proc] ... Section 7.6 FIND(UNIT=un,REC=rn[,ERR=s][,IOSTAT=iosj) FIND(un'rn[,ERR=s][,IOSTAT=ios ]) Section 11.8.1 FORMAT (fs) Section 12.1.1 fun ([argl,arg2, ... argnj) Section 13.3.4 [typ] FUNCTION fun ([argl [,arg2] ... j) 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 ... ])[,type (a[,a ... ]) ... IMPLICIT NONE Section 7.3 INQUIRE(FILE=fl[DEFAULTFILE=dfi][,fiistj) Section 11. 7.1 INQUIRE([UNIT=]u,ulist) Section 11.7.2 INTEGER v [,v ... ] Section 7.2 INTRINSIC fun[,fun] Section 7.7 LOGICAL v [,v ... ] Section 7.2 NAMELIST /name/list[jname/list] ... Section 12.7 OPEN (openlist) Section 10.14 PARAMETER (p=c[,p=c ... ]) PARAMETER p=c [,p=c ... ] Section 7.8 FORTRAN-10/20 VII A-2 February 1987 SUMMARY OF FORTRAN STATEMENTS Form Section Reference PAUSE [n] Section 9.6 PRINT(FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] PRINT(FMT=* [,ERR=s] [,IOSTAT=ios]) [iolist] PRINT f[,iolist] PRINT *[,iolist] Section 10.10 PROGRAM name Section 6.4.1 PUNCH(FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] PUNCH(FMT=*[,ERR=s][,IOSTAT=ios]) [iolist] PUNCH f[,iolist] PUNCH *[,iolist] Section 10.11 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] READ (UNIT=un,FMT=*[,END=s ][,ERR=s][,IOSTAT=ios]) [iolist] READ ( un,FMT=*[,END=s ][,ERR=s][,IOSTAT=iosj)[iolist] READ( un, *[,END=s][,ERR=s][,IOSTAT=ios])[iolist] READ (UNIT=un,FMT=name[,END=s] [,ERR=s] [,lOST AT=ios]) READ ( un,FMT=name[,END=s][,ERR=s][,IOSTAT=ios]) READ( un, name[,END=s][,ERR=s][,IOSTAT=ios]) READ f[,iolist] READ *[,iolistj READ (UNIT=*,FMT=f[,END=s ][,ERR=s][,IOSTAT=ios])[iolist] READ(UNIT=*,FMT=*[,END=s] [,ERR=s][,IOSTAT=ios]) [iolist] READ(UNIT=un[,END=s] [,ERR=s] [,IOSTAT=ios]) [iolist] READ ( un[,END=s][,ERR=s][;IOSTAT=ios]) [iolist] 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][,IOSTAT=ios]) [iolist] READ ( un'rn,FMT=f [,ERR=s][,IOSTAT=ios]) [iolist] READ ( un'rn, f [,ERR=s][,IOSTAT=iosj)[iolist] READ(UNIT=un,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] READ ( un,REC=rn[,ERR=s][,IOSTAT=iosj)[iolist] READ ( un'rn [,ERR=s][,IOSTAT=ios])[iolist] READ(UNIT=un,FMT=f,key=val[,KEYID=kn] [,ERR=s][,IOSTAT=ios])[iolist] READ(un, FMT=f,key=val[,KEYID=kn] [,ERR=s][,IOSTAT=ios]) [iolist] READ( un, f,key=val[,KEYID=kn ][,ERR=s][,IOSTAT=ios]) [iolist] READ (UNIT=un,key=val[,KEYID=kn] [,ERR=s] [,lOST AT=ios]) [iolist] READ ( un,key=val[,KEYID=kn][,ERR=s][,IOSTAT=ios]) [iolist] Section 10.5 REAL v [,v ... ] Section 7.2 REREAD (FMT=f[,END=s ][,ERR=s][,IOSTAT=ios)) [iolist] REREAD (FMT=* [,END=s][,ERR=s][,IOSTAT=ios]) [iolist] REREAD f[,iolist] REREAD *[,iolist] Section 10.7 RETURN [e) Section 13.4.4 REWIND un REWIND(UNIT=un[,ERR=s][,IOSTAT=ios)) REWIND (un[,ERR=s] [,IOSTAT=ios]) Section 11.8.2 REWRITE(UNIT=un,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] REWRITE( un, f[,ERR=s][,IOSTAT=ios]) [iolist] REWRITE(UNIT=un[,ERR=s] [,IOSTAT=ios]) [iolist] REWRITE( un[,ERR=s ][,IOSTAT=ios]) [iolist] Section 10.14 SAVE [a[,a] ... ] Section 7.10 SKIPFILE un SKIPFILE(UNIT=un[,ERR=s][,IOSTAT=ios)) SKIPFILE(un[,ERR=s][,IOSTAT=ios]) Section 11.8.7 FORTRAN-10/20 VII A-3 February 1987 SUMMARY OF FORTRAN STATEMENTS Section Reference Form SKIPRECORD un SKIPRECORD(UNIT=un[,ERR=s ][,IOSTAT=ios]) SKIPRECORD(un[,ERR=s][,IOSTAT=ios]) Section 11.8.6 STOP [n] Section 9.5 SUBROUTINE sub [([d1 [,d2] ... ])] Section 13.4.2.1 TYPE(FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] TYPE(FMT=*[,ERR=s][,IOSTAT=ios])[iolist] TYPE f[,iolist] TYPE *[,iolist] Section 10.9 v=e Section 8.2 UNLOAD un UNLOAD(UNIT""lln[,ERR=s][,IOSTAT=ios]) UNLOAD(un[,ERR=s][,IOSTAT=ios]) Section 11.8.3 UNLOCK(UNIT=un[,ERR=s][,IOSTAT=ios]) UNLOCK( un[,ERR=s][,IOSTA T=ios]) UNLOCK un Section 10.15 WRITE(UNIT=un,FMT=f[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE( un,FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un, f[,ERR=s][,IOSTA T=ios]) [iolist] WRITE(UNIT=un,FMT=*[,ERR=s][,IOSTAT=ios])[iolist] WRITE( un,FMT=*[,ERR-=s][,IOSTAT=ios]) [iolist] WRITE( un, *[,ERR=s][,IOSTAT=ios])[iolist] WRITE(UNIT=un,FMT=name[,ERR=s] [,IOSTAT=ios]) WRITE( un,FMT=name[,ERR=s][,IOSTAT=ios]) WRITE( un, name[,ERR=s][,IOSTAT=ios]) WRITE f[,iolist] WRITE *[,iolist] Section 10.6 WRITE(UNIT=* ,FMT=f[,ERR=s][,IOSTAT=ios]) [iolist] WRITE(UNIT=*,FMT=*[,ERR=s][,IOSTAT=ios]) [iolist] WRITE(UNIT=un[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un[,ERR=s][,IOSTA T=ios]) [iolist] WRITE(UNIT=un,FMT=f,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un,FMT=f,REC=rn[,ERR=s][,IOSTAT=ios]) [iolist] WRITE( un, f,REC=rn[,ERR=s][,IOSTAT=ios])[iolist] WRITE( un'rn,FMT=f, [,ERR=s][,IOSTAT=ios])[iolist] WRITE ( un'rn, f, [,ERR-s][,IOSTAT=ios]) [iolist] WRITE(UNIT=un;REC=rn[,ERR=s] [,IOSTAT=ios]) [iolist] WRITE( un,REC=rn[,ERR=s ][,IOSTAT=ios]) [iolist] WRITE( un'rn [,ERR=s][,IOSTAT=ios])[iolist] FORTRAN-10/20 V11 A-4 February 1987 APPENDIX 8 ASCII-1968 CHARACTER CODE SET The character code set defined in the X3.4-1968 Version of the American National Standard for Information Interchange (ASCII) is given in this appendix. 8-1 ASCII-1968 CHARACTER CODE SET ASCII CODE Control Characters Even Parity Bit 7-Bit Decimal 7-Bit Octal 0 000 000 NUL 001 001 SOH CC Start of heading [SaM, start of message] . Control A. 002 002 STX CC Start of text [EOA, end of address] . Control B. 0 003 003 ETX CC End of text [EOM, end of message] . Control C. 1 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 are you?"]. Triggers identification ("Here is ... ") at remote station if so equipped. Control E. CC Acknowledge [RU, "Are you ... ?"]. Control F. 0 Character Class· Remarks Null, tape feed. Control @ (control shift p 2). 006 006 ACK 007 007 BEL 008 010 BS FE Backspace. Control H. 0 009 011 FE Horizontal tabulation. Control I. 0 010 012 FE Line feed. Control J. 1 011 013 HT LF3 VT 3 FE Vertical tabulation. Control K. 0 012 014 FF3 FE Form feed (to top of next page). Control L. 013 015 CR FE Carriage return (to beginning of line). Control M. 014 016 so Bell (audible or attention signal). Control G. Shift out; change character set or change ribbon color to red. Control N. 0 015 017 SI 1 016 020 DLE Shift in; return to standard character set or color. Control O. 0 017 021 DCI Device control 1, turns transmitter (reader) on. Control Q (X ON). 0 018 022 DC2 Device control 2, turns punch or auxiliary on. Control R (TAPE, AUXON). 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 (--rAPE-, AUX OFF). 021 025 NAK CC Negative acknowledge [ERR, error]. Control U. 1 022 026 SYN CC Synchronous idle [SYNC]. Control V. CC CC Data link escape [DCO]. Control P. 0 023 027 ETB 0 024 030 CAN End of transmission block [LEM, logical end of medium] . Control W. 025 031 EM End of medium [S.]. Control Y. 1 026 032 SUB Substitute [S2]' Control Z. 0 027 033 ESC Escape, prefix [S3]' Control [(control shift K2). File separator [S 4] . Control \ (control shift L2). Cancel [So], Control X. 1 028 034 FS IS 0 029 035 GS IS 0 030 036 RS IS Group separator [Ss]' Control] (control shift M2). Record separator [S 6] . Control (control shift N2 ). 031 037 US IS Unit separator [S71. Control- (control shift 0 2). A 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 Even Even Parity 7-Bit 7-Bit Bit Decimal Octal Character 032 040 SP 1 033 041 o /I 034 042 o 035 043 # $ 036 044 o 045 037 1 % 1 038 046 & o 047 039 040 050 o 041 051 052 1 042 * 043 053 o + 044 054 045 o 055 046 o 056 057 1 047 / (/)1 048 060 o 049 061 1 050 2 062 051 063 3 o 4 052 064 1 053 065 5 o 054 6 066 o 055 067 7 070 8 1 056 057 9 071 o 058 072 o 1 059 073 074 060 o < 075 061 076 062 > 063 077 o Parity 7-Bit 7-Bit Bit Decimal Octal Character 064 100 @ 1 065 101 A o 066 B 102 o 1 067 C 103 068 D 104 o E 069 105 1 F 070 106 071 o G 107 H o 072 110 073 111 I 1 074 J 112 o 075 K 113 076 114 L 077 o M 115 078 N o 116 079 1 117 a p 080 o 120 Parity 7-Bit 7-Bit Bit Decimal Octal Character 3 o 096 140 ,2 1 o 1 o o 1 o o o 1 o 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 121 122 123 124 125 126 127 130 131 132 133 134 135 136 137 1 o 1 o o 1 o o 1 o o 1 Q o R S T U V o W o x o 1 o y z [ o \2 1 ] o ,,2 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 f g h j k 1 m n a p q u v w x y z { I }4 ",,2,5 DEL6 1 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 set 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 used 175 as the escape code and translated both 176 and 033 to it. 4Unassigned control character (usually ALT MODE) before 1965. Code generated by ALT MODE key on some DEC units, especially earlier ones; on some more recent 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 of lower case set). B-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. & (a) \ Ampersand. Circumflex, upward arrow head. t before 1965, but used until 1972 on DEC units. Underline, underscore.- before 1965, but used until 1972 on DEC units. Closing parenthesis. Asterisk. Plus. Grave accent, opening single quotation mark. (w 1965-67, but never on DEC units. Opening brace. Comma, cedilla. 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. Hyphen, minus. Period, decimal point. Slant, slash, solidus. Closing brace. Unassigned control (usually ALT MODE) before 1965. Colon. character Overline, tilde, general accent. Control charafter ESC before 1965; I 1965-67, but never on DEC units. Semicolon. < Reverse slant. ~ 1965-67, but never on DEC units. Shift Lon LT33, LT35 and similar units. Closing bracket. Shift M on LT33, LT35 and similar units. Opening parenthesis. * 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 two types of messages: warning and fatal error. While compiling the program, 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 produced. Compiler messages are printed in the following form: ?FTNxxx LINE:n text or %FTNxxx LINE:n flag: text where: ? % FTN xxx Line:n text flag: 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 the error occurred is the explanation of error 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 following: • Extension to Fortran-77: • VMS incompatibility: • Fortran-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 Fa tal Er ro rs 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 512P. 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 larg~ 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] file COMPILER MESSAGES CQL No closing quote in character constant CSA Can't split string across numeric and character variables 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] is duplicate dummy argument formal name illegal Duplicate fields specification. DIA reduce nesting 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 be values is not DNL Implied DO variables DPR Dummy parameter [name] DSF Argument [name] DTI The dimensions of [arrayname] must be of the type integer 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] backwards FEE Found [symbol] associated list of referenced before definition is same as FUNCTION name EQUIVALENCE-d to COMMON is illegal in SAVE into COMMON twice [filespec] when expecting either [symbol] or [symbol] General syntax error message. C-3 a COMPILER MESSAGES FER [file error text] An error has specification. occured when processing a command FlO Can't initialize character function name FNE Label [number] must refer to a statement FWE Found [symbol] when expecting [symbol] lAC Illegal ASCII character [character] in source IAL Incorrect argument type for library function [name] 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 [character] ICN Illegal combination of character and numeric data ION DO loop at line: [number] FORMAT, not an file executable in label field is illegally nested 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 lOT Illegal or misspelled data type IDV Implied DO index is not a variable lED 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 IFS Illegal format specifier 110 Non-integer implied DO index lIP Illegal implicit specification parameter lIS Incorrect INCLUDE switch ILF Illegal statement after logical IF open the symbolic specified Refer to Section 9.2.2 for restrictions on logical IF object statements. IND Improper nesting: DO at line [number] has not terminated C-4 COMPILER MESSAGES INI Improper nesting: INN INCLUDE statements may not be nested IOC Illegal operator for 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 UNIT nor FILE keywords were specified ISD Illegal subscript expression in DATA statement IF at line [number] has not terminated both UNIT and FILE keywords were specified Subscript expressions may be formed only indexes and constants combined with +, ISN [symbolname] with implicit DO *, or /. is not [symbol type] The symbol cannot be used in the attempted manner. ISS [var iable] ITL Illegal transfer into loop to label [number] 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] 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 [number] LED Illegal list directed [statement type] LFA Label arguments illegal in FUNCTION or array reference LGB Lower bound greater than upper bound for array [name] LLS Label too large or too small same specifier size modifier [number] already 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] - error code [GETSEG error code] 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 COMPILER MESSAGES OBO [variable] may only be specified once OPW OPEN/CLOSE parameter [name] OUB Only upper bound of last dimension asterisk PD6 FORTRAN will not run 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 DECsystem-IO file DECSYSTEM-20. . of [arrayname] may specifications PRF Pro t e c t ion fa i I u r e [ n urn b e r ] [ f i I e s pe c ] PTL Program too large be on the real or The program unit takes up more than 512P. QEF Quota exceeded or disk full [number] [filespec] RDE Rib or directory error [number] RFC [function name] is a recursive function call 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] statements may not be labeled SOR Subscript out of range STD Sta temen t [number] TDO [symbol type] type declaration out of order 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 [filespec] the is a declaration 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 ina relational other than EO 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 DII 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 DPE VMS incompatibility: Different precedence in exponentiation DWE Fortran-77 and VMS: [descriptor] DWL Extension to Fortran-77: DO without statement label DXB DATA statement exceeds bounds of array [name] EDD Extension to Fortran-77: END DO statement EDS Extension to Fortran-77: DECODE statement EDS Extension to Fortran-77: ENCODE statement 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: Format 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 widths with [function name] C-9 edit descriptor 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 [keyword name] LID Identifier [name] more than six characters The remaining characters are ignored. LNC Fortran-77 and VMS: Non-numeric operand in numeric context LNE VMS incompatibility: 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-logical operand in logical context NLK Extension to Fortran-77: Use of NAMELIST NOD Global optimization not supported with /DEBUG - /OPT ignored 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 Logical and [data type] numeric variables length specifier [variable] must be explicitly declared Numeric No C-ll greater expression parentheses index than] in to around the character computed 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 (i) 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] SSC 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 (I) [symbolic name] in dimension bound - statement is the same as use colon (:) [symbolic name] program instead subscr i pt with is the same as NAMELIST statement out of order [symbolic 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 a VGF VMS incompa ti b i 1 i ty: on VMS [funct i on name] is a VIF VMS incompatibility: function on VMS [function VND FUNCTION return value is never defined VNF VMS incompatibility: function on VMS [function name] VNG VMS incompatibility: function on VMS [func t ion VNI Opt - variable [name] Fortran-supplied gener ic function an intrinsic is name] is not is name] an not intrinsic 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 [subroutine name] VSD VMS incompatibility: Subroutine [subroutine name] may differ WDU Fortran-77 and VMS: WRITE with default unit WNA Wrong number of arguments for statement function WOP Opt - warnings given in Phase incorrect 1. is not a VMS-supplied 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 desired. XCR Extraneous carriage return Carriage return was not immediately preceded or followed a line termination character. [* or &] XEN Fortran-77 and VMS: XOR Extension to Fortran-77: Logical .XOR. operator ZMT Size modifier [number] by with external name 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 error 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-lO: 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) - 6. Device errors (DEV) - 7. Compatibility errors compatibility flagger 8. RMS-returned errors - (APR) - errors errors generated by OPEN in numer ic FORLIB library errors in data conversion on I/O I/O hardware errors (COM) - generated errors by the errors returned by RMS-20 to FOROTS The messages generated by FOROTS contain the following elements: 1. A 3-letter code that identifies the type of message onl y) 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. 5. what on the (TOPS-10 FOROTS has compatibility For RMS errors, the RMS STS and STV codes, where available, are included in the error message itself, and can be retrieved by the ERRSNS subroutine. FORTRAN-10/20 VII D-l February 1987 FOROTS ERROR MESSAGES ,The 3-letter code (TOPS-10 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. When an RMS-detected error occurs, the second ERRSNS value contains the STS code from RMS (a number between 300000 and 377777 octal). The STV code, which further amplifies the reason for an RMS error, is available to your program through an additional argument to the ERRSNS subroutine. For instructions on how to use the ERRSNS subroutine, see Section 13.4.1.15.) Table D-I contains a list of all the 3-letter message ERRSNS values that are generated by FOROTS. FORTRAN-10/20 VII D-2 codes and the February 1987 FOROTS ERROR MESSAGES Table D-l: 1st Value o FOROTS Error Codes 2nd Value(S) Meaning Code(l) No error detected No error detected o n (7) IDC (3) Arithmetic trap Integer divide check n (7) 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 FUN (3) 1 2 3 4 5 6 (3) Input Conversion Error Floating underflow 7 9 (7) o FTS (3) 104 IDU 105 106 UNO NOF 107 CWU 108 CLE 109 ICE 110 NCS 112 AQS 113 115 SSE SRE TMA 116 CGP 117 CRP (1) 118 NSS (2) 119 120 121 CFS (2) CGS (2) CPP (3) output Conversion Error Output field width too small 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 No character stack allocated 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 21 114 (3) (3) D-3 February 1987 FOROTS ERROR MESSAGES Table D-l: 1st Value FOROTS Error Codes (Cont'd) 2nd Va1ue(5) Code (1) Meaning 122 123 IPN CCS 124 ECS 125 ALZ 126 DMA (2,3) 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 509 ETL (3) 532 583 ARC (3) FVM (3) 584 RIF (3) 590 DQW (2,3) 22 23 I/O warnings At tempt 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 (3) SRE (3) bounds check FORLIB warnings Substring range error Subscript range error -1 EOF End of file End of file 24 25 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 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 302 510 BBF RNR 512 517 IRN RTL 536 CBI 536 CSI 570 ICD 572 RSM 573 FCL 576 WBA 577 SLN 502 CSF (2,3) 535 BSI (3) 26 D-4 OPEN/CLOSE warnings Can't set FORTRAN carriage control attribute BLOCKSIZE ignored: device is not a maqnetic tape February 1987 FOROTS ERROR MESSAGES Table D-l: 1st Value FOROTS Error Codes (Cont.) 2nd Value(5) Code (1) Meaning 541 UOA (3 ) 542 NCK (3) 550 588 CQF (1,3) BSC (2,3) 595 OGX (1,3) 609 NNI(1,3) Unknown keyword, OPEN igno red OPEN-only keyword specified in CLOSE, ignored Cannot QUEUE file Bytesize in OPEN different from FDB, FDB value used Galaxy version not 2 supported Node name ignored J J 250+n 250+n 250+n 610 CLS RNM CLS DEL RNM UDO J APP (2 ) J 240 UOF (2 ) FRR 240 RR1 240 RRR 242 243 NFC (1 ) CIR 244 RLB 245 246 NSD FBR 247 BLZ 248 lAC 249 IDM 250+n 405 OPN ( 1) PPN (2 ) 503 CEF (2 ) 506 540 ICA SDO 569 TFM 585 IAV 28 CLOSE error Cannot CLOSE file Cannot RENAME file " Close" FILOP. error n ( 4 ) "Delete" FILOP. error n (4 ) "Rename" FILOP. error n (4) Unsupported /DISPOSE option for RMS files (2) (2 ) (1 ) (1 ) (1 ) (2 ) 30 FORTRAN-10/20 VII OPEN error Cannot set up to append to magnetic tape file USEROPEN failed /RECORDTYPE:FIXED requires /RECORDSIZE Random requires I/O RECORDSIZE specifier in OPEN statement Random requires I/O /RECORDSIZE Too many OPEN units /CARRIAGECONTROL:TRANSLATED illegal this with /RECORDTYPE larger than /RECORDSIZE /BLOCKSIZE No such device BLOCKSIZE must be specified for RECORDTYPE='FIXED' integral BLOCKSIZE must be multiple of RECL Specified ACCESS illegal for this device is Specified MODE illegal for this device Cannot OPEN file JSYS error - PPN cannot be translated End of command file encountered Incompatible attributes Same device open on another unit conflicting with specifiers Tape format conflicts with OPEN statement or default Illegal value for OPEN specifier D-5 February 1987 FOROTS ERROR MESSAGES Table D-1: 1st Value FOROTS Error Codes (Cont.) 2nd Va1ue(5) Cod e (1) Meaning 600 ATC (2) 601 URT (2) 602 603 604 URS (2) BME (2) MEU (2) 606 607 608 KER (2) TKS (2) RMS (2) 611 DFR (2) 612 KDB (2) 613 RIR (2) 615 RNA (2) File's attribute different from that specified in OPEN RECORDTYPE value not supported for this file type Unsupported remote system Bytesize must be 8 Missing EXTERNAL for USEROPEN routine Missing required KEY= Too many KEY= specifiers RMS file requries ORGANIZATION= Default /RECORDTYPE:FIXED requires /RECORDSIZE KEY datatype CHARACTER conflicts with BYTESIZE New RELATIVE or INDEXED file requires /RECL RMS not available on SYS: 315 CDR 315 CDS 593 POI 594 CDF 605 KRI(2) 614 SIF(2) 239 IUN 321 CFC (3) 322 CFF (3) 323 CFR (2,3) 323 CFX (2,3) 323 CFR (I, 3) 323 CFX (1,3) 324 CFK (3) 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 Can't do keyed I/O to this file type Statement illegal for this type of access 32 Illegal logical unit number Illegal unit number 33 FORTRAN-10/20 VII D-6 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-10 supplied routine invoked FORTRAN-77 and VMS: FORTRAN-10 supplied routine invoked FORTRAN-77 and VMS: Keyword [keyword] February 1987 FOROTS ERROR MESSAGES Table D-l: 1st Value FOROTS Error Codes (Cont.) 2nd Value(5) Code.( 1) Meaning 325 CFT (3 ) 326 CFO (3) 327 CFG (3 ) 328 CFD (3 ) and FORTRAN-77 VMS: Trailing spaces in output reco rd FORTRAN-77 extension: Overlap of character assignments and FORTRAN-77: VMS: G format descriptor used with character VMS incompatibility: I Format default width used 310 RBR REREAD error REREAD not proceeded READ 39 45 241 ESV 241 241 533 539 544 USW (1 ) ASW (1 ) DLT EDS/EDA (2) NDI (1 ) 545 546 547 548 IPP TMF NSI IDD 551 NQS (1 ) 263 CDT 554 CWL 301 303 306 ILF 1FT DLF 524 RIC 538 552 553 575 IRC IHC IFW UDT 583 FVF OPEN/CLOSE statement syntax errors Unknown ambiguous or keyword Unknown swi tch Ambiguous switch Dialog string too long Error parsing DIALOG string No device specified with ":" (1 ) (1 ) (1 ) (1 ) Illegal PPN Too many SFDs Null SFD Illegal character in DIALOG str ing PADCHAR must be single character in double quotes 47 WRITE on READ-only file Cannot WRITE to READ-only file Cannot write a file with MODE=LINED 62 FORTRAN-10/20 VII by Syntax error in FORMAT Illegal character in FORMAT Illegal FORMAT Data in I/O list but not in FORMAT Reading into character format illegal Illegal repeat count Illegal Hollerith constant III egal field width Undefined data type or internal FOROTS error Format and variable type do not match D-7 February 1987 FOROTS ERROR MESSAGES Table D-1: 1st Value FOROTS Error Codes (Cont~) 2nd value(5) Code (1) Meaning 307 ILC Input conversion error Illegal character in data 501 508 574 579 581 582 UNS IOL IMV IDI (1) DLL (1) IWI 599 ICE 64 FOROTS calling errors Unit not specified Bad I/O list Illegal MTOP value Illegal DUMP mode I/O list Dump mode I/O list too long Illegal to initiate another I/O statement Illegal length for character expression 81 96 100 I LM (2) UMO (2,3) NLT 101 SLT 102 ALT 530 537 UTE (1)' UTO (1) 537 UTO (1,3) 587 ITE (1) 309 513 VNN NEQ 514 515 NRP ILN 516 519 ILS CCC 521 522 RPE SNV 580 596 NLS NEC 597 ISS 598 SNQ J J 97 FORTRAN-10/20 VII Error in magnetic tape operations Unexpected MTOPR% error (2) Error trying to set tape <statement> not allowed with Labeled Magnetic tape files Input/Output switching not allowed with Labeled Magnetic tape file /ACCESS='APPEND' not allowed with Labeled Magnetic tape files Unexpected TAPOP. error Unexpected TAPOP. error trying to set parameters Unexpected TAPOP. error trying to set parameters Tape is not usable by your job 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 when Found character expecting ":" Substring descriptor ill egal String not within single quotes D-8 February 1987 FOROTS ERROR MESSAGES Table D-l: 1st Value FOROTS Error Codes (Cont.) 2nd Val ue (5) Code (1) Meaning ISW IOE OSW ISW OSW IOE MFU DQE 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 98 J J J 250+n 250+n 400 586 590 (2) (2) (2) (1 ) (1 ) (1 ) (2 ) No ERRSNS values BLK (3 ,6) CCP CDP CGD DBM DST EFS FFX (1 ,6) (1,6) (6) (6 ) (1 ,6) (6) (6) IEM IJE MFU NOR PAG (6) (2,6) (6) (3,6) (3 ,6) PGD (6) POV (6) SNH (6 ) TDT (6 ) Blocks allocated but not deallocated Cannot create page Cannot destroy page Can't get DBMS DBMS not loaded Error in dialog string 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 (1) TOPS-10 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-10 Monitor Calls Manual FILOP. error codes and their meanings. (5) "J" means the TOPS-20 JSYS error code. be between 600000 and 610000 (octal). for the of This number will (6) No ERRSNS values (7) Where n is the number of times the error occurs D-9 list FOROTS ERROR MESSAGES 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, ~EAD, 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 returns one or two integer values that describe the status of the last I/O operation performed by FOROTS. (The second integer value is opt ional .) Fo r exampl e, CALL ERRSNS (I,J) calls this subroutine. D.l J, the second integer value, is optional. 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. ALT? /ACCESS='APPEND' not allowed with Labeled Magnetic tape files Cause: You specified ACCESS='APPEND' in an OPEN statement when using a labeled magnetic tape file. This is not allowed. Recovery: Change the OPEN statement. ERRSNS values: ALZ? First Value = 96 Second Val ue 102 Argument less than or equal to zero Cause: An argument (such as a memory size) was specified a value less than or equal to zero. with Recovery: Specify the correct value for the argument. ERRSNS values: APP? only) First Value = 21 Can't setup to append to magtape Cause: Second Value = 125 file <JSYS error> (TOPS-20 The MTOPR% JSYS failed trying to position the tape with the function .MOFWF or .MOBKR. magnetic Recovery: Use the information provided to determine a recovery. ERRSNS values: FORTRAN-10/20 VII First Value = 30 D-10 Second Value = JSYS error number February 1987 FOROTS ERROR MESSAGES AQS? First argument to SORT -must be a quoted string Cause: The SORT routine detected that the first argument was of type CHARACTER, 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 Value 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: ASW? First Value = 22 Ambiguous switch /<sw> Cause: Second Value = 532 (TOPS-10 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: First Value 45 ATC? File's <attribute> conflicts with (TOPS-20 only) Cause: Second Value OPEN statement 241 or default You opened an RMS file with RECORDTYPE= or ORGANIZATION= attributes in your OPEN statement, which conflict with the actual attributes of the file. Recovery: Specify the correct attributes, or omit them from to use the file's attributes. ERRSNS values: BBF? First Value = 30 OPEN Second Value = 600 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.24) ERRSNS values: FORTRAN-10/20 VII First Value 25 D-11 Second Value data {See 302 February 1987 FOROTS ERROR MESSAGES BLK % Pages allocated but not deallocated Cause: Internal FOROTS error in memory management. Recovery: Submit an SPR and include your program. BLZ? BLOCKSIZE must be integral multiple of RECL Cause: You specified a BLOCKSIZE in an OPEN statement that was not a multiple of the RECORDSIZE you specified when using magnetic tape files. Recovery: Change the BLOCKSIZE value to RECORDSIZE. ERRSNS values: BME? First Value 30 be a multiple Second Value of the 247 Bytesize must be eight (TOPS-20 only) Cause: You specified a BYTESIZE= other than 8 when accessing a VMS RMS file. Recovery: Change BYTESIZE=, or omit the specifier to default files to 8. ERRSNS values: First Value 30 Second Value VMS 603 BSC % Bytesize in OPEN different from FOB, FOB value used Cause: You specified a BYTESIZE= value in OPEN that was different than the one in the File Descriptor Block (FOB). The FOB value ,.is used. Recovery: If FOB value is correct, do not specify a BYTESIZE value in OPEN, else specify BYTESIZE value in OPEN. ERRSNS values: First Value = 26 BSI % Blocksize ignored: Cause: device is not a magnetic tape 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? Second Value = 588 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.~3). Otherwise, the BACKSPACE cannot be done. ERRSNS values: FORTRAN-10/20 VII First Value = 25 0-12 Second Value = 536 February 1987 FOROTS ERROR MESSAGES CCC? Can't convert constant to correct type Cause: In NAMELIST input, a variable was assigned a value that does not match. For example, if C is a complex variable, the input: 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> Cause: CCS? First Value = 97 (PAGE. Second Value = 519 error <n» (TOPS-10 only) FOROTS attempted to use a page of memory for some task, but was unable 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. Not enough memory for creating character stack Cause: A character stack was requested that was larger than 36 sections (larger that the maximum virtual memory available) • Recovery: Specify correct call argument. ERRSNS values: COF? 124 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 First Value Can't destroy page <n> Cause: COR? Second Value Can't determine whether formatted or unformatted Cause: COP? First Value = 21 (PAGE. error <n» with the same FORM= 594 (TOPS-10 only) FOROTS attempted to use a page of memory for some task, but was unable 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 sequential file Cause: An attempt was made to perform I/O to already open in a conflicting mode. Recovery: a file Second Value 315 that is Open file in the appropriate mode. ERRSNS values: First Value = 31 0-13 February 1987 FOROTS ERROR MESSAGES CDS? Can't do sequential I/O to direct file Cause: An attempt was made to perform I/O to a already open in a conflicting mode. Recovery: Open file is the appropriate mode. ERRSNS values: CDT? First Value = 31 Second Value file that is 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? First Value 47 Second Value 263 End of command file encountered (TOPS-20 only) Cause: An indirect file was specified as and the end of the file was terminator character (line-feed). a DIALOG argument, encountered before a Recovery: Edit the file and insert a line-feed. ERRSNS values: First Value = 30 CFC % Fortran-77 and VMS: Cause: Second Value = 503 Carriage control character A carriage-control character was used that incompatible with ANSI FORTRAN and VAX FORTRAN. Recovery: If you want the program to be compatible FORTRAN or VAX FORTRAN, use a carriage-control character. ERRSNS values: First Value = 33 CFD % VMS incompatibility: Cause: is wi th ANSI compatible Second Value = 321 I format default width used A format descriptor was used with a default width is incompatible with VAX FORTRAN. that Recovery: If you want your program to be compatible with VAX FORTRAN, then do not default the width of this edit descriptor. ERRSNS values: FORTRAN-10/20 VI) First Value 33 D-14 Second Value 328 February 1987 FOROTS ERROR MESSAGES CFF % VMS incompatibility: Cause: Intrinsic routine invoked incompatibly 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, chang~ to a method of invoking intrinsic routines that is compatible with VAX. ERRSNS values: First Value = 33 Second Value 322 CFG % Fortran-77 and VMS: G format descriptor used with character Cause: 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: Cause: 33 Second Value 327 Keyword [keyword] An OPEN or CLOSE keyword was used that is with ANSI FORTRAN and VAX FORTRAN. incompatible 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: Cause: Second Value = 324 Overlap of character assignments 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 referenced 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-10 onl y) Cause: First Value = 33 Second Value 326 extension: FORTRAN-20 supplied routine invoked extension: FORTRAN-l 0 supplied routine invoked A FORTRAN-10/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: First Value = 33 D-15 Second Val ue to ANSI 323 February 1987 FOROTS ERROR MESSAGES CFS? Can't find SYS:SORT.EXE Cause: <JSYS error> (TOPS-20 only) The file SORT.EXE cannot be found on SYS:. A supplied error message will give more detail. Recovery: Use the information provided by the determine the proper course of action. ERRSNS values: First Value = 21 CFT % Fortran-77 and VMS: Cause: monitor monitor to Second Value = 119 Trailing spaces in output record Your program contains a FORMAT that specifies trailing blanks (X format and $ format). In this case, FORTRAN-10/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 onl y) FORTRAN-10 supplied routine invoked (TOPS-10 CFX % Fortan-77 and VMS: only) Cause: A FORTRAN-10/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 Cause: Second Value = 116 <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: First Value = 21 0-16 Second Value monitor to 120 February 1987 FOROTS ERROR MESSAGES CIR? /CARRIAGECONTROL:TRANSLATED illegal with this /RECORDTYPE Cause: You specified CARRIAGECONTROL='TRANSLATED', which not allowed for the RECORDTYPE you specified. is Recovery: Change the OPEN statement. ERRSNS values: CLE? First Value = 30 Second Val ue 243 Concatenation result larger than expected Cause: The specified substring bounds are out of range. Recovery: Specify legal substring bounds. ERRSNS values: CLS? First Value = 21 Second Value 108 CLOSE failed, <I/O error message> (TOPS-10 only) Cause: A CLOSE UUO. or FILOP. CLOSE function failed. Recovery: Use the information provided to determine a recovery. ERRSNS values: First Value = 28 Second Value = 250+n CPP % Can't preallocate pages 600:677 for SORT Cause: A call to preallocate allocated. the SRTINI subroutine was SORT's pages because they unable to were already Recovery: Decrease the size of your program. Having fewer files open or using a BUFFERCOUNT=l specifier in the OPEN statement may help (see Section 11.3.5). ERRSNS values: First Value = 21 CQF % Can't queue file: Cause: Second Value QUEUE. UUO ERROR <N> (TOPS-10 only) This error may occur when executing a CLOSE statement in which the DISPOSE 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-10 Monitor Calls Manual explanation of the QUEUE. error number <n>. ERRSNS values: CRP? 121 First Value = 26 Second Value for an = 550 Can't return pages 600:677 after call to SORT (TOPS-10 only) Cause: Before the SORT subroutine returns to the user, it tries to deallocate the pages that the SORT program resides in. The pages could not be deallocated. This is not expected to occur. Recovery: Submit an SPR. ERRSNS values: First Value 21 D-17 Second Value 117 February 1987 FOROTS ERROR MESSAGES CSF % Can't set FORTRAN carriage control attribute (TOPS-20 only) Cause: 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.33) 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.24.) 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. 0-18 February 1987 FOROTS ERROR MESSAGES DEL? Can't delete file:<FILOP. Cause: error message> (TOPS-10 only) The "DELETE" FILOP. failed. 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: DFR? First Value 28 Second Value 250+n Default RECORDTYPE:FIXED requires /RECORDSIZE (TOPS-20 only) Cause: You attempted to create a new RMS relative or indexed file with a default /RECORDTYPE of FIXED, but did not specify /RECOROSIZE. Recovery: Specify /RECORDSIZE. ERRSNS values: First Value = 30 Second Value 611 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: tix 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? First Value = 62 Second Value 306 DUMP mode I/O list too long (TOPS-10 only) Cause: The I/O list specified 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) Cause: 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: FORTRAN-10/20 VII First Value = 21 D-19 Second Value = 126 February 1987 FOROTS ERROR MESSAGES DQE? Disk full or quota exceeded Cause: The disk quota for the disk on which a file is being written is exhausted, 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, the user is requested to type an EXPUNGE command and then a CONTINUE command. Recovery: EXPUNGE or create structure. ERRSNS values: more First Value = 98 room on the specified Second Value disk 590 DQW % Disk full or quota exceeded - please EXPUNGE, then type CONTINUE (TOPS-20 only) Cause: 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 Second Value 590 DSS % DISPOSE='SAVE' assumed - device is not a disk Cause: A DISPOSE value other than 'SAVE' was specified for a file on a device other than disk. (See Section 11.3.15.) ERRSNS values: DST? Fi rst Val ue 26 Second Value = 549 Error in dialog string (TOPS-10 only) Cause: 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. Recovery: Use a shorter ERRSNS values: is strin~. First Value = 45 0-20 Second Value 533 February 1987 FOROTS ERROR MESSAGES ECS? Not enough memory for expanding character stack More memory than is available on a KL10 was requested by either a dynamic concatenation (concatenation of character variables of length*) or by a call to the ALCCHR subroutine. Cause: 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? First value 21 Second Value = 124 Error in DIALOG string - <message> (TOPS-20 only) Cause: A syntax error in the DIALOG= specifier. 11.5.3.) (See Section Recovery: Retype the specifier correctly in DIALOG mode. ERRSNS values: First Value = 45 Second Value = 539 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-10 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: An input statement has attempted to read more data than the file contains. Recovery: Use an END= specifi~r lengthen the file. ERRSNS values: ESV? First value 24 in the READ Second Value statement, or -1 <unknown/ambiguous> keyword value /<switch>:<value> (TOPS-20 only) Cause: A switch entered in dialog mode was not was not specified uniquely. recognized or Recovery: Retype the line, specifying the correct switch. ERRSNS values: First Value = 45 D-2l Second Value = 241 February 1987 FOROTS ERROR MESSAGES 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: FBR? First Value = 22 Second Value = 509 BLOCKSIZE must be specified for RECORDTYPE='FIXED' Cause: For magnetic tape files, a RECORDTYPE='FIXED' specified, and no BLOCKSIZE value was specified. was Recovery: If you specify RECORDTYPE='FIXED' for magnetic tapes, you must specify a BLOCKSIZE, which must be a multiple of the RECORDSIZE. ERRSNS values: FCL? Second Value First Value = 30 246 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) specification in statement. ERRSNS values: Seco'nd Val ue First Value = 25 the OPEN 573 FDC % Floating divide check Cause: 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 is within Second Value = 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. FORTRAN-10/20 VII February 1987 FOROTS ERROR MESSAGES 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: = 3 or 4 Second Value = n First Value where n is the number of times the error occurs FRR? /RECORDTYPE:FIXED requries /RECORDSIZE Cause: A RECORDTYPE='FIXED' was specified in an OPEN statement without a RECORDSIZE (RECL) specifier. Recovery: Specify RECL 11.3.33) • ERRSNS values: in the First Value 30 OPEN statement (see Second Value 240 Section FTS % Output field width too small Cause: 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 =0 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 D-23 February 1987 FOROTS ERROR MESSAGES FVF? Format and variable type do not match Cause: 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 data character Second Value = 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? Second Value 583 /ACCESS illegal for this device Cause: An attempt was made to OPEN a device for access specified (or implied) is illegal. which the Recovery: Change the ACCESS specifier in the OPEN statement data transfer statement. (See Section 11.3.1.) or ERRSNS values: IAV? First Value = 22 the First Value = 30 Second Value = 248 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 Cause: An illegal combination spec i f i ed. 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 '0' (DELIMITED). The Record Control Word (ReW) contained a non-digit, or the data on the tape is incompatible. Recovery: Specify the correct TAPEFORMAT in the OPEN statement. ERRSNS values: First Value = 25 D-24 Second Value = 570 February 1987 FOROTS ERROR MESSAGES ICE? Illegal length for character expression Cause: 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 0. Recovery: Correct division in program. ERRSNS values: IDD ? First Value = 1 Second Value = n where n is the number of times the error occurs Illegal character <chr> (TOPS-10 only) Cause: An illegal character was encountered in dialog mode. Recovery: Retype the response without illegal characters. ERRSNS values: IDI ? First Value = 45 Second Value = 548 Illegal DUMP mode I/O list (TOPS-10 only) Cause: 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: IDM? First Value = 81 or do not Second Value the 579 /MODE:<mode> illegal for this device Cause: 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.24.) ERRSNS values: IDU? compile DIVERT: Cause: First Value 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: First Value = 21 D-25 Second Value = 104 February 1987 FOROTS ERROR MESSAGES IEM? 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. 1FT? Illegal FORMAT Cause: Your program contains an illegal FORMAT statement. Recovery: Correct FORMAT statement. ERRSNS values: IFW? First Value = 62 Second Value = 303 Illegal field width Cause: An illegal (negative) field width was FORMAT statement. 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 Cause: A format 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 descript~r. Section 12.4.2.) ERRSNS values: IJE? First Value = 62 (See Second Value = 552 "Impossible" JSYS error at <PC) - <JSYS ERROR) (TOPS-20 only) Cause: This is an internal FOROTS error that is not expected to occur. A monitor call failed that was not expected to. A monitor-supplied error message may be of assistance in avoiding the problem. Recovery: Submit an SPR. ILC? Illegal character in data Cause: A format descriptor that nonnumeric character. requires a number found a Recovery: Fix the input data or FORMAT statement. ERRSNS values: FORTRAN-10/20 VII First Value = 64 0-26 Second Value = 307 February 1987 FOROTS ERROR MESSAGES ILF? Illegal character in format Cause: ILM? A format specification contains defined meaning. a character Recovery: Correct the error in the program. format ERRSNS values: Second Value First Value 62 list no rerun the operation that and 301 Unexpected MTOPR% ERROR (TOPS-20 only) Cause: An error was encountered during a file FOROTS did not expect. Recovery: This type of error should not happen. SPR. ERRSNS values: ILN? with First Value 96 Please submit an Second Value JSYS error number Variable or namelist does not start with letter Cause: 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 legal NAMELIST name. (See Section 12.6.) ERRSNS values: ILS? Second Value or 515 Illegal subscript Cause: In NAMELIST I/O, an illegal subscript was given for array. ERRSNS values: IMV? First Value = 97 variable First Value 97 Second Value an 516 Illegal MTOP value Cause: 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 <10 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 Value = 98 Second Value = 400 (TOPS-10) JSYS error number (TOPS-20) D-27 February 1987 FOROTS ERROR MESSAGES IOL? Bad format IO list Cause: The code generated by the compiler for an I/O list is by this version of FOROTS. The not understood This erroneous entry in the I/O list is ignored. probably indicates an internal error in the compiler or in FOROTS. Recovery: Locate the problem area of the I/O it. First Value ERRSNS values: 81 list and Second Value 508 simplify IOV % Integer overflow Cause: An attempt was made to read data that was out of for an integer variable. ERRSNS values: IPP? =2 First Value range Second Value = 0 Illegal PPN (TOPS-10 only) Cause: A directory specification starts with something that is not a legal PPN specification. The forms of legal PPNs are: [n,n], [n,], [,n], or [,] where n represents a 1- to 6-digit octal number. Recovery: Use a legal directory specification. ERRSNS values: IPN? Second Value First Value = 45 545 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? = 21 First Value Second Value 122 Illegal repeat count Cause: An illegal statement. repeat count was given in FORMAT a Recovery: Correct the FORMAT statement. ERRSNS values: IRN? First Value = 62 Second Value 538 Illegal record number <n> Cause: 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: First Value = 25 D-28 Second Value = 512 February 1987 FOROTS ERROR MESSAGES ISS? 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-10) JSYS error number (TOPS-20) ITE? Tape is not usable by your job (TOPS-10 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: IUN? First Value = 96 Second Value 587 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 = 32 Illegal to initiate < I/O stat~ment) Cause: 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: First Value 81 0-29 Second Value or 582 February 1987 FOROTS ERROR'MESSAGES KDB? KEY datatype CHARACTER conflicts with BYTESIZE (TOPS-20 only) Cause: You specified or defaulted a KEY= CHARACTER, but specified a BYTESIZE (TOPS-20 file) or 8 (VMS file). datatype to not equal to 7 Recovery: Specify correct BYTESIZE or omit to use system default. ERRSNS values: KER? First Value = 30 Second Value = 612 New indexed file requires KEY= (TOPS-20 only) Cause: You attempted to create a new RMS indexed file specifying a primary index. without Recovery: Specify one or more KEY= specifiers in your OPEN. ERRSNS values: KRI? First Value = 30 Second Value = 606 Can't do keyed I/O to <sequential/relative> file (TOPS-20 only) Cause: You attempted a keyed (indexed) sequential or relative file. READ to an RMS Recovery: Correct the invalid READ statement in the program. ERRSNS values: First Value = 31 MEU? Missing EXTERNAL declaration in (TOPS-20 only) a call to USEROPEN routine Cause: You specified a USEROPEN routine but did not declare it EXTERNAL in the program. Recovery: Supply the EXTERNAL declaration. ERRSNS values: MFU? Second Value = 605 First Value = 30 Second Value = 604 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=1 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). FORTRAN-10/20 VII D-30 February 1987 FOROTS ERROR MESSAGES NCA? No memory available for character stack Cause: For non-overlay programs, this message indicates that the memory manager has allocated all available space between the user's low segment and FOROTS. For overlay programs, this messages indicates that /SPACE:0 has been specified 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 Second Value NCK % <keyword> in CLOSE is meaningless Cause: NCS? = III ignored Options have been included in the CLOSE statement are meaningless for closing the file. Recovery: Use valid CLOSE options. (See Section 11.5.) ERRSNS values: Second Value First Value = 26 No character stack allocated Cause: that = 542 compiler error An internal compiler error has occurred. Recovery: Submit an SPR. ERRSNS values: NDI? No device specified with ":" Cause: Second Value = 110 (TOPS-10 only) An OPEN statement has specified a null device name. ERRSNS values: NEC? First Value = 21 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? First Value = 97 Found "<chr>" when expecting Cause: Second Value = 596 "=" NAMELIST input found an illegal character in a that requires an equal sign. context Recovery: Replace illegal character with equal sign. ERRSNS values: First Value = 97 D-3l Second Value = 513 February 1987 FOROTS ERROR MESSAGES NFC? Too many open units (TOPS-10 only) Cause: On TOPS-10 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 Val ue 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: NLT? First Value = 97 Second Value = 580 <statement> not allowed with Labeled Magnetic tape files Cause: When using labeled magnetic tape files, you used a BACKSPACE or ENDFILE statement in your program, which is no tall owed. Recovery: Remove any BACKSPACE or ENDFILE program. ERRSNS values: First Value = 96 statements from your Second Value = 100 NNI % Node name ignored (TOPS-10 only) Cause: Remote file access is not supported on TOPS-10. Recovery: Omit the node specification from the filespec. ERRSNS values: NQS? Second Value = 609 PADCHAR must be single char in double quotes (TOPS-10 only) Cause: In dialog mode, the PADCHAR specifier must be by the pad character in double quotes. ERRSNS values: NRP? First Value = 26 First Value = 45 followed Second Value = 551 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: FORTRAN-10/20 VII Fi rst Val ue 97 D-32 Second Value = 514 February 1987 FOROTS ERROR MESSAGES NSD? No such device <dev> Cause: The specified device does not exist. Recovery: Change the device name to one that does exist. ERRSNS values: NSI? Second Value = 245 Null SFD (TOPS-10 only) Cause: A directory specification contains a null SFD. ERRSNS values: NSS? First Value = 30 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 extended addressing. There are no free sections available. simple is not should Recovery: There are 31 sections normally available when a FORTRAN program runs. If your application trying to use extended addressing, this error not occur, and you should submit an SPR. ERRSNS values: First Value = 21 Second Value = 118 OGX % Galaxy version 2 not supported (TOPS-10 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 upgrade to the 595 Can't OPEN file Cause: The specified file could not be opened. The reason given is taken from the monitor error code (see the TOPS-10 Monitor Calls Manual). ERRSNS values: OSW? First Value = 26 to FILOP. Cause: First Value = 30 Second Value = 250+n 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-10) JSYS error number (TOPS-20) D-33 February 1987 FOROTS ERROR MESSAGES PAG % Pages allocated but not deallocated Cause: 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. ERRSNS values: PPN? = 31 First Value 593 <JSYS error> (TOPS-20 only) Cause: 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 First Value = 30 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: RLB? First Value = 39 Second Value = 310 /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: First Value = 30 0-34 or specify Second Value = 244 February 1987 FOROTS ERROR MESSAGES RIC? Reading into character format illegal Cause: An attempt was made to READ into a character format. Recovery: Correct program to avoid this construct. READ into a character variable and use this variable (perhaps concatenated with other character expressions) for a modifiable format. ERRSNS values: First Value 62 Second Value 524 RIF % Reading into FORMAT nonstandard 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-10/20. Recovery: READ into character variables and use (perhaps concatenated with character constants) as the FORMAT. ERRSNS values: RIR? only) New RELATIVE or INDEXED file Second Value = 584 requires /RECORDSIZE (TOPS-20 Cause: You tried to create (STATUS='NEW') an RMS relative indexed file without specifying a record length. Recovery: Specify /RECORDSIZE. ERRSNS values: RMS? First Value = 22 First Value = 30 or Second Value = 613 RMS file requires ORGANIZATION in OPEN statement (TOPS-20 only) Cause: The OPEN statement did not specify an RMS file by means of ORGANIZATION=, but the file you tried to open is an RMS file. Recovery: Supply an ORGANIZATION attribute. ERRSNS values: RNA? First Value = 30 Second Value 608 RMS not available on SYS: Cause: Your program tried to invoke RMS (an OPEN specified a remote or RMS file, or an INQUIRE-by-file specified a remote file) when RMS is not available on your system. Recovery: Make sure your system supports RMS V3 and/or RMSFAL VI. ERRSNS values: FORTRAN-10/20 VII First Value = 30 D-35 Second Value = 615 February 1987 FOROTS ERROR MESSAGES RNM? 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-10) JSYS error number (TOPS-20) RNR? Record <n> has not been written Cause: In direct-access input, an attempt was made to read a record that was never written. This may indicate the use of an incorrect record number. Recovery: Make sure you are requesting the correct record. ERRSNS values: RPE? First Value = 25 Second Value = 510 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: RRl? First Value = 97 Second Value 521 Random I/b 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.33.) ERRSNS values: RRR? First Value = 30 Second Value = 240 Random 10 requires /RECORDSIZE Cause: An OPEN statement was attempted that specified ACCESS=DIRECT(RANDOM) with no record size specified Recovery: Specify a record size. ERRSNS values: First Value = 30 D-36 Second Value 240 February 1987 FOROTS ERROR MESSAGES RSM? Record size different from that specified Cause: 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 Cause: 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: SIF? First Value = 30 Second Value 540 <statement> illegal for this file type or access (TOPS-20 only) Cause: Your program attempted to execute a statement that is legal only for RMS files on a non-RMS file; or a file-positioning, DELETE, UNLOCK or REWRITE statement was attempted on an RMS file when either /ACCESS or /ORGANIZATION does not permit the operation. Recovery: Correct the invalid statement in the program. ERRSNS values: SLN? First Value = 31 Second Value = 614 Record length negative or zero Cause: 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: SLT? files First Value = 25 Input/Output switching not allowed with Labeled Cause: Magnetic tape Your program attempted to switch between input output when using labeled magnetic tape files. and Recovery: Don't switch input magnetic tape files. ERRSNS values: SNH? Second Value = 577 First Value and = 96 output when using labeled Second Value = 101 Internal FOROTS error at <PC> Cause: This error is not expected to occur. consistency check has found a bug. An internal Recovery: Please submit an SPR if you get this message. FORTRAN-10/20 VII D-37 February 1987 FOROTS ERROR MESSAGES SNQ? String not within single quotes Cause: A character data item read as list-directed or NAMELIST input is not enclosed in single quotes. Recovery: Enclose character data item in single quotes. ERRSNS values: SNV? First Value = 97 Second Value = 598 Sign with null value Cause: List-directed or NAMELIST input contains a + or not followed by a value. sign Recovery: Correct the input and try again. ERRSNS values: First Value = 97 Second Value SRE % Subscript range error - subscript <n> of array <n> Cause: 522 <name> on line An illegal subscript or range has been specified for an array reference. Recovery: Specify a legal array reference. ERRSNS values: First Value = 23 Second Value = 114 SSE % substring range error <var(bound» Cause: 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: TKS? First Value 30 Second Value = 569 Too many KEY specifiers (TOPS-20 only) Cause: RMS allows a maximum of file. 255 indexes for an indexed Recovery: Reduce the number of KEY= specifiers. ERRSNS values: FORTRAN-10/20 VII First Value = 30 0-38 Second Value = 607 February 1987 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? First Value = 21 Second Value constant, or 115 Too many SFDs (TOPS-10 only) Cause: A directory specification contains more than five SFDs. Recovery: Specify the correct directory. ERRSNS values: UDO? First Value = 45 Second Value Unsupported /DISPOSE:<option> for Cause: 546 RMS files (TOPS-20 only) A PRINT, LIST, PUNCH, SUBMIT or PLOT was specified for a TOPS-20 RMS file; or PUNCH or PLOT specified for a VMS RMS file. Recovery: Correct the specifier. ERRSNS values: UDT? First Value = 28 Second Value 610 Undefined data type or internal FOROTS error Cause: Internal FOROTS error. Recovery: Submit an SPR. ERRSNS values: UME? First Value Second Value 62 575 Unexpected MTCHR error <n> (TOPS-10 only) Cause: 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. Recove~y: Submit an SPR. ERRSNS values: First Value = 96 Second Value = 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: FORTRAN-10/20 VII First Value = 96 D-39 a drive that Second Value supports the JSYS error number February 1987 FOROTS ERROR MESSAGES UNO? DIVERT: Cause: unit <n> is not open The file to which error messages are diverted opened for output before DIVERT is called. must be Recovery: Open the file for output before calling DIVERT. ERRSNS values: UNS? First Value = 21 Second Value = 105 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. The keyword is ignored. Recovery: Make sure you are using the correct compiler, FORLIB, and FOROTS. ERRSNS values: UOF? First Value = 26 versions Second Value of the = 541 USEROPEN failed Cause: An RMS service call in a USEROPEN procedure has failed. Recovery: Examine the STS and STV error values to exact cause. ERRSNS values: URS? contains First Value 30 Second Value determine the JSYS error number Unsupported remote system (TOPS-20 only) Cause: A remote file access specified a remote system that neither TOPS-20 or VMS. is Recovery: Specify a TOPS-20 or VMS node. ERRSNS values: URT? only) First Value = 30 Recordtype <type> not supported for Cause: Second Value this file 602 type (TOPS-20 /RECORDTYPE:STREAM was specified for a TOPS-20 RMS file; or RMS returned a recordtype other than STREAM, VARIABLE or FIXED for an existing remote file. Recovery: Correct the invalid /RECORDTYPE. ERRSNS Values: FORTRAN-10/20 VII First Value = 30 D-40 Second Value 601 February 1987 FOROTS ERROR MESSAGES USW? Unknown switch /<sw> (TOPS-10 only) Cause: In dialog mode, an unknown switch was specified. Recovery: Retype the line, specifying the correct switch. ERRSNS values: UTE? First Value = 45 Second Value = 241 Unexpected TAPOP error <n> (TOPS-10 only) Cause: 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 = 530 96 UTO % Unexpected TAPOP. error <n> trying to set mode/blocksize> (TOPS-10 only) Cause: 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? <density/parity/data First Value = 96 a drive that supports the Second Value = 537 Variable <var> not in namelist Cause: NAMELIST input contains an assignment that is not in the namelist. to a variable Recovery: Correct the input and try again. ERRSNS values: WBA? First Value = 97 Second Value 309 Attempt to WRITE beyond variable or array Cause: 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 within 25 Second Value = 576 D-41 limits of character February 1987 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 text where: ? % FDT xxx text indicates a fatal message indicates a warning message is the FORDDT mnemonic is the 3-letter mnemonic for error message 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 character was detected in an octal input value. CCN Cannot continue A pause has been placed on some form of causing FORDDT to loop; should never FORTRAN-compiled programs. CFO skip instruction be encountered in Core file overflow The storage area for GROUP text has been exhausted. CNU The command [name] is not unique More letters of the command are required to from the other commands. E-l distinguish it INTERACTIVE DEBUGGER (FORDDT) ERROR MESSAGES CSH 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 FOR DDT 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 INTERACTIVE DEBUGGER (FORDDT) ERROR MESSAGES IWI 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 (on TOPS-20 or some other input) • LGU [array name] 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] multi-level array definition not allowed or is not a FORMAT statement DEBUG switch to type a FORMAT The same array cannot be dimensioned more than once (by means of the [dimensions] construct) in a single command. MSN More subscripts needed The array is defined to have more specified in the given reference. NAL dimensions than were Not allowed An attempt has been made to modify something other than data or a FORMAT. NAR Not after a 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) ERROR MESSAGES NUD [symbol] not a user-defined array An attempt has been made to remove dimension information for an array that was never defined. PAR Parentheses required, please retype Parentheses are required for the statements and complex constants. PRO specification FORMAT Too many PAUSE requests The PAUSE table has been exhausted. 10. RGR of The maximum limit is 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] size too large An attempt has been made to 256K. TMS define an array larger than Too many subscripts [dimensions] The array is defined to have fewer dimensions specified in the given element reference. URC defined 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 INTERACTIVE DEBUGGER (FORDDT) ERROR MESSAGES IWI 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 processed at this breakpoint. NAA [ s ym b 0 I ] i s no tan a r r ,a y NHF Cannot find help file; I'm sorry I can't help you NSL No symbols loaded FORDDT cannot find the symbol table. NST Not STARTed The specified command requires that a START be previously issued to ensure that the program is properly initialized. POV Program overlayed by [program name] Program overlayed by *** The symbol table is different from the last time FORDDT had control. The program name is printed only if it has changed, otherwise '***' is printed. SCA Supersedes compiled array dimension The FORTRAN generated dimension is being superseded for given array. SPO Variable is single-precision only WSP Writing to shared page XPA Attempt to exceed program area with [symbol name] An attempt has been made to access currently defined program space. E-5 memory outside the 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 draws 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.5.) a NUMBER The NUMBER subroutine causes floating-point plotted as text. (See Section F.6.) PLOT The PLOT subroutine moves the plotter pen to a new position. Raising and lowering the pen is also specified in the PLOT subroutine. (See Section 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.ID.) WHERE The WHERE subroutine reports on the current position of plotter pen. (See Section F.II.) specifies specifies F-I special a the points character set. through 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 octal) consecutive words. Each character table word contains the number of strokes (line segments) for the character in the left half, and the address of the table of strokes in the right half. See Section F.S.l for a description of these tables. Character Tables The next sections describe how to define and organize a character table. The character 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 ASCI 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 described in Sections F.S.l.l and F.S.l.2, respectively. F-S 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 '----v-----I '----v-----I 18 bits 18 bits MR-S-1752-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. x \ J Three 5-bit bytes Figure F-2: Character Stroke Table Entry As shown in Figure F-2, each stroke is stroke table by three 5-bit bytes. three bytes are: Byte 1 MR-S-1753-81 described in the character The possible values for these Value and Meaning a 1 pen is raised (off the paper) pen is lowered (on the paper) 2 x-coordinate ~alue 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 unit 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 characters 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 line 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 8,9 10 ~4 1V V lX N° 11 1V 15 '" 13 Base Line 5 o Figure F-3: 5 MR-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==l iIF 'SEEN' THEN THE STROKE MARKS THE PAPER UNSEEN==O iIF 'UNSEEN' THEN THE STROKE IS INVISIBLE RADIX ~DlO 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,11,SEEN,2,11 BYTE{S) UNSEEN,S,11,SEEN,6,10 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.5.l.4 FORTRAN- and User-Defined Character Sets - The standard ASCII character set is always defined and is character set 1 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 plotted to the right of the decimal point. If ndigit is negative, only the integer part of the number is plotted; the resulting integer is rounded. 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. pen up/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.8 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-SUPPLIED PLOTTER SUBROUTINES where: x is an array name of a one-dimensional floating-point array to be scaled for the AXIS subroutine. n is an integer constant or variable that length of the array 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 array x. The value of xmin will be the value of the scale at the beginning of the axis. dx is a constant or variable that 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 you to select the character set that used to plot characters. 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-ll 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 position 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 centimeters if you have ~metric plotter). 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.II 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 IND.EX A editing, 12-39 ABORT switch, 16-9 ACCEPT sequential list-directed, 10-46 ACCEPT statement, 10-45 sequential FORMAT-statement, 10-45 Access direct, 18-4 sequential, 18-3 ACCESS specifier in INQUIRE, 11-54 in OPEN, 11-7 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 Arguments 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 operators, 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 Assigned variables in FORMAT statements, 12-4 Assignment statement, 8-1 arithmetic, 8-1 character, 8-4 Assignment statement (Cont.) 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-67 BACKSPACE statement, 11-64 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-54 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-11 BYTESIZE specifier in INQUIRE, 11-54 in OPEN, 11-12 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.1 Carriage-control specifiers, 12-9 CARRIAGECONTROL specifier in INQUIRE, 11-54 in OPEN, 11-12 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 Index-I February 1987 Channel allocation routines, 18-30 Channel deal location routines, 18-30 CHAR function, 13-13 Character assignment statement, 8-4 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 statements, 7-6 CHARACTER*len, 7-6 CHKDIV subroutine, 13-28 CLOSE statement, 11-43 exampl es, 11-51 implicit, 11-44 CLOSE statement specifiers, 11-44 DEVICE, 11-46 DIALOG, 11-46 DIALOG=, 11-47 DIRECTORY, 11-46 DISPOSE, 11-47 ERR, 11-49 FILE, 11-46 IOSTAT, 11-49 LIMIT, 11-49 NAME, 11-46 PROTECTION, 11-46 STATUS, 11-50 summary of, 11-45 UNIT, 11-51 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 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-10, 16-2 Running FORTRAN-20, 16-6 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-1 Compiler switches FORTRAN-10, 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 int~ger, 5-5 logical, 5-10 Constant folding, 15-8 Constant propagation, 15-8 Constants, 3-1 bit data, 7-23 character, 3-4 compl ex, 3-4 doub1e-oetal, 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 Creating indexed files, 15-24 CROSSREF switch, 16-3, 16-9 Current-record DELETE, 10-60 Current-record pointer, 15-29 D editing, 12-32 D-floating double-precision format, 3-3 Data access, 10-5 direct, 10-6 keyed, 10-6 sequential, 10-6 Data magnitude on G-format, 12-35 DATA statement, 7-21 Data transfer operations, 10-5 Index-2 February 1987 Data transfer statements, 10-1 summary, 10-3 Data transfers formatted, 10-6, 12-1 unformatted, 10-8 DATA with EXTEND, 16-20 DATE subroutine, 13-29 DEBUG and FORDDT, 17-4 DEBUG arguments, 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-56 Default memory layout /EXTEND, 16-16 DEFAULTFILE specifier in OPEN, 11-14 Deferred OPEN statement, 11-2 DELETE statement, 10-59 current record, ~0-60 direct, 10-60 Deleting records in indexed files, 15-29 DENSITY specifier in OPEN, 11-15 Device assignments logical, 10-12 Device control statements, 10-1, 11-61 DEVICE specifier in CLOSE, 11-46 in OPEN, 11-15 Devices rea1-t ime, 19-1 DFLOATING switch, 16-3, 16-9 DIALOG specifier in CLOSE, 11-46 in OPEN, 11-16 DIALOG= specifier in CLOSE, 11-47 in OPEN, 11-16 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, 18-4 Direct DELETE, 10-60 Direct FORMAT-statement READ, 10-30 Direct FORMAT-statement WRITE, 10-38 DIRECT specifier in INQUIRE, 11-55 Direct unformatted READ, 10-33 Direct unformatted WRITE, 10-41 DIRECTORY specifier in CLOSE, 11-46 in OPEN, 11-17, 11-18 DISCON subroutine, 19-7 DISMIS subroutine, 19-6 DISPOSE specifier in CLOSE, 11-47 in OPEN, 11-19 DIVERT subroutine, 13-30 DO iteration control, 9-12 DO lists implied, 10-25 DO loop extended range, 9-15 DO loop iterations, 15-2.1 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-f1oating, 3-3 G-floating, 3-3 Double-precision numbers range and accuracy, 15-1 DTOG function, 13-19 DTOGA subroutine, 13-30 Dummy arguments, 13-49 length of character, 13-51 DUMP subroutine, 13-30 E (exponential notation), 3-2 E editing, 12-32 ECHO-OPTION switch, 16-9 Edit descriptors FORMAT-statement, 12-6 nonrepeatab1e, 12-8 numer ic, 12-29 repeatable, 12-7 Ed i ti ng 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 numer ic, 12-29 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 Index-3 February 1987 Editing (Cont.) 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-56 END DO statement, 9-17 END IF statement, 9-5 END LSCW, 18-4 END statement, 9-20 END= specifier, 10-18 ENDFILE statement, 11-65 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-49 in INQUIRE, 11-55 in OPEN, 11-20 ERR= specifier, 10-19 Error codes FOROTS, D-3 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, II-55, EXIT subroutine, 13-33 EXPAND switch, 16-3, 16-9 Expressions arithmetic, 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 Expressions (Cont.) relational, 5-11 EXTEND applications with large arrays, 16-17 applications with large code, 16-17 EXTEND arguments, 16-19, 16-20 EXTEND psect placement, 16-18 EXTEND switch, 16-9, 16-16 Extended addressing, 16-16 and EQUIVALENCE, 7-17 and FORDDT, 17-17 default memory layout, 16-16 memory layout, 15-22 Extended attribute block fields, 18-43 Extended attribute block (XAB) , 18-40 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 FAB block, 18-40 fields, 18-40 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 access block fields, 18-40 File access block (FAB), 18-40 File control statements, 10-1, 11-1 File identifier internal, 10-13 File specifications remote, 11-21 FILE specifier in CLOSE, 11-46 in OPEN, 11-20 Files ASCII data, 18-4 binary data, 18-4 internal, 10-8, 10-54 linking TWOSEG REL, 16-21 non-FORTRAN, 15-10 FILESIZE specifier in OPEN, 11-21 FIND statement, 11-62 FLAG arguments, 16-22 FLAG switch, 16-3, 16-21 FLAG switch arguments, 16-22 FLAG-NON-STANDARD switch, 16-9 Index-4 February 1987 Floating-point DO loops, 15-2 FORDDT and extended addressing, 17-17 call i ng, 1 7 -1 7 loading, 17-5 starting, 17-5 FORDDT and DEBUG, 17-4 FORDDT commands~ 17-1, 17-7 FORDDT debugger, 17-1 FORDDT error messages, E-1 FORM specifier in INQUIRE, 11-56 in OPEN, 11-22 Format control, 12-11 Format editing, 12-16 Format list, 12-3 I/O list interaction, 12-11 order and interpretation, 12-5 Format specifications, 12-3 embedded, 12-15 Format specifier, 10-14 FORMAT statement, 12-2 assigned variables in, 12-4 FORMAT-statement ACCEPT sequential, 10-45 FORMAT-statement edit descriptors, 12-6 FORMAT-statement formatting, 10-15, 12-2 FORMAT-statement PRINT sequential, 10-50 FORMAT-statement PUNCH sequential, 10-53 FORMAT-statement READ direct, 10-30 sequential, 10-29 FORMAT-statement REREAD sequential, 10-43 FORMAT-statement TYPE sequential, 10-48 FORMAT-statement WRITE direct, 10-38 sequential, 10-37 Formatted data transfers, 10-6, 12-1 Formatted indexed READ, 10-34 Formatted input, 12-14 Formatted output, 12-15 Formatted READ transfers, 10-29 Formatted REWRITE, 10-61 FORMATTED specifier in INQUIRE, 11-56 Formatted WRITE transfers, 10-37 Formatting FORMAT-statement, 10-15, 12-2 list-directed, 10-16, 12-41 NAMELIST-statement, 10-17, 12-44 FOROTS, 18-1 and INQUIRE by file, 18-36 MACRO calls for, 18-17 RESET in, 15-11 FOROTS (Cont.) sharable, 15-10 using, 18-15 FOROTS calling sequences, 18-16.1 FOROTS entry points, 18-15 FOROTS error codes, D-3 FOROTS error messages, D-l FOROTS error processing, 18-2 FOROTS features, 18-1 FOROTS in~ut/output facility, 18-2.1 FOROTS memory management, 15-20 FOROTS/RMS data and control structures, 18-40 FORRTF subroutine, 19-1 FORTRAN-10 compiler switches, 16-2 running the compiler, 16-2 FORTRAN-10/20, 1-1 FORTRAN-20 compiler switches, 16-9 running the compiler, 16-6 FORTRAN-20 compiler using, 16-5 FORTRAN-77 standard, 1-1 FORTRAN-defined character set, F-9 FORTRAN-supplied external functions, 13-18 FORTRAN-supplied plotter subroutines, F-1 FORTRAN-supplied subroutines, 13-24 Function effects, 15-10 FUNCTION statement, 13-20 Function subprogram, 13-20 restrictions, 13-21 Function subprograms using, 13-21 Functions, 13-1' bit manipulation, 13-14 CBC, 18-34 CDABS, 13-25 CHAR, 13-13 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 ICHAR, 13-13 IFS, 18-34 ILL, 18-32 INDEX, 13-12 Index-5 February 1987 Functions (Cont.) intrinsic, 13-1 LEN, 13-12 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 specific, 13-2 statement, 13-15 TIM2GO, 13-19 UPG, 18-36 user-defined external, 13-20 using intrinsic, 13-2 using statement, 13-16 WRS, 18-34 Functions for overlays, 18-31 G editing, 12-33 G-f10ating 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 ass ig ned, 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 list, 10-23 I/O list and format list interaction, 12-11 ICHAR function, 13-13 IF statement, 9-3 arithmetic, 9-3 IF statement (Cont.) block, 9-5 logical, 9-4 logical two-branch, 9-4 IF THEN statement, 9-5 IFS function, 18-34 ILL function, 18-32 ILL subroutine, 13-34 Implicit CLOSE, 11-44 Implicit OPEN, 11-3 IMPLICIT statements, 7-7 Implied DO lists, 10-25 INCLUDE statement, 6-4 INCLUDE switch, 16-3, 16-9 INDEX function, 13-12 Index variable, 9-11 INDEX with DEBUG, 16-12 Indexed f i 1 es creating, 15-24 defining keys, 11-24 deleting records in, 15-29 reading, 15-28 updating records in, 15-29 us i ng, 15 - 24 writing, 15-26 Indexed .HEAD, 10-33 formatted, 10-34 sequential, 10-34 unformatted, 10-35 Indexed sequential access method, 15-24 . INIOVL in LINK, 15-20 Initial lines, 2-4 Initial tab, 2-3 INITIALIZE specifier in OPEN, 11-21 Input formatted, 12-14 NAMELIST-controlled, 12-45 Input/output facility FOROTS, 18-2.1 Input/output statements, 10-1 INQUIRE by file and FOROTS, 18-36 INQUIRE specifiers ACCESS, 11-54 BLANK, 11-54 BYTESIZE, 11-54 CARRIAGECONTROL, 11-54 DIRECT, 11-55 ERR, 11-55 EXIST, 11-55 FORM, 11-56 FORMATTED, 11-56 IOSTAT, 11-56 KEYED, 11-56 NAME, 11-57 NAMED, 11-58 NEXTREC, 11-58 NUMBER, 11-58 OPENED, 11-58 ORGANIZATION, 11-59 RECL, 11-59 RECORDSIZE, 11-59 Index-6 February 1987 INQUIRE specifiers (Cont.) RECORDTYPE, 11-59 SEQUENTIAL, 11-60 UNFORMATTED, 11-60 INQUIRE statement, 11-52 by file, 11-52 by unit, 11-53 INQUIRE statement specifiers, 11-54 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-8, 10-54 Internal READ statement, 10-55 Internal WRITE statement, 10-55 Intrinsic functions, 13-1 character, 13-12 using, 13-2 INTRINSIC statement, 7-18 Invoking RMS, 11-29 IOSTAT specifier, 10-20 in CLOSE, 11-49 in INQUIRE, 11-56 in OPEN, 11-23 Iteration control DO, 9-12 Key attributes, 10-23 KEY specifier in OPEN, 11-24 Key-fie1d-va1ue specifier, 10-21 Key-of-reference specifier, 10-23 Keyed access, 10-6 KEYED specifier in INQUIRE, 11-56 Keywords, 1-1 L editing, 12-38 Labels compiler generated, 16-23 LABELS with DEBUG, 16-12 Large arrays and extended addressing, 16-17 Large code applications, 16-19 Large executable code and extended addressing, 16-17 LEGAL subroutine, 13-34 LEN function, 13-12 Length of character actual arguments, 13-51 Length of character dummy arguments, 13-51 Length specification, 7-6 LIMIT specifier in CLOSE, 11-49 in OPEN, 11-25 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 overlay facilities, 15-19 LINK overlay handler, 18-31 LINK subroutines, 15-20 Linking TWOSEG REL files, 16-21 List-directed ACCEPT sequential, 10-46 List-directed formatting, 10-16, 12-41 List-directed PRINT sequential, 10-51 List-directed PUNCH sequential, 10-53 List-directed READ sequential, 10-30 List-directed REREAD sequential, 10-44 List-directed TYPE sequential, 10-49 List-directed WRITE sequential, 10-39 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 LSNGET function, 13-19 MACHINE-CODE switch, 16-10 MACRO calls for FOROTS, 18-17 MACROCODE switch, 16-3 MAXREC specifier in OPEN, 11-25 Memory allocation routines, 18-29 Memory layout extended addressing, 15-22 Memory management FOROTS, 15-20 Index-7 February 1987 Memory management (Cont.) overlay, 15-20 Message summary, 16-34 Messages compiler, C-1 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-26 MPG function, 18-35 Multi-statement lines, 2-5 MVBITS subroutine, 13-35 .NOT. logical operator, 5-8 NOVMS with FLAG, 16-22 NOWARN arguments, 16-15 NOWARN switch, 16-3, 16-10, 16-15 NUMBER specifier in INQUIRE, 11-58 NUMBER subroutine, F-9 Numeric edit descriptors, 12-29 Numeric editing, 12-29 Numeric type specification statements, 7-5 NAME specifier in CLOSE, 11-46 in INQUIRE, 11-57 in OPEN, 11-28 NAMED specifier in INQUIRE, 11-58 NAMELIST statement, 12-44 NAMELIST-contro11ed input, 12-45 NAMELIST-contro11ed output, 12-46 NAMELIST-statement formatting, 10-17, 12-44 NAMELIST-statement READ sequential, 10-31 NAMELIST-statement WRITE sequential, 10-40 Names array, 4-3 common block, 7-9 symbol ic, 4-1 variable, 4-2 .NEQV. logical operator, 5-8 Nested Block IF constructs, 9-9 Nested DO statements, 9-14 Next record pointer, 15-29 NEXTREC specifier in INQUIRE, 11-58 NOANSI with FLAG, 16-22 NOBINARY switch, 16-10 NOCOMMON with EXTEND, 16-20 NODATA with EXTEND, lE-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 wi th DEBUG, 16-12 NONE with FLAG, 16-22 NONE with NOWARN, 16-15 Nonexecutable statements, 1-1, 6-2 Nonrepeatable edit descriptors, 12-8 NOSPANBLOCKS specifier in OPEN, 11-28 ~ o (octal) editing, 12-36 Object time system, 18-1 Octal constants, 3-5 OPEN TAPEFORMAT specifier in, 11-41 OPEN statement, 11-1 deferred, 11-2 examples, 11-51 implicit, 11-3 on connected unit, 11-4 OPEN statement specifiers, 11-4 ACCESS, 11-7 ASSOCIATEVARIABLE, 11-8 BLANK, 11-9 BLOCKSIZE, 11-10 BUFFERCOUNT, 11-11 BYTESIZE, 11-12 CARRIAGECONTROL, 11-12 DEFAULTFILE, 11-14 DENSITY, 11-15 DEVICE, 11-15 DI ALOG, 11-16 DIALOG=, 11-16 DIRECTORY, 11-17, 11-18 DISPOSE, 11-19 ERR, 11-20 FILE, 11-20 F I L E S I Z E, 11- 21 FORM, 11-22 INITIALIZE, 11-21 IOSTAT, 11-23 KEY, 11-24 LIMIT, 11-25 MAXREC, 11-25 MODE, 11-26 NAME, 11-28 NOSPANBLOCKS, 11-28 ORGANIZATION, 11-29 PADCHAR, 11-29 PARITY, 11-30 PROTECTION, 11-30, 11-32 READONLY, 11-34 RECL, 11-34 RECORDSIZE, 11-34 RECORDTYPE, 11-36 SHARED, 11-38 STATUS, 11-39 summary of, 11-6 TYPE, 11-39 UNIT, 11-42 USEROPEN, 11-42 Index-8 February 1987 OPEN statement specifiers (Cont.) VERSION, 11-43 OPENED specifier in INQUIRE, 11-58 Operators arithmetic, 5-2 concatenation, 5-6 hierarchy of, 5-14 logical, 5-8 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 ORGANIZATION specifier in INQUIRE, 11-59 in OPEN, 11-29 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-29 PARAMETER statement, 7-20 Parenthetical subexpressions, 5-13 PARITY specifier in OPEN, 11-30 PAUSE statement, 9-19 PDUMP subroutine, 13-36 PLOT subroutine, F-10 PLOTS subroutine, F-2 positional editing, 12-18 PRINT sequential FORMAT-~tatement, 10-50 sequential list-directed, 10-51 PRINT statement, 10-50 priority interrupt levels, 19-2 Priority interrupt system, 19-1 PROGRAM statement, 6-4 Programs compiling, 16-1, 16-5 debugging, 16-1, 16-5 executing, 16-1, 16-5 loading, 16-1, 16-5 non-FORTRAN, 15-10 Programs (Cont.) source, 1-1 wr it i ng, 15-1 PROTECTION specifier in CLOSE, 11-46 in OPEN, 11-30, 11-32 Psect placement /EXTEND, 16-18 PSECT with EXTEND, 16-20 PUNCH sequential FORMAT-statement, 10-53 sequential list-directed, 10-53 PUNCH statement, 10-52 Qed i t i ng, 12 - 2 9 QUIETX Subroutine, 13-36 R editing, 12-40 RAB block, 18-40 fields, 18-42 RAD function, 18-33 RAN function, 13-19 RANS function, 13-19 RCH function, 18-33 READ direct FORMAT-statement, 10-30 direct unformatted, 10-33 formatted indexed, 10-34 indexed, 10-33 indexed sequential, 10-34 sequential FORMAT-statement, 10-29 sequential list-dJrected, 10-30 sequential NAMELIST-statement, 10-31 sequential unformatted, 10-32 unformatted indexed, 10-35 READ state~ent, 10-27 internal, 10-55 READ transfers formatted, 10-29 unformatted, 10-32 Reading indexed files, 15-28 READONLY specifier in OPEN, 11-34 Real constants, 3-2 Real-time devices, 19-1 Real-time error messages, 19-7 Real-time software, 19-1 RECL specifier in INQUIRE, 11-59 in OPEN, 11-34 Record access block fields, 18-42 Record access block (RAB) , 18-40 Record specifier, 10-13 Records deleting, 15-29 updating, 15-29 RECORDSIZE specifier in INQUIRE, 11-59 in OPEN, 11-34 Index-9 February 1987 RECORDTYPE specifier in INQUIRE, 11-59 in 0 PEN, 11- 3 6 Register allocation global, 15-9 Relational expressions, 5-11 Relational operators, 5-11 Remark field, 2-4 Remarks, 2-6 Remote file specifications, 11-21 Remote links, 15-2 REMOVL in LINK, 15-20 Reordering computations, 15-4 Repeat specification, 7-22 Repeatable edit descriptors, 12-7 REREAD sequential FORMAT-statement, 10-43 sequential list-directed, 10-44 REREAD statement, 10-43 RESET in FOROTS, 15-11 RETURN statement, 13-47 REWIND statement, 11-63 REWRITE formatted, 10-61 unformatted, 10-61 REWRITE statement, 10-60 RMS data files, 18-14 defining keys, 11-24 invoking, 11-29 RMS data structures, 18-40 RMS files writing, 10-42 RMS indexed files reading, 10-33 RMS/FOROTS data and control structures, 18-40 RMSUTL utility, 15-24 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 t i ng, 12-24 SAOVL in LINK, 15-20 SAVE statement, 7-24 SAVFMT subroutine, 13-37 SAVRAN subroutine, 13-37 SCALE subroutine, F-10 SECNDS function, 13-19 Sequential access, 10-6, 18-3 Sequential FORMAT-statement PUNCH, 10-53 Sequential FORMAT-statement ACCEPT, 10-45 Sequential FORMAT-statement PRINT, 10-50 Sequential FORMAT-statement READ, 10-29 Sequential FORMAT-statement REREAD, 10-43 Sequential FORMAT-statement TYPE, 10-48 Sequential FORMAT-statement WRITE, 10-37 Sequential indexed READ, 10-34 Sequential list-directed ACCEPT, 10-46 Sequential list-directed PRINT, 10-51 Sequential list-directed PUNCH, 10-53 Sequential list-directed READ, 10-30 Sequential list-directed REREAD, 10-44 Sequential list-directed TYPE, 10-49 Sequential list-directed WRITE, 10-39 Sequential NAMELIST-statement READ, 10-31 Sequential NAMELIST-statement WRITE, 10-40 SEQUENTIAL specifier in INQUIRE, 11-60 Sequential unformatted READ, 10-32 Sequential unformatted WRITE, 10-41 SETABL subroutine, F-11 SETRAN subroutine, 13-38 Sharable high segment, 16-35 SHARED specifier in OPEN, 11-38 SKIPFILE statement, 11-67 SKIPRECORD statement, 11-66 Slash editing, 12-23 Software Real-time, 19-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 Index-10 February 1987 Specifiers carriage-control, 12-9 CLOSE statement, 11-44 END=, 10-18 ERR=, 10-19 format, 10-14 INQUIRE statement, 11-54 IOSTAT, 10-20 key-field-value, 10-21 key-of-reference, 10-23 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 function restrictions, 13-17 Statement functions, 13-15 using, 13-16 Statement label constants, 3-7 Statement label field, 2-3 Statement numbers, 2-3 Statements ACCEPT, 10-45 arithmetic assignment, 8-1 arithmetic IF, 9-3 ASSIGN, 8-3 assigned GO TO, 9-3 assignment, 8-1 BACKFILE, 11-67 BACKSPACE, 11-64 BLOCK DATA, 14-1 block IF, 9-5 CALL, 13-44 character assignment, 8-4 character type specification, 7-6 CLOSE, 11-43 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 data transfer summary, 10-3 DECODE, 10-56 DELETE, 10-59 device control, 10-1, 11-61 DIMENSION, 7-1 DO WHILE, 9-13 ELSE, 9-5 ELSE IF THEN, 9-5 ENCODE, 10-56 END, 9-20 END DO, 9-17 END IF, 9-5 ENDFILE, 11-65 Statements (Cont.) ENTRY, 13-45 EQUIVALENCE, 7-11 executable, 1-1, 6-1 EXTERNAL, 7-17 file control, 10-1, 11-1 FIND, 11-62 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-52 internal READ, 10-55 internal WRITE, 10-55 INTRINSIC, 7-18 logical assignment, 8-3 logical IF, 9-4 logical two-branch IF, 9-4 NAMELIST, 12-44 nested DO, 9-14 nonexecutable, 1-1, 6-2 numeric type specification, 7-5 OPEN, 11-1 ordering of, 6-2 PARAMETER, 7-20 PAUSE, 9-19 PRINT, 10-50 PROGRAM, 6-4 PUNCH, 10-52 READ, 10-27 REREAD, 10-43 RETURN, 13-47 REWIND, 11-63 REWRITE, 10-60 SAVE, 7-24 SKIPFILE, 11-67 SKIPRECORD, 11-66 specification, 7-1 STOP, 9-18 SUBROUTINE, 13-43 Summary of, A-I TYPE, 10-47 type specification, 7-4 unconditional GO TO, 9-2 UNLOAD, 11-64 UNLOCK, 10-62 WRITE, 10-35 STATI subroutine, 19-6 STATO subroutine, 19-5 STATUS specifier in CLOSE, 11-50 in OPEN, 11-39 STOP statement, 9-18 Storage common, 7-9 Subexpressions parenthetical, 5-13 Index-II February 1987 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 cncos, 13-25 CDEXP, 13-26 CDLOG, 13-26 CDSIN, 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 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-11 SETRAN, 13-38 SORT, 13-38 Subroutines (Cont.) 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 statement specifiers, 11-45 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 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-10, 16-15 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 T editing, 12-19 TAPEFORMAT specifier in OPEN, 11-41 TIM2GO function, 13-19 TIME subroutine, 13-39 TL editing, 12-20 TOPMEM subroutine, 13-40 TR editing, 12-20 TRACE subroutine, 13-41 Index-12 February 1987 TRACE with DEBUG, 16-12 TYPE sequential FORMAT-statement, 10-48 sequential list-directed, 10-49 Type declarators, 7-5 Type specification statements, 7-4 character, 7-6 numeric, 7-5 TYPE specifier in OPEN, 11-39 TYPE statement, 10-47 Unconditional GO TO statements, 9-2 Unformatted data transfers, 10-8 to ASCII devices, 10-8 Unformatted Indexed READ, 10-35 Unformatted READ direct, 10-33 sequential, 10-32 Unformatted READ transfers, 10-32 Unformatted REWRITE, 10-61 UNFORMATTED specifier in INQUIRE, 11-60 Unformatted WRITE direct, 10-41 sequential, 10-41 Unformatted WRITE transfers, 10-40 Unit identifier logical, 10-11 UNIT specifier in CLOSE, 11-51 in OPEN, 11-42 UNLOAD statement, 11-64 UNLOCK statement, 10-62 UNLOCK subroutine, 19-7 Updating records in indexed files, 15-29 UPG function, 18-36 User-defined character set, F-9 User-defined external functions, 13-20 User-defined subroutines, 13-42 USEROPEN example, 18-38 USEROPEN procedures, 18-38 USEROPEN specifier in OPEN, 11-42 Using FOROTS, 18-15 Using FORRTF, 19-2 Using function subprograms, 13-21 Using indexed files, 15-24 exceptions, 15-30 Using intrinsic functions, 13-2 Using statement functions, 13-16 Using the compiler, 16-1 Using the FORTRAN-20 compiler, 16-5 Variable names, 4-2 Variables, 4-2 compiler generated, 16-24 VERSION specifier in OPEN, 11-43 VMS with FLAG, 16-22 Warning messages, 16-34, C-8 WHERE subroutine, F-12 WRITE direct FORMAT-statement, 10-38 direct unformatted, 10-41 sequential FORMAT-statement, 10-37 sequential list-directed, 10-39 sequential NAMELIST-statement, 10-40 sequential unformatted, 10-41 WRITE statement, 10-35 internal, 10-55 WRITE transfers formatted, 10-37 unformatted, 10-40 Writing arithmetic expressions, 5-2 Writing indexed files, 15-26 Writing programs, 15-1 for use on other computers, 15-2 Writing subroutine calls, 15-11 Writing to RMS files, 10-42 WRS function, 18-34 X editing, 12-21 XAB block, 18-40 fields, 18-43 Z (hexadecimal) editing, 12-37 Index-13 February 1987 TOPS-10/TOPS-20 FORTRAN Language Manual AA-N383B-TK READER'S COMMENTS NOTE: This form is for document 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 Perfo'rmance 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. o Assembly language programmer o Higher-level language programmer o Occasional programmer (experienced) o User with little programming experience o Student programmer o Other (please specffy)~~~~~~~~~~~~~~~~~~~~~~ Name Date _~_ _~_~~~~_ Organization _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Telephone _ _ _ _ _ _ _ __ Street _____________________________________ City _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ State ____ Zip Code _ _ __ or Country - -- - -- - ~.- -ODO ~.oto Tear t- F~HeIr e and Tape- - - - - - - - - -- - - - - - - - - - - ~ ~ -r ~-111--------~~~~;:;~~ -- ~ 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 I 1 1 Do Not Tear - Fold Here and Tape - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - __ I 1 1 1 1 1 1 1 UPDATE NOTICE TOPS-10/TOPS-20 FORTRAN Language Manual AD-N383B-T1 February 1987 Insert this Update Notice in the TOPS-10/TOPS-20 FORTRAN Language Manual to maintain an up-to-date record of changes to the manual. Changed Information: The changed pages contained in this update package reflect Version 11 of FORTRAN-1 0/20. The instructions for inserting this update start on the next page. ©Digital Equipment Corporation 1987. All Rights Reserved. ~DmDDmD wore INSTRUCTIONS AD-N383B-T1 The following list of page numbers specifies which pages are to be placed in the TOPS-10/TOPS-20 FORTRAN Language Manual as replacements for, or additions to, current pages. Title Page Copyright Page Entire Chapter 11 17-3 17-4 18-37 18-43 Entire Contents 12-1 12-2 17-7 17-8 Entire Appendix A Entire Preface 13-31 13-34 17-11 17-12 Entire Appendix 0 2-1 2-4 15-1 15-2.2 17-15 17-16 Entire Index 4-1 4-2 15-15 15-20 18-1 18-4 Readers Comment Mailer 6-1 6-2 15-23 15-30 18-13 18-18 Entire Chapter 10 16-11 16-35 18-29 18-30 KEEP THIS UPDATE NOTICE IN YOUR MANUAL TO MAINTAIN AN UP-TO-DATE RECORD OF CHANGES. TYPE AND IDENTIFICATION OF DOCUMENTATION CHANGES. Five types of changes are used to update documents contained in the TOPS-10/TOPS-20 software manuals. Change symbols and notations are used to specify where, when, and why alterations were made to each update page. The five types of update changes and the manner in which each is identified are described in the following table. The Following Symbols and/or Notations Identify the Following Types of Update Changes 1. Change bar in outside margin; version number and change date printed at bottom of page. 1. Changes were required by a new version of the software being described. 2. Change bar in outside margin; change date printed at bottom of page. 2. Changes were required to either clarify or correct the existing material. 3. Change date printed at bottom of page. 3. Changes were made for editorial purposes but use of the software is not affected. 4. Bullet (e) in outside margin; version number and change date printed at bottom of page. 4. Data was deleted to comply with a new ver'sion of the software being described. 5. Bullet (e) in outside margin; change date printed at bottom of page. 5. Data was deleted to eit~er clarify or correct the existing material. February 1987
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies