Digital PDFs
Documents
Guest
Register
Log In
AA-V193A-TK
July 1983
236 pages
Original
10MB
view
download
OCR Version
10.0MB
view
download
Document:
F77langRf Jul83
Order Number:
AA-V193A-TK
Revision:
0
Pages:
236
Original Filename:
AA-V193A-TK_F77langRf_Jul83.pdf
OCR Text
PDP-11 FORTRAN-77 Language Reference Manual Order No. AA-V193A-TK July 1983 This document describes the syntax and semantics of the FORTRAN-77 implementation of PDP-11 FORTRAN. It does not, however, present infor- mation specific to any operating system. SUPERSESSION/UPDATE INFORMATION: This is a new manual for this release. OPERATING SYSTEM AND VERSION: RSX-11M V41 RSX-11M-PLUS V2.1 RSTS/E V8.0 VAX/VMS V3.2 SOFTWARE VERSION: FORTRAN-77 V5.0 digital equipment corporation - maynard, massachusetts First Printing, July 1983 The information in this document is subject to change without notice and should not be <construed as a commitment by Digital Equipment Corporation. Digital Equipment Corporation assumes no responsibility for any errors that may appear in this document. The and software described in this document is furnished may be wused or copied only in accordance with under a 1license the terms of such license,. No responsibility equipment that affiliated is assumed for the use is not supplied by Digital companies. or reliability of software Equipment Corporation or on its Copyright (:) 1983 by Digital Equipment Corporation All Rights Printed in Reserved. U.S.A. The postpaid READER'S COMMENTS form on the last page of this document requests the user's critical evaluation to assist in preparing future documentation. The following are trademarks of Digital Equipment DEC DIBOL RSX DEC/CMS DEC/MMS EduSystem IAS VAX DECnet MASSBUS VMS DECsystem—-10 DECSYSTEM=-20 PDP PDT VT DECUS RSTS DECwriter Corporation: UNIBUS mfl@flflan HOW TO ORDER ADDITIONAL DOCUMENTATION in Continental USA and Puerto Rico call 800-258-1710 In New Hampshire, Alaska, and Hawaii call 603-884-6660 In Canada call 613-234-7726 (Ottawa-Hull) 800-267-6146 (all other Canadian) DIRECT MAIL ORDERS (USA & PUERTO RICO)* Digital Equipment Corporation P.O. Box CS2008 Nashua, New Hampshire 03061 DIRECT MAIL ORDERS (CANADA) Digital Equipment of Canada Ltd. 940 Belfast Road Ottawa, Ontario K1G 4C2 Attn: A&SG Business Manager DIRECT MAIL ORDERS (INTERNATIONAL) Digital Equipment Corporation A&SG Business Manager c¢/o Digital's local subsidiary or approved distributor *Any prepaid order from Puerto Rico must be placed with the local Digital subsidiary (809-754-7575) Internal orders should be placed through the Software Distribution Center (SDC), Digital Equipment Corporation, Northboro, Massachusetts 01532 ZK2402 CONTENTS Page PREFACE . ASSIGNMENT STATEMENTS ARITHMETIC ASSIGNMENT LOGICAL ASSIGNMENT e 4 s o bt b o e b ® o ® e [ e . b [) . . NtohJNtchNtoh)N | 1 HFOWWOUNNAUdWWN o 8 o 6 ¢ © o ® & ¢ O g P o O ¢ & ¢ 6 ¢ ¢ ¢ o o e o o o o o e [N O o g ® ® © o o o 4 ¢ e o o ° o * g v ¢ ® ¢ ® ¢ * o € ¢ ® o o o o & o o o © o ® & ® o (T o n e o o o o (De 0 [ o © o . % s ° * . 'Y L3 * [) Y ¢ © [2 =~ J o o o o STATEMENT STATEMENT iii i o o Arithmetic Expressions . Use of Parentheses . . Data Type of an Arithme Character Expressions Relational Expressions Logical Expressions . o . o e . o e o . e o o o'o"O.‘-o. ¢« o ¢ e . o SUBSTRINGS EXPRESSIONS o . Array References Without Adjustable Arrays . . . CHARACTER 0o o s . Array e an (D o . . ¢ of . . o Type . . o . o . Storage & . [NNe =1 T e n Q s o o « o Implication o Data ¢ Declarators Subscripts Array by « o + o . (T e Array Typing . &« o o o & Specificatio o Constants o Hollerith VARIABLES . & ¢ Data Typing by . @ o 4 o o 2 o o o Real Constants . . . . Double-Precision Constant nts Complex Constants . . . . Octal and Hexadecimal Const a n Logical Constants . . Character Constants .. o L) L4 o [ L] (T e o . o o . o o o o o & o ¢ o . Constants o . o .+ o . . o . . o . . e . . [Tle x . . ¢ NAMES Integer Data [ [ COMPONENTS TYPES ARRAYS ° 'Y . = . . ¢ W . . STRUCTURE . . * STATEMENT . [ INCLUDE . Indicator . . Field Number UNIT . . . L Sequence PROGRAM . . . . N Continuation Field Statement Field . CONSTANTS RN Indicators . . . = Comment SYMBOLIC [NS Field Debugging-Statement DATA AU W N Formatting Label o Statement . WwWwwWw Tab-Character Formatting tin e b | . ® LINE Character-per-Column & . o . L FORTRAN . . . o A . . o . Set [) . . [ . . . e . . L Comments Character . [] Statements . . & OVERVIEW WOOOONJIJJAAUNHDWWW FORTRAN=-77 e wWN - PDP-11 ELEMENTS FORMATTING AUV MdbwwwwwwwwwhphdDd - PROGRAM STATEMENT NSNNNNNNOOM OO Na e RWWWWWWWwW WN - NNNMNNNNNONMDNNNNNNOMDNNMDODMODNDNNDNNNDNDNDNDNDND ww W CHAPTER LANGUAGE TO - CHAPTER INTRODUCTION [\ I e T S o = S Wy 1 N CHAPTER ix STATEMENT CONTROL . S I L O i N G O~ I i Y i A A & . . STATEMENTS STATEMENT DECLARATION . . . STATEMENTS Numeric Type Declaration St atements Character Type Declaration Statements DIMENSION COMMON STATEMENT STATEMENT VIRTUAL . STATEMENT Restrictions Virtual on Array EQUIVALENCE HOWLWOAUMd LS WNDNDN L] [ [ o e . [ [ ¢« auoononnng G,y i 1 = OWONWUM D WWN IMPLICIT « L . . « STATEMENT L END L) . . . . . PAUSE STATEMENT STOP STATEMENT . [y + pPs . . > « o Lo - + ° » DO . in ° « STATEMENT STATEMENT [] . . « . . . LoopsS STATEMENT TYPE .« [} « [ DO « L] . Control L4 . Iteration L] STATEMENT | o Py ¢ L] o Py o ¢« Arithmetic IF Statemen . Logical IF Statement . . . Block IF Statements . . . Statement Blocks . . . . Block IF Examples . . . Nested Block IF Consructs - . . . . . . . . . . . . . Using Virtual References STATEMENT . . . in Arrays Subprogra ms . . . . . . . . . . . . .« . & STATEMENT . . . . ARGUMENTS . . . . PARAMETER PROGRAM BLOCK . STATEMENT STATEMENT DATA & iv [) L] L4 L4 [] L] L4 A4 L] £ L i . o . ¢ . in Function Subprog rams L4 . Statement ENTRY . ENTRY 3 4 4 .1 . . . . L] . Statement Functions . Function Subprograms . Subroutine Subprograms * USER-WRITTEN o SUBPROGRAMS 1 2 3 o & o Rules Governing Subprogram Arguments Adjustable Arrays . . . . Assumed-Size Dummy Arrays AN i | i I I NHEOJAUTH N . . . P . . STATEMENT STATEMENT (o) W0 ) & . & o . o « . 8 ¢« . ¢ « . INTRINSIC DATA . & + STATEMENT o STATEMENT O SAVE EXTERNAL o Making Arrays Equivalent . Making Substrings Equivalen t Extending Common Blocks . © N W N L ® . « RETURN N ® Y Statement . CONTINUE WN - . Ld L] TO CALL = L] . PY GO Control Transfers Extended Range . . L] L4 o STATEMENTS Nested W N . - ¢« o W N * s . o o s T o Assigned DO wn 9 & o *» o « L) Stateme nt . DO HEFRFFRFOOJOASTAANNUVTUNTUTE WN NN KK . . « s o wN = O o e ¢« Statement SUBPROGRAM o « TO SUBPROGRAMS o .+« GO TO GO IF NDNDNE . Computed 2)] oottty n STATEMENTS Unconditional (o)W e We Mo Mo We) We) Mo We)We)) CHAPTER TO STATEMEN T LABELS STATEMENTS SPECIFICATION e CHAPTER GO WWwwwN = ® s 8 O R R I N S ® Y- o N o s e it~ T ASSIGNMENT ASSIGNING LCONOAUTBWWWWWRNNONNDNDDNDNDOND R CHARACTER 3.4 NN CHAPTER 3.3 [~ CONTENTS CONTENTS ENTRY in INTRINSIC 6-13 FUNCTIONS 6-13 . . 6-14 3 Intrinsic and Usage 6-15 4 Character Functions and Lexical Comparison L] L] L . L * - L L ® L4 Generic Function 6-13 Library Ll o o o o o o .« ¢« . o o . ¢ « o o « ¢ &« o o « o « o o « « .« o & . & . o .1.4 Access o o L] . L) L4 . [) L L) [ . . L] [} . w N - I 1 . Sequential READ Statements The Formatted Sequential READ Statement The List-Directed READ Statement The Unformatted Direct N~ The e o Access Formatted The . Sequential e READ Direct o & s 7-15 7-15 RE AD 7-17 e Statements Access READ Direct Unformatted e ¢ ¢ & o ® L4 | . e . NN . e & . NN . o . . © . . . & [ « o STATEMENTS & . . s . Spe01f1ers o . . L) READ RULES . » Transfer-of-Control . . . . 4 o . ¢ . I/O List . . + + ¢ Simple List . . Implied DO List The ° . . The . N NN . . ° . . . @ * AN D WN [\ . o e °« L] L} NN . . I/0 STATEMENT COMPONENTS The Control List . . . . Logical Unit Specifier Internal File Specifier Format Specifier . . . . Record Specifier . . . . Key Specifier . . . . . THE * L] [] [] e L] [] L] * o . . SYNTACTICAL BB B L] D D g N NANSNNNNNNNNS . o . Access . o . Statement LAauuuonoog.b &b o Sequential Access Direct Access . . Keyed . o (S o o . .« . o Modes o NN NNNSNNSNNN 1 { o o . . . ¢ 4.3 « = o 4.1 4.2 . W N HFONNNOOOVIUUUbaDdWWWWHNN o Files . & ¢ & o o o o o o Sequential Organization Relative Organization . Indexed Organization . . Internal Files . . & ¢ ¢« ¢« @ Records 1.2 .1.2.1 1.2.2 .1.2.3 .1.3 . 1.1 NN N A N N N STATEMENTS = ~J S WNNONNNNNNNN R e b Subprograms LIBRARY . . INPUT/OUTPUT NN NUNNNSNNNSNNNNNSNNNNNNEN N NNNNNNNS OTHER Intrinsic Function References Generic Function References . 1 2 7-18 Statement Access 7-18 READ o o o 9 o o o o ~NSNoooooomuioahan = Formatted Unformatted The W N o o o e ¢ * N B e e Statements The Internal WRITE Indexed READ . READ Indexed . . ¢« .« « 7-19 Statement READ Statement STATEMENTS Statement The 1 2 Indexed . & 7-23 The The The THE REWRITE The THE WRITE Statement STATEMENT Indexed The The Statements . Formatted Indexed WRITE Statement Unformatted Indexed WRITE Statement Internal . REWRITE . . . Statement Formatted Indexed REWRITE Statement Unformatted Indexed REWRITE Statement ACCEPT STATEMENT 7-23 1-24 7-24 7-25 7-26 7-27 7-27 . WRITE 7-20 7-21 7-21 The Sequential WRITE Statements The Formatted Sequential WRITE Statement The List-Directed WRITE Statement The Unformatted Sequential WRITE Statemen t The Direct Access WRITE Statements The Formatted Direct Access WRITE Statement WRITE Direct Access The Unformatted Statement e READ The L) L] * Indexed N . . oW w W The THE NN ® [ ] « s o 7-19 NNNNNNNAGN CHAPTER Subroutine AND . . . . .« & 7-27 7-28 7-28 7-29 7-29 7-30 7-30 7-30 7-31 CONTENTS THE TYPE 8 FORMAT AND PRINT 7-31 STATEMENTS STATEMENTS —QPP TT T T TTT T TO . R c3I PR & CLOXDOu O <<«CONELo bt CHAPTER 7.8 (PCTMoEHI@eO5SRt< L L * L ] * L) * L L L Ll L] L L] » L] * L L] gX 4+ Le&o4@ - L * L2 . L * L4 * L] L4 9 eo*[, (e&o°i eo*, Eo+ o4 eo 2eo eo¢l AUXILIARY O @) INPUT/OUTPUT ovooOo'.o-.oo- Ll L4 =3 . L ® L 2 * L] * L3 L] L L 4 * [J L3 . . L] vi = ) 1951 <C 3] STATEMENTS =] = 0Oor~rr~oo0 OOOO BRe 24 = CHAPTER O~ 3 e W00 o ~MN o } s =[« F] > E ] o o ¢ ey 30 mo Jm0o D=[ o 163] Ow o1= (SRd)]=L . ®* o e L] NN SSNd WO W CONTENTS 9. 9. A o o o o o o o o o 9-12 ¢ ¢ ¢ « o o o o o 9-12 RECORDTYPE 9-13 SHARED 9-13 9-14 . . STATUS . . TYPE . . . UNIT . . . . USEROPEN . . CLOSE 9-14 . . STATEMENT REWIND . o o STATEMENT BACKSPACE DELETE Sequential Direct UNLOCK . . STATEMENT AND DEFINE A. SN b WN THE A. B. B. B. C C. cC. C. FILE PARAMETER . OF 9-14 . 9-15 . 9-15 . 9-16 9-17 9-17 9-18 . . . . . . . ¢ ¢ o o o o 9-18 . ¢« ¢ ¢ « o o 9-19 STATEMENTS « « . INTEGER . . . . « o« o & . . . . . CONSTANTS OF THE EXTERNAL STATEMENT SETS CHARACTER CHARACTER SET SET RADIX-50 CONSTANTS LANGUAGE SUMMARY . AND . . . . . . . . . . CHARACTER SET . Range . EXPRESSION OPERATORS . . . . . . STATEMENTS . ¢ ¢ o o o o & . . . . . . . LIBRARY 9-18 ELEMENTS DECODE . . Statement INTERPRETATION FORTRAN ASCII . STATEMENT FORMS /NOF77 . STATEMENT STATEMENT CHARACTER W N+~ B ENCODE OCTAL . Statement A. FIND o DELETE DELETE STATEMENT ENDFILE o STATEMENT STATEMENT A. A. APPENDIX o . LANGUAGE A. APPENDIX ¢ ADDITIONAL WIN = APPENDIX 4+ = 9. 9. 9. 9. 9. 9. 9. 9. 9. 9. ¢ RECORDSIZE N 9. SNAVTUNT TS WN 9. 9. R e b s 9. RECL . ¢ ¢ FUNCTIONS INDEX 112~ 44~ 4- WD 1- FORTRAN Coding Form . . . . Line Formatting Example . . Required Order of Statements . . . . and Array o Storage Examples Nested Control of DO . « Block LooOpsS . Transfers o and o o o o o o o o Extended WD Equivalence of Arrays with Nonunity Lower Bounds Equivalence of Substrings . . . Equivalence of Character Arrays Multiple Functions in a Function Subprogram Multiple Function Name Usage . . Variable Format Expression Example . . 5 6— 8- Storage . o 5 6— Array o Constructs Equivalence 5 of ¢ IF 55— HF N FIGURE R WND - FIGURES . » vii CONTENTS o List-Directed Output Formats . . . . . Effect of Data Magnitude on G Formats Default Field Widths . . . . . Carriage Control Characters . Summary of FORMAT Codes . . . . & . . . . .« .« « o Generic and Intrinsic viii . . . « « « ¢ o ¢ o Functions ¢ o o o o o ¢ o o o« @ & . . . . . o @ o e o . ©® o ® o e o ) O ASCII Character Set Expression Operators e . OPEN Statement ‘Keyword Values . . . . Allowed Combinations of ACCESS Values . . Valid Access Modes for ORGANIZATION Keyword OFNNAWWDWHFERFOMALAENVION W LN « Types o)) N 0 0 | I NSl ow il o [ I = NN o Data 0wl Exponentiation Conversion Rules for Assignment Statements Types of User-Written Subprograms . . . . Generic Function Name Summary .« « « ¢ « & Available I/0 Statements . . « ¢ ¢ &+ ¢ o & Access Modes for Each File Organization . | . . QOwl . . N Entities Identified by Symbolic Names Data Type Storage Requirements . . . . @] [ Y Y Y Y U Y Y N A N I N N B NHFFWNHEBWNHFWNENEFWND - QOQPDOWOUOWOOOOIIIOATWNNDDND TABLES PREFACE MANUAL OBJECTIVES This manual describes the PDP-11 FORTRAN-77 systems that run on the elements language the PDP-11 of PDP-11 reference family FORTRAN-77 manual of for computers. No specific to any operating system is presented here. on a particular operating system, refer to the user's system or INTENDED Readers the who have will STRUCTURE OF manual e a basic derive THIS User's as operating information For information guide for that Guide. understanding maximum benefit of from the this FORTRAN nine chapters and three appendixes. Chapter 1 consists of general information FORTRAN-77 and introduces basic facts FORTRAN-77 Chapter programming manual. DOCUMENT contains PDP-11 ® FORTRAN-77 serves AUDIENCE language This PDP-11 and several 2 PDP-11 writing programs. describes statements, concerning needed for the including components symbolic of PDP-11 names, FORTRAN-77 constants, and variables. e Chapter used in e Chapter 4 discusses control statements, which from one point in the program to another, transfer Chapter which e 3 a 5 describes program. assignment describes specification characteristics of symbols type and array dimensions. e Chapter 6 supplied discusses with subprograms, PDP-11 1in both a PDP-11 Chapter 8 describes the FORMAT with formatted I/0O statements. statements e Chapter 9 on such OPEN, FORTRAN-77 information CLOSE, program, user-written e contains define values control define such as and the data those FORTRAN-77. Chapter e discusses which statements, used e as 7 statements, and input and used auxiliary output (1/0). in conjunction I/0 statements, ENDFILE. Appendix A describes some statements and language that provide compatible support for programs written versions of PDP-11 FORTRAN. ix features in older PREFACE e Appendix B summarizes the character sets supported by PDP-11 FORTRAN-77. e of elements language the summarizes C Appendix PDP-11 FORTRAN-77. ASSOCIATED DOCUMENTS The documents following are interest of FORTRAN-77 PDP-11 to programmers: FORTRAN-77 User's Guide e PDP-11 e PDP-11 FORTRAN-77 Object Time System Reference Manual ® PDP—ll_FORTRAN—77 Installation Guide/Release Notes CONVENTIONS USED IN THIS DOCUMENT The following conventions are in used this manual: in examples indicate that you e VUppercase words and letters used e Lowercase words and letters used in examples indicate that you are to substitute a word or value of your choice. e Brackets e the words and type should enclose optional ([]) shown. elements. enclose lists from which ({}) Braces letters as one is to be item can be element chosen. e (...) An ellipsis repeated In addition, the one or indicates that the more following characters: Tab character (@B Space character A preceding times. characters denote special nonprinting CHAPTER INTRODUCTION 1.1 LANGUAGE The PDP-11 Standard FORTRAN-77 to 1language subset the FORTRAN-77 FORTRAN as to obtain a American Standards York National You can use If the integer e subset the American X3.9-1978), standard, and National DIGITAL-supplied certain features defined by the ANSI Standard. copy of the ANSI standard, write to Institute, enhancements any Inc., 1430 Broadway, New For the York, the FORTRAN-77 array standard expression as not an type, it is converted expressions can contain elements of any data integer an subset is subscript. to type. type character. e The LOGICAL*1 e The IMPLICIT symbolic The to arithmetic expression Mixed-mode except e (ANSI 10018. The DIGITAL-supplied follow: e FORTRAN-77 comprises lanquage of full-language information on how New PDP-11 OVERVIEW FORTRAN-77 enhancements TO 1 and LOGICAL*2 statement data types redefines the have been implied added. data type of names. following input/output (I/0) statements have been added: ACCEPT TYPE _ Device-oriented I/0 PRINT READ WRITE FIND (u'r) (u'r) Unformatted direct—-access 1I/0 (u'r) READ (u'r,fmt) WRITE (u'r,fmt) Formatted DEFINE FILE File direct-access control I/0 and specification ENCODE DECODE READ (u,f,key) READ (u,key) Formatted data in memory Indexed 1/0 REWRITE DELETE Record UNLOCK and control update conversion attribute INTRODUCTION TO PDP-11 FCRTRAN-77 You can include an explanatory comment on the same line as any with an exclamation point begin comments These statement. (). placing by You can include debugging statements in a program These statements are compiled only 1letter D in column 1. the otherwise, qualifier; command compiler when you specify a they are You can in the treated as comments. use any arithmetic computed GO TO expression as the control parameter statement. Virtual arrays provide program address large data areas outside of normal OPEN, CLOSE, space. You can include the specification ERR=s in any DELETE, UNLOCK, BACKSPACE, REWIND, or ENDFILE statement FIND, to transfer control to the statement specified by s when an error condition occurs. The INCLUDE statement incorporates FORTRAN statements from separate file into a FORTRAN program during compilation. The INTEGER*4 data You can use octal numeric type provides a sign bit and 31 data bits. and hexadecimal constants in place Double-precision Function forms, function FORTRAN-defined a control real of data £features of types including LEN, including double-precision including ICHAR, and INDEX S§,SP,SS,T,TL, selection based on argument and TR data type for functions or double-precision variable as a DO statement variable Use of any increment, or Use complex edit descriptors, Generic CLOSE and subprograms, Exponentiation of any use character substrings and all the character functions defined in the full language except CHAR. In addition, PDP-11 FORTRAN-77 includes the following full-language FORTRAN as defined by the ANSI Standard: Use of constants. You can intrinsic Format a and OPEN the transfer arithmetic final value expression as the in a DO statement. 1initial wvalue, statements specification control to the ERR=s in statement READ or WRITE specified statements by s when to an error occurs Use of format list-directed specification 1/0 to Use constants expressions of REWRITE, TYPE, and and PRINT perform in statements formatted the I/0 1I/0 1lists without of a WRITE, INTRODUCTION e Specification of lower TO PDP-11 bounds FORTRAN-77 for array dimensions in array declarators 1.2 e Use of ENTRY statements in SUBROUTINE to define multiple entry points e Use of PARAMETER constant values PROGRAM statements to 1.2.1 subprograms symbolic names to ELEMENTS FORTRAN programs consist of statements statements are organized into program sequence of statements that defines a terminates FUNCTION assign All program program and with an END statement. A and optional comments. wunits. A program unit computing procedure program unit or a subprogram. An executable program and one or more optional subprograms. can be consists either of a one The is a and main main §Statements Statements are grouped into two general classes: executable and nonexecutable, Executable statements specify the actions of a program; nonexecutable statements describe data arrangement and characteristics, and provide editing and data-conversion information. Statements are a string of up one line, divided into physical to 80 characters. If can be continued on one it continuation lines. continuation information character on A in sections called lines. a statement is too long or more continuation the continuation sixth characters, additional 1line column of see A line is to fit on lines, called 1is that Section identified line. (For by a further 1.3.4.) You can identify a statement with a label to enable other statements to reference it: that 1is, either to transfer control to it or to obtain the information it contains. A statement label is an integer number placed in the first five columns of a statement's initial line. Any statement can have a label; however, only executable and FORMAT statements can be referenced with a label. l1.2.2 Comments Comments do not affect a documentation aid. freely to describe the program processing You can, actions of and a in any way; they are are encouraged to, use program, to identify merely comments program sections and processes, and to facilitate the reading of source-program listings. The letter C or an asterisk (*) in the first column of a source 1line identifies that 1line as a comment. 1In addition, if you place an exc¢lamation point (!) in any column of a line except column 6, the rest of that line is treated as a comment. (However, if you place an exclamation point in column 6 of a line, that line will be treated as a continuation line.) Any printable character can appear in a comment. INTRODUCTION 1.2.3 The Character PDP-11 1. FORTRAN-77 Set FORTRAN-77 All TO PDP-11 character uppercase and set consists of: letters (A lowercase through Z, a through z) 2. The numerals 0 through 9 3. The special characters listed below: Character A or Name (A8 Space or tab = Equal sign + Plus - Minus * Asterisk / Slash ( Left ) Right v Comma . Period ! Apostrophe sign sign parenthesis parenthesis Quotation S Dollar mark sign Exclamation point Other : Colon < Left > Right printable ASCII characters can angle angle Except in character 1.3 between and Hollerith uppercase FORMATTING A FORTRAN FORTRAN has Every line statement A e A continuation-indicator a FORTRAN (see the lowercase letters. fields: e in constant constants, LINE four label and bracket appear only as part of a character or Hollerith a list of printable characters). distinction bracket field field statement Appendix compiler B for makes no INTRODUCTION You e A statement field ®¢ A sequence number can per format column a FORTRAN TO PDP-11 FORTRAN-77 field line in two (character-per-column ways: 1) by typing formatting); or conjunction one 2) character by using, in with character-per-column formatting, the tab character (tab-character formatting) to get from field to field. You can use character-per-column formatting when punching cards, writing on a coding form, or typing on a terminal keyboard; you can use tab-character formatting, terminal keyboard. l.3.1 As Character-per-Column shown in fields: and a of each Each however, Figure a 1-1, statement sequence a column represents you are typing at FORTRAN a a single To get space, from one into which field to can another, be placed you type space individually until you arrive at the correct position. example, in Figure 1-1, to enter the comment, after typing 'C' press the space bar five times and then begin typing the comment. FO RTRAN ) CODEr CODING FORM C Comment STATEME{NT e t2343 C + + FORTRAN STATEMENT ¢ IDENTIFICATION | 7891011 121314150617101920212223242520272029303132333435363738394041 424344454647 4849505152515455365750506006162636465660676809 70N T2[7374757677 78798 DQ STRSLIELT 10, =11, .2 W e .50, R B LA R I T I N B I B =Jr 442 L e i R R TA e e | e e + :JM—++ R —— 2Ll b+t 8 e I e S + i e T e e o e e e SB T S S R T T I T Tk SR R S VTSR U I O S S ararey R T I S N R RN N N e e 4 e e e I S S S S S e e e e e e e e e P ey Gy b T T T IR T T U S S e e e e S e e + DR S e b e e] L§¢4+700<1-00—>f+k¢7f'00‘*—«00900'¢§0'-0<400‘0t"¢4'rroro—’¢0v90v-0¢~o»+—0A—4¢—4——+—0—| R GQ LF (J,LY. SQRT (FLOAT (1))) B e 1O 4 i + S eS R SS S A A =S T ) bt oot Aeeornsle P . - TYPE f‘vo‘.sv‘ 4100"—'»'&—*4-—0-44v¢4'0'0040—71—f'oofl—rvq—fflvvvv"otfo000'0¢vf!00~v?r0 S :O‘NTIAU+E—+¢‘k»+—$+++—0v¢+¢-4~¢oaf—r¢7—44»+o B O + AR 1,05 I pe—y S R S ‘0 AR O e st bl »——0——&—«4—--'—«50—0-(49—02-&-4—54-‘&4—1¢00h+5r0 L e eA e e e v R Jc—_kl—vvooowo—+4oofoo—+oo-q—*»o+o+++oa»oooo&»r—+¢—v—0<+wooroo'frv—o¢¢o¢4‘oq—4+—o +—+ ., PAGE € H TéHel es‘ +P4R.O+QRAM ‘CA.LS:*U‘LAJ‘E ‘54 ffi’l‘ME. »N%Mthgéo +F+R—+00M 4-‘&‘+-rT.oQ¢ 45+O¢ R e ST 4 Oate PROBLEM 2 & e e i e FORMAT, B i R LA B S i e e R S LS, PR M e e e S Sl S e S ST S SHD I A SP S ST ST S S S T T T S TRT R S et TR I IS I A 2 T T S ) e e S S epr ep e e O L =) R I SO R R e e S eet e ND, R e e T B I e BT R L 44—+ — M oot + S +—44+-+ + ot W Y V234 PG-3 S A e o e S o R I S b4 S S e e e 44— S S e S e T S e e S L e e i .4 o R A A e Sl e e b o e 4 e e e e b e e A B A& e i e e e i e 2 D 4 o A o R I o e i B A S 4 I Tk i I S TR R B A ee S o i i I e i T S T e e o oo S I e S 42 b b A T A e e i 4 A R e 4 B i 4 e I S e e A I RLTT SN e T o S e i W I I eS S e e e U W T S e U B e e S T G T W e Y W W e o e R S Ii B e e T ik = e i Y W e R e e W W e S U Wy W W G PP UL TEFOEPRPS PO S S W U S S R S P U S S S S W U S G e et e e e sk o S S e G PRSP S S G U =SB SY JHE SRS SUT ST RN SN SRS SRS SR S e S U e e ok T + e et i e ot JE T S PGSR et P S S S Y bbbttt e I W A (R S e e S e ee N IR SR N . bbbt i S e e e B R + i e e A e e R i e S dpmpredmedeoreeormeedbepored ilB —— i O S G S G o 2 i = TR T Be S S o o = T == S o SO S o i G W SR Y U VD U U W e R R Sy S G S b B SRS SR T G e N W R S = R Y Y S W ¢ 316170910010 12131413101710192021222324232627202930313233341330)70D94041 4243644540 47484930315233134533437383960010703040308 07080270 N 1M 7aTs 77 PUPR DIGITAL a line is divided into four separate continuation indicator, statement text, (Sections 1.3.3 through 1.3.6 describe the use number. character. when Formatting label, field.) single only EQUIPMENT CORPORATION . MAYNARD, MASSACHUSETTS ZK-203-81 Figure 1-1: FORTRAN Coding Form a each For you INTRODUCTION TO PDP-11 FORTRAN-77 Field Statement Column(s) label Continuation 1 indicator l1.3.2 Tab-Character 5 through 72 6 Statement Sequence through 7 number 73 through 80 Formatting You can press the tab character to move to the continuation-indicator field from the statement label field, or to the statement field from the continuation-character field; however, you cannot move to the sequence-number field by using the tab. Figure 1-2 compares keystrokes in lines typed with tab-character formatting with those in lines typed with character-per-column formatting, Format Using TAB Character Character-per-Column Format 12 3 4 5|6}7 8 9 10|11 12 13 14 15616 C @8 FIRST VALUE C FIHIR|S|T VIA|L 0@ | = J + 5«K + 1]0 I + 1 L*M 1 @B IVAL = I+2 = J 1718 19 20 |UI|E 5[+ |K + Lf=IM I |[V]A]|L = I |+12 ZK-204-81 Figure 1-2: Line Formatting Example In tab-character formatting, the statement-label field consists of the characters you type before you type the first tab character; however, the statement-label field cannot have more than five characters, After you type the first tab continuation-indicator field or character, a statement To enter a continuation-indicator field, statement field then consists of all this digit, to the end of the line. you <can field. enter either you type any digit; the characters you type a the after To enter a statement field without entering a continuation-indicator field, you simply type the statement immediately after the first tab. (No FORTRAN statement can start with a digit.) INTRODUCTION TO PDP-11 FORTRAN-77 Many text editors and terminals advance the terminal print carriage to a predefined print position when you type the TAB key. However, this action is not related to the PDP-11 FORTRAN-77 compiler's interpretation of the tab character described above. If you use the tab character to improve the legibility of a FORTRAN statement, the spaces introduced into the statement are ignored by the compiler but are printed in a source listing. Tab characters in a statement listing, a the next forth). l1.3.3 A field are ignored by the compiler as well. 1In a source tab causes the character following the tab to be printed at tab stop (which is located at columns 9, 17, 25, 33, and so Statement statement the Label label, or statement-label leading 0s are Any statement two statements You can use Field number, field ignored. (An referenced within two a special consists of by a all-zero another program of up to statement's indicators statement statement unit can in have the five initial decimal line. label must the is have same £first digits Spaces in and invalid.) a 1label. No label. column of a 1label field: the comment indicator and the debugging-statement indicator. These indicators are described in Sections 1.3.3.1 and 1.3.3.2. The statement label field of a continuation line must 1.3.3.1 Comment Indicators - The letter C or an column 1 of a line indicates that the entire line exclamation point (!) in any column of a 1line indicates indicate a that the blank comment. The compiler then ignores prints it. remainder a comment of line the in line a is a be blank. asterisk (*) 1in is a comment. An except column 6 comment. source-—-program All blanks 1listing and 1.3.3.2 Debugging-Statement Indicator - The letter D in column 1 of a line designates the contents of the statement field as a debugging statement. A debugging-statement line can have a statement 1label in the four remaining columns of the 1label field. If a debugging statement is continued tc one or more other lines, every continuation line must have a D in column 1 and a continuation indicator in column 6. Debugging statements are not compiled wunless you use a compiler command to specify that they be compiled. 1If you do not specify debugging-statement compilation, any debugging statements are treated as comments. For a description of the available compilation commands, refer to the PDP-11 FORTRAN-77 User's Guide. 1.3.4 Continuation Field A continuation indicator is any column 6 of a line, or any digit A statement can be divided into character (except 0) continuation (except 0 or the first after lines at any space) tab. point. in INTRODUCTION TO PDP-11 FORTRAN-77 The compiler considers the characters after the continuation character to follow the last character of the previous line, as if there were no physical breaks at that point. If a continuation indicator is 0, the compiler considers the 1line containing it to be the first line of a statement. Comment lines cannot be continued. They can, however, occur between a statement's initial 1line and 1its continuation 1line or lines, and between successive continuation lines. 1.3.5 Statement Field The text of a statement is placed in a statement field. Because the compiler ignores all tab characters and spaces in a statement field except those in Hollerith constants and alphanumeric literals, you can space the text in a statement field in any way you desire to maximize legibility. The use of tabs for spacing 1is discussed 1in Section 1.3.2. NOTE If a 1line extends beyond character position 72, the text following position 72 is ignored; no warning message 1is printed. 1.3.6 Sequence Number A sequence number or columns 73 through 80 this field. Remember that tab--character 1.4 PROGRAM you Field other of any cannot identifying information can appear line; the compiler ignores characters in in move by to the sequence-number field formatting. UNIT STRUCTURE Figure 1-3 shows the allowed order of statements in a PDP-11 FORTRAN-77 program unit. In this figure, vertical lines separate statement types that may be interspersed with one another -- that is, occur in any order relative to each other. For example, comment lines and FORMAT statements statements of be For and may executable occur before, statements (see between, next or paragraph) body the program. Horizontal lines indicate statement types that cannot interspersed but must occur in a prescribed order within a program. example, or an IMPLICIT after an statement END cannot occur before ELSE, ACCEPT, OPEN, ENDIF, FIND, CLOSE, CONTINUE, DELETE, CALL, declaration. COMMON, STOP, PAUSE, REWRITE, RETURN, ‘"specification" DIMENSION, a PROGRAM 1-3 block include: IF, ELSE statement. The "executable" statements mentioned in Figure assignment, ASSIGN, GOTO, arithmetic IF, logical IF, The DATA in a statement IF, after and DO, READ, BACKSPACE, WRITE, ENDFILE, PRINT, REWIND, TYPE, UNLOCK, END. statements EQUIVALENCE, mentioned EXTERNAL, in Figure INTRINSIC, 1-3 SAVE, include: and type INTRODUCTION TO PDP-11 FORTRAN-77 PROGRAM, FUNCTION, SUBROUTINE, or BLOCK DATA Statements IMPLICIT Statements PARAMETER Other Comment Statements Specification Li tnes FORMAT and INCLUDE Statements and Statements ENTRY Statements Statement Function DATA Definitions Statements Executable Statements END Line ZK-205-81 Figure 1.5 The INCLUDE INCLUDE are to 1-3: Order specifies that incorporated statement. INCLUDE The statement INCLUDE INCLUDE of Statements the contents and Lines STATEMENT statement be Required has into no has a effect the compilation on program of a designated directly following file the execution. form: 'filespec[/[NO]JLIST]' filespec A file specification that represents file specification (See the PDP-11 specification.) in the the file must form to be be of a character included acceptable FORTRAN-77 User's to Guide in a the for constant string compilation. This system. operating the form of a file The /LIST qualifier specifies that the statements in the designated file are to be included in the compilation source listing; an asterisk (*) precedes each statement included. The /NOLIST qualifier specifies that the statements 1in the designated file are not to be included in the compilation source listing. The default 1is /LIST; that 1is, the compiler assumes /LIST if you do not specify either qualifier, When the compiler statements the from designated, file, the statement, encounters the or included, compiler an current reads INCLUDE file file. the and When next statement, begins it it reading reaches statement stops reading statements the after end the of from this INCLUDE INTRODUCTION TO PDP-11 FORTRAN-77 An INCLUDE statement can be contained in an included file. each An included file cannot begin with a continuation 1line; file. single a within contained completely be statement included must that The INCLUDE statement can appear anywhere a comment 1line can : appear. Any PDP-11 FORTRAN-77 statement can appear in an included file; however, all the statements in an included file, when combined with the other statements in a compilation, must satisfy in shown the requirements 1-3. Figure In the following example, the included file COMMON.FTN defines the size of the blank COMMON block and the size of the arrays X, Y, and Z. File COMMON.FTN Main Program File INCLUDE 'COMMON.FTN' DIMENSION Z (M) CALL DO 5 CUBE I=1,M 5, X(I)+SQRT(Y(I)) Z(I) SUBROUTINE INCLUDE po 10 10, X(I) I=1,M = Y(I)**3 RETURN END CUBE 'COMMON.FTN' ' PARAMETER (M = 100) ,Y (M) COMMON X (M) CHAPTER STATEMENT PDP-11 FORTRAN-77 statements Constants -- cannot changed be fixed are COMPONENTS composed values, by 2 such program symbolic These can be changed by groups of values that Arrays -- as names that are called Function references -lists of arguments. performs a specified trigonometric sine) represent are be referenced individually subscript, or collectively by values -- components: These values array stored values. statements. stored contiguously by a a symbolic symbolic name and with name a only. elements. function names optionally followed by A function 1is a program unit that computation (for wusing arguments reference; the resulting value is then function reference. Expressions basic numbers. program can Individual five statements. Variables -values of example, supplied used in computing a function by a place of the combinations of references, constants, variables, array and operators. An operator is a unique symbol for a particular operation (such as multiplication) that obtains a single result, elements, function Variables, arrays, and functions have symbolic names. is a string of characters that identifies an entity in Constants, following variables, data arrays, types: expressions, and A symbolic a program, functions can have name the Logical Integer Real Double-precision Complex Character Symbolic names, (except data function references references are for types, discussed are in functions) and all the discussed Chapter 6. statement in this components chapter; except function STATEMENT COMPONENTS 2.1 SYMBOLIC NAMES Symbolic names identify the entities that can appear in a program The entities that symbolic names identify are listed in Table unit. 2-1, where the column labelled "Typed" indicates whether an entity has (Data types are discussed in a data type (such as real or integer). Section 2.2.) Entities Identified by Symbolic Names ‘Table 2-1: Entity Typed Yes Yes Yes Yes Yes No No No No Yes Yes Variables Arrays Statement functions Intrinsic functions Function subprograms Subroutine subprograms Common blocks Main programs Block data subprograms Dummy arguments Function entry points No ‘Subroutine entry points Parameter Yes constants (letters and digits) is a string of characters A symbolic name If the first character must be a letter. totaling a maximum of six; automatically will system the used, are characters more than six truncate the name to six characters during compilation. invalid symbolic names are: Examples of valid and Invalid valid (begins with a numeral) 5Q NUMBER (contains a special character) B.4 K9 the is, unit -- that Symbolic names must be unique within a program symbolic name cannot be used to identify two or more entities in same the unit. same program In executable programs consisting of two symbolic name throughout all for the any of program units: e Intrinsic functions e Function subprograms e Subroutine e Common ® Main ® Block e Function entries ® Subroutine subprograms blocks programs data the subprograms entries or following more program entities units, a must be unique STATEMENT Therefore if, for example, one function named UMP, you other entity anywhere else separate program unit. 2.2 COMPONENTS of your program units contains a cannot use UMP as the symbolic name for any in your program, even 1in a completely DATA TYPES Each basic statement component in a PDP-11 FORTRAN-77 program (constant, variable, array, function reference, or expression) has assigned to it one of six data types that specifies the kind of wvalue it can represent. The data types and the values they represent are: e Integer -- e Real -decimal for decimal fraction Double precision e for Complex number: second whole number a decimal number: that 1is, fraction, or a combination of many maximum e a —-—- -- for for a pair the ‘first representing e Logical -- e Character a significant for -- the for number as with whole number, whole number and more than twice a a as real of real numbers representing a complex value representing the real part, the the imaginary value a real digits a a true sequence or of part the value false characters The data type of a basic component can be assigned in one of three ways: it can be inherent in the component's construction (as in constants); it can be implied by a naming convention (with or without an IMPLICIT statement); or it can be explicitly declared. Whenever a value of one data type is converted type, the conversion is performed assignment statements (see Table 3-1). For the memory data purpose of type These PDP-11 FORTRAN-77 The type form PDP-11 variations) above, data facilitating requirements, data addition types data requires *n in appended are types, for control FORTRAN-77 to of the well a as value to six in Table the for performance and data data 2-2, amount another rules several basic of the processing provides included as to according types types which of (or 1listed lists memory all each storage. to a data type name is called a data-type length specifier. 2.3 CONSTANTS A constant represents values true or false, Octal, hexadecimal, constants appear assume (see the Section a fixed value and can be or a character string. and Hollerith data type 2.3.8). constants prescribed by a have the number, no data context the 1logical type; in which these they STATEMENT Table 2-2: Data COMPONENTS Type Storage Data Type Requirements Storage Requirements (Bytes) BYTE la LOGICAL 2 LOGICAL*1 la LOGICAL*2 LOGICAL*4 INTEGER 2 2 INTEGER*4 4 REAL 4 REAL*4 4 REAL*8 The or 4b 8 PRECISION 8 COMPLEX 8 COMPLEX*8 8 CHARACTER*1len len l-byte values storage true integers b: 4b 2 4 : INTEGER*2 DOUBLE a: or in or the area can false, a range -128 contain single to ¢ . the 1logical character, or +127. Either two or four bytes are allocated depending on compiler command qualifier specified. The default allocation is two bytes. When four bytes are allocated, all four bytes are used for computation. the c: The value specified; the BYTE and 2.3.1 An range LOGICAL*1 Integer integer have a integer of 1 1len this to are 1is the number number can be any Leading constant is a whole sign and 1is has the form: optional sign. 0s, if decimal point. Constants 1leading constant string within synonymous. number of numeric any, are characters. ignored. with no interpreted nn A characters integer 255. snn An of as a decimal It can number. An STATEMENT A minus sign sign 1is must appear optional assumed to Except for the sign, other than the numerals The be absolute before before a a COMPONENTS negative positive integer constant (an constant; unsigned a plus constant is positive). value an of integer 0 constant through an cannot contain a character 9. integer constant cannot be greater than 2147483647. Examples of valid and valid invalid integer constants are: Invalid 0 99999999999 3.14 32,767 -127 +32123 (too large) (decimal point and comma hot allowed) -~ If the value value 4-byte 2.3.2 A A data constant a is within 2-byte type; signed Real real one a represents INTEGER*2 a of if a quantity value and is is range -32768 quantity outside treated as and this an to +32767, 1is treated range, it INTEGER*4 this as an represents data type. Constants constant is a number with of three forms: e As a basic real constant ® As a basic real constant e As an basic the signed real integer constant constant is a a decimal followed followed string of point by by a decimal a and can decimal decimal digits occur in any exponent exponent in one of three formats: S.nn snn.nn snn. s An optional sign. nn A string of decimal digits. The decimal digits is Leading 0s counting point not (0s the can limited, to the appear anywhere but the left leftmost 0.00001234567, all of the the 0s is significant. A decimal Esnn exponent has the only of 7 the in first digits; nonzero form: the leftmost digits string. 7 nonzero are digit) therefore, are The digits are 1in significant, number of significant. ignored the but in constant none of STATEMENT COMPONENTS An optional An integer sign. nn constant. or real The exponent represents a power of 10 by which the preceding represents 1.0E6 example, for multiplied; be to is constant integer the value 1.0 * 10 ** 6. A real constant occupies four bytes and 1is interpreted as number with a precision, typically, of seven decimal digits. a real A minus sign must appear between the letter E and a negative exponent; a plus sign is optional between the letter E and a positive exponent. Except for algebraic signs and a decimal point, and the letter E if used, a real constant cannot contain a character other than the numerals 0 through 9. If the letter E appears exponent must follow it. can be in a real constant, an integer constant The exponent cannot be omitted; however, it 0. The magnitude of a nonzero real approximately 0.29E-38 or greater Examples of valid and invalid constant cannot be smaller than approximately 1.7E38. real constants valid Invalid 3.14159 621712. -.00127 +5.0E3 2E-3 1,234,567 325E-45 ~-47.E47 100 $25.00 2.3.3 than are: (commas not allowed) (too small) (too large) (decimal point missing) (special character not allowed) Double-Precision Constants A double-precision constant is constant followed by a decimal a basic real constant exponent of the form: or an integer Dsnn An optional An integer sign. nn constant. A double-precision constant occupies eight bytes and is interpreted as a real number with a precision, typically, of 16 decimal digits. The number of digits that precede the exponent is not 1limited, but only the leftmost A minus sign 16 digits must are appear significant. before a negative double-precision constant; a plus sign is optional before a positive constant. A minus sign must appear between the letter D and a negative exponent; a plus sign 1is optional between the letter D and a positive exponent. 2-6 STATEMENT COMPONENTS The exponent following the letter D cannot be can be The magnitude of a approximately than omitted; 0. Examples of valid nonzero double-precision 0.29D-38 and or invalid greater constant than however, cannot approximately double-precision constants are: Invalid 1234567890D+5 +2.71828182846182D00 1234567890D45 1234567890.0D~-89 (too (too +2.7182812846182 (no Dsnn this is large) small) real 2.3.4 Complex A complex a comma and real part the present; valid constant) a Constants constant is a enclosed of a pair in of integer or parentheses. complex number, part. A smaller 1.7D38. valid -72.5D-15 1DO be it real The the constants first second separated constant constant by represents the imaginary : complex constant has the form: (rc,rc) rc . A The real parentheses required. A constant. See complex complex and comma Section constant are 2.3.2 part for occupies of the eight the rules bytes complex for and is number. Examples of valid and invalid complex constant forming constants (1.70391,-1.70391) (1.23,) (second : missing) real Octal Octal and numeric and Hexadecimal hexadecimal constants; a constant is are not allowed) Constants constants you as (double-precision constants 2.3.5 are are: Invaliad (1.0,1.0D0) and constants. interpreted valiad (+12739E3,0.) real can are use alternative them wherever string of octal ways numeric to represent constants are enclosed by allowed. An octal constant is an unsigned apostrophes and constant the has followed by the form: 'clc2c3...cn'0 A digit in the range 0 to 7. alphabetic digits character 0. An octal STATEMENT COMPONENTS of string A hexadecimal constant is an unsigned hexadecimal digits A enclosed by apostrophes and followed by the alphabetic character X. constant has hexadecimal the form: '‘clc2c3...cn'X in the range A hexadecimal digit in the range 0 to 9, or a letter F or A to Leading a zeros are to £. Examples of valid in octal ignored specify up to 32 bits and hexadecimal invalid octal and valid Invalid '07737'0 '1'0 '7782'0 7772'0 '0737" and constants are: (invalid character) (no initial apostrophe) (no 0 after second apostrophe) (signed) '-4367" Examples of valid You can constants. (11 octal digits, 8 hexadecimal digits). invalid hexadecimal constants are: Invaliad valid 'AF9730'X 'FFABC'X '999.,'X (invalid character) 'FOX (no apostrophe before '-ACF4! (signed) the X) Octal and hexadecimal constants are typeless numeric constants; they assume data types that are based on the way they are used (and thus they are ® not converted before use), as follows: When the constant is used with a binary operator, including the assignment operator, the data type of the constant is the data type of the other operand. For Data Statement example: Type Length of of Constant Constant REAL*4 INTEGER*2 REAL*8 4 2 8 REAL*8 DOUBLE INTEGER*4 N RAPHA = '99AF2'X JCOUNT = ICOUNT + '777'0 DOUBLE = 'FFF99A'X IF(N.EQ.'123'0) e e GO TO 10 4 INTEGER*4 When a specific data type —-- generally integer -- is this type is assumed for the constant. For example: required, Statement Data Type of Constant Length of Constant Y(IX)=Y('15'0)+3. INTEGER*2 2 When the constant is used as an actual argument, no data is assumed; For example: however, a length of two bytes is always Statement Data Type of Constant Length of Constant CALL APAC('34BC'x) None 2 type used. STATEMENT e When the type is constant is assumed. For used COMPONENTS in any other Data Statement IF('AF77'X) An of octal or data. is more context, INTEGER*2 ~ of Type Length Constant = '7777'0 1,2,3 INTEGER*2 2 J = .NOT.'73777'0 INTEGER*2 2 'A39'X of Constant I - data example: INTEGER*2 2 hexadecimal constant actually specifies as much as 4 bytes When the data type implies that the length of the constant than the number of digits specified, the leftmost digits have a value of zero. When the data type implies that the length of the constant is less than the number of digits specified, the constant is truncated on the left. An error results if any nonzero digits are truncated. Table 2-2 lists the number of bytes that each data type requires. 2.3.6 Logical A logical following Constants constant specifies true two logical constants are or false; possible: therefore, only the .TRUE. .FALSE. The delimiting 2.3.7 periods are a required a string part of each constant. Character Constants A character enclosed by constant 1is apostrophes. A constant character has the of printable ASCII characters form: 'clc2c3...Cn’ A Both printable delimiting character. apostrophes must be present. The value of a character constant is the string of characters between the delimiting apostrophes. The value does not include the delimiting apostrophes, but does include all spaces or tabs within the apostrophes. Within a character constant, the apostrophe character by two consecutive apostrophes (with no space or between them). The length of the character constant 'is the number 1is represented other character of between the delimiting apostrophes (two consecutive apostrophes counting as one character). The 1length of a constant must be in the range 1 through 255. characters internal character STATEMENT COMPONENTS and Examples of valid invalid character constants are: valid Invalid '"WHAT?' 'HEADINGS (no trailing ' apostrophe) 'HE SAID, (character constant vy 1S:' 'TODAY''S DATE contain one character) at least (quotation marks "NOW OR NEVER" "HELLO"' must cannot be used in place of apostrophes) If a character constant appears in a numeric context (for example, as the expression on the right side of an arithmetic assignment statement), it 1is considered a Hollerith constant (see Section 203.8.) [ Hollerith Constants 2.3.8 A Hollerith constant character count A Hollerith and is a string of printable characters preceded the constant has letter the by a H. form: nHclc2c3...Cn An unsigned, nonzero integer constant stating the characters in the string (including spaces and tabs). A printable number of character. The maximum number of characters Hollerith constants are stored is as 255. byte strings, one character per byte. Hollerith constants have no data type; they assume a numeric data type according to the context in which they are used. Hollerith constants cannot assume a character data type and cannot be used where a character value Examples of valid is expected. and invalid valid Hollerith constants are: Invalid 16HTODAY'S DATE 1IS: 3HABCD (wrong number of characters) 1HB When Hollerith constants a data type according to ® are the When the constant used in numeric expressions, following rules: is used with a binary they operator, assume including the assignment operator, the data type of the constant data type of the other operand. For example: is the STATEMENT COMPONENTS Data Statement INTEGER*2 REAL*8 ) of = 4HABCD = ICOUNT DOUBLE = 8HABCDEFGH a the specific +2HXY data constant. type For is 4 INTEGER*2 2 REAL*8 8 required, Data of X=Y (1HA) the constant is used assumed. For example: as ° APAC When the data type Type type an of (9HABCDEFGHI) assumed actual argument, Type Data of context, Type Length Constant INTEGER*2 of Constant IF (2HAB) INTEGER*2 1HC-1HA 2 INTEGER*2 2 J= .NOT. INTEGER*2 2 1lHB type Constant I= 1,2,3 data 9 is used in any other assumed. For example: of no Length Constant None Statement of Constant 2 constant is is Length Constant Data Statement CALL this INTEGER*2 When is REAL*4 example: Statement ) of ICOUNT RALPHA for Length Constant DOUBLE JCOUNT When Type Constant When data the length of the constant is less than the length implied by the type, spaces are appended to the constant on the right; when the length of the constant is greater than the length implied by the data type, the constant is truncated on nonblank characters are truncated. Table 2-2 lists Each character 2.4 VARIABLES the number occupies of one the right. characters byte of An required error for results each data if any type. storage. A variable is a symbolic name associated with a storage location (see Section 2.1 for the form of a symbolic name). The value of the variable is the value currently stored in that location; however, you can change that value by assigning a new value to the variable. Like constants, variables are classified by data type. The data type indicates the type of data the variable represents, its its storage requirements. When data of any type is a variable, this data is converted, if necessary, to the the variable. You can establish the data type of a using type declaration statements or IMPLICIT statements, of a variable precision, and assigned data type to of variable by or by choosing names any other for real). that begin with certain letters (I-N for integer; STATEMENT COMPONENTS Two or more variables are associated with each other when they refer to the same memory location. They are partially assocliated when part of the location to which one variable refers is the same as part or all of the location to which the other variable refers. Association and partial association EQUIVALENCE statements, occur when you use COMMON and actual and dummy arguments statements, in subprogram references, A variable is considered defined if the storage location associated with it contains data of the same type as the variable name. A variable can be defined before program execution by a DATA statement, or during execution by an assignment or input statement. If variables of different data types are associated (or partially associated) with the same storage location, and if the value of one variable is defined (for example, by assignment), the wvalue of the other variable becomes undefined; that 1is, 1its wvalue cannot be predicted. 2.4.1 To Data Typing by Specification specify the data statements (see types Section COMPLEX VAR1 DOUBLE PRECISION of 5.2). variables, For example, you the use type statements declaration VAR2 assign the COMPLEX data type to the wvariable VARl and the DOUBLE PRECISION data type to the variable VAR2: that is, they cause the variable VARl to be associated with an 8-byte storage 1location that will contain complex data, and the variable VAR2 to be associated with an 8-byte double-precision storage location. Character type declaration and a value length to statements specified assign the character data variables. For example, type the statements CHARACTER*72 INLINE CHARACTER NAME*12, NUMBER*9 cause the variables INLINE, NAME, and NUMBER to be associated with storage locations containing character data of lengths 72, 12, and 9, respectively. The IMPLICIT statement (see Section 5.1) has a more general effect: it assigns, in the absence of an explicit type declaration, a specified data type to any variable beginning with a specified letter or any letter within a specified range. You can explicitly declare the data explicit declaration 2.4.2 takes type of a variable only once. precedence over an IMPLICIT statement. An Data Typing by Implication In the absence of either IMPLICIT statements or type declaration statements, all variables you use that have names beginning with I, J, K, L, M, or N are assumed to be integer variables, and those that have names beginning with any other letter are assumed to be real variables. For example: STATEMENT Real 2.5 COMPONENTS Variables Integer Variables ALPHA JCOUNT BETA ITEM TOTAL NTOTAL ARRAYS An array single is a locations, appended In PDP-11 single the column refer row number several this The a and its 1is following a page The DIMENSION e The COMMON e The VIRTUAL statements the have to by discusses from example, associated one is to an with individual referred 2.5.2 a a storage subscript subscripts.) seven array dimensions. having only one array; to refer to a value in this the value's row number. Similarly a figures array, number. And the is you a two-dimensional must a three-dimensional specify table of array; value's statements statements statement statement (see (see contain array name number of of the (see (see statement may the of this FORTRAN-77 e define can for column in declaration that are The figures to row both refer array; the value's that to number, a covers value its in column number. PDP-11 These array locations name). (Section specify Type and an column e array, elements, name. one you must its storage array figures, value pages and (the one-dimensional only specify than to array, number, of or a need more to contiguous array array FORTRAN-77, dimension -array, Yyou of of name called to A table group symbolic Section Section Section Section in the each arrays: 5.2) 5.3) 5.4) 5.5) declarators array, elements establish number (see Section of dimensions 2.5.1) in the dimension. An element of an array is considered defined if the storage 1location associated with it contains data of the same type as the array name (see Section 2.5.4). An array element or an entire array can be defined before program execution by a DATA statement. An array element can be defined during program execution by an assignment or input statement; an entire array execution by an input statement. 2,5.1 An Array array array a specifies program unit, the and array. An defined during that to program symbolic it name specifies the is identify properties of ' array a be Declarators declarator within can declarator (d[,d] ...) has the form: an this STATEMENT COMPONENTS array the 1is, that -array The symbolic name of the (Section 2.1 gives the form of a symbolic name.) : name. A dimension declarator. The number of dimension declarators indicates the number of dimensions the number of dimensions can range from one to seven. in the array; For in example, DIMENSION IUNIT (10,10,10) three-dimensional IUNIT is a array. The value of a dimension declarator specifies the number of elements in the example above, each dimension of IUNIT that dimension: in consists of 10 elements. to the product of the The number of elements in an array is equal IUNIT above contains 1000 values of the dimension declarators; elements (10 X 10 10). X An array name can appear in only one array declarator within a program unit. Dimension declarators that vary in value are not permitted in a main but they are permitted in a subprogram in order to define program, single a within arrays adjustable You can use adjustable arrays. subprogram--to process arrays with different dimension declarators--by specifying arguments. array name the declarators as well as the (See Section 6.1.2 for more information.) as A dimension declarator in PDP-11 FORTRAN-77 can specify both an and bound [dl:] upper bound, as subprogram a lower (*); see and 1lower follows: du dl The lower bound of the dimension. The upper bound of the dimension. du (Can be an asterisk below.) The number of elements specified by a dimension with upper bounds is du-dl+1l. range of a Specifying the lower bound of an array allows you to use For example, to reference an does not begin with 1. that subscripts an specify could array storing data for the years 1964 to 1974, you upper bound of 74 and a DIMENSION KYEAR lower bound of 64 as follows: (64:74) The value of the lower bound, dl, can be negative, 0, or positive. The value of the upper bound, du, must be greater than or equal to the |is it If a lower bound is not specified, corresponding lower bound. 1is 1 and that the value of the upper bound 1lower the that assumed bound is the number of elements in the dimension. STATEMENT For example, in DIMENSION NUM contains The upper the NUM 30 statement (0:9,-1:1) elements. bound in the dimension declarators declarator as Each an dimension e Each COMPONENTS last may assumed-size bound is an dimension be declarator an asterisk; an array declarator (see integer arithmetic a 1list of asterisk 1in marks the Section 6.1.3). expression in which: operand 1is an integer constant, an integer or an integer variable in a COMMON block dummy argument, e Array Each operator references and bounds expressions. 2.5.2 Subscripts A subscript is a is a +, -, function list of *, /, or references expressions, ** operator are not called allowed in subscript expressions, enclosed 1in parentheses, that specify, or reference, element in an array; a subscript is said to "qualify" an A subscript is appended to the array name it qualifies. A subscript has the dimension a particular array name. form: (sl,s]...) A A subscript subscript expression. expression expression. If converted integer A to subscripted the array for each each dimension 2.5.3 Array Storage suggested earlier As dimension can value by be of a a constant, subscript truncating reference must defined for any a is of fractional contain the variable, not array one or type an arithmetic integer, it is part. subscript expression being referenced think of (one for as an declarator). in Section 2.5, you can an array arrangement of values in rows, columns, and pages (or planes) -- that is, as an arrangment of wvalues in other than a strictly 1linear sequence, An array of any size is always stored in memory, however, as a linear sequence of values: A one-dimensional array 1is stored with 1its first element 1in the first storage location, and its last element 1in the 1last storage location of the sequence; a multidimensional array is stored so that the leftmost subscripts vary most rapidly. This storage arrangement for arrays 1is called the "order of subscript progression." Figure 2-1 shows array storage in one, two, and three dimensions. STATEMENT One-Dimensional Array COMPONENTS BRC(6) LIIBRC(I) 2|BRC(2)]3|BRC(3) 4lBRC(4)[SIBRC(S)IGIBRC(G)] A ) Memory W N = Two-Dimensional Array Positions BAN(3,4) BAN(1,1)|4|BAN(1,2)|7|BAN(1,3)|10}{BAN(1,4) BAN(2,1) |{S|BAN(2,2) BAN(3,1) |6 |8 |BAN(2,3)|11|BAN(2,4) |[BAN(3,2)|9 Memory Three-Dimensional Array [BAN(3,3) |12 |{BAN(3,4) Positions BO0S(3,3,3) 19{B0OS(1,1,3)]|22|B0S(1,2,3) [25|B0S(1,3,3)} 20]B0OS(2,1,3)[23|B0S(2,2,3) [26]/B0s(2,3,3)1} 10/BOS(1,1,2)]|13|B0OS(1,2,2)]16|B0S(1,3,2)§27[B0S(3,3,3)1 18 |B0S(3,3,2)} L o =31 LY N[+ 11/B0S(2,1,2)[14]B0S(2,2,2)[17[B0S(2,3,2)] BOS(1,1,1)]4[B0S(1,2,1)[7[B0S(1,3,1)} BOS (2,1,1) 5 BOS(2,2,1) 8 BOS(2,3,1)] Bos(3,1,1)[6[BOS(3,2,1){9]BOS(3,3,1)] Memory Figure 2.5.4 Data Type of Positions 2-1: Array Storage an Array The data type of an array is specified in the same way that the data type of any other variable is specified -- that is, implicitly by the initial letter of the name, or explicitly by a type declaration statement. All the values in an array have the same data type. Any value assigned to an array element 1is converted to the data type of the array. 1If an array is named in a DOUBLE PRECISION statement, for example, the compiler element of the element of this 2.5.5 array. array, allocates When it is a value e Type declaration e COMMON e DATA statement statement of converted Array References Without In the following types of array 1is to be used (or without its subscript: an 8-byte any to storage type double 1is location for each assigned to any precision. Subscripts statements, you can indicate that .an entire defined) simply by specifying the array name statements STATEMENT e EQUIVALENCE e FUNCTION ® SUBROUTINE e Input/output @ ENTRY ® SAVE COMPONENTS statement statement statement statements statement statement You can also use unsubscripted array references to external procedures. permitted 2.5.6 in any other type of names as actual Unsubscripted array Adjustable Arrays dimensions. To the array bounds Chapter 6 wuse an and the for more CHARACTER adjustable array name character of variable array in a subprogram, you specify as subprogram arguments. (See information.) SUBSTRINGS A character substring is a contiguous or character array element. A 1in not statement. Adjustable arrays allow subprograms to manipulate arrays 2.6 arguments names are substring reference has segment one of of the a character variable forms: v([el]l:[e2]) a(sf,sl...) ([el]l:[e2]) A character variable A character array A subscript expression. v name. a name. s el A numeric position of expression that a substring. specifies the 1leftmost character rightmost character e2 A numeric expression that position of a substring. specifies the Character positions within a character variable or array element are numbered from 1left to right, beginning with 1. For example, LABEL (2:7) specifies the substring beginning with the second character position and ending with the seventh character position of the STATEMENT COMPONENTS character variable LABEL. If the CHARACTER*8 variable LABEL has a has a value of LABEL(2:7) substring the then XVERSUSY, of value VERSUS. If the value of the numeric expression el or e2 1is not of type integer, it is converted to an integer value before use by truncating any fractional The values of following part. the numeric expressions el and e2 must meet the conditions: .LE. The length of len .LE. e2 .LE. el 1 len If el is omitted, omitted, the character variable or FORTRAN-77 assumes that FORTRAN-77 assumes that e2 equals el array element. len. -equals For example, NAMES(1,3)(:7) specifies the substring first character position and ending with the position of the character array element NAMES(1,3). 2.7 1; if starting seventh e2 s with the character EXPRESSIONS An expression consists of a single basic component (such as a constant or a variable) or a combination of basic components with one or more operators that represents a single value, Operators specify computations to be performed on the values of the basic components. Expressions are classified as arithmetic, character, relational, or logical. Arithmetic expressions produce numeric values, character expressions produce character values, and relational and logical expressions produce logical values. Arithmetic Expressions 2.7.1 Arithmetic expressions are expressions that are formed with arithmetic elements and arithmetic operators. The evaluation of an arithmetic expression yields a single numeric value. An arithmetic element can be any of ) A numeric, ) A numeric variable ° A array ) An arithmetic expression ° An arithmetic function numeric Hollerith, octal, following: or hexadecimal constant element The term "numeric," as used logical data 1is treated context. the enclosed in parentheses reference above, includes 1logical data, because as integer data when used in an arithmetic STATEMENT Arithmetic the operators values result., of The specify arithmetic operators and Operator These two a COMPONENTS computation elements their to meanings that is to be performed on produce a numeric value as a are: Function * % Exponentiation * Multiplication / Division + Addition - Subtraction operators are elements, called When and binary written unary and plus unary operators can except use as A variable used in an Table types, 2-3 and any noted arithmetic in Table operator with the also each preceding wvalue, any the valid is an used with arithmetic plus (+) arithmetic and element, 2-3. or array element must have arithmetic expression. shows because immediately element, to denote a positive or negative minus (-) symbols are unary operators., You minus allowed shows the Table 2-3: a defined combinations data type of of the base result Exponentiation Exponent value Data before and of it can exponent be data exponentiation. Types Type Base Type Integer Real Double Complex Integer Integer Real Double Complex Real Real Real Double Complex Double Double Double Double No Complex Complex Complex No Complex be an exponentiated element with a Note: only A by negative an element integer 0 value cannot element. be element; can and exponentiated In any valid exponentiation, base element, except in by the result has two cases: another the (1) 0-value same data a real type base as the and a double-precision exponent produces a double-precision result; and (2) a base of any type and a complex exponent produces a complex result. Arithmetic expressions are the operators involved. in the following order of evaluated in an order The five operators precedence: in that is FORTRAN determined are by performed STATEMENT COMPONENTS Operator Precedence * % First “* and /- Second + and - Third When two or more operators of equal precedence (such as + and -) appear, they are evaluated by the compiler in any order that is algebraically equivalent to a left-to-right order of evaluation. For example, in 3+4-1, the addition is performed before the subtraction. Exponentiation, however, is evaluated right to left. For example, 1in the expression A**B**C, B**C is evaluated first, and then A is raised to the result 2.7.1.1 of Use of B**(C. Parentheses - You can use parentheses to force a particular order of evaluation. When part of an expression is enclosed in parentheses, this part is evaluated first, and then the result is wused in the evaluation of the remainder of the expression. In the following examples, the numbers below the operators indicate the order of evaluation: 4+3*%2-6/2=7 b 2 1 (443) * 2 4 3 =6 / a 3 b 2 = 11 (4+3*2-6)/2=2 O 2 1 SR 3 4 ((4+3)*2—6)12=4 1 As shown 2 in 4 the third and fourth examples parentheses are evaluated according to unless you override the order by using above, expressions within the normal order of precedence, parentheses within parentheses. Using parentheses to specify evaluation order is often important high-accuracy computations because rounding and normalizations cause algebraically equivalent evaluation orders not to computationally equivalent. Using parentheses to specify complex expressions, where writing a program to analyze you have any doubt about evaluation order 1is also it is difficult during visually what is to happen accuracy, use important the process to what. in may be in of If parentheses. 2,7.1.2 Data Type of an Arithmetic Expression - If every element in an arithmetic expression is of the same data type, the value produced by the expression is also of this data type. If elements of different data types are combined in an expression, the data type of the result of each operation is determined by a rank associated with each data type. The data types are ranked as follows: STATEMENT Data Type Rank Logicai 1l (Low) Integer 2 Real 3 Double Precision 4 Complex The 5 data type elements of of the value element resulting an last data from type of operation Operations ) are in the expression is classified by an operation 1is the operation. an in by types on performed that integer the For and data a on that rounded. 1/3 + The value In PDP-11 element For 1/3 of of element the Real type results + this as or type equal to an of division performed only in an arithmetic arithmetic, any 1is truncated, -- and Real integer giving The 0, not an operations of 1is are present integer 1is INTEGER%*2 out operations double-precision precision, by making the significant portion of a significant then portion evaluated Converting a not increase in -- Any operation is given the only on and logical are converted a to real part evaluated wusing converted or converted integer element element; The real (I/J)*X J, and and X. element to to (approximately): 0.3333333134651184D0 in double the the most least expression Iis arithmetic. real element to a double-precision element its accuracy. For example, the real number 0.3333333 is real 0. real fractional is value an integer, real or integer double-precision double-precision as result. performed element then an carried INTEGER*4 real, elements each expression Double-precision a not 1. involving element produces combinations by is arithmetic. Note, however, that in the statement Y = an integer division operation is performed on I and then a real multiplication is performed on the result ) the follows: operation INTEGER*4 Any 0. from expression an operations elements., real. 1/3 operation data is result the wvalue expression. data FORTRAN-77, elements of the example: and INTEGER*4 arithmetic type example, real type two data Integer operations —-- Integer operations are on integer elements. (Logical entities used context are treated as integers.) In integer fraction ® data operation an (High) produced different highest-ranked The COMPONENTS does STATEMENT COMPONENTS not to either: 0.3333333000000000D0 or: 0.3333333333333333D0 ) expression operations -- In an operation on an Complex a complex element, integer elements are converted containing and described, previously as type, data real to double-precision elements are converted to real data type, by element real The rounding the least-significant portion. 1is designated as the real part of a complex number; obtained Iis The expression the imaginary part is given the value 0. then evaluated with complex arithmetic, and the resulting value is complex. Character Expressions 2.7.2 The evaluation Character expressions consist of character elements. of a character expression yields a single value of character data type. A character element can be any one of the following: e A character constant e A character variable e A character array element e A character substring expression has A character character and can be enclosed A relational by separated true element Relational 2.7.3 if the form: the with parentheses. Expressions expression consists of two arithmetic expressions The value of the expression is relational operator. a stated relationship exists, false if it does not. A relational operator tests for a relationship between two expressions. These operators are: Relationship Operator than .LT. ~Less .LE. Less than or equal .EQ. Equal .NE. Not equal .GT. Greater than .GE, Greater than or equal to to to 2-22 to arithmetic STATEMENT The delimiting Complex periods expressions can operators. Complex imaginary parts are In an arithmetic example, a required be related entities are both equal. relational evaluated and then to determine whether For are the the the COMPONENTS part of only equal if expression, each by their the operator. the .EQ. and corresponding arithmetic .NE. real and expressions are resulting values are compared with each other relationship stated by the - operator exists. expression APPLE+PEACH .GT. PEAR+ORANGE states the relationship: "The sum of the real variables APPLE and PEACH 1is greater than the sum of the real variables PEAR and ORANGE." if this relationship exists, the value of the expression is true; if not, the In character a value evaluated to the then whether FORTRAN-77 character means "follows in false, expression, resulting the relationship 1In 1in is the uses values., "precedes means expression relational and determine PDP-11 of the the ASCII ASCII character are stated ASCII character the the values by the <collating relational collating collating expressions compared with each operator sequence in expressions, sequence," and sequence."TM are other exists; comparing "less than" "greater than" For example, the expression 'ABZZZ' states that .LT. 'cCcccc'! 'ABZZZ' is less does exist, the value of stated did not exist, the If the the two character same 1length, spaces until expressions 'ABC' 'AB! the first though 'AB' shorter lengths L.EQ. 'ABC has expressions Because are in of a relational the equal. two For is this relationship If the relationship would be false. expression padded example, on in the the are not right with relational ' 'C a value are not is 'CCCCC'. expressions the the LT than the expression is true. value of the expression longer of true, -equal; than even and the though second the has a 1lengths value of of the true even 'C'. All relational operators have arithmetic operators have a the same precedence; higher precedence than however, the the relational operators. You can use parentheses to alter the order expressions 1in a relational expression; operators are evaluated before relational enclose the whole of an arithmetic of arithmetic however, because operators, you of arithmetic need. not expression evaluation in parentheses. You can compare two numeric expressions of different data types in a relational expression. To make such a comparison, the system converts the value of the expression with the lower-ranked data type to the data type of the expression with the higher-ranked data type. STATEMENT COMPONENTS Logical Expressions 2.7.4 Logical expressions are logical A operators. either true A logical The or the following: ) An integer or logical constant ° An integer or logical variable ® An integer or logical array ) A relational ) A logical ® An expression or operators Operator element expression enclosed integer logical in function parentheses reference are: Meaning Example The expression is Logical conjunction: if, and only if, both A and B are true B .AND. A +AND. logical value-- false. element can be any of logical elements and single logical formed with logical a yields expression true. The B, .XOR. «XOR. (inclusive disjunction is true if either both, is true. Logical B .OR. .OR. expression or The expression exclusive OR: if A is true and B is false, or Logical is true B OR) : A or vice versa; false 1if both the expression is but elements have the same > value. .NEQV. .EQV. .EQV. B .NEQV. B Same as Logical .XOR. equivalence: The expression is true if, and only if, both A and B have the same logical value, whether true or false. NOT. . NOT. A Logical negation: true if, and only The delimiting periods of logical operators are The if, A expression is false. 1is required. A logical expression is evaluated in accordance with the precedence of The following list the arithmetic, relational, and logical operators. a logical expression are gives the order in which the operators in evaluated: Operator Precedence First * % * and / Second + and - Third (Highest) STATEMENT Operator '"The Precedence relational operators Fourth «NOT. Fifth «AND., Sixth .OR. Seventh .XOR., .EQV., .NEQV. Operators example, of in equal the A*B+C*ABC the COMPONENTS sequence Eighth rank are evaluated from 1left to right. For expression .EQ. in X*Y+DM/ZZ which .AND. evaluation .NOT. occurs K*B .GT. TT is: (((A*B)+ (C*ABC)) .EQ. ((X*Y)+(DM/ZZ) )} .AND.( .NOT. ((K*B) .GT.TT)) As in arithmetic normal Two sequence consecutive expressions, of you can use operators are not parentheses to alter the evaluation., logical allowed unless the second is .NOT. Some logical expressions are are evaluated. For example, A .AND. (F(X,Y) .GT. evaluated before if A is .FALSE. 2.0) .AND. all their subexpressions 1in the expression B the value of the expression can be determined by testing A without evaluating F(X,Y); therefore, the function subprogram F is not called and consequences resulting from a call, such as changing variables 1in COMMON, When a data do not occur. logical type elements, operator 1is example, in the INTEGER I, J, I J K J logical When has operation on a logical logical elements, operator 1is carried the value out the operates resulting on sequence K ="'65'0 = I.OR.'100'0 = I.AND.'23'0 the value '165'0 and K has '21'0. bit-by-bit integer the corresponding bits of the internal (binary) representation of the integer elements; the resulting data type is integer. When a logical operator combines integer and 1logical values, the logical value is first converted to an integer value and then the operation is carried out as it would be for any two integer elements; the resulting data type is integer. ' For the operates logical. on CHAPTER 3 ASSIGNMENT Assignment array statements element, statements evaluate specified variable, The four kinds of e Arithmetic e Logical e Character assign or a an a STATEMENTS value character expression array and element, assignment to (or "define") substring; or assign that the character statements a variable, 1is, an assignment resulting value substring. to a to a are: ASSIGN 3.1 An ARITHMETIC ASSIGNMENT STATEMENT arithmetic variable The assignment array arithmetic v = A numeric An The or statement assigns an arithmetic value element. assignment statement has the form: e variable arithmetic equal rather, sign it or array element. expression. does not means "is mean "is replaced equal by." to," For as 1in example, mathematics; the assignment statement KOUNT means the = KOUNT "Replace sum of Although the the undefined, references the + 1 current current symbolic value value name to of of the KOUNT the integer and 1left the of wvariable integer the equal values must have been previously assigned in the expression to the right of the equal KOUNT constant sign to all sign. with 1." can be symbolic ASSIGNMENT The expression must real the expression entity and to e the If v of is directly e converted to have summarizes the A character yield that left the a value produces of same a STATEMENTS of the value proper greater the equal sign data types, the is an For 32767 is example, a invalid if INTEGER*2 variable. statement the assigns value data types are different, the value Table of v before it is assigned. conversion rules for assignment statements. of e to v. If the the data type data element cannot be Table 3-1: assigned to Conversion Rules a numeric Integer or Logical Real Statements (E) Double Complex Precision Element 3-1 entity. for Assignment Expression Variable or Array size. than : (V) Truncate Integer or Truncate E to integer and Assign E to V assign to V Logical Real Append fraction Append fraction (.0) to E and assign to V Double Precision (.0) to E and assign to MS Assign E to Msl portion of V; LSl portion of Vis 0 V is 0 portion of V; LSl portion of (.0) assign E and to real part of V; imaginary part of 1. to v is 0.0 MS = most significant assign to V Assign real part of V; of V is imaginary part 0.0 (high order); real E to assign to V; imaginary part of E is not used Assign msl Assign real portion of E to part of v; LSl portion of E is rounded Assign E to V portion of E to V; imaginary part of E is not used Assign Assign Ms 1 E to of integer and real part of E to Msl portion of Vv; LSl portion of V is 0, imaginary part of Append fraction Complex Assign E to V Truncate E to integer and part E is not used E to real part of of E is rounded; v; Lsl portion Assign E to V imaginary part of V is 0.0 LS least significant (low order). ASSIGNMENT Examples of valid and invalid STATEMENTS assignment statements are: Valid BETA = PI 3.14159 = -1./(2.*X)+A*A/(4.% (X*X)) SUM = SUM+1. Invalid 3.14 = A-B (entity on variable -J = I%*%4 (entity or ALPHA = ((X+6)*B*B/(X-Y) the or on array (entity the 3.2 The LOGICAL ASSIGNMENT logical false) The V to a logical assignment variable or assignment be a left must be a variable on the right because is an the invalid parentheses statement array assigns a logical value (true has the form: e A logical variable A logical expression. be of logical or data array type element. and e must yield a logical otherwise, conversions will be made according resultant values will not be meaningful. to Values, either numeric or to all variables or array previously of logical logical, elements assignment must have in e, statements been Table 3-1 wvalue; and LOGICAL PAGEND PAGEND, = PRNTOK = A PRNTOK, are: ABIG ,FALSE. LINE .LE. .GT. B 132 .AND. .AND. A .GT. .NOT. C PAGEND .AND. A .GT. D Invalid X=.TRUE. (entity on the left must be the assigned Valid ABIG or element. statement = Examples are balanced) STATEMENT v must must element) element) expression not left array logical) ASSIGNMENT STATEMENTS CHARACTER ASSIGNMENT STATEMENT 3.3 The character assignment statement assigns the value The character assignment statement has form: of a character expression to a character variable, array element, or substring. the = e v A character variable, A If of character array element, expression. the length of the character the character variable, expression is or substring. truncated on expression is greater than the 1length array element, or substring, the character the right. If the length of the character expression is less than the the character variable, array element, or substring, expression is filled on the right with spaces. The expression must be of character data type: you of length the character cannot assign numeric value to a character variable, array element, or substring. Note that assigning character included substring if the in positions the a value substring. character wvariables character to a character substring 1If a character position the position data and is does character variable or has a value previously assigned, Examples of valid and (All 1in undefined, it not outside in these of the examples and undefined. invalid character assignment statements arrays affect array element not it remains unchanged; remains a are assumed follow. to be of type.) valid FILE = 'PROG2' 'MARCIA' = REVOL (1) LOCA(3:8) = TEXT(I,J+1) 'PLANTS' (2:N-1) = 'NAMEX' Invalid '"ABC' = CHARS = CHARS (element on the array element, 25 (ixprission on ype left must be or substring the right must a character reference) be variable, of character data ASSIGNMENT STATEMENTS ASSIGN 3.4 ASSIGNING The ASSIGN STATEMENT statement variable. The destination in LABELS assigns variable a a statement can subsequent label then be wused assigned GO TO value to to an integer specify a transfer (see Section statement 4.1.3). The ASSIGN statement ASSIGN A label same An s TO of the form: v an program integer has executable unit as statement the ASSIGN or a FORMAT becomes defined for use as as a variable; that is, the for output The statement statement The or in ASSIGN statement are arithmetic computations. label refer the must same statement or executed. must occur in For example, ASSIGN program must is be the ASSIGN same to a variable. The assignment statement in differs in that the a statement-label reference and assigned value cannot be used executable executed statement the undefined an The the = to in statement or a FORMAT which program the before assigned and the the assigned variable assigned GO is TO GO to be TO used statements unit. statement TO NUMBER wvariable arithmetic operations the variable NUMBER in NUMBER the unit. statements 100 associates in variable. The ASSIGN statement assigns a statement label ASSIGN statement 1is similar to an arithmetic that it assigns a value to a variable, but variable undefined statement statement. NUMBER on the with the variable statement the are statement now invalid. of 101 label For 100; example, NUMBER+1 and does not result in a value being stored in NUMBER. An associated statement. assignment variable can become defined For example, assigning statement as follows: again NUMBER a with value with an an assignment arithmetic NUMBER=10 dissociates the variable arithmetic wvalue statement, but can 10 be from and used statement 100. can no longer for output and The variable be used in arithmetic now has the an assigned GO TO computations. ASSIGNMENT STATEMENTS Examples: valid Invalid ASSIGN 10 TO NSTART ASSIGN 99999 TO KSTOP ASSIGN 250 TO ERROR (variable must be integer) CHAPTER 4 CONTROL Statements are written. However, normally to another point unit. You can STATEMENTS exected you within may use the same in the control order program unit or processing, also suspension use control statements of program execution, and The statements are control GO TO IF -- transfers statement -- conditionally THEN, executes ELSE conditionally DO statement group of CONTINUE IF -- a to they are transfer control another program to govern iterative program termination. control within a program transfers unit control or statements -- statement THEN, execute which to follows: statement conditionally IF as in statements ELSE, blocks specifies of and END IF statements iterative processing statements a specified number statement -- transfers control of of a specified next executable times. to the statement CALL statement transfers RETURN statement -- calling program unit PAUSE STOP END The -- statement statement statement foll owing sections -- -~-- returns control to control from temporarily terminates marks describe the program end these suspends of a a subprogram a subprogram program execution program statements. unit to execution the CONTROL STATEMENTS GO TO 4.1 GO TO STATEMENTS GO TO statements containing the transfer control GO TO statement. to a The point within three types the program unit of GO TO statements are: e Unconditional e Computed ® Assigned 4.1.1 The Unconditional unconditional statement The every GO time unconditional GO A TO GO TO Statement GO TO statement it is TO statement transfers control ¢to the same executed. has the be an form: s statement The statement same program label. identified unit as by the s must GO TO executable statement 1in the statement. Examples: GO TO 7734 GO TO 99999 4.1.2 The Computed computed specified The by computed GO TO GO GO the GO TO Statement TO statement value TO of an statement (slist)[,] transfers arithmetic has the control to a statement expression. form: e slist A list, called executable An arithmetic where n is the transfer statements, 1list, separated expression the number of whose of one or more the range 1labels of by commas. value statement is in labels in the 1 transfer to list. n, CONTROL STATEMENTS The computed GO the result to statement If in the label value the TO statement evaluates integer data type. in of e is transfer statement after position less list, the e in than 1 control computed the or is GO e and, if Control transfer greater necessary, converts 1is transferred to the list. than transferred the to number the of first labels executable TO. Examples: In GO TO (12,24,36),INDEX Go TO (320,330,340,350,360), the first transferred has a The of assigned has Therefore, executed 3, the assigned GO TO An INDEX 24. execution GO TO GO TO been ASSIGN if statement Assigned label The to value 4.1.3 example, is SITU(J,K)+1 has a value of 2, In the second example, transferred TO statement 340. Statement statement transfers control placed in a variable by transfer destination statement. GO to execution is if SITU(J,K)+1 statement may depend has the labels of to an a on the statement whose ASSIGN statement. most recently form: v[[,](slist)] integer variable. slist A list by The of one or more assigned GO TO statement transfers label on the was most recently assigned ASSIGN statement.) The TO GO statement, the and the statements to statements in the same value of v In PDP-11 in slist must Examples be a (if of ASSIGN GO TO (This ASSIGN TO (This slist statement assigned 200 TO IGO example 450 IBEG, TO to associated if is of the statements separated GO TO ASSIGN statement (See Section or whose statements, 3.4 be executable the assigned the label value to equivalent to v is is transferred assigned GO TO statements equivalent of control are: GO TO 200.) GO TO 450.) IBEG is statement statement (300,450,1000,25) example the v. is transferred must If slist is used, IGO is to variable slist. specified), following control the which control program unit. member FORTRAN-77, executable GO executable commas. not to statement. present the next CONTROL STATEMENTS control or IF 4.2 IF STATEMENTS An IF of statements) statement statements specified @ Arithmetic IF e Logical statement e Block decision evaluation 4.2,1 IF IF the executes condition is a statement met. The (or three a block types of IF to based on statement statement transfer control of an expression Arithmetic IF Statement arithmetic statements, The a are: The The transfers if on arithmetic 1IF the IF IF (e) sl, An arithmetic statement basis or to in transfers of the value statement has the s2, execute contained of a statement the IF control an is statement. to one arithmetic of three expression. form: s3 e expression. sl,s2,s3 Labels of executable statements in the same All three labels (sl,s2,s3) are required; refer to three different statements. The arithmetic zero, passes to label s3. Some IF control label statement passes to s2; e if evaluates label is however, expression sl; greater 1if e than is unit. they need not e less than If to is zero, control control passes to examples: THETA IF is greater than 4.2.2 (NUMBER/2*2-NUMBER) Logical logical statement on IF IF the if the real variable CHI, to statement 100 CHI. 20,40,20 This statement transfers control integer variable NUMBER is even, The e. equal zero, This statement transfers control to statement 50 THETA is less than or equal to the real variable if program to to statement statement 40 20 if if the the value value of the is odd. single FORTRAN Statement statement basis of conditionally the evaluation 4-4 executes of a a logical expression. CONTROL The logical IF A IF (e) statement has the STATEMENTS form: st logical expression. st A complete FORTRAN statement. executable statement block IF statement, or The logical value of IF statement the first expression 1is value of the expression 1is executable statement after executed. Examples Note of that logical .GT. e must IF 4 .OR. J IF (REF(J,K) .NE. HOLD) 4.2.3 statement can logical statement be expression st is logical a e. If the executed. 1If the is next not groups) of block IF false, control transfers to the 1logical IF, and statement a any statement, the st value. statements: (J LOGICAL evaluates true, yield IF IF The except a DO statement, an END another logical IF statement. .LT. 1) GO TO REF(J,K) 250 = REF(J,K)*(-1.5D0) ENDRUN (ENDRUN) CALL EXIT Block IF Statements Block IF statements conditionally execute blocks (or statements. The four These block e IF e ELSE e ELSE e END IF IF IF THEN IF has (e) the are THEN IF block ELSE block END IF (e) used form: block ELSE are: THEN statements construct statements THEN 1in block IF constructs. The CONTROL STATEMENTS A logical expression. block A sequence of zero sequence is called Figure 4-1 describes or more <complete a statement block. the flow of control FORTRAN for four statements. examples of This block IF constructs. Each block IF statement, associated statement expressions in block. except the END IF statement, has The statement block consists of all an the statements following the block IF statement up to (but not including) the next block IF statement in the block IF construct. The statement block is conditionally executed based on the values of logical The IF THEN THEN The ELSE is that IF statements. a block IF construct. is a exist: 1IF THEN statement ELSE construct preceding Except ELSE The statement 1is statement block that for an specifies the an optional statement The is value true, statement within a block IF the expression in construct can block of to be executed 1logical a in optional statement statement the IF no block to a block be executed construct IF if no was executed. IF statement can follow the statement. END IF construct ELSE statement can be IF THEN and labels cannot statement label transferred Section terminates executed the block IF construct. time referenced. to which control only from within describes Section Section each 4.2.3.3 an IF THEN END can be the block describes nested IF IF statement loops block back block into cannot contains terminal statement statement to block. statements a blocks, DO statement, each 1loop and vice of a IF a can statement constructs. IF constructs. Dblock END but statement can contain any statement. You <can you cannot transfer blocks. When a from one statement it must also contain the DO loop's versa. must these have control in block but c¢an You cannot transfer control ' partially overlap statement, block. the another. but construct. examples block labels, statement transferred, restrictions on 4.2.3.2 describes The 4.2.3.1 Statement Blocks - A statement executable FORTRAN statement except an transfer control out of a statement block, control 1is executed, control following the END IF block in a block IF statement is executed. ELSE statements can have statement be 4.2.3.1 block. DO IF within block block END IF statement, if the and no preceding statement block After the last statement in a statement block passes to the next executable statement statement. Consequently, only one statement be block in the true. in the block IF construct was executed. A block contain any number of ELSE IF THEN statements. The The if the value of the logical expression specifies conditions ELSE block begins IF THEN statement following the statement statement construct preceding it is executed following IF the be If you wholly wuse DO 1loops with contained within one CONTROL STATEMENTS Construct Flow of Control False IF (e) THEN block True END IF Execute block Te& False e IF(e}) THEN block, True block, END IF Execute blOCk1 Execute blOCk2 Execute block Execute blocks, IF (e,) THEN Block, ELSE IF (e;) THEN block, END IF IF (1) THEN blOCk1 ELSE IF (e;) THEN blocky ELSE IF (e3) THEN blocks ELSE block END IF 4 - Execute block, Execute Execute block, block, Execute block, ZK-206-81 Figure 4-1: Examples of Block IF Constructs CONTROL STATEMENTS 4.2.3.2 Block of IF THEN one statement the executes IF Examples and END - The IF An block. (e) block this example IF construct consists construct conditionally follows: Example Form IF simplest statements; IF THEN (ABS(ADJU).GE.1.0E-6) THEN TOTERR=TOTERR+ABS (ADJU) block QUEST=ADJU/FNDVAL END IF END The statement and the The IF END block IF consists THEN executed. The following all the statements between the IF THEN logical expression e, evaluates value of e is true, the statement block of e is false, control transfers to the the block is statement after the END IF statement; first statement executable not of statements. ABS (ADJU) .GE.1:0E-6. is executed. If the next IF If value example the shows a block IF construct with an ELSE IF THEN and the ELSE statement: Form IF (el) Example THEN IF (A blockl D .GT. B) THEN =B F=A-8B ELSE IF (e2) block?2 END Blockl THEN ELSZ D IF END consists of all the IF (A .GT. = B/2. statements between block2 consists of ELSE IF END statements. If A is greater If A is and the than not greater IF B blockl is than B but than B THEN IF IF THEN statements; THEN B/2.) all the the IF THEN statements between the executed. A is greater than B/2, block2 is executed. If A is not greater blockl nor block2 executable statement The following and A is executed; after example the shows is not control END a IF B/2, neither transfers directly to greater than the next statement. block IF construct with an ELSE and ELSE statement: Form Example IF (e) THEN IF (NAME .LT. blockl IFRONT = 'N') THEN IFRONT + 1 FRLET (IFRONT) =NAME (1:2) ELSE ELSE block?2 END Blockl consists statements; and the IBACK=IBACK + END IF END of all block2 IF 1 IF the statements consists of all between the the IF THEN statements between the ELSE statements. If the value of the character variable NAME is less than is executed. 'N', blockl CONTROL If the value of NAME is greater STATEMENTS than or equal to executed. The following THEN example statements and shows an a ELSE block2 block IF (el) construct with several ELSE statement: Form IF 'N', is _ IF Example THEN IF (A blockl D .GT. B) THEN =B F=A-B ELSE IF (E2) THEN ELSE block2 IF D (A F=A ELSE IF (e3) THEN ELSE block3 .GT. C) THEN -2 _ (A .GT. Z) THEN =C IF D =12 F=A-12 ELSE ELSE block4 END IF D = 0.0 F = A END IF The above example contains four statement blocks. of all the statements Block between the Delimiting blockl IF THEN block?2 First block3 Second block4 ELSE and ELSE ELSE and than END B, Block first IF block IF ELSE THEN listed below. THEN second and Each block consists statements Statements IF THEN and IF IF ELSE IF THEN ELSE IF If A is greater blockl If A is not greater than B but If A is not greater than B or greater than B, is executed. is greater C but 1is than C, block2 greater than is executed. Z, block3 is executed. If A is not 4.2.3.3 included or Z, block4 is executed. Nested Block IF Consructs - A block 1in a statement block of another block nested block IF statement block; The C, following construct must be it must not overlap example contains a completely contained statement blocks. nested block IF Form IF (e) IF construct IF construct. construct: IF (A .LT. 100) INRAN=INRAN IF (e) THEN IF blocka blockl ELSE END 1 (ABS (A-AVG) INAVG = OUTAVG IF END .LE. INAVG + 1 = OUTAVG + IF ELSE, block2 END THEN + IF 5.) ELSE blockb ELSE within Example THEN - can But OUTRAN END IF = OUTRAN + 1 1 THEN be the a CONTROL STATEMENTS If A is less than 100, blockl is executed. block IF construct. If the absolute AVG is less or equal to 5, blocka is executed. If the absolute value of equal to 100, block2 is executed; the AVG is greater executed than because it is 5, blockb not in is executed. nested If IF nested a Blockl contains value of A minus A A is greater construct than nminus than or not is block2. DO 4.3 DO STATEMENT The DO statement specifies statements. statement, and iterative processing of a sequence of The sequence of statements is called the range of the DO the DO statement together with its range is called a DO loop. The DO statement has the form: v=el,e2[,e3] DO sf{,] The label s must of an executable follow physically unit. statement. the DO This executable statement in the same program statement, \Y Usually an integer variable but may be a real or double-precision variable. el,e2,e3 Usually integer expressions but may be real or double-precision expressions. The variable v initial, omit the In e2, is called terminal, the control variable; increment increment parameter, FORTRAN-77, and and e3 expressions can be are parameters, a default el, e2, and e3 are respectively. increment value of 1 is the If you used. v can be a real or double-precision variable, and el, any arithmetic converted to expressions. 1If necessary, evaluated the data type of the control variable before they are used. If the data type of the control variable |is number of iterations of the DO range the double-precision, or real might not be what is expected because of the effects of floating-point rounding. The label s identifies the terminal terminal statement must not be: e A GO TO statement e An e Any e An END e A RETURN @ A DO IF statement arithmetic block IF statement statement statement statement statement of the DO 1loop. The CONTROL The range follow of the the DO DO statement statement, up STATEMENTS consists to and of all including the the statements terminal that statement. The DO statement first evaluates the expressions el, e2, and e3 to determine values for the initial, terminal, and increment parameters, respectively. The value of the initial parameter is assigned to the control wvariable. loop then are in Section The number of given by: is [(e2 where, 4.3.1. - executable repeatedly. executions el + letting X integer The executed whose of the If the iteration executed. iteration count DO exact range, in the range mechanism called the of is iteration represent magnitude the does count If is is the zero DO After each 1. Iteration to 2. 3. value the or of [X] is the largest magnitude of X and whose the negative, compiler negative, of The iteration If the the the DO [-3.5] the body qualifier the body of = of is =3). the loop is increment count to for range, the following parameter is is decremented count the another iteration is first count can using also a cause statement loop. If «control variable of the DO is and the executed greater 0, of execution within of the a DO range 1is transferred statement remains are taken: algebraically added than 0, statement the execution control after is the DO statement is range. of statement that actions 1. executable iteration is by terminated. You The 1loop specified the variable. iteration statement, If the control transferred 4. count, Control execution The DO expression, exceed X (for example, be zero. or /NOF77 zero above not once, 4.3.1 the explained e3)/e3] sign is the same as the sign of increment parameter, e3, cannot not statements The the to be transfers outside the defined with DO terminated control the control 1loop, its by outside the current value. When execution of a DO loop terminates, but other DO loops share this loop's terminal statement, control transfers outward to the next DO loop in the nesting structure (see Section 4.3.2). If no other DO loop shares a DO loop's terminal statement, or if a DO loop is outermost, control the terminal You cannot the DO altering transfers alter 1loop; the value however, to first executable of the control can reference variable it it. cannot this the you The range of a DO statement loops), as long as these DO Section 4.3.2. You to statement. transfer rule are control described can contain statements into in the other meet range Sections for DO of a and within the purposes statements certain 4.3.3 statement DO range other loop. of than (nested requirements. 4.3.4. after DO See Exceptions CONTROL STATEMENTS You can modify variables holding the initial, terminal, increment or parameters within the loop without affecting the iteration count. Examples of DO statements follow. valid DO 100 K=1,50,2 statement This specifies 25 iterations; K=49 during the final 27 iterations; J=-2 during the final IVAR=5 during the final iteration. Do 350 J=50,-2,-2 specifies statement This iteration. DO 25 IVAR=1,5 specifies This statement 5 1iterations; iteration. Invalid is missing) DO NUMBER=5,40,4 (the statement label DO 40 M=2.10 (a decimal point has been typed for a comma) Note in the that DO40OM invalid example, last the statement 2,10 = is an unintentionally valid arithmetic assignment statement. 4.3.2 Nested DO Loops nested A DO loop can include one or more complete DO loops called loops. The range of the next outer loop. statement. — Nested loops can Fiqure 4-2 illustrates nested loops. share Correctly Nested DO Loops Incorrectly Nested DO Loops DO 45 K=1,10 DO 15 K=1,10 Dé 35 L=2,50,2 li:35 CéNTINUE 45 CONTINUE Dé 25 L=1,20 — 15 CéNTINUE Dé 30 M=1,15 N Dé 45 M=1,20 L DO range of a nested DO loop must lie completely within the B 25 CONTINUE L*30 CéNTINUE Figure 4-2: Nested DO Loops 4-12 a terminal CONTROL 4.3.3 Control Within a to outer an loop If to two Transfers nested an or DO loop, loop; inner more therefore 4.3.4 A DO is is can transfer you cannot DO loops share to this innermost the same shared loop. inner from an loop outer terminal statement, terminal statement Because this shared you only from terminal any transfer to it to an inner loop, from and an is Range an out extended of the range 1loop 1if and a control statement The of DO includes range this destination control following loop statement to the rules of control then, another The an invalid. loop has returns from control loop. statements, the control transfer part of the innermost loop, transfer from an outer loop Extended control Loops you nested a DO however, can transfer «control within the range of the statement outer loop in STATEMENTS the after returns all first statement execution control executable transfer and of transfers one into statements the or the more 1loop. between statement that loop. govern the use of a DO statement with an extended range: e A transfer from ® its into the extended Statements in the range of a DO statement extended range must not variable. Figure 4-3 transfers. illustrates valid and 1invalid vValid Control — DO GO - Gé TO 20 15 CONTINUE 20 A=B+C DO DO 30 Loop 35 20 control 20 A;B+C 30 D=E/F 35 CONTINUE X=A*D DO 45 M=1,15 . 50 D=E/F : R | 40 X=A*D 45 CONTINUE 50 CONTINUE . . . TO 30 GO Figure TO GO TO 40 GO range Transfers GO TO 50 CONTINUE Range control DO 35 L=2,20 M=],15 35 4-3: only the DO 50 K=1,10 . Extended change extended Control K=1,10 DO 15 L=2,20 - permitted Invalid Transfers 35 is range. Control Transfers 4-13 and TO 30 Extended Range CONTROL STATEMENTS CONTINUE STATEMENT CONTINUE 4.4 The CONTINUE statement transfers control to the next executable used as the terminal statement of a DO primarily is It statement. loop that would otherwise end with a prohibited control statement such as The a GO TO or CONTINUE an arithmetic statement has IF. the form: CONTINUE CALL 4.5 CALL STATEMENT The CALL statement executes a SUBROUTINE subprogram or other external can also specify an argument list for the subroutine. It procedure. (See Chapter 6 for detail on the definition and use of a subroutine). following The CALL statement has the form: CALL s[([all,[al]l...)] s The name or a of dummy other a SUBROUTINE subprogram or other external procedure, argument associated with a SUBROUTINE subprogram or external procedure. a An actual argument. (Section 6.1 describes actual arguments.) If you specify an argument list, the CALL statement associates values in the 1list with the dummy arguments in the subroutine. then transfers control to the first executable of the It the order, and statement subroutine, The arguments in the CALL statement must agree in number, data type with the dummy arguments in the subroutine. These arguments can be variables, arrays, array elements, substring references, constants, expressions, Hollerith constants, character constants, or subprogram names. An unsubscripted array name in the argument list refers to Examples the of entire CALL CALL CURVE CALL PNTOUT CALL EXIT array. statements are: (BASE,3.14159+X,Y,LIMIT,R(LT+2)) (A,N,'ABCD') CONTROL STATEMENTS RETURN 4.6 RETURN STATEMENT The RETURN statement the calling program. is used to return has the form: It control from a subprogram to RETURN When is a RETURN returned Chapter statement to 6). the When is executed statement a RETURN that statement 10 function the 1is to subprogram, executed the control reference (see function first in a subroutine executable statement example: SUBROUTINE IF a statement subprogram, control 1is returned following the CALL statement. RETURN in contains SIZCHK 10,20,30 (N) (N,K) K=-1 RETURN 20 K=0 30 K=+1 RETURN RETURN END PAUSE 4.7 PAUSE The PAUSE displays The STATEMENT statement a PAUSE message statement PAUSE temporarily on the has suspends terminal the to program permit you to execution and some action. take form: ([disp] disp An alphanumeric digits, The disp depends batch and an argument on job, the or how the is your If the program are displayed is not the decimal optional. of is disp The being are digit string effect of executed. written of a If it one the system in interactive mode, terminal, followed the by a program is suspended. After you to five PAUSE statement is running as a to suspended. is running at your that a constant. program contents program indicating literal, octal output contents prompt then file, of disp sequence enter the proper control command, execution resumes with the first executable statement following the PAUSE. The proper control command is specific to the Some operating system examples of PAUSE 999 PAUSE 'MOUNT PAUSE (refer to statements NEXT TAPE' the are: PDP-11 FORTRAN-77 User's Guide). " CONTROL STATEMENTS STOP STOP STATEMENT 4.8 The STOP statement terminates program execution and returns control to system. the operating The STOP statement has the form: [disp] STOP disp to digit string of one if present, specifies a message to be The END statement marks the end of a program unit. It must A character constant, a decimal digits, an octal or The disp argument, when execution Examples of constant. five displayed stops. STOP STOP 98 STOP 'END OF statements are: RUN' STOP END 4.9 END STATEMENT last source line of every program unit. The END statement has the be the must not execution from form: END The END statement must not occur on a continuation line and itself be continued. In a main program, reaching the END if no STOP statement, statement program prevents execution terminates; subprogram, a RETURN statement is implicitly executed. in a CHAPTER SPECIFICATION Specification allocate statements and characteristics The of specification e e e the STATEMENTS nonexecutable variables symbolic statements IMPLICIT statement symbolic e are initialize 5 names statements and arrays, used in the that 1let you define other and program. are: -- specifies the implied data type Type declaration type of statement -- explicitly symbolic names specified DIMENSION statement array, and the COMMON statement -- number -- declares the declares the number of dimensions elements in each dimension of reserves one or more contiguous VIRTUAL be e e statement two more OAVE statement execution INTRINSIC FORTRAN DATA -- a PARAMETER -- statement -- one the the a specified one or arrays to 1location an entity more symbolic symbolic names names to to functions initial values before program execution statement an of storage of in subprogram names declares more status in assigns elements or same definition statement declares -- intrinsic the RETURN for storage associates retains of procedure statement array -- space program entities statement external and e or EXTERNAL be e reserves normal EQUIVALENCE be e -- outside with after e statement located data areas storage e of names -- assigns a to symbolic variables, name arrays, to a constant a main program value e PROGRAM statement -- assigns a symbolic name to unit ® BLOCK in in The DATA which common following statement initial blocks sections -- values describe establishes may these be a BLOCK assigned statements. to DATA program entities unit contained SPECIFICATION STATEMENTS IMPLICIT IMPLICIT STATEMENT 5.1 The IMPLICIT statement permits you to change the default are all with interpreted to be of integer data type, and IMPLICIT statement allows you to alter these The the IMPLICIT statement has IMPLICIT names beginning letter are interpreted to be of real data type; the other any data-typing default, all names beginning with the letters I through N By rules. interpretations. form: typ(al,al...)[,typ(al,al...)]... typ One of An the data-type alphabetic specifiers. specification in (See Table one of two 2-2.) forms: ¢ or cl-c2, The cl-c2 form specifies a is an alphabetic character. ¢ where in occur that must <¢2), through ¢l (from range of letters order. alphabetical The IMPLICIT statement assigns the specified data type to all symbolic begin with any of the specified letters and that have no that names explicit data-type declaration. over implicit declarations. Explicit declarations The IMPLICIT statement also affects symbolic PARAMETER statement (see Section 5.11). For example, the take names precedence defined in a statements IMPLICIT INTEGER IMPLICIT REAL (I,J,K,L,M,N) (A-H, 0O-Z) specify the default in the absence of any explicit statement. statements specification other IMPLICIT statements must precede all except PARAMETER statements, and they must precede all executable statements. You can use character is the the data default IMPLICIT statement to type; length. Typ must positive integer constant Any data type following can be examples IMPLICIT set a default be an unsigned in parentheses, specified in an DOUBLE PRECISION (S,Y), (D) LOGICAL*1 integer in the range IMPLICIT demonstrate: IMPLICIT COMPLEX 1length for the simply specify typ as CHARACTER*len, where len (L,A-C) constant 1 through statement, as or 255. a the SPECIFICATION STATEMENTS TYPE DECLARATION 5.2 TYPE DECLARATION STATEMENTS Type declaration statements specified symbolic names. statements: character The numeric type following e declarations declarations rules Type type apply (see to declaration explicitly define There are two forms Section type (see Section 5.2.1) and 5.2.2). declaration statements the data type of of type declaration must statements: precede all executable statements. 5.2.1 The e The data type e You by can use a appending array name. Numeric Type numeric type of a type an symbolic name can be declared only once. declaration statement to declare an array declarator (see Section 2.5.1) Declaration declaration array to an Statements statement has the form: typ v([,v] typ Any data The type symbolic function specifier name of subprogram, A symbolic name can form *s, where s being declared (see (see a or Table wvariable, an 2-2) except array, CHARACTER statement function, array declarator. be followed by a data-type length specifier of the is one of the acceptable lengths for the data type Table 2-2). ©Such a specification overrides the length attribute that the statement implies, and assigns a new length to the specified item. If you specify both a data-type 1length specifier and an array declarator, the data type length specifier goes first. Examples of type declaration statements are: INTEGER COUNT, REAL MATRIX(4,4), SUM MAN, IABS LOGICAL SWITCH INTEGER*2 Q, REAL*8 WX1l, M12%*4, WX3*4, IVEC*4(10) WXS5, WX6*8 5~3 SPECIFICATION STATEMENTS Character Type Declaration Statements 5.2.2 Character type declaration CHARACTER[*1len[,]] statements have the form: v[*len][,v[*1len]]... v The symbolic name of a constant, variable, array, or array declarator. (You cannot declare a function subprogram, a statement function, or a virtual-array name to be of character data type.) len An unsigned of the enclosed 1in integer constant or parentheses. character data an integer-constant The value of its own length length elements. If you specify CHARACTER*len, len becomes specification for the specified list., If an not have expression len specifies the specification, the the item default length in this list does item's 1length is len. However, if an item does have 1its own length specification, this specification overrides the default length specified in CHARACTER*len. If you do not specify a length, a length of 1 is assumed. The 1length specification must be in the range 1 to 255; a length specification of zero 1is 1invalid. You can use a character type declaration statement to define arrays by including array declarators (see Section 2.5.1) in length, numeric the the type Examples of list. If you specify both array declarator goes declarations). character type declaration CHARACTER*32 NAMES (100), This statement specifies first SOCSEC an array LAST, FIRST an array declarator and (the reverse of the rule statements a for follow: (100)*9, NAMETY*10 NAMES comprising one hundred 32-character elements, an array SOCSEC comprising one hundred 9-character elements, and a variable NAMETY, which 1is 10 characters long. PARAMETER (LENGTH=4) CHARACTER®* (4+LENGTH) The latter statement specifies two 8-character wvariables, LAST FIRST. (The PARAMETER statement is described in Section 5.11.) CHARACTER This LETTER(26) statement l-character specifies This statement and expression. an array LETTER comprising twenty-six elements. CHARACTER*16 large, and is the BIGCHR*(30000*2) ,QUEST*(5*INT (A)) invalid; the value length specifier for specified QUEST for is not an BIGCHR integer 1is too constant SPECIFICATION STATEMENTS DIMENSION 5.3 DIMENSION The DIMENSION and the The DIMENSION STATEMENT statement number of specifies elements statement DIMENSION in has the each the number dimension. of dimensions in an array form: a(d)[,a(d)]... a(d) An array declarator (see Section 2.5.1). a The symbolic name of an array. d A dimension The DIMENSION in each the length The total the statement dimension of the number product example, the defines ARRAY MATRIX addition of array. one storage element The data type of the to unit, Examples of elements array's assigned individual ARRAY (4,4), as having as 16 having DIMENSION you (4x4) 125 statements, COMMON, can DIMENSION real (5x5x5) use and an elements array is equal declarators. statements name to For MARK(4,4,4,4) arrays can array statements. in only of one 2 each bytes and each. declarators However, array in within a declarator. are: DIMENSION on bytes use BUD(12,24,10) information 4 you VIRTUAL array of elements X(5,5,5),Y(4,85),2(100) 2.5. an integer DIMENSION further to dimension MATRIX(5,5,5) DIMENSION Section to each element array determines element. storage the declaration, program For allocates an statement defines In of storage of DIMENSION type declarator. and on storing array elements, see SPECIFICATION STATEMENTS COMMON 5.4 A COMMON COMMON STATEMENT statement reserves one or more contiguous blocks of storage. A symbolic name is used to identify each contiguous block; however, you can omit a symbolic name for a blank common block in a program unit, COMMON statements also specify the order of variables and arrays The in each COMMON common statement COMMON block. has [/[cb]l/] the form: nlist[[,]1/[cb]l/ nlist]... cb A symbolic (If the name, first called c¢cb a 1is common blank, block you name; can <c¢b omit can the be blank. first pair of slashes.) nlist A list of variable separated COMMON A common by names, commas. array names, (You cannot use and a array block can When common blocks programs are made become following in a statement.) have the same name as a variable or same executable program. However, it cannot have the function, subroutine, or entry in the same executable Section 2.1). names declarators virtual-array name having the part the associated of with an array in same name program the as a (see same name but 1located 1in separate same executable program, the individual the same storage area. Consider the with example: PROGRAM MAIN COMMON/BLOCK1/ICOUN, IHOL/BLOCK2/ICHK (10) CALL GSUB END SUBROUTINE GSUB COMMON/BLOCK2/JCHK (10) /BLOCK1/JCOUN, JHOL END In this the a example, same single storage storage You can have you can have BLOCK1l area; in MAIN and likewise, BLOCKl the two GSUB are associated BLOCK2s in are associated with area. only one blank common block in up to 250 named common blocks. an executable program, but SPECIFICATION Entities are In above the storage assigned space respective storage in example, ICOUN BLOCKl, because in STATEMENTS common blocks on a one-for-one basis. JCOUN are associated with the same and each entity occurs first list. Entities placed in a one-to-one correspondence in the block should agree in data type. For example, if one contains the statement COMMON and program INTEGER*2 COMMON must results not unit contains may occur common block is allocated on for integer of assign a the an the when such odd a in numeric byte Examples of COMMON Main COMMON COMMON data program variables or that character subsequent boundary. The data compiler blocks: type or statements The data entirely of in a combined, correspond of are mix COMMON the arrays other supplies character to or any however, all common blocks In addition, you must not no type filler begun on a character block data must type. be follow. Program Subprogram HEAT,X/BLK1/KILO,Q SUBROUTINE COMMON FIGURE FIGURE /BLK1/LIMA,R/ /ALFA,BET . . RETURN . END COMMON are (BYTE) . common units to way blocks; boundary. of these MONEY is made variable CENTS. real LOGICAL*1 in entirely The statement variable common word (even byte) and numeric data CALL common program unit MONEY to space same MONEY because the 2-byte high-order 2 bytes You its CENTS another incorrect in statement in and puts block, the main KILO and program puts Q in a named HEAT and X in a blank common block, BLKl. The COMMON statement in the subroutine makes ALFA and BET correspond to HEAT and X in the blank common block, and makes LIMA and R correspond to KILO and Q in BLK1. valid Invalid INTEGER CHARS (9) CHARACTER COMMON/STRING/ILEN, CHARS In this block example, as a BYTE the character integer CHARS (9) COMMON/STRING/CHARS, ILEN variable ILEN is allocated ILEN is allocated on the same variable. BO,Bl COMMON/STRING/BO, ILEN,B1 In this address. example, the integer variable on an odd byte SPECIFICATION STATEMENTS VIRTUAL 5.5 VIRTUAL A virtual STATEMENT array is an array whose storage 1is allocated in main memory outside of the program's directly addressable The use of virtual arrays in a program frees directly memory for executable The VIRTUAL of dimensions VIRTUAL code statement and statement VIRTUAL other a virtual names the has a(d) and number the data of physical main memory. addressable storage. array and elements specifies in each the number dimension. The form: [,a(d)]... a(d) An array declarator (see Section 2.5.1). a The symbolic name of an array. d A The dimension maximum declarator. total directly programs executing on 65,536 bytes. In light arrays, can be 32,767 it is used easy up. elements LOGICAL*]1 array to see numeric of from of 1 64K limit on addra2ssable computer in the allowable how A quickly array, 1 byte storage space, and would require 262,136 the a of to per 8 for bytes element memory directly addressable instance, in addressable can length. would have a to user is 64K, or FORTRAN-77 main memory maximum Therefore, require a maximum COMPLEX array bytes of storage space, a directly available the PDP-1l1 family sizes of PDP-11 32,767 a of maximum bytes of of 8 bytes per element requirement far beyond memory. NOTE Virtual arrays RSTS/E operating The data type data type of by the first are not systems. of a virtual array any other array is letter of the name, supported is specified in specified, that or explicitly, on the is, by same way that the either implicitly a type declaration statement. An example of VIRTUAL This a A(1000), statement elements, a VIRTUAL statement follows: LARG(180,180), defines a two-dimensional Mult (4,4,4,4,4,4,4) one-dimensional array array of named LARG named 32400 A of elements, 1000 and a SPECIFICATION STATEMENTS seven-dimensional array named MULT of 16384 elements. are placed in external main memory and therefore do not diminish the 64K of directly addressable memory. These arrays significantly For storage, further information Section 2.5. 5.5.1 Restrictions Virtual arrays limitations: and A virtual (see The on name array of used A virtual Using virtual Section be concerning in arrays Virtual array name their not be are subject used in a a an Virtual COMMON arrays The name following statement array or virtual array element must EQUIVALENCE statement (see Section 5.6). or by a virtual DATA cannot array element statement be used (see to cannot Section contain specifications (see Section 8.6). The name or virtual array element must not appear as I/0 the virtual array value an to 5.4). initial in see Arrays elements must and be not assigned an 5.10). run-time format of a virtual array a format specifier statement. of a virtual be specified as parentheses) of an Anl) [ the array or buffer ENCODE or virtual array element must not argument (third argument inside DECODE statement (see Section The name of a virtual array element must not be used as an actual argument to a subprogram if the subprogram assigns a value to the corresponding dummy argument (see Section 6.1). The name used Section The Below of to a virtual specify array the name of a virtual array in a keyed I/0 A virtual array name must examples VIRTUAL of valid and not A(1000),B(2000) WRITE (2,*) SUB be invalid READ (1,*) A DO 10,I=1,1000 B(I)=-A(I)*2 CALL array in cannot be statement. valid 10 virtual keyword an element OPEN cannot statement be (see 9.1.10). expression are or FILE (A(I),I=1,1000) (A,B) of use used data of to specify type character. virtual arrays: a key SPECIFICATION STATEMENTS Invalid VIRTUAL A(10) CHARACTER A (declared COMMON /X/ EQUIVALENCE WRITE (1,A) A (used type character) X,Y X,Y Virtual Array References in COMMON statement) (used as format specifier) (used in EQUIVALENCE statement) (A(1l),Y) ENCODE (4,100,A(3)) 5.5.2 as (used in DATA statement) DATA A(l1)/2.5/ (used as ENCODE output buffer) in Subprograms array can become wvirtual name of a A dummy argument that is the name of a virtual the also is that argument actual an with associated array. An actual argument that is a can reference to a virtual array element become associated only with a dummy argument that is a simple variable wvirtual a is 1In effect, an actual argument that (see Section 2.4). array element is treated as if it were an expression. Furthermore, a value must be before this must not alter assigned to virtual a array element element is used as an actual argument and the subprogram the value of the corresponding dummy argument. Below are examples of valid and invalid virtual array references in subprograms: Valid Usage VIRTUAL A(1000),B(1000) B(3)=0.5 CALL SCALE (A,1000,B(3)) END SUBROUTINE SCALE (X,N,W) VIRTUAL X (N) 5=0 po 10, 10 I=1,N S=S+X(I)*W TYPE *,S END Invalid Usage VIRTUAL A(1000) REAL B(4000) CALL ABC(A,B,A(3)) END SUBROUTINE ABC(X,Y,2) REAL X (1000) VIRTUAL Y (4000) Z=2.3 END (actual argument is virtual) (actual argument is nonvirtual) (actual argument is virtual element) array SPECIFICATION STATEMENTS EQUIVALENCE 5.6 EQUIVALENCE STATEMENT The EQUIVALENCE entities in the statement partially or same program unit with The statement EQUIVALENCE EQUIVALENCE (nlist) has the totally associates two or the same storage location. more form: [,(nlist)]... nlist A 1list of variables, array elements, arrays, or references, separated by commas. You must of these entities in each list. substring least two The EQUIVALENCE location In an to statement all of the EQUIVALENCE substring allocates entities statement, reference must used arguments, in an virtual EQUIVALENCE storage its each be an expression. Dummy in arrays, begins at the same list. expression integer and that character specify at in constant virtual statement. array a or subscript integer elements may not The entities in nlist must be either entirely of numeric data type entirely of character data type: you cannot make numeric entities character entities equivalent. You must a way byte An not equivalence that subsequent data LOGICAL*1 used EQUIVALENCE of arrays any with other boundary. array name of You equivalence can is, you the in element can an variables store them of such different that you can store component of example, if you make an variable, the integer the complex variable. integer variable of statement other is elements allocated refers to valid and invalid numeric each data entity in on such an odd types; that begins at the one type. variable equivalent to a shares storage with the real statements or and first multiple components of a higher-ranked data EQUIVALENCE be the array. address. Furthermore, type with a single Examples type or constant same data For complex part of are: valid DOUBLE PRECISION INTEGER*2 This array DVAR. DVAR IARR(4) EQUIVALENCE (DVAR,IARR(1)) EQUIVALENCE statement IARR occupy CHARACTER the KEY*16, EQUIVALENCE makes same the storage STAR*10 (KEY,STAR) 5-11 four as the elements the integer double-precision of variable SPECIFICATION STATEMENTS character This EQUIVALENCE statement makes the first character of the variables KEY and STAR share the same storage location. the substring KEY variable STAR is equivalent to (1:10). The character Invalid LOGICAL*1 BYTES(10) (ILEN, EQUIVALENCE BYTES(8)) In the above example, the integer variable ILEN is allocated on an odd byte address. Making Arrays Equivalent 5.6.1 When you make an element of one array equivalent to an element of the EQUIVALENCE statement also sets equivalences another array, the 1f Therefore, between corresponding elements of the two arrays. both equivalent, made are arrays equal-sized two of first elements third the And, for example, if arrays share the same storage space. element first the to equivalent made is array element of a 7-element first array overlap of another array, the last five elements of the the first five elements of the second array. You must not use the EQUIVALENCE statement to assign the same storage You also must not location to two or more elements of the same array. with inconsistent is that way a in locations memory attempt to assign For example, you cannot the normal linear storage of array elements. make the first element of one arrav equivalent to the first element of another and array attempt then to set an equivalence between the the second element of the first array and the sixth element of other array. Some examples of the use of the EQUIVALENCE statement follow: DIMENSION TABLE EQUIVALENCE (2,2), TRIPLE (TABLE(2,2), (2,2,2) TRIPLE(1,2,2)) As a result of these statements, the entire array TABLE shares part of Figure 5-1 shows how the storage space allocated to array TRIPLE. these statements align the arrays. Array TABLE Element Array Number Element Figure OC~Jaun b WN TRIPLE (1,1,1) TRIPLE(2,1,1) TRIPLE (1,2,1) TRIPLE(2,2,1) TRIPLE(1,1,2) TRIPLE (2,1,2) TRIPLE (1,2,2) TRIPLE (2,2,2) 5-1: Array Element Element Number W N Array TRIPLE TABLE (1,1) TABLE (2,1) (1, 2) TABLE TABLE (2,2) Equivalence of Array Storage SPECIFICATION Each in of the Figure You following statements STATEMENTS also aligns EQUIVALENCE (TABLE,TRIPLE(2,2,1)) EQUIVALENCE (TRIPLE(1,1,2), can identify single though the two arrays as shown 5-1: an subscript the statement array array element (that 1is, is aligns TABLE(2,1)) in with an EQUIVALENCE the 1linear multidimensional. arrays TRIPLE and For TABLE as statement element example, they are with number), the a even following aligned in Figure 5-1: EQUIVALENCE Similarly, For can make example, values. sequence, you you can (TABLE(4), an use whole array B. make the statement of array as A now with A(2:3,4) refers to array A(2:3,4) the share nonunity lower is a sequence third storage with element array shares part how the of above the storage statement B Array space aligns Array Element Array Element Number Element Number B(2,1) 1 B(3,1) 2 B(4,1) 3 A(2,1) 1 B(2,2) 4 A(3,1) 2 B(3,2) 5 A(2,2) B(2,3) 7 A(2,3) A(3,3) 6 B(4,3) 9 A(2,4) 7 B(2,4) 10 A(3,4) 8 B(3,4) 11 B(4,4) 12 Figure 6 Making the B(2:4,4), allocated the to arrays. 3 A(3,2) 8 5-2: eight A Element B(3,3) in B(2,4)) 5-2 shows B(4,2) bounds. of ‘ (A(3,4), Figure equivalent defined To Array 5.6.2 arrays array A reference to A(2,2) EQUIVALENCE The TRIPLE(7)) 4 5 Equivalence of Arrays with Nonunity Lower Bounds Substrings Equivalent When you make one character substring equivalent to another character substring, the EQUIVALENCE statement also sets equivalences between the other corresponding characters in the character entities. For example, as CHARACTER a result NAME*16, EQUIVALENCE of statements ID*9 (NAME (10:13), ID(2:5)) the character variables NAME and Figure 5-3. ID share space as illustrated in SPECIFICATION The following aligned in statement Figure EQUIVALENCE If the Character For substring as CHARACTER a character Figure 5-4. in NAME and are array arrays result equivalences the of ID as they are complete can FIELDS the the other arrays. overlap at any character ©position. STAR(5)*5 (FIELDS(l) (2:4), arrays elements, between statements FIELDS(100)*4, EQUIVALENCE the of references sets characters elements example, arrays (NAME(9:9),ID(1:1)) statement corresponding aligns 5-3: character EQUIVALENCE also STATEMENTS and STAR(2) (3:5)) STAR share storage space as shown in NAME Character Position 1 2 3 4 5 6 7 ID Character 8 Position oljlo|l~Nj]OO]jO]Is»x]lWIMN - 9 10 11 12 13 14 15 16 ZK-207-81 Figqure You cannot use the to positions in the same You cannot use also The following a or way Equivalence of EQUIVALENCE location locations in of character two 5-3: more character variable EQUIVALENCE is inconsistent and statements to that the that variables statement substrings Substrings assign start or at character statement with the the same different storage character array. to normal assign linear memory storage arrays. also EQUIVALENCE (A,B(4,1)) EQUIVALENCE (B(3,2), align A(2,2)) the arrays as shown in Figure 5-2: SPECIFICATION STATEMENTS STAR Character Position 1 Subscript 1 2 3 FIELDS Subscript : C;:sriaticc}r?r 1 2 3 4 5 1 1 2 2 3 3 4 4 5 1 1 2 2 3 3 4 4 1 5 2 1 3 2 4 3 1 4 2 5 3 1 4 2 1 3 2 4 3 5 2 3 4 5 4 6 1 2 3 4 7 1 2 AAYA 100 1 2 3 4 ZK-208-81 Figure 5-4: Equivalence of Character Arrays 5-15 SPECIFICATION STATEMENTS Extending Common Blocks 5.6.3 in common a entities stored the EQUIVALENCE statement. is, you can only extend it beyond the last element of the previously before the first element of the existing common block. The following to When you make entities equivalent block, the common block can be extended beyond its original boundaries to include However, the entities in specified you can extend the common block in only one direction, common established cannot You block. place That the extended portion examples show valid and invalid extensions of the common block: valid A(l) ]| A(2) | A(3) | A(4) DIMENSION A(4),B(6) COMMON A EQUIVALENCE (A(2),B(1)) B(1) | B(2) | B(3) | B(4) | B(5) | B(6) . __J\ T J NS Extended Portion Existing Common Invalid COMMON A EQUIVALENCE B(1)| (A(2),B(3)) B(2)| e Extended Portion If you assign two entities to common equivalent to A(4) A(l) | A(2) | A(3)| DIMENSION A(4),B(6) B(5) | B(6) B(4)| B(3)| —— Existing Common blocks, you D N Extended Portion cannot make them each other. SAVE 5.7 SAVE STATEMENT The SAVE statement retains the definition status of an execution of a RETURN or END statement in a subprogram. The SAVE statement has SAVE the entity after form: [a[,al...] A unique common-block name variable name, or an (preceded and followed by a slash), a array name. Dummy argument names, procedure names, and names of entities contained in common blocks must not appear in a SAVE statement. these restrictions, a multiple definition of the name If you violate wused illegally SAVE statement occurs. An entity contained in a common block specified in a does not become undefined upon execution of a RETURN or END statement undefined However, it may become contained in the same program unit. (or redefined) in another program unit. SPECIFICATION Because one a variable, overlay an segment array can by another useful in you SAVE statement, SAVE it program unit a The common in does SAVE the a block this contained segment is in replaced SAVE statement can be especially To retain the definition of an entity can simply specify that entity in a proper program unit. not list the common when explicitly consisting SAVE contain of statement all a list is allowable treated items resides. in as the name is specified in a SAVE statement within a executable program, this common block name must be statement in every subprogram in which the common an SAVE example DIMENSION SAVE a which appears. following The that block COMMON of the contained subprogram of specified in a block within statement though If or undefined overlay segment, the overlaid programs. are using overlays, you when A element, become STATEMENTS demonstrates use of the SAVE statement: A(100) /CMN2/B(100),C,D(50) A,/CMN2/,E statement array A, in the this named example common preserves block the CMN2, current and the definitions local variable E. EXTERNAL 5.8 EXTERNAL The EXTERNAL arguments to STATEMENT statement other allows you to use external subprogram names subprograms. as The subprograms to be used as arguments can never be FORTRAN intrinsic functions; they can only be user-supplied functions and subroutines. The INTRINSIC statement discussed in Section 5.9 allows intrinsic function The names EXTERNAL The EXTERNAL the an actual Note in of a in Appendix (A, from A to a of form: for user-supplied with declares a function C), of the each the of earlier name or the name of a subprogram. name included in it to name can be used as can use or a CALL used as example reference EXTERNAL earlier a This that reference for of symbolic reference complete function statement. that subprogram, the procedure. subprogram function FUNC(B), interpretation different the external complete SUBR subprogram. A in an EXTERNAL The an argument that arguments. associated statement name argument CALL as has name argument be used v([,v]... symbolic dummy dummy be statement EXTERNAL The to -is interpretation. the corresponding statement. an argument represents not, statement versions of then a -- FUNC(B) value, therefore, not a defined described above DIGITAL FORTRAN. is See SPECIFICATION STATEMENTS INTRINSIC 5.9 INTRINSIC STATEMENT The INTRINSIC statement allows you to use intrinsic function names C.3 Section subprograms. to arguments contains names the as and descriptions of the individual PDP-11 FORTRAN-77 intrinsic functions; for further information on intrinsic functions, see Chapter 6. The INTRINSIC statement has the form: INTRINSIC v[,v]... The symbolic name of an intrinsic function. symbolic The INTRINSIC statement declares a actual argument to a subprogram, which reference or symbolic This procedure. intrinsic CALL statement. a name can the name wuse it in An example of the use of the INTRINSIC statement follows: Main EXTERNAL Program CTN INTRINSIC SIN, COS CALL TRIG (ANGLE, SIN, SINE) CALL TRIG (ANGLE, COS, COSINE) CALL TRIG (ANGLE, CTN, COTANGENT) Subprograms SUBROUTINE TRIG (X,F,Y) Y=F (X) RETURN END FUNCTION CTN(X) CTN=COS (X)/SIN (X) RETURN END 5-18 an name of a function can then be passed as an SPECIFICATION STATEMENTS In this example, when TRIG is called with a second argument of SIN or CO0Ss, the function reference F(X) references the FORTRAN library functions SIN and COS; but when TRIG is called with a second argument of CTN, F(X) references the user function CTN. DATA 5.10 The DATA STATEMENT DATA statement array elements The DATA assigns statement DATA initial values program execution. before has the to variables, arrays, and form: nlist/clist/[[,]lnlist/clist/]... nlist A list of one or more names, or character variable names, substring array names, names, Subscript expressions and expressions must be integer expressions containing array separated element by commas. in substring references integer constants. clist A list of constants, separated by commas, to be assigned Clist constants have one of the following forms: nlist. to val n * The val number of successive times is a nonzero, of an integer Subscript the entities 1in same value the associated unsigned integer constant. expressions and constant 1is constant values to or may be The DATA statement value symbolic integer to of n name constant assigns the constant values in each «clist to the preceding nlist. Values are assigned in the order the from assigned The the expressions. entities in they appear, be nlist. left to right. The number of constants must correspond entities in the preceding nlist. exactly to the number of When an unsubscripted array name appears in a DATA statement, values are assigned to every element of that array. The associated constant list must therefore contain enough values to £ill the array. Array elements are filled in the order of subscript progression. If both the constant value have numeric rules: e The type data constant of the in types, value the the is variable clist converted, being and conversion if the entity is based necessary, initialized. 5-19 in on the nlist the following to the data SPECIFICATION STATEMENTS e When an variable assigned octal or hexadecimal or array element, depends constant variable left can e be or numeric the data fewer =zeroes. stored, the Hollerith 1is assigned of the the component. than the constant component constant is 1is truncated character or (see constant contains variable or array <character data 2-2). If fewer characters array If the constant value a the of the extended on constant numeric Table element, right with spaces. than can be stored, both If capacity the on the is element, left. assigned the characters that can be assigned depends on the the to that can be 1If the constant contains more digits than or variable type digits array element, with When a on contains constant the number of digits the than the data Hollerith the type or is a of of character capacity constant ¢to number extended of on the the 1If the constant contains more characters the constant is truncated on the right. in the clist and type, the the entity conversion is in the based on the nlist are following rules: If is e If the constant contains entity, the rightmost initialized with spaces. e If the entity, the contains more the character constant constant value character these constant fewer bytes than the 1length of the character positions of the entity are data is numeric type, data bytes is than 1length of the type and the constant and the entity in the nlist the entity must conform to restrictions: e e The character The constant constant and entity must must must be have have an a a length of one integer, value in entity 1is specified initialized with by the constant; initialized to any Dummy arguments, initialized the in 8-bit the a ASCII range these character character character. or 0 hexadecimal through 255. restrictions, the that has the ASCII code entity, then, can be code. virtual arrays, DATA octal, the When the constant and the entity conform to In the truncated on the right. and virtual statements. array elements may not be example INTEGER BYTE A(10) BELL,TAB,LF,FF,ACHR,ZCHR DATA A, BELL,TAB,LF,FF,ACHR,ZCHR /10%*0,7,9,10,12,'A"',1HZ/ the DATA statement assigns control <character assigns values Some other following 'A' and lHZ examples of 0 to to all byte 10 elements of array A, variables to ACHR and ZCHR, the DATA STRING X (5) COMPLEX Z BELL, DATA X/2*-3.,4.,2*0.37/,2/(1.0,-3.0)/ DATA STRING/'ABCD'/ TAB, LF, and and ASCII FF. It 1in the respectively. statement segment: CHARACTER*4 REAL codes are included SPECIFICATION STATEMENTS PARAMETER 5.11 PARAMETER STATEMENT The PARAMETER statement assigns a The PARAMETER statement has form: PARAMETER (p=c[,p=cl...) A name. symbolic Any valid FORTRAN Each name in a the value type of determined by type other of any Therefore, unless the a The You to name, becomes equated. is or of any wvalid by a a constant and IMPLICIT name is statement (for defined be to preceding example, a is to be a constant is that determine the data type declaration. in a PARAMETER statement is interpreted as statement is preceded by an appropriate name of however, use a it constant can REAL*8 constant, a symbolic name symbolic name can The and form are statement cannot appear as appear either constant. containing the be defined PARAMETER it defined only interpretation different provided FORTRAN-77 from in the earlier provides to be following PARAMETER MU=1, type MU). can appear once sequence INTEGER BYTS1Z, REAL*4 PI REAL*8 DPI LOGICAL FLAG CHARACTER*25 PARAMETER PARAMETER PARAMETER part real constant that within the the PARAMETER and interpretation the of DIGITAL FORTRAN-77 demonstrates and of any another imaginary only same of versions or defined form both statement: a as the statement the PARAMETER statement; see Appendix earlier form and interpretation. The constant. name statement it name defined implicit-typing rules symbolic unit PDP-11 which symbolic a expression. symbolic same program above PARAMETER to itself,. complex can the integer name program that an ordinary constant can appear. The effect symbolic name defined to be a constant is that of using the symbolic a an a constant; of or symbolic place in of using a constant a the MU=1.23 PARAMETER declaration Once constant, or be to data FORTRAN constant, symbolic defined The the symbolic within it. statement PARAMETER However, earlier A for information the use of the form on of the FORTRAN-77 WRDS12Z LONGNAME (PI=3.1415927, a unit. described the FORTRAN. the the Also, program of part DPI=3,141592653589793238D0) (BYTS1Z=2, WRDS1lZ=BYTS1Z/2) (FLAG=,TRUE.,LNGNAM='A STRING OF 25 CHARACTERS') SPECIFICATION STATEMENTS PROGRAM PROGRAM STATEMENT 5.12 The PROGRAM statement assigns a symbolic name to a main program unit. The PRCGGRAM statement has the PROGRAM form: nam nam A symbolic name. The PROGRAM statement is optional. 1If you use the main program. in statement first 1it, it must be the The symbolic name must not be not be It also must the name of any entity within the main program. or common block in the same entry, the name of any subprogram, executable program (see Section 2.1). BLOCK DATA 5.13 BLOCK DATA STATEMENT The BLOCK DATA statement begins a special type of program declares common blocks and defines data in common blocks. ‘The BLOCK DATA statement has DATA [nam] A symbolic name. BLOCK the unit that form: nam You can use EQUIVALENCE, its terminal unit must be only and type DATA declaration, IMPLICIT, DIMENSION, COMMON, statements between a BLOCK DATA statement and statement. The last an END statement. statement in a A BLOCK DATA program unit must not contain any and must not have a statement label. BLOCK DATA executable program statements If you initialize any entity in a common block declared in a BLOCK complete set of data-type a provide you must unit, DATA program even block, the in entities the specification statements for all though some of the entities are not assigned an initial value. can use the same BLOCK DATA program unit to define initial values more than one common block. You for SPECIFICATION An example of BLOCK a BLOCK DATA INTEGER LOGICAL DOUBLE DATA program unit STATEMENTS follows: BLKDAT S,X T,W PRECISION DIMENSION U R(3) COMMON DATA /AREA1l/R,S,T,U/AREA2/W,X,Y R/1.0,2*2.0/,T/.FALSE./,U/0.214537D-7/,W/.TRUE./,Y/3.5/ END In or this example, implicitly AREAl and AREA2. enough the Not information data all type the of is provided every variables 5 to variable appear 23 in declare in the the explicitly common DATA blocks statement. CHAPTER 6 SUBPROGRAMS A subprogram computing statement. same is This program There are two many cases, Section to 6.1 or of group invoked that with can be located in a different or subprograms: statements is statement subprogram a defines a referencing either program in the unit. user written and system supplied. of statement functions, functions, consist subprograms consist of intrinsic functions. program referencing arguments, The of subprogram system-supplied a to that subprogram receive these describes user-written system-supplied 6.1 the generic called actual computations. describes A subprograms and arguments, as kinds subroutines; functions In statement referencing unit User-written and a procedure. a subprogram subprogram specifies actual for it passes to entities, use in values, making called dummy arguments. actual and dummy arguments; subprograms; and Section Section 6.2 6.3 describes subprograms. SUBPROGRAM ARGUMENTS A subprogram argument is an entity that passes a value to or from a subprogram, There are two kinds of arguments: actual and dummy. Actual arguments are specified in the statement referencing the subprogram. subprogram Dummy and, associated argument turn, with takes any assigned on value to returned when the to the actual and dummy association from arguments are control transferred actual the is specified arguments on a in to one-to-one value of the corresponding assigned to the dummy corresponding main program arguments ends: one reference of the definition basis. Each argument. When subprogram, there is no a subprogram the Rules Actual arguments array elements, must with Dummy agree which Governing or be constants, substrings, are arrays, dummy control retention of to the next. in is is of argument is an I, L is Subprogram Arguments or in order, number, and they are associated. arguments variables can the are association If (I,J3(3),4) is a 1list of actual arguments and (K,L,M) associated 1list of dummy arguments, K 1is associated with associated with J(3), and M is assigned a value of 4. 6.1.1 of subprogram, actual argument; argument in the subprogram actual from the the symbolic or with variables, subprogram data names type 6-1 with that subprograms expressions, arrays, Actual arguments the dummy arguments names. become defined or associated declared in with other SUBPROGRAMS program units; subprograms. associated A with they are not dummy an actual Although dummy arguments each dummy argument If the name, actual or argument may variables 1is undefined are not be variables, be or arrays or it is not currently arrays, declared as though is a constant, an or subprograms, it were a variable, declared expression, virtual array element reference, not if Each dummy argument name is associated actual argument. argument a themselves argument. may array, or subprogram. the attributes of its in argument a to have subprogram the corresponding dummy modified. A dummy argument declared to be an array can be associated only with an actual argument that is an array or array element of the same data type. If the must not be equal to actual argument is an array, the dummy larger than the actual argument array; or smaller than the number is element of of argument that is, elements in array it can be the actual argument. If an actual succeeding argument elements corresponding an an array, this element and of the array are associated with elements of the dummy argument array. The number of actual argument array elements associated depends on the size of the dummy argument array. The dummy argument array must not be larger than the number of elements in the actual argument array involved in the reference; that is, it can be equal to or smaller than the number of elements in the actual argument. valid Invalid PROGRAM MAIN DIMENSION A(10), CALL END X (A, PROGRAM MAIN DIMENSION A(10), B(5,5) B(1,21)) SUBROUTINE CALL EMD X (Y,2) DIMENSION Y (10), END X(A,B(1,21)) SUBROUTINE Z(5,2) B(5,5) X (C,D) DIMENSION C(12) DIMENSION (dummy array must larger than D (5,5) not be actual array) (dummy array not larger than of elements be number of actual included) adjustable subprogram, the array Adjustable Arrays 6.1.2 An must dimensions program. array whose of an 1is a dummy argument dimensions can be changed, associated actual argument array, or declared "adjusted," array in a in a to match referencing The dimension declaration of a dummy argument array contains one or Section 6.1.3 more integer for variables The following rules govern and, information on the use e An adjustable array must e An adjustable array must argument that is an optionally, the use of of be a adjustable dummy become array. 6-2 an asterisk. the asterisk.) (See arrays: argument. associated with an actual SUBPROGRAMS e e The size of an the size of a Variables in arguments, defined e e adjustable the in defined; you an Variables in or an to through values integer examples PROGRAM assign adjustable assigned converted adjustable can arguments following array actual array values data demonstrate these blocks. array declarator type the than be to dummy must have a must become variables through may be integer of data before use. use adjustable of equal must declarator to other or arguments common of than declarator corresponding value. type; The an and Variables dummy adjustable array must be less corresponding actual array. any data type are arrays: MAIN DIMENSION Al(10,35), SUM1 = SUM(A1,10,35) SUM2 = SUM(A2,3,56) SUM3 = SUM(A1,10,10) A2(3,56) END FUNCTION SUM(A,M,N) DIMENSION 10 SUM = DO DO 10 10 SUM = or FUNCTION A(M,N) 0.0 J I SUM = = 1,N 1,M SUM + A(I,J) 10 RETURN In the example, of Al The or Al and DO For information and that statement on lower-bound These if the values changed. For values A(M,?*) 0.0 DO 10 J DO 10 SUM = I = SUM ARRAY dummy array = not and the 1,N 1,M + A(I,J) as can be change contained A sum arguments of M well declarators, values do arrays computes iteration of variables example: DIMENSION L actual the Note the Upper- are subprogram A2. array. A2 function control A. more = RETURN END END array. SUM(A,M,N) DIMENSION as see and N are used specify the size to Section specified during in 1is the adjustable specified sections the 2.5.1. for subprogram array to of an adjustable execution, declaration even are (11,5) =29 M =5 CALL SUB (ARRAY,L,M) END SUBROUTINE SUB(X,I,J) DIMENSION J =1 I =2 X (-I/2:1/2,J) END In this éxample, the adjustable array X is declared to the subsequent assignments to I and J do not affect this be X(-4:4,5); declaration. SUBPROGRAMS Note that argument association is not retained one reference to a subprogram and the next. REAL in the interim between B DIMENSION B(10) CALL S(B,2,3.0) CALL Ss1(5,B,3,2) SUBRROUTINE DIMENSION A(I) = S(A,I,Jd) A(I) J RETURN ENTRY S1 (I,A,K,L) A(I) + 1 this example, statement B is A(I) = RETURN END In the DIMENSION The declared to be a real array with 10 elements by actual argument A, first reference. B(10) statement sets CALL S(B,2,3) B(2) = CALL S1(5,B,3,2) increments 3; B(5) which was not 6.1.3 the by next 1, retained Assumed-Size statement but only because in the it provides subroutine after the Dummy Arrays An assumed-size dummy array is a dummy array (argument) for which upper bound of the last dimension is specified as *. For example: SUBROUTINE DIMENSION SUB(A,N) A(N,*) The size of an assumed-size array and the number of elements that be referenced are determined as follows: e If the actual noncharacter size e of the the argument corresponding array actual name, argument to the dummy array can 1is a the size of the dummy array is the array. If the actual argument corresponding to the dummy argument is a noncharacter array element name, with a subscript value of s in an array of size a, the size of the dummy array is a+l-s. SUBPROGRAMS e If the array actual element and begins character at argument is name, character or character storage INT(n+1-b)/y, a storage units, where y character is unit the the array array b of size length of of an array. Because the actual size of array name cannot assumed-size 6.2 A ® An © A unit ® A run-time ® A key e A buffer array either There three each used are a list an of an I/0 for in an of with n the dummy array is element array any I/0O internal specifier in an as array 1is the of not the dummy known, statement file I1/0 in an I/0 statement statement statement ENCODE/DECODE operations of types Table are or or program. of statements in needed each Types of statements. avoiding statements user-written statements control to 6-1: FORTRAN useful operations single type, the to transfer to having in two subprograms. define each or to duplicate more different Table type, and 6-1 1lists the method type. User-Written Subprograms Control Transfer Subprogram Defining Statement Statement-function definition Function reference FUNCTION Function reference function Function an following: is a statement or group of statements that procedure. A computing procedure can be a series subprograms in used name, an subprogram series locations be character substring SUBPROGRAMS arithmetic same assumed-size for specifier computing User-written the the format specifier user-written a in identifier USER-WRITTEN performs of name an name, element subprogram Statements Method ENTRY RETURN Subroutine subprogram SUBROUTINE CALL statement ENTRY RETURN A function reference (Table 6-1) function arguments, and is used is discussed in Section 4.5. consists of a in an expression. function The CALL name and statement SUBPROGRAMS Function and subroutine subprograms can change the wvalues their of arguments, and the calling program can use these changed values. A subprogram can refer to other subprograms but it cannot, either directly or indirectly, refer to itself. Statement Functions 6.2.1 d by a A statement function is a single-statement computation specifie in an name n functio ent wWhen vyou reference a statem symbolic name. |is name function nt stateme the by defined expression, the computation nt performed and the value produced is used to replace the statemeand function name in the expression. Statement functions are defined ' referenced within a single program unit. A statement function has the form: ([pl,pPl...]1)=e £ f The name of a statement function. P A dummy argument. e An expression. The expression (e) is an arithmetic or logical expression that defines the computation to be performed. A reference to a statement function has the form: £ (lal,al...]) The name of the An actual function. argument. on, the Wwhen a statement function reference appears in an expressiargumen ts dummy the with ted associa are ts values of the actual argumen in the statement function. The expression in the statement function is then evaluated, and the result is used to complete the evaluation of the expression containing the reference. The following rules govern the use of statement functions: e A statement function may not return a value of type CHARACTER. e Statement function e program names must be wunique within the same unit. A statement function reference must appear in the same program unit as the statement function. SUBPROGRAMS e Statement e functions include function (defined Statement functions must statements e <can statement (see Figure earlier be a reference in the placed before data type of a value computed by a determined either by the first letter by a type declaration statement. Statement order, function number, dummy and Names of statement arguments data type of The data type determined by e a type function dummy statement subroutine. only to indicate for the statement arguments valid must be Variables can be unique or arrays declared and by function and cannot invalid be used statement is or serve statement function dummy arguments the first letter of the argument name declaration statement. A of ‘executable of either a Examples unit). arguments only within each statement function. having the same names as dummy arguments used within the same program unit. e all another statement function of the function name function. e to program 1-3). The e same as an functions EXTERNAL argument is or in are: valid VOLUME (RADIUS) = AVG (A+B+C)/3 (A,B,C) SINH (X) = = 4.189*RADIUS**3 (EXP(X) - EXP (-X))*0.5 Invalid AXG(A,B,C,3.) The examples second valid of = (A+B+C)/3 statement statement (a constant function function references cannot be a dummy argument) below refer to the integer, but is real) above. valid GRADE IF = (AVG AVG (TEST1,TEST2,XLAB) (P,D,Q).LT.AVG(X,Y,Z))GO TO 300 Invalid FINAL 6.2.2 = AVG (TEST3,TEST4,LAB2) Function FUNCTION [typ] is C Subprograms A function subprogram consists of a series of statements that make invoked with a function reference. The (LAB2 statement FUNCTION has the FUNCTION statement followed up a computing procedure. following nam{*m [ ([{p[,p]..-1)] j| form: by It a is SUBPROGRAMS typ Any data type specifier The name of function. except CHARACTER (see Table 2-2). nam A data A a type dummy length specifier (see Table 2-2). argument. The function reference that 1invokes, function subprogram has the form: nam ([a[,a)...]) The symbolic or transfers control ¢to, a control is nam When An actual a function transferred arguments (if name of the function. argument. reference to in an expression the referenced any) in the is subprogram and function reference executed, the values of are associated the actual with the dummy arguments in the FUNCTION statement of the subprogram. The statements in the subprogram are then executed and a computed value is assigned to the function name (as if this name were a variable). Finally, a returned of a to RETURN RETURN statement acts function name containing The is executed implied RETURN.) the calling program unit. an the function and control The value assigned is in place to the is now used to complete the evaluation of the expression the following as in (An END statement used name. rules govern function may not the use e A return e A FUNCTION statement must of function a value of be the first subprograms: type CHARACTER. statement of a function subprogram. @ A FUNCTION e A e subprogram must SUBROUTINE, BLOCK DATA, not statement label. contain the or following FUNCTION. A function subprogram can reference another subprogram, reference The data itself, in a either directly or type of a function name can be FUNCTION statement or A function name must have as e a function the @ not have statements: cannot e statement must referencing in a type and specified declaration the same data program, vice type but it indirectly. in either in statement. a subprogram versa. ENTRY statements can be included in a function subprogram to provide one or more other entry points to the subprogram (see Section 6.2.4). SUBPROGRAMS An example of a function FUNCTION X 2 is the function ROOT: ROOT (A) =1.0 EX = EXP (X) EMINX ROOT IF X subprogram = = 1./EX ((EX+EMINX)*,.5+COS(X)-A)/((EX (ABS (X-ROOT).LT.1E-6) = GO - EMINX)*.5-SIN (X)) RETURN ROOT TO 2 in this END The to function obtain F(X) The value this root the = example root of cosh(X) + of A is Xi - the uses cos(X) passed the following as - an A Newton-Raphson iteration method function: =0 argument. The iteration formula for is: cosh(Xi)+cos(Xi)-A Xi+l = sinh(Xi)-sin(Xi) The calculation is repeated is less than 1.0E-6. The function uses (see Section 6.3). 6.2.3 Subroutine A subroutine symbolic of a The the FORTRAN 1in SUBROUTINE SUBROUTINE a is CALL statement statement SUBROUTINE the difference library functions between EXP, Xi SIN, and COS, Xi+l and ABS Subprograms subprogram name until nam a computing procedure statement. A subroutine followed a has the by series of referenced subprogram by a consists statements. form: [([(pl,P}...1)] nam The A name dummy You must use a arguments CALL and unit., When control the subroutine. argument. subprogram, program of statement a RETURN Section is 4.5 transferred (if any) in to transfer statement describes to a the return as an a value implied to the RETURN.) the to a control to the CALL subroutine calling the values of the actual statement. statement are associated with in the SUBROUTINE statement. The are then executed until a RETURN calling program. (An END statement Unlike referencing control return subroutine, CALL corresponding dummy arguments statements 1in the subprogram statement returns control to the acts to a function, program. a subroutine does not SUBPROGRAMS The following @ rules govern the use of subroutine The SUBROUTINE statement must be the subprograms: first statement of a subroutine. e A subroutine subprogram must not contain DATA, or another SUBROUTINE statement. @ A subroutine it cannot reference itself, o ENTRY statements can be provide edge. It in the polyhedron, uses polyhedron 1is procedure for icosahedron. another either directly or included in a a the a following given computed subprogram, example subroutine The GO GO TO statement TO statement «cube, also calculating the volume. the computes subprogram to the volume subroutine to determine octahedron, transfers control to the If the number of faces displays an error message Program COMMON NFACES,EDGE, VOLUME ACCEPT *, NFACES,EDGE PLYVOL TYPE *, 'VOLUME=',6VOLUME END Subroutine SUBROUTINE COMMON PLYVOL NFACES,EDGE, VOLUME CUBED = EDGE**3 GoToO (6,6,6,1,6,2,6,3,6,6,6,4,6,6,6,6,6,6,6,5) ,NFACES GOTO 6 VOLUME = CUBED * 0.11785 = CUBED = CUBED * 0.47140 = CUBED * 7.66312 = CUBED * 2.18170 RETURN 2 VOLUME RETURN 3 VOLUME RETURN 4 VOLUME RETURN S5 VOLUME RETURN 6 100 TYPE 100, NFACES FORMAT (' NO REGULAR POLYHEDRON HAS VOLUME=0.0 RETURN END of whether STOP 1 (see dodecahedron, Example: CALL but indirectly. a the number of faces and the length of one tetrahedron, 4, 6, 8, 12, or 20, user's terminal. Main BLOCK 6.2.4). subroutine regular reference FUNCTION, one or more other entry points to the subprogram Section The subprogram can a ',I3, ' FACES.'/) the or proper is not on the SUBPROGRAMS ENTRY 6.2.4 ENTRY Statement The ENTRY statement is a nonexecutable multiple entry points to a subprogram. function or subroutine subprogram after the statement. begins Execution with the first 1in a statement It can FUNCTION subprogram containing executable statement an that provides appear within a or SUBROUTINE ENTRY following statement the ENTRY statement. The ENTRY statement has the form: ENTRY nam [([p[,pl...]1)] The name. nam A CALL entry dummy argument. statements are used to refer to entry subprograms; function references within function subprograms. The following e Within type @ rules You a govern function declaration can then specify wuse the of subprogram, names wused ENTRY an to within refer subroutine to entry names statements: entry name can appear in a statement. an entry use are entry name name as an an entry in an actual EXTERNAL argument (but statement not as a and dummy argument) . e ® You must not use subprogram) that You dummy can order, in the use subroutine, ¢ You arguments in executable follow in an ENTRY ENTRY However, each entry use must statements statements a that differ in dummy arguments you use statements in the same reference to actual argument an (in statement. a function, 1list that in order, number, and type with the dummy argument list corresponding FUNCTION, SUBROUTINE, or ENTRY statement. statements ® or A dummy argument ENTRY name or number, type, and name from the FUNCTION, SUBROUTINE, and ENTRY subprogram. agrees in the precede statement must not can that use be referred follow in an which ENTRY the to only first the dummy statement in the SUBROUTINE, argument within is a DO executable FUNCTION, specified. loop. or SUBPROGRAMS 6.2.4.1 ENTRY subprogram 1in and all Function the mutually associated; Subprograms - The entry names therefore, contained a value assigned name in the of a function subprogram to any one name are Iis assigned to all the names. However, only names of the same data type can be mutually defined at any one time, because conversions between data types are not made. A referenced entry name must be transferred back to the calling Figure 6-1 illustrates the use assigned program. of an a ENTRY value before statement 1in control a subprogram that computes the hyperbolic functions sinh, cosh, of a variable x. PROGRAM MAIN EXTERNAL TANH, SINH, function and tanh COSH X = 24.0 TANHX = TANH (X) SINHX = SINH (X) COSHX = COSH (X) END REAL C C FUNCTION STATEMENT TANH (X) FUNCTION TO COMPUTE TWICE SINH TWICE COSH C TSINH(X) = EXP(X) - EXP (-X) C C STATEMENT FUNCTION TO COMPUTE C TCOSH(X) = EXP(X) COMPUTE TANH + EXP (-X) C C C TANH = TSINH(X) / TCOSH(X) / 2.0 / 2.0 RETURN C C COMPUTE SINH C ENTRY SINH (X) SINH = TSINH(X) RETURN C C COMPUTE COSH C ENTRY COSH COSH (X) = TCOSH(X) RETURN END Figure 6-1: Multiple Functions in a |is Function Subprogram SUBPROGRAMS 6.2.4.2 ENTRY in Subroutine Subprograms - To reference an entry in a subroutine, you execute a CALL statement that includes the point name. The following example demonstrates the use of the statement to reference an Main Program CALL SUBA(A,B,C) entry point entry CALL point: Subroutine SUBROUTINE ENTRY SUB (X,Y,Z) SUBA(Q,R,S) In this example, the CALL is subroutine (SUB). Execution ENTRY SUBA (Q,R,S), CALL statement. 6.3 INTRINSIC FORTRAN AND OTHER library perform using the used entry point with the first actual LIBRARY functions commonly to an begins arguments FORTRAN references references result of R = the intrinsic consist of intrinsic mathematical the reference 3.14159 absolute and Appendix C actual 6.3.1 passed 1in the are functions, computations, listed and in and provided to character and 1lexical Appendix comparison C. Function to these functions are written in the same way function to user-defined functions are written. For example, as a 3.14159, its functions (A,B,C) FUNCTIONS lexical comparison functions. Character functions are discussed in Section 6.3.4. The (SUBA) within the statement following * gives ABS in ABS (X-1) value the to of X-1 result the is is data calculated assigned type of to and the each multiplied by the constant function and that variable intrinsic R. of arguments. Intrinsic Function References Normally, a name in the table of intrinsic function names (Table C-2) refers to the FORTRAN library function with that name. However, the name can refer to a user-defined function under any of the following conditions: e The name is used different data e The name the rules in type appears in provided a function from an in that reference shown EXTERNAL Section in statement 5.8. with the arguments of a table. in accordance with SUBPROGRAMS Except when they names can be are used 1local to the program unit that refers to them. for other purposes in other program units, In the data IMPLICIT same 6.3.2 Some name change EXTERNAL same implied functions type function Thus, they addition, if you use an rules. user-defined function with unit. perform types. or These generic, of within For intrinsic not change data function and a program the the name. the example, if A generic function The D computation are computation category. same functions to be 1is a generic function SIN(D) refers to not to the real sine function. but referenced with reference performed, selection that is, the actual computing procedure left to the compiler, which chooses a category on the basis of the data argument. statement, function does the intrinsic the data category function an Function References intrinsic categorical, in intrinsic to an in Generic different the used type of an statement You cannot have the are of a not to specific handle the same refers a to specific function -- for a specific data type -- is specific function within a type of the relevant actual double-precision variable, the the double-precision sine function, (Therefore, you need not write DSIN (D) .) Generic function references are 1independent from Therefore, you could wuse both SIN(X) and SIN(D) in unit in the example in the preceding paragraph. Table 6-2 only with You cannot if you use lists the generic the argument data function names. types shown use the names in Table them in a program unit e As the e As a name of a These names can the name, be table. 6-2 for generic in either of the statement dummy argument array in one another., the same program function following used selection ways: function common block name, variable name, or name Generic function selection does not apply to a generic function name declared in an EXTERNAL statement and used as an actual argument, because there is no argument 1list on which to base the function selection. The name is treated according to the rules for nongeneric FORTRAN functions described in Section 6.3.1. For example, in EXTERNAL EXP CALL (EXP (D)) EXP (D) is therefore, SQRT SUB a generic function reference, not a generic function selection applies. EXTERNAL SQRT CALL SUB (SQRT) is generic a therefore, function generic Generic function them., units. Therefore, function names are they can name being used selection does local be to used the for 6-14 as generic function However, in a not program other nongeneric name; function; apply. unit purposes that references in other program SUBPROGRAMS Table Generic 6-2: Function Name ABS INT, Data Type of Result Data Type of Argument Generic Name AINT, Summary ANINT NINT REAL Integer Integer Real Double Complex Real Double Real Real Real Double Double Real Integer Double Integer Integer ' Real Real DBLE MOD, EXP, MAX, MIN, LOG, SIN, SIGN, COS, DIM SQRT LOG10, TAN, ATAN, ATAN2, ACOS, SINH, COSH, TANH 6.3.3 ASIN, Intrinsic and Generic - Real Double Real Complex Real Integer Double Real Double Double Double Integer Integer Real Real Double Double Real Double Real Double Complex Complex Real Real Double Double Function Usage Figure 6~-2 demonstrates the use of intrinsic and generic In this figure, a single executable program uses the four distinct ways: names., in As the name As a As an intrinsic As a user—-defined generic Using the name in properties of the In Figure that 6-2, follow the of a statement function these name. function name SIN function name function name function four ways the parenthetical figure. emphasizes references are the local keyed to and the global hotes Q0o SUBPROGRAMS COMPARE WAYS PROGRAM X, PI PARAMETER 10 SINE. (PI \ 3.141592653589793238D0) = V (3) SIN AS A STATEMENT FUNCTION = COS(PI/2-X) SIN(X) DO COMPUTING SINES REAL*8 COMMON DEFINE OF X = -PI, PI, (Note 1) 2*PI/100 CALL COMPUT (X) REFERENCE 10 100 THE WRITE (6,100) FORMAT (5(' STATEMENT FUNCTION SIN (Note 2) X,V, SIN(X) '+ F10.7)) END SUBROUTINE COMPUT (Y) REAL*8 Y USE INTRINSIC INTRINSIC COMMON FUNCTION SIN AS ACTUAL ARGUMENT V(3) GENERIC REFERENCE TO DOUBLE V(l) = SIN(Y) INTRINSIC FUNCTION SINE CALL SUB(REAL (Y), SIN) AS PRECISION ACTUAL SINE (Note 4) ARGUMENT (Note 5) END SUBROUTINE SUB(A,S) DECLARE SIN AS EXTERNAL SIN NAME OF DECLARE TYPE REAL*8 SIN REAL*8 SIN COMMON V (3) AS USER FUNCTION (Note (Note = 6) 7) EVALUATE INTRINSIC FUNCTION SIN (Note 8) V(2) = S(A) EVALUATE USER DEFINED SIN FUNCTION (Note V(3) 9) SIN(A) oNoNQ] END DEFINE THE REAL*8 FUNCTION INTEGER FACTOR SIN USER SIN FUNCTION (Note 10) SIN (X) = X - X**3/FACTOR(3) (7) ~ X**7/FACTOR + X**5/FACTOR(5) END INTEGER FUNCTION FACTOR =1 DO 10 I=N, 10 FACTOR (Note SIN = 1, FACTOR (N) -1 FACTOR * I END Figure 6-2: Multiple Function Name 6-16 Usage 3) SUBPROGRAMS l. A statement function named SIN generic function name COS. double precision, evaluated. the The is defined Because the double-precision statement function 1in terms of the argument of COS is cosine function SIN is 1itself so be that passed |is single precision. 2. The statement 3. The name SIN 1is declared intrinsic precision intrinsic sine function can argument 4. The at function generic The function name sine single-precision actual is SIN intrinsic name SIN is 7. The type of SIN 8. The single-precision sine 9. The user-defined SIN function 10. The user—-defined SIN function series wusing factorial Character Character take Three wused to refer to the sine function is wused as an declared is and user-defined declared double function user-defined Lexical function name. precision. passed at is evaluated. is defined function Comparison functions lexical are comparison arguments character a as 5 is a evaluated. simple FACTOR Taylor to compute the function. 1library character 1is argument. The arguments; the singleas an actual function. 6. 6.3.4 called. 5. double-precision 5. SIN and functions functions 1library return are Library that functions logical provided Functions take are character functions that values. with PDP-11 FORTRAN-77, as follows: e LEN The LEN function returns the The LEN function has form: the length of a character expression. LEN (c) c A character many e bytes expression. there are in The the value returned indicates how expression. INDEX The INDEX specified substring, occurs function more than first (leftmost) %n cl, the value orm: INDEX searches character returns the (cl, c2) once in occurrence zero for a substring string (cl) and, substring's starting cl, is the starting returned. is returned. The If (c2) in if it finds position. If c2 a the c2 position of the does not occur INDEX function has the SUBPROGRAMS cl A character searched expression for the substring specifying specified the string by c2. to be c2 A character the e expression starting location specifying the substring is to be determined. for which ICHAR The ICHAR function converts a character expression to its equivalent ASCII code and returns the ASCII value. ICHAR has the form: ICHAR The (c) character longer than returned; An example to one the remainder illustrating CHARACTER INTEGER 1 be converted to an ASCII code. 1If ¢ byte, only the value of the first byte COMPOS IF the is LEN is is ignored. and INDEX functions follows: BUFR*80 COMPOS, INIPOS = INDEX(BUFR(INIPOS:),',"') (LEN(BUFR (INIPOS:COMPOS)) TYPE *,'NAME IS TOO LONG, .GT. 8) THEN IT HAS BEEN TRUNCATED.'® ENDIF Four lexical comparison functions are provided with PDP-11 FORTRAN-77, as follows: The e LLT, where LLT(X,Y) is equivalent to (X .LT. Y) e LLE, where LLE (X,Y) is equivalent to (X .LE. YY) e LGT, where LGT(X,Y) is equivalent to (X .GT. Y) e LGE, where LGE (X,Y) is equivalent to (X .GE. Y) lexical functions have the form func(c,c) func One of the symbolic names: A character The lexical according pProcessors. On identical the to expression. library to .LLT, LLE, LGT, or LGE. the functions are guaranteed to make comparisons ASCII collating sequence, even on non-ASCII PDP-11 systems, corresponding the 1lexical character 1library relationals. functions are SUBPROGRAMS An The example of the use CHARACTER*10 CH2 IF 'SMITH')) IF IF (LGT(CH2, statement (CH2 .GT. in of this the lexical functions STOP example 'SMITH') library is equivalent STOP 6-19 to: follows: CHAPTER INPUT/OUTPUT FORTRAN programs REWRITE, TYPE, use and READ and PRINT 7 STATEMENTS ACCEPT statements statements for Some forms of these statements are used with control the translation and editing of data form and external (readable character) form. The READ which and WRITE data statements data 1is do user's line to reference the reference a transferred. program a and Normally user's 1logical the wunit and PRINT to TYPE, rather, logical ACCEPT terminal; and WRITE, specifiers that internal (binary) ACCEPT, wunit; implicit the format between The logical an input, or from and PRINT they transfer unit (for TYPE statements statement, example to the the are system printer. Input/output e (I/0) statements Sequential e The a be terminal). connected or not between statements to for output. I/0 -- files, or to and Direct Access number to Indexed 1I/0 contained in e Internal variables 1I/0 and statement forms I/0 an -- from e grouped transfers from 1/0 and are into records transfers categories: sequentially I/0 device direct-access four such as records a can be a and from selected by record by data files. values data between files. —- transfers records selected the records to and from indexed -~ translates arrays within to terminal. and transfers program. classified as formatted, list-directed, unformatted. Formatted I/0 statements contain explicit format specifiers that are used to control the translation of data from internal (binary) form within a program to external (readable character) form in records, or vice versa. List-directed function, format the I/0 but statements differ specifiers to in are that control similar to formatted they use data the types translation of statements instead of data from one in explicit form to of any other. Unformatted I/0 statements do not contain format specifiers kind and therefore are not used to translate data being Unformatted I/0 saves execution time, by eliminating data transferred. translation; storage data preserves output is Table 7-1 used in the precision of external data; space. Unformatted subsequently shows PDP-11 the to be various FORTRAN-77 I/0 is used I/0 and especially as 7-1 when to file be input. statements, programs. usually conserves useful by category, that can be INPUT/OUTPUT STATEMENTS Table 7-1: Available I/O Statements Category Statement Statement Name Sequential Direct L U F U F U F READ X X X X X X X X WRITE X X X X X X X X REWRITE - - - - - X X - ACCEPT X X - - - - - - TYPE X X - - = - - - PRINT X X - - - - - - data in records (see - L - List-Directed U - Unformatted Formatted I/0 statements transfer units of The amount of data that one of these whether unformatted or formatted I/0 is unformatted data Internal F F With Indexed to be I1/0, the transferred; associated format I/0 with specifier statement formatted jointly Section records can contain used to transfer alone I/0, determine specifies the I/0 the 7.1.1). depends on the data. the amount statement amount of is read and data to of its be transferred. Normally, the data written to only I/0 statements to Section 7.2 7.1 transferred describes describes by one record. transfer data the general FORTRAN components describes the syntactical Sections 7.4 through 7.8 an I/0 statement It is possible, from or to more of rules input/output FORTRAN I/0 that govern describe however, than one the from concepts. statements. the I/0 Section Section 7.3 statements. 1I/0 individual or for formatted record. statements in detail, 7.1 The I/0 OVERVIEW following sections describe in general terms the characteristics of FORTRAN I/0 processing: records, files, internal files, modes. See the PDP-11 FORTRAN-77 User's Guide for specific FORTRAN 7.1.1 1/0 and access on detail processing. Records A record is a collection of data items, called fields, that are logically related and that are processed as a unit; that is, the I/0 statements transfer data to and from files and internal files in units of records. formatted I/0 Normally, each statements may I/0 statement transfer more processes than one one record, record. though INPUT/OUTPUT If an input record, statement the requires more data condition occurs read If as an not use fields fields than or, 1in the all are the data fields ignored. If it an can transfers statement contain, fewer record 1is unformatted the record contains, either case of formatted input, all attempts an data error than filled with record). to write condition file can have sequential, Files required spaces are one of relative, normally three or to (if a more data fields If an output fill a fixed-length formatted record) 7.1.2.1 stored Sequential appear in appear always to 7.1.2,2 the possible on arrangements disk; however, Peripheral are treated Organization - physical is written record, or zeros the (if an last). A sequence. identical cell's of The specific record to In a The A key that is a the indexed number in a a have in file, key; order represents relative You must 1is 1in key value identify can designated field that the to 1is records contents at least primary keys additional record which in be card records which the 1its file 1 records records consists (the 1location are first) of in the have one an field field in indexed relative key for alternate field that is contained record the the an called of any one these key indexed file. keys. Each the value. them for same When to the it can to a relative creating file's records record file. alternate the fields are is then to a of This mandatory key represents you can define records can retrieval. an used The 1length of the same in each Optionally, in all additional containing same a (the record or to refer file. in the in of one n keys. contained, in this be key any of to 1in an indexed file are sequence -- by fields in the that record for subsequent processing. as well as its relative position, is in a file. the may file. you decide which data define additional been all the to identify key field, the records files file, order the file. A cell can contain a single cell number, or record number, is used data position, organizations: sequential physical 7.1.2.3 1Indexed Organization - Records ordered -- not necessarily in physical records or sequential Organization - A relative fixed-length cells numbered from of arranged in a or organization file. beginning be empty. The the statement devices such as terminals, as sequential files. Relative sequence an than indexed. stored on magnetic tape. readers, and line printers key a an error fields are occurs. A file is a collection of logically related records specific order and treated as a unit. The arrangement of a file is determined when the file is created. be from statement Files 7.1.2 A reads input spaces. output record does remaining STATEMENTS be in a More file. used to than one INPUT/OUTPUT An internal facilitate An file substring. except an a is file a A is internal same length of records, The of A the internal record in defined Prior to of is, mode file. 7-2 the in consists manipulated of array, of any a or of character a character the the Table 7-2: be a or element, length single a element. the order only if the comprising the record character has been positioned at the value. internal file is always a program mode uses to retrieve 1is FORTRAN-77 and specified supports as and store part of three access Access Modes modes for each file organization. for Each File Organization Mode Yes Yes 1 No Relative Yes Yes No Indexed Yes No Yes in sequential file, records; in numbers; and values. file. Access a fixed - length. Sequential numerical, relative sequence indexed access means or this processing order If two records in an processing be physical, in an 1I/0 modes: keyed. valid must records each access Sequential Sequential If array Keyed 7.1.4.1 or the sequence Direct Records is substring. comprises Sequential processed above is determined by read substring a file array whose element, this of can record File Organization l. to record. PDP-11 shows array array, file assigned an variable, single internal or access direct, a Access the 1is consists consisting an file method The statement. file variable, record first in is it character character transfer, the Access Table the a element, Access Modes sequential, single internal that that a character internal progression. an file; comprises each 7.1.4 a real an a records data beginning of is array -- is of subscript variable, in with sequence a array element, file file space array. file this as not record character storage I/O. character substring, an internal internal internal variable, If Files 1Internal 7.1.3 STATEMENTS that chronological is the physical a sequence of the it is ascending cell file, it is the sequence of ascending Kkey have the indexed file sequence are In file, is the order the records order. the same of key in which the records were value, inserted in INPUT/OUTPUT 7.1.4.2 Direct Access 1is specified processed statement. the file For must 7.1.4.3 - records Direct by in wholly Keyed Access - Keyed 1is specified by of a can mix statements in the that same I/0 statements to sequential statements I/O access program reference the position a file to to a process in directly that access file. be record number the record (Section and particular successive be an I/0 to 7.2.1.5) sequential Therefore, to accessed, records. means keyed same the record specification file to that access fixed-length key I/0 statement. You means direct sequential consist processed access a a STATEMENTS you place be in access can use and an I/0 keyed then use records. The key specificaton in an I/0 statement may specify an exact match by providing a complete key value, or it may specify a generic match by providing a partial key value. In the case of a generic match, the first record whose leftmost characters match the partial key value is the record selected. A match criterion match. An calls for approximate greater-than-or-equal-to 7.2 I/0 I/0 statements There a are six remaining The control basic The and the list an of I/0 an approximate e Specify whether the number Specify the key match or a error where or of control statement asterisk in file statement ACCEPT, represent WRITE, input REWRITE, operations, discussed of and is a 1list functions: be to acted be is below. be one or more upon acted to of upon used for data editing specification a direct access key-of-reference control end-of-file a record of a to keyed be and, accessed access record is to be For contains of a place of can always example, the a format in the format be determined by control list of a specifier 1list-directed a transferred event of an condition statement list. always 1list a accessed Specify control to formatting the category unit format Specify be are following internal is, components: READ, these statement the the it of list I/0 perform Specify its or greater-than operations. e to The output logical if of a list,. two first the e match basic I/0 keywords: List that an The Specify e either three and e ® exact be statement Control control specifiers four list of list, PRINT. the The an match. consist control and 7.2.1 can STATEMENT COMPONENTS keyword, TYPE, either match I/0 specifier. 7-5 (FMT=f statement or the contents formatted I/O f), always and contains the an INPUT/OUTPUT STATEMENTS The control list has the form: (pl,pP}...) A specifier of the form: keyword = value. The control list specifiers are discussed in the following sections. Logical Unit Specifier - The logical unit specifier specifies 7.2.1.1 It has one of the forms: the logical unit that is to be accessed. [UNIT=]u [UNIT=]*%* u An integer expression, with a value in the range refers to a specific file or I/0 device. that value is converted to 0 through 99, If necessary, the integer data type before being used. * Specifies that the default input or output unit 1is to be specifier Iis of two accessed. The keyword UNIT= is optional only if the logical the first parameter in the control list. A logical unit number unit is connected to a file or device in one ways: e e Explicitly, by an OPEN statement Implicitly, by the system. describes the use of in greater detail. 7.2.1.2 1Internal The internal File internal specifies the file (see The PDP-11 FORTRAN-77 User's Guide implicitly connected Specifier - An file specifier Section 9.1). internal to be used. has the logical unit numbers file specifier array, character form: [UNIT=]cv cv The name of a array element, The logical mutually wunit character variable, character or character substring. specifier exclusive. file specifier is the The first and keyword the parameter internal file specifier are UNIT= is optional if the internal in the control list. See Section 7.1.3 for more information on internal files. INPUT/OUTPUT STATEMENTS 7.2.1.3 Format Specifier - The format specifier or list-directed formatting is to be used formatting, identifies the parameter that formatting. The format specifier has the form: specifies whether and, in the case of will control the explicit explicit [FMT=]f [FMT=]* £ The statement label of a FORMAT statement, an integer that has been assigned (with an ASSIGN statement) statement-label a character value, the expression name of containing an a array run-time or array variable a FORMAT element, format. or * Specifies The keyword list-directed FMT= is second parameter logical unit or formatting. optional in the internal only file You can format 7.4.1.2 use an FORMAT formats asterisk specifier, to and on 7.2.1.4 7.5.1.2 Record of the the forms: direct REC= in format and the without sequential I/O - The to record be 8.7 specifier The See a keyword instead specifies record the is describes formatting. accessed. 1is parameter optional statements, list-directed list-directed I/O. record specifier first the statements. Section and I/0 statements. denote Specifier access the 1list specifier UNIT=. Chapter 8 describes interaction between if «control the of a Sections the number specifier has r 'r A numeric expression with a value that represents the position, in a direct access file, of the record to be accessed. The value must be greater than or equal to 1, and less than or equal to the max imum number of record «cells allowed 1in the file. If necessary, before a record being number is converted to integer 7.2.1.5 indexed Key Specifier file record - The key specifier specifies to be accessed, the index in located, and criterion the match An indexed file contains this 1index are 1listed containing increasing Using a key to be used to a a key index for each designated key the keys and the locations of looks up the the proper obtain 7.1.4.3). in the key which this search. an them; records are ordered key wvalue. Once supplied record, the system the 1location of Section data type used. specific of an key is field. In the records sequentially 1in order of with the key of the desired key in the appropriate index and finds record. It then accesses this record. record is called keyed access (see INPUT/OUTPUT The the indexes of a maximum must be primary key. The keys; alternate key. READ The A of than 255. alternate Keyed file are denoted by numbers number less access STATEMENTS 1Index other for to indexes number 1indexes example, indexed defined 0 files is the file. is called are 1index from 0 to n, for the called number specified specifies key value primary alternate 3 by where The n of |is n index or indexes or the third specifications in statements. key specification of a key 1. A key 2, A key-of-reference 3. A match key expression, which has which the has specifies specifier, criterion, specification specifier three the which components: key specifies the specifies the selection value of which, index constraints form: KEY Egzgg =ke [ ,KEYID=kn] KEYGT ke A key expression. kn An integer expression, key-of-reference The KEY the logical (1) and Key parameters and e Character e Integer format key - Two key must be e CHARACTER e CHARACTER constant e A array of be key used used any be order, expressions in or with with one called the searched. but must are follow supported: of character integer the keys. following array name containing you can now specify keys as STATUS='OLD', Hollerith follows: ACCESS='KEYED'. ORGANIZATION="'INDEXED', 2 KEY=(1:5,18:23)) CKEY='SMITH' READ (3,KEYGE=CKEY) and ALPHA,BETA FORM='UNFORMATTED', integer A character forms: CKEY (UNIT=3, keys substring 1 END in to element (LOGICAL*1) CHARACTER*5 OPEN must specified CHARACTER variable example, appear index specifiers. types be e BYTE may the expressions expressions may specifies key expressions expressions expression For unit Expressions Character key KEYID the number, data key INPUT/OUTPUT STATEMENTS The length character key of expression occurs. of the value the If key character or is the greater the length field, a key length expression of than the the of the key generic key search (See "Match An integer key expression is and values The name of a Criterion" wvirtual is the If the key is made 1length the field, less rather of length the of the an error than the length than an exact below.) an array of expression search. complex 1is array. length key double-precision, BYTE integer are cannot expression. not permitted. be wused to Real, specify a key expression. (2) Key-of-Reference the value, key-of-reference or index Specifier specifies to be If no given (3) in the last number, must be must be equal key specified The an integer is to included be what statement in it for the in the match by the criterion to, greater key expression. has the than, key in given EQ - specifies equal - specifies greater than GE - specifies greater than or to KEY criterion is greater 0 specification, the specification logical unit. than or the match equal to the forms: GT match or Its range file. A value of 0 the first alternate : a was specifier record. Match Criterion - The match criterion specifies whether key The I/0 locations of a keys defined for the value of 1 specifies is assumed keyed key-of-reference the key-of-reference specifier key-of-reference The for to the maximum number of specifies the primary key; a key; and so forth. the - searched to appended equal as to follows: KEY KEYEQ KEYGT KEYGE For character ASCII For no integer comparisons are made on the match criterion For character the leftmost For example, characters contains keys, KEYGE) generic if are the as of the key key expression an equal of the basis of the equal matching or is assumed. exact matching the match first is field is are used 'ABCD', obtained four bytes of and for the for the the key. is used. I/O statement is matching, only the match. key field first The is ten record that remaining six arbitrary. generic matching is selected matching, comparison. specified, either generic matching characters 'ABCD' Approximate is applies if the key expression in the key field in the record. 1In generic 1long, characters basis sequence. Generic matching shorter than the or matching sequence. integer keys, matching comparisons are made on the signed If keys, collating occurs when approximate in addition to generic matching. only the 1leftmost characters matching (KEYGT In approximate are used for INPUT/OUTPUT STATEMENTS For example, if the key expression five characters long, and a 'ABCDA' does not match. The 7.2.1.6 Transfer-of-Control specifiers specify transferred in condition. The the a is and the Specifiers - The statement event 'ABCD', key field is greater-than match is selected, the value value 'ABCEA', however, does match. of an to which end-of-file transfer-of-control transfer-of-control program control condition specifiers have or is to be an error the form: can include either END=s ERR=s The A READ, or both label of an executable WRITE, REWRITE, of above the specifiers must statement. ENCODE, or DECODE specifiers in any order. 1logical unit, follow the statement The transfer-of-control record, and format specifiers. The statement an executable as the I/0 An end-of-file (see or transfers control If a END=s READ, error to whose present, An END= the label the read or or The PDP-11 FORTRAN-77 you can used to the must same refer to program unit to for obtain or in an error or record the logical Guide error information REWRITE using a a statement operation, it specification. condition occurs. encounters transfers control If to no an the ERR=s execution. statement, record unit, an describes the ENDFILE READ END=s statement processing. from 1I/0 1in the specification. program READ a exist by statement it ERR=s If an the DECODE the access User's control in WRITE a records produced during I/0 operation, terminates a more record named present, appears in no encountered. ENCODE an write specified use 1is keyed maximum when end-file condition is I/0 error the be specifier located within statement REWRITE, specification to an 9.7) during statement, attempt is occurs specification WRITE, is READ that end-of-file condition statement transfer-of-control when Section an no a condition file encounters If in statement statement. sequential statement label is number error system These 1I/0 direct access ignored. 1If greater condition occurs. subroutines subroutines system on you than that can errors also that occur. Examples statements READ This of WRITE wuse (8,END=550) statement condition the of specifiers in I1/0 (MATRIX(K),K=1,100) transfers occurs on control logical to unit 8. control to statement 550 statement 390 if an end-of-file (6,50,ERR=390) This statement transfers during execution. READ transfer-of-control follow. (1,FORM,ERR=150,END=200) ARRAY if an error occurs INPUT/OUTPUT This statement transfers during execution, and control to STATEMENTS to statement statement 200 150 if an if an error end-of-file occurs condition occurs. 7.2.2 I/0 List The I/0 list in an input or output statement contains the variables, arrays, array elements, and character substrings or to which data is to be transferred. The 1I/0 1list in statement An I/0 can list also has contain the constants and expressions to be names of which from an output output. form: s[,s]... A simple list or an implied DO 1list. The I/0 statement assigns values to, or list elements in the order in which they appear, from left 7.2.2.1 Simple List I/0 1list element or consists of either more separated by commas. A simple a group A I/O of simple an array, an array example, in the statement For WRITE J, K(3), When you ACCEPT a (L+4)/2, use an TYPE, in subscript defines a If the and are simple I/0O N PRINT order array enough data statement with of name constant, list in fill writes an all I/0 or a list can be an a simple elements single expression. 1list, element the values element progression, For I/O the right. elements. every initial subscript simple from, to example, the appears in of in a READ the or array; the array. of the array with the leftmost and following statement ARRAY (3,3) ARRAY, statement ARRAY (1,1), name to the varying most rapidly. two-dimensional array: DIMENSION this N values element a (L+4)/2, begins the 1list element, 4, reads or or K(3), unsubscripted transfer proceeds J, 4, statement WRITE, Data (5,10) list two I/0 variable, transfers with no assigns ARRAY(2,1), subscripts, values from ARRAY(3,1), the input ARRAY(l1,2), a READ record statement, or records to and so on through I/0 list can be used say you are given ARRAY (3,3) . In a in array the READ or ACCEPT subscripts later in variables the list. in For the example, statements: READ 1250 and statement, an (1,1250) FORMAT input J,K,ARRAY (J,K) (I1,X,I1l,X,F6.2) record that contains the values: 1,3,721.73 When to the J READ and statement the second is to executed, K; the the first actual input value subscript is values assigned are now INPUT/OUTPUT established for ARRAY (1, 3). ARRAY (J,K). Variables must appear before in the An I/0 example, that this an the are to left of) I/0 1list expression output refers input than The value that be 721.73 1is used subscripts their as use as then assigned the array in to this way subscripts list. output-statement However, An (to STATEMENTS to a statement function statement I/0 as a subscript may must contain I/0 list subprogram list must expression any not attempt that not in must not contain performs contain an valid array expression. any I/0 operations. an an an For expression I/0 operation. expression used other reference. 7.2.2.2 1Implied DO List - An implied DO list is an I/0 1list element that functions as if it were a part of an I/0 statement within a DO loop. 1Implied DO lists can be used to: An e Specify e Transfer part e Transfer array order subscript implied iteration of of DO list of an part of I/0 list array elements has an in an order that differs from the progression the form: (list,i=el,e2[,e3]) list An I/0 An integer list. variable. el,e2,e3 Arithmetic expressions. The variable i and the parameters el, e2, and e3 have the " same and The functions that list immediately the 1implied must not For example, WRITE behaves as WRITE In the DO alter loop. the the Elements value of forms the DO statement (see Section 4.3). DO loop parameter is the range of in that list can reference i but they i. statement (3,200) if they have in preceding the you (A,B,C, had (3,200) I=1,3) written the statement A,B,C,A,B,C,A,B,C statement WRITE (6) the implied I/0 list DO for each value (I,(J,P(I),Q(I,J),J=1,L),I=1,M) consists of an 1list of nested I and implied within write a it. total 7-12 DO The of 1list that implied (14+3*L)*M DO contains lists fields. vary another the Js INPUT/OUTPUT STATEMENTS In a series nesting of (see repeated most nested implied DO Section 4.3.2). often. WRITE 150 because (6,150) FORMAT the In the lists, the Execution parentheses indicate the of the innermost list is example ((FORM(K,L), L=1,10), K=1,10,2) (F10.2) inner DO loop is executed 10 times for each iteration of the outer 1loop, the second subscript advances from 1 through 10 for each increment of the first subscript -- that is, in the reverse of the standard order of subscript progression. In addition, because K is incremented by 2, only the odd-numbered rows of the array are output. The entire control list READ 0(1,1), When processing an is (5,999) P(1), fixed list. of variable implied DO incremented. (p(I), (Q(I,J), J=1,10), read in statement is incremented before I of DO J=1,10) of The value of the control variable can also be output example, the WRITE 7.3 The statement (6,1111]) prints the SYNTACTICAL FORTRAN subject e to I/O the When e integers 1 through directly. For 20. keyword a described syntactical form, control the in Sections control nonkeyword form of internal file specifier must a control When used with a specifier, the the file therefore occupy If you use specifier, parameters either the logical occupy 7.8 are appear in any unit the specifier or first position specifier the (leftmost) 1list. first in must the control specifier. list; internal specifier the also be in nonkeyword position in the control the nonkeyword form of a it must immediately follow a unit can 1logical wunit specifier or nonkeyword form of the format second internal through list. the in 7.4 rules. The logical then I=1,20) statements in occupy BOX(1l,10), and the array. RULES position e¢ (I, following in order e the I=1,5) assigns input wvalues to BOX(l,1) through terminates without affecting any other element simply before the multidimensional arrays, you can use a combination subscripts and subscripts that vary according to an implied For example, the statement (BOX(1,J), is transmitted 2. (3,5555) ...,Q0(1,10) is example, to READ ©0(1,2) 1list For wunit form file must or (and list). direct access nonkeyword form record of the INPUT/OUTPUT STATEMENTS READ THE READ STATEMENTS 7.4 The READ statements records from internal sequential, 7.4.1 The Sequential from files. Sequential input external There are four indexed, accessed three classes of classes Formatted of or of to storage fmt storage internal storage READ statements: the data READ to sequential mode of access. statements: formatted, READ statements have the forms: READ Statement [,err][,end])[list] f[,list] READ Statements READ (extu, READ *[, Unformatted * [,err] [,end]) [list] list] Sequential READ Statements [list] [,end]) (extu [,err] unit specifier. extu A logical A format See Section 7.2.1.1. fmt specifier. See Section 7.2.1.3. format specifier. £ The nonkeyword form of a See fmt, * Specifies from internal internal. input under sequential sequential Sequential List-Directed READ categories and internal unformatted. READ (extu, READ to units, READ Statements records and data logical READ statements transfer list-directed, three in direct access, external There are The transfer contained list-directed formatting. err end Transfer-of-control specifiers., See Section 7.2.1.6. above. INPUT/OUTPUT STATEMENTS list An Refer the I/0 to list. Section above 7.4.1.1 7.3 The for statement under Translates Assigns in the the number of the the appear If in The statement ® of data I/O the Each an data elements character in - The more mode external of access binary elements right, in form in READ Statement - The records using format I/0 1list, the which data the of from records those elements than the the excess 1list-directed accessed READ under access from the external elements provide in to the binary I/0 form list, of formatted a statement is 1less the statement ignores record, and the using the forms the of editing translated data to the from left to right, in elements in which those the I/0 list in elements appear records from which 1list-directed READ statements sequence of values and value separators. of these records may e A constant ® A null ® A repetition of constants @ A repetition of null constant read has the constant a be any one of the following: value form has comma the and of in values the form of enclosed closing parenthesis. A values -- that is, .TRUE. or to the to the in .FALSE. constant or 1is any form the r*c form corresponding a in pair of r¥* FORTRAN real or parentheses. between the opening parenthesis and after the separating comma, and between .t; use a one by to 1left input data character the list. the separated or keyed editing Translates in or character of The external data contain one from mode complex govern following: the order, in the list A value that Statement provide sequential Assigns READ from from list in data types the data, to e to List-Directed does Reads e rules following: sequential translated the fields the data order, fields. 7.4.1.2 syntactical does the specifications number 7.2.2. Sequential character accessed ® the Formatted READ Reads o Section parameters. sequential ®¢ See the the constant. integer Spaces A constants can occur first constant, before second constant and and the logical constant represents true or false any value beginning with T, .T, t, or or value delimited beginning by with apostrophes, F, .F, with £, an or .f. A apostrophe INPUT/OUTPUT are A not Hollerith, octal, hexadecimal two by represented and constants permitted. null value intervening Spaces apostrophes. being constant character that occurs within a consecutive STATEMENTS can 1is occur indicates that represents complex specified constant, an or before by by or after the corresponding entire complex two an the consecutive initial commas. A list element constant (but commas comma or a null with trailing wvalue remains unchanged, not Jjust one no comma. either part or it of a constant). The form r*c specifies r occurrences of ¢, where r 1is a nonzero, unsigned integer constant and ¢ 1is a constant. Spaces are not permitted except within the constant c as specified above. The form r* unsigned A value specifies integer separator e One or e A e A slash, r occurrences of a null value, constant. in more comma, a record spaces with or may be or any one of the where r 1is an following: tabs without surrounding spaces or tabs with or without surrounding spaces or tabs The slash terminates execution of the input statement and processing of the record; all remaining I/0 list elements are left unchanged. When any of the above considered part of the appear in a character constant, constant, not value separators. The equivalent end of occurs a record is to 1in a character constant. character constant, constant 1is character in the previous character in the next Spaces the at the end continued of with the space record the record a character When the end of a is next is ignored record. followed they except are when record occurs and the That character 1is, immediately by it in a the the last first record. beginning of a record are ignored unless they are part of a character constant continued from a previous record. When spaces are part of a continued character constant, they are considered part of that Input constant. constants can be any of real, logical, complex, determines the data type external to A numeric a If internal list and of the following character. its wvalue the element constant rules Each input satisfy for its do can correspond not match, arithmetic only to conversion assignment (see If a slash a separator numeric to a and is Table statement reads whatever number of I1/0 list. types: constant, the record An example of is the performed according of list-directed READ to 3-1). records occurs, or ignored. use and character constant. 1its corresponding is if is exhausted before all the values.in a record are used, of integer, type of a constant translation from form. character list element can correspond only the data types of a numeric 1list element numeric data The data and the statements required the to I/0 list the remainder follows. INPUT/OUTPUT A program unit consists CHARACTER*14 the 4 Upon to (1,*) record (3.4,4.2), execution the T I,R,D,E,L,M,J,K,S,T,C,A,B external 6.3 I/0 following: L,M LOGICAL And the C DOUBLE PRECISION COMPLEX D,E READ of STATEMENTS of list to (3, the be read 2) , program contains: T7,F,,3*%14.6 unit, the ,'ABC,DEF/GHI''JK"'/ following values are assigned elements: I/0 List Element Value QR NRIrmOoH 4 A, B, and 6.3 (3.4,4.2) (3.0,2.0) . TRUE. .FALSE. 14 14.6 14.6D0 ABC,DEF/GHI'JK J are 7.4.1.3 The unformatted accessed fields Unformatted Sequential sequential READ statement under of unchanged. the sequential or binary data contained keyed READ reads an mode in that of Statement - The external record access. record It assigns to the elements the in the I/0 list, in the order, from left to right, in which those elements appear in the list. The data is not translated. The amount of data assigned The If to each unformatted the element is sequential I/0 list does there are more values not determined READ statement use in the all the If a statement execution of contains no the a file READ element's data reads in exactly a record than elements I/0 list, to the values remainder of the record is discarded. is greater than the number of values in positioning by read statement. the it record in examples of the use of the follow. READ (UNIT=1) FIELD1l, FIELD2 one -- the record. that is, if 1list -- the If the number of list elements the record, an error occurs. skips over succeeding one unformatted full record The unformatted sequential READ statement can only created by unformatted sequential WRITE statements. Some type. sequential record, on the next read READ records statement INPUT/OUTPUT STATEMENTS In this example, the READ statement reads one record from logical unit 1 and assigns values of binary data to variables FIELD1l and FIELD2, 1n the order indicated. READ (8) In this example, record. 7.4.2. The the READ statement advances logical wunit 8 one Direct Access READ Statements Direct access READ statements transfer input data to internal from external records accessed under the direct mode of access. formatted and unformatted. are two classes: storage There The two classes of direct access READ statement have the forms: Formatted READ( Direct Access extu, rec, READ Statements fmt {[,err])[list] Unformatted Direct Access READ Statements READ( extu, rec [,err])[list] extu A logical unit specifier. See Section 7.2.1l.1. rec A record specifier. See Section 7.2,1.4. A format specifier. See Section 7.2.1.3. fmt err A transfer-of-control specifier. See Section 7.2.1.6. list An Refer the I/0 to list. Section above ©See 7.3 Section for the 7.2.2. syntactical rules that govern the use of parameters. 7.4.2.1 The Formatted Direct Access READ Statement - The direct access READ statement does the following: e Reads character data from one or more accessed under the direct mode of access external e Translates form the data from character to binary formatted using records format specifications to provide editing e Assigns the translated in the order, from appear in the list data to the elements in the I/0 1list, 1left to right, in which those elements INPUT/OUTPUT If the I/0 record, the list the formatting record, the An example follows: 10 In this formatting of require remaining the more of formatted REC=35, the binary form, and of and in assign the read FMT=10) 35 then locations the READ record are direct (NUM(K), in data the order, the list. each contained from The data element is in left of record right, is not I/0 access READ in list contained values the to by the in which translated. determined the 1in a and the statement K=1,10) translated elements this to characters if FORMAT statements read the first ten 1logical wunit 2, translate the values to the ten as array 7.4.2.2 The Unformatted Direct Access unformatted direct access READ statement accessed under the direct mode of access and binary the than (2, from all discarded; spaces. READ example, use is characters use (10I2) not are the FORMAT do record fields of fields storage and remainder STATEMENTS that to READ reads an internal Statement - The external record the fields of assigns elements those the NUM. in the elements I/0 list, appear in The amount of data assigned to element's data type. The unformatted direct access READ statement reads exactly one record. If this record contains more fields than there are elements in the I/0 list of the statement, the unused fields are discarded; if there are more elements Examples follow. of READ than the fields, use (1'10) of error occurs. wunformatted LIST(l), In this example, the and assigns binary an direct access READ statements LIST(8) READ statement reads record 10 integer values to elements 1 in logical unit 1 and 8 of the array LIST. READ (4, REC=58, ERR=500) (RHO(N), N=1,5) In this example, the READ statement reads record 58 in logical and assigns binary values to 5 elements of the array RHO. 7.4.3 The from are A The Indexed indexed READ external two series sequence of statement transfers accessed formatted records by using in a an two classes Formatted READ( of indexed extu, READ fmt, input data to the keyed mode internal of access. storage There unformatted. sequential indexed Indexed under and indexed READ statement. The using the indexed statement, The 4 READ Statements records classes: unit file may READ be read statement in in key-of-reference conjunction with an first record in the sequence 1is found the rest using sequential statements. READ statement have the forms: Statement key [,keyid] [,err])([list] INPUT/OUTPUT STATEMENTS Unformatted Indexed READ Statement READ( extu, key [,keyid] [,erq])[list] extu A logical unit specifier. See Section 7.2.1.1. fmt A format specifier. See Section 7.2.1.3. key A key specifier. See A key-of-reference Section 7.2.1.5. keyid specifier. See Section 7.2.1.5 (2). err end Transfer-of-control specifiers. See Section 7.2.1.6. list An Refer the I/0 to 1list. Section above ©See Section 7.3 for the 7.2.2. syntactical rules that govern the use of parameters. 7.4.3.1 The Formatted Indexed READ Statement READ statement does the following: - The formatted 1indexed records ® Reads character data from one or more accessed under the keyed mode of access external e Translates binary form e Assigns elements in the data from character specifications to provide editing in the translated the order, values to to the from left to right, using the format I/O in which they appear list, in the list The formatted files. If indexed the I/0 READ statement 1list and additional records are additional records sequentially, to be may format only be used specifications read, the using statement on indexed specify that reads those the current key-of-reference value. If the KEYID unchanged If the the parameter from the most specified key wvalue appropriate the match referred key key value 1is field An example of an error the omitted, is matched until is then read. to, 1is recent the key-of-reference remains specification. shorter than against the a match is the found; If the key value key field referred to, 1leftmost characters of the the record is longer than the supplying key field occurs. use of the READ (3,KAT,KEY="'ABCD') formatted A,B,C,D indexed READ statement follows: INPUT/OUTPUT STATEMENTS In this example the READ statement retrieves a of 'ABCD' in the primary key, and then uses the array KAT to read the first four fields variables A,B,C, and D. 7.4.3.2 indexed keyed The Unformatted READ statement mode of access in that record left to right, in is not by Indexed READ Statement - The unformatted reads an external record accessed under the assigns the fields of to the elements in the I/0 which those elements appear translated. determined The can and the record with the wvalue the format contained in from the record into The amount of element's data data binary data list, in the in the list. assigned to contained order, The each from data element is type. unformatted indexed READ statement be used only on indexed files. If reads exactly the number of one record and I/O list elements is less than the number of fields in the record being read, the unused fields in the record are discarded. If the number of I/0 list elements is greater than the number of fields, an error occurs. If a specified key value is shorter than the key field -referred to, the key value 1is matched against the 1leftmost characters of the appropriate key field until a match is found; the record supplying the match is key referred field Some then examples of read. to, the 1If an use the specified error of key value is longer than the occurs. the wunformatted 1indexed READ statement follow. OPEN (UNIT=3, ACCESS='KEYED', 2 FORM='UNFORMATTED', 3 KEY=(1:5, READ In STATUS='OLD', 1 this (3,KEY='SMITH') example, logical unit 3 the and READ ORGANIZATION='INDEXED', 30:37, 18:23)) ALPHA,BETA statement retrieves the primary key field (bytes 1 to 5). retrieved are placed in variables READ reads record from with the the file value connected 'SMITH' The first two fields of the ALPHA and BETA, respectively. (3,KEYGE='XYZDEF',KEYID=2,ERR=99) value equal field the (bytes variable 7.4.4 The 18 to to or greater 23). The Internal DECODE The internal READ field of in the second that record input data to Appendix A may to the READ (intu, transfers is placed discussed internal statement 1in READ is internal key in be internal always formatted and has fmt{,errl([,end])[list] file specifier. used storage as statement. intu An having alternate READ Statement statement alternative first 'XYZDEF' record IKEY. The internal READ statement from an internal file. The than to the IKEY In this example, the READ statement retrieves the first record a in See 7-21 Section 7.2.1.2. the form: an INPUT/OUTPUT STATEMENTS fmt A format specifier. See Section 7.2.1.3. err end Transfer-of-control specifiers. See Section 7.2.1.6. list An Refer I/0 to 1list. Section the above The internal See 7.3 Section for READ statement does e Reads character data e¢ Translates e Assigns in the appear Refer to the the in Section internal The syntactical rules that govern the use of parameters. data specifications of the 7.2.2. to from an 1list 7.1.3 for internal from character editing data from the following: provide translated order, the 1left to the to information file to binary elements right, on the in form in using format I/0 1list, the which those characteristics elements and use files. following program segments demonstrate the use of internal file reads: CHARACTER*80 ACCEPT BUFFER BUFFER *, READ (BUFFER, This an segment integer reads and INTEGER '(I4.4)')1I the first assigns this four characters integer value to in the variable the variable BUFFER as I. IVAL CHARACTER TYPE, RECORD*80 CHARACTER*S5 AFMT, IFMT, OFMT, ZFMT PARAMETER (AFMT='(Q,A)', IFMT= '(Il10)', 1 ZFMT= ACCEPT AFMT, ILEN, TYPE= RECORD (1:1) IF (TYPE .EQ. READ (RECORD ELSEIF (TYPE READ ELSEIF 'D') '(0ll1)', RECORD THEN (2:MIN(ILEN, .EQ. (RECORD (TYPE READ OFMT= ' (Z8)"') 'O') (2:MIN(ILEN, .EQ. (RECORD 11)), IFMT)IVAL 12)), OFMT)IVAL THEN 'X') THEN (2:MIN(ILEN, 9)),ZFMT)IVAL ELSE - PRINT *, 'ERROR' ENDIF END This to program decimal, make segment determine octal, or appropriate binary. reads whether a the record hexadecimal. conversions and remaining It then examines data uses from character the first should be internal string character interpreted as file reads to representations to INPUT/OUTPUT STATEMENTS WRITE 7.5 THE WRITE STATEMENTS The WRITE statements records contained internal storage WRITE For statements statements statement 7.5.1 output data user-specified internal files. sequential, cannot that discussed The Sequential to to statements: WRITE transfer 1in write can in There direct to this Statements WRITE transfer statements records accessed three classes Formatted WRITE( of sequential Sequential extu,fmt WRITE( extu, Unformatted * WRITE [,err]) List-Directed WRITE in or categories and an refer of internal. indexed to to from file. the REWRITE output WRITE the data from internal sequential mode of storage access. WRITE statements: statement have the formatted, forms: Statements [list] Statements [,err]) Sequential WRITE( extu records function, under There are three classes of sequential list directed, and unformatted. The four indexed, storage units, 7.6. Sequential WRITE external internal logical are access, existing perform Section from external [list] WRITE [,err]) Statement [list] extu A logical A format unit specifier. See Section 7.2.1.1. fmt specifier. See Section 7.2.1.3. err A transfer-of-control list specifier. See Section 7.2.1.6. | An I/0 list., See Section Refer to Section 7.3 for the above parameters. the 7.2.2. syntactical rules ‘ 7-23 that govern the use of INPUT/OUTPUT STATEMENTS 7.5.1.1 The Formatted Sequential sequential WRITE statement does the ® Reads e specified Translates the data specifications e Writes under the the data to from from internal binary provide translated sequential WRITE Statement - The following: to storage character form Using an statement Because always appropriate can values mode numeric rounded format write to of format an external record than accessed access specification, more using editing The length of the records written to a wuser-specified (for example, a 1line printer) must not exceed the length that this device can process. In the case of a the maximum record length is usually 132 characters. WRITE formatted one a output device maximum record 1line printer, formatted sequential record. data transferred by formatted output statements is during its conversion from binary to character form, a loss of precision may result if this data is subsequently used as input., It is recommended, therefore, that whenever numeric output is to be used subsequently as 1input, unformatted output and input statements Some be examples used of for the data use transfer. of formatted sequential WRITE statements follow WRITE 650 (6,650) FORMAT (' HELLO THERE') In this example, the WRITE statement writes one record, consisting the contents of the character constant in the format statement, logical unit 6. 95 WRITE (1,95) FORMAT (3F8.5) In this example, fields AYE, BEE, 900 In this logical WRITE (1,900) FORMAT (F8.5) the unit each 1; statement writes three record consists of only one specified e Translates that data from data type of the elements e Writes the translated values under the sequential mode of consisting from The internal binary in the separate forms list-directed READ as Character of records the and constant ACCEPT constants 1list-directed WRITE storage to character form using the I/O list to provide editing to an access values external record transferred statements, are to field. transferred as output by the list-directed WRITE same exception: data Statement - Retrieves the record WRITE ¢ The values one DEE,EEE,EFF 7.5.1.2 The List-Directed WRITE statement does the following: have to AYE,BEE,CEE the WRITE statement writes and CEE to logical unit 1. example, of with transferred as the accessed statement input without by the following delimiting INPUT/OUTPUT apostrophes, apostrophe records but for each containing cannot a full Table and instead 7-3 below Data the e As list-directed shows the a is represented consequence character default 7-3: output List-Directed Type LOGICAL*1 LOGICAL*2 LOGICAL*4 IS L2 L2 INTEGER*2 INTEGER*4 17 I12 output REAL*4 1PG15.7 data formats for Formats Output Format 1PG25.16 1X,'(',1pPG14.7, ',', CHARACTER 1X, is the (where character n by only this can one exception, be printed Section each Output COMPLEX*8 An of (Refer to forms.) REAL*8 data 7.4.1.2 type. 1PGl4.7,')" the length of expression) following: List-directed output hexadecimal values, forms ¢ apostrophe two. be used for list-directed input. discussion on list-directed value Table Note internal of STATEMENTS of values. List-directed statements null output do values, removes not slash from a produce octal separators, complex value values, or repeated any embedded spaces. e Each output record e Each output statement e Each individual begins with a space for writes one or more output value 1is An example of the comma. the use DIMENSION of the complete contained record, with the exception of character one record length, and complex constants after carriage list-directed WRITE control. records. within a single constants longer than that can be split statement follows: A(4) DATA A/4*3.4/ WRITE (1,*) WRITE (1,*) In 'ARRAY A,4 this example, logical unit ARRAY VALUES FOLLOW' the WRITE statements write VALUES 3.400000 3.400000 7.5.1.3 The Unformatted Sequential WRITE internal storage mode of following records to FOLLOW 3.400000 unformatted the 1: WRITE access. statement transfers to an external The data are Statement - The specified record accessed under not translated. 7-25 3.400000 binary the 4 sequential data from sequential INPUT/OUTPUT STATEMENTS The sequential if there is Some examples follow. WRITE(1) In this I/0 list, of the the use of statement writes the unformatted one null sequential record; record. WRITE statement (LIST(K),K=1,5) example, containing array unformatted WRITE statement writes exactly one no the the WRITE values, in statement writes to logical unit 1 binary form, of elements 1 through a 5 record of the LIST. WRITE (4) In this unit 4. example, 7.5.2 The Direct access storage to There and are Direct WRITE statement Access WRITE WRITE statements external records two classes of writes one null record to logical Statements transfer accessed direct output under access the WRITE data direct from mode statements: internal of access. formatted unformatted. Using an direct The the two OPEN access statement classes Formatted WRITE( is one method of establishing attributes of a file. of direct Direct extu, Unformatted Access rec, Direct WRITE( extu, access WRITE fmt statement have the forms: Statements [,err])[list] Access rec WRITE WRITE Statements [,err])[list] extu A logical unit specifier. See Section 7.2.1.1. A record specifier. See Section 7.2.1.4. A format specifier. See Section 7.2.1.3. A transfer-of-control rec fmt err specifier. See Section 7.2.1.6. list An I/0 list. See Section Refer to Section 7.3 for the above parameters. the 7.2.2, syntactical rules that govern the use of INPUT/OUTPUT STATEMENTS 7.5.2.1 The Formatted Direct Access WRITE Statement direct access WRITE statement does the following: ® Retrieves e Translates those specifications to @ Writes the accessed If the values output with error occurs. from values provide the being space values translated under specified record filled binary data by the to I/0 characters. a mode list the If the form user-specified of The formatted storage to character editing direct written, internal - using format external record access and formatting unused portion of values overfill the do not the fill the record is record, an 7.5.2.2 The Unformatted Direct Access WRITE Statement - The unformatted direct access WRITE statement retrieves binary values from internal storage and writes those values to a user-specified external record accessed translated. If the under the direct mode of access. The values are values being If the specified by the I/0 list do not fill the output written, the unused portion of the record is filled with values do not fit in the record, an error occurs. 7.5.3 The The Indexed indexed storage WRITE to are two unformatted. indexed statement records classes WRITE of transfer accessed indexed statement discussed record zeros. Statements statements external There The WRITE 1in output under WRITE always Section data from keyed mode statements: writes 7.6 the a 1is new wused access. formatted record. to internal of update REWRITE an existing : Using an of indexed The only OPEN of in that refers two to form of one the sequential the to a is method of establishing WRITE statement indexed an classes WRITE( of unit extu, Unformatted WRITE Indexed whereas connected WRITE WRITE fmt statement; statement file, indexed Indexed indexed WRITE indexed logical Formatted to a is the two refers to the attributes sequential statement have the [,err])[list] Statements WRITE( extu [,err])[list] logical unit specifier. See Section a logical WRITE file. Statements WRITE identical statements sequential extu A the file. the connected The statement syntactical that and The record. an not 7.2.1.1. forms: to differ unit statement INPUT/OUTPUT STATEMENTS fmt A format specifier. See Section 7.2.1.3. err A transfer-of-control specifier. See Section 7.2.1.6. list An I/0 list. See Section 7.2.2. of Refer to Section 7.3 for the syntactical rules that govern the use the above parameters. 7.5.3.1 The Formatted Indexed WRITE Statement - The WRITE statement does the following: e e Retrieves binary values Translates from values those specifications to provide internal to under accessed the all because key necessary in using format external records storage character or keyed mode of access No key parameters are required indexed form editing Writes the translated data to one e formatted 1list the 1is information more of control parameters, contained in the output record. If the values specified by the I/0 list and formatting do not fill a fixed-length record being written, the unused portion of the record is filled with space characters. If additional contained ’ are these in each record. An example of the use of formatted (4,100) WRITE 100 records are specified, inserted in the file logically according to the key values FORMAT KEYVAL, indexed WRITE statement follows: (RDATA (I), I=1,20) (A1l0,20F15.7) values of In this example, the WRITE statement writes the translated the array RDATA to a new of elements 20 the of each and KEYVAL formatted record in the indexed file connected to logical unit 4. 7.5.3.2 indexed The Unformatted Indexed Statement - The WRITE unformatted WRITE statement retrieves binary values from internal storage and writes those values to an external record accessed under the keyed mode of access. The values are not translated. parameters control of contained in the output 1list the in No key parameters are required because all necessary key 1information 1is : record. If the values specified by the I/0 list do record zeros; not fill a fixed-length being written, the unused portion of the record is filled with L1f the values specified overfill the record, an error occurs., INPUT/OUTPUT 7.5.4 The The_Internal WRITE internal storage to You also can control The WRITE an use internal internal WRITE Statement statement internal the STATEMENTS transfers output data discussed in from internal file. ENCODE statement Appendix A to output. WRITE (intu, statement is always formatted and has the form: fmt{,err])[list] intu An internal file specifier. See Section 7.2.1.2. fmt A format specifier. See A transfer-of-control Section 7.2.1.3. err specifier. See Section 7.2.1.6. list An I/0 list. See Section Refer to Section 7.3 for above parameters. the 7.2.2. syntactical rules that govern the use of the The internal e Retrieves e Translates @ Refer of The WRITE statement data from this does the internal data from specifications to Writes the values to Section internal 7.1.3 for storage binary format translated following: provide to information to character form wusing editing an on internal the file characteristics and use files. following example demonstrates the wuse of the internal WRITE statement: CHARACTER*80 ACCEPT BUFFER *,1I WRITE (BUFFER,"'(I4.4)')I ! Start buffer with 4 digits from input END REWRITE 7.6 THE REWRITE STATEMENT The REWRITE statement transfers output data the current REWRITE record statement: in an indexed indexed. file. from There is internal only one storage to category of INPUT/OUTPUT 7.6.1 The The Indexed indexed storage to REWRITE the statement. formatted The OPEN REWRITE There and Statement statement last record are STATEMENTS transfers in two an output indexed <classes file of data to be indexed from REWRITE two classes Formatted of is used to indexed Indexed REWRITE( Unformatted establish where extu, WRITE statements fmt, REWRITE REWRITE extu,fmt Indexed REWRITE( extu 7.6.1.1 the attributes statement have the [,err]) REWRITE of an _ err, and list discussed syntactical in forms: [list] Statement are defined Section as 7.5.3. they are Refer to for the Section indexed 7.3 for rules. Retrieves binary e Translates specifiers to Writes translated the indexed [,err])[list] e e READ Statement The Formatted 1Indexed REWRITE Statement REWRITE statement does the following: indexed a unformatted. statement applicable by statements: file. The internal accessed values those from values provide internal to - The formatted storage character form using format in indexed editing data to an existing record an file The record written to is the the last record to be accessed READ statement. Changing the primary current key value by record a in the preceding results in an file indexed error, and rewrite more than one record causes an error. Any rewritten fixed-length record is filled with spaces; too long, an An example error of -or that is, sequential attempting to unused space in a if the record is occurs. the wuse of a formatted indexed REWRITE statement follows: REWRITE (3, In 10 FORMAT this example, the contained in the values represented 7.6.1.2 The indexed REWRITE storage file. and The 10, (Al6, REWRITE values are not AGE, statement BIRTH updates file connected AGE, and BIRTH. Indexed statement those NAME, A8) 1indexed by NAME, Unformatted writes ERR=99) I2, REWRITE retrieves values to an record written to is the the 1last record to be accessed current READ statement. by current unit Statement - The record a the logical binary existing translated. The to values record in preceding the 3 in file the unformatted from indexed record with internal an -or indexed that is, sequential INPUT/OUTPUT STATEMENTS Changing in a record the primary key value results in an error. Any unused rewritten, fixed-length record 1is filled with zeros; is too long, an error space 1if the occurs. ACCEPT 7.7 THE ACCEPT The ACCEPT external ACCEPT STATEMENT statement records transfers accessed statements can only units. The ACCEPT statement ACCEPT f[,list] ACCEPT *[,list] The nonkeyword has input under be the the used data to internal sequential on mode implicitly of storage from access. connected logical forms: form of a format spécifier. See Section 7.2.1.3. * Specifies list-directed formatting. list An The I/0 ACCEPT READ list. statement statement important example of functions The logical the use CHARACTER 200 Section discussed exception: user-specified An See 7.2.2. exactly in as Section ACCEPT the formatted sequential 7.4.1.1, with following statement can never be the connected units. of *10 ACCEPT 200, FORMAT (5A10) the formatted ACCEPT statement to follows: CHARAR(5) CHARAR In this example, the ACCEPT implicit wunit and assigns of the array CHARAR. statement reads character data from the binary values to each of the five elements TYPE PRINT 7.8 THE TYPE The TYPE and PRINT to external storage access, AND PRINT STATEMENTS statements records transfer output accessed under data the from sequential internal mode of INPUT/OUTPUT STATEMENTS TYPE and PRINT statements have the forms: TYPE f£[,list] f PRINT TYPE * PRINT * [,list] [, [, list] list] The nonkeyword form of a Specifies list-directed format specifier. See Section 7.2.1.3. formatting. list An I/0 list. See Section 7.2.2. TYPE and PRINT statements function exactly as the formatted sequential with the following Section 7.5.1.1, 1in WRITE statement discussed PRINT and TYPE sequential formatted The exception: important data to user-specified transfer to used can never be statements logical units. An example of the use a of formatted sequential PRINT statement follows: CHARACTER*16 NAME, 400 PRINT 400, NAME, FORMAT ('NAME=', JOB JOB A, 'JOB=', A) In this example, the PRINT statement writes one record to the implicit output device; the record consists of four fields of character data. CHAPTER STATEMENTS FORMAT FORMAT statements statements format in which conversion and Throughout this and a "internal data are (and field data the ENCODE is to be editing chapter form." of nonexecutable with a a transferred, FORMAT statements have to distinction a form" record; data the used with DECODE statements) required formatted representation of statements and "External binary 8 and to achieve is made refers the the kind of format. between "internal I/O the specify this to formatted to describe "external ASCII form" form" characters refers to in the value. form: FORMAT (qlflslf2s2 ... fnqgn) Zero more slash (/) record edit descriptor, q or terminators. f A field or descriptors enclosed in or a group of field or edit parentheses. s A field separator. The entire list of field and edit descriptors, field separators, and record terminators, including the enclosing parentheses (which must be present), is called the format specification. The field separators are record terminator. the field separators. The field and edit the comma Section 8.5 descriptors and have [r]lc[w[.d[Ee]]] [rlcw.m The the the slash. describes the in The detail slash the is also functions a of forms: r number repeated of times field (repeat count). If or edit you omit r, descriptor it 1is is assumed to to be be 1. c A field L, A, H, or X, edit T, descriptor P, Q, $, BN, code (S, SpP, SS, BZ, TL, or TR). 1, O, 2, F, E, D, G, FORMAT STATEMENTS w The external The number field width, in characters. -4 of characters to the right of an exponent the decimal point. E In this context, identifies field. e The number of The minimum characters in the exponent. m field The terms r, w, m, d, nonzero. w, You d, The some field are or not r in term which characters is allowed to be or always and use that must appear within the zeros). it can be descriptors are unsigned equal to an used. The d invalid parameter integer constants; and r and w must 255, optional and element e in others. constants for in terms are the terms r, be those required r, w, m, e. field and edit descriptors e Integer field -- Iw, ® Logical field -- Lw e Real, Gw.d, @ Character Q, e Section S, field : Character 8.1 first data Ow, -- Aw (where n and 1is Hollerith field character an in information transfers, the Zw, and describes each carriage-control During are: double-precision, Ew.dEe, Gw.dEe positions) The of leading m, and d must all must be less than and e The descriptors in number (including Iw.m, complex a number constant and format Zw.m field of field -- Section Fw.d, Ew.d, characters or -- nH, edit descriptor output (see Ow.m, record Dw.d, character '...' in detail. generally contains 8.3). specification is scanned from left to right and the elements in the I/O list are correlated one-for-one with corresponding field descriptors in the specification, except in the case of edit descriptors and character- and Hollerith-constant field descriptors, which do not require corresponding I/0 1list elements. Section 8.7 specifiers and describes the in I/0 list. detail the interaction between format You use an logical I, O, Z, data. FORMAT STATEMENTS L field descriptor use an or You F, process real, double-precision, You use an O, You can create the A, FORMAT FORMAT or a Z field format and Section You can A FIELD AND field items. EDIT descriptor (Data to O, a to process or process format a field integer and descriptor to character program summarizes of Z data. before 8.8 create G, complex descriptor by using a run-time format instead describes run-time formats. 8.1 D, specification statement. statements. E, the during FORMAT data. execution rules for program statement. with writing execution Section 8.6 DESCRIPTORS describes items in the size and external medium an format of are called a data external item or fields.) An edit descriptor specifies an editing function to be performed on a data item or items. (Some edit descriptors, such as the Scale Factor perform control functions descriptors P, actually for sake simplicity.) The field numeric field; the the BN the they edit is in effect ignored. At descriptors however, unless ignore treat but are leading embedded included spaces and in trailing the of the execution of each formatted OPEN statement has has been input statement, and edit BZ been executed, executed. During the interpretation descriptors -- that superseded by either of these. only the formatted I/O statement is, 8.1.1 The and has BN Edit the input editing, repeat BLANK= of spaces the default may edit external as zeros = 'NULL' spaces are statement, interpretation 'NULL' when 'ZERO' execution The BN and BZ of which they The field and edit descriptors are 8.1.1 through 8.1.23. Sections complex-data respectively. and the the spaces is in effect, or unless BLANK 1logical wunit, in which case all the BLANK attribute for the wunit determines the spaces; the PDP-11 FORTRAN-77 defaults are BLANK = statement among descriptor for beginning of of be when a no of an OPEN formatted controlled interpretation edit descriptors are a part. by may BN be affect described 1in detail 1in Sections 8.1.24, 8.1.25, and 8.1.26 discuss counts, and default descriptors, Descriptor BN edit descriptor trailing blanks the form: causes to it the processor encounters within a ignore numeric all the embedded input field. It BN The effect is right-justifying treated as zero. G editing, and that of actually removing the the remainder of the field. A field of The only BN upon descriptor the affects execution 8-3 of an only I, input O, Z, blanks and all blanks is F, statement. E, D, and STATEMENTS FORMAT The BZ and Edit Descriptor BZ 8.1.2 edit descriptor trailing zeros. It causes blanks has the it the processor encounters form: to treat all within a numeric the embedded input field as BZ The BZ only 8.1.3 The descriptor upon SP SP affects the execution of Edit Descriptor edit descriptor character in optional. It any has only I, an input causes position the O, 2, F, E, D, and G statement. the where editing, and : processor to this character produce a plus would otherwise be form: SP The SP upon descriptor the 8.1.4 SS The edit SS Edit character produced SP field affects execution of an I, F, E, D, and G editing, and only statement. Descriptor descriptor causes from any an optional as only output the position processor where character; descriptor described above. to suppress this character 1t has The the a leading would opposite SS descriptor plus normally be effect has the of the form: SS The SS upon descriptor execution 8.1.5 S Edit affects of an only output I, F, E, D, and G editing, and only statement. Descriptor The S edit descriptor numeric output fields. reinvokes It has the optional form: plus characters (+) in S The S descriptor by restoring plus The characters same 8.1.6 I counters to on action of processor the an optional basis. apply for restrictions Field the the as either the decision-making the SP and SS SP or SS descriptor ability to produce descriptors. Descriptor The I field descriptor specifies decimal integer values. It has the form: Iw[ .m] The corresponding logical data type. I/0 list element must be of either integer or FORMAT Rules in Effect The I for field read from value, and The Data descriptor external If external the If the If a value that w characters field, interpreted as the corresponding I/0 decimal corresponding minus specifies data value contain the Input an external assigned to cannot STATEMENTS must be point or exceeds list an an integer exponent the maximum element, an error first nonblank character of the sign, the the field is first nonblank appears 1in the treated character field, the as a is a to be constant; it field. allowed magnitude of occurs. external negative field value. plus sign, 1is treated field are a decimal integer list element. or if as a 1is no a sign positive value. An Input all-blank field is treated as a value of 0. Examples Format External Internal 2788 2788 I3 -26 -26 312 312 in : Effect for Data Output The I field descriptor specifies that corresponding I/O 1list element 1is to decimal wvalue, right Jjustified, to an characters If m is present, if the digits total the filled If the have external to exceeds asterisks. value of minus the signs value of the be transferred as a external field w the are the list sign term field 2zeros consists are added on of at the left least to w field element as is width, 1its large suppressed, is the entire negative, 1leftmost, the field field nonblank enough, unless SP is Internal Value External specified. Representation I3 284 284 I4 -284 -284 I5 174 12 3244 I3 17 14.2 -473 29,812 1 I4.4 1 174 *x Not *k* permitted: 01 0001 error |is will character, Examples Format m bring m. with provided Plus the necessary, value a the long. digits; If Output Value I4 19 Rules Field FORMAT O Field 8.1.7 The O field STATEMENTS Descriptor descriptor specifies octal integer wvalues. It form: has the Ow(.m] The corresponding Rules in Effect The O read and I/0 list for Data element descriptor from an specifies external to the An all-blank field If the of Input value any data is the corresponding field, type. that w characters interpreted corresponding The external field can it cannot contain a field. the be Input field assigned can I/0 list as are to an octal element. be value, contain only the numerals 0 through 7; sign, a decimal point, or an exponent treated external list as a data element, value of exceeds an error 0, the allowed size of of the occurs. Examples Internal Format Rules External Field Decimal value 05 77777 32767 04 06 31274 15 1623 53248 03 97 in ¢ Effect The O for Not Data field permitted: Output descriptor specifies that corresponding I/0 1list element octal integer, right Jjustified, characters e No e signs 1is to the octal value to be transferred as an external field an w long. are output; a negative octal (two's complement) If value does the error not value is transmitted in |its spaces are form. fill the field, 1leading inserted. e If the filled e If m is value exceeds with asterisks. field present, digits; the total Output the width, the external field if necessary, zeros are digits to m. the consists added on entire of the field at left least m to bring Examples ‘ Format Internal External (Decimal) Value (Octal) Representation 06 32767 77777 06 -32767 100001 02 04 Oll 04.2 04.4 14261 27 bl 33 13.52 7 7 12173041130 07 0007 8-6 1is FORMAT 8.1.8 The the Z Field Z field form: STATEMENTS Descriptor descriptor specifies hexadecimal (base 16) values. It has Zw( .m] The Z fleld element Rules of in @ descriptor can any data type. Effect for Data The Z field read from value, and o The and a e e sign, field A decimal An all-blank field If the of value correpsonding Input with a corresponding I/0 1list Input letters a used descriptor specifies that w characters are to be an external field, interpreted as a hexadecimal assigned to the corresponding I/0 list element. external the be can contain only the (or a) through F (or point, or an exponent is the list treated external element, as a f£); it field. value field an numerals of exceeds error 0 through cannot 9 contain zero. the range of the occurs. Examples Format External Z3 Z5 Z5 Rules in Internal Hexadecimal Vvalue Field A94 A23DEF A94 A23DE 95.AF2 Effect for ¢ The e No ® A negative Data Not are e If the value If m is digits; Output Examples Format is transferred does not 1in if with £ill the 1its external the value asterisks. exceeds present, the external field 1if necessary, the field is Internal Z4 (Decimal) Vvalue 32767 zZ5 zZ2 Z4 Z3.3 Z6.4 Note that if m external field that the value of the element is to .be transferred as a justified, to an external field w hexadecimal (two's form. are Inserted; field is filled e specifies output. value complement) error Output Z field descriptor corresponding I/0 1list hexadecimal value, right characters long. signs permitted: is zero, is blank field, the leading field, spaces entire consists of at 1least zero filled on the left. External m Representation 7FFF -32767 16 8001 10 -10.5 2708 2708 c228 A94 0A94 and the filled. the internal 8-17 representation is zero, the FORMAT STATEMENTS F Field Descriptor 8.1.9 The F has the field descriptor specifies real or double-precision values. It form: Fw.d The corresponding type, data complex data Rules in or element must be either the real F read for Data field descriptor from an list Any element. present is in part the of and decimal the for real double-precision evaluate the position the minus If the is first sign, the first appears in to point, field are the be or corresponding signs, included or in exponent the 1I/0 field w count, and point 1is placed before the w. include constant constant number's determined. nonblank an exponent exponents magnitude is nonblank of character the the before the treated as field, field and exponents), character the field the a decimal point, the position of 1If the w characters do not include decimal digits of w characters 2.3.2 If double-precision imaginary part of a w. point, rightmost 4 assigned decimal external If the w characters include the decimal point is used. If or the specifies that w characters are to external field, interpreted as a real value, a real or Input double-precision d of type. Effect The I/0 list it must be is a a (see Section exponent the is Section 2.3.3 decimal external for used field to point 1is a negative value. plus field 1is sign, or if treated as a no sign positive value. An The Input all-blank is treated term w must be greater as a value of 0. than or equal to d+l. Examples Format Rules field External Field Internal Value F8.5 123456789 F8.5 -1234.567 -1234.56 F8.5 24.77E+2 2477.0 F5.2 1234567.89 in Effect The Output of the real and the field Data 123.45 corresponding 1I/0 list element is to be transferred as a or double-precision value, rounded to d decimal positions right justified, to an external field w characters long. If F for 123.45678 value descriptor does not specifies fill the that field, the value 1leading spaces are inserted. If the filled value exceeds with asterisks. the field Plus signs are suppressed, width, unless SP is the entire specified. field |1is FORMAT e¢ STATEMENTS The term w must be greater than or equal field width should be large enough to digits after the decimal point, plus the number of digits to plus Output 1 for a possible Internal F8.5 1 the left sign. External however, the of the decimal point, 8789.736 51.44 F10.4 Field field kkkkk -2 -0.20 Descriptor descriptor exponential -23.2435 325.013 F5.2 E ** -23.24352 F5,.2 Representation 2,35472 8789.7361 F2.1 8.1.10 Value 2.3547188 F9.3 E d+l; Examples Format The negative plus to contain the number of for the decimal point, form. It specifies has the real or double-precision values in form: Ew.d[Ee] The corresponding data type, complex data Rules On in or must element must be either the real be of real or the or double-precision imaginary part of a F field type. Effect input, I/O list it the E for Input field descriptor does not differ from the descriptor. Input Examples Format External E9.3 Internal 734.432E3 El2.4 In Field Value 0.734432E+6 1022.43E-6 0.102243E-2 E15.3 52.3759663 0.523759E+2 El2.5 210.5271D+10 0.2105271E+13 the last exponent single Rules note Effect The E for or field If are If I/0 list digits characters the E E field descriptor indicator if the I/0 treats list the D element is specifies element value and in right is that to be exponential justified, the wvalue transferred form, to as rounded an external characters, 1leading of the a real to d field w long. value does not fill the w spaces inserted. the filled @ the an descriptor double-precision decimal e as Output corresponding e that indicator precision. in e example, field value exceeds with asterisks. the w characters, Output is in a standard form; that is, the optional wvalue 1is negative, an the entire field 1is it has a minus sign if 0, a decimal point, d FORMAT STATEMENTS digits to exponent the right of the decimal point, and an e+2 character forms: in one of the E+nn Ew.d (for exponent < 99) E-nn E+n(l)n(2)...n(e) Ew.dEe E-n(1)n(2)...n(e) n A digit e The exponent omitted, is too of an integer. field width specification is optional; the value of e defaults to 2. large to be output digits to the 1if it |is If the exponent value in one of the above right of the decimal forms, an error occurs, e The d entire value, e scaled Plus signs are e to a decimal suppressed, point unless SP is greater than or the specified. The term w must be large enough to include: necessary (plus point; d digits; represent fraction. a minus sign when signs are optional); a zero; a decimal and an exponent. Therefore, w must be equal to d+7, or to d+e+5 if e is present. Examples Output Format Internal Value El12.5 E12.3 E10.3 475867.222 0.00069 -0.5555 ES5.3 0.47587E+06 0.690E-03 -0.556E+00 56.12 E14,5E4 *hkhk -1.001 0.10010E+0001 0123E-000003 0.000123 E14.3E6 D Field Representation 0.48E+06 475867.222 E9.2 8.1.11 External Descriptor The D field descriptor specifies with a D instead of an E real double-precision values in exponential form. It has the form: or Dw.d The corresponding I/0 list element must be of real or double-precision data type, or it must be either the real or the imaginary part of a complex Rules in data type. Effect for : Input On input, the D field descriptor does not differ from the F or E field descriptors. Input Examples Format External D10.2 12345 D15.3 367.4981763D-04 D10.2 Field Internal Value 0.1234500000D+8 123.45 8-10 0.1234500000D+3 0.3674981763D~1 FORMAT Rules in Effect There is only one difference output: If of the letter you E. use Output for Output the Internal 0.0363 D23,.12 5413.87625793 8.1.12 D the and letter E descriptors D is G External output on instead Field field Value 0.363D-01 0.541387625793D+04 1.2 combining being the Value D14.3 D9.6 G between D descriptor, Examples Format The STATEMENTS khkkkkhkkhk Descriptor descriptor E- or output. It specifies F-type real formats has the I/0 list or double-precision according to the size of values, the number form: Gw.d[Ee] The corresponding data type, complex Rules in or data in ¢ Effect for G G for @ of real or or the double-precision imaginary part of a does not differ from the F, field descriptor I/0 list rounded external specifies element value in to d decimal field is that to either be the exponential positions and w characters value transferred 8-1: Data 0.1 or or D <m¢< 1.0 1.0 < m < \. 10.0 Effective Format F(w-4).d4, ' F(w-4).(d-1), ' ' ! ) F(w-4).1, ' ' 10d-1 F(w-4).0, ' ! m < 10d m > 10d the a real fixed-point Formats 10d-2 < m < 104-1 < of to long. Effect of Data Magnitude on G Magnitude as right justified, The form in which the value is written is a function magnitude of the value, as described in Table 8-1. Table E, Output double-precision form, an real descriptor corresponding or be the Input field Effect The must either type. On input, the descriptors. Rules element it must be Ew.d [Ee] of the FORMAT Note: The four spaces ' ' in the second column of to follow the numeric data are e Plus e The STATEMENTS signs term are 8-1 specifies. that minus when representation. suppressed. w must necessary Table be (plus large signs enough to include: a sign are optional); a decimal point; d digits to the right of the decimal point; and either a 4-character or an (e+2)-character exponent. Therefore, w must be greater than or equal to d+7 or d+S+e. Output Examples Format Internal Gl3.6 Gl3.6 Gl13.6 Gl13.6 the above values examples output with an 12,3457 123.457 with the -1234.57 12345.7 123457. -0.123457E+07 following equivalent Internal F13.6 F13.6 F field Value examples, which descriptor. External 0.01234567 0.012346 -0.123457 F13.6 F13.6 Fl13.6 12.34567890 123.45678901 F13.6 12.345679 123.456789 -1234.56789012 -1234.567890 F13.6 F13.6 12345.67890123 12345.678901 123456.78901234 123456.789012 F13.6 -1234567.89012345 khkhhhhkhhhhkh L Field field show the Representation -0.12345678 1.23456789 8.1.13 L 12.34567890 123456.78901234 -1234567.89012345 Format The 0.123457E-01 -0.123457 1.23457 12345.67890123 Gl3.6 Representation -0.12345678 1.23456789 123.45678901 -1234.56789012 Gl3.6 Gl3.6 same External 0.01234567 Gl3.6 Gl3.6 Compare Value 1.234568 Descriptor descriptor specifies logical data. It has the form: Lw The corresponding I/0 list logical data type. Rules in ¢ Effect The L read e If for field from the element be of either integer or are to be is the letter assigned to T, the Input descriptor the first t, .T, or corresponding external nonblank specifies character .t, the wvalue I/0 list element. e If the first nonblank £, .F, or .f, or .FALSE., 1s assigned. e Any other value in the that w characters field. of the .TRUE. field is character of the field is the letter F, 1if the entire field is blank, the value external field produces an error. FORMAT Rules in ¢ Effect for The L the the wvalue letter Output field element descriptor letter Output specifies of the corresponding F (if the wvalue of 1is .FALSE.) w characters @ STATEMENTS 1is to be that either the letter I/0 list element is the corresponding transferred to an T (if .TRUE.) or I/0 1list external field long. T or F preceded by w-1 is in the rightmost position of the field, spaces. Examples Format Internal L5 . TRUE. Ll .FALSE. 8.1.14 A Field The A has the Value field External Representation T F Descriptor descriptor specifies character or Hollerith values. It form: Alw] The I/O list element variables corresponding of any data type can The of w must value Rules in e Effect The for A be less than can be of used to store or equal descriptor record and e to data type, Hollerith because data. 255. transfers assigns them element. e any Input field external be to w the characters from the corresponding I/0 list ' The maximum number the size of the The size of a of I/0 characters list character that can be stored depends on element. I/0 list element is the length of the character variable, character substring reference, or character array element that makes up the element. The size of a numeric I/0 list element depends on the data type of the element, as follows: I/0 List Maximum Number Element of Characters BYTE 1l LOGICAL*1 LOGICAL*2 1 2 LOGICAL*4 INTEGER*2 INTEGER*4 2 4 REAL 4 REAL*8 DOUBLE PRECISION 4 8 8 COMPLEX 8 CHARACTER*n n FORMAT e STATEMENTS If w is greater than the maximum number of characters that can be stored 1in the corresponding I/0 list element, rightmost characters are assigned to the element. excess e characters If w is less than are ignored. the number of characters that w characters are assigned to the list element, and trailing spaces are added to fill can only the Leftmost be stored, left justified, the element. Examples Input Format External Field A6 A6 A6 A6 A6 A6 A6 A6 PAGE PAGE PAGE PAGE PAGE PAGE PAGE PAGE in Effect Rules Internal Vvalue # # # # # # # # # E # PAGE # PAGE # # # GE # PAGE # (CHARACTER*1) (CHARACTER*3) (CHARACTER*6) (CHARACTER*S8) (LOGICAL*1) (INTEGER*2) (REAL) (DOUBLE PRECISION) Output for e The A field descriptor specifies corresponding I/0 1list element external field w characters long. e If w is greater than the size of the list element, appears in the field, right justified, with leading e If w is less than the leftmost w characters Output that the are to be size of the 1list are transferred. contents of the transferred to an element, the data spaces. only the Examples Format Internal Value External Representation AS OHMS OHMS A5 VOLTS VOLTS A5 AMPERES AMPER If you omit w in an A field descriptor, a default value 1is supplied. If the 1I/0.list element is of character data type, the default value is the length of the I/0 list element, If the I/O list element is of numeric data type, the default value 1is the maximum number of characters 8.1.15 The that can be an descriptor An external itself. nHclc2c3 The in a variable of that data type. H Field Descriptor H field descriptor between stored ... number ASCII of specifies record It has the that data 1is form (of a Hollerith €N characters character. to be transferred and the storage location of the H field to be transferred. constant): FORMAT Rule Rule An in Effect for ¢ The in Effect ¢ The H the letter STATEMENTS Input H field descriptor specifies that n characters be accepted from an external field and assigned to the same storage location as the characters of the H descriptor. The characters of the H descriptor are overlaid by the input data, character for character. example for Output field of H descriptor H be field-descriptor 100 TYPE 100 FORMAT (41H ACCEPT 200 200 FORMAT The TYPE descriptor ENTER (20H TITLE statement accepts the H the GOES response field to can Both In a For use types a TITLE, HERE format from descriptor character specifier constant, the UP TO in characters following field. 20 CHARACTERS) ) the characters to the user's character constant of n external follows. the keyboard statement replace the words TITLE GOES HERE. If characters, the remainder of the H spaces to the right. You that the usage PROGRAM statement transfers in statement 100 data in specifies transferred from the H terminal. The and 200. places The the field ACCEPT input new characters the user enters fewer than 20 field descriptor is filled with instead function apostrophe of an H field descriptor. identically. is written as two apostrophes. example: 50 FORMAT A pair of character. 8.1.16 ('TODAY''S apostrophes used DATE IS: ',12,'/',12,'/',12) 1in this way 1s considered a single X Edit Descriptor The X edit be skipped. descriptor It has specifies the that a number of form: character positions : nX The term The n specifies the number of character positions to be skipped. value of n must be greater than or equal to 1, and less than or equal Rule Rule to 255. in Effect for Input e The the in Effect ¢ The X edit descriptor tabs right n over anything already written. statement in: X edit descriptor specifies that input record are to be skipped. for next n characters |{n Output WRITE 90 the FORMAT (6,90) spaces; it does not For example, the write WRITE NPAGE (l3HlPAGE NUMBER ,I2, 16X 23HGRAPHIC ANALYSIS, 8-15 CONT.) FORMAT prints a record similar PAGE NUMBER to STATEMENTS the following: nn GRAPHIC where nn is the current value of the variable NPAGE. numeral 1 1in the first H field to advance the printer paper describes T is not Note printed to the top of a new page. specifies the position, carriage control.) CONT. that but the is used (Section 8.3 T Edit Descriptor 8.1.17 The printer descriptor ANALYSIS, edit descriptor an external record, form: of the next character relative to be to the processed. start It has of the Tn where the next character or equal in the Rule term to n 1, indicates to be position but not greater for Input in the external The value of than the number of the n must be greater than of record characters allowed record. in Effect e In an input data statement, starting transferred with as the T the input. field nth For descriptor character example, the specify that position 7 in the followed position by 1. a 3-character for a 3-character string external starting record string 1is be starting at e In an output statement, the T field descriptor data output is to begin at the nth character external 8.1.18 TL TL edit to the left. record. For "COLUMN 1" at remainder of the Edit The to be first, character example, 20 and contains that position of the statements 2',T20,'COLUMN position line the specifies COLUMN blank 1°') 2" at position 50. characters. Descriptor descriptor It character read Output PRINT 25 FORMAT (T50,'COLUMN 25 at to Effect print that 1is statements in The specifies position READ (5,10) J,K FORMAT (T7,A3,T1,A3) 10 Rule the processed. has is a relative the form: that the tabulation specifier for tabbing TLn The term n specifies to a record The value of n must is be greater greater than or equal character in next is the nth character the record is to character to be transferred from or the left of the current character. than or equal to 1. If the value to the current character position, specified. the of n first FORMAT 8.1.19 The TR to the TR Edit edit Descriptor descriptor right. STATEMENTS It has is a the relative tabulation specifier for tabbing form: TRn The term to a n indicates record character. Q the The that the value the nth of n next character character must be to to the greater than be transferred right or of equal the to from or current 1. Q Edit Descriptor 8.1.20 The 1is edit descriptor characters assigned to a specifies themselves) corresponding that remaining variable the count of the characters in a record being in an I/0 list. It (not read are to be has the form: 1logical data Q A corresponding I/0 list element must be of integer or type. For example, the READ two fields characters exactly this In an output to cause 8.1.21 a XRAY,KK,NCHRS, (ICHR(I),I=1,NCHRS) (E15.7,I14,Q,80Al) into the remaining number placing the specification, statements (4,1000) FORMAT 1000 read input of variables in the characters is and KK. The 1is then stored read into the count specification, the I/0 Q edit descriptor list element to be of in NCHRS, array Q descriptor in the first position you can determine the actual length of an corresponding Dollar XRAY record ICHR. in a input the and By format record. has no effect except skipped. Sign Edit Descriptor In an output specification, the dollar sign ($) edit descriptor suppresses a carriage return at the end of a 1line whose first character is a space or a plus sign (see Section 8.3 on carriage control characters). descriptor primarily 1is for ignored. In an The interactive I1/0; input dollar specification, sign it leaves the the dollar sign descriptor 1is intended terminal print position at the end of the output text (rather than returning it to the left margin) so that a response can be typed immediately after the text. For example, the TYPE 100 200 will on your 100 FORMAT (' ACCEPT 200 FORMAT (F6.2) ENTER RADIUS the message RADIUS VALUE: produce ENTER statements terminal. VALUE: ',$) FORMAT STATEMENTS Your response ENTER Note that character result. list RADIUS the this case, VALUE: dollar instead The it of sign descriptor as following a two field formats 200 (11HSSIGN FORMAT 12.0) can then go on used as a the same are carriage control descriptor accomplishes the same equivalent: HERE:) Colon Edit Descriptor are (:) edit descriptor in an items remain. For PRINT 100,3 200,4 FORMAT(' 200 FORMAT(' two the I/0 list. PRINT 100 print is 12.0 (11H SIGN HERE:,$) colon items in 200 FORMAT 8.1.22 The (say, follows: as line, terminates example, I=',I2, ' format control if no The colon descriptor has no effect the statements more if I/O J=',12) K=',I2,:,' L=',12) lines: I= 3 J= 4 K= Section 8.7 8.1.23 Scale A scale factor the format control in detail. Factor is location complex The describes a of value the used in decimal a format point specifier 1in that determines real, double precision, or values. scale factor has the form: nP A signed +127. the Rules left in @ or unsigned This or Effect If you integer constant integer constant right for do that Both not the Input use a in specifies decimal and scale the range =127 through the number of positions point is to move. default scale to Output factor, a factor of OP applies. e The scale factor is set to OP at the start of every 1I/0 statement. @ A scale e The factor applies to all subsequent F, E, D, descriptors until a new scale factor is specified. scale example, 10 factor in FORMAT the (X, can appear as a field or descriptor. statement I4, E6.3, 3P, 8-18 2A3, 212, G 2F5.3, E8.5) field For FORMAT the 3P applies to descriptor, but A descriptors. A scale factor descriptor. 10 FORMAT 3P applies Format 10 both two start of factor 3P A scale as a in the to in of OP the Effect If the external has no effect. If the external to an to the or to the X, F, E, D or G ES8.5 I, or field statement 8.7) to can has no effect on the scale statement 2PE4.2, read, 1In E8.5. the E3.2, are now applies prefix to Section F3.2, in and given format. factor Rules (see and descriptor E8.5) 2F5.3 records specification descriptor E6.3 appear (X, the the example, example, FORMAT 2F5.3 to (3P2F5.3, For suppose Additional can reversion factor. the not For STATEMENTS with the F4.,2, 3PE4.2) reversion occurring second record, the only an to active the scale F3.2. be reinstated by explicit OP format. for Input field contains an field does contain not exponent, factor specifies multiplication of assignment of the result to the an the scale exponent, the value by <corresponding factor the scale 10**-n and I/0 1list element. For example, .01, moving scale factor decimal Input a 2P scale factor multiplies an input value the decimal point two places to the left. A multiplies an input value by 100, moving point two places to the by -2P the right. Examples Format External 3PE10.5 3PE10.5 -3PE10.5 Additional Field Internal 37.614 37.614E2 37.614 Rules in Effect for .037614 3761.4 37614.0 Output Scale factors apply only to data output. I/0 list variables do not change. For the F field descriptor, the value is multiplied by 10**n before external decimal the record. Therefore, point to the right, decimal point to the moves the decimal of this value The the is wvalues I/O list transferred of the element to the a positive scale factor moves the and a negative scale factor moves left. For the E or D field descriptor, of the value (see Section 2.3.2) is subtracted from the exponent. factor Value the basic real constant is multiplied by 10**n, Therefore, a positive part and n scale point to the right and decreases the exponent, and a negative scale factor moves the decimal to the left and increases the exponent. point FORMAT function, a scale factor has no effect when the magnitude of the data to effective range of the data value is outside G field descriptor be descriptor. on a G output When the scaling own its supplies descriptor field G Because the e STATEMENTS field is descriptor within magnitude of the the the range of the G field descriptor, the functions as an E field descriptor; therefore, the scale factor has the same effect as it does for the Output E field descriptor. Examples Format Internal Value External Representation 1PE12.3 -270.139 -2.701E+02 1PE12.2 -270.139 -2.70E4+02 8.1.24 -0.03E+04 -270.139 -1PE12.2 Complex Data Editing Input and output of complex values is governed by pairs of real field descriptors that use any combination of the Ew.dEe, Dw.d, or in Effect e During Rule value real successive forms Fw.d, Gw.dEe. for Input input, are the two read successive under field descriptors fields comprising a complex the control of repeated or successive and assigned to a complex I/0 1list respectively. element as the value's real and imaginary parts, Input Examples Format | External Field E9.1,F9.3 in @ 734.432E8123456789 Effect for During repeated or 734.432E8, 12345.67 123456.789 Output output, transferred to the an two parts external successive parts two The punctuation or e¢ 123.45678, 1234567812345,.67 F8.5,F8.5 Rules Internal Value field of record a complex under descriptors. value the control are of without consecutively, transferred are spacing, unless the format specifier states otherwise. Output Examples Format 2F8.5 E9.2,' 8.1.25 , Internal Value ' ',E5.3 Repeat 2.3547188, 47587.222, Counts and Group External Representation 2.35472 3.45673 3.456732 56.123 Repeat 0.48E+06 , ****% Counts You can apply any field descriptor except H, T, P, or X to a number of field descriptor with an the by preceding fields successive data integer constant that specifies the number of unsigned nonzero FORMAT applications, or called a repeat equivalent: STATEMENTS repetitions, desired. count. For example, the 20 FORMAT (El12.4,E12.4,E12.4,15,15,15,15) 20 FORMAT (3El2.4,415) Similarly, you enclosing the nonzero can apply a group integer in group For of field parentheses constant. repeat count. equivalent: This and descriptors preceding it integer constant is the following two example, 50 FORMAT (I18,18,F8.3,E15.7,F8.3,E15.7,F8.3,E15.7) To repeat an H or X field enclose it in parentheses (for example, 5(20H)). you do not specify a S by unsigned a group statements (218,3(F8.3,E15.7)) e an called FORMAT 1 is are repeatedly with 50 R If This 1integer constant following two statements are g 2 3 specification (for example, 20H), you can and treat it as a group repeat specification group repeat count, a default count of 1 is G, or A assumed. 8.1.26 If you Default write Field the Descriptors field descriptors without specifying a field width are supplied on the basis of the Note that Table 8-2 for F, lists the A field corresponding E, D, the and default descriptor, I/0 list G, 1, you must values the 2, L, F, E, for specify w, default d, w.d[Ee] and for e. w 1is D, for w, 1list or 8-2: Default List Descriptor of for length Field the w d e 15 7 2 25 1 16 2 Widths Element Data Type 0, 2 INTEGER*2 7 O, Z INTEGER*4 12 0, 2 CHARACTER*n 0, Z LOGICAL*1l, 0o, 2z REAL o, Z DOUBLE (see BYTE Note) 7 12 PRECISION LOGICAL 23 2 F, E, G, D REAL, F, A E, G, D DOUBLE PRECISION LOGICAL*1 or BYTE COMPLEX A LOGICAL*2, INTEGER*2 2 A LOGICAL*4,INTEGER*4 4 A REAL, 4 A DOUBLE A CHARACTER*n COMPLEX PRECISION if (n*8 MOD otherwise 3) = 8 n The default value of w is: (n*8)/3+1 (n*8)/3+2 that the I, Note: nothing. Notice I, L 4, and e element. element. Table Field 0, value, default values data type of the 1I/0 0 FORMAT STATEMENTS 8.2 You VARIABLE can use FORMAT an EXPRESSIONS expression in a FORMAT statement any place you can use an integer (except in the specification of the number of characters in the H field), by enclosing it in angle brackets. For example, the statement FORMAT performs (I<J+1>) an I (integer) than the value is reevaluated of J each If the expression is converted to integer valid FORTRAN data transfer with at the time the format time it is encountered not of integer data data type before it expression, including a field is in type, its is used. function width scanned. a normal one evaluated You can calls and greater The expression format scan. result is use any references to dummy arguments. The wvalue of a variable restrictions on magnitude format, or an error occurs. Figure 8-1 shows an example DIMENSION A(S) DO 1,10 10 I = format expression must obey the that apply to an integer constant of 100 WRITE (6,100) I FORMAT (I<MAX(I,S5)>) 10 CONTINUE DO 201 WRITE a variable format expression. =1,5 (6,101) 101 FORMAT 20 CONTINUE (A(I),J=1,1I) (<I>F10.<I-1>) END On execution, these statements produce the following output: 1 2 3 4 5 6 7 8 9 10 l. 2.0 2.0 3.00 4.000 3.00 4,000 3.00 4.000 4.000 5.0000 5.0000 5.0000 5.0000 Figure 8-1: Variable Format Expression 5.0000 Example same in a FORMAT 8.3 STATEMENTS CARRIAGE CONTROL CHARACTERS The first assumed character by overridden '"LIST' the by or of every system the to be OPEN 'NONE'); record a transferred carriage statement system recognizes certain characters Table 8-3 lists these characters and 8-3: Carriage is not Control line 0 (zero) Advances two lines 1l (one) Advances to (plus) next page Does not (allows sign) Any character other than those space and 1is deleted from accidentally omit the carriage 8.4 record is not = I/0 characters. top of the advance overprinting) Advances one line before printing and suppresses carriage return at the end the The FORTRAN Effect Advances one (dollar |is when Characters (space) $ printer (except CARRIAGECONTROL printed. A + a as carriage control their effects. Character of to character specification this character Table control of the record listed in Table 8-3 1is treated as a the print 1line. Note that 1if you control character, the first character printed. FORMAT SPECIFICATION SEPARATORS When the next value in an I/0 list is to be transferred to or from the current record, you use a comma to separate the relevant field descriptor from the preceding one. However, when the next value is to be (/) transferred to separate For example, to or from the next succeeding record, the relevant field descriptor from the the WRITE 40 are 40 50 You can blank (6,40) K,L,M,N,O,P (306/16,2F8.4) to the following: WRITE (6,40) K,L,M FORMAT (306) WRITE (6,50) N,O,P FORMAT (16,2F8.4) use multiple records. If slashes to consecutive first slash (n-1l) second terminates the output. slash The bypass n descriptors, are slash one. statements FORMAT equivalent you use a preceding records are skipped first 1input records or to output blank records slashes appear between two fleld on input terminates skipped or or (n-1) the current record; blank record; and so the on. FORMAT STATEMENTS However, n slashes at the beginning or end of a result 1in n skipped parentheses of initiator and terminator, the 50, top respectively. of line) (blank line) field the w Using reads input comma to with the it when example, you if the READ 100 The the are field a override entering I, O, (5,100) that than w short characters, field is numeric, comma to descriptor's a statement If the data from the next data the input field with is field the in input in the external leading 2zeros or you can avoid having to terminate the field; the field-width specification. field descriptor's field-width Z, data E, F, from a terminal keyboard. You can For D, G, and L field descriptors. I,J,A,B (216,2F10.2) record I =1 J = assignments occur:- -2 A= 1.0 B 0.35 physical end of the record also serves as Note that the d part of a w.d specification external an record. short field termination and is particularly called statements FORMAT following = specifies fewer padded by using the 1is useful Fw.d field descriptor field overrides a as characters specification the record statements LINE contains you have When the the comma such record unless spaces. read the closing a LINE characters from an external external record, use example, and line) descriptor read statement pad themselves EXTERNAL FIELD SEPARATORS 8.5 to For opening page SUBHEADING A are specification specification format the output: HEADING (blank (blank because ('l1',T51,'HEADING LINE'//T51,'SUBHEADING LINE'//) following Column records, (6,99) FORMAT produce blank format the WRITE 99 or field separator. Therefore, explicit decimal point in an external a field 1is not you should field for F, terminator. by affected E, always D, and include G an an field descriptors. You can use a comma to terminate fields only when those fields are a field of w follows comma a If long. than w characters less characters or more, the comma is considered part of the next field. FORMAT Two successive commas, or a characters, constitutes a null field descriptor specified, the 0.D0, You or STATEMENTS comma after (zero-length) resulting a field of exactly w field. Depending on the value assigned .FALSE.. cannot use a 1is 0, 0.0, : comma to terminate a field that is controlled by an A, H, or alphanumeric-literal field descriptor. However, if a record being read under the control of an A, H, or alphanumeric-literal field descriptor reaches short-field termination are by successfully the 8.6 You RUN-TIME can store format at time. can be A the Trailing list element specifications character These format constructed Virtual arrays run-time I/0 end and before that spaces appended or must or not in format expressions are in not formats execution solve this The are field have are read, been read as required descriptor. and specifications altered be during used (numeric character are called program for or character), substrings run-time to use formats execution. storing specifications for formats. run-time field the arrays variables, an array has the same statement, without the word FORMAT opening and closing parentheses are Run-time w characters characters FORMATS elements, run physical occurs assigned. corresponding array and 1its form as that following are especially that example REAL a FORMAT permitted. useful when you cannot time exactly which field descriptors will problem, you can write a program to create descriptors of and the statement label. The required. Variable format depend on the demonstrates attributes the use of of be a Kknow before required. To format with the relevant run-time formats: data. TABLE (10,5) CHARACTER*26 FMT CHARACTER*5 FBIG,FMED,FSML DATA FMT(l:1)/'('/,FMT(26:26)/')'/ DATA FMT (6:6)/','/,FMT(11:11)/','/,FMT(16:16)/"','/,FMT(21:21)/','/ DATA FBIG,FMED,FSML/'F8.2','F9.4','F9.6"'/ DO 10 I=1,10 DO 15 J=1,5 TABLE (I,J)=100. 15 CONTINUE 10 CONTINUE DO 20 I=1,10 DO 18 J=1,5 IF (TABLE(I,J).GE.100) THEN FMT (5* (J-1)+2:5* (J-1)+5=FBIG ELSEIF(TABLE(I,J).LE.O.1) THEN FMT (5% (J-1)+2:5% (J-1)+5) =FMED ELSE FMT (5*(J-1)+2:5*%(J-1)+5)=FSML ENDIF 18 CONTINUE TYPE *, FMT WRITE (6, FMT) (TABLE(I,Jd), 20 CONTINUE END J=1,5) FORMAT STATEMENTS In the above example, will the given data magnitudes The TABLE. not be known until just is stored before output. in the first character of FMT and the character real a The format right parenthesis specification is stored variables FBIG, FMED, FSML. The choice of statement location. of the compiled 1is Data read recompiled) (or and assigned into that location through use of the is not stored in the array holding the format. descriptor the field references Each time an I/O statement referencing a run-time format is format in to be assigned to FMT is made to depend on the magnitudes of the data in TABLE. Finally, the output instead of a format statement label. the array A selection of field descriptors is stored in character of FMT. descriptors the A left parenthesis is stored is stored in the character variable FMT. last in the data stored in the elements of TABLE of I/0 statement, the data a FMT executed, H storage field At the end is lost. FORMAT CONTROL INTERACTION WITH INPUT/OUTPUT LISTS 8.7 Format control begins with execution of a formatted I/0 statement. information taken depends on action the format control, During provided jointly by the next element of the I/O list (if one exists) list and the format specification are correlated from left except when repeat counts are specified. If the I/0 statement contains an an error to I/0 list, you must specify right, at least z, F, E, D, G, L, A, or Q field descriptor in the format, or 0, one 1, The I/0 field descriptor of the format specification. next the "and occurs. On execution, a formatted input statement reads one unit control requires record from the Thereafter, additional and initiates format control. specified records can be read as indicated by the format specification. Format format specification, or when the last closing parenthesis of a format a new record be read when a slash occurs in a that 1is reached before all the elements in the corresponding specification I/0 list have been assigned values. When this new record is read, any remaining characters read from the current record are discarded. A formatted output statement transmits a record to the specified control format as format control 1if or specification, a slash appears 1in the controlling remain to Q field descriptor corresponds to transferred. Each I, 0, 2, element one P, T, BN, BZ, F, E, D, G, L, A, in an I/0 list. $, :, TL, TR, S, character-constant between an external format 1f the last closing parenthesis in the controlling format specification is reached and more I/O list elements be unit can also be written during Records terminates. field and No list element corresponds to an H, X, SP, SS, or field descriptor. In H and data transfer occurs directly descriptors, record and the storage location of the format specification. In format control, when an I, O, 2, F, E, D, G, L, A, or Q field descriptor is encountered, the I/0 list is checked for a corresponding element. and, list if If a corresponding appropriate, element. terminates. If a element is found, data 1is transferred translated between the external record and the corresponding element is not found, format control FORMAT When the last reached, closing format parenthesis control elements remaining control terminates. or all format of the format reversion. Format reversion STATEMENTS to of determines be processed. However, if If of format there there additional specification consists the whether the is any are list reused termination specification are of more no more, elements I/0 is list format remain, in a the current part called process record and the starting of a new record. Format control reverts to the group repeat specification whose left parenthesis 1is complemented by the next-to-last right parenthesis of the format specification. 1If the format does not contain a group repeat specification, format control returns to Examples the of beginning format READ 100 In this first the example, record third to In are (I2, example, specification assigned values In this SUMMARY The following C, D, E, F records containing to A and two B; fields the are second to read. C and The D; and N, A, I1, I3, F8.3,2(I2, I4), control and the I2, I4, Il1l1, I13, to the I12, I14 I4)) 1/0 reverts list next elements Ill1, group I13, I12, repeat and Il4 record. A(5,5),B(5) (E10.3/(15,E10.3, example, 8.8 B, (6,10)X,(I,B(I),(A(I,J),J=1,5),I=1,5) FORMAT specification follow. values from DIMENSION 10 specification. F8.3) format 2(12, WRITE format F. (4,200) FORMAT this three and READ 200 A, (F8.3, assigns E the reversion (I,100) FORMAT of that OF format begins RULES 5(F8.5))) reversion with returns to the group repeat IS. FOR FORMAT STATEMENTS sections summarize the rules for constructing and using the format specifications and their components, and for constructing external fields and records. Table 8-4 summarizes the FORMAT codes. 8.8.1 General Rules e A FORMAT statement ¢ In a field descriptor such as rIw or nX, the terms r, w, m, and n must be unsigned integer constants greater than 0. (They cannot be names assigned to constants in PARAMETER statements.) You must can always omit be the labeled. repeat count and term d field width specification. e In a field descriptor such as Fw.d, the must be an unsigned integer constant. If w is specified, then you must specify d4d in F, E, D, and G field descriptors even if it is 0; and the field width specification (w) must be greater than or equal to d. The decimal point is also required. You must either specify both w and d or omit them both. 1In a field descriptor such as Ew.dEe, the term e must also be an unsigned integer constant. FORMAT ¢ In a field descriptor STATEMENTS such characters must follow printing ASCII character e In a scale factor unsigned integer inclusive. descriptors as the in H this nHcle2 ... cn, format code. You field of the form nP, n constant in the exactly can n use any signed through or 127 descriptor. must range be a =127 The scale factor affects the F, only. Once you specify a scale E, D, and G field factor, it applies to all subsequent F, E, D, and G field descriptors in that format specification until another scale factor appears. You must explicitly specify OP to reinstate a scale factor of zero. e No Format repeat TL, S, these group e If reversion count SP, SS, is or the permitted character descriptors repeat does are A associated run-time enclosed I/0 statement including the If a and BZ, scale $, field :, factor. H, X, T, descriptors, parentheses and TR, unless treated as a opening the be must and an be specification statement must contains I/0 1list, the closing label only format constructed in by in the FORMAT statement, parentheses. are The word omitted. 1includes represented a apostrophes, double those apostrophes. Rules sign must field; input, must point a an be or must input only the An control must On input, negative optional is field field F(f). form a under I wvalue before field a 1in an external positive value. descriptor 1integer constant. It cannot contain exponent. An external field wunder contain through the sign control external exponent. precede plus external an an descriptor An a character-constant A minus On the contain at 1least one field T, or a character constant. format input ¢ must X, P, specification Input e in format apostrophes e BN, as FORMAT 8.8.2 for constant way 'same e affect specification. format specification descriptor other than H, e¢ not an or field the numerals descriptor numerals 0 through 9 and field under O or Z contain cannot '777'0 only Z use 'AF9'X external a sign, octal and a external field under decimal field through 7. must letters A(a) descriptor field decimal hexadecimal in 0 0 control the external not You contain under control a point, or constants an in records. F, E, D, or G field descriptor control must be an integer constant or a real or double~-precision constant. It can contain a decimal point and/or an E or D exponent field. e¢ If an external of the decimal corresponding e If (if on an external any) the field contains fractional part point, overrides of real or field the conversion actual size of the field, as indicated by the d specification of a that the double-precision contains an corresponding of decimal that field. point, field exponent, field the descriptor. the descriptor scale factor has effect no FORMAT The field width accommodate field sign, A both specification the numeric must be character large string and any other characters that are decimal point, and/or exponent). comma is the separator. shorter than designates 8.8.3 STATEMENTS Output only It the null character terminates number of you can enough of the allowed use as an (algebraic external input of numeric fields characters expected. (zero-length) to external field that are It also fields. Rules A format specification cannot specify more output characters than the external record can contain. For example, a line printer record cannot contain more than 133 characters, including the The width field carriage control specification accommodate all generate, including character. (w) characters an must that algebraic be the large data sign, enough decimal point, exponent., For example, the field width specification in field descriptor should be 1large enough to contain characters. ' The first terminal The first $, or deleted character is wused of a for character of +. from Any Code such a record other character the Table record output to a «carriage control; record. 8-4: Summary of 1line it is should is be a transfer of decimal Ow[.m] Specifies transfer of octal Specifies transfer of printer or not printed. space, integer integer Specifies hexadecimal transfer Specifies Specifies in in with a in D integer or real form real or exponential of values values real basic of values transfer double-precision exponential form Gw.d[Ee] of values transfer double-precision Dw.d 0, values values double-precision form real or double-precision instead of an E Specifies transfer of real or double~-precision values: on input, acts like F code; on output, acts like E code or F code (continued on E d+7 Effect Specifies Ew.d[Ee] and an treated as a space and Iw[ .m] Fw.d can FORMAT Codes Form Zw([ .m] to transfer next page) 1, is Table 8-4: Code L FORMAT STATEMENTS (Cont.) Summary of FORMAT Codes Form Lw Effect Specifies input, A A[w] H nHc...cC Specifies values nX Specifies on numeric SP SS SP SS SP Tn F, data: £, .F, or Hollerith Hollerith record on or F character and characters or that values the format n are spaces to are be to be output optional and Writes .t, T or of n input output plus fields: characters counters the in action SS plus characters be optional into Suppresses optional numeric T that Reinvokes of of external on skipped S .T, location skipped S logical t, transfer an storage X transfer Specifies between of T, transfers output, on .£; transfer ¢transfers output Specifies would plus otherwise fields characters in fields the record, that numeric output position, of the in next the external character to be processed TL TLn Relative tabulation specifier (left) TR TRn Relative tabulation specifier (right) Q Q Specifies to $ : $ : be the number transferred Suppresses of characters an input carriage interactive Terminates in remaining record return during 1/0 format control if the I/0 list is exhausted BN BN Specifies in BZ BZ a Specifies in as that numeric a that numeric zeros embedded input field embedded input and trailing are and field to be trailing are to blanks ignored be blanks treated CHAPTER AUXILIARY INPUT/OUTPUT The auxiliary '1nput/output functions. The auxiliary functions ® ® are as follows: -- file establishes or a and device, write specifies CLOSE a =-- file operations terminates or REWIND and ® DELETE -- deletes ® UNLOCK -- frees BACKSPACE shared-file ¢ ENDFILE Section 7.2 the -- -- perform records 1locked writes for a statements. an a in a and a for read between logical unit and a or I/0 file users causes an functions indexed other that when the unit required for record of logical management respective attributes relative transfer) definition a file their file-positioning records special END= between the connection environment condition (and the record See connection device ® STATEMENTS statements perform 1I/0 statements and OPEN and 9 input an in a end-of-file statement components of reads these OPEN 9.1 An OPEN STATEMENT OPEN statement or creates In addition, a OPEN creation and/or The statement OPEN either new file can connects and specify subsequent has the an existing connects file processing. this new file file attributes to a to a that 1logical unit logical unit. control file form: OPEN (par{,par]...) par A parameter, kwd kwd = or value keyword specification, in one of the forms: AUXILIARY INPUT/OUTPUT STATEMENTS kwd A keyword, as described below. value Depends on the keyword, as described below. Keywords are divided into functional categories as follows: Keywords that identify the unit and file. UNIT FILE or NAME STATUS or TYPE DISPOSE - logical unit number to be used - file name specification for the file - file existence status at OPEN - file existence status after CLOSE Keywords that describe the file processing to be performed. ACCESS ORGANIZATION READONLY - FORTRAN access method to be used - logical file structure - write protection Keywords that describe the records in the file. BLOCKSIZE- - size of I/0 transfer buffer RECORDTYPE - logical KEY - key field definition - type of printer control CARRIAGECONTROL - type of FORTRAN record formatting FORM RECL or RECORDSIZE - logical record length BLANK record structure - blank interpretation for numeric input Keywords that describe file storage allocation when a file |is created. INITIALSIZE EXTENDSIZE - initial file storage allocation - file storage allocation increment size Keywords that provide additional capability for direct access direct access I1/0. ASSOCIATEVARIABLE - variable holding the next MAXREC - maximum direct access record number record number Optional keywords that provide improved per formance or special capabilities. ERR , - statement to which control is transferred if an error occurs during execution of the OPEN statement BUFFERCOUNT NOSPANBLOCKS - number of I1I/0 buffers to use - records are not to be split across SHARED - other programs can simultaneously access USEROPEN - option to provide a user-written external function that controls the opening of the physical the file file blocks AUXILIARY INPUT/OUTPUT STATEMENTS NOTE Not all all PDP-11 operating keywords PDP-11 and FORTRAN-77 information on 9-1 lists in associated values, ACCESS Guide 9-1: OPEN Statement Valuesl 'SEQUENTIAL' the for system-specific alphabetical order the keywords including default values. Table Keyword support Consult User's restrictions. Table systems options. Keyword and their Values Function Access possible method Default 'SEQUENTIAL' 'DIRECT?® 'APPEND' 'KEYED' ASSOCIATEVARIABLE \Y Next record number direct BLANK BLOCKSIZE in access No associate variable '"NULL' Interpretation '"NULL' 'ZERO' of (/F77) e blanks Size of 1/0 System default System default buffer BUFFERCOUNT e Number of I/0 buffers CARRIAGECONTROL '"FORTRAN' Print control 'LIST' "NONE' 'FORTRAN' (formatted) 'NONE' (unformatted) DISPOSE 'SAVE' DISP '"PRINT' 'DELETE"' ERR or 'KEEP' s File disposi- Error transfer label EXTENDSIZE e '"SAVE' tion at close File No error transfer storage allocation Volume tem or sys- default increment FILE c NAME FORM File name Depends specification 'FORMATTED' Format type '"UNFORMATTED' INITIALSIZE e unit Depends ACCESS File storage on and system on keyword No allocation No default allocation KEY (k[,k]ees) Indexed file key fields (continued on next page) AUXILIARY Table 9-1: Keyword INPUT/OUTPUT (Cont.) OPEN Statement valuesl! MAXREC e NOSPANBLOCKS Keyword Values Function Maximum - ORGANIZATION STATEMENTS record number in direct access Records 'SEQUENTIAL"' Default do not No maximum Records can span span blocks blocks File structure 'SEQUENTIAL' Write protec- 'RELATIVE' '"INDEXED' READONLY - tion RECL e No write protection Record length RECORDSIZE Depends on TYPE, ORGANIZATION, and RECORDTYPE keywords RECORDTYPE 'FIXED' Record Depends 'VARIABLE' structure ACCESS and FORM keywords File File 'SEGMENTED' SHARED - sharing allowed STATUS 'OLD! File TYPE '"NEW' "SCRATCH' at open not status on sharing allowed 'UNKNOWN'' (/F77) "UNKNOWN' UNIT e Logical unit No default program No option variable name, number USEROPEN p User option l. ¢ is e element name, or a character substring reference. 1is an integer, real, or double-precision expression. <o x of a character this constant, expression is array converted name, to the integer data array The value type before it is used. is a key specification. is an external function. is is Keyword a statement label. an integer variable name. specifications can appear in any order. Determining whether they are optional and which ones are required depends upon the type of file you are establishing or have established, and upon what you plan to do with it. AUXILIARY INPUT/OUTPUT STATEMENTS Some examples OPEN This the (UNIT=1, example default OPEN follow. ERR=100) creates file a new sequential (UNIT=3, STATUS='SCRATCH', INTTIALSIZE=50, This example access., The OPEN a file deleted is (UNIT=I, 50-block (UNIT=I, opens unit 1 with ACCESS='DIRECT', sequential at program file to be used with direct termination. ERR=14, on BLOCKSIZE=8192, RECL=1024, RECORDTYPE='FIXED') magnetic tape FILE='MTO:MYDATA.DAT', RECL=1024, example on FILE='MTO:MYDATA.DAT', This example creates a file for efficient processing. This file RECL=64) creates STATUS='NEW', OPEN formatted name. file created in a READONLY, RECORDTYPE='FIXED', the with large block size STATUS='OLD', BLOCKSIZE=8192) the previous example for input. Example: OPEN (UNIT=1,STATUS='NEW', ORGANIZATION='INDEXED', RECL=60, FORM="'UNFORMATTED', KEY= (1:20, 30:33:INTEGER, 46:57), ACCESS='KEYED') This statement creates a new indexed file specifying three keys: primary key will be from byte 1 to 20; the first alternate key be an integer key from byte 30 to 33; and the second alternate will be from byte 46 to 57. Sections 9.1.1 through 9.1.26 describe the OPEN statement The will Kkey keywords in detail. 9.1.1 ACCESS ACCESS specifies There the method of locating, reading, or writing records. three access methods: sequential, direct and, keyed. If 'DIRECT', the file is accessed directly. 1If you specify 'SEQUENTIAL', the file 1is accessed sequentially. If you specify 'KEYED', the file 1is accessed by a specified key. 'APPEND' implies sequential access and positioning after the last record of the file. The default is 'SEQUENTIAL'. you are specify An ACCESS specification has the form: ACCESS= acc acc One of the character constants 'SEQUENTIAL', 'DIRECT', 'APPEND'. If no ACCESS is specified, the default is 'SEQUENTIAL'. 'KEYED' or AUXILIARY Table 9-2 shows the valid INPUT/OUTPUT STATEMENTS file and values ACCESS of combinations organizations: Table 9-2: Allowed Combinations of ACCESS Values and File Organizations ACCESS File SEQUENTIAL DIRECT KEYED APPEND Sequential Yes Yesl No Yes Relative Yes Yes No No Indexed Yes No Yes No 1. Organization Value Direct access to a sequential records in the file be file fixed requires 1length (see that the Section 9.1.19). In sequential access, you must read or write records the beginning of the file. (See Section 7.1.4.1.) In the direct access, you specify in an I/0O statement in sequence the record desired record, and the system selects that record. In keyed access, you specify record, Section and key. (See 9.1.2 ASSOCIATEVARIABLE I/0 access sequential access or record keyed an I/O statement 7.1.4.3.) ASSOCIATEVARIABLE specifies direct in the system selects the the operation, in a file. integer the number of (See Section 7.1.4.2.) desired from key value of the record having a matching wvariable that, after each contains the record number of the next This specifier is ignored for sequential access. An ASSOCIATEVARIABLE specification has the ASSOCIATEVARIABLE = form: asv asv An 9.1.3 integer variable. BLANK BLANK specifies either be (except ignored that all 1if blanks in a numeric the field is all blanks, input field are to in which case it is treated as zero), or that all blanks other than leading blanks are The default value is 'NULL'. be treated as zeros. BLANK has the BLANK = form: blnk to AUXILIARY INPUT/OUTPUT STATEMENTS blnk A character constant having a value equal to either 'NULL' or 'ZERO'. If the value /NOF77 is 9.1.4 compiler command qualifier size bytes) is specified, the default 'ZERO',. BLOCKSIZE BLOCKSIZE specifies the I/0 statements appear the entities specified to transfer in transfers records between BLOCKSIZE affects the A BLOCKSIZE = the a size specification BLOCKSIZE (in of directly between however, the and has the transfer list; file this I/0 records I/0O of the an buffer. a file system intermediate and actually 1I/0 buffer. disk blocks buffer. form: bks bks An integer For sequential to transfer magtape expression. files, (for files). BLOCKSIZE disk The default For relative and indexed size, A bucket is the transfer bucket See the unit of control PDP-11 FORTRAN-77 or the the the number physical system of blocking default for BLOCKSIZE determines a of disk blocks used as locking and information as User's Guide control well as for more the factor logical not specifies wunit previous file's the unit bucket of I/0 information. Each data. information. for section, specify the number of multibuffered specifies the BUFFERCOUNT, or specification has buffers 1I1I/0. size if of to be associated BLOCKSIZE, each you specify of 0, these the BUFFERCOUNT BUFFERCOUNT = the A integer specification the buffers. If you system default form: bc expression. of BUFFERCOUNT= -1 opens a file for a in bc An with discussed used. A (for device. BUFFERCOUNT BUFFERCOUNT do as is files, number contains the 9.1.5 and determines files), block I/0. is AUXILIARY INPUT/OUTPUT STATEMENTS CARRIAGECONTROL 9.1.6 CARRIAGECONTROL determines the default unformatted normal for FORTRAN the kind of carriage 1is 'NONE'. files interpretation of A CARRIAGECONTROL specification has the = to the be used 'FORTRAN'; 'FORTRAN' first character 8.3); 'LIST' specifies single spacing between specifies no implied carriage control. CARRIAGECONTROL control The default for formatted files is when a file is printed. specifies (see Section records; and 'NONE' form: cc cc The character constant 'FORTRAN', 'LIST', or 'NONE'. DISPOSE 9.1.7 DISPOSE determines the disposition of a retained unit that unit 1is after If operation. system line closed. the you printer printing.) after spooler. you If file A DISPOSE specification DISPOSE DISP = = is closed; specify read-only a scratch file (see If you specify file 'PRINT', (On (see Section 9.1.23) the connected 'SAVE' or to a unit when 1is the default file 1is deleted 'KEEP', the file is retention file is submitted to the the some systems, specify Section 9.1.18) has file 'DELETE', cannot be the the file is deleted. printed or deleted, cannot be saved or printed. A and forms: dis dis dis The character constant 'SAVE', 'KEEP', 'PRINT', or 'DELETE'. ERR 9.1.8 ERR transfers control to a specified executable statement if an error occurs during execution of the OPEN statement containing it. The ERR specification applies only to the OPEN statement containing the ERR If to subsequent I/0 operations on the specified unit. not keyword, an error does occur, no An ERR specification has ERR= The 9.1.9 file the is opened or created. form: s label of an executable statement. EXTENDSIZE EXTENDSIZE specifies the number of blocks a disk file 1is to be extended when additional £file storage is allocated. If you do not specify EXTENDSIZE, or if you specify 0, the system default for the device is used. AUXILIARY An EXTENDSIZE EXTENDSIZE = An expression. integer specifies name has the form: es FILE 9.1.10 FILE specification INPUT/OUTPUT STATEMENTS can be The PDP-11 conventions. the any name file of the file to be connected to a unit. The specification accepted by the operating system. FORTRAN-77 User's Guide describes default file name If the file name is stored in a numeric variable, numeric array, or numeric array element, the name must consist of ASCII characters terminated by an ASCII null character (zero byte). However, if the file name 1is stored in a character variable, character array, or character array element, it must not contain a zero byte. A FILE specification FILE = has the form: fln fln An array name, constant, name of a variable name, array or a character substring virtual array or virtual FORM specifies whether the file being written to with formatted or with sequential access, 'FORMATTED' is the access, 'UNFORMATTED' is the unformatted I/0 statements on FORM name, character cannot use the FORM 9.1.11 A element reference. You array element. specification FORM = has the opened is to be read from and unformatted I/0 statements. For default. For direct or keyed default. the same You must unit, not mix formatted and form: ft ft The 9.1.12 character constant 'FORMATTED' INITIALSIZE specifies the number not specify INITIALSIZE = of allocated or if for a you specify ' the insz insz integer blocks INITIALSIZE, made. INITIALSIZE specification has An 'UNFORMATTED'. INITIALSIZE a disk. If you do initial allocation is An or expression. 9-9 form: new file 0, on no AUXILIARY INPUT/OUTPUT STATEMENTS KEY 9.1.13 KEY designates fields to be used as key fields 1in an indexed file. These designated key fields must be included in an OPEN statement when an indexed file available an existing Or file, A KEY created. KEY = (kspec each kspec el : all key information is 1If key parameters are specified for they must match specification where Thereafter, the file itself. the parameters of the existing file occurs. error an 1is from e2 has the form: [,kspecl...) has the form: [:dtn] el The first byte position The last byte position The data type of of the key. e2 of the key. dtn the key. el,e2 Integer expressions. dtn One If dtn of the following data-type - Integer - Character key key data type omitted, the The key starts at position el The values If be to the key INTEGER CHARACTER is 1 of el .LE. and (el) key type is e2 .LE. must (e2) INTEGER, in a be 255 key specifications. The The second key, and The order of specification, a key key number 254 be key 2 specification kspec 0, 1, or 4. There must but there may be up defines a key defines the primary key. defines the first to specification alternate in a list of alternate key specifications determines the key-of-reference number be used a file must be specified Up to kspec length of e2-el+l. on. KEY specification) (the length must following KEY=; first key specification, key so and has a that: record-length key Each character. record .LE. the is such at least one key specification field. names: in subsequent I/0 statements). in a key specification 1list. keys may be specified in a for (in Each key specification key in list; however, at least one key -- the primary key -- must be specified. 9-10 a that key AUXILIARY 9.1.14 MAXREC MAXREC specifies access file. ignored for A MAXREC the The other maximum default types specification MAXREC = INPUT/OUTPUT number is of no of STATEMENTS records maximum number permitted of in a direct disk block records. MAXREC is files. has the form: mr mr An integer 9.1.15 NAME NAME a is 9.1.16 nonstandard specifies boundaries; A synonym for FILE. See Section 9.1.10. NOSPANBLOCKS NOSPANBLOCKS any expression. record it is exceeds NOSPANBLOCKS that used the records only size for of specification a has are not sequential disk the block, to files an cross stored error on disk. If occurs. form: NOSPANBLOCKS 9.1.17 ORGANIZATION ORGANIZATION specifies the internal structure of a file. organization is 'SEQUENTIAL'. The organization of always be specified for relative and indexed files. An ORGANIZATION specification ORGANIZATION= org The constant has the The default the file must form: org In character sequential written, In by files, records 'SEQUENTIAL', are stored in 'RELATIVE', the order relative files, records are stored in an integer number. In indexed files, or 'INDEXED'. in which they are fixed-length cells records are stored identified in a system-defined order; indexes or directories are maintained to locate records based on character strings or integer values, called keys, contained in Table 9-3 the access shows the record. valid combinations modes: 9-11 of ORGANIZATION keywords and AUXILIARY Table 9-3: INPUT/OUTPUT STATEMENTS Valid Access Modes for ORGANIZATION Keywords Access Mode FILE ORGANIZATION Sequential Direct Keyed Append SEQUENTIAL Yes Yesl No Yes RELATIVE Yes Yes No No INDEXED Yes No Yes No 1. For Direct access to a sequential file requires that the in the additional be fixed length information, see (see records Section 9.1.18). the PDP-11 FORTRAN-77 User's Guide. READONLY 9.1.18 READONLY A file prohibits READONLY a program specification has from writing the to a file. form: READONLY 9.1.19 RECL RECL specifies If file a the contains logical length You must specify RECL fixed-length records or RECL specification RECL = length. fixed-length records, RECL specifies file contains variable-length each record. If a specifies the maximum A record has when for you is to the form: size of RECL create a file that 1is to have relative organization. have any that the records, record. rl rl An integer expression. The value of rl depends on the value of FORM (see Section 9.1.11). 1If the records are formatted, the length is the number of characters; 1if the records are unformatted, the 1length is the number of numeric storage units (four bytes). For existing 9.1.20 files, the default is the existing record size. RECORDSIZE RECORDSIZE is a nonstandard synonym for RECL. See Section 9.1.19. AUXILIARY 9.1.21 STATEMENTS RECORDTYPE RECORDTYPE specifies variable-length file, INPUT/OUTPUT the default whether records, or record types a for follows: File Relative Indexed Direct Type Record file records, you types create a are as Type 'FIXED' files 'FIXED' sequential Unformatted 'VARIABLE' sequential 'SEGMENTED' files Segmented records allow FORTRAN However, various When files access a fixed-length records. '"FIXED' organization Formatted has the Default organization access access file segmented they consist can with sequential other file of logical only be one or more record used in organization. to variable-length records span several physical sequential access, unformatted You cannot specify type. and records. 'SEGMENTED' files for any NOTE ASCIZ stream supported A RECORDTYPE by specification RECORDTYPE = files PDP-11 has the are not FORTRAN-77. directly form: typ typ The If you character do record you In or of when you access or 'SEGMENTED'. an existing RECORDTYPE, typ must match file. record, (for record files, if an the record is filled an 9.1.22 SHARED SHARED specifies one file, the is a sequential this file has 'SEGMENTED'. specify zeros than RECORDTYPE 'VARIABLE', of fixed-length full 'FIXED', the file 1is wused, unless the file unformatted file with sequential organization; existing a specify type access, a default If not constant program unformatted file). that is a file executing Sequential files may only only one program may have to the record output statement with spaces (for be opened for type of the does not specify a formatted file) shared access by more disk, and simultaneously. be shared if they write access. are stored on AUXILIARY INPUT/OUTPUT STATEMENTS Relative and indexed files may be shared with multiple programs having access. write A SHARED specification has the form: SHARED See the PDP-11 FORTRAN-77 User's Guide for additional on STATUS 9.1.23 STATUS specifies the status of file to the file must already exist. 'OoLD', deleted system will will assume you If opened. be specify If you specify 'NEW', a new file then If you specify 'SCRATCH', a new file is created and is created. is information keyword. this when file is closed. the 1if the file is first try 'OLD'; 'NEW' If you specify 'UNKNOWN', the not the found, therefore create a new file. and system The default is "UNKNOWN' . A STATUS specification has STATUS = the form: sta sta The character constant 'OLD', 'NEW', If the /NOF77 compiler command qualifier value is when do, it 1is or 'UNKNOWN'. the specified, default 'NEW'. You cannot specify STATUS='SCRATCH' you 'SCRATCH', for a file on magnetic tape. If at run time your program will terminate with no error message encounters the OPEN statement. NOTE STATUS to the is also specify file used the in CLOSE statements however, the values status of a is closed; file after it uses are different from those used in OPEN 9.1.24 statements. TYPE TYPE is a nonstandard synonym for STATUS. 9.1.25 See Section 9.1.23. UNIT UNIT specifies the logical unit to which a file is to be connected. When an OPEN The UNIT keyword must appear in any OPEN keyword list. statement is executed, another file cannot be connected to the logical unit specified by the UNIT keyword in the OPEN statement. AUXILIARY INPUT/OUTPUT STATEMENTS There must not be a file converted to the logical unit at the time the OPEN statement is executed. = [UNIT] An The u integer optional expression. character of u will occupy the 9.1.26 form: the A UNIT specification has string UNIT= first position can be omitted a user-written external function invoked to control the opening of the specified knowledgeable users directly writing to employ available programs in from USEROPEN = features of FORTRAN, A USEROPEN specification has An value it. the file. file that 1is to be USEROPEN allows management system yet retain the convenience of form: p external function Consult the PDP-11 USEROPEN FORTRAN, the name. The external function name must in the program unit. the the USEROPEN USEROPEN specifies not only when in the keyword list containing be declared FORTRAN-77 User's Guide in for an EXTERNAL information statement on using keyword. CLOSE 9.2 The CLOSE CLOSE STATEMENT statement disconnects statement has The CLOSE the a file from a unit. form: STATUS CLOSE ([UNIT=]u , [,ERR=s]) [DISPOSE = p] DISP u A logical unit number. P A character constant that determines 'KEEP', its values are 'SAVE', The executable s label of an the 'DELETE', statement. 9-15 disposition of and 'PRINT'. the file; AUXILIARY INPUT/OUTPUT STATEMENTS If you specify either 'SAVE' unit is closed. line printer spooler. printing.) or 1If you specify 'PRINT', the (On some systems, the If you specify 'DELETE', files, the default is 'DELETE'; 'SAVE'. 'KEEP', the file is retained after the the file file file is submitted to is deleted. for all other files, the The disposition specified For the after deleted is scratch is default in a CLOSE statement supersedes the disposition specified in a preceding OPEN statement; file however, a opened as a scratch file cannot be saved or printed, and a file opened for read-only access cannot be printed or deleted. For example, the statement CLOSE (UNIT=1,DISPOSE="PRINT') closes the file on unit 1 and submits the file for printing. And the statement CLOSE (UNIT=J,DISPOSE='DELETE"',ERR=99) closes the file on unit J and deletes it. REWIND 9.3 REWIND STATEMENT The REWIND statement repositions to the beginning of the file sequential file currently open for sequential or append access. The REWIND statement has the forms: REWIND u REWIND ([UNIT=]Jul[,ERR=s]) A logical The label unit of an number. executable The unit number must refer to an magnetic For a statement. open sequential file on disk or tape. the example, REWIND statement 3 repositions logical unit 3 to the beginning of a currently open You must not issue a REWIND statement for a direct or keyed access or for a relative or file indexed that file. 1is file. open for AUXILIARY INPUT/OUTPUT STATEMENTS BACKSPACE 9.4 The BACKSPACE BACKSPACE STATEMENT statement repositions an open sequential beginning of the ©preceding record. When the unit is executed, this preceding record The BACKSPACE statement the u BACKSPACE ([UNIT=]ul[ ,ERR=s]) A unit logical label of the for number. an executable The unit number must magnetic to forms: BACKSPACE The For has file the next I/0 statement is the one processed. refer to statement. an open sequential file on disk or of the open for tape. example, the BACKSPACE statement 4 repositions the open preceding record. file You must not BACKSPACE direct, keyed, issue a on logical unit statement or append access, or 4 to the beginning for a file that for a relative or is indexed file. DELETE 9.5 The DELETE STATEMENT DELETE files. records statements delete Specifically, so marked are records they not <cause accessible in relative a record to files and in 1indexed to be marked as deleted; subsequent READ or REWRITE statements. The DELETE statement cannot be used There are two DELETE statements: the direct DELETE statement. with a sequential the sequential file. DELETE statement and AUXILIARY INPUT/OUTPUT STATEMENTS Sequential DELETE Statement 9.5.1 The sequential from a logical DELETE statement deletes the last unit by a READ statement. The sequential DELETE statement has the logical The For label unit of example, the DELETE (11) deletes read logical unit form: ([UNIT=]u[,ERR=s]) DELETE A record that was the number. an executable statement. statement last record read from the file connected to 11. 9.5.2 Direct The direct DELETE Statement DELETE statement deletes a DELETE statement record specified by a I, in the record number. The direct has the forms: (u'r[,ERR=s]) ([UNIT=]u,REC=r[,ERR=s]) DELETE DELETE u A logical unit number. r The direct The label access record number. s For of example, the DELETE (1'I) an executable statement. statement deletes the record specified by the value of connected to logical unit 1. located file UNLOCK UNLOCK STATEMENT 9.6 The When or UNLOCK statement unlocks a record is "locked," logical unit. records in a relative or indexed file,. it cannot be accessed by any other program AUXILIARY A record when a either or when when an Attempts The accessed READ a shared-file statement another UNLOCK to UNLOCK in INPUT/OUTPUT I/0 selects access a is locked environment is used statement has the in result place of operation. The UNLOCK UNLOCK u UNLOCK ([UNIT=]u A logical The The UNLOCK unit, in You label a unit of no must Consult sharing not an an error messages. otherwise unnecessary 1I/0 forms: executable frees file issue in [,ERR=s]) record sequential locked number. statement If automatically executed. record statement is the record. The record is unlocked is executed on the same logical unit statement statement STATEMENTS is the locked locked, cannot an statement. be UNLOCK the PDP-11 FORTRAN-77 and record locking. the records on statement the has specified logical effect. Records no locked. statement User's on a Guide sequential for file. information on file ENDFILE 9.7 ENDFILE STATEMENT The ENDFILE statement writes The ENDFILE statement has ENDFILE u ENDFILE ([UNIT=]u A logical The You can label of write sequential For unit files example, ENDFILE outputs an the an end-file record the specified unit. [,ERR=s]) executable end-file that contain statement. record only to variable-length statement 2 end-file to forms: number. an an the record to logical 9-19 unit 2. sequentially or segmented accessed records. APPENDIX A ADDITIONAL For the purpose of PDP-11 FORTRAN, DECODE, DEFINE PARAMETER discussed LANGUAGE facilitating PDP-11 compatibility FORTRAN-77 FILE, and FIND, and and octal constants. Sections A.1 through with other versions of includes statement in ELEMENTS offers the statements ENCODE, alternative syntax for the These language elements A.S5. are Section A.6 describes the interpretation of the EXTERNAL statement that applies when the /NOF77 compiler command qualifier is used. The FORTRAN-77 interpretation of the EXTERNAL statement (see Section 5.8) is 1incompatible DIGITAL FORTRAN with the previous ANSI implementations. standard and with previous ENCODE DECODE A.l1 THE ENCODE AND DECODE STATEMENTS The ENCODE and DECODE statements transfer data between variables or arrays in 1internal storage and translate that data from internal to character form, or from character to internal form, according to format specifiers. Similar results can be accomplished using internal files The with ENCODE formatted and sequential DECODE WRITE and READ statements. have the forms: statements ENCODE (c,f,b [,ERR=s])([1list] DECODE(c,f,b [,ERR=s])[list] c An of integer expression. (In characters (bytes) to be DECODE to statement, internal ¢ is the the ENCODE translated number form) of statement, ¢ to character characters to is the form. be number In the translated £ A format error identifier. occurs.) (If more than one record is specified, an ADDITIONAL LANGUAGE ELEMENTS b The name of an substring or virtual the array, array reference. array characters statement, b element. after element, You cannot (In the translation contains the use variable, ENCODE to statement, external characters or character the name of a virtual to be form. b In translated array receives the to DECODE internal form.) s The label of an executable statement. list An I/0 list. (In the ENCODE statement, the I/0 list contains the data to be translated to character form, In the DECODE statement, the 1list receives the data after translation to internal The ENCODE statement according does a to WRITE the remaining The DECODE (binary) form.) the statement. statement in If character form elements translates the fewer list translates list, as to does a are the the elements and stores than positions according If b is an array, the format specifier c characters filled with character READ to format character the characters are data in b to and statement. in as transmitted, spaces. specifier its elements are processed form in b, internal stores the the order of subscript progression. The number of characters that process depends on the data an can INTEGER*2 maximum array. contain equal the interaction same An by as for example a of variable in characters multiplied contain of characters A character characters The array number the type two character to 1its equal in number number of elements. the format I/O statement. DIMENSION and DECODE statement statement. per DECODE array the specifier can For example, element, element 1length. to between ENCODE or that characters formatted the in so that is twice the number of elements or number ENCODE of b <can A character the in that contain array can 1length of each element and I/O0 list is the integer form statements the follows: K (3) CHARACTER*12 A, B DATA A /'123456789012'/ 100 The DECODE (3I4) ENCODE (12,100,B) by = 1234 = 5678 K(3) = 9012 ENCODE follows: B = statement form K K(3), translates statement K(1) K(2) character as (12,100,A) FORMAT statement (specified The DECODE 100) and translates the K(2), 12 stores the K(1) characters them values and stores the characters '901256781234" in K(3), in A to array K, K(2), as follows: and K(l1) ¢to in the character variable B ADDITIONAL LANGUAGE ELEMENTS DEFINE FILE A.2 DEFINE The DEFINE that are FILE FILE STATEMENT statement associated statement (Section sequential files, The FILE DEFINE direct The access DEFINE can also is the statement direct logical be used preferred establishes access unit sequential number. to However, describe files the direct OPEN access instrument. the size and structure of a file. FILE DEFINE a 9.1) and describes with statement FILE u has the (m,n,U,asv) form: [,u(m,n,U,asv)] ... u An integer logical <constant unit or integer variable that specifies the number. m An integer constant of records in An integer the or integer variable that specifies the number file. n length, constant in 16-bit or words integer (2 variable bytes), of each that specifies the record. U Specifies that the file is unformatted only acceptable entry in this (binary); this 1is the position. asv An integer variable, At the end of of the next called each direct the associated access higher-numbered variable I/0 operation, record in the file of the the file. record number 1is assigned to asv. DEFINE n FILE 16-bit records specifies words in the file DEFINE FILE must statement DEFINE that FILE associated the record Because record the in a file or numbered executed to the the immediately sequentially the file. file of the number (unless At following it the file by using specifier. fixed-length on logical from first integer the the end direct of u. The access 1I/0 through m. variable of in asv redefined one by each the Jjust associated asv direct record read the assignment, next variable of the I/0 or to perform as access number an I/0 statements can the 1 records unit file. always points is direct access m to exist, before associated variable the is specified establishes of containing FORTRAN I/0 system places FIND statement), processing the record be also the are refers variable operation, that each exists, of written. sequential input, or sequential the file as ‘ ADDITIONAL For example, the DEFINE FILE specifies that LANGUAGE ELEMENTS statement 3 (1000,48,U,NREC) logical unit fixed-length records; The records are numbered 3 is to be connected to a file of 1000 each record is forty-eight 16-bit words long. sequentially from 1 through 1000 and are unformatted. direct After each access I/0 operation on integer variable NREC will contain the record number immediately following the record just processed. this of file, the the record FIND A.3 FIND The to The FIND a STATEMENT statement particular FIND positions record. statement has No the a direct data access transfer file takes on a specified unit place. forms: FIND (u'r[,ERR=s]) FIND ([UNIT=]u[,REC=r][,ERR=s]) u A logical unit number. r The direct The label access record number. s The record records The access For a For example, positions associated FIND positions file's executable cannot for the be less than 1 or greater than the number of of the file, 1if specified, 1is set to the number. organization the statement. file. variable record relative FIND an number defined associated direct the of file, the record is locked. first record of the statement (1'1) logical unit variable is 1 to set the to 1. And the file; the file's statement (4'INDX) the file to associated the record variable is identified set to the by the value content of INDX. of INDX; ADDITIONAL LANGUAGE ELEMENTS PARAMETER A.4 PARAMETER STATEMENT This statement assigns PARAMETER statement a symbolic discussed name 1in from to a Section constant, 5.11. as does However, it the differs the PARAMETER statement discussed in Section 5.11 in that its list is not bounded with parentheses and the form of the constant (rather than the typing of the symbolic name) determines the data type of the variable. The PARAMETER Each of statement PARAMETER p=c A symbolic name. An integer symbolic the Once a has the [,p=c] ... name (p) becomes (c); c¢ symbolic name is can The symbolic name constant; complex The being of a PARAMETER A statement in constant it can applies symbolic name the same constant assigned The 1initial 1letter cannot specify explicit type Examples of program to of the the the valid forms "nn defined by the constant. constant, appear as a real PARAMETER FORMS of FORTRAN OF to the appear it can as or program only appear part unit in of in any using if of imaginary once wvalue the another part of which a a it PARAMETER unit. statement. type statements PI=3.1415927, OCTAL only constant's declaration FLAG=.TRUE., is: is symbolic name determines constant's name does not PARAMETER PDP-11 a and FORTRAN cannot can PARAMETER Octal be appear statement The A.5 to valid constant. appears. You constant any constant is allowable. The effect be a constant is the same as used. however, a be defined place 1in a program that a a symbolic name defined to were form: expression. constant constant following by using its data affect its the name type. type. in an are: DPI=3.141592653589793238D0 LONGNAME='A STRING OF 25 CHARACTERS® INTEGER CONSTANTS integer constants IV-PLUS V3.0. are The provided for octal form of compatibility with an integer constant LANGUAGE ELEMENTS ADDITIONAL nn A string of An octal digits in the range 0 to integer constant cannot 7. be negative or greater than “37777777777. Examples of valid and invalid octal valid Invalid "107 "108 integer (contains a constants digit are: outside the allowed range) "177777 Note that these have integer constants octal discussed data in "1377. (decimal "17777" (trailing forms are type point not not the same Section 2.3.5. 1Integer and treated as are allowed) quotation as mark the not allowed) typeless constants in octal octal form integers. EXTERNAL A.6 The /NOF77 /NOF77 INTERPRETATION OF THE interpretation function of statement discussed /NOF77 the compiler of the JINTRINSIC in EXTERNAL EXTERNAL statement Section 5.8. command qualifier STATEMENT It is statement with that is combines of the available the EXTERNAL only 1if the present. The /NOF77 EXTERNAL statement allows the programmer to use subprograms as The arguments to subprograms procedures or The /NOF77 to used be FORTRAN [*]v symbolic argument as arguments library statement has name of associated a a with subprogram, or the name symbolic library function having information procedure to argument name a user-supplied on FORTRAN however, example, name. subprogram; in a function wuser-supplied the library that Such the function a the is same each name or of statement, The a dummy a subprogram. to be used instead of name. See Section 6.3 functions. name can subprogram can reference name of CALL in then use the appear the 1list 1is as actual function name need an associated an dummy statement. that a complete function reference used as an SQRT(B) in CALL SUBR(A,SQRT(B),C)) represents not a subprogram name. EXTERNAL either form: that argument be [,[*]V]... EXTERNAL statement declares Note, (for the a FORTRAN external can functions. Specifies for The subprograms. EXTERNAL EXTERNAL The other not be defined argument value, a in an ADDITIONAL An example of Main the EXTERNAL LANGUAGE statement ELEMENTS is: Program EXTERNAL Subprograms SIN,COS,SINDEG SUBROUTINE EXTERNAL . Y . RETURN CALL TRIG (ANGLE,SIN,SINE) CALL TRIG (ANGLE,COS,COSINE) CALL TRIG (ANGLE,SINDEG,SINE) = TRIG (X,F,Y) F F(X) END . FUNCTION SINDEG . SINDEG SIN . RETURN = (X) (X*3.14159/180) END In the the example, FORTRAN statements function second TRIG, An SIN and library, pass the name reference statement the of second Y = SIN(X) = COS (X) Y = SINDEG (X) (*) may are SINDEG of F(X) a trigonometric is a TRIG. function Depending precede is to on equivalent a name functions user-supplied subsequently statement Y asterisk COS and the subroutine 1invokes which to in the the CALL one of supplied function. The TRIG. function statement the 1list; in in CALL The the invoked following: the name then identifies a wuser-supplied function or subprogram, not a FORTRAN library function. Use the asterisk only when a user-supplied function or subprogram (See Section has the 6.3 same for functions.) For example, EXTERNAL identifies the FORTRAN the name as additional that of a FORTRAN information on library FORTRAN function. library statement: *SIN, *COS the names SIN and COS as user-supplied subprograms library functions for the sine and cosine. and not APPENDIX CHARACTER B.l1 B SETS FORTRAN CHARACTER SET The FORTRAN character set through ® The letters e The numerals e The following Character A 0 consists Z through special of: and Space or = Equal sign + Plus - Minus * through z 9 characters: Name A a Character tab Name ' Apostrophe " Quotation $ Dollar v Comma Asterisk ! Exclamation / Slash : Colon ( Left < Left ) Right > Right . Period Other printing part of a comment. B.2 sign sign parenthesis parenthesis characters Hollerith See ASCII Table can appear constant. Any in a FORTRAN printing mark sign angle angle statement character can point bracket bracket only appear B-1. as in a CHARACTER SET Table B-1 is a table representing the ASCII character set. of the table are hexadecimal digits (0 to 7), and to the table are hexadecimal digits (0 to F). To determine the value use the number of the of an row ASCII number character, as the locate unit's the ASCII position as the 16's position digit. equal sign (=) is 3D. For character digit, and example, the use At the top left of the hexadecimal in the table, the hexadecimal column value CHARACTER SETS Table B-1: ASCII Character Set Columns 0 3 4 5 6 7 P NUL DLE SP O @ P 1 SOH DC1l | 1 A Q a 2 STX DC2 " 2 B R b q r 3 ETX DC3 # 3 C S c 5 ENQ NAK % 5 E F U \' e £ \V 7 BEL ETB ' 7 G W g W 8 9 BS HT CAN EM suBp ( ) * 8 9 H I X Y h i X Y B VT ESC + ; K [ k EOT 6 DC4 ACK A S SYN LF 4 & D 6 : T J yA s d t u j z C FF FS ¢ < L \ 1 D CR GS - = M ] m F SI us / ? 0 _ o DEL Link E SO RS . > N " n NUL Null DLE Data SOH Start of Heading DC1 Device Control 1 STX ©Start of Text DC2 Device Control 2 ETX End of Text DC3 Device Control 3 EOT End of Transmission DC4 Device Control 4 Escape ENQ Enquiry NAK Negative ACK Acknowledge SYN Synchronous BEL Bell ETB End BS HT Backspace Horizontal CAN EM Cancel End of LF Line SUB Substitute VT Vertical ESC Escape FF Form CR Carriage so SI SP shift Shift Space RADIX-50 Radix-50 Tabulation Feed Tab Feed Return Out In CONSTANTS character Idle Transmission Medium FS File GS Group RS us DEL Record Separator Unit Separator Delete AND CHARACTER Block Separator Separator SET a special character data representation in which up to 3 The Radix-50 can be encoded and packed into 16 bits. set is a subset of the ASCII character set. Radix-50 characters Character and their -2 corresponding ASCII Octal Equivalent Space A of Acknowledge is characters The 2 0 4 B.3 1 - $ . (Unassigned) 132 44 0 1l - - 71 32 33 34 35 56 60 values Radix-50 Value (Octal) 40 101 code 36 - 47 are: CHARACTER Radix-50 them values into 50 ((i * i, j, where are single and k up to values 3 characters according to per the word, by packing formula: k) + 50 * j) + stored, numeric SETS represent the code values of three Radix-50 characters. Thus, the maximum 47*50*%50 A Radix-50 + Radix-50 47*50 constant + value 47 has = the is: 174777 form: nRclc2...cn An unsigned, nonzero integer characters to follow. A character from the Radix-50 constant that character states the number of set. The maximum number of characters is 12. The character count must include any spaces that appear in the character string (the space character is a wvalid Radix-50 character). You <can use Radix-50 constants Examples only of in DATA valid and statements. invalid Radix-50 constants valid Invalid 4RABCD 4RDKO: are: (the colon is not a Radix-50 character) 6R TO When a Radix-50 element, type of constant is assigned the number of bytes the component contains fewer contains more characters characters (0 are (see bytes bytes) bytes not are than used. Table the appended than to a that can be the 2-2). numeric variable assigned depends on If the Radix-50 1length of the component, on the right. If length of the component, the the or the array data constant ASCII null constant rightmost APPENDIX LANGUAGE C.1l EXPRESSION Table Type Arithmetic SUMMARY OPERATORS Table C-1 lists the expression descending precedence. Data C C-1: in Expression Operator *% operators each data type in order of Operators Operation Operates Exponentiation upon: Arithmetic expressions *,/ Multiplication, division +,- Addition, unary Relational .GT. subtraction, plus and minus Greater than Arithmetic, or .GE. Greater equal .LT. .LE. Logical than Less than Less than equal to .EQ. Equal to .NE. Not .NOT. .AND, .OR. is is only are both A.OR.B true A and is if and false true if A true true either A or are (all relational operators have priority) equal to is if A.AND.B both expressions or equal .NOT.A only or to logical, character B Logical or integer expressions if and B if or true (continued on next page) LANGUAGE Table Data Type C-1: (Cont.) Operator Logical (cont.) Expression Operators Operation .EQV. Operates A.EQV.B only if is true if and A and B both true, or A are and . XOR, B are A.XOR.B .NEQV. C.2 SUMMARY both is true if and if A is true and false, or B is true and Same as is .EQV. and .XOR. have equal priority false only B is A upon: false .XOR. STATEMENTS The following list summarizes the statements available in the PDP-11 FORTRAN-77 language, 1including the general form of each statement. The statements are listed alphabetically for ease of reference. The "Manual Section" column indicates the section of the manual that describes each statement in detail. Manual Form Effect ACCEPT See Section READ Arithmetic/Logical/Character Assignment 3.1, 3.2, 3.3 v=e \ is or a a e is an name, expression. Assigns the logical, or the Statement variable name, an array element character substring name. value of the arithmetic, character expression to variable. Function 6.2.1 £(lpl,P)...])=e f is a symbolic name (not data type character). P is a e is an symbolic name. expression. Creates a user-defined function having the variable p as a dummy argument. When referred to, the expression is evaluated using the actual arguments in the function call. LANGUAGE Form Manual Section Effect ASSIGN s TO S V. v 3.4 is a label or a FORMAT is an of integer statement u ([UNIT=]ul[,ERR=s]) name. statement TO BACKSPACE v for label later statement or s use as a with in the an format 9.4 u is an S is a'label integer logical expression. of Backspaces nam variable the BACKSPACE DATA executable variable assigned GO specifier. BLOCK an statement. integer Associates an one unit executable record the statement. currently open file is on u. [nam] 5.13 a symbolic Specifies BLOCK CALL SUMMARY name. the DATA subprogram that follows as a subprogram. f[([all,[al]...)] 4.5 6.2 f a is a is an name expression, an procedure name. Calls subroutine name CLOSE subprogram the specified arguments a arguments in to by f, or array point. name, subprogram passing replace the entry the subroutine the or with a the actual dummy definition. ([UNIT=]ul,p][,ERR=s}) p is one of STATUS DISPOSE = DISP e is an s is a following forms: 'SAVE' 'KEEP' 'DELETE' 'PRINT' integer label Closes be the 9.2 the of expression. an executable specified abbreviated DISP. C-3 file. statement. DISPOSE can LANGUAGE SUMMARY Manual Section Effect Form COMMON [/[cb}/] nlist a ([[,]/[cb]l/nlist]... common block 5.4 name. cb is nlist is a list of one or more variable names, or array declarators array names, separated by commas. Reserves one or more blocks of storage space under the name specified to contain the variables associated with that block name., 4.4 CONTINUE Causes no processing. DATA nlist/clist/[[,] nlist nlist/clist/]... is a list of one or more variable names, array names, array element names, or character substring references, separated Subscript and substring by commas. expressions must be constant. clist is a list of one or more constants separated by commas, each optionally preceded by j*, where j is a nonzero, unsigned integer constant, Initially stores elements of clist in the corresponding elements of nlist. DECODE (c,f,b[,ERR=s])[list] is an is a is integer expression. format specifier. a variable name, array name, array element name, or character substring reference. is a label of an'executable statement, list is an I/0 list. Reads c characters from buffer b and assigns values to the elements in the list, converted according to format specification f£. LANGUAGE Form SUMMARY Manual Section Effect DEFINE FILE u(m,n,U,v)[,u(m,n,U,v)]... A.2 u is an integer variable or integer constant., m is an integer variable or integer constant. n is an integer variable or integer constant. \Y is an integer variable name. Defines the record structure of a direct access file where u is the logical unit number, m is the number of fixedlength records in the file, n is the length in words of a single record, U is a fixed argument, and v is the associated variable. DELETE ([UNIT=]Ju(,REC=r][,ERR=s]) DELETE (u'r 9.5 [,ERR=s]) u is an integer expression. r is an integer expression. S is a label Deletes by DIMENSION r, of the or an executable record the most on unit recently statement. u that is specified accessed record. a(d)[,a(d)]... a(d) is an 5.3 array Specifies declarator. storage space requirements for arrays. DO s [,] v = el,el3[,e3] : s is a label \ is a variable ei,e2,e3 are of numeric Executes the an 4.3 executable statement. name. expressions. DO loop by performing the following steps: 1. Evaluates cnt= 2. Sets 3. If cnt is less zero, does not INT((e2-el+e3)/e3) v=el than or execute equal to the loop LANGUAGE SUMMARY Manual Section Effect Form is greater If cnt 4. Executes a. the than the body of Evaluates c. the Decrements (cnt=cnt-1). greater the loop then statements the b. zero, 1in loop v=v+e3 than count loop is cnt If zero, repeats ELSE Defines a block of statements to be executed if logical expressions in previous IF THEN and ELSE IF THEN statements have values of false. IF See ELSE IF (e) e THEN. THEN is a logical expression. Defines a block of statements to be executed if logical expressions in previous IF THEN and ELSE IF THEN statements have values of false, the of ENCODE logical true. expression See IF e has and a value THEN. (c,f,b[,ERR=s])[list] c is an integer f is a b is a variable name, array name, array element name, or character substring format expression. specifier. reference. S is a list is an label of an executable statement. 1/0 list. Writes ¢ characters into buffer b, which contains the values of the elements of the list, converted according to format specification £, LANGUAGE SUMMARY Manual Form Effect Section END 4.9 Delimits a program ENDFILE u ENDFILE ([UNIT=]u,[,ERR=s]) u is an S is a Writes unit END 9.7 integer label of an unit. expression. an executable end-file record statement. on logical u. IF Terminates block IF construct. See IF THEN. END=s, ERR=s s 7.2.1.6 is a label of an executable Transfers control condition. This on is statement. end-of-file an optional or error element in each type of I/0 statement and allows program to transfer to statement number s when an end-of-file (END=) or the error ENTRY nam (ERR=) condition [([p[,pP]...])] 6.2.4 nam is a subprogram p is a symbolic Defines a EQUIVALENCE nlist occurs. an name. name. alternative subroutine or entry function point within subprogram. (nlist)[,(nlist)]... is a list array of names, character two 5.6 or array substring commas. Subscript be constants. Assigns the same each of storage the more variable names, element names, names separated expressions names location. in or must nlist by LANGUAGE SUMMARY Manual Section Effect Form EXTERNAL v[,v]... is a subprogram name. \' Defines the names specified as subprograms. 5.8 EXTERNAL *v[,*v]... \' is a subprogram name. Defines the names specified user-defined subprograms. FIND FIND as (u'r(,ERR=s]) A.3 ([UNIT=]u,REC=r[,ERR=s]) u is an integer expression, r is an integer Positions the unit the u record FORMAT to expression., file on specified by logical r. (field specification,...) 8.1 - 8.8 Describes the format in which one or more records are to be transmitted; statement label must be present, [typ] a FUNCTION nam[*n] (([p[,P]...])] 6.2.2 typ is a data nam is a symbolic name. *n is a data type length specifier. P is a type specifier. symbolic Begins a name. function subprogram, the program name names (p). can be included. and An optional type specification 4.1.1 | GO TO s S indicating any dummy argument is a label of an executable statement, Transfers control to statement number s. LANGUAGE SUMMARY Manual Form Effect GO TO (slist)[,] slist e 4.1.2 is a 1list of one labels separated is an integer Transfers control by control label; to the e or more statement by commas. expression. specified If Section the transfers to the value to the 1if e=2, control second statement is less than 1 statement of e TO v e=1, statement transfers label, and or greater number of statement labels transfer takes place. GO (if first so than present, forth). the no [[,)(slist)] 4.1.3 v is slist is a list of one labels separated an integer variable or by name. more statement commas. Transfers control to the recently associated with statement most v by an ASSIGN statement. IF (e) sl,s2,s3 e is an -] is a expression. label Transfers depending of an executable statement. control to statement si on the value of e (if e is less than 0, control transfers to sl; 1f e equals 0, control transfers to s2; 1if e is greater than 0, control transfers to s3)., IF (e) e st st is an is any executable block IF, or END, expression. statement except IF. a logical Executes the statement expression has a value Cc-9 if of the logical true, DO, LANGUAGE SUMMARY Manual Effect Form IF (el) Section 4.2.3 THEN block ELSE IF (e2) THEN block ELSE block END IF are el,e? is block logical a series expressions. of zero or more FORTRAN statements. Defines blocks of statements conditionally executes them. and If the logical expression in the IF THEN statement has a value of true, the first block is executed and control transfers to the first executable statement 1f of after the END IF statement. the logical expression has a value false, the process is repeated for the next ELSE IF THEN statement. If all logical expressions have values of false, the ELSE block is executed. If there is no ELSE block, control transfers to the next executable statement following END IMPLICIT typ IF. (af,al...)[,typ(al,a]...)]... is typ a a data type is elither in alphabetical a hyphen a specifier. single (i.e., 5.1 letter order or two separated letters by X-Y). The element a represents a single (or a range of) letter(s) whose presence as the initial letter of a variable specifies the variable to be of that data type. INCLUDE 'filespec’ 'filespec' is 1.5 a character constant. Includes the source statements in the compilation from the file specified. LANGUAGE SUMMARY Manual Section Effect Form INTRINSIC func funci,func]... is an 5.9 intrinsic function Designates symbolic intrinsic functions those names actual to be name. names and used as allows as arguments. OPEN(par([,par]...) par is a keyword following specification in one of the forms: kwd kwd = value kwd is a keyword, value depends on the keyword, described below. Keyword ACCESS as described as Values "'SEQUENTIAL' 'DIRECT' "APPEND' 'KEYED' ASSOCIATEVARIABLE v BLOCKSIZE BLANK below. e "NULL' 'ZERO' BUFFERCOUNT CARRIAGECONTROL DISPOSE DISP e 'FORTRAN"' "LIST' "NONE" 'SAVE' or 'PRINT' '"DELETE" ERR s EXTENDSIZE e FILE o) FORM 'FORMATTED' 'UNFORMATTED" INITIALSIZE KEY e (k[ ,k]..e) MAXREC NAME 'KEEP' e (same as FILE) NOSPANBLOCKS - ORGANIZATION 'SEQUENTIAL' 'RELATIVE' "INDEXED' READONLY - RECL RECORDSIZE e (same as RECL) LANGUAGE SUMMARY Manual Section Effect Form Values Keyword '"FIXED' RECORDTYPE 'VARIABLE' 'SEGMENTED' SHARED '‘oLD! STATUS - "NEW' 'SCRATCH' 'UNKNOWN'' (same as STATUS) TYPE e UNIT P USEROPEN is an array name, c element name, or variable name, character e is a numeric expression. k is a key specification. o) is a program unit s is a \ is an array constant. name. label of an executable statement. integer variable name. opens a file on the specified logical unit according to the parameters specified by the PARAMETER PARAMETER keywords. 5.11 A.4 (p=c [,p=c]...) p=c [,p=C]l... o is a symbolic c is a constant. Defines a name. symbolic name for a constant. 4.7 PAUSE [disp] disp is a decimal digit string containing one to five digits, an octal alphanumeric literal. constant, Suspends program execution and display, if one is specified. or an prints : the See WRITE PRINT 5.12 PROGRAM nam nam is a symbolic name. Specifies a name for the main program. LANGUAGE SUMMARY Manual Section Effect Form READ ([UNIT=]u, [FMT=] f[ ,END=s] [ ,ERR=8]) [list] 7.4.1.1 READ £(,1list] 7.4.1.1 ACCEPT f[,list] 7.7 u is an integer expression. £ is a format S is a label list is an I/0 list. specifier, of an executable statement. Reads one or more logical records from unit u and assigns values to the elements in the 1list. The values are converted according to format specification £, READ READ ([UNIT=]u,REC=r,[FMT=]f[,ERR=s8])[list] (u'r,[FMT=]£f[,ERR=s]) [list] u is an integer expression. r is an integer expression. £ is a format s is a label of list is an I/0 list, 7.4.2.1 specifier, an executable statement. Reads records starting at record r from logical unit u and assigns values to the elements in the list. The values are converted according to format specification f. READ([UNIT=]u(,END=s] [ ,ERR=s]) [list] u is an integer s is a label of list is an I/0 list. Reads one unformatted 7.4.1.3 expression. an executable record unit u and assigns values elements in the list. to statement. from the logical LANGUAGE SUMMARY Manual Section Effect Form =s]) READ ({UNIT=]u,REC=r[,ERR[list] 7.4.2.2 READ(u'r[,ERR=s]) [list] u is an integer expression. r is an s is a label of an executable statement. list is an integer expression. I/0 list. Reads record r from logical unit u and assigns values to the elements in the list, READ 7.4.1.2 ([UNIT=]u,[FMT=]*[,END=s][,ERR=s])[list] 7.4.1.2 7.7 READ *[,list] "ACCEPT *[,list] u is an * denotes list-directed s is list is an a integer label of expression. formatting. an executable statement. I/0 list, Reads one or more records from logical unit u and assigns values to The the elements in the list. values are converted according to the data READ type of the list element. ([UNIT=]u, ( KEY 7.4.3.2 RKEYEQ L _y v[i,K EYID=kn] 10, [,ERR=s]) NI [list ] D KEYGE KEYGT u is an kv is a kn is S is a list is an an integer expression. key expression. integer label expression. of an executable statement. list. I/0 Reads the record on logical unit u described key-of-reference and by the key expression kv kn. The values in the elements the in record list. are assigned to the number LANGUAGE SUMMARY Manual READ Section Effect Form ([UNIT=]u,[FMT=]f, ( KEY KEYEQ % —xy[,KEYID=kn] [,ERR=s])[1list] KEYGE 7.4.3.1 KEYGT u is an integer expression, £ is a format specifier. kv is a key expression, kn is an S is a list is integer expression. label of I/0 list, an an executable statement. Reads the record on logical unit u described by the key expression kv and key-of-reference number kn. The values in the record are converted according to format specification f and assigned in the list. READ to the elements ([UNIT=]c,[FMT=]f[,ERR=s][,END=s])[1list] o] is an internal f is a S is the list is an file 7.4.4 specifier, format specifier. label of an executable statement. I/0 list. Reads one or more internal records into the I/0 list in accordance with the format specification. RETURN 4.6 Returns control from the current to the calling program subprogram. 9.3 REWIND u REWIND ([UNIT=]ul,ERR=s]) u is an ] is a integer expression. label of an executable Repositions logical unit statement. u to the beginning of the currently opened file. LANGUAGE SUMMARY Manual Form Effect REWRITE Section ([UNIT=]u,[FMT=]f[,ERR=s]) u is an integer f is a format s is a label list is an [list] . 7.6.1.1 expression, specifier. of an executable statement. I/0 list. Rewrites the current record on logical unit u, containing the values of the elements of the list. The values translated according to format specification f. REWRITE ([UNIT=]ul,ERR=s]) u is an s is a list is an ([list] integer label are of 7.6.1.2 expression. an . executable statement. I/0 list. Rewrites the current record on logical unit u, containing the values of the elements of the list. SAVE[a[,a]...] a 5.7 is a named common block enclosed slashes, a variable name, or an in array name. Retains the definition status of an entity after the execution of a RETURN or END statement in a subprogram. STOP ([disp] disp 4.8 is a decimal digit string containing one to five digits, alphanumeric an octal literal. constant, or an Terminates program execution and prints the display, if one is specified. SUBROUTINE nam([([pl,P]l...])] 6.2.3 nam is a symbolic name. p is a symbolic name, Begins a subroutine subprogram, indicating the program name names and any dummy argument (p). C-16 LANGUAGE Form Manual Section Effect TYPE See WRITE, Formatted Sequential. See Type SUMMARY WRITE, | 7.8 List-Directed. Declaration 5.2 typ vi,v]... typ is one of the following data types: BYTE LOGICAL LOGICAL*1 LOGICAL*2 LOGICAL*4 INTEGER INTEGER*2 INTEGER*4 REAL REAL*4 REAL*8 DOUBLE PRECISION COMPLEX COMPLEX*8 CHARACTER CHARACTER*1len \Y is a variable name, function or array name, function entry an array declarator. The optionally be followed by type length specifier For character specifier can a (*n). entities, be UNLOCK u ([UNIT=]Ju[,ERR=s]) data length are assigned the 9.6 u is an ] is a integer label Unlocks logical VIRTUAL the or can *len., The symbolic names (v) specified data type. UNLOCK name, name of expression. an executable all records unit u. statement. currently locked a(d)([,a(d)] ... a(d) on 5.5 is an array declarator. Specifies storage space for arrays outside normal program address space. C-17 LANGUAGE SUMMARY Manual Effect Form s]) [list] WRITE ([UNIT=]u,[FMT]=£f[,ERR= Sectio 7.5.1.1 PRINT f[,list] 7.8 TYPE f£[,list] 7.8 u is an integer expression. f is a S is a label of an executable statement. list is on format specifier. an I/0 list. Writes one or more records to logical unit u, containing the values of the elements The values are converted in the list. according to format specification f. =s]) WRITE ([UNIT=]u,REC=r,[FMT=]f[,ERR[list] =s]) (u'r,[FMT=]1£[,ERR[list] WRITE 7.5.2.1 integer expression. u is an r is an integer expression. f is a format specifier. s is a label of an executable statement. list is an I/0 list. Writes one or more records on logical unit u, containing the values of the elements The of the list starting at record r. values are converted according to format specification f. ([UNIT=]Jul,ERR=s])[list] WRITE integer expression. u is an S is a label of an executable statement label. list is an I/0 list. Writes one unformatted record to logical unit u containing the values of the elements in the list. 7.5.1.3 LANGUAGE SUMMARY Manual Form Effect Section WRITE ([UNIT=]u,REC=r{,ERR=s])[list] WRITE (u'r[,ERR=s]) [list] 7.5.2.2 u is an integer expression. r is an integer expression. s is a label of list is an 1I/0 list,. Writes the an record values r of executable to the logical elements statement unit in u the label. containing list. WRITE([UNIT=]u, [FMT=]*[ ,ERR=s])[list] 7.5.1.2 7.8 PRINT TYPE *[,list] 7.8 *[,list] u is an integer * denotes ] is a label of list is an 1/0 list. Writes unit u expression. list-directed an formatting. executable statement. one or more logical records to logical containing the values of the elements in the list. according to The values are converted the data type of the list element. WRITE ([UNIT=]c,[FMT=]f o] is an f is a ] is the list is an [,ERR=s])[List] internal format label I/0 file 7.5.4 specifier. specifier. of an executable statement. list. Writes elements in the list to the internal file specified by the unit, converting to character strings in accordance with the format specification. LANGUAGE C.3 LIBRARY Table C-2 SUMMARY FUNCTIONS lists the PDP-11 FORTRAN-77 generic functions and functions (listed in the column headed "Specific Name"). in the table refer to notes that follow the table. Table Functions Square rootl C-2: Generic and Number of Arguments Intrinsic Generic Name SQRT a(l/2) Natural logarithm2 LOG Log(e)a Common logarithm2 LOG10 intrinsic Superscripts Functions Specific Name Type of Argument Type of Result SQRT Real Real DSQRT CSQRT Double Complex Double Complex ALOG Real Real DLOG CLOG Double Complex Double Complex ALOG10 Real Real DLOG10 Double Double Log(10)a Exponential EXP e(a) Sine3 Sin SIN a Cosine3 Cos cos a Tangent 3 Tan TAN sin ASIN Arc cos tan tan Hyperbolic Sinh Complex Complex SIN Real Real DSIN CSIN Double Complex Double Complex cos Real Real DCOS CCos Double Complex Double Complex TAN Real Real DTAN Double Double ASIN Real Real DASIN Double Double a ACOS ACOS Real Real DACOS Double Double ATAN ATAN Real Real DATAN Double Double a Arc tangent 5,6 Arc CEXP a tangent (5) Arc Real Double a Arc cosine4,5 Arc Real Double a Arc sine4,5 Arc EXP DEXP ATAN?2 a(l)/a(2) sine SINH ATAN2 Real Real DATAN2 Double Double SINH Real Real DSINH Double Double (continued on next page) LANGUAGE Table C-2: (Cont.) Functions Hyperbolic Cosh cosine Generic Number of Arguments and Intrinsic Specific Name Name COSH tangent TANH a Absolute value 7 ABS [a] IABS Truncation$8 INT [a] IDINT AINT Nearest integer8 NINT [a+.5*sign(a)] IDNINT ANINT (real-to-integer conversion) Float9 (integer-to-real conversion) Double-Precision float? (integer-to-double Conversion precision? to conversion) single IFIX of Result Real Real Double TANH Real Real DTANH Double Double ABS Real Real DABS Double Double CABS Complex Real IIABS Integer*2 1Integer*2 JIABS Integer*4 1Integer*4 IIABS Integer*2 Integer*2 JIABS Integer*4 1Integer*4 IINT Real JINT Integer*2 Real Integer*4 IIDINT Double Integer*2 JIDINT Double Integer*4 IIDINT Double Integer*2 JIDINT Double Integer*4 AINT Real Real DINT Double Double ININT Real Integer*2 Real Integer*4 IIDNNT Double Integer*?2 JIDNNT Double Integer*4 IIDNNT Double Integer*2 JIDNNT Double Integer*4 ANINT Real Real DNINT Double Double IIFIX Real Integer*2 FLOATI DFLOTI DFLOTJ SNGL Type Double FLOATJ DFLOAT of COSH JIFXI FLOAT Type Argument DCOSH JNINT Fix 2 Functions Generic a Hyperbolic Tanh SUMMARY - Real Integer*4 Integer*2 Integer*4 Integer*2 Integer*4 Real Real Real Double Double Real SNGL Double FLOATI Real Integer*2 Real FLOATJ Integer*4 Real (continued on next page) LANGUAGE Table C-2: (Cont.) Functions Conversion to double—precision9 SUMMARY Generic and Intrinsic Functions Number of Arguments 1 Generic Name DBLE Type of Type of Real Double Complex Integer*2 Integer*4 Double Double Double REAL FLOATI FLOATJ Complex Integer*2 Integer*4 Real Real Real Specific Name DBLE - DFLOTI DFLOTJ REAL Argument Double Result Double Real part of complex or conversion to single precision 1 Imaginary part of complex 1 - AIMAG Complex Real Complex from two reals 2 - CMPLX Real Complex CMPLX CMPLX Integer*2 Integer*4 Real Real Complex Complex Complex Complex - Double Complex Complex Complex SNGL SNGL Conversion to complex or complex from two arguments Complex conjugate Real Double Real Real 1 - CONJG Complex Complex 2 - DPROD Real Double n MAX AMAX1 (if a=(X,Y) CONJG (a)=(X,Y) Double product of reals a(l)*a(2) Max imum Double Double IMAXO JMAXO IMAX1 JMAX1 Integer*2 Integer*4 Real Real Integer*2 1Integer*4 Integer*2 Integer*4 IMAXO JMAXO0 max{a(l) ,a(2),...a(n})) (returns the maximum value Real Real DMAX1 Integer*2 Integer*4 1Integer*2 Integer*4 from among the argument list; there must be at least two arguments) MAXO0 MAX1 AMXAQ Minimum min(a(l),a(2),..a(n)) (returns the minimum value among there the argument list; must be at least two n MIN AIMAXO Integer*2 Real AJMAXO Integer*4 Real AMIN1 Real Real IMINO JMINO Integer*2 Integer*4 1Integer*2 Integer*4 DMIN1 Double Double arguments) (continued on next page) LANGUAGE Table C-2: (Cont.) Generic Number of Arguments Functions Minimum SUMMARY and Intrinsic Generic Name MINO (Cont.,) MIN1 AMINO Positive difference 2 DIM a(l)-(min(a(l,,a(2))) two Specific Name Type of Argument Type of Result IMINO Integer*2 Integer*2 JMINO Integer*4 Integer*4 IMIN1 Real Integer*2 JMIN1 Real Integer*4 AIMINO Integer*2 Real AJMINO Integer*4 Real DIM Real Real DDIM Double Double JIDIM Integer*4 Integer¥*4 IIDIM (returns the first argument minus the minimum of the Functions Integer*2 Integer*2 arguments) IDIM Remainder 2 MOD a(l)-a(2)*[a(l)/a(2)] (returns the remainder IIDIM Integer*2 Integer*2 JIDIM Integer*4 1Integer*4 AMOD Real Real DMOD Double Double IMOD Integer*2 Integer*2 JMOD Inetger*4 1Integer*4 when the first argument is divided by the second) Transfer of la(l)*Sign sign 2 SIGN a(2) AND (performs a 2 logical corresponding Bitwise inclusive JISIGN Integer*4 1Integer*4 IISIGN Integer*2 Integer*2 JISIGN Integer*4. 1Integer*4 ITIAND Integer*2 Integer*2 JIAND Integer*4 1Integer*4 Integer*2 Integer*2 OR IOR on IIOR Integer*2 1Integer*2 JIOR Integer*4 Integer*4 ITEOR Integer*2 Integer*2 JIEOR Integer*4 1Integer*4 INOT Integer*2 1Integer*2 JNOT Integer*4 1Integer*4 IISHFT Integer*2 Integer*2 JISHFT Integer*4 1Integer*4 bits) exclusive OR 2 each 1 NOT bit) Bitwise shift (a(l) logically a(2) bits) IEOR OR on complement (complements Real Double bits) (performs an exclusive corresponding bits) Bitwise IAND on 2 an corresponding Bitwise AND OR (performs Real Double IISIGN ISIGN Bitwise SIGN DSIGN 2 shifted left ISHFT (continued on next page) LANGUAGE Table (Cont.) C-2: SUMMARY Generic and Intrinsic Functions Number of Generic Specific Type of Type Arguments Name Name Argument Result 1 - RAN Integer*4 Real 2 - RAN Integer*2 Real 1 - LEN Character Integer*2 2 - INDEX Character 1Integer*2 ASCII Value (returns the ASCII value of the argument; the argument must be a character expression that has a length of 1) 1 - ICHAR Character Integer*2 Character relationals (ASCII collating sequence) 2 2 - LLT LLE Logical*2 Logical¥*2 2 2 - LGT LGE Character Character Character Character Functions Random number10 (returns the next number from a sequence of pseudorandom numbers of uniform distribution over 0 to the range of 1) Length (returns length of the character expression) Index (C(1),C(2)) (returns the position substring c(2) in the expression of the character c(1)) Logical*2 Logical*2 1. The argument of SQRT and DSQRT must be greater than or equal to 0. The the principal value with the real part greater than or result of CSQRT is equal to 0. When the real part is 0, the result is the principal value with the imaginary part greater than or equal to 0. 2, The argument of ALOG, argument of CLOG must 3. The argument of SIN, DSIN, argument is treated modulo 4. The absolute less than or 5. The 6. The result of ATAN2 and equal to 0. The result DATAN2 is 0 or positive when a(2) is undefined if both arguments are is 0. 7. The complex value: result radians. value equal of absolute of to ASIN, value DLOG, ALOG10, and not be (0.,0.). COS, DCOS, 2*pi. the 1. argument DASIN, ACOS, of a of DLOG1l0 must be and DTAN must be ACOS, and TAN, ASIN, DACOS, number, DASIN, ATAN, DATAN, (X,Y), is the greater ATAN2, real than in 0. The radians. The DACOS and must DATAN2 1less be is in than or (X(2)+Y(2)) (1/2) 8. [x] is defined magnitude of equals and 5. as the and [-5.7]) x largest integer whose sign equals -5. is whose the same magnitude as that of does x. not For exceed the example [5.7] LANGUAGE Functions same SNGL with argument 10. The that effect a as cause the real return argument argument the value one and of the the function argument the argument generate different be to an to DBLE another type statements. with a provide The the function double-precision without conversion. integer variable array Resetting must type assignment stores random values function data in integer starting this of conversion element. The argument should initially be set to 0. The RAN function a value in the argument that it later uses to <calculate the next number, for conversion implied SUMMARY 0 regenerates random-number the or sequence. sequences. Alternate INDEX Arrays (Cont.) dummy ACCEPT statement, 1-8, 7-1, 6-2, 6-4 specifications in, multidimensional, 2-16 7-12, 7-31 Accessing ACCESS records, keyword, default function, Access 9-5 9-2, value, 9-3, 9-5 7-2, append, 9-5 direct, 7-5, 7-5, sequential, 7-4 Assignment 9-5 ASSIGN 9-5 7-4, 9-5 (See Arguments, 2-14, 2-17, 6-3 governing, bound values 8-30 rules statement, 7-12 3-1 for, 1-8, variables, ASSOCIATEVARIABLE 9-3, 3-2 3-5, 4-3, Asterisk (*), Auxiliary I/0 6-3 to 9-2, arrays, 6-5 dummy 1-3, 1-7, 2-15 statements statements, of, 6-4 descriptor, 8-13 3-6 keyword, 9-6 Assumed-size arrays, rules " 2-16, statements, Associated actual) field 2-15 7-7 9-4 arguments Adjustable 8-26 Assigned GO TO statement, 4-3 Assigning statement labels, 3-5 shared, A of, 2-16 conversion keyed, Actual storage typing, unsubscripted, 9-3 9-5 mode, argument, format (See I/0 auxiliary) 8-15, defaults for, 8-22 variables, 5-1 Alphanumeric literals, 1-8 Allocating .AND., Angle ANSI BACKSPACE brackets, Standard 8-23 FORTRAN-77, enhancements to, 1-1 in 8-29 input Arguments, 2-2, 7-25 Arithmetic BLOCK 6-1, 6-2 Block conversion rules examples Arithmetic of, for, type of, of, IF elements, Array names, 2-21 Bounds, 4-4, Arrays, 2-1, 9-6 statement, 5-1, subprograms, (See 5-22, 2-2 IF block) constructs, 4-6, 4-7 4-10 factor, 9-7 allocating, array, 9-10 2-14 size, 9-7 BUFFERCOUNT keyword, Buffer, 2-17 2-13 actual argument, 6-3 adjustable, 2-14, 2-17, 9-2, 9-3, 9-7 2-14 unsubscripted, 2-2, trailing, Bucket 2-19 2-12, 2-14 2-13, 9-3, BLOCKSIZE keyword, 9-2, 9-3, 9-7 BN edit descriptor, 8-3, 8-31 statement, Array and statement IF Blocks, 2-20 declarators, IF Blocking 2-19 4-11, 4-14 Arithmetic operators, Array DATA nested, 3-2 3-3 expressions, evaluation Arithmetic 9-2, 9-6 as zeros, statements, Block 3-1 8-3, embedded 6-10 Block data 6-1 6-1 assignment statements, 9-1, ' treating subprogram, data keyword, 8-3 ignoring, 7-16 4-15, (See 9-6 5-9 actual, 1-8, operators) Blanks, records, buffer, Arithmetic operators constants, in output records, 'APPEND', 9-5 dummy, 4-16 Binary BLANK character Argument, Batch, 1-1 Apostrophes, in statement, 9-17 2-24 1/0 transfer, 9-7 Buffers, specifying, 9-7 BZ edit descriptor, 8-3, 8-31 BYTE, 6-2 2-4 storage, Index-1 2-4 INDEX Common blocks, 2-2, blank, 5-5 extending, 5-16 C comment indicator, 1-3, CALL statement, 1-8, 4-1, 5-17, 6-6, 6-9, 6-11, 1-7 4-14, 6-13 debugging 7-3, space, TAB, 8-4 2 assignment 3-4 Character statements, CONTINUE constants, apostrophe within, 2-9 2-10 to data, statement, 1-8, 4-1, 4-14 Control Control Control input records, 7-16 output records, 7-25 Character 2-4 editing, 8-20, 8-21 type, 2-1, 2-3 COMPLEX*8, 2-4 Computed GO TO, 4-2 Continuation characters, 1-3, 1-7 Continuation field, 1-7 Continuation line, 1-3, 1-7, 1-10, 4-17 2 Character in in storage, 9-11 plus, 1-7 Complex data Complex data 7-3 Character, statement, Complex constants, 2-7 in a record, 7-16 control, 8-2, 8-18, 8-23, 8-30, 9-8 CARRIAGECONTROL keyword, 8-23, 9-2, 9-3, 9-8 empty, 5-22 Compilation, Carriage Cells, 5-5, specifying, 8-13 descriptors, 8-2 statements, 4-1 variable, 4-11 Conventions, document, naming, 2-3 8-15 Characters, ASCII, B-1, B-2 carriage control, 8-24 continuation, 1-3, 1-7 Conversion rules, statement, assignment 3-2 Converting data, 8-1 Counting, character, Creating files, 9-1 FORTRAN, B-1 printing, B-1 2 8-17 Character data type, 2-1, 2-3 Character expressions, 2-22 CHARACTER*len, 2-4, 5-2, 5-3 storage, 2-4 Character library functions (See Functions, character) Characters-per-column formatting, 1-5 Character set, FORTRAN, PDP-11 ASCII, FORTRAN-77, RADIX-50, Character Character B-1, B-2 B-1 1-4 B-2 substring, 2-17 substring reference, statement, 1-8, 9-1, 9-14, descriptor, 8-18, 9-15 Colon (:) readable, 7-1, 8- 1 translating, 7-1 DATA statement, 1-8, 2-12, 2-14, 2-17, 5-1, 5-9, 5-19, 5-23 Data Data type type edit 8-31 Control list, specifiers, Constants, Hollerith, 1-4 2-2 RADIX-50, storage, of 2-3 B-2 (,) field terminator, 8-1 Debugging Comma (,) format separator, 8-24 Decimal Comma (,) terminator, 7-16 Comment indicators, 1-7 optional, 1-3 statement, 5-23 2-17, assigning, 2-3 statements, point, 1-7 determining location of, 8-19 Declarations, adjustable 1-3 COMMON 7-25 2-4 1-7 Comma 2-13, 2-3 Data typing, 2-3, 5-2, 5-3, 5-21 by implication, 2-12 by specification, 2-12 default, 5-2 Debugging statement indicator, 1-4 parameter, type, PDP-11 FORTRAN-77 variations, 2-3 Data types, 2-1, 2-2 default output formats of, ways 7-5 7-6 2-1, character, Comments, conversion, 2-3 length specifier, Data 2-18 CLOSE Data conversion, 8-1 Data, binary, 7-1, 8-1 editing, 7-1, 8-1 array, 6-3 array, 1-8, 5-1, 2-12, 5-6, 5-8, 2-13 DECODE statement, 5-9, 7-22, 8-1, A-1 DEFINE FILE statement, Index-2 6-5, 7-10, A-1, A-3 INDEX 'DELETE', DELETE 9-8, 9-16 statement, ' 1-8, 9-1, ELSE, 9-17 direct, 9-18 sequential, 9-18 Descriptor summary codes, of, Descriptors, Descriptors, D exponent, 8-1 5—1, 5—5' IF THEN, END 1-8, 2-13 in in Dimension declarator, array, 2-14 'DIRECT', 9-5 Direct-access file, A-3, A-4 attributes of, 7-26 number of records in, 9-11 Direct-access 1/0, 9-6, A-3 Direct-access input, 7-18 Direct-access output, 7-23 Direct-access READ statements, 7-18 formatted, 7-18, 7-19 unformatted, Direct—-access 7-18, WRITE 7-19 7-23 formatted, 7-23, DO 8-17, 8-31 4-8, nested, 4-12, within, 1-8, 4-1, specifying, 2-1, 2-4 arguments (See Edit governing, 2-23 descriptors 7-10, 6-6, 9-1 6-10, 6-11 2-2, 6-11 statement, 1-8, 5-1, 5-9, 5-11, 2-17, 2-12, 5-13, 5-16 Equivalencing arrays, 5-12 Equivalencing substrings, 5-13 examples +EQV., of, 5-14, 5-15 2-25 keyword, Error 7-10, 9-2, conditions, 7-10 Error processing, result (!), 1-3, statements, type 9-8 2-19, from, 1-7 1-8 declaration, types Exponents, 9-3, 7-11 point Exponentiation, 2-13 2-20 2-20 2-6 8-9, 2-1, arithmetic, 2-18 character, 2-19, 8-10 2-18 2-22 logical, 2-19, 2-24 relational, 2-19, 2-22 subscript, 2-15 variable format, 8-22 Extended range DO, 4-13 rules governing, 4-14 EXTENDSIZE keyword, 9-2, 9-3, EXTERNAL 5-1, EXTERNAL dummy) 2-17, 6-11, 6-12, 6-13 function subprograms, 6-12 subroutine subprograms, 6-13 statement, 5-17, Arguments, 7-10, 4-5 statement, .EQ., 4-13 8-9 1-8, 5-23, EQUIVALENCE 4-10, 8-8 to 8-9, 8-10, 8-11 to 8-12 precision data type, 2-3, 4-1, Expressions, 2-6 4-1, 5-16, conditions, points, 4-13 4-11, 4-12, 6-3 Double precision constants, Double precision data, Dummy 1-8, Executable 6-12, 4-8 7-10, 9-19 specifying, transfers to Double statement, Explicit 4-10, 7-12 control statement, 6-10 Exclamation 9-16 DISPOSE keyword, 9-2, 9-3, 9-8 Dollar sign ($) edit descriptor, loops, 6-8, controlling, DISP (See DISPOSE) DISPOSE (in CLOSE), DO 4-16, rules 7-24 unformatted, 7-23, 7-24 Disk blocks, 9-7, 9-11 1-8, 1-3, 4-11, Entry ERR statements, A-2 statement, ENTRY 4-6, 6-5, A-1, 4-8, ENDIF, 5-23 array, 4-5, 5-9, 9-1 End-of-file 2-13, 4-1, 8-1, 7-10, 9-1, 8-11, 4-5 statement, ENDFILE 2-7 statement, Dimensions, ELSE 7-29, D debugging indicator, 1-7 D field descriptor, 8-10 to 8-20, 8-22, 8-30 DIMENSION 1-8 END=, 8-30 4-1, I1IF, ENCODE control, 8-2, 8-3 edit, 8-3 field, 8-2, 8-3 Descriptors, 1-8, ELSE 6-11, 1-8, 9-8 6-14 statement, /NOF77, A-1, A-6 (See Descriptors, edit) Editing data (See Data, E field descriptor, 8-9 8-11 to 8-12, 8-20, defaults for, 8-22 F editing) to 8-10, 8-30 field descriptor, 8-11 to defaults Field, to number, 8-9, 8-30 indicator, 1-6 sequence Index-3 for, 8-20, 8-22 continuation 1-4, 8-8 8-12, 1-5, 1-6 INDEX Formatted sequential 7-24, 7-33, A-1 Formatting, Field, continuation indicator (Cont.) statement, 1-5, 1-6 statement label, 1-4, 1-6, 1-7 Field descriptors, 8-1, 8-2 default parameters of, 8-21 explicit, 7-7 list-directed, File File Function specifying, positioning, 9-1 9-9 indexed, 9-9 intrinsic, multiple, specific, 7-30, 9-10 opening, 9-1 relative, 7-3 sharing, 9-13 sequential, 7-3 user 6-6, 6-6, 6-12 5-1, 5-17, 6-13, 6-14, 6-17 6-12 6-14, ' C-20 6-14 generic and list of, C-20 Function subprograms, 6-7, 6-12 rules governing, 9-9 status, specifying, 9-14 statement, 1-8, A-1l, A-4 'FIXED', FMT, 2-2, defined, Functions, unformatted, 9-8 File size, extending, File FIND 6-11, 5-18, 6-1, 6-15, C-20 lexical, 6-13, 9-15 7-21, 2-2 character, 6-13, 6-17 generic, 6-1, 6-14, 6-15 9-8 7-3, points, 6-8, 6-10, Functions, 2-1 Files, 7-2, 7-3 ASCIZ stream, 9-13 connecting, 9-1 formatted, entry Function references, 2-1, 6-8 generic, 6-14 intrinsic, 6-14 FUNCTION statement, 2-17, specifying, 9-11 name, disconnecting, lines, 1-4 9-9, 9-12 9-3, 'FORTRAN', 9-8 FORTRAN lines, fields of, 1-4 Field widths, default, 8-22 File, direct-access (See Direct—-access file) FILE keyword, 5-9, 9-2, 9-3, File organizations, 7-23, 7-7 Formatting FORTRAN FORM keyword, 9-2, separating, 8-24 Fields, 7-3 external, 8-3 Field separator, 8-1 external, 8-29 Field terminators, 8-1 WRITE, intrinsic, 2-2, 6-5, 6-9 9-13 7-7 Format Format codes, 8-29 control, 8-26 Format reversion, 8-27, 8-29 Format specifications, 8-1 Format specifiers, 7-1, 7-7 explicit, 7-1 Formats, run-time, 8-2 FORMAT statements, 1-8, 3-5, 7 -7, 8-1, 8-23, 8-26, 8-28, 8- 29 rules governing, 8-27 ' FORMATTED', 9-9 Formatted direct-access READ, 7-18, Formatted 7-19 direct-access 7-19, 7-32, of, functions (See generic) Field descriptor, 8-20, 8-30 defaults for, GO names, 6-15 Functions, 8-11 to 8-22 TO statement, 1-8, 3-5, 4-2, 4-3, 4-11, 4-14 assigned, 4-2, computed, 4-2 2-23, 8-12, 4-1, 4-3 4-2 6-19 indexed READ, 7-20 indexed REWRITE, 7-30 indexed WRITE, 7-28 I/O (See 1/0, input, 7-20, 7-15, 7-22, 7-18, 7-27, Hexadecimal 7-31, 8-3 Formatted 7-27, Formatted Generic G 6-19 function summary .GT., formatted) Formatted 2-23, unconditioned, WRITE, 7=-27 Formatted Formatted Formatted Formatted .GE., Generic output, 7-23, 7-24, 7-28, 7-29, 7-30, 7-32 sequential READ, 7-15, constants, 2-3, 2-7 Hexadecimal data, specifying, 8-7 H field descriptor, 8-14, 8-30 Hollerith constants, 1-8, 2-3, 2-10 Hollerith to A-1l Index-4 data, 8-15 specifying, 8-13 INDEX I ICHAR IF function, 6-19 statements, 4-1, 4-4 arithmetic, 1-8, 4-4 block, I INTRINSIC 5-17, I1/0 1list, implied 1-8, 4-4, simple, 7-11 I1/0, direct access, 4-5, 4-11 logical, 1-8, 4-4 field descriptor, 8-4, 4-8, 4-1, 4-9, , defaults for, 8-22 IF THEN, Statement, 5-18 7-5, 7-11, DO, 7-12 indexed, 1-8, 5-1, 8-4, 8-27 7-1 7-1 internal, 7-1 multibuffered, 9-7 sequential, 7-1 8-30 I1/0 statements, 2-17, 7-1, 7-2, 9-7 4-5 IMPLICIT statement, 1-8, 2-3, 2-12, 2-13, 5-1, 5-2, 5-23, 6~14 Implicit type declarations, 2-13 auxiliary, 9-1 components of, 7-5 formatted, 7-1, 8-1, 9-9 list-directed, 7-1 Included file, 1-9, 1-10 INCLUDE statement, 1-9 7-13 unformatted, 7-1 Implied DO list, 7-12 Increment parameter, INDEX function, 6-18 'INDEXED', 9-11 Indexed access mode, syntactical Iteration control, 4-11 Iteration count, 4-11, 4-12 Iterative processing, 4-1 4-11 7-4, rules governing, 7-5 Indexed files (See Files, indexed) Indexed input, 7-20 Indexed I/0 statements, 5-9 K Indexed WRITE statements, 7-27 formatted, 7-28 unformatted, 7-28, 7-29 'KEEP', 9-8, 9-15 KEY, 7-8, 7-9 'KEYED', 9-5 KEYEQ, 7-8, 7-9 Key expressions, 5-9, 7-8, 7-9 primary, 7-8 alternate, 7-8 Indicators, 1-7 KEYGE, 7-8, 7-9 KEYGT, 7-9, 7-9 KEYID, 7-8, 7-21 Indexed output, 7-28, 7-30 Indexed READ statements, 7-31 Key fields, designating, 9-10 Index, key, 7-8 Initial parameter, 4-11 INITIALSIZE keyword, 9-2, 9-3, 9-9 KEY keyword, 9-2, 9-3, 9-10 Key-of-reference number, 7-8, 7-9 (also see I/0 statements) INTEGER*2, 2-4 7-9 Keys, 7-3, 9-11 INTEGER*4, 2-4, 2-5 storage, 2-4 Integer constants, 2-4 octal form of, A-1, A-5 primary, 7-4, 7-31 Key specification, 7-5, 7-8 Key specifier, 7-8 Keyword, statement, 7-5 Input statements, 7-14, 7-31 storage, 2-4 Integer data, specifying, 8-4 to 8-5 Integer data type, 2-1, 2-3 Interactive 1/0, 8-18 Interactive mode, 4-16 Internal files, 7-2, 7-3, 7-7, 17-22, 7-29 Internal Internal file specifier, input, Key-of-reference specifier, 7-8, alternate, 7-4, 7-9 Keywords, OPEN statement, 9-2 Keyword specifications, statement, OPEN examples of, 9-6 7-4, L 7-7 7-22 Internal output, 7-29 Internal READ statements, 7-22 Internal WRITE statements, 7-29 Intrinsic Functions, FORTRAN (See Functions, intrinsic) Initializing variables, 5-1 Label, statement, 1-3 .LE., 2-23, 6-19 LEN function, 6-18 lLexical comparison library functions (See Functions, lexical comparison) Index-5 INDEX L field descriptor, defaults for, 8-12, 8-30 Memory, directly addressable, Multibuffered 1/0, 9-7 Multiple functions, 8-22 LGE function, 6-19 LGT function, 6-19 Library functions, name FORTRAN, usage, 5-8 6-17 6-9, 6-13 list Line, of, C-20 FORTRAN, Lines, 1-5 FORTRAN, 1-3 continuation, 1-3 'LIST', 9-8 List-directed ACCEPT, List-directed input, List-directed output, 7-15 List-directed WRITE, 7-25 /LIST qualifier, 1-9 with INCLUDE, 1-9 LLE function, 6-19 LLT function, 6-19 LOGICAL*1, 2-4 (also storage, 2-4 LOGICAL*2, 2-4 storage, 2-4 LOGICAL*4, 2-4 storage, 2-4 Logical assignment conversion rules see statements, for, 3-2 unit 2-23, Magtape 3-3 O specifier, 9-7 fields, 8-26, 8-29 value, a record, 7-16 field descriptor, 7-26, statements, 7-6 9-8, for, files, 7-30, 9-7 4-17 7-5 generic Match (partial), criterion, Matching, 8-24, 7-5, approximate 9-1, double precision, 2-22 integer, 2-21 real, 2-22 Operators, 2-1, 2-18 arithmetic, 2-19, C-1 logical, Match, exact, 8-3, 2-24, C-1 2-23, C-1 keyword, 9-2, 9-11 default value, 9-4 Output statements (See 2-2, 8-30 2=-22 complex, relational, 1-3, 8-5, 8-22 A-3 Operations, 6-19 programs, 9-4, 2-25 .OR., 2-24 ORGANIZATION Main 9-2, Octal constants, 2-3, 2-7 Octal data, specifying, 8-5 to 8-6 'OLD', 9-14 OPEN statement, 1-8, 5-9, 7-6, Logical units, connecting files to, 9-1 explicit, 7-6 implicit, 7-1, 7-6, 7-31 specifying 9-14 user-specified, 7-32, 7-33 .LT., keyword) 2-~25 defaults data type, 2-1, 2-3 Logical expressions, 2-24 evaluation of, 2-25 Logical FILE 'NEW', 9-14 Newton-Raphson, 6-9 /NOF77, 4-11 'NONE', 9-8 NOSPANBLANKS keyword, 9-11 default value, 9-4 Null Null in BYTE) Logical IF (See 'NULL', 2-4 Logical IF (See logical) 2-23 .NOT., Logical constants, 2-19 in a record, 7-16 storage, keyword .NE., .NEQV., 7-25 7-15 7-23, 7-25 READ, 7-25 sequential READ, List-directed List-directed NAME 9-4, I/0 statements) Overlaid programs, Overlays, 5-17 5-17 PARAMETER, /NOF77, 5-21, PARAMETER statement, 7-5 7-8, 7-9 generic, 7-10 exact, 7-10 generic, 7-10 MAXREC keyword, 9-2, 9-4, default values, 9-4 9-11 5-2, Index-6 5-21, 8-28 2-2, A-1, 5-1, A-5 INDEX PAUSE statement, pPDP-11, 1-8, 4-1, 4-15 RECORDTYPE 5-8 PDP-11 FORTRAN-77, 1-1, default 1-2 Precedence in operations, 2-20 arithmetic operator, 2-20 Record operator, 2-24 relational operator, 2-24 'PRINT', 9-3, Procedure, 7-1, computing, statement, Program elements, Program Program termination, 4-1 unit, 1-3, 1-8 DATA, scale factor, 8-20, 5-22 statements, count, group, 8-18 to 8-21 group, 8-29 RETURN 8-28 statement, 6-8, REWIND descriptor, 8-17 to 4-17, 6-10 1-8, 5-1, 1-8, statement, RSTS/E, 5-8 Run-time formats, DO data READONLY statement, value, 7-11, 9-2, 9-4, 'SAVE', 1-8, 7-1, 7-12, 7-14, 2-4 data, 8-9, 8-12 Real specifying, 8-9 to 8-10, 8-8 8-11 to to type, 2~-1, 2-3 9-4, 9-12 default value, 9-4 Record length, specifying, end-file, 7-10, external, 7-14 length, locked, 7-5, Record in keyword specifier, a (See RECL) 7-7 terminators, 8-1 I/0 number 9-13 8-25 list, 8-4, 8-31 5-17 field, specification, Sequential Sequential factor) positions, 9-13 external record, 7-20, 9-13 9-4, overlay, Sequential 9-12, 5-1, 9-4 (See Separators, 9-13 unlocking, 9-18 variable length, RECORDSIZE 9-13 9-2, termination, 'SEQUENTIAL' 'SEQUENTIAL' 9-12, scale 8~16 edit descriptor, Sequence 9-19 P simple) Skipping character 9-12 9-18 segmented, Record list format Records, 7-2, 7-3 deleting, 9-17 fixed field 'SEGMENTED', 9-2, (See value, Simple Segment, 7-7 keyword, 2-17, 9-14 Short S data REC=, 2-5 1-8, keyword, default 2-4 storage, RECL SHARED constants, Real factor '*'SCRATCH', 2-4 9-15 5-16 9-17, 2-4 storage, 9-8, statement, Scale storage, Real SAVE 7-8, 2-4 REAL*8, 8-29 5-9 9-12 A-2 REAL*4, 7-31 4-11 9-4 statements, 7-10, 9-16 7-1, 2-21 keyword, default READ type, 9-1, 1-8, 8-25, specifications, Range, 4-11, 6-6, 7-10, 7-11, 7-29 formatted indexed, 7-30 unformatted indexed, 7-30, 8-18, 8-31 Rank, 4-1, 5-16, ' statement, REWRITE edit 8-29 8-1 specification, 4-15, Q 6-1 8-21, descriptor, Repeat 8-3, 1-3 1-3 9-11 Relational expressions, 2-23 evaluation of, 2-23 Relative access mode, 7-4, 7-5 Repeat 5-1. 8-28, 2-17 'RELATIVE', 7-31 5-1, Program P FORMAT 6-5 1-8, 1-3 suspension, 4-1 BLOCK arrays, statements, subprograms, 1-8, PROGRAM 9-4, 9-4, 9-13 specifying, 9-13 executable 9-15 statement, 9-2, values, type, Referencing, logical PRINT keyword, 9-13 7-15, 8-24 8-23 7-16 field, 1-8 (access), 9-5 (organization), 9-11 input, 7-14, 7-31 output, 7-23, 7-32 READ statements, 7-14, 7-31 formatted, 7-14, 7-15 list-directed, 7-14, 7-15 unformatted, 7-14, 7-17 Sequential WRITE statements, formatted, 7-23, 7-24 Index-7 7-23 INDEX Sequential WRITE statements (Cont.) list-directed, 7-23, 7-25 unformatted, 7-24, 7-26 Slash (/) field terminator, 8-1 Slash (/) format separator, 8-24 Slash (/) record terminator, 8-1, 8-27 Slash Space 5-1 statements, 1-8, list, 7-5 control Specifiers, SP edit descriptor, 8-4, 8-31 SS edit descriptor, 8-4, 8-31 Statement blocks, 4-6, 4-8 Statement components, 2-1 Statement field, 1-8 Statement functions, 2-2, 6-1, 6-6 Statement label, all zero, 1-7 Statement label field, Statements, 1-3 nonexecutable, required summary STATUS of, 9-2, 5-1, 8-1 9-14 4-1, 9-9 4-16 user, Transferring program control, 4-1, 4-12, 4-13, 7-10 TR edit descriptor, 8-17, 8-31 Type declaration statements, 1-8, 2-12, 2-13, 2-17, 5-1, 5-3, 5-23, 6-11 TYPE keyword (See STATUS) TYPE statement, 1-8, 7-1, 7-12, 7-31 Typing Typing Unconditional Unformatted 7-27 Unformatted 6-1 left, 8-17 right, 8-17 formatting, 1-5, 1-8 8-31 parameter, direct-access WRITE, 4-11 to 8-17, 7-20, indexed READ, indexed REWRITE, 7-31 Unformatted 6-1, READ, 7-19 7-29 6-1 Tab terminator, 7-16 T edit descriptor, 8-16 Terminal (See GO TO GO TO 'UNFORMATTED', 9-9 Unformatted direct-access WRITE, indexed input, 7-19, 7-20, 7-14, 7-17 7-17, 7-28, 7-18, 7-21 Unformatted output, 7-24, 7-26, 7-28, 7-29, 7-30, 7-31 Unformatted sequential READ, Unformatted sequential 7-18, 7-26 UNIT=, 7-6, 7-7 UNIT keyword, 9-2, '"UNKNOWN', 9-14 default value, 9-4, UNLOCK statement, 1-8, USEROPEN keyword, 9-2, T 1-6, (See typing) Unformatted 6-1 5-17 Tab-character (See Data by specification 7-30, SUBROUTINE statement, 2-17, 6-6, 6-9, 6-11, 6-12 Subroutine entry points, 2-2 Subscripts, array, 2-15 Symbolic names, 2-1, 2-2 Syntactical rules, 7-14 Tabbing Tabbing implication by typing) Unformatted references in, 5-9 subroutine, 2-2, 4-15, 6-6, 6-9, 6-13 system, 7-11 7-21 data type, 2-4 units, 9-11 external, specifiers, Transfer-of-control 7-18, 2-16, 5-5 block, 5-5 1-3, 8-31 statements) 9-4, STOP statement, 1-8, Storage, allocating, Subprograms, 8-16, 4-2 list, A-1 1-9 default value, 9-4 STATUS (in CLOSE), 9-15 array, common Transfer 1-7 C-2 keyword, 7-10 TL edit descriptor, ‘ 1-3, order, Terminating program executions, Data compatibility, executable, sharing, statements, 4-13 7-10, (/) terminator, 7-16 terminator, 7-16 Spacing, 1-8 Specification Terminal 9-4 WRITE, 9-14 9-1, 9-18 9-4, 9-15 'VARIABLE', 9-13 Variable format expressions expressions) variables, 2-1, 2-2 allocating, 5-1 Index-8 (See INDEX Variables (Cont.) associated, 2-12, 3-6 typing, 2-12 (See Data Virtual arrays, 5-7 in subprograms, 5-10 VIRTUAL statement, 2-13, typing) X 5-1, 5-8 edit .XOR., descriptor, 8-15, 8-31 8-7, 8-30 2-25 W WRITE statements, 7-11, 7-12, 1-8, 7-1, 7-10, *ZERO', Z field 7-23 9-7 descriptor, defaults Index-9 for, 8-22 PDP-11 FORTRAN-77 Language Reference Manual AA-V193A-TK READER’S COMMENTS NOTE: This form is for document comments only. DIGITAL will use comments submitted on this form at the company’s discretion. If you require a written reply and are eligible to receive one under Software Performance Report (SPR) service, submit your comments on an SPR form. Did you find this manual understandable, usable, and well organized? Please make suggestions for improvement. Did you find errors in this manual? If so, specify the error and the page number. Please indicate the type of user/reader that you most nearly represent. [ Assembly language programmer (] Higher-level language programmer [[] Occasional programmer (experienced) [] User with little programming experience (7] Student programmer [[] Other (please specify) Name Date Organization Street City State Zip Code or Country — — DoNot Tear- Fold Hereand Tape¢ — — — — — — — — —_— — e — - — = - No Postage | if Mailed in the | | United States | | Necessary BUSINESS REPLY MAIL FIRST CLASS PERMIT NO.33 MAYNARD MASS. POSTAGE WILL BE PAID BY ADDRESSEE BSSG PUBLICATIONS ZK1-3/J35 DIGITAL EQUIPMENT CORPORATION 110 SPIT BROOK ROAD NASHUA, NEW HAMPSHIRE 03061 — DoNotTear-FoldHeg — — — — — — — — — — — — — — — — — — _—— - - Cut Along Dotted Line —
Home
Privacy and Data
Site structure and layout ©2025 Majenko Technologies