Digital PDFs
Documents
Guest
Register
Log In
AA-D034E-TE
June 1988
464 pages
Original
25MB
view
download
OCR Version
21MB
view
download
Document:
VAX FORTRAN Language Reference Manual (Ver 5.0)
Order Number:
AA-D034E-TE
Revision:
000
Pages:
464
Original Filename:
OCR Text
VAX FORTRAN Language Reference Manual Order Number: AA-DO34E-TE June 1988 This manual details the VAX FORTRAN programming language as implemented for VMS systems. Revision/Update Information: This revised manual supersedes Programming in VAX FORTRAN number AA-D0O34D-TE). Operating System and Version: VMS Version 5.0 or higher Software Version: VAX FORTRAN Version 5.0 digital equipment corporation maynard, massachusetts (order First Printing, September 1984 Revision, June 1988 The information in this document is subject to change without notice and should not be construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document. The software described in this document is furnished under a license and may be used or copied only in accordance with the terms of such license. 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. Copyright © 1984, 1988 by Digital Equipment Corporation All Rights Reserved. Printed in U.S.A. The postpaid Reader’'s Comments forms at the end of this document request the user’s critical evaluation to assist in preparing future documentation. The following are trademarks of Digital Equipment Corporation: DEC DEC/CMS DEC/MMS DECnet DECsystem-10 DIBOL EduSystem IAS MASSBUS PDP UNIBUS VAX VAXcluster VMS VT 'DECwriter RSX dlilgli|t|all | DECSYSTEM-20 DECUS PDT RSTS ZK-4671 Contents PREFACE xvii NEW AND EXPANDED LANGUAGE FEATURES xXi CHAPTER 1 1.1 INTRODUCTION TO VAX FORTRAN 1-1 ELEMENTS OF FORTRAN SOURCE PROGRAMS 1-2 1.1.1 Program Units 1-2 1.1.2 Statements 1-2 1.1.3 Symbolic Names 1-5 1.1.4 Comments 1-7 1.2 CHARACTER SET 1.3 CODING RULES 1.3.1 1.4 1-8 1-9 Fixed-Format Lines 1-10 1.3.2 Tab-Format Lines 1-11 1.3.3 Statement Label Field 1-13 1.3.3.1 Comment Indicator ® 1-13 1.3.3.2 Debugging Statement Indicator ¢ 1-14 1.3.4 Continuation Indicator Field 1.3.5 Statement Field 1-14 1.3.6 Sequence Number Field 1-15 COMPILATION CONTROL STATEMENTS 1-14 1-15 1.4.1 DICTIONARY Statement 1-15 1.4.2 INCLUDE Statement 1-17 1.4.3 OPTIONS Statement 1-18 CHAPTER 2 2.1 DATA TYPES, DATA ITEMS, AND EXPRESSIONS 2-1 DATA TYPES Storage Requirements 2-1 2-2 2.1.2 2-4 2.1.1 2.2 VAX Implementations of REAL*8 DATA ITEMS 2.2.1 Constants 2.2.2 2.2.1.1 2.2.1.2 2.2.1.3 2.2.1.4 Integer Constants ® 2-5 Real Constants ® 2-8 Complex Constants ® 2—13 Octal and Hexadecimal Constants ® 2—-15 2.2.1.5 2.2.1.6 2.2.1.7 Logical Constants ® 2—-18 Character Constants ® 2—-18 Hollerith Constants ® 2-19 Variables 2.2.2.1 2.2.2.2 2.2.3 2.3 2-4 2-5 2-22 Data Type by Specification ® 2—-23 Data Type by Implication ® 2-24 Arrays 2-24 2.2.3.1 Array Declarators ® 2—-25 2.2.3.2 2.2.3.3 2.2.3.4 2.2.3.5 2.2.3.6 2.2.3.7 Array Subscripts ® 2-27 Arrangement of Array Elements in Storage ® 2-27 Data Type of an Array ® 2-29 Array References without Subscripts ® 2-29 Adjustable Arrays ® 2-29 Assumed-Size Arrays ® 2-30 2.2.4 2.2.5 Character Substrings Records 2.2.5.1 Arrangement of Records in Storage ® 2—-33 2.2.5.2 References to Record Fields ® 2—-36 2-30 2-31 2.2.6 Terminology Used to Refer to Data Items 2-39 EXPRESSIONS 2-42 2.3.1 2-42 Arithmetic Expressions 2.3.1.1 2.3.1.2 2.3.2 2.3.3 2.3.4 Using Parentheses ® 2—-44 Data Type of an Arithmetic Expression ® 2—-45 Character Expressions Relational Expressions Logical Expressions 2-47 2-48 2-49 CHAPTER 3 ASSIGNMENT STATEMENTS 3-1 3.1 ARITHMETIC ASSIGNMENT STATEMENT 3-1 3.2 LOGICAL ASSIGNMENT STATEMENT 3-4 3.3 CHARACTER ASSIGNMENT STATEMENT 3-4 3.4 AGGREGATE ASSIGNMENT STATEMENT 3-6 3.5 ASSIGN STATEMENT 3-7 SPECIFICATION STATEMENTS 4-1 4.1 BLOCK DATA STATEMENT 4-2 4.2 COMMON STATEMENT 4-3 4.3 DATA STATEMENT 4-5 DATA TYPE DECLARATION STATEMENTS 4-8 CHAPTER 4 4.4 4.5 4.6 4.4.1 Numeric Type Declaration Statements 4-8 4.4.2 Character Type Declaration Statements 4-10 DIMENSION STATEMENT 4-12 EQUIVALENCE STATEMENT 4-13 4.6.1 Making Arrays Equivalent 4-14 4.6.2 Making Substrings Equivalent 4-17 4.6.3 EQUIVALENCE and COMMON Interaction 4-20 4.7 EXTERNAL STATEMENT 4-21 4.8 IMPLICIT STATEMENT 4-22 4.9 INTRINSIC STATEMENT 4-23 410 NAMELIST STATEMENT 4-24 4.11 PARAMETER STATEMENT 4-26 412 PROGRAM STATEMENT 4-28 4.13 RECORD STATEMENT 4-29 414 SAVE STATEMENT 4-30 4.15 STRUCTURE DECLARATION BLOCK Structure Declaration 4.15.1 Substructure Declarations 4.15.2 Union Declarations 4.15.3 4-31 4-33 4-38 4-38 4.16 VOLATILE STATEMENT 4-41 CHAPTER 5 CONTROL STATEMENTS 5.1 CALL STATEMENT b—2 5.2 CONTINUE STATEMENT 5-3 5.3 DO STATEMENTS Indexed DO Statement 5.3.1 5-3 5—4 5.3.1.1 5.3.1.2 DO lteration Control ® 5-5 Nested DO Loops ® 5-7 5.3.1.4 Extended Range ® 5-9 5.3.1.3 5.3.2 5.4 Vi 5-1 Control Transfers in DO Loops ® 5-8 DO WHILE Statement END DO STATEMENT 5-9 5-11 5.5 END STATEMENT 5-12 5.6 GO TO STATEMENTS 5-12 5.6.1 Unconditional GO TO Statement 5-13 5.6.2 Computed GO TO Statement 5-13 5.6.3 Assigned GO TO Statement 5-14 5.7 IF STATEMENTS 5-15 5.7.1 Arithmetic IF Statement 5-16 5.7.2 Logical IF Statement 5-17 5.7.3 Block IF Statements 5-17 5.7.3.1 Statement Blocks ® 5-21 5.7.3.2 Block IF Examples ® 5-21 5.7.3.3 Nested Block IF Constructs ® 5-23 5.8 PAUSE STATEMENT 5—-24 5.9 RETURN STATEMENT 5-25 5.10 STOP STATEMENT 5-27 SUBPROGRAMS — SUBROUTINES AND FUNCTIONS 6—-1 SUBPROGRAM ARGUMENTS 6-2 CHAPTER 6 6.1 6.1.1 Actual Argument and Dummy Argument Association 6.1.1.1 Adjustable Arrays ® 6-3 6.1.1.2 Assumed-Size Arrays ® 6—6 6.1.1.3 Passed-Length Character Arguments ® 6—7 6.1.1.4 Character and Hollerith Constants as Actual 6-2 Arguments ® 6-8 6.1.1.5 6.1.2 6.2 Alternate Return Arguments ® 6-9 Built-In Functions 6.1.2.1 Argument List Built-In Functions ® 6-9 6.1.2.2 %LOC Built-In Function ® 6—11 USER-WRITTEN SUBPROGRAMS 6.2.1 6—-9 6-11 Statement Functions vii 6.2.2 6.2.3 6.2.4 6.3 Function Subprograms 6.2.2.1 6.2.2.2 6.2.2.3 Logical and Numeric Functions ® 6-15 Character Functions ® 6—15 Function Reference ® 6—-16 Subroutine Subprograms — SUBROUTINE 6-18 Statement 6-21 ENTRY Statement 6-22 ® ms Subprogra Function in s ENTRY Statement 6.2.4.1 ENTRY Statements in Subroutine Subprograms ® 6-24 6242 FORTRAN INTRINSIC FUNCTIONS 6.3.1 6.3.2 Intrinsic Function References 6.3.1.1 6.3.1.2 Generic References to Intrinsic Functions ® 6—-26 Using Intrinsic Function Names ® 6—-28 6.3.2.1 Character Functions ® 6-30 Character and Lexical Comparison Library Functions _ 6.3.2.2 7.1.2 7.1.1.1 Syntax Rules for Control-List Parameters ® 7-3 7.1.1.10 Transfer-of-Control Specifiers ¢ 7—-10 1/0 List 7.1.2.1 7.1.2.2 7.2 viii 6—25 6-30 7-1 COMPONENTS OF 1/O STATEMENTS Control List 7.1.1 7.1.1.2 7.1.1.3 7.1.1.4 7.1.1.5 7.1.1.6 7.1.1.7 7.1.1.8 7.1.1.9 6—-25 Lexical Comparison Functions ® 6—-32 CHAPTER 7 1/0 STATEMENTS 7.1 6-15 7-1 7-2 Logical Unit Specifier ® 7-3 Internal File Specifier ® 7-4 Format Specifiers ® 7-4 Namelist Specifier ® 7-5 Record Specifier ® 7—6 Key-Field-Value Specifier ® 7-6 Key-of-Reference Specifier ® 7-9 1/O Status Specifier ® 7-9 Simple List Elements ® 7—12 READ STATEMENTS 7-11 Implied-DO Lists in I/O Statements ¢ 7-13 7-15 7.2.1 Sequential READ Statements 7.2.1.1 7.2.2 7.2.3 7.2.4 7.3 7.2.1.2 List-Directed Sequential READ Statement ® 7—17 7.2.1.3 Namelist-Directed Sequential READ Statement ® 7-20 7.2.1.4 Unformatted Sequential READ Statement ® 7-25 Direct Access READ Statements 7—26 7.2.2.1 Formatted Direct Access READ Statement ® 7-26 7.2.2.2 Unformatted Direct Access READ Statement ® 7-27 Indexed READ Statements 7.2.3.1 Formatted Indexed READ Statement ® 7—29 7.2.3.2 Unformatted Indexed READ Statement ® 7-30 Internal READ Statement 7.2.41 Formatted Internal READ Statement ® 7—-31 7.2.4.2 List-Directed Internal READ Statement ® 7-32 7-28 7-31 WRITE STATEMENTS 7-33 7.3.1 7-33 Sequential WRITE Statements 7.3.1.1 7.3.2 7.3.3 7.3.4 7.4 7-15 Formatted Sequential READ Statement ® 7—16 Formatted Sequential WRITE Statement ® 7-34 7.3.1.2 List-Directed Sequential WRITE Statement ® 7-35 7.3.1.3 Namelist-Directed Sequential WRITE Statement ® 7-37 7.3.1.4 Unformatted Sequential WRITE Statement ® 7-39 Direct Access WRITE Statements 7-39 7.3.2.1 Formatted Direct Access WRITE Statement ® 7—40 7.3.2.2 Unformatted Direct Access WRITE Statement ® 7—40 Indexed WRITE Statements 7.3.3.1 Formatted Indexed WRITE Statement ® 7—42 7.3.3.2 Unformatted Indexed WRITE Statement ® 7—-43 Internal WRITE Statement 7.3.4.1 Formatted Internal WRITE Statement ® 7—44 7.3.4.2 List-Directed Internal WRITE Statement ® 7—44 7-41 7-43 REWRITE STATEMENT 7-45 7.4.1 Formatted REWRITE Statement 7-46 7.4.2 Unformatted REWRITE Statement 7-46 7.5 ACCEPT STATEMENT 7-47 7.6 TYPE AND PRINT STATEMENTS 7-48 CHAPTER 8 8.1 8.2 8.3 I/0 FORMATTING GENERAL RULES FOR WRITING FORMAT STATEMENTS 8.1.1 Input Rules for FORMAT Statements 8.1.2 Output Rules for FORMAT Statements FORMAT STATEMENT SYNTAX FIELD AND EDIT DESCRIPTORS 8.3.1 8.3.2 Repeat Counts and Group Repeat Counts Variable Format Expressions 8.3.3 Blank Control Editing 8.3.3.1 BN Edit Descriptor ® 8-10 BZ Edit Descriptor ® 8—11 8.3.3.2 8.3.4 Sign Control Editing SP Edit Descriptor ® 8—11 8.3.4.1 SS Edit Descriptor ® 8-11 8.3.4.2 8.3.4.3 8.3.5 8.3.56.3 8.3.6 8.3.8 8.3.9 Z Field Descriptor ® 8-16 Real Editing F Field Descriptor ® 8-17 8.3.6.1 E Field Descriptor ® 8—19 8.3.6.2 8.3.6.3 8.3.6.4 8.3.6.6 8.3.7 S Edit Descriptor ® 8—12 Integer Editing | Field Descriptor ® 8—12 8.3.5.1 8.3.5.2 O Field Descriptor ® 8-14 D Field Descriptor ® 8-21 G Field Descriptor ® 8—-22 Complex Data Editing ® 8-25 Scale Factor Editing—P Edit Descriptor Logical Editing—L Edit Descriptor Character Editing 8.3.9.1 A Field Descriptor ® 8-29 H Field Descriptor ® 8—32 8.3.9.2 8.3.9.3 Character Constants ® 8-32 8.3.10 Default Field Descriptors 8.3.11 Positional Editing X Edit Descriptor ® 8-34 8.3.11.1 8.3.11.2 T Edit Descriptor ® 8-35 8.3.11.3 TL Edit Descriptor ® 8-36 8.3.11.4 TR Edit Descriptor ® 8-36 8-12 8.3.12 Additional Editing Operations 8.3.12.1 Q Edit Descriptor ® 8-37 8.3.12.2 Dollar Sign Descriptor ® 8-37 8.3.12.3 Colon Descriptor ® 8—38 8.4 CARRIAGE CONTROL 8-38 8.5 FORMAT SPECIFICATION SEPARATORS 8-39 8.6 EXTERNAL FIELD SEPARATORS 8-40 8.7 RUN-TIME FORMAT 841 8.8 FORMAT CONTROL INTERACTION WITH 1I/0 LISTS 8-42 AUXILIARY I/O STATEMENTS 9-1 OPEN STATEMENT 9-2 CHAPTER 9 9.1 9.1.1 ACCESS Keyword 9-8 9.1.2 ASSOCIATEVARIABLE Keyword 9-8 9.1.3 BLANK Keyword 9-8 9.1.4 BLOCKSIZE Keyword 9-9 9.1.5 BUFFERCOUNT Keyword 9.1.6 CARRIAGECONTROL Keyword 9-10 9-9 9.1.7 DEFAULTFILE Keyword 9-10 9.1.8 DISPOSE Keyword 9-11 9.1.9 ERR Keyword 9-12 9.1.10 EXTENDSIZE Keyword 9-12 9.1.11 FILE Keyword 9-13 9.1.12 FORM Keyword 9-13 9.1.13 INITIALSIZE Keyword 9-14 9.1.14 IOSTAT Keyword 9-14 9.1.15 KEY Keyword 9-15 9.1.16 MAXREC Keyword 9-16 9.1.17 NAME Keyword 9-17 9.1.18 NOSPANBLOCKS Keyword 9-17 9.1.19 ORGANIZATION Keyword 9-17 9.1.20 READONLY Keyword 9-18 Xi 9.2 9.3 Xii 9.1.21 RECL Keyword 9-18 9.1.22 RECORDSIZE Keyword 9-20 9.1.23 RECORDTYPE Keyword 9-20 9.1.24 SHARED Keyword 9-21 9.1.25 STATUS Keyword 9-21 9.1.26 TYPE Keyword 9-22 9.1.27 UNIT Keyword 9-22 9.1.28 USEROPEN Keyword 9-23 CLOSE STATEMENT 9-23 INQUIRE STATEMENT 9-24 9.3.1 ACCESS Specifier 9-25 9.3.2 BLANK Specifier 9-26 9.3.3 CARRIAGECONTROL Specifier 9-26 9.34 DIRECT Specifier 9-27 9.3.5 ERR Specifier 9-27 9.3.6 EXIST Specifier 9-27 9.3.7 FORM Specifier 9-28 9.3.8 FORMATTED Specifier 9-28 9.3.9 IOSTAT Specifier 9-28 9.3.10 KEYED Specifier 9-29 9.3.11 NAME Specifier 9-29 9.3.12 NAMED Specifier 9-30 9.3.13 NEXTREC Specifier 9-30 9.3.14 NUMBER Specifier 9-30 9.3.15 OPENED Specifier 9-31 9.3.16 ORGANIZATION Specifier 9-31 9.3.17 RECL Specifier 9-32 9.3.18 RECORDTYPE Specifier 9-32 9.3.19 SEQUENTIAL Specifier 9-33 9.3.20 UNFORMATTED Specifier 9-33 94 REWIND STATEMENT 9.5 BACKSPACE STATEMENT 9-35 9.6 ENDFILE STATEMENT 9-35 9.7 DELETE STATEMENT 9-36 9.8 UNLOCK STATEMENT 9-38 CHAPTER 10 COMPILER DIRECTIVES 10-1 10.1 COMPILER DIRECTIVE SYNTAX RULES 10-1 10.2 PARALLEL DIRECTIVES 10-2 10.2.1 CPARS$ CONTEXT_SHARED 10-3 10.2.2 CPARS CONTEXT_SHARED_ALL 10-3 10.2.3 CPARS DO_PARALLEL 10-4 10.2.4 CPARS$ LOCKON, CPARS LOCKOFF 10-5 10.2.5 CPARS$ PRIVATE 10-6 10.2.6 CPARS PRIVATE_ALL 10-7 10.2.7 CPARS SHARED 10-7 10.2.8 CPARS$ SHARED_ALL 10-8 10.2.9 Parallel Directive Examples 10-8 10.3 GENERAL DIRECTIVES 10-10 10.3.1 CDECS$ IDENT 10-10 10.3.2 CDEC$ PSECT 10-11 10.3.3 CDECS TITLE, CDECS$ SUBTITLE 10-13 ADDITIONAL LANGUAGE FEATURES A-1 A1 THE ENCODE AND DECODE STATEMENTS A-1 A.2 DEFINE FILE STATEMENT A-3 A.3 FIND STATEMENT A-5 A4 PARAMETER STATEMENT A—-6 A.5 OCTAL NOTATION FOR INTEGER CONSTANTS A—7 APPENDIX A A.6 APPENDIX B A-8 CHARACTER SETS B-1 B.1 FORTRAN CHARACTER SET B-1 B.2 ASCIl CHARACTER SET B-2 B.3 RADIX-50 CONSTANTS AND CHARACTER SET B-4 APPENDIX C FORTRAN DATA REPRESENTATION C-1 C.1 INTEGER*2 REPRESENTATION C-1 C.2 INTEGER*4 REPRESENTATION C-2 C.3 LOGICAL+1 (BYTE) REPRESENTATION CcC-2 c4 LOGICAL+«2 AND LOGICAL+4 REPRESENTATION C-2 FLOATING-POINT REPRESENTATIONS CcC-3 C.5 Xiv /NOF77 INTERPRETATION OF THE EXTERNAL STATEMENT C.5.1 REAL+*4 (F_floating) CcC14 C.5.2 REAL+8 (D_floating) C-5 C.5.3 REAL+*8 (G_floating) C—-6 C.5.4 REAL#*16 (H_floating) Cc-7 C.5.5 COMPLEX+*8 (F_floating) CcC-8 C.5.6 COMPLEX*16 (D_floating) C-8 C.5.7 COMPLEX*16 (G_floating) Cc-10 C.6 CHARACTER REPRESENTATION C-11 C.7 HOLLERITH REPRESENTATION C-11 VAX FORTRAN LANGUAGE SUMMARY D-1 D.1 EXPRESSION OPERATORS D-1 D.2 STATEMENTS D-2 D.3 LIBRARY FUNCTIONS D-32 D.4 SYSTEM SUBROUTINE SUMMARY DATE Subroutine D.4.1 IDATE Subroutine D.4.2 ERRSNS Subroutine D.4.3 EXIT Subroutine D.4.4 SECNDS Subroutine D.4.5 TIME Subroutine D.4.6 RAN Subroutine D.4.7 D—45 D—46 D—-47 D-47 D48 D-48 D-49 D-50 D.5 BIT FUNCTIONS Bit Position D.5.1 Bit Function Arguments D.5.2 D.5.3 MVBITS Subroutine D-50 D-51 D-51 Using Multiple Function Names 6—-28 APPENDIX D D-53 INDEX EXAMPLES 6—1 FIGURES 1-1 Required Order of Statements and Lines 1-3 1-2 FORTRAN Coding Form 1-10 1-3 Line Formatting Example 1-12 2-1 Array Storage 2—-28 4-1 Equivalence of Substrings 4-18 4-2 Equivalence of Character Arrays 4-19 XV 5-1 Control Transfers and Extended Range 5-10 5-2 Examples of Block IF Constructs 5-20 TABLES Xvi 1-1 Entities Identified by Symbolic Names 2-1 Data Type Storage Requirements 2-3 3—-1 Conversion Rules for Assignment Statements 3-3 4-1 Equivalence of Array Storage 4-15 4-2 Equivalence of Arrays with Nonunity Lower Bounds 4-16 5-1 Nested DO Loops 6-1 Argument List Built-In Functions and Defaults 6-2 Types of User-Written Subprograms 6-12 6-3 Summary of Generic Intrinsic Function Names 6-27 7-1 List-Directed Default Output Formats 7-36 8-1 FORMAT Code Summary 8-2 Effect of Data Magnitude on G Format Conversions 8-23 8-3 Size Limit of Numeric Elements Using the A Field Descriptor 8-30 84 Default Field Descriptor Values 8-33 8-5 Carriage Control Characters 8-39 9-1 OPEN Statement Keyword Values 9-2 Record Size (RECL) Limits 9-3 Record Size (RECL) Default Values 10-1 Common Block Default Attributes and PSECT Modification B-1 ASCII Character Set B-3 B-2 RADIX-50 Character Set with Comparative Values B—4 D-1 Expression Operators D-1 D-2 VAX FORTRAN Language D-3 D-3 VAX FORTRAN Intrinsic Functions 1-7 5-7 6-10 8-6 9-4 9-19 9-19 ___ 10-12 D-33 Preface This manual presents a complete description of the VAX FORTRAN language for VMS systems. It is designed as a reference manual, not as a tutorial document. For detailed instructions on the features of the VAX FORTRAN compiler and its use, see the VAX FORTRAN User Manual. Intended Audience This manual is intended for programmers and students who have a basic understanding of the FORTRAN language. Readers do not need a detailed understanding of the VMS operating system, but some familiarity is helpful. For detailed information about the VMS system, refer to the VM5 documentation set. Structure of this Document The documentation for VAX FORTRAN Version 5.0 is a major revision of the Version 4.0 documentation. The material is reorganized into two manuals. The VAX FORTRAN User Manual describes how to compile, link, execute, and debug VAX FORTRAN programs on the VMS system. It also describes special VAX FORTRAN features and system resources of interest to VAX FORTRAN programmers. XVii This manual presents the language-specific information. It is divided into ten chapters and four appendixes: Chapter 1 discusses VAX FORTRAN's relationship with FORTRAN standards, the elements of a source program, the character set, general coding rules, and compiler control statements. Chapter 2 describes the data types, data items, and expressions that can be used in VAX FORTRAN programs. Chapter 3 describes the assignment statement, which defines the values of data items. Chapter 4 describes specification statements, which are nonexecutable statements. Specification statements allocate and initialize data items and define various characteristics of symbolic names used in a program. Chapter 5 describes control statements, which specify when and where control transfers from one point in a program to another. Chapter 6 discusses subprograms (subroutines and functions), both those written by users and those supplied by VAX FORTRAN. Chapter 7 describes I/O (input/output) statements, which physically transfer data, both internally within memory and to and from output storage devices. Chapter 8 describes formatting statements, which are used together with formatted 1/0 statements. Chapter 9 describes auxiliary I/0 statements that manage files. Chapter 10 describes compiler directives, which support directed decomposition and general-purpose functions. Appendix A describes some statements and language features that support programs written in older versions of FORTRAN. Appendix B summarizes the character sets supported by VAX FORTRAN. Appendix C shows how VAX FORTRAN data types are stored in memory. Appendix D summarizes VAX FORTRAN features: operators used in expressions, statements, intrinsic functions and their arguments, and system subroutines and bit manipulation functions. Xviii Associated Documents The following documents contain information directly related to the topic of this manual: VAX FORTRAN User Manual This manual describes how to perform basic operations using the VMS system and screen-display editor. The information about the VMS system and the editor should enable a programmer who is not acquainted with VMS to begin productive work on it. The VMS documentation set This set provides detailed information about features of the VMS operating system. Conventions Used in this Document The following syntactic conventions are used in this manual: Uppercase type is used in text to indicate VMS commands and command options. Lowercase letters are used in syntax specifications and examples to indicate variables; anything that is not a variable (for example, statement names and keywords) appears in uppercase. Brackets ([]) indicate optional elements within statements. Braces ({}) are used to enclose lists from which one element is to be chosen. Horizontal ellipses (...) indicate that the preceding items can be repeated one or more times. “Real” (lowercase) is used to refer to the REAL*4 (REAL), REALx*8, and REAL*16 data types as a group; likewise, “complex” (lowercase) is used to refer to the COMPLEX*8 (COMPLEX) and COMPLEX*16 (DOUBLE COMPLEX) data types as a group; “logical” (lowercase) is used to refer to the LOGICAL#*2 and LOGICAL=*4 data types as a group; and “integer” (lowercase) is used to refer to the INTEGERx2 and INTEGER#*4 data types as a group. VAX FORTRAN extensions to the FORTRAN-77 standard are printed in blue. Xix In addition, the following notations denote special nonprinting characters: XX Tab character <TAB> Space character A New and Expanded Language Features VAX FORTRAN Version 5.0 provides the following new and expanded language features: Directed decomposition of DO-loops for parallel processing. Parallel processing is mediated by a group of compiler directives that are specifically called parallel directives. See Section 10.2. Several general-purpose functions: specifying the identification string in object modules, modifying some common block attributes, and listing title and subtitle. These functions are mediated by a group of compiler directives that are specifically called general directives. See Section 10.3. Support for descending ISAM (Indexed Sequential Access Mode) keys: — Expanded syntax for the KEY parameter in the OPEN statement. — Additional keywords in the key-field-value specifier in input See Section 9.1.15. /output statements. See Section 7.1.1.7. SIZEOF intrinsic function. This new function returns the number of bytes of storage used in a specified argument. See Table D-3. NWORKERS intrinsic function. This new function returns the number of processes executing a routine. See Table D-3. REWRITE operations on files that are open for direct access. See Section 7.4. UNLOCK operations of files with sequential organization. See Section 9.8. See the VAX FORTRAN User Manual for a description of new compiler features available in VAX FORTRAN Version 5.0. XXi 1 Chapter Introduction to VAX FORTRAN This chapter discusses VAX FORTRAN's relationship to FORTRAN standards, the elements of a VAX FORTRAN program, the character set, and general coding rules. It also presents compiler control statements. VAX FORTRAN is based on the American National Standard FORTRAN-77 (ANSI X3.9-1978). It includes support for programs that conform to the previous standard (ANSI X3.9-1966). VAX FORTRAN also supports programs that conform to the International Standards Organization FORTRAN standard (ISO 1539-1980 (E)) because the ISO standard is the same as the ANSI standard. VAX FORTRAN provides a number of extensions to the ANSI Standard: e Compiler directives that support directed decomposition for parallel processing e Compiler directives that perform several general-purpose functions e Relative file organization * e Indexed file organization with two-directional keys Conformance with the VAX procedure-calling standard e Records and structures e DO WHILE statement e Additional data types e Namelist-directed input/output e Hexadecimal constants and field descriptors Symbolic debugging facility e Extensions to the FORTRAN-77 standard appear in blue print in this manual. Introduction to VAX FORTRAN 1-1 VAX FORTRAN is also a compatible superset of PDP-11 FORTRAN-77. This means that existing PDP-11 FORTRAN-77 source programs will compile properly on the VAX FORTRAN compiler (see the VAX FORTRAN User Manual). 1.1 Elements of FORTRAN Source Programs This section provides an overview of the makeup of a FORTRAN source program. It describes the concept of a program unit and the rules gov- erning the use of statements and symbols within a program unit. It also describes the use of comments within programs. 1.1.1 Program Units A program unit is a sequence of statements that defines a computing procedure and is terminated by an END statement. A program unit can be either a main program or a subprogram. An executable program consists of one main program and, optionally, one or more subprograms. A subprogram is a program unit that is separate from the main program. Subprograms are invoked from the main program or another subpro- gram. There are two types of subprograms: function subprograms and subroutine subprograms. See Chapter 6 for detailed information on subprograms. 1.1.2 Statements Statements are grouped into two general classes: executable and nonexecutable. Executable statements describe the action of the program. Nonexecutable statements describe data arrangement and characteristics, and provide editing and data-conversion information. Statements are divided into physical sections called lines. A line is a string of up to 72 characters (optionally, 132; see Section 1.3.5). If a statement is too long to fit on one line, it can continue on one or more additional lines called continuation lines. A continuation line is identified by a continuation character in the sixth column of that line. (For further information on continuation characters, see Section 1.3.4) 1-2 Introduction to VAX FORTRAN A statement label can identify a statement so that other statements can refer to it, either to get information or to transfer control. A statement label must be an integer, and it must appear in the first five columns of a statement’s initial line. Any statement can have a label. However, you can only refer to labels on executable statements and FORMAT statements. Order of Statements in a Program Unit Figure 1-1 shows the required order of statements in a FORTRAN pro- gram unit. In this figure, vertical lines separate statement types that can be interspersed. For example, you can intersperse DATA statements with executable statements. On the other hand, horizontal lines indicate statement types that cannot be interspersed. For example, you cannot intersperse type declaration statements with executable statements. Figure 1-1: Required Order of Statements and Lines OPTIONS Statement PROGRAM FUNCTION,SUBROUTINE, or BLOCK DATA Statements IMPLICIT NONE Statement IMPLICIT Statements Comment Lines, INCLUDE Stat‘;:];ms' General Directives Other Specification Statements NAMELIST PARAMETER Statements FORMAT and Statement Function ENTRY Statements Executable Statements END Statement ZK-615-82 Introduction to VAX FORTRAN 1-3 The following statements are the general directives that are included in the category with comment lines and INCLUDE statements in Figure 1-1: CDEC$ IDENT CDEC$ SUBTITLE CDECS$ TITLE CDEC$ PSECT The following statements are included in the category of executable statements in Figure 1-1: ACCEPT IF (arithmetic, logical, block) and END IF ASSIGN INQUIRE Assignment statements OPEN BACKSPACE PAUSE CALL PRINT CLOSE READ CONTINUE RETURN CPAR$ DO_PARALLEL REWIND CPARS$ LOCKOFF REWRITE CPAR$ LOCKON STOP DELETE TYPE DO and END DO UNLOCK ELSE WRITE END ENDFILE FIND GO TO (normal, computed, assigned) 1-4 |Introduction to VAX FORTRAN The following statements are included in the category of “other specification statements” in Figure 1-1: COMMON EQUIVALENCE CPAR$ CONTEXT_SHARED EXTERNAL CPAR$ CONTEXT_SHARED_ALL INTRINSIC CPAR$ PRIVATE RECORD CPAR$ PRIVATE _ALL SAVE CPAR$ SHARED Structure declarations' CPAR$ SHARED_ALL Type declarations DICTIONARY VOLATILE DIMENSION "The statements STRUCTURE and END STRUCTURE, UNION and END UNION, and MAP and END MAP are included in the “other specification statements” category. They are used only in structure declaration blocks. As a VAX FORTRAN extension, DATA statements can be freely interspersed with PARAMETER statements and other specification statements. 1.1.3 Symbolic Names Symbolic names identify entities within a FORTRAN program unit. These entities are listed in Table 1-1. A symbolic name is a string of letters, digits, and the special characters dollar sign ($) and underscore (—). The first character in a symbolic name must be a letter. The symbolic name can contain a maximum of 31 characters. (FORTRAN-77 limits the length of a symbolic name to six characters.) Examples The following examples demonstrate valid and invalid symbolic names and explain why the invalid ones are not valid: Introduction to VAX FORTRAN 1-5 Valid NUMBER FIND_IT X Invalid Explanation 5Q Begins with a numeral B.4 Contains a special character other than _ or $ $FREQ Begins with $ By convention, symbolic names containing a dollar sign are reserved for DIGITAL-supplied software components. To avoid name conflicts, do not define any symbolic names in your program that contain dollar signs. Symbolic names cannot identify more than one entity in the same pro- gram unit—except when they identify common blocks, records, structures, structure fields, and either arrays or variables. For example, in the following valid statements, X is the name of a common block, a structure, a structure field, and a variable: COMMON /X/ I, J STRUCTURE /X/ INTEGER X END STRUCTURE REAL X Section 4.15.1 and Section 4.15.2 provide more information about structure and field names. In an executable program having two or more program units, the symbolic names of the following entities must be unique within the entire program: 1-6 ®* Function subprograms ® Subroutine subprograms e Common blocks * Main program * Block data subprograms * Function entry points * Subroutine entry points Introduction to VAX FORTRAN For example, if your program contains a function named BTU, you cannot use BTU as the symbolic name of any other subprogram, entry, or common block in the program—even if the name appears in a different program unit. Table 1-1 lists those entities that can be given a symbolic name. It also indicates whether the entities can be given a data type. Sections 2.2.2.1 and 2.2.2.2 discuss how to specify the data type of a symbolic name. Table 1-1: 1.1.4 Entities Ildentified by Symbolic Names Entity Typed Variables Yes Arrays Yes Structures No Records No Record elements Yes Statement functions Yes Intrinsic functions Yes Function subprograms Yes Subroutine subprograms No Common blocks No Namelist data groups No Main programs No Block data subprograms No Function entry points Yes Subroutine entry points No Parameter constants Yes Comments Comments are documentation aids that do not affect program processing in any way. They can be freely used to describe the actions of a program, identify program sections and processes, and provide greater ease in reading a source program listing. ' Introduction to VAX FORTRAN 1-7 Three different characters identify comments: ®* The letter ®* An asterisk (*) * An exclamation point (!) C — except when C begins a compiler directive When the letter C or an asterisk appears in the first column of a source line, it identifies the line as a comment. An exclamation point in the first column, or anywhere in the statement portion of a source line, identifies the remainder of that line as a comment. An all-blank line is also treated as a comment line. Section 10.2.9 provides an example of when the letter C in column 1 begins a compiler directive instead of a comment. 1.2 Character Set VAX FORTRAN supports the following character set: 1-8 * All uppercase and lowercase letters (A through Z, a through z) * The numerals 0 through 9 * The following special characters: Character Name A or <TAB> Space or tab Apostrophe = Equal sign Quotation mark Character Name + Plus sign $ Dollar sign - Minus sign — Underscore * Asterisk ! Exclamation point / Slash Colon ( Left parenthesis < Left angle bracket ) Right parenthesis > Right angle bracket , Comma % Percent sign Period & Ampersand Introduction to VAX FORTRAN You can use the space character to improve the legibility of a FORTRAN statement. The compiler ignores all spaces in a statement field except those within a character or Hollerith constant; for example, GO TO and GOTO are equivalent. Other printable ASCII characters can appear in a FORTRAN statement only as part of a character or Hollerith constant (see Appendix B for a list of printable characters). Any printable character can appear in a comment. If nonprintable characters appear anywhere in a FORTRAN source statement, they appear as question marks in the compilation source listing. The control character <NEWLINE> ( <LF> or "A’ X) is not supported in VAX FORTRAN source records. VAX FORTRAN uses <NEWLINE > to separate successive FORTRAN source lines. If you must manipulate this character, use the CHAR(10) function reference, which is allowed in all compile-time character expressions (see Section 6.3.2.1). Except in character and Hollerith constants, the compiler makes no distinction between uppercase and lowercase letters. 1.3 Coding Rules Coding rules specify the structure of lines in VAX FORTRAN source code. A line has four fields: the statement label, continuation indicator, statement, and sequence number. Rules affecting individual fields are described in Sections 1.3.3 through 1.3.6. There are two ways to code a line: by fixed format or tab format. The fixed-format method is convenient when you punch cards or use a coding form. The tab-format method is convenient when you enter lines at a terminal with a text editor. 1.3.1 Fixed-Format Lines As shown in Figure 1-2, a FORTRAN line is divided into fields for statement labels, continuation indicators, statement text, and sequence numbers. Each column represents a single character. To enter an item in a field, enter it in the columns in the coding form, as follows: Introduction to VAX FORTRAN 1-9 Figure 1-2: FORTRAN Coding Form FO RTRA N CODER CODING FORM l DATE PAGE PROBLEM CCan-\'rflé 2 FORTRAN STATEMENT o statiment 1234516178 C, .. ——+—+ + 4 ~+—+ %1011 JfrHls PROGR ——— CALCULATES J= b —————+ e =LA L, + -+ et — +—+ 105 e —— e + B U —+ e e FORMAT +— ——+ -t S S e e et + P e A G S U s sun un sl il ol e e ———+ I bt e Ak S e e e e R 3 o A A e 4 A e o e e ol e e e e e B A e A i e T 2 S A e S e & 4 e i 4 A e e A4 e o i e e A A e b e I B e o U R b W ——— A A A ———t OIGITAL ————t M " A R - I D — . —————— e+ et ] + S +—+—+ S ¥ +—+ bt ——+ +————— b+ S e e e e S S S S B A il e S S e it g st S T —— ei e S o 4 & p A i b A A .} R B S TR T W S Sy v R i WO LY WY W W W T S e S S S e T U G U Uy W S WP - S i VU S S S ——————t—————t . e i SR R S S o bt S T EQUIPMENT CORPORATION . L bbbt S S SN S S U SN S e o GO W U W e Wb WUl W +—+ U W U W S Aaun e U U U U U S st U G i ob SIS B MAYNARD. U U W e e e e PN e — PP AIPAIFIIIEN . (PSS &+—+—¢4_4_++4_++-¢++4,4¢;,1: W P S S G S o U JU G U S— 4 D ot S 516|170 9101 12121415161718192021222124252627202920 1373334133637 I94041424344435464740493031323533453545735859606102030403086 07880070 N PG-3 p—4 . + bt A ——t * Sn ge aa S I e gt i e B G S I e eT O i i et Mmoo t S ik 0 S e v s + + i ei e e e ot R B SlS = . +——+ b+ . P e -~ e e e e S a St ALcuve s b anie ch G e S —r—— PRIME'") U e e e A e o + amm ae d 1S + (1))), GQ 1O 4 +—— bt .+—+ ——————+ e P el o e i e e — i ~+ ——+ B oAk i R —+ (14, 4+ V234 + R S e + 5 LT . SQRT (FLOAT 1 bt . "AQNTJAU¢E¢ ¢¢¢ e A At e 10, TYPE et 105, +— b+t e . v ot JLF (I ]v¢fi 1.1 10O 50, @\ ity e bt —— 1LF, (B), 5, 5 FROM A:‘J.+#¢*¢¢¢:‘:::¢¢¢¢¢¢¢¢#¢+¢Av¢¢~¢AA¢A*A AAAAAA = B=A-L . BERS, , - NN - PRIME D¢Q¢]¢O¢#l¢=€]¢]¢‘¢¢5¢O£‘¢£+¢##¢¢‘v“#######%#‘##9#¢¢3##%%9#9######36%4#44## =1, N IDENTIFICATION 121314151617181920212223242526272829303132333435363738394041424344454647484950 5152515453506575850600162634465880768070N 72{7374737877 7879040 T S G G S e e 44— 1 UW SN SO W W ¢ 22N743 M7 7R MASSACHUSETTS ZK-613-82 1-10 Field Column Statement label 1 through 5 Continuation indicator 6 Statement 7 through 72 (optionally, to 132) Sequence number 73 through 80 Introduction to VAX FORTRAN ‘ 1.3.2 Tah-Format Lines You can specify the statement label field, the continuation indicator field, and the statement field using tab formatting. However, you cannot specify a sequence number field using this method of coding. Figure 1-3 illustrates FORTRAN lines coded using tab formatting and the equivalent lines with fixed formatting. Figure 1-3: Line Formatting Example Format Using TAB Character Character-per-Column Format 112 3 4 5|67 8 9 10|11 12 13 14 15|16 C @B FIRST VALUE C FII|R|S]|T VI|A|L 10G@AD | = J + b*K + 110 | + @8 1 L+*M @AB) IVAL = [+2 1 = J 1718 19 20 |U|E 51+ |K + L{~* (M I [V|A|L = I [+]2 ZK-614-82 The statement label field consists of the characters that you type before the first tab character. The statement label field cannot have more than five characters. After typing the first tab character, you can type either the continuation indicator field or the statement field. To enter the continuation indicator field, type any nonzero digit after the first tab. If you enter the continuation indicator field, the statement field consists of all the characters after the digit to the end of the line. Introduction to VAX FORTRAN 1-11 To enter the statement field without a continuation indicator field, type the statement immediately after the first tab. No FORTRAN statement starts with a digit. Many text editors and terminals advance the terminal print carriage to a predefined print position when you press the TAB key. However, this action is not the VAX FORTRAN compiler’s interpretation of the tab character. The compiler treats the tab character in a statement field the same way as it treats a space. In the source listing that the compiler produces, the tab causes the character that follows to be printed at the next tab stop (located at columns 9, 17, 25, 33, and so on). NOTE Do not use tabs when you are using sequence numbers. If you use tabs to position your sequence numbers, the compiler may interpret the sequence numbers as part of the statement fields In your program. 1.3.3 Statement Label Field Any statement can have a label. A statement label (or statement number) consists of from one to five decimal digits in the statement label field of a statement’s initial line. Spaces and leading zeros are ignored. An all-zero statement label is invalid. Labeled FORMAT and labeled executable statements are the only statements that can be referred to by other statements (see Section 1.1.2). FORMAT statements are referred to only in the format specifier of an [/O statement or in an ASSIGN statement. No two statements within a program unit can have the same label. The first column of the label field can contain two special indicators: the comment indicatorand the debugging statement indicator. The statement label field of a continuation line must be blank—except in the case of a debugging statement., 1-12 Introduction to VAX FORTRAN 1.3.3.1 Comment Indicator The letter C (except when beginning a compiler directive); an asterisk (*); or an exclamation point (!) in column 1 indicates that the line is a comment. The compiler prints that line in the source program listing and then ignores it. An all-blank line is also considered to be a comment. The exclamation point can also be used anywhere in the statement field (except when used in a Hollerith or character constant) to start an end-of-line comment. See Chapter 10 for a description of when the letter C in column 1 begins a compiler directive instead of a comment. 1.3.3.2 Debugging Statement Indicator The letter D in column 1 designates debugging statements. The initial line of the debugging statement can contain a statement label in the remaining columns of the label field. If a debugging statement is continued onto more than one line, every continuation line must begin with a D (in column 1) and a continuation indicator. The compiler treats debugging statements either as source text to be compiled or as comments, depending on the setting of the /D_LINES qualifier on the FORTRAN command. If you specify the /D_LINES qualifier, debugging statements are compiled as a part of the source program. If you do not specify the /D_LINES qualifier, debugging statements are treated as comments. See the VAX FORTRAN User Manual for more information on the /D_LINES qualifier. 1.3.4 Continuation Indicator Field A continuation indicator is any character, except a zero or a space, in column 6 of a FORTRAN line, or any digit, except zero, after the first tab. The compiler considers the characters after the continuation character to be the characters following the last character of the previous line, as if there were no break at that point. If a continuation indicator is a zero or a space, the compiler considers the line to be an initial line of a FORTRAN statement. Comment lines cannot be continued. They can occur between a statement’s initial line and its continuation lines, or between successive continuation lines. Introduction to VAX FORTRAN 1-13 1.3.5 Statement Field The text of a FORTRAN statement is placed in the statement field. Because the compiler ignores the tab character and spaces (except in character and Hollerith constants), you can space the text in any way desired for maximum legibility. By default, the statement field extends to character position 72. If the default is in effect, any text following position 72 is ignored and no warning message is printed. However, if the /EXTEND_SOURCE qualifier is specified on the FORTRAN command line, the statement field is extended to position 132. Any text beyond that position generates a fatal error and causes immediate termination of the compilation. See the VAX FORTRAN User Manual for more information on the /JEXTEND_SOURCE qualifier. 1.3.6 Sequence Number Field By default, a sequence number or other identifying information can appear in columns 73 through 80 of any line in a FORTRAN program. The compiler ignores the characters in this field. However, if the /EXTEND_ SOURCE qualifier is specified on the FORTRAN command line, a sequence number field does not exist; the statement field is extended to position 132. See the VAX FORTRAN User Manual for more information on the 1.4 /EXTEND_SOURCE qualifier. Compilation Control Statements In addition to qualifiers on the FORTRAN command line, several statements used in the body of a VAX FORTRAN program also influence compilation: e DICTIONARY—extracts records from the Common Data Dictionary (CDD) and converts them into VAX FORTRAN records. e INCLUDE—incorporates external source code into programs. e OPTIONS—establishes compiler qualifiers otherwise specified on the FORTRAN command line; overrides command line qualifiers if a conflict occurs between OPTIONS statement qualifiers and command line qualifiers. 1-14 Introduction to VAX FORTRAN 1.4.1 DICTIONARY Statement The DICTIONARY statement incorporates VAX Common Data Dictionary data definitions into the current VAX FORTRAN source file during compilation. It can occur anywhere in a VAX FORTRAN source file that a specification statement can occur (see Chapter 4). The DICTIONARY statement takes the following form: DICTIONARY 'cdd-path [/[NOJLIST]' cdd-path Is interpreted as the full or relative pathname of a CDD object. /[NOJLIST Controls whether the source code representation of the resulting structure declaration is listed in a compilation source listing. The default is /NOLIST. Syntax Rules and Behavior There are two types of CDD pathname: full and relative. Their formation must conform to the rules for forming VAX CDD pathnames. A full pathname begins with CDD$TOP and specifies the given names of all its descendants; it is a complete path to the record definition. Descendant names are separated from each other by a period. A relative pathname begins with any generation name other than CDD$TOP and specifies the given names of the descendants after that point. A relative path comes into existence when a default directory is established with a logical name. Examples In the following example, the logical name definition specifies the beginning of the CDD pathname; thus, a relative pathname specifies the remainder of the path to the record definition: $ DEFINE CDD$DEFAULT CDD$TOP.FOR The following examples illustrate how a CDD pathname beginning with CDD$TOP overrides the default CDD pathname. Consider a record with the pathname CDD$TOP.SALES.JONES.SALARY. If you defined CDD$DEFAULT to be CDD$TOP.SALES.JONES, you could then specify a relative pathname: Introduction to VAX FORTRAN 1-15 DICTIONARY 'SALARY' Alternatively, you could specify a full pathname: DICTIONARY 'CDD$TOP.SALES.JONES.SALARY' See the VAX Common Data Dictionary Utilities Manual for further details. 1.4.2 INCLUDE Statement The INCLUDE statement directs the compiler to stop reading statements from the current file and read the statements in the included file or module. When it reaches the end of the included file or module, the compiler resumes compilation with the next statement after the INCLUDE statement. The INCLUDE statement takes one of the following forms: e) [/ [NO]JLIST]' (module-nam INCLUDE ‘'[text-1ib] INCLUDE 'file-spec[/[NO]JLIST]' text-lib Is a character string that specifies the text library to be searched. Its form must be acceptable to the operating system, as described in the VAX FORTRAN User Manual. file-spec Is a character string that specifies the file to be included. The form of the file-spec must be acceptable to the operating system, as described in the VAX FORTRAN User Manual. module-name Is the name of the text module, located in a text library, that is to be included. The name of the module must be enclosed in parentheses. It can be up to 31 characters long and can contain any alphanumeric character and the special characters dollar sign ($) and underscore (—). /[NOJLIST Specifies whether the incorporated code is to appear in the compilation source listing. In the listing, a number precedes each incorporated statement. The number indicates the “include” nesting depth of the code. The default is /NOLIST. 1-16 Introduction to VAX FORTRAN Syntax Rules and Behavior The INCLUDE statement and included files have the following rules: * An included file or module cannot begin with a continuation line. Each VAX FORTRAN statement must be completely contained within a single file or module. * An included file or module can contain an INCLUDE statement. * The INCLUDE statement can appear anywhere within a program unit. * Any VAX FORTRAN statement can appear in an included file or module. However, the included statements, when combined with the other statements in the compilation, must satisfy the statementordering restrictions described in Figure 1-1. Example In the following example, the file COMMON.FOR defines the size of the blank common block and the size of the arrays X, Y, and Z. Main Program File INCLUDE 'COMMON.FOR' DIMENSION Z(M) CALL CUBE DO 5 5, Z(I) COMMON.FOR File PARAMETER (M=100) COMMON X (M), Y(M) I=1,M = X(I)+SQRT(Y(I)) END SUBROUTINE CUBE INCLUDE DO 10 10, X(I) 'COMMON.FOR' I=1,M = Y(I)x*x3 RETURN END Introduction to VAX FORTRAN 1-17 1.4.3 OPTIONS Statement The OPTIONS statement overrides or confirms the FORTRAN command line qualifiers in effect for a program unit. It takes the following form: OPTIONS qualifier[qualifier...] qualifier Is one of the following: / [NO]1G_FLOATING 14 / [NO] / [NOJF77 ALL [NO]OVERFLOW /CHECK = [NO]BOUNDS [NO]UNDERFLOW NONE /NOCHECK / [NO]EXTEND_SOURCE Syntax Rules and Behavior The OPTIONS statement must be the first statement in a program unit, preceding the PROGRAM, SUBROUTINE, FUNCTION, and BLOCK DATA statements. OPTIONS statement qualifiers have the same syntax and abbreviations as the FORTRAN command line qualifiers, as described in the VAX FORTRAN User Manual. The OPTIONS qualifiers override FORTRAN command line qualifiers, but only until the end of the program unit in which they are defined. Thus, an OPTIONS statement must appear in each program unit in which you wish to override the command line qualifiers. 1-18 Introduction to VAX FORTRAN Example In the following example, the check and extend_source options do not remain in effect across program unit boundaries. The first OPTIONS statement specifies that only the program unit immediately following it is to be compiled with full checking and extend_source options, regardless of the /CHECK and /EXTEND_SOURCE specifications on the FORTRAN command line. The second OPTIONS statement specifies that only the program unit following it is to be compiled with the G_floating option. OPTIONS /CHECK/EXTEND_SOURCE END OPTIONS /G_FLOATING Introduction to VAX FORTRAN 1-19 Chapter 2 Data Types, Data Items, and Expressions This chapter contains information on the following topics: Data types—integer, real, complex, logical, character, and BYTE (Section 2.1) Data items—constants, variables, arrays, character substrings, and records (Section 2.2) Expressions—arithmetic, character, relational, and logical (Section 2.3) 2.1 Data Types Each constant, variable, array, expression, or function reference in a FORTRAN statement represents typed data. The data type of these items can be inherent in their constructions, implied by convention, or explicitly declared. The following data types are available in VAX FORTRAN: Integer—a whole number. REAL (REAL#*4) —a floating point number, that is, a whole number, a decimal fraction, or a combination of the two. DOUBLE PRECISION (REAL#*8) —similar to REAL*4, but has more than twice the degree of accuracy in its representation (the G_floating implementation also has an extended range). REAL*16—similar to REAL#*4 but has an extended range and more than four times the accuracy in its representation. Data Types, Data Items, and Expressions 2-1 e COMPLEX (COMPLEXx*8)—a pair of REAL*4 values that represent a complex number; the first value represents the real part of that number and the second represents the imaginary part. e DOUBLE COMPLEX (COMPLEX*16)—similar to complex; its real and imaginary parts are REAL*8. e Logical—a logical value, .TRUE. or .FALSE. e Character—a string of printable ASCII characters. e BYTE— a one-byte storage location that is equivalent to LOGICAL=*1. See Appendix C for descriptions of the VAX hardware representations of these data types. See Section 4.4 for descriptions of data type declaration statements. 2.1.1 Storage Requirements An important attribute of each data type is the amount of memory required to represent a value of that type. Variations on the basic types affect either the accuracy of the represented value or the allowed range of values. ANSI FORTRAN defines a numeric storage unit as the amount of storage needed to represent a REAL, INTEGER, or LOGICAL value. In VAX FORTRAN, a numeric storage unit corresponds to four bytes of memory. REAL*8 and COMPLEX*8 values occupy two of these numeric storage units, whereas REAL*16 and COMPLEXx16 values occupy four. ANSI FORTRAN defines a character storage unit as the amount of storage needed to represent one character value. In VAX FORTRAN, a character storage unit corresponds to one byte of memory. VAX FORTRAN provides additional data types for optimum selection of performance and memory requirements. Table 2-1 lists the data types available, the names associated with each data type, and the amount of storage required (in bytes). The form *n appended to a data type name is called a data type length specifier. 2-2 Data Types, Data Items, and Expressions Table 2-1: Data Type Storage Requirements Data Type Storage Requirements (in bytes) BYTE 1 LOGICAL 2 or 4° LOGICALx1 1! LOGICAL=*2 LOGICAL=*4 4 INTEGER 2 or 4° INTEGER*2 2 INTEGER*4 4 REAL 4 REAL*4 4 REAL=*8 8 DOUBLE PRECISION 8 REAL*16 16 COMPLEX 8 COMPLEX*8 COMPLEX*16 16 DOUBLE COMPLEX 16 CHARACTER=*len len’ CHARACTER=*(*) 'BYTE and LOGICAL*1 are equivalent. See Section C.3 for information on the range of values that can be stored in them. “Either two or four bytes are allocated, depending on the setting of the [NOJI4 qualifier on the FORTRAN command line. The default allocation is four bytes. The value of len is the number of characters specified, which can be in the range 1 to 65535. Passed-length format, *(*), applies to dummy arguments or character functions, and indicates that the length of the actual argument or function is used (see Section 6.1.1.3 and the VAX FORTRAN User Manual). Data Types, Data Items, and Expressions 2-3 2.1.2 VAX Implementations of REAL*8 The REAL#*8 (and thus, COMPLEX*16) data type has two implementations on a VAX computer: D_floating and G_floating. The G_floating implementation offers a greater range but is less precise, having a smaller number of significant digits. D_floating is the default implementation of REAL#*8. You can select G_floating by using the OPTIONS statement or the /G_FLOATING qualifier on the FORTRAN command line. Some VAX processors emulate floating-point data types rather than executing them in hardware or microcoded instruction. Processing time with software emulation is much slower. Thus, you should be aware of which data types are emulated on your system and choose them (especially REAL=*8) with this information in mind. See Sections 2.2.1.2, C.5, C.5.2, and C.5.3 for more detailed information on the two implementations of the REAL#8 data type. 2.2 Dataltems VAX FORTRAN statements use the following data items: e Constants—fixed, self-describing values. e Variables—stored values represented by symbolic names. e Arrays—groups of values that are stored contiguously and can be referred to individually or collectively. Individual values are called array elements. e e Character substrings—a contiguous segment of a character variable or character array element. Records—structured data items consisting of one or more elements (variables and arrays) or one or more groups of these elements. Different record elements in the same record can have unlike data types. 2-4 Data Types, Data Items, and Expressions 2.2.1 Constants A constant is a data item with a fixed value that cannot be changed during program execution. The value of a constant can be a numeric value, a logical value, or a character string. There are eight types of constants: * Integer * Real e Complex ® QOctal e Hexadecimal * Logical e (Character e Hollerith Octal, hexadecimal, and Hollerith constants have no data type. They assume a data type that conforms to the context in which they appear (see Sections 2.2.1.4 and 2.2.1.7). All eight types of constants are scalar references in that they resolve into single, typed data items. (See Section 2.2.6 for more information on scalar references.) 2.2.1.1 Integer Constants An integer constant is a whole number with no decimal point. It can have a leading sign and is interpreted as a decimal number. Integer constants take the following form: snn S Is an optional sign. nn Is a string of decimal digits. Any leading zeros are ignored. Data Types, Data ltems, and Expressions 2-5 Syntax Rules A minus sign must appear before a negative integer constant, whereas a plus sign is optional before a positive constant (an unsigned constant is assumed to be positive). Except for a leading algebraic sign, an integer constant cannot contain any character other than the numerals 0 through 9. The value of an integer constant must be within the range -2147483648 to 2147483647. Examples The following examples demonstrate valid and invalid integer constants and explain why the invalid ones are not valid: Valid 0 -127 +32123 Invalid Explanation 99999999999 Number too large 3.14 Decimal point not allowed 32,767 Comma not allowed If the value of the constant is within the range -32768 to 32767, it represents a 2-byte signed quantity and is treated as an INTEGER#*2 data type. If the value is outside that range, it represents a 4-byte signed quantity and is treated as an INTEGER*4 data type. Integer constants can be used to assign signed and unsigned values to BYTE, LOGICAL*1, LOGICAL#*2, and INTEGER*2 data. BYTE and LOGICAL=*1 can contain signed integers with a range of -128 to 127 or unsigned integers with a range of 0 to 255. LOGICAL*2 and INTEGER=*2 can contain signed integers with a range of -32768 to 32767 or unsigned integers with a range of 0 to 65535. The following table illustrates VAX FORTRAN assignments to different data and lists the integer and hexadecimal values in the data: 2-6 Data Types, Data Items, and Expressions VAX FORTRAN Assignment Integer Value Hexadecimal Value -128 127 -1 '80'X '7F'X 'FF'X -128 127 -1 '80'X "7E'X 'FF'X -32768 32767 -1 '8000'X '"7FFF'X 'FFFF'X -32768 32767 -1 '8000'X '7FFF'X 'FFFF'X in the Data in the Data BYTE X X =-128 X =127 X =255 LOGICAL*1 X X =-128 X =127 X =255 LOGICAL*2 X X =-32768 X = 32767 X = 65535 INTEGER#*2 X X =-32768 X = 32767 X = 65535 Integer constants can also be specified in octal form, as described in Sections 2.2.1.4 and A.5. Data Types, Data Items, and Expressions 2-1 2.2.1.2 Real Constants A real constant is a number written with a decimal point, exponent, or both. The constant can be positive, zero, or negative. It can have single precision (REAL*4), double precision (REAL*8), or quad precision (REAL*16), REAL*4 (REAL) Constants A REAL*4 constant can be any one of the following: ® Basic real constant * Basic real constant followed by a decimal exponent * Integer constant followed by a decimal exponent A basic real constant takes one of the following forms: sS.nn sSnn.nn snn. S Is an optional sign. nn Is a string of decimal digits. A decimal point can appear anywhere in the string. A decimal exponent takes the following form: Esnn S Is an optional sign. nn Is a string of decimal digits. Syntax Rules and Behavior A REAL#*4 constant occupies four bytes of VAX storage. It is interpreted as a real number with a degree of precision that is typically seven decimal digits (see Sections C.5 and C.5.1. 2-8 Data Types, Data Items, and Expressions The number of digits is not limited, but typically only the leftmost seven digits are significant. Leading zeros (zeros to the left of the first nonzero digit) are ignored in counting the leftmost seven digits. Thus, in the constant 0.00001234567, all of the nonzero digits, and none of the zeros, are significant. The exponent represents a power of 10 by which the preceding real or integer constant is to be multiplied (for example, 1.0E6 represents the value 1.0 * 10%*6). A minus sign must appear before a negative REAL*4 constant; a plus sign is optional before a positive constant. Similarly, a minus sign must appear between the letter E and a negative exponent, whereas a plus sign is optional between the letter E and a positive exponent. A REAL#*4 constant can only contain the numerals 0 through 9, algebraic signs, a decimal point, and the letter E. When the letter E appears in a REAL*4 constant, an integer constant exponent field must follow. The exponent field cannot be omitted, but it can be zero. The magnitude of a nonzero REAL*4 constant cannot be smaller than approximately 0.29E-38 or greater than approximately 1.7E38. Examples The following examples demonstrate valid and invalid REAL*4 constants and explain why the invalid ones are not valid: Data Types, Data Items, and Expressions 2-9 Valid 3.14159 621712. -.00127 +5.0E3 2E-3 Invalid Explanation 1,234,567. Commas not allowed 325E-45 Too small -47 .E47 Too large 100 Decimal point missing - this is a valid integer constant $25.00 Special character not allowed REAL+*8 (DOUBLE PRECISION) Constants A REAL#*8 constant is a basic real constant or an integer constant followed by a decimal exponent. Its decimal exponent takes the following form: Dsnnn S Is an optional sign. nnn Is a string of decimal digits. Syntax Rules and Behavior A REAL*8 constant occupies eight bytes of VAX storage. The number of digits that precede the exponent is unlimited. Both D_floating and G _floating implementations of REAL*8 have the same syntax and storage requirements. However, they differ in the num- ber of significant digits and exponential range. D_floating implementation typically has 16 (leftmost) significant numbers and a two-digit exponent, On the other hand, G_floating typically has 15 (leftmost) significant digits and a three-digit exponent. See Sections C.5, C.5.2, and C.5.3. D_floating is the default implementation. To select G_floating implemen- tation, you must include the command line. 2-10 Data Types, Data Items, and Expressions /G_FLOATING qualifier on the FORTRAN A minus sign must appear before a negative REAL*8 constant; a plus sign is optional before a positive constant. Similarly, a minus sign must appear between the letter D and a negative exponent, whereas a plus sign is optional between the letter D and a positive exponent. A REAL#*8 constant can only contain the numerals 0 through 9, algebraic signs, a decimal point, and the letter D. An integer constant exponent field must follow the letter D. The exponent field cannot be omitted, but it can be zero. The magnitude of a nonzero REAL*8 constant cannot be less than approximately 0.29D-38 or greater than approximately 1.7D38 for the D_floating implementation; nor can it be less than approximately 0.56D-308 or greater than approximately 0.9D308 for the G _floating implementation. Examples The following examples demonstrate valid and invalid D_floating and G_floating REAL*8 constants and explain why the invalid ones are not valid: D_floating REAL*8 Constants Valid 1234567890D+5 +2.71828182846182D00 -72.5D-15 1DO Invalid Explanation 1234567890D45 Too large 1234567890 .0D-89 Too small +2.7182812846182 No Dsnnn present; this is a valid single-precision constant Data Types, Data Items, and Expressions 2-11 G_floating REAL*8 Constants Valid 123456789.D0 +2.34567890123D-5 -1D+300 Invalid Explanation 123456789 .D400 Too large 123456789.D-400 Too small REAL+*16 Constants A REAL*16 constant is a basic real constant or an integer constant fol- lowed by a decimal exponent. Its decimal exponent takes the following form: (snnnn s Is an optional sign. nnnn Is a string of decimal digits. Syntax Rules and Behavior A REAL*16 constant occupies 16 bytes of VAX storage. The number of digits that precede the exponent is unlimited; however, typically only the leftmost 33 digits are significant (see Sections C.5 and C.5.4). A minus sign must appear before a negative REAL*16 constant, but a plus sign is optional before a positive constant. Similarly, a minus sign is required between the letter Q and a negative exponent, but a plus sign is optional between the letter Q and a positive exponent. A REAL*16 constant can only contain the numerals 0 through 9, algebraic signs, a decimal point, and the letter Q. An integer constant exponent field must follow the letter Q. The exponent field cannot be omitted, but it can be zero. The magnitude of a nonzero REAL*16 constant cannot be less than approximately 0.84Q-4932 or greater than approximately 0.59Q4932. 2-12 Data Types, Data Items, and Expressions Examples The following examples demonstrate valid and invalid REAL*16 constants and explain why the invalid ones are not valid: Valid 123456789Q4000 -1.23Q-400 +2.72Q0 2.2.1.3 Invalid Explanation 1.Q5000 Too large 1.Q-5000 Too small Complex Constants A complex constant is a pair of real or integer constants. The two con- stants are separated by a comma and enclosed in parentheses. The first constant represents the real part of that number; the second constant represents the imaginary part. VAX FORTRAN supports COMPLEX*8 and COMPLEX*16 complex constants. COMPLEX+8 (COMPLEX) Constants A COMPLEX=*8 constant is a pair of integer or REAL*4 constants that represents a complex number. It takes the following form: (c,c) c Is an integer or REAL#*4 constant. The parentheses and comma are required parts of the constant. (See Section 2.2.1.2 for the rules for forming REAL*4 constants.) A COMPLEX*8 constant occupies eight bytes of VAX storage and is interpreted as a complex number (see Sections C.5 and C.5.5). Data Types, Data ltems, and Expressions 2-13 Examples The following examples demonstrate valid and invalid COMPLEX*8 constants and explain why the invalid ones are not valid: Valid (1.7039,-1.70391) (+12739E3,0.) (1,2) Invalid Explanation (1.23,) Missing second REAL constant (1.0,1.0Q0) REAL*16 constant not allowed COMPLEX*16 (DOUBLE COMPLEX) Constants A COMPLEX*16 constant is a pair of constants that represents a complex number. One constant must be REAL*8; the other must be an integer, REAL*4, or REAL*8. The two constants are separated by a comma and enclosed in parentheses; the first constant represents the real part of the complex number, the second the imaginary part. There are two implementations of COMPLEX*16, corresponding to the D_floating and G _floating implementations of REAL#*8. A COMPLEX*16 constant takes the following form: (c,c) c Is an integer, a REAL*4, or a REAL*8 constant. (One of the pair must be a REAL*8 constant.) A COMPLEX#*16 constant occupies 16 bytes of VAX storage and is interpreted as a complex number (see Sections C.5, C.5.6, and C.5.7). The parentheses and the comma are required parts of the constant. Syntax rules for REAL*8 constants also apply to the REAL*8 portion of COMPLEX=*16 constants. 2-14 Data Types, Data ltems, and Expressions Examples The following examples demonstrate valid and invalid COMPLEX*16 constants and explain why the invalid examples are not valid: Valid (1.7039D0, -1.7039D0) (+12739D3,0.D0) Invalid Explanation (1.23D0) Second constant missing (0.8Q0,0.4Q0) REAL#*16 constants not allowed (1.0D300, -1.0D300) Both constants out of range for D_floating implementation of REAL*8; they are valid for G_floating implementation of REAL*8 2.2.1.4 Octal and Hexadecimal Constants Octal and hexadecimal constants are alternative ways to represent numeric constants. They can appear wherever numeric constants are allowed. An octal constant is a string of octal digits enclosed by apostrophes and followed by the letter O. It takes the following form: 'clc2c3...¢cn'0 cn Is a digit with a range of 0 to 7. A hexadecimal constant is a string of digits enclosed by apostrophes and followed by the alphabetic character X. It takes the following form: 'c1c2c3...cn'X cn Is a digit in the range of 0 to 9, or an uppercase or lowercase letter in the range of A to F. Leading zeros are ignored in octal and hexadecimal constants. You can specify up to 128 bits (43 octal digits, 32 hexadecimal digits). Data Types, Data Iltems, and Expressions 2-1b Examples The following examples demonstrate valid and invalid octal and hexadecimal constants and explain why the invalid ones are not valid: Octal Constants Valid '07737'0 '1'0 Invalid Explanation '7782'0 The character 8 is invalid 7772'0 No initial apostrophe '0737" No O after second apostrophe Hexadecimal Constants Valid "AF9730'X 'FFABC'X Invalid Explanation '999. 'X Invalid character 'FOX No apostrophe before X Data-Typing Octal and Hexadecimal Constants Octal and hexadecimal constants have no data type until they are used. When used, they assume a data type based on their use. When the constant is used with a binary operator, including the assign- ment operator, the data type of the constant is the data type of the other operand. For example: 2-16 Data Types, Data ltems, and Expressions Length of Data Type of Constant (in bytes) RAPHA = '99AF2'X REAL*4 4 JCOUNT = ICOUNT + '777'0 INTEGER*2 2 DOUBLE = 'FFF99A'X REAL*8 8 IF (N .EQ. INTEGER*4 4 Statement Constant INTEGER*2 ICOUNT REAL*8 DOUBLE '123'0) GO TO 10 When a specific data type (generally integer) is required, that type is assumed for the constant. For example: Statement Constant Length of Constant (in bytes) Y(IX) = Y('15'0) + 3. INTEGER*4 4 Data Type of When the constant is used as an actual argument, no data type is assumed. However, a length of four bytes is always used. For example: Length of Data Type of Constant Statement Constant (in bytes) CALL APAC('34BC2'X) None 4 When the constant is used in any other context, an INTEGER#*4 data type is assumed (or an INTEGER=*2 data type if /NOI4 is in effect). For example: Length of Statement Data Type of Constant Constant (in bytes) IF ('AF77'X) 1,2,3 INTEGER*4 4 INTEGER*4 4 INTEGER*4 4 = '"7777'0 - 'A39'X J = .NOT. '73777'0 An octal or hexadecimal constant specifies up to 16 bytes of data. When the data type implies that the length of the constant is more than the Data Types, Data ltems, and Expressions 2-17 number of digits specified, the leftmost digits have a value of zero. When the data type implies that the length of the constant is less than the number of digits specified, the constant is truncated on the left. An error results if any nonzero digits are truncated. Table 2-1 lists the number of bytes that each data type requires. 2.2.1.5 Logical Constants A logical constant specifies a logical value, true or false. Thus, only the following two logical constants are possible: .TRUE. .FALSE. Both delimiting periods are required. 2.2.1.6 Character Constants A character constant is a string of printable ASCII characters enclosed by apostrophes. It takes the following form: 'clc2c3...cn' cn Is a printable ASCII character. Syntax Rules and Behavior Both delimiting apostrophes are required. 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. The length of the character constant is the number of characters between the apostrophes, except that two consecutive apostrophes represent a single apostrophe. The length of a character constant must be in the range of 1 to 2000. 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 2.2.1.7). 2-18 Data Types, Data Items, and Expressions Examples The following examples demonstrate valid and invalid character constants and explain why the invalid ones are not valid: Valid 'WHAT?' '"TODAY''S DATE IS:' 'HE SAID, "HELLO"' Invalid Explanation 'HEADINGS No trailing apostrophe Vo Character constant must contain at least one character "NOW/OR NEVER" Q}:mtation marks cannot take the place of apostrophes 2.2.1.7 Hollerith Constants A Hollerith constant is a string of printable ASCII characters preceded by a character count and the letter H. It takes the following form: nHclc2c3...cn n Is an unsigned, nonzero integer constant stating the number of characters in the string (including spaces and tabs). cn Is a printable ASCII character. Hollerith constants are strings of 1 to 2000 characters. They are stored as byte strings, one character per byte. Examples The following examples demonstrate valid and invalid hollerith constants and explain why the invalid ones are not valid: Data Types, Data ltems, and Expressions 2-19 Valid 16HTODAY'S DATE IS: 1HB Invalid Explanation 3HABCD Wrong number of characters OH Hollerith constants must contain at least one character Data-Typing Hollerith Constants Hollerith constants have no data type. They assume a numeric data type based on the way they are used. Hollerith constants cannot assume a character data type and cannot be used where a character value is expected. When the constant is used with a binary operator, including the assignment operator, the data type of the constant is the data type of the other operand. For example: Data Type of Length of Constant Constant (in bytes) RALPHA = 4HABCD REAL*4 4 JCOUNT = ICOUNT + 2HXY INTEGER*2 2 DOUBLE = 8HABCDEFGH REAL*8 8 IF (N. EQ. 1HZ) GO TO 10 INTEGER*4 4 Statement INTEGER*2 ICOUNT REAL*8 DOUBLE When a specific data type is required (generally integer), that type is assumed for the constant. For example: 2-20 Data Types, Data Items, and Expressions Length of Data Type of Constant Statement Constant (in bytes) Y(IX) = Y(1HA) + 3. INTEGER*4 4 When the constant is used as an actual argument, no data type is assumed. Length of Data Type of Constant Statement Constant (in bytes) CALL APAC(9HABCDEFGHI) None 9 When the constant is used in any other context, an INTEGER#*4 data type is assumed (or an INTEGER*2 data type if /NOI4 is in effect). For example: Length of Data Type of Constant Statement Constant (in bytes) IF (2HAB) 1,2,3 INTEGER*4 4 I = 1HC - 1HA INTEGER*4 4 J = .NOT. 1HB INTEGER*4 4 When the length of the constant is less than the length implied by the data type, spaces are appended to the constant on the right. When the length of the constant is greater than the length implied by the data type, the constant is truncated on the right. An error results if any characters other than space characters are truncated. Table 2-1 (in Section 2.1.1) lists the number of characters required for each data type. Each character occupies one byte of storage. Data Types, Data Items, and Expressions 2-21 2.2.2 \ariables A variable is represented by a symbolic name associated with a storage location. The value of the variable is the value currently stored in that location; you can change its value at any point in a program by assigning a new value to it. (See Section 1.1.3 for the form of a symbolic name.) Variables are classified by data type, just as constants are. The data type of a variable indicates the type of data it contains, its precision, and its storage requirements. When data of any type is assigned to a variable, it is converted, if necessary, to the data type of the variable. The following statements and rules establish the data type of a variable: * Type declaration statements e IMPLICIT statements * Predefined typing rules All types of variables are scalar references in that they resolve into single, typed data items. (Section 2.2.6 discusses scalar references.) Associating Variables Two or more variables are associated with each other when each is associated with the same storage location. They are partially associated when part (but not all) of the storage associated with one variable is the same as part or all of the storage associated with another variable. Association and partial association occur when you use COMMON or EQUIVALENCE statements; MAP declarations (within structure declaration blocks) or actual arguments and dummy arguments in subprogram references. If variables of different data types are associated (or partially associated) with the same storage location, and the value of one variable is defined (for example, by assignment), the value of the other variable becomes undefined. This occurs because a variable is defined only if the storage associated with it contains data of the same type as the name. A variable can be defined before program execution by a DATA statement or during execution by an assignment or input statement. 2-22 Data Types, Data Items, and Expressions 2.2.2.1 Data Type by Specification Data type declaration statements explicitly specify the data type of vari- ables (see Section 4.4). For example, the following statements associate VAR1 with an 8-byte complex-data storage location, and VAR2 with an 8-byte double-precision storage location: COMPLEX VAR1 DOUBLE PRECISION VAR2 You can explicitly specify the data type of a variable only once. An explicit data type specification takes precedence over the type specified by an IMPLICIT statement. The data type specified by an IMPLICIT statement associates with a variable only when an explicit specification is absent. Thus, in the absence of an explicit specification, any variable with a name that begins with the letter in the range specified in the IMPLICIT statement becomes the data type of the variable. Character type declaration statements (see Sections 4.4 and 4.4.2) specify that given variables represent character values with the length specified. For example, the following statements associate the variable names INLINE, NAME, and NUMBER with storage locations containing character data of lengths 72, 12, and 9, respectively: CHARACTER*72 INLINE CHARACTER NAMEx12, NUMBERx*9 In single subprograms, passed-length character arguments process character strings with different lengths. The passed-length character argument has a length specification of asterisk (*); for example: CHARACTER* (*) CHARDUMMY The passed-length character argument assumes the length of the actual argument. (See Section 6.1.1.3 and the VAX FORTRAN User Manual.) Data Types, Data ltems, and Expressions 2-23 2.2.2.2 Data Type by Implication In the absence of either IMPLICIT statements or explicit data type declarations, all variables with names beginning with I, J, K, L, M, or N are assumed to be integer variables. Variables with names beginning with any other letter are assumed to be REAL*4 variables. For example: 2.2.3 Real Variables Integer Variables ALPHA JCOUNT BETA ITEM TOTAL NTOTAL Arrays An array is a group of contiguous storage locations associated with a single symbolic name, the array name. The individual storage locations, array elements, are referenced by a subscript appended to the array name. An array can have from one to seven dimensions. For example, a column of figures is a one-dimensional array. A table with more than one column of figures is a two-dimensional array. To refer to a specific value in this array, you must specify both its row and column numbers. A table of figures that covers several pages is a three-dimensional array. To locate a value in this array, you must specify the page, row, and column numbers. The following VAX FORTRAN statements establish arrays: e Data type declaration (see Section 4.4) e DIMENSION (see Section 4.5) e COMMON (see Section 4.2) These statements contain array declarators that define the name of the array, the number of dimensions in the array, and the number of elements in each dimension. Associating Arrays Two or more arrays are associated when each one is associated with the same storage location. They are partially associated when part of the storage associated with one array is the same as part or all of the storage associated with another array. 2-24 Data Types, Data ltems, and Expressions Association and partial association occur when you use COMMON or EQUIVALENCE statements; MAP declarations (within structure declara- tion blocks); or actual arguments and dummy arguments in subprogram references. If arrays with different data types are associated (or partially associated) with the same storage location, and the value of one array is defined (for example, by assignment), the value of the other array becomes undefined. This happens because an element of an array is considered defined only if the storage associated with it contains data of the same type as the array name (see Section 2.2.3.3). The DATA statement defines an array element or an entire array before program execution. During program execution, array elements are defined by an assignment or input statement, and entire arrays are defined by input statements. 2.2.3.1 Array Declarators An array declarator specifies the symbolic name that identifies an array within a program unit and indicates the properties of that array. It takes the following form: a(al,d] ...) a Is the symbolic name of the array. (Section 1.1.3 gives the form of a symbolic name.) d Is a dimension declarator that can specify both a lower bound and an upper bound: [d1:]du dl Is the lower bound of the dimension. du Is the upper bound of the dimension. An asterisk (*) can be used as an upper bound, but only for the last dimension of a dummy argument. An asterisk marks the declarator as an assumed-size array declarator (see Section 6.1.1.2). The number of dimension declarators indicates the number of dimensions in the array. The number of dimensions can range from one to seven. Data Types, Data Items, and Expressions 2-25 The value of the lower-bound dimension declarator can be negative, zero, or positive. The value of the upper-bound dimension declarator must be greater than or equal to that of the corresponding lower-bound dimension declarator. The number of elements in the dimension is du — dl + 1. If a lower bound is not specified, it is assumed to be one, and the value of the upper bound specifies the number of elements in that dimension. For example, a dimension declarator of 50 indicates that the dimension contains 50 elements. Each dimension bound is an integer arithmetic expression in which each operand is a constant, a dummy argument, or a variable in a common block. The expression is converted to an integer if necessary. The type of a variable used in a bound expression cannot be changed by a later type declaration. NOTE Do not use array references and references to user-defined functions in dimension bounds expressions. Dimension bounds that are not constant expressions can be used in a subprogram to define adjustable arrays. You can use adjustable arrays within a single subprogram to process arrays with different dimension bounds by specifying the array name as a subprogram argument, and by either specifying the bounds as subprogram arguments or by placing the bounds in a common block. (See Section 6.1.1.1 for more information on adjustable arrays.) Dimension bounds that are not constant expressions are not permitted in a main program. The number of elements in an array is equal to the product of the number of elements in each dimension. An array name can appear in only one array declarator within a program unit, 2-26 Data Types, Data Items, and Expressions 2.2.3.2 Array Subscripts A subscript qualifies an array name. A subscript is a list of expressions, called subscript expressions, enclosed in parentheses, that determine which element in the array is referred to. The subscript is appended to the array name it qualifies. Subscript array references are scalar references in that they resolve into single, typed data items. (Section 2.2.6 describes this terminology.) A subscript takes the following form: (s(,s]...) S Is a subscript expression. A subscripted array reference must contain one subscript expression for each dimension defined for that array (one for each dimension declarator). Each subscript can be any valid arithmetic expression. However, noninteger subscript expressions are converted to integers before use (any fractional parts are truncated). 2.2.3.3 Arrangement of Array Elements in Storage As discussed earlier in this section, you can think of the dimensions of an array as pages, rows, and columns. However, FORTRAN actually stores arrays in memory as a linear sequence of values. A one-dimensional array is stored with its first element in the first storage location and its last element in the last storage location of the sequence. A multidimensional array is stored so that the leftmost subscripts vary most rapidly. This is called the “order of subscript progression.” For example, Figure 2-1 shows array storage in one, two, and three dimensions. Data Types, Data Items, and Expressions 2-27 Array Storage Figure 2-1: One-Dimensional Array BRC (6) r1 [BRC(1)] 2 ]BRC(z)I 3 IBRC(B)I 4 [BRC(4)1 5 ]BRC(s)l 6 lBRC(G)] Memory Positions Two-Dimensional Array BAN (3,4) 4 | BAN(1,2)] 7 |BAN(1,3)] BAN(2,1)| 5 | BAN(2,2)| 8 BAN(3,1)| 6 | BAN(3,2)] 9 |BAN(3,3)] |BAN(2,3)] 10 BAN(1,4)] 1 ,BAN(2,4)| ot 1 | BAN(1,1)] 12 BAN(3,4)| Memory Positions Three-Dimensional Array BOS (3,3,3) 19 | BOS(1,1,3) | 22| BOS(1,2,3) | 25| BOS(1,3,3) BOS(2,1,3) | 23| BOS(2,2,3) | 26| BOS(2,3,3) 20| Fo B0s(1,1.2) |13| Bos(1.2.2) | 16| BOS(1,3,2) |11 B0OS(2,1,2) | 14| BOS(2,2,2) | 17| BOS(2,3,2) 1 | Bos(.1.1)} 4 | BOS(1,2,1) BOs(1,3,1) § | 18] BOSG.3.2) 2 | BOS(2,1,1) | 5 | BOS(2,2.1) BOS(2,3,1) 6 | BOS(3,2,1) BOS(3,3,1) 3 | BOs(3,1,1)7] {127 | BOS(:3.3) Memory Positions ZK-616-82 2-28 Data Types, Data ltems, and Expressions 2.2.3.4 Data Type of an Array The data type of an array is specified in the same way as the data type of a variable—implicitly by the initial letter of the name, or explicitly by a data type declaration statement (see Sections 2.2.2.1 and 2.2.2.2). All the values in an array have the same data type. Any value assigned to an array element is converted to the data type of the array. If an array is named in a DOUBLE PRECISION statement, for example, the compiler allocates an 8-byte storage location for each element of the array. When a value of any type is assigned to any element of that array, the value is converted to double precision. 2.2.3.5 Array References without Subscripts In the following statements, you can specify an array name without a subscript to indicate that the entire array is to be used (or defined): e COMMON « DATA e EQUIVALENCE e NAMELIST e SAVE ¢ 1/0 * Data type declaration You can also use unsubscripted array names as dummy arguments in FUNCTION, SUBROUTINE, and ENTRY statements, and as actual arguments in references to external procedures. Using unsubscripted array names is not permitted in all other types of statements. 2.2.3.6 Adjustable Arrays Adjustable arrays allow subprograms to manipulate arrays of variable dimensions. To use an adjustable array in a subprogram, you specify the array bounds, as well as the array name, as subprogram arguments. The bounds may also be given in a common block. See Section 6.1.1.1 for more information. Data Types, Data Items, and Expressions 2-29 2.2.3.7 Assumed-Size Arrays Assumed-size arrays are similar to adjustable arrays. With assumed-size arrays, however, an asterisk is used to specify the upper bound of the last dimension. Section 6.1.1.2 describes the rules governing the dimensions that are assumed. 2.2.4 Character Substrings A character substring is a contiguous segment of a character variable or character array element. It takes one of the following forms: v([e1]: [e2]) a(s[,s]...) ([e1]:[e2]) v Is a character variable name. a Is a character array name. S Is a subscript expression. el Is a numeric expression that specifies the leftmost character position of the substring. e2 Is a numeric expression that specifies the rightmost character position of the substring. Character positions within a character variable or array element are numbered from left to right, beginning at one. For example, LABEL(2:7) speci- fies the substring beginning with the second character position and ending with the seventh character position of the character variable LABEL. If the CHARACTER#8 variable LABEL has a value of 'XVERSUSY’, then the substring LABEL(2:7) has a value of VERSUS. If the value of the numeric expression el or e2 is not of type integer, it is converted to an integer value by truncating any fractional part before use. 2-30 Data Types, Data Items, and Expressions The values of the numeric expressions el and e2 must meet the following conditions: (1 .LE. e1) .AND. (el .LE. e2) .AND. (e2 .LE. len) len Is the length of the character variable or array element. If el is omitted, FORTRAN assumes that el equals one. If e2 is omitted, FORTRAN assumes that e2 equals len. 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). 2.2.5 Records A record is an aggregate entity containing one or more elements. (Record elements are also called fields or components.) You can use records when you need to declare and operate on multifield data structures in your VAX FORTRAN programs. You can also access records in the VAX Common Data Dictionary (CDD) and use them in your programs. NOTE Do not confuse a VAX FORTRAN record with an RMS 1/0 record. VAX FORTRAN records are named data entities with one or more fields that you create in your program. A record is similar to an array in that they both contain one or more elements. However, a record differs from an array in the following respects: * Unlike arrays, which are defined by a single declaration statement, creating a record is a two-step process: 1. Defining the form of the record with a multistatement structure declaration. 2. Declaring the record as an entity with a symbolic name, thus establishing its structure in memory. More than one RECORD statement can refer to a given structure. * Unlike arrays, whose data elements must have the same data type, records can have fields with different data types. Because records have heterogeneous data elements, they are not typed as arrays are. Record fields can be operated on individually or collectively. Data Types, Data Items, and Expressions 2-31 e Unlike array elements, each element of a record can be named. References to a record element consist of both the name of the record containing the element and the name of the desired element. Structure Declaration Blocks A structure declaration block is a named group of statements that define the form of a record. To establish a structure declaration in memory, its name must be specified in a RECORD statement. A structure declaration block includes one or more of the following items: * Data Type Declarations (variables or arrays): Data type declarations in structure declarations have the form of normal VAX FORTRAN data type declarations. Data items with different types can be freely intermixed within a structure declaration. For example, INTEGER and LOGICAL data items can be declared in the same structure. e Substructure Declarations: Substructures can be established with a structure by using either a nested structure declaration or a RECORD statement. — Structure declarations can be nested within structure declarations. A nested structure declaration must have one or more field names specified on its STRUCTURE statement. A nested structure declaration can optionally be given a structure name for later reference by a RECORD statement. — The fields in another, previously declared, structure declaration can be incorporated in a structure by including, within a structure declaration, a RECORD statement naming the other structure. This feature enables you to create a structure declaration and then include it, as necessary, as a substructure declaration within other structure declarations. Depending on the needs of an application, this can have advantages over the use of nested structure declarations, which are individually coded within a containing, outer structure. e Mapped Field Declarations: Mapped field declarations are made up of one or more typed data declarations, substructure declarations (nested structure declarations and RECORD statements), or other mapped field declarations. 2-32 Data Types, Data Items, and Expressions Mapped field declarations are defined by a block of statements called a union declaration. Unlike typed data declarations, all mapped field declarations that are made within a single union declaration share a common location within the containing structure. This capability is similar to using EQUIVALENCE statements to give names to variables and arrays. In other languages, it is called a “variant record” capability. * Unnamed Fields: Unnamed fields can be declared in a structure by specifying %FILL in place of an actual field name. This mechanism can be used to generate space in a record for purposes such as alignment. Unnamed fields cannot be initialized. For example, the following field declaration is invalid and generates an error message: INTEGER*4 %FILL /1980/ For a detailed description of the syntax and use of RECORD statements and structure declarations, see Sections 4.13 and 4.15. 2.2.5.1 Arrangement of Records in Storage FORTRAN stores a record in memory as a linear sequence of values, with the record’s first element in the first storage location and its last element in the last storage location. No gaps are left between elements. A record array is stored in a similar fashion, with no gaps between array elements. Examples The following examples contain structure declaration blocks, RECORD statements, and diagrams of the resulting records as they are stored in memory. The first example shows a basic structure declaration block and RECORD statement: Source Code STRUCTURE /STRA/ CHARACTER*1 INTEGER*4 CHR INT END STRUCTURE RECORD /STRA/ REC,AREC(2) Data Types, Data ltems, and Expressions 2-33 Memory Diagram 0O 1 5 (byte offset) REC.CHR REC.INT Record REC ZK-1844-84 0 1 5 6 10 (byte offset) 44 AREC(1).CHR { §- AREC(1).INT AREC(2).CHR AREC(2).INT {C —~———— { ( e —— — Record array AREC ZK-1843-84 2-34 Data Types, Data Items, and Expressions The next example includes a substructure: Source Code STRUCTURE /STRB/ REAL*8 FLT RECORD /STRA/ STR(2) END STRUCTURE RECORD /STRB/ NRD Memory Diagram 8 9 13 14 18 L NRD.STR(1)}.CHR NRD.FLT NRD.STR{1}.INT 10g NRD.STR(2).CHR NRD.STR(2).INT d € o r (byte offset) £ ¢ 2y 4 ¢ 4 7 WW Substructure STRA (STR(1)) ‘—v" Substructure STRA (STR(2)) j Record NRD ZK-1842-84 The next example shows how unions cause the storage of the associated mapped fields to be overlaid: Source Code STRUCTURE /STR/ INTEGER*4 TAG UNION MAP REAL*4 FLT CHARACTER*2 CHR END MAP MAP INTEGER*2 INT END MAP END UNION LOGICAL*1 LOG END STRUCTURE Data Types, Data ltems, and Expressions 2-35 Memory Diagram 0 4 6 FLT TAG INT 8 10 11 (byte offset) CHR l (unused) LOG Area for mapped fields ZK-1845-84 2.2.5.2 References to Record Fields References to record fields must correspond to the kind of field being referenced. Aggregate field references refer to composite structures (and substructures). Scalar field references refer to singular data items, such as variables. An operation on a record can involve one or more fields. Record field references take one of the following forms: Aggregate Field Reference record-name[.aggregate-field-name] . .. Scalar Field Reference record-name[.aggregate-field-name] ... .scalar-field-name record-name Is the name used in a RECORD statement to identify a record. See Section 4.13 for a description of the RECORD statement. aggregate-field-name Is the name of a field that is a substructure (a record or a nested structure declaration) within the record structure identified by the record name. See Section 4.15 for a description of how fields are specified within structure declarations. scalar-field-name Is the name of a typed data item defined within a structure declaration. 2-36 Data Types, Data ltems, and Expressions Scalar field references are scalar references in that they resolve into single, typed data items. Conversely, aggregate field references are aggregate references in that they resolve into references to structured data items: records and nested structure declarations. Aggregate field references are the only references that fall into the aggregate reference category. (Section 2.2.6 discusses this terminology.) Syntax Rules and Behavior Records and record fields cannot be used in EQUIVALENCE statements. However, you can make fields of record structures equivalent to them- selves by using the UNION and MAP statements in a structure declaration block (see Section 4.15.1). A scalar field reference consists of the name of a record (as specified in a RECORD statement) and zero or more levels of aggregate field names followed by the name of a scalar field. A scalar field reference refers to a single, typed data item and can be treated like a normal reference to a FORTRAN variable or array element. Scalar field references can be used in statement functions and in exe- cutable statements. However, they cannot be used in COMMON, SAVE, NAMELIST, or EQUIVALENCE statements, or as the control variable in an indexed DO-loop. Type conversion rules for scalar field references are the same as those for variables and array elements. An aggregate field reference consists of the name of a record (as specified in a RECORD statement) and zero or more levels of aggregate field names. You can assign an aggregate field to another aggregate field (record = record) only with records having the same structure. VAX FORTRAN supports no other operations (such as arithmetic or comparison) on aggregate fields. Aggregate field references can be used in unformatted 1/0O statements (one I/0 record is written no matter how many aggregate and array name references appear in the 1/0 list) but cannot be used in formatted and NAMELIST I/0 statements. Aggregate field references can be used as both dummy and actual arguments. The declaration of the dummy record in the subprogram must match the form of the record declared in the calling program unit; that is, each structure must have the same number and types of fields in the same order. The ordering of map fields within a union declaration is irrelevant. Data Types, Data Items, and Expressions 2-37 Records are passed by reference. Aggregate field references are treated like normal variables. Adjustable arrays can be used in RECORD statements that are used as dummy arguments. NOTE Because periods are used in record references to separate fields, you should not use relational operators (.EQ., . XOR.) logical constants ((TRUE., .FALSE.) and logical expressions (.AND., NOT:, .OR\)) as field names in structure declarations. Examples The following examples demonstrate record and field references. Consider the following structure declarations (described at length in Section 4.15.1). Structure DATE: STRUCTURE /DATE/ LOGICAL*1 DAY, INTEGER*2 MONTH YEAR END STRUCTURE Structure APPOINTMENT: STRUCTURE /APPOINTMENT/ RECORD /DATE/ APP_DATE STRUCTURE /TIME/ APP_TIME (2) LOGICALx*1 HOUR, MINUTE END STRUCTURE CHARACTER*20 APP_MEMO (4) LOGICAL*1 APP_FLAG END STRUCTURE Consider also the following RECORD statement, which creates a variable named NEXT_APP and a 10-element array named APP_LIST. Both the variable and each element of the array take the form of the structure APPOINTMENT. RECORD /APPOINTMENT/ NEXT_APP,APP_LIST(10) Each of the following examples of record and field references are derived from the preceding structure declarations and RECORD statement. Aggregate Field References e The record NEXT_APP: NEXT_APP 2-38 Data Types, Data Items, and Expressions The field APP_TIME(1), an array field of the record NEXT_APP: e NEXT_APP.APP_TIME(1) The field APP_DATE, a 4-byte array field in the record array APP_ e LIST(3): APP_LIST(3) .APP_DATE Scalar Field References The field APP_FLAG, a LOGICAL field of the record NEXT_APP: e NEXT_APP .APP_FLAG The field HOUR, a LOGICAL=*1 subfield of field APP_TIME(1) of e record NEXT_APP: NEXT_APP .APP_TIME(1) . HOUR e The first character of APP_MEMO(1), a CHARACTER%*20 field of the record NEXT_APP: NEXT_APP.APP_MEMO(1) (1:1) e The field MONTH, a LOGICAL#1 subfield of field APP_DATE of record array APP_LIST(1): APP_LIST(1) .APP_DATE MONTH 2.2.6 Terminology Used to Refer to Data Items Constants, variables, arrays, array elements, scalar record fields, aggregate fields, character substrings, and expressions can be specified in many places in a VAX FORTRAN program. FORTRAN statements and expressions have individual restrictions governing which of these items can be used in statements and expressions and in what form. Thus, to avoid repeatedly enumerating lists of the various items that can be specified with the various statements and expressions, the items divide into four general categories. The names of these categories are used throughout this manual to identify what can be included in a particular statement or expression. The categories are as follows: e Scalar Reference—resolves into a reference to a single, typed data item (a variable, scalar record field, array element, constant, character substring, or expression). Data Types, Data Items, and Expressions 2-39 ® Scalar Memory Reference—resolves into a data item that can be assigned a value by means of an assignment statement. It is the same as a scalar reference, excluding constants and expressions. * Array Name Reference—resolves into a reference to an array. e Aggregate Reference—resolves into a reference to a structured data item (a record structure or substructure). Scalar reference, scalar memory reference, array name reference, and aggregate reference are used throughout this manual to indicate where these various categories of data items can be specified. Examples Consider the following declarations: INTEGER INT, INTARY (10) STRUCTURE /STRA/ INTEGER INTFLD, INTFLDARY (10) END STRUCTURE STRUCTURE /STRB/ CHARACTER*20 INTEGER CHARFLD INTFLD, INTFLDARY (10) STRUCTURE STRUCFLD COMPLEX END CPXFLD, CPXFLDARY (10) STRUCTURE RECORD /STRA/ RECFLD, RECFLDARY (10) END STRUCTURE RECORD /STRB/ REC, RECARY (10) Each of the following references are derived from the preceding data declarations. 2-40 Data Types, Data Items, and Expressions Scalar References INT INTARY (1) REC. INTFLD REC.INTFLDARY(1) REC.RECFLD.INTFLD REC.STRUCFLD.CPXFLD REC.RECFLD.INTFLDARY (1) REC.RECFLDARY (1) . INTFLD REC.RECFLDARY (1) . INTFLDARY (1) REC.CHARFLD REC.CHARFLD(5:10) RECARY (1) . CHARFLD(5:10) RECARY (1) . INTFLD RECARY (1) . INTFLDARY (1) RECARY (1) .RECFLD.INTFLD RECARY (1) .STRUCFLD.CPXFLD RECARY (1) .RECFLD. INTFLDARY (1) RECARY (1) .RECFLDARY (1) . INTFLD RECARY (1) .RECFLDARY (1) . INTFLDARY (1) Scalar Memory References All references listed in the scalar reference category are also in the category of scalar memory reference because they do not include constants and expressions. Array Name References INTARY RECARY REC. INTFLDARY REC.RECFLDARY REC.RECFLD. INTFLDARY REC.RECFLDARY (1) . INTFLDARY REC.STRUCFLD.CPXFLDARY RECARY (1) . INTFLDARY RECARY (1) . RECFLDARY RECARY (1) .RECFLD. INTFLDARY RECARY (1) . STRUCFLD.CPXFLDARY RECARY (1) .RECFLDARY (1) . INTFLDARY Aggregate References REC RECARY (1) REC.RECFLD REC.STRUCFLD REC.RECFLDAR (1) Y RECARY (1) .RECFLD RECARY (1) . STRUCFLD RECARY (1) . RECFLDARY(1) Data Types, Data ltems, and Expressions 2-41 2.3 Expressions An expression is a scalar field reference, function reference, or combination of these references plus operators. Expressions represent singular values. Combinations represent singular values because they resolve into singular values when computations are made on their data items, as specified by the operators. Expressions are classified as arithmetic, character, relational, or logical. Arithmetic expressions produce numeric values, character expressions produce character values, and relational and logical expressions produce logical values. 2.3.1 Arithmetic Expressions Arithmetic expressions express numeric computations. Arithmetic expressions are formed with arithmetic elements and arithmetic operators. The evaluation of an arithmetic expression yields a single numeric value. An arithmetic element can be any of the following: e Numeric scalar reference e Arithmetic expression enclosed in parentheses e Numeric function reference The term numeric includes logical data, because logical data are treated as integer data when used in an arithmetic context. Arithmetic operators specify a computation to be performed using the values of arithmetic elements. They produce a numeric value as a result. Operators and their functions are as follows: Operator Function Aok Exponentiation * Multiplication Division Addition or unary plus — 2-42 Subtraction or unary minus Data Types, Data ltems, and Expressions The plus and minus operators are unary operators because they can operate on a single operand. Used as unary operators, the plus or minus operators precede a single operand and denote a positive or negative value, respectively. Thus, they preserve or change the arithmetic sign of a value. The exponentiation, multiplication, and division operators are binary operators because they operate on a pair of operands. Variables, array elements, and field references must have defined values before being used in an arithmetic expression. Valid arithmetic operations must have results that are mathematically defined. For example, dividing by zero or raising a zero-valued base to a zero-valued or negative-valued power is invalid. Raising a negativevalued base to a real power is also invalid. Arithmetic expressions are evaluated in an order determined by a precedence associated with each operator: Operator Precedence *k First * and / Second + and — Third When operators with equal precedence appear, they can be evaluated in any order as long as the order is algebraically equivalent to a left-to-right order of evaluation. Exponentiation, however, is evaluated from right to left. For example, A**B**C is evaluated as A**(B*+C); Bx*C is evaluated first, and then A is raised to the resulting power. Normally, two operators cannot appear together. However, VAX FORTRAN allows two consecutive operators if the second operator is a plus or minus. Examples In the following example, the exponentiation operator is evaluated first because it takes precedence over the multiplication operator: A**xB+C 1S evaluated as (A**B)x*C. Ordinarily, the exponentiation operator would be evaluated first in the next example. However, because VAX FORTRAN allows the combination of the exponentiation and minus operators, the multiplication operator 1s evaluated first. The exponentiation operator must wait until the minus Data Types, Data Items, and Expressions 2-43 operator is evaluated. As a result, the multiplication operator is evaluated first, since it takes precedence over the minus operator: Ax*-B*C is evaluated as Axx(- (BxA)). 2.3.1.1 Using Parentheses You can use parentheses to force a particular order of evaluation. When part of an expression is enclosed in parentheses, that part is evaluated first and the resulting value is used in the evaluation of the remainder of the expression. In the following four examples, the numbers below the operators indicate a possible order of evaluation. Alternative evaluation orders are possible in the first three examples because they contain operators of equal precedence that are not dictated by parentheses. In these cases, the compiler is free to evaluate operators of equal precedence in any order—as long as the result is the same as the result gained by the algebraic left-to-right order of evaluation. 4 + 3 *x 2 6 / 2 - 7 ~ 11 ! (4+3) 4 * 1 b 2 6) ((4+3) 1 = 2 6) / - -~ ~ 2 3 4 As shown in the last two examples, expressions within parentheses are evaluated according to the normal order of precedence, unless you override the order by using parentheses within parentheses. Nonessential parentheses do not affect expression evaluation, as shown in the following example: 4+ (3%2) — (6/2) 2-44 Data Types, Data Items, and Expressions However, using parentheses to specify the evaluation order is often important in high-accuracy numerical computations. In such computations, evaluation orders that are algebraically equivalent might not be computationally equivalent when processed by a computer (because of the way intermediate results are rounded off). Data Type of an Arithmetic Expression If every element in an arithmetic expression is of the same data type, the value produced by the expression is also of that data type. If elements of different data types are combined in an expression, the evaluation of that expression and the data type of the resulting value depend on a rank associated with each data type. The rank assigned to each data type is as follows: Rank Logical 1 (Lowest) INTEGER=*2 2 REAL=*16 S COMPLEX*8 (COMPLEX) g REAL*8 (DOUBLE PRECISION) o REAL=*4 (REAL) G INTEGER*4 W Data Type COMPLEX*16 (DOUBLE COMPLEX) X 2.3.1.2 (Highest) The data type of the value produced by an operation on two arithmetic elements of different data types is the data type of the highest-ranked element in the operation. For example, the data type of the value resulting from an operation on an integer and a real element is real. However, an operation involving a COMPLEX+8 data type and either a REAL*8 or REAL#*16 data type produces a COMPLEX#16 result. The data type of an expression is the data type of the result of the last operation in that expression and is determined according to the following conventions: e [nteger operations: Integer operations are 1Eerformecl only on integer elements. (Logical entities used in an arithmetic context are treated Data Types, Data Items, and Expressions 2-4b as integers.) In integer arithmetic, any fraction that can result from division is truncated, not rounded. For example: 1/4+1/4+1/4+1/4 The value of this expression is 0, not 1. * Real operations: Real operations are performed only on real elements or combinations of real, integer, and logical elements. Any integer elements present are converted to the real data type by giving each a fractional part equal to zero. The expression is then evaluated using real arithmetic. However, in the statement Y = (1/3)*X, an integer division operation is performed on I and J, and a real multiplication is performed on that result and X. * REAL+8 and REAL*16 operations: Any element in an operation in which there is a higher-precision element is converted to the data type of the higher-precision element by making the existing element the most significant portion of the higher-precision data. The least significant portion of the binary representation is zero. The expression is then evaluated in the higher-precision arithmetic. ® Real element to higher-precision element conversions: Converting a real element to a higher-precision element does not increase its accuracy; for example, a REAL variable having the value 0.3333333 is converted approximately to 0.3333333134651184D0. It is not converted to either 0.3333333000000000D0 or 0.3333333333333333.D0. * Complex operations: In operations that contain any complex elements, integer elements are converted to the real data type, as previously described. The obtained REAL or REAL*8 element is then designated as the real part of a complex number and the imaginary part is assigned a value of zero. Next, the expression is evaluated using complex arithmetic and the resulting value is a complex data type. Operations involving COMPLEX+*8 and REAL*8 elements are done as COMPLEX*16 operations; the REAL*8 element is not rounded, * Constants defined by PARAMETER statements: If a constant was assigned a value by a PARAMETER statement, it may be treated as a lower-order type in an arithmetic expression. This treatment can occur even if the constant was explicitly typed. For example, an INTEGER=*4 constant might be treated as ar INTEGER*2 constant. These rules also generally apply to arithmetic operations in which one of the operands is a constant. However, if a real or complex constant is used in a higher-precision expression, additional Igrecision will be retained for the constant. The effect is as if a REAL*8 or REAL*16 representation of the constant had been given. For example, the expression 1.0D0 + 0.3333333 is treated as if it were 1.0D0 + 0.3333333000000000D0. 2-46 Data Types, Data ltems, and Expressions 2.3.2 Character Expressions Character expressions consist of character elements and character operators. The evaluation of a character expression yields a single value with a character data type. Character expressions take the following form: character-element [//character-element]. .. character-element Is any one of the following entities: e (Character scalar reference * Character substring e Character expression, optionally enclosed in parentheses e (Character function reference The only character operator is the concatenation operator (//). The value of a character expression is a character string formed by successive left-to-right concatenations of the values 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 five. Parentheses do not affect the value of a character expression; for example, the following character expressions are equivalent: (*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, the spaces are included in the value of the character expression. For example, ‘ABC '//'D E'//'F ' has a value of '"ABC D EF . Data Types, Data Items, and Expressions 2-47 2.3.3 Relational Expressions A relational expression consists of two arithmetic expressions or two character expressions separated by a relational operator. A relational operator tests for a relationship between the two expressions. The value of the relational expression is either .TRUE. or .FALSE. depending on whether the stated relationship holds. VAX FORTRAN supports the following relational operators: Operator Relationship .LT. Less than .LE. Less than or equal to EQ. Equal to NE. Not equal to .GT. Greater than .GE. Greater than or equal to Both delimiting periods are required. Complex expressions can be related only by the .EQ. and .NE. operators. Complex entities are equal if their corresponding real and imaginary parts are both equal. In an arithmetic relational expression, the arithmetic expressions are first evaluated to obtain their values. These values are then compared to determine whether the relationship stated by the operator holds; for example: APPLE+PEACH .GT. PEAR+QORANGE This expression states the relationship, “The sum of APPLE and PEACH is greater than the sum of PEAR and ORANGE.” If that relationship holds, the value of the expression is .TRUE. If not, the value of the expression is .FALSE. Similarly, in a character relational expression, the character expressions are first evaluated to obtain their values. These values are then compared to determine whether the relationship stated by the operator holds. 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'//'Z2Z' 2-48 .LT. 'CCCCC' Data Types, Data ltems, and Expressions This expression states that ‘ABZZZ’ is less than ‘CCCCC’. Because that relationship does hold, the value of the expression is .TRUE. If the relationship stated does not hold, the value of the expression is .FALSE. If the two character expressions in a relational expression are not the same length, the shorter one is padded on the right with spaces until the lengths are equal; for example: '"ABC' 'AB' .EQ. .LT. 'ABC '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’". All relational operators have the same precedence. However, arithmetic and character operators have a higher precedence than relational operators. As in any other expression, you can use parentheses to alter the order of evaluation of the expressions in a relational expression. However, because arithmetic and character operators are evaluated before relational operators, you do not need to enclose the entire arithmetic or character expression in parentheses. A relational expression can compare two numeric expressions of different data types. In this case, the value of the expression with the lowerranked data type is converted to the higher-ranked data type before the comparison is made. 2.3.4 Logical Expressions A logical expression is a single logical element or a combination of logical elements and logical, arithmetic, or relational operators. Logical elements can be any one of the following; * Integer or logical scalar reference * Relational expression * Integer or logical expression enclosed in parentheses * Integer or logical function reference Data Types, Data Items, and Expressions 2-49 VAX FORTRAN logical operators are any one of the following: Operator Example .AND. A .AND. B .OR. A .OR. B Meaning Logical conjunction: The expression is true if both A and B are true. Logical disjunction (inclusive OR): The expression is true if either A or B, or both, are true. NEQV. A .NEQV. B XOR. A .XOR. B EQV. A .EQV. B Logical exclusive OR: The expression is true if A and B have different logical values; but the expression is false if both elements have the same logical value. Same as .NEQV. Logical equivalence: The expression is true if both A and B have the same logical value, whether true or false. .NOT. A NOT. Logical negation: The expression is true if A is false and false if A is true. Delimiting periods are required. Periods cannot appear consecutively except when the second operator is .NOT. For example, the following logical expression is valid: A+B/(A-1) .AND. .NOT. D+B/(D-1) Data Types that Result from Logical Operations On logical elements, logical operations produce single logical values (.TRUE. or .FALSE.) with a logical data type. On integers, logical operations produce single values with an integer data type; they are carried out bit-by-bit on corresponding bits of the internal (binary) representation of the integer elements. On a combination of integer and logical values, logical operations also produce single values with an integer data type. The operation first converts logical values to integers and then operates as it does with integers. Logical operations cannot be performed on other data types. 2-50 Data Types, Data Items, and Expressions Evaluation of Logical Expressions Logical expressions are evaluated according to the precedence of their operators. Consider the following expression: A*B+C*ABC .EQ. X+Y+DM/ZZ .AND. .NOT. K*B .GT. TT This expression is evaluated in the following sequence: (((AxB)+(C+ABC)) .EQ. ((X*Y)+(DM/ZZ))) .AND. (.NOT. ((K*B). GT. TT)) The following list identifies all the operators that can appear in a logical expression in the order of their precedence: Operator Precedence ok First (highest) *, /[ Second +, - // Third Relational Operators Fourth NOT. Fifth AND. Sixth .OR. Seventh XOR., .EQV., NEQV. Eighth (lowest) As with arithmetic expressions, you can alter the sequence of evaluation by using parentheses. When operators have equal precedence, the compiler can evaluate them in any order—as long as the result is the same as the result gained by the algebraic left-to-right order of evaluation (except for exponentiation, which is associated from right to left). You should not write logical expressions whose results might depend on the evaluation order of subexpressions. The compiler is free to evaluate subexpressions in any order. In the following example, either (A(I)+1.0) or B(I)*2.0 could be evaluated first: (A(I)+1.0) .GT. B(I)*2.0 Data Types, Data Items, and Expressions 2-51 Some subexpressions may not be evaluated if the compiler can determine the result by testing other subexpressions in the logical expression. Consider the following expression: A _AND. (F(X,Y) .GT. 2.0) .AND. B If A is false, and if the compiler evaluates A first, then the compiler can determine that the expression is false and may not call the subprogram F(X)Y). 2-52 Data Types, Data Items, and Expressions Chapter 3 Assignment Statements Assignment statements define the value of a data item—a variable, array element, record (structured variable), record element, or character substring. The expression on the right side of the assignment statement’s equal sign is evaluated and the resulting value is assigned to the data item. VAX FORTRAN supports five assignment statements: arithmetic, logical, character, iaggregate, and ASSIGN. 3.1 Arithmetic Assignment Statement The arithmetic assignment statement assigns the value of the expression on the right of the equal sign to the numeric scalar memory reference on the left of the equal sign. It takes the following form: v=e v Is a numeric scalar memory reference. e Is an arithmetic expression. The equal sign does not mean “is equal to,” as in mathematics. It means “is replaced by.” For example: COUNT = COUNT + 1 This statement means, “replace the current value of the integer variable COUNT with the sum of that current value and the integer constant 1.” Assignment Statements 3-1 Although the symbolic name on the left of the equal sign can be undefined, values must have been previously assigned to all symbolic references in the expression on the right of the equal sign. The expression e must yield a value that conforms to the range requirements of v. For example, a real expression that produces a value greater than 32767 is invalid if the entity on the left of the equal sign is an INTEGER#*2 variable. Significance may be lost if an INTEGER*4 value, which can exactly represent values of approximately the range —2*10**9 to +2%10%*9, is converted to REAL*4 (including the real part of a complex constant), which is accurate to only about seven digits. If v has the same data type as that of the expression on the right, the statement assigns the value directly. If the data types are different, the value of the expression is converted to the data type of the entity on the left of the equal sign before it is assigned. Examples The following examples demonstrate valid and invalid assignment statements and explain why the invalid ones are not valid: Valid BETA = -1./(2.%X) +A*A/ (4. % (X*xX)) PI = 3.14159 SUM = SUM + 1. NEW = RECORD1.FIELD1 Invalid Explanation 3.14=A-B Entity on the left must be a numeric ~J = Ixx4 Entity on the left must not be signed. ALPHA = ((X+6)*B*B/ (X-Y) Left and right parentheses do not bal- scalar memory reference. ance. ICOUNT = A//B(3:7) Expression on the right cannot have a character data type if the entity on the left does not. Table 3-1 summarizes the data conversion rules for assignment statements. 3-2 Assignment Statements Table 3-1 : Conversion Rules for Assignment Statements Scalar Expression(E) Memory Reference (V) Integer Integer or Logical Assign E to V or Logical REAL Truncate E to REAL*8 REAL*16 Truncate E to Truncate E to COMPLEX COMPLEX*16 Truncate real part Truncate real part of E to integer and assign to integer and integer and integer and of E to integer and assign to V assign to V assign to V assign to V; imaginary part of V; imaginary part of E E ] is not used 1s not used REAL Append fraction Assign E to V Assign MS* portion | Assign MSs portion | Assign real part of Assign MS+ portion (.0) to E and of E to V; LS+ of E to V; LS+ E to V; imaginary of the real part of assign to V portion of E is portion of E is part of E is not E to V. LS* portion rounded rounded used of the real part of E is rounded; imaginary part of E is not used REAL*8 Append fraction Assign E to MS» (.0) to E and portion of V; LS» E to MS+ of V; E to V: imaginary assign to V portion of V is 0 Assign E to V Same as above Assign real part of LS* portion of V part of E is not used Assign real part of 1s 0: imaginary part of E is not used REAL=*16 Same as above Same as above Assign E to MS+ Assign E to V Same as above Assign real part of portion of V; LS* E to MS* portion portion of V is 0 of V: L8* portion of real part of V is 0. Imaginary part of E is not used COMPLEX Append fraction Assign E to real Assign MS* portion Assign MS* portion | Assign E to V Assign MS* portion (.0) to E and part of V; of E to real part of of E to real part of of real part of E to assign to real imaginary part V. LS* portion of part of V; of Vis 0.0 V. LS#* portion of real part of V, LS+ E is rounded; E is rounded; portion of real part imaginary part of imaginary part of imaginary part of of E is rounded. Vis 0.0 Vis 0.0 Vis 0.0 Assign MS* portion of imaginary part of E to imaginary part of V. LS* portion of imaginary part of E 1s rounded. COMPLEX*16 Append fraction Assign E to MS» Assign E to real {.0) to E and assign portion of real part of V: E to MS+ portion to V: imaginary part of V; imaginary part of real part of V; imaginary part is 0.0 part of V is 0.0 of Vis 0.0 Same as above Assign real part of Assign E to V LS= portion of real part is 0. Assign imaginary part of E to M8+ portion of imaginary part of V; LS* portion of imaginary part is 0. *MS = most significant (high order) LS = least significant (low order) ZK-4812-85 Assignment Statements 3-3 3.2 Logical Assignment Statement The logical assignment statement assigns the value of the logical expression on the right of the equal sign to the logical scalar memory reference on the left of the equal sign. A logical assignment statement takes the following form: v =e v Is a logical scalar memory reference. e Is a logical, integer, or arithmetic expression. Values must have previously been assigned to all symbolic references that appear in the expression. The expression must yield a logical value. Examples The following examples demonstrate valid logical assignment statements: PAGEND .FALSE. PRNTOK = LINE .LE. 132 .AND. .NOT. PAGEND ABIG = A.GT.B .AND. A.GT.C .AND. A.GT.D 3.3 Character Assignment Statement The character assignment statement assigns the value of the character expression on the right of the equal sign to the character scalar memory reference on the left of the equal sign. It takes the following form: v =28 v Is a character scalar memory reference. e Is a character expression. If the length of e is greater than the length of v, the character expression is truncated on the right. 3-4 Assignment Statements If the length of e is less than the length of v, the character expression is filled on the right with spaces. The expression e must have a character data type. You cannot assign a numeric value to a character scalar memory reference. By assigning a value to a character substring, you do not affect character positions in the character scalar memory reference 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 The following examples demonstrate valid and invalid character assignment statements and explain why the invalid ones are not valid. (In the examples, all memory references have a character data type.) Valid FILE = 'PROG2' REVOL(1) = 'MAR'//'CIA" LOCA(3:8) = 'PLANT5' TEXT(I,J+1) (2:N-1) = NAME//X Invalid 'ABC' = CHARS Explanation Left element must be a character variable, array element, or substring reference. CHARS = 25 Expression on right must have a character data type. STRING = S5HBEGIN Expression on right must have a character data type—Hollerith constants are numeric, not character. Assignment Statements 3-5 3.4 Aggregate Assignment Statement The aggregate assignment statement assigns the value of each field of the aggregate on the right of an equal sign to the corresponding field of the aggregate on the left. Both aggregates must be declared with the same structure. An aggregate assignment statement takes the following form: v =@ v Is an aggregate reference with the same structure as the aggregate represented by e (see Section 2.2.5.1). e Is an aggregate reference with the same structure as the aggregate represented by v (see Section 2.2.5.1). Example The following example demonstrates valid aggregate assignments: STRUCTURE /DATE/ LOGICAL=*1 DAY, MONTH INTEGER*2 YEAR END STRUCTURE RECORD /DATE/ TODAY, THIS_WEEK(7) STRUCTURE /APPOINTMENT/ RECORD /DATE/ APP_DATE END STRUCTURE RECORD /APPOINTMENT/ MEETING DOI =17 CALL GET_DATE (TODAY) THIS_WEEK (I) = TODAY THIS_WEEK (I).DAY = TODAY.DAY + 1 END DO MEETING.APP_DATE = TODAY 3-6 Assignment Statements 3.5 ASSIGN Statement The ASSIGN statement assigns a statement label value to an integer variable. The variable can then be used as either a transfer destination in a subsequent assigned GO TO statement or a format specifier in a formatted 1/0 statement. ASSIGN statements take the following form: ASSIGN s TO v S Is the label of an executable statement or a FORMAT statement in the same program unit as the ASSIGN statement. v Is an integer variable. The ASSIGN statement assigns the statement number to the variable. It is similar to an arithmetic assignment statement with one exception: the variable becomes defined as a statement label reference and undefined as an integer variable. An ASSIGN statement must be executed before the statements in which the assigned variable is used. Additionally, the ASSIGN statement and the statements in which the assigned variable is used must occur in the same program unit; for example: ASSIGN 100 TO NUMBER This statement associates the variable NUMBER with the statement label 100. Once the ASSIGN statement associates a statement label to a variable, arithmetic operations on the variable produce unpredictable run-time behavior; for example: NUMBER = NUMBER + 1 To return the variable to the status of an integer variable, you could use | the following statement, which dissociates NUMBER from statement 100 and assigns it an integer value of 10: NUMBER = 10 Once returning the variable NUMBER to its integer variable status, it can no longer be used in an assigned GO TO statement. Assignment Statements 3-7 Examples The following additional examples demonstrate valid ASSIGN statements: ASSIGN 10 TO NSTART ASSIGN 99999 TO KSTOP ASSIGN 250 TO ERROR In the last example, ERROR must be previously defined as an integer variable. 3-8 Assignment Statements Chapter 4 Specification Statements Specification statements are nonexecutable statements used to allocate and initialize variables, arrays, records, and structures; and to define other characteristics of symbolic names used in a program. VAX FORTRAN supports the following specification statements: BLOCK DATA—initiates a series of statements that establish common blocks and assign initial values to entities in named common blocks (Section 4.1). COMMON—defines one or more contiguous areas of storage (Section 4.2). DATA—assigns initial values to variables, arrays, and array elements before program execution (Section 4.3). Data type declaration statements—explicitly define the data type of specified symbolic names (Section 4.4). DIMENSION—defines the number of dimensions in an array and the number of elements in each dimension (Section 4.5). EQUIVALENCE—associates two or more entities with the same storage location (Section 4.6). EXTERNAL—allows use of user-supplied procedures as arguments to subprograms (Section 4.7). IMPLICIT—overrides the implied data type of symbolic names (Section 4.8). INTRINSIC—allows use of FORTRAN intrinsic functions as arguments to subprograms (Section 4.9). NAMELIST—specifies lists of entities whose values may be read or written in namelist-directed 1/O statements; associates the list with specified group-names (Section 4.10). Specification Statements 4-1 e PARAMETER—associates a symbolic name with a constant value (Section 4.11). ¢ PROGRAM—assigns a symbolic name to a main program unit (Section 4.12). » RECORD—establishes a record with the structure defined by the block of statements in a structure declaration (Section 4.13). e SAVE—retains values of local variables after a return from a subprogram (Section 4.14). e Structure declaration block—specifies the structure (form) of a record (Section 4.15). e 4.1 VOLATILE—prevents optimizations from being performed on specified variables, arrays, and common blocks (Section 4.16). BLOCK DATA Statement A BLOCK DATA statement initiates a series of specification statements that establish common blocks and assign initial values to the entities in named common blocks. The BLOCK DATA statement takes the following form: BLOCK DATA [nam] nam Is a symbolic name. Syntax Rules and Behavior A BLOCK DATA statement and its associated specification statements are a special kind of program unit, called a block data subprogram. The block data subprogram has the following syntax rules: Any of the following specification statements can appear in a block data subprogram: COMMON DATA DIMENSION EQUIVALENCE IMPLICIT PARAMETER RECORD 4-2 Specification Statements SAVE Structure declaration Type declaration statements * A block data subprogram must not contain any executable statements. * As with other types of program units, the last statement in a block * Within a block data subprogram, if a DATA statement initializes data subprogram must be an END statement. any entity in a named common block, the subprogram must have a complete set of specification statements that establishes the common block. However, all of the the entities in the block do not have to be assigned initial values in a DATA statement. ® One block data subprogram can establish and define initial values for more than one common block. ® The name of a block data subprogram can appear in the EXTERNAL statement of a different program unit to force the VMS Linker to search object libraries for the BLOCK DATA program unit at link time. Example The following example demonstrates a valid block data subprogram: BLOCK DATA BLKDAT INTEGER S,X LOGICAL T,W DOUBLE PRECISION U DIMENSION R(3) COMMON /AREA1/R,S,T,U /AREA2/W.X,Y DATA R/1.0,2%2.0/, T/.FALSE./, U/0.214537D-7/, W/ .TRUE./, END 4.2 Y/3.5/ COMMON Statement A COMMON statement defines one or more contiguous areas, or blocks, of storage. COMMON statements also define the order in which variables, arrays, and records are stored in each common block. A symbolic name identifies each block. However, you can omit a symbolic name for one block in a program unit. The block without a name is known as the blank common block. Specification Statements 4-3 The COMMON statement takes the following form: COMMON [/[cbl/Inlist[[.] /[cbl/nlist]... cb Is a symbolic name, called a common block name; cb can be blank. If the first cb is blank, you can omit the first pair of slashes. nlist Is a list of variable names, array names, array declarators, and record names separated by commas. Syntax Rules and Behavior Any common block name, blank or otherwise, can appear more than once in one or more COMMON statements in a program unit. The list following each successive appearance of the same common block name is treated as a continuation of the list for the block associated with that name. You can use array declarators in the COMMON statement to define arrays. A common block can have the same name as a variable, array, record, structure, or field. However, in a program with one or more program units, a common block cannot have the same name as a function, subroutine, or entry name in the executable program. When common blocks from different program units have the same name, they share the same storage area when the units are combined into an executable program. Entities are assigned storage in common blocks on a one-for-one basis. Thus, the entities assigned by a COMMON statement in one program unit should agree with the data type of entities placed in a common block by another program unit; for example, consider a program unit containing the following statement: COMMON CENTS And consider another program unit containing the following statements: INTEGER*2 MONEY COMMON MONEY When these program units are combined into an executable program, incorrect results may occur if the 2-byte integer variable MONEY is made to correspond to the lower-addressed two bytes of the real variable CENTS. 4-4 Specification Statements Example In the following example the COMMON statement in the main program puts HEAT and X in the blank common block, and KILO and Q in a named common block, BLK1. The COMMON statement in the subroutine makes ALFA and BET share the same storage location as HEAT and X in the blank common block. It makes LIMA and R share the same storage location as KILO and Q in BLK1. Main Program Subprogram COMMON HEAT,X /BLK1/KILO,Q SUBROUTINE FIGURE COMMON /BLK1/LIMA,R / /ALFA,BET CALL FIGURE . RETURN END 4.3 DATA Statement The DATA statement assigns initial values to variables and array elements before program execution. It takes the following form: DATA nlist/clist/[[,] nlist/clist/]... nlist Is a list containing any combination of variable names, array names, array element names, character substring names, and implied-DO lists. Elements in the list must be separated by commas. Subscript expressions and expressions in substring references must be integer expressions containing integer constants and implied-DO variables. An implied-DO list in a DATA statement takes the following form: (dlist, i=n1,n2(,n3]) Specification Statements 4-5 dlist Is a list of one or more array element names, character substring names, or implied-DO lists, separated by commas. i Is the name of an integer variable. n1,n2,n3 Are integer constant expressions. The expression can contain impliedDO variables of other implied-DO lists that have this implied-DO list within their ranges. clist Is a list of constants separated by commas; clist constants take one of the following forms: C n*x c c Is a constant or the symbolic name of a constant. n Defines the number of times the same value is to be assigned to successive entities in the associated nlist; n is a nonzero, unsigned integer constant or the symbolic name of an integer constant. Syntax Rules and Behavior The DATA statement assigns the constant values in each clist to the entities in the preceding nlist, from left to right, as they appear in the nlist. The number of constants must equal the number of entities in the nlist. When an unsubscripted array name appears in a DATA statement, values are assigned to every element of that array in the order of subscript progression. The associated constant list must contain enough values to fill the array. The following list describes the relationship between nlist items and clist items: * If both the constant value in clist and the entity in nlist have numeric data types, conversion is based on the following rules: — If necessary, the constant value is converted to the data type of the variable being initialized. 4-6 Specification Statements — When an octal or hexadecimal constant is assigned to a variable or array element, the number of digits that can be assigned depends on the data type of the data item. If the constant contains fewer digits than the capacity of the variable or array element, the constant is extended on the left with zeros. If the constant contains more digits than can be stored, the constant is truncated on the left. If the constant value in clist and the entity in nlist are both of character data type, the conversion is based on the following rules: — If the constant contains fewer bytes than the length of the entity, the rightmost character positions of the entity are initialized with spaces. If the constant contains more bytes than the length of the entity, the character constant is truncated on the right. If the constant value in clist is of numeric data type and the entity in nlist is of character data type, the constant and the entity must — conform to the following restrictions: — The character entity must have a length of one character. — The constant must be an integer, octal, or hexadecimal constant and must have a value in the range 0 through 255. When the clist constant and the nlist entity conform to these restric- tions, the nlist entity is initialized with the character that has the ASCII code specified by the clist constant. (This behavior lets you initialize a character entity to any 8-bit ASCII code.) If the constant value in clist is a Hollerith or character constant and the entity in nlist is a numeric variable or numeric array element, the number of characters that can be assigned depends on the data type of the data item (see Table 3-1). If the Hollerith or character constant contains fewer characters than the capacity of the variable or array element, the constant is extended on the right with spaces. If the constant contains more characters than can be stored, the constant is truncated on the right. Specification Statements 4-7 Examples In the following example, the first DATA statement assigns zero to all 10 elements of array A and 4 asterisks followed by 2 spaces to the character variable STARS. The second DATA statement assigns ASCII control character codes to the character variables BELL, TAB, LF, and FF. The last DATA statement uses an implied-DO loop to assign values to the odd numbered elements in the array B. INTEGER A(10), B(10) CHARACTER BELL, TAB, LF, FF, STARS*6 DATA A,STARS /10%0, '*xxx'/ DATA BELL,TAB,LF,FF DATA (B(I), 4.4 /7,9,10,12/ I=1,10,2) /5%1/ Data Type Declaration Statements Type declaration statements explicitly define the data type of specified symbolic names. There are two forms of type declaration statements: numeric type declarations and character type declarations. Type declaration statements can initialize data in the same way as the DATA statement: by having values, bounded by slashes, listed immedi- ately after the symbolic name of the entity. Syntax Rules The following rules apply to type declaration statements: * Type declaration statements must precede all executable statements. * The data type of a symbolic name can be declared only once. * Once a symbolic name has been used in a context that implicitly assumes a data type, its assumed type cannot be changed by a type declaration statement. 4.4.1 Numeric Type Declaration Statements Numeric type declaration statements take the following form: type *nlv 4-8 Specification Statements [*n] [/clist/] [,v *n] [/clist/1]... type Is any one of the following data type specifiers: BYTE LOGICAL INTEGER REAL DOUBLE PRECISION COMPLEX DOUBLE COMPLEX BYTE and LOGICAL#1 are equivalent. *n Is an integer that specifies (in bytes) the length of v. It overrides the length that is implied by the data type. The value of *n must specify an acceptable length for the type of v, as listed in Table 2.1. BYTE, DOUBLE PRECISION, and DOUBLE COMPLEX data types have one acceptable length; thus, for these data types, the *n specifier is invalid. If an array declarator is used, the *n specifier must be positioned immedi- ately after the array name. v Is the symbolic name of a constant, variable, array, array declarator, statement function, or function subprogram. clist Is a list of constants, as in a DATA statement. If v is the symbolic name of a constant, the clist cannot be present. (See Section 4.3.) Syntax Rules and Behavior A numeric data type declaration statement can define arrays by including array declarators in the list (see Section 2.2.3.1). A numeric type declaration statement can assign initial values to variables or arrays if it specifies a list of constants (the clist). The specified constants initialize only the variable or array that immediately precedes them. The clist cannot have more than one element unless it initializes an array. When the clist initializes an array, it must contain a value for every element in the array. Specification Statements 4-9 Examples In the following example, the first statement declares COUNT and SUM as integers, and MATRIX as a two-dimensional array of integers. INTEGER COUNT, REAL MAN, MATRIX(4,4), SUM MU LOGICAL SWITCH The next example shows instances where one declaration overrides another. In the first statement, M12*4 and IVEC*4 override INTEGER*2. In the second statement, WX3*4 and WX6*4 override REAL*8. In the third statement, QARRAY is initialized with implicit conversion of the REAL*4 constants to a REAL*16 data type. INTEGER*2 I, REAL*8 WX1, J, K, M12x4, Q, WXZ, WX3x4, WX5, IVEC*4 (10) WX6x4 REAL*16 PI/3.14159Q0/, E/2.72Q0/, QARRAY(10)/5%0.0,5%1.0/ 4.4.2 Character Type Declaration Statements Character type declaration statements take the following form: CHARACTER[*1en[,]] v[*len][/clist/][,v[*len][/clist/]]... len Is an unsigned integer constant, an integer constant expression enclosed in parentheses, or an asterisk enclosed in parentheses. The value of len specifies the length of the character data elements. v Is the symbolic name of a constant, variable, array, array declarator, statement function, or function subprogram. clist Is a list of constants, as in a DATA statement. (See Section 4.3.) If v is the symbolic name of a constant, the clist must not be present. Syntax Rules and Behavior If you use 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. However, if an item does have a length specification, it overrides the default length specified in CHARACTER*len. 4-10 Specification Statements When an asterisk length specification *(*) is used for a function name or dummy argument, it assumes the length of the corresponding function reference or actual argument (see Chapter 2). Similarly, when an asterisk length specification is used for the symbolic name of a constant, the name assumes the length of the actual constant it represents. For example, STRING assumes a 9-byte length in the following statements: (*) STRING CHARACTERx* PARAMETER (STRING = 'VALUE IS:') The length specification must range from 1 to 65535. If there is no length specification, a length of 1 is assumed. Character type declaration statements can define arrays if they include array declarators (see Section 2.2.3.1) in their list. The array declarator goes first if both an array declarator and a length are specified. A character type declaration statement can assign initial values to variables or arrays if it specifies a list of constants (the clist). The specified constants initialize only the variable or array that immediately precedes them. The clist cannot have more than one element unless it initializes an array. When the clist initializes an array, it must contain a value for every element in the array. Examples The following examples demonstrate valid and invalid character type declaration statements: Valid The first example specifies an array, NAMES, with one hundred 32character elements; an array, SOCSEC, with one hundred 9-character elements; and a variable, NAMETY, that is 10 characters long and has an initial value of 'ABCDEFGHI]J'. CHARACTER*32 NAMES(100),SOCSEC(100)*9,NAMETY+*10/'ABCDEFGHIJ'/ In the next example, the CHARACTER statement specifies two 8-character variables, LAST and FIRST (the PARAMETER statement is described in Section 4.11). PARAMETER (LENGTH=4) CHARACTER* (4+LENGTH) LAST, FIRST Specification Statements 4-11 In the next example, the CHARACTER statement specifies an array, LETTER, with twenty-six 1-character elements; and a dummy argument, BUBBLE, that has a passed length defined by the calling program. SUBROUTINE S1(BUBBLE) CHARACTER LETTER(26), BUBBLEx*(*) Invalid The following CHARACTER statement is invalid because the length specified for BIGCHR is too large and the length specifier for QUEST is not an integer constant expression: CHARACTER*16 BIGCHR*(60000%*2), 4.5 QUEST+*(5+*INT(A)) DIMENSION Statement The DIMENSION statement defines the number of dimensions in an array and the number of elements in each dimension. It takes the following form: DIMENSION a(d)[,a(d)]. .. a(d) Is an array declarator. (See Section 2.2.3.1.) Syntax Rules and Behavior The DIMENSION statement allocates a number of storage elements to each array named in the statement, one storage element to each array element in each dimension. The size of each storage element is determined by the data type of the array. The total number of storage elements assigned to an array is equal to the number produced by multiplying together the number of elements in each dimension in the array declarator. For example, the following statement defines ARRAY as having 16 real elements of 4 bytes each and defines MATRIX as having 125 integer elements of 4 bytes each: DIMENSION ARRAY(4,4), MATRIX(5,5,5) Although arrays can also be declared in type declaration and COMMON statements, array names can appear in only one array declarator in each program unit. For further information on arrays and the storage of array elements, see Section 2.2.3. 4-12 Specification Statements DIMENSION has the same form and effect as the VIRTUAL statement. (The VIRTUAL statement is described in Appendix D.) Examples The following examples demonstrate valid DIMENSION statements: DIMENSION BUD(12,24,10) DIMENSION X(5,5,5), Y(4,85), Z(100) DIMENSION MARK(4,4,4,4) SUBROUTINE APROC(A1,A2,N1,N2,N3) DIMENSION A1(N1:N2), A2(N3:x*) 4.6 EQUIVALENCE Statement The EQUIVALENCE statement partially or totally associates two or more entities in the same program unit with the same storage location. It takes the following form: [, (nlist)]... EQUIVALENCE (nlist) nlist Is a list of variables, arrays, array elements, or character substring references, separated by commas. The list must contain at least two of these entities. Each expression in a subscript or a substring reference must be an integer constant expression. Records, record fields, and dummy arguments cannot be specified in EQUIVALENCE statements. Syntax Rules and Behavior The EQUIVALENCE statement causes all of the entities in one parenthesized list to be allocated storage beginning at the same storage location. Entities having different data types can be associated because multiple components of one data type can share storage with a single component of a higher-ranked data type. For example, if you make an integer variable equivalent to a complex variable, the integer variable shares storage with the real part of the complex variable. Specification Statements 4-13 Examples In the first example, the EQUIVALENCE statement makes the four elements of the integer array IARR occupy the same storage as that of the double-precision variable DVAR. DOUBLE PRECISION DVAR INTEGER*2 IARR(4) EQUIVALENCE (DVAR, IARR(1)) In the second example, the 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). 4.6.1 CHARACTER KEY*16, STAR*10 EQUIVALENCE (KEY, STAR) Making Arrays Equivalent When you make an element of one array equivalent to an element of another array, the EQUIVALENCE statement also sets equivalences between the other elements of the two arrays. Thus, if the first elements of two equal-sized arrays are made equivalent, both arrays share the same storage space. If the third element of a 7-element array is made equivalent to the first element of another array, the last five elements of the first array overlap the first five elements of the second array. Two or more elements of the same array should not be associated with each other in one or more EQUIVALENCE statements. For example, you cannot use an EQUIVALENCE statement to associate the first element of one array with the first element of another array, and then attempt to associate the fourth element of the first array with the seventh element of the other array. Consider the following valid example: DIMENSION TABLE (2,2), TRIPLE (2,2,2) EQUIVALENCE (TABLE(2,2), TRIPLE(1,2,2)) As a result, the entire array TABLE would share part of the storage space allocated to TRIPLE. Table 4-1 shows how these statements align the arrays. 4-14 Specification Statements Table 4-1: Equivalence of Array Storage Array TRIPLE Array TABLE Array Element Element Number Array Element Element Number TRIPLE(1,1,1) 1 TRIPLE(2,1,1) 2 TRIPLE(1,2,1) 3 TRIPLE(2,2,1) 4 TABLE(1,1) 1 TRIPLE(1,1,2) 5 TABLE(2,1) 2 TRIPLE(2,1,2) 6 TABLE(1,2) 3 TRIPLE(1,2,2) 7 TABLE(2,2) 4 TRIPLE(2,2,2) 8 Each of the following statements also aligns the two arrays as shown in Table 4-1: EQUIVALENCE (TABLE, TRIPLE(2,2,1)) EQUIVALENCE (TRIPLE(1,1,2), TABLE(2,1)) Similarly, you can make arrays equivalent with nonunity lower bounds. For example, an array defined as A(2:3,4) is a sequence of eight values. A reference to A(2,2) refers to the third element in the sequence. To make array A(2:3,4) share storage with array B(2:4,4), you can use the following statement: EQUIVALENCE (A(3,4), B(2,4)) The entire array A shares part of the storage space allocated to array B. Table 4-2 shows how these statements align the arrays. Each of the following statements also aligns the arrays as shown in Table 4-2: Specification Statements 4-15 EQUIVALENCE (A, EQUIVALENCE (B(3,2), Table 4-2: B(4,1)) A(2,2)) Equivalence of Arrays with Nonunity Lower Bounds Array B Array A Array Element Element Number B(2,1) 1 B(3,1) 2 Array Element Element Number A(2,1) 1 B(4,1) 3 B(2,2) 4 A@G3,1) 2 B(3,2) 5 A(2,2) 3 B(4,2) 6 A(3,2) 4 B(2,3) 7 A(2,3) 5 B(3,3) 8 A(3,3) 6 B(4,3) 9 A(2,4) 7 B(2,4) 10 A(3,4) 8 B(3,4) 11 B(4,4) 12 Only in the EQUIVALENCE statement can you identify an array element with a single subscript (the linear element number), even though the array was defined as a multidimensional array. For example, the following statements align the two arrays as shown in Table 4-1: DIMENSION TABLE EQUIVALENCE 4-16 Specification Statements (2,2), (TABLE(4), TRIPLE (2,2,2) TRIPLE(7)) 4.6.2 Making Substrings Equivalent 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 entities; for example: CHARACTER NAME*16, ID%9 EQUIVALENCE (NAME(10:13), ID(2:5)) As a result of these statements, the character variables NAME and ID share space as illustrated in Figure 4-1. The following statement also aligns the arrays as shown in Figure 4-1: 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. Specification Statements 4-17 Figure 4-1: Equivalence of Substrings NAME Character Position . 1 ‘ 2 3 4 5 6 ID 7 Character Position 8 9 | 1 10 2 11 3 12 4 13 5 14 6 15 7 16 8 9 ZK-618-82 Character elements of arrays can overlap at any character position; for example: CHARACTER FIELDS(100)*4, STAR(5)*5 EQUIVALENCE (FIELDS(1)(2:4), STAR(2)(3:5)) As a result of these statements, the character arrays FIELDS and STAR share storage space as shown in Figure 4-2. 4-18 Specification Statements Figure 4-2: Equivalence of Character Arrays STAR Character Position 1 Subscript 1 2 3 FIELDS Subscript Character Position 1 1 2 2 3 3 4 4 5 1 1 2 2 3 3 4 4 1 5 3 5 > 1 2 4 ‘ 2 1 3 2 4 3 1 4 2 5 3 1 4 2 1 3 2 4 3 5 2 3 4 5 4 6 1 2 3 4 7 1 2 AV NAAN AN 100 1 2 3 4 ZK-619-82 Specification Statements 4-19 The EQUIVALENCE statement cannot assign the same storage location to two or more substrings that start at different character positions in the same character variable or character array. The EQUIVALENCE statement also cannot assign memory locations in a way that is inconsistent with the normal linear storage of character variables and arrays. 4.6.3 EQUIVALENCE and COMMON Interaction A common block can extend beyond its original boundaries if variables or arrays are associated with entities stored in the common block. However, a common block can only extend beyond its last element; the extended portion cannot precede the first element in the block. Examples The following examples demonstrate valid and invalid extensions of the common block: Valid DIMENSION AC4d) » B(B) A | A2) | AG3) | A4) COMMON A Bl | B(2)| B(3)| B4) | B(5) | B(6) Existing Extended Portion Common ZK-1944-84 Invalid ) » B(B) DIMENSION A(4 COMMON A EQUIVALENCE (A(Z2) 1 B(3)) A | AR AB)] A(4) B(hH | B2)] B(3)] B4)] B(5) ] B(6) o e e Extended Portion Existing Common e Extended Portion ZK-1945-84 The second example is invalid because the extended portion, B(1), precedes the first element of the common block A. 4-20 Specification Statements 4.7 EXTERNAL Statement EXTERNAL statements allow you to use the names of external procedures as arguments to other subprograms. The subprograms mentioned in the EXTERNAL statement cannot be FORTRAN intrinsic functions; they can only be user-supplied functions, subroutines, or block data subprograms. The INTRINSIC statement discussed in Section 4.9 allows intrinsic function names to be used as arguments. The EXTERNAL statement takes the following form: EXTERNAL v[,v]... v Is the symbolic name of a user-supplied subprogram or the name of a dummy argument associated with the name of a subprogram. Syntax Rules and Behavior 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 named SIN, not to the intrinsic function of the same name (see Section 6.3.1.2). A name specified in an EXTERNAL statement can be used as an actual argument to a subprogram, and the subprogram can then use the corresponding dummy argument in a function reference or a CALL statement. You can include the name of a block data subprogram in the EXTERNAL statement to force the VMS Linker to search the object module libraries for the block data subprogram. However, the name of the subprogram must not be used in a type declaration statement. Used as an argument, a complete function reference represents a value, not a subprogram; for example, FUNC(B) represents a value in the following statement: CALL SUBR (A, FUNC(B), C) Specification Statements 4-21 A complete function reference cannot be defined in an EXTERNAL statement because there is no data type information. NOTE The interpretation of the EXTERNAL statement described here is different from that of earlier versions of FORTRAN produced by DIGITAL. See Appendix A for the earlier interpretation. See Section 4.9 for an example of EXTERNAL statements. 4.8 IMPLICIT Statement The IMPLICIT statement overrides implied (default) data typing of symbolic names. (The default data type is INTEGER for symbolic names beginning with the letters I through N, and REAL*4 for symbolic names beginning with any other letter.) The IMPLICIT statement takes one of the following forms: IMPLICIT typ (al,al...)[,typ(al,al..)]... IMPLICIT NONE typ Is one of the data type specifiers (listed in Section 2.1). When typ is equal to CHARACTER=len, len specifies the length for character data type. Len is an unsigned integer constant or an integer constant expression enclosed in parentheses; len must be in the range of 1 to 65535. a Is an alphabetic specification in either of the general forms: c or cl-c2, where c is an alphabetic character. The latter form specifies a range of letters, from c1 through c2, where c1 precedes c2 in alphabetical order. Syntax Rules and Behavior The IMPLICIT statement assigns the specified data type to all symbolic names that have no explicit data type and begins with the specified letter or range of letters. It has no effect on the default types of intrinsic functions. 4-22 Specification Statements The IMPLICIT NONE statement disables all implicit defaults. When IMPLICIT NONE appears, all symbolic names in a program unit must be explicitly declared. No other IMPLICIT statements can appear in a program unit containing an IMPLICIT NONE statement. NOTE By using the /WARNINGS = DECLARATIONS qualifier on the FORTRAN command line, you will be issued warnings when variables are used but not typed—without having to use the IMPLICIT NONE statement, a language extension. Examples The following IMPLICIT statements represent the default in the absence of any explicit data type specifications: IMPLICIT INTEGER IMPLICIT REAL (I,J,K,L,M,N) (A-H, 0-2) As above, the following IMPLICIT statements assign the specified data type in the absense of any explicit data type specification: IMPLICIT DOUBLE PRECISION IMPLICIT COMPLEX (S,Y), IMPLICIT CHARACTER*32 IMPLICIT CHARACTER*2 4.9 (D) LOGICAL*1 (L,A-C) (T-V) (W) INTRINSIC Statement The INTRINSIC statement lets you use names of intrinsic functions as arguments to subprograms. It takes the following form: INTRINSIC v[,v]... v Is the symbolic name of an intrinsic function. Syntax Rules and Behavior 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. The subprogram can then use the corresponding dummy argument in a function reference or a CALL statement. Specification Statements 4-23 See Appendix D for the names and descriptions of the individual VAX FORTRAN intrinsic functions. For further information on intrinsic functions, see Chapter 6. Example In the following example, when TRIG is called with a second argument of SIN or COS, the function reference F(X) references the FORTRAN library functions SIN and COS; but when TRIG is called with a second argument of CTN, F(X) references the user function CTN. Subprogram Main Program SUBROUTINE TRIG(X,F,Y) Y = F(X) RETURN EXTERNAL CTN INTRINSIC SIN, COS END FUNCTION CTN(X) . CTN = COS(X)/SIN(X) CALL TRIG(ANGLE,SIN,SINE) RETURN END CALL TRIG(ANGLE,COS,COSINE) CALL TRIG(ANGLE,CTN,COTANGENT) 4.10 NAMELIST Statement The NAMELIST statement defines a list of variables or array names and associates that list of names with a unique group-name. The group-name is used in the namelist-directed 1/O statement to identify the variables or arrays that are to be read or written. NAMELIST statements take the following form: NAMELIST /group-name/ namelist[[,] /group-name/ namelist]... 4-24 Specification Statements group-name Is a symbolic name. namelist Is a list of variable or array names, separated by commas, that is to be associated with the preceding group-name. Syntax Rules and Behavior The namelist associates a group of entities (variables or arrays) with a single group-name, which is used by namelist-directed I/O statements instead of an I/O list. The unique group-name identifies a list whose entities can be modified or transferred. You cannot include array elements, character substrings, records, and record fields in a namelist, but you can use namelist-directed I/0 to assign values to elements of arrays or substrings of character variables that appear in namelists. The namelist entities can have any data type and can be explicitly or implicitly typed. Only the entities specified in the namelist can be read or written in namelist-directed 1/0. It is not necessary for the input records in a namelist-directed input statement to define every entity in the associated namelist. The order of entities in the namelist controls the order in which the values are written in the namelist-directed output. Input of namelist values can be in any order. A variable or an array name can appear in several namelists. Dummy arguments cannot appear in a namelist. Example In the following example, the NAMELIST statement defines two groupnames: INPUT, with the entities NAME, GRADE, and DATE; and OUTPUT, with the entities TOTAL and NAME. CHARACTER*30 NAME(25) NAMELIST /INPUT/ NAME, GRADE, DATE /OUTPUT/ TOTAL, NAME Refer to Sections 7.2.1.3 and 7.3.1.3 for more information on namelistdirected 1/0. Specification Statements 4-25 4.11 PARAMETER Statement The PARAMETER statement associates a symbolic name with a constant value. It takes the following form: PARAMETER (p=c[,p=c]...) p Is a symbolic name. C Is a constant, a compile-time constant expression, or the symbolic name of a constant. NOTE The form and interpretation of the PARAMETER statement described here are different from those of the PARAMETER statement provided in earlier DIGITAL versions of FORTRAN. However, VAX FORTRAN provides support for both the FORTRAN-77 and the earlier form of the PARAMETER statement. See Appendix A for information on the earlier form and interpretation. Syntax Rules and Behavior The data type of a symbolic name associated with a constant is determined as follows: e By an explicit type declaration statement preceding the defining e By the same rules for implicit declarations that determine the data PARAMETER statement type of any other symbolic name For example, the following PARAMETER statement is interpreted as MU=1 (MU has an integer data type by implication): PARAMETER (MU=1.23) If the PARAMETER statement is preceded by an appropriate type declaration or IMPLICIT statement, it could be interpreted as MU=1.23; for example: REAL*8 MU PARAMETER (MU=1.23) 4-26 Specification Statements Once a symbolic name is associated with a constant, it can appear anywhere in a program that anv other constant can appear—except in FORMAT statements (where constants can only be used in variable format expressions) and as the character count for Hollerith constants. For compilation purposes, writing the name is the same as writing the value. The following additional rules apply to symbolic names: e If the symbolic name is used as the length specifier in a CHARACTER declaration, it must be enclosed in parentheses. If it is used as a numeric item in a FORMAT edit description, it must be enclosed in angle brackets. * The symbolic name of a constant cannot appear as part of another constant, although it can appear as either the real or imaginary part of a complex constant, * A symbolic name can be defined only once within the same program unit. * A symbolic name defined to be a constant can be used only within the program unit containing the defining PARAMETER statement. Compile-Time Constant Expressions A compile-time constant expression can be a compile-time logical expression, a compile-time character expression, or a compile-time arithmetic expression. A compile-time logical expression is a logical expression with the following characteristics: * Each operand is either a constant; the symbolic name of a constant; one of the intrinsic functions IAND, IOR, NOT, IEOR ISHFT, LGE, LGT, LLE, LLT with constant operands; or another compile-time * Each operand has a data type of logical or integer. * Each operator is a Boolean or relational operator. constant expression. A compile-time character expression is a character expression with the following characteristics: e Each operand is either a constant, the symbolic name of a constant, the intrinsic function CHAR with a constant operand, or another compile-time constant expression. Specification Statements 4-27 e Each operand has a data type of character. e Each operator is the concatenation operator (//). A compile-time arithmetic expression is an arithmetic expression with the following characteristics: * Each operand is either a constant; the symbolic name of a constant; one of the intrinsic functions MIN, MAX, ABS, MOD, ICHAR, NINT, DIM, DPROD, CMPLX, CON]JG, IMAG with constant operands; or another compile-time constant expression. * Each operand has a data type of integer, real, or complex. * Each operator is a plus, minus, multiplication, division, or exponentiation sign. (The exponentiation operator is evaluated at compile time only if the exponent has an integer data type.) Example The following example demonstrates valid FORTRAN-77 PARAMETER statements: REAL*4 PI, PIOV2 REAL*8 DPI, DPIOV2 LOGICAL FLAG CHARACTER* (*) LONGNAME PARAMETER (PI=3.1415927, DPI=3.141592653589793238D0) PARAMETER (PIOV2=PI/2, PARAMETER (FLAG=.TRUE., 4.12 DPIOV2=DPI/2) LONGNAME='A STRING OF 25 CHARACTERS') PROGRAM Statement The PROGRAM statement associates a symbolic name with a main program unit. It takes the following form: PROGRAM nam nam Is the symbolic name of a source file. 4-28 Specification Statements Syntax Rules and Behavior The PROGRAM statement is optional. The default name for a main pro- gram unit is filename$3MAIN, where filename is the name of your source file. If filename is larger than 26 characters and a name is not specified in a PROGRAM or BLOCK DATA statement, the name is truncated to 26 characters and $MAIN is appended to form the program name. If you use the PROGRAM statement, it can be preceded only by an OPTIONS statement. Otherwise, it must come first in the main program. Its symbolic name cannot be the name of any entity within the main program or the name of any subprogram or entry point in the same executable program. 4.13 RECORD Statement The RECORD statement creates a record having the form specified in a previously declared structure (described in Section 4.15). The effect of using a RECORD statement is comparable to that of an ordinary FORTRAN type declaration, except composite or aggregate data items are declared instead of scalar data items. RECORD statements take the following form: RECORD /structure-name/record-namelist [,/structure-name/record-namelist] [,/structure-name/record-namelist] structure-name Is the name of a previously declared structure. See Section 4.15.1 for a description of structure declarations. record-namelist Is a list of one or more variable names, array names, or array declarators, separated by commas. All of the records named in this list have the same structure and are allocated separately in memory. Specification Statements 4-29 Syntax Rules and Behavior You can use record names in the following statements: COMMON DIMENSION Record names cannot be used in DATA, EQUIVALENCE, NAMELIST, or SAVE statements. Records initially have undefined values unless you have defined their values in structure declarations. Examples The following RECORD statement creates a pair of records (TODAY and YESTERDAY) in separate memory locations, but with the same structure (DATE): RECORD /DATE/ TODAY,YESTERDAY The following RECORD statement creates a record (CURRENT_CHECK) and an array of records (CHECKBOOK) with the structure CHECK: RECORD /CHECK/ CURRENT_CHECK, CHECKBOOK(1000) 4.14 SAVE Statement The SAVE statement causes the definition of data entities to be retained after execution of a RETURN or END statement in a subprogram. It takes the following form: SAVE [a[,a]...] a Is the symbolic name of a common block (preceded and followed by a slash), a variable, or an array. 4-30 Specification Statements Syntax Rules and Behavior A SAVE statement cannot include a blank common block, names of entities in a common block, procedure names, and names of dummy arguments. Within a program unit, an entity listed in a SAVE statement does not become undefined upon execution of a RETURN or END statement within that program unit. Even though a common block may be included in a SAVE statement, individual entities within the common block could become undefined (or redefined) in another program unit. When a SAVE statement does not explicitly contain a list, it is treated as though it contained a list of all allowable items in the program unit that contains it. NOTE It is not necessary to use SAVE statements in VAX FORTRAN programs. The definitions of data entities are retained automatically by VAX FORTRAN, making the use of SAVE statements redundant. However, its use is required by the ANSI FORTRAN Standard for programs that depend on such retention for their correct operation. If you want your programs to be transportable, you should include SAVE statements where your programs would otherwise require them. The omission of SAVE statements in necessary instances is not flagged, even when you specify the /STANDARD qualifier on the FORTRAN command line, because the compiler has no way to determine whether such dependencies exist. 4.15 Structure Declaration Block A structure declaration block is a multistatement declaration that defines the structure (or form) of a record. It contains the following elements: * STRUCTURE statement — marks the beginning of a structure declaration and defining the name of the structure. * Declaration body — contains one or more field declarations whose order determines the order of the fields within the structure,. Components of the declaration body are individually discussed in this section. Specification Statements 4-31 e END STRUCTURE statement — marks the end of a structure declaration. The Declaration Body The declaration body can have any of the following components: e Typed data declaration statements: These are ordinary FORTRAN type declarations, as described in Section 4.4. Fields can have any data type and can be dimensioned in the normal way. e Substructure declarations: A field within a structure can be a substructure composed of atomic fields, other substructures, or both. There are two ways to declare substructures: — By using RECORD statements that specify names of other, previously declared, structure declarations to be incorporated as substructures; see Section 4.13. — e By nesting structure declarations (having one or more levels of them contained within a structure declaration). Union declarations: A union declaration declares that groups of fields logically share a common location within a structure. Each group (one or more fields) is individually declared by a map declaration within the union declaration. e You use union declarations when you want to use the same area of memory to alternately contain two or more groups of fields. Whenever one of the fields declared by a union declaration is referenced in your program, that field and any other fields in its map declaration become defined. Then, when a field in one of the other map declarations in the union declaration is referenced, the fields in that map declaration become defined, superseding the fields that were previously defined. PARAMETER statements: PARAMETER statements can appear in a structure declaration block and have the same effect as if they appeared outside the block. (See Section 4.11 for information about PARAMETER statements.) The names specified in these statements are not the names of variables and the statements in a structure declaration do not create variables. The names are field names, and the information provided in the statements describes the layout, or form, of the structure. The ordering of both the statements and the field names within the statements is important because this ordering determines the order of the fields in records. The following sections describe structure declarations, substructure decla- rations, and union declarations. 4-32 Specification Statements 4.15.1 Structure Declaration Structure declarations define one or more fields within a VAX FORTRAN record. This declaration defines the field names, types of data within fields, and order and alignment of fields within a record. Unlike type declaration statements, structure declarations do not create variables. Structured variables (records) are created when you use a RECORD statement containing the name of a previously declared structure. The RECORD statement can be considered as a kind of type statement. The difference is that aggregate items, rather than single items, are being defined. A structure declaration takes the following form: STRUCTURE [/structure-name/][field-namelist] field-declaration [field-declaration] [field-declaration] END STRUCTURE structure-name Is the name used to identify a structure. A structure name is enclosed by slashes. If the slashes are present, a name must be specified between them. Subsequent RECORD statements use the structure name to refer to the structure. A structure name must be unique among structure names. However, structures can share names with variables (scalar or array), record fields, or common blocks. Thus, it is possible to have a variable named X, a structure named X, one or more fields named X, and a common block named X. Structure declarations can be nested (contain one or more other structure declarations). A structure name is required for the structured declaration at the outermost level of nesting, and optional for the other declarations nested in it. However, if you wish to reference a nested structure in a RECORD statement in your program, it must have a name. Structure, field, and record names are all local to the defining program unit. When records are passed as arguments, the fields must match in type, order, and dimension. Specification Statements 4-33 field-namelist Is a list of fields having the structure of the associated structure declaration. A field namelist is allowed only in nested structure declarations. Nested structure declarations are described in Section 4.15.2. field-declaration Consists of any combination of the following types of declarations: e Substructure declaration: A field within a structure can be a substructure composed of atomic fields, other substructures, or a combination of atomic fields and substructures. See Section 4.15.2 for a description of substructure declarations. e Union declaration: A union declaration is composed of one or more mapped field declarations. The mapped fields logically share a common location within a structure. See Section 4.15.3 for a more complete description of union declarations. e Field declaration: The syntax of a field declaration within a record structure is identical to that of a normal FORTRAN type statement: it includes a type (for example, INTEGER), one or more names of variables or arrays; and optionally, one or more data initialization values. Syntax Rules and Behavior The following rules and behavior apply to typed data declarations in record structures: e %FILL can be specified in place of a field name to leave space in a record for purposes such as alignment. This creates an unnamed field. Unnamed fields cannot be initialized. For example, the following statement is invalid and generates an error message: INTEGER*4 J%FILL /1980/ e Initial values can be supplied in field declaration statements. These initial values are supplied for all records that are declared using this structure. Fields not initialized will have undefined values when variables are declared by means of RECORD statements. Unnamed fields cannot be initialized; they are always undefined. e All field names must be explicitly typed. There are no default names. The IMPLICIT statement has no effect on statements within a structure declaration. e 4-34 All VAX FORTRAN data types are allowed in field declarations. Specification Statements * Any required array dimensions must be specified in the field declaration statements. DIMENSION statements cannot be used to define field names. * Adjustable or assumed sized arrays and passed-length CHARACTER declarations are not allowed in field declarations. * Field names within the same declaration level must be unique, but an inner structure declaration (substructure declaration) can include field names used in an outer structure declaration without conflict. In a structure declaration, each field offset is the sum of the lengths of the previous fields. The length of the structure, therefore, is the sum of the lengths of its fields. The structure is packed; you must explicitly provide any alignment that is needed by including, for example, unnamed fields of the appropriate length. Examples In the first example, the declaration defines a structure named DATE. This structure contains three scalar fields: DAY (LOGICALx*1), MONTH (LOGICAL=*1), and YEAR (INTEGER*2). STRUCTURE /DATE/ LOGICAL*x1 DAY, INTEGER*2 YEAR MONTH END STRUCTURE The following diagram shows the memory mapping of any record or record array element with the structure DATE. (byte offset) 0 field DAY 1 field MONTH 2 field YEAR 4 ZK-1849-84 Specification Statements 4-35 In the second example, the declaration defines a structure named APPOINTMENT. APPOINTMENT contains the structure DATE (field APP_DATE) as a substructure. It also contains a substructure named TIME (field APP_TIME, an array), a CHARACTER+*20 array named APP_ MEMO, and a LOGICAL=*1 field named APP_FLAG. STRUCTURE /APPOINTMENT/ RECORD /DATE/ APP_DATE STRUCTURE /TIME/ APP_TIME (2) LOGICAL*1 HOUR, MINUTE END STRUCTURE CHARACTER*20 APP_MEMO (4) LOGICAL*1 APP_FLAG END STRUCTURE The length of any instance of structure APPOINTMENT is 89 bytes. The following diagram shows the memory mapping of any record or record array element with the structure APPOINTMENT: 4-36 Specification Statements (byte offset) 0 field DAY of field APP_DATE field MONTH of field APP_DATE field YEAR of field APP_DATE field HOUR of field APP_TIME(1) field MINUTE of field APP__TIME(1) field HOUR of field APP_TIME(2) field MINUTE of field APP_TIME(2) field APP_MEMO(1) 28 field APP_MEMO(2) 48 field APP_MEMO(3) 68 field APP_MEMO(4) 88 field APP_FLAG 89 ZK-1848-84 Specification Statements 4-37 4.15.2 Substructure Declarations A field within a structure can itself be a structured item composed of other fields, other structures, or both. You can declare a substructure in two ways: e By nesting structure declarations within other structure or union declarations (with the limitation that you cannot refer to a structure inside itself at any level of nesting). One or more field names must be defined in the STRUCTURE statement for the substructure because all fields in a structure must be named. In this case, the substructure is being used as a field within a structure or union. Field names within the same declaration nesting level must be unique, but an inner structure declaration can include field names used in an outer structure declaration without conflict. %FILL can be specified in place of a field name to leave space in a record for purposes such as alignment. By using a RECORD statement that specifies another previously defined record structure, thereby including it in the structure being declared. See the second example in the preceding section for a sample structure declaration containing both a nested structure declaration (TIME) and an included structure (DATE). 4.15.3 Union Declarations A union declaration is a multistatement declaration defining a data area that can be shared intermittently during program execution by one or more fields or groups of fields. A union declaration is initiated by a UNION statement and terminated by an END UNION statement. Enclosed within these statements are two or more map declarations, initiated and terminated by MAP and END MAP statements. Each unique field or group of fields is defined by a separate map declaration. 4-38 Specification Statements A union declaration takes the following form: UNION map-declaration map-declaration [map-declaration] [map-declaration] END UNION map-declaration Takes the following form: MAP field-declaration [field-declaration] [field-declaration] END MAP field-declaration Is a structure declaration or RECORD statement contained within a union declaration, a union declaration contained within a union declaration, or the declaration of a typed data field within a union. See Section 4.15.1 for a more detailed description of what can be specified in field declarations. Syntax Rules and Behavior As with normal FORTRAN type declarations, data can be initialized in field declaration statements in union declarations. However, if fields within multiple map declarations in a single union are initialized, the data declarations are initialized in the order in which the statements appear. As a result, only the final initialization takes effect and all of the preceding initializations are overwritten. The size of the shared area established for a union declaration is the size of the largest map defined for that union. The size of a map is the sum of the sizes of the fields declared within it. As the variables or arrays declared in map fields in a union declaration are assigned values during program execution, the values are established in a record in the field shared with other map fields in the union. The fields of only one of the map declarations are defined within a union at any given point in the execution of a program. However, if you overlay one Specification Statements 4-39 variable with another smaller variable, that portion of the initial variable is retained that is not overlaid. Depending on the application, the retained portion of an overlaid variable may or may not contain meaningful data and can be utilized at a later point in the program. Manipulating data using union declarations is similar to what happens using EQUIVALENCE statements. The difference is that data entities specified within EQUIVALENCE statements are concurrently associated with a common storage location and the data residing there; union declarations enable you to use one discrete storage location to alternately contain a variety of fields (arrays or variables). With union declarations, only one map declaration within a union declaration can be associated at any point in time with the storage location that they share. Whenever a field within another map declaration in the same union declaration is referenced in your program, the fields in the prior map declaration become undefined and are succeeded by the fields in the map declaration containing the newly referenced field. Example In the following example, the structure WORDS_LONG is defined. This structure contains a union declaration defining two map fields. The first map field consists of three INTEGER#*2 variables (WORD_0, WORD_1, and WORD_2), and the second, an INTEGER*4 variable, LONG: STRUCTURE /WORDS_LONG/ UNION MAP INTEGER*2 WORD_O, WORD_1, WORD_2 END MAP MAP INTEGER*4 LONG END MAP END UNION END STRUCTURE The length of any record with the structure WORDS_LONG is six bytes. The following diagram shows the memory mapping of any record with the structure WORDS_LONG: 4-40 Specification Statements 0 1 - 2 3 N\ Field WORD_O \ I 4 4 5 N Field WORD_1 Y — Field LONG 6 (byte offset) . 4 Field WORD_2 VA J/ D Unused Space ZK-1846-84 4.16 VOLATILE Statement The VOLATILE statement specifies that a value is entirely unpredictable, based on information local to the current program unit. It prevents specified variables, arrays, and common blocks from being optimized during compilation. VOLATILE takes the following form: VOLATILE nlist nlist Is a list of one or more variable names, named common blocks (preceded and followed by a slash), or array names, separated by commas. If array names or common block names are used, the entire array or common block becomes volatile, as the following example demonstrates. Example In the following statements, the named common block, BLK1, and the variables D and E are volatile. In addition, variables P1 and P4 become volatile because the direct equivalence (in the case of P1) and the indirect equivalence (in the case of P4) causes them to assume the volatile attribute. Specification Statements 4-41 PROGRAM TEST LOGICAL*1 IPI(4) INTEGER*4 A,B,C,D,E, ILOCK INTEGER*4 P1,P2,P3,P4 COMMON /BLK1/A,B,C VOLATILE /BLK1/,D.E EQUIVALENCE (ILOOK, IPI) EQUIVALENCE (A,P1) EQUIVALENCE (P1,P4) See the VAX FORTRAN User Manual for information about the optimizations performed by the VAX FORTRAN compiler and the circumstances in which you should use the VOLATILE declaration. 4-42 Specification Statements Chapter 5 Control Statements Statements normally execute in the order in which they are written. However, you can alter the normal order of execution by transferring control to another section of a program unit or a subprogram. Transfer of control can be conditional or unconditional: Conditional transfer occurs only when specified conditions are met at a certain point in a program unit. Unconditional transfer occurs each time a certain point is reached in a program unit. FORTRAN control statements transfer control to a point within the same program unit or to another program unit. These statements govern iterative processing, suspension of program execution, and program termination. VAX FORTRAN supports the following control statements: e CALL—invokes a subroutine subprogram (Section 5.1). CONTINUE—transfers control to the next executable statement e DO and DO WHILE—execute a block of statements repetitively e END DO—terminates DO and DO WHILE loops (Section 5.4). END—marks the end of a program unit (Section 5.5). GO TO—transfers control within a program unit (Section 5.6). e e e (Section 5.2). (Section 5.3). e IF—conditionally transfers control or executes a statement or block of e PAUSE—temporarily suspends program execution (Section 5.8). statements (Section 5.7). Control Statements 5-1 * RETURN-—returns control from a subprogram to the calling program unit (Section 5.9). * 5.1 STOP—terminates program execution (Section 5.10). CALL Statement The CALL statement executes a subroutine subprogram or other external procedure. It can specify an argument list for the subroutine. The CALL statement takes the following form: CALL sub{([a][,[al]l...)] sub Is the name of a subroutine subprogram or other external procedure, or a dummy argument associated with a subroutine subprogram or other external procedure. See Chapter 6 for details on the definition and use of subroutines. a Is an actual argument. (Section 6.1 describes actual arguments.) Syntax Rules and Behavior If you specify an argument list, the CALL statement associates the values in the list with the dummy arguments in the subroutine. It then transfers control to the first executable statement following the SUBROUTINE or ENTRY statement referenced by the CALL statement. The arguments in the CALL statement must agree in number, order, and data type with the dummy arguments in the subroutine. They can be variables, arrays, array elements, records, record elements, record arrays, record array elements, substring references, constants, expressions, Hollerith constants, alternate return specifiers, or subprogram names. An unsubscripted array name or record array name in the argument list refers to the entire array. 5-2 Control Statements Examples The following examples demonstrate valid CALL statements. The last CALL statement uses statement label identifiers in its argument list. The asterisks indicate that *10 and *20 are statement label identifiers. Label identifiers that are prefixed by asterisks or ampersands (&) are called alternate return specifiers (see Section 6.1.1.5). CALL CURVE(BASE,3.14159+X,Y,LIMIT,R(LT+2)) CALL PNTOUT(A,N, 'ABCD') CALL EXIT RECORD /GETJPI/ GETJPIARG CALL SYS$GETJPI (,,,GETJPIARG,,,) CALL MULT(A,B,*10,%*20,C) 52 CONTINUE Statement The CONTINUE statement transfers control to the next executable statement. It primarily functions as the terminal statement of a labeled DO loop when the loop would otherwise end improperly with either a GO TO, arithmetic IF, or other prohibited control statement. CONTINUE takes the following form: CONTINUE 5.3 DO Statements DO statements can be either one of two types: ® Indexed (DO) ®* Pretested and indefinite (DO WHILE) Control Statements 5-3 5.3.1 Indexed DO Statement The indexed DO statement controls iterative processing (the statements in its range are repeatedly executed a specified number of times). It takes the following form: DO [s[,]] v=el,e2[,e3] s Is the label of an executable statement. The executable statement must physically follow the DO statement in the same program unit. The label is optional in VAX FORTRAN. v Is a variable with an integer or real data type. el,e2,e3 Are arithmetic expressions. Syntax Rules and Behavior The variable v is the control variable; el, e2, and e3 are the initial, terminal, and increment parameters, respectively. If you omit the increment parameter, a default increment value of 1 is used. The optional label that appears in the DO statement identifies the terminal statement of the DO loop. If no label appears in the DO statement, the DO loop must be terminated by the END DO statement, as discussed in Section 5.4. The terminal statement must not be one of the following statements: e Unconditional or assigned GO TO ® Arithmetic IF * Any block IF e END e RETURN e DO The range of the DO statement includes all the statements that follow the DO statement, up to and including the terminal statement or END DO. b-4 Control Statements The DO statement first evaluates the expressions el, e2, and e3 to determine values for the initial, terminal, and increment parameters, respectively. The increment parameter (e3) cannot be zero. The value of the initial parameter is assigned to the control variable. If the data type of the initial, terminal, and increment parameters are not the same as the data type of the control variable, they are converted before they are used. The number of executions of the DO range, or iteration count, is given by the arithmetic expression [(e2 — el + €3)/e3]. The notation [e] represents the largest integer whose magnitude does not exceed the magnitude of e and whose sign is the same as the sign of e. If the iteration count is zero or negative, the body of the loop is not executed. If the /NOF77 qualifier is specified on the FORTRAN command and the iteration count is zero or negative, the body of the loop executes once. 5.3.1.1 DO Iteration Control After each iteration of the DO range, the following steps execute: 1. The value of the increment parameter (e3) is algebraically added to the control variable. 2. The iteration count is decremented. 3. The iteration count is evaluated and action taken as follows: e [If the iteration count is greater than zero, control transfers to the first executable statement after the DO statement for another iteration of the range. e [f the iteration count is zero, execution of the DO statement terminates. The final value of the control variable is the value determined by step 1. If the control variable has a real data type, the number of iterations of the DO range might not be what you expect because of rounding errors. You can also terminate execution of a DO statement by using a statement within the range that transfers control outside the loop. The control variable of the DO statement remains defined with its current value. Control Statements b-5 When execution of a DO loop terminates and other DO loops share its terminal statement, control transfers to the next outermost DO loop in the DO nesting structure (see Section 5.3.1.2). If no other DO loop shares the terminal statement or if the DO statement is outermost, control transfers to the first executable statement after the terminal statement. You cannot alter the value of the control variable within the range of the DO statement. However, you can use the control variable for reference as a variable within the range. You can modify the initial, terminal, and increment parameters within the loop without affecting the iteration count. The range of a DO statement can contain other DO statements, as long as these nested DO loops meet certain requirements. Section 5.3.1.2 describes these requirements. You can transfer control out of a DO loop, but not into a loop from elsewhere in the program. Exceptions to this rule are described in Sections 5.3.1.3 and 5.3.1.4. Examples The following examples demonstrate valid and invalid DO iteration control: Valid The first statement specifies 25 iterations: K=49 during the final iteration, =51 after the loop. DO 100 K=1,50,2 The next statement specifies 27 iterations: J=-2 during the final iteration, J=—4 after the loop. DO 350 J=50,-2,-2 The next statement specifies 5 iterations: IVAR=5 during the final iteration, IVAR=6 after the loop. DO 25 IVAR=1,5 The next statement specifies 9 iterations: NUMBER=37 during the final iteration, NUMBER=41 after the loop. The terminating statement of the DO loop must be END DO. DO NUMBER=5,40,4 5-6 Control Statements Invalid The last statement shows how a common typing error can cause errors with DO loops—a decimal point is typed in place of a comma. In effect, this statement assigns 2.10 to the real variable DO40M. DO 40 M=2.10 5.3.1.2 Nested DO Loops A DO loop can contain one or more complete DO loops. The range of an inner nested DO loop must lie completely within the range of the next outer loop. Nested loops can share a labeled terminal statement but not an END DO statement, Table 5-1 illustrates correctly and incorrectly nested DO loops. Table 5-1: Nested DO Loops Correctly Nested Incorrectly Nested DO loops DO Loops B DO 45 K=1,10 B DO 15 K=1,10 B DO 35 L=2,50,2 | 35 CONTINUE __ 15 CONTINUE B DO 45 M=1,20 o DO 30 M=1,15 L 45 CONTINUE B __| DO 25 L=1,20 25 CONTINUE 30 CONTINUE Control Statements 5-7 Table 5-1 (Cont.): Nested DO Loops Correctly Nested Incorrectly Nested DO Loops DO loops — — DO 10 I=1,20 — DO J=1,5 B — DO X=1,10 _ END DO _ 5.3.1.3 __ END DO 10 CONTINUE DO J=1,10 |10 | DO 10 I=1,5 CONTINUE END DO Control Transfers in DO Loops In a nested DO loop, you can transfer control from an inner loop to an outer loop. However, a transfer into a loop from outside that loop is not permitted. If two or more nested DO loops share the same terminal statement, you can transfer control to that statement only from within the range of the innermost loop. Any other transfer to that statement constitutes a transfer from an outer loop to an inner loop because the shared statement is part of the range of the innermost loop. b-8 Control Statements 5.3.1.4 Extended Range A DO loop has an extended range if it contains a control statement that transfers control out of the loop and if, after execution of one or more statements, another control statement returns control back into the loop. Thus, the range of the loop is extended to include all executable statements between the destination statement of the first transfer and the statement that returns control to the loop. The following rules apply when using a DO loop extended range: * 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 change the control variable of the DO statement. Figure 5-1 illustrates valid and invalid extended range control transfers. 5.3.2 DO WHILE Statement The DO WHILE statement is similar to the DO statement. However, whereas the DO statement executes unconditionally for a fixed number of iterations, the DO WHILE statement executes conditionally for as long as a logical expression contained in it continues to be true. The DO WHILE statement takes the following form: DO [s[,]] WHILE (e) S Is the label of an executable statement that must physically follow in the same program unit. e Is a logical expression. Control Statements 5-9 Figure 5-1: Control Transfers and Extended Range Invalid Valid Control Transfers Control Transfers GO TO 20 DO 35 K=1,10 DO 15 L=2,20 DO 50 K=1,10 - 20 GO TO 20 s 20 CONTINUE DO 35 L=2,20 B A=B+C 30 D = E/F DO 35 M=1,15 |35 coNTINGE GO TO 40 GO TO 50 DO A=B+C 30 X =A*D s CONTINUE DO 45 M=1,15 - Loop 50 Extended Range D = E/F GO TO 30 40 X =A=*D L.45 CONTINUE L 50 CONTINUE GO TO 30 ZK-4761-85 5-10 Control Statements Syntax Rules and Behavior 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 5.4). You can transfer control out of a DO WHILE loop but not into a loop from elsewhere in the program. Example The following example demonstrates a valid DO WHILE statement: CHARACTER*132 LINE I =1 LINE(132:) DO WHILE = 'x' (LINE(I:I) .EQ. ' ') I=1+1 END DO 5.4 END DO Statement The END DO statement terminates the range of the DO and DO WHILE statements. END DO is a mandatory terminator of DO blocks if the DO or DO WHILE statement defining the blocks does not contain a terminalstatement label. If they do contain a terminal-statement label, END DO is optional and can be used as a labeled terminal statement. END DO takes the following form: END DO Control Statements 5-11 Examples The following examples demonstrate mandatory and optional END DO statements: Mandatory Optional DO 10 WHILE (I .GT. J) DO WHILE (I .GT. J) ARRAY(I,J) =1.0 ARRAY(I,J) = 1.0 I1=1-1 END DO 5.5 10 I1=1-1 END DO END Statement The END statement marks the end of a program unit and must be the last source line of every program unit. It takes the following form: END In a main program, if control reaches the END statement, program ex- ecution terminates. In a subprogram, a RETURN statement is implicitly executed. If an initial line contains only an END in the statement field, it is treated as an END statement even if it is followed by continuation lines. 5.6 GO TO Statements GO TO statements transfer control within a program unit. Depending on the value of an expression, control transfers to the same statement every time GO TO executes or to one of a set of statements. VAX FORTRAN supports three different kinds of GO TO statements: 5-12 ¢ Unconditional e Computed e Assigned Control Statements 5.6.1 Unconditional GO TO Statement The unconditional GO TO statement transfers control to the same state- ment every time it executes. It takes the following form: GO TO s S Is the label of an executable statement that is in the same program unit as the GO TO statement. The unconditional GO TO statement transfers control to the statement identified by the specified label. The label must identify an executable statement that is in the same program unit as the GO TO statement. Examples The following examples demonstrate unconditional GO TO statements: GO TO 7734 GO TO 99999 5.6.2 Computed GO TO Statement The computed GO TO statement transfers control to a statement based on the value of an expression within the statement. It takes the following form: GO TO (slist)[,] e slist Is a list of one or more labels of executable statements separated by commas. The list of labels is called the transfer list. e Is an arithmetic expression in the range 1 to n (where n is the number of statement labels in the transfer list). Control Statements 5-13 Syntax Rules and Behavior The computed GO TO statement evaluates the expression e and, if nec- essary, converts the resulting value to integer data type. Control is transferred to the statement label in position e in the transfer list. For example, if the list contains (30,20,30,40) and the value of e is 2, control is transferred to statement 20. If the value of e is less than 1 or greater than the number of labels in the transfer list, control is transferred to the first executable statement after the computed GO TO statement. Examples The following examples demonstrate valid computed GO TO statements: GO TO (12,24,36), INDEX GO TO (320,330,340,350,360), SITU(J,K) + 1 5.6.3 Assigned GO TO Statement The assigned GO TO statement transfers control to a statement label that is represented by a variable. An ASSIGN statement must establish the relationship between the variable and a specific statement label. Thus, the transfer destination can be changed, depending on the most recently executed ASSIGN statement. Assigned GO TO statements take the following form: GO TO v[[,]1(slist)] v Is an integer variable. slist Is a list of one or more labels of executable statements separated by commas; slist does not affect statement execution and can be omitted, 5-14 Control Statements Syntax Rules and Behavior The assigned GO TO statement transfers control to the statement whose label was most recently assigned to the variable v. The variable v must be of integer data type and must have a statement label value assigned to it by an ASSIGN statement (not an arithmetic assignment statement) before the GO TO statement is executed. Both the assigned GO TO statement and its associated ASSIGN statements must exist in the same program unit. Statements that receive control must also be in the same program unit and must be executable. Examples The first example is equivalent to ¢o T0 200: ASSIGN 200 TO IGO GO TO IGO The second example is equivalent to 6o 10 450: ASSIGN 450 TO GO TO IBEG, 5.7 IBEG (300,450,1000,25) IF Statements IF statements conditionally transfer control or execute a statement or block of statements. They can be any one of three kinds: * Arithmetic * Logical e Block (IF THEN, ELSE IF THEN, ELSE, END IF) For each kind, the decision to transfer control or to execute the statement or block of statements is based on the evaluation of an expression within the IF statement. Control Statements 5-15 5.7.1 Arithmetic IF Statement The arithmetic IF statement conditionally transfers control to one of three statements, based on the current value of an arithmetic expression. It takes the following form: IF (e) s1,s2,s83 e Is an arithmetic expression. s1,s2,s3 Are labels of executable statements in the same program unit. Syntax Rules and Behavior All three labels (s1,s2,s3) are required, but they do not need to refer to three different statements. The arithmetic IF statement first evaluates the expression e. It then transfers control to one of the three statement labels in the transfer list, as follows: If the value of e is: Control passes to: Less than 0 Label s1 Equal to 0 Label s2 Greater than 0 Label s3 Examples The first example transfers control to statement 50 if the real variable THETA is less than or equal to the real variable CHI. Control passes to statement 100 only if THETA is greater than CHI. IF (THETA-CHI) 50,50,100 The second example transfers control to statement 40 if the value of the integer variable NUMBER is even. It transfers control to statement 20 if the value is odd. IF 5-16 (NUMBER/2#2-NUMBER) Control Statements 20,40,20 5.7.2 Logical IF Statement The logical IF statement conditionally executes a single FORTRAN statement based on the current value of a logical expression within the logical IF statement. It takes the following form: IF (e) st e Is a logical expression. st Is any complete, executable FORTRAN statement—except any of the block IF statements, DO, END DO, or another logical IF statement. The logical IF statement first evaluates the logical expression e and then acts as follows: e [f e is true, st executes. o [If e is false, control transfers to the next executable statement after the logical IF; st does not execute. Examples The following examples demonstrate valid logical IF statements: 5.7.3 IF (J.GT.4 IF (REF(J,K) IF (ENDRUN) .OR. J.LT.1) .NE. HOLD) GO TO 250 REF(J,K) = REF(J,K) * (-1.5DO) CALL EXIT Block IF Statements Block IF statements conditionally execute blocks (groups) of statements. They can be any one of the following: e [F THEN e ELSE IF THEN e ELSE e ENDIF Control Statements 5-17 In block IF constructs, these statements take the following form: (e) IF THEN block ELSE IF (el) THEN block ELSE block END IF e Is a logical expression. block Is a sequence of zero or more complete FORTRAN statements. This sequence is called a statement block. Syntax Rules and Behavior Each statement in a block IF construct, 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 the logical expressions in the preceding block IF statements. The functions of individual statements in a block IF construct are as follows: e [F THEN—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. NOTE No additional statement can be placed after the IF THEN statement in a block IF construct. For example, the following statement is invalid in the block IF construct: IF (e) THEN I = J This statement is translated as the logical IF statement IF h-18 Control Statements (e) THENI = J. ELSE IF THEN—is an optional statement that specifies a statement block to be executed if no preceding statement block in the block IF construct has been executed, and if the value of the logical expression in the ELSE IF THEN statement is true. A block IF construct can contain any number of ELSE IF THEN statements. ELSE—specifies a statement block to be executed if no preceding statement block in the block IF construct has been executed. The ELSE statement is optional. However, if the ELSE statement is present, the ELSE statement block must be immediately followed by the END IF statement. END IF—terminates the block IF construct. After the last statement in a statement block is executed, control passes to the next executable statement following the END IF statement. Consequently, no more than one statement block in a block IF construct is executed each time the IF THEN statement is executed. ELSE IF THEN and ELSE statements can have statement labels, but the labels cannot be referenced. The END IF statement can have a statement label to which control can be transferred, but only from within the immediately preceding block. Figure 5-2 shows the flow of control for four examples of block IF constructs. Control Statements 5-19 Figure 5-2: Examples of Block IF Constructs Flow of Control Construct False {F (e) THEN block True END IF Execute block Test False e IF (e) THEN b|OCk1 True ELSE blocks END IF ! Execute Execute block blacky Execute Execute IF {(e7) THEN b|OCk1 ELSE IF (e3) THEN b|0Ck2 END IF block blocksy IF (e1) THEN b|OCk1 ELSE IF (ep) THEN blockso ELSE IF (e3) THEN. blocks ELSE blockg Execute block, END IF Execute block; Execute blocks Execute blockg L \ ZK-617-82 5-20 Control Statements 5.7.3.1 Statement Blocks A statement block can contain any executable FORTRAN statement except an END statement. You can transfer control out of a statement block, but you must not transfer control into a block. Thus, you must not transfer control from one statement block to another. DO loops cannot partially overlap statement blocks. The DO statement and its terminal statement must appear together in a statement block. 5.7.3.2 Block IF Examples The following examples illustrate four variations of block IF constructs: Variation 1: The simplest block IF construct consists of the IF THEN and END I[F statements. This construct conditionally executes one state- ment block, which consists of all the statements between the IF THEN and the END IF statements. Form Example IF (e) THEN IF (ABS(ADJU) block .GE. 1.0E-6) THEN TOTERR = TOTERR + ABS(ADJU) QUEST = ADJU/FNDVAL END IF END IF The IF THEN statement first evaluates the logical expression e. 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, and the block is not executed. Variation 2: The second variation contains a block IF construct with an ELSE IF THEN statement. Block1 consists of all the statements between the IF THEN and the ELSE IF THEN statements; block2 consists of all the Control Statements 5-21 statements between the ELSE IF THEN and the END IF statements. Form Example IF (e1) THEN IF (A .GT. B) THEN D=8 block1 F=A-B ELSE IF (e2) THEN block?2 ELSE IF (A .GT. B/2.) THEN D = B/2. F=A-B/2 END IF END IF If A is greater than B, blockl is executed. If A is not greater than B but A is greater than B/2, block2 is executed. If A is not greater than B and A is not greater than B/2, neither blockl nor block2 is executed; control transfers directly to the next executable statement after the END IF statement. Variation 3: The third variation contains a block IF construct with an FLSE statement. Blockl consists of all the statements between the IF THEN and ELSE statements; block2 consists of all the statements between the ELSE and the END IF statements. If the value of the character variable NAME is less than 'N’, blockl is executed. If the value of NAME is greater than or equal to ‘N’, block2 is executed. Form Example IF (e) THEN IF (NAME .LT. 'N') THEN IFRONT = IFRONT + 1 block1 FRLET (IFRONT) = NAME(1:2) ELSE block2 END IF Variation 4: ELSE IBACK = IBACK + 1 END IF The fourth variation contains a block IF construct with several ELSE IF THEN statements and an ELSE statement. h-22 Control Statements There are four statement blocks in this example. Each consists of all the statements between the block IF statements that follow: Block Delimiting Block IF Statements block1 IF THEN and first ELSE IF THEN block2 First ELSE IF THEN and second ELSE IF THEN block3 Second ELSE IF THEN and ELSE block4 ELSE and END IF If A is greater than B, blockl is executed. If A is not greater than B but is greater than C, block2 is executed. If A is not greater than B or C but is greater than Z, block3 is executed. If A is not greater than B, C, or Z, block4 is executed. Form Example IF (e1) THEN IF (A .GT. B) THEN block1 = B F=A-B ELSE IF (e2) THEN ELSE IF (A .GT. C) THEN block2 D=C F=A-C ELSE IF (e3) THEN ELSE IF (A .GT. Z) THEN block3 D=2 F=A-2 ELSE block4 ELSE D=0.0 F END IF 5.7.3.3 = END IF Nested Block IF Constructs You can include a block IF construct in the statement block of another block IF construct—but the nested block IF construct must be completely contained within a statement block. It cannot overlap statement blocks. Control Statements 5-23 The following example contains a nested block IF construct: Form Example IF (el) THEN IF (A .LT. 100) THEN INRAN = INRAN + 1 IF (e2) THEN IF (ABS(A-AVG) .LE. 5.) blockla INAVG = INAVG + 1 block 1 ELSE ELSE OUTAVG = OUTAVG + 1 block1b END IF END IF ELSE THEN ELSE OUTRAN = OUTRAN + 1 block 2 END IF END IF If A is less than 100, the code immediately after the IF is executed. This code contains a nested block IF construct. If the absolute value of A minus AVG is less than or equal to 5, blockla is executed. If the absolute value of A minus AVG is greater than 5, block1b is executed. If A is greater than or equal to 100, block?2 is executed, and the nested IF construct (block1) is not executed. 5.8 PAUSE Statement The PAUSE statement displays a message on the terminal and temporarily suspends program execution in order to permit you to take some action. It takes the following form: PAUSE disp [disp] Is a character constant or a string of decimal numbers (one to five digits). h-24 Control Statements Syntax Rules and Behavior The disp argument is optional. The effect of a PAUSE statement depends on how your program is being executed. If your program is running as a batch job or detached process, the contents of disp are written to the system output file, but the program 1s not suspended. If the program is running in interactive mode, the contents of disp are displayed at your terminal, followed by the prompt sequence, indicating that the program is suspended and that you should enter a command. For example, if the following statement is executed in interactive mode: PAUSE 'ERRONEQOUS RESULT DETECTED' You will see the following display at the terminal: ERRONEOUS RESULT DETECTED $ If you do not specify a value for disp, the following message is displayed by the system: FORTRAN PAUSE You can respond by typing one of the following DCL commands: ¢ 5.9 CONTINUE-—resume execution at the next executable statement. e EXIT—terminate execution. * DEBUG—resume execution under control of the VMS Debugger. RETURN Statement The RETURN statement transfers control from a subprogram to the program that called the subprogram. You can use RETURN only in a subprogram unit. The RETURN statement takes the following form: RETURN [i] i Is an optional integer constant or expression (such as 2 or I+]) that is converted to an integer value if necessary. Control Statements 5-25 Syntax Rules and Behavior The optional argument, i, indicates an alternate return from the subprogram. It can be specified only in subroutine subprograms, not in function subprograms. The value of i specifies that the ith alternate return in the actual argument list is to be taken (see the second example that follows in this section). When a RETURN statement is executed in a function subprogram, control is returned to the calling program at the statement that contains the function reference (see Chapter 6). When a RETURN statement is executed in a subroutine, control is returned either to the first executable statement following the CALL statement that initiated the subroutine, or to the statement label that was specified as the ith alternate return in the CALL argument list. Examples In the first example, control is returned to the calling program at the first executable statement following the CALL CONVRT statement. SUBROUTINE CONVRT(N,ALPH,DATA,PRNT,K) INTEGER ALPH(*), DATA(*), PRNT(%) IF (N .GE. 10) THEN DATA(K+2) = N-(N/10)*N N = N/10 DATA(K+1) = N PRNT(K+2) = ALPH(DATA(K+2)+1) PRNT(K+1) = ALPH(DATA(K+1)+1) ELSE PRNT(K+2) = ALPH(N+1) END IF RETURN END The second example shows how alternate returns can be included in a subroutine. Bb-26 Control Statements SUBROUTINE CHECK(X,Y,*,*,C) 50 IF 60 RETURN (Z) 60,70,80 70 RETURN 80 RETURN 2 1 END Depending on the computed value of Z, one of the following returns occurs: ® If Zis less than zero, a normal return occurs and the calling program continues at the first executable statement following CALL CHECK. * If Z equals zero, the first alternate return (RETURN 1) occurs. * If Zis greater than zero, the second alternate return (RETURN 2) occurs. Control returns to the statement specified as the first or second alternate return argument in the CALL statement argument list; for example, the CALL statement might take the following form: CALL CHECK(A,B,*10,%*20,C) In this case, RETURN 1 transfers control to statement label 10 and RETURN 2 transfers control to statement label 20. If a subroutine includes an alternate return specifying a value less than 1 or greater than the number of alternate return arguments, control returns to the next executable statement after the CALL statement (alternate returns are ignored). Thus, you should ensure that the value of i is within the range of alternate return arguments. 5.10 STOP Statement The STOP statement terminates program execution. It takes the following form: STOP [disp] Control Statements 5-27 disp Is a character constant or a string of decimal numbers (one to five digits). The disp argument is optional. If you specify it, the STOP statement displays the contents of disp at your terminal, terminates program execution, and returns control to the operating system. If you do not specify a value for disp, the following message is sent by the system: FORTRAN STOP Examples The following examples demonstrate valid STOP statements: STOP 98 STOP 'END OF RUN' h-28 Control Statements Chapter 6 Subprograms — Subroutines and Functions Subprograms are program units that can be invoked from another program unit, usually to perform some commonly used computation on behalf of the other program unit. Normally, the program unit invoking the subprogram passes values, known as actual arguments, to the subprogram, which uses the actual arguments to compute the results and then returns the results to the calling program. Subprograms are either written by the user or supplied as part of the VAX FORTRAN library. User-written subprograms include the following;: Statement functions—A computing procedure defined by a single statement that is similar in form to an assignment statement. A statement function is invoked by a function reference in a main program unit or a subprogram unit. Function subprograms—Program units, also called functions, that contain a set of commonly used computations. A function subprogram’s first statement is a FUNCTION statement, optionally preceded by an OPTIONS statement A function subprogram is invoked by a function reference in a main program unit or a subprogram unit. Subroutine subprograms—Program units, also called subroutines, that contain a set of commonly used computations. A subroutine subprogram’s first statement is a SUBROUTINE statement, optionally preceded by an OPTIONS statement A subroutine subprogram receives control when it is invoked with a CALL statement and returns control with a RETURN statement. Subprograms — Subroutines and Functions 6-1 Subprograms supplied as part of the FORTRAN library are called intrinsic functions and include the following categories: 6.1 * Mathematical ®* Character-handling ® Lexical-comparison Subprogram Arguments Subprogram arguments are either dummy arguments or actual arquments: * Dummy arguments are specified when you write the subprogram. * Actual arguments are specified when you invoke the subprogram. When control is transferred to a subprogram, each dummy argument takes the value of the corresponding actual argument. When control is returned to the calling program unit, the last value assigned to a dummy argument is assigned to the corresponding actual argument. Section 6.1.1 describes the general techniques used to pass arguments between FORTRAN programs. Section 6.1.2 describes how to use built-in functions, supplied by VAX FORTRAN, to pass arguments between VAX FORTRAN subprograms and subprograms written in other languages. 6.1.1 Actual Argument and Dummy Argument Association Actual arguments must agree in order, number, and data type (or structure, for record arguments) with their corresponding dummy arguments. Actual arguments can be scalar references, array name references, aggre- gate references, alternate return specifiers, or subprogram names. The dummy arguments specified in subprogram definitions, representing corresponding actual arguments, appear as unsubscripted names. Although dummy arguments are not actual variables, arrays, records, or subprograms, each dummy argument can be declared as though it were a variable, array, record, or subprogram. ®* A dummy argument declared as an array can be associated only with an actual argument that is an array or array element of the same data type. The actual argument must not be placed in parentheses. I[f a dummy argument is an array, it must be no larger than the 6-2 Subprograms — Subroutines and Functions array that is the actual argument. You can use adjustable arrays (see Section 6.1.1.1) to process arrays of different sizes in a single subprogram. * A dummy argument declared as a record can be associated only with an actual argument that is an aggregate reference for an entity with a matching structure. * A dummy argument referenced as a subprogram must be associated with an actual argument that has been declared EXTERNAL or INTRINSIC in the calling routine. The length of a dummy argument with a data type of character must not be greater than the length of its associated actual argument. If the character dummy argument’s length is specified as *(*), it uses the length of the associated actual argument. (This is known as a passed-length character argument. See Section 6.1.1.3.) The following sections discuss several kinds of arguments: * Adjustable array * Assumed-size array * Passed-length character * Character and Hollerith constant Alternate return 6.1.1.1 Adjustable Arrays Adjustable arrays are dummy arguments in subprograms. The dimensions of an adjustable array are determined in the reference to the subprogram. The array declarator (see Section 2.2.3.1) for an adjustable array can contain integer variables that are either dummy arguments or variables in a common block. When the subprogram is entered, each dummy argument used in the array declarator must be associated with an actual argument, and each variable in a common block used in an array declarator must have a defined value. The dimension declarator is evaluated using the values of the actual arguments, variables in common blocks, and constants specified in the array declarator. Argument association is not retained between one reference to a subprogram and the next reference to that subprogram. The size of the adjustable array must be less than or equal to the size of the array that is its corresponding actual argument. Subprograms — Subroutines and Functions 6-3 Examples The following examples demonstrate valid and invalid adjustable arrays: Valid In the first example, the function computes the sum of the elements of a two-dimensional array. Notice how the dummy arguments M and N control the iteration. FUNCTION SUM(A,M,N) DIMENSION A(M,N) SUM = 0.0 DO 10 J=1,N DO 10 I=1,M 10 SUM = SUM + AT, D) RETURN END The following statements are sample calls on SUM: DIMENSION A1(10,35), A2(3,56) SUM1 = SUM(A1,10,35) SUM2 = SUM(A2,3,56) SUM3 = SUM(A1,10,10) An adjustable array is undefined if a dummy argument array is not currently associated with an actual argument array. It is also undefined if any of the variables in the adjustable array declarator are either not currently associated with an actual argument or not in a common block. The subroutine subprogram in the next example includes statements of a calling program unit. It illustrates how argument association is not retained between one reference to a subprogram and the next reference. SUBROUTINE S(A,I,X) DIMENSION A(I) A(D =X RETURN ENTRY S1(I,A,K,L) A(I) = AC(I) + 1.0 RETURN END The following program unit calls the subroutine subprogram from the previous example. This calling program unit defines B as a real array with 10 elements. The first call to subroutine S sets array element B(2) equal to the value 3.0. The second call to subroutine S (at entry point S1) increments array element B(5) by the value 1.0. RECORD statements not contained within structure declaration blocks can also declare adjustable arrays. 6-4 Subprograms — Subroutines and Functions DIMENSION B(10) CALL S(B,2,3.0) CALL S1(5,B,3,2) The upper- and lower-dimension bound values are determined once each time a subprogram is entered. These values do not change during the execution of that subprogram even if the values of variables contained in the array declaration are changed. In the next example, the adjustable array X is declared as X(—4:4,5) on entry to subroutine SUB. The assignments to I and ] do not affect that declaration. DIMENSION ARRAY(9,5) L=9 M=5 CALL SUB(ARRAY,L,M) END SUBROUTINE SUB(X,I,J) DIMENSION X(-I1/2:1/2,J) X(I/2,J) = 999 J=1 I=2 END Invalid The following example is invalid—once a variable is used in an array declarator for an adjustable array, it must not appear in a type declaration that changes the variable’s data type. SUBROUTINE SUB1(A,X) DIMENSION A(X) INTEGER X Subprograms — Subroutines and Functions 6-5 6.1.1.2 Assumed-Size Arrays An assumed-size array is a dummy array for which the upper bound of the last dimension is specified as an asterisk (*), for example: SUBROUTINE SUB(A,N) DIMENSION A(1:N,1:%) The size of an assumed-size array and the number of elements that can be referenced are determined as follows: e If the actual argument corresponding to the dummy array is a name of a noncharacter array, the size of the dummy array is the size of the actual-argument array. * [If the actual argument corresponding to the dummy argument is a name of a noncharacter array element, with a subscript value of s in an array of size a, the size of the dummy array isa + 1 — s. * If the actual argument is a name of a character array, character array element, or character array element substring and begins at character storage unit b of an array with n character storage units, the size of the dummy array is INT(n + 1 — b)/y, where y is the length of an element of the dummy array. Because the actual size of an assumed-size array is unknown, an assumedsize array name cannot be used as any of the following items in an I/O statement: * Array name in the I/0 list * Unit identifier for an internal file * Run-time format specifier RECORD statements not contained within structure declaration blocks can also declare adjustable arrays. 6-6 Subprograms — Subroutines and Functions 6.1.1.3 Passed-Length Character Arguments A passed-length character argument is a dummy argument that assumes the length attribute of the corresponding actual argument. An asterisk is used to specify the length of the dummy character argument. When control transfers to the subprogram, each dummy argument as- sumes the length of its corresponding actual argument. A character array dummy argument can also have a passed length. The length of each element in the dummy argument is the length of the elements in the actual argument. The passed length and the array declarator together determine the size of the passed-length character array. A passed-length character array can also be an adjustable or assumed-size array. Examples 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. (The processor-defined function LEN determines the length of the argument. See Section 6.3.2.1 for a description of the LEN function.) INTEGER FUNCTION ICMAX(CVAR) CHARACTER* (*) CVAR ICMAX = 10 1 DO 10 I=2,LEN(CVAR) IF (CVAR(I:I) .GT. CVAR(ICMAX:ICMAX)) ICMAX=I RETURN END 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. Each of the following function references specifies a different length for the dummy argument: CHARACTER VAR*10, CARRAY(3,5)%*20 I1 = ICMAX(VAR) I2 = ICMAX(CARRAY(2,2)) I3 = ICMAX(VAR(3:8)) I4 = ICMAX(CARRAY(1,3)(5:15)) I5 = ICMAX(VAR(3:4)//CARRAY(3,5)) Subprograms — Subroutines and Functions 6-7 6.1.1.4 Character and Hollerith Constants as Actual Arguments Actual 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 VAX FORTRAN, if an actual argument is a character constant (for example, 'ABCD), the corresponding dummy argument can have either a numeric or a character data type. If the dummy argument has a numeric data type, the character constant 'ABCD’ is, in effect, converted to a Hollerith constant by the FORTRAN compiler and the linker. 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 link time whether a character constant or Hollerith constantis required. In this case, a character constant actual argument can correspond only to a character dummy argument. Example The following example shows character and Hollerith constants being used as actual arguments. In this example, the subroutine names CHARSUB and HOLLSUB are themselves dummy arguments of the subroutine S. Therefore, the actual argument 'STRING' in the call to CHARSUB must correspond to a character dummy argument, whereas the actual argument 6HSTRING in the call to HOLLSUB must correspond to a Hollerith dummy argument SUBROUTINE S(CHARSUB,HOLLSUB,A,B) EXTERNAL CHARSUB, HOLLSUB CALL CHARSUB(A, 'STRING') CALL HOLLSUB(B, 6HSTRING) 6-8 Subprograms — Subroutines and Functions 6.1.1.5 Alternate Return Arguments To specify an alternate return argument in a dummy argument list, place asterisks in the list; for example: SUBROUTINE MINN(A,B,*,*,C) The actual argument list passed in the CALL statement must include alternate return arguments in the corresponding positions. These arguments take either one of the following forms: *label &label Either an asterisk or an ampersand can indicate an alternate return argument in an actual argument list. The value you specify for label must be the label of an executable statement in the program unit that issues the CALL statement. 6.1.2 Built-In Functions Built-in functions perform utility operations that are useful in communicating with subprograms written in languages other than FORTRAN. VAX FORTRAN provides the following built-in functions: 6.1.2.1 * Argument list e 9%LOC Argument List Built-In Functions To call subprograms (such as VAX/VMS system services) written in languages other than FORTRAN, you may need to pass the actual arguments in a form different from that used by FORTRAN. To change the form of the argument, you can use the following built-in functions in the argument list of a CALL statement or function reference: %VAL, %REF, %DESCR. These built-in functions specify the way the argument should be passed to the subprogram. You can use them only in the actual argument list of a CALL statement or function reference—and in no other context. Subprograms — Subroutines and Functions 6-9 The three argument list built-in functions have the following effects: Function Effect %VAL(a) Pass the argument as a 32-bit immediate value. (If the actual argument is shorter than 32 bits, it is sign-extended to a 32-bit value.) %REF(a) Pass the argument by reference. %DESCR(a) Pass the argument by descriptor. a is an actual argument. See the VAX FORTRAN User Manual for more information on argumentpassing mechanisms. Table 6-1 lists the FORTRAN argument-passing defaults and the allowed uses of %VAL, %REF, and %DESCR. Table 6—-1: Argument List Built-In Functions and Defaults Allowed Functions Actual Argument Data Type Default %VAL %REF %DESCR Logical REF Yes' Yes Yes Integer REF Yes' Yes Yes REAL*4 REF Yes Yes Yes REAL%*8 REF No Yes Yes REAL*16 REF No Yes Yes Complex REF No Yes Yes Character DESCR No Yes Yes Hollerith REF No No No Aggregate REF No Yes No REF No Yes Yes Expressions Array Name Numeric 'If a logical or integer value occupies less than 32 bits of storage, it is converted to a 32-bit value by sign extension. Use the ZEXT function if zero extension is desired. 6-10 Subprograms — Subroutines and Functions Table 6—-1 (Cont.): Argument List Built-In Functions and Defaults Allowed Functions Actual Argument Data Type Default Character DESCR Aggregate REF Numeric REF Character DESCR % VAL %REF %DESCR No Yes Yes No Yes No No Yes Yes No Yes Yes Procedure Name 6.1.2.2 %LOC Built-In Function The %LOC built-in function computes the internal address of a storage element. It takes the following form: %LOC (arg) arg Is a scalar memory reference, array name reference, aggregate reference, or external procedure name. The %LOC built-in function produces an INTEGER*4 value that repre- sents the location of its argument. The INTEGER*4 value can be used as an element in an arithmetic expression. See the VAX FORTRAN User Manual for more information on the %LOC built-in function. 6.2 User-Written Subprograms A user-written subprogram is a FORTRAN statement or group of FORTRAN statements that performs a computing procedure. The computing procedure can be either a series of arithmetic operations or a series of FORTRAN statements. A single subprogram can perform a computing procedure in several places in your program, and thus avoid duplicating a series of operations or statements in each place. Subprograms — Subroutines and Functions 6-11 There are three types of subprograms. Table 6-2 lists each type of subprogram, the statements needed to define the subprogram, and the method of transferring control to it. Types of User-Written Subprograms Control Transfer Method Defining Statements Subprogram Type Table 6—-2: Statement function Function Subroutine Statement function Function reference definition FUNCTION Function reference ENTRY SUBROUTINE CALL statement ENTRY A function reference is used in an expression and consists of the function name and the function arguments. A function reference returns a value that is used in evaluating the expression in which the function appears. Function and subroutine subprograms can change the values of their arguments, and the calling program can use the changed values. A subprogram can refer to other subprograms, but it cannot refer to itself, either directly or indirectly. 6.2.1 Statement Functions A statement function is a computing procedure defined in the same program unit in which it is referenced. It is defined by a single statement that is similar in form to an assignment statement. The computation is performed each time you refer to the statement function. The resulting value is then made available to the expression that contains the statement function reference. Statement function definitions take the following form: fun([pl,pl...1) = e fun Is the symbolic name of the statement function. p Is a dummy argument. 6-12 Subprograms — Subroutines and Functions e Is an arithmetic, logical, or character expression that defines the computa- tion to be preformed. Statement function references take the following form: f(lpl.pl..1) . f Is the symbolic name of the statement function. p Is an actual argument. Syntax Rules The following rules apply to statement function definitions and references: When a statement function reference appears in an expression, the values of the actual arguments are associated with the dummy ar- guments in the statement function definition. The expression in the definition is then evaluated. The resulting value is used to complete the evaluation of the expression containing the function reference. The data type of a statement function is determined either implicitly by the initial letter of the function name, or explicitly in a type declaration statement. The data type can be any of the data types, including the character data type. Dummy arguments in a statement function indicate only the number, order, and data type of the actual arguments. The names of the dummy arguments can represent other entities elsewhere in the program unit. Except for the data type, declarative information associated with an entity is not associated with dummy arguments in the statement function: declaring an entity to be an array or to be in a common block does not affect a dummy argument with the same name. Actual arguments must agree in number, order, and data type with their corresponding dummy arguments. Subprograms — Subroutines and Functions 6-13 e e The name of the statement function cannot represent any other entity within the same program unit. The expression in a statement function definition can contain function references. If a reference to another statement function appears in the expression, it must be previously defined in the same program unit. e e Any reference to a statement function must appear in the same program unit as the definition of that function. A statement function reference must appear as, or be part of, an expression. The reference cannot appear on the left side of an assignment statement. Examples The following statement function definitions are valid: VOLUME(RADIUS) = 4.189*RADIUS**3 SINH(X) = (EXP(X)-EXP(-X))*0.5 CHARACTER*10 CSF,A,B CSF(A,B) = A(6:10)//B(1:5) The following statement function definition is invalid because it contains a constant, which cannot be used as a dummy argument: AVG(A,B,C,3.) = (A+B+C)/3. Consider the following definition: AVG(A,B,C) = (A+B+C)/3. Based on the previous statement, the following references are valid: GRADE = AVG(TEST1,TEST2,XLAB) IF (AVG(P,D.Q) .LT. AVG(X,Y,Z)) GO TO 300 The following reference is invalid because the data type of the third argument does not agree with the dummy argument: FINAL = AVG(TEST3,TEST4,LAB2) 6-14 Subprograms — Subroutines and Functions 6.2.2 Function Subprograms A function subprogram is a program unit consisting of a FUNCTION statement followed by a series of statements that define a computing procedure. Function references transfer control to a function subprogram; RETURN or END statements return control to the calling program unit. A function subprogram returns a single value to the calling program unit by assigning that value to the function’s name. The function’s name determines the data type of the value returned. 6.2.2.1 Logical and Numeric Functions The FUNCTION statement takes the following form: [typ] FUNCTION nam[*m] [([p[.p]l...D)] typ Is one of the logical or numeric data type specifiers. See Section 4.4.1 for a list of these specifiers. nam Is the symbolic name of the function. m Is an unsigned, nonzero integer constant specifying the length of the data type. It must be one of the valid length specifiers for the data type given by typ. p Is a dummy argument. 6.2.2.2 Character Functions The CHARACTER FUNCTION statement takes the following form: CHARACTER [*n] FUNCTION nam{*n] ([([p[.pl...1)] Subprograms — Subroutines and Functions 6-15 n Is an unsigned, nonzero integer constant, or parenthetical asterisk indicat- ing a passed-length function name. If you specify CHARACTERx(*), the function assumes the length declared for it in the program unit that invokes it. A passed-length character function can have different lengths when it is invoked by different program units. If n is an integer constant, the value of n must agree with the length of the function specified in the program unit that invokes the function. If you do not specify n, a length of one is assumed. If the length has already been specified following the keyword CHARACTER, the optional length specification following nam is not permitted. nam Is the symbolic name of the function. p Is a dummy argument. 6.2.2.3 Function Reference A function reference that transfers control to a function subprogram takes the following form: nam([p[.p]...1) nam Is the symbolic name of the function. P Is an actual argument. When control transfers to a function subprogram, the values of any actual arguments in the function reference are associated with any dummy arguments in the FUNCTION statement. The statements in the subprogram are then executed. The resulting value is assigned to the name of the function. Finally, the function returns control to the calling program unit. The value assigned to the function’s name is now available to the expression containing the function reference and is used to complete the evaluation of that expression. 6-16 Subprograms — Subroutines and Functions The data type of a function name can be specified explicitly in the FUNCTION statement or in a type declaration statement; it can also be specified implicitly. The function name defined in the function subprogram must have the same data type as the function name in the calling program unit. The FUNCTION statement must be the first statement of a function subprogram, unless an OPTIONS statement is used. A function subprogram cannot contain a SUBROUTINE statement, a BLOCK DATA statement, a PROGRAM statement, or another FUNCTION statement. ENTRY statements can be included to provide multiple entry points to the subprogram (see Section 6.2.4). Examples Consider the following example: FUNCTION ROOT(A) X=1.0 2 EX = EXP(X) EMINX = 1./EX ROOT = IF ((EX+EMINX)*.5+C0S(X)-A)/((EX-EMINX)*.5-SIN(X)) (ABS(X-ROOT) .LT. 1E-6) RETURN X = ROOT GO TO 2 END To obtain the root of the function, the previous example uses the NewtonRaphson iteration method: F(X)=cosh(X)+cos(X)—A=0 The value of A is passed as an argument. The iteration formula for this root is as follows: Xz'+l = X; — cosh(X;) + cos(X;) — A sinh(X;) — sin(X;) This formula is calculated repeatedly until the difference between X; and X, is less than 1.0E-6. The function uses the FORTRAN intrinsic functions EXP, SIN, COS, and ABS (see Section 6.3). Subprograms — Subroutines and Functions 6-17 The next example is a passed-length character function. It returns the value of its argument, repeated to fill the length of the function. (*) FUNCTION REPEAT(CARG) CHARACTER* CHARACTER*1 CARG DO 10 I=1,LEN(REPEAT) REPEAT(I:I) = CARG 10 RETURN END Within any given program unit all references to a passed-length character function must have the same length. In the following example, the REPEAT function has a length of 1000: H CHARACTER*1000 REPEAT, MANYAS, MANYZS MANYAS = REPEAT('A') MANYZS = REPEAT('Z') Another program unit within the executable program can specify a different length. In the following example, the REPEAT function has a length of 2: CHARACTER HOLD*6, REPEAT*2 HOLD = REPEAT('A')//REPEAT('B')//REPEAT('C") 6.2.3 Subroutine Subprograms — SUBROUTINE Statement A subroutine subprogram is a program unit consisting of a SUBROUTINE statement followed by a series of statements that define a computing procedure. The CALL statement transfers control to a subroutine subprogram; a RETURN or END statement returns control to the calling program unit. SUBROUTINE statements take the following form: SUBROUTINE sub [([p[.pl...D)] sub Is the symbolic name of the subroutine. p Is a dummy argument. An asterisk in the argument list specifies a dummy argument as an alternate return argument. When control transfers to the subroutine, the values of any actual arguments in the CALL statement are associated with any corresponding dummy arguments in the SUBROUTINE statement. The statements in the subprogram are then executed. (Section 5.1 describes the CALL statement.) 6-18 Subprograms — Subroutines and Functions The SUBROUTINE statement must be the first statement of a subroutine, unless an OPTIONS statement is used. A subroutine subprogram cannot contain a FUNCTION statement, a BLOCK DATA statement, a PROGRAM statement, or another SUBROUTINE statement. ENTRY statements are allowed to specify multiple entry points in the subroutine (see Section 6.2.4). Examples The first example contains a subroutine that computes the volume of a regular polyhedron, given the number of faces and the length of one edge. It uses the computed GO TO statement to determine whether the polyhedron is a tetrahedron, cube, octahedron, dodecahedron, or icosahedron. The GO TO statement also transfers control to the proper procedure for calculating the volume. If the number of faces is not 4, 6, 8, 12, or 20, the subroutine sends an error message to the terminal. Main Program COMMON NFACES, ACCEPT *, EDGE, NFACES, VOLUME EDGE CALL PLYVOL TYPE *, 'VOLUME=', VOLUME STOP END AN Subprograms — Subroutines and Functions 6-19 Subroutine SUBROUTINE PLYVOL COMMON NFACES, EDGE, VOLUME CUBED = EDGE**3 ¢o 170 (6,6,6,1,6,2,6,3,6,6,6,4,6,6,6,6,6,6,6,5), NFACES GO TO 6 1 VOLUME = CUBED * 0.11785 2 VOLUME = CUBED 3 VOLUME = CUBED * 0.47140 RETURN RETURN RETURN 4 VOLUME = CUBED * 7.66312 5 VOLUME = CUBED * 2.18170 RETURN RETURN 6 100 TYPE 100, NFACES FORMAT (' NO REGULAR POLYHEDRON HAS ',I3,'FACES.'/) VOLUME = 0.0 RETURN END The next example uses alternate return specifiers to determine where control transfers on completion of the subroutine. The SUBROUTINE statement argument list contains two dummy alternate return arguments corresponding to the actual arguments *10 and *20 in the CALL statement argument list. The decision about which RETURN statement executes depends on the value of Z, as computed in the subroutine: o e If Z is less than zero, the normal return executes. If Zis equal to zero, the return is to statement label 10 in the main program. o If Z is greater than zero, the return is to statement label 20 in the main program. 6-20 Subprograms — Subroutines and Functions Main Program Subroutine CALL CHECK(A,B,*10,%20,C) TYPE *, SUBROUTINE CHECK(X,Y,*,*,Q) 'VALUE LESS THAN ZERO' GO TO 30 10 TYPE*, 'VALUE EQUALS ZERO' . GO TO 30 20 TYPE*, 50 'VALUE MORE THAN ZERO' IF (Z) 60,70,80 60 RETURN 30 CONTINUE 70 RETURN 1 80 RETURN 2 END 6.2.4 ENTRY Statement The ENTRY statement provides multiple entry points within a subpro- gram. It is not executable and can appear within a function or subroutine program after the FUNCTION or SUBROUTINE statement. Execution of a subprogram referred to by an entry name begins with the first executable statement after the ENTRY statement. The ENTRY statement takes the following form: ENTRY nam([([p[.p]...1)] nam Is the symbolic name of an entry point. P Is a dummy argument. Syntax Rules The following rules apply to ENTRY statements and names: * CALL statements should be used to refer to entry names within subroutine subprograms. * Function references should be used to refer to entry names within function subprograms. * An entry name within a function subprogram can appear in a type declaration statement. Subprograms — Subroutines and Functions 6-21 An EXTERNAL statement can specify an entry name and use it as an e actual argument—but not as a dummy argument. Entry names cannot appear in executable statements that physically e precede their appearance in an ENTRY statement. Alternate return arguments can be included in ENTRY statements if e they have asterisks in the dummy argument list. ENTRY statements that specify alternate return arguments can be used only in subroutine subprograms. Dummy arguments can be used in ENTRY statements even if they e differ in order, number, type, and name from the dummy arguments used in the FUNCTION, SUBROUTINE, and other ENTRY statements in the same subprogram. However, each reference to a function, subroutine, or entry must use an actual argument list that agrees in order, number, and type with the dummy argument list in the corresponding FUNCTION, SUBROUTINE, or ENTRY statement. e e 6.2.4.1 Dummy arguments can be referred to only in executable statements that follow the first SUBROUTINE, FUNCTION, or ENTRY statement in which the dummy argument is specified. If a dummy argument is not currently associated with an actual argument, the dummy argument is undefined and cannot be referenced—arguments do not retain their association from one reference of a subprogram to another. ENTRY statements cannot appear within a block IF construct or a DO loop. ENTRY Statements in Function Subprograms All entry names within a function subprogram are associated with the name of the function subprogram. Therefore, defining any entry name or the name of the function subprogram defines all the associated names with the same data type. All associated names with different data types become undefined. The function and entry names do not need to have the same data type, but they all must be consistent within one of the following groups of data types: 6-22 Group 1: BYTE, INTEGER#*2, INTEGER#*4, LOGICAL*2, LOGICAL+4, Group 2: COMPLEX*16, REAL*16 Group 3: CHARACTER REAL*4, REAL*8, COMPLEX*8 Subprograms — Subroutines and Functions When either a RETURN statement or an implied return at the end of a subprogram is executed, the symbolic name used to refer to the function subprogram must be defined. If the function has a character data type, all entry names must have a character data type and the same length specification as the function. The specified length must also agree with the length specified in the program unit referring to the entry name. If an asterisk enclosed in parentheses is used to specify the length of the entry name, the entry name has a passed length (see Section 6.1.1.3 and the VAX FORTRAN User Manual). Example The following example illustrates a function subprogram that computes the hyperbolic functions sinh, cosh, and tanh: REAL FUNCTION TANH(X) C Statement function to TSINH(Y) C = EXP(Y) twice sinh compute twice cosh - EXP(-Y) Statement function to TCOSH(Y) = EXP(Y) C compute + EXP(-Y) Compute tanh TANH = TSINH(X)/TCOSH(X) RETURN C Compute sinh ENTRY SINH(X) SINH = TSINH(X)/2.0 RETURN C Compute cosh ENTRY COSH(X) COSH = TCOSH(X)/2.0 RETURN END Subprograms — Subroutines and Functions 6-23 6.2.4.2 ENTRY Statements in Subroutine Subprograms To refer to an entry point name in a subroutine, you should issue a CALL statement that includes the entry point name defined in the ENTRY statement. In the following example, the call is to an entry point (SUBA) within the subroutine (SUB). Execution begins with the first statement following ENTRY SUBA (Q,R,S), using the actual arguments (A,B,C) passed in the CALL statement. Main Program Subroutine CALL SUBA(A,B,C) SUBROUTINE SUB(X,Y,Z) ENTRY SUBA(Q,R,S) Alternate returns can be specified in ENTRY statements, for example: SUBROUTINE SUB(K, *, *) ENTRY SUBC(J,K,*,*,X) RETURN 1 RETURN 2 END If you issue a call to entry point SUBC, you must include actual alternate return arguments, for example: CALL SUBC(M,N,*100,*200,P) In this case, the RETURN 1 statement transfers control to statement label 100 and the RETURN 2 statement transfers control to statement label 200 in the calling program. 6-24 Subprograms — Subroutines and Functions 6.3 FORTRAN Intrinsic Functions FORTRAN intrinsic functions perform frequently used mathematical computations. They are supplied in the VAX FORTRAN library. References to FORTRAN intrinsic functions use the same form as references to user-defined functions. For example, the following intrinsic function reference is valid: R = 3.14159 * ABS(X-1) This reference to the intrinsic function ABS causes the absolute value of X-1 to be multiplied by the constant 3.14159; the result of that calculation is assigned to the variable R. Two methods of referencing intrinsic functions are described in the following sections. A listing of the intrinsic functions, their data types, and the data type of their actual arguments is located in Appendix D. Further information describing intrinsic function algorithms is located in the VMS Run-Time Library Routines Volume. 6.3.1 Intrinsic Function References FORTRAN library function names are called intrinsic function names. Normally, a name in the table of intrinsic function names (Table D-3) refers to the FORTRAN library function with that name. However, the name can refer to a user-defined function when the name appears in an EXTERNAL statement (see Section 4.7). Except when they are used in an EXTERNAL statement, intrinsic function names are local to the program unit that refers to them. Thus, they can be used for other purposes in other program units. In addition, the data type of an intrinsic function does not change if you use an IMPLICIT statement to change the implied data type rules. Intrinsic and user-defined functions cannot have the same name if they appear in the same program unit. Subprograms — Subroutines and Functions 6-25 6.3.1.1 Generic References to Intrinsic Functions Many of the intrinsic functions supplied with VAX FORTRAN have generic names, which means that you refer to them by a common name and the selection of the actual library routine to be used is based on the data type of the argument in the function reference. For example, there are five intrinsic functions that calculate cosines. All of them can be referred to by the generic name COS. Their names are COS, DCOS, QCOS,CCOS, and CDCOS These functions differ in that they return REAL*4, REAL*S, REAL*16, COMPLEX*8, and COMPLEX*16values, respectively. To invoke the cosine function, you can refer to it generically as COS. The compiler then selects the appropriate routine, based on the arguments that you specify. For example, if the argument is REAL*4, COS is selected; if it is REAL*8, DCOS is selected; and if COMPLEX#*8, CCOS is selected. However, you can explicitly refer to a particular routine if you wish. Thus, to invoke the double-precision cosine function, you could specify DCOS rather than use the generic name. The compiler lists the internal names of the intrinsic functions it has selected in the “FUNCTIONS AND SUBROUTINES REFERENCED” section of the source code listing. Function selection occurs independently for each generic reference. Thus, you can use a generic reference repeatedly in the same program unit to access different intrinsic functions. Table 6-3 lists generic intrinsic function names. However, you cannot use the names in this table to generically select intrinsic functions if you use them in any of the following ways: e As the name of a statement function * As a dummy argument name, a common block name, or a variable or array name Using the generic name of an intrinsic function in an INTRINSIC statement (see Section 4.9) does not affect function references. However, when you use a generic function name in an actual argument list as the name of a function to be passed, function selection does not occur because there is no argument list on which to base a selection. The name is treated according to the rules for handling specific intrinsic function names described in Section 6.3. 6-26 Subprograms — Subroutines and Functions Generic function names are local to the program unit that refers to them. Thus, they can be used for other purposes in other program units. Table 6-3: Summary of Generic Intrinsic Function Names Data Type of Data Type of Generic Name Argument Result ABS Integer Real COMPLEX*8 Integer Real REAL*4 COMPLEX*16 REAL=*8 AINT, ANINT Real Real NINT Real Integer INT Integer Real Integer Integer Complex Integer Integer Real REAL*4 REAL*4 Complex REAL*4 Integer REAL#8 Integer REAL*16 Complex REAL*16 CMPLX Integer Real Complex COMPLEX=*8 COMPLEX+8 COMPLEX=*8 DCMPLX Integer COMPLEX=*16 MOD, MAX, MIN, SIGN, DIM Integer Real Integer Real EXP, LOG, SIN, COS, SQRT Real Real LOG10, SIND, COSD, TAN, Real Real REAL DBLE QEXT Real Complex Real Real Complex Complex REAL=*8 REAL=*8 REAL*16 COMPLEX=*16 COMPLEX=*16 Complex TAND. ATAN, ATAND, ATAN2, ATAN2D, ASIN, ASIND, ACOS, ACOSD, SINH, COSH, TANH Subprograms — Subroutines and Functions 6-27 6.3.1.2 Using Intrinsic Function Names Example 6-1 shows the different ways to use intrinsic function names. In this annotated example, a single executable program uses the name SIN in four distinct ways: As the name of a statement function As the generic name of an intrinsic function As the specific name of an intrinsic function As the name of a user-defined function Using the name in these four ways emphasizes the local and global properties of the name. Example 6-1: Using Multiple Function Names Compare ways of computing sine. PROGRAM SINES REAL*8 X, PI PARAMETER (PI=3.141592653589793238D0) COMMON V(3) Define SIN as a statement function " SIN(X) = COS(PI/2-X) DO 10 X = -PI, PI, 2*xPI/100 CALL COMPUT(X) Reference the statement function SIN €? 10 WRITE (6,100) X, V, SIN(X) 100 FORMAT (5F10.7) END SUBROUTINE COMPUT(Y) REAL*8 Y Use intrinsic function SIN as actual argument © INTRINSIC SIN COMMON V(3) Generic reference to double-precision sine (4 V(1) = SIN(Y) Example 6—-1 Cont’'d. on next page 6-28 Subprograms — Subroutines and Functions Example 6-1 (Cont.): Using Multiple Function Names INTRINSIC FUNCTION SINE AS ACTUAL ARGUMENT @ C CALL SUB(REAL(Y),SIN) END SUBROUTINE SUB(A,S) Declare SIN as name of user function @ EXTERNAL SIN Declare SIN as type REAL*S @ REAL*8 SIN COMMON V(3) Evaluate intrinsic function SIN (3 V(2) = S(A) Evaluate user-defined SIN function GD V(3) = SIN(A) END Define the user SIN function fl) REAL*8 FUNCTION SIN(X) INTEGER FACTOR SIN = X - X*x3/FACTOR(3) 1 + X**5/FACTOR(5) - X*x7/FACTOR(7) END INTEGER FUNCTION FACTOR(N) FACTOR = DO 10 10 1 I=N,1,-1 FACTOR = FACTOR * I END Notes: A statement function named SIN is defined in terms of the generic function name COS. Because the argument of COS is double precision, the double-precision cosine function is evaluated. The statement 0 function SIN is itself single precision. The statement function SIN is called. The name SIN is declared intrinsic so that the single-precision intrinsic sine function can be passed as an actual argument at ©. The generic function name SIN is used to refer to the double-precision sine function. Subprograms — Subroutines and Functions O The single-precision intrinsic sine function is used as an actual argu- 60000 ment. The name SIN is declared a user-defined function name. The type of SIN is declared double precision. The single-precision sine function passed at @ is evaluated. The user-defined SIN function is evaluated. The user-defined SIN function is defined as a simple Taylor series using a user-defined function FACTOR to compute the factorial function. Character and Lexical Comparison Library Functions 6.3.2 Character library functions take character arguments and return integer, ASCII, or character values; lexical comparison library functions take character arguments and return logical values. 6.3.2.1 Character Functions FORTRAN provides four character functions: LEN, INDEX, ICHAR, and CHAR. LEN Function The LEN function returns the length of a character expression. It takes the following form: LEN(c) c Is a character expression. The value returned indicates how many bytes there are in the expression. The following example uses the LEN function: SUBROUTINE REVERSE(S) CHARACTER T, S*(x) J = LEN(S) DO 10 I=1,J/2 T = S(I:1I) S(I:I) = 8(J:J) S(J:J) =T J=J-1 10 CONTINUE RETURN END 6-30 Subprograms — Subroutines and Functions INDEX Function The INDEX function searches for a substring (c2) in a specified character string (c1) and, if it finds the substring, returns the substring’s starting position. If ¢2 occurs more than once in cl, the starting position of the first (leftmost) occurrence is returned. If c2 does not occur in cl1, the value zero is returned. INDEX takes the following form: INDEX(c1,c2) c1 Is a character expression specifying the string to be searched for the substring specified by c2. c2 Is a character expression specifying the substring for which the starting location is to be determined. The following example uses the INDEX function: SUBROUTINE FIND_SUBSTRINGS(SUB,S) CHARACTER* (*) SUB, S CHARACTER*132 MARKS I=1 MARKS = 10 ' ! J = INDEX(S(I:), IF (J .NE. SUB) THEN 0) I =1+ (J-1) MARKS(I:I) = '#' I=1+1 IF (I END IF .LE. WRITE (6,91) 91 FORMAT S, LEN(S)) GO TO 10 MARKS (2(/1X,A)) END ICHAR Function The ICHAR function converts a character expression to its equivalent ASCII code and returns the ASCII value. It takes the following form: ICHAR (c) Subprograms — Subroutines and Functions 6-31 c Is the character to be converted to an ASCII code. If ¢ is longer than one byte, only the value of the first byte is returned; the remainder is ignored. CHAR Function The CHAR function converts an ASCII integer value to a character value and returns the character value. It takes the following form: CHAR (i) i Is an integer expression. 6.3.2.2 Lexical Comparison Functions FORTRAN provides four lexical comparison functions: e LLT, where LLT(X,Y) is equivalent to (X .LT. Y) e LLE, where LLE(X,Y) is equivalent to (X .LE. Y) e LGT, where LGT(X,Y) is equivalent to (X .GT. Y) e LGE, where LGE(X)Y) is equivalent to (X .GE. Y) Lexical functions take the following form: func(c,c) func Is one of the symbolic names: LLT, LLE, LGT, or LGE. c Is a character expression. The lexical 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 VAX systems, the lexical comparison functions are identical to the corresponding character relationals. 6-32 Subprograms — Subroutines and Functions Example The following example illustrates a valid lexical comparison function: CHARACTER*10 CH2 IF (LGT(CH2, 'SMITH')) STOP The IF statement in the example is equivalent to the following IF statement: IF (CH2 .GT. 'SMITH') STOP Subprograms — Subroutines and Functions 6-33 Chapter 7 1/0 Statements The following VAX FORTRAN I/0O (input/output) statements initiate data transfer operations: READ WRITE REWRITE ACCEPT TYPE and PRINT Following a discussion of the basic components of complete /0 state- ments, this chapter discusses individual I/O statements. For information on other statements that influence data transfer operations, but do not directly initiate them, see Chapters 8 and 9. 1.1 Components of 1/0 Statements I/O statements have three basic components: the statement keyword, the control list, and the 1/0 list. The I/O statement keywords specifically control either input or output operations, as follows: |/0 Statements 7-1 Input Operations Output Operations READ WRITE ACCEPT REWRITE TYPE PRINT The control list and 1/0 list are described separately in the next two sections. 7.1.1 Control List The control list is composed of one or more parameters that specify the following: e Logical unit to be acted upon Internal file to be acted upon Whether formatting is to be used for data editing, and if it is, the format specification NAMELIST group-name specification Number of a direct access record to be accessed e Key and key-of-reference of a keyed access record to be accessed Name of the variable that contains the completion status of an 1/0 operation Label of the statement that receives control if an error or end-of-file condition occurs The type of a statement can always be determined by the contents of its control list. For example, the control list of a formatted I/O statement always contains a format specifier (FMT=f or f), whereas that of a listdirected 1/O statement always contains an asterisk in place of a format specifier. 7-2 1/0 Statements The control list takes the following form: (pl.pl.. ) p Is a specifier taking the following form: [keyword =] value Is one of several possible keywords and values that are described in the following sections. 7.1.1.1 Syntax Rules for Control-List Parameters In VAX FORTRAN [/O statements, control-list parameters have three different forms (keyword, nonkeyword, and mixed) with the following syntax rules: e Keyword Form: When the control list parameter is specified with a keyword and equal sign, control-list parameters can appear in any order in the control list. e Nonkeyword Form: When the control-list parameter is specified without a keyword or equal sign, either the logical unit specifier or the internal file specifier must occupy the first (leftmost) position in the control list. The nonkeyword form of the direct-access record specifier must immediately follow the nonkeyword form of the logical unit specifier. When used with a logical unit specifier or internal file specifier, the nonkeyword form of the formator namelist specifier must occupy the second position in the control list. The unit or internal file specifier must also be in nonkeyword form (and thus occupy the first position in the control list). e 7.1.1.2 Mixed Forms: When keyword and nonkeyword forms are mixed in the same 1/0 statement, nonkeyword rules apply to the control list. Logical Unit Specifier The logical unit specifier identifies the logical unit to be accessed. It takes either one of the following forms: [UNIT=]u [UNIT=] * l/0 Statements 7-3 u Is an integer expression with a value in the range 0 through 99 that refers to a specific file or I/O device. If necessary, the value is converted to integer data type before use. * Specifies that the default input or output unit is to be accessed. The keyword UNIT is optional only if the logical unit specifier is the first parameter in the control list. A logical unit number is assigned to a file or device in one of two ways: 7.1.1.3 * Explicitly through an OPEN statement (see Section 9.1) * Implicitly by the system (see the VAX FORTRAN User Manual for more information on implicit logical assignments). Internal File Specifier | The internal file specifier identifies the internal file to be used. It takes the following form: [UNIT=]cv cv Is a character scalar memory reference or a character array name reference. The external logical unit specifier and the internal file specifier are mutually exclusive. The keyword UNIT is optional if the internal file specifier is the first parameter in the control list. See the VAX FORTRAN User Manual for more information on internal files. 7.1.1.4 Format Specifiers The format specifier stipulates either explicit or list-directed formatting. In the case of explicit formatting, it also identifies the parameter that controls formatting. The format specifier takes either one of the following forms: [FMT=]f [FMT=]* 7-4 1/0 Statements f Is the statement label of a FORMAT statement; an integer variable that has been assigned a FORMAT statement label with an ASSIGN statement; the name of an array or array element containing a run-time format; or a character expression containing a run-time format. * Specifies list-directed formatting. The keyword FMT is optional only if the format specifier is the second parameter in the control list, and the first parameter is a logical unit or internal file specifier without the optional keyword UNIT. Chapter 8 describes FORMAT statements. Section 8.8 describes the interaction between formats and 1/0 statements. In sequential I/O statements, you can use an asterisk instead of a format specifier to denote list-directed formatting (see Sections 7.2.1.2 and 7.3.1.2). 7.1.1.5 Namelist Specifier The namelist specifier stipulates namelist-directed 1/0. It identifies the group-name of the list of entities that may be modified on input or written on output. The namelist specifier takes the following form: [NML=] group-name group-name Is the name of a list previously defined in a NAMELIST statement. The keyword NML is optional only if the following conditions are true: * The first parameter is a logical unit specifier without an optional UNIT keyword. * The namelist specifier is the second parameter in the control list. A namelist specifier cannot be used in a statement that contains a format specifier. |/0 Statements 7-5b 7.1.1.6 Record Specifier The record specifier identifies the number of the record you wish to access in a file with relative organization. It takes either one of the following forms: REC = r 'r r Is a numeric expression with a value that represents the position in a direct access file of the record to be accessed. The value must be greater than or equal to one, and less than or equal to the maximum number of records allowed in the file. If necessary, a record number is converted to integer data type before being used. 7.1.1.7 Key-Field-Value Specifier The key-field-value specifier identifies the key field of a record that you wish to access in an indexed file. The key-field value is equal to the contents of a key field. The key field contains such information as the number, direction, length, byte offset, and type of the fields. It can be used to access records in indexed files because it determines their location. The attributes of the key field are specified at file creation. Records in an indexed file have the same attributes for their key fields. Key-field-value specifiers have two components: * An expression (val) that specifies a value used to compare with key-field values. * A selection condition keyword (such as KEY) that specifies how to compare val with key-field values. They take the following forms: Ascending Keys KEY = val KEYEQ = val KEYNXT = val KEYNXTNE = val KEYGT = val KEYGE = val 7-6 I/0 Statements Descending Keys KEY = val KEYEQ = val KEYNXT = val KEYNXTNE = val KEYLT = val KEYLE = val val Is an integer or character expression. Integer expressions must compare with integer key fields; they cannot contain real or complex values. Character expressions must compare with character key fields; they must be ASCII strings made up of either characters or BYTE (LOGICAL*1) array names containing Hollerith data. The Selection Condition The selection condition determines how val is compared with key-field values. The keyword can be any one of the following specifiers: Ascending Keys * KEY and KEYEQ-—the value in the key field must be equal to val. * KEYNXT—the value in the key field must be the next value of the key equal to or greater than val. * KEYNXTNE-—the value in the key field must be the next value of the key strictly greater than val. e KEYGT—the value in the key field must be greater than val. * KEYGE—the value in the key field must be greater than or equal to val. Descending Keys e KEY and KEYEQ-—the value in the key field must be equal to val. * KEYNXT—the value in the key field must be the next value of the key e KEYNXTNE—the value in the key field must be the next value of the equal to or less than val. key that is strictly less than val. e KEYLT—the value in the key field must be less than val. * KEYLE—the value in the key field must be less than or equal to val. |/0 Statements 7-7 Keyword specifiers are interchangeable between ascending-key files and descending-key files—except KEYGT, KEYGE, KEYLT, and KEYLE. These four keywords are one-directional. If you use them with keys going in the opposite direction, the Run-Time Library (RTL) displays an error at run time, KEYNXT and KEYNXTNE are interchangeable between ascending-key files and descending-key files. Unlike KEY and KEYEQ, they are interpreted differently depending on the direction of the keys in the file. In ascendingkey files, KEYNXT is the same as KEYGE, and KEYNXTNE is the same as KEYGT. In descending-key files, KEYNXT is the same as KEYLE, and KEYNXTNE is the same as KEYLT. You should use KEYGT and KEYGE when exclusively accessing ascending keys and, similarly, KEYLT and KEYLE when exclusively accessing descending keys. When a program must be able to use either kind, you should use KEYNXT and KEYNXTNE. The Selection Process To select key-field integer values, the process compares values using the signed integers themselves. | To select key-field character values, the process compares values using the ASCII collating sequence. Additionally, the comparative length of val and a key-field value, and the specified selection condition determine the kind of selection that occurs: exact, generic, or approximate-generic. Exact selections occur when the expression in val is equal in length to the expression in the key field of the currently accessed record and the keyword specifies a unique selection. Generic selections occur when the expression in val is shorter than the expression in the key field of the currently accessed record and the keyword specifies a unique selection. The process compares all the characters in val, from left to right, with the same amount of characters in the key field, also from left to right. Remaining key-field characters are ignored. For example, if val is "ABCD’ and a record’s key-field is 10 characters long, and you specified an equal selection, the process could select a record with a key-field value '"ABCDEFGHIJ'. An approximate-generic selection occurs when val is shorter than the expression in the key field and the keyword (KEYGT, KEYGE, KEYLT, KEYLE, KEYNXT, and KEYNXTNE) does not specify a unique selection. As with generic selections, the process uses only the leftmost characters in 1-8 |/0 Statements the key-field to compare values. It selects the first key field that satisfies the generic selection criterion. For example, if val is "ABCD’ and a record’s key-field value is 5 characters long and you specify a greater-than selection, the process could select the key-field value '"ABCEx’ (and not the key-field value '"ABCDA"). No selection occurs if val is longer than the key-field value. The RTL displays an error message. 7.1.1.8 Key-of-Reference Specifier The key-of-reference specifier may optionally accompany the key-fieldvalue specifier; it designates the key-field index that is searched to find the specified key-field value. Key-of-reference specifiers take the following form: KEYID=kn kn Is an integer expression, called the key-of-reference number, that 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/0O statement for that logical unit. 7.1.1.9 1/0 Status Specifier The I/0O status specifier designates a variable in which is a stored value that indicates whether an error or end-of-file condition exists: If the value is zero, no error or end-of-file condition exists. * If the value is positive, an error condition exists. * If the value is negative, an end-of-file condition exists but an error condition does not. The I/O status specifier takes the following form: IOSTAT=1io0s I/0 Statements 7-9 ios Is an integer scalar memory reference. See the VAX FORTRAN User Manual for more information on the error numbers returned by IOSTAT. 7.1.1.10 Transfer-of-Control Specifiers The transfer-of-control specifier identifies an executable statement and transfers control to that statement if an end-of-file or error condition occurs. It takes either one of the following forms: END=s ERR=s S Is the label of the executable statement that receives control. A sequential READ statement can include either or both of the previous specifications, in any order. WRITE,REWRITE, direct access READ,and keyed access READ statements can include only the ERR=s specification. The statement label in the END=s or ERR=s specification must refer to an executable statement within the same program unit as that of the /O statement. An end-of-file condition occurs when no more records exist in a file during a sequential read, or when an end-of-file record produced by the ENDFILE statement is encountered (see Section 9.6). End-of-file conditions do not occur in direct accessOr keyed access READ statements. If a READ statement encounters an end-of-file condition during an I/O operation, it transfers control to the statement designated by the END=s specification. If there is no END=s specification, control transfers to the statement designated by the ERR=s specification. If there is neither specification (nor an IOSTAT specifier), the program terminates. If a READ, WRITE,Or REWRITE gtatement encounters an error condition during an 1/O operation, it transfers control to the statement whose label appears in the ERR=s specification. If neither an ERR specifier nor an IOSTAT specifier is present, the I/O error terminates program execution. See the VAX FORTRAN User Manual for a description of system subroutines that you can use to control error processing. To obtain information from the I/0 system on the type of error that occurred, use the IOSTAT parameter discussed in Section 7.1.1.9. 7-10 |/0 Statements Examples The following READ statement transfers control to statement 550 if an end-of-file condition occurs on logical unit 8. READ (8,END=550) (MATRIX(K),K=1,100) The following WRITE statement transfers control to statement 390 if an error occurs while it is being executed. WRITE (6,50,ERR=390) VAR1, VAR2, VAR3 The following READ statement transfers control to statement 150 (if an error occurs while it is being executed) or to statement 200 (if an end-of-file condition occurs). READ 7.1.2 (1,FORM,ERR=150,END=200) ARRAY 1/0 List The I/0O list in an input or output statement contains the scalar references, array name references, and a gregate referencesspecifying the memory locations from which or to which data will be transferred. (See Section 2.2.6 for a description of the different types of references.) The I/O list in an input statement cannot contain constants and expressions because these do not specify named memory locations that can be referenced later in the program. The I/O list in an output statement can contain constants and expressions, however, because the compiler can use temporary memory locations to hold these values during the execution of the I/0 statement. An 1/0 list takes the following form: s(,s]... s Is a simple list element or an implied-DO list. The I/0 statement assigns values to (or transfers values from) the list elements in the order in which they appear, from left to right. I/0 Statements 7-11 7.1.21 Simple List Elements A simple 1/0 list element can be a scalar reference, scalar array name reference, or aggregate reference; for example: WRITE (5,10) J, K(3), 4, (L+4)/2, N When you use an array name reference or an aggregate reference in an I/0 list, an input statement reads enough data to fill every element of the array or aggregate. An output statement writes all of the values in the array or aggregate. 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; for example, the following statement 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(1,1), ARRAY(2,1), ARRAY(3,1), ARRAY(1,2), and so on through ARRAY(3,3). In an input statement, variables in the 1/ O list can be used in array subscripts later in the list; for example: READ (1,1250) J, X, ARRAY(J,.K) 1250 FORMAT (I1,1X,I1,1X,F6.2) 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. An output statement 1/0 list may contain any valid expression. However, this expression must not attempt any further I/O operations on the same logical unit. For example, an output statement /O list expression must not refer to a function subprogram that performs I/O on the same logical unit. An input statement I/O list must not contain a constant or an expression, except as a subscript expression in an array reference or as an expression in a substring reference. 7-12 1/0 Statements Aggregate references can be used only in unformatted input and output statements. When multiple array names in the I/0 or aggregate referencesare used list of an unformatted input or output statement, only one record is read or written regardless of how many array name references aggregate referencesappear in the list. 7.1.2.2 or Implied-DO Lists in 1/0 Statements An implied-DO list is an I/0 list element that acts as though it were a part of an 1/0O statement within a DO loop. Implied-DO lists can achieve the following: * Specify iteration of part of an 1/0 list * Transfer part of an array * Transfer array elements in a sequence different from the order of subscript progression An implied-DO list takes the following form: (list, i=el,e2[,e3]) list Is an I/0 list. i Is an integer or real variable. el,e2,e3 Are arithmetic expressions. 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 5.3). The list immediately preceding the DO loop parameter is the range of the implied-DO loop. Elements in that list can reference i, but they must not alter the value of i. Examples The following examples demonstrate valid implied-DO lists. * The following two WRITE statements have the same effect: WRITE (3,200) (A,B,C, I=1,3) I/0 Statements 7-13 In the next example, the I/O list consists of an implied-DO list e containing another implied-DO list nested within it: WRITE (6) (I, (J,P(I),Q(I,J), J=1,L), I=1,M) Together, the implied-DO lists write a total of (1+3*L)*M fields, varying the Js for each value of I. In a series of nested implied-DO lists, parentheses indicate the nesting (see Section 5.3.1.2). Execution of the innermost lists is repeated most e often: WRITE (6,150) ((FORM(X,L), L=1,10), K=1,10,2) 150 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; thus, only the odd-numbered rows of the array are output. e The entire list of an implied-DO list is transmitted before the control variable is incremented: READ (5,999) (P(I), (Q(I,J), J=1,10), I=1,5) In this example, P(1), Q(1,1), Q(1,2) ...,Q(1,10) are read before I is incremented to 2. e When processing multidimensional arrays, you can use a combination of fixed subscripts and subscripts that vary according to an implied-DO list: READ (3,5555) (BOX(1,J), J=1,10) e This statement assigns input values to BOX(1,1) through BOX(1,10) and then terminates without affecting other elements of the array. The value of the control variable can also be output directly: WRITE (6,1111) (I, I=1,20) This statement prints the integers 1 through 20. If the I/O statement containing an implied-DO list terminates abnormally (with an END= or ERR= transfer or with an IOSTAT value other than zero), the loop control variable becomes undefined. 7-14 |/0 Statements 7.2 READ Statements The READ statement transfers input data to internal storage from records contained in external logical units or to internal storage from internal files. VAX FORTRAN provides the following kinds of READ statements: 7.2.1 * Sequential ®* Direct ® Internal * Indexed Sequential READ Statements Sequential READ statements transfer input data to internal storage from external records that were sequentially accessed. They can be formatted, list-directed, namelist-directed, or unformatted, taking one of the following forms: Formatted READ (extu,fmt[,iostat][,err][,end]) [iolist] READ f[,iolist] List-Directed READ (extu,*[,iostat][,err][,end]) [iolist] READ =*[,iolist] Namelist-Directed READ (extu,nml[,iostat][,err][,end]) READ n Unformatted READ (extul,iostat][,err][,end]) [iolist] Control-list parameters are symbolized as follows: extu—a logical unit specifier fmt—a format specifier I/0 Statements 7-15 f—the nonkeyword form of a format specifier +—a list-directed format specifier (You can also use FMT=*.) nml—a namelist specifier n—the nonkeyword form of a namelist specifier iostat—an I/O status specifier err, end—transfer-of-control specifiers The I/O-list parameter is symbolized as follows: iolist—the 1/0 list specifier The parameters in 1/O statements are fully described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). Their syntax rules are summarized in Section 7.1.1.1. 7.2.11 Formatted Sequential READ Statement The formatted sequential READ statement performs the following operations: e Reads character data from one or more external records accessed under e Translates the data from character to binary form using format specifi- » Assigns the translated data to the elements in the I/O list, in the order, from left to right, in which those elements appear in the list. the sequential or keyedmode of access. cations to provide editing. If the number of 1/0 list elements in a statement is less than the number of fields in an input record, the statement ignores the excess fields. See Section 7.2.3 for information about the combined use of formatted sequential READ statements and indexed READ statements under the keyed mode of access 7-16 |/0 Statements 7.2.1.2 List-Directed Sequential READ Statement The list-directed sequential READ statement performs the following operations: Reads character data from records accessed under the sequential mode of access. Translates data from external to binary form using the data types of the elements in the I/O list, and the forms of the data, to provide editing. Assigns the translated data to the elements in the [ /O list in the order, from left to right, in which those elements appear in the list. The external records from which list-directed READ statements read data contain a sequence of values and value separators. A value in one of these records may be any one of the following: A constant: Each constant has the form of the corresponding FORTRAN constant. Input constants can be any of the following data types: integer, real, logical, complex, and character. The data type of the constant determines the data type of the value and the translation from external to internal form. A numeric list element can correspond only to a numeric constant, and a character list element can correspond only to a character constant. If the data types of a numeric list element and its corresponding numeric constant do not match, conversion is performed according to the rules for arithmetic assignment (see Table 3-1). A complex constant has the form of a pair of real or integer constants separated by a comma and enclosed in parentheses. Spaces can occur between the opening parenthesis and the first constant, before and after the separating comma, and between the second constant and the closing parenthesis. A logical constant represents true or false values: .TRUE. or any value beginning with T, .T, t, or .t; or .FALSE. or any value beginning with F, .F, {, or f. A character constant must be delimited by apostrophes. An apostrophe occurring within a character constant is represented by two consecutive apostrophes. Hollerith, octal, and hexadecimal constants are not permitted. |/0 Statements 7-17 e A null value: A null value is specified by two consecutive commas with no intervening constant or by an initial comma or trailing comma. Spaces can occur before or after the commas. A null value indicates that the corresponding list element remains unchanged. A null value can represent an entire complex constant, but cannot be used for either part of a complex constant. e A repetition of constants in the form r+*c: The form r*c indicates r occurrences of ¢, where r is a nonzero, unsigned integer constant and c is a constant. Spaces are not permitted except within the constant c as previously specified. e A repetition of null values in the form r*. The form r* indicates r occurrences of a null value, where r is an unsigned integer constant. A record can use any one of the following entities as a value separator, with or without surrounding spaces of tabs: e Space or tab ¢ (Comma e Slash The slash terminates processing of the input statement and the record, leaving all remaining I/O list elements unchanged. When any of the preceding entities appear in a character constant, they are considered part of the constant, not value separators. The end of a record is equivalent to a space character 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 last character in the previous record is immediately followed by the first character of the next record). Spaces at the beginning of a record are ignored unless they are part of a character constant continued from the previous record. In this case, the spaces at the beginning of the record are considered part of the constant. Each input statement reads one or more records as required to satisfy the /0 list. If a slash separator occurs or the I/O list is exhausted before all of the values in a record are used, the remainder of the record is ignored. 7-18 |/0 Statements Example Consider a program unit with the following statements: CHARACTER*14 C DOUBLE PRECISION T COMPLEX D,E LOGICAL L,M And the external record that will be read: 46.3(3.4,4.2), (3, 2) , T,F,,3%14.6 ,'ABC,DEF/GHI''JK'/ Upon execution of the program unit, the following values are assigned to the I/0 list elements: — 6.3 (3.0,2.0) (3.4,4.2) .TRUE. 14 14.6 N R .FALSE. =34 v ZC 4 = Value Mg I/0O List Element 14.6D0 ABC,DEF/GHI'JK A, B, and ] are unchanged. I/0 Statements 7-19 7.2.1.3 Namelist-Directed Sequential READ Statement The namelist-directed sequential READ statement performs the following operations: e Reads data from external records accessed under the sequential mode e Translates the data from external to internal form using the data types of the entities in the corresponding NAMELIST statement, and the of access until it finds the specified group-name. forms of the data, to provide editing. Assigns the translated data to the specified namelist entities in the order in which the entities appear in the input records. * The input for a namelist-directed READ consists of a record or records delimited by the special symbol dollar sign ($), which starts in the second column of the first record. Namelist input takes the following form: column 2 Y $group-name entity = value [,entity = value ,...] $[END] $ Is the special symbol used to indicate the beginning or end of input. The ampersand (&) can be used in place of the dollar sign. group-name Is the name of the namelist that contains the entity or entities to be given values. The namelist must have been previously defined in a NAMELIST statement in the program unit. entity Is a namelist-defined entity. The entity can be a variable, array name, subscripted variable, variable with a substring, or subscripted variable with a substring. value Is a constant, a list of constants, a repetition of constants in the form r*c, or a repetition of values in the form r* (see Section 7.2.1.2). END Is an optional part of the last delimiter. 1-20 1/0 Statements Information on syntax rules for namelist input, prompting for current values, and assigning values is presented separately under the headings that follow. Syntax Rules The following syntax rules apply to namelist input: The group-name cannot contain spaces or tabs and must be contained within a single record. The entities appearing on the left side of the equal sign in a value as- signment cannot contain spaces or tabs except within the parentheses of a subscript or substring specifier. Each entity must be contained in a single record. Each constant that appears in a value assignment has the form of the corresponding FORTRAN constant. A complex constant has the form of a pair of real or integer constants separated by a comma and enclosed in parentheses. Spaces can occur between the opening parenthesis and the first constant, before and after the separating comma, and between the second constant and the closing parenthesis. A logical constant represents true or false values: .TRUE. or any value beginning with T, .T, t, or .t; or .FALSE. or any value beginning with F, .F, 1, or .f. A character constant is delimited by apostrophes. An apostrophe occurring within a character constant is represented by two consecutive apostrophes. Hollerith, octal, and hexadecimal constants are not permitted. The valid separators in a list of constants are spaces, tabs, and com- mas. Except within a character constant, any number of consecutive spaces and tabs is equivalent to a single space. A null value is specified by two consecutive commas, by an initial comma, or by a trailing comma. A separating comma preceded or followed by spaces is equiv- alent to a single comma. A null value indicates that the corresponding namelist array element is unchanged. A null value can represent an entire complex constant, but it cannot be used for either part of a complex constant. The form r*c indicates r occurrences of ¢, where r is a nonzero, un- signed integer constant and c is a constant. Spaces are not permitted except within the constant ¢ in complex or character constants. The form r* indicates r occurrences of a null value, where r is an unsigned integer constant. I/0 Statements 7-21 e e o The valid separators in a list of value assignments are spaces, tabs, and commas. Any number of consecutive spaces and tabs is equivalent to a single space. A separating comma preceded or followed by spaces is equivalent to a single comma. Consecutive commas are not permitted. The equal sign in a value assignment can be preceded and followed by any number of spaces or tabs. The end of a record in namelist input is equivalent to a space character except when the end of the record occurs in a character constant. If this occurs, the end of the record is ignored, and the character constant is continued with the next record; that is, the last character in the previous record is followed immediately by the second character of the next record. The first character is used for carriage control. Prompting for Current Values If your program is executing a namelist READ statement, you may prompt it for the group name and namelist entities that it will accept. To do this, enter a question mark (?) record character. If you precede the question mark with an equal sign (=?), the group name and current values of the namelist entities for that group are displayed as in namelist output (see Section 7.3.1.3). Assigning Values Input values can be assigned in any order using an assignment of the form: entity=value. Each new line of input can begin in column 2 or in any column thereafter. Column 1 of each record is assumed to contain a FORTRAN carriage-control character. Any data placed in that column is ignored. Assigned values, array subscripts, and substring specifiers must be constant values. Symbolic (PARAMETER) constants are not permitted. Input values can be any of the following data types: integer, real, logical, complex, and character. If the data type of a namelist entity and its assigned constant value do not match, conversion is performed according to the rules for arithmetic assignment (see Table 3-1). Conversion between numeric and character data types is not permitted. 1-22 I/0 Statements Examples In the first example, the NAMELIST statement associates the group-name CONTROL with a list of five entities. The corresponding READ statement reads input data and assigns values to specified namelist entities. NAMELIST /CONTROL/ TITLE, RESET, START, STOP, INTERVAL CHARACTER*10 TITLE REAL*8 START, STOP LOGICAL*4 RESET INTEGER*4 READ INTERVAL (UNIT=1,NML=CONTROL) In the next example, values are assigned to all of the namelist entities previously associated with the group-name CONTROL. column 2 ¥CONTRDL TAB| TITLE='TESTTOO2AA" , [TAB| INTERVAL=1, ERsN ., B] RESET=.TRUE B] START=10.2, ] B] STOP =14.5 Upon program execution, values are assigned to list entities as follows: Entity Value TITLE TESTTO02AA RESET T START 10.2 STOP 14.5 INTERVAL 1 It is not necessary to assign values to all of the list entities defined in the corresponding NAMELIST group-name. The namelist-directed READ statement does not change the values of namelist entities that do not appear in the input data. Similarly, when character substrings and array elements are specified, only the values of the specified variable substrings and array elements are changed. For example, if the next input to the character variable TITLE used in the last example contains the following statement: I/0 Statements 7-23 column 2 v $CONTROL TITLE(9:10)='BB' $END Its new value is TESTT002BB; the first eight positions of the variable do not change. When a list of values is assigned to an array name, the first value in that list is assigned to the first element of the array, the second value is assigned to the second element of the array, and so on. The number of array elements assigned must be less than or equal to the size of the array. Consecutive commas within a list indicate that the values of the array elements remain unchanged. Consider the following example: A program unit contains the following statements: DIMENSION ARRAY(20) NAMELIST /ELEM/ ARRAY READ (UNIT=1,NML=ELEM) The input contains the following;: column 2 v $ELEM ARRAY=1.1, 1.2, , 1.4%END Upon program execution, the READ statement assigns values to array elements as follows: Array Element Value ARRAY(1) 1.1 ARRAY(2) 1.2 ARRAY(3) unchanged ARRAY(4) 1.4 ARRAY(5)—ARRAY(20) unchanged When a list of values is assigned to an array element, the assignment begins with the specified array element, rather than with the first element of the array. In this example, if the next input to ARRAY consists of the following: column 2 | $ELEM ARRAY (3)=34.54, 45.34, 87.63, 3%20.00 $END 1-24 |/0 Statements Upon program execution, the READ statement assigns new values only to ARRAY elements 3 through 8. It does not alter unspecified elements. 7.2.1.4 Unformatted Sequential READ Statement The unformatted sequential READ statement reads an external record accessed under the sequential or keyed mode of access; it assigns the fields of binary data contained in that record to the elements in the 1/O list, in the order, from left to right, in which those elements appear in the list. The data is not translated and the amount of data assigned to each element is determined by the element’s data type. The unformatted sequential READ statement reads exactly one record. If the 1/0 list does not use all of the values in a record, the remainder of the record is discarded; this happens when there are more values in the record than elements in the list. If the number of list elements is greater than the number of values in the record, an error occurs. If a statement contains no 1/0 list, it skips over one full record, positioning the file to read the following record on the next execution of a READ statement. Examples In the first example, the READ statement reads one record from the file connected to logical unit 1 and assigns values of binary data to variables FIELD1 and FIELD2, in that order. READ (UNIT=1) FIELD1, FIELD2 In the second example, the READ statement advances the file connected to logical unit 8 by one record. READ (8) |/0 Statements 7-25 7.2.2 Direct Access READ Statements Direct access READ statements transfer input data to internal storage from external records accessed under the direct mode of access. They can be formatted or unformatted, taking one of the following forms: Formatted READ (extu,rec,fmt[,iostat][,err]) [iolist] Unformatted READ (extu,rec[,iostat][,err]) [iolist] Control-list parameters are symbolized as follows: extu—a logical unit specifier rec—a record specifier fmt—a format specifier iostat—an 1/0 status specifier err—a transfer-of-control specifier The 1/O-list parameter is symbolized as follows: iolist—the 1/0O-list specifier The parameters in I/O statements are fully described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter) and their controllist syntax rules are summarized in Section 7.1.1.1. 7.2.2.1 Formatted Direct Access READ Statement The formatted direct access READ statement performs the following operations: e Reads character data from one or more external records accessed under the direct mode of access. e Translates the data from character to binary form using format specifications to provide editing. * 71-26 |/0 Statements Assigns the translated data to the elements in the I/O list in the left-to-right order in which the elements appear. If the I/O list and formatting do not use all of the characters in a record, the remainder of the record is discarded. If the I/O list and formatting require more characters than are contained in the record, the remaining fields are read as spaces. Example In the following example, the READ and FORMAT statements read the first 10 fields from record 35 in the file connected to logical unit 2, translate the values to binary form, and then assign the translated values to the internal storage locations of the 10 elements of the array NUM. READ 10 7.2.2.2 (2,REC=35,FMT=10) FORMAT (NUM(K), K=1,10) (1012) Unformatted Direct Access READ Statement The unformatted direct access READ statement reads an external record accessed under the direct mode of access; it assigns the fields of binary data contained in that record to the elements in the I /0O list, in the order, from left to right, in which those elements appear in the list. The data is not translated. The amount of data assigned to each element is determined by that element’s data type. The unformatted direct access READ statement reads exactly one record. If that record contains more fields than there are elements in the 1/0 list of the statement, the unused fields are discarded; if there are more elements than fields, an error occurs. Examples In the first example, the READ statement reads record 10 in the file connected to logical unit 1 and assigns binary integer values to elements 1 and 8 of the array LIST. READ (1'10) LIST(1), LIST(8) In the second example, the READ statement reads record 58 in the file connected to logical unit 4 and assigns binary values to five elements of the array RHO. READ (4,REC=58,I0STAT=K,ERR=500) (RHO(N), N=1,5) I/0 Statements 7-27 1.2.3 Indexed READ Statements Indexed READ statements transfer input data to internal storage from external records using keyed access. In an indexed file, a series of records can be read in key value sequence by using an indexed READ statement together with a sequential READ statement. The first record in the sequence is read using the indexed statement and the rest are read using sequential READ statements. Indexed READ statements can be formatted or unformatted, taking one of the following forms: Formatted READ (extu,fmt,key[,keyid]l[,iostat][,err]) [iolist] Unformatted READ (extu,keyl[,keyid] [,iostat][,err]) [iolist] Control-list parameters are symbolized as follows: extu—a logical unit specifier fmt—a format specifier key—a key specifier keyid—a key-of-reference specifier iostat—an 1/0 status specifier err—transfer-of-control specifier The 1/0O-list parameter is symbolized as follows: iolist—the 1/0O-list specifier All of the parameters used in I/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. 7-28 |/0 Statements 7.2.3.1 Formatted Indexed READ Statement The formatted indexed READ statement performs the following operations: e Reads character data from one or more external records accessed under the keyed mode of access. * Translates the data from character to binary form using format specifications to provide editing. * Assigns the translated values to the elements in the 1/0 list, in the order, from left to right, in which they appear in the list. 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 parameter is omitted, the key-of-reference remains unchanged from the most recent specification. If the KEYID parameter 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. If the key value is longer than the key field referred to, an error occurs. Example In the following 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(25) to read the first four fields from the record into variables A,B,C, and D. READ (3,KAT(25) ,KEY='ABCD') A,B,C,D |/0 Statements 7-29 7.2.3.2 Unformatted Indexed READ Statement The unformatted indexed READ statement reads an external record accessed under the keyed mode of access. It assigns the fields of binary data contained in that record to the elements in the /O list, in the order, from left to right, in which those elements appear in the list. The data is not translated. The amount of data assigned to each element is determined by the element’s data type. The unformatted indexed READ statement reads exactly one record, and may be used only on indexed files. If the number of I/0O list elements is less than the number of fields in the record being read, the unused fields in the record are discarded. If the number of /0 list elements is greater than the number of fields, an error occurs. 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. If the specified key value is longer than the key field that is referred to, an error occurs. Examples In the first example, the READ statement reads from the file connected to logical unit 3 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. OPEN 1 (UNIT=3, STATUS='0OLD', ACCESS='KEYED', ORGANIZATION='INDEXED', 2 FORM='UNFORMATTED', 3 KEY=(1:5,30:37,18:23)) READ (3,KEY='SMITH') ALPHA, BETA In the second 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). The first field of that record is placed in the variable IKEY. READ (3,KEYGE='XYZDEF' KEYID=2,ERR=99) IKEY 1-30 I/0 Statements 1.2.4 Internal READ Statement Internal READ statements transfer input data to internal storage from an internal file. (This statement has an alternative statement, DECODE, which is discussed in Appendix A.) The internal READ statement can be formatted or list-directed, taking one of the following forms: Formatted READ (intu,fmt[,iostat][,err][,end]) [iolist] List-Directed READ (intu,*[,iostat][,err][,end]) [iolist] Control-list parameters are symbolized as follows: intu—an internal file specifier fmt—a format specifier *—a list-directed formatting specifier (You can also use FMT=*) iostat—an 1/0 status specifier err, end—transfer-of-control specifiers The 1/0-list parameter is symbolized as follows: iolist—the 1/0O-list specifier The parameters used in I/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. 7.2.4.1 Formatted Internal READ Statement The formatted internal READ statement performs the following operations: e Reads character data from an internal file. e Translates the data from character to binary form using format specifications to provide editing. * Assigns the translated data to the elements in the I/O list in the left-to-right order in which the elements appear. I/0 Statements 7-31 Example The following program segment reads a record and examines the first character to determine whether the remaining data should be interpreted as decimal, octal, or hexadecimal. It then uses internal-file reads to make appropriate conversions from character string representations to binary. INTEGER IVAL CHARACTER TYPE, RECORD*80 CHARACTER* (*) AFMT, IFMT, PARAMETER (AFMT='(Q,A)', 1 ZFMT= ACCEPT AFMT, OFMT, ZFMT IFMT= '(I10)', OFMT= '(011)', '(Z8)"') ILEN, RECORD TYPE = RECORD(1:1) IF (TYPE .EQ. READ (RECORD(2:MIN(ILEN, ELSE IF READ ELSE IF READ (TYPE 'D') .EQ. THEN '0') (RECORD(2:MIN(ILEN, (TYPE .EQ. 'X') 11)), IFMT) IVAL 12)), OFMT) IVAL THEN THEN (RECORD(2:MIN(ILEN, 9)),ZFMT) IVAL ELSE PRINT *, END 'ERROR' IF END 7.2.4.2 List-Directed Internal READ Statement The list-directed internal READ statement performs the following operations: e Reads character data from an internal file. * Translates the data from external to binary form using the data types of the elements in the I/0O list and the forms of the data to provide editing. * Assigns the translated data to the elements in the I/O list, in the order, from left to right, in which those elements appear in the list. Namelist-directed formatting is not permitted with an internal READ statement. Refer to the VAX FORTRAN User Manual for information on the characteristics and use of internal files. 71-32 I/0 Statements 7.3 WRITE Statements The WRITE statement transfers output data from internal storage to userspecified external logical units (disks, printers, terminals, mailboxes) or to internal files. It can be used in sequential, direct, keyed, or internal access modes. WRITE statements cannot write to existing records in an indexed file. For statements that can perform this function in indexed files, refer to the REWRITE statement discussed in Section 7.4. 7.3.1 Sequential WRITE Statements Sequential WRITE statements transfer output data from internal storage to external records accessed under the sequential mode of access. (See the VAX FORTRAN User Manual for descriptions of the various access modes.) Sequential WRITE statements can be formatted, list-directed, namelistdirected, or unformatted, taking one of the following forms: Formatted WRITE (extu,fmt[,iostat][,err]) [iolist] List-Directed WRITE (extu,*[,iostat][,err]) [iolist] Namelist-Directed WRITE (extu,nml[,iostat][,err]) Unformatted WRITE (extul,iostat][,err]) [iolist] Control-list parameters are symbolized as follows: extu—a logical unit specifier fmt—a format specifier *—a list-directed formatting specifier (You can also use FMT=*) nml—a namelist specifier |/0 Statements 7-33 1ostat—an 1/0O status specifier err—a transfer-of-control specifier The I/0O-list parameter is symbolized as follows: iolist—the 1/0O-list specifier All of the parameters used in I/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. 7.3.11 Formatted Sequential WRITE Statement The formatted sequential WRITE statement performs the following operations: * e Retrieves specified data from internal storage. Translates the data from binary to character form using format specifications to provide editing. ® Writes the translated values to an external record that is sequentially accessed. The length of the records written to a user-specified output device (for example, a line printer) must not exceed the maximum record length that the device can process. In the case of a line printer, this maximum is usually 132 characters. Using an appropriate format specification, a statement can write more than one record. If you transfer numeric data using formatted output statements and you subsequently use the data as input, the resulting data may not be precise because of a rounding of the data during conversion from binary to character form. Therefore, if you expect to subsequently use numeric data as input, use unformatted output and input statements for data transfer. Examples In the first example, the WRITE statement writes one record to logical unit 6. The record consists of the character constant defined in the FORMAT statement. WRITE 650 1-34 I/0 Statements FORMAT (6,650) (' HELLO THERE') In the second example, the WRITE statement writes one record consisting of fields AYE, BEE, and CEE to logical unit 1. WRITE 95 (1,95) AYE, FORMAT BEE, CEE (3F8.5) In the third example, the WRITE statement writes three separate records to logical unit 1. Each record has only one field. WRITE 900 7.3.1.2 (1,900) DEE, EEE, EFF FORMAT (F8.5) List-Directed Sequential WRITE Statement The list-directed sequential WRITE statement performs the following operations: * Retrieves specified data from internal storage. * Translates that data from binary to character form using the data type of the elements in the I/0 list to provide editing. e Writes the translated values to an external record accessed under the sequential mode of access. The values transferred as output by the list-directed WRITE statement have the same forms as those of constant values transferred as input by the list-directed READ and ACCEPT statements, with the following exceptions: * Character constants are transferred without delimiting apostrophes. * Each internal apostrophe is represented by only one apostrophe instead of two. Consequently, records containing list-directed character output data can be printed but not used for list-directed input. (See Section 7.2.1.2 for a discussion of list-directed value forms.) Table 7-1 shows the default output formats for each data type. I/0 Statements 7-35 Table 7-1: List-Directed Default Output Formats Data Type Output Format LOGICAL*1(BYTE) I5 LOGICAL*2 L2 LOGICAL+*4 L2 INTEGER#*2 17 INTEGER*4 112 REAL 1PG15.7E2 REAL=*8 1PG24.16E2 REAL*8(/G_FLOATING) 1PG24.15E3 REAL*16 1PG43.33E4 COMPLEX (", 1PG14.7E2, '), 1PG14.7E2,) COMPLEX*16 (", 1PG23.16E2,",’, 1PG23.16E2,") COMPLEX*16(/G_FLOATING) (", 1PG23.15E3,",',1PG23.15E3,"Y CHARACTER An where n is the length of the character expression List-directed output formats behave in the following ways: List-directed output statements do not produce octal values, null values, slash separators, or repeated forms of values. * List-directed output edits a complex value so that there are no embed- ded spaces in the value. * Each output record begins with a space for carriage control. * Each output statement writes one or more complete records. * Each individual output value is contained within a single record, with the exception of character constants longer than one record length and complex constants that can be split after the comma. 7-36 |/0 Statements Example The following example illustrates a valid list-directed WRITE statement: DIMENSION A(4) DATA A/4%3.4/ WRITE (1,%) 'ARRAY VALUES FOLLOW' WRITE (1,*) A.4 In this example, the WRITE statements write the following records to logical unit 1: ARRAY VALUES FOLLOW 3.400000 7.3.1.3 3.400000 3.400000 3.400000 4 Namelist-Directed Sequential WRITE Statement The namelist-directed sequential WRITE statement performs the following operations: e Retrieves data specified by the namelist specifier from internal storage. Translates that data from internal to external form using the data type e Writes the translated values to external records accessed under the e of the list entities in the corresponding NAMELIST statement. sequential mode of access. The namelist-directed WRITE statement transfers as output the current values of all list entities associated with the specified namelist specifier. These values are written in a form that can be read as input by the namelist-directed READ and ACCEPT statements. The order of data output is dictated by the sequence in which namelist entities are defined in a NAMELIST statement. The first list entity and its value are written first, the second list entity and its value are written second, and so on. Each value display begins on a new line. |/0 Statements 7-37 Example Consider a program unit with the following statements: CHARACTER*19 NAME(2)/2x*' REAL PITCH, ROLL, YAW, '/ POSITION(3) LOGICAL DIAGNOSTICS INTEGER ITERATIONS NAMELIST /PARAM/ NAME, PITCH, 1 ITERATIONS READ DIAGNOSTICS, ROLL, YAW, POSITION, (UNIT=1,NML=PARAM) WRITE (UNIT=1,NML=PARAM) The input contains the following statements: A$PARAMANAME(2) (10:)="'HEISENBERG', APITCH=5.0, YAW=0.0, ROLL=5.0, ADIAGNOSTICS=.TRUE. AITERATIONS=10$END In this case, the WRITE statement would write the following;: A$PARAM ANAME = APITCH = AROLL = AYAW = v, 5.000000 , 5.000000 : HEISENBERG', 0.0000000E+0Q0Q, APOSITION = 3%0.0000000E+00, ADIAGNOSTICS = T, AITERATIONS = 10 A$END Notice that character values are enclosed in apostrophes. The value of POSITION is not defined in the namelist-directed input. It may be defined elsewhere in the program or be undefined. The namelist-directed WRITE statement prints the current contents of POSITION. 7-38 |/0 Statements 7.3.1.4 Unformatted Sequential WRITE Statement The unformatted sequential WRITE statement transfers specified binary data from internal storage to an external record accessed under the sequential mode of access. The data is not translated. The unformatted sequential WRITE statement writes exactly one record. If there is no I/0 list, the statement writes one null record. Examples In the first example, the WRITE statement writes a record to the file connected to logical unit 1 containing the values (in binary form) of elements 1 through 5 of the array LIST. WRITE (1) (LIST(K), K=1,5) In the second example, the WRITE statement writes one null record to the file connected to logical unit 4. WRITE (4) 7.3.2 Direct Access WRITE Statements Direct access WRITE statements transfer output data from internal storage to external records accessed under the direct mode of access. (The attributes of a direct access file are established by the OPEN statement.) Direct access WRITE statements can be formatted or unformatted, taking one of the following forms: Formatted WRITE (extu,rec,fmt[,iostat][,err]) [iolist] Unformatted WRITE (extu,rec[,iostat][,err]) [iolist] Control-list parameters are symbolized as follows: extu—a logical unit specifier rec—a record specifier fmt—a format specifier iostat—an 1/0 status specifier err—transfer-of-control specifier |/0 Statements 7-39 The I/O-list parameter is symbolized as follows: iolist—the 1/0-list specifier The parameters used in I/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. 7.3.2.1 Formatted Direct Access WRITE Statement The formatted direct access WRITE statement performs the following operations: * Retrieves binary values from internal storage. * Translates those values to character form using format specifications to provide editing. * Wirites the translated data to a user-specified external record accessed under the direct mode of access. If the values specified by the I1/0 list and formatting do not fill the output record being written, the unused portion of the record is filled with space characters. If the values overfill the record, an error occurs. 7.3.2.2 Unformatted Direct Access WRITE Statement The unformatted direct access WRITE statement retrieves binary values from internal storage and writes those values to a user-specified external record accessed under the direct mode of access. The values are not translated. If the values specified by the I1/0 list do not fill the output record being written, the unused portion of the record is filled with zeros. If the values do not fit in the record, an error occurs. 1-40 I/0 Statements 1.3.3 Indexed WRITE Statements The indexed WRITE statement transfers output data from internal storage to external records accessed under the keyed mode of access. (The OPEN statement establishes the attributes of an indexed file.) Indexed WRITE statements always write a new record. You should use the REWRITE statement to update an existing record (see Section 7.4). The syntactic form of the indexed WRITE statement is identical to that of the sequential WRITE statement. The two statements differ only in that the indexed WRITE statement refers to a logical unit connected to an indexed file, whereas the sequential WRITE statement refers to a logical unit connected to a sequential file. Indexed WRITE statements can be formatted or unformatted, taking one of the following forms: Formatted WRITE (extu,fmt[,iostat][,err]) [iolist] Unformatted WRITE (extul,iostat][,err]) [iolist] Control-list parameters are symbolized as follows: extu—a logical unit specifier fmt—a format specifier iostat—an 1/0 status specifier err—a transfer-of-control specifier The 1/0-list parameter is symbolized as follows: iolist—the 1/0-list specifier The parameters used in I/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. |/0 Statements 7-41 7.3.3.1 Formatted Indexed WRITE Statement The formatted indexed WRITE statement performs the following operations: * * Retrieves binary values from internal storage. Translates those values to character form using format specifications to provide editing. ®* Wirites the translated data to one or more external records accessed under the keyed mode of access. No key parameters are required in the list of control parameters because all necessary key information is contained in the output record. It the values specified by the 1/0 list and formatting do not fill a fixedlength record being written, the unused portion of the record is filled with space characters. If additional records are specified, they are inserted in the file logically according to the key values contained in each record. When you write an INTEGER key using the formatted indexed WRITE statement, the key is translated from internal binary form to external character form. A subsequent attempt to read the record using an integer key may not match the key field in the record. Example In the following example, the formatted indexed WRITE statement writes the translated values of each of the 20 elements of the array RDATA to a new formatted record in the indexed file connected to logical unit 4. KEYVAL is the key by which the record is accessed. (This example assumes that the first 10 bytes of a record are a character key.) WRITE 100 7-42 1/0 Statements FORMAT (4,100) KEYVAL, (A10,20F15.7) (RDATA(I), I=1,20) 7.3.3.2 Unformatted Indexed WRITE Statement The unformatted indexed WRITE statement retrieves binary values from internal storage and writes those values to an external record accessed under the keyed mode of access. The values are not translated. No key parameters are required in the list of control parameters because all necessary key information is contained in the output record. If the values specified by the I/O list do not fill a fixed-length record being written, the unused portion of the record is filled with zeros. If the values specified overfill the record, an error occurs. Using records (structured data items) has advantages when writing to indexed files. Such files usually have a fixed record format. Thus, by using a structure declaration that models the file’s record format, you can accomplish the I/O operation with a single record variable instead of a potentially long I/0O list. For an example, refer to the VAX FORTRAN User Manual. 7.3.4 Internal WRITE Statement Internal WRITE statements transfer output data from internal storage to an internal file. (You can also use the ENCODE statement discussed in Appendix A to control internal output.) See the VAX FORTRAN User Manual for information about the characteristics and use of internal files. Namelist-directed formattingis not permitted with internal WRITE statements. Internal write statements can be formatted or list-directed, taking one of the following forms: Formatted WRITE (intu,fmt[,iostat][,err]) [iolist] List-Directed WRITE (intu,*[,iostat][,err]) [iolist] Control-list parameters are symbolized as follows: intu—an internal file specifier fmt—a format specifier I/0 Statements 7-43 *—a list-directed formatting specifier (You can also use FMT=+.) iostat—an 1/0O status specifier err—a transfer-of-control specifier The I/O-list parameter is symbolized as follows: iolist—the 1/0O-list specifier The parameters used in I/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. 7.3.4.1 Formatted Internal WRITE Statement The formatted internal WRITE statement performs the following operations: e Retrieves data from internal storage. e Translates that data from binary to character form using format e Writes the translated values to an internal file. specifications to provide editing. 7.3.4.2 List-Directed Internal WRITE Statement The list-directed internal WRITE statement performs the following operations: 7-44 e Retrieves data from internal storage. e Translates that data from binary to character form using the data type of the elements in the I/O list to provide editing. e Writes the translated values to an internal file. 1/0 Statements 7.4 REWRITE Statement The REWRITE statement transfers data from internal storage to the current record in a file with indexed or relative organization. The current record is the one that was most recently accessed by a successful direct access, indexed, or sequential READ statement. Between a READ and REWRITE statement, you should not issue any other /0O statement (except INQUIRE) on that logical unit. Execution of any other I/O statement on the logical unit destroys the current-record context and causes the current record to become undefined. REWRITE statements can be formatted or unformatted, taking one of the following forms: Formatted REWRITE (extu,fmt([,iostat](,err]) ([iolist] Unformatted REWRITE (extu[,iostat][,err]) [iolist] Control-list parameters are symbolized as follows: extu—a logical unit specifier fmt—a format specifier iostat—an 1/0 status specifier err—a transfer-of-control specifier The I/0O list parameter is symbolized as follows: i0list—an 1/0O-list specifier The parameters used in I/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. |/0 Statements 7-45 1.4.1 Formatted REWRITE Statement The formatted REWRITE statement performs the following operations: e e e Retrieves binary values from internal storage. Translates those values to character form using format specifiers to provide editing. Writes the translated data to an existing record in a file with indexed or relative organization. The formatted REWRITE statement writes to the current record in the file (the last record accessed by a preceding direct access, indexed, or sequential READ statement). Errors occur with the following conditions: e e e If the primary key value is changed, an error usually occurs. If you attempt to rewrite more than one record in a single REWRITE statement operation, an error occurs. If a record is too long, an error occurs. (A record might become too long when unused space in a rewritten fixed-length record is filled with spaces.) Example In the following example, the REWRITE statement updates the current record contained in the indexed organization file connected to logical unit 3 with the values represented by NAME, AGE, and BIRTH. 10 7.4.2 REWRITE (3,10,ERR=99) NAME, AGE, BIRTH FORMAT (A16,12,A8) Unformatted REWRITE Statement The unformatted REWRITE statement retrieves binary values from internal storage and writes those values to an existing record in a file with indexed or relative organization. The values are not translated. The unformatted REWRITE statement writes to the current record in the file (the last record accessed by a preceding indexed or sequential READ statement). Unused space in a rewritten fixed-length record is filled with Zeros. 1-46 I/0 Statements Errors occur with the following conditions: * If the primary key value is changed, an error usually occurs. * If you attempt to rewrite more than one record in a single REWRITE statement operation, an error occurs. * 1.5 If a record is too long, an error occurs. ACCEPT Statement The ACCEPT statement transfers input data to internal storage from external records accessed under the sequential mode of access. ACCEPT statements can only be used on implicitly connected logical units. ACCEPT statements take any one of the following forms: ACCEPT f[,iolist] ACCEPT =[,iolist] ACCEPT n Control-list parameters are symbolized as follows: f—the nonkeyword form of a format specifier *—a list-directed formatting specifier n—the nonkeyword form of a namelist specifier The I/0O-list parameter is symbolized as follows: iolist—an 1/0 list specifier The parameters used in I/0O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). The rules for specifying control-list parameters are summarized in Section 7.1.1.1. The ACCEPT statement functions exactly like the sequential READ statements discussed in Sections 7.2.1.1 through 7.2.1.3, with the following important exception: the ACCEPT statement can never be connected to user-specified logical units. |/0 Statements 7-47 Example In the following example, the ACCEPT statement reads character data from the implicit unit and assigns binary values to each of the five elements of the array CHARAR: CHARACTER*10 CHARAR(5) ACCEPT 200, 200 7.6 FORMAT CHARAR (5A10) TYPE and PRINT Statements The TYPE and PRINT statements transfer output data from internal storage to external records that are sequentially accessed. TYPE and PRINT statements take the same forms, which can be any one of the following;: TYPE f[,iolist] PRINT f[,iolist] TYPE *[,iolist] PRINT *[,iolist] TYPE n PRINT n Control-list parameters are symbolized as follows: f—the nonkeyword form of a format specifier *—the list-directed formatting specifier n—the nonkeyword form of a namelist specifier The I/0O-list parameter is symbolized as follows: iolist—the 1/0O-list specifier The parameters used in 1/O statements are described in Sections 7.1.1 (control-list parameters) and 7.1.2 (I/O-list parameter). TYPE and PRINT statements function exactly like the formatted sequential WRITE statement discussed in Section 7.3.1.1, with the following important exception: the formatted sequential TYPE and PRINT statements can never be used to transfer data to user-specified logical units. 1-48 |/0 Statements Example In the following example, the PRINT statement writes one record to the implicit output device. The record has four fields of character data. CHARACTER*16 NAME, PRINT 400, 400 NAME, JOB JOB FORMAT ('NAME=', A, 'JOB=',A) /0 Statements 7-49 Chapter 8 1/0 Formatting Formatting I/O statements specify the form of data being transferred. They also specify the data conversion (editing) required to achieve that form. The primary formatting statement is the FORMAT statement. It is a nonexecutable statement used in conjunction with formatted 1/0 statements and with ASSIGN, ENCODE, and DECODE statements. This chapter contains the following information about 1/0O formatting: General rules for writing FORMAT statements (Section 8.1) FORMAT statement syntax (Section 8.2) Field and edit descriptors (Section 8.3) Carriage control options for output records (Section 8.4) Format specifications and field separators (comma and slash) (Sections 8.5 and 8.6) Run-time formats (instead of a FORMAT statement) that dynamically creates formats during program execution (Section 8.7) Format control interactions with 1/0 lists (Section 8.8) |/0 Formatting 8-1 8.1 General Rules for Writing FORMAT Statements This section summarizes the rules for constructing and using the format specifications and their components in FORMAT statements. It also summarizes the rules for constructing external fields and records. The following are general FORMAT statement rules: A FORMAT statement must always be labeled. In a field descriptor such as rlw[.m] or nX, the terms r, w, m, and n must be unsigned integer constants or variable format expressions whose values are greater than or equal to zero. The values of r and w must be greater than zero and less than or equal to 32767, and the values of m and n must be greater than zero and less than or equal to 255. (They cannot be names assigned to constants in PARAMETER statements.) You can omit the repeat count and field width specification. In a field descriptor such as Fw.d, the term d must be an unsigned integer constant or variable format expression. You must specify d with F, E, D, and G field descriptors even if d is zero. The decimal point is also required. You must either specify both w and d, or omit them both. In a field descriptor such as Ew.dEe, the term e must also be an unsigned integer constant. In a field descriptor such as nHclc2 ... cn, exactly n characters must follow the H format code. You can use any printable ASCII character in this field descriptor. In a scale factor of the form nP, n must be an integer constant or variable format expression in the range —-128 to 127. The scale factor affects the F, E, D, and G field descriptors only. Once you specify a scale factor, it applies to all subsequent real field descriptors in that format specification until another scale factor appears. You must explicitly specify OP to reinstate a scale factor of zero. Format reversion does not affect the scale factor. No repeat count is permitted in BN, BZ, 5, S5, SP, H, Q, X, T, TR, TL, $, :, or character constant field descriptors unless these descriptors are enclosed in parentheses and treated as a group repeat specification. If the associated 1/O statement contains an I/O list, the format specification must contain at least one field descriptor. This descriptor mustbel, O,Z,F E D, G,L, A, or Q. 8-2 |/0 Formatting A format specification in a character variable, character substring ref- erence, character array element, character array, character expression, numeric array, or numeric array element must be constructed in the same way as a format specification in a FORMAT statement, including the opening and closing parentheses. If a character-constant format includes apostrophes, those apostrophes must be represented by double apostrophes (”). 8.1.1 Input Rules for FORMAT Statements The following are general FORMAT statement input rules: A minus sign must precede a negative value in an external input field; a plus sign is optional before a positive value. On input, an external field under I field descriptor control must be an integer constant. It cannot contain a decimal point or an exponent. An external field under O field descriptor control must contain only the numerals 0 through 7. An external field input under Z field descriptor control must contain only the numerals 0 through 9 and the letters A(a) through F(f). An external field under O or Z field descriptor control must not contain a sign, a decimal point, or an exponent. You cannot use octal and hexadecimal constants in the form '777°0O or "AF9’X in external records. On input, an external field under F, E, D, or G field descriptor control must be an integer constant or a real constant. It can contain a decimal point; an E(e), D(d), or Q(q) exponent field; or both. If an external field contains a decimal point, the actual size of the fractional part of the field, as indicated by that decimal point, overrides the d specification of the corresponding real field descriptor. If an external field contains an exponent, the scale factor (if any) of the corresponding field descriptor is inoperative for the conversion of that field. The field width specification must be large enough to accommodate both the numeric character string of the external field and any other characters that are allowed (algebraic sign, decimal point, exponent, or combination of the three). A comma is the only character you can use as an external field separator. It terminates the input of fields (for noncharacter data types) that are shorter than the number of characters expected. It also designates null (zero-length) fields. I/0 Formatting 8-3 8.1.2 Output Rules for FORMAT Statements The following are general FORMAT statement output rules: A format specification cannot specify more output characters than the external record can contain. For example, a line printer record cannot contain more than 133 characters, including the carriage control character. The field width specification (w) must be large enough to accommodate all characters that the data transfer can generate, including an algebraic sign, decimal point, and exponent. For example, the field width specification in an E field descriptor should be large enough to contain d+7 or d+e+5 characters. The first character of a record transmitted to a line printer or terminal is typically used for carriage control; it is not printed. The first character of such a record should be a space, 0, 1, §, +, or ASCII NUL. Any other character is treated as a space. 8.2 FORMAT Statement Syntax The FORMAT statement takes the following form: FORMAT (qifis1f2s2 ... fngn) qn Is zero or more slash ( /) record terminators. (See Section 8.5.) fn Is a field descriptor or a group of field descriptors enclosed in parentheses. (See Section 8.3.) S Is a field separator. (See Sections 8.5 and 8.6.) The entire list of field descriptors and field separators, including the parentheses, is called the format specification. 8-4 I/0 Formatting The field descriptor takes one of the following forms: [rlc [rlcw [rlcw.m [rlcw.d[Ee] r Is the repeat count for the field descriptor. If you omit r, the repeat count is assumed to be 1. c Is a format code (I, O, Z,F, E,D,G,L, A, H, X, T,P, Q, $,:, BN, BZ, S, SP, SS, TL, or TR). w Is the external field width, in characters. m Is the minimum number of characters that must appear within the field (including leading zeros). d Is the number of characters to the right of the decimal point. E In this context, identifies an exponent field. e Is the number of characters in the exponent. The r, w, m, and d terms must all be unsigned integer constants or variable format expressions. The values of r and w must be greater than zero and less than or equal to 32767, and the values of m, d, and e must be greater than zero and less than or equal to 255. The r term is optional with some field descriptors but invalid with others (see Section 8.3.1). The d and e terms are required with some field descriptor but invalid with others. PARAMETER constants cannot be used as values for the r, w, m, d, or e specifiers. I/0 Formatting 8-5 The field descriptors are as follows: e Integer—Iw, Ow, Zw, Iw.m, Ow.m, Zw.m e Logical—Lw e Real and complex—Fw.d, Ew.d, Dw.d, Gw.d, Ew.dEe, Gw.dEe e (Character—Aw Editing, and character and Hollerith constants—nH, "...", nX, Tn, TLn, TRn, nP, Q, $, :, BN, BZ, S, SP, SS (n is the number of characters or e character positions). Table 8—1 summarizes the FORMAT codes. Table 8-1: Code Form A A[w] BN BN FORMAT Code Summary Effect Transfers character or Hollerith values. (See Section 8.3.9.1.) Specifies that embedded and trailing blanks in a numeric input field are to be ignored. (See Section 8.3.3.1.) BZ BZ Specifies that embedded and trailing blanks in a numeric input field are to be treated as zeros. (See Section 8.3.3.2.) D Dw.d Transfers real values (D exponent field indicator). (See E Ew.d[Ee] Transfers real values (E exponent field indicator). (See F Fw.d Transfers real values. (See Sections 8.3.6.2 and 8.3.6.5.) Transfers real values: on input, acts like F code; on Gw.d[Ee] Sections 8.3.6.3 and 8.3.6.5.) Sections 8.3.6.2 and 8.3.6.5.) output, acts like E code or F code, depending on the magnitude of the value. (See Sections 8.3.6.4 and 8.3.6.5.) 8-6 1/0 Formatting Transfers data between the H field descriptor and an H nHc...c I Iw[.m] L Lw Transfers decimal integer values. (See Section 8.3.5.1.) Transfers logical data: on input, transfers characters; on O Ow[.m] Transfers octal values. (See Section 8.3.5.2.) external record. (See Section 8.3.9.2.) output, transfers T or F. (See Section 8.3.8.) Table 8-1 (Cont.): FORMAT Code Summary Code Form Effect P nP Alters locations of decimal points. (See Section 8.3.7.) Q Q Obtains the number of characters remaining to be transferred in an input record. (See Section 8.3.12.1.) S S Reinvokes optional plus characters in numeric output fields; counters the action of SP and SS. (See SpP Sp Writes plus characters that would otherwise be optional Section 8.3.4.3.) into numeric output fields. (See Section 8.3.4.1.) SS 5SS Suppresses optional plus characters in numeric output fields. (See Section 8.3.4.2)) T Tn Specifies positional tabulation. (See Section 8.3.11.2.) TL TLn Specifies relative tabulation (left). (See Section 8.3.11.3.) TR TRn Specifies relative tabulation (right). (See Section 8.3.11.4.) X nX Specifies that n characters are to be skipped. (See Section 8.3.11.1)) Zw[.m] $ $ Transfers hexadecimal values. (See Section 8.3.5.3.) Suppresses carriage return during interactive 1/0. (See Section 8.3.12.2)) Terminates format control if the I/0O list is exhausted. (See Section 8.3.12.3.) 8.3 Field and Edit Descriptors A field descriptor describes the size and format of one or more data items. Each data item in the external medium is called an external field. An edit descriptor specifies an editing function to be performed on a data item or items. The numeric field descriptors ignore leading spaces in the external field. Embedded and trailing spaces are ignored only if the BN edit descriptor is specified or if BLANK='NULL' is in effect for the logical unit. Otherwise, embedded and trailing spaces are treated as zeros. |/0 Formatting 8-7 At the beginning of the execution of each formatted input statement, the BLANK attribute for the relevant logical unit determines the interpretation of spaces. Default values are as follows: e BLANK =’NULL'—when an open has been executed e BLANK = 'ZERO'—when no explicit open has been executed During execution of a formatted input statement, the BN and BZ edit descriptors may supersede the default interpretation of blanks. The BN and BZ edit descriptors affect only the formatted I/O statement of which they are a part (as do the S, SP, and SS edit descriptors). Sections 8.3.3 through 8.3.12 describe each of the field and edit descriptors. 8.3.1 Repeat Counts and Group Repeat Counts You can apply the field descriptors I, O, Z,F, E, D, G, L, and A to a number of successive data fields by preceding the field descriptor with an unsigned integer constant (parameter constants not allowed) specifying the number of repetitions. This constant is called a repeat count. For example, the following two statements are equivalent: 20 FORMAT (E12.4,E12.4,E12.4,15,15,15,15) 20 FORMAT (3E12.4,4I5) Similarly, you can apply a group of field descriptors repeatedly to data fields by enclosing these field descriptors in parentheses and preceding them with an unsigned integer constant (parameter constants are prohibited). The integer constant is called a group repeat count. For example, the following two statements are equivalent: 50 FORMAT (218,3(F8.3,E15.7),2(I5)) 50 FORMAT (I8,18,F8.3,E15.7,F8.3,E15.7,F8.3,E15.7,15,15) 1 2 3 An H or Q field descriptor, which could not otherwise be repeated, can be enclosed in parentheses and treated as a group repeat specification. Thus, it could be repeated a desired number of times. If you do not specify a group repeat count, a default count of 1 is assumed. Section 8.8 discusses how to use parentheses when the number of values to be formatted is greater than the number of format specifications. |/0 Formatting 8.3.2 Variable Format Expressions By enclosing an arithmetic expression in angle brackets, you can use it in a FORMAT statement wherever you can use an integer (except as the specification of the number of characters in the H field); for example: FORMAT (I<J+1>) When the format is scanned, the preceding statement performs an I (inte- ger) data transfer with a field width of J+1. The expression is reevaluated each time it is encountered in the normal format scan. Syntax Rules The following syntax rules apply to variable format expressions: e If the expression is not of integer data type, it is converted to integer * The expression can be any valid FORTRAN expression, including data type before being used. function calls and references to dummy arguments. * The value of a variable format expression must obey the restrictions ¢ Variable format expressions are not permitted in run-time formats. on magnitude applying to its use in the format, or an error occurs. Variable format expressions are evaluated each time they are encountered in the scan of the format. If the value of the variable used in the expression changes during the execution of the /0O statement, the new value is used the next time the format item containing the expression is processed. See Section 8.8 for a description of the synchronization of I/0 lists with formats. Example Consider the following statements: DIMENSION A(5) DATA A/1.,2.,3.,4.,5./ DO 10 I=1,10 WRITE (6,100) 100 FORMAT 10 CONTINUE I (I<MAX(I,5)>) |/0 Formatting 8-9 DO 20 I=1,5 WRITE (6,101) (A(I), 101 FORMAT (<I>F10.<I-1>) 20 CONTINUE J=1,1) END On execution, these statements produce the following output: 1 2 3 4 5 6 7 8 9 10 1. 2.0 2.0 3.00 3.00 4.000 4.000 5.0000 5.0000 3.00 4.000 5.0000 4.000 5.0000 5.0000 Blank Control Editing 8.3.3 The treatment of embedded and trailing blanks within numeric input files is controlled by BN and BZ edit descriptors. 8.3.3.1 BN Edit Descriptor The BN descriptor causes the processor to ignore all the embedded and trailing blanks it encounters within a numeric input field. It takes the following form: BN The effect is that of actually removing the blanks and right-justifying the remainder of the field. A field of all blanks is treated as zero. The BN descriptor affects only I, O, Z, F, E, D, and G editing during the execution of an input statement. 8-10 1/0 Formatting 8.3.3.2 BZ Edit Descriptor The BZ descriptor causes the processor to treat all the embedded and trailing blanks it encounters within a numeric input field as zeros. It takes the following form: BZ The BZ descriptor affects only I, O, Z, F, E, D, and G editing during the execution of an input statement. 8.3.4 Sign Control Editing The treatment of optional plus characters in output data is controlled by SP, S5, and S edit descriptors. 8.3.4.1 SP Edit Descriptor An SP descriptor causes the processor to produce a plus character (+) in any position where this character would otherwise be optional. It takes the following form: SP The SP descriptor affects only I, F, E, D, and G editing during the execution of an output statement. 8.3.4.2 SS Edit Descriptor The SS descriptor causes the processor to suppress a leading plus character from any position where this character would normally be produced as an optional character. It has the opposite effect of the SP field descriptor described previously. The SS descriptor takes the following form: S5 The SS descriptor affects only I, F, E, D, and G editing during the execution of an output statement. |/0 Formatting 8-11 8.3.4.3 S Edit Descriptor The S edit descriptor reinvokes optional plus characters (+) in numeric output fields. It takes the following form: S The S descriptor counters the action of either the SP or SS descriptor by restoring to the processor the discretion of producing plus characters on an optional basis. The same restrictions apply as for the SP and SS descriptors. Integer Editing 8.3.5 Integer editing is controlled by I (decimal), O (octal), and Z (hexadecimal) field descriptors. 8.3.5.1 | Field Descriptor The I field descriptor transfers decimal integer values. It takes the following form: Iw(.m] The corresponding I/0O list element must have an integer or logical data type. Input Processing In an input statement, the I field descriptor transfers w characters from the external field and assigns them to the corresponding I/0 list element as an integer value. The external data must have the form of an integer constant. It cannot contain a decimal point or exponent field. The I field descriptor processes input in the following ways: e If the value of the external field exceeds the range of the corresponding list element, an error occurs. e 8-12 1/0 Formatting If the first nonblank character of the external field is a minus sign, the field is treated as a negative value. e If the first nonblank character is a plus sign or if no sign appears in the field, the field is treated as a positive value. e If the field is blank, it is treated as a value of zero. The following list illustrates valid input processing with the I field descriptor: Format External Field Internal Value 14 2788 2788 13 -26 -26 19 AAAAAA312 312 Output Processing In an output statement, the I field descriptor transfers the value of the corresponding 1/0 list element, right-justified, to an external field that is w characters long. The I field descriptor processes output in the following ways: e If the value does not fill the field, leading spaces are inserted. e If the value is too large for the field, the entire field is filled with asterisks. e If the value of the list element is negative, the field will have a minus sign as its leftmost, nonblank character. Therefore, the term w must be large enough to fit a minus sign when necessary. e If m is present, the external field consists of at least m digits and is filled with zeros on the left, if necessary. The following list illustrates valid output processing with the I field descriptor: I/0 Formatting 8-13 Format Internal Value External Representation I3 284 284 14 -284 -284 14 0 AAAO I5 174 AA174 12 3244 ok 13 -473 ok* [7 29.812 (Not permitted: error) 14.0 0 AAAA 1 AAO1 14.2 14.4 1 0001 If m is zero and the internal representation is zero, the external field is blank. 8.3.5.2 O Field Descriptor The O field descriptor transfers octal (base 8) values and can be used with any data type. It takes the following form: Ow[.m] Input Processing In an input statement, the O field descriptor transfers w characters from the external field and assigns them as an octal value to the corresponding I/0 list element. The external field can contain only the numerals 0 through 7. It cannot contain a sign, a decimal point, or an exponent field. An all-blank field is treated as a value of zero. An error occurs if the value of the external field exceeds the range of the corresponding list element. The following list illustrates valid input processing using the O field descriptor: 8-14 /0 Formatting Format External Field Internal Octal Value 05 32767 32767 04 16234 1623 O3 97A (Not permitted: error) Output Processing In an output statement, the O field descriptor transfers the octal value of the corresponding [/O list element, right-justified, to an external field that is w characters long. No signs are transmitted; a negative value i1s transmitted in internal form. If the value does not fill the field, leading spaces are inserted; if the value is too large for the field, the entire field is filled with asterisks. If m is present, the external field consists of at least m digits and is zero-filled on the left if necessary. The following list illustrates valid output processing using O field descriptors: Format Internal (Decimal) Value External Representation 06 32767 NTTT77 06 -32767 100001 02 14261 04 27 AA33 05 10.5 41050 04.2 7 ANO7 0O4.4 7 0007 *ok If m is zero and the external representation is zero, the external field is filled with blanks. |/0 Formatting 8-15 8.3.5.3 Z Field Descriptor The Z field descriptor transfers hexadecimal (base 16) values, and can be used with any data type. It takes the following form: Zw[.m] Input Processing In an input statement, the Z field descriptor transfers w characters from the external field and assigns them as a hexadecimal value to the corresponding [/O list element. The external field can contain only the numerals 0 through 9 and the letters A (a) through F (f). It cannot contain a sign, decimal point, or exponent field. An all-blank field is treated as a value of zero. If the value of the external field exceeds the range of the corresponding list element, an error occurs. The following list illustrates valid input processing using the Z field descriptor: Format External Field Z3 A94 75 A23DEF 75 95. AF2 Internal Hexadecimal Value A94 A23DE (Not permitted: error) Output Processing In an output statement, the Z field descriptor transfers the hexadecimal value of the corresponding 1/0O list element, right-justified, to an external field that is w characters long. No signs are transmitted. A negative value is transmitted in internal form. If the value does not fill the field, leading spaces are inserted; if the value is too large for the field, the entire field is filled with asterisks. If m is present, the external field consists of at least m digits and is filled with zeros on the left, if necessary. The following list illustrates valid output processing using the the Z field descriptor: 8-16 |/0 Formatting Format Internal (Decimal) Value Z4 32767 Z5 -32767 External Representation TFFF A8001 Z2 16 10 Z4 -10.5 €228 Z3.3 2708 A94 6.4 2708 AAOA94 If m is zero and the internal representation is zero, the external field is filled with blanks. 8.3.6 Real Editing Editing performed on data with a real data type is controlled by the F, E, D, and G field descriptors. NOTE When attempting to parse textual input, you should not mix F, E, D, or G format descriptors. These descriptors accept some forms that are purely textual as valid numeric input values. For example, the input values D, E, E1, +, -, and . are all treated as 0.0. 8.3.6.1 F Field Descriptor The F field descriptor transfers real values. It takes the following form: Fw.d The corresponding 1/0 list element must have a real data type or it must be either the real or the imaginary part of a complex data type. Input Processing In an input statement, the F field descriptor transfers w characters from the external field and assigns them as a real value to the corresponding 1/0 list element. |/0 Formatting 8-17 Input processing with the F field descriptor behaves in the following ways: If the first nonblank character of the external field is a minus sign, the field is treated as a negative value. If the first nonblank character is a plus sign or if no sign appears in the field, the field is treated as a positive value. If a field is all blank, it is treated as a zero value. If a field contains only an exponent or decimal point, it is treated as a zero value. If the field contains neither a decimal point nor an exponent, it is treated as a real number of w digits, in which the rightmost d digits are to the right of the decimal point, with leading zeros assumed, if necessary. If the field contains an explicit decimal point, the location of that decimal point overrides the location specified by the field descriptor. If the field contains an exponent, that exponent is used to establish the magnitude of the value before it is assigned to the list element. The following list illustrates valid input processing using the F field descriptor: Format External Field Internal Value F8.5 123456789 123.45678 F8.5 ~1234.567 -1234.56 F8.5 24 . TTE+2 2477.0 F5.2 1234567 .89 123.45 Output Processing In an output statement, the F field descriptor transfers the value of the corresponding I/0O list element, rounded to d decimal positions and right-justified, to an external field that is w characters long. If the value does not fill the field, leading spaces are inserted; if the value is too large for the field, the entire field is filled with asterisks. The term w must be large enough to include all of the following;: Minus sign when necessary (plus signs are optional) 8-18 |/0 Formatting e At least one digit to the left of the decimal point e Decimal point e d digits to the right of the decimal In other words, w must be greater than or equal to d+3. The following list illustrates valid output processing using the F field descriptor: Format Internal Value 2.3547188 F8.5 8.3.6.2 F9.3 8789.7361 F2.1 51.44 External Representation A2.35472 A8789.736 K F10.4 -23.24352 AA-23.2435 F5.2 325.013 s s ok ok F5.2 -.2 -0.20 E Field Descriptor The E field descriptor transfers real values in exponential form. It takes the following form: Ew.d[Ee] The corresponding 1/0 list element must have a real data type or it must be either the real or the imaginary part of a complex data type. Input Processing In an input statement, the E field descriptor transfers w characters from the external field and assigns them as a real value to the corresponding I/0 list element. The F field descriptor interprets and assigns data in exactly the same way. The following example illustrates valid input processing using the E field descriptor: 1/0 Formatting 8-19 Format External Field Internal Value E9.3 734 .432E3 734432.0 E12.4 AA1022.43E-6 E15.3 52.37596630AAAA E12.5 210.5271D+10 1022.43E-6 52.3759663 210.5271E10 In the last example, the E field descriptor treats the D exponent field indicator as an E indicator if the I/0O list element is single precision. Output Processing In an output statement, the E field descriptor transfers the value of the corresponding I/O list element, rounded to d decimal digits and right-justified, to an external field that is w characters long. If the value does not fill the field, leading spaces are inserted. If the value is too large for the field, the entire field is filled with asterisks. When you use the E field descriptor, data output is transferred into standard form. The standard form has the following components: Minus sign, when necessary (plus signs are optional) Zero Decimal point d digits to the right of the decimal point e + 2-character exponent that takes one of the following forms: For exponents less than or equal to 99, with Ew.d: E+nn E-nn For exponents less than or equal to 999, with Ew.a: +nnn -nnn For all exponents with Ew.dEe: E+nin2.. .ne E-nin2.. .ne 8-20 |/0 Formatting The exponent field width specification is optional. If you omit it, the value of e defaults to two. If the exponent value is too large to be converted into one of the preceding forms, an error occurs. The d digits to the right of the decimal point represent the entire value, scaled to a decimal fraction. The term w must be large enough to include all of the following: e Minus sign when necessary (plus signs are optional) e Zero e Decimal point e d digits * Exponent In other words, w must be greater than or equal to d+7. If e is present, w must be greater than or equal to d+e+5. The following list illustrates valid output processing using the E field descriptor: Internal Value E9.2 475867 .222 AO.48E+06 E12.5 475867 .222 AO.47587E+06 E12.3 8.3.6.3 External Representation Format 0.00069 AAAO .690E-03 E10.3 -0.5555 -0.556E+00 E5.3 56.12 KKK Kok E14.5E4 -1.001 -0.10010E+0001 E14.3E6 0.000123 AO. 123E-000003 D Field Descriptor The D field descriptor transfers real values in exponential form. It takes the following form: Dw.d The corresponding I/0 list element must have a real data type or it must be either the real or the imaginary part of a complex data type. |/0 Formatting 8-21 Input Processing In an input statement, the D field descriptor transfers w characters from the external field and assigns them as a real value to the corresponding [/0 list element. The F and E field descriptors interpret and assign data in exactly the same way. The following list illustrates valid input processing using the D field descriptor: Format External Field Internal Value BZ,D10.2 12345AAAAA 12345000.0D0 D10.2 AA123 .45AA D15.3 367.4981763D+04 123.45D0 3.674981763D+06 Output Processing In an output statement, the D field descriptor has the same effect as the E field descriptor, except that the D exponent field indicator is used in place of the E indicator. The following list illustrates valid output processing using the D field descriptor: Format Internal Value D14.3 0.0363 D23.12 5413.87625793 D9.6 8.3.6.4 1.2 External Representation AAAAAQ . 363D-01 AAAAAQ . 541387625793D+04 ok ok ok ok ok ok G Field Descriptor The G field descriptor transfers real values in a form that, in effect, combines the F and E field descriptors. It takes the following form: Gw.d[Ee] The corresponding 1/0O list element must be of real data type, or it must be either the real or the imaginary part of a complex data type. 8-22 I/0 Formatting Input Processing In an input statement, the G field descriptor transfers w characters from the external field and assigns them as a real value to the corresponding 1/0 list element. The F, D, and E field descriptors interpret and assign data in exactly the same way. Output Processing In an output statement, the G field descriptor transfers the value of the corresponding I/0O list element, rounded to d decimal positions and right-justified, to an external field that is w characters long. The form in which the value is written is a function of the magnitude of the value, as described in Table 8-2. Table 8-2: Effect of Data Magnitude on G Format Conversions Data Magnitude Effective Conversion m .LT. 0.1 Ew.d[Ee] 0.1 .LE. m .LT. 1.0 F(w-4).d, n (') 1.0 .LE. m .LT. 10.0 F(w-4).(d-1), n (' ') 10%*d-2 .LE. m .LT. 10%*d-1 F(w-4).1, n(" ) 10#*d-1 .LE. m .LT. 10%=d F(w-4).0, n(" ') m .GE. 10%+d Ew.d[Ee] The n(’ ‘) field descriptor, which is in effect, inserted by the G field descriptor for values within its range, specifies that four or e+2 spaces are to follow the numeric data representation. The term w must be large enough to include all of the following: e Minus sign when necessary (plus signs are optional) * Decimal point * One digit to the left of the decimal point e d digits to the right of the decimal point » FEither a 4-character or e+2-character exponent |/0 Formatting 8-23 In other words, w must be greater than or equal to d+8. If e is present, w must be greater than or equal to d+e+6. The following list illustrates valid output processing using the G field descriptor: Format Internal Value External Representation G13.6 0.01234567 A0. 123457E-01 G13.6 -0.12345678 -0.123457AAAA G13.6 1.23456789 AA1.23457AMAA G13.6 12.34567890 AA12.3457AAAA G13.6 123.45678901 AA123 .457AAAA G13.6 -1234.56789012 A-1234 .57AAAA G13.6 12345.67890123 AA12345 . 7TAAAA G13.6 123456.78901234 AA123457 . AAAA G13.6 -1234567.89012345 -0.123457E+07 The following list shows the same values output-processed as the previous list, except the following list uses an equivalent F field descriptor: Format 8-24 Internal Value External Representation F13.6 0.01234567 AAAAAOD . 012346 F13.6 -0.12345678 AAAA-0O. 123457 F13.6 1.23456789 AAAAA1L . 234568 F13.6 12.34567890 AAAA12 345679 F13.6 123.45678901 AAA123.456789 F13.6 -1234.56789012 A-1234 .567890 F13.6 12345.67890123 A12345.678901 F13.6 123456 .78901234 123456.789012 F13.6 -1234567.89012345 sk sk sk ok ok ok ok ok ok 1/0 Formatting 8.3.6.5 Complex Data Editing A complex value is an ordered pair of real values. Therefore, input or output of a complex value is governed by two real field descriptors, using any combination of the forms Fw.d, Ew.dEe, Dw.d, or Gw.dEe. Input Processing In an input statement, the two successive fields are read and assigned to a complex /0 list element as its real and imaginary parts, respectively. The following list illustrates valid input processing using complex data editing: Format External Field Internal Value F8.5,F8.5 1234567812345 .67 123.45678, 12345.67 E9.1,F9.3 734 .432E8123456789 734 .432E8, 123456.789 Output Processing In an output statement, the two parts of a complex value are transferred under the control of repeated or successive field descriptors. The two parts are transferred consecutively without punctuation or spacing unless the format specifier states otherwise. The following list illustrates valid output processing using complex data editing. 8.3.7 Format Internal Value External Representation 2F8.5 2.3547188, 3.456732 A2 .35472 A3.45673 E9.2,'A,A" E5.3 47587 .222, 56.123 AO . 48E+06A , Ax**xx Scale Factor Editing—P Edit Descriptor During either input or output processing, the scale factor lets you alter the location of the decimal point in real values and in the two parts of complex values. The scale factor takes the following form: nP |/0 Formatting 8-25 n Is a signed or unsigned integer constant in the range -128 through 127. It specifies the number of positions, to the left or right, that the decimal point is to move. A scale factor can appear anywhere in a format specification but it must precede the first field descriptor that associates with it; for example: nPFw.d nPEw.d nPDw.d nPGw.d Input Processing On input, the scale factor associated with an F, E, D, or G field descriptor multiplies the data by 10**—n and assigns it to the corresponding 1/0 list element. For example, a 2P scale factor multiplies an input value by .01, moving the decimal point two places to the left. A -2P scale factor multiplies an input value by 100, moving the decimal point two places to the right. However, if the external field contains an explicit exponent, the scale factor has no effect. The following list illustrates valid input processing using scale factor editing: Format External Field Internal Value 3PE10.5 AAA3T .614A 3PE10.5 AA37 .614E2 3761.4 -3PE10.5 AAAA3T .614 37614.0 . 037614 Output Processing On output, the effect of the scale factor depends on the type of field descriptor associated with it. For the F field descriptor, the value of the I/0 list element is multiplied by 10**n before transfer to the external record. Thus, a positive scale factor moves the decimal point to the right. A negative scale factor moves the decimal point to the left. For the E or D field descriptor, the basic real constant part of the 1/0 list element is multiplied by 10**n, and n is subtracted from the exponent. For a positive scale factor, n must be less than (d + 2) or an output conversion error occurs. Thus, a positive scale factor moves the decimal point to the right and decreases the exponent. A negative scale factor moves the decimal point to the left and increases the exponent. 8-26 |/0 Formatting The following list illustrates valid output processing using scale factor editing;: ‘ Format Internal Value External Representation 1PE12.3 ~270.139 AA-2.701E+02 1PE12.2 -270.139 AAA-2.70E+02 -1PE12.2 -270.139 AAA-0 . 03E+04 The effect of the scale factor for the G field descriptor is suspended if the magnitude of the data to be output is within the effective range of the descriptor, because the G field descriptor supplies its own scaling function. The G field descriptor functions as an E field descriptor if the magnitude of the data value is outside its range. In this case, the scale factor has the same effect as for the E field descriptor. On input and on output under F field descriptor control, a scale factor actually alters the magnitude of the data. On output, a scale factor under E, D, or G field descriptor control merely alters the form in which the data is transferred. In addition, on input, a positive scale factor moves the decimal point to the left and a negative scale factor moves the decimal point to the right. On output, the effect is the reverse. If you do not specify a scale factor with a field descriptor, a default scale factor of zero is assumed. However, once you specify a scale factor, it applies to all subsequent real field descriptors in the same FORMAT statement, unless another scale factor appears. For example, consider the following statements: DIMENSION A(6) DO 10 I=1,6 10 A(I) = 25. 100 FORMAT(' TYPE 100, A ',F8.2,2PF8.2,F8.2) These statements produce the following results: 25.00 2500.00 2500.00 2500.00 2500.00 2500.00 If a second scale factor appears in the FORMAT statement, it takes control from the first scale factor. Format reversion has no effect on the scale factor (see Section 8.8). A scale factor of zero can be reinstated only by an explicit OP specification. I/0 Formatting 8-27 8.3.8 Logical Editing—L Edit Descriptor The L field descriptor transfers logical data. It takes the following form: Lw The corresponding 1/0 list element must have an integer or logical data type. Input Processing In an input statement, the L field descriptor transfers w characters from the external field in the following ways: e If the first nonblank characters of the field are T, t, .T, or .t, the value TRUE. is assigned to the corresponding I/O list element. e If the first nonblank characters are F, f, .F, or .f, the value .FALSE. is assigned. e If the field contains all blanks, the value .FALSE. is assigned. e If any other value is in the external field, an error occurs. The logical constants .TRUE. and .FALSE. are acceptable input forms. Output Processing In an output statement, the L field descriptor transfers either the letter T (if the value of the corresponding I/0O list element is .TRUE.) or the letter F (if the value is .FALSE.) to an external field that is w characters long. The letter T or F is in the rightmost position of the field, preceded by w-1 spaces. The following list illustrates valid output processing using logical editing;: 8-28 Format Internal Value External Representation L5 .TRUE. AAAAT L1 .FALSE. F |/0 Formatting 8.3.9 Character Editing Editing data with a character data type is controlled by the A and H field descriptors. 8.3.9.1 A Field Descriptor The A field descriptor transfers character or Hollerith values. It takes the following form: Alw] The corresponding 1/0 list element can have any data type. If it has a character data type, character data is transmitted. If it has any other data type, Hollerith data is transmitted. The value of w must be less than or equal to 32767. Input Processing In an input statement, the A field descriptor transfers w characters from the external record and assigns them to the corresponding 1/0 list element. The maximum number of characters that can be stored depends on the size of the 1/0O list element. For character I/O list elements, the size is the length of either the character variable, the character substring reference, or the character array element. For numeric [/0O list elements, the size depends on the data type, as listed in Table 8-3. I/0 Formatting 8-29 Table 8-3: Size Limit of Numeric Elements Using the A Field Descriptor I/O List Element Maximum Number of Characters el BYTE = LOGICAL=*1 N LOGICAL*2 LOGICAL*4 N INTEGER%*2 R INTEGER*4 REAL*8(DOUBLE PRECISION) Qo — REAL*16 OTM QO = REAL COMPLEX COMPLEX*16(DOUBLE COMPLEX) 16' 'Because complex values are treated as pairs of real numbers, complex data editing requires two format codes. See Section 8.3.6.5. If w is greater than the maximum number of characters that can be stored in the corresponding 1/0O list element, only the rightmost characters are assigned to that element. The leftmost excess characters are ignored. If w is less than the number of characters that can be stored, w characters are assigned to the list element, left-justified, and trailing spaces are added to fill the element. The following list illustrates valid input processing using the A field descriptor: 8-30 |/0 Formatting Internal Format External Field Representation Data Type A6 PAGEA# # CHARACTER=*1 A6 PAGEA# EA# CHARACTER=*3 A6 PAGEA# PAGEA# CHARACTER=*€ A6 PAGEA# PAGEA#AA CHARACTER=*8 A6 PAGEA# # LOGICALx*1 A6 PAGEA# A# INTEGER*2 A6 PAGEA# CEA# REAL A6 PAGEA# PAGEA#AN REAL*8 Output Processing In an output statement, the A field descriptor transfers the contents of the corresponding 1/0 list element to an external field w characters long. If w is greater than the list element size, the data appears in the field, right-justified, with leading spaces. If w is less than the list element, only the leftmost w characters are transferred. The following list illustrates valid output processing using the A field descriptor: Format Internal Value External Representation A5 OHMS AOHMS A5 VOLTS VOLTS A5 AMPERES AMPER If you omit w in an A field descriptor, a default value is supplied. If the I/0 list element has a character data type, the default value is the length of the /0 list element. If the I/O list element has a numeric data type, the default value is the maximum number of characters that can be stored in a variable of that data type. I/0 Formatting 8-31 8.3.9.2 H Field Descriptor The H field descriptor transfers data between the external record and the H field descriptor itself. It has the form of a Hollerith constant: nHc1c2c3 ... ¢cn n Is the number of characters to be transferred. C Is an ASCII character. Input Processing In an input statement, the H field descriptor transfers n characters from the external field to the field descriptor. The first character appears immediately after the letter H. Any characters in the field descriptor before input are replaced by the input characters. Output Processing In an output statement, the H field descriptor transfers n characters following the letter H from the field descriptor to the external field. 8.3.9.3 Character Constants You can use a character constant instead of an H field descriptor. Both types of format specifier function identically. In a character constant, the apostrophe is written as two apostrophes; for example: 50 FORMAT ('TODAY''SADATEAIS:A',I12,'/',12,'/',12) When you use a pair of apostrophes this way, they count as a single character. 8-32 |/0 Formatting 8.3.10 Default Field Descriptors If you write the field descriptors I, O, Z, L, F, E, D, G, or A without specifying a field width value, default values for w, d, and e are supplied based on the data type of the /O list element. Table 8-4 lists the default values for w, d, and e. Table 8—4: Default Field Descriptor Values Field Descriptor List Element 1,O,Z BYTE 1,O0,Z INTEGER*2,LOGICAL*2 [LO,Z INTEGER#*4,LOGICAL*4 w d e 12 O,Z REAL*4 12 O,Z REAL*8 23 0,Z REAL*16 44 L LOGICAL 2 F.E,G,D REAL, COMPLEX*8 15 7 FEGD REAL*8, COMPLEX*16 25 16 2 FEGD REAL*16 42 33 3 A LOGICAL*1 A LOGICAL=#2,INTEGER*2 2 A LOGICAL*4,INTEGER*4 4 A REAL*4, COMPLEX*8 4 A REAL*8, COMPLEX%*16 8 1 A REAL*16 16 A CHARACTER*n n For the A field descriptor, the default is the actual length of the corresponding [/O list element. |/0 Formatting 8-33 Positional Editing 8.3.11 Positional editing is controlled by the X, T, TL, and TR edit descriptors. On output, a T, TL, TR, or X edit descriptor does not by itself cause characters to be transmitted and therefore does not by itself affect the length of the record. If characters are transmitted to positions at or after the position specified by a T, TL, TR, or X edit descriptor, positions skipped and not previously filled are filled with blanks. The result is as if the entire record were initially filled with blanks. 8.3.11.1 X Edit Descriptor The X edit descriptor is a positional specifier. It takes the following form: nX The term n specifies how many character positions are passed over. The value of n must be greater than or equal to one. Input Processing In an input statement, the X field descriptor specifies that the next n characters in the input record are skipped. Output Processing In an output statement, the X field descriptor tabs right n spaces. It does not write over anything already written on the same record; for example: 90 WRITE (6,90) NPAGE FORMAT ('1PAGEANUMBERA',I12,16X,'GRAPHICAANALYSIS,ACONT. ') The preceding WRITE statement would print a record similar to the following output: PAGE NUMBER nn GRAPHIC ANALYSIS, CONT. The term nn is the current value of the variable NPAGE. The numeral 1 in the first character constant is not printed; it is used to advance the printer paper to the top of a new page. (Section 8.4 describes printer carriage control.) 8-34 |/0 Formatting A trailing X format on a record does not write any characters unless it is followed by another field that does; for example: WRITE 99 (6,99) FORMAT K ('AK=',16,5X) The preceding example writes a record of only 9 characters. To cause n trailing blanks to be written at the end of a record, use the format n(’a"). 8.3.11.2 T Edit Descriptor The T edit descriptor is a positional tabulation specifier. It takes the form: Tn The term n indicates the character position of the external record. The value of n must be greater than or equal to one. Input Processing In an input statement, the T field descriptor positions the external record to its nth character position. For example, if an input statement reads a record containing ABCAAAXYZ, and this record is controlled by the following format statement: 10 FORMAT (T7,A3,T1,A3) On execution, the input statement would first read the characters XYZ and then read the characters ABC. Output Processing In an output statement, the T field descriptor specifies that subsequent data transfer begins at the nth character position of the external record. The first position of a record to be printed is usually reserved for a carriage control character, which is not printed (see Section 8.4). For example: PRINT 25 25 FORMAT (T51,'COLUMN 2',T21,'COLUMN 1') These statements print the following line (assuming normal carriage control processing): Position 20 ' COLUMN 1 Position 50 v COLUMN 2 |/0 Formatting 8-35 8.3.11.3 TL Edit Descriptor The TL edit descriptor is a relative tabulation specifier. It takes the following form: TLn n Indicates that the next character to be transferred to or from a record is the nth character to the left of the current character. The value of n must be greater than or equal to one. If the value of n is greater than or equal to the current character position, the first character in the record is specified. 8.3.11.4 TR Edit Descriptor The TR edit descriptor is also a relative tabulation specifier. It takes the following form: TRn n Indicates that the next character to be transferred to or from a record is the nth character to the right of the current character. The value of n must be greater than or equal to one. 8.3.12 Additional Editing Operations Additional edit descriptors are Q, dollar sign ($), and colon (3). e The Q edit descriptor obtains the number of characters remaining e The $ edit descriptor controls carriage returns. e 8-36 1/0 Formatting following a partial read operation. The : edit descriptor terminates format control if no more items are in the 1/0 list. 8.3.12.1 Q Edit Descriptor The Q edit descriptor obtains the number of characters in the input record remaining to be transferred during a read operation. It takes the form: Q The corresponding 1/0 list element must be of integer or logical data type; for example: READ (4,1000) 1000 FORMAT XRAY, KK, NCHRS, (E15.7,14,Q,80A1) (ICHR(I), I=1,NCHRS) The preceding input statements read two fields into the variables XRAY and KK. The number of characters remaining in the record is stored in NCHRS, and exactly that many characters are read into the array ICHR. By placing the Q descriptor first in the format specification, you can determine the actual length of the input record. In an output statement, the Q edit descriptor has no effect except that the corresponding 1/0 list element is skipped. 8.3.12.2 Dollar Sign Descriptor The dollar sign character ($) in a format specification modifies the carriage control specified by the first character of the record. It only affects those files for which the 'FORTRAN' carriage control attribute is in effect (see Section 8.4). In an input statement, the $ descriptor is ignored. In an output statement, if the first character of the record is a space, the $ descriptor suppresses the carriage return. For terminal 1/0, this means that a typed response will follow the output on the same line. If the first character of the record is a plus sign, the $ descriptor causes the output to begin at the end of the previous line and leaves the print position at the end of the line. If the first character of the record is 0 or 1, the $ descriptor is ignored. Consider the following statements: TYPE 100 100 FORMAT (' ENTER RADIUS VALUE ACCEPT 200, 200 FORMAT ',$) RADIUS (F6.2) I/0 Formatting 8-37 The resulting formatted message would appear as follows: ENTER RADIUS VALUE Your response (for example, “12.”) can then go on the same line: ENTER RADIUS VALUE 8.3.12.3 12. Colon Descriptor In a format specification, the colon character (:) terminates format control if no more items are in the 1/O list. The : descriptor has no effect if I/O list items remain; for example: PRINT 1,3 PRINT 2,4 1 2 FORMAT (' I=',I2,' J=',12) FORMAT (' K=',I2,:,' L=',1I2) These statements print the following two lines: I=A3AJ= K=A4 Section 8.8 describes format control in detail. 8.4 Carriage Control Whenever the default for the OPEN statement’s CARRIAGECONTROL keyword is in effect (FORTRAN'), the first character of every record is not printed when it is transferred to a printer. Instead, it is interpreted as a carriage control character (except when overridden by the OPEN statement keyword CARRIAGECONTROL = 'LIST' or 'NONE'). The I/O system recognizes certain characters as carriage control characters. Table 8-5 lists these characters and their effects. 8-38 1/0 Formatting Table 8-5: Carriage Control Characters Character Meaning + Overprinting: starts output at the beginning of the current line and returns to the left margin after printing A Single spacing: starts output at the beginning of the next line 0 Double spacing: skips a line before starting output 1 Paging: starts output at the top of a new page $ Prompting: starts output at the beginning of the next line and suppresses carriage return at the end of the line ASCII NUL Overprinting with no advance: starts output at the beginning of the current line and does not return to the left margin after printing Any character other than those listed in Table 8-5 is treated as a space and is deleted from the print line. If you accidentally omit the carriage control character, the first character of the record is not printed. 8.5 Format Specification Separators Field descriptors in a format specification are generally separated by commas. You can also use the slash (/) record terminator to separate field descriptors. A slash terminates input or output of the current record and initiates a new record; for example: WRITE 40 FORMAT (6,40) K,L,M,N,0,P (316.6/16,2F8.4) The preceding statements are equivalent to the following statements: WRITE 40 FORMAT WRITE 50 FORMAT (6,40) K,L,M (316.6) (6,50) N,0,P (I6,2F8.4) Multiple slashes cause input records to be bypassed or blank records to be outputted. If n consecutive slashes appear between two field descriptors, (n—1) records are skipped on input, or (n-1) blank records are output. The first slash terminates the current record. The second slash terminates the first skipped or blank record, and so on. |/0 Formatting 8-39 However, n slashes at the beginning or end of a format specification result in n skipped or blank records. This is because the opening and closing parentheses of the format specification are themselves a record initiator and terminator, respectively; for example: 99 WRITE (6,99) FORMAT ('1',T51,'HEADING LINE'//T51, 'SUBHEADING LINE'//) The previous statements produce the following output: Column 50, top of page \ HEADING LINE (blank line) SUBHEADING LINE (blank line) (blank line) 8.6 External Field Separators A field descriptor such as Fw.d specifies that an input statement is to read w characters from the external record. If the data field in the external record contains fewer than w characters, the input statement reads characters from the next data field in the external record, unless the short field is padded with leading zeros or spaces. When the field descriptor is numeric, you can avoid padding the input field by using a comma to terminate the field. The comma overrides the field descriptor’s field width specification. This is called short field termination. It is particularly useful when you are entering data from a terminal keyboard. You can use it with the I, O, Z, F, E, D, G, and L field descriptors; for example: 100 READ (5,100) I,J,A.B FORMAT (216,2F10.2) If the preceding statements read the following record: 1,-2,1.0,35 Based on this input, the following assignments occur: =1 8-40 |/0 Formatting J=-2 A=10 B =0.35 The physical end of the record also serves as a field terminator. The d part of a w.d specification is not affected by an external field separator. A comma can only terminate fields less than w characters long. If a comma follows a field of w or more characters, the comma is considered part of the next field. Two successive commas or a comma after a field of w characters constitutes a null (zero-length) field. Depending on the field descriptor specified, the resulting value assigned is 0, 0.0, 0.D0, 0.Q0, or .FALSE. A comma cannot terminate a field that is controlled by an A, H, or character constant field descriptor. However, if the record reaches its physical end before w characters are read, short field termination occurs and the characters that were read are assigned successfully. spaces are appended to fill the corresponding [/0 Trailing list element or the field descriptor. 8.7 Run-Time Format You can store format specifications in character scalar references, numeric array references, or numeric scalar field references (see Section 2.2.5.1). Such a format specification is called a run-time format and can be constructed or altered during program execution. A run-time format in an array has the same form as a FORMAT statement, without the word FORMAT and the statement label. Opening and closing parentheses are required. Variable format expressions are not permitted in run-time formats. Example In the following example, the DATA statement assigns a left parenthesis to the character array element FORCHR(0) and a right parenthesis and three field descriptors to four character variables for later use. Next, the proper field descriptors are selected for inclusion in the format specification. The selection is based on the magnitude of the individual elements of the array TABLE. /0 Formatting 8-41 A right parenthesis is then added to the format specification just before the WRITE statement uses it. Thus, the format specification changes with each iteration of the DO loop. SUBROUTINE PRINT(TABLE) REAL TABLE(10,5) CHARACTER*5 FORCHR(0:5), RPAR*1, FBIG, FMED, FSML DATA FORCHR(O) ,RPAR /'(',")'/ DATA FBIG,FMED,FSML /'F8.2,','F9.4,','F9.6,'/ DO 20 I=1,10 DO 18 J=1,5 IF (TABLE(I,J) .GE. FORCHR (J) = FBIG ELSE IF (TABLE(I,J) 100.) THEN .GT. 0.1) THEN FORCHR(J) = FMED ELSE FORCHR (J) = FSML END IF CONTINUE 18 FORCHR(5) (5:5) = RPAR WRITE (6,FORCHR) 20 (TABLE(I,J), J=1,5) CONTINUE END NOTE Format specifications stored in arrays are recompiled at run time each time they are used. If a Hollerith or character run-time format is used in a READ statement to read data into the format itself, that data is not copied back into the original array. Thus, it will be subsequently unavailable for using that array as a run-time format specification. 8.8 Format Control Interaction with 1/0 Lists Format control begins with the execution of a formatted I/O statement. The action taken by format control depends on information provided jointly by the next element of the I/O list (if one exists) and the next field descriptor of the format specification. Both the I/O list and the format specification are interpreted from left to right, except when repeat counts and implied-DO lists are specified. If the 1/O statement contains an I/O list, you must specify at least one I, O,Z F E, D,G,L, A, or Q field descriptor in the format specification. An error occurs if a field descriptor is not specified in this case. 8-42 I/0 Formatting On execution, a formatted input statement reads one record from the specified unit and initiates format control. Thereafter, additional records are read as indicated by the format specification. Format control requires that a new record be read when a slash occurs in the format specification, or when the last closing parenthesis of the format specification is reached and [/O list elements remain to be filled. Any remaining characters in the current record are discarded when the new record is read. On execution, a formatted output statement transmits a record to the specified unit as format control terminates. Records can also be written during format control if a slash appears in the format specification or if the last closing parenthesis is reached and more 1/0 list elements remain to be transferred. Thel, O, Z F, E, D, G, L, A, and Q field descriptors each correspond to one element in the I/O list. No list element corresponds to an H, X, P, T, TL, TR, SP, SS, S, BN, BZ, $, :, or character constant field descriptor. In H and character constant field descriptors, data transfer occurs directly between the external record and the format specification. When an /O list element is to be transferred, format field descriptors are processed, beginning with the current format item, until a descriptor is found that corresponds to an 1/0 list element. The I/O list element is then transferred under control of the field descriptor. Format execution continues until one of the following is encountered: an element-transferring field descriptor, a colon edit descriptor, or the end of the format. These also terminate format execution when no 1/0 list elements are to be transferred. | When the last closing parenthesis of the format specification is reached, format control determines whether more 1/0 list elements are to be processed. If not, format control terminates. However, if additional list elements remain, part or all of the format specification is reused in a process called format reversion. In format reversion, the current record is terminated, a new one is initiated, and format control reverts to the group repeat specification whose opening parenthesis matches the next-to-last closing parenthesis of the format specification. If the format does not contain a group repeat spec- ification, format control returns to the initial opening parenthesis of the format specification. Format control continues from that point. I/0 Formatting 8-43 Example The following annotated example shows several interactions between the I1/0 list and the FORMAT statement. Consider a data file named FOR002.DAT: $ TYPE FOROO2.DAT 001 0101 0102 0103 0104 0105 002 0201 0202 0203 0204 0205 003 0301 0302 0303 0304 0305 004 0401 0402 0403 0404 0405 005 0501 0502 0503 0504 0505 006 0601 0602 0603 0604 0605 007 0701 0702 0703 0704 0705 008 0801 0802 0803 0804 0805 009 0901 0902 0903 0904 0905 010 1001 1002 1003 1004 1005 $ Assume that the data is to be processed 2 records at a time. Each record starts with a number to be put into an element of a vector B, followed by 5 numbers to be put in a row in matrix A. The following program uses several different FORMAT statements to read the data in FOR002.DAT: INTEGER I, J, A(2,5), B(2) 100 909 200 READ (2,100) (B(I), (A(I,J), J=1,5),1=1,2) ©@ FORMAT (2 (I3, X, 5(14,X), /) ) WRITE (6,999) B, ((A(I,J),J=1,5),I=1,2) © FORMAT (' B is ', 2(I3, X), '; 1 (r A is', / ', 5 (14, X)) ) READ (2,200) (B(I), (A(I,J), J=1,5),I1=1,2) © FORMAT (2 (I3, X, 5(I4,X), :/) ) WRITE (6.999) B, ((A(I,J),J=1,5),I=1,2) © 300 READ (2,300) (B(I), (A(I,J), J=1,5),I=1,2) ©@ FORMAT ( (I3, X, 5(14,X)) ) WRITE (6,999) B, ((A(I,J),J=1,5),1=1,2) @ 400 READ (2,400) (B(I), (A(I,J), J=1,5),1=1,2) © FORMAT ( 13, X, 5(I4.,X) ) WRITE (6,999) B, ((A(I.J),J=1,5),I=1,2) © END 8-44 I/0 Formatting Notes: This starts by reading B(1); then A(1,1) through A(1,5); then B(2) and A(2,1) through A(2,5). The first record (starting with 001) is read to start the processing of the 1/0 list. There are two records, each in the format I3, X, 5(I4, X). The / forces the reading of the second record after A(1,5) is processed; it also forces the reading of the third record after A(2,5) is processed—no data is taken from that record. This will output: B 1s 1 101 102 2 103 ; A is 104 105 201 202 203 204 205 This starts by reading the record starting with 004. The / forces the reading of the next record after A(1,5) is processed; the : stops the reading after A(2,5) is processed but before the / forces another read. This will output: Bis 4 401 402 403 b5 ; A is 404 405 501 502 503 504 505 This starts by reading the record starting with 006. After A(1,5) is processed, format reversion reads the next record and starts format processing at the ( before the I3. This will output: Bis 6 601 602 7 603 ,; A is 604 605 701 702 703 704 705 This starts by reading the record starting with 008. After A(1,5) is processed, format reversion reads the next record and starts format processing at the ( before the 14. This will output: Bis 8 801 802 90 ; 803 A is 804 9010 9020 9030 9040 805 100 |/0 Formatting 8-45 The record 009 0901 0902 0903 0904 0905 was processed with 14 as “009 ” for B(2), which is 90; X skips the next “0”; then "901 ” is processed for A(2,1), which is 9010; "902 ” for A(2,2); "903 ” for A(2,3); and "904 ” for A(2,4). The repetition factor of 5 is now exhausted and the format ends. Format reversion reads another record and starts format processing at the ( before the 14 so that “010 ” is read for A(2,5), which is 100. 8-46 |/0 Formatting Chapter 9 Auxiliary 1/0 Statements The following auxiliary I/O statements manage files during I/O operations: OPEN—connects a FORTRAN logical unit to a file or device; declares required attributes for read and write operations (see Section 9.1). CLOSE—terminates the connection between a logical unit and a file or device (see Section 9.2). INQUIRE—questions the status of specified properties of a file or logical unit (see Section 9.3). REWIND—repositions an open file to the beginning of that file (see Section 9.4). BACKSPACE—repositions an open file to the beginning of the preceding record in that file (see Section 9.5). ENDFILE—writes an end-of-file record to a specified unit. When an input statement reads this record, an end-of-file condition results (see Section 9.6). DELETE—deletes a record from a file (see Section 9.7). UNLOCK—permits other programs to access a file that is locked by a previous READ statement (see Section 9.8). Auxiliary 1/0 Statements 9-1 9.1 OPEN Statement The OPEN statement connects an existing file to a logical unit or creates a new file and connects it to a logical unit. In addition, it can specify file attributes that control file creation and subsequent processing. The OPEN statement takes the following form: OPEN (par(,par]...) par Is a keyword specification taking one of the following forms: keywd keywd = value keywd Is a keyword, as described in the text that follows (see also Table 9-1). value Depends on the keyword (see Table 9-1). Keywords can be divided into several categories based on function: * * 9-2 Identifying the unit and file: UNIT — logical unit number to be used FILE or NAME — file-name specification for the file DEFAULTFILE — default file-name specification for the file STATUS or TYPE - file existence status at OPEN DISPOSE — file existence status after CLOSE Describing file processing: ACCESS — FORTRAN access method to be used ORGANIZATION — logical file structure READONLY — write protection Auxiliary 1/0 Statements * * * * Describing the records in a file: BLOCKSIZE - physical block size CARRIAGECONTROL — printer control type FORM — type of FORTRAN record formatting RECL or RECORDSIZE - logical record length RECORDTYPE — logical record format BLANK — blank interpretation for numeric input KEY — positions of key fields within records in an indexed file Describing file storage allocation when a file is created: INITIALSIZE - initial file allocation EXTENDSIZE — file allocation increment size Providing additional capability for direct access 1/0: ASSOCIATEVARIABLE - the next record number value MAXREC - maximum direct access record number Providing improved performance or special capabilities; (these optional keywords are generally transparent to I/O processing): BUFFERCOUNT — number of 1/0 buffers to be used NOSPANBLOCKS — records are not to be split across physical blocks USEROPEN — user program option to provide additional OPEN capability SHARED — other programs can simultaneously access the file ERR - statement to which control is transferred if an error occurs during execution of the OPEN statement IOSTAT — status value that indicates whether an error condition exists Table 9-1 lists the values accepted for each keyword. Auxiliary 1/0 Statements 9-3 Table 9-1: OPEN Statement Keyword Values Keyword Values Function Default ACCESS 'SEQUENTIAL' Access mode 'SEQUENTIAL' ASSOCIATEVARIABLE asv 'DIRECT’ '"KEYED' 'APPEND’ Next direct access record BLANK 'NULL' ‘ZERO’ Interpretation of blanks 'NULL' BLOCKSIZE e Physical block size System default BUFFERCOUNT e Number of 1/0 buffers System default CARRIAGECONTROL 'FORTRAN’ Print control "LIST’ 'NONE' 'FORTRAN’ (formatted) 'NONE' (unformatted) DEFAULTFILE cl Default file specification DISPOSE DISP 'KEEP’ or ‘SAVE' 'DELETE’ 'PRINT’ 'PRINT/DELETE’ 'SUBMIT’ 'SUBMIT /DELETE’ File disposition at close ERR S Error transfer label 'KEEP’ Key to Values asv—an integer variable v—an integer scalar memory reference e—a numeric expression s—a statement label dt—a data type, INTEGER or CHARACTER dr—direction, ASCENDING or DESCENDING c—a character scalar reference, numeric scalar memory reference, or numeric array name reference cl—a character expression el—the first byte position of a key e2—Ilast byte position of a key p—an external function 9-4 Auxiliary 1/0 Statements Table 9-1 (Cont.): OPEN Statement Keyword Values Keyword Values Function Default EXTENDSIZE e File allocation increment Volume or system default FILE C NAME FORM File-name specification 'FORMATTED’ 'UNFORMATTED' Format type INITIALSIZE e File allocation IOSTAT \ I/0 status KEY (el:e2[:dt[:dr]],...) Key field definitions Depends on ACCESS keyword CHARACTER ASCENDING MAXREC e Direct access record limit NOSPANBLOCKS - Records do not span blocks ORGANIZATION 'SEQUENTIAL' File structure READONLY - Write protection RECL e Record length 'RELATIVE’ 'INDEXED’ RECORDSIZE 'SEQUENTIAL' Depends on record type and file organization Key to Values asv—an integer variable v—an integer scalar memory reference e—a numeric expression s—a statement label dt—a data type, INTEGER or CHARACTER dr—direction, ASCENDING or DESCENDING c—a character scalar reference, numeric scalar memory reference, or numeric array name reference cl—a character expression el—the first byte position of a key e2—Ilast byte position of a key p—an external function Auxiliary 1/0 Statements 9-5 Table 9-1 (Cont.): OPEN Statement Keyword Values Keyword Values Function Default RECORDTYPE 'FIXED' 'VARIABLE' Record structure Depends on ORGANIZATION, 'SEGMENTED' ACCESS, and 'STREAM’ 'STREAM_CR’ 'STREAM_LF FORM keywords SHARED - File sharing allowed STATUS 'OLD’ File status at open TYPE 'NEW' 'UNKNOWN' 'SCRATCH' 'UNKNOWN' UNIT e Logical unit number USEROPEN p User program option Key to Values asv—an integer variable v—an integer scalar memory reference e—a numeric expression s—a statement label dt—a data type, INTEGER or CHARACTER dr—direction, ASCENDING or DESCENDING c—a character scalar reference, numeric scalar memory reference, or numeric array name reference cl—a character expression el—the first byte position of a key e2—Ilast byte position of a key p—an external function Specifying OPEN Statement Keywords Keyword specifications can appear in any order. In most cases, they are optional. Default values apply in their absence. If the logical unit specifier is the first parameter in the list, the UNIT keyword is optional. You can specify character values at run time by substituting a general character expression for a keyword value in the OPEN statement. The character value can contain trailing spaces but not leading or embedded spaces; for example: 9-6 Auxiliary 1/0 Statements CHARACTER*7 QUAL /' IF (exp) OPEN QUAL = (UNIT=1, '/ '/DELETE' STATUS='NEW', DISP='SUBMIT'//QUAL) Examples The first statement creates a new sequential formatted file on unit 1 with the default file name FOR001.DAT. OPEN (UNIT=1, STATUS='NEW', ERR=100) The next statement creates a 50-block direct access file for temporary storage. The file is deleted at program termination. OPEN (UNIT=3, 1 STATUS='SCRATCH', ACCESS='DIRECT', INITIALSIZE=50, RECL=64) The next statement creates a file on magnetic tape with a large block size for efficient processing. OPEN (UNIT=I, 1 STATUS='NEW', 1 RECORDTYPE='FIXED") FILE='MTAO:MYDATA.DAT', ERR=14, BLOCKSIZE=8192, RECL=1024, The next statement opens the file created in the previous example for input. OPEN (UNIT=I, 1 STATUS='0LD', 1 BLOCKSIZE=8192) FILE='MTAO:MYDATA.DAT', RECL=1024, READONLY, RECORDTYPE='FIXED', The next statement uses the file name supplied by the user and the default file specification supplied by the DEFAULTFILE keyword to define the file specification for an existing file. TYPE *, 'ENTER NAME OF DOCUMENT' ACCEPT *, DOC OPEN (UNIT=1, 1 STATUS='0LD"') FILE=DOC, DEFAULTFILE='[ARCHIVE].TXT', The following sections provide specific information about OPEN statement keywords. As used in these sections, a numeric expression can be any integer or real expression. The value of the expression is converted to integer data type before it is used in the OPEN statement. Auxiliary 1/0 Statements 9-7 9.1.1 ACCESS Keyword The ACCESS parameter specifies whether a file opens for keyed, direct, or sequential access. It takes the following form: ACCESS = acc acc Is a character expression having one of the following values: e 'DIRECT'—by record number e 'SEQUENTIAL'—by sequential access e 'KEYED'—Dby a specified key e 'APPEND’'—sequentially, after the last record of the file The default is 'SEQUENTIAL'. 9.1.2 ASSOCIATEVARIABLE Keyword The ASSOCIATEVARIABLE parameter specifies the integer variable that updates after each direct access 1/0O operation to reflect the record number of the next sequential record in the file. This specifier is valid only for direct access and is ignored for other access modes. It takes the following form: ASSOCIATEVARIABLE = asv asv Is an integer variable. It cannot be a dummy argument to the routine in which the OPEN statement appears. 9.1.3 BLANK Keyword The BLANK parameter specifies how empty spaces are treated in a file. It takes the following form: BLANK = blnk 9-8 Auxiliary 1/0 Statements bink Is a character expression with one of the following values: * ’'NULL'—ignore all blanks in a numeric field (except if the field is all blank, in which case blanks are treated as zero) * 'ZERO’—treat all blanks other than leading blanks as zeros The default value is 'NULL'. However, if the /NOF77 qualifier is specified on the FORTRAN command line, the default is 'ZERO'. 9.1.4 BLOCKSIZE Keyword The BLOCKSIZE parameter specifies the physical 1/0 transfer size for the file. It takes the following form: BLOCKSIZE = bks bks Is a numeric expression. For magnetic tape files, the value of bks specifies the physical record size in the range 18 to 32767 bytes. The default value is 2048 bytes. For sequential disk files, the value of bks is rounded up to an integral number of 512-byte blocks and used to specify multiblock transfers. The number of blocks transferred can be 1 to 127. The number of blocks transferred is determined by RMS defaults. Refer to the description of the SET RMS_DEFAULT command in the VMS DCL Dictionary for more information on setting process and system default multiblock counts if you do not specify a block size. For relative and indexed files, the value of bks is rounded up to an integral number of 512-byte blocks and used to specify the RMS bucket size in the range 1 to 63 blocks. The default is the smallest value capable of holding a single record. 9.1.5 BUFFERCOUNT Keyword The BUFFERCOUNT parameter specifies the number of buffers to be as- sociated with the logical unit for multibuffered 1/0. It takes the following form: BUFFERCOUNT = bc Auxiliary 1/0 Statements 9-9 bc [s a numeric expression. The range of values for bc is from 1 to 127. The size of each buffer is determined by the BLOCKSIZE keyword. Thus, if BUFFERCOUNT=3 and BLOCKSIZE=2048, the total number of bytes allocated for buffers is 3%2048, or 6144. The BLOCKSIZE keyword determines the size of each buffer. If you do not specify BUFFERCOUNT, or if you specify zero, the system default is assumed. Refer to the description of the SET RMS_DEFAULT command in the VMS DCL Dictionary for information on setting process and system default buffer counts. 9.1.6 CARRIAGECONTROL Keyword The CARRIAGECONTROL parameter determines the type of carriage control processing used when printing a file. It takes the following form: CARRIAGECONTROL = cc cC Is a character expression taking one of the following values: e 'FORTRAN'—normal FORTRAN interpretation of the first character e 'LIST'—single spacing between records e 'NONE'—no implied carriage control The default for formatted files is 'FORTRAN’; for unformatted files, the default is ‘'NONE'. 9.1.7 DEFAULTFILE Keyword The DEFAULTFILE parameter specifies a default file specification string. It takes the following form: DEFAULTFILE = ce 9-10 Auxiliary |/0 Statements ce Is a character expression that contains a default file name specification string. This keyword can supply a value to the RMS default file specification string for the missing components of a file specification. If you do not specify the DEFAULTFILE keyword, FORTRAN uses the default value 'FORnnn.DAT’, where nnn is the unit number with leading zeros. The default file specification string is used primarily when accepting file specifications interactively. File specifications known to a user program are normally completely specified in the FILE keyword. You can specify default values for any one of the following filespecification components: * Node * Device * Directory * File name * Tile type e File version number When you specify any of the above components in the FILE=keyword, they override those values specified in the DEFAULTFILE=keyword. Refer to the VMS Record Management Services Manual for more information. 9.1.8 DISPOSE Keyword The DISPOSE (or DISP) parameter determines the disposition of the file connected to a logical unit when the unit closes. It takes one of the following forms: DISPOSE = dis DISP = dis dis Is a character expression having one of the following values: * 'KEEP’ or 'SAVE’'— retain the file after the unit closes * 'DELETE’—delete the file after the unit closes * 'PRINT'—submit the file to the system line printer spooler and retain it Auxiliary 1/0 Statements 9-11 e e e 'PRINT/DELETE'—submit the file to the system line printer spooler and then delete it 'SUBMIT —submit the file to the batch job queue and retain it 'SUBMIT/DELETE'—submit the file to the batch job queue and then delete it A read-only file cannot be deleted. A scratch file cannot be saved, printed, or submitted. The default is 'KEEP’ or ‘'SAVE'. ERR Keyword 9.1.9 The ERR parameter identifies the executable statement that receives control when an error occurs. It takes the following form: ERR = s S Is the label of an executable statement. The ERR parameter applies only to the OPEN statement in which it is specified and not to subsequent 1/O operations on the unit. If an error occurs, no file is opened or created. 9.1.10 EXTENDSIZE Keyword The EXTENDSIZE parameter specifies the number of blocks by which to extend a disk file when additional storage space is allocated. It takes the following form: EXTENDSIZE = es es I[s a numeric expression. If you do not specify EXTENDSIZE or if you specify zero, the system default for the device is used. See Section 9.1.13 for a discussion about the relationship between the EXTENDSIZE keyword and the INITIALSIZE keyword. 9-12 Auxiliary I/0 Statements 9.1.11 FILE Keyword The FILE parameter specifies the name of the file to be connected to the unit. It takes the following form: FILE = fln fin Is a character scalar reference, numeric scalar memory reference, or numeric array name reference. The name of a file can be any specification accepted by the operating system. (See the VAX FORTRAN User Manual for a description of default file name conventions.) If the file name is stored in a numeric scalar or array, the name must consist of ASCII characters terminated by an ASCII null character (zero byte). However, if it is stored in a character scalar or array, it must not contain a zero byte. 9.1.12 FORM Keyword The FORM parameter specifies whether the file being opened is read or written using formatted or unformatted READ or WRITE statements. It takes the following form: FORM = ft ft Is a character expression taking one of the following values: * 'FORMATTED' o 'UNFORMATTED' The default is 'FORMATTED' for sequential access files, and 'UNFORMATTED' for direct and keyed access files. Auxiliary 1/0 Statements 9-13 9.1.13 INITIALSIZE Keyword The INITIALSIZE parameter specifies the number of blocks in the initial storage allocation for a disk file. It is contracted by the EXTENDSIZE parameter, which specifies the number of blocks by which a disk file is extended each time more space is needed for a file. The INITIALSIZE parameter takes the following form: INITIALSIZE = insz insz Is a numeric expression. If you do not specify INITIALSIZE or if you specify zero, no initial allocation is made. The system attempts to allocate contiguous space for INITIALSIZE. If not enough contiguous space is available, noncontiguous space is allocated. INITIALSIZE is effective only at the time the file is created. If EXTENDSIZE is specified when the file is created, the value specified is the default value used to allocate additional storage for the file. If you specify EXTENDSIZE when you open an existing file, the value you specify supersedes any EXTENDSIZE value specified when the file was created, and remains in effect until you close the file. Unless specifically overridden, the default EXTENDSIZE value is in effect on subsequent openings of the file. 9.1.14 I0STAT Keyword The IOSTAT parameter specifies /O status. It takes the following form: IOSTAT = ios ios Is an integer scalar memory reference. This parameter causes ios to be defined as follows: 9-14 e Zero—if no error condition exists * A positive integer—if an error condition exists Auxiliary 1/0 Statements VAX FORTRAN I/O status values are described in the VAX FORTRAN User Manual. IOSTAT applies only to the OPEN statement in which it appears and not to subsequent I/O operations on the logical unit that is opened. However, you can use the IOSTAT parameter in subsequent 1/0 statements to perform a similar function (see Section 7.1.1.9). 9.1.15 KEY Keyword The KEY parameter defines the access keys for records in an indexed file. It takes the following form: KEY = (kspec[,kspec]...) kspec Takes the following form: el:e2[:dt[:dr]] el Is the first byte position of the key. e2 Is the last byte position of the key. dt Is the data type of the key: INTEGER or CHARACTER. dr Is the direction of the key: ASCENDING or DESCENDING. CHARACTER and ASCENDING are the default values. The key starts at position el in a record and has a length of €2 — el + 1. The values of el and e2 must be such that the following calculations are true: 1 .LE. (e1) 1 .LE. (e2-el+1) .AND. (el) .AND. .LE. (e2) (e2-e1+1) .AND. .LE. (e2) .LE. record-length 255 If the key type is INTEGER, the key length must be either 2 or 4. Auxiliary 1/0 Statements 9-15 Defining Primary and Alternate Keys You must define at least one key in an indexed file. This primary key is the default key. It usually has a unique value for each record. You can choose to define alternate keys. RMS allows up to 254 alternate keys. However, individual OPEN statements only allow up to 85 key definitions, a number that is further reduced when multiple OPEN statements appear together in a program unit. If a file requires more keys than the OPEN statement limit, you must create it from another language or with the File Definition Language (FDL). For information on FDL, see the VMS Record Management Services Manual. Specifying and Referencing Keys You must specify the KEY parameter when creating an indexed file. However, you do not have to respecify it when opening an existing file because key attributes are permanent aspects of the file. These attributes include key definitions and reference numbers for subsequent I/O operations. If you do choose to specify the KEY parameter for an existing file, your specification must be identical to the established key attributes. Subsequent 1/0 operations use a reference number, called the key-ofreference number, to identify a particular key. You do not specify this number; it is determined by the key’s position in the specification list: the primary key is key-of-reference number 0; the first alternate key is key-of-reference number 1, and so forth. 9.1.16 MAXREC Keyword The MAXREC parameter applies only to direct access files. It specifies the maximum number of records permitted in a direct access file. The MAXREC parameter takes the following form: MAXREC = mr mr Is a numeric expression. The default is an unlimited number of records. 9-16 Auxiliary 1/0 Statements 9.1.17 NAME Keyword NAME is a nonstandard synonym for FILE. See Section 9.1.11. 9.1.18 NOSPANBLOCKS Keyword The NOSPANBLOCKS parameter specifies that records are not to cross disk block boundaries. It takes the following form: NOSPANBLOCKS When you specify this parameter, an error occurs if any record exceeds the size of a physical block. 9.1.19 ORGANIZATION Keyword The ORGANIZATION parameter specifies the internal organization of the file. It takes the following form: ORGANIZATION = org org Is a character expression with one of the following values: e 'SEQUENTIAL'’ e 'RELATIVE’ e 'INDEXED’ The default file organization is sequential. However, if you omit the ORGANIZATION keyword when you open an existing file, the organization already specified in that file is used. If you specify ORGANIZATION for an existing file, org must have the same value as that of the existing file. Auxiliary 1/0 Statements 9-17 9.1.20 READONLY Keyword The READONLY parameter specifies that an existing file can be read and prohibits writing to that file. It takes the following form: READONLY The FORTRAN 1/0 system’s default file access privileges are readwrite, which can cause run-time I/O errors if the file protection does not permit write access. The READONLY keyword has no effect on the protection specified for a file. Its main purpose is to allow a file to be read simultaneously by two or more programs. For example, if you wish to open a file for the purpose of reading the file but want to allow others to read the same file while you have it open, specify the READONLY keyword. Refer to the VAX FORTRAN User Manual for information on file sharing. 9.1.21 RECL Keyword The RECL parameter specifies the length of logical records in a file. It takes the following form: RECL = rl rl Is a numeric expression indicating the length of logical records in the file. The value of 1l does not include space for control information, such as for two segment control bytes (if present) or the bytes that RMS requires for maintaining record length and deleted record control information. The specification is for record data only. The value of 1l is expressed in units of bytes or longwords, depending on the record’s format. Formatted records use byte units and unformatted records use longword units (which are equal to 4 bytes). Table 9-2 lists the maximum values that can be specified for rl, based on file organization and record format. 9-18 Auxiliary I/0 Statements Table 9-2: Record Size (RECL) Limits Record Format File Organization Unformatted Formatted (bytes) (longwords) Sequential 32766 8191 Sequential and variable- 9999! 2499! 16380 4095 length records on ANSI magnetic tape Relative and indexed "Limit imposed by 4-byte ASCII count field. RECL is mandatory when opening files with fixed-length records or relative or indexed organization; it is optional when opening all other types. Default values for optional cases depend on the value of the RECORDTYPE parameter. Table 9-3 lists the RECL default values. Table 9-3: Record Size (RECL) Default Values RECORDTYPE value RECL value 'FIXED' none; value must be explicitly specified 'SEGMENTED'’ 2048 All other types 133 The interpretation and effect of the logical record length varies as follows: e [f the file contains fixed-length records, RECL specifies the size of each record. * If the file contains variable-length records, RECL specifies the maximum length for any record. * If your program attempts to write to an existing file a record that is longer than the logical record length, an error occurs. * If you are opening an existing file that contains fixed-length records or that has relative organization and you specify a value for RECL that is different from the actual length of the records in the file, an error occurs. Auxiliary 1/0 Statements 9-19 9.1.22 RECORDSIZE Keyword RECORDSIZE is a nonstandard synonym for RECL; refer to Section 9.1.21 for more information. 9.1.23 RECORDTYPE Keyword The RECORDTYPE parameter specifies whether the file has fixed-length records, variable-length records, segmented records, or stream-type variable-length records. It takes the following form: RECORDTYPE = typ Itsyg character expression with one of the following values: e 'FIXED' e 'VARIABLE' e 'SEGMENTED’ e 'STREAM' e 'STREAM_CR’ e 'STREAM_LF When you create a file, default record types are as follows: File Type Default Record Type Relative or indexed files 'FIXED' Direct access sequential files 'FIXED' Formatted sequential access files 'VARIABLE' Unformatted sequential access files 'SEGMENTED' A segmented record consists of one or more variable-length records. Using segmented records allows a FORTRAN logical record to span several physical records. Only unformatted sequential access files with sequential organization can use segmented records. You cannot specity 'SEGMENTED' for any other file type. §-20 Auxiliary 1/0 Statements If you do not specify the RECORDTYPE parameter when you are accessing an existing file, the record type of the file is used— except for unformatted sequential-access files with sequential organization and variable-length records. These files have a default of 'SEGMENTED'. If you do specify the RECORDTYPE parameter when you are accessing an existing file, the type that you specify must match the type of an existing file. In fixed-length record files, if an output statement does not specify a full record, the record is filled with spaces in a formatted file and zeros in an unformatted file. You cannot use an unformatted READ statement to access an unformatted sequential organization file containing variable-length records, unless you specify the corresponding RECORDTYPE value in your OPEN statement. Files containing segmented records can be accessed only by unformatted sequential FORTRAN I/0 statements. 9.1.24 SHARED Keyword The SHARED parameter specifies that the file can be opened for shared access by more than one program executing simultaneously. It takes the following form: SHARED For information on file sharing, see the VAX FORTRAN User Manual. 9.1.25 STATUS Keyword The STATUS parameter specifies the status of the file that you wish to open. It takes the following form: STATUS = sta sta Is a character expression with one of the following values: * 'OLD’—the file must already exist. o 'NEW’'—a new file is created. * '‘SCRATCH'—a new file is created and is deleted when it closes. Auxiliary 1/0 Statements 9-21 e 'UNKNOWN'—the processor first tries ‘'OLD’; if the file is not found, the processor uses 'NEW’, thereby creating a new file. The default is 'UNKNOWN'. However, if you specify the /NOF77 qualifier on the FORTRAN command line, the default value specified by the compiler is 'NEW'. NOTE The STATUS parameter is also used in CLOSE statements to specify the status of a file after the file is closed. However, the values it uses are different from those used in OPEN statements. 9.1.26 TYPE Keyword TYPE is a nonstandard synonym for STATUS. See Section 9.1.25. 9.1.27 UNIT Keyword The UNIT parameter specifies the logical unit that connects to the file. It takes the following form: [UNIT=] u u Is a numeric expression. The unit specification must appear in the parameter list unless the unit specifier occupies the first position in the list. The logical unit may already be connected to a file when an OPEN statement is executed. If this file is not the same as the one to be opened, the OPEN statement executes as if a CLOSE statement had executed just before it. If the file to be opened is already connected to the unit, or if the file specifier (FILE keyword) is not included in the OPEN statement, only the blank specifier (BLANK keyword) can have a value different from the one currently in effect. The position of the file is unaffected. See the VAX FORTRAN User Manual for additional information about logical unit numbers. 9-22 Auxiliary 1/0 Statements 9.1.28 USEROPEN Keyword The USEROPEN parameter specifies a user-written external function that controls the opening of the file. It takes the following form: USEROPEN = procedure-name procedure-name Is the symbolic name of the USEROPEN procedure. The procedure name must be declared EXTERNAL. Knowledgeable users can employ additional features of the operating system that are not directly available from FORTRAN, while retaining the convenience of writing programs in FORTRAN. See the VAX FORTRAN User Manual for more information on USEROPEN. 9.2 CLOSE Statement The CLOSE statement disconnects a file from a unit. It takes the following form: STATUS CLOSE ([UNIT=]ul[, { DISPOSE; =p][,ERR=s] [, I0STAT=io0s]) DISP u Is a logical unit number. p Is a character expression that determines the disposition of the file. It can be any one of the following values: e 'SAVE' or 'KEEP'— retain the file after the unit closes e 'DELETE'- delete the file * 'PRINT'- submit the file to the line printer spooler and retain it e 'PRINT/DELETE’—submit the file to the line printer spooler and then delete it * 'SUBMIT'- submit the file to the batch job queue and retain it e 'SUBMIT/DELETE'—submit the file to the batch job queue and then delete it Auxiliary |/0 Statements 9-23 The default is 'DELETE’ for scratch files. For all other files, the default is 'KEEP'. s Is the label of an executable statement. ios Is an integer scalar memory reference. Syntax Rules and Behavior CLOSE statement parameters can occur in any order. The UNIT keyword is optional only if the unit specifier is the first parameter in the list. The disposition specified in a CLOSE statement supersedes the disposition specified in the OPEN statement, except that a file opened as a scratch file cannot be saved, printed, or submitted, and a file opened for read-only access cannot be deleted. For example, the following statement closes the file on unit 1 and submits it for printing;: CLOSE (UNIT=1, STATUS='PRINT') The next statement closes the file on unit | and deletes it: CLOSE (UNIT=J, STATUS='DELETE', ERR=99) 9.3 INQUIRE Statement The INQUIRE statement “asks” about specified properties of a file or of a logical unit on which a file might be opened. It takes two forms, one for inquiring by file and the other for inquiring by unit: Inquiring by File INQUIRE (FILE=fil ,DEFAULTFILE=dfi...] ,flist) Inquiring by Unit INQUIRE ([UNIT=]u,flist) 9-24 Auxiliary |/0 Statements fi Is a character expression, numeric scalar memory reference, or numeric array name reference whose value specifies the name of the file to be inquired about. dfi Is a character expression specifying a default file name specification string, flist Is a list of property specifiers in which any one specifier appears only once. The specifiers are described in the following sections. u Is the number of the logical unit to be inquired about. The unit does not have to exist, nor does it need to be connected to a file. If the unit is connected to a file, the inquiry encompasses both the connection and the file. Syntax Rules and Behavior FILE=fi and UNIT=u can appear anywhere in the property-specifier list; however, if the UNIT keyword is omitted, the unit specifier (u) must be the first parameter in the list. 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 a file is open with both FILE and DEFAULTFILE keywords specified in the OPEN statement, then you can inquire about this file by specifying both the FILE and DEFAULTFILE keywords in the INQUIRE statement. An INQUIRE statement may be executed before, during, or after the connection of a file to a unit. The values assigned by the statement are those that are current when the INQUIRE statement executes. 9.3.1 ACCESS Specifier The ACCESS specifier takes the following form: ACCESS = acc Auxiliary 1/0 Statements 9-25 acc Is a character scalar memory reference that is assigned one of the following values: 9.3.2 » SEQUENTIAL—if the file is open for sequential access e DIRECT—if the file is open for direct access e KEYED—if the file is open for keyed access ¢ UNKNOWN—if no connection exists BLANK Specifier The BLANK specifier takes the following form: BLANK = blk blk Is a character scalar memory reference that is assigned one of the following values: e NULL—if null blank control is in effect for a file open for formatted 1/0 e ZERO—if zero blank control is in effect e UNKNOWN—if no connection exists or if the connection is not for formatted I/0 9.3.3 CARRIAGECONTROL Specifier The CARRIAGECONTROL specifier takes the following form: CARRIAGECONTROL = cc cc Is a character scalar memory reference that is assigned one of the following values: §-26 e FORTRAN—if the file has FORTRAN carriage control e LIST—if the file has implied carriage control e NONE—if the file has no carriage control attribute e UNKNOWN—if no other values apply Auxiliary 1/0 Statements 9.3.4 DIRECT Specifier The DIRECT specifier takes the following form: DIRECT = dir dir Is a character scalar memory reference that is assigned one of the following values: 9.3.5 e YES—if direct access is allowed for the file e NO—if direct access is not allowed e UNKNOWN—if the processor cannot determine whether direct access is allowed ERR Specifier The ERR specifier takes the following form: ERR = s s [s the label of an executable statement. The ERR specifier is a control specifier rather than a property specifier. If an error occurs during execution of the INQUIRE statement, control is transferred to the statement whose label is s. 9.3.6 EXIST Specifier The EXIST specifier takes the following form: EXIST = ex ex Is a logical scalar memory reference that is assigned one of the following values: * * . TRUE.—if the specified file or unit exists _FALSE.—if the specified file or unit does not exist or the file cannot be opened even though it exists Auxiliary 1/0 Statements 9-27 9.3.7 FORM Specifier The FORM specifier takes the following form: FORM = fm fm Is a character scalar memory reference that is assigned one of the following values: 9.3.8 e FORMATTED—if the file is open for formatted 1/O e UNFORMATTED—Iif the file is open for unformatted /0 e UNKNOWN—if no connection exists FORMATTED Specifier The FORMATTED specifier takes the following form: FORMATTED = fmd fmd Is a character scalar memory reference that is assigned one of the following values: e YES—if formatted is an allowed form for the file e NO—if formatted is not an allowed form e 9.3.9 UNKNOWN—if the processor is unable to determine whether formatted is an allowed form I10STAT Specifier The IOSTAT specifier takes the following form: IOSTAT = 1o0s 9-28 Auxiliary I/0 Statements ios Is an integer scalar memory reference. The IOSTAT specifier is a control specifier rather than a property specifier. Ios can be assigned one of the following values: 9.3.10 e [f an error occurs during execution of the INQUIRE statement, it takes a processor-dependent positive integer value. e [f no error occurs, it takes a ZERO value. KEYED Specifier The KEYED specifier takes the following form: KEYED = kyd kyd Is a character scalar memory reference that is assigned one of the following values: e YES—if keyed access is allowed for the file (The file must be indexed.) e NO-—if keyed access is not allowed e UNKNOWN—if the processor is unable to determine whether keyed access is allowed 9.3.11 NAME Specifier The NAME specifier takes the following form: NAME = nme nme Is a character scalar memory reference that is assigned the name of the file being inquired about. If the file does not have a name, nme is undefined. The value assigned to nme is not necessarily identical to the value specified with the FILE keyword. For example, the value that the processor returns may be qualified by a directory name or a version number. However, the value that is assigned is always valid with the FILE keyword in an OPEN statement. Auxiliary 1/0 Statements 9-29 NOTE The FILE and NAME keywords are synonyms when used with the OPEN statement, but not when used with the INQUIRE statement. 9.3.12 NAMED Specifier The NAMED specifier takes the following form: NAMED = nmd nmd Is a logical scalar memory reference that is assigned one of the following values: 9.3.13 e _TRUE.—if the specified file has a name e FALSE.—if it does not have a name NEXTREC Specifier The NEXTREC specifier takes the following form: NEXTREC = nr nr Is an integer scalar memory reference that is assigned one of the following values: * If a record was previously read or written on the specified unit, the value of nr is one more than the number of that record. e If no records have been read or written, the value of nr is one. e [f the file is not opened for direct access or if the position is indetermi- nate because of an error condition, nr is zero. 9.3.14 NUMBER Specifier The NUMBER specifier takes the following form: NUMBER = num 9-30 Auxiliary I/0 Statements num Is an integer scalar memory reference. Num is assigned the number of the logical unit currently connected to the specified file. If there is no logical unit connected to the file, num is not defined. 9.3.15 OPENED Specifier The OPENED specifier takes the following form: OPENED = od od Is a logical scalar memory reference that is assigned one of the following values: e .TRUE.—if the specified file is open on a unit or if the specified unit is open e 9.3.16 FALSE.—if the specified file or unit is not open ORGANIZATION Specifier The ORGANIZATION specifier takes the following form: ORGANIZATION= org org Is a character scalar memory reference that is assigned one of the following values: * SEQUENTIAL—If the file is a sequential file * RELATIVE—if the file is a relative file e INDEXED—if the file is an indexed file e UNKNOWN-—if the processor is unable to determine the file’s organization Auxiliary 1/0 Statements 9-31 9.3.17 RECL Specifier The RECL specifier takes the following form: RECL = rcl rcl Is an integer scalar memory reference taking one of the following values: If the file or unit is open, rcl is the maximum record length allowed in the file. If the file is not open, rcl is the maximum record length allowed in the file; or, if the maximum record length is 0, rcl is the length of the longest record in the file. If inquiring about a file that has no maximum record size, see Section 9.1.21. If the file is segmented, rcl is the longest segment length in the file. If a specified file does not exist, rcl is zero. The rcl value is expressed in longwords if a file is (or has been) opened for unformatted I/O; and in bytes in all other circumstances. 9.3.18 RECORDTYPE Specifier The RECORDTYPE specifier takes the following form: RECORDTYPE = rtype rtype Is a character scalar memory reference that is assigned one of the following values: FIXED—if the file is open for fixed-length records VARIABLE—if the file has variable-length records SEGMENTED—if the file is open for unformatted sequential 1/0 using segmented records STREAM—if the file’s records are terminated with a carriage-return and line-feed STREAM _CR—if carriage-return 9-32 Auxihary 1/0 Statements the file's records are terminated only with a 9.3.19 * STREAM_LF—if the file's records are terminated only with line-feed e UNKNOWN—if the processor cannot determine the record type SEQUENTIAL Specifier The SEQUENTIAL specifier takes the following form: SEQUENTIAL = seq seq Is a character scalar memory reference that is assigned one of the following values: 9.3.20 * YES—if sequential access is allowed for the specified file * NO—if sequential access is not allowed * UNKNOWN—if the processor cannot determine whether sequential access is allowed UNFORMATTED Specifier The UNFORMATTED specifier takes the following form: UNFORMATTED = unf unf Is a character scalar memory reference that is assigned one of the following values: e YES—if unformatted is an allowed form for the file ¢ NO—if unformatted is not an allowed form for the file e UNKNOWN—if the processor is unable to determine whether unformatted is an allowed form for the file Auxiliary 1/0 Statements 9-33 9.4 REWIND Statement The REWIND statement repositions a sequential file currently open for sequential or append access to the beginning of the file. It takes either one of the following forms: REWIND ([UNIT=]u[,ERR=s][,I0STAT=ios]) REWIND u u Is a logical unit number. S Is the label of the executable statement that receives control if an error occurs. ios Is an integer scalar memory reference that is assigned a positive integer if an error occurs and zero if no error occurs. Syntax Rules and Behavior The unit number must refer to a file on disk or magnetic tape. For exam- ple, the following statement repositions logical unit 3 to the beginning of the currently open file: REWIND 3 This statement repositions logical unit 3 to the beginning of the currently open file. A REWIND statement should not be issued for a file that is open for direct or keyed access. 9-34 Auxiliary 1/0 Statements 9.5 BACKSPACE Statement The BACKSPACE statement repositions a sequential file currently open for sequential access to the beginning of the preceding record. When the next 1/0 statement for the unit is executed, the preceding record is available for processing. The BACKSPACE statement takes one of the following forms: BACKSPACE ([UNIT=]ul[,ERR=s] [,I0STAT=ios]) BACKSPACE u u Is a logical unit number. S Is the label of the executable statement that receives control if an error occurs. ios Is an integer scalar memory reference that is defined as a positive integer if an error occurs and zero if no error occurs. Syntax Rules and Behavior The unit number must refer to an open file on disk or magnetic tape. For example, the following statement repositions the open file on logical unit 4 to the beginning of the preceding record: BACKSPACE 4 A BACKSPACE statement should not be issued for a file that is open for direct, keyed, or append access. Backspacing from record n is done by rewinding to the start of the file and then performing n-1 successive reads to reach the previous record. For direct, keyed, and append access, the current record count (n) is not available to the FORTRAN 1/0 system. 9.6 ENDFILE Statement The ENDFILE statement writes an end-file record to the specified unit. It takes one of the following forms: ENDFILE ([UNIT=]ul,ERR=s][,I0STAT=1io0s]) ENDFILE u Auxiliary 1/0 Statements 9-35 u Is a logical unit number. S Is the label of the executable statement that receives control if an error occurs. ios Is an integer scalar memory reference that is defined as a positive integer if an error occurs and zero if no error occurs. Syntax Rules and Behavior If the unit specified in the ENDFILE statement is not open, the default file is opened for unformatted output. An end-file record can be written only to files with sequential organization that are accessed as formatted-sequential or unformatted-segmented sequential files. For example, the following statement writes an end-file record to the logical unit 2: ENDFILE 2 An ENDFILE statement must not be issued for a file that is open for direct or keyed access. End-file records should not be written in files that are read by programs written in a language other than FORTRAN because VAX RMS does not support the embedded end-file concept. An end-file record is a 1-byte record containing the hexadecimal code 1A (CTRL/Z). 9.7 DELETE Statement The DELETE statement deletes records from relative and indexed files. It takes one of the following forms: Indexed File Access DELETE ([UNIT=]ul[,ERR=s][,I0STAT=io0s]) Relative File Access 9-36 DELETE ([UNIT=]u,REC=r[,ERR=s][,I0STAT=1i0s]) DELETE (u'r[,ERR=s] [, IOSTAT=io0s]) Auxiliary |/0 Statements u Is the number of the logical unit containing the record to be deleted. r Is the positional number of the record to be deleted. S Is the label of an executable statement that receives control if an error condition occurs. ios Is an integer scalar memory reference that is defined as a positive integer if an error occurs and zero if no error occurs. Syntax Rules and Behavior The form of the DELETE statement for indexed files is a current-record delete. This form deletes the current record, which is the last record that is accessed by a READ statement on the specified logical unit. The forms of the DELETE statement with relative files are direct access deletes. These forms delete the record specified by the number r. The DELETE statement logically removes the appropriate record from the specified file by locating the record and marking it as a deleted record. It then frees the position formerly occupied by the deleted record so that a new record can be written into that position. Following a direct access delete, any associated variable is set to the next record number. In the following example, the fifth record in the file connected to logical unit 10 is deleted from the file: DELETE (10,REC=5) In the next example, the current record is deleted from the file connected to logical unit 11: DELETE (11) Auxiliary 1/0 Statements 9-37 9.8 UNLOCK Statement The UNLOCK statement frees a record in an indexed, relative, or sequential file that was locked on a specified logical unit by a previous READ. It performs no other I/O operation. The UNLOCK statement takes one of the following forms: UNLOCK ([UNIT=]ul[,ERR=s][,I0STAT=ios]) UNLOCK u u Is the number of a logical unit. S Is the label of the executable statement that receives control if an error occurs. ios Is an integer scalar memory reference that is defined as a positive integer if an error occurs and zero if no error occurs. If no record is locked, the operation has no effect. 9-38 Auxiliary I/0 Statements 10 Chapter Compiler Directives Compiler directives tell the compiler to perform certain tasks when it compiles a source program unit. They are preceded by special tags that identify them to the compiler. VAX FORTRAN provides two categories of compiler directives: one category, parallel directives, supports directed decomposition for parallel processing. Parallel directives are preceded by the CPARS$ tag. The other category, general directives, provides several general-purpose functions. General directives are preceded by the CDEC$ tag. 10.1 Compiler Directive Syntax Rules The following general syntax rules apply to all compiler directives. They must be precisely followed to properly compile your program and obtain meaningful results: The tag (CPAR$ or CDEC$) must appear in columns 1 through 5. e e Column 6 must be a blank or tab. From column 7 on, blanks are insignificant. Thus, the directive can be positioned anywhere on the line after column 6. e Continuation lines cannot appear in compiler directives. e If a blank common block is used in a compiler directive, it must be specified as two slashes (/ /). See the individual sections in this chapter for listings of rules that pertain only to specific categories or individual directives. Compiler Directives 10-1 10.2 Parallel Directives Parallel directives invoke parallel processing of indexed DO-loops, synchronize execution of critical regions within the loops, and define the sharability of common blocks and symbols in parallel applications. The /PARALLEL qualifier enables parallel directives. See the VAX FORTRAN User Manual for details about this qualifier. Parallel directives take the following form: column 1 \ CPAR$ directive directive Is any one of the following values: e CONTEXT_SHARED—specifies shared memory locations for symbols declared in routines that contain parallel DO-loops. e CONTEXT_SHARED_ALL—reinforces the context-shared default of symbols in routines compiled with the /PARALLEL qualifier. e DO_PARALLEL—enables parallel processing of indexed DO-loops. e LOCKON and LOCKOFF—forces processes to sequentially execute a region of code. e SHARED—specifies shared common blocks for parallel processing. o SHARED_ALL—reinforces the shared default of common blocks in routines compiled with the /PARALLEL qualifier. * PRIVATE—specifies unique (private) common blocks or symbols for each process. e PRIVATE_ALL—forces all common blocks and symbols to have PRIVATE defaults in routines compiled with the /PARALLEL qualifier. Section 10.2.9 provides examples of parallel directives appropriately used in a program unit. 10-2 Compiler Directives 10.2.1 CPARS CONTEXT_SHARED The CONTEXT_SHARED directive specifies that the same memory location will be used for a symbol declared in a routine. The symbol uses the same memory location in any parallel DO-loops contained within the routine, If a routine has several concurrent invocations (because it is called from within a parallel DO-loop), each invocation uses different memory locations for its variables that are declared CONTEXT_SHARED. The CONTEXT_SHARED directive takes the following form: CPAR$ CONTEXT_SHARED syname [,syname]... syname Is the name of a variable, array, or record declared within the routine. Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, CONTEXT_SHARED has the following specific rules: e CONTEXT_SHARED can appear anywhere within declaration statements in the routine. * Arrays cannot be dimensioned within CONTEXT_SHARED. e Symbols listed in CONTEXT_SHARED cannot also be listed in a * Dummy arguments cannot be declared CONTEXT_SHARED. PRIVATE directive. 10.2.2 CPARS CONTEXT_SHARED_ALL The CONTEXT_SHARED_ALL directive forces all symbols that are declared within a routine to default to CONTEXT_SHARED. It takes the following form: CPAR$ CONTEXT_SHARED_ALL This directive affects only default behavior. Individual symbols can still be declared PRIVATE. All general compiler-directive syntax rules apply to the CONTEXT_ SHARED directive (see Section 10.1). Compiler Directives 10-3 10.2.3 CPARS DO_PARALLEL The DO_PARALLEL directive tells the compiler to run an indexed DOloop in parallel. It takes the following form: CPAR$ DO_PARALLEL [count] count Is a numeric expression specifying the number of iterations in each set distributed to processes running the DO-loop. Any remaining iterations run in the last process. For example, if the total number of iterations is 1330, count is 100, and two processes are running the DO-loop, then each process is distributed sets of 100 iterations at a time. The last set contains the last 30 iterations. The numeric expression must evaluate to a positive, non-zero integer. If necessary, the process converts it to an integer by truncation. For example, 50.56 is acceptable and is converted to 50. However, 0.20 is not acceptable because it is converted to zero. Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, DO_PARALLEL and its corresponding DO-loop have the following specific rules: * The indexed DO statement must be the next executable statement following the DO_PARALLEL directive. Only comments can appear between the directive and its corresponding DO-loop. The parallel DO-loop control variable must be a private integer. If it is not specified PRIVATE, the compiler gives an informational message and changes the control variable’s default to PRIVATE. If the control variable is not an integer, the compiler gives an error. * * 10-4 A parallel DO-loop cannot contain the following;: — I/0O statements — PAUSE, RETURN, or STOP statements — (alls to system services or run-time library routines that modify the context of the process A parallel DO-loop must not have a branch into or out of its body. Compiler Directives When calculations in parallel DO-loops require serial (sequential) execution to achieve correct results, you must guard those calculations (called critical regions) against parallel execution. This situation occurs when calculations modify shared values that are needed in successive iterations of the parallel DO-loop or elsewhere in the routine. The following section describes the LOCKON and LOCKOFF directives, which guard critical regions. See also the VAX FORTRAN User Manual for additional information. 10.2.4 CPARS LOCKON, CPARS LOCKOFF The LOCKON and LOCKOFF directives enclose a region of executable code within a parallel DO-loop. They effectually force processes to execute this critical region one at a time by excluding all other processes from the region while one process is executing it. A process executing the critical region “has the lock” while other processes that want to execute it must wait until it is free. The lock becomes free when the process in the critical region executes the associated LOCKOFF directive. The LOCKON and LOCKOFF directives take the following forms: CPAR$ LOCKON 1lck-var (critical region) CPAR$ LOCKOFF 1lck-var Ick-var Is a LOGICAL#*4 variable that can be any of the following items: e Scalar variable ¢ Dummy argument e Record field * Array element The lock variable (Ick-var) must be in a shared common block or a variable declared as CONTEXT_SHARED in the routine containing a parallel DO-loop. The lock variable is considered locked when it has a value of .TRUE. and free when it has a value of .FALSE. Compiler Directives 10-5 Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, LOCKON and LOCKOFF have the following specific rules: * All LOCKON directives require an associated LOCKOFF directive that executes in the DO-loop. * Statements in critical regions cannot transfer control outside the region. 10.2.5 * Lock variables can only have a LOGICAL+*4 data type. Other data types cause a compilation error. * Lock variables must be shared, either by specification or default. If they are declared private, a compilation error results. CPARS PRIVATE The PRIVATE directive specifies the common blocks and symbols that must be unique for each process that runs the parallel DO-loop. It takes the following form: CPAR$ PRIVATE name [,name]. .. name [s the name of a symbol or a common block (preceded and followed by a slash). Common block names cannot exceed 26 characters; they can be blank. Symbols can be any variable name (scalar, array, or record) that is declared within the routine. Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, PRIVATE has the following specific rules: * PRIVATE directives can appear anywhere within declaration statements in the routine. * Arrays cannot be dimensioned within this directive. * Elements contained in a common block cannot be declared PRIVATE. e Common blocks that are declared PRIVATE cannot also be declared SHARED. * Symbols declared PRIVATE cannot also be declared CONTEXT_ SHARED. 10-6 Compiler Directives 10.2.6 * Symbols can only be declared PRIVATE in routines containing a parallel DO-loop. * Dummy arguments cannot be declared PRIVATE. * SAVE statements cannot refer to PRIVATE symbols or common blocks. CPARS PRIVATE_ALL The PRIVATE_ALL directive forces all symbols and common blocks to default to PRIVATE in each process that runs the parallel DO-loop. It takes the following form: CPAR$ PRIVATE_ALL The PRIVATE_ALL directive changes only default behavior. Individual common blocks can still be declared SHARED and individual symbols can still be declared CONTEXT_SHARED. All general compiler-directive syntax rules apply to the PRIVATE_ALL directive (see Section 10.1). 10.2.7 CPARS SHARED The SHARED directive specifies the common blocks that must be shared between processes running a parallel DO-loop. It takes the following form: CPAR$ SHARED /[cbl/[,/[cbl/]... cb Is the name of a common block. The name cannot exceed 26 characters; it can be blank. Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, SHARED has the following specific rules: e e SHARED directives can appear anywhere within declaration statements in the routine. (Common blocks that are declared SHARED cannot also be declared PRIVATE. Compiler Directives 10-7 10.2.8 CPARS SHARED_ALL The SHARED_ALL directive forces all common blocks to have SHARED defaults among processes that use the parallel DO-loop. It takes the following form: CPAR$ SHARED_ALL This directive affects only default behavior. Individual common blocks can still be declared PRIVATE. All compiler-directive syntax rules apply to the SHARED_ALL directive (see Section 10.1). 10.2.9 Parallel Directive Examples The following examples demonstrate valid applications of parallel directives. In the first example, assignment to the context-shared variables SUMA and SUMB must be guarded from multiple processes attempting to write to the variable at the same time. The LOCKON and LOCKOFF directives accomplish this task by ensuring scalar execution of the statements. CPAR$ PRIVATE I CPAR$ SHARED /COM1/ CPAR$ CONTEXT_SHARED SUMA, SUMB COMMON/COM1/A, B INTEGER A(1000), B(1000), SUMA, SUMB LOGICAL *4 LCK_VAR CPAR$ DO_PARALLEL DO I =1, 1000 CALL CALCULATE (I) CPAR$ LOCKOFF LCK_VAR ENDO PRINT*, 'SUM A=', SUMA PRINT*, 'SUM B=', SUMB END 10-8 Compiler Directives 4 Guard against multiple processes SUMA = SUMA + A(I) SUMB = SUMB + B(I) writing to the context-shared s— CPAR$ LOCKON LCK_VAR variable at the same time. The second example uses valid SHARED, CONTEXT_SHARED, and PRIVATE directives. INTEGER A(1000), B(1000) COMMON/COM1/B PARAMETER (N = 1000) CPAR$ SHARED_ALL Reinforces the SHARED default for common blocks. CPAR$ CONTEXT_SHARED_ALL Reinforces the CONTEXT_SHARED default for local CPAR$ PRIVATE I symbols. Loop control must be private. CPAR$ DO_PARALLEL DO 10 10 I =1, ACI) = A(T) B(I) = A(I) N + 1 éoNTINUE CALL SUBR(A, WRITE (5,%) N) A, B END SUBROQUTINE SUBR(A, INTEGER A(N), N) B(1000) COMMON/COM1/B CPAR$ SHARED /COM1/ CPAR$ PRIVATE_ALL The CPAR$ DO_PARALLEL N/2 DOJ =1, A(J) N =BQ) common block must be SHARED. Make the default PRIVATE. ! ! Distributes half of the iterations to each of two processors. + 7 ENDO RETURN END Compiler Directives 10-9 10.3 General Directives General directives label or modify certain entities. No qualifier is needed on the FORTRAN command line to enable general directives. General directives take the following form: column 1 \ CDEC$ directive directive Is any one of the following values: 10.3.1 e IDENT—provides identification of an object module. e PSECT—modifies certain attributes of a common block. e TITLE, SUBTITLE—provides a listing header. CDECS IDENT The IDENT directive specifies a string that can be used to identify an object module. The compiler places the string in the identification field of an object module when it generates the module for each source program unit. The IDENT directive takes the following form: CDEC$ IDENT string string Is a group of up to 31 printable characters delimited by apostrophes. Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, IDENT has the following specific rules: e Only the first IDENT directive is effective—the compiler ignores any e IDENT has no effect when you specify additional IDENT directives in a program unit. command line. 10-10 Compiler Directives /NOOBJECT on the FORTRAN 10.3.2 CDECS PSECT The PSECT directive modifies several attributes of a common block. It takes the following form: CDEC$ PSECT /common-name/ attr [,attr]... common-name Is the name of the common block, preceded and followed by a slash. attr Is one of the following attributes: LCL—local scope; opposite to GBL and cannot appear with it GBL—global scope [INOJWRT—writability or no-writability [NO]SHR—shareability or no-shareability ALIGN=val—alignment for the common block; val must be a constant ranging from 0 thru 9 Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, PSECT has the following specific rules: If one program unit changes one or more attributes, all other units that reference the common block must also change those attributes in the same way. Default attributes apply if you do not modify them with a PSECT directive. Table 10-1 lists the default attributes of common blocks and how they can be modified by PSECT. Compiler Directives 10-11 Table 10-1: Common Block Default Attributes and PSECT Modification Common Block Default Attributes PSECT Modification Relocatability none Overlaid none Global Scope Global or local scope No executability none Writability Writability or no-writability Readability none Position independence none Shareability Shareability or no-shareability No protection none LONGWORD alignment (2) 0 thru 9 (FORTRAN default) Global or local scope is significant for an image that has more than one cluster. The attribute determines whether program sections with the same name but from different modules in different clusters are finally placed in separate clusters (local scope) or in the same cluster (global scope). [NoJwritability determines whether the contents of a common block can be modified during program execution. [No]shareability determines whether the contents of a common block can be shared by more than one process. ALIGN = val aligns the common block. The specified number is interpreted as a power of 2. The value of the expression is the alignment in bytes: a value of 0 specifies BYTE alignment; a value of 9 specifies page alignment. Refer to the VMS Linker Utility Manual for detailed information about default attributes of common blocks. 10-12 Compiler Directives 10.3.3 CDECS TITLE, CDECS SUBTITLE The TITLE directive specifies a string and places it in the title field of a listing header. Similarly, SUBTITLE places a specified string in the subtitle field of a listing header. These directives take the following forms: CDEC$ TITLE string CDEC$ SUBTITLE string string Is a group of up to 31 printable characters delimited by apostrophes. Syntax Rules In addition to the general compiler-directive syntax rules listed in Section 10.1, TITLE and SUBTITLE have the following specific rules: * To enable TITLE and SUBTITLE directives, you must specify /LIST on the FORTRAN command line. * When TITLE or SUBTITLE appear on a page of a listing file, the specified string appears in the listing header of the following page. If two or more of either directives appear on a page, the last directive is the one in effect for the following page. * [f either directive does not specify a string, no change occurs in the listing file header. Compiler Directives 10-13 Appendix A Additional Language Features To facilitate compatibility with other versions of FORTRAN, VAX FORTRAN provides the following additional language features: ¢ ENCODE, DECODE, DEFINE FILE, and FIND statements * Alternative syntax for the PARAMETER statement and octal constants * A /NOF77 interpretation of the EXTERNAL statement These language features are particularly useful in transporting older FORTRAN programs to a VAX system. However, you should avoid using them in new programs on VAX systems and in new programs for which portability to other FORTRAN-77 implementations is important. A.1 The ENCODE and DECODE Statements The ENCODE and DECODE statements transfer data between variables or arrays in internal storage. The ENCODE statement translates data from internal (binary) form to character form. Inversely, the DECODE statement translates data from character to internal form. These statements are comparable to using internal files in formatted sequential WRITE and READ statements, respectively. The ENCODE and DECODE statements take the following forms: ENCODE (c,f,b[,I0STAT=ios][,ERR=s]) [1list] DECODE [list] (c,f,b[,I0STAT=ios] [,ERR=s]) Additional Language Features A-1 c Is an integer expression. In the ENCODE statement, c is the number of characters (in bytes) to be translated to character form. In the DECODE statement, ¢ is the number of characters to be translated to internal form. f Is a format identifier. An error occurs if more than one record is specified. b Is a scalar or array name reference. If b is an array name reference, its elements are processed in the order of subscript progression. In the ENCODE statement, b receives the characters after translation to external form. If less than ¢ characters are received, the remaining character positions are filled with blank characters. In the DECODE statement, b contains the characters to be translated to internal form. ios Is an integer scalar memory reference that is defined as a positive integer if an error occurs, and zero if no error occurs. S Is the label of an executable statement. list Is an 1/0 list. In the ENCODE statement, the list contains the data to be translated to character form. In the DECODE statement, the list receives the data after translation to internal form. The interaction between the format specifier and the 1/0 list is the same as for a formatted I/O statement. Syntax Rules and Behavior The number of characters that the ENCODE or DECODE statement can process depends on the data type of b. For example, an INTEGER#2 array can contain two characters per element, so that the maximum number of characters is twice the number of elements in that array. A character variable or character array element can contain characters equal in number to its length. A character array can contain characters equal in number to the length of each element multiplied by the number of elements. A-2 Additional Language Features Examples In the following example, the DECODE statement translates the 12 characters in A to integer form (as specified by FORMAT 100): DIMENSION K(3) CHARACTER*12 A,B DATA A/'123456789012'/ 100 DECODE (12,100,A) FORMAT (314) ENCODE (12,100,B) K K(3), K(2), K(1) The 12 characters are stored in array K: K(1) = 1234 K(2) = 5678 K(3) = 9012 The ENCODE statement translates the values K(3), K(2), and K(1) to character form and stores the characters in the character variable B: B = A.2 '901256781234"' DEFINE FILE Statement The DEFINE FILE statement establishes the size and structure of files with relative organization and associates them with a logical unit number. The DEFINE FILE statement is comparable to the OPEN statement (in situations where you can use the OPEN statement, it is the preferable mechanism for creating and opening files). The DEFINE FILE statement takes the following form: DEFINE FILE u (m,n,U,asv)[,u(m,n,U,asv)]. .. u Is an integer constant or variable that specifies the logical unit number. m Is an integer constant or variable that specifies the number of records in the file. n Is an integer constant or variable that specifies the length of each record in 16-bit words (2 bytes). Additional Language Features A-3 U Specifies that the file is unformatted (binary); this is the only acceptable entry in this position. asv Is an integer variable, called the associated variable of the file. At the end of each direct access 1/O operation, the record number of the next higher numbered record in the file is assigned to v; asv must not be a dummy argument. Syntax Rules and Behavior The DEFINE FILE statement specifies that a file containing m fixed-length records, each composed of n 16-bit words, exists (or is to exist) on the specified logical unit. The records in the file are numbered sequentially from 1 through m. A DEFINE FILE statement must be executed before the first direct access 1/0 statement referring to the specified file, even though the DEFINE FILE statement does not itself open the file. The file is actually opened when the first direct access 1/O statement for the unit is executed. If this I/O statement is a WRITE statement, a new relative organization file is created. If it is a READ or FIND statement, an existing file is opened, unless the specified file does not exist. If a file does not exist, an error occurs. The DEFINE FILE statement establishes the integer variable asv as the associated variable of a file. At the end of each direct access I/O operation, the FORTRAN I/0O system places in asv the record number of the record immediately following the one just read or written. Because the associated variable always points to the next sequential record in the file (unless the associated variable is redefined by an assignment, input, or FIND statement), direct access /O statements can perform sequential processing on the file. They do this by using the associated variable of the file as the record number specifier. Example In the following example, the DEFINE FILE statement specifies that the logical unit 3 is to be connected to a file of 1000 fixed-length records; each record is forty-eight 16-bit words long. The records are numbered sequentially from 1 through 1000 and are unformatted. After each direct access 1/0O operation on this file, the integer variable NREC will contain the record number of the record immediately following the record just processed. DEFINE FILE 3 (1000,48,U,NREC) A-4 Additional Language Features A.3 FIND Statement The FIND statement positions a direct access file at a particular record and sets the associated variable of the file to that record number. It is comparable to a direct access READ statement with no 1/0 list, and can open an existing file. No data transfer takes place. (See the description of the OPEN statement’s ASSOCIATEVARIABLE keyword or the DEFINE FILE statement for information about associate variables.) The FIND statement takes one of the following forms: FIND (u'r[,ERR=s] [,I0STAT=io0s]) FIND ([UNIT=]u,REC=r[,ERR=s][,I0STAT=io0s]) u Is a logical unit number. It must refer to a relative organization file. r Is the direct access record number. It cannot be less than one or greater than the number of records defined for the file. s Is the label of the executable statement that receives control if no error occurs. ios Is an integer variable or integer array element that is defined as a positive integer if an error occurs, and as a zero if no error occurs. Examples In the first example, the FIND statement positions logical unit 1 at the first record in the file. The file’s associated variable is set to one: FIND (1'1) In the second example, the FIND statement positions the file at the record identified by the content of INDX. The file’s associated variable is set to the value of INDX: FIND (4'INDX) Additional Language Features A-5 A.4 PARAMETER Statement The PARAMETER statement discussed here is similar to the one discussed in Section 4.11; they both assign a symbolic name to a constant. However, this PARAMETER statement differs from the other one in the following two ways: its list is not bounded with parentheses; and the form of the constant, rather than implicit or explicit typing of the symbolic name, determines the data type of the variable. This PARAMETER statement takes the following form: PARAMETER p=c [,p=c]... p Is a symbolic name. c Is a constant, the symbolic name of a constant, or a compile-time constant expression. Syntax Rules and Behavior Each symbolic name (p) becomes a constant and is defined as the value of the constant or constant expression (c). Once a symbolic name is defined as a constant, it can appear in any position in which a constant is allowed. The effect is the same as if the constant were written there instead of the symbolic name. The symbolic name of a constant cannot appear as part of another constant, but it can appear as a real or imaginary part of a complex constant. Compile-time constant expressions are defined in Section 4.11. You can use symbolic names in a PARAMETER statement only to identify the symbolic name’s corresponding constant in that program unit. Such a name can be defined only once in PARAMETER statements within the same program unit. The symbolic name of a constant assumes the data type of its corresponding constant expression. The data type of a parameter constant cannot be specified in a type declaration statement. Nor does the initial letter of the constant’s name implicitly affect its data type. A-6 Additional Language Features Examples A.5 PARAMETER PI=3.1415927, PARAMETER PIOV2=PI/2, PARAMETER FLAG=.TRUE., DPI=3.141592653589793238D0 DPIOV2=DPI/2 LONGNAME='A STRING OF 25 CHARACTERS' Octal Notation for Integer Constants Octal forms of integer constants allow compatibility with PDP-11 FORTRAN. An octal integer constant takes the following form: "nn nn Is a string of digits in the range 0 to 7. Examples The following examples demonstrate valid and invalid octal integer constants and explain why the invalid ones are not valid: Valid "107 "177777 Invalid Explanation "108 Contains a digit outside the allowed range "1377. Contains a decimal point "17777" Contains a trailing quotation mark These octal forms are not the same as the typeless octal constants discussed in Section 2.2.1.4. Integer constants in octal form have integer data type and are treated as integers. Additional Language Features A-7 A.6 /NOF77 Interpretation of the EXTERNAL Statement By using the /NOF77 qualifier on the FORTRAN command line, you can obtain another interpretation of the EXTERNAL statement. This additional interpretation facilitates compatibility with older versions of FORTRAN due to the ANSI FORTRAN-77 interpretation being incompatible with the previous Standard and previous DIGITAL implementations. The /NOF77 interpretation of the EXTERNAL statement combines the function of the INTRINSIC statement with that of the EXTERNAL statement discussed in Section 4.7. It is available only if the /NOF77 qualifier is specified on the FORTRAN command line. The /NOF77 EXTERNAL statement lets you use subprograms as arguments to other subprograms. The subprograms to be used as arguments can be either user-supplied procedures or FORTRAN library functions. The /NOF77 EXTERNAL statement takes the following form: EXTERNAL [*]v[, [*]v]... v Is the symbolic name of a subprogram or the name of a dummy argument associated with the symbolic name of a subprogram. * Specifies that a user-supplied function is to be used instead of a FORTRAN library function having the same name. See Section 6.3 for information on FORTRAN library functions (intrinsic functions). Syntax Rules and Behavior The /NOF77 EXTERNAL statement declares that each symbolic name in its list is an external procedure name. Such a name can then be used as an actual argument to a subprogram, which in turn can use the corresponding dummy argument in a function reference or CALL statement. However, used as an argument, a complete function reference represents a value, not a subprogram name; for example, SQRT(B) in CALL SUBR(A, SQRT(B), Q). It is not, therefore, defined in an EXTERNAL statement (as would be the incomplete reference SQRT). A-8 Additional Language Features Example The following example uses the Main Program EXTERNAL SIN, COS, /NOF77 EXTERNAL statement: Subprograms *TAN, SINDEG SUBROUTINE TRIG(X,F,Y) Y = F(X) RETURN CALL TRIG(ANGLE,SIN,SINE) END CALL TRIG(ANGLE,COS, COSINE) FUNCTION TAN(X) CALL TRIG(ANGLE,TAN,TANGNT) TAN = SIN(X)/COS(X) RETURN END CALL TRIG(ANGLED, SINDEG, SINE) FUNCTION SINDEG(X) SINDEG = SIN(X*3.1459/180) RETURN END o SIN(X) Honou =T e S S The CALL statements pass the name of a function to the subroutine TRIG. The function reference F(X) subsequently invokes the function in the second statement of TRIG. Depending on which CALL statement invoked TRIG, the second statement is equivalent to one of the following: TAN(X) Cos(X) SINDEG (X) The functions SIN and COS are examples of trigonometric functions supplied in the FORTRAN library. The function TAN is also supplied in the library. But the asterisk in the EXTERNAL statement specifies that the user-supplied function be used, instead of the library function. The function SINDEG is also a user-supplied function. Because no library function has the same name, no asterisk is required. Additional Language Features A-9 Appendix B Character Sets This appendix describes the following three character sets: B.1 e FORTRAN e ASCII e Radix-50 FORTRAN Character Set The FORTRAN character set consists of the following;: * All upper- and lowercase letters (A through Z, a through z) * The numerals 0 through 9 * The following special characters: Character Sets B-1 Character Name por <TAB> Spaceor tab Character Apostrophe Name = Equal sign Quotation mark + Plus sign $ Dollar sign — Minus sign — Underscore * Asterisk ! Exclamation point / Slash ( Left parenthesis < Left angle bracket ) Right parenthesis > Right angle bracket , Comma % Percent sign Period & Ampersand Colon Other printing characters can appear in a FORTRAN statement only as part of aHollerith or character constant. Any printing character can appear in a comment. Printing characters are characters whose ASCII codes are in the range 20 through 7D. See Table B-1. B.2 ASCII Character Set Table B-1 represents the ASCII character set. At the top of the table are hexadecimal digits (0 to 7), and to the left of the table are hexadecimal digits (0 to F). To determine the hexadecimal value of an ASCII character, use the hexadecimal digit that corresponds to the row in the “units” position, and use the hexadecimal digit that corresponds to the column in the “16s” position. For example, the value of the character representing the equal sign is 3D. B-2 Character Sets ASCII Character Set Table B—1: Column Row 6 7 Q a q B R b r C S C S 4 D T d t % 5 E U e u & 6 F Vv f Y ’ 7 G W g w CAN ( 8 H X h X 9 I Y i y J V4 j z ! 0 1 2 3 4 5 0] NUL DLE SP O @ P 1 SOH DC1 ! 1 A 2 STX DC2 " 2 3 ETX DC3 # 3 4 EOT DC4 $ 5 ENQ NAK 6 ACK SYN 7 BEL ETB BS 8 9 HT EM ) A LF SUB * p B VT ESC + ; K [ k C FF FS , < L \ | | D CR GS — = M ] m ! E SO RS . > N ’ n ~ F Sl usS / ? @) _ 0 DEL NUL Null DLE Data Link Escape SOH Start of Heading DC1 Device Control 1 STX Start of Text DC2 Device Control 2 ETX End of Text DC3 Device Control 3 EOT End of Transmission DC4 Device Control 4 ENQ Enquiry NAK Negative Acknowledge ACK Acknowledge SYN Synchronous ldle BEL Bell ETB End of Transmission Block BS Backspace CAN Cancel HT Horizontal Tabulation EM End of Medium LF Line Feed SuB Substitute VT Vertical Tab ESC Escape FF Form Feed FS File Separator CR Carriage Return GS Group Separator SO Shift Out RS Record Separator Si Shift In usS Unit Separator SP Space DEL Delete ZK-7458-HC Character Sets B-3 B.3 Radix-50 Constants and Character Set Radix-50 is a special character data representation in which up to 3 characters can be encoded and packed into 16 bits. The Radix-50 character set is a subset of the ASCII character set and is provided for compatibility with PDP-11 FORTRAN. . The Radix-50 characters and corresponding values are given in Table B-2. Table B—-2: RADIX-50 Character Set with Comparative Values Character ASCII Octal Equivalent Radix-50 Octal Value Space 40 0 A-Z 101 - 132 1-32 $ 44 33 : 56 34 (Unassigned) 0-9 35 60 - 71 36 - 47 Radix-50 values are stored, up to three characters per word, by packing them into single numeric values according to the following formula: ((Z % 50 + 7) % 50 + k) The values 7, 7, and k represent the code values of the three Radix-50 characters. Thus, the maximum Radix-50 value is as follows: 47 * 50 * 50 + 47 » 50 + 47 = 174777 A Radix-50 constant takes the following form: nRcic2.. .¢cn B-4 Character Sets n Is an unsigned, nonzero integer constant that states the number of charac- ters to follow. C Is a character from the Radix—50 character set. The maximum number of characters is 12. The character count must include any spaces that appear in the character string (the space character is a valid Radix-50 character). You can use Radix-50 constants only in DATA statements. When a Radix-50 constant is assigned to a numeric variable or array element, the number of bytes that can be assigned depends on the data type of the component (see Table 2-1). If the Radix-50 constant contains fewer bytes than the length of the component, ASCII null characters (zero bytes) are appended on the right. If the constant contains more bytes than the length of the component, the rightmost characters are not used. Examples The following examples illustrate valid and invalid Radix-50 constants and explain why the invalid ones are not valid: Valid 4RABCD 6RATOAAA Invalid Explanation 4RDKO: colon is not a Radix-50 character Character Sets B-bH Appendix C FORTRAN Data Representation This appendix describes the data types supported by VAX FORTRAN and illustrates how they are stored in memory. The symbol :A in any illustration specifies the address of the byte containing bit 0, which is the starting address of the represented data element. C.1 INTEGER+2 Representation 0 15 14 S = BINARY NUMBER A N ZK-798-82 SIGN = 0(+), 1(-) Integers are stored in a twos complement representation. INTEGER*2 values are in the range —-32768 to 32767, and are stored in two contiguous bytes aligned on an arbitrary byte boundary. For example: +22 = 0016 (hex) -7 = FFF9(hex) FORTRAN Data Representation C-1 C.2 INTEGER+4 Representation 31 30 0 S 'G BINARY NUMBER ‘A N ZK-799-82 SIGN = 0(+), 1(-) INTEGER=*4 values are stored in twos complement representation and lie in the range -2147483648 to 2147483647. Each value is stored in four contiguous bytes, aligned on an arbitrary byte boundary. Note that if the value is in the range of an INTEGER*2 value (-32768 to 32767), then the first word can be referenced as an INTEGER*2 value. C.3 LOGICAL+1 (BYTE) Representation 7 0 BINARY NUMBER A ZK-797-82 LOGICAL=*1 (or BYTE) values are in the range -128 to 127. C.4 LOGICAL+#2 and LOGICAL+4 Representation Logical values are stored in two (LOGICAL#*2) or four (LOGICAL=*4) contiguous bytes, starting on an arbitrary byte boundary. The low-order bit (bit 0) determines the value. If bit 0 is set, the value is .TRUE. If bit 0 is clear, the value is .FALSE. C-2 FORTRAN Data Representation LOGICAL*2 0 1 15 10 16 :A 0] UNDEFINED BITS FALSE: :A 1] UNDEFINED BITS TRUE: ZK-802-82 LOGICAL+*4 1 15 TRUE: UNDEFINED BITS 0 1| :A UNDEFINED BITS :A+2 16 31 1 15 UNDEFINED BITS. FALSE: 0 :A 0] UNDEFINED BITS 31 :A+2 16 ZK-803-82 C.5 Floating-Point Representations The exponent for the REAL*4 and REAL*8 (D_floating) formats is stored in binary excess 128 notation. Binary exponents from -127 to 127 are represented by the binary equivalents of 1 through 255. FORTRAN Data Representation C-3 The exponent for the REAL*8 (G_floating) format is stored in binary excess 1024 notation. The exponent for the REAL*16 format is stored in binary excess 16384 notation. In REAL*8 (G_floating) format, binary exponents from -1023 to 1023 are represented by the binary equivalents of 1 through 2047. In REAL*16 format, binary exponents from -16383 to 16383 are represented by the binary equivalents of 1 through 32767. For each floating-point format, fractions are represented in sign-magnitude notation, with the binary radix point to the left of the most significant bit. Fractions are assumed to be normalized, and therefore the most significant bit is not stored (this is called “hidden bit normalization”). This bit is assumed to be 1 unless the exponent is 0. If the exponent equals 0, then the value represented is either zero, or it is a reserved operand. (Refer to the VAX FORTRAN User Manual for an explanation of the representation of 0.0 and reserved operand faults.) C.5.1 REAL+4 (F_floating) REAL*4 (F_floating) data is four contiguous bytes starting on an arbitrary byte boundary. Bits are labeled from the right, 0 through 31. 15 14 PG 7 EXPONENT 6 0 FRACTION A N FRACTION 31 :A+2 16 ZK-800-82 SIGN = 0(+), 1(-) The form of REAL*4 (F_floating) data is sign magnitude, with bit 15 the sign bit, bits 14:7 an excess 128 binary exponent, and bits 6:0 and 31:16 a normalized 24-bit fraction with the redundant most significant fraction bit not represented. The value of F_floating data is in the approximate range: 0.29+10++-38 through 1.7%10#*38. The precision is approximately one part in 2*+23; that is, typically, seven decimal digits. C-4 FORTRAN Data Representation C.5.2 REAL+8 (D_floating) REAL=*8 (D_floating) data is eight contiguous bytes starting on an arbitrary byte boundary. Bits are labeled from the right, 0 through 63. 15 14 S g 7 EXPONENT 0 FRACTION A N 63 FRACTION A+2 FRACTION A+4 FRACTION . A+6 48 ZK-801-82 SIGN = 0(+), 1(-) The form of REAL*8 (D_floating) data is identical to an F_floating real number, except for an additional 32 low-significance fraction bits. The exponent conventions and approximate range of values are the same as those for F_floating. The precision is approximately one part in 2%*55; that is, typically, 16 decimal digits. FORTRAN Data Representation C-5 C.5.3 REAL*8 (G_floating) REAL#*8 (G_floating) data is eight contiguous bytes starting on an arbitrary byte boundary. The bits are labeled from the right, 0 through 63. 15 14 'S = 43 EXPONENT 0 FRACTION | :A N 63 FRACTION : A+2 FRACTION . A+4 FRACTION : A+6 48 ZK-804-82 SIGN = 0(+), 1(-) The form of REAL*8 (G_floating) data is sign magnitude, with bit 15 the sign bit, bits 14:4 an excess 1024 binary exponent, and bits 3:0 and 63:16 a normalized 53-bit fraction with the redundant most significant fraction bit not represented. The value of a G_floating data is in the approximate range 0.56*10#*%-308 through 0.9+¥10%+308. The precision of G_floating data is approximately one part in 2+*52; that is, typically, 15 decimal digits. C-6 FORTRAN Data Representation C.5.4 REAL+16 (H_floating) REAL#*16 (H_floating) data is 16 contiguous bytes starting on an arbitrary byte boundary. The bits are labeled from the right, 0 through 127. 15 14 S 'G 0 EXPONENT ‘A FRACTION : A+2 FRACTION . A+4 FRACTION . A+6 FRACTION . A+8 FRACTION : A+10 FRACTION A+12 FRACTION . A+14 N 127 112 ZK-805-82 SIGN = 0(+), 1(-) The form of a REAL*16 (H_floating) data is sign magnitude with bit 15 the sign bit, bits 14:0 an excess 16384 binary exponent, and bits 127:16 a normalized 113-bit fraction with the redundant most significant fraction bit not represented. The value of H_floating data is in the approximate range 0.84+10%*—4932 through 0.59*10%%4932. The precision of H_floating data is approximately one part in 2**112; that is, typically, 33 decimal digits. FORTRAN Data Representation C-7 C.5.5 COMPLEX+8 (F—_floating) COMPLEX=*8 data is eight contiguous bytes aligned on an arbitrary byte boundary. The low-order four bytes contain REAL*4 data that represents the real part of the complex number. The high-order four bytes contain REAL#*4 data that represents the imaginary part of the complex number. 15 14 PG REAL PART 76 EXPONENT 0 FRACTION A N FRACTION : A+2 . 1S }3 EXPONENT FRACTION - A+4 N IMAGINARY PART ¢ FRACTION - A+6 \ 63 48 ZK-806-82 SIGN = 0(+), C.56 1(-) COMPLEX*16 (D_floating) COMPLEX*16 (D_floating) data is 16 contiguous bytes aligned on an arbitrary byte boundary. The low-order eight bytes contain REAL*8 (D_floating) data that represents the real part of the complex data. The high-order eight bytes contain REAL*8 (D_floating) data that represents the imaginary part of the complex data. C-8 FORTRAN Data Representation /76 EXPONENT FRACTION A FRACTION : A+2 FRACTION - A+4 FRACTION :A+6 N REAL PART fi 7fi EXPONENT FRACTION :A+8 FRACTION :A+10 FRACTION :A+12 FRACTION :A+14 IMAGINARY PART ¢ ZK-807-82 SIGN = 0(+), FORTRAN Data Representation C-9 C.5.7 COMPLEX+16 (G_floating) COMPLEX#*16 (G_floating) data is 16 contiguous bytes aligned on an arbitrary byte boundary. The low-order eight bytes contain REAL*8 (G_floating) data that represents the real part of the complex data. The high-order eight bytes contain REAL*8 (G_floating) data that represents the imaginary part of the complex data. 15 14 S g 43 EXPONENT 0 FRACTION A N FRACTION . A+2 FRACTION A+ FRACTION . A+6 —_ REAL PART ¢ S g EXPONENT FRACTION . A+8 N FRACTION - A+10 FRACTION :A+12 FRACTION A+14 IMAGINARY PART ¢ 127 112 ZK-808-82 C-10 FORTRAN Data Representation C.6 Character Representation A character string is a contiguous sequence of bytes in memory. CHAR 1 CHAR L :A+L-1 ZK-809-82 A character string is specified by two attributes: the address A of the first byte of the string, and the length L of the string in bytes. The length L of a string is in the range 1 through 65535. C.7 Hollerith Representation Hollerith constants are stored internally, one character per byte. FORTRAN Data Representation C-11 1 Byte 7 0 CHAR 1 ‘A 2 Bytes 15 87 CHAR 2 0 CHAR 1 A 4 Bytes 31 24 23 CHAR 4 16 15 CHAR 3 87 CHAR 2 0 CHAR 1 A 8 Bytes 15 63 87 0 CHAR 2 CHAR 1 A CHAR 4 CHAR 3 ‘A+2 CHAR 6 CHAR 5 :A+4 CHAR 8 CHAR 7 :A+6 56 55 48 ZK-810-82 C-12 FORTRAN Data Representation Appendix D VAX FORTRAN Language Summary This appendix summarizes VAX FORTRAN expression operators (Table D-1), statements (Table D-2), and intrinsic functions (Table D-3). It also describes the system subroutines provided with VAX FORTRAN (Section D.4) and discusses the intrinsic functions available for manipulating bits in integer data items (Section D.5). D.1 Expression Operators This section lists the expression operators in each data type in order of descending precedence: Table D-1: Expression Operators Data Type Operator Operation Arithmetic *k Exponentiation Operates Upon Arithmetic or logical expressions *, / Multiplication, division +, - Addition, subtraction, unary plus and minus Character // Concatenation Character expressions Relational .GT. .GE. Greater than Greater than or equal to Arithmetic, logical, or character expressions (all relational operators have equal precedence) .LT. Less than VAX FORTRAN Language Summary D-1 Table D-1 (Cont.): Data Type Logical Expression Operators Operator Operation LE. Less than or equal to EQ. Equal to .NE. Not equal to NOT. AND. Operates Upon | NOT.A is true only if A is false Logical or integer expressions A.AND.B is true only if A and B are both true .OR. A.OR.B is true if either A or B or both are true EQV. NEQV. A.EQV.B is true only if A and B are both true or and B are both false A .EQV., .NEQV., and .XOR. have equal priority ANEQV.B is true only if A is true and B is false or B is true and A is false XOR. D.2 Same as .NEQV. Statements This section summarizes the statements available in the VAX FORTRAN language, including the general form of each statement. The statements are listed alphabetically for ease of reference. D-2 VAX FORTRAN Language Summary Table D-2: VAX FORTRAN Language Statement Summary ACCEPT See READ statements (sequential access). See Section 7.5. ASSIGN s TO v S is the label of an executable statement or a FORMAT statement. % is an integer variable name. Associates the statement label s with the integer variable v for later use as a format specifier or in an assigned GO TO statement. See Section 3.4. Assignment Statement v=e v is a scalar memory reference or an aggregate reference. e 1S an expression or an aggregate. The assignment statement assigns the value of the arithmetic, logical, or character expression on the right of the equal sign to the corresponding numeric, logical, or character scalar memory reference on the left. If aggregates are involved, the aggregate reference and the aggregate must have matching structures. See Sections 3.1 - 3.3. BACKSPACE ([UNIT=]Ju|,ERR=s][,IOSTAT=ios]) BACKSPACE u u is a logical unit specifier. S is the label of an executable statement. ios is an I/0O status specifier. The BACKSPACE statement backspaces the currently open file on logical unit u by one record. See Section 9.5. BLOCK DATA [nam] nam is a symbolic name. The BLOCK DATA statement specifies the subprogram that follows as a BLOCK DATA subprogram. See Section 4.1. VAX FORTRAN Language Summary D-3 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary CALL sub][([a][,[a]]..)] sub a subprogram name or entry point name. a is an expression, an array name, a procedure name, or an alternate return specifier. An alternate return specifier is *s or &s, where s is the label of an executable statement. The CALL statement calls the subroutine subprogram with the name specified by sub, passing the actual arguments (a) to replace the dummy arguments in the subroutine definition. See Sections 5.1 and 6.2.3. CDECS IDENT string string is a group of up to 31 printable characters delimited by apostrophes. The IDENT directive specifies a string that identifies an object module. See Section 10.3.1. CDEC$ PSECT /common-name/ attr [,attr]... common- is the name of the common block, which must be preceded and name followed by a slash. attr is one of the following attributes: LCL (local scope); GBL (global scope); [NOJWRT (writability or no writability); [NO]JSHR (shareability or no shareability); or ALIGN = val (alignment for the common block, val must be a constant ranging from 0 thru 9). The PSECT directive modifies certain attributes of a common block. See Section 10.3.2. CDECS$ SUBTITLE string string is a group of up to 31 printable characters delimited by apostrophes. The SUBTITLE directive creates a header in a listing’s subtitle field. See Section 10.3.3. CDECS$ TITLE string string is a group of up to 31 printable characters delimited by apostrophes. The TITLE directive creates a header in a listing’s title field. See Section 10.3.3. CLOSE ([UNIT=]ul,p][,ERR=s][, IOSTAT=ios)) u D-4 is a logical unit specifier. VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary P is one of the following parameters: 'SAVE' 'KEEP’ STATUS DISPOSE DISP = \ '‘DELETE’ ‘PRINT’ 'SUBMIT’ P 'PRINT/DELETE' 'SUBMIT/DELETE’ S is the label of an executable statement. ios is an 1/0O status specifier. | The CLOSE statement closes the specified file. See Section 9.2. COMMON [/[cb]/]nlist[[,] /[cb]/nlist]... cb is a common block name, nlist is a list of one or more variable names, array names, array declarators, or records separated by commas. The COMMON statement reserves one or more blocks of storage space to contain the variables associated with a specified block name. See Section 4.2. CONTINUE The CONTINUE statement transfers control to the next executable statement. See Section 5.2. CPAR$ CONTEXT_SHARED syname [,syname]... syname is the name of a variable, array, or record declared within the routine. The CPAR$ CONTEXT_SHARED directive specifies shared memory locations for symbols declared in the routines compiled with the /PARALLEL qualifier. See Section 10.2.1. CPARS$ CONTEXT_SHARED_AILL The CPAR$ CONTEXT_SHARED_ALL directive reinforces the context-shared default of symbols in routines compiled with the /PARALLEL qualifier. See Section 10.2.2. CPAR$ DO_PARALLEL [count] VAX FORTRAN Language Summary D-5 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary count is a numeric expression specifying the number of iterations in each set distributed to processors running the parallel DO-loop. The number must be able to be evaluated as a positive, non-zero integer. The DO_PARALLEL directive enables parallel processing of the DO-loop that follows it. See Section 10.2.3. CPAR$ LOCKON Ick-var (critical region) CPAR$ LOCKOFF Ick-var Ick-var is a scalar memory reference with a LOGICAL*4 data type. The LOCKON and LOCKOFF directives enclose a critical region of executable code within a parallel DO-loop and permit only one process at a time to execute the region. See Section 10.2.4. CPARS$ PRIVATE name [,name]... name is the name of a symbol or a common block (preceded and followed by a slash). The CPAR$ PRIVATE directive specifies the common blocks or symbols that must be private for each process that runs a parallel DO-loop. See Section 10.2.5. CPARS PRIVATE_ALL The CPAR$ PRIVATE_ALL directive forces all common blocks and symbols to have PRIVATE defaults in routines compiled with the /PARALLEL qualifier. See Section 10.2.6. CPAR$ SHARED /[cb]/[,/[<b]/]-- cb is the name of a common block. The CPAR$ SHARED directive specifies the common blocks to be shared by each process that runs a parallel DO-loop. See Section 10.2.7. CPARS$ SHARED_AILL The CPAR$ SHARED_ALL directive forces all common blocks to have SHARED defaults in routines compiled with the /PARALLEL qualifier. See Section 10.2.8. D-6 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary DATA nlist/clist/[[,] nlist/clist/]... nlist is a list of one or more variable names, array names, array element names, character substring names, or implied-DO lists, separated by commas. Subscript expressions and substring expressions must be constants. clist is a list of one or more constants separated by commas, each optionally preceded by j*, where j is a nonzero, unsigned integer constant. The DATA statement initially stores elements of clist in the corresponding elements of nlist. See Section 4.3. Data Type Declaration See Type Declaration. DECODE (cf,b[,ERR=s][,IOSTAT=ios)) [list] C is an integer expression representing the number of characters to be translated to internal form. is a format identifier. b is a scalar reference or array name reference that contains the characters to be translated to internal form. S is the label of an executable statement. 10s Is an integer scalar memory reference that is defined as a positive integer if an error occurs or as a zero if no error occurs. list i1s an [/0O list. The DECODE statement reads ¢ characters from buffer b and assigns values to the elements in list, converted according to format specification f. See Section A.l. 3 o specifies the length of each record in 16-bit words. specifies unformatted. < is a logical unit specifier. specifies the number of records in the file. 3 DEFINE FILE u(m,n,U,v)[,u(m,n,U,v)]... u 1s an integer variable name. VAX FORTRAN Language Summary D-7 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary The DEFINE FILE statement defines the record structure of a direct access file where u is the logical unit number, m is the number of fixed-length records in the file, n is the length in 16-bit words of a single record, U is a fixed argument, and v is the associated variable. See Section A.2. DELETE(UNIT=]Ju[, REC=][,ERR=s][,IOSTAT=ios]) DELETE (u'r,ERR=s][,IOSTAT=ios]) u is a logical unit specifier. I is a record specifier. S is the label of an executable statement. ios is an [/O status specifier. The DELETE statement deletes records from relative or indexed files. See Section 9.7. DICTIONARY ’‘cdd-path[/[NO]JLIST] ’ cdd-path is the full or relative pathname of a CDD object. [NOJLIST directs the compiler to include or not include the generated FORTRAN source code in the listing. The DICTIONARY statement extracts a data definition from the VAX/VMS Common Data Dictionary, translates it to FORTRAN source code, and includes it in a FORTRAN source program. See Section 1.4.1. DIMENSION a(d){,a(d)]... a(d) is an array declarator. a is an array name. d is the lower (optional) and upper bounds of the array. It takes the form [dl:]du where dl is the lower bound and du is the upper bound. The DIMENSION statement specifies storage space requirements for arrays. See Section 4.5. DO Is[,]] v=el,e2[,e3] D-8 S is the label of an executable statement. VAX FORTRAN allows the \% is a variable name. statement label to be omitted. VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary el is a numeric expression that specifies the initial value of v. e2 is a numeric expression that specifies the terminal value of the control variable. e3 is a numeric expression that specifies the value by which to increment the control variable. The DO statement executes the DO loop by performing the following steps: 1. Evaluates cnt = INT((e2-el+e3)/e3). 2. Sets v =el. 3. If cnt is less than or equal to zero, does not execute the loop. 4. If cnt is greater than zero: a. Executes the statements in the body of the loop. b. Evaluates v =v + e3. c. Decrements the loop count (cnt = cnt-1). If cnt is greater than zero, repeats the loop. See Section 5.3. DO [s[,]] WHILE (e) S is the label of an executable statement. VAX FORTRAN allows the statement label to be omitted. e is a logical expression. The DO WHILE statement is similar to the DO statement, but DO WHILE executes as long as the logical expression contained in the statement continues to be true, instead of for a specified number of iterations. See Section 5.3.2. ELSE The ELSE statement defines a block of statements to be executed if logical expressions in previous IF THEN and ELSE IF THEN statements have values of false. See IF THEN. See Section 5.7.3. ELSE IF (e) THEN e is a logical expression. VAX FORTRAN Language Summary D-9 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary The ELSE IF THEN statement defines a block of statements to be executed if logical expressions in previous IF THEN and ELSE IF THEN statements have values of false, and the logical expression e has a value of true. See IF THEN. See Section 5.7.3. ENCODE (¢ f,b[,ERR=s][,IOSTAT=ios)) [list] C is an integer expression representing the number of characters f is a format identifier. b is a scalar reference or array name reference. S is a label of an executable statement. ios is an integer scalar memory reference that is defined as a positive integer if an error occurs or as a zero if no error occurs. list is an I/0 list. (bytes) to be translated to character form. The ENCODE statement writes ¢ characters into buffer b, which contains the values of the elements of the list, converted according to format specification f. See Section A.l. END The END statement marks the end of a program unit. See Section 5.5. END DO The END DO statement marks the end of the body of a DO loop, and may be used in place of a labeled statement. See Section 5.4. END IF The END IF statement marks the end of a block IF construct. See Section 5.7.3. END MAP The END MAP statement marks the end of a field declaration or a series of field declarations in a UNION. See Section 4.15.3. END STRUCTURE D-10 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary The END STRUCTURE statement marks the end of a structure declaration. See Section 4.15.1. END UNION The END UNION statement marks the end of a union declaration. See Section 4.15.3. ENDFILE (JUNIT=]u|,ERR=s][,IOSTAT=ios)) ENDFILE u u is a logical unit specifier. S is a label of an executable statement. ios is an I/O status specifier. The ENDFILE statement writes an end-of-file record on logical unit u. See Section 9.6. ENTRY nam|[([p[,p]}---D] nam is a subprogram name. p is a dummy argument or an alternate return specifier (*). The ENTRY statement defines an alternate entry point within a subroutine or function subprogram. See Section 6.2.4. EQUIVALENCE (nlist)[,(nlist)]... nlist is a list of two or more variable names, array names, array element names, or character substring names separated by commas. Subscript expressions and substring expressions must be compile- time constant expressions. Records and record fields cannot be specified in EQUIVALENCE statements. The EQUIVALENCE statement assigns the same storage location to each of the names in nlist. See Section 4.6. EXTERNAL v[,v]... EXTERNAL #v{*v]... v is a subprogram name. * is used only if /NOF77 is specified. VAX FORTRAN Language Summary D-11 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary The EXTERNAL statement defines the names specified as user-defined subprograms. See Sections 4.7 and A.6. FIND ((UNIT=}u,REC=t[,ERR=s][,IOSTAT=ios]) FIND (u't[ ERR=s][,IOSTAT=ios)) u is a logical unit specifier. r is a direct access record number. S is a label of an executable statement. ios is an I1/O status specifier. The FIND statement positions the file on logical unit u to record r and sets the associated variable to record number r. See Section A.3. FORMAT (format-spec|,...]) format- is a list of field descriptors and field separators. spec The FORMAT statement describes the format in which one or more records are to be transmitted; a statement label must be specified on the FORMAT statement. See Chapter 8. [typ] FUNCTION nam[*m][([p[,p].-.D] typ is a data type specifier. nam is a function name. *M is a data type length specifier. p is a dummy argument. The FUNCTION statement begins a function subprogram, indicating the program name and any dummy argument names (p). An optional type specification can be included. See Section 6.2.2. GO TO s S is a label of an executable statement. This GO TO statement transfers control to statement number s. See Section 5.6.1. D-12 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary GO TO (slist)[,] e slist is a list of one or more statement labels separated by commas. e is an integer expression. This GO TO statement transfers control to the statement specified by the value of e (if e=1, control transfers to the first statement label; if e=2, control transfers to the second statement label, and so forth). If e is less than one or greater than the number of statement labels present, no transfer takes place. See Section 5.6.2. GO TO vi[,](slist)] v is an integer variable name. slist is a list of one or more statement labels separated by commas. This GO TO statement transfers control to the statement most recently associated with v by an ASSIGN statement. See Section 5.6.3. IF (e) s1,52,83 e 1s an expression. s1,s2,s3 are labels of executable statements. This IF statement transfers control to statement sl, s2, or s3 depending on the value of e (if e is less than zero, control transfers to sl; if e equals zero, control transfers to s2; if e is greater than zero, control transfers to s3). See Section 5.7.1. IF (e) st e i1s an expression. st is any executable statement except a DO, END DO, END, block IF, or logical IF. This IF statement executes the statement if the logical expression has a value of true. See Section 5.7.2. VAX FORTRAN Language Summary D-13 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary IF e1 THEN block ELSE IF e2 THEN block ELSE block END IF el,e2 are logical expressions. block is a series of zero or more FORTRAN statements. This IF statement defines blocks of statements and conditionally executes them. If the logical expression in the IF THEN statement has a value of true, the first block is executed and control transfers to the first executable statement after the END IF statement. If the logical expression has a value of false, the process is repeated for the next If all logical expressions have values of false, the ELSE block is executed. If there is no ELSE block, control transfers to the next executable statement following END IF. ELSE IF THEN statement. See Section 5.7.3. IMPLICIT typ(a[,a]...|,typ(al,al..)]... IMPLICIT NONE typ is a data type specifier. a is either a single letter, or two letters in alphabetical order, separated by a hyphen (for example, X-Y). NONE inhibits the implicit type declaration of variables in the module. The IMPLICIT statement implicitly declares the data types of variables within program units. The element a represents a single letter or a range of letters whose presence as the initial letter of a variable specifies the variable to be of that data type. IMPLICIT NONE and IMPLICIT must not be used in the same program unit. See Section 4.8. INCLUDE 'file-spec[/[NO]JLIST] ' INCLUDE '[file-spec](module-name)[/[NO]JLIST] ’ file-spec D-14 is a character constant that specifies the file to be included. VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary module- is the name of a text module located in a text library. name /[NOJLIST indicates that the statements in the specified file are to be in the source listing. The INCLUDE statement includes the source statements in the compilation from the file or module specified. See Section 1.4.2. INQUIRE (par],par}...) par is a keyword specification having the form: key = value key is a keyword (see the list of keywords and values that follows). value depends on the keyword. Keyword Values Inputs FILE fin UNIT e DEFAULTFILE fin Outputs ACCESS cv BLANK cv CARRIAGECONTROL cv DIRECT cv ERR S VAX FORTRAN Language Summary D-15 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary Keyword Values Outputs (continued) EXIST lv FORM cv FORMATTED cv IOSTAT v KEYED cv NAME cv NAMED lv NEXTREC A NUMBER \ OPENED lv ORGANIZATION cv RECL \% RECORDTYPE cv SEQUENTIAL cv UNFORMATTED cv e is a numeric expression identifying a logical unit. fin is a character expression identifying a file. \ is an integer scalar memory reference. v is a logical scalar memory reference. cv is a character scalar memory reference. S is a statement label. The INQUIRE statement furnishes information on specified characteristics of a file or of a logical unit on which a file might be opened. See Section 9.3. D-16 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary INTRINSIC v],v]... \Y is an intrinsic function name. The INTRINSIC statement identifies symbolic names as representing intrinsic functions and allows those names to be used as actual arguments. See Section 4.9. Map Declaration See Union Declaration. NAMELIST /group-name/ namelist[[,] /group-name/ namelist]... group- is a symbolic name. name namelist is a list of variables or array names, separated by commas, that is associated with the preceding group-name. The NAMELIST statement defines a list of variables or array names and associates that list of names with a unique group-name for use in namelist-directed 1/O statements. See Section 4.10. OPEN (par|,par}...) par is a keyword specification in one of the following forms: keyword keyword = value keyword is a keyword (see the list of keywords and values that value depends on the keyword. follows). VAX FORTRAN Language Summary D-17 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary Keyword ACCESS Values 'SEQUENTIAL' 'DIRECT’ 'KEYED' 'APPEND' ASSOCIATEVARIABLE BLANK \ 'NULL' 'ZERO’ BLOCKSIZE e BUFFERCOUNT e CARRIAGECONTROL 'FORTRAN'’ 'LIST ‘NONE' DEFAULTFILE C DISP (same as DISPOSE) DISPOSE 'KEEP' or 'SAVE' 'DELETE’ 'PRINT’ 'SUBMIT' 'SUBMIT /DELETE’ 'PRINT/DELETE’ D-18 ERR S EXTENDSIZE e FILE C VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary Keyword Values FORM 'FORMATTED' INITIALSIZE e IOSTAT \Y KEY keyspec MAXREC e NAME (same as FILE) NOSPANBLOCKS — ORGANIZATION 'UNFORMATTED' 'SEQUENTIAL' 'RELATIVE' 'INDEXED’ READONLY — RECL e RECORDSIZE (same as RECL) RECORDTYPE 'FIXED' 'VARIABLE' 'SEGMENTED’ 'STREAM' 'STREAM _CR’ 'STREAM _LF’ SHARED — STATUS 'OLD’ TYPE (same as STATUS) UNIT e USEROPEN p 'NEW’ 'SCRATCH' 'UNKNOWN' VAX FORTRAN Language Summary D-19 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary C is a character scalar reference, numeric scalar memory reference, or numeric array name reference. e IS a numeric expression. p is a program unit name. S is a statement label. \ is an integer scalar memory reference. keyspec is el:e2[:dt[:dr]]. el is first byte position of the key. e2 is last byte position of the key. dt is the data type, INTEGER or CHARACTER. dr is the direction of the key, ASCENDING or DESCENDING. The OPEN statement opens a file on the specified logical unit according to the parameters specified by the keywords. See Section 9.1. OPTIONS qualifier[qualifier...] qualifier is one of the following: /NOCHECK /CHECK= { ([NOJOVERFLOW, [NO]BOUNDS, [NOJUNDERFLOW) } ALL NONE /INOJEXTEND_SOURCE /INOJF77 /INOJG_FLOATING /INOJI4 The OPTIONS statement overrides the command line qualifiers for a single program unit. See Section 1.4.3. PARAMETER (p=c[,p=c]...) P D-20 is a symbolic name. VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary is a constant, the name of a constant, or compile—time constant C expression. The PARAMETER statement defines a symbolic name for a constant. See Sections 4.11 and A.4. PAUSE [disp] disp is a decimal digit string containing 1 to 5 digits or a character constant. The PAUSE statement displays a message on the screen and temporarily suspends program execution in order to permit you to take some action. You can respond by typing CONTINUE, EXIT, or DEBUG. See Section 5.8. PRINT See WRITE statements (sequential access). See Section 7.6. PROGRAM nam nam is a program name. The PROGRAM statement specifies a name for the main program. See Section 4.12. Read Statements—Formatted Sequential Access READ ([UNIT=]u,[FMT=]f[ ERR=s][IOSTAT=ios][ END=s]) [list] READ f],list] ACCEPT f],list] u is a logical unit specifier. f is the nonkeyword form of a format specifier. S is a label of an executable statement. i0s is an I/0O status specifier. list is an 1/0 list. These input statements read one or more logical records from unit u and assign values to the elements in the list. The records are converted according to the format specifier (f). See Section 7.2.1.1 and 7.5. Read Statements—List-Directed Sequential Access VAX FORTRAN Language Summary D-21 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary READ ([UNIT=]u,[FMT=]*[ERR=s][,IOSTAT=ios][, END=s)) [list] READ =*[,list] ACCEPT #[,list] u is a logical unit specifier. * denotes list-directed formatting. S is a label of an executable statement. ios is an I/O status specifier. list is an I/0 list. These input statements read one or more logical records from unit u and assign values to the elements in the list. The records are converted according to the data type of the list element. See Section 7.2.1.2 and 7.5. Read Statements—Namelist-Directed Sequential Access READ ([UNIT=]u,[NML=]nl{,ERR=s][,IOSTAT=ios]|[,END=s)) READ nl ACCEPT nl u is a logical unit specifier. nl is a namelist group-name. S is a label of an executable statement. ios is an I[/O status specifier. These input statements read one or more logical records from unit u and assign values to specified namelist entities. The records are converted according to the data type of the namelist entities. See Sections 7.2.1.3 and 7.5. Read Statements—Unformatted Sequential Access READ ([UNIT=]u[,ERR=s][,IOSTAT=ios][,END=s]) [list] u is a logical unit specifier. S is a label of an executable statement. ios is an I/O status specifier. list is an I/O list. This READ statement reads one unformatted record from unit u and assigns values to the elements in the list. D-22 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary See Section 7.2.1.4. Read Statements—Formatted Direct Access READ ([UNIT=]u,[FMT=]f,REC=r[,ERR=s][,IOSTAT=ios)) [list] READ (u'r,[FMT=]f[,ERR=s|,IOSTAT=ios]) [list] u is a logical unit specifier. r is a record specifier. f is a format specifier. S is a label of an executable statement. ios is an I/O status specifier. list is an 1/0O list. This READ statement reads record r from unit u and assigns values to the elements in the list. The record is converted according to f. See Section 7.2.2.1. Read Statements—Unformatted Direct Access ) [list] [ IOSTAT=ios] REC=r ERR=s][, READ ([UNIT=Ju, READ (u'r[,ERR=s]|, IOSTAT=ios]) [list] u is a logical unit specifier. I is a record specifier. S is a label of an executable statement. ios is an I/0 status specifier. list is an 1/0 list. This READ statement reads record r from unit u and assigns values to the elements in the list. See Section 7.2.2.2. Read Statements—Formatted Indexed and Unformatted Indexed Formatted indexed READ statement: READ ([UNIT==]u,[FMT=]f,keyspec[,KEYID=kn][,ERR=s] [ IOSTAT=ios)) [list] Unformatted indexed READ statement: ERR=s] [[IOSTAT=ios]) [list] =]u KEYID=kn][, NIT keyspec[ READ ([U u is a logical unit specifier. VAX FORTRAN Language Summary D-23 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary f is a format specifier. keyspec is a key specifier (see Section 7.1.1.6). kn is a key-of-reference specifier. s is the label of an executable statement. 10S i1s an I/O status specifier. list is an 1/0 list. These input statements read one or more logical records specified by key value, and assign values to the elements in the list. See Sections 7.2.3.1 and 7.2.3.2. Read Statements—Formatted Internal and List-Directed Internal Formatted internal READ statement: READ (intu, fmt [ iostat][,err][,end]) [iolist] List-directed internal READ statement: READ (intu,*[,iostat][,err][,end]) [iolist] intu is an internal file specifier. fmt is a format specifier. * is a list-directed formatting specifier. iostat is an 1/0 status specifier. err, end are transfer-of control specifiers. iolist is the I/O list specifier. These input statements read into elements in the list. They read one or more internal records containing character strings, converting in accordance with the format specification. See Section 7.2.4, RECORD /structure-name/ record-namelist [,/structure-name/record-namelist] [,/structure-name/record-namelist] structure- is the name of a previously declared structure. name D-24 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary record- is one or more variable or array names, or both; separated by namelist commas. The RECORD statement creates a record for each variable specified or an array of records for each array specified. The structure declaration identified by structure-name defines the form of these records. See Section 4.13. RETURN [i] i is an integer value that indicates which alternate return is to be taken. The RETURN statement returns control to the calling program from the current subprogram. See Section 5.9. REWIND ([UNIT=]u[,ERR=s][,IOSTAT=ios)) REWIND u u is a logical unit specifier. S is a label of an executable statement. ios is an 1/0O status specifier. The REWIND statement repositions logical unit u to the beginning of the currently opened file. See Section 9.4. REWRITE Statement—Formatted Indexed and Unformatted Indexed Formatted indexed REWRITE statement: REWRITE ([UNIT=]u,[FMT=]f[ ERR=s}[, IOSTAT=ios]) [list] Unformatted indexed REWRITE statement: REWRITE ([UNIT=]u[,ERR=s][, IOSTAT=ios]) [list] u is a logical unit specifier. f is a format specifier. S is a label of an executable statement. i0s is an 1/0 status specifier. list is an I1/0 list. The REWRITE statement transfers data from internal storage to the current record in an indexed file. VAX FORTRAN Language Summary D-25 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary See Section 7.4. SAVE [a],a]...] a is the name of a variable, an array, or a named common block enclosed in slashes. The SAVE statement retains the definition status of an entity after the execution of a RETURN or END statement in a subprogram. See Section 4.14. Statement Function f(plp)---P =e f is a statement function name. p is a dummy argument. e is an expression. A statement function creates a user-defined function having the variables p as dummy arguments. When referred to, the expression is evaluated using the actual arguments in the function call. See Section 6.2.1. STOP [disp] disp is a decimal digit string containing 1 to 5 digits or a character constant. The STOP statement terminates program execution and prints the display, if one is specified. See Section 5.10. Structure Declaration Block STRUCTURE [/structure-name/] [field-namelist] field-declaration [field-declaration] [field-declaration] END STRUCTURE D-26 structure- is the name that is used in RECORD statements to refer to a name structure. VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary field- are unique field names. (Used only in nested structure declarations.) namelist field- is any declaration or combination of declarations of substructures, declaration unions, or typed data. A structure declaration block defines the field names, types of data within fields, and the order and alignment of fields within a record. Unlike type declaration statements, structure declarations do not create variables. Structured variables (records) are created when you use a RECORD statement containing the name of a previously declared structure. See Section 4.15.1. SUBROUTINE nam[([p[,p].--D] nam is a subroutine name. P is a dummy argument or an alternate return specifier (*). The SUBROUTINE statement begins a subroutine subprogram, indicating the program name and any dummy argument names (p). See Section 6.2.3. TYPE See WRITE statements (sequential access). See Section 7.6. Type Declarations—Character and Numeric Type Declaration (Character): CHARACTER([*len][,]] v[*len)/clist/][,v[*len] /clist/]... len specifies the length of the character data elements; or it can be an asterisk enclosed in parentheses. \Y is a variable name, array name, function or function entry name, or an array declarator. The name can optionally be followed by a length specifier (*n). clist is an initial value or values to be assigned to the immediately preceding variable or array element. The character type declaration assigns the specified data type to the symbolic names (v). See Section 4.4.2. Type Declaration (Numeric): VAX FORTRAN Language Summary D-27 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary type [*n]v[*n][clist][,v[*n][/clist/]] type 1s one of the following data type specifiers: BYTE, LOGICAL, INTEGER, REAL, DOUBLE PRECISION, COMPLEX, or DOUBLE COMPLEX. *1 is an integer that specifies the byte length of v. It must be an acceptable length for the entity (see Table 2-1); *n is not valid for DOUBLE PRECISION and DOUBLE COMPLEX data types. \Y is a variable name, array name, function or function entry name, or clist is an initial value or values to be assigned to the immediately preceding variable or array element. an array declarator. The Numeric Type Declaration assigns the specified data type to the symbolic names (V). See Section 4.4.1. Union Declaration UNION map-declaration map-declaration [map-declaration] [map-declaration] END UNION where map-declaration is: MAP field-declaration [field-declaration] [field-declaration] END MAP field- is any declaration or combination of declarations of substructures, declaration unions, or typed data. Unions define a data area that can be shared by fields or groups of fields at run time. D-28 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary See Section 4.15.3. UNLOCK (JUNIT=}u[,ERR=s][,IOSTAT=ios)) UNLOCK u u is a logical unit specifier. S is a label of an executable statement. ios is an I/0O status specifier. The UNLOCK statement frees a previously locked record in the file connected to logical unit u. See Section 9.8. VIRTUAL a(d)[,a(d)]... a(d) is an array declarator. a 1s an array name. d is the lower (optional) and upper bounds of the array. It takes the form [dl:]du where dl is the lower bound and du is the upper bound. The VIRTUAL statement has the same effect as the DIMENSION statement and is included for compatibility with PDP-11 FORTRAN. See Section 4.5. VOLATILE nlist nlist is a list of one or more variable names, array names, or common block names separated by commas. The VOLATILE statement prevents all optimizations for the items specified in the namelist. See Section 4.16. Write Statements—Formatted Sequential Access WRITE ((UNIT=]u,[FMT=]f[, ERR=s][,IOSTA T=ios)) [list] PRINT f[ list] TYPE f[ list] u is a logical unit specifier. f is a format specifier. S is a label of an executable statement. ios is an I/O status specifier. list is an I1/0O list. VAX FORTRAN Language Summary D-29 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary These output statements write one or more logical records to unit u containing the values of the elements in the list. The records are converted according to f. For information about the formatted sequential access WRITE statement, see Section 7.3.1.1. For information about formatted sequential access PRINT and TYPE statements, see Section 7.6. Write Statements—List-Directed Sequential Access WRITE ((UNIT=]u,[FMT=]*[ ERR=s][,JOSTAT=ios]) [list] PRINT #[ list] TYPE +[list] u is a logical unit specifier. * denotes list-directed formatting. S is a label of an executable statement. ios is an I/0O status specifier. list is an I1/0O list. These output statements write one or more logical records to unit u containing the values of the elements in the list. The records are converted according to the data type of the list element. For information about the list-directed sequential access WRITE statement, see Section 7.3.1.2. For information about list-directed sequential access PRINT and TYPF statements, see Section 7.6. Write Statements—Namelist-Directed Sequential Access WRITE ([UNIT=]u,[NML=]nl[,ERR=s] [[IOSTAT=ios]) PRINT nl TYPE nl u is a logical unit specifier. nl is a namelist group-name. S is a label of an executable statement. ios is an I/O status specifier. These output statements write one or more logical records to unit u containing the values of the namelist entities. The records are converted according to the data type of the namelist entities. For information about the namelist-directed sequential access WRITE statement, see Section 7.3.1.3. For information about namelist-directed sequential access PRINT and TYPE statements, see Section 7.6. D-30 VAX FORTRAN Language Summary Table D-2 (Cont.): VAX FORTRAN Language Statement Summary Write Statements—Unformatted Sequential Access WRITE (JUNIT=]u[, ERR=s][,JIOSTAT=ios)) [list] u is a logical unit specifier. S is a label of an executable statement label. ios is an I/O status specifier. list is an 1/0 list. This WRITE statement writes one unformatted record to unit u containing the values of the elements in the list. See Section 7.3.1.4. Write Statements—Formatted Direct Access WRITE (JUNIT=]u,[FMT=|f,REC=r[, ERR=s][, IOSTAT=ios]) [list] WRITE (u'r,f[,ERR=s][,IOSTAT=ios)) [list u is a logical unit specifier. r is a record specifier. f is a format specifier. S is a label of an executable statement. ios is an I/O status specifier. list is an [/0O list. These WRITE statements write the values of the elements of the list to record r on unit u. The record is converted according to f. See Section 7.3.2.1 Write Statements—Unformatted Direct Access WRITE (J[UNTT=}u,REC=r],ERR=s][,IOSTAT=ios)) [list] WRITE (u'r[,ERR=s][,IOSTAT=ios)) [list] u is a logical unit specifier. I is a record specifier. S is a label of an executable statement. i0s is an I/O status specifier. list is an I1/0 list. These WRITE statements write record r to unit u containing the values of the elements in the list. VAX FORTRAN Language Summary D-31 Table D-2 (Cont.): VAX FORTRAN Language Statement Summary See Section 7.3.2.2. Write Statements—Formatted Internal and List-Directed Internal Formatted internal WRITE statement: WRITE (intu,[FMT=}f[,ERR=s][,IOSTAT=ios)) [list] List-directed internal WRITE statement: WRITE (intu,[FMT=}*[,ERR=s] [[IOSTAT=ios]) [list] intu is an internal file specifier. * denotes list-directed formatting. f is a format specifier. S is the label of an executable statement. ios is an I/O status specifier. list is an 1/0 list. These WRITE statements write elements in the list to the internal file specified by intu. The formatted internal WRITE statement converts the elements to character strings in accordance with the format specification. See Section 7.3.4. D.3 Library Functions Table D-3 lists the VAX FORTRAN intrinsic functions. Superscripts in the table refer to the notes that follow the table. Refer to Section 6.3 for more information about intrinsic functions. For descriptions of the intrinsic function algorithms, refer to the VMS RTL Mathematics (MTH$) Manual. D-32 VAX FORTRAN Language Summary Table D-3: VAX FORTRAN Intrinsic Functions Functions Square Root' a'/? No. of Arguments Generic Name Specific Name Type of Argument Type of Result 1 SQRT SQRT DSQRT REALx4 REAL*8 REAL+*4 REAL=*8 QSQRT Natural Logarithm? 1 LOG logea logjoa Exponential e Sine’ 1 1 1 LOG10 EXP SIN Sin a Sine’(degree) Sin a 1 SIND REAL*16 COMPLEX*8 COMPLEX*8 CDSQRT COMPLEX*16 COMPLEX*16 ALOG REAL*4 REAL*4 DLOG REAL*8 REAL*8 QLOG Common Logarithm® REAL*16 CSQRT REAL*16 REAL*16 CLOG COMPLEX*8 COMPLEX*8 CDLOG COMPLEX*16 ~ COMPLEX*16 ALOG10 REAL#4 QLOG10 REAL*16 REAL*16 EXP DEXP REAL*4 REAL*8 REAL*4 REAL*8 QEXP CEXP REAL*16 COMPLEX*8 REAL*16 COMPLEX*8 ~ COMPLEX*16 DLOG10 REAL#8 REAL*4 REAL*8 CDEXP COMPLEX*16 SIN REAL*4 REAL*4 DSIN REAL*8 REAL*8 QSIN CSIN REAL*16 COMPLEX*8 REAL*16 COMPLEX*8 CDSIN COMPLEX*16 ~ COMPLEX*16 SIND REAL*4 REAL*4 DSIND QSIND REAL*8 REALx16 REAL*8 REAL*16 'The argument of SQRT, DSQRT, or QSQRT must be greater than or equal to zero. The result of CSQRT or CDSQRT is the principal value, with the real part greater than or equal to zero. When the real part is zero, the result is the principal value, with the imaginary part greater than or equal to zero. The argument of ALOG, DLOG, QSQRT, ALOG10, DLOG10, QLOG10, ATAND, ATAN2D, ASIND, DASIND, ACOSD, DACOSD, or QACOSD must be greater than zero. The argument of CLOG or CDLOG must not be (0.,0.). >The argument of SIN, DSIN, QSIN COS, DCOS, QCOS, TAN, DTAN, or QTAN must be in radians. The argument is treated modulo 2*pi. The argument of SIND, COSD, or TAND must be in degrees. The argument is treated modulo 360. VAX FORTRAN Language Summary D-33 Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions No. of Generic Specific Type of Type of Functions Arguments Name Name Argument Result Cosine’ 1 COS Cos a Cosine’ (degree) 1 COSD Tangent’ 1 TAN Cos a Tan a Tangent3 (degree) 1 TAND Tan a Arc Sine*” Arc Sin a Arc Sine (degree) 1 1 ASIN ASIND Arc Sin a Arc Cosine*” Arc Cos a Arc Cosine (degree) 1 1 Arc Cos a ACOS ACOSD DCOS COS REAL=*8 REAL*4 REAL*4 QCOS CCOS CDCOS REAL*16 COMPLEX*8 COMPLEX*16 REAL=*16 COMPLEX*8 COMPLEX*16 COSD REAL*4 REAL*4 REAL*4 DCOSD QCOSD REAL=*8 REAL*16 REAL=*8 REAL=*8 REAL+*16 TAN REAL*4 DTAN REAL*8 REAL*8 QTAN REAL*16 REAL*16 TAND REAL*4 REAL*4 DTAND QTAND REALx*8 REAL=*16 REAL*8 REAL=*16 ASIN REAL*4 REAL*4 QASIN REAL*16 REAL*16 ASIND REAL=*4 REAL*4 DASIND REAL*8 REAL=*8 QASIND REAL=*16 REAL*16 ACOS REAL*4 REALx4 QACOS REAL*16 REAL*16 ACOSD REAL*4 REAL*4 DACOSD QACOSD REAL#*8 REAL=*16 REAL=*8 REAL*16 DASIN DACOS REAL=*8 REAL=*8 REAL#*8 REAL=*8 >The argument of SIN, DSIN, QSIN, COS, DCOS, QCOS, TAN, DTAN, or QTAN must be in radians. The argument is treated modulo 2*pi. The argument of SIND, COSD, or TAND must be in degrees. The argument is treated modulo 360. *The absolute value of the argument of ASIN, DASIN, QASIN, ACOS, DACOS, QACOS, ASIND, DASIND, QASIND, ACOSD, DACOSD, or QACOSD must be less than or equal to 1. The result of ASIN, DASIN, QASIN, ACOS, DACOS, QACOS, ATAN, DATAN, QATAN, ATAN2, DATAN2, or QATAN2? is in radians. The result of ASIND, DASIND, QASIND, ACOSD, DACOSD, QACOSD, ATAND, DATAND, QATAND, ATAN2D, DATAN2D, or QATAN2D is in degrees. D-34 VAX FORTRAN Language Summary Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions Functions No. of Arguments Generic Name Specific Name Arc Tangent’ 1 ATAN Arc Tan a Arc Tangent>’(degree) 1 ATAND Arc Tan a Arc Tangent>® 2 ATAN2 Arc Tan a;/a; Arc Tangent®”’(degree) 2 ATAN2D Arc Tan a;/a Hyperbolic Sine 1 SINH Sinh a Hyperbolic Cosine 1 COSH Cosh.a Hyperbolic Tangent 1 TANH Tanh a Type of Argument Type of Result ATAN REALx4 REAL*4 DATAN REAL*8 REAL*8 QATAN REAL*16 REAL*16 ATAND REAL*4 REAL*4 DATAND REAL=*8 REAL*8 OQATAND REALx*16 REAL*16 ATAN2 REALx4 REAL~*4 DATAN2 REAL=*8 REAL*8 QATAN2 REAL*16 REAL*16 ATAN2D REAL+4 REAL*4 DATAN2D REAL=*8 REAL=*8 QATAN2D REAL=*16 REAL*16 SINH REAL*4 REAL*4 DSINH REAL*8 REAL*8 QSINH REAL*16 REAL*16 COSH REAL*4 REAL*4 DCOSH REAL=*8 REAL*8 QCOSH REAL*16 REAL#*16 TANH REAL*4 REAL*4 DTANH REAL*8 REAL=*8 QTANH REAL*16 REAL*16 "The result of ASIN, DASIN, QASIN, ACOS, DACOS, QACOS, ATAN, DATAN, QATAN, ATAN2, DATANZ2, or QATAN? is in radians. The result of ASIND, DASIND, QASIND, ACOSD, DACOSD, QACOSD, ATAND, DATAND, QATAND, ATAN2D, DATAN2D, or QATAN2D is in degrees. ®If the value of the first argument of ATAN2, DATAN2, or QATAN?2 is positive, the result is positive. When the value of the first argument is zero, the result is zero if the second argument is positive and pi if the second argument is negative. If the value of the first argument is negative, the result is negative. of the second argument is zero, the absolute value of the result is pi/2. value zero. If the value Both arguments must not have the The range of the result for ATAN2, DATAN2, and QATAN2is: -pi < result < pi. ’If the value of the first argument of ATAN2D, DATAN2D, or QATAN2D is positive, the result is positive. When the value of the first argument is zero, the result will be zero if the second argument is positive and 180 degrees if the second argument is negative. negative. arguments must not have the value zero. degrees If the value of the first argument is negative, the result is If the value of the second argument is zero, the absolute value of the result is 90 degrees. < result Both The range of the result for ATAN2D, DTAN2D, QATAN2D is: —180 < 180 degrees. VAX FORTRAN Language Summary D-35 Table D-3 (Cont.): Functions Absolute Value® lal VAX FORTRAN Intrinsic Functions No. of Generic Specific Type of Type of 1 ABS IIABS JIABS INTEGER*2 INTEGER*4 INTEGER=*2 INTEGER*4 Arguments Name Name REAL*4 REAL*8 CABS CDABS COMPLEX*8 COMPLEX*16 REAL*4 REAL=*8 [IABS JIABS INTEGER*2 INTEGER*4 INTEGER=*2 INTEGER*4 [INT JINT REAT %4 REAL*4 INTEGER=*2 INTEGER*4 QABS Truncation” '’ [a] 1 INT [IDINT JIDINT [IQINT JIQINT — — — IDINT IQINT AINT Result REAL*4 REAL*8 ABS DABS IABS Argument — REAL*16 REAL*8 REAL*8 REAL*16 REAL*16 COMPLEX*8 COMPLEX*8 COMPLEX*16 REAL*16 INTEGER*2 INTEGER*4 INTEGER*2 INTEGER*4 INTEGER=*2 INTEGER=*4 INTEGER#2 [IDINT REAL=*8 COMPLEX*16 INTEGER*4 JIDINT REAL*8 INTEGER*4 IIQINT JIOINT AINT REAL*16 REAL*16 REAL*4 INTEGER=*2 INTEGER*2 INTEGER*4 REAL*4 DINT REAL=*8 REAL*8 QINT REAL*16 REAL*16 8The absolute value of a complex number, (X,Y), is the real value SQRT (X**2 + Y**2) 9[x] is defined as the largest integer whose magnitude does not exceed the magnitude of x and whose sign is the same as that of x. For example, [5.7] equals 5. and [-5.7] equals -5. 10The functions INT, IDINT, IQINT, NINT, IDNINT, IQNINT, IFIX, MAX1, MINI, and ZEXT return INTEGER#*4 values if the /14 command qualifier is in effect, INTEGER#2 values if the /NOI4 qualifier is in effect. D-36 VAX FORTRAN Language Summary Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions No. of Generic Specific Type of Type of Functions Arguments Name Name Argument Result Nearest Integer”'° 1 NINT [a+.5*sign(a)] ININT REAL*4 INTEGER*2 JNINT REAL+*4 INTEGER*4 IIDNNT REAL*8 INTEGER*2 JIDNNT REAL=*8 INTEGER*4 HONNT REAL*16 INTEGER*2 JIQNNT REAL=*16 INTEGER*4 IIDNNT REAL=*8 INTEGER*2 JIDNNT REAL=*8 INTEGER*4 IQNINT IIQNNT REAL*16 INTEGER*2 ANINT JIQNNT ANINT REAL=*4 REAL=*8 REAL*16 REALx*4 REAL=*8 REAL*16 LOGICAL=*1 LOGICAL%*2 LOGICAL=*2 LOGICAL*1 INTEGER*2 IDNINT DNINT QNINT Zero-Extend Functions 1 ZEXT IZEXT JZEXT INTEGER*4 LOGICAL=*2 LOGICAL=*4 INTEGER*2 INTEGER*4 Conversion to REAL*4'! 1 REAL FLOATI INTEGER*2 REAL*4 FLOAT] — SNGL SNGLQ — INTEGER*4 REAL=*4 REAL=*8 REAL*16 COMPLEX=*8 REAL=*4 REAL*4 REAL+*4 REAL*4 REAL#*4 — COMPLEX*16 REAL*4 9[)(] is defined as the largest integer whose magnitude does not exceed the magnitude of x and whose sign is the same as that of x. For example, [5.7] equals 5. and [-5.7] equals -5. YThe functions INT, IDINT, IQINT, NINT, IDNINT, IQNINT, IFIX, MAX1, MINI, and ZEXT return INTEGER#*4 values if the /14 command qualifier is in effect, INTEGER#*2 values if the /NOI4 qualifier is in effect. "Functions that cause conversion of one data type to another type provide the same effect as the implied conversion in assignment statements. The following functions return the value of the argument without conversion: the function REAL with a real argument, the function DBLE with a double precision argument, the function INT with an integer argument, and the function QEXT with a REAL*16 argument. VAX FORTRAN Language Summary D-37 Table D-3 (Cont.): Functions Conversion to REAL*8'' VAX FORTRAN Intrinsic Functions No. of Generic Arguments Name 1 - DBLE Conversion to REAL*16'" 1 QEXT Fix!0-11 1 IFIX 1 FLOAT 1 DFLOAT (REAL*4-to- Specific Name Type of Argument Type of Result INTEGER*2 REAL*8 — DBLE — DBLEQ INTEGER*4 REAL*4 REAL=*8 REAL*16 REAL=*8 REAL=*8 REAL*8 REAL*8 — — COMPLEX*8 COMPLEX*16 REAL*8 REAL=*8 — INTEGER*2 REALx*16 — — QEXT QEXTD — — — IIFIX JIFIX INTEGER=*4 REAL*4 REAL*8 REAL*16 COMPLEX=*8 COMPLEX*16 REAL=x4 REAL*4 REAL*16 REAL*16 REAL*16 REAL=*16 REAL=*16 REAL*16 INTEGER*2 INTEGER*4 integer conversion) Float'! (Integer-to- FLOATI INTEGER*2 REAL*4 REAL*4 FLOAT] INTEGER*4 DFLOTI INTEGER*2 INTEGER*4 REAL=*8 — INTEGER*2 INTEGER*4 REAL*16 REAL*16 REAL*4 conversion) REAL*8 Float'’ (Integer-to- DFLOT] REAL*8 REAL=*8 conversion) REAL*16 Float (Integer-to- QFLOAT REAL*16 conversion) 0The functions INT, IDINT, IQINT, NINT, IDNINT, IQNINT, IFIX, MAX1, MINI, and ZEXT return INTEGER#4 values if the /14 command qualifier is in effect, INTEGER*2 values if the /NOI4 qualifier is in effect, HEunctions that cause conversion of one data type to another type provide the same effect as the implied conversion in assignment statements. The following functions return the value of the argument without conversion: the function REAL with a real argument, the function DBLE with a double precision argument, the function INT with an integer argument, and the function QEXT with a REAL*16 argument. D-38 VAX FORTRAN Language Summary Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions Functions No. of Arguments Generic Name Specific Name Conversion to 1,2 CMPLX — INTEGER*2 COMPLEX*8 COMPLEX=*8, 1,2 — INTEGER*4 COMPLEX=*8 or 1,2 — REAL*4 COMPLEX*8 1,2 — REAL=*8 COMPLEX*8 1 — COMPLEX*8 COMPLEX*8 — COMPLEX*16 ~ COMPLEX*8 — INTEGER*2 COMPLEX*16 COMPLEX*8 from Two Arguments'? 1,2 Type of Argument — 1 COMPLEX*8 Conversion to 1,2 COMPLEXx*16, 1,2 — INTEGER=*4 COMPLEX*16 or 1,2 — REAL*4 COMPLEX*16 1,2 1,2 — — REAL*8 COMPLEX*16 1 — COMPLEX*8 COMPLEX*16 1 — COMPLEX*16 REAL COMPLEX*8 DREAL COMPLEX16 REAL*8 AIMAG COMPLEX*8 REAL*4 DIMAG COMPLEX*16 REAL*8 COMPLEX*16 from Two Arguments'? Real Part of Complex Imaginary Part of 1 1 DCMPLX REAL*16 Type of Result — — Complex REAL*16 Complex from Two Arguments (See Conversion to COMPLEX*8 and Conversion to COMPLEX*16) Complex Conjugate 1 CONJG (if a=(X,Y) CON]JG COMPLEX+*8 DCONJG COMPLEX*16 DPROD REAL*4 COMPLEX*16 ~ COMPLEX*16 REAL*4 COMPLEX*8 ~ COMPLEX*16 CONJG(a)=(X,-Y)) REAL#*8 product of 2 — REAL*8 REAL*4s ay*ap 2When CMPLX and DCMPLX have only one argument, this argument is converted into the real part of a complex value, and zero is assigned to the imaginary part. (When there are two arguments (not complex), a complex value is produced by converting the first argument into the real part of the value and converting the second argument into the imaginary part.) VAX FORTRAN Language Summary D-39 Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions No. of Generic n MAX Arguments Name Functions Maximum*° max(ai,az, - - - an) (returns the value from among the argument list; there must be at least two arguments) Minimum "’ min(aj,az, . . an) MAXO0 MAX1 AMAX0 n MIN Name IMAXO0 JMAXO0 minimum value from among the argument list; there must be at least two arguments) MINO MIN1 AMINO 2 (returns the first argument minus the minimum of the two DIM Argument INTEGER=*2 Type of Result INTEGER=*2 AMAX1 REAL*4 INTEGER*4 DMAX1 QMAX1 IMAXO JMAXO0 IMAX1 JMAX1 REAL*8 REAL*16 INTEGER*2 INTEGER*4 REAL*4 REAL*4 REAL*8 REAL*16 INTEGER#*2 INTEGER*4 INTEGER=*2 INTEGER*4 AJMAXO0 INTEGER*4 REAL*4 AIMAXO IMINO INTEGER*2 INTEGER*2 REAL*4 REAL*4 INTEGER*2 JMINO INTEGER*4 INTEGER*4 DMIN1 REAL=*8 REAL*8 IIDIM JIDIM INTEGER*2 INTEGER*4 INTEGER*2 INTEGER*4 DDIM QDIM [IDIM JIDIM REAL*8 REAL=*16 INTEGER*2 INTEGER*4 REAL*8 REAL*16 INTEGER*2 INTEGER*4 QMIN1 IMINO JMINO IMIN1 JMIN1 AIMINO AJMINO DIM IDIM Type of INTEGER*4 AMINI1 (returns the Positive Difference a;-(min(a,az)) Specific REAL*4 REALx*16 INTEGER%*2 INTEGER*4 REAL*4 REAL*4 INTEGER*2 INTEGER*4 REAL*4 REAL=*4 REAL=*16 INTEGER=*2 INTEGER+*4 INTEGER#*2 INTEGER+*4 REAL~*4 REAL*4 REAL*4 arguments) %The functions INT, IDINT, IQINT, NINT, IDNINT, IQNINT, IFIX, MAX1, MINI, and ZEXT return INTEGER*4 values if the /14 command qualifier is in effect, INTEGER*2 values if the /NOI4 qualifier is in effect. D-40 VAX FORTRAN Language Summary Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions Functions No. of Arguments Name Generic Remainder 2 MOD aj-az*[a; /az] Specific Name Type of Argument Type of Result IMOD INTEGER=*2 INTEGER=*2 JMOD INTEGER*4 INTEGER*4 AMOD REAL*4 REAL*4 (returns the DMOD REAL=*8 REAL=*8 remainder when the first QMOD REAL*16 REAL*16 argument is divided by the second) Transfer of Sign la;| Sign a; 2 SIGN IISIGN INTEGER*2 INTEGER=*2 JISIGN INTEGER+*4 INTEGER*4 SIGN DSIGN REAL*4 REAL+*8 REAL*4 REAL*8 QSIGN REAL*16 REAL*16 ISIGN IISIGN JISIGN INTEGER*2 INTEGER*4 INTEGER*2 INTEGER*4 Bitwise AND (performs a logical AND on corresponding bits) 2 IAND [IAND JIAND INTEGER=*2 INTEGER+*4 INTEGER«*2 INTEGER*4 Bitwise OR (performs an inclusive OR 2 IOR IIOR JIOR INTEGER=*2 INTEGER*4 INTEGER=*2 INTEGER*4 2 IEOR IIEOR INTEGER%*2 INTEGER*2 JIEOR INTEGER+*4 INTEGER*4 INOT INTEGER*2 INTEGER=*2 JNOT INTEGER*4 INTEGER=*4 IISHFT INTEGER=*2 INTEGER=*2 JISHFT INTEGER*4 INTEGER*4 on corresponding bits) Bitwise Exclusive OR (performs an exclusive OR on corresponding bits) Bitwise Complement 1 NOT (complements each bit) Bitwise Shift (a1 logically 2 ISHFT shifted left a, bits) VAX FORTRAN Language Summary D-41 Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions No. of Generic Specific Type of Functions Arguments Name Name Argument Type of Result Bit Extraction 3 IBITS (extracts bits a, thru a,+as-1 from [IBITS INTEGER*2 INTEGER*4 JIBITS INTEGER*4 INTEGER*4 ay, see also MVBITS system subroutine) 2 Bit Set IBSET (returns the value [IBSET INTEGER=*2 INTEGER*2 JIBSET INTEGER*4 INTEGER*4 BITEST INTEGER*2 LOGICAL#2 BJTEST INTEGER*4 LOGICAL+*4 of aj with bit a> of a; set to 1) Bit Test 2 BTEST (returns .TRUE. if bit a; of argument a; equals 1) Bit Clear 2 IBCLR (returns the value [IBCLR INTEGER#*2 INTEGER*4 JIBCLR INTEGER*4 INTEGER*4 a, of a; set to 0) Bitwise Circular Shift (circularly shifts rightmost a3 bits of argument a; by 3 ISHFTC [ISHFTC INTEGER=*2 INTEGER*4 JISHEFTC INTEGER*4 INTEGER*4 LEN CHARACTER INTEGER*4 a; places; bits in a; beyond the value specified by a3 are unaffected) Length (returns length of the character expression; see Chapter 2 for additional information on character functions) D-42 VAX FORTRAN Language Summary Table D-3 (Cont.): VAX FORTRAN Intrinsic Functions Functions No. of Arguments Index (C1,C2) 2 Generic Specific Name Type of Argument Type of Name INDEX CHARACTER INTEGER*4 LOGICAL=*1 CHARACTER Result (returns the position of the substring c; in character expression cj; see Chapter 2 for additional information on character functions) Character CHAR (returns a INTEGER*2 character that has the ASCII value specified by the INTEGER*4 argument; see Chapter 2 for additional information on character functions) Nworkers INTEGER*4 NWORKERS (returns the total number of processes executing a routine) SIZEOF (returns the number of bytes of storage used by the argument) Anything with INTEGER*4 a valid data type, except assumed-size arrays or passed-length characters VAX FORTRAN Language Summary D-43 Functions No. of Arguments Generic Name Specific Name Type of Argument Type of Result ASCII Value 1 — ICHAR CHARACTER INTEGER*4 — LLT CHARACTER LOGICAL*4 | VAX FORTRAN Intrinsic Functions NN Table D-3 (Cont.): LLE CHARACTER LOGICAL*4 (returns the ASCII value of the argument; the argument must be a character expression that has a length of 1; see Chapter 2 for additional information on character functions) Character relationals (ASCII collating sequence) D.4 — LGT CHARACTER LOGICAL=4 — LGE CHARACTER LOGICAL*4 System Subroutine Summary The VAX FORTRAN system provides subroutines that you call in the same manner as a user-written subroutine. These subroutines are described in this section. The subroutines supplied are as follows: D-44 VAX FORTRAN Language Summary DATE Returns a 9-byte string containing the ASCII representation of the current date in the form dd-mmm-yy. IDATE Returns three integer values representing the current month, day, and year. ERRSNS EXIT Returns information about the most recently detected error condition. Terminates the execution of a program and returns control to the operating system. SECNDS Provides system time of day, or elapsed time, as a floating-point value in seconds. TIME Returns an 8-byte string containing the ASCII representation of the current time in hours, minutes, and seconds, in the form hh:mm:ss. RAN Returns the next number from a sequence of pseudo random numbers of uniform distribution over the range 0 to 1. MVBITS Transfers a bit field from one storage location to another. References to integer arguments in the following subroutine descriptions refer to arguments of either INTEGER*4 data type or INTEGER*2 data type. However, the arguments must be either all INTEGER#*4 or all INTEGER#*2. In general, INTEGER%*4 variables or array elements may be used as input values to these subroutines if their values are within the INTEGER#*2 range. D.4.1 DATE Subroutine The DATE subroutine obtains the current date as set within the system. The call to DATE takes the following form: CALL DATE(buf) buf Is a 9-byte variable, array, array element, or character substring. The date is returned as a 9-byte ASCII character string taking the following form: dd-mmm-yy dd Is the 2-digit date. VAX FORTRAN Language Summary D-45 mmm Is the 3-letter month specification. Yy Is the last two digits of the year. D.4.2 IDATE Subroutine The IDATE subroutine returns three integer values representing the current month, day, and year. The call to IDATE takes the following form: CALL IDATE(i,j,.k) D.4.3 - | O LI ] k 0 co i o If the current date were October 9, 1988, the values of the integer variables upon return would be as follows: ERRSNS Subroutine The ERRSNS subroutine returns information about the most recent error that has occurred during program execution. The call to ERRSNS takes the following form: CALL ERRSNS(fnum,rmssts,rmsstv,iunit,condval) fnum [s an integer variable or array element in which the most recent FORTRAN error number is stored. VAX FORTRAN error numbers are listed in the VAX FORTRAN User Manual. A zero is returned if no error has occurred since the last call to ERRSNS, or if no error has occurred since the start of execution. rmssts Is an integer variable or array element in which the RMS completion status code (STS) is stored, if the last error was an RMS 1/0 error. rmsstv Is an integer variable or array element in which the RMS status value (STV) is stored, if the last error was an RMS I/0 error. This status value provides additional status information. D-46 VAX FORTRAN Language Summary iunit Is an integer variable or array element in which the logical unit number is stored, if the last error was an 1/O error. condval Is an integer variable or array element in which the actual VAX condition value is stored. Any of the arguments can be null. If the arguments have an INTEGER*2 type, only the low-order 16 bits of information are returned. The saved error information is set to zero after each call to ERRSNS. D.4.4 EXIT Subroutine The EXIT subroutine causes program termination, closes all files, and returns control to the operating system. A call to EXIT has the form: CALL EXIT[(exit-status)] exit-status Is an optional integer argument you can use to specify the image exitstatus value. D.4.5 SECNDS Subroutine The SECNDS function subprogram returns the system time in seconds as a single-precision, floating-point value, minus the value of its single-precision, floating-point argument. The call to SECNDS takes the following form: y = SECNDS(x) y Is set equal to the time in seconds since midnight, minus the user-supplied value of x. The SECNDS function can perform elapsed-time computations. For example: VAX FORTRAN Language Summary D-47 C START OF TIMED SEQUENCE T1 = SECNDS(0.0) C CODE TO BE TIMED DELTA = SECNDS(T1) DELTA gives the elapsed time. The value of SECNDS is accurate to 0.01 second, which is the resolution of the system clock. The time is computed from midnight. The SECNDS subroutine also produces correct results for time intervals that span midnight. The 24 bits of precision provides accuracy to the resolution of the system clock for about one day. However, loss of significance can occur if you attempt to compute very small elapsed times late in the day. More precise timing information can be obtained using the following Run-Time Library procedures: D.4.6 e LIB$INIT_TIMER * LIB$SHOW_TIMER e LIB$STAT_TIMER TIME Subroutine The TIME subroutine returns the current system time as an ASCII string. The call to TIME takes the following form: CALL TIME(buf) buf Is an 8-byte variable, array, array element, or character substring. The TIME call returns the time as an 8-byte ASCII character string having the following form: hh:mm:ss hh Is the 2-digit hour indication. mm Is the 2-digit minute indication. D-48 VAX FORTBAN Language Summary SS Is the 2-digit second indication. For example: 10:45:23 A 24-hour clock is used. D.4.7 RAN Subroutine The RAN function is a general random number generator of the multiplicative congruential type. The result is a floating-point number that is uniformly distributed in the range between 0.0 inclusive and 1.0 exclusive. The call to RAN takes the following form: y = RAN(i) y Is set equal to the value associated, by the function, with the argument 1. The argument i is called the seed. It must be an INTEGER*4 variable or INTEGER*4 array element. The argument should initially be set to a large, odd integer value. The RAN function stores a value in the argument that it later uses to calculate the next random number. There are no restrictions on the seed, although it should be initialized with different values on separate runs in order to obtain different random numbers. The seed is updated automatically, and RAN uses the following algorithm to update the seed passed as the parameter: SEED = MOD (69069 * SEED + 1, 2x%x32) The value of SEED is a 32-bit number whose high-order 24 bits are converted to floating point and returned as the result. D.5 Bit Functions VAX FORTRAN provides intrinsic functions for manipulation of the bits in the binary patterns that represent integer data types. For more information, refer to Table D-3. VAX FORTRAN Language Summary D-49 D.5.1 Bit Position Integer data types are represented internally in binary twos 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. A bit in a binary pattern has a value of 0 or 1. D.5.2 Bit Function Arguments The intrinsic functions IAND, IOR, IEOR, and NOT operate on all of the bits of their argument or arguments. Bit 0 of the result is the result of applying the specified logical operation to bit 0 of the argument or arguments. Bit 1 of the result is the result of applying the specified logical operation to bit 1 of the argument or arguments, and so on for all of 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. ISHFT specifies a logical shift; bits shifted out of one end are lost and zeros are shifted in at the other end. ISHFTC performs a circular shift; bits shifted out at one end are shifted back in at the other end. The functions IBSET, IBCLR, BTEST, and IBITS and the subroutine MVBITS 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 47 is represented by the following: Binary pattern: Bit position: 0...0101111 n...6543210 Where n is the number of bit positions in the numeric storage unit. 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. Negative integers are represented in twos complement notation. For example, the integer —47 is represented by the following;: D-50 VAX FORTRAN Language Summary Binary pattern: Bit position: 0...1010001 n...6543210 Where n is the number of bit positions in the numeric storage unit. Notice that the value of bit position n is as follows: 1 — for a negative number 0 — for a non-negative number All the high-order bits in the pattern from the last significant bit of the value up to bit n are the same as bit n. IBITS and MVBITS operate on general bit fields. Both the starting position of a bit field and its length are arguments to these intrinsics. IBSET, IBCLR, and BTEST operate on 1-bit fields. They do not require a length argument. For optimum selection of performance and memory requirements, FORTRAN provides two integer data types: INTEGER#*2 requires two bytes of storage, while INTEGER*4 requires four bytes. The bit manipulation functions each have a generic form that operates on either of the two integer types and a specific form for each type. When you use the intrinsic functions that refer to bit positions or that shift binary patterns within a storage unit, you must be careful that you do not create a value that is outside the range of integers representable by the data type. For example: INTEGER*2 I,J I 1 J 17 I ISHFT(I,J) The variables I and J have INTEGER=*2 data type. Therefore, the generic function ISHFT maps to the specific function [ISHFT, which returns an INTEGER#*2 result. INTEGER#*2 results must be in the range -32768 to 32767, but the value 1, shifted left 17 positions, yields the binary pattern 1 followed by 17 zeros, which represents the integer 131072. (This would be valid if either I or ] or both were INTEGER#*4 because in both cases ISHFT would map to the specific function JISHFT, which returns an INTEGER*4 value.) If ISHFT is called with constant arguments, it returns an INTEGER+*4 value. VAX FORTRAN Language Summary D-51 D.5.3 MVBITS Subroutine The MVBITS subroutine transfers a bit field from one storage location (source) to a field in a second storage location (destination). The call to MVBITS takes the following form: CALL MVBITS(m,i,len,n,j) m Is an integer variable or array element that represents the source location (the location from which a bit field is transferred). i Is an integer expression that identifies the first bit position in the field transferred from m. len Is an integer expression that identifies the length of the field transferred from m. n Is an integer variable or array element that represents the destination location (the location to which a bit field is transferred). J Is an integer expression that identifies the starting position, within n, for the bits being transferred. The MVBITS subroutine transfers len bits from positions i through i+len-1 of the source location (m) to positions j through j+len-1 of the destination location (n). Other bits of the destination location and all of the bits of the source location remain unchanged. The values of i+len must be less than 32, and j+len must be less than or equal to 32. D-52 VAX FORTRAN Language Summary Index Access, shared SHARED keyword See Subtraction or unary minus operator See Exclamation point See Quotation marks See Dollar sign on OPEN statement ® 9-4, 9-21 Access keys for indexed files specified in OPEN statement®9-15 Access modes direct in OPEN statement keywords ® 9-2 ACOSD intrinsic function® D—-34 ACOS intrinsic function®D-34 Actual arguments See Asterisk * % See Exponentiation operator See Addition or unary plus operator See Colon See Question mark See Division operator /1 See Concatenation operator A aggregate field references used as ® 2—-37 external procedure names used as®4-21to 4-22 unsubscripted array used as ® 2-29 Addition operator (+)® 2—42 to 2-44, 2-51 Adjustable arrays ® 2—-29 in RECORD statements ® 2—-38 A field descriptor® 8—29 to 8-31 Aggregate assignment statement ® 3—6 Aggregate field reference examples®2-38 to 2-39 format of ® 2-36 to 2-37 Aggregate reference ® 2—39 to 241 AIMAG intrinsic function ® D—39 AINT intrinsic function ® D—-36 Allocation see File storage allocation ABS intrinsic function ® D-36 Absolute Value intrinsic function ® D—-36 ACCEPT statement® 7—47 to 7-48 Alternate return argument ® 6—9 ACCESS .AND. INQUIRE statement specifier ® 9-25 OPEN statement keyword ® 9—-4, 9-8 AMAXO intrinsic function ® D—40 AMINO intrinsic function ® D-40 See logical operators ANINT intrinsic function ® D—37 Index-1 ANSI Standard Array element comparison with ISO Standard® 1—1 defining values of® 3—1 VAX FORTRAN extensions of® 1—-1 Array name APPEND references to®2-39 to OPEN statement keyword value ® 9—4 'APPEND’ Array references OPEN statement keyword value ® 9—-8 Arc Cosine (degree) intrinsic function ® D-34 Arc Cosine intrinsic function ® D-34 in dimension bounds expressions ® 2—-26 without subscripts ® 2—-29 with subscripts ® 2—-27 Arc Sine (degree) intrinsic function ® D-34 Arrays Arc Sine intrinsic function ® D-34 Arc Tangent (degree) intrinsic function ® D-35 Arc Tangent intrinsic function® D-35 addressing character substrings in elements of®2-30 to 2-31 adjustable ® 2-29 Arguments See also Actual arguments, Dummy arguments aggregate field references as ® 2-37 arrangement of elements ® 2—-27 associating two or more ® 2-25 assumed-size ® 2—-30 associating array elements with® 2—-25 data types of ® 2—1 associating variables with® 2—-22 data typing ® 2—29 bit function arguments ® D-50 to D-52 declarators ® 2-25 to external procedure names used defining in as®4-21to 4-22 general description®6-2 to definition of ® 2—-4 dimension bounds expressions ® 2—-25 to 6-5 elements as scalar references ® 2—-39 character arrays ® 6—7 establishing with subprogram references® 2—25 defaults for arguments general description® 2-24 to 6—11 Hollerith and character constants ® 6—8 overview ® 6—2 passed-length character arguments ® 6—7 intrinsic function names used as ® 4—-23 argument list functions (% VAL, %REF, %DESCR)®6-9 to 6-11 Arithmetic assignment statement®3—-1 to 2-46 4-16 references to in statements ® 2—29 subscripts ® 2—-27 ASCIl character set® B-2 ASCII collating sequence functions ® D—45 ASCII constants data type ranking ® 2—-45 assigned in DATA statements ® 4—7 in relational expressions ® 2—48 operator precedence® 2-43 to ASCIl Value intrinsic function ® D—45 2-44 2-45 rules governing typing of® 2—45 to Arithmetic IF statement®5—16 Arithmetic operators 2-Index in structure declaration blocks® 2—-32 usage restrictions ® 2—-29 3-3 compile-time ®4-27, 4-28 order of evaluation® 2-43 to SHARED ® 10-3 initializing with DATA statements®4-5 to unsubscripted array names %LOC function®6-—11 Arithmetic expressions ® 2—42 to 2-25 inability to dimension within CONTEXT_ making equivalent®4—-14 to use of built-in functions in expressions®2-42 to 2-26 dimensioning®4—12 assumed-size arrays ® 6—6 passing®6-9 to 2-26 a COMMON statement ® 4—4 defining with character type declarations ® 4—11 6-11 alternate return arguments ® 6—9 arrays ®*6-3 to 2-41 unsubscripted in a DATA statement ® 4—6 ASIND intrinsic function ® D-34 ASIN intrinsic function ® D-34 2-46 Assigned GO TO statement®5-14 to for®3-7 to 2-44, D-1 5-15 establishing symbolic statement labels 3-8 4-8 Assignment statements BLANK character®3—-4 to 3-5 INQUIRE statement specifier® 9—-26 OPEN statement keyword ® 9—-4, 9-8 Blank common block ® 4-3 logical ® 3—4 Blank control editing aggregate ® 3—6 arithmetic® 3—1 to 3-3 ASSIGN statement® 3-7 to 3-8 ASSOCIATEVARIABLE OPEN statement keyword ® 9—4, 9-8 Association of arrays ® 2-24 of variables ® 2—-22 Assumed-size arrays ® 2—-30 BN and BZ edit descriptors®8-10 to 8-11 Blank lines® 1-8, 1-13 Block DATA statement®4-2 to 4-3 BLOCK DATA statement position after OPTIONS statement® 1-19 Block DATA subprogram ®4-2 to 4-3 BLOCK DATA subprogram comment line indicator® 1-8, 1-13 forcing linker to search libraries ® 4-21 Block IF constructs®5-17 to 5-24 format specifier Blocks Asterisk (*) in list-directed |/O®7-2, 7-5 multiplication operator® 2—-42 to 2-44, 2-51 upper bound of array ® 2—-25 Asterisk (*) length specifier for dummy argument or function name ®4-11 in numeric type declarations ® 4-9 ATAN2 intrinsic function ® D-35 ATAND2D intrinsic function ® D-35 ATAND intrinsic function®D-35 ATAN intrinsic function®D-35 OPEN keywords affecting ® 9-2 BLOCKSIZE OPEN statement keyword ® 9-4, 9-9 BN edit descriptor® 8—-10 BTEST intrinsic function® D—-42 BUFFERCOUNT OPEN statement keyword ® 9—4, 9-9 Built-in functions argument list functions %VAL, %REF, %DESCR®6-9 to 6-11 %L.OC function®6—11 BYTE as a data type ®2-2 as storage location® 2-3 BACKSPACE statement See also REWIND statement general description ® 9-35 Binary operators declaring data type ®4-8 to 4-10 equivalence with LOGICAL*1®4-9 BZ edit descriptor® 8—11 definition of ® 2—-43 Bit Clear intrinsic function® D—42 C Bit field transfers C Bit Extraction intrinsic function® D—42 MVBITS subroutine ® D-53 Bit functions general information about ® D-50 to D-52 Bit Set intrinsic function ® D—42 Bit Test intrinsic function® D—-42 Bitwise AND intrinsic function® D—-41 Bitwise Circular Shift intrinsic function ® D-43 Bitwise Complement intrinsic function ® D—41 Bitwise Exclusive OR intrinsic function® D—-41 Bitwise OR intrinsic function ® D—41 Bitwise Shift intrinsic function® D—42 to begin a compiler directive® 1-13 See also Compiler directives to indicate a comment line® 1-8, 1-13 Calendar dates subroutines for calculating DATE and IDATE ®D-46 CALL statement®5-2 to 5-3 use of return args® 5-25, 5-27 use with ENTRY statement® 6—-24 use with SUBROUTINE statement®6-18, 6-20 Index-3 CALL statement (cont’d.) Characters (cont’'d.) using names declared in INTRINSIC statement ® 4-23 defining values of® 3—1 in character and Hollerith constants® 1—9 using names specified in EXTERNAL statement ® 4-21 printable/nonprintable ® 1-9 Character set® 1-8 CARRIAGECONTROL ASCIll®B-2 INQUIRE statement keyword ® 9-26 OPEN statement keyword ® 9—4, 9—-10 Carriage control characters ® 8-38 to 8-39 Carriage control editing® 8—38 to 8-39 CDD$TOP® 1-16 FORTRAN®B-1 Radix-50®B-4 to B-5 Character storage units ® 2—2 Character substrings addressing in variables, arrays, and array CDD records® 1-15 elements® 2-30to CDECS$ IDENT directive® 10-10 CDEC$ PSECT directive® 10-11to 10-12 CDEC$ SUBTITLE directive® 10-13 2-31 as scalar references ® 2—39 definition® 2—-4 making equivalent®4-17 to 4-20 CDEC$ TITLE directive® 10-13 Character type declaration statement CHARACTER general description®4—-10to data type 4-12 CHAR function®6-32 definition ® 2—1 CHAR intrinsic function® D—44 representation in memory®C—11 CLOSE statement storage requirement ® 2—-2 to 2-3 Character arguments general description® 9-23 to 9-24 CMPLX intrinsic function ® D-39 passed length® 2-23 Coding form® 1-10 Character assignment statement® 3—4 to 3-5 Character comparison library functions LEN, INDEX, ICHAR, CHAR®6-30 to 6-32 See also Lexical comparison functions Character constants Colon (:) edit descriptor ® 8—-38 Columns comment indicator position® 1-13 continuation indicator position® 1-14 as actual arguments ® 6—-8 inaline® 1-2 assigned in DATA statements ® 4—7 of a statement label field® 1-13 general description®2—-18 to 2-19 upper and lowercase letters in® 1-9 use of space within® 1-9 Character editing (A,H)®8-29 to 8-32 character constants ® 8—-32 Character expressions ® 2—47 sequence number field position® 1-15 statement field position® 1-14 Comment® 1-7 to 1-8 allowable characters in® 1-9 in a parallel DO-loop ® 10-4 Comment line indicator compile-time® 4-27 D in column 1®1-14 in relational expressions ® 2—48 general description® 1-7 CHARACTER FUNCTION statement® 6—15 Character intrinsic function ® D—44 Character operators ® 2—47 in expressions ® D—1 Character relational intrinsic functions ® D—45 Characters See also uppercase characters, lowercase characters declaring variables ® 4—10 4-Index common block names in COMMON statement ® 4—4 Common block COMMON and EQUIVALENCE interaction ® 4—-20 default attributes of ® 10—12t establishing order of contents ® 4-4 initializing values in®4-2 to 4-3 Complex from Two Arguments function (cont’d.) Common block in parallel processing See CMPLX intrinsic function, DCMPLX intrinsic ® specifying private default shareability specifying private shareability ® 10-6 specifying shared default shareability® specifying shared shareability® 10-7 modifying attributes of® 10—-11 modifying shareability in paraliel 10-7 intrinsic functions to operate on® 6-26 Concatenation operator (//)®2-47, 2-51 CONJG intrinsic function ® D—39 Connections, logical to logical 1/O units explicitly by means of OPEN ® 9-22 Common Data Dictionary See DICTIONARY statement Common logarithm intrinsic function ® D—-33 COMMON statement Constants as scalar references ® 2—-39 assigning symbolic names with PARAMETER statement® 4-26 to 4-28 See also Common block establishing arrays with®2-24, 2-25 establishing variables with® 2-22 general description®4-3 to 4-5 interaction with EQUIVALENCE ® 4-20 using unsubscripted array names® 2-29 Compilation options overriding FORTRAN command options® 1-18 to intrinsic functions that operate on® D-39 Computed GO TO statement®5-13 to 5-14 10-8 DO-loop® 10-2 to function Complex numbers 10-7 1-19 Compiler directives® 10—1to 10-13 Compile-time constant expressions ®4-27 to 4-28 COMPLEX declaring data type®4-8 to 4-10 COMPLEX*16 constants ® 2—-14 data type representation in memory®C-8 to C-10 storage requirement®2—-2 to 2-3 D_floating and G_floating implementations ® 2—-4 COMPLEX*8 constants®2-13 to 2-14 data type definition ® 2-1 representation in memory ® C-8 storage requirement®2—-2 to 2-3 Complex Conjugate intrinsic function ® D-39 Complex data editing ® 8-25 Complex entities in relational expressions ® 2—-48 Complex from Two Arguments function character®2-18 complex®2-13to 2-15 data types of ® 21 definition® 2-4 hexadecimal®2-15 to 2-18 Hollerith® 2—19 to 2-21 initialized by a PARAMETER statement ® 2—-46 integer ® 2-5 logical® 2—-18 octal®2—-15 to 2-18 Radix—50 ® B—4 real®2-8 to 2-13 specifying data types of®2-5to 2-21 using a symbolic name® 4—-27 CONTEXT_SHARED directive ® 10-3 CONTEXT_SHARED_ALL directive® 10-3 Continuation indicator field® 1-10, 1-14 Continuation line ® 1-2 effect on statement labels® 1-13 in debug source statements ® 1-14 indicator in source code® 1-14 in included files® 1-17 use of in compiler directive ® 101 CONTINUE statement ® 5-3 Control characters ® 1-9 Control list parameters general description®7-2 to 7-3 Control statements®5—-1 to 5-28 See also CALL, RETURN in parallel DO-loop® 10-4 Control transfer FORTRAN control statements®5—-1 to 5-28 index-5 Control transfer (cont'd.) Data items with DO-loops ® 5—-8 as scalar references ® 2—-39 Conversion of data types in arithmetic assignments ® 3—3t with FORMAT statements ® 8—1 defining values for ® 3—1 definition ® 2—4 identified by symbolic names ® 1-7 Conversion to COMPLEX*16 function ® D—-39 DATA statement Conversion to COMPLEX*8 function ® D-39 general description®4-5 to 4-8 Conversion to REAL*16 function® D-38 to define arrays and elements ® 2—-25 Conversion to REAL*4 function® D-37 using unsubscripted array names ® 2-29 Conversion to REAL+*8 function® D—38 Data type declaration statement COSD intrinsic function® D—-34 See also Type declaration statement COSH intrinsic function® D-35 character type declarations®4-10 to Cosine (degree) intrinsic function ® D-34 numeric type declarations ® 4-8 to Cosine intrinsic function ® D—34 4-12 4-10 use to establish arrays ® 2—-24 COS intrinsic function ® D—-34 using unsubscripted array names ®2—-29 CPAR$ CONTEXT_SHARED directive® 10-3 CPARS$ CONTEXT_SHARED_ALL directive® 10-3 CPARS$ DO_PARALLEL directive® 10-4 to CPAR$ LOCKOFF directive® 10-5 to 10-6 CPAR$ LOCKON directive ® 10-5 to 10-6 10-5 Data types ability of entities to have® 1-7 conversion in arithmetic assignment statements ® 3—3t declaration within structures ® 4—-34 used to resolve data dependences ® 10-5 default data types of undeclared names®4-22 CPARS$ PRIVATE directive® 10-6 to 10-7 CPARS PRIVATE_ALL directive® 10-7 CPAR$ SHARED directive ® 10-7 definition of different types®2-1to 2-2 establishing in arithmetic expressions ® 2—-45 to CPAR$ SHARED_ALL directive® 10-8 2-46 length specifiers ® 2—-2 Critical region rank in arithmetic expressions ® 2—45 in a parallel DO-loop ® 10-5 specifying for arrays ® 2—-28 specifying for constants® 2-5 to 2-21 specifying for variables ® 2—-22, 2-23 to 2-24 Dates, calendar D subroutines for calculating in REAL*8 constants ® 2—11 DATE and IDATE ® D-46 D_floating data implementation DATE subroutine ® D-46 representation in memory COMPLEX+16®C—-8 to DBLE intrinsic function ® D—-38 C-9 DCMPLX intrinsic function ® D—-39 REAL+»8¢(C-3, C-5 D debugging statement indicator with COMPLEX+*16 data type®2-4, 2-14 with REAL*8 data type ® 2—-4, 2—-10 in column 1 1-14 Debugging statements ® 1—-14 /D_LINES qualifier® 1-14 Declarators, array® 2-25 to 2-26 Data DECODE statement® A—1 to A-3 as stored in memory by VAX FORTRAN®C-1to DEFAULTFILE C-12 INQUIRE statement keyword ® 9-25 editing OPEN statement keyword ® 9—4, 9—-10 with FORMAT statements ® 8—1 retaining after END or RETURN®4-30 to Data dependences in a parallel DO-loop ® 10-5 6-Index Defaults 4-31 argument passing defaults ® 6—10 data type of undeclared names ® 4-22 field descriptors vs. 1/0 list elements ® 8—33 DEFINE FILE statement® A-3 to A-4 DELETE transferring control ® 5—8 DO statements®5-3 to 5-12 file description® 9-23 indexed®5—4 to 5-9 DELETE statement general description ® 9-36 to 9-37 Delimiting periods pretested indefinite DO WHILE®5-9 to 5-11 DOUBLE COMPLEX of logical values ® 2-50 declaring data type®4-8 to of relational values ® 2—48 4-10 DOUBLE PRECISION %DESCR built-in function® 6-10 declaring data type®4—-8 to D field descriptor ® 8—21 DO WHILE statement®5-9 to in complex data editing ® 8—25 4-10 5-11 DO_PARALLEL directive® 10-4 to DFLOAT intrinsic function ® D—-38 DICTIONARY statement® 1-15to DO-loop (cont’'d.) 1-16 DIMAG intrinsic function ® D—39 Dimension bounds expressions See Arrays Dimensions array limits ® 2-24 declaring of an array ® 2—-25 to 2-26 DIMENSION statement 10-5 DPROD intrinsic function® D—39 DREAL intrinsic function® D—39 Dummy arguments aggregate field references used as ® 2—-37 inability to declare in CONTEXT_SHARED® 10-3 unsubscribed array names used as ® 2-29 using asterisk (*) length specifier®4—11 general description®4—-12 to 4-13 use to establish arrays ® 2-24 DIM intrinsic function ® D-40 DIRECT Edit descriptors INQUIRE statement specifier® 9—-27 summary ® 8—6 to OPEN statement keyword value ® 9-4 E field descriptor® 8—19 Direct access FIND statements ® A-5 Direct access mode OPEN statement keywords ® 9-2 Direct access READ statements ® 7-26 to 7-27 Direct access WRITE statements®7-39 to 7—40 Directives See Compiler directives '‘DIRECT’ OPEN statement keyword value ® 9-8 DISP CLOSE statement keyword ® 9-23 DISPOSE 8-7 in complex data editing ® 8-25 ELSE IF THEN statement block IF constructs®5—17 to 5-24 ELSE statement block IF constructs®5—-17 to 5-24 ENCODE statement® A—-1 to A-3 END DO statement®5-11to 5-12 ENDFILE statement® 9-35 to 9-36 END IF statement block IF constructs® 5—-17 to 5-24 END MAP statement ® 4-39 End-of-file condition CLOSE statement keyword ® 9-23 reporting with IOSTAT value ® 7-9 OPEN statement keyword ® 9—-4, 9—-11 transferring control with END specifier® 7—-10 Division operator (/)®2-42 to 2-44, 2-51 Dollar sign ($) delimiter for namelist record ® 7-20 edit descriptor® 8-37 to 8-38 in @ symbolic name® 1-6 DO-loop See also Parallel DO-loop End-of-file record ENDFILE statement® 9—35 to 9-36 END specifier in 1/O statements® 7-10 END statement general description® 5—12 with BLOCK DATA statement® 4-3 Index-7 END statement (cont'd.) EXIST with FUNCTION statement®6—15 INQUIRE statement specifier ® 9-27 with SUBROUTINE statement® 6-18 EXIT system subroutine ® D—-48 END UNION statement ® 4—-39 EXP intrinsic function® D-33 ENTRY statement®6-21to 6-24 Explicit formatting use with FUNCTION statement® 6—17/ I/O statement specifier® 7-4 to use with SUBROUTINE statement®6—-19 using unsubscripted array names ® 2—-29 Exponentiation operator (**)®2-42 to EQ. 2-44, 2-51 See relational operators Exponents EQUIVALENCE statement in REAL*4 constants ® 2—-8 associating arrays with ® 2-25 in REAL*8 constants ® 2—-10 associating variables with® 2—-22 in REAL*16 constants ®2-12 contrasted with union declaration ® 4—40 general description®4—-13 to Expressions, FORTRAN 4-20 See also Arithmetic expressions, Character interaction with COMMON ® 4-20 use of unsubscripted arrays with® 2-22, expressions, Logical expressions, 2-25 Relational expressions using unsubscripted array names® 2-29 as scalar references ® 2—-39 EQV. compile-time constant See logical operators expressions®4-27 to 4-28 ERR data types of® 2—1 BACKSPACE statement keyword ® 9-35 definition of CLOSE statement keyword ® 9-23 summary of®*D—-1 to ENDFILE statement keyword ® 9-35 |/O statement specifier® 7—10 INQUIRE statement specifier® 9—-27 OPEN statement keyword ® 9—4, 9-12 REWIND statement keyword ® 9-34 UNLOCK statement keyword ® 9-38 Error condition EXTENDSIZE OPEN statement keyword ® 9—4, 9—12 External field separators ® 8—40 to External procedures invoking with CALL ® 5-2 ERRSNS subroutine ® D—47 unsubscripted array names as dummy user controls in 1/O statements ERR, END, and IOSTAT specifiers® 7-9, 7-10 arguments ® 2-29 EXTERNAL statement®4-21 to 4-22 /NOF77 implementation® A—8 to ERRSNS subroutine ® D—47 A-9 to search object libraries for block data Exclamation point (!) subprograms® 4-3 comment indicator® 1-8, 1-13 Executable statements® 1-2, 1-4 Execution, program temporarily suspending STOP®5-27 8-41 External procedure names duplicating intrinsic function names ® 4-21 subroutine for obtaining error information EXIT®D-48 8-10 Extended ranges, DO-loop ® 5-9 as arguments®4-21 to 4-22 Error handling terminating D-2 variable FORMAT ®8-9 to during I/O®7-9, 7-10 (PAUSE)®5-24 to ®2—-42 expression operators DELETE statement keyword ® 9-36 8-Index 7-5 Exponential intrinsic function ® D-33 5-25 F F_floating data implementation representation in memory COMPLEX+8®(C-8 REAL*4¢C-4 File-handling commands (cont'd.) F field descriptor®8-17 REWIND statement ® 9—-34 in complex data editing® 8—25 File sharing Field in FORTRAN source code® 1-9 to 1-15 SHARED keyword (OPEN statement) ® 9—4, 9-21 Field declarations File specifications allowable entities ® 4—35 OPEN statement keywords ® 9-2 Field descriptors File status defaults for 1/0 list elements ® 8—33 summary ® 8-6 to CLOSE statement keywords ® 9-23 8-7 OPEN statement keywords Field namelist ® 4—34 DISPOSE ®9-4, 9-11 Field names ® 4-34 STATUS or TYPE®9—-4, 9-22 in structure declarations ® 4-38 File storage allocation Field references OPEN statement keywords ® 9-2 See Record and field references %FILL® 2-33, 4-34, 4-38 Fields FIND statement® A-5 definition in structure Fixed-format® 1-10to declarations ® 4—-33 to 4-38 initialization of unnamed fields ® 2—-33 1-11 Fixed-length records RECORDTYPE keyword Fields, unnamed (OPEN statement) ®9-4, use of %FILL®2-33 Field separators, external® 8—40 to 8-41 9-20to 9-21 Fix intrinsic function® D-38 Floating-point data types File combining at compilation® 1-17 to 1-18 DELETE statement® 9-36 to 9-37 CLOSE statement keywords ® 9-23 in I/O statements ® 7-4 FORM 1-18 INQUIRE statement specifier ® 9—-28 processing options OPEN statement keywords ® 9-2 OPEN statement keyword ® 9—4, 9-13 Format properties, inquiring about INQUIRE statement ® 9-24 to 9-33 providing a listing header for® 10-13 record description options, 1/0 OPEN statement keywords ® 9-2 coding with fixed format® 1-10to coding with tab format® 1-11to BACKSPACE statement® 9-35 repositioning with REWIND statement ® 9-34 1-11 1-13 Formats passed length ® 2—-2 run-time®8-41to repositioning 8-42 Format specification separators ® 8—39 to 8-40 Format specifier control list parameter status options OPEN statement keywords ® 9-2 in 1/O statements ® 7—4 FORMAT statements FILE INQUIRE statement keyword ® 9—-25 arithmetic expressions in®8-9 to OPEN statement keyword ® 9—4, 9-13 description of use ® 8—1 8-10 external field separators ® 8—40 to 8-41 File-handling commands BACKSPACE statement® 9-35 CLOSE statement®9-23 to 9-24 INQUIRE statement®9-24 to OPEN statement®9-2 to C-10 FLOAT intrinsic function® D-38 FMT format specifier disposition INCLUDE files® 1-17 to emulation of ® 2—-4 representation in memory® C-3 to deleting records from 9-33 9-23 field and edit descriptors additional editing operations (Q,%$,))*8-36 to 8-38 blank control editing, (BN,BZ)® 8—-10 Index-9 FORMAT statements field and edit descriptors (cont’'d.) character editing (A,H) ® 8-29 to 8-32 FORTRAN command (DCL) (cont’'d.) overriding® 1-15, 1-18 to memory®C-1to C-12 counts, repeat ® 8—8 integer editing (1,0,Z)®*8-12 to 8-17 1-19 FORTRAN data representation in FORTRAN statements® 1-2 to 1-5 logical editing (L) ® 8—-28 assignment statements®3-1 to 3-8 positional editing (X, T,TL,TR)® control statements®5-1 to 5-28 8-34 to 8-36 /O statements® 7—1 to 7-49 real editing (F,E,D,G)®*8-17 to 8-25 I/0 statements, auxiliary ® 9—-1 to 9-38 scale factor editing (P)® 8-25 to 8-27 language summary (alphabetic)® D—-2 to sign control editing (SP,SS,S) ® 8-11 scalar field references in ® 2—-37 summary of® 8—6 to 8-7 specification statements ®4—1 to 4-42 use of character constants ® 8—-32 supplemental statements supported to maintain non-VAX FORTRAN format expressions, variable® 8-9 to 8-10 compatibility® A-1to format specification separators ® 8—39 to 8-40 general rules®8-2 to 8-3 1/0 lists, interaction with®8-42 to 8-46 A-9 Function name using asterisk (*) length specifier ® 4—1 Function references input rules ® 8—3 data types of® 2—1 output rules®*8-3 to 8-4 run-time formats®8-41 to 8-42 types of references to intrinsic functions general description®6—-16 to 6—-18 specific and generic ® 6-25 to 6-30 syntax®8-4 to 8-6 FORMATTED INQUIRE statement specifier® 9—-28 Formatted |/O statements ACCEPT statement® 7—-47 establishing symbolic statement labels for®e3-7 to 3-8 PRINT statement® 7-48 to 7-49 READ statements direct access ® 7—-26 indexed® 7-28, 7-29 internal® 7-31 D-32 Functions See Built-in functions See Intrinsic functions, system supplied See Lexical comparison library functions See Statement functions FUNCTION statement®6-15 to 6-18 logical and numeric functions ®6—-15 position after OPTIONS statement® 1-19 using unsubscripted array names ® 2—-29 Function subprograms ®6—-15 to 6—18 sequential® 7—15, 7-16 REWRITE statement® 7—-45, 7-46 TYPE statement® 7—-48 to 7-49 WRITE statements direct access ® 7-39, 7-40 G _floating data implementation representation in memory COMPLEX+16*C-10 indexed® 7-41, 7-42 internal® 7-43, 7-44 sequential® 7-33, 7-34 to 7-35 FORTRAN-66 VAX FORTRAN support of® 1-—1 FORTRAN-77 VAX FORTRAN extensions of® 1-1 FORTRAN character set® B—1 FORTRAN command (DCL) /D_LINES ® 1-14 10-iIndex REAL+*8® C-6 with COMPLEX+*16 data type®2—-4, 2-14 with REAL+*8 data type ® 2—4, 2-10 .GE. See relational operators General directives® 10-10 to 10-13 ordering with statements ® 1-3f Generic references |/O statement components Generic references (cont'd.) to intrinsic function names ®6-26 to 6-27, control list parameters (cont’'d.) namelist specifier ® 7—-5 6-28 record specifier ® 7—6 G field descriptor® 8—22 in complex data editing ® 8—25 rules for specifying® 7-3 transfer-of-control specifier® 7—10 GO TO statement establishing symbolic statement labels for I/0 list parameter® 7—-11 to 7-14 implied-DO lists®7—-13 to 7-14 assigned® 3-7 to 3-8 GO TO statements®5-12 to 5-15 interaction with format controls ® 8—42 to 8-46 Group repeat counts simple list elements ® 7—12 in FORMAT statements ® 8—8 /O statements GT. See relational operators See also I/0O statement components, ACCEPT, FORMAT, OPEN, PRINT, READ, REWRITE, TYPE, WRITE in parallel DO-loop® 10-4 list of ® 7—1 H_floating data implementation OPEN statement interdependencies representation in memory logical unit specifier® 7—4 REAL=16® C-7 Hexadecimal constants®2-5, 2—15 to 2-18 assigned in DATA statement® 4-7 data type assignments ® 2—-16 to 2-17 specifiers See 1/0 statement components using unsubscripted array names ® 2—-29 I/O status specifier H field descriptor® 8-32 Hollerith constants® 2—-5, 2—-19 to 2-21 assigned in DATA statements ® 4-7 control list parameter in 1/O statements ® 7-9 upper and lowercase letters in® 1-9 IABS intrinsic value® D-36 use of space within® 1-9 IAND intrinsic function ® D-41 IBCLR intrinsic function®D—42 Hollerith Constants IBITS intrinsic function ® D—-42 representation in memory ® C—-11 Hyperbolic Cosine intrinsic function ® D-35 Hyperbolic Sine intrinsic function ® D—35 Hyperbolic Tangent intrinsic function ® D—-35 IBTSET intrinsic function®D—-42 ICHAR function ® 6-31 - ICHAR intrinsic function ® D—45 IDATE subroutine® D-47 IDENT directive ® 10—-10 IDIMintrinsic function® D—40 IDINT intrinsic function ® D-36 | field descriptor®8-12 to IDNINT intrinsic function® D-37 8-14 IEOR intrinsic function® D—41 I/0, iterative IFIX intrinsic function® D—-38 See iterative |I/0O IF statements ®5-15 to 5-24 I/O statement components control list parameters®7—1 to 7-3 format specifier® 7-4 I/O status specifier® 7-9 internal file specifier® 7—-4 key-field value specifier® 7—6 key-of-reference specifier ® 7-9 logical unit specifier® 7-3 general descriptions arithmetic IF®*5-16 block IF®5-17 to 5-24 logical IF®5-17 IF THEN statement biock IF constructs®5-17 to 5-24 Imaginary Part of Complex function ® D—39 Index-11 IMPLICIT NONE statement®4-23 Integer editing (1,0,Z)®*8-12 to 8-17 IMPLICIT statement Internal file specifier effect of /WARNINGS option®4-23 control list parameter in /O statements ® 7—4 general description®4-22 to 4-23 Internal 1/O statements using to type variables ® 2—-23 ENCODE and DECODE statements ® Implied-DO list A-1to See lterative | /O initializing with statements ®4-5 to 4-8 INCLUDE statement® 1-17 to 1-18 WRITE statements® 7-43 to 7-44 Internal WRITE statements®7-43 to 7-44 INT intrinsic function ® D—-36 Indefinite DO statement, pretested DO WHILE®5-9 to A-3 READ statements®7-31 to 7-32 Implied-DO variables Intrinsic functions, system-supplied 5-11 character comparison functions® Indexed DO statement®5—4 to 5-9 6-30 to Indexed files description of types ® 6—2 Indexed I/O statements READ statements® 7-28 to WRITE statements® 7-41 to 6-32 complete list of*D-32 to D-45 freeing locked records ® 9-38 external procedures of same name ®4-21 7-30 lexical comparison functions ®6-32 to 7-43 references, generic®6-26 to 6-27, access keys 6-28 to specifier in OPEN statement®9-15 6-30 references, specific ® 6-25, 6-28 to 6-30 deleting records from DELETE statement® 9-36 to 9-37 Indexed WRITE statements®7-41 to 7-43 INTRINSIC statement general description®4-23 to 4-24 INDEX function ® 6-31 IOR intrinsic function®D-41 INDEX intrinsic function ® D—43 IOSTAT BACKSPACE statement keyword ® 9-35 INITIALSIZE OPEN statement keyword ® 9—4, 9—-14 CLOSE statement keyword ® 9-23 DELETE statement keyword ® 9-36 INQUIRE statement ENDFILE statement keyword ® 9-35 general description® 9-24 to 9-33 INQUIRE statement specifier ® 9-28 Integer OPEN statement keyword ® 9—4, 9-14 constants in REAL*4 constants ® 2—8 REWIND statement keyword ® 9-34 octal notation® A-7 specifier in 1/O statements ® 7-9 UNLOCK statement keyword ® 9-38 data type IQINT intrinsic function ® D-36 definition ® 2-1 representation in memory® C-1, C-2 IQNINT intrinsic function ® D—-37 storage requirements ® 2—-2 to ISHFTC intrinsic function® D—-43 2-3 declaring data type ®4-8 to 4-10 default data type of undeclared names ® 4-22 Integer constants in COMPLEX+*8 constants ® 2—13 in REAL*8 constants ® 2—-10 ISHFT intrinsic function ® D—42 ISIGN intrinsic function® D—-41 ISO Standard comparison with ANSI Standard® 1-1 Iterative |/O in REAL*16 constants®2-12, 2-14 implied-DO list®* 7-13 to used to assign values ® 2—6 iterative count controls Integer data type See also Constants 7-14 indexed DO statement®5-4 to 5-9 Iterative processing controls See DO statements 12-Index 6-33 names used as arguments ® 4-23 Indexed organization files Library functions, system-supplied algorithms used in®D-32 Line KEEP file disposition® 9-23 KEY key-field value specifier in 1/0 statements ® 7—6 OPEN statement keyword ® 9—4, 9—-15 KEYED INQUIRE statement specifier® 9-29 OPEN statement keyword value ® 9-4 'KEYED' OPEN statement keyword value ® 9-8 Key-field value specifier control list parameter in I/O statements ® 7—6 KEYID specifier see key-of-reference specifier® 7-9 as a physical section of statements ® 1-2 blank® 1-8, 1-13 characters embedded in® 1-9 continuation indicator field® 1-14 entering with fixed format® 1-10to entering with tab format® 1-11to format of statement label field® 1-13 sequence number field® 1-15 statement field® 1-14 Linefeed control character ® 1-9 List-directed formatting I/O statement specifier ® 7—4 List-directed 1/O statements ACCEPT statement® 7—47 READ statements internal READ®7-31 Key-of-reference specifier control list parameter in I/0O statements ® 7—-9 sequential READ® 7—-15, 7-17 to KEYx specifier (KEY, KEYEQ, KEYGE, KEYGT, KEYNXTNE, KEYNXT) See key-field value specifier 7-19 WRITE statements internal WRITE® 7—-43, 7-44 Keys, access specified in OPEN statement® 9-15 1-11 1-13 sequential WRITE® 7-33, 7-35 to 7-37 List elements, simple I/0 list parameter in 1/O statements® 7—12 Listing See Source listing L Listing header Labels /LIST qualifier providing for a file® 10—13 See statement labels to enable TITLE and SUBTITLE compiler .LE. directives ® 10—13 See relational operators L edit descriptor ® 8—28 Lists, implied-DO in DATA statements ® 4-5 LEN function ® 6—30 LLE function®6-32 to 6-33 Length LLT function®6-32 to 6-33 effect of /EXTEND_SOURCE on sequence number field® 1-15 specifier in data type declarations ® 2-2 %LOC built-in function®6-—11 Locked records freeing locked records ® 9—-38 Length intrinsic function ® D-43 LOCKOFF directive® 10-5 to 10-6 LEN intrinsic function ® D—43 LOCKON directive® 10-5 to 10-6 Lexical comparison library functions LLT, LLE, LGT, LGE®6-32 to 6-33 <LF> control character® 1-9 used to resolve data dependences ® 10-5 Lock variable ® 10-5 LOG10 intrinsic function ®*D-33 LGE function®6-32 to 6-33 LGT function®6-32 to 6-33 index-13 Logical Lowercase characters ® 1-8 See also Arrays, Constants, Data types, Logical values, Variables affect on compiler® 1-9 in character and Hollerith constants® 1-9 constants LT. representation in memory ® C-2 storage requirement® 2—-2 to 2-3 See relational operators data type definition ® 2—-2 relationship to BYTE data type ® 4-9 LOGICAL Main program as a program unit® 1-2 declaring data type®4-8 to 4-10 Map declaration LOGICAL=*n general description®4-38 to 4-41 See Logical to establish variables ® 2—22 Logical assignment statement ® 3—4 use to establish arrays ® 2—-25 Logical constants®2-18 Mapped field declarations ® 2—33 Logical editing (L) ® 8—28 MAP statement ® 4—38, 4-39 Logical elements Mathematical functions, intrinsic® D-32 to See Logical expressions Logical expressions ® 2—-49 to 2-52 MAX1 intrinsic function ® D—40 compile-time ® 4—27 evaluation of subexpressions® 2-51 order of evaluation®2-51 to 2-5b2 Logical functions® 6—15 Maximum intrinsic function ® D—40 MAX intrinsic function ® D—-40 MAXREC OPEN statement keyword ® 9—-4, 9-16 Logical I/O units Memory diagrams CLOSE statement options ®9-23 of structured records ® 2—-34 to 2-36 connection method explicitly by means of OPEN ® 9-22 defining logical unit numbers DEFINE FILE statement® A-3 to A-4 inquiring about properties INQUIRE statement®9-24 to 9-33 OPEN statement options ® 9—2 Logical IF statement® 5—-17 Messages sending to terminal See PAUSE statement MINO intrinsic function ® D—40 MIN1 intrinsic function ® D—40 Minimum intrinsic function ® D—40 MIN intrinsic function ® D—40 Minus operator (—)® 2-42 to Logical operations data types that result from ® 2-50 Logical operators ® 2-50t 2-44, 2-51 MOD intrinsic function®D-41 Multiplication operator (*)®2-42 to 2-44, 2-51 MVBITS subroutine ® D-53 in expressions ® D-2 Logical scalar memory reference See Scalar memory reference Logical unit specifier Name control list parameter in I/O statements ® 7-3 Logical values representation in memory®C-2 to C-3 LOG intrinsic function ® D—33 Loops, DO DO statements®5-3 to 14-Index D-45 MAXO intrinsic function ® D—-40 5-12 See also symbolic names, entry names NAME INQUIRE statement specifier® 9-29 OPEN statement keyword ® 9-4, 9-17 Name, structure using ® 4—33 NAMED INQUIRE statement specifier ® 9—-30 Named common blocks establishing order of contents® 4—-4 initializing values in®4-2 to 4-3 Namelist-directed I/O statements See also NAMELIST statement ACCEPT statement® 7-47 sequential READ statement® 7—-15, 7-20 to 7-25 sequential WRITE statement® 7-33, 7-37 to 7-38 Namelist specifier control list parameter NOSPANBLOCKS OPEN statement keyword ® 9-4, 9-17 NOT. See logical operators NOT intrinsic function® D—41 NUMBER INQUIRE statement specifier® 9—30 Number, sequence® 1-15 Numerais ® 1-8 Numeric functions ® 6-15 Numeric scalar memory reference See Scalar memory reference Numeric storage unit® 2—2 Numeric type declarations in 1/0 statements ® 7-5 NAMELIST statement general description®4-8 to 4-10 NWORKERS intrinsic function ® D-44 general description® 4-24 to 4-25 using unsubscripted array names ® 2-29 Names, symbolic See Symbolic names Natural Logarithm intrinsic function ® D-33 .NE. See relational operators Nearest Integer intrinsic function ® D-37 .NEQV. See logical operators Nested block IF constructs ®5-23 to 5-24 Nested DO loops®5-7 to 5-8 Nested structured declarations See substructure declarations Nesting structure declarations ® 4-33, 4-38 <NEWLINE> control character® 1-9 NEXTREC INQUIRE statement specifier ® 9—-30 NINT intrinsic function® D-37 NML specifier in /O statements ® /-5 /NOF77 qualifier effect on Do-loops ®5-5 /NOLIST qualifier in the DICTIONARY statement® 1-16 in the INCLUDE statement® 1-17 Nonexecutable statements ® 1-2 Nonprintable characters ® 1-9 /NOOBJECT qualifier disabling IDENT directive® 10-10 @) field descriptor® 8-14 Object libraries searching for block data subprograms ® 4—-3 Object module labeling and identifying with compiler directive ® 10-10 Octal constants ® 2-5, 2—-15 to 2-18 assigned in DATA statement ® 4-7 data type assignments® 2—16 to 2-17 Octal notation (") for integer constants ® A—7 Octal values I/O transfers by O field descriptor® 8—-14 OPENED INQUIRE statement specifier ® 9-31 OPEN statement general description®9-2 to 9-23 I/0 statement interdependencies logical unit specifier ® 7—4 Operators See also arithmetic operators, relational operators expression operators summary of®*D-1 to D-2 logical ® 2-50t index-15 Operators (cont'd.) Periods precedence in arithmetic expressions ® delimiting logical values ® 2-50 2-43 to 2-44 precedence in relational expressions ® 2—49 used in logical expressions ® 2-51 2-44, 2-51 Positional editing (X,T,TL,TR)®8-34 to Optimization effect of VOLATILE statement® 4—-41 OPTIONS statement® 1-3, 1-18 to delimiting relational values ® 2-48 Plus operator (+)® 2-42 to 1-19 8-36 Positive Difference intrinsic function ® D—40 Precedence, operator effect of parentheses ®2—-44 to .OR. 2-45 in relational expressions ® 2—-49 See logical operators within arithmetic expressions®2-43 to Order required of statements® 1-3t ORGANIZATION INQUIRE statement specifier ® 9-31 OPEN statement keyword ® 9-4, 9-17 DO WHILE®5-9 to 5-11 PRINT file disposition® 9-23 PRINT statement® 7-48 to 7-49 PRIVATE directive® 10—-6 to P 2-44 Pretested indefinite DO statement 10-7 Private entities using SAVE statement for® 10-7 Parallel directives ® 10-2 to 10-9 See also NWORKERS function PRIVATE_ALL directive ® 10-7 Procedure See subprogram enabling ® 10-2 examples of® 10-8 to 10-9 Program See program unit ordering with statements ® 1-3t Parallel DO-loop® 10-4 to 10-9 Program execution temporarily suspending /PARALLEL qualifier® 10-2 (PAUSE)®5-24 to PARAMETER statement alternate version of ® A—6 5-25 terminating EXIT®D-48 defining constants in arithmetic STOPe®5-27 expressions ® 2—46 general description ® 4-26 to 4-28 PROGRAM statement general description®4-28 to 4-29 in structure declaration block ® 4-32 position after OPTIONS statement® 1-19 Parentheses effect in arithmetic expressions ® Program unit 2-44 to 2-45 assigning a hame to main program unit®4-28 to 4-29 effect in character expressions ® 2—47 block data subprogram ® 4—-2 in logical expression®2-51 Passed-length character arguments ® 2—-23 definition of® 1-2 PSECT directive® 10-11 to Passed-length format, *(*) 10-12 for dummy arguments or character Q functions ® 2-2 Pathnames (CDD)® 1-16 PAUSE statement®5-24 to 5-25 in parallel DO-loop® 10-4 PDP-11 FORTRAN-77 source programs on a VAX FORTRAN compiler® 1-2 P edit descriptor®8-25 to 16-Index 8-27 Q edit descriptor ® 8-37 in REAL*16 constants®2—-12 QEXT intrinsic function ® D-38 QFLOAT intrinsic function ®D-38 Question mark (?) namelist prompt ® 7-22 Quotation marks (“) REAL*4 data type definition ® 21 octal notation for integer constants ® A—7 representation in memory ® C—4 storage requirements ® 2—-2 to 2-3 default data type of undeclared names ® 4—-22 REAL+8 Radix—50 constants and character sets®B—-4 to B-5 Random number generator RAN function ® D-50 See also Arrays, Constants, Data types, Variables constants®2-10to 2-12 data type definition ® 2—-1 RAN function ® D-50 representation in memory (G_ and D_ READONLY floating)®*C-3, C—4, C-5to C-6 OPEN statement keyword ® 9—-4, 9-18 READ statements direct access READ®7-26 to 7-27 formatted ® 7—-26 unformatted ® 7-26, 7-27 indexed READ® 7-28 to 7-30 formatted ® 7-28, 7-29 unformatted ® 7-28, 7-30 internal READ®7-31 to 7-32 formatted® 7-32 list-directed ® 7-31, 7-32 relationship to DECODE statement® A—1, A-2 sequential READ®7-15 to 7-25 formatted® 7—-15, 7-16 list-directed ® 7—-15, 7-17 to 7-19 namelist-directed ® 7—-15, 7-20 to 7-25 unformatted ® 7—-15, 7-25 REAL See REAL*4 declaring data type®4-8 to 4-10 REAL+*16 See also Arrays, Constants, Data types, Variables constants®2-12 to 2-13 data type definition® 2-1 representation in memory® C-4, C-7 storage requirements ®2-2 to 2-3 REAL*16 float intrinsic function ® D—38 REAL+4 See also Arrays, Constants, Data types, Variables constants ®2-8 to 2-10 storage requirement®2-2 to 2-3 D_floating and G_floating implementations ® 2—-4 REAL+*8 float intrinsic function ® D—-38 REAL*8 product of REAL*4's function ® D—39 Real editing (F,E,D,G)®*8-17 to 8-25 complex data editing ® 8—25 relationship to DECODE statement® A—1 REAL intrinsic function® D-37, D—-39 Real Part of Complex function ® D—39 REC DELETE statement keyword ® 9—-36 specifier in 1/0O statements ® 7—6 RECL INQUIRE statement specifier® 9-32 OPEN statement keyword ®9-4, 9-18 Record and field references ® 2-36 to 2-37 examples ®2—-38 to 2-39 Record names statements that can use ®4-30 Records allowable operations on aggregate fields ® 2—-37 arrangement in memory ® 2-33 to 2-36 defining values of® 3—1 freeing locked records ® 9-38 general description®2-31 to 2-32 /0 records deleting records from a file (DELETE)®9-36 to 9-37 RECORDTYPE keyword (INQUIRE statement) ® 9—32 RECORDTYPE keyword (OPEN statement) ® 9-20 Index-17 Records Run-time formats ® 8—-41 to I/0 records (cont'd.) sizes (OPEN statement keywords) ® 9-18 8—42 Run-time library routines in parallel DO-loop ® 10-4 RECORDSIZE OPEN statement keyword ® 9—4, 9-20 Record size (RECL) default values ® 9-19 limits S ®9-19 edit descriptor® 8-12 Record specifier SAVE control list parameter file disposition®9-23 in 1/0O statements ® 7-6 SAVE statement RECORD statement general description®4-29 to 4-30 RECORDTYPE INQUIRE statement specifier® 9-32 OPEN statement keyword ® 9-4, 9-20 to 9-21 %REF built-in function® 6-10 examples ® 2-38 to 2-39 Scalar reference ® 2-39 to 2-41 Scale factor editing (P) ® 8-25 to 8-27 References, generic or specific SECNDS function subprogram ® D—48 See function references Relational expressions ® 2—-48 to 2-49 Relational operators ® 2—48 avoiding use as field names ® 2—-38 in expressions ® D—1 Segmented records RECORDTYPE keyword (OPEN statement) ® 9-4, 9-20 to 9-21 Separators external field separators ® 8—-40 to Relative organization files 8-41 format specification defining size and structure DEFINE FILE statement® A-3 to A-4 deleting records from DELETE statement®9-36 to 9-37 freeing locked records ® 9-38 Remainder intrinsic function® D—41 Repeat count separators ® 8—39 to 8-40 Sequence number field® 1-10, 1-15 SEQUENTIAL INQUIRE statement specifier ® 9-33 OPEN statement keyword value ® 9—-4 Sequential 1/0O statements READ statements® 7-15 to 7-25 in FORMAT statements ® 8—-8 WRITE statements ® 7-33 to Return argument, alternate ® 6-9 7-39 Sequential organization files RETURN statement 5-27 in parallel DO-loop ® 10-4 return args in CALL®5-25, 5-27 use with FUNCTION statement® 6—15 use with SUBROUTINE statement® 6—18, 6-20 freeing locked records ® 9-38 repositioning REWIND statement® 9-34 repositioning with BACKSPACE statement ® 9-35 writing end-of-file records ENDFILE statement® 9-35 to 9-36 REWIND statement See also BACKSPACE statement general description ® 9-34 18-Index Scalar field reference Scalar memory reference® 2-39 to 2-41 See function references REWRITE statements® 7—-45 to use of for private entities® 10-7 using unsubscripted array names® 2-29 format of® 2-36 to 2-37 References, function general description ® 5-25 to general description®4-30 to 4-31 7-47 'SEQUENTIAL'’ OPEN statement keyword value® 9-8 SHARED OPEN statement keyword ® 9—4, 9-21 Standards SHARED directive ® 10-7 See ANSI Standard, FORTRAN-66, SHARED_ALL directive ® 10-8 FORTRAN-77, ISO Standard Sign control editing® 8—11 Statement field® 1-10, 1-14 SIGN intrinsic function ® D—41 Statement functions®6—-12 to 6-14 Simple list elements Statement label I/0 list parameter rules governing use of® 1-13 in I/O statements®7—-12 Statement label field® 1-10, 1-13 SIND intrinsic function® D-33 Statement label references Sine (degree) intrinsic function ® D-33 FORMAT and GOTO statements ® 3—7 Sine intrinsic function ® D-33 symbolic® 3-7 to 3-8 SINH intrinsic function ® D-35 Statement labels SIN intrinsic function® D—-33 assigning symbols to®3-7 to SIZEOF intrinsic function ® D-44 division operator® 2—-42 to 2-44, 2-51 requirements of® 1-3t in FORMAT statements ® 8—4 Statements Source code See FORTRAN statements See also source program STATUS allowable characters ® 1-9 CLOSE statement keyword ® 9-23 comments in® 1-7 OPEN statement keyword ® 9-4, 9-21 debugging statements in® 1-14 description of fields® 1-9 to STOP statement 1-15 format using fixed-format® 1-10to format using tab-format® 1-11to 1-11 1-13 Source listing INITIALSIZE® 9-4, 9-14 Source program Storage requirements See also source code of data types ® 2—3 definition of a program unit® 1-2 Storage units Dincolumn 1®1-14 character® 2-2 1-5 symbolic names in® 1-5 to numeric ® 2-2 1-7 Stream records SP RECORDTYPE keyword (OPEN edit descriptor®8-11 statement) ®* 9-4, 9-20to Space character® 1-9 effect of FORMAT descriptors®8-7, in statement label fields® 1-13 Special characters ® 1-8 Specification statements®4—1 to 4-42 SQRT intrinsic function ® D-33 Square root intrinsic function® D-33 /STANDARD qualifier® 4—31 in parallel DO-loop ® 10-4 Storage allocation, file EXTENDSIZE ®9-4, 9-12 of included files® 1-17 edit descriptor® 8-11 general description®5-27 OPEN statement keywords of CDD records® 1-16 SS Statement order following OPTIONS statement® 1-19 record terminators statement order® 1-3 to 3-8 rules governing use® 1-3 Slash (/) 8-10 9-21 Structure declaration block general description®2-32 to 2-33 Structure declaration blocks components of ®4-32 data type declaration rules ® 4—-34 field declarations within ® 4-34 to 4-38 general description®4-31 to 4-41 use of %FILL®2-33, 4-34 Structure declarations ® 4-33 STRUCTURE statement general description®4-33 to 4-34 Index-19 Subprograms Subexpressions system-supplied FORTRAN intrinsic functions in logical expressions®2-51 (cont’d.) SUBMIT complete list of *D-32 to file disposition® 9-23 aggregate field references used as®2—-37 duplicating external procedure names ®4-21 associating arrays with® 2-25 lexical comparison associating variables with® 2-22 bit function arguments ® D-50 to functions ®6-32 to D-52 6-27, 6-28 to 6-30 4-22 general description®6-2 to 6-33 references, generic®6-26 to external procedure names used as®4-21to D-45 description of types ® 6-2 Subprogram arguments references, specific ® 6-25, 6-11 adjustable arrays ®6-3 to 6-28 to 6-30 6-5 system-supplied intrinsic functions alternate return arguments ® 6-9 names used as arguments ®4-23 assumed-size arrays ® 6—6 system-supplied subroutines and functions character arrays ® 6—-7 list and descriptions of* D-45 to defaults for arguments use of RETURN statement® 5-25 to passing®6-9to 6-11 Hollerith and character constants ® 6-8 D-53 5-27 user-written functions overview ® 6—2 function subprograms ®6-15 to passed-length character arguments ® 6-7 subroutine subprograms ®6-18 to general description®6-11 to 6-12 use of built-in functions argument list functions (% VAL, %REF, statement functions ®6-12 to 6-14 Subroutine arguments %DESCR)®6-9 to 6-11 %LOC function®6—11 See subprogram arguments Subprograms SUBROUTINE statement®6—18 to 6-21 bit functions see also subprograms general discussion about® D-50 to D-52 CHARACTER FUNCTION statement® 6—15 position after OPTIONS statement® 1-19 using unsubscripted array names ® 2—-29 Subscripts, array ® 2—-27 definition of® 1-2 Substrings effect of END statement® 5-12 6-24 function references®6-16 to 6-18 functions, built-in making equivalent® 4—-17 to 4-20 Substrings, character addressing in variables, arrays, and array argument list functions (% VAL, %REF, %DESCR)®6-9 to 6-11 %LOC function®6-11 elements® 2-30 to 2-31 definition ® 2—4 Substructure FUNCTION statement®6—15 to 6-18 invoking with CALL®5--2 example of ® 2—-35 Substructure declarations passed-length character arguments general description® 2-32, 4-32, 4-34, 4-38 SUBTITLE directive® 10-13 used in®2-23 SUBROUTINE statement®6—-18 to 6-21 Subtraction operator (—)® 2-42 to 2-44 system-supplied FORTRAN intrinsic functions Symbolic names algorithms used in® D—-32 character comparison functions® 6-30 to 20-Index 6-21 user-written subprograms intrinsic function names used as ® 4-23 ENTRY statement®6-21to 6-18 assigning to constants with PARAMETER statement®4—-26 to 6-32 4-28 assigning to main program unit® 4-28 to 4-29 Symbolic names (cont'd.) default data types ® 4—-22 external procedure names as subprogram arguments ®4-21 to 4-22 intrinsic function names used as subprogram arguments ® 4-23 of arrays ® 2—-25 of constants ® 4—-26 TITLE directive® 10-13 TL edit descriptor ® 8—34, 8—-36 Transfer, control See Control transfer Transfer-of-control specifier control list parameter in 1/O statements® 7—-10 rules, conventions, and use® 1-5 to 1-7 use with variables ® 2—-22 Symbolic statement labels establishing® 3—7 to 3-8 in formatted 1/O statements ® 3—-7 to 3-8 in GOTO statements®3-7 to 3-8 Symbols Transfer of Sign intrinsic function® D41 TR edit descriptor® 8—-34, 8—-36 Truncation intrinsic function ® D-36 TYPE OPEN statement keyword ® 9-4, 9-22 Type declaration statement See Data type declaration statement to establish variables ® 2—-22, 2-23 in parallel processing specifying private default shareability® 10-3, 10-7 TYPE statement® 7-48 to 7-49 specifying private shareability® 10-3, 10-6 Unary operators modifying ® shareability in parallel DO-loop 10-2 to 10-7 System services calling from parallel DO-loop® 10-4 System time function subprogram for calculating SECNDS ® D-48 subroutine for calculating TIME®D-49 to D-50 definition of® 2—43 Unary plus and minus operators (+and —)®2-42 to 2-44, 2-51 Unconditional GO TO statement® 5—-13 Undeclared symbolic names default data types ® 4—-22 UNFORMATTED INQUIRE statement specifier ® 9—33 Unformatted 1/O statements READ statements direct access ® 7-26, 7-27 T indexed ® 7-28, 7-30 Tab format® 1-11to 1-13 Tags of compiler directives ® 10—1 TAND intrinsic function ® D-34 sequential® 7—-15, 7-25 REWRITE statements® 7—-45, 7-46 use of aggregate field references ® 2—-37 WRITE statements direct access ® 7-39, 7-40 indexed® 7-41, 7-43 Tangent (degree) intrinsic function ® D—-34 Tangent intrinsic function ® D—-34 TANH intrinsic function ® D-35 TAN intrinsic function®D-34 T edit descriptor® 8—34, 8-35 Text file libraries accessing® 1-17to 1-18 Time, system See System time ® D-48 TIME subroutine® D—49 to D-50 sequential ® 7-33, 7-39 Union declarations contrasted with EQUIVALENCE ® 4-40 definition ® 4—32 general description ® 4—-38 to 4-41 UNION statement ® 4—39 UNIT BACKSPACE statement keyword ® 9-35 CLOSE statement keyword ® 9-23 Index-21 UNIT (cont’'d.) DELETE statement keyword ® 9-36 ENDFILE statement keyword ® 9—-35 INQUIRE statement keyword ® 9-25 VIRTUAL statement DIMENSION statement compared to® 4—13 VOLATILE statement general description® 4—-41 OPEN statement keyword ® 9—4, 9-22 REWIND statement keyword ® 9-34 specifier in 1/0 statements ® 7-3 UNLOCK statement keyword ® 9-38 UNLOCK statement ® 9-38 /WARNINGS qualifier® 4-23 WRITE statements® 7-33 to 7-44 Unnamed fields direct access WRITE® 7-39 to in a structure ® 2—-33 7-40 formatted ® 7-39, 7-40 Unsubscripted array names unformatted ® 7-39, 7-40 usage restrictions ® 2—-29 indexed WRITE®7-41 to use of ® 2-29 7-43 formatted® 7-41, 7-42 Uppercase characters® 1-8 unformatted ® 7-41, 7-43 effect on compiler® 1-9 internal WRITE® 7-43 to 7-44 in character and Hollerith constants ® 1-9 formatted ® 7-43, 7-44 User-defined functions list-directed ® 7-43, 7—-44 references to in dimension bounds expressions relationship to ENCODE statement® A-1, ®2-26 sequential WRITE® 7-33 to USEROPEN formatted® 7-33, 7-34 to OPEN statement keyword® 9—-4, 9-23 7-35 list-directed ® 7-33, 7-35 to 7-37 namelist-directed ® 7-33, 7-37 to ') unformatted ® 7-33, 7-39 %V AL built-in function®6-10 Variable-length records RECORDTYPE keyword (OPEN statement) ® 9-4, 9-20to 9-21 Variables X X edit descriptor ® 8-34, 8-34 to 8-35 .XOR. See logical operators as scalar references ® 2—39 association of two or more ® 2-22 character substrings® 2-30 to 2-31 Z data types of ® 21 data typing by implication® 2—-24 Zero-Extended Functions ® D-37 data typing by specification® 2—-23 ZEXT intrinsic function® D-37 default shareability in parallel Z field descriptor® 8-16 DO-loop® 10-2 to 10-7 defining in memory ® 2-22 defining values of ® 3—1 definition® 2—4, 2-22 establishing with subprogram references ® 2-22 initializing with DATA statements ® 4-5 to 4-8 in structure declarations ® 2—-32 Variant record capability ® 2—33 VAX FORTRAN extensions to ANSI Standard® 1-1 22-Index A-2 7-39 7-38 Reader's Comments VAX FORTRAN Language Reference Manual | AA-DO34E-TE Please use this postage-paid form to comment on this manual. If you require a written reply to a software problem and are eligible to receive one under Software Performance Report (SPR) service, submit your comments on an SPR form. Organization (structure of subject matter) Figures (useful) Examples (useful) Index (ability to find topic) Page layout (easy to find information) Fair Poor OOoOoO0000d Clarity (easy to understand) Good OoOoO0O0oOoad Accuracy (software works as manual says) Completeness (enough information) Excellent Oooooood I rate this manual’s: OoO0O0OooOoaono Thank you for your assistance. I would like to see more/less What I like best about this manual is What [ like least about this manual is I found the following errors in this manual: Page Description Additional comments or suggestions to improve this manual: [ am using Version Name/Title of the software this manual describes. Dept. Date Company Mailing Address Phone — Do Not Tear - Fold Here and Tape — —— e e e e No Postage Necessary if Mailed United States BUSINESS REPLY MAIL FIRST CLASS PERMIT NO. 33 MAYNARD MASS. POSTAGE WILL BE PAID BY ADDRESSEE DIGITAL EQUIPMENT CORPORATION Corporate User Publications—Spit Brook ZKO1-3/J35 110 SPIT BROOK ROAD NASHUA, NH 03062-9987 Do Not Tear - Fold Here _——————— ~~”——_~— ————-*“— _—_-———_ ——“——_w— _——~ Cut Alang Natted T.ina —— Reader’'s Comments VAX FORTRAN Language Reference Manual AA-DO34E-TE Please use this postage-paid form to comment on this manual. If you require a written reply to a software problem and are eligible to receive one under Software Performance Report (SPR) service, submit your comments on an SPR form. Clarity (easy to understand) Organization (structure of subject matter) Figures (useful) Examples (useful) Index (ability to find topic) Page layout (easy to find information) Fair Poor Ooo0ooOooOoaad Completeness (enough information) Good OOo0O0000a0oad Accuracy (software works as manual says) Excellent Oo0oOooOooon I rate this manual’s: OooaoooOon Thank you for your assistance. I would like to see more/less What I like best about this manual is What I like least about this manual is I found the following errors in this manual: Page Description Additional comments or suggestions to improve this manual: [ am using Version Name/Title of the software this manual describes. Dept. Date Company Mailing Address Phone Do Not Tear - Fold Here and Tape mngnflan ——— = — e e e e e o i l ———————— Necessary No Postage TM if Mailed in the United States BUSINESS REPLY MAIL FIRST CLASS PERMIT NO. 33 MAYNARD MASS. POSTAGE WILL BE PAID BY ADDRESSEE DIGITAL EQUIPMENT CORPORATION Corporate User Publications—Spit Brook ZK01-3/J35 110 SPIT BROOK ROAD NASHUA, NH 03062-9987 Do Not Tear - Fold Here ———— e ———— e ———— e Cut Along Dnt-;p: Line —— Reader's Comments VAX FORTRAN Language Reference Manual | AA-DO34E-TE Please use this postage-paid form to comment on this manual. If you require a written reply to a software problem and are eligible to receive one under Software Performance Report (SPR) service, submit your comments on an SPR form. Thank you for your assistance. I rate this manual’s: Excellent Good Fair Poor Accuracy (software works as manual says) O O O o Completeness (enough information) O O O 0 Clarity (easy to understand) O O O O Organization (structure of subject matter) O O] O O Figures (useful) O [ [ [ Examples (useful) O B O O Index (ability to find topic) O L Ll [ Page layout (easy to find information) O L] [ [ I would like to see more/less What I like best about this manual is What I like least about this manual is I found the following errors in this manual: Page Description Additional comments or suggestions to improve this manual: [ am using Version Name/Title of the software this manual describes. Dept. Company Date Mailing Address Phone — Do Not Tear - Fold Hereand Tape -~ ~-——— e e e dlilgliltiallN I I l II No Postage Necessary if Mailed in the United States BUSINESS REPLY MAIL FIRST CLASS PERMIT NO. 33 MAYNARD MASS. POSTAGE WILL BE PAID BY ADDRESSEE DIGITAL EQUIPMENT CORPORATION Corporate User Publications—Spit Brook ZK01-3/J35 110 SPIT BROOK ROAD NASHUA, NH 03062-9987 Do Not Tear - Fold Here Cut Along Dotted Line -— Reader’'s Comments VAX FORTRAN Language Reference Manual AA-DO34E-TE Please use this postage-paid form to comment on this manual. If you require a written reply to a software problem and are eligible to receive one under Software Performance Report (SPR) service, submit your comments on an SPR form. Clarity (easy to understand) Organization (structure of subject matter) Figures (useful) Examples (useful) Index (ability to find topic) Page layout (easy to find information) Fair Poor CDOooooogad Completeness (enough information) Good OO0o00o0ooon Accuracy (software works as manual says) Excellent Ooo0oodod I rate this manual’s: OO0oOo0godgod Thank you for your assistance. I would like to see more/less What I like best about this manual is What I like least about this manual is I found the following errors in this manual: Page Description Additional comments or suggestions to improve this manual: I am using Version Name /Title of the software this manual describes. Dept. Company Date Mailing Address Phone —— Do Not Tear - Fold Here and Tape || | | || No Postage dlilglilt/all Necessary if Mailed in the United States I I . BUSINESS REPLY MAIL FIRST CLASS PERMIT NO. 33 MAYNARD MASS. POSTAGE WILL BE PAID BY ADDRESSEE I ] ] ] I ] DIGITAL EQUIPMENT CORPORATION Corporate User Publications—Spit Brook ZK01-3/J35 110 SPIT BROOK ROAD NASHUA, NH 03062-9987 Ao Meada A Y 2 Do Not Tear - Fold Here £t —— ]
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies