Digital PDFs
Documents
Guest
Register
Log In
AA-DO35A-TE
August 1978
196 pages
Original
9.1MB
view
download
OCR Version
8.3MB
view
download
Document:
VAX-11 Fortran IV-Plus User's Guide
Order Number:
AA-DO35A-TE
Revision:
0
Pages:
196
Original Filename:
OCR Text
August 1978 This manual describes how to compile, link, debug, and execute programs written in the VAX-11 FORTRAN 1V-PLUS language, using the facilities of the VAX/VMS operating system. It also contains other information of interest to FORTRAN programmers, such as: error processing, programming efficiency, compatibility with PDP-11 FORTRAN, and FORTRAN input/output. VAX-11 FORTRAN IV-PLUS User’s Guide Order No. AA-DO35A-TE SUPERSESSION/UPDATE INFORMATION: This is a new document for this release. OPERATING SYSTEM AND VERSION: VAX/VMS V01 SOFTWARE VERSION: VAX-11 FORTRAN IV-PLUS V01 To order additional copies of this document, contact the Software Distribution Center, Digital Equipment Corporation, Maynard, Massachusetts 01754 digital equipment corporation - maynard, massachusetts First Printing, The and information in this document is August 1978 subject to change without notice 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 and may only be used or copied license. document is furnished under a license accordance with the terms of such in No responsibility is assumed for the use or reliability of software on equipment that is not supplied by DIGITAL or its affiliated companies. Copyright (C) 1978 by Digital Equipment Corporation The postage~prepaid READER'S document requests the user's paring future documentation. COMMENTS The of following - are trademarks critical form on the last page of this evaluation to assist us in pre- Digital Equipment Corporation: DIGITAL DECsystem-~10 DEC DECtape OMNIBUS PDP DIBOL 0s/8 DECUS EDUSYSTEM UNIBUS FLIP COMPUTER LABS- - MASSBUS PHA CHIP ~FOCAL ~~ RSTS —~— — —RSX " — COMTEX INDAC TYPESET-8 DDT LAB-8 TYPESET-11 DECCOMM DECSYSTEM-20 ASSIST-11 TMS-11 RTS-8 VAX ITPS-10 VMS SBI DECnet IAS — iii HHERWOYWOWWOWWOWWOoOO-IOOTUL &N - e o N HOOOO HFHHERHRHEHERRREHERRHERRRRRE Lt [ I aouUTU > WH DEBUG A PROGRAM SHOW LANGUAGE Command SHOW, CANCEL MODULE Commands SHOW, CANCEL SCOPE Commands | N SET, SET, SET, | wN - PREPARING TO I w N N . RN OVERVIEW OF THE VAX-11l SYMBOLIC DEBUGGER Sample Debugging Terminal Session Debugger Command Syntax Debugger Symbol Table NN DEBUGGING FORTRAN PROGRAMS NNNDNDDNDDNNN 1-17 1-18 1-19 1-19 "1-21 1-23 XS] > wWw N . 1-15 1-17 NDNDDNDNDN Source Listing Section Machine Code Listing Section Storage Map Section Other Listing Information 1-13 1-14 1-14 1-14 1-14 1-14 1-15 I = o L] BPHOYOJOAUTES WD L4 e e o L] L] . NN [ & L] s * [} [} ¢ o L) NN * [ @ CORRECTING ERRORS Error-Related Command Qualifiers SHOW CALLS Command SAMPLE TERMINAL SESSION COMPILER LISTING FORMAT e o N FINDING AND NANNNOUMTU . Linker Command Qualifiers Image File Qualifiers Map File Qualifiers Debugging and Traceback Qualifiers Linker Input File Qualifiers /LIBRARY Qualifier /INCLUDE Qualifier EXECUTION NN CHAPTER Specifying Output Files FORTRAN Qualifiers CHECK Qualifier CONTINUATIONS Qualifier DEBUG Qualifier D_LINES Qualifier I4 Qualifier LIST Qualifier MACHINE_CODE Qualifier OBJECT Qualifier OPTIMIZE Qualifier WARNINGS Qualifier WORK_FILES Qualifier LINKING [} * @ e 9 ® e ° Q @ s COMPILATION [] . [ N CREATING AND EXECUTING A PROGRAM File Specifications Qualifiers MR WWWWWWWWNNNDNDNNDDNDNNDDNDNDNDND [ USING VAX-11l FORTRAN IV-PLUS o CHAPTER HFRRFHEFRHERHERERERERERRERRFRRERRRFRERERRRRRRRERRRRRE PREFACE |= ] [ Q ® g o CONTENTS CONTENTS Commands Commands SET, SHOW, SHOW CALLS CANCEL WATCH Command Commands GO, STEP Commands CTRL/Y Command EXIT Command EXAMINING AND MODIFYING LOCATIONS EXAMINE Command DEPOSIT Command EVALUATE Command SPECIFYING ADDRESSES Lines, Labels, and Absolute Addresses Specifying Scope 2.5.3 2.5.4 2.6 CALLING SUBROUTINES 2.7 DEBUGGER COMMAND QUALIFIERS 2.8 NUMERIC DATA TYPES 2.9 2.9.1 EFFECTS OF 3 Previous, Current, Use of FROM THE ON DEBUGGING Codes FORTRAN Flow of /NOOPTIMIZE and /OPTIMIZE INPUT/OUTPUT FILE LOGICAL NAMES SPECIFICATION FORTRAN Logical Names Implied FORTRAN Logical Unit Numbers OPEN Statement NAME Keyword Assigning Files to Logical Units Assigning Logical Names with MOUNT ‘FILE CHARACTERISTICS File Organization Sequential Organization Relative Organization Access to Records Sequential Access Direct Access 3.3.2.1 3.3.2.2 3.4 RECORD STRUCTURE 3.4.1 Fixed Length Records 3.4.2 Variable Length Records 3.4.3 Segmented Records 3.5 ~ OPEN STATEMENT KEYWORDS 3.5.1 BLOCKSIZE Keyword 3.5.2 BUFFERCOUNT Keyword 3.5.3 INITIALSIZE and EXTENDSIZE 3.5.4 ORGANIZATION Keyword 3.5.5 READONLY Keyword 3.5.6 RECORDSIZE Keyword 3.5.7 3.5.8 3.5.9 3.6 DEBUGGER Register Binding Control Effects 3.2 3.2.1 3.2.4 3.2.5 3.3 3.3.1 3.3.1.1 3.3.1.2 3.3.2 Symbolically OPTIMIZATION Condition 3.1 3.2.2 3.2.3 and Next Locations Defining Addresses RECORDTYPE Keyword SHARED Keyword USEROPEN Keyword AUXILIARY I/O OPERATIONS iv Commands | 2.9.2 2.9.3 2.9.4 CHAPTER CANCEL BREAK CANCEL TRACE i 2.5.2 SHOW, SHOW, |O WOWYWORVOVOJIJ~INIJOAOAUTDdWWN 2.4.2 2.4.3 2.5 2.5.1 SET, SET, Keywords o 2.3.7 2.4 2.4.1 CONTROLLING PROGRAM EXECUTION WWWWLwWWwWwwWwwwwwwwwwww 2.3 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 (Cont.) CONTENTS (Cont.) > N CHARACTER ARGUMENTS DATA EXAMPLES FUNCTIONS A CHARACTER LIBRARY [ T CHAR Function ICHAR Function INDEX Function LEN Function EXAMPLES Argument List Built-In Function Examples Character Functions ERROR PROCESSING AND RUN-TIME LIBRARY CONDITION DEFAULT ERROR HANDLERS PROCESSING Using ERR= and END= Transfers Run-Time Library Error Processing Control Using the ERRSNS Subroutine OVERVIEW OF THE VAX-11 FACILITY Definitions Condition Signals CONDITION BB R WWWWNDNND HWOYOOOJIJaUn CODE Argument Passing Examples el " oottt | m Reference Calling System Services as Subroutines Passing Arguments to System Services Input and Output Address Arguments Defaults for Optional Arguments Passing Character Arguments (+) W - %DESCR oottt orn | I o o = WN - e L * N wWwWwwwwn -+ $DESCR Examples of %VAL, $REF, Function Return Values wN - + $REF $LOC Built-In Function CALLING VAX/VMS SYSTEM SERVICES Calling System Services by Function . o & o o o o o o o * * * * Ld Ll WWwwwn $ VAL MACHINE * CALLING STANDARD Argument Lists Argument Passing Mechanisms Argument List Built-In Functions (o)) CALLS VAX-11l PROCEDURE 1 PROCEDURE CONVENTIONS wWwN N CALL (52 CHARACTER I/O ANy O CHARACTER HANDLING ~NoO oy PASSED LENGTH DATA CHARACTER VARIABLES |o CHARACTER INITIALIZING | — S CONSTANTS DECLARING R CHARACTER STRINGS CHARACTER 3-15 1 WOOOOIJTNHBEWWNH NETWORKS 3-15 A OO S e e * O e o S o A s o S ¢ e o N o o I o o o [ o o ¢ o o o o o o e * oottt COMPUTERS: DATA Oy OV OY OY OV oot L] . L] * L] L] . * L] bRk WWWWW REMOTE 3-14 3-14 CHARACTER SUBSTRINGS FORTRAN (<2 W)} CHAPTER CHARACTER BUILDING 19, e \O 000000000 ~JOYUI>»WN K USING n CHAPTER MAILBOXES Sending and Receiving Data Using Mailboxes COMMUNICATING WITH WwhitdhdBddddNDNDDDDNDND - CHAPTER LOCAL INTERPROCESS COMMUNICATION: Creating a Mailbox 1~ Wwww Page CONTENTS O W © -0 O | = B | R B AN W R B N B N B P B LOOPS N DO T ARGUMENTS REPRESENTATION I DATA T B 1 R e T B A B B i [ [0} O N D I T I/0 FORTRAN DATA SYSTEM CHARACTERISTICS REPRESENTATION INTEGER*2 FORMAT 2 INTEGER*4 FORMAT 3 FLOATING-POINT FORMATS Real Format (4-Byte Floating Point) Double Precision Format (8-Byte Floating Point) vi |S At Compiler Optimization Example FORTRAN 1 3.1 3.2 R B . T Program Blocks Eliminating Common Subexpressions ¥ W Characteristics of Optimized Programs Compile-Time Operations on Constants Source R Statement I INCLUDE Allocating Variables in Common Blocks Conditional Branching COMPILER OPTIMIZATIONS APPENDIX B PROGRAMS HO®JOUdWWWNH SOURCE Statement 00 00 00 OO0 00 00 00 CO OO0 00 0O OO CONSIDERATIONS N e . W N e PARAMETER 0.0 YRy wWN [ . . Representation of Sign Bit Tests ! [} [} * * L 0 Single Precision Floating Point Data Double Precision Floating Point Data Floating Point Data Characteristics Reserved Operand Faults > WWwwwn H B POINT CREATING EFFICIENT L) . * . Ld FOR I STATEMENT FLOATING L4 [) ] Statement Cautions Concerning Program Interchange Iteration Count Computation ENTRY WNHhRNMNNDNDNMNDNNDHRFRERFPE L) MODEL B 1 2 COUNT A the EXTERNAL e B of O Use PROGRAMMING 00 0O 00 00 CO CO 00 0O CO 0O OO 0 O CHAPTER N INTEGER*4 Integer Constant Typing Integer-Valued Processor-Defined Functions Byte (LOGICAL*1l) Data Type FUNCTIONS SUPPLIED WITH VAX~1ll FORTRAN Generic Functions ITERATION L) NNNNNNNNNNNN NN L] L L] . L] Ao UTIR R BBWWWNDNN 1 2 U DATA TYPES N AND FIXED-POINT Integer Data Types Supported Relationship of INTEGER*2 and Values .2 .3 a3 USAGE ALLOCATION R STORAGE DY N PROGRAM SECTION 2 = SYSTEM ENVIRONMENT 1 2 2.1.1 ~) HANDLER EXAMPLES BMBHEREREEREOVYOYOoOIOOAANMTUIULE B CONDITION (o)W e W e Wa Mo WerTe We ) HANDLERS W CONDITION w w . o W= & & e 8 & * * L] o dWwwwwwwN e Responses Establishing and Removing Handlers FORTRAN Condition Handlers Handler Function Return Values Condition Values and Symbols Floating Overflow, Zero Divide Exceptions FORTRAN NNa CHAPTER Handler USER-WRITTEN ~ [e) e Mo We Mo We ) We) eyt g o) Q ® (Cont.) CONTENTS (Cont.) Page APPENDIX A.3.3 A.4 A.5 A.6 A.7 Complex Format LOGICAL*1l FORMAT CHARACTER FORMAT HOLLERITH FORMAT LOGICAL FORMAT A-3 A-4 A-4 A-4 A-5 B DIAGNOSTIC B-1 B.1l DIAGNOSTIC MESSAGES OVERVIEW B.2 DIAGNOSTIC FROM THE B.2.1 Compiler-Fatal Compiler Limits B.3.2 B-1 COMPILER Program Diagnostic Messages B.2.3 ) APPENDIX MESSAGES B.2.2 B.3 B.3.1 APPENDIX Source MESSAGES Diagnostic Messages B-~1 B-~1 B-17 B-19 RUN-TIME DIAGNOSTIC MESSAGES Run-Time Library Diagnostic Message B-20 Presentation Run-Time Library B-20 B-20 Diagnostic Messages C SYSTEM C.1l SYSTEM SUBROUTINE SUMMARY C-1 C.2 DATE C-1 C.3 C.4 C.5 C.6 C.7 IDATE ERRSNS EXIT SECNDS TIME C-2 C=-2 C-3 C-3 C-4 D COMPATIBILITY D~-1 COMPATIBILITY: OVERVIEW DIFFERENCES Logical Tests Floating Point Results D=1 D-1 D~1 D-2 D.1 D.2 D.2.1 D.2.2 D.2.3 D.2.4 D.2.5 D.2.6 D.3 D.3.1 D.3.2 D.3.2.1 D.3.2.2 D.3.2.3 D.3.3 D.4 D.4.1 D.4.2 D.4.3 D.4.4 D.4.5 D.4.6 D.4.7 D.4.8 D.4.9 D.4.10 D.4.11 SUBROUTINES LANGUAGE Character and Hollerith Constants Logical Unit Numbers Assigned GO TO Label List DISPOSE='PRINT' Specification RUN-TIME SUPPORT DIFFERENCES Run-Time Library Error Numbers Error Handling and Reporting Continuing After Errors I/0 Errors with ERR= Specified OPEN/CLOSE Statement Errors OPEN Statement Keywords UTILITY SUBROUTINES ASSIGN Subroutine CLOSE Subroutine ERRSET Subroutine ERRTST Subroutine FDBSET Subroutine IRAD50 Subroutine RAD50 Function RAN Function RANDU Subroutine R50ASC Subroutine USEREX Subroutine vii Cc-1 D-2 D~-3 D=3 D-3 D-3 D-4 D=5 D-5 D-5 D-5 D-5 D=5 D-6 D-7 D-7 D-8 D-9 D~10 D-11 D-11 D-12 D-12 D-13 CONTENTS (Cont.) Page INDEX Index~-1 RELAX Source Program RELAX Machine Code (Optimized) Sample Diagnostic Messages (Terminal Format) Sample Diagnostic Messages (Listing Format) WNOWONANKFNNHEEND NO VWO Program Development Process Traceback List Source Listing Section Machine Code Listing Section Storage Map Listing Sample FORTRAN Program: CIRCLE Sample Debugging Terminal Dialog Character Data Program Example Output Generated by Example Program wrna>m4>¢nrh:wbdkflHb~ 11 oo NHEEHEPFENMFEFMDRPOBWNODH FIGURE WKflGDmdhhdrh)dedepa [ FIGURES /DEBUG and /TRACEBACK Qualifiers Debugger Commands and Keywords Debugger Command Qualifiers Predefined System Logical Names Implicit FORTRAN Logical Units RECORDSIZE Limits Function Return Values Variable Data Type Requirements Summary of FORTRAN Run-Time Errors Condition Handler Function Return Values PSECT Names and Attributes PSECT Attributes Source Program Diagnostic Messages Compiler-Fatal Diagnostic Messages Compiler Limits Run-Time Diagnostic Messages Default Logical Unit Numbers viii WOHPFRMWNHAARHAWHMAHMIW o N ~ W 0= File Specification Defaults FORTRAN Command Qualifiers Linker Qualifiers Utflu1wtn~chna\TLnu)ucuuawrapawra ! I i1 (| U(fiUJWtfl\JQChO\T(nUJwL»hJNIkohJH | I TABLE HE2WNDNFHFNFEFNMFENMNRFRPWONENDEBRWND - TABLES PREFACE MANUAL OBJECTIVES The VAX-1l FORTRAN IV-PLUS User's Guide 1is intended for wuse 1in developing new FORTRAN programs, and compiling and executing existing FORTRAN programs on VAX/VMS elements supported on VAX-11 IV-PLUS Language systems. FORTRAN IV-PLUS language are described in the VAX-11 FORTRAN Reference Manual. INTENDED AUDIENCE This manual is designed for programmers who have a working knowledge of FORTRAN. Detailed knowledge of VAX/VMS 1is helpful but not essential; familiarity with the VAX/VMS Primer is recommended. Some sections of this book, however, (condition handling, for instance) require more extensive understanding of the operating system. 1In such sections, you are directed to the appropriate manual(s) for the required additional information. STRUCTURE OF This manual e THIS is organized Chapter and DOCUMENT 1 as contains execute a follows: the FORTRAN information needed to compile, 1link, program. ® Chapter 2 covers the debugging process; Symbolic Debugger is described. e Chapter 3 provides information about FORTRAN input/output, including details on the use of 1logical names, file conventions, record structure, and use of certain OPEN statement use of the VAX-11 keywords. ® Chapter 4 discusses character data, and how character data can be manipulated. includes examples of ® Chapter 5 procedures, ® Chapter 6 describes error processing; in particular, the condition handling facility and how to use it. This chapter is intended for users with in-depth knowledge of VAX/VMS. ® Chapter 7 describes the relationship between VAX-11 FORTRAN IV-PLUS and the VAX-1ll system, with particular emphasis on program section usage, data types, functions, DO 1loops, and floating point data representation. discusses the conventions followed 1in calling especially the argument-passing conventions. ix Chapter 8 typical covers FORTRAN Appendixes A programming considerations relevant to applications. through D summarize internal data representation, diagnostic messages, system-supplied functions, compatibility between VAX-11l FORTRAN and PDP-11 FORTRAN. ASSOCIATED DOCUMENTS The following programming: documents are relevant e VAX/VMS Primer e VAX-11 FORTRAN e VAX/VMS e VAX-11 Common Run-Time Procedure e VAX-11l Linker Reference Manual e VAX-11l Symbolic Debugger ® VAX/VMS e VAX-11/780 Architecture Handbook IV-PLUS Command Language Language USED IN VAX-1l1l THIS 1IV-PLUS Reference Manual Library Reference software are observed and letters, you the word should type Lowercase words that you are to Brackets to FORTRAN User's Guide Uppercase words is VAX-1l1 Reference Manual Manual ({ be Ellipses repeated ([ }) ]) documents, see the VAX-11 DOCUMENT The following conventions VAX-11 documents: Braces to System Services Reference Manual For a complete list of Information Directory. CONVENTIONS and or and letters, substitute a indicate in this manual, used in letter used word optional examples, exactly in or as as in the other indicate that shown format examples, indicate value of your choice elements are used to enclose lists from which one chosen (...) indicate that one or more times the preceding item(s) element can be CHAPTER 1 USING VAX-11 FORTRAN IV-PLUS VAX-11l FORTRAN IV-PLUS is based on American National Standard FORTRAN X3.9-1966. It 1is also a compatible superset of PDP-11 FORTRAN IV-PLUS. VAX-11 FORTRAN IV-PLUS provides the following extensions: e Symbolic names up to 15 characters, and dollar sign characters e FORTRAN 77 character e FORTRAN 77 block ® Relative e Standard CALL e Hexadecimal constants e Symbolic debugging IF data including the underline type constructs file organization facility and field descriptors facility ) Increased’file manipulation facilities Because VAX-11 FORTRAN IV-PLUS is a compatible superset of PDP-11 FORTRAN, you can execute existing PDP-11 FORTRAN programs on VAX-11 hardware. (Note that throughout the rest of this manual, unless explicitly stated otherwise, VAX-11l FORTRAN IV-PLUS will usually be referred 1.1 to simply as FORTRAN.) CREATING AND EXECUTING A PROGRAM Figure 1-1 shows how a program proceeds from inception to execution. You specify the steps shown in Figure 1-1 by entering commands to the VAX-11l $ S S $ system. As shown, the commands are: EDIT file-spec FORTRAN file-spec LINK file-spec RUN file-spec With each command, you include information that further defines what you want the system to do. Of prime importance 1is the file specification, indicating the file to be processed. You can also specify qualifiers that modify the processing performed by the system. USING VAX-1l FORTRAN IV-PLUS COMMANDS INPUT/OUTPUT FILES $ EDIT AVERAGE.FOR Use the file type of FOR to indicate the file contains a VAX-11 FORTRAN IV-PLUS Create a | AVERAGE.FOR <ource program program. $ FORTRAN AVERAGE The FORTRAN command - assumes the file type of an input file is FOR. Compile the source program (If you use the /LIST AVERAGE.OBJ —_— (AVERAGE.LIS) ~ qualifier, the compiler libraries creates a listing file.) $ LINK AVERAGE The L/INK command assumes the file type of an input file AVERAGE.EXE Link the is OBJ. (AVERAGE.MAP) object modute (If you use the /MAP qualifier, the linker creates a map file.) $ RUN AVERAGE Run the The RUN command assumes exe:cutable the file type of an image is image EXE. Figure 1-1 Program Development Process l1.1.1 File Specifications A file output specification indicates the input file to be processed, or file to be produced. File specifications have the form: the node: :device: [directory]l filename.filetype.version node Specifies systems a network that device Identifies written. node support VAX-11l the device name. This 1is DECnet. on which a file is applicable stored : or only to to o be is S directory Identifies the name of the directory under which the file is cataloged, on the device specified. (You can delimit the directory name with either square brackets, as shown, or angle brackets < >). filename Identifies characters the file 1long. by its name; filename can be up to 9 USING VAX-11 filetype Describes the kind characters long. of data FORTRAN in the IV-PLUS file; filetype can be up to 3 version Defines which version of the file 1is desired. Versions are identified by a decimal number, which is incremented by 1 each time a new version of a file is created. Either a semicolon or a period can be used to separate filetype and version. You need not explicitly state all elements of a file specification each time you compile, link, or execute a program. The only part of the file specification that is usually required is the file name. If you omit any other part of the file specification, a default value is used. Table 1-1 summarizes the default values. Table 1-1 Specification Defaults File Optional Element Default Value node Local network node device User's current default device directory User's current default directory filetype Depends on usage: Input to compiler Output from compiler Input to linker Output from linker Input to RUN FOR OBJ OBJ EXE command EXE Compiler source listing Linker map listing Input to executing program Output from executing program version Input: highest existing version Output: highest existing version, plus 1 If you request compilation of a FORTRAN program, and you a file name, the compiler can process the source program file with the specified file name that: @ Is stored ® Is cataloged e Has If more one with than a on file one the default under type the LIS MAP DAT DAT specify only if it finds a device default directory name of FOR file meets the highest version these conditions, number. the compiler chooses the USING VAX-11] FORTRAN IV-PLUS For example, assume that your default device is DBAQ, your default directory is SMITH, and you supply the following file specification to the . compiler: CIRCLE The compiler will search device DBAO, in directory SMITH, seeking the highest version of CIRCLE.FOR. If you do not specify an output file, the compiler will generate the file CIRCLE.OBJ, store it on device DBAO in directory SMITH, and assign it a version number 1 higher than any other version of CIRCLE.OBJ currently cataloged in directory SMITH on DBAO. 1.1.2 Qualifiers Qualifiers specify special actions to be performed, and can be either command qualifiers or file qualifiers. Qualifiers have the form: /qualifier Many qualifiers have a corresponding negative form that negates the action that the qualifier specifies. The negative form is /NOqualifier. For example, the qualifier /LIST tells the compiler to produce a listing file; /NOLIST tells the compiler not to produce a listing file. Defaults have been established for each qualifier, based actions that are appropriate in most cases. Sections 1.2.2 which describe each command's qualifiers, contain tables on the and 1.3, 1indicating the defaults. You can specify qualifiers so that either all files included command are affected, or only certain files are affected. qualifier immediately follows the command name, it applies in the If the to all files. For example: $ If you and FORTRAN/LIST ABC,XYZ,RST specify the If you (with for ABC, XYz, include a qualifier as part of a file specification, it certain exceptions) affect only the file with which will it is assocliated. $ As a above, you will receive listing files RST. For example: FORTRAN/LIST ABC,XYZ/NOLIST,RST result of this command, RST, but not for XYZ. - listing : files S are created: A for 7 ABC and Qualifiers included with file specifications that are part of a concatenated 1list of input files are exceptions to this rule. See Example 5 in Section 1.2.1, below. USING VAX-11] 1.2 FORTRAN IV-PLUS COMPILATION To compile a source program, the FORTRAN command is: $ use FORTRAN|[/qualifiers] /qualifiers Codes indicating the FORTRAN command. The format of file-spec-list[/qualifiers] special actions to be performed by the compiler. file-spec-list Specification of the source file(s) containing the program to be compiled. You can specify more than one source file. If source file specifications are separated by commas, the programs are compiled separately. If source file specifications are separated by plus signs, the files are concatenated and compiled as one program., In interactive mode, you can also enter the file separate line by typing a carriage return after $§ responds with the prompt: specification FORTRAN. The on a system S_File: Type the 1.2.1 file specification immediately after the § File: prompt. Specifying Output Files The output produced by the compiler includes object files and 1listing files. You can control the production of these files by using the appropriate qualifiers with the FORTRAN command. If you do not specify otherwise, the compiler generates an object file. In interactive mode, the compiler generates no listing file, by default. In interactive mode, you must use the /LIST qualifier to generate a listing file. 1In batch mode, however, just the opposite is true: by default, the compiler will produce a listing file. To suppress the listing file, you must specify the /NOLIST qualifier. During the early stages of program development, you may £find it helpful to suppress the production of object files until your source program compiles without errors. Use the /NOOBJECT qualifier. 1If you do not specify /NOOBJECT, the <compiler generates object files as follows: e If you @ If you specify multiple source files, separated by plus the source files are concatenated and compiled, and one file is generated @ If you source specify one source specify multiple file generated for 1is each file, source compiled source one object files, file is generated separated by separately, and an signs, object commas, object each file is file @ You can use both plus signs and commas in the same command 1line to produce different combinations of concatenated and separate object files (see Example 4 below) To produce an object file with an explicit file specification, you must use the /OBJECT qualifier, in the form /OBJECT=file-spec (see Section 1.2.2.8). Otherwise, the object file will have the name of its corresponding source file, and a file type of OBJ. By default, USING VAX-11 FORTRAN IV-PLUS the object file produced from concatenated source files has the name of the first source file. All other file specification attributes (node, device, directory, and version) will assume the default attributes. Examples: l. $ FORTRAN/LIST AAA,BBB,CCC Source files AAA.FOR, BBB.FOR, and CCC.FOR are compiled as separate . files, producing object files named AAA.OBJ, BBB.OBJ, and CCC.OBJ; and 1listing files named AAA.LIS, BBB.LIS, 2. $ and FORTRAN CCC.LIS. ) XXX+YYY+Z7ZZZ Source files XXX.FOR, YYY.FOR, and compiled as one file, and Z2Z.FOR are concatenated producing an object file named XXX.0BJ. 3. $ FORTRAN/OBJECT=SQUARE $ FILE: CIRCLE The source file CIRCLE.FOR is compiled, producing an file named SQUARE.OBJ, but no listing file. (This applies to interactive mode only.) 4., $ object example FORTRAN AAA+BBB,CCC/LIST Two object files are produced: AAA.OBJ (comprising AAA.FOR and BBB.FOR), and CCC.OBJ (comprising CCC.FOR). One listing file is produced: CCC.LIS. 5. $ FORTRAN ABC+CIRC/NOOBJECT+XYZ When you include a qualifier in a list of files that are to be concatenated, the qualifier affects all files in the list. Thus, in the command shown, you will completely suppress the object file. That 1is, source files ABC.FOR, CIRC.FOR, and XYZ.FOR will be concatenated and compiled, but no object file will be produced. 1.2.2 FORTRAN Qualifiers in many cases, the simplest form of the FORTRAN command is for file processing. In some cases, however, you will need FORTRAN qualifiers that specify special processing. A FORTRAN qualifier /aal=yl where aa is has the form: L the qualifier's o name, L and y represents Note that many qualifiers accept no value; qualifiers is simply to activate or deactivate a processing. To For specify a sufficient to use the list of qualifier example: /CHECK= (BOUNDS ,OVERFLOW) values, enclose a qualifier wvalue. the purpose of these particular form of them in parentheses. USING VAX-11 FORTRAN IV-PLUS command. Table 1-2 lists the qualifiers you can use with the FORTRAN detail. Sections 1.2.2.1 through 1.2.2.11 describe each qualifier in Table 1-2 FORTRAN Command Qualifiers Default Negative Form Qualifier /NOCHECK /CHECK=0VERFLOW None /CONTINUATIONS=19 /NODEBUG /DEBUG=TRACEBACK /D_LINES /NOD_LINES /NOD_LINES /14 /NOI4 /14 /LIST[=file-spec] /NOLIST /NOLIST (interactive) [NO] BOUNDS . [NO]OVERFLOW /CHECK=) ALL NONE /CONTINUATIONS=n [NO] SYMBOLS [NO] TRACEBACK /DEBUG=) ALL NONE /LIST (batch) /MACHINE_CODE /NOMACHINE_CODE| /NOMACHINE_CODE /OBJECT [=file-spec] /NOOBJECT /OBJECT /OPTIMIZE /NOOPTIMIZE /OPTIMIZE /WARNINGS /NOWARNINGS /WARNINGS /WORK_FILES=n None /WORK_FILES=2 the 1.2.2.1 CHECK Qualifier - At run time, this qualifier causes ons conditi the for program your compiler to produce code to check It has the form: indicated. /CHECK =( [NO]BOUNDS [NO]OVERFLOW ALL NONE BOUNDS Array references are checked to ensure that they are within the array address boundaries specified. Note, however, that array bound checking 1is not performed for arrays that are dummy arguments, and for which the last dimension bound is specified as 1. For example: DIMENSION A(1) OVERFLOW BYTE, INTEGER*2, and arithmetic overflow. INTEGER*4 calculations are checked for USING VAX-11 FORTRAN IV-PLUS ALL Both OVERFLOW and BOUNDS checks are performed. NONE Neither The default /CHECK=ALL, check is and is performed. /CHECK=OVERFLOW. /NOCHECK is the If you specify /CHECK=BOUNDS implicitly canceled. or Note /CHECK of CONTINUATIONS Qualifier continuation lines allowed in - This the is the equivalent /CHECK=NONE. /CHECK=OVERFLOW, 1.2.2.2 of that equivalent the other check of is qualifier specifies the number program. It has the form: source /CONTINUATIONS=n You can specify /CONTINUATIONS, a value the default from 0 value to is 19. 99 for n. If you omit 1.2.2.3 DEBUG Qualifier - This qualifier specifies that the compiler is to provide information for use by the VAX-11 Symbolic Debugger and the run-time error traceback mechanism. It has the form: /DEBUG ={ [NO]SYMBOLS [NO] TRACEBACK ALL NONE SYMBOLS The compiler provides the debugger with local symbol user-defined variables, arrays (including for information), and labels of executable definitions dimension statements. TRACEBACK The compiler provides an address correlation table so the debugger and the run-time error traceback mechani sm can translate absolute addresses into source program routine names and compiler-generated line numbers. ALL The compiler provides both address correlation table. local symbol definitions and an NONE The compiler provides no debugging information. The default of /DEBUG=ALL, and/NODEBUG is the equivalent of /DEBUG=NONE. .If you specify either implicitly For more Chapter is /DEBUG=TRACEBACK. /DEBUG=TRACEBACK canceled. information 2. on debugging Note or and that /DEBUG is the /DEBUG=SYMBOLS, traceback, see the Section egquivalent other is 1.5 and USING VAX-11l FORTRAN IV-PLUS with D LINES Qualifier - This qualifier specifies that lines 1.2.2. 4 a D in column 1 are to be compiled. It has the form: /D_LINES The default is /NOD_LINES, which means that lines with a D in column 1 are treated as comments. compiler 1.2.2.5 I4 Qualifier - This qualifier controls how a Ehe length is not interprets specified. INTEGER and LOGICAL declarations for which It has the form: /14, The default is /I4, which causes the compiler to interpret INTEGER and If you specify LOGICAL declarations as INTEGER*4 and LOGICAL*4. /NOI4, the compiler interprets them as INTEGER*2 and LOGICAL*2, 1.2.2.6 file. LIST Qualifier - This qualifier It has the form: produces listing source a /LIST[=file-spec] You can include a file specification for the listing file. If you do not, it defaults to the name of the first source file, and a file type of LIS. The compiler does not produce a listing file in interactive mode unless you include the /LIST qualifier. In batch mode, the compiler produces a listing file by default. 1In either case, the listing file You must use the PRINT command to is not automatically printed. obtain a line printer copy of the listing file. See Section 1.7 for a sample listing. 1.2.2.7 listing MACHINE CODE Qualifier - This qualifier specifies that the file 1is to include a listing of the object code generated by the compiler. It has the form: /MACHINE_CODE This qualifier is ignored if no listing file is being generated. The default is /NOMACHINE CODE. 1.2.2.8 OBJECT Qualifier - This qualifier can be used when to specify the name of the object file. It has the form: you want /OBJECT [=file-spec] The default is /OBJECT. suppress object code; The negative form, /NOOBJECT, can be used to for example, when you only want to test the source program for compilation errors. If you omit the file specification, the object file defaults name of the first source file, and a file type of OBJ. to the USING VAX-1ll 1.2.2.9 produce FORTRAN IV-PLUS OPTIMIZE Qualifier - This qualifier optimized code. It has the form: tells the compiler to /OPTIMIZE The default is /OPTIMIZE. The negative form (/NOOPTIMIZE) should be used to ensure that the debugger has sufficient information to help you locate errors in your source program (see Section 2.9). 1.2.2.10 compiler WARNINGS Qualifier is to generate warning-level (W) errors. This qualifier specifies diagnostic messages in It has the whether response form: the to /WARNINGS The compiler generates warning (W) diagnostic messages by default. A warning diagnostic message indicates that the compiler has detected acceptable but nonstandard syntax, or has performed some corrective action; in either case, unexpected results may occur. To suppress W diagnostic messages, specify the negative form of this qualifier (/NOWARNINGS). Appendix B discusses 1.2.2.11 work The default files is compiler /WARNINGS. diagnostic messages. WORK_FILES Qualifier used by the compiler. This qualifier changes It has the form: the number of /WORK_FILES=n The value specified Note while that for n a value can be of 1 1, may 2, or increase 3. the restricts the size of programs that can be allows larger programs to be compiled, but may default is /WORK_FILES=2. 1.3 of compilation, compiled. A value slow compilation. it of 3 The LINKING Before file a compiled program to produce references symbolic in speed the $ an can be executable executed, you image file. in the object code, and establishes locations. To link an object module, following general form: LINK[/command-qualifiers] must absolute issue the input object /file-qualifiers Specify input file options. the the object resolves addresses LINK file to be linked. all for command, file-spec[/file-qualifiers]... /command=qualifiers Specify output file options. file-spec Specifies 1link Linking USING VAX-11] FORTRAN IV-PLUS no with In interactive mode you can issue the LINK command accompanying file specification. The system responds with the prompt: $§_File: the prompt. The file specification must be typed on the same line as If there are too many file specifications to fit on one line, you can the continue the line by typing a hyphen (-) as the last character of line, and continuing on the next line. You can enter multiple file specifications separated from each other When used with the LINK command, the comma by commas or plus signs. a is wused, no matter which sign: plus the as effect same has the If single executable image is created from the input files specified. no output file is specified, the linker produces an executable image with the same name as the first object module, and a file type of EXE. interest to Table 1-3 lists the 1linker qualifiers of particular users. FORTRAN the linker. See the VAX-11 Linker Reference Manual for details on Table 1-3 Linker Qualifiers Command Qualifiers Negative Form Default /EXECUTE [=file~spec] /NOEXECUTE /EXECUTE /SHAREABLE [=file-spec] /NOSHAREABLE None /MAP [=file-spec] /NOMAP /NOMAP (interactive) /BRIEF None Not applicable /FULL None Not applicable /CROSS_REFERENCE /NOCROSS_REFERENCE /NOCROSS_REFERENCE /DEBUG /NODEBUG /NODEBUG /TRACEBACK /NOTRACEBACK /TRACEBACK /MAP (batch) Input File Qualifiers /LIBRARY (s) /INCLUDE=module-name 1.3.1 Linker Command Qualifiers You can specify qualifiers for the LINK command to modify the output You can also define whether the debugging or the of the 1linker. traceback facility is to be included. USING VAX-11 FORTRAN IV-PLUS Linker output consists of an image file and, optionally, a map file. The following qualifiers control the image file generated by the linker: /EXECUTE=file-spec /NOEXECUTE /SHAREABLE=file-spec These Map qualifiers file are qualifiers described in Section 1.3.1.1. in Section 1.3.1.2. include: /MAP [=file-spec] /BRIEF /FULL /CROSS_REFERENCE These The qualifiers debugger and are described traceback qualifiers are: /DEBUG /TRACEBACK These qualifiers 1.3.1.1 Image are described File Qualifiers in - Section Image 1.3.1.3. file qualifiers include: /EXECUTE /SHAREABLE If you do not /EXECUTE; the production of an specify 1linker image, an image file qualifier, produces an executable specify the negative form, the image. as: default To 1is suppress /NOEXECUTE For example: $ LINK/NOEXECUTE CIRCLE The file CIRCLE.OBJ is 1linked, but no image is generated. The /NOEXECUTE gqualifier is wuseful if you want to verify the results of linking an object file, without actually producing the image. To designate a file specification /EXECUTE qualifier in the form: for an executable image, use the /EXECUTE=file~spec For example: $ The LINK/EXECUTE=TEST CIRCLE file named CIRCLE.OBJ TEST.EXE. is linked, and the executable image generated is USING VAX-11] FORTRAN IV-PLUS different of number A shareable image is one that can be used in a for your own use you 1image private a be It may applications. system the by system the in applications, or it may be installed manager for use by all users. To create a shareable image, specify the /SHAREABLE qualifier. For example: LINK/SHAREABLE CIRCLE $ To include a shareable image as input to the linker, you must wuse an options file, and specify the /OPTIONS qualifier in the LINK command. Refer to the VAX-11 Linker Reference Manual for details. If you specify /NOSHAREABLE, the effect is similar to /NOEXECUTE. The linker processes the object code and the input as though it were going to produce a shareable image, but in fact no image is generated. 1.3.1.2 whether is to Map File Qualifiers - The map file qualifiers a map file include. is to be generated, Map file qualifiers and, include: if so, the tell the linker information it /MAP /BRIEF /FULL /CROSS_REFERENCE The map qualifiers are specified as follows: /MAP [=file-spec] /BRIEF [/CROSS_REFERENCE] /FULL The linker uses defaults to generate or suppress a interactive mode, the default is to suppress the map; the default is to generate map file. In in batch mode, the map. If no file specification is included with /MAP, the map file has the name of the first input file, and a file type of MAP. It is stored on the default device, in the default directory. The qualifiers /BRIEF and included in the map file, /FULL as define follows: the amount of information ® /BRIEF produces a summary of the a list of contributing modules. e /FULL produces a summary of the image's characteristics and a list of contributing modules (as produced by /BRIEF); plus a list of global a summary of image. image's characteristics, and symbols and values, in symbol name order; and characteristics of image sections in the linked By default, if neither /BRIEF nor /FULL is specified, the map file contains a summary of the 1image's characteristics and a list of contributing modules (as produced by /BRIEF), plus a 1list of global symbols and values, in symbol name order. The /CROSS_REFERENCE qualifier can be used with either the default or /FULL map qualifiers, to request cross reference information for global symbols. This cross reference information indicates the object modules that linking. define USING VAX-11 FORTRAN and/or to The default 1.3.1.3 Debugging is and refer IV-PLUS global /NOCROSS_REFERENCE. Traceback symbols Qualifiers - The indicates that the VAX/VMS debugger (see Chapter 2) in the executable image. The default is /NODEBUG. When the /TRACEBACK accompanied by a qualifier symbolic 1is traceback specified, showing the encountered /DEBUG is error sequence during qualifier to be included messages of are calls that transferred control to the program unit in which the error occurred. If you specify /NOTRACEBACK, this information is not produced. The default 1is /TRACEBACK. If you specify /DEBUG, the traceback capability is automatically included, and the /TRACEBACK qualifier is ignored. Figure 1-2 illustrates a typical traceback 1list. (See Section 1.3.2 1.5.1.) Linker Input File Qualifiers File qualifiers affect the input file be object files; shareable files files. 1.3.2.1 /LIBRARY Qualifier - The specification. 1Input previously 1linked; /LIBRARY qualifier has files can or library the form: /LIBRARY This qualifier specifies that the input library that is to be searched to resolve in other input modules. The default file 1.3.2.2 /INCLUDE Qualifier - The file is an object-module undefined symbols referenced type is OLB. /INCLUDE qualifier has the form: /INCLUDE=module~name (s) The qualifier specifies that the input file is an object-module library, and that the modules named are the only modules in that library that are to be explicitly included as input. At least one module name is required. To specify more than one, enclose the module names in parentheses, and separate them with commas. The default file type 1is OLB. The /LIBRARY qualifier can also be used with the same file specification, to indicate that the same library is also to be searched 1.4 The The omit type even for unresolved references. EXECUTION RUN command $ RUN[/DEBUG] file initiates execution of your program. It has the form: file-spec name must be specified; default values are applied if you optional elements of the file specification. The default file is EXE. The /DEBUG qualifier allows you to use the debugger, though you omitted this qualifier from the FORTRAN and LINK commands. See Section 1.5 for details. USING VAX-11l 1.5 FINDING AND CORRECTING FORTRAN IV-PLUS ERRORS Both the compiler and the Run-Time Library include facilities for detecting and reporting errors. VAX/VMS also provides the debugger, to help you locate and correct errors. In addition there errors 1s a traceback facility that can also be that occur during program execution. 1.5.1 Error-Related Command Qualifiers to the used to debugger, track down At each step in compiling, linking, and executing your program, you can specify command qualifiers that affect how errors are processed. At compile time, you can use the /DEBUG qualifier to ensure that symbolic information is created for use by the debugger. At link time you can also specify the /DEBUG qualifier to make the symbolic information available to the debugger. The same qualifier can be specified with the RUN command, to invoke the debugger. Table 1-4 summarizes the /DEBUG Qualifier /DEBUG /DEBUG and /TRACEBACK Table 1-4 and /TRACEBACK Qualifiers Command FORTRAN Effect LINK Default The FORTRAN compiler creates symbolic data needed by debugger. /DEBUG qualifiers. the TRACEBACK) Symbolic data created by FORTRAN compiler is passed to the LINK Traceback information is passed to the debugger. Traceback will be produced. /DEBUG RUN Invokes the debugger. The DBG> prompt will be displayed. Not needed if $ LINK/DEBUG was specified. /NODEBUG RUN If /DEBUG was specified in the LINK command, RUN/NODEBUG the /NODEBUG debugger. /TRACEBACK suppresses /DEBUG= (NOSYMBOLS, DBG> /TRACEBACK prompt. If you use none of these qualifiers at any point in the compile-link-execute sequence, and an execution error occurs, you will receive a traceback list by default. However, you will not be able to invoke the debugger. To perform symbolic debugging, you must use the /DEBUG qualifier with both the FORTRAN command and the LINK command. It then becomes unnecessary to specify it with the RUN command. If you omit /DEBUG from either the FORTRAN or LINK command, you can use it with the RUN command, to invoke the debugger. However, any debugging you perform must then be done by specifying addresses in absolute form, rather than symbolically. USING VAX-11 If you linked your program with program without intervention by FORTRAN IV-PLUS the debugger, the debugger, but wish specify to execute the RUN/NODEBUG program If you specify LINK/NOTRACEBACK, event of shown error. in Figure An example you will of a receive source no program traceback and a in traceback the is 1-2. 0001 0002 0003 I=1 CONTINUE J=2 0004 0005 0006 0007 0008 CONTINUE K=3 CALL SUB1 CONTINUE END 0001 SUBROUTINE 0002 I=1 0003 0004 0005 J=2 CALL END 0001 0002 0003 SUBROUTINE COMPLEX W COMPLEX 2 0004 DATA W/(0.,0.)/ 0005 Z 0006 END = SUB1l SUB2 SUB2 LOG (W) $MTH-F-LOGZERNEG, logarithm of zero or negative value user PC 00000449 $TRACE-F-TRACEBACK, symbolic stack dump follows module name routine name line SUB2 SUB1 5 4 T1$SMAIN Figure The traceback is interpreted 6 1-2 as Traceback relative PC absolute PC 0000074cC 0000074cC 0000081C 00000011 00000017 0000081cC 00000449 00000437 0000001B 0000041B List follows: When the error condition is detected, you receive the appropriate message, followed by the traceback information. 1In this example, a message is displayed by the Run-Time Library, indicating the nature of the error, and the address at which the error occurred (user PC). This is followed by the traceback information, which is presented 1in inverse order to the <calls. Note that values may be produced for relative and absolute PC, with no corresponding values for routine name and line. These PC values reflect procedure calls internal to the Run-Time Library. USING VAX-11l FORTRAN IV-PLUS Of particular interest to you are the values 1listed under "routine name" and "line", the first of which shows what routine or subprogram called the Run-Time Library, which subsequently reported the error. The value given for "line" corresponds to the compiler-generated line number in the source program listing (not to be <confused with editor-generated line numbers). Using this information, you can usually isolate the error in a short time. If you specify either LINK/DEBUG, or RUN/DEBUG, the debugger assumes control of execution. If an error occurs, you do not receive a traceback list. To display traceback information, you can use the debugger command SHOW CALLS, as described in Section 1.5.2. 1.5.2 SHOW CALLS Command When an error occurs in a program that is executing under the control of the debugger, no traceback 1list 1is produced. To generate a traceback list, use the SHOW CALLS command, which has the form: DBG>SHOW 1.6 A CALLS SAMPLE TERMINAL SESSION typical dialog between you and the system might appear (ReT ) Username: SMITH Password: WELCOME (Your password is not displayed) TO VAX/VMS RELEASE $ EDIT CIRCLE.FOR Input:DBA2: [SMITH]CIRCLE.FOR 00100 (enter source program) 1 *E (terminate edit session and write [DBA2: [SMITH]CIRCLE.FOR;1] $ FORTRAN/NOOPTIMIZE/LIST/DEBUG CIRCLE $ LINK/DEBUG CIRCLE $ RUN CIRCLE file to disk) as follows: USING VAX-11l 1.7 FORTRAN IV-PLUS COMPILER LISTING FORMAT The listing produced sections, as follows: by ) Source listing ) Machine code ® Storage map Sections 1.7.1 detail. the compiler consists of two or three section listing section (optional) section through 1.7.3 describe the compiler listing sections in USING VAX-11l 1.7.1 Source Listing FORTRAN IV-PLUS Section The source listing section shows the the input file with the addition of by the compiler. Figure 1-3 shows a source program as it appears in sequential line numbers generated sample source listing section. Note that line numbers are generated only for statements that are compiled; comment 1lines are not numbered, nor are lines with D in column 1 unless you specified /D_LINES. Compiler-generated use them for line numbers debugging by appear using the in the RLINE left margin. specification You in can debugger commands (see Chapter 2). 1If the editor you use to create the .source file generates line numbers, these numbers will also appear in the source listing. In this case, the editor-generated 1line numbers appear in the left margin, and the compiler-generated line numbers are shifted to the right. The SLINE specification applies to the compiler—-generated line numbers, not the editor-generated numbers. / Compile-time and run-time error messages that contain line refer to the compiler-generated 1line numbers in the source section. See Appendix B for a summary of error messages. foeol SUBROUTINE 2002 PARAMETER eea3 geed DIMENSION X(@gM,02N) COMMON X goes LOGICAL Boeé 1 DONE oea? peos s Ms4Q, Nsb@ DONE ,TRUE, 12 10 J = I & {,N=} {, M=} 2812 IF (.NOT, DONE) 2013 RETURN 2014 END io ANEW 8 ( X(I=otpJ)eX(Ieg,J)eX(IpJe1)eX(I,J®1) ) /7 IF ( ABS(XNEWeX(I,J)) ,GT, EPS ) DONE = ,FALSE, X(I,J) = XNEW GO YO Figure 1-3 1.7.2 numbers listing RELAX2(EPS) 00 0O eaa9 eeio 2011 1line & ¢ Source Listing Section Machine Code Listing Section The machine code listing section provides a symbolic represen;a?ion of the compiler-generated object code. This representation is similar to a VAX-11l MACRO assembly listing for the generated code and data. The machine code listing section is optional. listing file, $ you must specify: To include FORTRAN/LIST/MACHINE_CODE Figure 1-4 shows a sample machine code listing section. it in the USING VAX-11 4000 +TITLE + JDENT RELAXR o1 +PSECT SBLANK 9000 X3 P200 0002 +PSECT RELAX213 0000 00ee 2009 00029 1119 eooF 0016 2216 ,113 +WORD ®M<IV,RS,R6,RT,R8,R9,R10,R11> MOVAL SLOCAL, R1i MNEGL #1, DONE(R1Y) MOVL ¥i, RY? MOVL ¥1, R9 MOVAL LSIANE $BLANK, 29210 ADDLY R9, goe29 ga2F 203s ADDF2 ADOF?2 MULF3 X=164(RS) (R12], RO X+164(RS) [R12]), R@ #¥“X3F8M, RO, RS °oa30 SUBF3 X(RS)[R1AA], ADDF3 BICw? CHMPF %41, R7, R6, 2Qae6 )y 2ea? )y 20208 ) 20n9 1 401 ) 001} ] 2412 R6 RO X+d4(RS) [R10), #*X80003, RO RO, OEPS(AP) 0948 @240 QO4F BLEQ CLRL LSIAP]s 0O4F MOVF R8, 2057 AOBLEQ #59, p0%8 POSF P063 MOVL MOVF MOVL R7, R8, R9, 2067 BR6A BLBC RET DONE(R11), 20583 1 RS MULLS LSIAGGH 2042 0047 IV-PLUS sCODE 0919 2010 on21 FORTRAN X=d4(RS5)([R1Q]), RS, RO RO LSIAP] NDONE(R1Y) AOBLEQ 439, X(RS)[R10Q) R9, LSIAGG R7, LSIANE J(R11) XNEW(R1}) I(R11) 1 +END Figure 1-4 Machine Code Listing Section The first line of the machine code listing contains a .TITLE assembler directive, indicating the program unit to which the machine code corresponds. For a main program, the title is either as declared in a PROGRAM statement, or filenameS$SMAIN, if you did not specify a PROGRAM statement. For subprograms, the title is the name of the subroutine or function. For a BLOCK DATA subprogram, the title is either name declared in the BLOCK DATA statement, or filename$DATA, if did not specify a name in the BLOCK DATA statement. the vyou The linesfollowing .TITLE provide information such as the contents of storage initialized for FORMAT statements, DATA statements, constants, and subprogram argument call 1lists. Machine instructions are represented by VAX-11 MACRO mnemonics and syntax. Compiler-generated line numbers corresponding to generated code lines are listed at the right margin before the machine code generated for the line. The VAX-11 general registers (0 through 12) are represented by RO through R12. When register 12 is used as the argument pointer, it is represented by AP; the frame pointer (register 13) is FP; the stack pointer (register 14) is SP, and the program counter (register 15) is USING VAX-11] PC. Note listed at that the the relative left margin, Variables and arrays machine code listing variables and arrays FORTRAN the source machine source program for each IV-PLUS instruction hexadecimal. or data item defined in the source program are shown in as they were defined in the source. Offsets are shown in decimal. labels code PC in FORTRAN referred listing refers to to in a dot with label 300, the source (.) the program prefix. label For appears are shown example, in the if is the from in the machine code 1listing as .300. Labels that appear in the source program, but that are not referred to or are deleted during compiler optimization, are ignored and do not appear in the machine code listing, unless you specified /NOOPTIMIZE. The compiler may generate labels for its own use. as L$xxxx, where the value of xxxx is unique for program unit. Integer constants precision, values and preceded Addresses are are shown complex by “X. as signed constants represented by integer are the shown program These labels appear each such label in a values; as real, unsigned section name hexadecimal offset within that program section. Changes program section to another are indicated by PSECT lines. 1.7.3 of the ) Program ) Entry ) Statement ) Variables ] Arrays ) Labels ® Functions () Total memory allocated Figure 1-5 summary for plus the from one Storage Map Section The storage map section following information: A double hexadecimal that compiler listing summarizes the sections points shows section section. a functions and subroutines sample heading storage is not map section. printed if no entries were generated USING VAX-11l FORTRAN IV-PLUS PROGRAM SECTIONS Name Bytes Attributes 2 $CODE € SLOCAL 107 16 10004 EXE SHR PIC CON REL LCL PIC CON REL LCL NOSHR NOEXE 3 SBLANK PIC OVR REL GBL SHR NOEXE RD NOWRT LONG WRT LONG RD WRT LONG RD ENTRY POINTS Tvype Name Address d=00002000 RELAX2 VARIABLES Address Tvype Nanme 2~000000089 Lx4 OONE 2=00000804 Type Name Address Type Name APegoooo0n04e L4 EPS 2=Qno0a0@8 Ix4 I Address 2*0000m2AC Ix4 J Rwy XNEW ARRAYS Address 3=00000000 Tvpe Name Bytes Dimengions Rweg X 100084 (0140,0360) LABELS 0=00000009 Tota) Address Lebe! Address 1 *k Space Allocated = 10127 Rytes Label 10 COMPILER OPTIONS /CHECK =(NOBOQUNDS, OVERFLOW) /DEBUG=(NOSYMBOLS, TRACEBACK) /OPTIMIZE /WARNINGS /14 /NOD,LINES Figure 1-5 Storage Map Listing Data in decimal. Sizes are printed as a number of bytes, expressed from the start of a program an offset as specified are addresses section, expressed in hexadecimal. The symbol AP can appear instead of a program section; in this case, the address refers to a dummy (AP). argument pointer the from argument, expressed as the offset Indirection is indicated by an at sign (@) following an address field. (or AP) In this case, the address specified by the program section to the address of the data, not to the data the offset points plus itself. each program The program section summary describes The descriptions include: generated by the compiler. ° PSECT number ® Name ° Size ° Attributes section (used by most of the other summaries) (PSECT) USING VAX-11 FORTRAN IV-PLUS Chapter 7 describes PSECT usage and attributes. addresses. their and The entry point summary lists all entry points If the program unit is a function, the declared data type of the entry point is also included. The statement function summary lists the entry point address and data The variable summary lists all simple variables, with type type of each statement function. and address of each. the data In addition to The array summary is similar to the variable summary. data type and address, it gives the total array size and dimensions. the size is shown as double If the array is an adjustable array, and each adjustable dimension bound is shown as a (**), asterisks single asterisk (*). FORMAT labels. statement user-defined The label summary lists all If the label suffixed with an apostrophe. statement labels are not was address field contains double asterisks (**), then the label used or referred to by the compiled code. external routine total the prints compiler the summaries, the Following allocated for all program sections compiled, in the form: memory The functions and subroutines references made by the summary source program. 1lists all Total Space Allocated = nnn Bytes 1.7.4 Other Listing Information The final entries on the compiler listing are the compiler in effect for that compilation. For example: COMPILER OPTIONS /CHECK= (NOBOUNDS ,OVERFLOW) /DEBUG= (NOSYMBOLS ,TRACEBACK) /OPTIMIZE /WARNINGS /I4 /NOD_LINES qualifiers CHAPTER 2 DEBUGGING FORTRAN PROGRAMS Debugging is the process of finding and correcting errors in executable programs; that is, in programs that have been compiled and linked without diagnostic messages, but that produce invalid results. This chapter shows you how to use debug 2.1 FORTRAN the VAX-1ll Symbolic Debugger to programs. OVERVIEW OF THE VAX-1ll SYMBOLIC DEBUGGER The VAX-11 Symbolic Debugger Reference Manual describes the VAX-11 debugger in detail. This section provides an overview of the debugger, showing a sample debugging session and introducing the debugger 2.1.1 command syntax and symbol table. sSample Debugging Terminal Session Figure 2-1 illustrates a program that requires debugging. The program has been compiled and linked without diagnostic messages from either the compiler or the linker. (Appendix B summarizes compiler diagnostic messages.) However, the program produces erroneous results because of the missing asterisk 1in the exponentiation operator (RADIUS*2 should be RADIUS**2), This error is so obvious that you hardly need the services of the debugger to find it. However, for purposes of illustration, this example will deal with the error as though it were shrouded C C 0001 0002 0003 0004 0005 0006 0007 0008 0009 in obscurity. PROGRAM TO FIND THE OF A CIRCLE AREA PROGRAM CIRCLE TYPE 5 5 FORMAT (' enter radius value FORMAT (' area of circle equals ACCEPT 10,RADIUS FORMAT (F6.2) PI = 3.1415927 AREA = PI*RADIUS*2 TYPE 15,AREA 10 15 0010 0011 ') STOP END Figure 2-1 Sample FORTRAN Program: 2-1 CIRCLE ',F10.3) DEBUGGING The key your to debugging program. selected if they To is to do find this, locations, and contain the FORTRAN out what you look at correct PROGRAMS happens need a at way to critical stop points in execution at the contents of these locations to see values. Points at which execution is stopped are called breakpoints. specify where you want to stop the The SET program. BREAK command lets vyou To look at the contents of a location, use the EXAMINE command. To resume execution, use either the GO or STEP command. All DEBUG commands relevant to FORTRAN are discussed in subsequent sections of this chapter. Figure 2-2 is session. that The follow an example of circled the figure typical numbers and explain $ FORTRAN/LIST/NOOFTIMIZE/DERUG $ $ LINK/DEBUG RUN CIRCLE DERUG Version 0,.5-1 28 Arril ") for a debugging are keyed to notes dialog. " 1978 ’ DRG>=GO start radius the CIRCLE ZDEBUG~-I-INITIAL» language is FORTRANy routine dialog CIRCLE DEBG>SET BREAK ZLINE 7 é enter terminal (for example, rc is score and module set to CIRCLE ‘a CIRCLENCIRCLE value 24, bresk at rc = CIRCLENCIRCLE Xline 7 ‘, NBGEXAMINE PI 6 CIRCLENFI? 3.141593 DRGEXAMINE RADIUS CIRCLENRADIUS? 24.00000 NDBEG>EXAMINE AREA CIRCLENAREA? 0.0000000 DEG>GO start area rpc of FORTRAN is CIRCLENCIRCLE Xline 7 eauals 150.796 circle STOF ZDEBUG-I-EXITSTATUSy is “XSYSTEM~-S—-NORMALs normal successful comrletion’ flb DBGHEXIT $ Figure " 2-2 Sample Debugging Terminal Invoke the FORTRAN compiler, You should symbolic Link In your include debugging program, response to the (see Section including the specifying /NOOPTIMIZE RUN the qualifier Dialog qualifiers if you intend shown. to use 2.9). the debugger. command, the debugger displays its identification, indicating that your program will be executed under the debugger's control.Following the identification message, the debugger displays an INITIAL message, telling you the mode settings it has assumed for the 1language, scope, and module. The debugger derives the mode settings from the first module specified in the LINK command. If this message does not appear, or 1if the settings assumed are not appropriate, use the SET LANGUAGE, Sections SET 2.2.1, SCOPE, 2.2.2, and and SET 2.2.3. MODULE commands, as described in DEBUGGING FORTRAN PROGRAMS Place a breakpoint at an appropriate point in the program. This point should be one at which you will be able to examine key variables. Note: Breakpoints suspend execution just before the point specified. Begin program execution. The debugger displays at which execution starts. The debugger announces specified breakpoint. that it has suspended the 1line execution number at the Check the variable PI to make sure the correct value 1is stored there. The debugger displays the contents of PI, showing that its scope is in module CIRCLE. Check the variable RADIUS. The debugger value has been properly stored. Examine the variable AREA to make Resume execution. The debugger point of program resumption. sure shows its displays that the specified contents are zero. a message Successful completion of the program 1is message. However, as you can see, the result flb indicating indicated by is incorrect. the this Exit from the debugger. By examining the variables PI, RADIUS, and AREA as the program is executing, you can determine that the correct values are being stored. It follows, then, that the error is probably in the expression of the formula for computing the area. To correct the problem, you must edit and recompile the source program, with the exponentiation operator properly specified in the formula expression. 2.1.2 Debugger Debugger is: Command commands DBG>command Syntax resemble other [keyword] [operand command Specifies the keyword Specifies the qualifiers command VAX/VMS commands. [,operand] The general form ...] name. for SET, SHOW, CANCEL commands. operand Specifies the object of the command. The operand may consist of constants, names of variables or array elements, or expressions. The command, keyword, and operand fields are separated by one can process integer, real, double precision, but not complex or character expressions. and or more spaces. The debugger expressions, 1logical The FORTRAN decreasing DEBUGGING FORTRAN PROGRAMS supported by operators order of the debugger are listed below, in concatenation, or precedence. *,/ +,- .NOT. .AND. .OR. .XOR., The .EQV. debugger relational does not support exponentiation, operators. The debugger evaluates expressions in the same way as FORTRAN. However, the syntax of expressions is slightly different. Spaces are used to separate elements of debugger commands, and are significant to the debugger; (such as .OR.) The the therefore, variable names and multicharacter must contain no embedded spaces. debugger accepts constants in the same form used following exceptions: Hollerith, Radix-50, constants Debugger forms. (for example "777) commands observe are not standard accepted VAX/VMS by the for and operators FORTRAN, with octal integer debugger. conventions for abbreviated Table 2-1 lists the debugger commands and keywords discussed in this chapter, and shows their full and abbreviated forms. Abbreviations are in parentheses next to the full form. Table Debugger 2-1 Commands and Keywords Command Names SET Keywords (SE) SHOW LANGUAGE (SH) (CAN) SCOPE (SC) EXAMINE (E) BREAK (B) TRACE (T) WATCH (W) (EV) DEPOSIT (D) DEFINE (DEF) EXIT (EXI) STEP (S) GO (G) CALL Debugger (LA) (MODU) CANCEL EVALUATE 2.1.3 MODULE (CA) Symbol Table The debugger maintains a table of symbols defined by the program with which it 1is 1linked. This table provides the name of each symbol defined in the program, its data type, and its address. The table also provides dimension bound information for arrays, and length information for character data. The debugger's 2000 symbols. defined in the more than one active symbol table provides room for approximately Thus, you should pay heed to the number of symbols programs you are debugging. If your program contains program unit, use the SET MODULE command to be sure the DEBUGGING FORTRAN PROGRAMS symbol table contains symbols from the program units you wish to debug. Use the CANCEL MODULE command to remove symbols defined in program units that no longer need debugging. The SET MODULE and CANCEL MODULE commands are defined in Section 2.2.2. 2.2 PREPARING TO DEBUG A PROGRAM The following sections describe the commands proper environment for debugging used to establish FORTRAN programs. These the commands are: SET LANGUAGE SHOW LANGUAGE SET MODULE SHOW MODULE CANCEL SET SHOW MODULE SCOPE SCOPE CANCEL SCOPE These commands can be used if debugger are not appropriate. 2.2.1 SET, SHOW LANGUAGE the 1initial settings assumed by the Command The SET LANGUAGE command tells the debugger that the debugging dialog is to be conducted according to the conventions of the specified language. For example, if you specify SET LANGUAGE FORTRAN, the debugger will accept and display numeric values in decimal radix. The command SET has the LANGUAGE language Specifies the form: language language to To determine which language is LANGUAGE command. This command SHOW be used. «currently in has the form: effect, wuse the SHOW effect. For LANGUAGE The debugger responds example: DBG>SHOW LANGUAGE language: FORTRAN by displaying the 1language in DEBUGGING 2.2.2 The SET, MODULE SHOW, CANCEL MODULE Commands the debugger's consists of following SET MODULE let you PROGRAMS active symbol table when the program you want to debug multiple program units. These commands perform the functions: e commands FORTRAN places unit into the active the the symbols contents defined in of the specified program the active symbol table. The debugger initializes symbol table to include all global symbols, and local symbols command. The control of the first program unit specified in the LINK ® SHOW MODULE displays the names of all program units whose symbols are potentially available. "Yes" means the symbols for that module are set; "no" means they are not set. e CANCEL MODULE removes the specified from the active symbol table. SET MODULE command SET MODULE has the program unit's symbols form: program-unit /ALL [,program-unit] ...} program-unit Specifies the name of the program unit whose included in the active symbol table. symbols are to be /ALL Requests the debugger to set the symbols of all known modules. If there 1is insufficient space, the debugger displays an error message. The SHOW MODULE SHOW command has the form: MODULE This command takes no parameters. The debugger responds by displaying the names of the modules 1linked with the debugger, indicating the modules whose symbols are included in the image, and their sizes. Only those module names marked "Yes" have their symbols in the active symbol table. The CANCEL MODULE command CANCEL MODULE has /ALL 2.2.3 /ALL removed. Specifies that symbol table. SET, SHOW, form: program-unit [,program-unit] program-unit Specifies the name of be the all CANCEL ...} the program unit for which ' information SCOPE is to be purged symbols from the are to active Commands The SCOPE commands let you control the default used to resolve references to symbols. When you use a command such as EXAMINE, you can either specify or omit the name of the module in which the symbol 2-6 DEBUGGING FORTRAN PROGRAMS is defined. If you omit the name, the debugger uses a default. If it cannot find the symbol in the default scope, the debugger creates a scope, based on the <current value of the PC. This indicates the module or routine in which your program stopped. If that fails, the debugger attempts to find an unambiguous symbol in the remaining program units. A message is displayed if the debugger cannot resolve the reference. The SCOPE commands perform the following functions: ® SET SCOPE defines the ® SHOW SCOPE displays the current default program unit name ® CANCEL SCOPE revokes the default program unit named previously in a SET SCOPE The SET SCOPE program-unit Specifies For the default command command has SET SCOPE specified program unit to be the form: program-unit the name of the program unit to be used as the default. example: SET SCOPE MAXI The SHOW SCOPE command has the form: SHOW SCOPE This command takes no parameters. current The CANCEL SCOPE CANCEL This command 2.3 The symbol displayed indicates the scope. command has the form: SCOPE takes no parameters. CONTROLLING Scope becomes <null>. PROGRAM EXECUTION To see what happens during execution of your program, you must be able to suspend and resume the program at specific points. The following commands are available for these purposes: SET BREAK SHOW CALLS SHOW BREAK CANCEL BREAK GO STEP SET TRACE SHOW TRACE CANCEL CTRL/Y TRACE EXIT SET WATCH SHOW WATCH CANCEL WATCH DEBUGGING 2.3.1 The SET, BREAK SHOW, the so program. @ SET e let you The you select can examine BREAK commands BREAK defines suspend PROGRAMS CANCEL BREAK Commands commands suspension, FORTRAN an specified and/or perform address 1locations for modify ‘variables the or following 1line or program arrays in functions. number at which to in the execution SHOW BREAK displays all breakpoints currently set program The e CANCEL BREAK SET BREAK command SET removes has BREAK[/AFTER:n] selected the breakpoints form: address [DO(debugger command(s))] address Specifies the address at which the breakpoint is to occur. Note that execution 1is suspended just before the specified address. Section 2.5 describes how addresses are specified. DO (debugger command(s)) Requests that the debugger perform the any, when the breakpoint is reached. For commands, if example: SET BREAK The result breakpoint You can a time DO is at use effect. of specified 3%LINE that line the following if you and through the 100 DO (EXAMINE TOTAL; variables TOTAL is reached. /AFTER qualifier Thus, loop, 100 to EXAMINE and AREA control are when a set a breakpoint on a line you want the loop, the then breakpoint specify the to be AREA) examined breakpoint that is in effective /AFTER when switch as the the shown the takes range third in the example: DBG>SET BREAK/AFTER:3 $LINE 20 Note that if you use the /AFTER qualifier, the breakpoint is reported the nth time it 1is encountered, and every time it is encountered thereafter. The SHOW BREAK SHOW command has the form: BREAK This command takes no parameters. the location of breakpoints. The CANCEL BREAK CANCEL BREAK command has address the The debugger responds by displaying i form: [,address...] /ALL address Removes the breakpoint(s) all breakpoints at the specified /ALL Removes in the program. address(es). DEBUGGING 2.3.2 SET, SHOW, CANCEL TRACE FORTRAN PROGRAMS Commands The TRACE commands let you set, examine, and remove tracepoints in your program. A tracepoint 1is similar to a breakpoint in that it suspends program execution, and displays the address at the point of suspension. However, program execution resumes immediately. Thus, tracepoints let you follow the sequence of program execution to ensure that execution is being carried out in the proper order. Note that tracepoints and breakpoints are mutually exclusive. That is, 1if you set a tracepoint at the same 1location as a current breakpoint, the breakpoint will be canceled, and vice versa. The TRACE commands perform the following functions: @ SET TRACE establishes points within execution is momentarily suspended the program at which ® SHOW TRACE displays the locations tracepoints are currently set the program at which e CANCEL TRACE the removes one or more in tracepoints currently set in program The SET TRACE command SET TRACE has the form: address address Specifies The SHOW TRACE the address at which command has the the tracepoint is to occur. form: SHOW TRACE This command takes The CANCEL TRACE CANCEL TRACE address Removes /ALL 2.3.3 no parameters. command has address /ALL the form: [,address the tracepoint(s) Removes all tracepoints SET, SHOW, in CANCEL WATCH at the ...]} specified address(es). the program. Commands The WATCH commands let you monitor specified when attempts are made to modify their 1locations contents, to determine and take the appropriate actions. These locations are called watchpoints. When an attempt 1is made to change a watchpoint, the debugger halts program execution, displays the address of the instruction, and prompts for a command. Watchpoints are monitored continuously. Thus, you can determine whether locations are being modified inadvertently during program execution. DEBUGGING The WATCH commands ® SET WATCH e SHOW WATCH e CANCEL perform defines the the displays WATCH FORTRAN PROGRAMS following functions: location(s) the disables to locations monitoring be monitored currently being monitored of specified Specifies the location to be monitored. variables and array elements. You can monitor breakpoints are locations The SET WATCH command has fhe form: SET WATCH var var For scalar example: SET WATCH AREA Note that watchpoints, exclusive. The SHOW WATCH command tracepoints, has the and mutually form: SHOW WATCH This The command takes CANCEL WATCH no parameters. command has CANCEL WATCH (var } /ALL Specifies location the All watchpoints are displayed. form: var the for which monitoring is to be disabled. /ALL Removes For all watchpoints from the program. example: CANCEL WATCH AREA 2.3.4 SHOW CALLS Command This command particularly CTRL/Y can be SHOW CALLS The debugger leading most used to produce useful when you have command. It has the form: to recent described a traceback returned to the of calls, debugger and following is a [n] displays the calls a traceback current module. are displayed. in Section 1.5. list, showing If you The form the include of the sequence a value for traceback of n, calls the 1list n is DEBUGGING FORTRAN PROGRAMS 2.3.5 GO, STEP Commands These commands let you initiate and resume program execution. @ GO initiates execution at a specified location, and to conclusion or to the next breakpoint @ STEP execution initiates from the continues 1location, current continues for a specified number of statements and The form of the GO command is: GO [address] address Specifies the address at which program execution is to begin. The address parameter is optional; at the current location. if you omit it, execution starts NOTE the You must not restart a program from beginning unless you first exit from the be Unspecified results will debugger. produced. The form of the STEP command is: STEP[/qualifiers] [n] be to statements The value specified for n determines the number of specify 0, or omit n, a default of 1 is assumed. If you executed. Note, however, that if you issue a STEP command while your program is in a module whose symbols are not set in the active symbol stopped table, then n instructions (not statements) will be executed. You can specify the following qualifiers for the STEP command: /[NO] SYSTEM /OVER /INTO /LINE /INSTRUCTION / [NO] SYSTEM If you specify /SYSTEM, debugger to count steps you are wherever including system address space. telling the they occur, The default is /NOSYSTEM. /OVER subprograms - Tells the debugger to ignore calls to That is, it is steps through the program. it as to step over the call. This is the default. /INTO to calls recognize to debugger the - Tells That subprograms as it steps through the program. is, it is requested to step into the subprogram. /LINE - Tells the debugger to step through the program a line-by-line basis (default for FORTRAN). /INSTRUCTION on on Tells the debugger to step through the program an 1instruction-by-instruction basis (default for VAX-11 MACRO). DEBUGGING You or can you specify can SET use STEP FORTRAN PROGRAMS each time you shown in these qualifiers a SET STEP command, INSTRUCTION, INTO, as issue the a STEP following command, example: SYSTEM This command specifies that all defaults applicable to FORTRAN programs are to be overridden. When you subsequently issue a STEP command with no qualifiers, these qualifiers are assumed to be 1in effect. with You a STEP can, however, command. STEP/LINE supersede them by including a qualifier Thus, 10 tells the debugger command. to execute 10 lines, regardless of the SET STEP It is advisable to use STEP to execute only a few instructions at a time. To execute many instructions, and then stop, use a SET BREAK command to set a breakpoint, and then issue a GO command. 2.3.6 You CTRL/Y Command can use the CTRL/Y command at any time to return to the system command level. This command is issued when you press the CTRL key and the Y key at the same time. The $ prompt will be displayed on the terminal. To return to the debugger, type DEBUG. You can use the CTRL/Y command if your program loops or otherwise fails to stop at a breakpoint. To find out where you were at the instant CTRL/Y was executed, use the SHOW CALLS command after you return to the debugger. See Section 2.3.7 The 2.3.4. EXIT Command EXIT terminate command lets a debugging you exit session. from the It has debugger the when you are ready to form: EXIT This command your program 2.4 takes no parameters. terminates to return You must to system use the command EXIT command level. when EXAMINING AND MODIFYING LOCATIONS Once you have set breakpoints and begun program execution, the next step 1is to see whether «correct values are being generated and, possibly, to change the contents of locations as execution proceeds. You may also want to calculate the value of an expression that appears in your program. The debugger provides the following commands for these purposes: EXAMINE DEPOSIT EVALUATE DEBUGGING FORTRAN 2.4.1 The EXAMINE EXAMINE locations. Command command It has EXAMINE PROGRAMS 1lets the you 1look at the contents of specified form: [address|:address]] address Specifies the address whose contents are to usually given symbolically as a variable be examined; it 1is name or array element name. Examples: EXAMINE The IZZY contents of variable EXAMINE The IARR(I) contents of EXAMINE IZZY are displayed. the Ith element the first through You can also specify that displayed. For example: EXAMINE 600 contents of 2.4.2 IARR are displayed. IARR(1l) :IARR(10) The contents of examined. The in array DEPOSIT absolute the tenth elements of contents address 600 of are an the array absolute IARR are address be displayed. Command L] The DEPOSIT locations. command It has DEPOSIT lets the you change contents of specified form: address=value{,value address Specifies the the address the value ... into which ] the value is to be deposited. value Specifies to be deposited. You can change the contents of a specific 1location, or consecutive locations, as shown in the following examples. DEPOSIT This This 1, 2, 3 the decimal value 100 into the variable IZZY. IARR(1)=100,150,200 command places and several I1I2ZY=100 command places DEPOSIT of of array the decimal values IARR. 100, 150, and 200 into elements DEBUGGING FORTRAN 2.4.3 The EVALUATE Command EVALUATE determine command the value EVALUATE value EVALUATE the use the debugger It expression whose has the as a calculator, form: to g value is to be determined. of PI*RADIUS this command expression will to determine EVALUATE /ADDRESS For you expressions. example: EVALUATE The lets of expression expression Specifies For PROGRAMS be displayed. addresses, as You can also use the such as follows: expression example: EVALUATE /ADDRESS This calculates the I address of the variable I, in decimal. EVALUATE/ADDRESS A (J) This calculates You can also computing an the address of element of array A. use EVALUATE to perform address arithmetic, offset or array element address. For example: EVALUATE /ADDRESS 2.5 the Jth I+4 SPECIFYING ADDRESSES The debugger allows you to express addresses in symbolic form. Thus, to examine a location, you need only refer to it by its symbolic name. You don't have to concern yourself with its 1location in memory (unless, of course, you omitted the /DEBUG qualifier from the FORTRAN and LINK commands). Simply specify the variable, array element, or function name in the debugger command. You also need to tell the debugger where to set breakpoints, watchpoints, and tracepoints. The following sections describe how to specify line numbers, statement labels, and absolute addresses. 2.5.1 Lines, Labels, and Absolute Addresses Addresses can be specified by 1line number, statement 1label, or absolute value. To specify a line number or a statement label, use either a $LINE prefix or a $LABEL prefix, respectively. For example: SET BREAK 3SLINE 6 This command sets a breakpoint at 1line 6, corresponding to the compiler-generated 1line numbers shown in the listing. Note that the debugger does not recognize all 1line numbers, in particular those associated with non-executable statements. If you specify such a line number, the debugger responds with a message indicating that no such DEBUGGING FORTRAN PROGRAMS line exists. Simply retry the command, specifying the line number of an executable statement. To specify a statement label, specify a command such as: SET BREAK $%LABEL 7 label This command sets a breakpoint at statement identified by the current scope (see Section 2.2.3). To specify an absolute address, do not use a prefix. module the in 7 For example: SET BREAK 700 You can also enter absolute addresses in symbolic form. have must defined (see Section 2.5.4). To do so, you them symbolically, by means of the DEFINE command Specifying Scope 2.5.2 If the program you are debugging consists of more one than program unit, you must be sure that your symbol references are unambiguous. For example, if your main program calls a subroutine, and the symbols from both program units are in the debugger's symbol table, you must distinguish between duplicate symbols. For example, assume that you want to set subroutine, and you issue the following command: a breakpoint the 1in SET BREAK %LINE 10 Because you do not specify a program unit name in this command, the debugger uses a default to decide which line 10 you mean. If you used a SET SCOPE command, the debugger uses the program unit specified in the SET SCOPE command (see Section 2.2.3). To override this default, you must specify a command in the following general form: SET BREAK $LINE program-unit\1l0 For example: SET BREAK %LINE ARGO\1l0 This command specifically calls for a breakpoint to be set at line 10 in the program unit named ARGO. Unambiguous references are also required when you specify variables. If there are duplicate variable names (for instance, X) you should specify which X you want, as in the following example: EXAMINE SUB3\X Previous, Current, and Next Locations 2.5.3 The debugger provides a quick method for referring to any of locations: e The previous location e The current location e The location at the next higher address (next location) 2-15 three DEBUGGING To specify (). the previous FORTRAN location, For example: PROGRAMS type an up-arrow (%) of the previous location. or circumflex EXAMINE This To command specify displays the DEPOSIT the current contents location, type a dot (.). For example: .=100 This command puts a decimal value of 100 in the current location. This method is most useful after you have looked at a location and decided to change it; or when you want to verify that a DEPOSIT command has been To specify the entirely. For executed as next higher example: expected. location, simply omit the address value EXAMINE The next 2.5.4 You location's Defining Addresses may do so, symbolic occasionally address DEFINE command The the Symbolically need to access absolute addresses. To help you has the form: For TOP=1036 references to this address example: DEPOSIT 2.6 displayed. example: Subsequent The be name=address DEFINE TOP. will the debugger provides the DEFINE command, which creates a reference for an absolute address. Then you can refer to the by its symbolic name, rather than by its absolute value. The DEFINE For contents contents can be made using the symbol TOP=256 of address 1036 will be changed to 256. CALLING SUBROUTINES FROM THE DEBUGGER CALL command form: lets you call Specifies the subroutine Specifies one or more a subroutine name. actual arguments. from the debugger. It has DEBUGGING FORTRAN PROGRAMS On return from the subroutine, control returns to the debugger, at the point at which the CALL command was issued. The context (general registers, etc.) that existed at the time of the CALL 1is also restored. When calling FORTRAN routines, you must adhere to the FORTRAN 5. conventions described in Chapter 2.7 calling DEBUGGER COMMAND QUALIFIERS Qualifiers can be used to modify some debugging commands. form in which qualifiers are specified is: The general command/qualifier Qualifiers change the defaults the debugger uses 1in processing when you deposit a value, the debugger uses example, For commands. You can override the default by specifying decimal radix by default. Table 2-2 summarizes the command qualifiers of either /HEX or /OCT. particular significance in FORTRAN debugging. Table 2-2 Debugger Command Qualifiers Qualifier Function Commands /ADDRESS Indicates that an address value 1is EVALUATE desired /HEX /OCT Refer to the VAX-11 Override the default radix (decimal) Symbolic information on gqualifiers. 2.8 Debugger EVALUATE DEPOSIT Reference Manual for more NUMERIC DATA TYPES FORTRAN 1in VAX-1ll The debugger supports all numeric data types used and (Complex values can be deposited except complex. IV-PLUS, examined, however.) Furthermore, if you attempt to deposit a numeric a variable or array element that does not have a matching into value data type, the value is converted to the data type of the variable or array element. To deposit a complex value, real part, For specify it in two parts as: imaginary part example: DEPOSIT CPLX=3.4,-4.7 When you examine a complex variable or array element, the data displayed as a complex constant, as (real part, imaginary part). is DEBUGGING When you deposit real numbers, you distinguish single precision D, respectively. For example: Number 2.9 You Data must specify a decimal point. use To E and Type Single precision 24.1E0 Single precision 24.1D0 Double precision 241E0 Invalid (default) (no decimal point) EFFECTS OF OPTIMIZATION ON DEBUGGING should include program necessary programs, the by bugs compiler /NOOPTIMIZE may need VAX-11 default; optimization eliminating is qualifier to be liable while to in when debugged. FORTRAN and, from programs uses IV-PLUS you This create difficulty the development in optimization central processor condition codes frequently-used variables to registers control proceeds e Binding e Assuming sequence, These techniques described below. that the based and flow on of source some of a is performs for and techniques: in a code the bug-free finding stage. following Using compile qualifier compiler highly desirable the e 2.9.1 the that because optimizations implications for certain debugging are in the Use of Condition Codes This optimization technique central the PROGRAMS and double precision numbers, 24.1 FORTRAN The FORTRAN processor's following source X =X+ IF (X 2.5 .LT. 0) takes condition advantage codes code: GO TO are of the way set. For which example, consider 20 Rather than test the new value of X to determine whether to branch, the optimized object code bases its decision on the condition code settings after 2.5 is added to X. Thus, if you attempt to set a breakpoint at the second line, and deposit a different value into X, you will not achieve the intended result, because the condition codes no 1longer reflect the value of X. 1In other words, the decision to branch is being made without regard to the new value of the variable. 2.9.2 Register Binding This technique is used to reduce the number of memory references or load-and-store instructions needed. The values of frequently-used variables are kept in general registers, and the registers are used, rather than the variables. Therefore, if you deposit a new value in a DEBUGGING FORTRAN PROGRAMS variable that has been bound to a register, the new value will have no if you examine the variable, the current value Moreover, effect. register) may not be displayed. the in kept is (which 2.9.3 Control Flow The compiler assumes that statements will be executed in the sequence in which they appear in source code, if there are no intervening labels. Optimization of such code sequences will not let you use the "GO address" version of the GO command. 2.9.4 Effects of /NOOPTIMIZE and /OPTIMIZE The /NOOPTIMIZE qualifier tells the compiler not to assume that not to keep the values of variables in condition codes are valid; across statement boundaries. optimize to not and general registers; In short, the object program directly reflects the source program. When /NOOPTIMIZE is in effect, you can issue any of debugging the commands. When /OPTIMIZE is in effect, you should not use the GO address However, you can set and clear breakpoints and examine command. COMMON variables. If you need to debug a program that was compiled with /OPTIMIZE in effect, you may need a compiler listing of the generated machine code. Thus, if you do not suppress optimization, you should specify /LIST and /MACHINE_CODE in the FORTRAN command. 2-19 CHAPTER 3 FORTRAN INPUT/OUTPUT This chapter describes FORTRAN input/output (I/0) as implemented for VAX-11 FORTRAN IV-PLUS. 1In particular, it provides information about FORTRAN IV-PLUS I/0 in relation to VAX-1l Record Management Services (RMS). The topics covered file include: e VAX/VMS e Logical names as used e FORTRAN e FORTRAN record formats e OPEN e Auxiliary I/O operations e Local 3.7) (Section 3.2) (Section 3.3) (Section statement features interprocess (Section 3.1) in FORTRAN file characteristics (Section e specifications 3.4) (Section 3.5) (Section 3.6) communication by means Remote communication by means of DECnet-VAX of mailboxes (Section 3.8) The FORTRAN I/O statements are: READ, WRITE, ACCEPT, PRINT, and TYPE. The device or file to or from which data is transferred is designated by a logical unit number, specified or implied as part of statement. Logical unit numbers are integers from 0 to 99. For the 1I/0 example: READ (2,100) I,X,Y This statement specifies that data is to be entered from the device or file corresponding to logical unit 2, in the format specified by the FORMAT statement labeled 100. The association between the 1logical unit number and the physical device or file occurs at execution time. You can change this association at execution time, if necessary, to match the needs of the program and the available resources. You need not change the logical unit numbers specified in the program. inherently device independent. Thus, FORTRAN programs are You can use standard FORTRAN I/0 statements to communicate between processes on either the same computer or different computers. Mailboxes permit interprocess communication on the same computer. DECnet network facilities are used for interprocess communication on different computers. DECnet can also be used to process files on different computers. FORTRAN 3.1 A FILE INPUT/OUTPUT SPECIFICATION complete VAX/VMS file specification has the form: node::device: [directory]filename.filetype.version For example: BOSTON: :DBAQO: [SMITH]TEST.DAT.2 node BOSTON device DBAO (unit 0 of disk DBA) file name is directory SMITH (the cataloged in the disk directory named SMITH) filename TEST filetype DAT version number 2 If you omit default elements values, as of the file follows. specification, If you omit the the node, system the supplies local computer is used; if you omit the device or directory, the current user default 1is used; if you omit the file name, the system supplies FOROnn, where nn is the logical unit number; if you omit the file type, the the system input) For or example, directory READ The system supplies DAT; and if you omit the version number, supplies either the highest current wversion number (for the highest current version number plus 1 (for output). is suppose your SMITH, and you default device is DBAO: and your default specify: (8,100) default file specification is: DBAO: [SMITH] FOR0O08.DAT.n The value FOR008 .DAT. Then, The of n equals suppose you specify: WRITE (9,200) default file the specification highest current version number of is: DBAO: [SMITH]FOR0O09.DAT.m Where m is 1 FOR009 .DAT. greater than the highest existing version number of FORTRAN INPUT/OUTPUT 3.2 LOGICAL NAMES a The VAX/VMS operating system provides the logical name mechanism as means of associating 1logical units with file specifications. A logical name is an alphanumeric string, up to 15 characters long, that is specified instead of a file specification. names, 1logical predefined The operating system provides a number of Table 3-1 file specifications. already associated with particular interest to FORTRAN users. lists the logical names of special Table 3-1 Predefined System Logical Names Name Meaning Default SYS$DISK Default device and directory As specified by the user SYSSINPUT Default input stream User's terminal SYSSOUTPUT Default output stream User's terminal batch (interactive); command file (batch) batch (interactive); log file (batch) You can create a logical name dynamically, and associate it with a file specification by means of the VAX/VMS ASSIGN command. Thus, before program execution, you can associate the logical names in your program with the file specification appropriate to your needs. For example: $ ASSIGN DBAQ:[SMITH]TEST.DAT.2 LOGNAM it with This command creates the logical name LOGNAM and associates This will be the file file specification DBAO: [SMITH]TEST.DAT.2. the specification used when the logical name LOGNAM is encountered during program execution. Logical names provide great flexibility because they can be associated not only with a complete file specification, but with a device, a device and a directory, 3.2.1 or even another logical name. FORTRAN Logical Names Usually, FORTRAN I/O is performed by associating a logical unit number The VAX/VMS logical name concept allows one or file. a device with name can be a user-specified 1logical more level of association: associated with a logical unit number. VAX-11 FORTRAN IV-PLUS provides predefined logical names, in the form: FOROnNnn By default, The value of nn corresponds to the logical unit number. FORTRAN logical name is associated with a file named FOROnn.DAT, each 3-3 FORTRAN which is assumed to be default directory. For WRITE located example: INPUT/OUTPUT on your default disk, under (17,200) If you enter this statement, without including an explicit specification, the data will be written to your default disk, file named FOR017.DAT, under your default directory. You can logical file to a change wunit associated $ your the file specification associated with a FORTRAN number by wusing the ASSIGN command to change the file with the corresponding FORTRAN logical name. For example: ASSIGN DBAO:[SMITH]TEST.DAT.2 FOR017 This command associates the FORTRAN logical name FOR017 (and therefore logical wunit 17) with file TEST.DAT.2 on device DBAO, in directory SMITH. You can also associate the FORTRAN logical names with predefined system logical names. Two examples follow. l. $ ASSIGN SYSSINPUT $ ASSIGN This Many VAX-11l assignments example. 3.2.2 SYSSOUTPUT command output systems for Implied (for FORTRAN logical example, provide 1logical the 5 with the default stream). input FOR006 associates device of FORO0O05 This command associates logical unit device (for example, the batch input 2. any unit batch system-wide wunits Logical the 5 and 6 6 with output default as shown the default stream). logical in the name preceding Unit Numbers The READ, ACCEPT, PRINT, and TYPE statements do not include an explicit logical unit number. Each of these FORTRAN statements uses an implicit logical unit number and logical name. Each of these logical names 1is, in turn, associated with one of the system's predefined 1logical names, by default. Table 3-2 shows these relationships. Implicit Table 3-2 FORTRAN Logical FORTRAN Statement READ f,list ACCEPT PRINT TYPE f,list f,1list f,list Logical Name Units System Logical Name FORSREAD SYSSINPUT FORSACCEPT SYSSINPUT FORSPRINT SYSSOUTPUT FORSTYPE SYSSOUTPUT FORTRAN INPUT/OUTPUT As with any other FORTRAN 1logical name, you can change the file specifications associated with these FORTRAN logical names by means of the ASSIGN command. SASSIGN For example: DBAO:[SMITH]TEST.DAT.2 FORSREAD Following execution of this command, the READ statement's logical name (FORSREAD) will refer to the file TEST.DAT.2, on device DBAO, in directory SMITH. 3.2.3 OPEN Statement NAME Keyword You can use the NAME keyword of the OPEN statement to specify the particular file to be opened on a logical unit. (Section 3.5 describes the OPEN statement in greater detail.) For example: OPEN (UNIT=4, NAME='DBAO: [SMITH]TEST.DAT.2', TYPE='OLD') In this example, the file TEST.DAT.2, on device DBAO:, in directory SMITH, is opened on logical unit 4. Neither the default file specification (FOR004.DAT) nor the FORTRAN logical name FOR004 is NAME keyword can be a character constant, the of value The used. variable, or expression. You can also specify a logical name as the value of the NAME keyword, if the 1logical name 1is associated with a file specification. For example: SASSIGN DBAO:[SMITH]TEST.DAT LOGNAM This command assigns the logical name LOGNAM to the file specification DBAQO: [SMITH] TEST.DAT. The logical name can then be used in an OPEN statement, OPEN as follows: (UNIT=19,NAME='LOGNAM',TYPE='OLD"') When an I/0 statement refers to logical unit 19, the system file specification associated with logical name LOGNAM. uses the If the value specified for the NAME keyword has no associated file specification, it is regarded as a true file name rather than as a logical name. That is, if LOGNAM had not been previously associated with the file specification DBA(O: [SMITH]TEST.DAT by means of an ASSIGN command, then the following statement would indicate that a file named LOGNAM.DAT is located on the default device, in the default directory: OPEN (UNIT=19,NAME='LOGNAM',TYPE='OLD"') A logical name specified in an OPEN statement must not contain brackets or periods. The system treats any name containing these punctuation marks as a file specification, not as a logical name. FORTRAN INPUT/OUTPUT 3.2.4 Assigning Files You can assign 1. By files to Logical Units to logical using default READ Logical units logical in any of names; two three ways: examples follow. (7,100) unit FOR007 is associated with the file FOR007.DAT by default. TYPE Logical default. 2. unit FORSTYPE By specifying example: OPEN 3. a logical 1is associated name in an with SYS$SOUTPUT by OPEN statement. For an OPEN statement. For (UNIT=7,NAME='LOGNAM') By supplying example: OPEN You and 100 a file specification in (UNIT=7 ,NAME='LOGNAM.DAT') use the ASSIGN command file specifications. to change the association of logical names A logical name used with the NAME keyword of the OPEN statement must be associated with a file specification, and the character expression specified for the NAME keyword must contain no punctuation marks. Otherwise, the logical name will be treated as a true file specification. Use the VAX/VMS associations of SHOW logical LOGICAL names To remove the association use the DEASSIGN command, $SDEASSIGN 3.2.5 You The of in and command file a logical the form: to determine the current specifications. name and a file specification, logical=-name Assigning Logical Names with MOUNT Commands can specify a MOUNT command $ logical has the name as form: MOUNT device-name,... a parameter of [volume-label,...] the TAPE2 MYTAPE command. [logical-name[:]] If your program refers to devices by means of logical change the association between the device name and when you mount the device. For example: $ MOUNT MT: MOUNT names, you the logical can name FORTRAN INPUT/OUTPUT This command associates the logical name MYTAPE with device name MT and volume label TAPE2. Whenever your program refers to logical name MYTAPE, access will be to the volume 1labeled TAPE2 mounted on the default magnetic tape unit. If you subsequently mount a different tape to be referenced by the logical name MYTAPE, you can change the logical name association when you issue the MOUNT command. For example: $ MOUNT MT: 3.3 TAPE7 MYTAPE FILE CHARACTERISTICS A clear distinction must organized and the manner be made between the way in which in which records are accessed. files are The term "file organization" applies to the way records are physically arranged on a storage device. "Record access" refers to the method used to read records from or write records to a file, regardless of its organization. A file's organization is specified when the file is created, and cannot be changed. Record access is specified each time the file is opened, and can be different each time. 3.3.1 File Organization VAX-11 FORTRAN IV-PLUS ® Sequential ® Relative supports two file The organization of a file is specified OPEN statement, as described in Section 3.3.1.1 Sequential Organization sequential. organizations: by means 3.5.4. The default of file a keyword in organization the 1is Sequential files consist of records arranged in the sequence in which they are written to the file (the first record written is the first record in the file, the second record written is the second record 1in the file, etc.). As a result, records can be added only at the end of the file. Sequential file organization is permitted on all devices supported by the VAX-11 FORTRAN system. 3.3.1.2 Relative Organization - Relative files are permitted only on disk devices. A relative file consists of numbered positions, called cells. These cells are of consecutively from 1 to last available cell in the fixed, equal n, where 1 is file. 1length, the first and are numbered cell, and n is the This arrangement lets you place records into the file according to cell number; the cell number becomes the record's relative record number; that is, its location relative to the beginning of the file. As a result, you can retrieve records directly by specifying their relative record number, because the actual location of the record 1is easily calculated relative to the beginning of the file. You can add records to, or delete them from, the file regardless of their FORTRAN location, the as long as you keep INPUT/OUTPUT track of the relative record numbers of records. 3.3.2 Access Records can be to Records accessed e Sequential @ Direct in two ways: access access The access mode chosen is unrelated to the file organization. You can access records in both relative and sequential files sequentially or directly (with certain restrictions, described below). 3.3.2.1 Sequential Access - If you records are written to or read beginning and continuing through the select sequential access mode, from the file, starting at the file one record after another. Sequential access to a file means that a particular record can be retrieved only when all the records preceding it have been read. Writing records by means of sequential access varies according to the file organization. New records can be written only at the end of a sequentially organized file. For a relative organization file, however, a new record can be written at any point, replacing the existing record in that cell. For example, if two records are read, and then a record is written, the new record occupies cell 3 of the file. 3.3.2.2 Direct Access - If you select direct access mode, you determine the order in which records are read or written. Each READ or WRITE statement must include the relative record number indicating the record to be read or written. You can access relative files directly, and you can also directly access a sequential file 1if it contains fixed length records and resides on disk. Because direct access uses cell numbers to find records, you can issue successive READ or WRITE statements requesting records that either precede or follow previously requested records. For 3.4 example: READ (12'24) - read record 24 in file 12 READ (12'20) - read record 20 in file 12 RECORD STRUCTURE Records are stored 1. Fixed 2, Variable 3. Segmented in one length length of three formats: FORTRAN INPUT/OUTPUT Fixed length and variable length formats can be used with sequential or relative file organization. Segmented format is unique to FORTRAN, and can be used only with sequential file organization, and only for unformatted sequential access. You should not use segmented records for files that will be read by programs written in languages other than FORTRAN. ‘ 3.4.1 Fixed Length Records When you specify fixed length records (see Section 3.5.7), you are specifying that all records in the file contain the same number of bytes. When you create a file that 1is to contain fixed length records, you must specify the record size (see Section 3.5.6). A sequentially organized file fixed 1length records, to correctly. Note that in length record contains an 3.4.2 opened allow for the a relative extra byte, direct record access must contain number to be computed organization file each fixed the deleted-record control byte. Variable Length Records Variable length records can contain any number of bytes, up to a specified maximum. Variable 1length records are prefixed by a count field, indicating the number of bytes in the record. The count field comprises two bytes on a disk device, and four bytes on magnetic tape. The value stored in the count field indicates the number of data bytes in the record. Variable length records in relative files are actually stored in fixed length cells, the size of which must be specified by means of the RECORDSIZE keyword of the OPEN statement (see Section 3.5.6). This value specifies the largest record that can be stored in the file. Each variable 1length record in a relative file contains three extra bytes, two for the count field and one for deleted record control. The count field of a variable length record is available when you read the record; issue a READ statement with a Q format descriptor. You can then use the count field information to determine how many bytes should be in an 1/0 list. 3.4.3 Segmented Records A segmented record is a single logical record consisting of one or more variable length records. Each variable length record constitutes a segment. The length of a segmented record is arbitrary. Segmented records are useful when you want to write exceptionally long records, and are especially appropriate to sequentially organized files. Unformatted sequential records written to sequentially organized files are, by default, stored as segmented records. Because there is no set limit on the size of a segmented record, each variable length record in the segmented record contains control information to indicate that it is one of the following: @ The first segment ® The last segment in the segmented record e The only segment in the segmented record ® None of the above in the segmented record FORTRAN INPUT/OUTPUT This control information is contained in the first two bytes of each segment of a segmented record. Thus, when you wish to access an unformatted sequential file that contains fixed 1length or variable length records, you must specify RECORDTYPE='FIXED' or 'VARIABLE' (as appropriate) when you open the file. Otherwise the first two bytes of record will be misinterpreted as control information, and errors each will probably result. 3.5 OPEN STATEMENT KEYWORDS The following sections supplement the OPEN statement description that 1In the VAX-11 FORTRAN IV-PLUS Language Reference Manual. in appears particular, of certain implementation-dependent and/or system-dependent aspects statement keywords are described as affected by the OPEN more For implementation. (RMS) Services VAX-11 Record Management to the VAX-11 Record Management Services Reference refer information Manual. 3.5.1 BLOCKSIZE Keyword The BLOCKSIZE keyword specifies the physical I/O transfer size for the It has the file. BLOCKSIZE form: = bks For magnetic tape files, the value of bks specifies the physical The default value is 2048 record size in the range 18 to 32767 bytes. ’ bytes. For sequential disk files, the value of bks 1is rounded up to an integral number of 512-byte blocks and used to specify RMS multiblock The 127. to 1 The number of blocks transferred can be transfers. is 2048 default value For relative files, bytes. the value of bks is rounded up to an integral of 512-byte blocks and used to specify the RMS bucket size, in number The default is the smallest value capable the range 1 to 32 blocks. of holding a single record. BUFFERCOUNT Keyword 3.5.2 The BUFFERCOUNT keyword specifies the number of memory buffers to use. It has the form: BUFFERCOUNT = bc The range of values for bc is from 1 to 255. The size of each buffer Thus, if BUFFERCOUNT=3 and is determined by the BLOCKSIZE keyword. Iis buffers for BLOCKSIZE=2048, the total number of bytes allocated 3%2048, or 6144. one buffer for 3.5.3 The default is two buffers for sequential files and relative files. INITIALSIZE and EXTENDSIZE Keywords The INITIALSIZE keyword specifies the initial storage allocation for a disk file, and the EXTENDSIZE keyword specifies the amount by which a disk file is extended each time more space is needed for the file. 3-10 FORTRAN INPUT/OUTPUT If INITIALSIZE is effective only at the time the file 1is created. 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 of the file. subsequent openings If The system attempts to allocate contiguous space for INITIALSIZE. not enough contiguous space is available, noncontiguous space is allocated. ORGANIZATION Keyword 3.5.4 It has the When an existing file is opened, the actual organization of the file The ORGANIZATION keyword specifies file organization. form: ORGANIZATION ={'RELATIVE' 'SEQUENTIAL' } The default file organization is sequential. is used. The relative file organization is applicable mainly when creating files to be used in non-FORTRAN applications, or when reading relative files created by programs written in languages other than FORTRAN. READONLY Keyword 3.5.5 The READONLY keyword specifies that write operations are not allowed The FORTRAN I/O system's default file on the file being opened. access privileges are read-write, which can cause run-time I/O errors The READONLY file protection does not permit write access. the if Its keyword has no effect on the protection specified for a file. to allow a file to be read simultaneously by two or is main purpose the purpose of Thus, if you wish to open a file for more programs. reading the file, but do not want to prevent others from being able to specify the READONLY it open, read the same file while you have keyword. RECORDSIZE Keyword 3.5.6 The RECORDSIZE keyword specifies how much data can be contained record. It has the form: RECORDSIZE = in a . rl The value specified for rl indicates the length of the logical records For files that contain fixed length records, rl in the file. for files that contain variable specifies the size of each record; length records, rl specifies the maximum length for any record. 3-11 FORTRAN INPUT/OUTPUT The value present), and of rl does not include the two segment control bytes (if or the bytes that RMS requires for maintaining record length deleted-record control information (two or four for sequential organization, The value of and rl one or is three interpreted for as relative organization). either bytes or longwords, depending on whether the records are formatted (bytes) or unformatted (longwords, that is, 4-byte units). Table 3-3 summarizes the maximum values that can be specified for rl, based on file organization and record format. Table 3-3 RECORDSIZE Limits File Organization | Record Formatted Unformatted (bytes) (longwords) 32766 8191 Sequential Sequential and variable length on ANSI 9999* records magnetic Limit 2499%* tape Relative * Format 16380 imposed by 4-byte ASCII count 4095 field. If you are opening an existing file containing fixed length that has relative organization, and you specify a value for that is different from the actual length of the records in an error file, the occurs, record default. If length you omit RECORDSIZE specified when the when opening file was The It an created You must specify RECORDSIZE when you create a file that fixed length records or that has relative organization. 3.5.7 records or RECORDSIZE the file, is existing is used to by contain RECORDTYPE Keyword RECORDTYPE keyword has the form: RECORDTYPE specifies the structure of records in a file. = { 'VARIABLE' 'SEGMENTED' This keyword is particularly useful default record structure used to structure is: FIXED - direct VARIABLE - formatted SEGMENTED - unformatted access, when you want to create a file. The sequential, sequential sequential 3-12 and relative override the default record FORTRAN INPUT/OUTPUT The default used when accessing an existing file 1is the record structure of the file, except for unformatted sequential files containing fixed or variable length records. 1In this case, you must explicitly override the default (SEGMENTED) by specifying the appropriate RECORDTYPE value in the OPEN statement. You cannot use an unformatted READ statement to access an unformatted sequentially organized file that contains fixed length or 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/O statements. 3.5.8 SHARED Keyword The SHARED keyword specifies that the file can be accessed by more than one program at a time, or by the same program on more than one logical unit. The forms of sharing permitted depend on the organization of the file. For sequential files, both read and write sharing are permitted. Because RMS does not prevent two or more programs from accessing the same file simultaneously, however, user programs that share write access to a file must provide interprocess communication and coordination to ensure reliable performance. Otherwise, problems may develop. For example, if two programs write to a shared file that contains records that cross block boundaries, records containing data written by two different programs can result. This can happen if the co-operating programs do not coordinate their read, modify, and rewrite sequerices, which are otherwise asynchronously and independently performed. Furthermore, RMS usually tries to minimize disk activity by postponing a rewrite in case a subsequent read or write can be performed using the program's buffer image. Thus, the file's disk image may be out of date for arbitrary time intervals. This problem can occur for both sequential and direct access I/0. You can encounter a similar problem involving the logical end-of-file on disk. When a file is extended, the logical end-of-file in the disk image is not updated until the file is closed. This means that 1if a file 1is open and program A is adding new records to it, and program B opens the same file before program A has closed the file, program B cannot read the new records even after program A finishes and closes the file. Program B can read the new records only by <closing and reopening the file. Only then will the file's disk image reflect the updated end-of-file. Relative files permit no write sharing. For shared reading to occur, all programs that open the file must specify the READONLY keyword. 3.5.9 USEROPEN Keyword The USEROPEN keyword provides access to supported by the FORTRAN I/O system. RMS features not directly. That is, this keyword allows access to RMS capabilities, while retaining the ease and convenience of FORTRAN programming. The USEROPEN keyword 1is intended for experienced users. For the interface specification for a USEROPEN routine, Common Run-Time Procedure Library Reference Manual. see the VAX-11 FORTRAN 3.6 AUXILIARY I/0 OPERATIONS This section describes INPUT/OUTPUT implications of the following I/0 statements: FIND BACKSPACE ENDFILE A FIND statement is similar to a direct access READ statement with I/0 1list, and can result 1in an existing file being opened. associated variable will be set to the specified record number. no An A BACKSPACE statement cannot be performed on a file that is opened for append access, because of the manner in which backspacing is done. A backspace operation requires that the current record count be available to the FORTRAN I/0 system, because 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. If the file is open for append access, the current record count is not available to the FORTRAN I/0O system. The ENDFILE statement writes an end-file record. The following convention has been adopted, since RMS does not support the embedded end-file concept: an end-file record is a l-byte record that contains the hexadecimal code 1A (CTRL/Z). An end-file record can be written only to sequentially organized files that are accessed as formatted sequential or unformatted segmented sequential. End-file records should not be written in files that will be read by programs written in a language other than FORTRAN, 3.7 LOCAL INTERPROCESS COMMUNICATION: MAILBOXES It is often useful to exchange data between processes; to synchronize execution, or to send messages. for example, A mailbox is a record-oriented pseudo I/0 device that allows data to be passed from one process to another. Mailboxes are created by the Create Mailbox system service. The following sections describe how to create mailboxes and how to send and receive data using mailboxes. 3.7.1 Creating a Mailbox Use the Create Mailbox system service ICHAN INTEGER*4 SYS$CREMBX MAILBX= SYS$CREMBX(,ICHAN, to create a mailbox, as follows: INTEGER*2 , , , ,'MAILBOX') The INTEGER*2 variable ICHAN is used to store the number mailbox, which is returned by the Create Mailbox and Assign system services. This argument is required by the Create systems service, so you must specify an INTEGER*2 variable ICHAN. However, all subsequent references to the mailbox logical of the Channel Mailbox such as are by name. For more information about calling system services, see Chapter 5. For more information about the arguments supplied to the Create Mailbox system service, see the VAX/VMS System Services Reference Manual. FORTRAN INPUT/OUTPUT 3.7.2 Sending and Receiving Data Using Mailboxes Sending or receiving data to or from a mailbox is no different from other forms of FORTRAN 1I/0. The mailbox 1is simply treated as a record-oriented I/0 device. Use FORTRAN formatted sequential I/0 statements to messages. Use receive data. WRITE send and receive statements to send data and READ statements to Data transmission by means of mailboxes is performed synchronously, so That is,-a program that communicating processes can be synchronized. 1is read, that writes a message to a mailbox waits until the message and a program that reads messages from a mailbox waits until a message an the mailbox, When the writing program closes is written. program. reading the to returned is condition end-of-file The sample program below reads messages from a mailbox known by the logical name MAILBOX. The messages comprise file names, which the program reads. The program then prints the file associated with the file names. CHARACTER FILNAM*64,TEXT*133 1 OPEN (UNIT = 1, NAME = 'MAILBOX', TYPE = READ (1,100,END=12)FILNAM 100 FORMAT (A) OPEN (UNIT = 2, NAME = FILNAM, TYPE = OPEN (UNIT = 3, NAME = 'SYSSOUTPUT') 3.8 'OLD') 2 READ (2,100, END = WRITE(3,100) TEXT GO TO 2 10 CLOSE (UNIT = 2) CLOSE (UNIT = 3) GO TO 1 12 END 10) 'OLD') TEXT COMMUNICATING WITH REMOTE COMPUTERS: NETWORKS If your system supports DECnet-VAX facilities, and your computer is one of the nodes in a DECnet-VAX network, you can communicate with 1/0 standard FORTRAN in the network by means of nodes other statements. These statements let you exchange data with a program at the remote computer (task-to-task communication), and to access files at the remote computer (resource sharing). Both task-to-task communication and transparent. intersystem exchanges. That 1is, exchanges, file access between systems are the first there is no apparent difference between these and 1local interprocess and file access To invoke network communication, specify a element of a file specification. node For example: name as BOSTON: :DBAQO: [SMITH] TEST.DAT.2 For remote task-to-task communication, you must use a special form of you must use TASK_ in place of the device name, specification: file and use the task name in place of the file name. For example: BOSTON: : TASK_ :UPDATE FORTRAN The following from a remote example program 100 shows how messages can be sent to and received by means of standard FORTRAN I/0 statements. OPEN (UNIT=7,NAME='BOSTON::TASK READ (7,100)IARRAY FORMAT CALL :UNA',ERR=200) - (2018) STATS (IARRAY) WRITE CLOSE 200 INPUT/OUTPUT (7,100)IARRAY (UNIT=7) END The effect of these (task) named UNA at statements is to the node BOSTON, establish and receive a 1link with data from the a job logical unit (7) associated with 20-element array, and a the remote program. The data is stored call is issued to the subroutine STATS, processes results link is the data. The are then sent back to BOSTON, in a which and the broken. The following example shows how a remote of standard FORTRAN I/0 statements. CHARACTER*64 OPEN (UNIT 1l 1 100 2 ACCESS = = NAME = 'DIRECT', = WRITE (2'IREC) GOTO 1 DATA = = can be updated by means DATA 2, READ(1,100,END FORMAT(I10, A) CLOSE (UNIT CLOSE (UNIT file 2) 'DENVER::MASTER.DAT', TYPE = IREC, 'OLD') DATA 1) 2) END This program reads local data describing new records into the remote file. transactions, and writes the If you use logical names in your program, you can equate the 1logical names with either 1local or remote files. Thus, if your program normally accesses a remote file, and the remote node becomes unavailable, you can bring the volume set containing the file to the local site. You can then mount the volume set, and assign the appropriate logical name. For example: Remote Access $ ASSIGN REM::APPLIC_SET:file—name LOGIC Local Access §$ MOUNT device-name APPLIC_SET $ ASSIGN APPLIC_SET:file-name The MOUNT and ASSIGN Command Language DECnet facilities Manual. commands are User's Guide. are described LOGIC described fully in in the detail in the DECnet-VAX VAX/VMS Reference CHAPTER 4 USING CHARACTER DATA The FORTRAN character data type allows you to easily manipulate alphanumeric data. You <can use character data in the form of character variables, arrays, constants, and expressions. A character operator (//) is available to form character strings by concatenating the character elements in a character expression. See Section 4.2. 4.1 CHARACTER SUBSTRINGS You can select certain segments (substrings) from a character variable or array element by specifying the variable name, followed by delimiter values indicating the leftmost and/or rightmost characters in the substring. For example, 1if the character string NAME contained: ROBERTAWILLIAMABOBAJACKSON and you wished to extract following: the substring BOB, you would specify the NAME (16:18) If you omit the first value, character of the substring For example, if you specify you are indicating that the first is the first character in the variable. NAME (:18) the resulting substring is ROBERTAWILLIAMABOB If you omit the second value, you are specifying the rightmost character to be the last character in the variable. For example: NAME (16:) encompasses BOBAJACKSON USING 4.2 CHARACTER DATA BUILDING CHARACTER STRINGS It is sometimes useful to create strings from two or more separate strings. This is done by means of the concatenation operator; the double slash (//). For example, you might wish to create a variable called NAME, consisting of the following strings: FIRSTNAME MIDDLENAME NICKNAME LASTNAME To do For so, define each as a character variable of a specified 1length. example: CHARACTER*42 NAME CHARACTER*12 FIRSTNAME ,MIDDLENAME , LASTNAME CHARACTER*6 NICKNAME Concatenation Thus, NAME = if the is strings FIRSTNAME are as follows: FIRSTNAME//MIDDLENAME//NICKNAME//LASTNAME = MIDDLENAME NICKNAME = LASTNAME = which accomplished contained the values: 'ROBERT' = 'WILLIAM' 'BOB' 'JACKSON' stored individually as ROBERTAAAAAA WILLIAMAAAAA BOBAAA JACKSONAAAAA then, when concatenated and stored in NAME, they become the string: ROBERTAAAAAAWILLIAMAAAAABOBAAAJACKSONAAAAA Applying nickname the substring extraction by specifying: facility, you can get the stored NAME (25:30) which picks blanks). up the 6-character NICKNAME Thus BOBAAA is retrieved as substring the (including substring. trailing USING CHARACTER DATA 4.3 CHARACTER CONSTANTS are Strings of alphanumeric characters enclosed 1in apostrophes character constants. You can assign a character value to a character variable in much the same way as you would assign a numeric value to a real or integer variable. XYZ = For example: 'ABC' are stored in As a result of this statement, the characters ABC three bytes, the than less is length XYZ's if that location XYZ. Note Thus 1if you character string will be truncated on the right. specified CHARACTER*2 XYZ XYZ = 'ABC' longer than The result is AB. If, on the other hand, the variable is example: For blanks. with right the on padded is it , the constant CHARACTER*6 XYZ XYZ = results ‘'ABC' in ABCAAA being stored in XYZ. If the previous contents of XYZ were CBSNBC, the result would still be ABCAAA: the previous contents are overwritten. You can give character constants symbolic names by using the PARAMETER statement. For example: PARAMETER TITLE = 'THE METAMORPHOSIS' The symbolic name TITLE can then be used anywhere a character constant is allowed. Note that an apostrophe can be included as part of the constant. do so, specify two consecutive apostrophes. For example: PARAMETER TITLE = To 'FINNEGAN''S WAKE' results in the character constant FINNEGAN'S WAKE. 4.4 DECLARING CHARACTER DATA To declare variables or arrays as character type, use the CHARACTER type declaration statement, as shown in the following example: CHARACTER*10 TEAM(12) ,PLAYER This statement defines a l2-element character array (TEAM), each, element of which is 10 bytes long; and a character variable (PLAYER) which is also 10 bytes long. USING You can specify statement by different including lengths a 1length example: CHARACTER*6 CHARACTER DATA for value variables for a CHARACTER variables. For NAME ,AGE*2,DEPT In this example, NAME and DEPT are defined to while AGE is defined to be a 2-byte variable. 4.5 in specific be 6-byte variables, character variable. INITIALIZING CHARACTER VARIABLES Use the For example: DATA statement CHARACTER*10 DATA to preset the value of a NAME,TEAM(5) NAME/' '/,TEAM/'SMITH','JONES', 'DOE','BROWN','GREEN'/ Note that NAME will contain 10 blanks, while TEAM will contain the corresponding character blanks. To initialize an array so that value, use a DATA statement of each array element 1in value, right-padded with each of its elements the following type: contains the same CHARACTER*5 TEAM(10) DATA TEAM/10*'WHITE'/ The 4.6 result is a l0-element array in which each element contains WHITE. PASSED LENGTH CHARACTER ARGUMENTS Subprograms that manipulate character data character actual arguments of any length the dummy argument as passed length. dummy argument, use an asterisk (*) as SUBROUTINE can be written to accept by specifying the length of To indicate a passed length follows: REVERSE (S) CHARACTER* (*) S The passed length notation indicates that the length of the actual argument is used when processing the dummy argument string. This length can change from one invocation of the subprogram to the next. For example: CHARACTER In A*20,B*53 CALL REVERSE (A) CALL REVERSE (B) the first call second call, its The FORTRAN the string to REVERSE, length will the be function LEN can be (see Section 4.8.4). length of § will 53. used to determine the be 20; actual in the length of USING CHARACTER DATA 4.7 CHARACTER DATA EXAMPLES example The shown below. 1is usage data An example of character of the 1letters the that manipulates a program 1is 4-1) (Figure The results are shown in Figure 4-2. alphabet. OO USING CHARACTER DATA CHAREXMPL ,FOR CHARACTER DATA TYPE EXAMPLE PROGRAM FOR VAX FORTRAN IVepPLUS CHARACTER C, DATA 99 100 ALPHABET/’ABCDEFGMIJKLMNOPQRSTUVWXYZ®/ WRITE(T7,99) FORMAT(’1 CHARACTER 00 10 ALPMNABET»26 100 EXAMPLE PROGRAM OUTPUT?/) Isi,26 WRITE(7,10) ALPHABET FORMAT(IX, A) ALPMABET ALPMABET(2:1) = /7 ALPHABET(!1Y) CONTINUE CALL REVERSE(ALPHABET) WRITE(?,10) ALPMARET CALL REVERSE(ALPHABET(1:113)) WRITE(Y,10) ALPHABET CALL FIND, SUBSTRINGS(®UVWN’, ALPHABET) CALL FINDSUBSTRINGS(°A’, °DAJHDMAJDANDJA4E CEUEBCUEIAWSAWQLG®) 98 WRITE(7,98) FORMAT(®@ END OF CHARACTER EXAMPLE PROGRAM OUTPUT’) 81w END SUBROUTINE REVERSE(S) CHARACTER T, Sa(w) J = LEN(S) IF ¢J ,GT, §) THEN DO 10 I=y, J/2 T = S$(Is) SCl11) = 8¢JtJ) $(JtJ) o T J n Jey CONT INUE ENDIF RETURN END SUBROUTINE FIND, SUBSTRINGS(SUB, CHARACTERw(w») 8) 8UB,S CHARACTERw# {32 MARKS 1= s MARKS K 10 = ¢ * J = INDEX(S(I1), 8UB) IF (J (NE, 0) THEN I 81 ¢ (Je}) MARKS(ItI) K = 1 8 IF ey (1 ENDIF ,LE, WRITE(T7,100) 100 FORMATC 4-1 *»° LEN(S)) S, 2(/71X, END Figure = GO TO 0 MARKS(1K) A) ) Character Data Program Example USING CHARACTER DATA CHARACTER EXAMPLF PROGRAM QUTPUT ABCDEFGHIJKILMNOPQRSTUVWXYZ BCDEFGHIJKLMNOPORSTUYWXYZA COEFGHIJKLMNOPQRSTUVWXYZAB DEFGHIJKLMNOPGRSTUVWXYZABC EFGHIJKLMNOPQRSTUVWXYZABCD FGHIJKLMNOPQRSTUVWXYZABCDE GHIJKLMNOPQRSTUVWXYZABCDEF HIJKLMNOPGRSTUVWXYZABCDEFG IJKLMNOPGRSTUVWXYZABCDEFGH JKLMNOPQRSTUVWXYZABCDEFGH] KLMNOPQRSTUVWXYZABCUEFGHIJ LMNOPQRS TUVWXYZABCDRFGHIJK MNOPQRSTUVWXYZABCDEFGHIJIKL NOPQRSTUVWXYZABCDEFGHIJKLM OPQRSTUVWXYZABCDEFGHIJKLMN PGRSTUVWXYZABCDEFGHIJKLMNO QRSTUVWXYZABCDEFGHIJKLMNOP RSTUVWXYZABCNDEFGHTIJXLMNOPQ STUVWXYZABCDEFGHIJKLMNOPQR TUVWXYZABCDEFGHIJKLTMNOPGRS UVWXYZABCDEFGHIJKLMNOPQRST VWXYZABCDEFGHIJKLMNOPQRSTU WXYZABCDEFGHIJKLMNOPQRSTUV XYZABCDEFGHIJKLMNOPGRSTUVW YZABCDEFGHIJKLMNOPQRSTUVHX ZABCDEFGMIJKLMNOPQRSTUVWXY ZYXWVUTSRGPONMLKJIHGFEDCBA NOPQRSTUVWXYZMLKJIHGFEDCBA NOPQRSTUVWXYZMLKJIHGFENCBA # DAJHOMAJDAHDJAUE CEUEBCUEIAWSAWOLG £ * “ " ¥ END OF CHARACTER EXAMPLE PROGRAM QUTPUT Figure 4.8 4-2 Output Generated by Example Program CHARACTER LIBRARY FUNCTIONS The VAX-11 FORTRAN IV-PLUS system provides four character functions: CHAR ICHAR INDEX LEN 4.8.1 CHAR Function The CHAR function returns a l-byte character value equivalent integer ASCII value passed as its argument. It has the CHAR(1) An integer expression equivalent to an ASCII code. form: to the USING CHARACTER DATA 4.8.2 The ICHAR Function ICHAR character function returns expression passed an integer as its ASCII code argument. equivalent It has the to the form: ICHAR(c) A character expression. code equivalent to the bytes are ignored. 4.8.3 If c first is longer than one byte, the ASCII byte is returned, and the remaining INDEX Function The INDEX function substring: it has is used to determine the form: the starting position of a INDEX (cl,c2) cl A character expression that specifies the string searched for a match with the value of c2. that is to be which a c2 A character expression match is desired. If INDEX an finds integer an instance representing the substring of the value corresponding specified to the substring starting (c2), location (cl). For example, if the substring sought is CAT, and that is searched contains DOGCATFISH, the return value of If INDEX cannot find the specified substring, 4.8.4 LEN in it the the INDEX returns string string is 4. it returns the value 0. Function The a for : LEN function returns character expression. an It integer has the value form: that indicates the length of LEN (¢) A 4.9 character expression CHARACTER 1/0 The character data type simplifies the transmission data. You can read and write character strings of to 32767 characters. For example: 100 CHARACTER*24 TITLE READ (12,100) TITLE FORMAT (A) of any alphanumeric length from 1 USING CHARACTER DATA These statements cause 24 characters read from logical unit 12 to be stored in the 24-byte character variable TITLE. Compare this with the code necessary if you used Hollerith data stored in numeric variables or arrays: INTEGER*4 100 TITLE (6) READ(12,100) FORMAT (6A4) TITLE Note that you must divide the data into lengths suitable for real or (in this case) integer data, and specify I/0 and FORMAT statements to match. In this example, a l-dimensional array comprising six 4-byte elements is filled with 24 characters from logical unit 12. CHAPTER 5 FORTRAN CALL CONVENTIONS VAX-11 FORTRAN IV-PLUS provides a mechanism you can use to gain access to services external to your FORTRAN programs. By including CALL statements or function references in your source program, you can procedures such as use mathematical functions, VAX/VMS system services, and procedures written in languages other than FORTRAN. Refer to the VAX-11l Common Run-Time Procedure Library Reference Manual for descriptions of the procedures included in the Run-Time Library, and information on how they are called. 5.1 PROCEDURE CALLS A procedure is a program, such as a FORTRAN function or subroutine, that performs one or more computations for other programs. In many cases, procedures perform calculations that are used widely t and It is more efficien to repeatedly in many FORTRAN applications. write these procedures (subprograms) once, and make them available to other programs, than to reinvent them every time the need arises. Subprograms can be either functions or subroutines. A function is a subprogram that returns a value to the calling program, by assigning the value to the function's name. A subroutine may return values, but a value is not associated with the subroutine name. Functions and subroutines can return values by storing values in elements of the argument 1list, or in COMMON blocks. See the VAX-11l FORTRAN IV-PLUS Language Reference Manual for information on defining and 1invoking subprograms. 5.2 VAX-11l PROCEDURE CALLING STANDARD Programs compiled by the VAX-11l FORTRAN IV-PLUS compiler conform to the standard defined for VAX-11l procedure calls (see Appendix C of the VAX-11 Architecture Handbook, Vol. 1l). This standard prescribes how arguments are passed, how function values are returned, and how VAX-11 procedures (such as subprograms) receive and return control. IV-PLUS also provides features that allow FORTRAN programs to call system services and procedures written in other native-mode FORTRAN languages supported in VAX/VMS. The information in this section pertains to calling system service If you want to write routines that can be routines from FORTRAN. n to called from FORTRAN programs, you should pay particular attentioformat the argument list descriptions and to the machine code description in Section 5.4. FORTRAN 5.2.1 sequence entry procedure of argument calling longword count. The argument the 1list. It in Memory for FORTRAN usually allocated argument lists are compile time, when argument list. = DIZ(Y) Z = DIZ(Y) A =X+ 2 * + list Section 5.4.1 argument lists. as a of which is an byte in the first how many arguments follow first in the example: (for example that for has a examples Argument Passing are passed use CALL X(A,,B)) value of of the same argument are list. represented by 0. machine code generated Call-by-value 2. Call-by-reference the value 3. Call-by-descriptor of a descriptor of - standard defines three mechanisms is the value entry is to procedures: 1. By default, VAX-11 call-by-descriptor will for an FORTRAN Mechanisms The VAX-11 procédure calling arguments the 1list first lists and VAX-1ll standard descriptors is statically. To optimize space and time, the pooled and argument list entries are initialized at possible. Sometimes several calls can use the same references entry See 5.2.2 is argument DIZ(Z) arguments argument count indicates an the DIZ(Y) these DIZ(Y) Omitted defines entries, argument For X of standard (4-byte) list. which CONVENTIONS Argument Lists The VAX-1l1l All CALL the argument - the list argument - the argument the value entry list list entry the is address the by of address FORTRAN IV-PLUS uses the call-by-reference and mechanisms. The call-by-reference mechanism is used to pass all numeric actual arguments: logical, integer, real, double precision, and complex. The call-by-descriptor mechanism is used to pass all character actual arguments. 5.2.3 By Argument List Built-In Functions default, FORTRAN mechani for sm type. 1In some uses passing cases, the call-by-reference arguments, however, depending a function may require or call-by~descriptor on-the reference argument's or call data to a arguments in non—-FORTRAN IV-PLUS a different Therefore, form. Calls to VAX/VMS system services are such a case. FORTRAN provides three built-in functions for passing arguments built-in when you procedure cannot functions are: 3VAL $REF ¥DESCR use the FORTRAN that you default supply mechanism. These FORTRAN CALL CONVENTIONS These functions can appear only in actual argument lists. The following sections describe the use of these functions. the argument 1list built-in functions are never used procedure written in FORTRAN. 5.2.3.1 S8VAL - This function forces the argument list the call-by-value mechanism. It has the form: Note that to call a entry to use $VAL (arg) The argument list entry (arg) is the wvalue of the entry. Because argument 1list entries are longwords, the argument value must be an integer, logical, or real constant, variable, array element, or expression. 5.2.3.2 $REF - This function forces the argument list the call-by-reference mechanism. It has the form: entry to use $REF (arg) The argument list entry (arg) 1is the address of the value. The argument value can be a numeric or character expression, array, array element, or procedure name. This is the default FORTRAN method for passing all numeric values. 5.2.3.3 $DESCR - This function forces the argument list entry to the call-by-descriptor mechanism. It has the form: use $DESCR (arg) The argument list entry (arg) is the address of a descriptor of the value. The argument value can be any type of FORTRAN expression. The compiler can generate VAX-11l descriptors for all FORTRAN data types. Call-by-descriptor 1is the default FORTRAN mechanism for passing character arguments, because the subprogram may need to know the length of the generates addresses code character to refer argument. to in their descriptors. In character particular, FORTRAN 5.2.3.4 Examples of $%VAL, $REF, $DESCR - The following illustrate the use of the argument list built-in functions. CALL always dummy arguments through the examples SUB(2,%VAL(2)) The first constant is passed by reference. passed by value. CHARACTER*10 A,B CALL SUB(A,%REF(B)) The second constant 1is FORTRAN CALL CONVENTIONS The first character variable is character variable is passed by passed by reference. descriptor. The second is passed second INTEGER IARY (20), JARY (20) SUB(IARY,%DESCR(JARY)) CALL The first array descriptor. See Section code. 5.2.4 5.4.2 for by reference. examples that The include the array generated by machine Function Return Values The method type is passed of of the returning value, as function procedure summarized in Table values 5-1. depends on the data Table 5-1 Function Return Values Data Type Return Logical General Method register RO Integer Real Double Precision RO: Rl: High-order result Low-order result Complex RO: Rl: Real part Imaginary part Character An of extra the argument entry is argument entry descriptor. allocated to and the the descriptor. $LOC points to At run contain result, 5.2.5 added as the first 1list. This new proper a character entry first string time, storage the wvalue of address is stored is the in Built-In Function The SLOC built-in function computes the address of a storage element, as an INTEGER*4 value. This value can be used in an arithmetic expression. This has particular applicability for certain system services or non-FORTRAN procedures that may require arguments that contain the addresses of storage elements. 5.3 CALLING VAX/VMS The VAX/VMS you can describe and to form. operating call from SYSTEM SERVICES system provides FORTRAN a number programs. The the methods you can use to ensure that you pass and of service following procedures subsections call system service procedures, receive information in the correct FORTRAN CALL CONVENTIONS You can invoke system services from a FORTRAN program by including a function reference or a subroutine CALL statement in your program, To specify a system specifying the system service you want to use. service, use the form: SYSS$service~-name (a,...,a) the to according You pass arguments to the system services a value, an requirements of the particular service you are calling: address, or the address of a descriptor may be needed, as described in See the VAX/VMS System Services Reference Section 5.3.3, below. Manual for a full definition of all services. Calling System Services by Function Reference 5.3.1 In most cases, you should check the return status after calling a Therefore, you should call system services by system service. function reference rather than by issuing a subroutine CALL. NOTE be must functions service System declared as INTEGER*4 functions. For example: INTEGER*4 INTEGER*2 SYSS$CREMBX ICHAN MBX = SYS$SCREMBX(,ICHAN,,,,, 'MAILBOX') IF (.NOT. MBX) GO TO 100 In this example, the system service referred to is the Create Mailbox then an the system service name 1is declared, First, service. INTEGER*2 variable (ICHAN) is declared, to receive the channel number. be The function reference allows a return status value to stored or .FALSE. the variable MBX, which can then be checked for .TRUE. in on return. If the function's return status is .FALSE., indicating failure, control transfers to statement 100, at which point some form of error processing can be undertaken. particular return status, You can check for by the system. the return status to one of the status codes defined For example: / (MBX .EQ. IF a also such as an access violation, by comparing SS$_ACCVIO) THEN Refer to the VAX/VMS System Services Reference Manual for information concerning return status codes. The return status codes are included in the description of each system service. 5.3.2 Calling System Services as Subroutines Subroutine calls to system services are made in the same way that calls are made to any other subroutine. For example, to call the Create Mailbox system service, issue a CALL to SYSSCREMBX, passing to it the appropriate arguments, as: CALL SYS$CREMBX (,ICHAN,,,,, 'MAILBOX') FORTRAN This CALL corresponds to difference 1is that the not tested. system For services. 5.3.3 Passing Arguments Generally, value, and must use this system output the %VAL CALL CONVENTIONS the function reference shown above. The main status code returned by the system service is reason, to you should avoid this method of calling System Services services require input arguments to be passed arguments to by reference. built-in passing function when be passed Therefore, by you arguments to input certain system services, to make sure they are passed the data. Some system services require character arguments (see 5.3.3.3). To determine the argument requirements for a service, see the VAX/VMS System Services Reference Manual. 5.3.3.1 tell Input the and Output Address Arguments - You will often system service where to find input values and where output values. Thus, you must determine the hardware argument: byte, word, longword, or quadword. data correct Section system need to type to store of the For can input arguments that refer to byte, word, or longword values, you specify either constants or variables. If you specify a variable, you must declare it to be equal to or 1longer than the data type required. Table 5-2 lists the variable data type requirements. For output required, system arguments to returns you must declare avoid including a value byte in a variable extraneous data. a word-length of exactly 1If, for variable, the length example, the eight bits of the variable will not be overwritten on output; the variable will not contain the data you expect. VAX/VMS Input Argument Required Output Argument Declaration Byte BYTE, Word INTEGER*2, Longword INTEGER*4 Quadword Properly thus, Table 5-2 Data Type Requirements Variable Type the leftmost INTEGER*2, Declaration INTEGER*4 BYTE INTEGER*4 INTEGER*2 INTEGER*4 dimensioned array Properly dimensioned array Indicator For LOGICAL arguments routine," example, want to in the the as "address of argument value an as entry mask" the of a "address of a procedure. For routine you and PROGA declarations portion of of or an external if a system service requires the address specify the routine PROGA, specify EXTERNAL address described declare routine for use the as an 5-6 FORTRAN input program argument. to define the FORTRAN To store output produced by CALL CONVENTIONS system services, vyou must allocate sufficient space to contain the output. You do this by declaring variables of the proper size. For example, the Create Mailbox system service produces a two-byte value. Thus, you set up space as follows: INTEGER*2 INTEGER*4 MBX = ICHAN SYS$SCREMBX SYSSCREMBX(,ICHAN,,,,,'MAILBOX') If the output is a quadword value, you must declare an array of the proper dimensions. For'' example, the Get Time system service (SYSSGETTIM) returns the time as a quadword binary value. Thus, you would need to specify the following: INTEGER*4 INTEGER*4 ISTAT = SYSTIM(2) SYSSGETTIM SYSSGETTIM(SYSTIM) ! DECLARE ARRAY ! GET TIME The type declaration INTEGER*4 SYSTIM(2) sets up a vector of two longwords, into which the time value will be stored. consisting 5.3.3.2 Defaults for Optional Arguments - All optional arguments have default values. You must use commas in place of omitted arguments. For example, the Translate Logical Name (SYSSTRNLOG) system service takes five arguments. If you omit the last two arguments you must include two commas in their place, as follows: ISTAT = An invalid reference would ISTAT = This SYSSTRNLOG('LOGNAM',LENGTH,BUFFA,,) result if you specified: SYSSTRNLOG ('LOGNAM',LENGTH,BUFFA) reference provides only three arguments, not the requisite five. 5.3.3.3 Passing Character Arguments - Some VAX/VMS system services (for example, the Translate Logical Name system service) require character arguments for either input or output. The Translate Logical Name system service (SYSSTRNLOG) accepts a logical name as input, and returns the associated logical name or file specification, if any, as output. VAX/VMS system services that process character data require that arguments be passed by descriptor. FORTRAN passes all character data by descriptor. On input, a character constant, variable, array element, or expression is passed to the system service by descriptor. On output, two arguments are needed: the character variable or array element to hold the output string, and an INTEGER*2 variable, which is set to the actual length of the output string. For example: CHARACTER*64 BUFFA INTEGER*2 LENGTH INTEGER*4 ISTAT = SYSSTRNLOG SYSSTRNLOG ('LOGNAM',LENGTH,BUFFA,,) 5-7 FORTRAN CALL CONVENTIONS The logical name LOGNAM is translated to its associated name -:or file specification, and the output values, length and associated name or file specification, are stored in the locations you specified -- LENGTH and BUFFA, respectively. 5.4 MACHINE CODE EXAMPLES The following sections present examples corresponding machine code. 5.4.1 of FORTRAN calls and their Argument Passing Examples The format used in the following examples shows FORTRAN followed by generated object code argument lists. Example 1: FORTRAN Source REAL source lines, Code X INTEGER J(10) CHARACTER*15 C CALL SUB (X,J(3),C) Object Code ARGLST: L$l: .LONG 3 ; COUNT .ADDR X ; ADDRESS .ADDR J+8 ; ADDRESS OF J(3) +.ADDR LS$1 ; C DESCRIPTOR ADDRESS .WORD 15 .BYTE 14 ; ; ; ; LENGTH OF C CHARACTER TYPE CODE .BYTE 1 .ADDR C This example shows how the OF X SCALAR CLASS ADDRESS OF C compiler generates CODE an argument list for the arguments specified in the CALL statement. The compiler can initialize the addresses of real variable X and array element J(3) because these are -explicitly specified in the CALL statement. Similarly, the compiler has enough information to generate an initialized descriptor for the character string C. FORTRAN CALL CONVENTIONS Example 2: FORTRAN Source Code REAL X (10) CHARACTER*15 C CALL SUB (X(I), C(J:K)) Object Code LS$1: W .LONG 2 0 .ADDR LS1 %6 . LONG -s ARGLST: COUNT X(I) INITIALIZED AT RUN TIME C(J:K) DESCRIPTOR ADDRESS .WORD O ; C(J:K) .LONG 0 ; ; ; .BYTE 14 .BYTE 1 LENGTH, SET AT RUN TIME CHARACTER TYPE CODE SCALAR CLASS CODE BASE ADDRESS OF C(J:K), SET AT RUN TIME Run~time argument list initialization code MOVL MOVAF SUBL3 I,RO X-4[R0O] ,ARGLST+4 #1,J,R0O ; COMPUTE ADDRESS OF X (I) AND ; STORE IT IN THE ARGUMENT LIST ; COMPUTE THE LENGTH OF C (J:K) MOVW R1,LS1 ; STORE LENGTH OF C(J:K) MOVAB C[RO] ,LS1+4 CALLG ARGLST,SUB SUBL3 RO,K,R1 H : LIST ;s ARGUMENT LIST IN ARGUMENT : STORE BASE ADDRESS OF C(J:K) : IN CALL SUBROUTINE SUB In this example, the FORTRAN source lines real a define array X, and a character variable C, comprising 15 comprising 10 elements; elements. The actual arguments passed to subroutine SUB are the I-th element of array X, and the substring of C from the J-th to the K-th character. The compiler generates an argument list consisting of three longwords; the first 1is the and count, the next two are (respectively) the address of the I-th element of X and the address of the descriptor of substring C(J:K). Note that the address of X(I) and C(J:K), and the length of C(J:K) are compile time these values are unknown. 5.4.2 initialized 0, to because at Argument List Built-In Function Examples In the following examples, the FORTRAN source followed by the generated object code. code 1is shown first, FORTRAN Example 1: FORTRAN Source CALL CALL CONVENTIONS $VAL SUB Code (4, %VAL(6)) Object Code ARGLST: CON4 : As shown, first the entry, .LONG 2 .ADDR CON4 ; ; ADDRESS .LONG 6 ; VALUE .LONG 4 ; compiler but generates generates an the entry. Example 2: FORTRAN Source COUNT OF address actual CONSTANT for the value constant (6) in the 4 in the following $REF Code CHARACTER*10 C,D CALL $REF (D)) SUB (C, Object Code ARGLST: .LONG L$l: 2 .ADDR LS$1 ’ COUNT ; ADDRESS OF C .ADDR D ; ADDRESS OF D .WORD 10 ; LENGTH .BYTE 14 TYPE CODE CLASS CODE ADDRESS .BYTE 1 ; ; .ADDR C ; DESCRIPTOR As shown, the argument list entry for D is the address of D. The compiler does not generate a descriptor for D, as it does for C, even though C and D are both specified in the source program as character variables. Example 3: FORTRAN Source CALL $DESCR SUB Code (X, %DESCR(X)) Object Code ARGLST: .LONG 2 .ADDR X .ADDR LS$1 L$l: .WORD 4 .BYTE 10 COUNT ; ADDRESS ; ADDRESS OF X DESCRIPTOR ; LENGTH TYPE CODE CLASS CODE ADDRESS .BYTE 1 ; ; .ADDR X ;+ In this example, while the second OF X the first argument list entry contains an entry contains a pointer to a descriptor. 5-10 address," FORTRAN CALL CONVENTIONS 5.4.3 Character Functions The following example lists illustrates are generated. FORTRAN Source how character function argument Code CHARACTER*10 = C(1,J) C,D D Object Code ARGLST: LS$1: .LONG 3 .ADDR LS1 7 ; COUNT ADDRESS OF FUNCTION DESCRIPTOR .ADDR I .ADDR J ;s ; ADDRESS OF 1 ADDRESS OF J .WORD 10 : LENGTH .BYTE 14 : TYPE .BYTE 1 : CLASS .LONG 0 ; ADDRESS ALLOCATE SPACE FOR 10 CHARACTERS CODE CODE SUBL2 $#10,SP ; MOVL SP,LS1+4 s SET ADDRESS CALLG ARGLST,C ;: CALL FUNCTION MOVC3 #10, (Sp) ,D : MOVE RESULT TO D MOVL R1l,SP ; REMOVE RESULT FROM STACK C In this example, an additional argument list entry is allocated; descriptor of the return value of the character function C. the CHAPTER 6 ERROR PROCESSING AND CONDITION HANDLERS During program execution, your program may occasionally encounter errors or exception conditions. These conditions may result from errors that occur during I/0 operations, invalid input data, argument errors 1in «calls to the mathematical library, arithmetic errors, or system-detected errors. VAX-11l FORTRAN IV-PLUS provides three methods of controlling and recovering from errors: 1. Run-Time Library default 2. ERR= 3. VAX-11 Condition Handling condition handlers) and END= error-processing procedures specifications in I/0 Facility statements (including user-written These error-processing methods are complementary, and can be used together in the same program. Thus, you have a number of options to choose from in dealing with errors. You can, of course, allow the Run-Time Library to handle errors for you. This is the default case. Or, you can use ERR= and/or END= specifications in I/0O statements to provide special processing if an error or end-of-file occurs while the I/0 statement is being executed. Or, you can provide condition handlers to tailor error processing to the special requirements of your applications. Note: This option should be undertaken only by more experienced users, in particular those familiar with the VAX-1l1 Condition Handling Facility. The Run-Time Library provides default processing for all exception conditions that occur during FORTRAN program execution. It generates appropriate messages, and takes action to recover from errors where possible. Section 6.1 describes FORTRAN-specific Run-Time Library error processing. Appendix B describes FORTRAN-specific Run-Time Library error messages. The VAX-11l Condition Handling Facility provides all error processing in the Run-Time Library. You <can also use it directly to provide procedures (user-written condition handlers) for processing exception conditions that occur during your program's execution. For example, you can include that 1is more code to respond appropriate to to certain kinds of errors a particular application 1in a than way the processing performed by the Run-Time Library. The use of condition handlers requires considerable experience: it is not appropriate for novice users. You should be familiar with the condition handling description in the VAX-11l Common Run-Time Procedure Library Reference Manual, and in the VAX-11/780 Architecture Handbook before you attempt to write a condition handler. ERROR PROCESSING AND 6.1 RUN-TIME LIBRARY DEFAULT The Run-Time Library contains CONDITION HANDLERS ERROR PROCESSING condition handlers that process a number of errors that may occur during FORTRAN program execution. A default action is defined for each FORTRAN-specific exception condition that the Run-Time Library recognizes; Table 6-1 These default actions occur wunless overridden condition handler (see Section 6.2). 1lists these actions. by a user-written Some errors result in recovery action. For example, you can use the ERR= specification to code an error statement label in an I/0 statement. In some cases, the error may be ignored and execution will continue. Or, recovery may be initiated based on the nature of the error. You can use the ERRSNS system subroutine to determine which error occurred. ERRSNS returns a FORTRAN-specific system status codes for the last error that occurred; The ERRSNS routine is described in Appendix C. 6.1.1 error number and see Table 6-1. Using ERR= and END= Transfers By including an ERR=label or END=label specification in an 1I/0 statement, you can transfer control to error processing code in your program. If you use an END= or ERR= transfer to process an I/0 error, no error message is printed and execution continues at the designated statement. However, if a severe error occurs while an I/0O statement is being processed, and you did not specify an ERR= transfer, the default action is to print an error message and terminate execution. If you specify ERR=label in an during I/0 statement execution, control to the statement at the I/0 statement and an error the Run-Time Library transfers label specified. For example: occurs program WRITE (8,50 ,ERR=400) If an error occurs during the the statement at label 400. You can also statement. write specify ERR=label For as operation, a keyword control in an transfers OPEN or to CLOSE example: OPEN (UNIT=INFILE,TYPE='OLD',ERR=100,NAME=FILN) If errors transfers are detected during to statement 100. The END=label condition, as specification follows: can OPEN be statement used to execution, handle an control end-of-file READ (12,70 ,END=550) If an end-of-file executed, control is detected transfers If an end-of-file executed, and you to while this statement 550. I/O statement 1is being ) 1is detected while a READ statement 1is being did not specify END=label, an error condition specified ERR=label, control is transferred to the occurs. If you specified statement. ERROR PROCESSING AND 6.1.2 Run-Time Library Error CONDITION HANDLERS Processing Control The Run-Time Library's error processing depends on three factors: severity of the error; whether the error permits continuation; whether Table an 6-1 A of transfer lists Library. symbolic code ERR= the was provided FORTRAN-specific in the errors case of an processed I/O by the and error. the Run-Time For each error, the table shows the error message text, the condition name, the FORTRAN-specific error code, the severity the error, severity code generated and is when the type included an error of as recovery part condition action. of is the error detected. All code that is FORTRAN-specific errors have severity codes of either error (E) or severe error (F). As shown in Table 6-1, most FORTRAN-specific errors are severe. If no recovery action is specified for a severe error, program execution terminates by default. Two types include and the of recovery ERR= error message, and ERR= transfer, receive ERR= one possible: ERR= However, if the message the was severe RETURN. specified will not error messages, specified. You can resulting program termination, error in your source program. by A that recovery and you Most no I/0O ERR= type of RET means be the including an implication the an ERR= recovery and error specify an Thus, if you displayed. circumvent errors transfer, severity was F, your program terminates with an exit status of severe error. If you did of transfer are recovery. is that no error, and the transfer for this continuation are possible only if you establish a condition handler for that User-written condition handlers are described in Section 6.3. error. The letter C in the "Sev" column means that you can continue execution immediately after the error if a user-written condition handler has changed the severity code to error (E) or warning (W). If there is no letter C in immediately after execution will be When errors occur exits; that message 1is is, the <column, for which no execution of printed. condition handler "Sev" the error. terminated. To If recovery cannot attempt type the program prevent that performs you you an is is program unwind (see continue to do specified, terminated, execution so, the and termination, Section 6.3). program program an error include a ERROR PROCESSING AND CONDITION HANDLERS Table 6-1 Summary of FORTRAN Run-Time Errors FORTRAN Condition Symbol Err # |Sev Rec. Type Message Text FOR$_NOTFORSPE | 1 | F FOR$_REWERR 20| F FORS DUPFILSPE | 21| F ERR= NOT A FORTRAN-SPECIFIC ERROR | REWIND ERROR FOR$_FILNOTFOU | 29| ERR= ERR= ERR= ERR= ERR= ERR= ERR= | INPUT RECORD TOO LONG | BACKSPACE ERROR | END-OF-FILE DURING READ | RECORD NUMBER OUTSIDE RANGE | OPEN OR DEFINEFILE REQUIRED... | MORE THAN ONE RECORD IN I/0O STATEMENT | CLOSE ERROR ERR= | FILE NOT FOUND FORS$ INPRECTOO | 22| FORS BACERR 23| FOR$S ENDDURREA | 24| FOR$ RECNUMOUT | 25| FOR$ OPEDEFREQ | 26| FORS MORONEREC | 27| 28| FORS CLOERR FOR$_OPEFAI FOR$_MIXFILACC FORS_INVLOGUNI FOR$_ENDFILERR FOR$_UNIALROPE FOR$_SEGRECFOR FOR$_ATTREANON FOR$_INCRECLEN FOR$_ERRDURWRI FOR$_ERRDURREA | | | | | | | | | FOR$_RECIO OPE | FOR$_INSVIRMEM | FOR$_NO_SUCDEV | FORS FILNAMSPE | FOR$_RECSPEERR | FOR$_KEYVALERR | FOR$__INCOPECLO | FOR$_WRIREAFIL | FORS_INVARGFOR | FORS LISIO SYN | FOR$_INFFORLOO | FOR$_FORVARMIS | FOR$_SYNERRFOR | F F F F F F F F 30| F 31| F 32| F 33| F 34| F 35| F 36 | F 37| F 38 | F 39| F 40| F 41| F 42| F 43| F 44| F 45| F 46| F 47| F 48| F 59|F,C | 60| F 61 |F,C | 62| F FORS_OUTCONERR | 63 FORS_INPCONERR | 64 [E,C | |F,C | FORS OUTSTAOVE | 66| F F FORSINPSTAREQ | 67| FOR$_VFEVALERR | 68 |F,C | ERR= | DUPLICATE FILE SPECIFICATIONS ERR= | OPEN FAILURE ERR= | MIXED FILE ACCESS MODES ERR= | INVALID LOGICAL UNIT NUMBER ERR= | ENDFILE ERROR ERR= | UNIT ALREADY OPEN ERR= | SEGMENTED RECORD FORMAT ERROR ERR= | ATTEMPT TO READ NON-EXISTENT RECORD ERR= | INCONSISTENT RECORD LENGTH ERR= | ERROR DURING WRITE ERR= | ERROR DURING READ ERR= ERR= ERR= ERR= ERR= ERR= ERR= ERR= ERR= ERR= ERR= ERR= ERR= | RECURSIVE I/0 OPERATION | INSUFFICIENT VIRTUAL MEMORY | NO SUCH DEVICE | FILE NAME SPECIFICATION ERROR | RECORD SPECIFICATION ERROR | KEYWORD VALUE ERROR IN OPEN STATEMENT | INCONSISTENT OPEN/CLOSE PARAMETERS | WRITE TO READONLY FILE | INVALID ARGUMENT TO FORTRAN I/0 LIBRARY | LIST-DIRECTED I/O SYNTAX ERROR | INFINITE FORMAT LOOP | FORMAT/VARIABLE-TYPE MISMATCH | SYNTAX ERROR IN FORMAT ERR= | OUTPUT CONVERSION ERROR ERR= | INPUT CONVERSION ERROR SS$ INTOVF SS$_INTDIV SS$_FLTOVF SS$ FLTDIV SS$_FLTUND SS$ SUBRNG 70 |F,C | 71 |F,C | 72 |F,C | ERR= | OUTPUT STATEMENT OVERFLOWS RECORD ERR= | INPUT STATEMENT REQUIRES TOO MUCH DATA ERR= | VARIABLE FORMAT EXPRESSION VALUE ERROR RET INTEGER OVERFLOW RET INTEGER ZERO DIVIDE RET FLOATING OVERFLOW 73|F,C| RET MTH$S INVARGMAT | MTHS UNDEXP MTH$ LOGZERNEG. | MTH$ SQUROONEG | MTHS SINCOSSIG | 81| F 82 |F,C| 83 [F,C | 84 [F,C | 87 |F,C | RET RET RET RET 74 |F,C | 77 |F,C| MTHS_WRONUMARG | 80| F MTH$_FLOOVEMAT | 88 (F,C | MTH$ FLOUNDMAT | 89 |F,C | FOR$_ADJARRDIM | 93| F RET RET RET RET FLOATING ZERO DIVIDE FLOATING UNDERFLOW SUBSCRIPT OUT OF RANGE WRONG NUMBER OF ARGUMENTS INVALID ARGUMENT TO MATH LIBRARY UNDEFINED EXPONENTIATION LOGARITHM OF ZERO OR NEGATIVE VALUE SQUARE ROOT OF NEGATIVE VALUE SINE OR COSINE SIGNIFICANCE LOST FLOATING OVERFLOW IN MATH LIBRARY FLOATING UNDERFLOW IN MATH LIBRARY ADJUSTABLE ARRAY DIMENSION ERROR ERROR PROCESSING AND CONDITION HANDLERS NOTES: is taken after completion of the 1I/0 1. The ERR= transfer 2. If no ERR= address has been defined for error 63, the program The entire message is printed. error the after continues the indicate to overflowed field is filled with asterisks, statement for continuable errors numbered 59, 61, 63, 64, and 68; the resulting file status and record position are the However, other I/0 errors as if no error had occurred. same detected; 1is error the as take the ERR= transfer as soon thus, file status and record position are undefined. error 3. in the output 87, 84, 83, Function return values for errors numbered 82, 88, and 89 can be modified by means of user-written condition handlers. 4. record. See Section Error number 1 detected 6.4. (FOR$_NOTFORSPE) indicates that an that was not a FORTRAN-specific error; error that is, was it table. the 1in was not reportable through any other message you call ERRSNS, an error of this kind returns a value of If that system condition value unique the To obtain 1. -error, use the fifth argument of the call to the identifies ERRSNS 6.1.3 (condval). See Section C.4. Using the ERRSNS Subroutine ERRSNS errors. You can use the ERRSNS system subroutine to process the exact nature of the error and take action lets you determine error integer FORTRAN-specific a contains Table 6-1 accordingly. This error number can be for each of the errors in the table. number situations In many obtained by calling ERRSNS after an error occurs. code to react to specific I/0 errors, once you know can provide you the ERRSNS wuse information, this To get occurred. which error routine, as shown in the following example. 10 CHARACTER*40 FILN ACCEPT *, FILN R=100 ,NAME=FILN) OPEN (UNIT=INFILE,TYPE='OLD',ER (process . 1060 CALL ERRSNS (IERR) IF (IERR .EQ. 29) THEN TYPE *, ELSE IF TYPE *, ELSE TYPE 'FILE:', (IERR *, .EQ. input FILN, 43) 'FILENAME:', file) 'DOES NOT EXIST, ENTER NEW FILENAME' THEN FILN, 'WAS BAD, ENTER NEW FILENAME' 'FAILURE ON INPUT FILE, I/O ERROR CODE=', IERR STOP ENDIF GO TO 10 END As shown, the OPEN statement contains an ERR=100 keyword, causing a branch to the ERRSNS subroutine if an error occurs during execution of the The ERRSNS subroutine returns an error number value in the OPEN. The program then uses the value of IERR either integer variable IERR. to print a message indicating the nature of the error and continue, or a message indicating that the error was too severe to allow to print the program to continue. ERROR PROCESSING AND See Appendix C 6.2 for more information OVERVIEW OF THE VAX-11 A condition handler condition occurs. software memory related. access CONDITION about the HANDLERS ERRSNS subroutine. CONDITION HANDLING FACILITY is a procedure that is invoked when an exception The exception condition may be either hardware or Hardware exceptions include floating overflows, violations, and the use of reserved operands. exceptions include output conversion errors, end-of-file and invalid arguments to mathematical procedures. When the VAX/VMS system creates a system-defined condition handler Software conditions, user that process, it establishes a will, in the absence of any user-written condition handler, process errors that occur during execution of the user image. Thus, by default, run-time errors will cause this condition handler to print one of the standard error messages and terminate severity code or associated with This default when an a the condition handler search error. continue If is no undertaken lower-level is to The default to the appropriate message file, to SYSSOUTPUT present. If the and condition execution continues. termination; and the program exit You can and relying on during the Definitions Before reading to one establish the established message user. Messages that file, system further, you e Condition value - an particular exception ® Procedure subroutine, an or ® Procedure executes. This permits e to a reached to handler, or 1list to of the output are these the respond routine, sent files to are continuation, an error application For the both program handlers example, describe program, messages. become INTEGER*4 condition. executable function. condition specifically of should own familiar with the program unit; a main to you can conditions instead of following value that identifies See Section 6.3.4. a program, activation - the environment in which a procedure environment includes a unique stack frame on stack; the stack frame contains the address of a the run-time condition handler procedure if applications. that terms: procedure called; handler handler system's the your your execution standard 6.2.1 has the SYSSERROR accommodate the needs of create and display messages encountered condition condition on have resignaled (see the condition handler responds calls was depending Otherwise, the default handler forces program condition value (see Table 6-1) becomes the status. create last a procedure error. handler the find if all lower-level handlers definitions below), the default send execution, error. for the procedure activation. A activation is created every time a procedure the procedure activation 1is deleted when returns. Condition handler - a function specifies as the procedure condition occurs. that to be new is the a procedure activation called when an exception ERROR PROCESSING AND CONDITION HANDLERS e Establish - the process of placing the address of a condition handler in the stack frame for the current procedure activation. A condition handler established for a procedure is called automatically when an exception condition occurs. In FORTRAN, condition handlers are established by means of the LIBSESTABLISH procedure. See Section 6.4.2. ® Signal - the means by which the LIB$SSIGNAL execution; LIBSSTOP -~ execution, See ® of an exception signal signal unless Section a condition and possibly continue program a severe error and do not continue program a condition handler performs an unwind. 6.2.2. Resignal - the means by which a condition handler indicates that the signal procedure 1is to continue searching for a condition handler to process a previously signaled error. To resignal, a condition handler returns the SS$_RESIGNAL value. See e occurrence condition is made known; signals are initiated by a call to a signal procedure, which then calls a condition handler. There are two signal procedures: Section 6.3.3. Condition symbol in the - a symbol used to specify a condition value, form: fac$_symbol where fac is a facility name prefix and specific condition. Table e 6.2.2 6~1 lists FORTRAN-related symbol identifies a condition symbols. Unwind - the act of returning control to a particular procedure activation, bypassing any intermediate procedure activations. For example, if X calls Y and Y calls Z; and 1Z detects an error; then a condition handler associated with Z can unwind to X, bypassing Y. Control returns to X immediately following the point at which X called Y. Condition Signals A condition signal consists of system-supplied signal procedures, CALL LIBSSIGNAL CALL LIBSSTOP a call to in either of (condition-value, (condition-value, one of the two the following forms: arg,...) arg,...) You can use a condition signal when you do not want to handle a condition in the routine in which it was detected, but wish to pass the information to a higher-level routine. If the current procedure can continue after the signal 1is made, call LIBSSIGNAL. A higher~-level procedure can then determine whether program execution is continued. If the condition will not allow the current procedure to continue, call LIBSSTOP. ERROR PROCESSING AND CONDITION HANDLERS To pass the condition value, you must use the $VAL argument 1list built-in function (see Section 5.2.3.1). Condition values are usually expressed as condition CALL LIB$SIGNAL Additional information symbols. For example: (3%VAL (MTHS_FLOOVEMAT)) arguments about the may be error. included to When called, a signal procedure searches examining the preceding stack frames procedure that handles the condition, or is reached. 6.2.3 Handler provide supplementary for a condition handler by in order, until it finds a the default condition handler Responses A condition handler responds to an exception by taking action in three major areas: 1) condition correction, 2) condition reporting, and 3) execution control. First, the handler may determine whether it can correct the condition. If it can, the handler will take the appropriate action, and execution will continue. If it cannot correct the condition, the handler may resignal the condition. That 1is, it may request that another condition handler process the exception. Condition reporting following actions: performed count of handlers ® Maintaining execution ® Resignaling the same condition to your terminal or log file @ Changing the severity field resignaling the condition ® Signaling a different message oriented to a Execution can be a by affected in e Continuing from the a call to LIBSSTOP, ® Unwinding to resulted in procedure's ® the the exceptions can involve encountered to send of the the number of ways. condition Among signal. If the signal was the program will exit. establisher exception. function value to at during the point The handler be returned. of the program appropriate message condition, for example, specific application a one of to wvalue and produce a them are: issued the specifies through call the that called Unwinding to the establisher's caller (the procedure that called the procedure that established the handler). The handler specifies the called procedure's function value to be returned. ERROR PROCESSING AND CONDITION HANDLERS 6.3 USER-WRITTEN CONDITION HANDLERS The following sections describe how to code and establish a condition handler, and provide some simple examples. See Appendix C of the VAX-11/780 Architecture Handbook, and the VAX-11] Common Run-Time Procedure Library Reference Manual for more details on condition handlers. 6.3.1 Establishing and Removing Handlers When a procedure 1is called, no condition handler 1is 1initially established. If you want to use a condition handler, you must "establish it by calling the Run-Time Library procedure LIBSESTABLISH and including in the call such code as the following: EXTERNAL HANDLER CALL LIBSESTABLISH (HANDLER) To remove an established handler, LIBSREVERT, as follows: call the Run-Time Library procedure CALL LIBSREVERT As a result of this call, the condition handler established in the current procedure activation 1is removed. When a procedure returns, the condition handler established by the procedure 1is automatically removed. 6.3.2 FORTRAN Condition Handlers A FORTRAN condition handler is an INTEGER*4 function that when an exception condition occurs. You must define arguments for a condition handler: 1is called two dummy l. An integer array to refer to the argument list from the call to the signal procedure (the "signal arguments"). That is, the list of arguments included in CALL LIBS$SIGNAL or CALL LIBSSTOP (see Section 6.2.2). 2. An integer array to refer to information concerning the procedure activation that established the condition handler (the "mechanism arguments"). For example, you can define a condition handler INTEGER*4 INTEGER*4 as follows: FUNCTION HANDLER (SIGARGS,MECHARGS) SIGARGS (6) ,MECHARGS (5) ERROR PROCESSING AND CONDITION HANDLERS The array SIGARGS is wused procedure. The values from to the obtain information signal procedure are Value Meaning SIGARGS (1) Indicates how many this vector SIGARGS (2) array handler. The n) MECHARGS activation are being passed in count). Indicates optional arguments as specified by the call to LIBSSIGNAL or LIBSSTOP; note that the dimension bounds for the SIGARGS array should specify as many entries as necessary to refer to the optional arguments is status used of MECHARGS is to the a obtain 5-element 4 FRAME MECHARGS (3) MECHARGS (4) MECHARGS (5) DEPTH RO R1 (MECHARGS (1)) that array MECHARGS (1) element information procedure MECHARGS (2) first arguments (argument Indicates the condition being signaled (condition value). See Section 6.3.4 for a discussion of condition values. SIGARGS (3 to The from the signal listed below. is the in about established the the procedure the condition form: argument count of this vector (4). FRAME (MECHARGS (2)) stack frame DEPTH (MECHARGS (3)) made from the been contains the address that established the handler. of the procedure contains the depth (number procedure activation, up to of the activation calls) that have point at which the exception occurred. MECHARGS (4) and at of the 6.3.3 time Handler MECHARGS (5) the contain the values of registers RO and Function Return Values Condition handlers specify function return subsequent execution. Function return values defined in Table 6-2. values to control and their effects are Table 6-2 Condition Handler Function Return Values Value SS$_CONTINUE Effect Continue execution from signal was 1issued by the signal. a «call to the program exits. however, SS$_RESIGNAL Rl signal. Resignal, handler to to continue process the the search condition. for a If the LIBSSTOP, condition ERROR PROCESSING AND CONDITION HANDLERS A condition handler can also request a stack unwind, by calling SYSSUNWIND before returning. If SYSSUNWIND is called, the function return value is ignored. The handler modifies the saved registers RO and Rl in the mechanism arguments to specify the called procedure's function value. A stack e unwind can be made to one of Unwind to the establisher, resulted in the exception. two places: at the point Specify: of the <call that CALL SYSSUNWIND (3VAL (MECHARGS (3)) ,%VAL (0)) e Unwind to the procedure that called the establisher. Specify: CALL SYSSUNWIND ($VAL (0) ,%VAL(O0)) 6.3.4 Condition Values and Symbols Condition values are used by VAX-1l1l to indicate that a called procedure has either executed successfully or failed, and to report exception conditions.. Condition values are INTEGER*4 values, consisting of fields that indicate which system component generated the value; the reason the value was generated; and the severity of the condition. 31 A condition value has 28 27 the form: 16 15 C 3 FACILITY C field (31:28) Message (15:3) describes the condition that occurred. Bit 15 = 1 to indicate the message is specific to severity code, 5, 6, as 0 to indicate a follows: - warning - success I - N WNEEO (2:0) SEV identifies the software component that generated the condition value. Bit 27 =1 to indicate a customer facility. Bit 27 = 0 to indicate a DIGITAL facility. a single facility. Bit 15 = system wide message. Sev o control bits (27:16) Facility MESSAGE 2 error ~ information - severe - reserved error A warning severity code (0) indicates that output was produced, but the results might not be what you expected. An error severity code (2) indicates that output was produced even though an error was detected. Execution can continue, but the results will not all be correct. A severe error code (4) indicates that the error was of such severity that output was not produced. One of the functions that can be performed by a condition handler is altering the severity code of a condition value, to allow execution to continue or to force an exit, depending on the circumstances. 6-11 ERROR PROCESSING AND CONDITION HANDLERS The condition value is passed as the second element of the array SIGARGS. There are times when you may require that a particular condition be identified by an exact match. That is, each bit of the condition value (31:0) must match the specified condition. For example, you may want to process a floating overflow condition only if its severity code 1is still 4 (that is, if no previous handler has changed the severity code). As noted above, a typical handler response is to change the severity code and resignal. In many cases, however, you may want to respond to a condition, regardless of the value of the severity code. To ignore the severity and control fields of a condition value, use the LIB$MATCH_COND function, as follows: index = LIBSMATCH_COND (SIGARGS(2),con-1,con-2,...con-n) This function compares bits 27:3 of the value in SIGARGS(2) with each of the condition values that follow (con-1 through con-n). If it finds a match, the index value is assigned according to the position of the matching condition value in the list. That is, if the match is with the third condition value following SIGARGS(2), then index = 3. If no match is found, index = 0. The value of the index can then be used to transfer control, as in the following example: INTEGER*4 INCLUDE INTEGER*4 1 FUNCTION HANDL (SIGARGS,MECHARGS) 'SYSS$LIBRARY:FORDEF' SIGARGS (6) ,MECHARGS (5) INDEX=LIB$MATCH_COND (SIGARGS (2) ,FOR$_FILNOTFOU, FOR$_NO_SUCDEV,FOR$_FILNAMSPE ,FOR$_OPEFAI) GO T0 (100,200,300,400) ,INDEX HANDL=SS$_RESIGNAL RETURN If no match is found between the condition value in SIGARGS (2) and any of the values in the list, INDEX=0, and control is transferred to the next executable statement after the computed GO TO. A match with any of the values 1in the 1list transfers control to the corresponding statement in the GO TO list. Thus, if SIGARGS(2) matches FORS$_OPEFAI, control is transferred to statement 400. Note the use of condition symbols to condition represent condition symbols and their values.. Table 6-1 1lists the FORTRAN values. The system provides parameter files comprising condition symbol definitions. When you write a condition handler, you must specify one of the following parameter files, as appropriate, 1in an INCLUDE statement: SYSSLIBRARY : FORDEF.FOR This file contains definitions for FORTRAN-specific Run-Time Library. FOR$_xyz For example: FOR$_INPCONERR 6-12 all condition symbols from the These symbols have the form: ERROR PROCESSING AND CONDITION HANDLERS SYSSLIBRARY :MTHDEF.FOR This file contains definitions for all condition symbols from the These symbols have the form: mathematical procedures library. MTHS _xyz For example: MTH$ SQUROONEG SYSSLIBRARY :SIGDEF.FOR contains This file miscellaneous FORTRAN condition handlers. definitions symbol These symbols have the form: wused in SS$_xyz For example: SS$_FLTOVF You can obtain a listing of the condition symbols for any facility and their corresponding hexadecimal values by means of the following procedure: Create a file that contains the lines 1. SxxDEF GLOBAL +END To simplify the procedure, make sure the file type is MAR. Specify a value for xx according symbols you're concerned with. $SSDEF to the set For example: of condition GLOBAL .END the command: Enter 2. $ MACRO file-spec If where file-spec specifies the file you created in step 1. you specified a file type of MAR, you need to enter only the file name with this command. the command: Enter 3. $ LINK/MAP/FULL/NOEXE file~-spec Following execution of this command, you will have a file the symbols defined in that contains all (file-name MAP) xxDEF, in numeric and alphabetic order. Example: $ EDIT (create $ MACRO DEF.MAR file) DEF $ LINK/MAP/FULL/NOEXE DEF 6-13 ERROR PROCESSING AND 6.3.5 Floating Overflow, CONDITION HANDLERS Zero Divide Exceptions Some conditions involving floating point operations require that you take special action if vyou wish to continue execution. Operations that involve floating overflow, divide by 0, computing the square root of a negative number, etc. store a unique result known as a floating reserved operand. If this a subsequent floating point operation accesses result, a hardware reserved operand fault is generated signaled. This may continue indefinitely if the reserved operand not changed and is accessed computation. To by by each subsequent reserved operand precision. For Common Run-Time will be changed more it, the r acorvad cperand include the argument, and This ensures that the et correctly hd N B Y o WA regardless information on LIBSFIXUP FLT, Procedure Library Reference Manual. see of its the VAX-11 that apply CONDITION HANDLER EXAMPLES examples typical Example in this FORTRAN section illustrate procedures. condition handlers 1: The following example shows a matrix inversion procedure, using logical function INVE to indicate RT success or failure. That is, if matrix can be inverted, INVERT returns the logical value .TRUE. the matrix is singular, INVERT returns the logical value .FALSE. the 1is the LIBSFIXUP_FLT (SIGARGS,MECHARGS,1.7D38) The third argument is optional. If you omit is changed to +0.0. However, you should specify it as’' a double precision value. to perform example: CALL The to allow computation to continue, you must change the reserved operand calling the Run-Time Library routine LIBSFIXUP_FLT, as shown in this 6.4 attempt and matrix inversion procedure is being executed, or divide-by-zero exception may occur. A provided to recover from these exceptions to the an INTEGER*4 calling program. function. Note that the a floating the the If As overflow condition handler (HANDL) is and return the value .FALSE. condition handler is defined as ERROR PROCESSING AND CONDITION HANDLERS LOGICAL FUNCTION DIMENSION A(N,N) INVERT (A,N) HANDL EXTERNAL CALL LIBSESTABLISH INVERT = .TRUE. . (HANDL) ! ! ESTABLISH HANDLER ASSUME SUCCESS (INVERT THE MATRIX) RETURN END INTEGER*4 FUNCTION (SIGARGS, MECHARGS) HANDL (5) SIGARGS (3), MECHARGS INTEGER*4 INCLUDE 'SYSSLIBRARY:SIGDEF' ! ASSUME RESIGNAL HANDL = SS$_RESIGNAL 1 IF (SIGARGS(2) .EQ. SIGARGS (2) .EQ. MECHARGS (4) = CALL SS$ FLTOVF SS$_FLTDIV) .OR. THEN .FALSE. SYSSUNWIND (%VAL(0),%VAL(0)) ENDIF RETURN END the condition If an exception occurs during the execution of INVERT, The handler must first determine whether is called. (HANDL) handler the condition Thus, it can deal with the condition being signaled. If the condition is the condition value (SIGARGS(2)). tests handler floating overflow or floating division by 0, the condition handler causes a return from INVERT with the value .FALSE. The condition handler uses the unwind procedure to force a return to 1is The 1logical value .FALSE., that called INVERT. the procedure stored in the saved RO element of the mechanism vector (MECHARGS(4)). This value 1is used as the function value for INVERT when the unwind the condition occurs. The handler calls SYSSUNWIND and returns; handling facility then gets control and actually performs the unwind operation. Note that the function value from the wuser condition handler (HANDL = SS$_RESIGNAL) is ignored if SYSSUNWIND is called. division by If the exception condition is not a floating overflow or condition handler returns a value of SS$_RESIGNAL, indicating the 0, The condition. the directly with to deal able that it is not immediately preceding procedure activation will then be checked for a condition handler; continuing until an established condition handler or the default condition handler is reached. ERROR PROCESSING AND Example CONDITION HANDLERS 2: The following example illustrates a condition handler that processes the Run-Time Library conditions MTH$ FLOOVEMAT and MTHS$ FLOUNDMAT. The purpose of the condition the Run-Time Library 0.0, and to suppress C MAIN handler is to modify the value returned by -0.0) to from the default value (reserved operand the printing of an error message. PROGRAM EXTERNAL HDLR CALL LIBSESTABLISH (HDLR) X =.EXP(Y) END INTEGER*4 INTEGER*4 INCLUDE INCLUDE IF FUNCTION HDLR (SIGARGS,MECHARGS) SIGARGS(2), MECHARGS (5) 'SYSSLIBRARY:SIGDEF' 'SYSSLIBRARY:MTHDEF' (SIGARGS(2) .EQ. MTH$_FLOOVEMAT SIGARGS(2) .EQ. MTHS$_FLOUNDMAT) 1 MECHARGS (4) = 0 MECHARGS (5) 0 HDLR = = .OR. THEN SS$_CONTINUE ELSE HDLR = SS$_RESIGNAL ENDIF RETURN END When an exception condition occurs, HDLR is called, and the contents of the second element of the signal vector are compared with MTH$ FLOOVEMAT and MTH$ FLOUNDMAT. If either of the specified conditions is detected, 07s are placed in the saved RO and Rl elements of array MECHARGS, the value SS§$_CONTINUE is returned in HDLR, and execution continues in the math 1library and no error message is printed. RO and Rl are returned. If the condition is not one of those specified, SS$_RESIGNAL is returned, and the preceding procedure activations are searched for an established 6-16 condition handler. CHAPTER 7 FORTRAN SYSTEM ENVIRONMENT This chapter discusses aspects of the relationship between VAX-11 FORTRAN IV-PLUS and the VAX-1ll system. The purpose is to provide insights that will permit you to use VAX-11 FORTRAN IV-PLUS in a way that makes best use of its features. The following subjects are discussed: 7.1 e Program sections e Storage e FORTRAN-supplied e DO ® ENTRY e Floating point data representation allocation functions loops statement arguments PROGRAM SECTION USAGE The storage required by a VAX-1l1 FORTRAN IV-PLUS program unit is allocated 1in contiguous areas called program sections (PSECTs). The VAX~-11] FORTRAN IV-PLUS compiler implicitly declares three PSECTs, named: SCODE - This program section contains all executable code. SPDATA - This program section constants and FORMAT SLOCAL -~ This program section contains read/write data local the program unit. In addition, PSECT with block PSECT contains read-only statements). data (e.g., to each COMMON block you declare causes allocation of a the same name as the COMMON block. (The unnamed COMMON is named $BLANK.) The linker controls memory allocation and attributes of each PSECT. See Table 7-1. sharing according Each module comprised by your program is named according to to the the name specified in the PROGRAM, BLOCK DATA, FUNCTION, or SUBROUTINE statement used in creating the module. You can use the module name to qualify the PSECT name specified 1in LINK commands. Refer to the VAX-11l Linker Reference Manual. FORTRAN Defaults are applied to SYSTEM PROGRAM and PROGRAM default DATA default - BLOCK ENVIRONMENT BLOCK DATA statements. They are: source-file-name$MAIN source-file-nameS$DATA - PSECT Table 7-1 Names and Attributes PSECT Name Use Attributes SCODE Executable SPDATA Read-only data: literals, read-only FORMAT SLOCAL code. PIC,CON,REL,LCL,SHR,NOEXE,RD,NOWRT,LONG statements Read/write data to PIC,CON,REL,LCL,SHR,EXE,RD,NOWRT, LONG the program local PIC,CON,REL,LCL,NOSHR,NOEXE ,RD ,WRT,LONG* unit: user local symbols, compiler temporary symbols, argument lists, and descriptors $BLANK Blank COMMON block. PIC,OVR,REL,GBL,SHR,NOEXE,RD,WRT ,LONG name (s) Named COMMON block(s). PIC,OVR,REL,GBL,SHR,NOEXE,RD,WRT ,LONG * Program section SLOCAL is aligned on quadword contains any double precision or complex data. Table 7-2 describes the meanings VAX-11 Linker Reference Manual. of the boundaries attributes. Refer also if it to the When the VAX/VMS linker constructs an executable image, it divides the executable image into sections. Each image section contains PSECTs that have the same attributes. By arranging image sections according to PSECT attributes, the linker is able to control memory allocation. The linker allows you to allocate memory to your own specification, by means of commands linker. The Manual. ) 7.2 you options include file in an options is described in file that the VAX-1l1l is input Linker to the Reference STORAGE ALLOCATION AND FIXED-POINT DATA TYPES The default storage unit for VAX-11l FORTRAN IV-PLUS is the (four bytes). A storage unit is the amount. of memory.- needed a real, logical, or integer value. Double precision and values are stored 1in two successive storage units. These sizes must be taken into account when you associate two longword to store complex relative or nmore variables through association. argument an EQUIVALENCE or COMMON statement, or by You can, however, declare integer and logical variables as 2-byte values to save space or to be compatible with PDP-11 FORTRAN. Either specify the /NOI4 qualifier in the FORTRAN command, or explicitly declare a variable as INTEGER*2 take advantage of VAX-1l's 32-bit data efficiently. or ability LOGICAL*2 to type. manipulate This both allows 16-bit you data to and FORTRAN SYSTEM ENVIRONMENT Table 7-2 PSECT Attributes Attribute Meaning PIC/NOPIC Position-independent or position~dependent. CON/OVR Concatenated or REL/ABS Relocatable or GBL/LCL Global SHR/NOSHR Shareable or EXE/NOEXE Executable or non-executable RD/NORD Readable or WRT/NOWRT Writeable or non-writeable LONG/QUAD Longword or quadword alignment 7.2.1 or overlaid absolute local scope non-shareable non-readable 1Integer Data Types Supported VAX-11 FORTRAN IV-PLUS supports INTEGER*2 and INTEGER*4 data types, which occupy two and four bytes of storage respectively. Both types can be mixed in computations; such mixed type computations are carried out to 32 bits of significance, and produce INTEGER*4 results. If you do not override the default storage allocation, are allocated for integer values. then four bytes 7.2.1.1 Relationship of INTEGER*2 and INTEGER*4 Values - INTEGER*2 values are stored as two's complement signed binary numbers, and occupy two bytes of storage. INTEGER*4 values are also stored as two's complement signed binary numbers, but occupy four bytes of storage. The lower addressed word of an INTEGER*4 value contains the low-order part of the value. INTEGER*2 values are a subset of INTEGER*4 values. That 1is, an INTEGER*4 value 1in the range -32768 to 32767 can be treated as an INTEGER*2 value. Conversion from INTEGER*4 to INTEGER*2 (without checks for overflow) consists of simply ignoring the high-order 16 bits of the INTEGER*4 value. This type of conversion provides an important FORTRAN usage, as 1illustrated in the following example. Given: CALL SUB(2) should the argument (2) be treated as an INTEGER*2 value or as INTEGER*4? By providing an INTEGER*4 constant as the actual argument, SUB executes correctly even if its dummy argument is typed INTEGER*2. FORTRAN SYSTEM ENVIRONMENT 7.2.1.2 1Integer Constant Typing - Integer constants are generally typed according to the magnitude of the constant. In most contexts, INTEGER*2 and INTEGER*4 variables and integer constants can be freely mixed. You are responsible, however, for ensuring that integer overflow conditions do not occur, as happens in the following example. INTEGER*2 INTEGER*4 I 32767 J I+ 3 I J In this example, I and 3 are INTEGER*2 values, and an INTEGER*2 result will be computed. The 16-bit addition, however, will overflow the valid INTEGER*2 range and be treated as -32766. This value will be converted detected to and INTEGER*4 reported type if and the assigned program default /CHECK=OVERFLOW qualifier to J. unit The was specified. overflow will compiled with the preceding example with the following uivalent program, which produces different results. qu Contrast be the 1] apparently PARAMETER I INTEGER*4 J = 32767 J=1IH++3 In this the case the compiler parameter performs constant 32767, The compiler recognizes this assigned the value 32770. 7.2.1.3 1Integer-Valued as the addition of producing an a INTEGER*4 Processor-Defined the constant value. constant result Thus, Functions of 3 and 32770. J will be - A number of the an integer-valued processor-defined functions provided by FORTRAN (see Section 7.3) produce integer results from real or double precision arguments; for example, INT. In order to support such functions in a manner compatible with both INTEGER*2 and INTEGER*4 modes, two versions of these integer-valued processor-defined functions are supplied. The compiler chooses the version that matches the compiler /I4 qualifier setting (/I4 or /NOI4). This is similar to generic function selection (described in Section 7.3.1), except that the selection is based on the mode of the compiler, rather than on the argument data type. In some cases, you may need to use the version of processor-defined function that 1is the opposite of the compiler qualifier setting. For this reason, a pair of additional processor-defined function names are provided for each standard integer-valued processor-defined function. The names of the INTEGER*2 versions are prefixed with I, and the names of the INTEGER*4 versions with J (for example, IIABS and JIABS). See Appendix B of the VAX-11 FORTRAN IV-PLUS processor—-defined 7.2.2 The Byte FORTRAN Language (LOGICAL*1l) IV-PLUS In general, when the Manual for a complete list of Data Type byte data processing capabilities signed integer data type, Hollerith data. operation, Reference functions. data of type lets you take advantage of VAX-1l. Actually, BYTE and is useful for storing different lower-ranked type 1is types are converted used to of the byte or LOGICAL*1l is a and manipulating in a binary the higher-ranked FORTRAN SYSTEM ENVIRONMENT discussed in the VAX-11l type prior to computation. (Data type rank) isHowever , in the case of a Manual. ce Referen e FORTRAN IV-PLUS Languag representable as a byte variable and an integer constant in the range t is treated as a byte byte variable (-128 to 127), the integer constantype. constant; 7.3 and the result is also of byte data FUNCTIONS SUPPLIED WITH VAX-11l FORTRAN processor—defined of VAX-11 FORTRAN IV-PLUS includes a number N These are listed in Appendix B of the VAX-11 FORTRA functions. thms algori the of ptions descri For Manual. IV-PLUS Language Reference used to generate processor-defined functions, Common Run-Time Procedure Library Reference Manual. refer to the VAX-1ll es provided by VAX-1l1 Processor-defined functions include routin atical functions (such mathem d ly-use common m perfor to FORTRAN IV-PLUS The and TIME). DATE as as COS and EXP) and utility services (such of use the by cted unaffe is on functi fined sor-de data type of a proces of these the IMPLICIT statement to change the default data type. Some that is, you can processor-defined functions are generic functions; common name. refer to a set of similar routines by one 7.3.1 Generic Functions FORTRAN IV-PLUS are generic Many of the functions supplied with VAX-11 them by a common name, to to refer you functions, which means that , there are three example For n. functio same the much perform , all of which are cosines ate calcul processor-defined functions that names are COS, their COS; name c generi the by to d referre (or can be) precision, single return they They differ in that DCOS, and CCOS. request you If ively. respect values, x comple or double precision, to it refer only need that the cosine function be invoked, youthe appropriate routin e selects er compil generically, as COS. The single is nt argume the If . specify you nts argume the on based if it is double precision, DCOS is precision, COS is selected; selected; and if complex, CCOS is selected. to a particular routine Note, however, that you can explicitly refer precis ion cosine function, double Thus, to obtain the if you wish. the generic name. you could specify DCOS, rather than using The compiler provides the selects names of processor-defined functions it by listing them by their internal names in the "FUNCTIONS AND SUBROUTINES REFERENCED" section of the listing. 7.3.2 Use of the EXTERNAL Statement in conjunction with The EXTERNAL statement has special applicability ram by means of subprog a to refer you If ns. functio processor-defined assumes that er compil the names, one of the processor-defined function if one Thus, used. be n functio fined sor—de proces you intend that the ed -suppli system— a as name of your own subprograms has the same from name e's routin your guish distin must you ine, function or subrout the processor-defined function name. To do so, specify the name in an EXTERNAL statement as follows: EXTERNAL *name FORTRAN The compiler is prefixed interprets SYSTEM any name by an asterisk, as ENVIRONMENT listed the name The EXTERNAL statement is described Language Reference Manual. 7.4 ITERATION COUNT MODEL VAX-11 with FORTRAN the IV-PLUS following The control variable precision variable. ® The or ® double The wvalue, can be of and parameter 7.4.1 of is the an size, and the 1loop at not loop. VAX-11l practices FORTRAN systems in FORTRAN ® IV-PLUS. Assigning the ® a 1loop cause associated may not For final is of DO of an the executed (the the the DO of of a negative 7.4.2 1Iteration Given the DO (where following label, ml, computed as count= This Count m2, or zero the DO successive times the real, iteration during number changing double control of the values loop of is the statement. Interchange the the use intended of DO statements effects when used the control variable within the greater than the final value, in termination long loop that is within the loop. or integer, the loop. Similarly modifying either a step size variable variable to either modify the loop behavio r the loop. Using IV-PLUS statement, real, value by with have the value e that subprogram. initialization example: value to that is early statement, FORTRAN integer, the Thus, used form re-evaluated affected variables common VAX-11 that produces result, Cautions Concerning Program other EXTERNAL user-supplied the extended expression 1is not in be determined statement, executions can times is executed an step any precision number count) Some provides features: initial an a FOR DO LOOPS ® variable in of step terminated size by a to cause conditional or or an on with body order of to a final terminate arbitrarily control transfer Computation sample DO statement V=ml,m2,m3 and m3 are any follows: expressions), the iteration count is executed at MAX(1,INT(((m2-ml)/m3)+1)) computation: e Provides least that once the body of the DO loop is always FORTRAN SYSTEM ENVIRONMENT Permits the step size (m3) to be negative or positive, but not e zero for value count Gives a well-defined and predictable allowed the of ion combinat any from g resultin ons expressi ff result types. Note, however, that the effects of round-othe cause may tion computa point g floatin any in t error inheren count to be greater or less than desired when real or double e precision values are used. compute the iteration Under certain conditions it is not necessary to paramet ers are of type the of all if , example For tly. count explici the loop, then in ed modifi not are integer and if the parameter values of iterations number the s control code ed generat IV-PLUS the FORTRAN the final with ly direct le variab of the loop by comparing the control value. 7.5 ENTRY STATEMENT ARGUMENTS ed in Chapter The association of actual and dummy arguments is describ Manual. In ce Referen Language IV-PLUS FORTRAN VAX-11] the 6 of However, the general, that description suffices for most cases. ents varies from implementation of argument association in ENTRY statem the way this is done on some other FORTRAN systems. 5), VAX-11l FORTRAN As described previously in this manual (Chapterriptor methods to pass y-desc call-b and rence y-refe call-b uses the er arguments, charact and arguments to called procedures (for numeric the use s ntation impleme FORTRAN other Some respectively). call-by-value/result method. This distinction becomes crucial when reference is made to dummy arguments in ENTRY statements. arguments in While standard FORTRAN allows you to use the same dummy only to those refer to you permits it nts, stateme different ENTRY dummy arguments that are defined for the ENTRY point being called. For example: SUBROUTINE SUBI1 (X,Y,Z) ENTRY ENTI1(X,A) ENTRY ENT2(B,Z,Y) Given this, you can make the following references: CALL SUB1 ENT1 ENT2 Valid References X X B Y A y/ Z Y FORTRAN FORTRAN implementations SYSTEM ENVIRONMENT that use the call-by-value/result however, permit you to refer to dummy arguments that in the ENTRY statement being called. For example: SUBROUTINE ENTRY = method, not defined INIT(A,B,C) RETURN Y are CALC(Y,X) (A*X+B)/C END You can use this non-standard device in call-by-value/result implementations, because a separate internal variabl e is allocated each dummy argument in the called procedure. When the procedure called, each scalar actual argument value is assigned to corresponding whenever internal there is variable, a and to called procedure. On return from arguments the are copied back to variables. When an entry point is with the values of referenced advised on VAX-11l on on not other and systems VAX-11l attempt FORTRAN. VAX-11l, Such use calls to do will that a the variables dummy are then argument procedure, corresponding used within modified actual the dummy argument referenced, all its dummy arguments are defined the corresponding actual arguments, and may be subsequent to these reference for is the to the this references produce the subprogram. in programs will programs that However, you are executed to be are not have the intended that are not transportable call-by-reference (descriptor) effect creates associations between dummy and actual arguments the address of each actual argument, or descriptor, to called procedure. Each reference to a dummy argument generates by passing indirect address reference control returns actual and from dummy the through called arguments the actual procedure, ends. The argument the dummy address. association arguments do For SUBROUTINE A = Al B = Bl C the an When between not their values, and therefore cannot be referenced on subseque nt Thus, to perform the sort of non-standard references shown previous example, the subprogram must copy the values of the arguments. to method. example: retain calls. in the dummy INIT(Al,Bl1,Cl) ) =2C1l RETURN ENTRY Y = CALC(Y,X) (A*X+B) /C END This will work on call-by-value/result avoided, because depends on the they will retain 7.6 The VAX-11, method. and on However, systems this it is also non-standard. The storage for A, B, and C being their values from one call to that method use should also the be success of this example statically allocated so the next. FLOATING POINT DATA REPRESENTATION following internally. sections describe how floating point data is represented FORTRAN SYSTEM ENVIRONMENT 7.6.1 8Single Precision Floating Point Data four A single precision floating point value is represented by 31. through 0 right the from d numbere are bits The bytes. ous contigu 0 6 7 15 14 A FRACTION EXPONENT S FRACTION 16 31 A, A single precision floating point value is specified by itstheaddress value is the address of the byte containing bit 0. The form of excess 128 sign magnitude with bit 15 the sign bit, bits 14:7 an fraction binary exponent, and bits 6:0 and 31:16 a normalizednot24-bit represented. with the redundant most significant fraction bit cance go from 16 Within the fraction, bits of increasing signifi through 31 and 0 through 6. An The 8-bit exponent field encodes the values 0 through s 255. the that indicate 0, of bit sign a with exponent value of 0 together of 1 through floating point value has a value of 0. Exponent values exponent value An +127. through -127 of 255 indicate binary exponents operand. reserved a as taken is 1, of bit sign a with together of 0, take a operand reserved a ng Floating point instructions processi reserved operand fault (see Section 7.6.3.1). range of The value of a floating point value is in the approxiamate floating point The precision of .29*10**-38 through 1.7*10**38. value is approximately one part in 2*%*23, i.e., typically 7 decimal digits. 7.6.2 Double Precision Floating Point Data by eight A double precision floating point value is represented 63. through 0 right the from d contiguous bytes. The bits are numbere 7 15 14 S EXPONENT 0 6 :A FRACTION FRACTION FRACTION FRACTION 63 48 FORTRAN SYSTEM ENVIRONMENT A double precision floating point value is specified by its address A, address of the byte containing bit 0. The form of a double precision floating point value is identical to a single precision floating point value except for an additional 32 low significance fraction bits. Within the fraction, bits of increasing significance go 48 through 63, 32 through 47, 16 through 31, and 0 through 6. the The exponent for double conventions and approximate precision floating point range of values are single the same precision floating point values. The precision of a double precision floating point value is approximately one part in 2*%*55, i.e., typically 16 decimal digits. 7.6.3 Floating Certain not FORTRAN permitted values as Point Data Characteristics programming under the the expected behavior described below. when practices rules for attempted that are commonly wused, standard FORTRAN, may not in VAX-11 FORTRAN. though produce These are 7.6.3.1 Reserved Operand Faults - Floating point variables that contain invalid floating point values (-0.0), indicate d by an exponent field of 0 and a sign bit of 1, cause a reserved operand fault in the VAX-11 hardware. An terminates. There are ® three ways The VAX-1l1l result ® to the and is create hardware of overflow error reported, and, reserved operand stores floating floating a reserved point zero by default, invalid. For program values: operand arithmetic value exceptions, as the floating divide. The mathematical function library returns a value if the function is called incorrectly is your example, reserved or if the operand argument / SQRT (-1.0) These return values can be handler (see Chapter 6). ® Integer operand modified and logical operations can create reserved patterns in floating point variables and arrays with integers. Associations of this kind can occur EQUIVALENCE COMMON, I = 32768 X = X+1.0 case other two can FORTRAN cases or argument association. For (X,I) Adding 1.0 to X will cause the integer value 32768 is as a floating point value. first condition bit example: last a arithmetic associated through EQUIVALENCE, The by providing a a occur reserved reserved when invalid inadvertently in a systems. occur 7-10 operand operand fault, because when interpreted programs or data are program, used. and The not be detected by FORTRAN SYSTEM ENVIRONMENT 7.6.3.2 Representation of 0.0 - The VAX-1l hardware defines 0.0 as any bit pattern that has an exponent field and sign bit of 0, regardless of the value of the fraction. When a bit pattern that is defined as 0.0 is used in a floating point operation, the VAX-1l1 hardware sets the fraction field to 0. One possible effect is that non-zero integers that are equivalenced to floating point values may be interpreted as 0. Logical operations following example: EQUIVALENCE I = 64 IF (X .EQ. can have a similar effect, as shown in the (X,I) 0) GO TO 10 The branch will always be taken because the bit pattern that represents the integer value is equivalent to 0 when interpreted as a floating point value. 7.6.3.3 Sign Bit Tests - The bit used as the sign bit of a floating point value is not the same bit as the sign bit of an equivalenced INTEGER*4 value. Consequently, you must test the sign of a value by testing the correct data type. EQUIVALENCE I = 40000 IF (X .GT. For example: (X,I) 0) GO TO 10 The branch will not be taken, because the bit pattern that the integer represents value 40000 is negative (bit 15 is set) when interpreted as a floating point value. 7-11 CHAPTER 8 PROGRAMMING CONSIDERATIONS This chapter discusses methods you can use to write programs. Topics covered are: e Creating efficient source programs e Compiler optimization e I/O system characteristics source source programs CREATING EFFICIENT SOURCE PROGRAMS 8.1 You can reduce the time and memory required for your by efficient taking of advantage features language, as described below. 8.1.1 in included the FORTRAN IV-PLUS PARAMETER Statement The PARAMETER statement allows you to assign constant. For example: a symbolic name to a PARAMETER PI=3.1415927 to represent the constant (PI) You can then use the symbolic name (3.1415927) anywhere a constant is valid (such as in expressions). Using the PARAMETER statement promotes more efficient object code by allowing constants to be used instead of variables, while permitting easy program modification. Constants can generally be compiled into (See Section 8.2.2.) Therefore, parametric more efficient code. variables should be defined by means of PARAMETER statements, rather than by means of DATA or assignment statements. The source code illustrated in Example A will produce more efficient code than either Example B or Example C. Example A PARAMETER M = 50, N = 100 5 DIMENSION X (M), DO 5, I =1, M po 5, J=1, N X(I) = X(I)*Y(J) Y(N) + X(M)*Y(N) PROGRAMMING CONSIDERATIONS Example B DIMENSION DATA M, 5 X (50), DO 5, I =1, DO 5, J =1, X(I) Example = Y(100) N/50,100/ M N X(I)*Y(J) + X(M)*Y(N) C DIMENSION M =50 N = X (50), Y(100) ; 100 DO DO 5, I = 1, M 5, J = 1, N X(I) = X(I)*Y(J) ( 5 8.1.2 The INCLUDE INCLUDE program. Statement statement This programs. code, such can For as a units. create INCLUDE a is allows source program + X(M)*Y(N) to to example, COMMON Rather separate statement used you in file avoid there may a that consists unit into your redundant be 1lines of that appear in each program several specification, repeat this code in program file duplicating block than each incorporate of that the code; requires then the source code in source several unit, you specify an code. Example In this example, a COMMON block specification is required in a program as well as in a subroutine called by the program. The COMMON block specification is put into a file (COMMON.FOR), and an INCLUDE statement is used in both the program and the subroutine, to reference the code. The file, COMMON.FOR, consists of the following text: PARAMETER M COMMON Main INCLUDE 'COMMON.FOR' CALL CUBE DO 5 Z(I) I = INCLUDE Z (M) =1,M X(I) SUBROUTINE 10 100 Y (M) Program DIMENSION 5 = X (M), + SQRT(Y(I)) CUBE 'COMMON.FOR' DO 10 I = 1,M X(I) = Y(I)**3 RETURN END The file COMMON.FOR defines the size of the COMMON block of the arrays X, Y, and Z. Any changes to the COMMON reflected automatically after recompilation. and the sizes block will be PROGRAMMING CONSIDERATIONS Allocating Variables in Common Blocks 8.1.3 in so When you allocate variables in a common block, you should do One memory. in boundaries natural on aligned are they that way a such in order, simple method to accomplish this is to allocate variables First allocate INTEGER*4, LOGICAL*4, REAL, to data type. according then INTEGER*2, LOGICAL*2 variables; and DOUBLE PRECISION variables; and finally BYTE and CHARACTER variables. 8.1.4 Conditional Branching You will generally produce more efficient programs if vyou use IF...THEN...ELSE statements to control program flow than if you use IF... 8.2 GO TO statements. COMPILER OPTIMIZATIONS Optimization refers to techniques used to produce the greatest amount The aim is to of processing with the least amount of time and memory. Optimum create programs that are efficient in speed and size. and programs, written and designed carefully from results efficiency from compilation techniques that take advantage of the machine You can produce optimum source programs by being aware architecture. of, and using, certain features provided by the VAX-11 FORTRAN IV-PLUS the VAX-11 FORTRAN IV-PLUS compiler produces efficient code language; by deriving maximum benefit from the VAX-1ll hardware. The primary goal of VAX-11 FORTRAN IV-PLUS optimizations is to produce an object program that executes faster than an unoptimized version of the same source program. the A secondary goal is to reduce size of the object program. The language elements you use in the source program directly affect Therefore, you the compiler's ability to optimize the object program. in which you can assist compiler the ways should be aware of the performs compiler IV-PLUS FORTRAN The VAX-11 optimization. following optimizations: > @ Evaluation at compile time of integer, real, and double precision constant expressions involving addition, subtraction, multiplication, or division (this technique is called "constant folding"). e Compile-time constant conversion. e Compile-time evaluation of constant subscript e the If two subprogram references have Argument-list merging. is 1list argument the single copy of a arguments, same expressions in array element references. generated. e Branch instruction optimizations for arithmetic, block @ IF 1logical and statements. Elimination of unreachable code. An optional warning message unreachable statements in the source indicate to issued is program. PROGRAMMING CONSIDERATIONS ® Recognition ® Removal ® Local register are retained of of memory and replacement of invariant common computations assignment. (if possible) references needed. from DO loops. Frequently-referenced in registers to reduce e Assignment of frequently-used registers across DO loops. ® Assignment of references to e Constant pooling. Storage is allocated for only one constant in the compiled program. Constants base COMMON variables registers, blocks. to immediate-mode operands are not includes most numeric constants. and provide shorter allocated ® Fast calling sequences for the real and double versions of some processor-defined functions. ® Reordering the evaluation number of temporary values e Delaying unary minus and .NOT. negation/complement operations. e Partial evaluation of Boolean expressions. in the following expression has the value evaluated: expansion e Optimization of ® Peephole GO for TO control optimization examining code operations that operations. Characteristics some processor-defined of expressions, required. operations to to to address copy of a used as storage. This In-line code variables the number expressions ® IF (el.AND.e2) 8.2.1 subexpressions. functions. precision minimize eliminate the wunary For example, if el .FALSE., e2 is not 20 transfers. of instruction sequences; i.e., on an instruction-by-instruction basis to find can be replaced by shorter, faster equivalent of Optimized Programs Optimized programs produce results and run-time diagnostic messages identical to those produced by an equivalent unoptimized program. An optimized program may produce fewer run-time diagnostics, however, the diagnostics may occur at different source program statements. example: Unoptimized 10 Program Optimized A = X/Y B = X/Y DO 10, I =1,10 C(I) = C(I)*(X/Y) Program t = X/Y A=t B 10 =t Do 10, 1 = 1,10 C(I) = C(I)*t and For PROGRAMMING CONSIDERATIONS In the example above, if Y has the value 0.0, the unoptimized program produces 12 zero-divide errors at run time; the optimized program (Note that t is a temporary variable created by the produces 1. compiler.) Eliminating redundant calculations and moving invariant calculations out of loops can affect detection of such arithmetic errors, and should be kept in mind when you include error-detecting routines in your program. Compile-Time Operations on Constants 8.2.2 The compiler performs the following computations on expressions involving constants (including PARAMETER constants) at compile time. e Negation of Constants: Constants signs are negated at compile time. For pfeceded by wunary minus example: X = -10.0 is compiled as a single move instruction. e Type Conversion of to converted compile time. For the Constants: data Lower ranked constants are type of the higher ranked operand at example: X = 10*Y is compiled as X = 10,0*Y e Arithmetic on Integer, Real, and Double Precision Constants: Expressions involving +, -, *, or / operators are evaluated at compile time. For example: PARAMETER NN = 27 I = 2*NN+J is compiled as I = 54+4J Array subscript calculations involving compile time wherever possible. constants example: For - DIMENSION I(10,10) I(1,2) = I(4,5) is compiled as a single move instruction. are simplified at PROGRAMMING CONSIDERATIONS 8.2.3 Source Program Blocks Some optimizations are performed within the confines of a single block of the source program, where a block consists of a sequence of one or more FORTRAN source defined by transfer from a statements. labeled another The statement statement (GO start that of 1is TO, a block the is target arithmetic 1IF, generally of a or by an ENTRY statement. The following kinds of statement however, do NOT generally define the start of a new block: ® unreferenced ® a label terminating a DO loop, label occur in DO statements ® labels of FORMAT statements; labeled, but control cannot statement labels with a single reference example: IF 40 ® (I.EQ.0) GO labels, labels if the TO only references to FORMAT be statement ® control ERR=option); that statements transferred to precedes the must a be FORMAT 1label. labels for which IF (A) X =1 10 40 the only or reference logical IF is in statement. an immediately For example: 10,20,20 A block can contain one or more DO loops, as 1long as none of labels within the 1loops defines the start of a new block. Thus following examples are considered single blocks and are optimized Example For CONTINUE preceding arithmetic complete the units: the the as 1 X = B*C po 10 10, 1=1,N A(I) = A(I)/(B*C) 20 po 20, Y(J) = Example 10 20 J=1,N Y(J)+B*C 2 Do 20, 1=1,N bo 20, J=1,N SUM = 0.0 DO 10, K=1,N SUM = SUM+A(I,K)*B(K,J) C(I,J) = SUM A more thoroughly optimized object program is produced if the number of separate blocks is minimized. Common subexpression, code motion, and register allocation optimizations are performed within single blocks. PROGRAMMING CONSIDERATIONS 8.2.4 Eliminating Common Subexpressions The same subexpression often appears a program. B*C+E*F A+G-B*C it A o within IF For 1in more than one computation example: ((B*C)-H)10,20,30 In this code sequence, the common subexpression B*C appears three times. If the values of the operands of this subexpression do not change between computations, its value can be computed once and the result can be used in place of the subexpression. Thus, the sequence shown above is compiled as follows: t A = = B*C t+E*F H = A+G-t IF ((t)-H)10,20,30 As you can see, two computations of B*C have been eliminated. Of course, you could have optimized the source program itself to preclude the redundant calculation of B*C. The following example shows a more significant application of this kind of compiler optimization, in which you could not reasonably modify the source code to achieve the same effect. Without optimization, the statements DIMENSION A(25,25), A(I,J) = B(I1,J) can be B(25,25) compiled as tl = J*25+1 t2 = J*25+1 A(tl)=B(t2) Variables tl and t2 represent equivalent expressions. The compiler eliminates this redundancy by producing the following optimization: t = J*25+1 A(t)=B(t) PROGRAMMING CONSIDERATIONS 8.2.5 Removing Invariant Computations Execution speed is enhanced loops. For example, if the DO 10 F = 10, T from Loops by taking invariant computations out of compiler detected the following sequence =1,100 3.0%Q*A(I)+F it would recognize each time the loop that the subexpression 3.0*Q has the is executed. Thus, it would change the same value sequence to t = 3.0%Q DO 10, I = 1,100 F = t*A(I)+F 10 This moves the calculation multiply operations. of 3.0*Q out of 8.2.6 Compiler Optimization Example Figure 8-1 illustrates many of the the optimization 1loop, and techniques saves used by 99 the VAX-11 FORTRAN IV-PLUS compiler. The complete VAX-11l FORTRAN subroutine, a first part relaxation in engineering function used to subroutine 1is a 2-dimensional a variable at coordinates on a surface; for applications. This obtain the values of example, temperatures distributed (Figure 8-la) shows a function often used across a metal plate. The second part (Figure 8-1b) shows the VAX-11l machine code generated by the FORTRAN compiler. Several compiler optimizations are illustrated, as noted by circled numbers next to the generated code lines. These are described in the notes that follow the figure. 0001 SUBROUTINE 0002 0003 0004 PARAMETER M=40, N=60 DIMENSION X (0:M,0:N) COMMON X 0005 LOGICAL DONE DONE .TRUE. 0006 0007 0008 0009 0010 0011 1 Do DO 10 = RELAX2 (EPS) 10 J = 1,N-1 10 I = 1,M-1 XNEW = ( X(I-1,J)+X(I+1,J)+X(I,J3-1)+X(1,J+1) ) / IF ( ABS (XNEW-X(I,J)) .GT. EPS ) DONE = ,FALSE. X(I,J) = XNEW 0012 IF (.NOT. 0013 0014 RETURN END Figure DONE) 8-la GO TO RELAX 1 Source Program 4 PROGRAMMING 0000 { .TITLE RELAX2 .IDENT 01 .PSECT S$BLANK .PSECT $CODE 0000 X 0000 0000 0000 RELAX2:: 0002 0009 .WORD "M<1V,R5,R6 ,R7,R8,R9,R10,R11> MOVAL S$SLOCAL, R1l i 0009 MNEGL #1, 000C MOVL #1, R7 MOVAL O00F 00le L$IANE: 0016 0019 001D MOVL MULL3 LSIAGG: 001D ADDL3 0021 ADDF3 ADDF2 ADDF2 0029 002F 0035 1 S$BLANK, R5 #1, 0006 ; 0007 ; 0008 ; 0009 ; 0010 ; 0011 ; 0012 @ RY #41, R7, R6‘, R9, R6, R10 X+4(R5) [R10], X-4(R5) [R10], X-164(R5) [R10], RO X+164 (R5) [R10], RO MULF3 ; DONE (R11) RO #"X3F80, RO, R8 @ 003D 0042 SUBF3 0047 004B CMPF BLEQ LSIAPI 004D CLRL DONE (R11) 004F CONSIDERATIONS X(R5) [R10], BICW2 #°X8000, RO, R8, RO RO (7} Q@EPS (AP) LS$SIAPI: 004F MOVL R8, X(R5)[R10] 0053 AOBLEQ #39, 0057 005B AOBLEQ #59, MOVL R7, 005F 0063 MOVL R8, LSIAGG LSIANE J(R11l) XNEW(R1l1l) MOVL R9, I(R1ll) 0067 006A BLBC DONE (R11), RY9, R7, .1 RET .END Figure Notes for Figure 8-1b RELAX Machine Code 8-1 Register assignment for J Register assignment for a Register assignment for 1I base Invariant computation (J*41) assigned to a register Common (Optimized) subexpression assignment; 6 uses register removed evaluation are made of the for from and value blank the COMMON inner local loop and register PROGRAMMING Notes for Figure 8-1 (Cont.) Peephole optimization; multiply by 0.25. Inline ABS CONSIDERATIONS a divide FORTRAN 4.0 1is replaced by a function DO loop control using the Add One Equal (AOBLEQ) instruction 8.3 by and Branch Less Than or programs FORTRAN by I/0 I/0 SYSTEM CHARACTERISTICS You can often reduce use of the making the execution time of your FORTRAN following facts relevant to the subsystem. Unformatted I/0 is substantially faster and more accurate than formatted 1I/0. The unformatted data representation usually occupies less file storage space as well. Thus unformatted I/0 should be used for storing intermediate results on secondary storage. Specifying an array name using an equivalent in an I/O implied list is more efficient DO 1list. A single transmission call passes an entire array, list can pass only a single while an implied array element per than 1I/0 DO I/0 call. The implementation of the BACKSPACE statement involves repositioning the file and scanning previously processed records. If a reread capability is required, it 1is more efficient to read the record into a temporary array and DECODE the array several times than to read and backspace the record. To obtain minimum I/0 processing, the record length access sequential organization files should be a multiple of the device block size of 512 bytes bytes, 64 bytes, etc.). For relative organization adds one overhead byte for fixed 1length records overhead bytes for variable length records. of direct divisor or (e.g., 32 files, RMS and three If the approximate size of the file 1is known, it 1is more efficient to allocate disk space when a file is opened than to incrementally extend the file as records are written. The use of run-time formats should be minimized. The compiler preprocesses FORMAT statements into an efficient internal form. Run-time formats must be converted into this internal form at run time. In many cases, using variable format expressions will allow the format to vary at run time. The BLOCKSIZE keyword can be used in an OPEN statement to obtain large amounts of data with each physical I/0 operation, thereby greatly improving the processing of sequentially accessed files. For example, specifying a BLOCKSIZE of 4096 bytes results in the transfer of 8 disk blocks for each 1I/0 operation. PROGRAMMING CONSIDERATIONS CLOSE The OPEN and files. and devices provide statements explicit control over 1I/0 Using these statements in the proper manner can help create efficient source programs, as illustrated in the following examples. e OPEN (UNIT=1, TYPE='NEW', INITIALSIZE=200) is file This statement allocates space for a file when the opened, which is more efficient than extending the size of the file dynamically. e OPEN (UNIT=3, TYPE='NEW', BLOCKSIZE=8192) 1I/0 for factor This statement specifies a large blocking If the file is on magnetic tape, the physical tape transfers. disk 16 if the file is on disk, blocks are 8192 bytes long; transferred by each I1/0 operation, thus enhancing are blocks though requiring more memory. I/0 performance, e OPEN (UNIT=J, (IERR) IF TYPE='NEW', CLOSE (UNIT=J, DISP='DELETE') DISP='SAVE') (UNIT=J, CLOSE ...) A file is created. However, if an error occurs that makes the file invalid or useless, it is deleted. e OPEN (UNIT=2, FORM='FORMATTED', CARRIAGECONTROL='LIST') This statement creates a file with implicit carriage control. The first character of each record is NOT used for carriage control, thus it can contain actual data. ® CHARACTER*64 TYPE 1 FORMAT ('SINPUT FILE?') 100 101 9 102 FILNAM 100 ' ACCEPT 101 ,FILNAM FORMAT (A) OPEN (UNIT=3, NAME=FILNAM, TYPE 102, FORMAT GO TO (' TYPE='OLD', ERR=9) FILNAM ERROR OPENING FILE ',A) 1 This program reads a file specification into the character 1is then qpened for processing. file The variable FILNAM. This permits you to specify the input file name at run time. APPENDIX A FORTRAN DATA REPRESENTATION A.1 INTEGER*2 FORMAT 0 15 14 BINARY NUMBER S S(sign) = 0(+), 1(-) INTEGER*2 Integers are stored in a two's complement representation. values 1lie in the range -32768 to +32767, and are stored in two For example: contiguous bytes aligned on an arbitrary byte boundary. +22 -7 A.2 0016 (hex) FFF9 (hex) INTEGER*4 FORMAT 0 31 30 BINARY NUMBER S S(sign)=0(+), 1(-) INTEGER*4 values are INTEGER*4 values 1lie value is stored in four Note that boundary. i.e., -32768 to value; as an INTEGER*2 value. A.3 stored in two's complement representation. in the range -2147483648 to 2147483647. The contiguous bytes, aligned on an arbitrary byte if the value is in the range of an INTEGER*2 +32767, then the first word can be referenced FLOATING-POINT FORMATS The exponent for both floating-point formats is stored in excess 128 Binary exponents from -128 to +127 are represented by the notation. Fractions are represented 1in binary equivalents of 0 through 255. sign-magnitude notation with the binary radix point to the left. the most therefore, Numbers are assumed to be normalized and, significant bit is not stored, because it is redundant (this is called "hidden bit normalization"). FORTRAN DATA REPRESENTATION This to bit is assumed 2**-128) represented example, in by +1.0 to be which an a exponent would be 1 case unlegs the exponent is it is assumed to be field of 0 a sign represented and in hexadecimal 0. 0 (corresponding The bit value of 0.0 0. is For by: 4080 0 in the 4-byte format, or: forsmat. The decimal 4080 0 0 0 in the 8-byte number -5.0 is: COAOQ V] in the 4-byte format, or: COAOQ 0 0 0 in the A.3.1 8-byte Real format. Format (4-Byte Floating Point) A single precision real number is four contiguous arbitrary byte boundary. Bits are labeled from 31. 15 14 S 7 EXPONENT 6 bytes starting on an the right, 0 through 0 FRACTION FRACTION 3 S(sign)=0(+), The 15 form of the sign and 31:16 a 16 1(-) a single precision real number is sign magnitude, with bit, bits 14:7 an excess 128 binary exponent, and bits normalized 24-bit fraction with the redundant bit 6:0 most significant fraction bit not represented. The value of a single precision real number is 1in the approximate range: .29%1(0**-38 through 1.7*10**38. The precision is approximately one part in 2**23, i.e., typically 7 decimal digits. FORTRAN DATA REPRESENTATION A.3.2 Double Precision Format (8-Byte Floating Point) A double precision real number is eight contiguous bytes, starting on an arbitrary byte boundary. Bits are 1labeled from the right, 0 through 63. 7 15 14 S 0 6 FRACTION EXPONENT FRACTION FRACTION FRACTION 48 63 S(sign)=0(+), 1(-) The form of a double precision real number is identical to a single precision real number except for an additional 32 low significance of range approximate and The exponent conventions, fraction bits. is The precision single precision. as same the are values approximately one part in 2**55, i.e., typically 16 decimal digits. A.3.3 Complex Format A complex number is eight contiguous bytes, aligned on an arbitrary byte boundary. The 1low-order four bytes contain a single precision real number that represents the real part of the complex number. The high-order four bytes contain a single precision real number that represents the imaginary part of the complex number. 15 14 76 S | BINARY EXCESS 128 EXP 0 FRACTION REAL PART FRACTION S |BINARY EXCESS 128 EXP FRACTION IMAGINARY PART FRACTION 63 48 FORTRAN DATA REPRESENTATION A.4 LOGICAL*1 FORMAT DATA ITEM The range format. A.5 of numbers from +127 to -128 can be represented in LOGICAL*1l CHARACTER FORMAT i Character data is stored as one character if necessary, to fill the data item. 15 A.6 8 per byte, 7 padded with blanks 0 CHAR 2 CHAR 1 CHAR 4 CHAR 3 BLANK =40 CHAR N (N<255) HOLLERITH FORMAT 15 8 7 0 CHAR 2 CHAR 1 CHAR 4 CHAR 3 BLANK =40 CHAR N (N<255) Hollerith constants are stored internally one character Hollerith values are padded on the right with blanks associated data item if necessary. per byte. to fill the FORTRAN DATA REPRESENTATION A.7 LOGICAL FORMAT Logical values are stored in two or four contiguous bytes, starting on an arbitary 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.. LOGICAL*2 15 TRUE: 10 . UNDEFINED BITS 15 FALSE: 1 10 UNDEFINED BITS 0 LOGICAL*4 15 TRUE: 10 UNDEFINED 1 BITS 31 16 15 10 FALSE: UNDEFINED 0 BITS 31 16 APPENDIX B DIAGNOSTIC MESSAGES B.1 DIAGNOSTIC MESSAGES Diagnostic messages come from compiler unmatched OVERVIEW related to a VAX-1l compiler, the 1linker, detects syntax errors in or the the illegal characters, parameters. The Run-Time DIAGNOSTIC MESSAGES FROM THE 1IV-PLUS program can Run-Time Library. The source parentheses, missing or illegal that occur during execution. (Linker VAX-11l Linker Reference Manual.) B.2 FORTRAN the program, misspelled such as keywords, Library reports messages are summarized and errors in the COMPILER The diagnostic messages issued by the compiler describe the error that has been detected, and in some cases contain an indication of the action taken by the compiler in response to the error. Besides reporting errors detected in source program compiler will issue messages 1indicating errors that compiler itself, such as I/0 errors, stack overflow, etc. B.2.1 syntax, involve the the Source Program Diagnostic Messages Three classes of source severity of the error. F E Fatal; must program errors are recognized, based on the These are (from greatest to least severity): before the compiled. No object file is detected during compilation. produced if Error; be not be fatal corrected but should program an corrected. F-class An can be error is object is produced in spite of the presence of an E-class but the program will probably not execute properly. W Warning; issued non-standard for syntax, statements and for that use statements file error, acceptable, but corrected the by compiler. An object file is produced but you should check the statements to which a W-class diagnostic message applies, to make sure the program will produce the correct result. Note that W-class messages are produced unless the /NOWARNINGS qualifier is set in the FORTRAN command. DIAGNOSTIC Typing mistakes are a likely cause of compiler to generate misleading especially of the following: 1. Missing comma or parenthesis FORMAT MESSAGES syntax errors, and can cause the diagnostic messages. Beware in a complicated expression or statement. 2. Misspelled variable names. The compiler may not detect error, so execution can be affected. 3. Inadvertent 1line continuation mark. This diagnostic message for the preceding line. 4. Confusion between letter O, which identical to you, can the digit =zero (0) and the can result in variable names but not to the compiler. cause this a wupper-case that appear Another source of diagnostic messages 1is the inclusion of invalid ASCII characters in the source program. With the exception of the tab, space, and form-feed characters, non-printing ASCII control characters are not valid in a FORTRAN source program. As the source program is scanned, such invalid characters are replaced by a question mark (?). However, because ? cannot occur in a FORTRAN statement, a syntax error usually results. Thus, because the message indicates only the immediate should always check the entire source statement carefully. cause, you Figure B-1 shows the form of source program diagnostic messages as they are displayed at your terminal, in interactive mode. Figure B-2 shows how these messages appear in listings. $FORT-W-ERROR 83, Extra comma in format list [FORMAT (I3,)] in module MORTGAGE at line 9 $FORT-F-ERROR 69, Undefined statement label [ 66] in module MORTGAGE at line 14 $FORT-I-ERRSUM, Figure B-1 2 Errors MORT.FOR.10 Sample Diagnostic Messages (Terminal Format) " DIAGNOSTIC MESSAGES PROGRAM TO CALCULATE MONTHLY MORTGAGE PAYMENTS C PROGRAM MORTGAGE 0001 0002 0003 0004 0005 0006 0007 0008 0009 TYPE 10 20 40 (' ENTER AMOUNT OF MORTGAGE ') ACCEPT 20,IPV FORMAT (I6) TYPE 30 10 FORMAT 30 FORMAT (' ENTER LENGTH OF MORTGAGE IN MONTHS ') ACCEPT 40,IMON FORMAT (I3,) $FORT-W-ERROR 83, Extra comma in format list [FORMAT (I3,)] in module MORTGAGE at line 9 0010 0011 0012 0013 0014 0015 0016 0017 0018 0019 0020 0021 0022 0023 TYPE 50 60 65 50 FORMAT (' ENTER ANNUAL INTEREST RATE ACCEPT 60,YINT FORMAT (F6.4) GO TO 66 YI = YI FIMON = FIMON = FMNTHLY TYPE 70 IGET MONTHLY RATE YI = YINT/12 IMON = FIPV = 0024 STOP 0025 END -IMON IPV*YI +1 YI ** IMON 1-FIMON = FIPV/FIMON 70,FMNTHLY FORMAT ') ) (' MONTHLY PAYMENT EQUALS ', F7.3 ) $FORT-F~ERROR 69, Undefined statement label [ 66] Figure B-2 in module MORTGAGE at line 14 Sample Diagnostic Messages (Listing Format) DIAGNOSTIC MESSAGES Table Source B-1 Program Diagnostic Messages Message Number 1 Text/Meaning Statement A too statement subdivided Compiler complex is too into complex two to or more expression stack be compiled. complex or a subprogram arguments can be expression, there are reference. many named COMMON Reduce the number Source line too A source line Too Up by many COMMON compilation than compiler line. continuation blocks. terminated 88 characters was encountered. examines only the first 72 lines, remainder ignored to 99 continuation lines are permitted, as determined the /CONTINUATIONS=n qualifier (default, 19). Syntax The error file invalid name failure The an specified incorrect unmounted INCLUDE Reduce number file lines. in INCLUDE string qualifier, Open the on file is not specification acceptable undefined INCLUDE device, (invalid file or nested a protection too violation. deeply level of INCLUDE nesting or continuation 1lines permitted. requires space equivalent to two of statement improperly letters) has initial line. syntax, etc.). file could not be opened, possibly due to file specification, non-existent file, volume, files Invalid An named long, a You can number of blocks longer NOTE: The characters on of be too many A maximum compiled. reduce the or arguments. Too must overflow An expression is too actual arguments in of 60 actual subdivide a complex It statements. label continuation ignored formed statement been detected The increase the Each INCLUDE statement label (e.g., in columns 1 label is containing 5 of an - ignored. (continued on next page) DIAGNOSTIC MESSAGES Table B-1 (Cont.) Source Program Diagnostic Messages Message Number 10 Text/Meaning Redundant continuation mark ignored A continuation mark was detected where is required. The continuation mark is 11 Extra characters Superfluous correct 12 following text was statement. Overflow while expression found Check a valid at the for 13 Missing exponent after A floating point notation, but the 14 Missing A 15 or of or a syntactically syntax is too must constant 1large or too D in character constant errors. or constant was specified exponent was omitted. apostrophe character E end constant The specified value of a constant small to be represented. 1line statement typing converting an initial ignored. be in E or D constant enclosed by apostrophes. Zero-length string The length hexadecimal, specified octal or for a character, Radix-50 constant Hollerith, must not be zero. 16 String constant A character characters. or A truncated Hollerith Radix-50 to maximum length constant can contain up to constant can contain up to 255 12 characters. 17 Count of Hollerith or Radix50 constant too large, reduced The is value specified by greater than the the source the integer preceding the H or number of characters remaining R in statement. (continued on next page) DIAGNOSTIC MESSAGES Table B-1 (Cont.) Source Program Diagnostic Messages Message Number 18 Text/Meaning E Invalid character used in constant An invalid character was detected in a constant. characters Hexadecimal: Octal: Radix-50: For Radix-50, character. constant 1s 20 21 space For set to is a 8, name or for or the octal, subprogram space 1invalid the name entire was not constant required Missing period, and A required found. variable f substituted hexadecimal zero. subprogram name A 22 a 0 - 9, A - F, 0 - 7 A-12%2,0-9, Missing variable or Missing Valid are: constant was variable or An expression, or a omitted. Examples: not found. constant term of an expression, has been WRITE ( ) DIST = *TIME 23 Missing operator or delimiter symbol Two terms of an expression are not separated by an operator, or a punctuation mark (such as a comma) has been omitted. Examples: CIRCUM = IF (I 24 Missing A 25 statement label required Missing 3.14 DIAM 10,20,30 statement label Non-integer as TO, 10 TO I. expression where An expression data omitted. keyword A required keyword, such statement such as ASSIGN 26 reference was that must be of was integer type omitted value INTEGER from a required was another type. (continued on next page) ‘ DIAGNOSTIC MESSAGES Table B-1 (Cont.) Source Program Diagnostic Messages Message Number 27 Text/Meaning Non-logical expression where logical value required An expression data 28 of type LOGICAL was Arithmetic expression where character value An expression data 29 that must be another type. that must be of required type CHARACTER was another type. Character expression where arithmetic value required An expression that must be arithmetic (INTEGER, REAL, LOGICAL, DOUBLE PRECISION, or COMPLEX) was of type CHARACTER. 30 Variable name, constant, or expression invalid in this context A quantity has been used incorrectly; for example, the name of a subprogram was used where an arithmetic expression is required. 31 Operation not permissible on these data An invalid operation was specified, two real variables. 32 Arguments supplied incompatible with such function, types as .AND. assumed of user A function reference was made, using a processor-defined function name, but the argument list does not agree in order, number, or type with the processor-defined function requirements. The function is assumed to be supplied by you as an EXTERNAL function. 33 Subscripted reference to non-array variable A variable that is not defined with subscripts. 34 Substring reference used in as an array cannot appear invalid context A substring reference has been detected to a variable or array that is not of type CHARACTER. Example: REAL X (10) Y 35 = Number of More or declared X(J:K) subscripts does not match array declaration fewer dimensions for the array. are referenced than were (continued on next page) DIAGNOSTIC MESSAGES ’ Table B-1 (Cont.) Program Diagnostic Messages Source Message Number 36 Text/Meaning More An than 7 array dimensions can be specified, defined as remainder having ignored up to seven dimensions. 37 Non-constant subscript where Subscript and EQUIVALENCE 38 Adjustable substring statements array constant expressions must bounds be must required used in DATA and constants. be dummy arquments or in COMMON Variables must specified either be in dimension declarator expressions subprogram dummy arguments or appear in a in COMMON. 39 Adjustable A reference where 40 such Passed A array was made a length reference array to 1in to a Lower bound declaration The to 43 upper or Character greater bound greater of than substring adjustable not name a a array used passed in invalid length such the specified outside the than upper lower limits context character reference out of array is or bounds, bound in must not bounds dimensions, specified dimension declarator the context allowed. expression value beyond character substring been referenced. 42 an context context where substring element invalid is character was made Subscript or An in reference or variable allowed. 41 used be a has array equal bound. out of The first character position of a is greater than the last character order substring position. expression Example: C(5:3) (continued on next page) DIAGNOSTIC MESSAGES Table B-1 (Cont.) Program Diagnostic Messages Source Message Text/Meaning Number 44 F Invalid use of A CALL statement used as included that was FUNCTION name referred in CALL to a statement subprogram name that was a character function; or a CALL statement that alternate return specifiers referred to a name defined as a data type other than INTEGER*4. Examples: 1. IMPLICIT CHARACTER*10 (C) CSCAL = CFUNC (X) CALL CFUNC (X) 2. REAL*4 CALL 45 E $VAL, TCB TCB(Y,&100) %REF, or $%$DESCR used in invalid context The argument 1list built-in functions $DESCR) cannot be used outside an actual Example: X 46 F = Invalid argument to %VAL, $REF, $DESCR, of the $VAL (3.5D0) - argument cannot be character, or complex. $LOC (X+Y) - argument F Alternate An $REF, list. %REF(Y) The argument specified for one is not valid. For example: 47 (%VAL, argument return alternate label return must used not in argument be $%LOC built-in functions double precision, an invalid was or expression. context used in a function to characters. reference. 50 W Name A 51 longer symbolic F Multiple A name than name 15 has characters been declaration of appears in two or truncated 15 name more inconsistent declaration statements. 52 E Multiple used declaration A variable declaration used. of appears 1in statement. data type more The for than first variable, first one data type type declaration is (continued on next page) DIAGNOSTIC MESSAGES Table B-1 (Cont.) Program Diagnostic Messages Source Message Number 53 Text/Meaning Syntax error in IMPLICIT Improper syntax was Refer to the VAX-11] Manual for the syntax 54 Letter mentioned statement used in an IMPLICIT statement. FORTRAN IV-PLUS Language Reference rules. twice in IMPLICIT statement, A letter has been given an implicit data once. The last data type given is used. ‘55 Incorrect length modifier type more used than in declaration An unacceptable length has been specified in declaration (see "Type Declaration" in a data type the VAX-1l1l FORTRAN Example: IV-PLUS INTEGER 56 last Left side element Language Reference Manual). PIPES*8 of assignment must be variable or array The symbolic name to which the value of an expression is assigned must be a variable, array element, or character substring reference. 57 Length specified declaration The length character must match character function specifications for all ENTRY names subprogram must be the function in a same. Example: CHARACTER*15 CHARACTER*20 ENTRY 58 FUNCTION G F G Inconsistent function data types All entry names in a function subprogram must character or numeric. Example: CHARACTER*15 REAL ENTRY 60 FUNCTION be either F X X Undimensioned array or function definition out of order Either a statement function definition has been found among executable statements, or an assignment statement has been detected 1involving an array for which dimensions have not been given. (continued on next page) DIAGNOSTIC MESSAGES Table B-1 (Cont.) Source Program Diagnostic Messages Message Text/Meaning Number 61 Statement out of order, statement ignored The order of statements was not as specified in VAX-11 FORTRAN IV-PLUS Language Reference Manual. * statement found out of order is 1ignored. 62 in Statement not valid this unit, program the The statement ignored ; A program unit contains a statement that is not allowedan ns contai gram subpro DATA example, a BLOCK for executable statement. 63 Statement cannot appear in logical IF statement A logical IF statement must not contain a DO statement or another logical IF, IF THEN, ELSEIF, ELSE, ENDIF, or END statement. 64 No path to this statement Program control cannot statement is deleted. reach statement. this The Example: 10 I=1I+1 GO TO 10 STOP 65 Missing END statement, END is assumed An END statement was missing at the input file, and has been inserted. 66 end the Statement cannot be labeled, label ignored A label was placed on a statement that does labels. 67 of The label is ignored. not last permit Inconsistent usage of statement label Labels of executable statements have been confused with labels of FORMAT statements. Example: 10 68 GO TO 10 FORMAT (I5) Multiple definition of a statement label, second ignored The The same label appears on more than one statement. first occurrence of the label is used. (continued on next page) Source DIAGNOSTIC MESSAGES Table (Cont.) B-1 Program Diagnostic Messages Message Number 69 Text/Meaning F Undefined statement label Reference has been made to a defined in the program unit. 70 F DO and DO loops and levels. 20 IF statements block nested IF statement too label that is not deeply statements cannot be nested beyond 71 One of 1. A statement label specified been used previously. the following conditions was in found: a DO statement has 1loop IF Example: 10 I=I+1 J=J+1 DO 2. A DO loop block. 10 K=1,10 contains an incomplete DO or Examples: DO 10 1=1,10 J=J+1 DO 20 10 The start IF, ELSEIF K=1,10 J=J+K CONTINUE of the or DO incomplete ELSE 10 IF block statement. can be a block next page) 1=1,10 J=J+1I IF (J.GT.20) THEN J=J-1 ELSE 10 J=J+1 CONTINUE ENDIF (continued on DIAGNOSTIC MESSAGES (Cont.) Table B-1 Source Program Diagnostic Messages Message Text/Meaning Number 72 F Invalid control structure using ELSE IF, ELSE, or ENDIF The order incorrect. of or ELSE, ELSEIF, statements ENDIF 1is ELSEIF, ELSE, and ENDIF statements cannot stand alone. ELSEIF and ELSE must be preceded by either a block IF statement preceded statement. or by statement. IF, an ELSEIF either a block ENDIF ELSEIF, be must or ELSE Examples: po 10 1=1,10 J=J+1 ELSEIF Error: (J.LE.K) THEN ELSEIF preceded by a DO statement. IF (J.LT.K) THEN J=1I+J ELSE J=I-J ELSEIF (J.EQ.K) THEN ENDIF ELSEIF preceded by an ELSE statement. Error: 73 Unclosed DO loop or IF block The terminal statement of a DO loop statement of an IF block was not found. or the ENDIF Example: Do 20 1=1,10 X=Y END 74 Statement cannot terminate a DO loop The terminal statement of a DO loop cannot be a GO TO, arithmetic IF, RETURN, block IF, ELSE, ELSEIF, ENDIF, DO or 75 END statement. ENTRY within DO loop or IF block, statement ignored An ENTRY statement is not allowed within the range of DO loop or 76 a IF block. Assignment to DO variable within loop The control variable of a DO loop within the range of the DO statement. has been altered (continued on next page) DIAGNOSTIC MESSAGES ‘Table B~1 (Cont.) Program Diagnostic Messages Source Message Number 77 Text/Meaning F Alternate return subprogram specifier invalid in FUNCTION The argument list of a FUNCTION declaration contains an asterisk, or a RETURN statement in a function subprogram specifies an alternate return. Examples: 1. INTEGER FUNCTION TCB (ARG, * ,X) 2. FUNCTION RETURN IMAX I+J END 78 E Alternate return omitted in -SUBROUTINE or ENTRY statement An asterisk is missing in the argument 1list of subroutine for which an alternate return is specified. For a example: SUBROUTINE RETURN XYZ (A,B) 1 Or: ENTRY MIN(Q,R) RET&RN I+4 80 81 E E Format groups nested too Format groups cannot be Unbalanced The of 82 parentheses deeply nested in beyond format separator between format A required separator character fields in a FORMAT statement. levels. list number of right parentheses does left parentheses. E Missing eight not match the number items has been omitted (continued between on next page) DIAGNOSTIC MESSAGES Table B-1 (Cont.) Source Program Diagnostic Messages Message Text/Meaning Number 83 Extra comma in format list FORMAT _Example: 84 (I14,) Constant in format item out of range value in a FORMAT statement exceeds the Refer to the VAX-11 FORTRAN IV-PLUS range. A numeric allowable Language Reference Manual. 85 Format item contains meaningless character An invalid character or a syntax error was detected in a FORMAT 86 statement. Format item cannot be signed A signed constant is valid only with the P format code. 87 Missing number in format list FORMAT Example: 88 Extra number in format list FORMAT Example: 89 (F6.) (I4,3) Invalid I/0 specification for this type of I/O statement an I/0 The format specifier in an I/O statement is invalid. It A syntax error was found in the portion statement that precedes the I/O list. of Examples: TYPE (6),J WRITE 100,J 90 Format specifier in error must be one of the following: e label of a FORMAT statement e * e 91 (list directed) a run-time format specifier: variable, element, or character substring reference. array END= or ERR= specification given twice, first used Two instances of either END= or ERR= were found. Control 1is transferred to the location specified in the first occurrence. (continued on next page) Source DIAGNOSTIC MESSAGES Table (Cont.) B-1 Program Diagnostic Messages Message Number 92 Text/Meaning Syntax error Improper 93 Missing An 94 I/0 in I/O list syntax was detected I/0 I/0 an I/0 not present where list element for required. input statement An input statement I/O list contains such as an expression or a constant. 95 Duplicated Each can 96 An keyword in OPEN/CLOSE keyword subparameter in be specified only once. UNIT= keyword OPEN or missing CLOSE in Incorrect A CLOSE keyword statement in an OPEN 100 Number of CLOSE The number match of contains a exceeds constants the number must number Number o0f values exceeds that of in variables be initialized. The remaining elements are not initialized. 101 CLOSE statement include keyword specified of or statement statement must element, the UNIT= valid only statement statement. names invalid statement OPEN/CLOSE statement in an an OPEN subparameter. 97 list. list list was Invalid in is values a or DATA array variables number of in DATA statement elements and/or names in statement to array DATA The number of variables or array elements to be initialized must match the number of constants specified in a DATA statement. The remaining constant values are ignored. 102 Invalid repeat count in DATA The repeat count in a DATA nonzero integer constant. 103 Constant size A constant in corresponding exceeds statement, statement is not It is ignored. variable a DATA variable. count size statement in DATA 1is an unsigned, statement larger (continued ignored on than next its page) DIAGNOSTIC MESSAGES Table B-1 (Cont.) Source Program Diagnostic Messages Message Number 104 Text/Meaning E Character name incorrectly 1initialized with numeric value Character data with initialized with a a 1length greater than 1 was numeric value in a DATA statement. Example: CHARACTER*4 A DATA A/l4/ 105 F Program storage requirements exceed addressable memory The storage space allocated to the variables and arrays of the program unit exceeds the addressing range of the machine. 106 F Variable inconsistently equivalenced EQUIVALENCE relationships to itself statements specify between variables or inconsistent array elements. Example: EQUIVALENCE 107 F Invalid equivalence Variables other. 108 F (A(1l) ,A(2)) in EQUIVALENCE of COMMON two variables cannot statement be in COMMON equivalenced incorrectly expands a A COMMON block cannot be extended beyond by an EQUIVALENCE statement. 109 W Mixed numeric A COMMON character 110 W Mixed and block data. numeric and character must elements not contain character elements Numeric and character variable be equivalenced to each other. 111 E Invalid initialization of An aftempt was made, initialize B.2.2 a variable in and variable a that BLOCK is not in each COMMON block its beginning COMMON both numeric and in EQUIVALENCE array not DATA in to a elements cannot in COMMON subprogram, common block. to Compiler-Fatal Diagnostic Messages Conditions can be encountered of such severity that compilation must be terminated at once. These conditions are caused by hardware errors, software errors, and errors that require changing the source program. Table B-2 1lists the diagnostic messages that report the occurrence of such compiler-fatal errors. B-17 DIAGNOSTIC MESSAGES Table B-2 Compiler-Fatal Diagnostic Messages Message Number Text/Meaning 201 Open error on work file on WKO: 202 Open error on file on WKO: temp FORTRAN IV-PLUS creates a temporary work file and zero, one, or two temporary scratch files during the compilation process. The compiler was unable to open these required files. Possibly the volume was not mounted, space was not available on the volume, or a protection violation occurred. 203 I/0 error on work file on WKO: 204 I/0 error on temp file on WKO: 205 I/0 error on source file 206 I/0 error on object file 207 I/0 error on listing file I/0 errors report either hardware I/0 errors, software error conditions such as an attempt to write a write-protected volume. 208 Compiler dynamic memory overflow Reduce the reduce 209 the Compiler number INCLUDE work file of file continuation nesting depth. Compiler internal lines allowed or overflow A single program unit 1is too Specify /WORK_FILES=3 or divide units. 210 or on large to be compiled. the program into smaller consistency check An internal consistency check has failed. This error should be reported to DIGITAL in a Software Performance Report. 211 Compiler control stack overflow The compiler's control stack overflowed. Simplifying the FORTRAN source program will correct the problem. 212 Branch displacement out of range A label referenced by a GO TO statement 1is beyond the displacement 1limits of a branch in the generated code. Modify the source program to reduce the distance between the GO TO and its reference. (See "Compiler Limits," Section B.2.3.) DIAGNOSTIC MESSAGES Compiler Limits B.2.3 There are limits to the size and complexity of a single VAX-11 FORTRAN There are also limits on the complexity of IV-PLUS program unit. FORTRAN statements. 1In some cases, the limits are readily described; see Table B-3. In other cases, however, the limits are not so easily defined. For example, the compiler uses external work files to store the symbol table and a compressed representation of the source program. The the number of work files is controlled by the /WORK_FILES qualifier: maximum is 3, which provides space for approximately 2000 or more If you run lines of source code in a typical FORTRAN program unit. out of work file space, error 209 occurs. In some cases, the limits can be adjusted by re-linking and modifying and n the to 1limits suit your needs. the compiler Table B-3 shows two values for such limits, in the form m(n), where m is the default limit is the maximum. Limits for which only one value is shown are not adjustable. Table B-3 Compiler Limits Limit Language Element DO and block-IF statement nesting 20 Actual arguments per CALL or function 60 (many) (combined) reference Named COMMON blocks 44 Format group nesting 8 (250) Labels in computed or assigned 250 Parentheses nesting in expressions 40 INCLUDE file nesting 10 Continuation lines 99 FORTRAN source line length 88 characters Symbolic name length 15 characters GOTO list Constants Character, Hollerith Radix-50 Array dimensions (many) 255 characters 12 characters 7 DIAGNOSTIC Error too 212 far occurs if apart. The a branch instruction compiler within a single program displacements. Thus, a MESSAGES and generates its target references unit by means of 8-bit jump must not cross more to and than statement are executable code 16-bit relative 32K bytes. You will not reach this limit if a program unit results than 32K bytes of generated code. You are more likely work The file limit amount of executable address B.3 first. data storage, programs space are available, the size limited as of only arrays, by determined the at and amount in to no more reach the the total of process size of virtual system generation. RUN-TIME DIAGNOSTIC MESSAGES Errors that reported occur by messages during diagnostic may result errors detected between the e xecution messages from: hardware by RMS; program and an errors internal overflow of from your the FORTRAN Run-Time file system errors; that occur during transfer of data record; computations that cause calls to the Run-Time Library; and Table detected by the Run-Time Procedure Run-Time Library Diagnostic Message Presentation Run-Time terminal B.3.2 are These conditions; or underflow; incorrect problems in array descriptions and conditions operating system. Refer to the VAX-11 Common Library Reference Manual for more information. B.3.1 program Library. Library diagnostic messages are usually sent to (interactive mode) or the log file (batch mode). either your Run-Time Library Diagnostic Messages B-4 lists the Run-Time library messages. There is a HELP file available, which contains these error messages and descriptive text. Thus you can print the descriptive text at your terminal, on-line. For example, to print the text for a file system error (such HELP as a rewind error), type in the following: ERROR FOR$_REWERR The condition in Table the VAX-11l 6-1. symbols corresponding For more Common to the information about Run-Time Procedure B-20 message the Library numbers are run-time HELP Reference 1listed file, Manual. see DIAGNOSTIC MESSAGES Table B-4 Run-Time Diagnostic Messages Messages 20 through 48 indicate errors related to the (No message numbers from 2 to 19 are used.) Message system. Text/Meaning Number 1 file NOT A FORTRAN-SPECIFIC ERROR Library Run-Time the that indicates This message a by caused not that was error an encountered a was it is, That condition peculiar to FORTRAN. condition not described by any other message in this table. 20 REWIND ERROR an during RMS by detected An error condition was RMSSREWIND operation used to position a file at its beginning. 21 DUPLICATE FILE SPECIFICATIONS file specify to made attempts were Multiple intervening close operation; attributes without an i.e., DEFINEFILE followed by DEFINEFILE 22 followed statement OPEN an or by DEFINEFILE. INPUT RECORD TOO LONG the than Your program tried to read a record longer To read the file, use an OPEN size. record maximum appropriate statement with a RECORDSIZE value of the size. 23 BACKSPACE ERROR One of the following has occurred: 1. BACKSPACE was attempted opened for 2. during condition error an detected RMS RMSSREWIND operation used to rewind the file the 3. 24 on a file appending RMS detected an forward error condition to the desired record. while reading the ENDFILE END-OF-FILE DURING READ Either an end-file record produced by was condition end-of-file RMS the or statement END= no and statement READ a encountered during transfer specification was provided. (continued on next page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Run-Time Diagnostic Messages Messages 20 (No message through numbers 48 indicate errors related from 2 to 19 are used.) to the file system. Message Number 25 Text/Meaning RECORD NUMBER OUTSIDE RANGE A direct access READ, WRITE, or FIND statement specified a record number outside the range specified in a DEFINEFILE statement or in the MAXREC keyword of the OPEN statement. 26 OPEN OR DEFINEFILE REQUIRED TO SPECIFY DIRECT ACCESS A direct access READ, WRITE or FIND operation was attempted before an OPEN statement specifying ACCESS='DIRECT', or DEFINEFILE statement was performed. 27 MORE THAN ONE RECORD An attempt was made single record in statement, 28 CLOSE An or an error attempted FILE to a I/O read or write direct access ENCODE or was DECODE NOT to detected or more READ than a or WRITE statement. during RMSS$SSPOOL close the an RMSSCLOSE, operation, when RMS file. FOUND A file with the specified during an open operation. 30 STATEMENT ERROR RMSSDELETE, 29 IN OPEN FAILURE RMS detected an error name could condition not be during found an open operation. (This message 1is used when the error condition is not one of the more common conditions for which specific error messages are provided.) 31 MIXED An FILE ACCESS attempt was MODES made to wuse both formatted unformatted operations, or both sequential access operations, on the same unit. 32 INVALID LOGICAL A logical was unit UNIT number and and direct NUMBER greater than 99 or less than 0 used. (continued on next page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Run-Time Diagnostic Messages Messages 20 through 48 indicate errors related to the (No message numbers from 2 to 19 are used.) Message file system. Text/Meaning Number ENDFILE ERROR 33 a direct to An end-file record may not be written relative file, or to an unformatted a file, access sequential file that does not contain segmented records. 34 UNIT ALREADY OPEN An OPEN attempted opened for statement that or DEFINEFILE specified input/output. a 1logical statement wunit was already SEGMENTED RECORD FORMAT ERROR 35 Invalid segmented record control data was detected in was file The file. sequential unformatted an or with RECORDTYPE='FIXED' probably either created 'VARIABLE' in effect, or written by a language other than FORTRAN. ATTEMPT TO READ NON-EXISTENT RECORD 36 One of e the following has occurred: been has A direct access read to a relative file that was either record a specifying attempted, never written, e 37 ° or deleted. been has read access direct A specifying a record beyond end-of-file. attempted, INCONSISTENT RECORD LENGTH An existing direct access file was opened whose length attribute is not the same as specified record in the OPEN or DEFINEFILE statement. It is possible the file was not created as a direct access file. 38 ERROR DURING WRITE RMS detected an error condition while writing. 39 ERROR DURING READ RMS detected an error condition while reading. (continued on next page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Diagnostic Messages Run-Time Messages 20 through 48 (No message numbers from indicate 2 to 19 errors are related to the file system. used.) Message Number 40 Text/Meaning RECURSIVE I/0 OPERATION I/0 was attempted on a logical unit while that unit was involved in a preceding I/O operation. This can happen if a function that performs I/0 to the same logical unit is referenced in an expression in an I/0 list; or if a condition handler executes an I/0 statement 1in response to an exception from an I/0 statement for the same logical unit. Note that 1I/0 can be performed to a different logical unit. 41 INSUFFICIENT VIRTUAL The I/O FORTRAN MEMORY 1library virtual page limit while for an I/0 statement. 42 NO A 43 SUCH filename specification when an open FILE NAME SPECIFICATION included operation was filename string used RECORD exceed 1its space SPECIFICATION an invalid device attempted. ERROR in syntactically invalid, or to the operating system. 44 to DEVICE name The attempted dynamically allocating an is OPEN otherwise statement not 1is acceptable ERROR The RECORDSIZE value in an OPEN statement or the record size parameter in a DEFINEFILE statement is invalid (0 or negative) or is missing on an attempt to create a relative file or a file with fixed length records. 45 KEYWORD VALUE An OPEN statement an ERROR IN OPEN keyword invalid value. The STATEMENT that requires following values a. BLOCKSIZE: 0 to 65535 b. EXTENDSIZE: 0 to 65535 c. INITIALSIZE: 0 to 2**3]1-1 d. MAXREC 0 to 2*%*3]1-1 e. BUFFERCOUNT 0 to 127 f. RECORDSIZE 32766 16380 9999 for a wvalue are has accepted: sequential organization for relative organization for variable length records on magnetic (continued on tape next page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Run-Time Diagnostic Messages Messages 20 through 48 indicate errors related (No message numbers from 2 to 19 are used.) to the file system. Message Number 46 Text/Meaning INCONSISTENT OPEN/CLOSE PARAMETERS The specifications in an OPEN and/or subsequent CLOSE statement indicated one or more of the following: a. A 'NEW' or 'SCRATCH' file which is 'SCRATCH', or 'READONLY' 47 b. 'APPEND' 'READONLY' c. d. '"SAVE' or 'PRINT' on a 'SCRATCH' file 'DELETE' or 'PRINT' on a 'READONLY' file. WRITE TO READONLY to file a 'NEW', FILE A write operation was attempted to a file declared be READONLY by currently active OPEN. 48 INVALID ARGUMENT TO FORTRAN to I/O LIBRARY A coded argument is not one of the defined set of codes on a call to the FORTRAN I1/0 library. This cannot occur in a FORTRAN I/0 statement unless the version of the compiler is newer than the version of the Run-Time Library. The following messages indicate errors in transmitting data a FORTRAN program and an 59 internal LIST-DIRECTED I/O record. SYNTAX ERROR The data in a list-directed 1input invalid format, or the type of incompatible with the corresponding value of the variable is unchanged. 60 INFINITE FORMAT between record has an the constant is variable. The LOOP The format associated with an I/0 statement that includes an I/0 list has no field descriptors to use in transferring those variables. For example: 1 WRITE(1,1)X FORMAT ('X=") (continued on next page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Run-Time Diagnostic Messages The following messages indicate errors in a FORTRAN program and an internal record. transmitting data between Message Text/Meaning Number 61 FORMAT/VARIABLE-TYPE MISMATCH An attempt was made to input or output a real variable with an integer field descriptor (I, O, 2Z, or L), or an integer or logical variable with a real field descriptor (D, E, F, or G). 62 SYNTAX ERROR IN FORMAT A syntax error was encountered Library was processing a format 63 OUTPUT CONVERSION while stored the in an Run-Time array. ERROR During a formatted output operation the value of a particular number could not be output in the specified field length without 1loss of significant digits. The field is filled with asterisks. 64 INPUT CONVERSION ERROR During a formatted input operation an invalid character was detected in an input field, or the input value overflowed the range representable in the input variable. The value of the variable is set to zero. 66 OUTPUT STATEMENT OVERFLOWS RECORD An output statement specified an I/0 1list that exceeds the maximum record size specified. The record size is specified by the RECORDSIZE keyword of the OPEN statement, or by the record length attribute of an existing file. 67 INPUT STATEMENT REQUIRES TOO MUCH DATA A READ statement attempted to input more existed in the record being read. For I/0 list might have too many elements. 68 VARIABLE FORMAT The value of within the for example, EXPRESSION VALUE data than example, the ERROR a variable format expression is not range acceptable for its intended use; a field width 1less than or equal to zero. (continued on next page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Run-Time Diagnostic Messages The following messages indicate arithmetic overflow and underflow conditions. Message Text/Meaning Number 70 INTEGER OVERFLOW value integer an operation arithmetic an During The INTEGER*4 range. or INTEGER*2 BYTE, exceeded 1low order the <correct 1is result of the operation This error will occur only for program units part. in qualifier compiled with the /CHECK=OVERFLOW effect. 71 INTEGER ZERO DIVIDE an integer mode arithmetic operation During an The result is attempt was made to divide by zero. set to the dividend, which is equivalent to division by 72 1. FLOATING OVERFLOW the During an arithmetic operation a value exceeded the of result The number. real e representabl largest operation is set to minus 0.0. 73 FLOATING ZERO DIVIDE During a floating point arithmetic to divide by zero. attempt was made the operation is set to minus 0.0. 74 operation an The result of FLOATING UNDERFLOW During an arithmetic operation a floating point value has become less than the smallest representable real zero. of number, and has been replaced with a value It may be enabled 1is normally disabled. This error by calling LIBSFLT_ UNDER. 77 SUBSCRIPT OUT OF RANGE An array reference has been detected that is outside This the array as described by the array declarator. checking is performed only for program units compiled with the /CHECK=BOUNDS qualifier in effect. (continued on next page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Run~-Time Diagnostic Messages The following messages result Mathematical Procedures Library. from incorrect calls to the Message Number 80 Text/Meaning WRONG NUMBER OF ARGUMENTS A library function was of arguments. 81 INVALID ARGUMENT TO MATH A math value. 82 called library function with an number LIBRARY detected an invalid . UNDEFINED improper argument EXPONENTIATION Exponentiation was attempted that is mathematically undefined; e.g., 0.**0, The result is set to minus 0.0 for floating point operations, and 0 for integer operations. 83 84 LOGARITHM OF An attempt a negative SQUARE An was made to number. take The of SINE a required negative OR COSINE The magnitude the The of an greater so that all significance overflow An IN to 2**31 was SIN or of zero or to minus 0.0. of square UNDERFLOW underflow of a set to minus LIBRARY was detected library IN condition mathematical or The the set LIBRARY was detected COS, to minus or DSIN respectively, result during procedure. MATH library is 2**63 lost. MATH condition a mathematical to minus 0.0. FLOATING than result 0.0. FLOATING OVERFLOW set set LOST argument was of 89 SIGNIFICANCE DCOS An logarithm is evaluation value. or to minus 88 the result 0.0. 87 VALUE ROOT OF NEGATIVE VALUE argument root ZERO OR NEGATIVE The during procedure. 0.0. (continued The on is set execution result is execution result next is page) DIAGNOSTIC MESSAGES Table B-4 (Cont.) Run-Time Diagnostic Messages The following message may be displayed if the adjustable array are inappropriately defined. dimensions of an Message Number 93 Text/Meaning " ADJUSTABLE ARRAY DIMENSION ERROR Upon entry to a subprogram, dimensioning information has the evaluation of detected an array in which: ® ) an upper dimension bound dimension bound, or the dimensions addressable is imply an array memory. less that than a exceeds lower the APPENDIX C SYSTEM SUBROUTINES C.1 SYSTEM SUBROUTINE SUMMARY The VAX-11 FORTRAN IV-PLUS system provides subroutines you call in the same mannher as a user-written subroutine. These subroutines are described in this Appendix. The subroutines supplied DATE Returns are: a 9-byte representation of IDATE Returns month, three day the integer and string containing values representing Returns information about error condition. EXIT Terminates control to SECNDS Provides system time TIME Returns an 8-byte representation of to INTEGER*2 range. seconds. 1integer the most the execution of a the operating system. floating point value References ASCII the current year. ERRSNS and the current date. arguments of in day or seconds. recently program detected and elapsed returns time as a string containing the ASCII the current time in hours, minutes in the following subroutine descriptions refer to arguments of either type INTEGER*4 or type INTEGER*2. 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 value is within the C.2 DATE The DATE subroutine obtains the current date as The call to DATE has the set within the system. form: CALL DATE (buf) where buf is a 9-byte variable, substring. array, array element or character SYSTEM The date is returned as a SUBROUTINES 9-byte ASCII character string of the form: dd-mmm-yy where dd mmm yy C.3 1is is 1is the the the 2-digit date 3-letter month specification last two digits of the year IDATE The IDATE subroutine returns three current month, day, and year. The CALL If the current date upon were October return would 9, 1979 the values of the integer be: ERRSNS The ERRSNS that has the the 10 9 79 J k C.4 representing the form: IDATE(i,j,k) variables i integer values call to IDATE has subroutine returns information about the most occurred during program execution. The call recent error to ERRSNS has form: CALL ERRSNS (fnum,rmssts,rmsstv,iunit,condval) where fnum is an most integer variable recent FORTRAN A 0 is ERRSNS returned or if no or error if no error array element into which is stored the number. error has occurred has occurred since since the the start last call to of execution. rmssts is an integer variable or array element RMS completion status code if the into which 1last error is stored was an RMS the I/0 error. rmsstv is an integer variable RMS status value if status value provides or array element into which is stored the last error was an RMS I/0 error. additional status information. the This iunit is an integer logical unit variable number if or array the last element error into which was an I/O is stored error. the SYSTEM SUBROUTINES condval is an integer variable or array element into which is stored the actual VAX-1l1l condition value. See Chapter 6 for a description of condition values. Any of the arguments may be null. 1If the arguments are of 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. C.5 EXIT 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)] where (exit-status) is an optional integer specify the image exit status value. C.6 argument you can use to SECNDS The SECNDS function subprogram returns the system time in seconds as a single precision floating point value less the value of its single precision floating point argument. The call to SECNDS has the form: y = SECNDS (x) where y is set equal to the user—-supplied value of x. The SECNDS For function can be time used in seconds since midnight to perform elapsed time minus the computations. example: C START oNoXe] Tl = OF TIMED SEQUENCE SECNDS(0.0) CODE TO DELTA = where DELTA will BE TIMED SECNDS (T1) give the elapsed The value of SECNDS 1is accurate resolution of the system clock. time. to 0.01 seconds, which is the Notes: 1. The time is computed from midnight. SECNDS also produces correct results for time intervals that span midnight. 2. 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. SYSTEM C.7 SUBROUTINES TIME The TIME subroutine returns the string. The call to TIME has the CALL an TIME call form: 8-byte returns variable, the time array, as an where hh For is the 1 Fha [ 59 9 & - © VI AdmtdE minnibka lllLilueT AliVd L\ QA L ALULL is the 2-digit second indication aLUIRL E ss -] 2-digit hour UiYiL example: 10:45:23 A 24-hour time as an clock is used. indication 1AL Nl array element, or character 8-byte ASCII hh:mm: ss mm system ASCII TIME (buf) where buf is substring. The the current form: AR character string of APPENDIX D COMPATIBILITY D.l1 COMPATIBILITY: OVERVIEW VAX~-11 FORTRAN IV-PLUS is a compatible superset of PDP-11 FORTRAN IV and PDP-11 FORTRAN 1IV-PLUS. Generally speaking, any PDP-11 FORTRAN program will run correctly on VAX-11l. Execution may be affected in some cases, however, because of differences 1in the hardware architecture of PDP-1l1l and VAX-1ll computers, and differences between the IAS/RSX-11 and VAX/VMS operating environments. The issues discussed in this appendix concern differences in language, run-time support, and utilities provided in the form of subroutines. D.2 LANGUAGE DIFFERENCES Differences related to language involve: 1. Logical 2. Floating point 3. Character 4., Logical 5. Assigned GO TO label 6. Effect of DISPOSE='PRINT' D.2.1 tests results and Hollerith constants unit numbers list specification Logical Tests The logical constants .TRUE. and .FALSE. are defined, respectively, as all 1's and all O0's by both VAX-11l FORTRAN IV-PLUS and PDP-11 FORTRAN. The test for .TRUE. and .FALSE. differs, however. VAX-11 FORTRAN IV-PLUS tests the low-order bit (bit 0) value. This is the system~-wide VAX-11l convention for of a 1logical testing logical values. PDP-11 FORTRAN IV-PLUS tests the sign bit of a logical value; for LOGICAL*1l, bit 15 for LOGICAL*2, and bit 31 for LOGICAL*4,. PDP-11 FORTRAN IV tests the low-order byte of a 1logical 0's is .FALSE., while any non-zero bit pattern is .TRUE. value; bit 7 all COMPATIBILITY In most cases, this difference will have no effect. significant only for non-standard FORTRAN programs arithmetic operations on logical values, and then make on the result. It will be that perform logical tests Example: LOGICAL*]1 BA=3 IF VAX-11 (BA) BA GO FORTRAN FORTRAN TO 10 IV-PLUS IV-PLUS will will produce produce a value .FALSE. of PDP-11 .TRUE., FORTRAN .TRUE. D.2.2 Floating while PDP-11 IV will produce Point Results Differences in math library routine results may occur because of new implementations of these routines, exploiting the VAX-11 instructions. The VAX-1ll greater functions than the produce results corresponding of PDP-11 an accuracy functions, equal but there to or may be differences. D.2.3 Character VAX-11 FORTRAN constants, with PDP-11 FORTRAN and Hollerith Constants IV-PLUS supports both Hollerith and character the notations nHa...a and 'aaaa' respectively. 1In 1IV-PLUS, both notations are used for Hollerith constants. (Note assume data type consistent with cases, the conflicting use In most a that Hollerith constants their of the have no data type, but use.) 'aaaa' notation 1is not a problem: VAX-11 FORTRAN IV-PLUS can determine from the program context whether a character or a Hollerith constant is intended. There 1is, however, one case in which this is not so. In an actual argument list for a CALL or function reference, where the subprogram called is a dummy argument, a constant in the 'aaaa' notation is always passed as a character constant, never as Hollerith. For example, given SUBROUTINE CALL S (F) F('ABCD') if the subroutine referenced by F expects a Hollerith constant (i.e., the dummy argument 1is numeric data type), execution will not be correct. The actual and dummy arguments must agree in data type. This will not be the case in the example shown. To avoid this problem, you must change to the nHaaa notation; as: SUBROUTINE CALL S (F) F (4HABCD) COMPATIBILITY Logical Unit Numbers D.2.4 a If you do not specify a logical unit number in an I/O statement, The defaults used by VAX-1l FORTRAN default unit number will be used. IV-PLUS differ from those used by PDP-11 FORTRAN IV-PLUS, as shown in Table D-1. Table D-1 Default Logical Unit Numbers I/0 Statement PDP-11 Unit VAX-11l Unit READ 1 -4 PRINT 6 -1 TYPE 5 -2 ACCEPT 5 -3 Note that PDP-11 FORTRAN IV-PLUS uses normal logical unit numbers, but VAX-11 FORTRAN IV-PLUS wuses unit numbers that are not available to 1I/0 This prevents conflicts between these I/O statements and users. This should have that use explicit logical unit numbers. statements no visible effect on program execution. Assigned GO TO Label List D.2.5 by checked The labels specified in an assigned GO TO label list are IV-PLUS compiler to ensure their validity in the FORTRAN the VAX-11 IV-PLUS does not perform a However, VAX-11 FORTRAN program unit. check at run time to ensure that a label actually assigned is in the PDP-11 FORTRAN IV-PLUS does perform this check at run time, but list. PDP-11 FORTRAN IV does not. N D.2.6 DISPOSE='PRINT' Specification On some PDP-11 systems, the file is deleted after being printed if you On VAX-1ll in an OPEN or CLOSE statement. specify DISPOSE='PRINT' FORTRAN IV-PLUS, D.3 the file is retained after being printed. RUN-TIME SUPPORT DIFFERENCES Differences in run-time support between VAX-11l FORTRAN IV-PLUS and PDP-11 FORTRAN are reflected in run-time error numbers, run-time error reporting, and in some OPEN statement keyword values. COMPATIBILITY D.3.1 Run-Time Library Error Numbers Programs that because certain deleted numbers from, or affected 2 through use the ERRSNS PDP-11 FORTRAN redefined are: subroutine run-time in, the VAX-1ll 14 may error need numbers Run-Time deleted; to have modified been Library. these reported be fatal either The error error numbers PDP-11 hardware conditions. 37 (INCONSISTENT RECORD LENGTH) redefined; continuation is not allowed. 65 (FORMAT TOO BIG FOR 'FMTBUF') deleted; this r ’ [¢ 2] [y e w ’ (4o o ’ ~J W ~J o because dynamically LTUTL error cannot space for is run-time TA-adsas LIITU formats. - - dvuauaiil arithmetic errors I and math errors return -0.0 (a reserved operand) rather 75 CONVERSION OVERFLOW) deleted; reported 86 deleted; error reported instead. 91 (FPP FLOATING TO (INVALID INTEGER ERROR NUMBER) (COMPUTED GOTO OUT OF RANGE) error (ASSIGNED LABEL NOT deleted; IN LIST) 95 (ARRAY through REFERENCE OUTSIDE ARRAY) 101 en e library hardware than +0.0. number 70 is number 48 is no error is generated hardware occurs. execution continues deleted; as in described D.2.5, VAX-1l1l FORTRAN not perform this check 94 e instead. the VAX-~11 condition 92 occur, acquired deleted; error reported instead. deleted; these by when this Program line. 1in Section IV-PLUS does at run-time. number error 77 is numbers reported PDP-11 FORTRAN errors that cannot occur in VAX-11 FORTRAN IV-PLUS. The following 35 (SEGMENTED RECORD 36 (ATTEMPT TO 48 (INVALID ARGUMENT TO 77 (SUBSCRIPT OUT OF RANGE) 87 (SINE OR COSINE 88 (FLOATING OVERFLOW IN 89 (FLOATING UNDERFLOW See Table B-4 error READ for numbers FORMAT have been ERROR) NON-EXISTENT FORTRAN SIGNIFICANCE IN added: MATH MATH descriptions RECORD) I/0 LIBRARY) LOST) LIBRARY) LIBRARY) of these error messages. COMPATIBILITY D.3.2 Error Handling and Reporting VAX~11 FORTRAN IV-PLUS differs from PDP-11 FORTRAN IV-PLUS in the way it treats error continuation, 1I/0O errors, and OPEN/CLOSE statement errors. Chapter 6 describes Run-Time Library error handling. D.3.2.1 Continuing After Errors - In PDP-11 FORTRAN, program execution normally continues after errors such as floating overflow, until 15 such errors, have occurred, at which point execution is terminated. VAX-11 FORTRAN IV-PLUS, however, sets a limit of 1 such error; program execution normally terminates when the first such error occurs. To change this behavior, you can take one of the following steps: @ Include a condition handler in your program to change severity level of the error. Severity levels of Warning Error permit continuation. See Chapter 6. e Include the ERRSET subroutine (see Section D.4.3). ERRSET alters the Run-Time Library's default error processing to match the behavior of PDP-11 FORTRAN IV-PLUS. D.3.2.2 the and 1I/0 Errors with ERR= Specified. VAX-11 FORTRAN IV-PLUS neither generates an error message nor increments the image error count when an I/0 error occurs, if an ERR= specification was included in the I/0O statement. PDP-11 FORTRAN both reports the error and increments the task error count. D.3.2.3 OPEN/CLOSE Statement Errors Unlike PDP-11 FORTRAN, VAX-11l FORTRAN IV-PLUS reports only the first error encountered in an OPEN or CLOSE statement. PDP-11 FORTRAN reports all errors detected in processing the statement. D.3.3 OPEN Statement Keywords The space allocation for the INITIALSIZE keyword 1is contiguous best-try for VAX-11 FORTRAN IV-PLUS. That 1is, if you specify an INITIALSIZE value, and sufficient contigquous space 1is available, allocation will be contiguous. If there is not sufficient contiguous space, allocation will be non-contiguous. 1In PDP-11 FORTRAN 1IV-PLUS, allocation of contiguous or non-contiguous space depends on the sign of the value specified for the INITIALSIZE and EXTENDSIZE keywords. To be compatible with PDP-11 FORTRAN, VAX-11 FORTRAN IV-PLUS uses the absolute value of the user-supplied value. D.4 UTILITY SUBROUTINES There are a number of utility subroutines available for wuse with PDP-11 FORTRAN IV-PLUS. All are supplied as part of PDP-11 FORTRAN IV-PLUS, as described in the PDP-11 FORTRAN IV-PLUS User's Guide. COMPATIBILITY Six of these subroutines are supplied as FORTRAN IV-PLUS (see Appendix C). These a standard subroutines part are: of VAX-1l1l DATE ERRSNS EXIT IDATE SECNDS TIME A new random number Library. For Common Run-Time generator function is included in the a description of this function, refer Procedure Library Reference Manual. to Run-Time the VAX-11 The remaining subroutines are provided for purposes of compatibility: most have been superseded by features included in VAX-11l FORTRAN IV-PLUS, while others are of little applicability on VAX-1ll systems. Sections D.4.1 through D.4.11 describe these routines. The remaining utility subroutines are: ASSIGN CLOSE ERRSET ERRTST FDBSET IRADS0 RADS0 RAN RANDU R50ASC USEREX D.4.1 ASSIGN The ASSIGN information Subroutine subroutine 1is for a logical wused unit. to supply That is, it to be until assigned to a logical unit. The the program terminates or until CLOSE statement. The ASSIGN issued for The CALL FDBSET, together, for the There but same are logical or use subroutine must be that logical unit. two CALL ASSIGN, none can be called and used assignment the logical before DEFINE in device allows the FILE a or file device or remains unit is first I/0 statements conjunction with statement can the OPEN other ways number: the ASSIGN to assign specify system a device the NAME or a file keyword in an OPEN command. Format: ASSIGN (n[,namel[,icnt]) Arguments: n an in effect closed by a be is used statement unit. wunit CALL name file integer value specifying the logical unit number name to a statement, COMPATIBILITY name a variable, array, array containing any standard file icnt an INTEGER*2 contained in element, or specification value that specifies the string name the character number of constant characters Note: If only the unit number is specified, all previously specified file/device associations pertaining to that unit are nullified, and the defaults become effective. If icnt 1is omitted (or specified as zero), the file specification (if specified) is read until the first ASCII null character is encountered. If the icnt argument 1is specified, then the name argument must also be specified. D.4.2 CLOSE Subroutine The CLOSE subroutine closes the file currently open on a logical unit. Format: \ CALL CLOSE (n) Argument: n an integer value specifying the logical unit After the file is closed, the logical unit again assumes file name D.4.3 specification. the default ERRSET Subroutine The ERRSET subroutine determines the action taken in response to an error detected by the Run-Time Library. The VAX-11l Condition Handling Facility provides a more general method of defining actions to be taken when errors are detected (see Chapter 6). Format: CALL ERRSET (number, contin, count, type, log, maxlim) Arguments: number an contin a integer logical value specifying the error number value: .TRUE. - continue after .FALSE. - exit after error error is detected is detected COMPATIBILITY count a logical value: .TRUE. - count .FALSE. - do the not error count against the error the maximum error against the limit maximum error limit type a logical value: .TRUE. - control passed to ERR= transfer label, if error, for specified .FALSE. - return to routine that default error recovery detected the NOTE PDP-11 FORTRAN and in this respect: VAX-1ll FORTRAN differ On PDP-1l1, this value takes precedence over an ERR= specification in the I/0 statement; on VAX-11, the specification or omission of ERR= takes precedence over this value. That is, if ERR= was specified, control is transferred on any error, regardless of the value of type. an error log a logical value: .TRUE. - produce .FALSE. - do not produce message an error for this message error for this maxlim positive INTEGER*2 value specifying the maximum error default is set to 15 at program initialization. error limit. The Notes: 1. The error action other errors. 2. Null have 3. arguments effect no that The are on for each error is independent of legal for all arguments except number, current state of that argument. and the An external reference to ERRSET or ERRTST causes a special PDP-11 FORTRAN compatibility error handler to be established before the main program is called. This special error handler D.4.4 specified ERRTST ERRTST of transforms PDP-11 the executing environment to approximate FORTRAN. Subroutine subroutine <checks for a specific appropriate actions in response to errors, condition handler, as described in Chapter 6. error. you should To perform establish a COMPATIBILITY Format: CALL ERRTST(i,]) Arguments: i an integer value specifying the error number J . a variable used for return value of error check j = 1: j = 2: error i has occurred error i has not occurred Notes: 1. ERRTST resets the error flag for the specified error. 2. ERRTST is independent of the ERRSET subroutine. subroutine has any direct effect on the other. Neither See also Note 3 under ERRSET. Example: CALL ERRTST (43,J) GO TO (10,20)Jd 20 CONTINUE nt 10 (J=1); I1f error 43 is detected, a branch is taken to stateme nt 20 (J=2). error 43 is not detected, control passes to stateme if FDBSET Subroutine D.4.5 The I/0 options. The FDBSET subroutine is used to specify special nt. stateme OPEN the is options I/0 recommended method of specifying Format: CALL FDBSET(unit,acc,share,numbuf,initsz,extend) Arguments: unit an integer value specifying the logical unit acc a character constant specifying the access mode to be used: 'READONLY' create a new file access an existing file 'UNKNOWN' try 'OLD'; 'APPEND' share read-only access 'NEW' 'OLD' extend an existing sequential file if no such file exists, use 'NEW' a character constant ‘'SHARE' indicating allowed that shared access is COMPATIBILITY numbuf an INTEGER*2 for value multibuffered specifying the number I1/0 of buffers to be used initsz an INTEGER*2 allocated value for a specifying new the number of file blocks initially extend an INTEGER*2 extend a value specifying the number file of blocks by which to Notes: l. FDBSET can statement 2. CALL FDBSET, used D.4.6 wused the ASSIGN, but statement only for none the The unit argument must optional. IRADS50 before issuing unit. CALL together, OPEN 3. be for and the can be same be DEFINEFILE used in the first statement conjunction can All other be with the arguments are unit. specified. 1I/0 Subroutine The IRAD50 subroutine is form. IRAD50 may be used to convert Hollerith data called as a function subprogram value is desired value is not (format 1, below), or as desired (format 2, below). l. n IRAD50 2. CALL a subroutine to Radix-50 if the return if the return Formats: = (icnt,input,output) IRAD50(icnt,input,output) Arguments: n (for are function) an INTEGER*2 value converted indicating how many characters icnt an INTEGER*2 be converted value specifying the maximum number of characters to input a Hollerith string to be variable or array converted to Radix~-50 >utput a numeric are stored element where the Radix-50 results COMPATIBILITY Notes: Three Hollerith characters are packed into each output word. The number of output words is computed by the expression: 1. /3 (ICNT+2) Thus if a value of 4 is specified for icnt, two output words will result, even if an input string of only one character is converted. Scanning of the input 2. characters terminates non-Radix-50 character in the input string. on first the RAD50 Function D.4.7 six The RAD50 function subprogram provides a simplified way to encode Hollerith characters as two words of Radix-50 data. Format: RADS50 (name) Argument: name a numeric variable name Hollerith string or array element to corresponding a The RADS50 function is equivalent to: Note: FUNCTION RAD50 (A) CALL IRAD50(6,A,RAD50) RETURN END RAN Function D.4.8 The RAN function subprogram returns a pseudo-random number as the seed for function value. Format: RAN (il,1i2) Arguments: il,i2 INTEGER*2 variables or array elements that contain the computing the random number. Notes: 1. The values of il and i2 are updated during the computation to 2. The algorithm for computing the random number value 1is identical to the algorithm used in the RANDU subroutine (see contain the updated seed. Section D.4.9). COMPATIBILITY 3. The RAN function FUNCTION is RAN CALL RANDU RETURN equivalent to: (Il1,I2) (I1l,I2,RAN) END D.4.9 RANDU Subroutine The RANDU subroutine computes a pseudo-random number, precision value uniformly distributed in the range: 0.0 .LE. value .LT. as a single 1.0 Format: CALL RANDU(il,i2,x) Arguments: il,i2 INTEGER*2 variables computing the or array random number. elements that contain the computed the seed for X a is real variable or array stored. element where random number Notes: l. The values of il and i2 are contain the updated seed. updated during 2. The the algorithm for computing follows: If I1=0, I2=0, X(n+l) set generator = 2**16 = (2**16+3) + random the computation number value Y(n+l), for 1is to as base 3 otherwise X(n+l) Store D.4.10 The generator Result is Y(n+l) .LT. R50ASC R50ASC X(n+l) base * X(n+l) scaled to in a 2**32 Il,I2. real 1. value 0.0 .LE. Subroutine subprogram converts Radix-50 Format: CALL X(n)mod R50ASC(icnt,input,output) values to Hollerith strings. COMPATIBILITY Arguments: icnt \ INTEGER*2 value specifying the number of ASCII characters to be produced input numeric variable or array element containing the Radix-50 data output numeric variable or array element where the Hollerith characters are to be stored Notes: 1. The number of words of input equals (icnt+2)/3. 2. If the undefined Radix-50 code is detected, or the Radix-50 (octal), then question marks will be word exceeds 174777 placed in the output location. D.4.11 USEREX Subroutine The USEREX subroutine specifies a routine to be called as part of the This allows clean-up operations in program termination process. non-FORTRAN routines. You can establish a termination handler directly by calling the system service routine SYSSDCLEXH. Format: CALL USEREX (name) Argument: name specifies the routine to be called Notes: the 1. The routine name must appear in an EXTERNAL statement in 2. The user exit subroutine is called as a VAX/VMS termination See the VAX/VMS System Services Reference Manual handler. program unit. for information regarding termination handlers. INDEX Call conventions, FORTRAN, 5-1 Calling standard, procedure, 5-1 Access, direct, 3-8 record, 3-8 sequential, Calling subroutines from 2-16 debugger, 3-8 Access privileges, file, 3-1l1 Addresses, defining, 2-16 specifying when debugging, 2-14 Argument lists, 5-2 Argument list built-in functions, 5-2 Argument passing, Calling system services, Calls, procedure, 5-1 CANCEL BREAK command, 2-8 CANCEL MODULE command, 2-6 CANCEL SCOPE command, 2-6 CANCEL TRACE command, 2-9 CANCEL WATCH command, 2-9 CHAR function, 5-2 Arguments, condition handler, 6-9 defaults for optional, 5-7 ENTRY statement, 7-7 input address, 5-6 lists, machine code, 5-8 lists, object code, 5-8 output, 5-6 passed length character, 4-4 passing, 5-6, 5-7 ASCII value, 4-7, 4-8 5-4, 5-5 4-7 Character arguments, passed length, 4-4 passing, 5-7 Character constants, Character data, 4-3, D-2 4-1 Character expression length, finding, 4-8 Character format, A-4 Character function argument list, 5-11 Character I/0, 4-8 Assigning files to logical Character library functions, Assigning logical names with Character strings, 4-2 Character substrings, 4-1 units, 3-6 MOUNT command, ASSIGN subroutine, 3-6 D-6 Attributes, program section, 7-2 Auxiliary I/0, 3-14 4-7 Character variables, initializ4-4 ing, CHECK qualifier, 1-7 Checking, bounds, 1-7 CLOSE statement, 8-11 CLOSE subroutine, D-7 Commands, Blocks, common, 8-3 source program, 8-6 BLOCKSIZE keyword, 3-10, 8-10 1-7 Bounds checking, Branching, conditional, 8-3 Breakpoints, 2-2, 2-8 BRIEF qualifier, 1-13 BUFFERCOUNT keyword, 3-10 Built-in functions, argument list, Byte data, 5-2 7-4 Call by descriptor, 5-2, 7-7 Call by reference, 5-2, 7-7 Call by value, 5-2, 7-7 CANCEL BREAK, 2-8 CANCEL MODULE, 2 6 CANCEL SCOPE, 2CANCEL TRACE, 2CANCEL WATCH, 2CTRL/Y, 2-12 OWWOWo | BACKSPACE statement, 3-14, 8-10 BLOCK DATA statement, 1-20, 7-2 Debugger, 2-3 DEPOSIT, 2-13 EDIT, 1-1 EVALUATE, 2-14 EXAMINE, 2-13 EXIT, 2-12 GO, 2-11 LINK, 1-1 MOUNT, 3-6 RUN, 1-1, 1-14 SET BREAK, 2-8 SET LANGUAGE, 2-5 SET MODULE, 2-6 SET SCOPE, 2-6 SET STEP, 2-12 Index-1 INDEX Commands SET D (Cont.), TRACE, 2-9 SET WATCH, 2-9 Data, SHOW BREAK, 2-8 SHOW CALLS, 1-17, SHOW LANGUAGE, SHOW MODULE, 2-5 2-6 SHOW TRACE, 2-9 SHOW WATCH, 2-9 integer, numeric, blocks, Common subexpressions, 8-3 Communication, remote, 3-14 Data representation, subroutine, C-1 DEBUG qualifier, 1-8, Debugger, limits, calling subroutine symbol B-19 Compile-time operations format, on, 8-3 on DECODE 2-17 2-4 optimization effects 2-18 statement, for A-3 optional Defining addresses, command, 6-8 DISPOSE='PRINT', 6-9 Condition signals, 6-7 Condition symbol files, 6-12 Condition symbol, 6-4, 6-7, 6-11 Condition value, 6-6, 6-11 D_LINES qualifier, DO loops, Double Control 2-19 flow, Conventions, FORTRAN call, Creating and executing a program, Current 2-12 location, statement 2-15 6-1, 6-2 3-14 arguments, correction, messages, 1-13 6-1, 6-2 1-15 B-1 D-4 processing, 6-1, run-time, 6-4 severity code, Index-~2 7-7 FORTRAN system, ERR specification, numbers, qualifier, A-3 Error, 8-1 CTRL/Y command, statement, Environment, 1-1 CROSS_REFERENCE format, command, l1l-1 specification, 7-1 5-1 Creating efficient source programs, EDIT END 1-8 1-9 7-6 E ENTRY qualifier, 5-10 7-7 6-14 precision ENDFILE CONTINUATIONS 5-3, 5-2, D-3 zero, D-2 Hollerith, D-2 integer, 7-4 5-2, by, Divide, Constants, on, 3-12 Diagnostic messages, B-1 Direct access, 3-8 Directory, 1-2 Disk file allocation, 3-10 6-10 compile time operations 8-5 2-16 2-13 $DESCR function, Descriptor, call Device, 1-2 6-9 1-21 character, 4-3, arguments, Deleted-record control, DEPOSIT 4-3 8-10 5-7 establish, 6-7, 6-9 function return values, removing, 6-9 responses, 2-16 table, Defaults 1-5 source files, 1-5 Concatenation operator, 4-2 Conditional branching, 8-3 Condition codes, 2-18 Condition handlers, 6-1, 6-6 user-written, from, Declaring character data, Concatenating arguments, 1-15 Debugger, 8-5 Compiling a program, 1-14, 2-3 qualifiers, B-18 Compiler listing, 1-18 Compiler optimization, constants, A-1 2-1 commands, diagnostic B-~17, 7-4 2-17 DATE D-1 Compiler-fatal Compiler 8-7 3-15 Compatibility, messages, 7-3 LOGICAL*1l, 2-11 interprocess, 7-9, 7-10 Common Complex byte, 7-4 character, 4-1, 4-3 fixed-point, 7-2 floating point, 7-8, 2-10 2-6 SHOW SCOPE, STEP, (Cont.) D-5 6-3, 6-11 INDEX ERRSET subroutine, D-7 ERRSNS subroutine, 6-2, 6-5, Cc-2, D-4 ERRTST subroutine, D-8 Establish a condition handler, 6-7, 6-9 EVALUATE command, 2-14 EXAMINE command, 2-13 Examining locations, 2-12 Executable image, 1-12, 7-2 EXECUTE qualifier, 1-12 Executing a program, 1-1, 1-14 EXIT command, 2-12 EXIT subroutine, C-3 EXTENDSIZE keyword, 3-10 EXTERNAL statement, 7-5 (Cont.) FORMAT statement, FORTRAN command, 1-6 FORTRAN I/0O system, 8-10 FORTRAN run—-time errors, FORTRAN map, 1-13 object, 1-5, organization, source, 1-9 3-7, 7-1 ICHAR, 4-8 INDEX, 4-8 LEN, 4-8 5-4 processor—-defined, 7-4, 7-5 RAD50, D-11 RAN, D-11 7-10 $REF, 5-2, 5-3, 5-10 return values, 5-4 VAL, 5-2, 5-3, 5-10, 3-11 6-8 G 3-11 1-5 Generic GO concatenating source, Files, condition symbol, 6-12 Files to logical units, assigning, 3-6 FIND statement, 3-14 Finding character expression length, 4-8 Fixed length records, 3-9 Fixed-point data, 7-2 Floating point data, 7-8, 7-9, 7-10 Floating point format, A-1 Floating point results, D-2 Floating overflow, 6-14 Format, character, A-4 complex, A-3 double precision, A-3 floating point, A-1 Hollerith, A-4 integer, A-1l logical, A-5 LOGICAL*1, A-4 real, A-2 run-time, 8-10 7-5 2-11 H 1-2 1-3 1-5 functions, command, 1-3 Files, 1-13 character library, 4-7 $DESCR, 5-2, 5-3, 5-10 generic, 7-5 $LOC, specification, 1-2, 3-2 File allocation, disk, 3-10 File specification defaults, Filename, Filetype, 6-4 system environment, FULL qualifier, Function, 5-1 CHAR, 4-7 File, access privileges, listing, 1-5, 1-9 5-1 1-1 FORTRAN command qualifiers, F Fault, reserved operand, FDBSET subroutine, D-9 8-10 FORTRAN call conventions, Hollerith constants, D-2 Hollerith format, A-4 ICHAR function, 4-8 IDATE subroutine, C-2 I4 gualifier, 1-9 Image, executable, 1-2, 7-2 shareable, 1-13 INCLUDE qualifier, 1-14 INCLUDE statement, 6-12, 8-2 INDEX function, 4-8 Initializing character variables, 4-4 INITIALSIZE keyword, 3-10, D-5 Input address arguments, 5-6 Input/output, 3-1 Integer constant, 7-4 Integer data, 7-3 INTEGER declaration, 1-9 INTEGER*2 and INTEGER*4, INTEGER*4 format, A-1l 7-3 Interprocess communication, Index-3 3-14 INDEX Invariant computations in loops, 8-8 I/0, auxiliary, 3-14 character, 4-8 FORTRAN system, 8-10 statements, 3-1 transfer size, 3-10 IRAD50 subroutine, D-10 Iteration count, 7-6 K Keyword, BLOCKSIZE, 3-10, 8-10 BUFFERCOUNT, 3-10 EXTENDSIZE, 3-10 INITIALSIZE, 3-10, D-5 NAME, 3-5 OPEN statement, 3-10 ORGANIZATION, Location, current, 2-15 examining a, 2-12 modifying a, 2-12 next, LOGICAL*]1 format, Loops, 8-8 Messages, 1-21 Language differences, LEN function, 4-8 Length, finding expression, D-1 character 4-8 LIBSESTABLISH, 6-9 LIBSREVERT, 6-9 LINK command, 1-1 Linker input file qualifiers, B-17 source B-4 program, Modifying locations, 2-12 MOUNT command, assigning logical names with, 3-6 Names, logical, 3-3 program section, Network, 1-14 Linker qualifiers, 1-11 Linking, 1-10 List built-in functions, argument, 5-2 LIST qualifier, 1-9 Listing, compiler, 1-18 machine code, 1-19 object code, 1-9 Listing file, Lists, 1-5, 5-2, 1-9 2-15 1-2 NOOPTIMIZE qualifier, 2-19 Numeric data types, 2-17 (o) Object code argument lists, OPEN statement, 5-11 3LOC function, 5-4 Locating a substring, Next location, Node, 7-2 3-15 5-8 Object code listing, 1-9 Object file, 1-5, 1-9 OBJECT qualifier, 1-9 1-19 argument, B-1 compiler-fatal, run-time, B-20 6-7 LIBSSTOP, 6-7 LIBRARY qualifier, 1-14 Limits, compiler, B-19 source, A-4 Machine code argument lists, 5-8 Machine code listing, 1-19 MACHINE_CODE qualifier, 1-9 Mailbox, 3-14 Map file, 1-13 MAP qualifier, 1-13 Map, storage, 1-21 L LIBSSIGNAL, 2-15 previous, 2-15 LOGICAL declaration, 1-9 Logical format, A-5 Logical names, 3-3 assigning with MOUNT command, 3-6 Logical tests, D-1 Logical unit numbers, 3-4, D-3 Logical units, assigning files to, 3-6 LOGICAL*1 data, 7-4 3-11 READONLY, 3-11 RECORDSIZE, 3-11 RECORDTYPE, 3-12 SHARED, 3-13 USEROPEN, 3-13 Labels, (Cont.) 4-8 3-5, 3-10, 8-10, 8-11 OPEN statement keywords, Index-4 3-10 INDEX OPEN statement NAME keyword, 3-5 Operator, concatenation, 4-2 Optimization, compiler, 8-3 effects on debugger, 2-18 OPTIMIZE qualifier, 1-10, 2-19 ORGANIZATION keyword, 3-11 Output address arguments, 5-6 Overflow, P PARAMETER statement, Passed length arguments, 8-1 4-4 to system Passing character arguments, 5-7 Previous location, 2-15 Procedure activation, 6-6 Procedure calling standard, 5-1 Procedure calls, 7-5 Program interchange, 7-6 Program section, 1-21, 7-1 attributes, 7-2 names, 7-2 PROGRAM statement, PSECT, 1-20, 7-1 (see Program section) Q Qualifiers, 1-1 BRIEF, 1-13 CHECK, 1-7 CONTINUATIONS, 1-8 CROSS_REFERENCE, 1-13 1-8, DEBUG, 1-14, Linker, LIst, 1-14 1-14 1-11, MAP, 1-13 7-2 3-7, 5-3, 5-10 3-11 6-9 Representation of 0.0, 7-11 Reserved operand fault, 7-10 Resignal, Responses, 6-7 condition handler, 6-8 R50ASC subroutine, D-12 RUN command, 1-1, 1-14 Run~-time diagnostic messages, B-20 to B-29 Run-time format, 8-10 Run-time library, 6-1, 6-2, 6-3 Run-time support, 1-14 specifying when debug- NOOPTIMIZE, 2-19 OBJECT, 1-9 OPTIMIZE, 1-10, 2-19 2-15 SECNDS subroutine, C-3 Segmented records, 3-9 Sequential access, 3-8 Sequential file organization, 3-7, 1-9 D-3 S ging, 1-9 MACHINE_CODE, 5-2, Remote communication, 3-15 Removing condition handlers, Scope, 1-13 I4, 1-9 INCLUDE, LIBRARY, ¢$REF function, Reference, call by, 5-2 Registers, 1-20 Register binding, 2-18 1-15 Debugger, 2-17 D_LINES, 1-9 EXECUTE, 1-12 FULL, fixed length, 3-9 segmented, 3-9 structure, 3-8, 3-12 variable length, 3-9 RECORDTYPE keyword, 3-12 Relative file organization, 5-1 Processor-defined functions, 7-4, R Record, character Passing arguments services, 5-6 Qualifiers (Cont.), SHAREABLE, 1-12 TRACEBACK, 1-14, 1-15 WARNINGS, 1-10 WORK_FILES, 1-10 RAD50 function, D-11 RAN function, D-11 RANDU subroutine, D-12 READONLY keyword, 3-11 Real format, A-2 Record access, 3-8 RECORDSIZE keyword, 3-11 1-7 6-14 checking, floating, (Cont.) SET SET SET SET SET Index-5 3-11 BREAK command, 2-8 LANGUAGE command, 2-5 MODULE command, 2-6 SCOPE command, 2-6 STEP command, 2-12 INDEX SET TRACE command, SET WATCH command, Shareable image, 2-9 (Cont.) Subroutine, 2-9 ERRSET, 1-13 SHAREABLE qualifier, SHARED keyword, 3-13 SHOW BREAK command, SHOW CALLS command, 1-12 system ERRSNS, 6-2, ERRTST, D-8 6-5, 1-17, 2-10 SHOW LANGUAGE command, 2-5 SHOW MODULE command, 2-6 IDATE, RANDU, D-10 D-12 SHOW SCOPE command, 2-6 command, R50ASC, D-12 2-9 SHOW WATCH command, SECNDS, 2-9 C-3 USEREX, D-13 Sign bit tests, 7-11 Signals, condition, 6-7 Signal procedure values, 6-10 Source files, concatenating, Substrings, locating, 1-5 Source program diagnostic messages, 1-19 B-1, B-4 definitions, table, 1-8 debugger, Symbol files, condition, 5-5 System procedure CLOSE, DATE, 3-14, BLOCK DATA, CLOSE, 8-~11 EXTERNAL, FIND, D-12 SECNDS, C-3 USEREX, D-13 SYSSUNWIND, 8-10 1-1 INCLUDE, 6-12, T TIME subroutine, Traceback, 1-8 8-2 3-1 OPEN, 8-10, PARAMETER, PROGRAM, Storage 8-1 7-2 Unit numbers, logical, 6-7, 6-8, 6-11 1-21 Unwind, Storage unit, 7-2 Strings, character, 4-2 Subexpressions, common, Subprograms, 5-1 Subroutines, 5-1 Subroutine, system, ASSIGN, calling CLOSE, 1-14, 1-15 U 7-2 2-11 allocation, Storage map, C-4 TRACEBACK qualifier, 8-11 1-20, command, DATE, 6-11 7-5 FORMAT, STEP R50ASC, D-12 3-14 FORTRAN, 1/0, D-10 7-2 7-7 D-4 : D-9 RANDU, 3-14 C-2, C-2 8-10 1-20, 6-5, C-3 IDATE, 8-10 ENDFILE, 6-2, D-8 IRAD50, BACKSPACE, ENTRY, 5-1 D-7 ERRTST, FDBSET, Statement, DECODE, C-1 ERRSNS, EXIT, 2-16 D~7 ERRSET, calling, D-6 calling from debugger, 1-5 6-12 6-7, 6-11 calling, 5-4, subroutine, ASSIGN, Specifying addresses when debugging, 2-14 Specifying scope when Standard, 2-4 condition, System services, program blocks, 8-6 Source programs, creating efficient, 8-1 4-1 Symbol B-17 Source debugging, 2-15 Specifying output files, SS$_CONTINUE, 6-10 SS$_RESIGNAL, 6-10 character, 4-8 Symbol Symbols, to D-4 C-2 IRAD50, SHOW TRACE listing, C-2, EXIT, C-3 FDBSET, D-9 2-8 Source (Cont.), D=7 8-7 USEREX subroutine, D-13 USEROPEN keyword, 3-13 User-written condition handlers, 6-9 Utility subroutines, D-5 ASSIGN, D-6 from debugger, 3-4, CLOSE, 2-16 D-7 C-1 Index~-6 D-6 D-7 ERRSET, D~7 ERRTST, D-8 FDBSET, D-9 D-3 INDEX (Cont.) I Utility subroutines IRADS50, D-10 (Cont.), Variable length records, Version, 1-3 RAD50, D-11 RAN, D-11 RANDU, D-12 R50ASC, D-12 USEREX, D-13 W WARNINGS qualifier, 1-10 WORK_FILES qualifier, 1-10 \'} $VAL function, 6-8 3-9 5-2, 5-3, Value, call by, 5-2, 7-7 Values, signal procedure, y4 5-10, Zero divide, 6-10 0.0, Index-~7 6-14 representation of, 7-11 VAX-11 FORTRAN User's IV~PLUS Guide AA-DO35A-TE READER'S NOTE: This form is use comments discretion. eligible Report to COMMENTS for document comments only. DIGITAL will submitted on this form at the company's If you require a written reply and are receive (SPR) one service, under Software Performance submit your comments on an SPR form. Did you find this manual understandable, Please make suggestions for improvement. Did page you find number. indicate DOodoodo Please errors the Assembly in this manual? type of language Higher-level reader If usable, so, and well-organized? specify the language programmer (experienced) User with little programming experience Student programmer Other (please specify) Name Date Organization Street City. State and that you most nearly represent. programmer Occasional programmer error Zip Code or Country the — — — — DoNot Tear-Fold Hereand Tape¢ — — — — — — — — — dlilgliltiall No Postage Necessary if Mailed in tl United State BUSINESS REPLY MAIL FIRST CLASS PERMIT NO.33 MAYNARD MASS. DNCTACE A1 TAO L AN H RT/C SOFTWARE PUBLICATIONS TW/A14 DIGITAL EQUIPMENT CORPORATION 1925 ANDOVER STREET TEWKSBURY, MASSACHUSETTS - — — Do Not Tear - Fold Here 01876
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies